windows-nls-includes-20080626
[openafs.git] / src / WINNT / client_config / drivemap.cpp
index 9716c4a..5485950 100644 (file)
@@ -6,6 +6,33 @@
  * License.  For details, see the LICENSE file in the top-level source
  * directory or online at http://www.openafs.org/dl/license10.html
  */
+/* AFSIFS portions copyright (c) 2005
+ * the regents of the university of michigan
+ * all rights reserved
+ * 
+ * permission is granted to use, copy, create derivative works and
+ * redistribute this software and such derivative works for any purpose,
+ * so long as no fee is charged, and so long as the copyright notice
+ * above, this grant of permission, and the disclaimer below appear
+ * in all copies made; and so long as the name of the university of
+ * michigan is not used in any advertising or publicity pertaining
+ * to the use or distribution of this software without specific, written
+ * prior authorization.
+ * 
+ * this software is provided as is, without representation from the
+ * university of michigan as to its fitness for any purpose, and without
+ * warranty by the university of michigan of any kind, either express
+ * or implied, including without limitation the implied warranties of
+ * merchantability and fitness for a particular purpose.  the regents
+ * of the university of michigan shall not be liable for nay damages,
+ * including special, indirect, incidental, or consequential damages,
+ * with respect to ant claim arising out of or in connection with the
+ * use of the software, even if it has been or is hereafter advised
+ * of the possibility of such damages.
+ */
+
+#include <winsock2.h>
+#include <ws2tcpip.h>
 
 extern "C" {
 #include <afs/param.h>
@@ -17,6 +44,7 @@ extern "C" {
 #include <stdlib.h>
 #include <stdio.h>
 #include <WINNT/TaLocale.h>
+#include <WINNT/afsreg.h>
 #undef REALLOC
 #include "drivemap.h"
 #include <time.h>
@@ -35,9 +63,6 @@ extern void Config_GetLanAdapter (ULONG *pnLanAdapter);
  *
  */
 
-#undef AFSConfigKeyName
-const TCHAR sAFSConfigKeyName[] = TEXT("SYSTEM\\CurrentControlSet\\Services\\TransarcAFSDaemon\\Parameters");
-
 
 /*
  * PROFILE SECTIONS ___________________________________________________________
@@ -46,9 +71,9 @@ const TCHAR sAFSConfigKeyName[] = TEXT("SYSTEM\\CurrentControlSet\\Services\\Tra
 
 #define cREALLOC_SUBMOUNTS   4
 
-static TCHAR cszSECTION_SUBMOUNTS[] = TEXT("SOFTWARE\\OpenAFS\\Client\\Submounts");
-static TCHAR cszSECTION_MAPPINGS[] = TEXT("SOFTWARE\\OpenAFS\\Client\\Mappings");
-static TCHAR cszSECTION_ACTIVE[] = TEXT("SOFTWARE\\OpenAFS\\Client\\Active Maps");
+static TCHAR cszSECTION_SUBMOUNTS[] = TEXT(AFSREG_CLT_OPENAFS_SUBKEY "\\Submounts");
+static TCHAR cszSECTION_MAPPINGS[]  = TEXT(AFSREG_CLT_OPENAFS_SUBKEY "\\Mappings");
+static TCHAR cszSECTION_ACTIVE[]    = TEXT(AFSREG_CLT_OPENAFS_SUBKEY "\\Active Maps");
 
 static TCHAR cszAUTOSUBMOUNT[] = TEXT("Auto");
 static TCHAR cszLANMANDEVICE[] = TEXT("\\Device\\LanmanRedirector\\");
@@ -141,7 +166,7 @@ DeleteRegistryString(HKEY key, TCHAR * subkey, LPTSTR lhs)
                     0,
                     NULL,
                     REG_OPTION_NON_VOLATILE,
-                    KEY_READ,
+                    KEY_WRITE,
                     NULL,
                     &hkSub,
                     NULL);
@@ -171,6 +196,7 @@ static void FreeStringMemory (LPTSTR pszString)
    Free (pszString);
 }
 
+#if 0
 static int lstrncmpi (LPCTSTR pszA, LPCTSTR pszB, size_t cch)
 {
    if (!pszA || !pszB)
@@ -192,7 +218,7 @@ static int lstrncmpi (LPCTSTR pszA, LPCTSTR pszB, size_t cch)
 
    return 0;  // no differences before told to stop comparing, so A==B
 }
-
+#endif
 
 /*
  * REALLOC ____________________________________________________________________
@@ -316,18 +342,27 @@ BOOL SubmountToPath (PDRIVEMAPLIST pList, LPTSTR pszPath, LPTSTR pszSubmount, BO
 
    // Otherwise, look up our list of submounts.
    //
-   for (size_t ii = 0; ii < pList->cSubmounts; ++ii)
-      {
-      if (!lstrcmpi (pList->aSubmounts[ii].szSubmount, pszSubmount))
-         {
-         if (fMarkInUse)
-            pList->aSubmounts[ii].fInUse = TRUE;
-         AdjustAfsPath (pszPath, pList->aSubmounts[ii].szMapping, TRUE, TRUE);
-         return TRUE;
-         }
-      }
+#ifdef AFSIFS
+    AdjustAfsPath (pszPath, pszSubmount, TRUE, TRUE);
+#endif
+    for (size_t ii = 0; ii < pList->cSubmounts; ++ii)
+    {
+        BOOL b;
+#ifndef AFSIFS
+        b = !lstrcmpi (pList->aSubmounts[ii].szSubmount, pszSubmount);
+#else
+        b = !lstrcmpi (pList->aSubmounts[ii].szMapping, pszPath);
+#endif
+        if (b)
+        {
+            if (fMarkInUse)
+                pList->aSubmounts[ii].fInUse = TRUE;
+            AdjustAfsPath (pszPath, pList->aSubmounts[ii].szMapping, TRUE, TRUE);
+            return TRUE;
+        }
+    }
 
-   return FALSE;
+    return FALSE;
 }
 
 
@@ -368,6 +403,7 @@ extern "C" {
 #define __CM_CONFIG_INTERFACES_ONLY__
 #include "../afsd/cm_config.h"
 
+#include "../afsd/cm_nls.h"
 #define __CM_IOCTL_INTERFACES_ONLY__
 #include "../afsd/cm_ioctl.h"
 
@@ -467,7 +503,8 @@ void QueryDriveMapList_ReadSubmounts (PDRIVEMAPLIST pList)
             if ( submountPath[0] != TEXT('\0') ) {
                 AdjustAfsPath (Submount.szMapping, submountPath, FALSE, TRUE);
 
-                for (size_t ii = 0; ii < pList->cSubmounts; ++ii)
+                size_t ii;
+                for (ii = 0; ii < pList->cSubmounts; ++ii)
                 {
                     if (!pList->aSubmounts[ii].szSubmount[0])
                         break;
@@ -523,7 +560,7 @@ void QueryDriveMapList_ReadMappings (PDRIVEMAPLIST pList)
                       &dwType, (LPBYTE)mapping, &mappingLen);
         if ( dwType == REG_EXPAND_SZ ) {
             TCHAR buf[MAX_PATH];
-            DWORD dummyLen = ExpandEnvironmentStrings(buf, mapping, MAX_PATH);
+            DWORD dummyLen = ExpandEnvironmentStrings(mapping, buf, MAX_PATH);
             if (dummyLen > MAX_PATH)
                 continue;
             _tcsncpy(mapping, buf, MAX_PATH);
@@ -648,7 +685,7 @@ BOOL DriveIsGlobalAfsDrive(TCHAR chDrive)
    TCHAR szValue[128];
    HKEY hKey;
 
-   _stprintf(szKeyName, TEXT("%s\\GlobalAutoMapper"), sAFSConfigKeyName);
+   _stprintf(szKeyName, TEXT("%s\\GlobalAutoMapper"), AFSREG_CLT_SVC_PARAM_SUBKEY);
 
    if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, szKeyName, 0, KEY_QUERY_VALUE, &hKey) != ERROR_SUCCESS)
       return FALSE;
@@ -817,13 +854,18 @@ BOOL ActivateDriveMap (TCHAR chDrive, LPTSTR pszMapping, LPTSTR pszSubmountReq,
       }
 
    // We now have a submount name and drive letter--map the network drive.
-   DWORD rc=MountDOSDrive(chDrive,szSubmount,fPersistent,NULL);
-   if (rc == NO_ERROR)
-      return TRUE;
+    DWORD rc;
+#ifndef AFSIFS
+    rc=MountDOSDrive(chDrive,szSubmount,fPersistent,NULL);
+#else
+    rc=MountDOSDrive(chDrive,/*szSubmount*/pszMapping,fPersistent,NULL);
+#endif
+    if (rc == NO_ERROR)
+        return TRUE;
 
-   if (pdwStatus)
-      *pdwStatus = rc;
-   return FALSE;
+    if (pdwStatus)
+        *pdwStatus = rc;
+    return FALSE;
 }
 
 
