windows-pioctl-service-check-20060828
[openafs.git] / src / sys / pioctl_nt.c
index 06bdbbb..05486c7 100644 (file)
@@ -6,6 +6,30 @@
  * 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 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.  if
+ * the above copyright notice or any other identification of the
+ * university of michigan is included in any copy of any portion of
+ * this software, then the disclaimer below must also be included.
+ * 
+ * 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 any damages,
+ * including special, indirect, incidental, or consequential damages, 
+ * with respect to any claim arising out 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 <afsconfig.h>
 #include <afs/param.h>
@@ -42,6 +66,10 @@ RCSID
 #include <pioctl_nt.h>
 #include <WINNT/afsreg.h>
 #include <lanahelper.h>
+#include <../WINNT/afsrdr/kif.h>
+
+#include <loadfuncs-krb5.h>
+#include <krb5.h>
 
 static char AFSConfigKeyName[] = AFSREG_CLT_SVC_PARAM_SUBKEY;
 
@@ -88,7 +116,10 @@ CMtoUNIXerror(int cm_code)
     case CM_ERROR_TOOMANYBUFS:
        return EFBIG;           /* hack */
     default:
-       return ENOTTY;
+       if (cm_code > 0 && cm_code < EILSEQ)
+           return cm_code;
+       else
+           return ENOTTY;
     }
 }
 
@@ -123,11 +154,245 @@ IoctlDebug(void)
     return debug;
 }
 
