Esempio n. 1
0
void cm_GetConfigDir(char *dir, afs_uint32 len)
{
    char * dirp = NULL;

    if (!afssw_GetClientCellServDBDir(&dirp)) {
        if (FAILED(StringCchCopy(dir, len, dirp)))
            return;
        free(dirp);
    } else {
        dir[0] = '\0';
    }
}
Esempio n. 2
0
static int
afsconf_Check(struct afsconf_dir *adir)
{
    char tbuffer[256];
#ifdef AFS_NT40_ENV
    char *p;
#endif
    struct stat tstat;
    afs_int32 code;

#ifdef AFS_NT40_ENV
    /* NT client CellServDB has different file name than NT server or Unix */
    if (IsClientConfigDirectory(adir->name)) {
	if (!afssw_GetClientCellServDBDir(&p)) {
	    strcompose(tbuffer, sizeof(tbuffer), p, "/",
		       AFSDIR_CELLSERVDB_FILE_NTCLIENT, NULL);
	    free(p);
	} else {
	    int len;
	    strncpy(tbuffer, adir->name, sizeof(tbuffer));
	    len = (int)strlen(tbuffer);
	    if (tbuffer[len - 1] != '\\' && tbuffer[len - 1] != '/') {
		strncat(tbuffer, "\\", sizeof(tbuffer));
	    }
	    strncat(tbuffer, AFSDIR_CELLSERVDB_FILE_NTCLIENT,
		    sizeof(tbuffer));
	    tbuffer[sizeof(tbuffer) - 1] = '\0';
	}
    } else {
	strcompose(tbuffer, 256, adir->name, "/", AFSDIR_CELLSERVDB_FILE,
		   NULL);
    }
#else
    strcompose(tbuffer, 256, adir->name, "/", AFSDIR_CELLSERVDB_FILE, NULL);
#endif /* AFS_NT40_ENV */

    code = stat(tbuffer, &tstat);
    if (code < 0) {
	return code;
    }
    /* did file change? */
    if (tstat.st_mtime == adir->timeRead) {
	return 0;
    }
    /* otherwise file has changed, so reopen it */
    return afsconf_Reopen(adir);
}
Esempio n. 3
0
static void
_afsconf_CellServDBPath(struct afsconf_dir *adir, char **path)
{
    char *p;

    /* NT client CellServDB has different file name than NT server or Unix */
    if (_afsconf_IsClientConfigDirectory(adir->name)) {
	if (!afssw_GetClientCellServDBDir(&p)) {
	    asprintf(path, "%s/%s", p, AFSDIR_CELLSERVDB_FILE_NTCLIENT);
	    free(p);
	} else {
	    asprintf(path, "%s/%s", adir->name, AFSDIR_CELLSERVDB_FILE_NTCLIENT);
	}
    } else {
	asprintf(path, "%s/%s", adir->name, AFSDIR_CELLSERVDB_FILE);
    }
    return;
}
Esempio n. 4
0
/* set modtime on file */
static int
afsconf_Touch(struct afsconf_dir *adir)
{
    char tbuffer[256];
#ifndef AFS_NT40_ENV
    struct timeval tvp[2];
#else
    char *p;
#endif

    adir->timeRead = 0;		/* just in case */

#ifdef AFS_NT40_ENV
    /* NT client CellServDB has different file name than NT server or Unix */

    if (IsClientConfigDirectory(adir->name)) {
	if (!afssw_GetClientCellServDBDir(&p)) {
	    strcompose(tbuffer, sizeof(tbuffer), p, "/",
		       AFSDIR_CELLSERVDB_FILE_NTCLIENT, NULL);
	    free(p);
	} else {
	    int len = (int)strlen(tbuffer);
	    if (tbuffer[len - 1] != '\\' && tbuffer[len - 1] != '/') {
		strncat(tbuffer, "\\", sizeof(tbuffer));
	    }
	    strncat(tbuffer, AFSDIR_CELLSERVDB_FILE_NTCLIENT,
		    sizeof(tbuffer));
	    tbuffer[sizeof(tbuffer) - 1] = '\0';
	}
    } else {
	strcompose(tbuffer, 256, adir->name, "/", AFSDIR_CELLSERVDB_FILE,
		   NULL);
    }

    return _utime(tbuffer, NULL);

#else
    strcompose(tbuffer, 256, adir->name, "/", AFSDIR_CELLSERVDB_FILE, NULL);
    gettimeofday(&tvp[0], NULL);
    tvp[1] = tvp[0];
    return utimes(tbuffer, tvp);
#endif /* AFS_NT40_ENV */
}
Esempio n. 5
0
/* initDirPathArray() -- Initializes the afs dir paths for the 
 *     server and client installations.
 *
 *     For NT these are determined dynamically; for Unix they are static.
 *
 *     NT NOTE: If a particular component (client/server) is not installed
 *              then we may not be able to initialize the paths to anything
 *              meaningful.  In this case the paths are set to the local
 *              temp directory to avoid later reference to an uninitialized
 *              variable.  The initStatus flag is set to indicate which
 *              paths (client/server) initialized properly for callers of
 *              initAFSDirPath() who would like to know this information.
 */
