/*
* Copyright 2000, International Business Machines Corporation and others.
* All Rights Reserved.
- *
+ *
* This software has been released under the terms of the IBM Public
* License. For details, see the LICENSE file in the top-level source
* directory or online at http://www.openafs.org/dl/license10.html
#include <afsconfig.h>
#include <afs/param.h>
-RCSID
- ("$Header$");
+#include <roken.h>
+#include <afs/opr.h>
#include <stddef.h>
-#include <stdlib.h>
-#include <string.h>
#include <ctype.h>
#include <limits.h>
-#include <errno.h>
-#include <stdio.h>
-#include "assert.h"
+
#include "afsutil.h"
#include "fileutil.h"
+
+#include <afs/opr.h>
+
#ifdef AFS_PTHREAD_ENV
#include <pthread.h>
static pthread_once_t dirInit_once = PTHREAD_ONCE_INIT;
#endif
+
#ifdef AFS_NT40_ENV
-#include <windows.h>
#include <WINNT\afssw.h>
#endif
-#ifdef AFS_DARWIN_ENV
-#include <unistd.h>
-#endif
/* local vars */
/* static storage for path strings */
/* Additional macros for ease of use */
/* buf is expected to be atleast AFS_PATH_MAX bytes long */
#define AFSDIR_SERVER_DIRPATH(buf, dir) \
- (void) strcompose(buf, AFSDIR_PATH_MAX, serverPrefix, dir, NULL)
+ (void) strcompose(buf, AFSDIR_PATH_MAX, serverPrefix, dir, (char *)NULL)
#define AFSDIR_SERVER_FILEPATH(buf, dir, file) \
- (void) strcompose(buf, AFSDIR_PATH_MAX, serverPrefix, dir, "/", file, NULL)
+ (void) strcompose(buf, AFSDIR_PATH_MAX, serverPrefix, dir, "/", file, (char *)NULL)
#define AFSDIR_CLIENT_DIRPATH(buf, dir) \
- (void) strcompose(buf, AFSDIR_PATH_MAX, clientPrefix, dir, NULL)
+ (void) strcompose(buf, AFSDIR_PATH_MAX, clientPrefix, dir, (char *)NULL)
#define AFSDIR_CLIENT_FILEPATH(buf, dir, file) \
- (void) strcompose(buf, AFSDIR_PATH_MAX, clientPrefix, dir, "/", file, NULL)
+ (void) strcompose(buf, AFSDIR_PATH_MAX, clientPrefix, dir, "/", file, (char *)NULL)
/* initAFSDirPath() -- External users call this function to initialize
}
-/* initDirPathArray() -- Initializes the afs dir paths for the
+/* initDirPathArray() -- Initializes the afs dir paths for the
* server and client installations.
*
* For NT these are determined dynamically; for Unix they are static.
static void
initDirPathArray(void)
{
- char *pathp;
+ char *pathp, *clntEtcDir;
const char *clientPrefix = "";
const char *serverPrefix = "";
FilepathNormalize(ntServerInstallDirShort);
/* get the afs client configuration directory (/usr/vice/etc equivalent) */
- if (afssw_GetClientInstallDir(&buf)) {
+ if (afssw_GetClientCellServDBDir(&buf)) {
/* failed */
status = GetWindowsDirectory(ntClientConfigDirLong, AFSDIR_PATH_MAX);
if (status == 0 || status > AFSDIR_PATH_MAX) {
"/NoUsrViceDirectoryOnWindows");
strcpy(dirPathArray[AFSDIR_CLIENT_ETC_DIRPATH_ID],
ntClientConfigDirShort);
+
+ clntEtcDir = pathp = dirPathArray[AFSDIR_CLIENT_ETC_DIRPATH_ID];
#else
strcpy(dirPathArray[AFSDIR_CLIENT_VICE_DIRPATH_ID], afsClntDirPath);
- pathp = dirPathArray[AFSDIR_CLIENT_ETC_DIRPATH_ID];
+ clntEtcDir = 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);
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,
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_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_AUDIT_FILEPATH_ID];
AFSDIR_SERVER_FILEPATH(pathp, AFSDIR_LOCAL_DIR, AFSDIR_AUDIT_FILE);
+ pathp = dirPathArray[AFSDIR_SERVER_CONFIG_FILE_FILEPATH_ID];
+ AFSDIR_CLIENT_FILEPATH(pathp, AFSDIR_SERVER_ETC_DIR,
+ AFSDIR_SERVER_CONFIG_FILE);
+
pathp = dirPathArray[AFSDIR_SERVER_NETINFO_FILEPATH_ID];
AFSDIR_SERVER_FILEPATH(pathp, AFSDIR_LOCAL_DIR, AFSDIR_NETINFO_FILE);
pathp = dirPathArray[AFSDIR_SERVER_MIGRATELOG_FILEPATH_ID];
AFSDIR_SERVER_FILEPATH(pathp, AFSDIR_MIGR_DIR, AFSDIR_MIGRATE_LOGNAME);
+ 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_RXKAD_KEYTAB_FILEPATH_ID];
+ AFSDIR_SERVER_FILEPATH(pathp, AFSDIR_SERVER_ETC_DIR, AFSDIR_RXKAD_KEYTAB_FILE);
/* client file paths */
#ifdef AFS_NT40_ENV
"/NoCellAliasOnWindows");
#else
pathp = dirPathArray[AFSDIR_CLIENT_THISCELL_FILEPATH_ID];
- AFSDIR_CLIENT_FILEPATH(pathp, AFSDIR_CLIENT_ETC_DIR,
- AFSDIR_THISCELL_FILE);
+ AFSDIR_CLIENT_FILEPATH(pathp, clntEtcDir, AFSDIR_THISCELL_FILE);
pathp = dirPathArray[AFSDIR_CLIENT_CELLSERVDB_FILEPATH_ID];
- AFSDIR_CLIENT_FILEPATH(pathp, AFSDIR_CLIENT_ETC_DIR,
- AFSDIR_CELLSERVDB_FILE);
+ AFSDIR_CLIENT_FILEPATH(pathp, clntEtcDir, AFSDIR_CELLSERVDB_FILE);
pathp = dirPathArray[AFSDIR_CLIENT_CELLALIAS_FILEPATH_ID];
- AFSDIR_CLIENT_FILEPATH(pathp, AFSDIR_CLIENT_ETC_DIR,
- AFSDIR_CELLALIAS_FILE);
+ AFSDIR_CLIENT_FILEPATH(pathp, clntEtcDir, AFSDIR_CELLALIAS_FILE);
#endif /* AFS_NT40_ENV */
+ pathp = dirPathArray[AFSDIR_CLIENT_CONFIG_FILE_FILEPATH_ID];
+ AFSDIR_CLIENT_FILEPATH(pathp, clntEtcDir, AFSDIR_CLIENT_CONFIG_FILE);
+
pathp = dirPathArray[AFSDIR_CLIENT_NETINFO_FILEPATH_ID];
- AFSDIR_CLIENT_FILEPATH(pathp, AFSDIR_CLIENT_ETC_DIR, AFSDIR_NETINFO_FILE);
+ AFSDIR_CLIENT_FILEPATH(pathp, clntEtcDir, AFSDIR_NETINFO_FILE);
pathp = dirPathArray[AFSDIR_CLIENT_NETRESTRICT_FILEPATH_ID];
- AFSDIR_CLIENT_FILEPATH(pathp, AFSDIR_CLIENT_ETC_DIR,
- AFSDIR_NETRESTRICT_FILE);
+ AFSDIR_CLIENT_FILEPATH(pathp, clntEtcDir, AFSDIR_NETRESTRICT_FILE);
initFlag = 1; /* finished dirpath initialization */
return;
}
-/* getDirPath - returns a const char pointer to the requested string
+/* afs_getDirPath - returns a const char pointer to the requested string
* from the internal path array.
- * string_id - index into the path array
+ * string_id - index into the path array
*/
const char *
-getDirPath(afsdir_id_t string_id)
+afs_getDirPath(afsdir_id_t string_id)
{
/* check if the array has been initialized */
if (initFlag == 0) { /* no it's not, so initialize */
return (const char *)dirPathArray[string_id];
}
+#ifdef AFS_NT40_ENV
+/* getDirPath - present for ABI compatibility on Windows systems;
+ * Unix systems should not use it. */
+const char *
+getDirPath(afsdir_id_t string_id)
+{
+ return afs_getDirPath(string_id);
+}
+#endif
+
/*
* LocalizePathHead() -- Make path relative to local part
*
- * ConstructLocalPath takes a path and a directory that path should
- * be considered relative to. This function checks the given path
- * for a prefix that represents a canonical path. If such a prefix
- * is found, the path is adjusted to remove the prefix and the path
- * is considered relative to the local version of that path.
+ * ConstructLocalPath takes a path and a directory that path should
+ * be considered relative to. There are two possible cases:
+ *
+ * The path is an absolute path. In this case, the relative path
+ * is ignored. We check the path for a prefix that represents a
+ * canonical path, and if one is found, we adjust the path to remove
+ * the prefix and adjust the directory to which it should be
+ * considered relative to be the local version of that canonical path.
+ *
+ * The path is a relative path. In this case, we check to see if the
+ * directory to which it is relative represents a canonical path, and
+ * if so, we adjust that directory to be the local version of that
+ * canonical path. The relative path itself is left unchanged.
*/
/* The following array maps cannonical parts to local parts. It
* might seem reasonable to simply construct an array in parallel to
* dirpatharray but it turns out you don't want translations for all
- local paths.
+ * local paths.
*/
struct canonmapping {
static void
LocalizePathHead(const char **path, const char **relativeTo)
{
- struct canonmapping *current;
- for (current = CanonicalTranslations; current->local != NULL; current++) {
- int canonlength = strlen(current->canonical);
- if (strncmp(*path, current->canonical, canonlength) == 0) {
- (*path) += canonlength;
- if (**path == '/')
- (*path)++;
- *relativeTo = current->local;
- return;
- }
- }
+ struct canonmapping *map;
+
+ if (**path == '/') {
+ for (map = CanonicalTranslations; map->local != NULL; map++) {
+ int canonlength = strlen(map->canonical);
+ if (strncmp(*path, map->canonical, canonlength) == 0) {
+ (*path) += canonlength;
+ if (**path == '/')
+ (*path)++;
+ *relativeTo = map->local;
+ return;
+ }
+ }
+ } else {
+ for (map = CanonicalTranslations; map->local != NULL; map++) {
+ if (strcmp(*relativeTo, map->canonical) == 0) {
+ *relativeTo = map->local;
+ return;
+ }
+ }
+ }
}
status = EINVAL;
} else {
/* fully qualified path; just make a copy */
- newPath = (char *)malloc(strlen(cpath) + 1);
- if (!newPath) {
+ newPath = strdup(cpath);
+ if (!newPath)
status = ENOMEM;
- } else {
- (void)strcpy(newPath, cpath);
- }
}
} else {
/* construct path relative to install directory only */
pathSize += strlen(cpath);
- newPath = (char *)malloc(pathSize);
+ newPath = malloc(pathSize);
if (!newPath) {
status = ENOMEM;
} else {
/* construct path relative to 'relativeTo' (and install dir) */
pathSize += strlen(relativeTo) + 1 + strlen(cpath);
- newPath = (char *)malloc(pathSize);
+ newPath = malloc(pathSize);
if (!newPath) {
status = ENOMEM;
} else {
LocalizePathHead(&cpath, &relativeTo);
if (*cpath == '/') {
- newPath = (char *)malloc(strlen(cpath) + 1);
- if (!newPath) {
- status = ENOMEM;
- } else {
- strcpy(newPath, cpath);
- }
+ newPath = strdup(cpath);
} else {
- newPath = (char *)malloc(strlen(relativeTo) + 1 + strlen(cpath) + 1);
- if (!newPath) {
- status = ENOMEM;
- } else {
- sprintf(newPath, "%s/%s", relativeTo, cpath);
- }
+ if (asprintf(&newPath, "%s/%s", relativeTo, cpath) < 0)
+ newPath = NULL;
}
+ if (newPath == NULL)
+ status = ENOMEM;
if (status == 0) {
FilepathNormalize(newPath);