From 15cde0e40db8c99ef9af7e9f04c406ce6ea3bfeb Mon Sep 17 00:00:00 2001 From: Michael Meffie Date: Mon, 20 Feb 2012 15:26:09 -0500 Subject: [PATCH] auth: get local cell internal function Add an internal function to retrieve the local cell name when the auth mutex is already held. Implement afsconf_GetLocalCell in terms of the new internal function. Change-Id: I2f021a9966129e8e256b61d5219e7315b904ac0e Reviewed-on: http://gerrit.openafs.org/6875 Reviewed-by: Alistair Ferguson Reviewed-by: Derrick Brashear Tested-by: BuildBot --- src/auth/cellconfig.c | 42 +++++++++++++++++++++++++++++++++++++----- src/auth/internal.h | 1 + 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/src/auth/cellconfig.c b/src/auth/cellconfig.c index bc9feef83..e4490e85d 100644 --- a/src/auth/cellconfig.c +++ b/src/auth/cellconfig.c @@ -1457,36 +1457,68 @@ afsconf_GetCellInfo(struct afsconf_dir *adir, char *acellName, char *aservice, } } +/** + * Get the current localcell name. + * + * Internal function to get a pointer to the local cell name. + * This function must be called with the global afsconf lock held. + * + * @param[in] adir afsconf object + * @param[out] aname address to a char pointer + * @param[in] check always perform a config check, even if the + * the AFSCELL name is set. + * + * @return status + * @retval 0 success + * @retval AFSCONF_UNKNOWN failed to get cellname + * + * @internal + */ int -afsconf_GetLocalCell(struct afsconf_dir *adir, char *aname, - afs_int32 alen) +_afsconf_GetLocalCell(struct afsconf_dir *adir, char **pname, int check) { static int afsconf_showcell = 0; char *afscell_path; afs_int32 code = 0; - LOCK_GLOBAL_MUTEX; /* * If a cell switch was specified in a command, then it should override the * AFSCELL variable. If a cell was specified, then the afsconf_SawCell flag * is set and the cell name in the adir structure is used. * Read the AFSCELL var each time: in case it changes (unsetenv AFSCELL). + * Optionally, check the configuration, even if using the environment variable. */ if (!afsconf_SawCell && (afscell_path = getenv("AFSCELL"))) { + if (check) { + _afsconf_Check(adir); + } if (!afsconf_showcell) { fprintf(stderr, "Note: Operation is performed on cell %s\n", afscell_path); afsconf_showcell = 1; } - strncpy(aname, afscell_path, alen); + *pname = afscell_path; } else { _afsconf_Check(adir); if (adir->cellName) { - strncpy(aname, adir->cellName, alen); + *pname = adir->cellName; } else code = AFSCONF_UNKNOWN; } + return code; +} +int +afsconf_GetLocalCell(struct afsconf_dir *adir, char *aname, afs_int32 alen) +{ + afs_int32 code = 0; + char *cellname = NULL; + + LOCK_GLOBAL_MUTEX; + code = _afsconf_GetLocalCell(adir, &cellname, 0); + if (!code && cellname) { + strlcpy(aname, cellname, alen); + } UNLOCK_GLOBAL_MUTEX; return (code); } diff --git a/src/auth/internal.h b/src/auth/internal.h index 94b42d511..9a351fee5 100644 --- a/src/auth/internal.h +++ b/src/auth/internal.h @@ -5,3 +5,4 @@ extern int _afsconf_IsClientConfigDirectory(const char *path); extern int _afsconf_LoadKeys(struct afsconf_dir *adir); extern void _afsconf_InitKeys(struct afsconf_dir *adir); extern void _afsconf_FreeAllKeys(struct afsconf_dir *adir); +extern int _afsconf_GetLocalCell(struct afsconf_dir *adir, char **pname, int check); -- 2.39.5