On tor, 2007-09-06 at 18:49 +0800, Adrian Chadd wrote: > On Thu, Sep 06, 2007, Henrik Nordstrom wrote: > > On tor, 2007-09-06 at 11:06 +0800, Adrian Chadd wrote: > > > I've seen a race condition here. The NCSA helper only reopens the file when > > > it sees the modification time change. > > > > Right.. it should add a little margin and not reopen the file if it's > > being modified just now.. > > You could stat() the file to see if the file size has changed. :P With a 2 seconds or so margin on the stat time you should not need to care. Also solves the double password change within the same second problem... but yes checking the size as well do not hurt. Patch adding a 2 seconds margin to the stat time is attached. Regards Henrik
Index: helpers/basic_auth/NCSA/ncsa_auth.c =================================================================== RCS file: /cvsroot/squid/squid3/helpers/basic_auth/NCSA/ncsa_auth.c,v retrieving revision 1.10 diff -u -p -r1.10 ncsa_auth.c --- helpers/basic_auth/NCSA/ncsa_auth.c 25 Jun 2007 11:27:03 -0000 1.10 +++ helpers/basic_auth/NCSA/ncsa_auth.c 6 Sep 2007 14:12:00 -0000 @@ -124,8 +124,11 @@ main(int argc, char **argv) *p = '\0'; /* strip \n */ if (stat(argv[1], &sb) == 0) { if (sb.st_mtime != change_time) { - read_passwd_file(argv[1]); - change_time = sb.st_mtime; + int diff = time(NULL) - sb.st_mtime; + if (diff > 2 || diff < 0) { + read_passwd_file(argv[1]); + change_time = sb.st_mtime; + } } } if ((user = strtok(buf, " ")) == NULL) {
Attachment:
signature.asc
Description: This is a digitally signed message part