From e89490fe8f3633bbb7b64a90b89e92cc6aceb5fb Mon Sep 17 00:00:00 2001 From: Adrian Lang Date: Mon, 11 Oct 2010 11:35:31 +0200 Subject: Check whether auth is available in mail notifications --- inc/subscription.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc/subscription.php') diff --git a/inc/subscription.php b/inc/subscription.php index 52091bafe..f198402f9 100644 --- a/inc/subscription.php +++ b/inc/subscription.php @@ -251,7 +251,7 @@ function subscription_addresslist(&$data){ $self = $data['self']; $addresslist = $data['addresslist']; - if (!$conf['subscribers']) { + if (!$conf['subscribers'] || $auth === null) { return ''; } $pres = array('style' => 'every', 'escaped' => true); -- cgit v1.2.3 From 30b9fabab69e5f3d63eab09a96a9aa7c669b9f38 Mon Sep 17 00:00:00 2001 From: Adrian Lang Date: Mon, 18 Oct 2010 16:30:04 +0200 Subject: Fix subscription locking - use directories since working with them is atomic - delete stale locks after 5 minutes --- inc/subscription.php | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'inc/subscription.php') diff --git a/inc/subscription.php b/inc/subscription.php index f198402f9..78cb3ed0d 100644 --- a/inc/subscription.php +++ b/inc/subscription.php @@ -44,9 +44,26 @@ function subscription_filename($id) { * * @author Adrian Lang */ +function subscription_lock_filename ($id){ + global $conf; + return $conf['lockdir'].'/_subscr_' . $id . '.lock'; +} + function subscription_lock($id) { - $lockf = subscription_filename($id) . '.lock'; - return !file_exists($lockf) && touch($lockf); + // FIXME merge this with the indexer lock generation, abstract out + global $conf; + $lock = subscription_lock_filename($id); + while(!@mkdir($lock,$conf['dmode'])){ + usleep(50); + if(time()-@filemtime($lock) > 60*5){ + // looks like a stale lock - remove it + @rmdir($lock); + }else{ + return false; + } + } + if($conf['dperm']) chmod($lock, $conf['dperm']); + return true; } /** @@ -58,8 +75,8 @@ function subscription_lock($id) { * @author Adrian Lang */ function subscription_unlock($id) { - $lockf = subscription_filename($id) . '.lock'; - return file_exists($lockf) && unlink($lockf); + $lockf = subscription_lock_filename($id); + return @rmdir($lockf); } /** -- cgit v1.2.3 From 377228581be9f054e9b3036972fa2e1395d92f90 Mon Sep 17 00:00:00 2001 From: Adrian Lang Date: Thu, 21 Oct 2010 12:55:50 +0200 Subject: Correctly decode user names in subscriptions --- inc/subscription.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'inc/subscription.php') diff --git a/inc/subscription.php b/inc/subscription.php index 78cb3ed0d..dc1c79320 100644 --- a/inc/subscription.php +++ b/inc/subscription.php @@ -175,6 +175,10 @@ function subscription_find($page, $pre) { // This is an old subscription file. $subscription = trim($subscription) . " every\n"; } + + list($user, $rest) = explode(' ', $subscription, 2); + $subscription = rawurldecode($user) . " " . $rest; + if (preg_match(subscription_regex($pre), $subscription, $line_matches) === 0) { continue; -- cgit v1.2.3 From 06ce34e4a80b6875db82190eb7abfb97bfd801b8 Mon Sep 17 00:00:00 2001 From: Adrian Lang Date: Fri, 22 Oct 2010 11:30:22 +0200 Subject: Correctly decode user names in unsubscriptions --- inc/subscription.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc/subscription.php') diff --git a/inc/subscription.php b/inc/subscription.php index dc1c79320..08d4cb241 100644 --- a/inc/subscription.php +++ b/inc/subscription.php @@ -115,7 +115,7 @@ function subscription_set($user, $page, $style, $data = null, // io_deleteFromFile does not return false if no line matched. return io_deleteFromFile($file, - subscription_regex(array('user' => $user)), + subscription_regex(array('user' => auth_nameencode($user))), true); } -- cgit v1.2.3 From d6a4a040ca66d247bb4c3fc3e67c4ee683c920b2 Mon Sep 17 00:00:00 2001 From: Michael Hamann Date: Mon, 10 Jan 2011 19:22:37 +0100 Subject: Use md5 of the id in the subscription lockdir. FS#2112 Filenames can't contain ":" on windows and the lock directory contained the unescaped page id. The lock function tries in an endless loop to create the lock directory when it fails and the directory doesn't exist. Just escaping the directory name won't work as then the filename length limit will be quickly hit when using deep namespace structures with utf8 names. Thus using the md5sum seems to be the best solution. Perhaps the lock function could also be changed to create a file with that name that contains the id so the id can be retrieved for debugging purposes. --- inc/subscription.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc/subscription.php') diff --git a/inc/subscription.php b/inc/subscription.php index 08d4cb241..1b5476553 100644 --- a/inc/subscription.php +++ b/inc/subscription.php @@ -46,7 +46,7 @@ function subscription_filename($id) { */ function subscription_lock_filename ($id){ global $conf; - return $conf['lockdir'].'/_subscr_' . $id . '.lock'; + return $conf['lockdir'].'/_subscr_' . md5($id) . '.lock'; } function subscription_lock($id) { -- cgit v1.2.3 From 412b5df14aaa2104af3d82e77380c5321cd94389 Mon Sep 17 00:00:00 2001 From: Michael Hamann Date: Sun, 6 Feb 2011 18:36:24 +0100 Subject: Prevent infinite loop in the subscription lock There is no reason why the subscription should wait for other calls because the lock is only for one page so once the other call has finished the work has already been done. This simplifies the lock mechanism so there is no more loop. --- inc/subscription.php | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'inc/subscription.php') diff --git a/inc/subscription.php b/inc/subscription.php index 1b5476553..8e3a99a8f 100644 --- a/inc/subscription.php +++ b/inc/subscription.php @@ -50,18 +50,19 @@ function subscription_lock_filename ($id){ } function subscription_lock($id) { - // FIXME merge this with the indexer lock generation, abstract out global $conf; $lock = subscription_lock_filename($id); - while(!@mkdir($lock,$conf['dmode'])){ - usleep(50); - if(time()-@filemtime($lock) > 60*5){ - // looks like a stale lock - remove it - @rmdir($lock); - }else{ - return false; - } + + if (is_dir($lock) && time()-@filemtime($lock) > 60*5) { + // looks like a stale lock - remove it + @rmdir($lock); } + + // try creating the lock directory + if (!@mkdir($lock,$conf['dmode'])) { + return false; + } + if($conf['dperm']) chmod($lock, $conf['dperm']); return true; } -- cgit v1.2.3