@@ -933,16 +975,33 @@ BOOL GetDriveSubmount (TCHAR chDrive, LPTSTR pszSubmountNow)
       //           <AuthID>: Authentication ID, 16 char hex.
       //           <netbiosname>: Netbios name of server
       //
-      if (_tcsnicmp(szMapping, cszLANMANDEVICE, _tcslen(cszLANMANDEVICE)))
+      BOOL b;
+#ifndef AFSIFS
+      b = _tcsnicmp(szMapping, cszLANMANDEVICE, _tcslen(cszLANMANDEVICE));
+#else
+      const TCHAR ker_sub_path[] = "\\Device\\afsrdr\\";
+      b = _tcsnicmp(szMapping, ker_sub_path, _tcslen(ker_sub_path));
+#endif
+       if (b)
          return FALSE;
+#ifndef AFSIFS
       pszSubmount = &szMapping[ _tcslen(cszLANMANDEVICE) ];
+#else
+      pszSubmount = &szMapping[ _tcslen(ker_sub_path) ];
+#endif
 
+#ifdef AFSIFS
+       if (*(pszSubmount) < '0' ||
+            *(pszSubmount) > '9')
+           return FALSE;
+       ++pszSubmount;
+#else   
       if (IsWindows2000())
-         {
+      {
           if (*(pszSubmount) != TEXT(';'))
              return FALSE;
-         } else 
-               --pszSubmount;
+      } else 
+          --pszSubmount;
 
       if (toupper(*(++pszSubmount)) != chDrive)
          return FALSE;