+static DWORD 
+GetServiceStatus(
+    LPSTR lpszMachineName, 
+    LPSTR lpszServiceName,
+    DWORD *lpdwCurrentState) 
+{ 
+    DWORD           hr               = NOERROR; 
+    SC_HANDLE       schSCManager     = NULL; 
+    SC_HANDLE       schService       = NULL; 
+    DWORD           fdwDesiredAccess = 0; 
+    SERVICE_STATUS  ssServiceStatus  = {0}; 
+    BOOL            fRet             = FALSE; 
+
+    *lpdwCurrentState = 0; 
+    fdwDesiredAccess = GENERIC_READ; 
+    schSCManager = OpenSCManager(lpszMachineName,  
+                                 NULL,
+                                 fdwDesiredAccess); 
+    if(schSCManager == NULL) 
+    { 
+        hr = GetLastError();
+        goto cleanup; 
+    } 
+    schService = OpenService(schSCManager,
+                             lpszServiceName,
+                             fdwDesiredAccess); 
+    if(schService == NULL) 
+    { 
+        hr = GetLastError();
+        goto cleanup; 
+    } 
+    fRet = QueryServiceStatus(schService,
+                              &ssServiceStatus); 
+    if(fRet == FALSE) 
+    { 
+        hr = GetLastError(); 
+        goto cleanup; 
+    } 
+    *lpdwCurrentState = ssServiceStatus.dwCurrentState; 
+cleanup: 
+    CloseServiceHandle(schService); 
+    CloseServiceHandle(schSCManager); 
+    return(hr); 
+} 
+
+// krb5 functions
+DECL_FUNC_PTR(krb5_cc_default_name);
+DECL_FUNC_PTR(krb5_cc_set_default_name);
+DECL_FUNC_PTR(krb5_get_default_config_files);
+DECL_FUNC_PTR(krb5_free_config_files);
+DECL_FUNC_PTR(krb5_free_context);
+DECL_FUNC_PTR(krb5_get_default_realm);
+DECL_FUNC_PTR(krb5_free_default_realm);
+DECL_FUNC_PTR(krb5_init_context);
+DECL_FUNC_PTR(krb5_cc_default);
+DECL_FUNC_PTR(krb5_parse_name);
+DECL_FUNC_PTR(krb5_free_principal);
+DECL_FUNC_PTR(krb5_cc_close);
+DECL_FUNC_PTR(krb5_cc_get_principal);
+DECL_FUNC_PTR(krb5_build_principal);
+DECL_FUNC_PTR(krb5_c_random_make_octets);
+DECL_FUNC_PTR(krb5_get_init_creds_password);
+DECL_FUNC_PTR(krb5_free_cred_contents);
+DECL_FUNC_PTR(krb5_cc_resolve);
+DECL_FUNC_PTR(krb5_unparse_name);
+DECL_FUNC_PTR(krb5_free_unparsed_name);
+
+FUNC_INFO krb5_fi[] = {
+    MAKE_FUNC_INFO(krb5_cc_default_name),
+    MAKE_FUNC_INFO(krb5_cc_set_default_name),
+    MAKE_FUNC_INFO(krb5_get_default_config_files),
+    MAKE_FUNC_INFO(krb5_free_config_files),
+    MAKE_FUNC_INFO(krb5_free_context),
+    MAKE_FUNC_INFO(krb5_get_default_realm),
+    MAKE_FUNC_INFO(krb5_free_default_realm),
+    MAKE_FUNC_INFO(krb5_init_context),
+    MAKE_FUNC_INFO(krb5_cc_default),
+    MAKE_FUNC_INFO(krb5_parse_name),
+    MAKE_FUNC_INFO(krb5_free_principal),
+    MAKE_FUNC_INFO(krb5_cc_close),
+    MAKE_FUNC_INFO(krb5_cc_get_principal),
+    MAKE_FUNC_INFO(krb5_build_principal),
+    MAKE_FUNC_INFO(krb5_c_random_make_octets),
+    MAKE_FUNC_INFO(krb5_get_init_creds_password),
+    MAKE_FUNC_INFO(krb5_free_cred_contents),
+    MAKE_FUNC_INFO(krb5_cc_resolve),
+    MAKE_FUNC_INFO(krb5_unparse_name),
+    MAKE_FUNC_INFO(krb5_free_unparsed_name),
+    END_FUNC_INFO
+};
+
+static int
+LoadFuncs(
+    const char* dll_name,
+    FUNC_INFO fi[],
+    HINSTANCE* ph,  // [out, optional] - DLL handle
+    int* pindex,    // [out, optional] - index of last func loaded (-1 if none)
+    int cleanup,    // cleanup function pointers and unload on error
+    int go_on,      // continue loading even if some functions cannot be loaded
+    int silent      // do not pop-up a system dialog if DLL cannot be loaded
+    )
+{
+    HINSTANCE h;
+    int i, n, last_i;
+    int error = 0;
+    UINT em;
+
+    if (ph) *ph = 0;
+    if (pindex) *pindex = -1;
+
+    for (n = 0; fi[n].func_ptr_var; n++)
+        *(fi[n].func_ptr_var) = 0;
+
+    if (silent)
+        em = SetErrorMode(SEM_FAILCRITICALERRORS);
+    h = LoadLibrary(dll_name);
+    if (silent)
+        SetErrorMode(em);
+
+    if (!h)
+        return 0;
+
+    last_i = -1;
+    for (i = 0; (go_on || !error) && (i < n); i++)
+    {
+        void* p = (void*)GetProcAddress(h, fi[i].func_name);
+        if (!p)
+            error = 1;
+        else
+        {
+            last_i = i;
+            *(fi[i].func_ptr_var) = p;
+        }
+    }
+    if (pindex) *pindex = last_i;
+    if (error && cleanup && !go_on) {
+        for (i = 0; i < n; i++) {
+            *(fi[i].func_ptr_var) = 0;
+        }
+        FreeLibrary(h);
+        return 0;
+    }
+    if (ph) *ph = h;
+    if (error) return 0;
+    return 1;
+}
+#if defined(_IA64_) || defined(_AMD64_)
+#define KERB5DLL "krb5_64.dll"
+#else
+#define KERB5DLL "krb5_32.dll"
+#endif
+static BOOL
+IsKrb5Available()
+{
+    static HINSTANCE hKrb5DLL = 0;
+
+    if ( hKrb5DLL )
+        return TRUE;
+
+    hKrb5DLL = LoadLibrary(KERB5DLL);
+    if (hKrb5DLL) {
+        if (!LoadFuncs(KERB5DLL, krb5_fi, 0, 0, 1, 0, 0))
+        {
+            FreeLibrary(hKrb5DLL);
+            hKrb5DLL = 0;
+            return FALSE;
+        }
+        return TRUE;
+    }
+    return FALSE;
+}
+
+static BOOL
+GetLSAPrincipalName(char * szUser, DWORD *dwSize)
+{
+    krb5_context   ctx = 0;
+    krb5_error_code code;
+    krb5_ccache mslsa_ccache=0;
+    krb5_principal princ = 0;
+    char * pname = 0;
+    BOOL success = 0;
+
+    if (!IsKrb5Available())
+        return FALSE;
+
+    if (code = pkrb5_init_context(&ctx))
+        goto cleanup;
+
+    if (code = pkrb5_cc_resolve(ctx, "MSLSA:", &mslsa_ccache))
+        goto cleanup;
+
+    if (code = pkrb5_cc_get_principal(ctx, mslsa_ccache, &princ))
+        goto cleanup;
+
+    if (code = pkrb5_unparse_name(ctx, princ, &pname))
+        goto cleanup;
+
+    if ( strlen(pname) < *dwSize ) {
+        strncpy(szUser, pname, *dwSize);
+        szUser[*dwSize-1] = '\0';
+        success = 1;
+    }
+    *dwSize = (DWORD)strlen(pname);
+
+  cleanup:
+    if (pname)
+        pkrb5_free_unparsed_name(ctx, pname);
+
+    if (princ)
+        pkrb5_free_principal(ctx, princ);
+
+    if (mslsa_ccache)
+        pkrb5_cc_close(ctx, mslsa_ccache);
+
+    if (ctx)
+        pkrb5_free_context(ctx);
+    return success;
+}
+
 static long
 GetIoctlHandle(char *fileNamep, HANDLE * handlep)
 {
+#ifndef AFSIFS
     char *drivep;
     char netbiosName[MAX_NB_NAME_LENGTH];
+    DWORD CurrentState = 0;
+    char  HostName[64] = "";
+#endif
     char tbuffer[256]="";
     HANDLE fh;
     HKEY hk;
@@ -140,6 +405,13 @@ GetIoctlHandle(char *fileNamep, HANDLE * handlep)
     DWORD gle;
     DWORD dwSize = sizeof(szUser);
 
+#ifndef AFSIFS
+    memset(HostName, '\0', sizeof(HostName));
+    gethostname(HostName, sizeof(HostName));
+    if (GetServiceStatus(HostName, TEXT("TransarcAFSDaemon"), &CurrentState) == NOERROR &&
+       CurrentState != SERVICE_RUNNING)
+       return -1;
+
     if (fileNamep) {
         drivep = strchr(fileNamep, ':');
         if (drivep && (drivep - fileNamep) >= 1) {
@@ -147,14 +419,16 @@ GetIoctlHandle(char *fileNamep, HANDLE * handlep)
             tbuffer[1] = ':';
             strcpy(tbuffer + 2, SMB_IOCTL_FILENAME);
         } else if (fileNamep[0] == fileNamep[1] && 
-                              fileNamep[0] == '\\')
+                  (fileNamep[0] == '\\' || fileNamep[0] == '/'))
         {
             int count = 0, i = 0;
 
             while (count < 4 && fileNamep[i]) {
                 tbuffer[i] = fileNamep[i];
-                if ( tbuffer[i++] == '\\' )
+                if ( tbuffer[i] == '\\' ||
+                    tbuffer[i] == '/')
                     count++;
+               i++;
             }
             if (fileNamep[i] == 0)
                 tbuffer[i++] = '\\';
@@ -169,14 +443,16 @@ GetIoctlHandle(char *fileNamep, HANDLE * handlep)
                 tbuffer[1] = ':';
                 strcpy(tbuffer + 2, SMB_IOCTL_FILENAME);
             } else if (curdir[0] == curdir[1] &&
-                       curdir[0] == '\\') 
+                       (curdir[0] == '\\' || curdir[0] == '/')) 
             {
                 int count = 0, i = 0;
 
                 while (count < 4 && curdir[i]) {
                     tbuffer[i] = curdir[i];
-                    if ( tbuffer[i++] == '\\' )
-                        count++;
+                   if ( tbuffer[i] == '\\' ||
+                        tbuffer[i] == '/')
+                       count++;
+                   i++;
                 }
                 if (tbuffer[i] == 0)
                     tbuffer[i++] = '\\';
@@ -190,13 +466,24 @@ GetIoctlHandle(char *fileNamep, HANDLE * handlep)
         lana_GetNetbiosName(netbiosName,LANA_NETBIOS_NAME_FULL);
         sprintf(tbuffer,"\\\\%s\\all%s",netbiosName,SMB_IOCTL_FILENAME);
     }
