/* * Check if a username is valid: If it contains only digits (or a * negative sign), then it might be bad. If we know the cellname, * then query the ptserver to see if the entry is recognized. */ static int BadName(char *aname, char *cellname) { afs_int32 tc, code, id = 0; char *nm; for ( nm = aname; tc = *nm; nm++) { /* all must be '-' or digit to be bad */ if (tc != '-' && (tc < '0' || tc > '9')) return 0; } if (cellname) { char confDir[257]; /* Go to the PRDB and see if this all number username is valid */ cm_GetConfigDir(confDir, sizeof(confDir)); pr_Initialize(1, confDir, cellname); code = pr_SNameToId(aname, &id); pr_End(); } /* 1=>Not-valid; 0=>Valid */ return ((!code && (id == ANONYMOUSID)) ? 1 : 0); }
long cm_CloseCellFile(cm_configFile_t *filep) { char wdir[MAX_PATH]; char sdir[MAX_PATH]; long code; long closeCode = fclose((FILE *)filep); cm_GetConfigDir(wdir, sizeof(wdir)); if (FAILED(StringCchCopy(sdir, sizeof(sdir), wdir))) return -1; if (closeCode != 0) { /* something went wrong, preserve original database */ if (FAILED(StringCchCat(wdir, sizeof(wdir), AFS_CELLSERVDB ".new"))) return -1; unlink(wdir); return closeCode; } if (FAILED(StringCchCat(wdir, sizeof(wdir), AFS_CELLSERVDB))) return -1; if (FAILED(StringCchCat(sdir, sizeof(sdir), AFS_CELLSERVDB ".new"))) /* new file */ return -1; unlink(sdir); /* delete old file */ code = rename(sdir, wdir); /* do the rename */ if (code) code = errno; return code; }
cm_configFile_t *cm_CommonOpen(char *namep, char *rwp) { char wdir[MAX_PATH]=""; FILE *tfilep = NULL; cm_GetConfigDir(wdir, sizeof(wdir)); if (*wdir) { if (FAILED(StringCchCat(wdir, MAX_PATH, namep))) return NULL; tfilep = fopen(wdir, rwp); } return ((cm_configFile_t *) tfilep); }
/* use cm_GetConfigDir() plus AFS_CELLSERVDB to * generate the fully qualified name of the CellServDB * file. */ long cm_GetCellServDB(char *cellNamep, afs_uint32 len) { size_t tlen; cm_GetConfigDir(cellNamep, len); /* add trailing backslash, if required */ if (FAILED(StringCchLength(cellNamep, len, &tlen))) return(-1L); if (tlen) { if (cellNamep[tlen-1] != '\\') { if (FAILED(StringCchCat(cellNamep, len, "\\"))) return(-1L); } if (FAILED(StringCchCat(cellNamep, len, AFS_CELLSERVDB))) return(-1L); } return 0; }