windows-refactor-cm_config-20080201
authorJeffrey Altman <jaltman@secure-endpoints.com>
Fri, 1 Feb 2008 21:42:17 +0000 (21:42 +0000)
committerJeffrey Altman <jaltman@secure-endpoints.com>
Fri, 1 Feb 2008 21:42:17 +0000 (21:42 +0000)
LICENSE MIT

cm_config.c was a nightmare.  there were several functions that each
computed the location of the OpenAFS Client configuration directory
in a slightly different way.  Now there is a single exported function
that determines the directory, and another that determines the name
of the CellServDB file.  All of the other functons in cm_config.c and
throughout the src/WINNT/afsd directory now use those two functions.

The new rule for determining the location of the OpenAFS Client
configuration directory and hence the CellServDB file location is:

1. check the AFSCONF environment variable
2. check the HKLM\SOFTWARE\OpenAFS\Client   CellServDBDir registry value
3. use AFSDIR_CLIENT_ETC_DIRPATH which currently refers to
   \Program Files\OpenAFS\Client

src/WINNT/afsd/afsd_init.c
src/WINNT/afsd/afskfw.c
src/WINNT/afsd/afskfw.h
src/WINNT/afsd/cm_cell.c
src/WINNT/afsd/cm_config.c
src/WINNT/afsd/cm_config.h
src/WINNT/afsd/cm_freelance.c
src/WINNT/afsd/fs.c
src/WINNT/afsd/libafsconf.def

index 735bc3d..b5d85ac 100644 (file)
@@ -1268,7 +1268,7 @@ int afsd_InitCM(char **reasonP)
               code, cm_freelanceEnabled, (code ? "<none>" : rootCellName));
     if (code != 0 && !cm_freelanceEnabled) 
     {
-        *reasonP = "can't find root cell name in CellServDB";
+        *reasonP = "can't find root cell name in " AFS_CELLSERVDB;
         return -1;
     }   
     else if (cm_freelanceEnabled)
@@ -1280,7 +1280,7 @@ int afsd_InitCM(char **reasonP)
         afsi_log("cm_GetCell addr %x", PtrToUlong(cm_data.rootCellp));
         if (cm_data.rootCellp == NULL) 
         {
-            *reasonP = "can't find root cell in afsdcell.ini";
+            *reasonP = "can't find root cell in " AFS_CELLSERVDB;
             return -1;
         }
     }