+#else   
+    sprintf(tbuffer,"\\\\.\\afscom\\ioctl");
+#endif 
 
     fflush(stdout);
     /* now open the file */
     fh = CreateFile(tbuffer, GENERIC_READ | GENERIC_WRITE,
                    FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING,
                    FILE_FLAG_WRITE_THROUGH, NULL);
-    fflush(stdout);
+
+       fflush(stdout);
+
+#ifdef AFSIFS
+    if (fh == INVALID_HANDLE_VALUE) {
+        return -1;
+    }
+#endif
+       
     if (fh == INVALID_HANDLE_VALUE) {
         int  gonext = 0;
 
@@ -213,14 +500,10 @@ GetIoctlHandle(char *fileNamep, HANDLE * handlep)
                                (va_list *) NULL
                                ) )
             {
-                fprintf(stderr,"pioctl CreateFile(%s) failed: 0x%8X\r\n\t[%s]\r\n",
+                fprintf(stderr,"pioctl CreateFile(%s) failed: 0x%X\r\n\t[%s]\r\n",
                         tbuffer,gle,buf);
             }
         }
-#ifdef COMMENT
-        if (gle != ERROR_DOWNGRADE_DETECTED)
-            return -1;                                   
-#endif
 
         lana_GetNetbiosName(szClient, LANA_NETBIOS_NAME_FULL);
 