@@ -972,6 +1031,7 @@ BOOL GetDriveSubmount (TCHAR chDrive, LPTSTR pszSubmountNow)
          return FALSE;
 
        pszSubmount += _tcslen(szNetBiosName);
+#endif
       }
    else // (!IsWindowsNT())
       {
@@ -993,7 +1053,12 @@ BOOL GetDriveSubmount (TCHAR chDrive, LPTSTR pszSubmountNow)
    if (!pszSubmount || !*pszSubmount)
       return FALSE;
 
+#ifndef AFSIFS
    lstrcpy (pszSubmountNow, pszSubmount);
+#else
+   lstrcpy (pszSubmountNow, "\\afs");
+   lstrcat (pszSubmountNow, pszSubmount);
+#endif
    return TRUE;
 }
 
@@ -1001,67 +1066,67 @@ BOOL GetDriveSubmount (TCHAR chDrive, LPTSTR pszSubmountNow)
 DWORD dwOldState=0;
 TCHAR pUserName[MAXRANDOMNAMELEN]=TEXT("");
 BOOL fUserName=FALSE;
-#define AFSLogonOptionName TEXT("System\\CurrentControlSet\\Services\\TransarcAFSDaemon\\NetworkProvider")
+#define AFSLogonOptionName TEXT(AFSREG_CLT_SVC_PROVIDER_SUBKEY)
 
 void SetBitLogonOption(BOOL set,DWORD value)
 {
 
-   RWLogonOption(FALSE,((set)?value | RWLogonOption(TRUE,0):RWLogonOption(TRUE,0) & ~value) ); 
+    RWLogonOption(FALSE,((set)?value | RWLogonOption(TRUE,0):RWLogonOption(TRUE,0) & ~value) );        
 }
 
 DWORD RWLogonOption(BOOL read,DWORD value)
 {
-       // if read is true then if value==0 return registry value
-       // if read and value!=0 then use value to test registry, return TRUE if value bits match value read
-   HKEY hk;
-   DWORD dwDisp;
-       DWORD LSPtype, LSPsize;
-       DWORD rval;
-   if (read)
-   {
-          rval=0;
-               if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSLogonOptionName, 0, KEY_QUERY_VALUE, &hk)==ERROR_SUCCESS)
-               {
-                       LSPsize=sizeof(rval);
-                       RegQueryValueEx(hk, "LogonOptions", NULL,
-                                               &LSPtype, (LPBYTE)&rval, &LSPsize);
-                       RegCloseKey (hk);
-               }
-               return (value==0)?rval:((rval & value)==value);
-
-   } else {    //write
-               if (RegCreateKeyEx (HKEY_LOCAL_MACHINE, AFSLogonOptionName, 0, NULL, 0, KEY_SET_VALUE, NULL, &hk, &dwDisp) == ERROR_SUCCESS)
-               {
-                       RegSetValueEx(hk,TEXT("LogonOptions"),NULL,REG_DWORD,(LPBYTE)&value,sizeof(value));
-                       RegCloseKey (hk);
-               }
-               return TRUE;
-   }
+    // if read is true then if value==0 return registry value
+    // if read and value!=0 then use value to test registry, return TRUE if value bits match value read
+    HKEY hk;
+    DWORD dwDisp;
+    DWORD LSPtype, LSPsize;
+    DWORD rval;
+   
+    if (read)
+    {
+        rval=0;
+        if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSLogonOptionName, 0, KEY_QUERY_VALUE, &hk)==ERROR_SUCCESS)
+        {
+            LSPsize=sizeof(rval);
+            RegQueryValueEx(hk, "LogonOptions", NULL,
+                             &LSPtype, (LPBYTE)&rval, &LSPsize);
+            RegCloseKey (hk);
+        }
+        return (value==0)?rval:((rval & value)==value);
+    } else {   //write
+        if (RegCreateKeyEx (HKEY_LOCAL_MACHINE, AFSLogonOptionName, 0, NULL, 0, KEY_SET_VALUE, NULL, &hk, &dwDisp) == ERROR_SUCCESS)
+        {
+            RegSetValueEx(hk,TEXT("LogonOptions"),NULL,REG_DWORD,(LPBYTE)&value,sizeof(value));
+            RegCloseKey (hk);
+        }
+        return TRUE;
+    }    
 }
 
 void MapShareName(char *pszCmdLineA)
 {
-       fUserName = TRUE;
-       TCHAR *p=pUserName;
-       pszCmdLineA++;
-       while (*pszCmdLineA && (*pszCmdLineA != ' '))
-       {
-         *p++=*pszCmdLineA++;
-       }
+    fUserName = TRUE;
+    TCHAR *p=pUserName;
+    pszCmdLineA++;
+    while (*pszCmdLineA && (*pszCmdLineA != ' '))
+    {
+       *p++=*pszCmdLineA++;
+    }
 }
 
 void GenRandomName(TCHAR *pname,int len)
 {
-       if (fUserName)
-       {               //user name was passed through command line, use once
-               fUserName=FALSE;
-               return;
-       }
-       srand( (unsigned)time( NULL ) );
-       for (int i=0;i<len;i++)
-               pname[i]='a'+(rand() % 26);
-       pname[len]=0;
+    if (fUserName)
+    {          //user name was passed through command line, use once
+       fUserName=FALSE;
        return;
+    }
+    srand( (unsigned)time( NULL ) );
+    for (int i=0;i<len;i++)
+       pname[i]='a'+(rand() % 26);
+    pname[len]=0;
+    return;
 }
 
 /*
@@ -1072,14 +1137,14 @@ void GenRandomName(TCHAR *pname,int len)
 BOOL TestAndDoMapShare(DWORD dwState)
 {
     if ((dwState!=SERVICE_RUNNING) || (dwOldState!=SERVICE_START_PENDING))
-       {
-               dwOldState=dwState;
-               return TRUE;
-       }
-       dwOldState=SERVICE_RUNNING;
-       if (RWLogonOption(TRUE,LOGON_OPTION_HIGHSECURITY))
-           return (DoMapShare() && GlobalMountDrive());
-       return GlobalMountDrive();
+    {
+       dwOldState=dwState;
+       return TRUE;
+    }
+    dwOldState=SERVICE_RUNNING;
+    if (RWLogonOption(TRUE,LOGON_OPTION_HIGHSECURITY))
+       return (DoMapShare() && GlobalMountDrive());
+    return GlobalMountDrive();
 }
 
 BOOL IsServiceActive()
@@ -1103,120 +1168,119 @@ BOOL IsServiceActive()
 
 void TestAndDoUnMapShare()
 {
-       if (!RWLogonOption(TRUE,LOGON_OPTION_HIGHSECURITY))
-               return;
-       DoUnMapShare(FALSE);    
+    if (!RWLogonOption(TRUE,LOGON_OPTION_HIGHSECURITY))
+       return;
+    DoUnMapShare(FALSE);       
 }
 
 void DoUnMapShare(BOOL drivemap)       //disconnect drivemap 
 {
-       TCHAR szMachine[MAX_PATH],szPath[MAX_PATH];
-       DWORD rc=28;
-       HANDLE hEnum;
-       LPNETRESOURCE lpnrLocal,lpnr=NULL;
-       DWORD res;
-       DWORD cbBuffer=16384;
-       DWORD cEntries=-1;
-       CHAR *pSubmount="";
+    TCHAR szMachine[MAX_PATH],szPath[MAX_PATH];
+    DWORD rc=28;
+    HANDLE hEnum;
+    LPNETRESOURCE lpnrLocal,lpnr=NULL;
+    DWORD res;
+    DWORD cbBuffer=16384;
+    DWORD cEntries=-1;
+    CHAR *pSubmount="";
 
     memset(szMachine, '\0', sizeof(szMachine));
     GetClientNetbiosName(szMachine);
 
    // Initialize the data structure
-       if ((res=WNetOpenEnum(RESOURCE_CONNECTED,RESOURCETYPE_DISK,RESOURCEUSAGE_CONNECTABLE,lpnr,&hEnum))!=NO_ERROR)
-               return;
-       sprintf(szPath,"\\\\%s\\",szMachine);
-       _strlwr(szPath);
-       lpnrLocal=(LPNETRESOURCE) GlobalAlloc(GPTR,cbBuffer);
-       do {
-               memset(lpnrLocal,0,cbBuffer);
-               if ((res = WNetEnumResource(hEnum,&cEntries,lpnrLocal,&cbBuffer))==NO_ERROR)
+    if ((res=WNetOpenEnum(RESOURCE_CONNECTED,RESOURCETYPE_DISK,RESOURCEUSAGE_CONNECTABLE,lpnr,&hEnum))!=NO_ERROR)
+       return;
+    sprintf(szPath,"\\\\%s\\",szMachine);
+    _strlwr(szPath);
+    lpnrLocal=(LPNETRESOURCE) GlobalAlloc(GPTR,cbBuffer);
+    do {
+       memset(lpnrLocal,0,cbBuffer);
+       if ((res = WNetEnumResource(hEnum,&cEntries,lpnrLocal,&cbBuffer))==NO_ERROR)
+       {
+           for (DWORD i=0;i<cEntries;i++)
+           {
+               if (strstr(_strlwr(lpnrLocal[i].lpRemoteName),szPath))
                {
-                       for (DWORD i=0;i<cEntries;i++)
-                       {
-                               if (strstr(_strlwr(lpnrLocal[i].lpRemoteName),szPath))
-                               {
-                                       if ((lpnrLocal[i].lpLocalName) && (strlen(lpnrLocal[i].lpLocalName)>0))
-                                       {
-                                               if (drivemap) {
-                                                   DisMountDOSDrive(*lpnrLocal[i].lpLocalName);
+                   if ((lpnrLocal[i].lpLocalName) && (strlen(lpnrLocal[i].lpLocalName)>0))
+                   {
+                       if (drivemap) {
+                           DisMountDOSDrive(*lpnrLocal[i].lpLocalName);
                             DEBUG_EVENT1("AFS DriveUnMap","UnMap-Local=%x",res);
-                        }
-                                       } else {
-                                           DisMountDOSDriveFull(lpnrLocal[i].lpRemoteName);
+                        }              
+                   } else {
+                       DisMountDOSDriveFull(lpnrLocal[i].lpRemoteName);
                         DEBUG_EVENT1("AFS DriveUnMap","UnMap-Remote=%x",res);
                     }
-                               }
-                       }
                }
-       } while (res!=ERROR_NO_MORE_ITEMS);
-       GlobalFree((HGLOBAL)lpnrLocal);
-       WNetCloseEnum(hEnum);
+           }
+       }
+    } while (res!=ERROR_NO_MORE_ITEMS);
+    GlobalFree((HGLOBAL)lpnrLocal);
+    WNetCloseEnum(hEnum);
 }
 
-BOOL DoMapShareChange()
+BOOL DoMapShareChange(BOOL removeUnknown)
 {
-       DRIVEMAPLIST List;
-       TCHAR szMachine[ MAX_PATH],szPath[MAX_PATH];
-       DWORD rc=28;
-       HANDLE hEnum;
-       LPNETRESOURCE lpnrLocal,lpnr=NULL;
-       DWORD res;
-       DWORD cEntries=-1;
+    DRIVEMAPLIST List;
+    TCHAR szMachine[ MAX_PATH],szPath[MAX_PATH];
+    DWORD rc=28;
+    HANDLE hEnum;
+    LPNETRESOURCE lpnrLocal,lpnr=NULL;
+    DWORD res;
+    DWORD cEntries=-1;
     DWORD cbBuffer=16384;
 
     memset(szMachine, '\0', sizeof(szMachine));
     GetClientNetbiosName(szMachine);
 
     // Initialize the data structure
-       if (!IsServiceActive())
-               return TRUE;
-       memset (&List, 0x00, sizeof(DRIVEMAPLIST));
-       for (size_t ii = 0; ii < 26; ++ii)
-               List.aDriveMap[ii].chDrive = chDRIVE_A + ii;
-       QueryDriveMapList_ReadSubmounts (&List);
-       if ((res=WNetOpenEnum(RESOURCE_CONNECTED,RESOURCETYPE_DISK,RESOURCEUSAGE_CONNECTABLE,lpnr,&hEnum))!=NO_ERROR)
-               return FALSE;
-       lpnrLocal=(LPNETRESOURCE) GlobalAlloc(GPTR,cbBuffer);
-       sprintf(szPath,"\\\\%s\\",szMachine);
-       _strlwr(szPath);
-       do {
-               memset(lpnrLocal,0,cbBuffer);
-               if ((res = WNetEnumResource(hEnum,&cEntries,lpnrLocal,&cbBuffer))==NO_ERROR)
+    if (!IsServiceActive())
+       return TRUE;
+    memset (&List, 0x00, sizeof(DRIVEMAPLIST));
+    for (size_t ii = 0; ii < 26; ++ii)
+       List.aDriveMap[ii].chDrive = chDRIVE_A + ii;
+    QueryDriveMapList_ReadSubmounts (&List);
+    if ((res=WNetOpenEnum(RESOURCE_CONNECTED,RESOURCETYPE_DISK,RESOURCEUSAGE_CONNECTABLE,lpnr,&hEnum))!=NO_ERROR)
+       return FALSE;
+    lpnrLocal=(LPNETRESOURCE) GlobalAlloc(GPTR,cbBuffer);
+    sprintf(szPath,"\\\\%s\\",szMachine);
+    _strlwr(szPath);
+    do {
+       memset(lpnrLocal,0,cbBuffer);
+       if ((res = WNetEnumResource(hEnum,&cEntries,lpnrLocal,&cbBuffer))==NO_ERROR)
+       {
+           for (DWORD i=0;i<cEntries;i++)
+           {
+               if (strstr(_strlwr(lpnrLocal[i].lpRemoteName),szPath)==NULL)
+                   continue;   //only look at real afs mappings
+               CHAR * pSubmount=strrchr(lpnrLocal[i].lpRemoteName,'\\')+1;
+               if (lstrcmpi(pSubmount,"all")==0) 
+                   continue;                           // do not remove 'all'
+               for (DWORD j=0;j<List.cSubmounts;j++)
                {
-                       for (DWORD i=0;i<cEntries;i++)
-                       {
-                               if (strstr(_strlwr(lpnrLocal[i].lpRemoteName),szPath)==NULL)
-                                       continue;       //only look at real afs mappings
-                               CHAR * pSubmount=strrchr(lpnrLocal[i].lpRemoteName,'\\')+1;
-                               if (lstrcmpi(pSubmount,"all")==0) 
-                                       continue;                               // do not remove 'all'
-                               for (DWORD j=0;j<List.cSubmounts;j++)
-                               {
-                                       if (
-                                               (List.aSubmounts[j].szSubmount[0]) &&
-                                               (lstrcmpi(List.aSubmounts[j].szSubmount,pSubmount)==0)
-                                               ) 
-                                       {
-                                               List.aSubmounts[j].fInUse=TRUE; 
-                                               goto nextname;
-                                       }
-                               }
-                               // wasn't on list so lets remove
-                               DisMountDOSDrive(pSubmount);
-                               nextname:;
-                       }
+                   if ((List.aSubmounts[j].szSubmount[0]) &&
+                        (lstrcmpi(List.aSubmounts[j].szSubmount,pSubmount)==0)
+                        ) 
+                   {
+                       List.aSubmounts[j].fInUse=TRUE; 
+                       goto nextname;
+                   }
                }
-       } while (res!=ERROR_NO_MORE_ITEMS);
-       GlobalFree((HGLOBAL)lpnrLocal);
-       WNetCloseEnum(hEnum);
-       sprintf(szPath,"\\\\%s\\all",szMachine);
+               // wasn't on list so lets remove
+               DisMountDOSDrive(pSubmount);
+             nextname:;
+           }
+       }
+    } while (res!=ERROR_NO_MORE_ITEMS);
+    GlobalFree((HGLOBAL)lpnrLocal);
+    WNetCloseEnum(hEnum);
+    sprintf(szPath,"\\\\%s\\all",szMachine);
 
-       // Lets connect all submounts that weren't connectd
+    // Lets connect all submounts that weren't connectd
     DWORD cbUser=MAXRANDOMNAMELEN-1;
-       CHAR szUser[MAXRANDOMNAMELEN];
+    CHAR szUser[MAXRANDOMNAMELEN];
     CHAR * pUser = NULL;
-       if (WNetGetUser(szPath,(LPSTR)szUser,&cbUser)!=NO_ERROR) {
+    if (WNetGetUser(szPath,(LPSTR)szUser,&cbUser)!=NO_ERROR) {
         if (RWLogonOption(TRUE,LOGON_OPTION_HIGHSECURITY)) {
             if (!pUserName[0]) {
                 GenRandomName(szUser,MAXRANDOMNAMELEN-1);
@@ -1226,42 +1290,42 @@ BOOL DoMapShareChange()
             }
         }
     } else {
-               if ((pUser=strchr(szUser,'\\'))!=NULL)
+       if ((pUser=strchr(szUser,'\\'))!=NULL)
             pUser++;
-       }
+    }
 
     for (DWORD j=0;j<List.cSubmounts;j++)
-       {
-               if (List.aSubmounts[j].fInUse)
-                       continue;
-               DWORD res=MountDOSDrive(0,List.aSubmounts[j].szSubmount,FALSE,pUser);
-       }
-       return TRUE;
+    {
+       if (List.aSubmounts[j].fInUse)
+           continue;
+       DWORD res=MountDOSDrive(0,List.aSubmounts[j].szSubmount,FALSE,pUser);
+    }
+    return TRUE;
 }
 
 BOOL DoMapShare()
 {
-       DRIVEMAPLIST List;
-       DWORD rc=28;
-       BOOL bMappedAll=FALSE;
+    DRIVEMAPLIST List;
+    DWORD rc=28;
+    BOOL bMappedAll=FALSE;
 
    // Initialize the data structure
-       DEBUG_EVENT0("AFS DoMapShare");
-       QueryDriveMapList (&List);
-       DoUnMapShare(TRUE);
-       // All connections have been removed
-       // Lets restore them after making the connection from the random name
+    DEBUG_EVENT0("AFS DoMapShare");
+    QueryDriveMapList (&List);
+    DoUnMapShare(TRUE);
+    // All connections have been removed
+    // Lets restore them after making the connection from the random name
 
-       TCHAR szMachine[ MAX_PATH],szPath[MAX_PATH];
+    TCHAR szMachine[ MAX_PATH],szPath[MAX_PATH];
     memset(szMachine, '\0', sizeof(szMachine));
     GetClientNetbiosName(szMachine);
     sprintf(szPath,"\\\\%s\\all",szMachine);
 
     // Lets connect all submounts that weren't connectd
     DWORD cbUser=MAXRANDOMNAMELEN-1;
-       CHAR szUser[MAXRANDOMNAMELEN];
+    CHAR szUser[MAXRANDOMNAMELEN];
     CHAR * pUser = NULL;
-       if (WNetGetUser(szPath,(LPSTR)szUser,&cbUser)!=NO_ERROR) {
+    if (WNetGetUser(szPath,(LPSTR)szUser,&cbUser)!=NO_ERROR) {
         if (RWLogonOption(TRUE,LOGON_OPTION_HIGHSECURITY)) {
             if (!pUserName[0]) {
                 GenRandomName(szUser,MAXRANDOMNAMELEN-1);
@@ -1271,33 +1335,33 @@ BOOL DoMapShare()
             }
         }
     } else {
-               if ((pUser=strchr(szUser,'\\'))!=NULL)
+       if ((pUser=strchr(szUser,'\\'))!=NULL)
             pUser++;
-       }
+    }
 
-       for (DWORD i=0;i<List.cSubmounts;i++)
+    for (DWORD i=0;i<List.cSubmounts;i++)
+    {
+       if (List.aSubmounts[i].szSubmount[0])
        {
-               if (List.aSubmounts[i].szSubmount[0])
-               {
-                       DWORD res=MountDOSDrive(0,List.aSubmounts[i].szSubmount,FALSE,pUser);
-                       if (lstrcmpi("all",List.aSubmounts[i].szSubmount)==0)
-                               bMappedAll=TRUE;
-               }
+           DWORD res=MountDOSDrive(0,List.aSubmounts[i].szSubmount,FALSE,pUser);
+           if (lstrcmpi("all",List.aSubmounts[i].szSubmount)==0)
+               bMappedAll=TRUE;
        }
-       if (!bMappedAll)        //make sure all is mapped also
-       {
+    }
+    if (!bMappedAll)   //make sure all is mapped also
+    {
         DWORD res=MountDOSDrive(0,"all",FALSE,pUser);
         if (res==ERROR_SESSION_CREDENTIAL_CONFLICT)
         {
             DisMountDOSDrive("all");
             MountDOSDrive(0,"all",FALSE,pUser);
         }
-       }
-       for (TCHAR chDrive = chDRIVE_A; chDrive <= chDRIVE_Z; ++chDrive)
+    }
+    for (TCHAR chDrive = chDRIVE_A; chDrive <= chDRIVE_Z; ++chDrive)
+    {
+       if (List.aDriveMap[chDrive-chDRIVE_A].fActive ||
+            ForceMapActive(chDrive))
        {
-               if (List.aDriveMap[chDrive-chDRIVE_A].fActive ||
-            ForceMapActive(chDrive))
-               {
             TCHAR szSubmount[ MAX_PATH ];
             if (List.aDriveMap[chDrive-chDRIVE_A].szSubmount[0])
                 lstrcpy(szSubmount,List.aDriveMap[chDrive-chDRIVE_A].szSubmount);
@@ -1307,12 +1371,12 @@ BOOL DoMapShare()
             BOOL fPersistent = List.aDriveMap[chDrive-chDRIVE_A].fPersistent;
             if (RWLogonOption(TRUE,LOGON_OPTION_HIGHSECURITY))
                 fPersistent = FALSE;
-                   DWORD res=MountDOSDrive(chDrive
-                                           ,szSubmount
-                                           ,fPersistent,pUser);
-               }
+           DWORD res=MountDOSDrive(chDrive
+                                    ,szSubmount
+                                    ,fPersistent,pUser);
        }
-       return TRUE;
+    }
+    return TRUE;
 }
 
 BOOL GlobalMountDrive()
@@ -1331,7 +1395,7 @@ BOOL GlobalMountDrive()
        return TRUE;
     if (!GetComputerName(cm_HostName, &dwType))
         return TRUE;
-    sprintf(szKeyName, "%s\\GlobalAutoMapper", sAFSConfigKeyName);
+    sprintf(szKeyName, "%s\\GlobalAutoMapper", AFSREG_CLT_SVC_PARAM_SUBKEY);
     
     dwResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE, szKeyName, 0, KEY_QUERY_VALUE,
                            &hKey);
@@ -1360,9 +1424,41 @@ BOOL GlobalMountDrive()
 
 DWORD MountDOSDrive(char chDrive,const char *szSubmount,BOOL bPersistent,const char * pUsername)
 {
-    TCHAR szPath[MAX_PATH];
+    DWORD err;
+       BOOL succ;
+       TCHAR szPath[MAX_PATH], szTokens[MAX_PATH], *tok;
     TCHAR szClient[MAX_PATH];
     TCHAR szDrive[3] = TEXT("?:");
+
+#ifdef AFSIFS
+    int pathCount, currPos, lastPos, x;
+    
+    pathCount = 0;
+
+    pathCount = 0;
+    strcpy(szTokens, szSubmount);
+    tok = strtok(szTokens, "/\\");
+    strcpy(szPath, "");
+    while (tok)
+    {
+        if (pathCount || stricmp(tok, "afs"))
+        {
+            strcat(szPath, "\\");
+            strcat(szPath, tok);
+            pathCount++;
+        }
+        tok = strtok(NULL, "/\\");
+    }
+
+    sprintf(szDrive,"%c:",chDrive);
+    strcpy(szTokens, szPath);
+    sprintf(szPath,"\\Device\\afsrdr\\%d%s",pathCount,szTokens);
+    //succ = DefineDosDevice(DDD_RAW_TARGET_PATH, "J:", "\\Device\\afsrdr\\2\\ericjw\\test");
+    succ = DefineDosDevice(DDD_RAW_TARGET_PATH, szDrive, szPath);
+    err = GetLastError();
+
+    return succ ? NO_ERROR : ERROR_DEVICE_IN_USE;
+#else
     sprintf(szDrive,"%c:",chDrive);
     GetClientNetbiosName (szClient);
     sprintf(szPath,"\\\\%s\\%s",szClient,szSubmount);
@@ -1377,11 +1473,19 @@ DWORD MountDOSDrive(char chDrive,const char *szSubmount,BOOL bPersistent,const c
                   (bPersistent)?"Persistant" : "NonPresistant",
                   szDrive,szPath,pUsername?pUsername:"NULL",res);
     return res;
+#endif
 }
 
 DWORD DisMountDOSDriveFull(const char *szPath,BOOL bForce)
 {
+#ifndef AFSIFS
     DWORD res=WNetCancelConnection(szPath,bForce);
+#else
+    DWORD res;
+    res = ERROR_DEVICE_IN_USE;
+    // must handle drive letters and afs paths
+    // DDD_REMOVE_DEFINITION
+#endif
     DEBUG_EVENT3("AFS DriveMap","%sDismount Remote[%s]=%x",
                   bForce ? "Forced " : "",szPath,res);
     return (res==ERROR_NOT_CONNECTED)?NO_ERROR:res;
@@ -1400,6 +1504,13 @@ DWORD DisMountDOSDrive(const char *pSubmount,BOOL bForce)
 DWORD DisMountDOSDrive(const char chDrive,BOOL bForce)
 {
     TCHAR szPath[MAX_PATH];
+    DWORD succ;
+
     sprintf(szPath,"%c:",chDrive);
+#ifdef AFSIFS
+    succ = DefineDosDevice(DDD_REMOVE_DEFINITION, szPath, NULL);
+    return (!succ) ? GetLastError() : 0;
+#else
     return DisMountDOSDriveFull(szPath,bForce);
+#endif
 }