no-more-ini-files-20040713
[openafs.git] / src / WINNT / afsd / cm_ioctl.c
index c2b0c7c..b001ade 100644 (file)
@@ -1079,7 +1079,6 @@ long cm_IoctlNewCell(struct smb_ioctl *ioctlp, struct cm_user *userp)
     */  
   
     cm_cell_t *cp;
-    cm_cell_t *tcp;
   
     cm_SkipIoctlPath(ioctlp);
     lock_ObtainWrite(&cm_cellLock);
@@ -1137,30 +1136,94 @@ long cm_IoctlGetWsCell(smb_ioctl_t *ioctlp, cm_user_t *userp)
 
 long cm_IoctlSysName(struct smb_ioctl *ioctlp, struct cm_user *userp)
 {
-       long setSysName;
-        char *cp;
+       long setSysName, foundname = 0;
+    char *cp, *cp2, inname[MAXSYSNAME], outname[MAXSYSNAME];
+    int t, count, num = 0;
+    char **sysnamelist[MAXSYSNAME];
         
        cm_SkipIoctlPath(ioctlp);
 
-        memcpy(&setSysName, ioctlp->inDatap, sizeof(long));
-        ioctlp->inDatap += sizeof(long);
+    memcpy(&setSysName, ioctlp->inDatap, sizeof(long));
+    ioctlp->inDatap += sizeof(long);
         
-        if (setSysName) {
-               strcpy(cm_sysName, ioctlp->inDatap);
+    if (setSysName) {
+        /* check my args */
+        if ( setSysName < 0 || setSysName > MAXNUMSYSNAMES )
+            return EINVAL;
+        cp2 = ioctlp->inDatap;
+        for ( cp=ioctlp->inDatap, count = 0; count < setSysName; count++ ) {
+            /* won't go past end of ioctlp->inDatap since maxsysname*num < ioctlp->inDatap length */
+            t = strlen(cp);
+            if (t >= MAXSYSNAME || t <= 0)
+                return EINVAL;
+            /* check for names that can shoot us in the foot */
+            if (*cp == '.' && (cp[1] == 0 || (cp[1] == '.' && cp[2] == 0)))
+                return EINVAL;
+            cp += t + 1;
         }
-        else {
+        /* args ok */
+
+        /* inname gets first entry in case we're being a translator */
+        /* (we are never a translator) */
+        t = strlen(ioctlp->inDatap);
+        memcpy(inname, ioctlp->inDatap, t + 1);
+        ioctlp->inDatap += t + 1;
+        num = count;
+    }
+
+    /* Not xlating, so local case */
+    if (!cm_sysName)
+        osi_panic("cm_IoctlSysName: !cm_sysName\n", __FILE__, __LINE__);
+
+    if (!setSysName) {      /* user just wants the info */
+        strcpy(outname, cm_sysName);
+        foundname = cm_sysNameCount;
+        *sysnamelist = cm_sysNameList;
+    } else {                /* Local guy; only root can change sysname */
+        /* clear @sys entries from the dnlc, once afs_lookup can
+         * do lookups of @sys entries and thinks it can trust them */
+        /* privs ok, store the entry, ... */
+        strcpy(cm_sysName, inname);
+        if (setSysName > 1) {       /* ... or list */
+            cp = ioctlp->inDatap;
+            for (count = 1; count < setSysName; ++count) {
+                if (!cm_sysNameList[count])
+                    osi_panic
+                        ("cm_IoctlSysName: no cm_sysNameList entry to write\n"
+                          , __FILE__, __LINE__);
+                t = strlen(cp);
+                memcpy(cm_sysNameList[count], cp, t + 1);  /* include null */
+                cp += t + 1;
+            }
+        }
+        cm_sysNameCount = setSysName;
+    }
+
+    if (!setSysName) {
                /* return the sysname to the caller */
-                setSysName = 1;        /* really means "found sys name */
                cp = ioctlp->outDatap;
-                memcpy(cp, &setSysName, sizeof(long));
-                cp += sizeof(long);    /* skip found flag */
-                strcpy(cp, cm_sysName);
-                cp += strlen(cp) + 1;  /* skip name and terminating null char */
-                ioctlp->outDatap = cp;
+        memcpy(cp, (char *)&foundname, sizeof(afs_int32));
+        cp += sizeof(afs_int32);       /* skip found flag */
+        if (foundname) {
+            strcpy(cp, outname);
+            cp += strlen(outname) + 1; /* skip name and terminating null char */
+            for ( count=1; count < foundname ; ++count) {   /* ... or list */
+                if ( !(*sysnamelist)[count] )
+                    osi_panic("cm_IoctlSysName: no cm_sysNameList entry to read\n"
+                               , __FILE__, __LINE__);
+                t = strlen((*sysnamelist)[count]);
+                if (t >= MAXSYSNAME)
+                    osi_panic("cm_IoctlSysName: sysname entry garbled\n"
+                               , __FILE__, __LINE__);
+                strcpy(cp, (*sysnamelist)[count]);
+                cp += t + 1;
+            }
         }
+        ioctlp->outDatap = cp;
+    }
         
        /* done: success */
-        return 0;
+    return 0;
 }
 
 long cm_IoctlGetCellStatus(struct smb_ioctl *ioctlp, struct cm_user *userp)
@@ -1372,7 +1435,8 @@ long cm_IoctlCreateMountPoint(struct smb_ioctl *ioctlp, struct cm_user *userp)
          /* we are adding the mount point to the root dir., so call
             the freelance code to do the add. */
          osi_Log0(afsd_logp,"IoctlCreateMountPoint within Freelance root dir");
-         code = cm_FreelanceAddMount(leaf, fullCell, volume, NULL);
+         code = cm_FreelanceAddMount(leaf, fullCell, volume, 
+                                  *ioctlp->inDatap == '%', NULL);
          return code;
        }
 #endif
@@ -1918,10 +1982,12 @@ long cm_IoctlMakeSubmount(smb_ioctl_t *ioctlp, cm_user_t *userp)
        char afspath[MAX_PATH];
        char *submountreqp;
        int iteration;
-       int submountDataSize;
-       char *submountData;
-       char *submountName;
        int nextAutoSubmount;
+    HKEY hkSubmounts;
+    DWORD dwType, dwSize;
+    DWORD status;
+    DWORD dwIndex;
+    DWORD dwSubmounts;
 
        cm_SkipIoctlPath(ioctlp);
 
@@ -1940,33 +2006,45 @@ long cm_IoctlMakeSubmount(smb_ioctl_t *ioctlp, cm_user_t *userp)
         * that submount name is in use... if so, the submount's path
         * has to match our path.
         */
-       if (submountreqp && *submountreqp) {
+
+    RegCreateKeyEx( HKEY_LOCAL_MACHINE, 
+                    "SOFTWARE\\OpenAFS\\Client\\Submounts",
+                    0, 
+                    "AFS", 
+                    REG_OPTION_NON_VOLATILE,
+                    KEY_READ|KEY_WRITE|KEY_QUERY_VALUE,
+                    NULL, 
+                    &hkSubmounts,
+                    NULL );
+
+    if (submountreqp && *submountreqp) {
                char submountPathNormalized[MAX_PATH];
                char submountPath[MAX_PATH];
                int submountPathLen;
 
-               submountPathLen = GetPrivateProfileString("AFS Submounts",
-                                       submountreqp, "", submountPath,
-                                       sizeof(submountPath), "afsdsbmt.ini");
+        dwSize = sizeof(submountPath);
+        status = RegQueryValueEx( hkSubmounts, submountreqp, 0,
+                         &dwType, submountPath, &dwSize);
 
-               if ((submountPathLen == 0) ||
-                   (submountPathLen == sizeof(submountPath) - 1)) {
+               if (status != ERROR_SUCCESS) {
 
                        /* The suggested submount name isn't in use now--
                         * so we can safely map the requested submount name
                         * to the supplied path. Remember not to write the
                         * leading "/afs" when writing out the submount.
                         */
-                       WritePrivateProfileString("AFS Submounts",
-                                       submountreqp, 
-                                       (strlen(&afspath[strlen(cm_mountRoot)])) ?
-                                                 &afspath[strlen(cm_mountRoot)]:"/",
-                                       "afsdsbmt.ini");
-
+            RegSetValueEx( hkSubmounts, submountreqp, 0,
+                           REG_SZ, 
+                           (strlen(&afspath[strlen(cm_mountRoot)])) ?
+                           &afspath[strlen(cm_mountRoot)]:"/",
+                           (strlen(&afspath[strlen(cm_mountRoot)])) ?
+                           strlen(&afspath[strlen(cm_mountRoot)])+1:2);
+
+            RegCloseKey( hkSubmounts );
                        strcpy(ioctlp->outDatap, submountreqp);
                        ioctlp->outDatap += strlen(ioctlp->outDatap) +1;
                        lock_ReleaseMutex(&cm_Afsdsbmt_Lock);
-                       return 0;
+            return 0;
                }
 
                /* The suggested submount name is already in use--if the
@@ -1977,35 +2055,26 @@ long cm_IoctlMakeSubmount(smb_ioctl_t *ioctlp, cm_user_t *userp)
                if (!strcmp (submountPathNormalized, afspath)) {
                        strcpy(ioctlp->outDatap, submountreqp);
                        ioctlp->outDatap += strlen(ioctlp->outDatap) +1;
+            RegCloseKey( hkSubmounts );
                        lock_ReleaseMutex(&cm_Afsdsbmt_Lock);
-                       return 0;
+            return 0;
                }
        }
 
-       /* At this point, the user either didn't request a particular
-        * submount name, or that submount name couldn't be used.
-        * Look through afsdsbmt.ini to see if there are any submounts
-        * already associated with the specified path. The first
-        * step in doing that search is to load the AFS Submounts
-        * section of afsdsbmt.ini into memory.
-        */
-
-       submountDataSize = 1024;
-       submountData = malloc (submountDataSize);
+    RegQueryInfoKey( hkSubmounts,
+                 NULL,  /* lpClass */
+                 NULL,  /* lpcClass */
+                 NULL,  /* lpReserved */
+                 NULL,  /* lpcSubKeys */
+                 NULL,  /* lpcMaxSubKeyLen */
+                 NULL,  /* lpcMaxClassLen */
+                 &dwSubmounts, /* lpcValues */
+                 NULL,  /* lpcMaxValueNameLen */
+                 NULL,  /* lpcMaxValueLen */
+                 NULL,  /* lpcbSecurityDescriptor */
+                 NULL   /* lpftLastWriteTime */
+                 );
 
-       for (iteration = 0; iteration < 5; ++iteration) {
-
-               int sectionSize;
-               sectionSize = GetPrivateProfileString("AFS Submounts",
-                                       NULL, "", submountData,
-                                       submountDataSize, "afsdsbmt.ini");
-               if (sectionSize < submountDataSize-2)
-                       break;
-
-               free (submountData);
-               submountDataSize *= 2;
-               submountData = malloc (submountDataSize);
-       }
 
        /* Having obtained a list of all available submounts, start
         * searching that list for a path which matches the requested
@@ -2015,13 +2084,15 @@ long cm_IoctlMakeSubmount(smb_ioctl_t *ioctlp, cm_user_t *userp)
 
        nextAutoSubmount = 1;
 
-       for (submountName = submountData;
-               submountName && *submountName;
-               submountName += 1+strlen(submountName)) {
-
+    for ( dwIndex = 0; dwIndex < dwSubmounts; dwIndex ++ ) {
                char submountPathNormalized[MAX_PATH];
                char submountPath[MAX_PATH] = "";
-               int submountPathLen;
+               DWORD submountPathLen = sizeof(submountPath);
+        char submountName[256];
+        DWORD submountNameLen = sizeof(submountName);
+
+        RegEnumValue( hkSubmounts, dwIndex, submountName, &submountNameLen, NULL,
+              &dwType, submountPath, &submountPathLen);
 
                /* If this is an Auto### submount, remember its ### value */
 
@@ -2033,14 +2104,6 @@ long cm_IoctlMakeSubmount(smb_ioctl_t *ioctlp, cm_user_t *userp)
                                                thisAutoSubmount+1);
                }
 
-               /* We have the name of a submount in the AFS Submounts
-                * section; read that entry to find out what path it
-                * maps to.
-                */
-               submountPathLen = GetPrivateProfileString("AFS Submounts",
-                                       submountName, "", submountPath,
-                                       sizeof(submountPath), "afsdsbmt.ini");
-
                if ((submountPathLen == 0) ||
                    (submountPathLen == sizeof(submountPath) - 1)) {
                        continue;
@@ -2052,18 +2115,15 @@ long cm_IoctlMakeSubmount(smb_ioctl_t *ioctlp, cm_user_t *userp)
                 */
                cm_NormalizeAfsPath (submountPathNormalized, submountPath);
                if (!strcmp (submountPathNormalized, afspath)) {
-
                        strcpy(ioctlp->outDatap, submountName);
                        ioctlp->outDatap += strlen(ioctlp->outDatap) +1;
-                       free (submountData);
+            RegCloseKey(hkSubmounts);
                        lock_ReleaseMutex(&cm_Afsdsbmt_Lock);
-                       return 0;
+            return 0;
 
                }
        }
 
-       free (submountData);
-
        /* We've been through the entire list of existing submounts, and
         * didn't find any which matched the specified path. So, we'll
         * just have to add one. Remember not to write the leading "/afs"
@@ -2072,12 +2132,17 @@ long cm_IoctlMakeSubmount(smb_ioctl_t *ioctlp, cm_user_t *userp)
 
        sprintf(ioctlp->outDatap, "auto%ld", nextAutoSubmount);
 
-       WritePrivateProfileString("AFS Submounts", ioctlp->outDatap,
-                                 (strlen(&afspath[lstrlen(cm_mountRoot)])) ? 
-                                 &afspath[lstrlen(cm_mountRoot)]:"/",
-                                 "afsdsbmt.ini");
+    RegSetValueEx( hkSubmounts, 
+                   ioctlp->outDatap,
+                   0,
+                   REG_SZ, 
+                   (strlen(&afspath[strlen(cm_mountRoot)])) ?
+                   &afspath[strlen(cm_mountRoot)]:"/",
+                   (strlen(&afspath[strlen(cm_mountRoot)])) ?
+                   strlen(&afspath[strlen(cm_mountRoot)])+1:2);
 
        ioctlp->outDatap += strlen(ioctlp->outDatap) +1;
+    RegCloseKey(hkSubmounts);
        lock_ReleaseMutex(&cm_Afsdsbmt_Lock);
        return 0;
 }