From: Simon Wilkinson Date: Sat, 5 Mar 2011 23:09:18 +0000 (+0000) Subject: auth: Rework afsconf_UpToDate to use CellServDB X-Git-Tag: upstream/1.8.0_pre1^2~4058 X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=1eb570996485023ce902393a251c5f4e92229d10;p=packages%2Fo%2Fopenafs.git auth: Rework afsconf_UpToDate to use CellServDB Rework the afsconf_UpToDate check so that it uses the modifcation of the CellServDB, and not the KeyFile to determine whether the configuration information has been changed under us or not. afsconf defines the CellServDB as being the single sentinel for a config directory being changed, and our tools are careful to always touch the CellServDB when updating anything else there. Also, rework the _afsconf_Check() code so that it uses afsconf_UpToDate, rather than including this logic twice. Change-Id: I8ef5f67afbb5982bb25e12407ea5dc5dc1512840 Reviewed-on: http://gerrit.openafs.org/4203 Tested-by: BuildBot Reviewed-by: Derrick Brashear --- diff --git a/src/auth/cellconfig.c b/src/auth/cellconfig.c index c457e3acb..57842a320 100644 --- a/src/auth/cellconfig.c +++ b/src/auth/cellconfig.c @@ -336,9 +336,8 @@ _afsconf_IsClientConfigDirectory(const char *path) return 1; } - int -_afsconf_Check(struct afsconf_dir *adir) +_afsconf_UpToDate(struct afsconf_dir *adir) { char tbuffer[256]; #ifdef AFS_NT40_ENV @@ -374,13 +373,36 @@ _afsconf_Check(struct afsconf_dir *adir) #endif /* AFS_NT40_ENV */ code = stat(tbuffer, &tstat); - if (code < 0) { - return code; - } + if (code < 0) + return 0; /* Can't throw the error, so just say we're not up to date */ + /* did file change? */ - if (tstat.st_mtime == adir->timeRead) { + if (tstat.st_mtime == adir->timeRead) + return 1; + + /* otherwise file has changed */ + return 0; +} + +int +afsconf_UpToDate(void *rock) +{ + int code; + + LOCK_GLOBAL_MUTEX; + code = _afsconf_UpToDate(rock); + UNLOCK_GLOBAL_MUTEX; + + return code; +} + +int +_afsconf_Check(struct afsconf_dir *adir) +{ + /* did configuration change? */ + if (_afsconf_UpToDate(adir)) return 0; - } + /* otherwise file has changed, so reopen it */ return afsconf_Reopen(adir); } @@ -1498,40 +1520,6 @@ afsconf_GetLocalCell(struct afsconf_dir *adir, char *aname, return (code); } -int -afsconf_UpToDate(void *rock) -{ - struct afsconf_dir *adir = rock; - char tbuffer[256]; -#ifdef AFS_NT40_ENV - char *p; -#endif - struct stat tstat; - afs_int32 code = 0; /* default to not up to date */ - LOCK_GLOBAL_MUTEX; -#ifdef AFS_NT40_ENV - /* NT client config dir has no KeyFile; don't risk attempting open - * because there might be a random file of this name if dir is shared. - */ - if (_afsconf_IsClientConfigDirectory(adir->name)) { - /* Not a server, nothing to reread */ - code = 1; - } else { -#endif - strcompose(tbuffer, 256, adir->name, "/", AFSDIR_KEY_FILE, NULL); - - /* did file change? */ - code = stat(tbuffer, &tstat); - if ((code == 0) && (tstat.st_mtime <= adir->timeRead)) { - code = 1; - } -#ifdef AFS_NT40_ENV - } -#endif - UNLOCK_GLOBAL_MUTEX; - return code; -} - int afsconf_Close(struct afsconf_dir *adir) { diff --git a/tests/auth/authcon-t.c b/tests/auth/authcon-t.c index b5f688ccd..1552f2637 100644 --- a/tests/auth/authcon-t.c +++ b/tests/auth/authcon-t.c @@ -45,9 +45,12 @@ main(int argc, char **argv) struct afsconf_dir *dir; char *dirname; struct rx_securityClass **classes; + struct rx_securityClass *secClass; + int secIndex; int numClasses; + struct afsconf_typedKey *key; - plan(3); + plan(9); dirname = buildTestConfig(); dir = afsconf_Open(dirname); @@ -70,5 +73,19 @@ main(int argc, char **argv) afsconf_BuildServerSecurityObjects(dir, &classes, &numClasses); is_int(4, numClasses, "When encryption is enabled, 4 classes are returned"); + /* Up to date checks */ + + ok(afsconf_UpToDate(dir), "Newly opened directory is up to date"); + is_int(0, afsconf_AddKey(dir, + 1, "\x19\x16\xfe\xe6\xba\x77\x2f\xfd", 0), + "Adding key worked"); + ok(!afsconf_UpToDate(dir), "Directory with newly added key isn't"); + afsconf_ClientAuth(dir, &secClass, &secIndex); + ok(afsconf_UpToDate(dir), "afsconf_ClientAuth() resets UpToDate check"); + afsconf_DeleteKey(dir, 1); + ok(!afsconf_UpToDate(dir), "Directory with newly deleted key isn't"); + afsconf_GetLatestKeyByTypes(dir, afsconf_rxkad, 0, &key); + ok(afsconf_UpToDate(dir), "afsconf_GetLatestKeyByTypes resest UpToDate"); + return 0; }