@@ -234,7 +517,69 @@ GetIoctlHandle(char *fileNamep, HANDLE * handlep)
 
         if ( szUser[0] ) {
             if ( ioctlDebug )
-                fprintf(stderr, "pioctl logon user: [%s]\r\n",szUser);
+                fprintf(stderr, "pioctl Explorer logon user: [%s]\r\n",szUser);
+
+            sprintf(szPath, "\\\\%s", szClient);
+            memset (&nr, 0x00, sizeof(NETRESOURCE));
+            nr.dwType=RESOURCETYPE_DISK;
+            nr.lpLocalName=0;
+            nr.lpRemoteName=szPath;
+            res = WNetAddConnection2(&nr,NULL,szUser,0);
+            if (res) {
+                if ( ioctlDebug ) {
+                    fprintf(stderr, "pioctl WNetAddConnection2(%s,%s) failed: 0x%X\r\n",
+                             szPath,szUser,res);
+                }
+                gonext = 1;
+            }
+
+            sprintf(szPath, "\\\\%s\\all", szClient);
+            res = WNetAddConnection2(&nr,NULL,szUser,0);
+            if (res) {
+                if ( ioctlDebug ) {
+                    fprintf(stderr, "pioctl WNetAddConnection2(%s,%s) failed: 0x%X\r\n",
+                             szPath,szUser,res);
+                }
+                gonext = 1;
+            }
+
+            if (gonext)
+                goto try_lsa_principal;
+
+            fh = CreateFile(tbuffer, GENERIC_READ | GENERIC_WRITE,
+                             FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING,
+                             FILE_FLAG_WRITE_THROUGH, NULL);
+            fflush(stdout);
+            if (fh == INVALID_HANDLE_VALUE) {
+                gle = GetLastError();
+                if (gle && ioctlDebug ) {
+                    char buf[4096];
+
+                    if ( FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,
+                                        NULL,
+                                        gle,
+                                        MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),
+                                        buf,
+                                        4096,
+                                        (va_list *) NULL
+                                        ) )
+                    {
+                        fprintf(stderr,"pioctl CreateFile(%s) failed: 0x%X\r\n\t[%s]\r\n",
+                                 tbuffer,gle,buf);
+                    }
+                }
+            }
+        }
+    }
+
+  try_lsa_principal:
+    if (fh == INVALID_HANDLE_VALUE) {
+        int  gonext = 0;
+
+        dwSize = sizeof(szUser);
+        if (GetLSAPrincipalName(szUser, &dwSize)) {
+            if ( ioctlDebug )
+                fprintf(stderr, "pioctl LSA Principal logon user: [%s]\r\n",szUser);
 
             sprintf(szPath, "\\\\%s", szClient);
             memset (&nr, 0x00, sizeof(NETRESOURCE));
@@ -261,7 +606,7 @@ GetIoctlHandle(char *fileNamep, HANDLE * handlep)
             }
 
             if (gonext)
-                goto next_attempt;
+                goto try_sam_compat;
 
             fh = CreateFile(tbuffer, GENERIC_READ | GENERIC_WRITE,
                              FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING,
@@ -281,7 +626,7 @@ GetIoctlHandle(char *fileNamep, HANDLE * handlep)
                                         (va_list *) NULL
                                         ) )
                     {
-                        fprintf(stderr,"pioctl CreateFile(%s) failed: 0x%8X\r\n\t[%s]\r\n",
+                        fprintf(stderr,"pioctl CreateFile(%s) failed: 0x%X\r\n\t[%s]\r\n",
                                  tbuffer,gle,buf);
                     }
                 }
