pastebin - collaborative debugging tool
nrubsig.kpaste.net RSS


UNC mount prototype
Posted by Anonymous on Wed 2nd Oct 2024 16:56
raw | new post

  1. diff --git a/dll/nfs41_np.c b/dll/nfs41_np.c
  2. index 5a89134..53ec774 100644
  3. --- a/dll/nfs41_np.c
  4. +++ b/dll/nfs41_np.c
  5. @@ -517,14 +517,20 @@ NPAddConnection3(
  6.      WCHAR ServerName[NFS41_SYS_MAX_PATH_LEN];
  7.      PWCHAR p;
  8.      DWORD i;
  9. +    LPWSTR  lpLocalName = lpNetResource->lpLocalName;
  10.  
  11.      DbgP((L"-->  NPAddConnection3(lpNetResource->lpLocalName='%s', "
  12.          L"lpNetResource->lpRemoteName='%s', "
  13.          L"username='%s', passwd='%s')\n",
  14. -        lpNetResource->lpLocalName,
  15. +        lpLocalName,
  16.          lpNetResource->lpRemoteName,lpUserName,
  17.          lpPassword));
  18.  
  19. +    if (lpLocalName == NULL) {
  20. +        lpLocalName = L"_:";
  21. +        DbgP((L"lpLocalName==NULL, changed to _:\n"));
  22. +    }
  23. +
  24.      Status = InitializeConnectionInfo(&Connection,
  25.          (PMOUNT_OPTION_BUFFER)lpNetResource->lpComment,
  26.          &ConnectionName);
  27. @@ -536,16 +542,16 @@ NPAddConnection3(
  28.      //  \device\miniredirector\;<DriveLetter>:\Server\Share
  29.  
  30.      // local name, must start with "X:"
  31. -    if (lstrlen(lpNetResource->lpLocalName) < 2 ||
  32. -        lpNetResource->lpLocalName[1] != L':') {
  33. -        DbgP((L"lpNetResource->lpLocalName(='%s') "
  34. +    if (lstrlen(lpLocalName) < 2 ||
  35. +        lpLocalName[1] != L':') {
  36. +        DbgP((L"lpLocalName(='%s') "
  37.              "is not a device letter\n",
  38. -            lpNetResource->lpLocalName));
  39. +            lpLocalName));
  40.          Status = WN_BAD_LOCALNAME;
  41.          goto out;
  42.      }
  43.  
  44. -    LocalName[0] = towupper(lpNetResource->lpLocalName[0]);
  45. +    LocalName[0] = towupper(lpLocalName[0]);
  46.      LocalName[1] = L':';
  47.      LocalName[2] = L'\0';
  48.      (void)StringCchCopyW(ConnectionName,
  49. @@ -659,6 +665,30 @@ NPAddConnection3(
  50.          (wcslen(ConnectionName) + 1) * sizeof(WCHAR),
  51.          (lstrlen(ConnectionName) + 1) * sizeof(WCHAR)));
  52.  
  53. +    if (lpNetResource->lpLocalName == NULL) {
  54. +        wchar_t dummy_remotename[1024];
  55. +        DWORD gc_status;
  56. +        DWORD gc_remotename_size = 1024;
  57. +
  58. +        gc_status = NPGetConnection(NULL,
  59. +            dummy_remotename, &gc_remotename_size);
  60. +        DbgP((L"lpNetResource->lpLocalName == NULL, "
  61. +            "NPGetConnection() returned "
  62. +            "gc_status=%d, dummy_remotename='%s'\n",
  63. +            (int)gc_status, dummy_remotename));
  64. +
  65. +        if (gc_status == WN_SUCCESS) {
  66. +            /*
  67. +             * Do not return |WN_ALREADY_CONNECTED| here, as UNC
  68. +             * paths are reused
  69. +             * We explicitly use this to skip |StoreConnectionInfo()|
  70. +             * below, so we only have one stored UNC connection
  71. +             */
  72. +            Status = WN_SUCCESS;
  73. +            goto out;
  74. +        }
  75. +    }
  76. +    else {
  77.          wszScratch[0] = L'\0';
  78.          Status = QueryDosDevice(LocalName, wszScratch, 1024);
  79.          DbgP((L"QueryDosDevice(lpDeviceName='%s',lpTargetPath='%s') "
  80. @@ -669,6 +699,7 @@ NPAddConnection3(
  81.              Status = WN_ALREADY_CONNECTED;
  82.              goto out;
  83.          }
  84. +    }
  85.  
  86.      MarshalConnectionInfo(&Connection);
  87.  
  88. @@ -680,19 +711,21 @@ NPAddConnection3(
  89.          goto out;
  90.      }
  91.  
  92. -    DbgP((L"DefineDosDevice(lpNetResource->lpLocalName='%s', "
  93. +    if (lpNetResource->lpLocalName != NULL) {
  94. +        DbgP((L"DefineDosDevice(lpLocalName='%s', "
  95.              L"ConnectionName='%s')\n",
  96. -        lpNetResource->lpLocalName, ConnectionName));
  97. +            lpLocalName, ConnectionName));
  98.          if (!DefineDosDevice(DDD_RAW_TARGET_PATH |
  99.              DDD_NO_BROADCAST_SYSTEM,
  100. -        lpNetResource->lpLocalName,
  101. +            lpLocalName,
  102.              ConnectionName)) {
  103.              Status = GetLastError();
  104. -        DbgP((L"DefineDosDevice(lpNetResource->lpLocalName='%s',"
  105. +            DbgP((L"DefineDosDevice(lpLocalName='%s',"
  106.                  L"ConnectionName='%s') failed with %d\n",
  107. -            lpNetResource->lpLocalName, ConnectionName, Status));
  108. +                lpLocalName, ConnectionName, Status));
  109.              goto out_delconn;
  110.          }
  111. +    }
  112.  
  113.      // The connection was established and the local device mapping
  114.      // added. Include this in the list of mapped devices.
  115. @@ -708,10 +741,12 @@ out:
  116.      DbgP((L"<-- NPAddConnection3 returns %d\n", (int)Status));
  117.      return Status;
  118.  out_undefine:
  119. +    if (lpNetResource->lpLocalName != NULL) {
  120.          (void)DefineDosDevice(DDD_REMOVE_DEFINITION |
  121.              DDD_RAW_TARGET_PATH |
  122.              DDD_EXACT_MATCH_ON_REMOVE,
  123.              LocalName, ConnectionName);
  124. +    }
  125.  out_delconn:
  126.      SendTo_NFS41Driver(IOCTL_NFS41_DELCONN, ConnectionName,
  127.          Connection.Buffer->NameLength, NULL, &CopyBytes);
  128. @@ -836,6 +871,11 @@ NPGetConnection(
  129.  
  130.      DbgP((L"--> NPGetConnection(lpLocalName='%s')\n", lpLocalName));
  131.  
  132. +    if (lpLocalName == NULL) {
  133. +        lpLocalName = L"_:";
  134. +        DbgP((L"lpLocalName==NULL, changed to _:\n"));
  135. +    }
  136. +
  137.  #ifdef NFS41_DRIVER_USE_AUTHENTICATIONID_FOR_MOUNT_NAMESPACE
  138.      (void)get_token_authenticationid(GetCurrentThreadEffectiveToken(),
  139.          &authenticationid);

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with {%HIGHLIGHT}




All content is user-submitted.
The administrators of this site (kpaste.net) are not responsible for their content.
Abuse reports should be emailed to us at