static void
initDirPathArray(void)
{
    char *pathp;
    const char *clientPrefix = "";
    const char *serverPrefix = "";

#ifdef AFS_NT40_ENV
    char *buf;
    int status;

    /* get the afs server software installation dir from the registry */
    if (afssw_GetServerInstallDir(&buf)) {
	/* failed; server not installed; use temp directory */
	strcpy(ntServerInstallDirLong, gettmpdir());
    } else {
	strcpy(ntServerInstallDirLong, buf);
	free(buf);
	initStatus |= AFSDIR_SERVER_PATHS_OK;
    }
    FilepathNormalize(ntServerInstallDirLong);
    status =
	GetShortPathName(ntServerInstallDirLong, ntServerInstallDirShort,
			 AFSDIR_PATH_MAX);
    if (status == 0 || status > AFSDIR_PATH_MAX) {
	/* can't convert path to short version; just use long version */
	strcpy(ntServerInstallDirShort, ntServerInstallDirLong);
    }
    FilepathNormalize(ntServerInstallDirShort);

    /* get the afs client configuration directory (/usr/vice/etc equivalent) */
    if (afssw_GetClientCellServDBDir(&buf)) {
        /* failed */
        status = GetWindowsDirectory(ntClientConfigDirLong, AFSDIR_PATH_MAX);
        if (status == 0 || status > AFSDIR_PATH_MAX) {
            /* failed to get canonical Windows directory; use temp directory */
            strcpy(ntClientConfigDirLong, gettmpdir());
        } else {
            initStatus |= AFSDIR_CLIENT_PATHS_OK;
        }
    } else {
        strcpy(ntClientConfigDirLong, buf);
        free(buf);
        initStatus |= AFSDIR_CLIENT_PATHS_OK;
    }
    FilepathNormalize(ntClientConfigDirLong);

    status =
	GetShortPathName(ntClientConfigDirLong, ntClientConfigDirShort,
			 AFSDIR_PATH_MAX);
    if (status == 0 || status > AFSDIR_PATH_MAX) {
	/* can't convert path to short version; just use long version */
	strcpy(ntClientConfigDirShort, ntClientConfigDirLong);
    }
    FilepathNormalize(ntClientConfigDirShort);
    clientPrefix = ntClientConfigDirShort;

    /* setup the root server directory path (/usr/afs equivalent) */
    strcpy(afsSrvDirPath, ntServerInstallDirShort);
    strcat(afsSrvDirPath, AFSDIR_CANONICAL_SERVER_AFS_DIRPATH);

    /* there is no root client directory path (/usr/vice equivalent) */
    afsClntDirPath[0] = '\0';

    /* setup top level dirpath (/usr equivalent); valid for server ONLY */
    strcpy(dirPathArray[AFSDIR_USR_DIRPATH_ID], ntServerInstallDirShort);
    serverPrefix = ntServerInstallDirShort;
    strcat(dirPathArray[AFSDIR_USR_DIRPATH_ID], AFSDIR_CANONICAL_USR_DIRPATH);

#else /* AFS_NT40_ENV */
    /* setup the root server directory path */
    strcpy(afsSrvDirPath, AFSDIR_CANONICAL_SERVER_AFS_DIRPATH);

    /* setup the root client directory path */
#ifdef AFS_DARWIN_ENV
    if (access(AFSDIR_ALTERNATE_CLIENT_VICE_DIRPATH, F_OK) == 0)
	strcpy(afsClntDirPath, AFSDIR_ALTERNATE_CLIENT_VICE_DIRPATH);
    else
#endif
	strcpy(afsClntDirPath, AFSDIR_CANONICAL_CLIENT_VICE_DIRPATH);

    /* setup top level dirpath; valid for both server and client */
    strcpy(dirPathArray[AFSDIR_USR_DIRPATH_ID], AFSDIR_CANONICAL_USR_DIRPATH);

    initStatus |= (AFSDIR_CLIENT_PATHS_OK | AFSDIR_SERVER_PATHS_OK);
#endif /* AFS_NT40_ENV */

    /* now initialize various dir and file paths exported by dirpath module */

    /* server dir paths */
    strcpy(dirPathArray[AFSDIR_SERVER_AFS_DIRPATH_ID], afsSrvDirPath);

    pathp = dirPathArray[AFSDIR_SERVER_ETC_DIRPATH_ID];
    AFSDIR_SERVER_DIRPATH(pathp, AFSDIR_SERVER_ETC_DIR);

    pathp = dirPathArray[AFSDIR_SERVER_BIN_DIRPATH_ID];
    AFSDIR_SERVER_DIRPATH(pathp, AFSDIR_SERVER_BIN_DIR);

    pathp = dirPathArray[AFSDIR_SERVER_CORES_DIRPATH_ID];
    AFSDIR_SERVER_DIRPATH(pathp, AFSDIR_CORES_DIR);

    pathp = dirPathArray[AFSDIR_SERVER_DB_DIRPATH_ID];
    AFSDIR_SERVER_DIRPATH(pathp, AFSDIR_DB_DIR);

    pathp = dirPathArray[AFSDIR_SERVER_LOGS_DIRPATH_ID];
    AFSDIR_SERVER_DIRPATH(pathp, AFSDIR_LOGS_DIR);

    pathp = dirPathArray[AFSDIR_SERVER_LOCAL_DIRPATH_ID];
    AFSDIR_SERVER_DIRPATH(pathp, AFSDIR_LOCAL_DIR);

    pathp = dirPathArray[AFSDIR_SERVER_BACKUP_DIRPATH_ID];
    AFSDIR_SERVER_DIRPATH(pathp, AFSDIR_BACKUP_DIR);

    pathp = dirPathArray[AFSDIR_SERVER_MIGRATE_DIRPATH_ID];
    AFSDIR_SERVER_DIRPATH(pathp, AFSDIR_MIGR_DIR);

    pathp = dirPathArray[AFSDIR_SERVER_BIN_FILE_DIRPATH_ID];
    AFSDIR_SERVER_DIRPATH(pathp, AFSDIR_BIN_FILE_DIR);

    /* client dir path */
#ifdef AFS_NT40_ENV
    strcpy(dirPathArray[AFSDIR_CLIENT_VICE_DIRPATH_ID],
	   "/NoUsrViceDirectoryOnWindows");
    strcpy(dirPathArray[AFSDIR_CLIENT_ETC_DIRPATH_ID],
	   ntClientConfigDirShort);
#else
    strcpy(dirPathArray[AFSDIR_CLIENT_VICE_DIRPATH_ID], afsClntDirPath);

    pathp = dirPathArray[AFSDIR_CLIENT_ETC_DIRPATH_ID];
#ifdef AFS_DARWIN_ENV
    if (access(AFSDIR_ALTERNATE_CLIENT_ETC_DIR, F_OK) == 0)
	AFSDIR_CLIENT_DIRPATH(pathp, AFSDIR_ALTERNATE_CLIENT_ETC_DIR);
    else
#endif
	AFSDIR_CLIENT_DIRPATH(pathp, AFSDIR_CLIENT_ETC_DIR);
#endif /* AFS_NT40_ENV */

#ifndef AFS_NT40_ENV
    pathp = dirPathArray[AFSDIR_CLIENT_DATA_DIRPATH_ID];
#ifdef AFS_DARWIN_ENV
    if (access(AFSDIR_ALTERNATE_CLIENT_DATA_DIR, F_OK) == 0)
	AFSDIR_CLIENT_DIRPATH(pathp, AFSDIR_ALTERNATE_CLIENT_DATA_DIR);
    else
#endif
	AFSDIR_CLIENT_DIRPATH(pathp, AFSDIR_DATA_DIR);
#endif

    /* server file paths */
    pathp = dirPathArray[AFSDIR_SERVER_THISCELL_FILEPATH_ID];
    AFSDIR_SERVER_FILEPATH(pathp, AFSDIR_SERVER_ETC_DIR,
			   AFSDIR_THISCELL_FILE);

    pathp = dirPathArray[AFSDIR_SERVER_RXKAD_KEYTAB_FILEPATH_ID];
    AFSDIR_SERVER_FILEPATH(pathp, AFSDIR_SERVER_ETC_DIR, AFSDIR_RXKAD_KEYTAB_FILE);

    pathp = dirPathArray[AFSDIR_SERVER_CELLSERVDB_FILEPATH_ID];
    AFSDIR_SERVER_FILEPATH(pathp, AFSDIR_SERVER_ETC_DIR,
			   AFSDIR_CELLSERVDB_FILE);

    pathp = dirPathArray[AFSDIR_SERVER_NOAUTH_FILEPATH_ID];
    AFSDIR_SERVER_FILEPATH(pathp, AFSDIR_LOCAL_DIR, AFSDIR_NOAUTH_FILE);

    pathp = dirPathArray[AFSDIR_SERVER_BUDBLOG_FILEPATH_ID];
    AFSDIR_SERVER_FILEPATH(pathp, AFSDIR_LOGS_DIR, AFSDIR_BUDBLOG_FILE);

    pathp = dirPathArray[AFSDIR_SERVER_TAPECONFIG_FILEPATH_ID];
    AFSDIR_SERVER_FILEPATH(pathp, AFSDIR_BACKUP_DIR, AFSDIR_TAPECONFIG_FILE);

    pathp = dirPathArray[AFSDIR_SERVER_KALOGDB_FILEPATH_ID];
    AFSDIR_SERVER_FILEPATH(pathp, AFSDIR_LOGS_DIR, AFSDIR_KALOGDB_FILE);

    pathp = dirPathArray[AFSDIR_SERVER_KALOG_FILEPATH_ID];
    AFSDIR_SERVER_FILEPATH(pathp, AFSDIR_LOGS_DIR, AFSDIR_KALOG_FILE);

    pathp = dirPathArray[AFSDIR_SERVER_KADB_FILEPATH_ID];
    AFSDIR_SERVER_FILEPATH(pathp, AFSDIR_DB_DIR, AFSDIR_KADB_FILE);

    pathp = dirPathArray[AFSDIR_SERVER_NTPD_FILEPATH_ID];
    AFSDIR_SERVER_FILEPATH(pathp, AFSDIR_SERVER_BIN_DIR, AFSDIR_NTPD_FILE);

    pathp = dirPathArray[AFSDIR_SERVER_PRDB_FILEPATH_ID];
    AFSDIR_SERVER_FILEPATH(pathp, AFSDIR_DB_DIR, AFSDIR_PRDB_FILE);

    pathp = dirPathArray[AFSDIR_SERVER_PTLOG_FILEPATH_ID];
    AFSDIR_SERVER_FILEPATH(pathp, AFSDIR_LOGS_DIR, AFSDIR_PTLOG_FILE);

    pathp = dirPathArray[AFSDIR_SERVER_KCONF_FILEPATH_ID];
    AFSDIR_SERVER_FILEPATH(pathp, AFSDIR_SERVER_ETC_DIR, AFSDIR_KCONF_FILE);

    pathp = dirPathArray[AFSDIR_SERVER_VLDB_FILEPATH_ID];
    AFSDIR_SERVER_FILEPATH(pathp, AFSDIR_DB_DIR, AFSDIR_VLDB_FILE);

    pathp = dirPathArray[AFSDIR_SERVER_VLOG_FILEPATH_ID];
    AFSDIR_SERVER_FILEPATH(pathp, AFSDIR_LOGS_DIR, AFSDIR_VLOG_FILE);

    pathp = dirPathArray[AFSDIR_SERVER_CORELOG_FILEPATH_ID];
    AFSDIR_SERVER_FILEPATH(pathp, AFSDIR_LOGS_DIR, AFSDIR_CORE_FILE);

    pathp = dirPathArray[AFSDIR_SERVER_SLVGLOG_FILEPATH_ID];
    AFSDIR_SERVER_FILEPATH(pathp, AFSDIR_LOGS_DIR, AFSDIR_SLVGLOG_FILE);

    pathp = dirPathArray[AFSDIR_SERVER_SALSRVLOG_FILEPATH_ID];
    AFSDIR_SERVER_FILEPATH(pathp, AFSDIR_LOGS_DIR, AFSDIR_SALSRVLOG_FILE);

    pathp = dirPathArray[AFSDIR_SERVER_SALVAGER_FILEPATH_ID];
    AFSDIR_SERVER_FILEPATH(pathp, AFSDIR_SERVER_BIN_DIR,
			   AFSDIR_SALVAGER_FILE);

    pathp = dirPathArray[AFSDIR_SERVER_SALSRV_FILEPATH_ID];
    AFSDIR_SERVER_FILEPATH(pathp, AFSDIR_SERVER_BIN_DIR,
			   AFSDIR_SALSRV_FILE);

    pathp = dirPathArray[AFSDIR_SERVER_SLVGLOCK_FILEPATH_ID];
    AFSDIR_SERVER_FILEPATH(pathp, AFSDIR_LOCAL_DIR, AFSDIR_SLVGLOCK_FILE);

    pathp = dirPathArray[AFSDIR_SERVER_KEY_FILEPATH_ID];
    AFSDIR_SERVER_FILEPATH(pathp, AFSDIR_SERVER_ETC_DIR, AFSDIR_KEY_FILE);

    pathp = dirPathArray[AFSDIR_SERVER_ULIST_FILEPATH_ID];
    AFSDIR_SERVER_FILEPATH(pathp, AFSDIR_SERVER_ETC_DIR, AFSDIR_ULIST_FILE);

    pathp = dirPathArray[AFSDIR_SERVER_BOZCONF_FILEPATH_ID];
    AFSDIR_SERVER_FILEPATH(pathp, AFSDIR_BOSCONFIG_DIR, AFSDIR_BOZCONF_FILE);

    pathp = dirPathArray[AFSDIR_SERVER_BOZCONFNEW_FILEPATH_ID];
    AFSDIR_SERVER_FILEPATH(pathp, AFSDIR_BOSCONFIG_DIR,
			   AFSDIR_BOZCONFNEW_FILE);

    pathp = dirPathArray[AFSDIR_SERVER_BOZLOG_FILEPATH_ID];
    AFSDIR_SERVER_FILEPATH(pathp, AFSDIR_LOGS_DIR, AFSDIR_BOZLOG_FILE);

    pathp = dirPathArray[AFSDIR_SERVER_BOZINIT_FILEPATH_ID];
    AFSDIR_SERVER_FILEPATH(pathp, AFSDIR_BOSCONFIG_DIR, AFSDIR_BOZINIT_FILE);

    pathp = dirPathArray[AFSDIR_SERVER_BOZRXBIND_FILEPATH_ID];
    AFSDIR_SERVER_FILEPATH(pathp, AFSDIR_BOSCONFIG_DIR, AFSDIR_BOZRXBIND_FILE);

    pathp = dirPathArray[AFSDIR_SERVER_BOSVR_FILEPATH_ID];
    AFSDIR_SERVER_FILEPATH(pathp, AFSDIR_BOSSERVER_DIR, AFSDIR_BOSVR_FILE);

    pathp = dirPathArray[AFSDIR_SERVER_VOLSERLOG_FILEPATH_ID];
    AFSDIR_SERVER_FILEPATH(pathp, AFSDIR_LOGS_DIR, AFSDIR_VOLSERLOG_FILE);

    pathp = dirPathArray[AFSDIR_SERVER_ROOTVOL_FILEPATH_ID];
    AFSDIR_SERVER_FILEPATH(pathp, AFSDIR_SERVER_ETC_DIR, AFSDIR_ROOTVOL_FILE);

    pathp = dirPathArray[AFSDIR_SERVER_HOSTDUMP_FILEPATH_ID];
    AFSDIR_SERVER_FILEPATH(pathp, AFSDIR_LOCAL_DIR, AFSDIR_HOSTDUMP_FILE);

    pathp = dirPathArray[AFSDIR_SERVER_CLNTDUMP_FILEPATH_ID];
    AFSDIR_SERVER_FILEPATH(pathp, AFSDIR_LOCAL_DIR, AFSDIR_CLNTDUMP_FILE);

    pathp = dirPathArray[AFSDIR_SERVER_CBKDUMP_FILEPATH_ID];
    AFSDIR_SERVER_FILEPATH(pathp, AFSDIR_LOCAL_DIR, AFSDIR_CBKDUMP_FILE);

    pathp = dirPathArray[AFSDIR_SERVER_OLDSYSID_FILEPATH_ID];
    AFSDIR_SERVER_FILEPATH(pathp, AFSDIR_LOCAL_DIR, AFSDIR_OLDSYSID_FILE);

    pathp = dirPathArray[AFSDIR_SERVER_SYSID_FILEPATH_ID];
    AFSDIR_SERVER_FILEPATH(pathp, AFSDIR_LOCAL_DIR, AFSDIR_SYSID_FILE);

    pathp = dirPathArray[AFSDIR_SERVER_FILELOG_FILEPATH_ID];
    AFSDIR_SERVER_FILEPATH(pathp, AFSDIR_LOGS_DIR, AFSDIR_FILELOG_FILE);

    pathp = dirPathArray[AFSDIR_SERVER_AUDIT_FILEPATH_ID];
    AFSDIR_SERVER_FILEPATH(pathp, AFSDIR_LOCAL_DIR, AFSDIR_AUDIT_FILE);

    pathp = dirPathArray[AFSDIR_SERVER_NETINFO_FILEPATH_ID];
    AFSDIR_SERVER_FILEPATH(pathp, AFSDIR_LOCAL_DIR, AFSDIR_NETINFO_FILE);

    pathp = dirPathArray[AFSDIR_SERVER_NETRESTRICT_FILEPATH_ID];
    AFSDIR_SERVER_FILEPATH(pathp, AFSDIR_LOCAL_DIR, AFSDIR_NETRESTRICT_FILE);

    pathp = dirPathArray[AFSDIR_SERVER_KRB_EXCL_FILEPATH_ID];
    AFSDIR_SERVER_FILEPATH(pathp, AFSDIR_SERVER_ETC_DIR, AFSDIR_KRB_EXCL_FILE);

    pathp = dirPathArray[AFSDIR_SERVER_FSSTATE_FILEPATH_ID];
    AFSDIR_SERVER_FILEPATH(pathp, AFSDIR_LOCAL_DIR, AFSDIR_FSSTATE_FILE);

    pathp = dirPathArray[AFSDIR_SERVER_OSDDB_FILEPATH_ID];
    AFSDIR_SERVER_FILEPATH(pathp, AFSDIR_DB_DIR, AFSDIR_OSDDB_FILE);

    pathp = dirPathArray[AFSDIR_SERVER_OSDDBLOG_FILEPATH_ID];
    AFSDIR_SERVER_FILEPATH(pathp, AFSDIR_LOGS_DIR, AFSDIR_OSDDB_LOGNAME);

    pathp = dirPathArray[AFSDIR_SERVER_RXOSDLOG_FILEPATH_ID];
    AFSDIR_SERVER_FILEPATH(pathp, AFSDIR_LOGS_DIR, AFSDIR_RXOSD_LOGNAME);

    pathp = dirPathArray[AFSDIR_SERVER_RXOSD_FETCHQ_FILEPATH_ID];
    AFSDIR_SERVER_FILEPATH(pathp, AFSDIR_LOCAL_DIR, AFSDIR_RXOSD_FETCHQ_FILE);

    pathp = dirPathArray[AFSDIR_SERVER_RECALL_MIGRATED_FILE_FILEPATH_ID];
    AFSDIR_SERVER_FILEPATH(pathp, AFSDIR_SERVER_BIN_DIR, AFSDIR_RECALL_MIGRATED_FILE_FILE);

    pathp = dirPathArray[AFSDIR_SERVER_RECALLLOG_FILEPATH_ID];
    AFSDIR_SERVER_FILEPATH(pathp, AFSDIR_LOGS_DIR, AFSDIR_RECALL_LOGNAME);

    /* client file paths */
#ifdef AFS_NT40_ENV
    strcpy(dirPathArray[AFSDIR_CLIENT_THISCELL_FILEPATH_ID],
	   "/NoUsrViceEtcThisCellFileOnWindows");
    sprintf(dirPathArray[AFSDIR_CLIENT_CELLSERVDB_FILEPATH_ID], "%s/%s",
	    ntClientConfigDirShort, AFSDIR_CELLSERVDB_FILE_NTCLIENT);
    strcpy(dirPathArray[AFSDIR_CLIENT_CELLALIAS_FILEPATH_ID],
	   "/NoCellAliasOnWindows");
#else
    pathp = dirPathArray[AFSDIR_CLIENT_THISCELL_FILEPATH_ID];
    AFSDIR_CLIENT_FILEPATH(pathp, AFSDIR_CLIENT_ETC_DIR,
			   AFSDIR_THISCELL_FILE);

    pathp = dirPathArray[AFSDIR_CLIENT_CELLSERVDB_FILEPATH_ID];
    AFSDIR_CLIENT_FILEPATH(pathp, AFSDIR_CLIENT_ETC_DIR,
			   AFSDIR_CELLSERVDB_FILE);

    pathp = dirPathArray[AFSDIR_CLIENT_CELLALIAS_FILEPATH_ID];
    AFSDIR_CLIENT_FILEPATH(pathp, AFSDIR_CLIENT_ETC_DIR,
			   AFSDIR_CELLALIAS_FILE);
#endif /* AFS_NT40_ENV */

    pathp = dirPathArray[AFSDIR_CLIENT_NETINFO_FILEPATH_ID];
    AFSDIR_CLIENT_FILEPATH(pathp, AFSDIR_CLIENT_ETC_DIR, AFSDIR_NETINFO_FILE);

    pathp = dirPathArray[AFSDIR_CLIENT_NETRESTRICT_FILEPATH_ID];
    AFSDIR_CLIENT_FILEPATH(pathp, AFSDIR_CLIENT_ETC_DIR,
			   AFSDIR_NETRESTRICT_FILE);

    initFlag = 1;		/* finished dirpath initialization */
    return;
}
Esempio n. 6
0
static int
afsconf_OpenInternal(struct afsconf_dir *adir, char *cell,
		     char clones[])
{
    afsconf_FILE *tf;
    char *tp, *bp;
    struct afsconf_entry *curEntry;
    struct afsconf_aliasentry *curAlias;
    afs_int32 code;
    afs_int32 i;
    char tbuffer[256], tbuf1[256];
    struct stat tstat;
#ifdef AFS_NT40_ENV
    cm_enumCellRegistry_t enumCellRegistry = {0, 0};
#endif /* AFS_NT40_ENV */

    /* figure out the local cell name */
#ifdef AFS_NT40_ENV
    i = GetCellNT(adir);
    enumCellRegistry.adir = adir;
#else
    i = GetCellUnix(adir);
#endif

#ifndef AFS_FREELANCE_CLIENT	/* no local cell not fatal in freelance */
    if (i) {
	return i;
    }
#endif

    /* now parse the individual lines */
    curEntry = 0;

#ifdef AFS_NT40_ENV
    /* NT client/server have a CellServDB that is the same format as Unix.
     * However, the NT client uses a different file name
     */
    if (IsClientConfigDirectory(adir->name)) {
	/* NT client config dir */
	char *p;

        enumCellRegistry.client = 1;

	if (!afssw_GetClientCellServDBDir(&p)) {
	    strcompose(tbuffer, sizeof(tbuffer), p, "/",
		       AFSDIR_CELLSERVDB_FILE_NTCLIENT, NULL);
	    free(p);
	} else {
	    int len;
	    strncpy(tbuffer, adir->name, sizeof(tbuffer));
	    len = (int)strlen(tbuffer);
	    if (tbuffer[len - 1] != '\\' && tbuffer[len - 1] != '/') {
		strncat(tbuffer, "\\", sizeof(tbuffer));
	    }
	    strncat(tbuffer, AFSDIR_CELLSERVDB_FILE_NTCLIENT,
		    sizeof(tbuffer));
	    tbuffer[sizeof(tbuffer) - 1] = '\0';
	}
    } else {
	/* NT server config dir */
	strcompose(tbuffer, 256, adir->name, "/", AFSDIR_CELLSERVDB_FILE,
		   NULL);
    }
#else
    strcompose(tbuffer, 256, adir->name, "/", AFSDIR_CELLSERVDB_FILE, NULL);
#endif /* AFS_NT40_ENV */

    if (!stat(tbuffer, &tstat)) {
	adir->timeRead = tstat.st_mtime;
    } else {
	adir->timeRead = 0;
    }

    strlcpy(tbuf1, tbuffer, sizeof tbuf1);
    tf = fopen(tbuffer, "r");
    if (!tf) {
	return -1;
    }

    /* The CellServDB file is now open.
     * The following code parses the contents of the
     * file and creates a list with the first cell entry
     * in the CellServDB file at the end of the list.
     *
     * No checking is performed for duplicates.
     * The side effects of this process are that duplicate
     * entries appended to the end of the CellServDB file
     * take precedence and are found in a shorter period
     * of time.
     */

    while (1) {
	tp = fgets(tbuffer, sizeof(tbuffer), tf);
	if (!tp)
	    break;
	TrimLine(tbuffer, sizeof tbuffer);	/* remove white space */
	if (tbuffer[0] == 0 || tbuffer[0] == '\n')
	    continue;		/* empty line */
	if (tbuffer[0] == '>') {
	    char linkedcell[MAXCELLCHARS];
	    /* start new cell item */
	    if (curEntry) {
		/* thread this guy on the list */
		curEntry->next = adir->entries;
		adir->entries = curEntry;
		curEntry = 0;
	    }
	    curEntry =
		(struct afsconf_entry *)malloc(sizeof(struct afsconf_entry));
	    memset(curEntry, 0, sizeof(struct afsconf_entry));
	    code =
		ParseCellLine(tbuffer, curEntry->cellInfo.name, linkedcell);
	    if (code) {
		afsconf_CloseInternal(adir);
		fclose(tf);
		free(curEntry);
		return -1;
	    }
	    if (linkedcell[0] != '\0')
		curEntry->cellInfo.linkedCell = strdup(linkedcell);
	} else {
	    /* new host in the current cell */
	    if (!curEntry) {
		afsconf_CloseInternal(adir);
		fclose(tf);
		return -1;
	    }
	    i = curEntry->cellInfo.numServers;
	    if (i < MAXHOSTSPERCELL) {
		if (cell && !strcmp(cell, curEntry->cellInfo.name))
		    code =
			ParseHostLine(tbuffer,
				      &curEntry->cellInfo.hostAddr[i],
				      curEntry->cellInfo.hostName[i],
				      &clones[i]);
		else
		    code =
			ParseHostLine(tbuffer,
				      &curEntry->cellInfo.hostAddr[i],
				      curEntry->cellInfo.hostName[i], 0);

		if (code) {
		    if (code == AFSCONF_SYNTAX) {
			for (bp = tbuffer; *bp != '\n'; bp++) {	/* Take out the <cr> from the buffer */
			    if (!*bp)
				break;
			}
			*bp = '\0';
			fprintf(stderr,
				"Can't properly parse host line \"%s\" in configuration file %s\n",
				tbuffer, tbuf1);
		    }
		    free(curEntry);
		    fclose(tf);
		    afsconf_CloseInternal(adir);
		    return -1;
		}
		curEntry->cellInfo.numServers = ++i;
	    } else {
		fprintf(stderr,
			"Too many hosts for cell %s in configuration file %s\n",
			curEntry->cellInfo.name, tbuf1);
	    }
	}
    }
    fclose(tf);			/* close the file now */

    /* end the last partially-completed cell */
    if (curEntry) {
	curEntry->next = adir->entries;
	adir->entries = curEntry;
    }

#ifdef AFS_NT40_ENV
     /*
      * Windows maintains a CellServDB list in the Registry
      * that supercedes the contents of the CellServDB file.
      * Prepending these entries to the head of the list
      * is sufficient to enforce the precedence.
      */
     cm_EnumerateCellRegistry( enumCellRegistry.client,
                               cm_enumCellRegistryProc,
                               &enumCellRegistry);
#endif /* AFS_NT40_ENV */

    /* Read in the alias list */
    strcompose(tbuffer, 256, adir->name, "/", AFSDIR_CELLALIAS_FILE, NULL);

    tf = fopen(tbuffer, "r");
    while (tf) {
	char *aliasPtr;

	tp = fgets(tbuffer, sizeof(tbuffer), tf);
	if (!tp)
	    break;
	TrimLine(tbuffer, sizeof tbuffer);	/* remove white space */

	if (tbuffer[0] == '\0' || tbuffer[0] == '\n' || tbuffer[0] == '#')
	    continue;		/* empty line */

	tp = tbuffer;
	while (tp[0] != '\0' && tp[0] != ' ' && tp[0] != '\t')
	    tp++;
	if (tp[0] == '\0')
	    continue;		/* invalid line */

	while (tp[0] != '\0' && (tp[0] == ' ' || tp[0] == '\t'))
	    0[tp++] = '\0';
	if (tp[0] == '\0')
	    continue;		/* invalid line */

	aliasPtr = tp;
	while (tp[0] != '\0' && tp[0] != ' ' && tp[0] != '\t' && tp[0] != '\r'
	       && tp[0] != '\n')
	    tp++;
	tp[0] = '\0';

	curAlias = malloc(sizeof(*curAlias));
	memset(curAlias, 0, sizeof(*curAlias));

	strlcpy(curAlias->aliasInfo.aliasName, aliasPtr, sizeof curAlias->aliasInfo.aliasName);
	strlcpy(curAlias->aliasInfo.realName, tbuffer, sizeof curAlias->aliasInfo.realName);

	curAlias->next = adir->alias_entries;
	adir->alias_entries = curAlias;
    }

    if (tf != NULL)
	fclose(tf);
    /* now read the fs keys, if possible */
    adir->keystr = (struct afsconf_keys *)0;
    afsconf_IntGetKeys(adir);

    return 0;
}