@@ -289,11 +634,12 @@ GetIoctlHandle(char *fileNamep, HANDLE * handlep)
         }
     }
 
-  next_attempt:
+  try_sam_compat:
     if ( fh == INVALID_HANDLE_VALUE ) {
+        dwSize = sizeof(szUser);
         if (GetUserNameEx(NameSamCompatible, szUser, &dwSize)) {
             if ( ioctlDebug )
-                fprintf(stderr, "pioctl logon user: [%s]\r\n",szUser);
+                fprintf(stderr, "pioctl SamCompatible logon user: [%s]\r\n",szUser);
 
             sprintf(szPath, "\\\\%s", szClient);
             memset (&nr, 0x00, sizeof(NETRESOURCE));
@@ -336,13 +682,14 @@ GetIoctlHandle(char *fileNamep, HANDLE * handlep)
                                         (va_list *) NULL
                                         ) )
                     {
-                        fprintf(stderr,"pioctl CreateFile(%s) failed: 0x%8X\r\n\t[%s]\r\n",
+                        fprintf(stderr,"pioctl CreateFile(%s) failed: 0x%X\r\n\t[%s]\r\n",
                                  tbuffer,gle,buf);
                     }
                 }
                 return -1;
             }
         } else {
+            fprintf(stderr, "GetUserNameEx(NameSamCompatible) failed: 0x%X\r\n", GetLastError());
             return -1;
         }
     }
@@ -358,14 +705,18 @@ Transceive(HANDLE handle, fs_ioctlRequest_t * reqp)
     long rcount;
     long ioCount;
     DWORD gle;
+#ifdef AFSIFS
+    char *data;
+#endif
 
-    rcount = reqp->mp - reqp->data;
+    rcount = (long)(reqp->mp - reqp->data);
     if (rcount <= 0) {
         if ( IoctlDebug() )
             fprintf(stderr, "pioctl Transceive rcount <= 0: %d\r\n",rcount);
        return EINVAL;          /* not supposed to happen */
     }
 
+#ifndef AFSIFS
     if (!WriteFile(handle, reqp->data, rcount, &ioCount, NULL)) {
        /* failed to write */
        gle = GetLastError();
@@ -383,6 +734,17 @@ Transceive(HANDLE handle, fs_ioctlRequest_t * reqp)
             fprintf(stderr, "pioctl Transceive ReadFile failed: 0x%X\r\n",gle);
         return gle;
     }
+#else
+    /* ioctl completes as one operation, so copy input to a new buffer, and use as output buffer */
+    data = malloc(rcount);
+    memcpy(data, reqp->data, rcount);
+    if (!DeviceIoControl(handle, IOCTL_AFSRDR_IOCTL, data, rcount, reqp->data, sizeof(reqp->data), &ioCount, NULL))
+    {
+        free(data);
+        return GetLastError();
+    }
+    free(data);
+#endif
 
     reqp->nbytes = ioCount;    /* set # of bytes available */
     reqp->mp = reqp->data;     /* restart marshalling */
@@ -423,7 +785,7 @@ MarshallString(fs_ioctlRequest_t * reqp, char *stringp)
     int count;
 
     if (stringp)
