rx: Remove RX_CALL_BUSY
[openafs.git] / src / WINNT / afsreg / afssw.c
index c6aa2fe..0fcbc77 100644 (file)
@@ -1,20 +1,20 @@
 /*
  * 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>
 #include <afs/stds.h>
 
+#include <roken.h>
+
 #include <windows.h>
-#include <stdlib.h>
-#include <stddef.h>
-#include <string.h>
-#include <errno.h>
+#include <shlobj.h>
 
 #include <afs/errmap_nt.h>
 
@@ -77,9 +77,74 @@ afssw_GetClientInstallDir(char **bufPP)   /* [out] data buffer */
 int
 afssw_GetClientCellServDBDir(char **bufPP)   /* [out] data buffer */
 {
-    return StringDataRead(AFSREG_CLT_OPENAFS_KEY,
+    char wdir[512];
+    int tlen;
+    char *path = NULL;
+    DWORD cbPath;
+
+    cbPath = GetEnvironmentVariable("AFSCONF", NULL, 0);
+    if (cbPath) {
+        cbPath += 2;
+        path = malloc(cbPath);
+        if (path) {
+            GetEnvironmentVariable("AFSCONF", path, cbPath);
+            tlen = (int)strlen(path);
+            if (path[tlen-1] != '\\') {
+                strncat(path, "\\", cbPath);
+                path[cbPath-1] = '\0';
+            }
+            *bufPP = path;
+            return 0;
+        }
+    }
+
+    if (!StringDataRead(AFSREG_CLT_OPENAFS_KEY,
                          AFSREG_CLT_OPENAFS_CELLSERVDB_DIR_VALUE,
-                         bufPP);
+                         &path)) {
+        tlen = (int)strlen(path);
+        if (path[tlen-1] != '\\') {
+            char * newPath = malloc(tlen+2);
+            if (newPath) {
+                _snprintf(newPath,tlen+2,"%s\\",path);
+                free(path);
+                path = newPath;
+            }
+        }
+        *bufPP = path;
+        return 0;
+    }
+
+    /*
+     * Try to find the All Users\Application Data\OpenAFS\Client directory.
+     * If it exists and it contains a CellServDB file, return that.
+     * Otherwise, return the Install Directory for backward compatibility.
+     * SHGetFolderPath requires wdir to be of length MAX_PATH which is 260.
+     */
+    if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_COMMON_APPDATA, NULL,
+                                    SHGFP_TYPE_CURRENT, wdir)))
+    {   HANDLE fh;
+
+        tlen = (int)strlen(wdir);
+        if (wdir[tlen-1] != '\\') {
+            strncat(wdir, "\\", sizeof(wdir));
+            wdir[sizeof(wdir)-1] = '\0';
+            tlen++;
+        }
+        strncat(wdir, "OpenAFS\\Client\\CellServDB", sizeof(wdir));
+        wdir[sizeof(wdir)-1] = '\0';
+
+        fh = CreateFile(wdir, GENERIC_READ, FILE_SHARE_READ, NULL,
+                        OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
+        if (fh != INVALID_HANDLE_VALUE) {
+            CloseHandle(fh);
+            tlen += (int)strlen("OpenAFS\\Client\\");
+            wdir[tlen] = '\0';
+            *bufPP = strdup(wdir);
+            return 0;
+        }
+    }
+
+    return afssw_GetClientInstallDir(bufPP);
 }
 
 
@@ -234,7 +299,7 @@ StringDataRead(const char *keyName, const char *valueName, char **bufPP)
 
 /*
  * StringDataWrite() -- write registry data of type REG_SZ.
- * 
+ *
  * RETURN CODES: 0 success, -1 failed (errno set)
  */
 static int