index 160d928..69bd459 100644 (file)
@@ -2624,7 +2624,7 @@ ViceIDToUsername(char *username,
                  struct ktc_token *atoken)
 {
     static char lastcell[MAXCELLCHARS+1] = { 0 };
-    static char confname[512] = { 0 };
+    static char confdir[512] = { 0 };
 #ifdef AFS_ID_TO_NAME
     char username_copy[BUFSIZ];
 #endif /* AFS_ID_TO_NAME */
@@ -2634,14 +2634,12 @@ ViceIDToUsername(char *username,
     afs_int32 id;
 #endif /* ALLOW_REGISTER */
 
-    if (confname[0] == '\0') {
-        strncpy(confname, AFSDIR_CLIENT_ETC_DIRPATH, sizeof(confname));
-        confname[sizeof(confname) - 2] = '\0';
-    }
+    if (confdir[0] == '\0')
+        cm_GetConfigDir(confdir, sizeof(confdir));
 
     strcpy(lastcell, aserver->cell);
 
-    if (!pr_Initialize (0, confname, aserver->cell)) {
+    if (!pr_Initialize (0, confdir, aserver->cell)) {
         char sname[PR_MAXNAMELEN];
         strncpy(sname, username, PR_MAXNAMELEN);
         sname[PR_MAXNAMELEN-1] = '\0';    
@@ -2684,7 +2682,7 @@ ViceIDToUsername(char *username,
             strncpy(aclient->cell, realm_of_user, MAXKTCREALMLEN - 1);
             if (status = ktc_SetToken(aserver, atoken, aclient, 0))
                 return status;
-            if (status = pr_Initialize(1L, confname, aserver->cell))
+            if (status = pr_Initialize(1L, confdir, aserver->cell))
                 return status;
             status = pr_CreateUser(username, &id);
            pr_End();
index d774924..1c46bcd 100644 (file)
@@ -37,6 +37,7 @@ extern "C" {
 #include <afs/stds.h>
 #include <afs/auth.h>
 #include <afs/cellconfig.h>
+#include <cm_config.h>
 #include <rxkad.h>
 
 #define MAXCELLCHARS   64
index 19820d3..6552d32 100644 (file)
@@ -127,7 +127,7 @@ static cm_cell_t *cm_UpdateCell(cm_cell_t * cp, afs_uint32 flags)
     return code ? NULL : cp;
 }
 
-/* load up a cell structure from the cell database, afsdcell.ini */
+/* load up a cell structure from the cell database, AFS_CELLSERVDB */
 cm_cell_t *cm_GetCell(char *namep, afs_uint32 flags)
 {
     return cm_GetCell_Gen(namep, NULL, flags);
index e009db7..de7de24 100644 (file)
 #include <afs/afsint.h>
 #endif
 
-
-
-/* TODO: these should be pulled in from dirpath.h */
-#define AFS_THISCELL "ThisCell"
-#define AFS_CELLSERVDB_UNIX "CellServDB"
-#define AFS_CELLSERVDB_NT "afsdcell.ini"
-#ifndef AFSDIR_CLIENT_ETC_DIRPATH
-#define AFSDIR_CLIENT_ETC_DIRPATH "c:/afs"
-#endif
-#define AFS_CELLSERVDB AFS_CELLSERVDB_UNIX
-
 static long cm_ParsePair(char *lineBufferp, char *leftp, char *rightp)
 {
     char *tp;
@@ -141,11 +130,10 @@ long cm_SearchCellFile(char *cellNamep, char *newCellNamep,
     if ( IsWindowsModule(cellNamep) )
        return -3;
 
-    cm_GetCellServDB(wdir);
+    cm_GetCellServDB(wdir, sizeof(wdir));
     tfilep = fopen(wdir, "r");
 
-    /* If we are NT or higher, we don't do DJGPP, So just fail */
-    if ( !tfilep )
+    if (!tfilep) 
         return -2;
 
     bestp = fopen(wdir, "r");
@@ -334,69 +322,54 @@ long cm_SearchCellByDNS(char *cellNamep, char *newCellNamep, int *ttl,
  * or use the Client Dirpath value to produce a CellServDB 
  * filename
  */
-long cm_GetCellServDB(char *cellNamep)
+long cm_GetCellServDB(char *cellNamep, afs_uint32 len)
 {
-       DWORD code, dummyLen;
-       HKEY parmKey;
     int tlen;
-
-       code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_OPENAFS_SUBKEY,
-                               0, KEY_QUERY_VALUE, &parmKey);
-       if (code != ERROR_SUCCESS)
-        goto dirpath;
-
-       dummyLen = 256;
-       code = RegQueryValueEx(parmKey, "CellServDBDir", NULL, NULL,
-                               cellNamep, &dummyLen);
-       RegCloseKey (parmKey);
-
-  dirpath:
-       if (code != ERROR_SUCCESS || cellNamep[0] == 0)
-        strcpy(cellNamep, AFSDIR_CLIENT_ETC_DIRPATH);
+    
+    cm_GetConfigDir(cellNamep, len);
 
     /* add trailing backslash, if required */
     tlen = (int)strlen(cellNamep);
-    if (cellNamep[tlen-1] != '\\') 
-        strcat(cellNamep, "\\");
+    if (cellNamep[tlen-1] != '\\') {
+        strncat(cellNamep, "\\", len);
+        cellNamep[len-1] = '\0';
+    }
         
-    strcat(cellNamep, AFS_CELLSERVDB);
-       return 0;
+    strncat(cellNamep, AFS_CELLSERVDB, len);
+    cellNamep[len-1] = '\0';
+    return 0;
 }
 
 /* look up the root cell's name in the Registry */
 long cm_GetRootCellName(char *cellNamep)
 {
-       DWORD code, dummyLen;
-       HKEY parmKey;
+    DWORD code, dummyLen;
+    HKEY parmKey;
 
-       code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY,
-                               0, KEY_QUERY_VALUE, &parmKey);
-       if (code != ERROR_SUCCESS)
-               return -1;
+    code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY,
+                        0, KEY_QUERY_VALUE, &parmKey);
+    if (code != ERROR_SUCCESS)
+        return -1;
 
-       dummyLen = 256;
-       code = RegQueryValueEx(parmKey, "Cell", NULL, NULL,
+    dummyLen = 256;
+    code = RegQueryValueEx(parmKey, "Cell", NULL, NULL,
                                cellNamep, &dummyLen);
-       RegCloseKey (parmKey);
-       if (code != ERROR_SUCCESS || cellNamep[0] == 0)
-               return -1;
+    RegCloseKey (parmKey);
+    if (code != ERROR_SUCCESS || cellNamep[0] == 0)
+        return -1;
 
-       return 0;
+    return 0;
 }
 
 cm_configFile_t *cm_CommonOpen(char *namep, char *rwp)
 {
     char wdir[256];
-    long tlen;
     FILE *tfilep;
 
-    strcpy(wdir, AFSDIR_CLIENT_ETC_DIRPATH);
-        
-    /* add trailing backslash, if required */
-    tlen = (long)(strlen(wdir));
-    if (wdir[tlen-1] != '\\') strcat(wdir, "\\");
+    cm_GetConfigDir(wdir, sizeof(wdir));
 
-    strcat(wdir, namep);
+    strncat(wdir, namep, sizeof(wdir));
+    wdir[sizeof(wdir)-1] = '\0';
         
     tfilep = fopen(wdir, rwp);
 
@@ -425,140 +398,138 @@ long cm_WriteConfigString(char *labelp, char *valuep)
 
 long cm_WriteConfigInt(char *labelp, long value)
 {
-       DWORD code, dummyDisp;
-       HKEY parmKey;
-
-       code = RegCreateKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY,
-                               0, "container", 0, KEY_SET_VALUE, NULL,
-                               &parmKey, &dummyDisp);
-       if (code != ERROR_SUCCESS)
-               return -1;
-
-       code = RegSetValueEx(parmKey, labelp, 0, REG_DWORD,
-                            (LPBYTE)&value, sizeof(value));
-       RegCloseKey (parmKey);
-       if (code != ERROR_SUCCESS)
-               return -1;
-
-       return 0;
+    DWORD code, dummyDisp;
+    HKEY parmKey;
+
+    code = RegCreateKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY,
+                           0, "container", 0, KEY_SET_VALUE, NULL,
+                           &parmKey, &dummyDisp);
+    if (code != ERROR_SUCCESS)
+        return -1;
+
+    code = RegSetValueEx(parmKey, labelp, 0, REG_DWORD,
+                          (LPBYTE)&value, sizeof(value));
+    RegCloseKey (parmKey);
+    if (code != ERROR_SUCCESS)
+        return -1;
+
+    return 0;
 }
 
 cm_configFile_t *cm_OpenCellFile(void)
 {
-        cm_configFile_t *cfp;
+    cm_configFile_t *cfp;
 
-       cfp = cm_CommonOpen("afsdcel2.ini", "w");
-       return cfp;
+    cfp = cm_CommonOpen(AFS_CELLSERVDB ".new", "w");
+    return cfp;
 }
 
 long cm_AppendPrunedCellList(cm_configFile_t *ofp, char *cellNamep)
 {
-       cm_configFile_t *tfilep;        /* input file */
-        char *tp;
-        char lineBuffer[256];
-        char *valuep;
-        int inRightCell;
-        int foundCell;
-
-        tfilep = cm_CommonOpen(AFS_CELLSERVDB, "r");
-        if (!tfilep) return -1;
-
-       foundCell = 0;
-
-       /* have we seen the cell line for the guy we're looking for? */
-       inRightCell = 0;
-       while (1) {
-               tp = fgets(lineBuffer, sizeof(lineBuffer), (FILE *)tfilep);
-                if (tp == NULL) {
-                       if (feof((FILE *)tfilep)) {
-                               /* hit EOF */
-                               fclose((FILE *)tfilep);
-                               return 0;
-                       }
-                }
-                
-                /* turn trailing cr or lf into null */
-                tp = strchr(lineBuffer, '\r');
-                if (tp) *tp = 0;
-                tp = strchr(lineBuffer, '\n');
-                if (tp) *tp = 0;
+    cm_configFile_t *tfilep;   /* input file */
+    char *tp;
+    char lineBuffer[256];
+    char *valuep;
+    int inRightCell;
+    int foundCell;
+
+    tfilep = cm_CommonOpen(AFS_CELLSERVDB, "r");
+    if (!tfilep) 
+        return -1;
+
+    foundCell = 0;
+
+    /* have we seen the cell line for the guy we're looking for? */
+    inRightCell = 0;
+    while (1) {
+        tp = fgets(lineBuffer, sizeof(lineBuffer), (FILE *)tfilep);
+        if (tp == NULL) {
+            if (feof((FILE *)tfilep)) {
+                /* hit EOF */
+                fclose((FILE *)tfilep);
+                return 0;
+            }
+        }
+
+        /* turn trailing cr or lf into null */
+        tp = strchr(lineBuffer, '\r');
+        if (tp) *tp = 0;
+        tp = strchr(lineBuffer, '\n');
+        if (tp) *tp = 0;
                 
-               /* skip blank lines */
-                if (lineBuffer[0] == 0) {
-                       fprintf((FILE *)ofp, "%s\n", lineBuffer);
-                       continue;
-               }
+        /* skip blank lines */
+        if (lineBuffer[0] == 0) {
+            fprintf((FILE *)ofp, "%s\n", lineBuffer);
+            continue;
+        }
 
-                if (lineBuffer[0] == '>') {
-                       /* trim off at white space or '#' chars */
-                        tp = strchr(lineBuffer, ' ');
-                        if (tp) *tp = 0;
-                        tp = strchr(lineBuffer, '\t');
-                        if (tp) *tp = 0;
-                        tp = strchr(lineBuffer, '#');
-                        if (tp) *tp = 0;
-
-                       /* now see if this is the right cell */
-                       if (strcmp(lineBuffer+1, cellNamep) == 0) {
-                               /* found the cell we're looking for */
-                               inRightCell = 1;
-                       }
-                        else {
-                               inRightCell = 0;
-                                fprintf((FILE *)ofp, "%s\n", lineBuffer);
-                       }
-                }
-                else {
-                       valuep = strchr(lineBuffer, '#');
-                       if (valuep == NULL) return -2;
-                        valuep++;      /* skip the "#" */
-                       if (!inRightCell) {
-                                fprintf((FILE *)ofp, "%s\n", lineBuffer);
-                        }
-                }      /* a vldb line */
-        }              /* while loop processing all lines */
-}
+        if (lineBuffer[0] == '>') {
+            /* trim off at white space or '#' chars */
+            tp = strchr(lineBuffer, ' ');
+            if (tp) *tp = 0;
+            tp = strchr(lineBuffer, '\t');
+            if (tp) *tp = 0;
+            tp = strchr(lineBuffer, '#');
+            if (tp) *tp = 0;
+
+            /* now see if this is the right cell */
+            if (strcmp(lineBuffer+1, cellNamep) == 0) {
+                /* found the cell we're looking for */
+                inRightCell = 1;
+            }
+            else {
+                inRightCell = 0;
+                fprintf((FILE *)ofp, "%s\n", lineBuffer);
+            }
+        }
+        else {
+            valuep = strchr(lineBuffer, '#');
+            if (valuep == NULL) return -2;
+            valuep++;  /* skip the "#" */
+            if (!inRightCell) {
+                fprintf((FILE *)ofp, "%s\n", lineBuffer);
+            }
+        }      /* a vldb line */
+    }          /* while loop processing all lines */
+}       
 
 long cm_AppendNewCell(cm_configFile_t *filep, char *cellNamep)
 {
-       fprintf((FILE *)filep, ">%s\n", cellNamep);
-        return 0;
+    fprintf((FILE *)filep, ">%s\n", cellNamep);
+    return 0;
 }
 
 long cm_AppendNewCellLine(cm_configFile_t *filep, char *linep)
 {
-       fprintf((FILE *)filep, "%s\n", linep);
-        return 0;
+    fprintf((FILE *)filep, "%s\n", linep);
+    return 0;
 }
 
 long cm_CloseCellFile(cm_configFile_t *filep)
 {
-    char wdir[256];
-    char sdir[256];
+    char wdir[260];
+    char sdir[260];
     long code;
     long closeCode;
-    int tlen;
     closeCode = fclose((FILE *)filep);
 
-    strcpy(wdir, AFSDIR_CLIENT_ETC_DIRPATH);
-        
-       /* add trailing backslash, if required */
-    tlen = (int)strlen(wdir);
-    if (wdir[tlen-1] != '\\') strcat(wdir, "\\");
-
+    cm_GetConfigDir(wdir, sizeof(wdir));
     strcpy(sdir, wdir);
 
-       if (closeCode != 0) {
-               /* something went wrong, preserve original database */
-        strcat(wdir, "afsdcel2.ini");
+    if (closeCode != 0) {
+        /* something went wrong, preserve original database */
+        strncat(wdir, AFS_CELLSERVDB ".new", sizeof(wdir));
+        wdir[sizeof(wdir)-1] = '\0';
         unlink(wdir);
         return closeCode;
     }
 
-    strcat(wdir, AFS_CELLSERVDB);
-    strcat(sdir, "afsdcel2.ini");      /* new file */
+    strncat(wdir, AFS_CELLSERVDB, sizeof(wdir));
+    wdir[sizeof(wdir)-1] = '\0';
+    strncat(sdir, AFS_CELLSERVDB ".new", sizeof(sdir));/* new file */
+    sdir[sizeof(sdir)-1] = '\0';
 
-    unlink(wdir);                      /* delete old file */
+    unlink(sdir);                      /* delete old file */
 
     code = rename(sdir, wdir); /* do the rename */
 
@@ -568,19 +539,48 @@ long cm_CloseCellFile(cm_configFile_t *filep)
     return code;
 }   
 
-void cm_GetConfigDir(char *dir)
+void cm_GetConfigDir(char *dir, afs_uint32 len)
 {
-       char wdir[256];
+    char wdir[512];
     int tlen;
-#ifdef AFS_WIN95_ENV
     char *afsconf_path;
     DWORD dwSize;
-#endif
 
-    strcpy(wdir, AFSDIR_CLIENT_ETC_DIRPATH);
-        
-       /* add trailing backslash, if required */
+    dwSize = GetEnvironmentVariable("AFSCONF", NULL, 0);
+    afsconf_path = malloc(dwSize);
+    dwSize = GetEnvironmentVariable("AFSCONF", afsconf_path, dwSize);
+    if (!afsconf_path) {
+        DWORD code, dummyLen;
+        HKEY parmKey;
+
+        code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_OPENAFS_SUBKEY,
+                             0, KEY_QUERY_VALUE, &parmKey);
+        if (code != ERROR_SUCCESS)
+            goto dirpath;
+
+        dummyLen = sizeof(wdir);
+        code = RegQueryValueEx(parmKey, "CellServDBDir", NULL, NULL,
+                               wdir, &dummyLen);
+        RegCloseKey (parmKey);
+
+      dirpath:
+        if (code != ERROR_SUCCESS || wdir[0] == 0) {
+            strncpy(wdir, AFSDIR_CLIENT_ETC_DIRPATH, sizeof(wdir));
+            wdir[sizeof(wdir)-1] = '\0';
+        }
+    } else {
+        strncpy(wdir, afsconf_path, sizeof(wdir));
+        wdir[sizeof(wdir)-1] = '\0';
+        free(afsconf_path);
+    }
+
+    /* add trailing backslash, if required */
     tlen = (int)strlen(wdir);
-    if (wdir[tlen-1] != '\\') strcat(wdir, "\\");
-    strcpy(dir, wdir);
+    if (wdir[tlen-1] != '\\') {
+        strncat(wdir, "\\", sizeof(wdir));
+        wdir[sizeof(wdir)-1] = '\0';
+    }
+
+    strncpy(dir, wdir, len);
+    dir[len-1] ='\0';
 }
index 1a75b41..d1b0017 100644 (file)
@@ -48,9 +48,14 @@ extern long cm_AppendNewCellLine(cm_configFile_t *filep, char *linep);
 
 extern long cm_CloseCellFile(cm_configFile_t *filep);
 
-extern long cm_GetCellServDB(char *cellNamep);
+extern long cm_GetCellServDB(char *cellNamep, afs_uint32 len);
 
-extern void cm_GetConfigDir(char *dir);
+extern void cm_GetConfigDir(char *dir, afs_uint32 len);
+
+/* TODO: these should be pulled in from dirpath.h */
+#define AFS_THISCELL "ThisCell"
+#define AFS_CELLSERVDB_UNIX "CellServDB"
+#define AFS_CELLSERVDB AFS_CELLSERVDB_UNIX
 
 #endif /* __CM_CONFIG_INTERFACES_ONLY__ */
 
index 068eb87..78e7dcc 100644 (file)
@@ -463,7 +463,7 @@ long cm_InitLocalMountPoints() {
     char line[512];
     char*t, *t2;
     cm_localMountPoint_t* aLocalMountPoint;
-    char hdir[120];
+    char hdir[260];
     long code;
     char rootCellName[256];
     HKEY hkFreelance = 0, hkFreelanceSymlinks = 0;
@@ -668,7 +668,7 @@ long cm_InitLocalMountPoints() {
     /* What follows is the old code to read freelance mount points 
      * out of a text file modified to copy the data into the registry
      */
-    cm_GetConfigDir(hdir);
+    cm_GetConfigDir(hdir, sizeof(hdir));
     strcat(hdir, AFS_FREELANCE_INI);
     // open the ini file for reading
     fp = fopen(hdir, "r");
@@ -957,7 +957,7 @@ long cm_FreelanceSymlinkExists(char * filename, int prefix_ok)
 long cm_FreelanceAddMount(char *filename, char *cellname, char *volume, int rw, cm_fid_t *fidp)
 {
     FILE *fp;
-    char hfile[120];
+    char hfile[260];
     char line[512];
     char fullname[200];
     int n;
@@ -1052,7 +1052,7 @@ long cm_FreelanceAddMount(char *filename, char *cellname, char *volume, int rw,
         RegCloseKey(hkFreelance);
     } else 
     {
-        cm_GetConfigDir(hfile);
+        cm_GetConfigDir(hfile, sizeof(hfile));
         strcat(hfile, AFS_FREELANCE_INI);
         fp = fopen(hfile, "r+");
         if (!fp)
@@ -1086,7 +1086,7 @@ long cm_FreelanceRemoveMount(char *toremove)
     char* cp;
     char line[512];
     char shortname[200];
-    char hfile[120], hfile2[120];
+    char hfile[260], hfile2[260];
     FILE *fp1, *fp2;
     int found=0;
     HKEY hkFreelance = 0;
@@ -1137,7 +1137,7 @@ long cm_FreelanceRemoveMount(char *toremove)
         RegCloseKey(hkFreelance);
     } else 
     {
-        cm_GetConfigDir(hfile);
+        cm_GetConfigDir(hfile, sizeof(hfile));
         strcat(hfile, AFS_FREELANCE_INI);
         strcpy(hfile2, hfile);
         strcat(hfile2, "2");
index 22438f3..87896d8 100644 (file)
@@ -1112,6 +1112,7 @@ BadName(char *aname, char *fname)
     afs_int32 tc, code, id;
     char *nm;
     char cell[MAXCELLCHARS];
+    char confDir[257];
 
     for ( nm = aname; tc = *nm; nm++) {
        /* all must be '-' or digit to be bad */
@@ -1124,7 +1125,9 @@ BadName(char *aname, char *fname)
     if (code)
         return 0;
 
-    pr_Initialize(1, AFSDIR_CLIENT_ETC_DIRPATH, cell);
+    cm_GetConfigDir(confDir, sizeof(confDir));
+
+    pr_Initialize(1, confDir, cell);
     code = pr_SNameToId(aname, &id);
     pr_End();
 
@@ -1569,9 +1572,12 @@ ExamineCmd(struct cmd_syndesc *as, void *arock)
         blob.out = (char *) &owner;
        if (0 == pioctl(ti->data, VIOCGETOWNER, &blob, 1)) {
            char oname[PR_MAXNAMELEN] = "(unknown)";
+            char confDir[257];
 
            /* Go to the PRDB and see if this all number username is valid */
-           pr_Initialize(1, AFSDIR_CLIENT_ETC_DIRPATH, cell);
+            cm_GetConfigDir(confDir, sizeof(confDir));
+
+            pr_Initialize(1, confDir, cell);
            pr_SIdToName(owner[0], oname);
            printf("Owner %s (%u) Group %u\n", oname, owner[0], owner[1]);
         }
@@ -3095,45 +3101,22 @@ static int SetCellCmd(struct cmd_syndesc *as, void *arock)
     return error;
 }
 
-#ifdef WIN32
 static int
 GetCellName(char *cellNamep, struct afsconf_cell *infop)
 {
     strcpy(infop->name, cellNamep);
     return 0;
 }
-#else
-static int
-GetCellName(char *cellName, struct afsconf_cell *info)
-{
-    struct afsconf_dir *tdir;
-    int code;
-
-    tdir = afsconf_Open(AFSDIR_CLIENT_ETC_CLIENTNAME);
-    if (!tdir) {
-       fprintf(stderr,
-                "Could not process files in configuration directory (%s).\n",
-                 AFSDIR_CLIENT_ETC_CLIENTNAME);
-       return -1;
-    }
-
-    code = afsconf_GetCellInfo(tdir, cellName, AFSCONF_VLDBSERVICE, info);
-    if (code) {
-       fprintf(stderr,"fs: cell %s not in %s/CellServDB\n", cellName, 
-                AFSDIR_CLIENT_ETC_CLIENTNAME);
-       return code;
-    }
-
-    return 0;
-}
-#endif /* not WIN32 */
 
 static int
 VLDBInit(int noAuthFlag, struct afsconf_cell *info)
 {
     afs_int32 code;
+    char confDir[257];
+
+    cm_GetConfigDir(confDir, sizeof(confDir));
 
-    code = ugen_ClientInit(noAuthFlag, (char *)AFSDIR_CLIENT_ETC_DIRPATH, 
+    code = ugen_ClientInit(noAuthFlag, confDir, 
                           info->name, 0, &uclient, 
                            NULL, pn, rxkad_clear,
                            VLDB_MAXSERVERS, AFSCONF_VLDBSERVICE, 50,
index d43a2df..75590c9 100644 (file)
@@ -23,4 +23,4 @@ EXPORTS
         cm_GetConfigDir                 @16
         afs_uuid_create                 @17
         afs_uuid_equal                  @18
-  
\ No newline at end of file
+        cm_GetCellServDB                @19