-       count = strlen(stringp) + 1;    /* space required including null */
+       count = (int)strlen(stringp) + 1;/* space required including null */
     else
        count = 1;
 
@@ -456,7 +818,34 @@ fs_GetFullPath(char *pathp, char *outPathp, long outSize)
     int pathHasDrive;
     int doSwitch;
     char newPath[3];
+#ifdef AFSIFS
+    HANDLE rootDir;
+    wchar_t *wpath;
+    unsigned long length;
+#endif
+    char * p;
+
+#ifdef AFSIFS
+    if (!pathp)
+        return CM_ERROR_NOSUCHPATH;
+
+    rootDir = CreateFile(pathp, 0, 0, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
+    if (rootDir == INVALID_HANDLE_VALUE)
+        return CM_ERROR_NOSUCHPATH;
+
+    wpath = (wchar_t *)tpath;
+    length = 0;
+    if (!DeviceIoControl(rootDir, IOCTL_AFSRDR_GET_PATH, NULL, 0, wpath, 1000, &length, NULL))
+    {
+        CloseHandle(rootDir);
+        return CM_ERROR_NOSUCHPATH;
+    }
+    CloseHandle(rootDir);
+
+    code = WideCharToMultiByte(CP_UTF8, 0/*WC_NO_BEST_FIT_CHARS*/, wpath, length/sizeof(wchar_t), outPathp, outSize/sizeof(wchar_t), NULL, NULL);
 
+    return 0;
+#else
     if (pathp[0] != 0 && pathp[1] == ':') {
        /* there's a drive letter there */
        firstp = pathp + 2;
@@ -466,7 +855,8 @@ fs_GetFullPath(char *pathp, char *outPathp, long outSize)
        pathHasDrive = 0;
     }
 
-    if ( firstp[0] == '\\' && firstp[1] == '\\') {
+    if ( firstp[0] == '\\' && firstp[1] == '\\' || 
+        firstp[0] == '/' && firstp[1] == '/') {
         /* UNC path - strip off the server and sharename */
         int i, count;
         for ( i=2,count=2; count < 4 && firstp[i]; i++ ) {
@@ -479,10 +869,18 @@ fs_GetFullPath(char *pathp, char *outPathp, long outSize)
         } else {
             strcpy(outPathp,&firstp[--i]);
         }
+       for (p=outPathp ;*p; p++) {
+           if (*p == '/')
+               *p = '\\';
+       }
         return 0;
     } else if (firstp[0] == '\\' || firstp[0] == '/') {
         /* already an absolute pathname, just copy it back */
         strcpy(outPathp, firstp);
+       for (p=outPathp ;*p; p++) {
+           if (*p == '/')
+               *p = '\\';
+       }
         return 0;
     }
 
@@ -512,7 +910,8 @@ fs_GetFullPath(char *pathp, char *outPathp, long outSize)
     GetCurrentDirectory(sizeof(tpath), tpath);
     if (tpath[1] == ':')
         strcpy(outPathp, tpath + 2);   /* skip drive letter */
-    else if ( tpath[0] == '\\' && tpath[1] == '\\') {
+    else if ( tpath[0] == '\\' && tpath[1] == '\\'||
+             tpath[0] == '/' && tpath[1] == '/') {
         /* UNC path - strip off the server and sharename */
         int i, count;
         for ( i=2,count=2; count < 4 && tpath[i]; i++ ) {
@@ -532,7 +931,7 @@ fs_GetFullPath(char *pathp, char *outPathp, long outSize)
 
     /* if there is a non-null name after the drive, append it */
     if (*firstp != 0) {
-        int len = strlen(outPathp);
+        int len = (int)strlen(outPathp);
         if (outPathp[len-1] != '\\' && outPathp[len-1] != '/') 
             strcat(outPathp, "\\");
         strcat(outPathp, firstp);
@@ -543,7 +942,12 @@ fs_GetFullPath(char *pathp, char *outPathp, long outSize)
        SetCurrentDirectory(origPath);
     }
 
+    for (p=outPathp ;*p; p++) {
+       if (*p == '/')
+           *p = '\\';
+    }
     return 0;
+#endif
 }
 
 long