pastebin - collaborative debugging tool
rovema.kpaste.net RSS


nfs_mount.exe -o port=... option prototype
Posted by Anonymous on Wed 20th Sep 2023 15:07
raw | new post
view followups (newest first): nfs_mount.exe -o port=... option patch by Anonymous
modification of post by Anonymous (view diff)

  1. diff --git a/daemon/mount.c b/daemon/mount.c
  2. index 55345f6..3b18cba 100644
  3. --- a/daemon/mount.c
  4. +++ b/daemon/mount.c
  5. @@ -37,6 +37,8 @@ static int parse_mount(unsigned char *buffer, uint32_t length, nfs41_upcall *upc
  6.  
  7.      status = get_name(&buffer, &length, &args->hostname);
  8.      if(status) goto out;
  9. +    status = safe_read(&buffer, &length, &args->port, sizeof(DWORD));
  10. +    if (status) goto out;
  11.      status = get_name(&buffer, &length, &args->path);
  12.      if(status) goto out;
  13.      status = safe_read(&buffer, &length, &args->sec_flavor, sizeof(DWORD));
  14. @@ -46,10 +48,12 @@ static int parse_mount(unsigned char *buffer, uint32_t length, nfs41_upcall *upc
  15.      status = safe_read(&buffer, &length, &args->wsize, sizeof(DWORD));
  16.      if (status) goto out;
  17.  
  18. -    dprintf(1, "parsing NFS14_MOUNT: srv_name=%s root=%s sec_flavor=%s "
  19. -        "rsize=%d wsize=%d\n", args->hostname, args->path,
  20. +    dprintf(1, "parsing NFS41_MOUNT: srv_name=%s port=%d root=%s "
  21. +        "sec_flavor=%s rsize=%d wsize=%d\n", args->hostname, args->port, args->path,
  22.          secflavorop2name(args->sec_flavor), args->rsize, args->wsize);
  23. +    return status;
  24.  out:
  25. +    dprintf(1, "parsing NFS41_MOUNT: failed %d\n", status);
  26.      return status;
  27.  }
  28.  
  29. @@ -64,7 +68,7 @@ static int handle_mount(nfs41_upcall *upcall)
  30.      nfs41_path_fh file;
  31.  
  32.      // resolve hostname,port
  33. -    status = nfs41_server_resolve(args->hostname, 2049, &addrs);
  34. +    status = nfs41_server_resolve(args->hostname, (unsigned short)args->port, &addrs);
  35.      if (status) {
  36.          eprintf("nfs41_server_resolve() failed with %d\n", status);
  37.          goto out;
  38. @@ -76,7 +80,7 @@ static int handle_mount(nfs41_upcall *upcall)
  39.          root = upcall->root_ref;
  40.      } else {
  41.          // create root
  42. -        status = nfs41_root_create(args->hostname, args->sec_flavor,
  43. +        status = nfs41_root_create(args->hostname, args->port, args->sec_flavor,
  44.              args->wsize + WRITE_OVERHEAD, args->rsize + READ_OVERHEAD, &root);
  45.          if (status) {
  46.              eprintf("nfs41_root_create() failed %d\n", status);
  47. diff --git a/daemon/namespace.c b/daemon/namespace.c
  48. index ab16f49..e3ea077 100644
  49. --- a/daemon/namespace.c
  50. +++ b/daemon/namespace.c
  51. @@ -36,6 +36,7 @@
  52.  /* nfs41_root */
  53.  int nfs41_root_create(
  54.      IN const char *name,
  55. +    IN uint32_t port,
  56.      IN uint32_t sec_flavor,
  57.      IN uint32_t wsize,
  58.      IN uint32_t rsize,
  59. @@ -44,7 +45,7 @@ int nfs41_root_create(
  60.      int status = NO_ERROR;
  61.      nfs41_root *root;
  62.  
  63. -    dprintf(NSLVL, "--> nfs41_root_create()\n");
  64. +    dprintf(NSLVL, "--> nfs41_root_create(name=%s, port=%d)\n", name, port);
  65.  
  66.      root = calloc(1, sizeof(nfs41_root));
  67.      if (root == NULL) {
  68. @@ -60,7 +61,7 @@ int nfs41_root_create(
  69.      root->sec_flavor = sec_flavor;
  70.  
  71.      /* generate a unique client_owner */
  72. -    status = nfs41_client_owner(name, sec_flavor, &root->client_owner);
  73. +    status = nfs41_client_owner(name, port, sec_flavor, &root->client_owner);
  74.      if (status) {
  75.          eprintf("nfs41_client_owner() failed with %d\n", status);
  76.          free(root);
  77. @@ -443,6 +444,8 @@ static int referral_mount_location(
  78.      int status = ERROR_BAD_NET_NAME;
  79.      uint32_t i;
  80.  
  81. +    dprintf(NSLVL, "--> referral_mount_location()\n");
  82. +
  83.      /* create a client and session for the first available server */
  84.      for (i = 0; i < loc->server_count; i++) {
  85.          /* XXX: only deals with 'address' as a hostname with default port */
  86. @@ -453,6 +456,9 @@ static int referral_mount_location(
  87.          if (status == NO_ERROR)
  88.              break;
  89.      }
  90. +
  91. +    dprintf(NSLVL, "<-- referral_mount_location() returning %d\n", status);
  92. +
  93.      return status;
  94.  }
  95.  
  96. diff --git a/daemon/nfs41.h b/daemon/nfs41.h
  97. index aa679a6..3902393 100644
  98. --- a/daemon/nfs41.h
  99. +++ b/daemon/nfs41.h
  100. @@ -287,6 +287,7 @@ typedef struct __nfs41_root {
  101.  /* nfs41_namespace.c */
  102.  int nfs41_root_create(
  103.      IN const char *name,
  104. +    IN uint32_t port,
  105.      IN uint32_t sec_flavor,
  106.      IN uint32_t wsize,
  107.      IN uint32_t rsize,
  108. @@ -404,6 +405,7 @@ void nfs41_server_addrs(
  109.  /* nfs41_client.c */
  110.  int nfs41_client_owner(
  111.      IN const char *name,
  112. +    IN uint32_t port,
  113.      IN uint32_t sec_flavor,
  114.      OUT client_owner4 *owner);
  115.  
  116. diff --git a/daemon/nfs41_client.c b/daemon/nfs41_client.c
  117. index 0460fc5..f5bac1d 100644
  118. --- a/daemon/nfs41_client.c
  119. +++ b/daemon/nfs41_client.c
  120. @@ -353,6 +353,7 @@ out:
  121.  
  122.  int nfs41_client_owner(
  123.      IN const char *name,
  124. +    IN uint32_t port,
  125.      IN uint32_t sec_flavor,
  126.      OUT client_owner4 *owner)
  127.  {
  128. @@ -405,6 +406,12 @@ int nfs41_client_owner(
  129.          goto out_hash;
  130.      }
  131.  
  132. +    if (!CryptHashData(hash, (const BYTE*)&port, (DWORD)sizeof(port), 0)) {
  133. +        status = GetLastError();
  134. +        eprintf("CryptHashData() failed with %d\n", status);
  135. +        goto out_hash;
  136. +    }
  137. +
  138.      /* add the mac address from each applicable adapter to the hash */
  139.      status = hash_mac_addrs(hash);
  140.      if (status) {
  141. diff --git a/daemon/nfs41_server.c b/daemon/nfs41_server.c
  142. index d58c03a..ef8f0ac 100644
  143. --- a/daemon/nfs41_server.c
  144. +++ b/daemon/nfs41_server.c
  145. @@ -338,6 +338,6 @@ out:
  146.              "error %d\n", hostname, port, status);
  147.      else
  148.          dprintf(SRVLVL, "<-- nfs41_server_resolve(%s:%u) returning "
  149. -            "%s\n", hostname, port, addrs->arr[0].uaddr);
  150. +            "OK %s\n", hostname, port, addrs->arr[0].uaddr);
  151.      return status;
  152.  }
  153. diff --git a/daemon/upcall.h b/daemon/upcall.h
  154. index fd26353..9cdc0a1 100644
  155. --- a/daemon/upcall.h
  156. +++ b/daemon/upcall.h
  157. @@ -30,6 +30,7 @@
  158.  /* structures for upcall arguments */
  159.  typedef struct __mount_upcall_args {
  160.      const char *hostname;
  161. +    DWORD       port;
  162.      const char *path;
  163.      DWORD       sec_flavor;
  164.      DWORD       rsize;
  165. diff --git a/libtirpc/src/pmap_getport.c b/libtirpc/src/pmap_getport.c
  166. index 45c8b1c..4d3a277 100644
  167. --- a/libtirpc/src/pmap_getport.c
  168. +++ b/libtirpc/src/pmap_getport.c
  169. @@ -62,6 +62,7 @@ pmap_getport(address, program, version, protocol)
  170.         u_long version;
  171.         u_int protocol;
  172.  {
  173. +       (void)fprintf(stderr, "pmap_getport: returning default NFS port 2049\n");
  174.         return (u_short)2049;
  175.  }
  176.  #else
  177. @@ -106,4 +107,4 @@ pmap_getport(address, program, version, protocol)
  178.         address->sin_port = 0;
  179.         return (port);
  180.  }
  181. -#endif /* ! _WIN32 */
  182. \ No newline at end of file
  183. +#endif /* ! _WIN32 */
  184. diff --git a/mount/mount.c b/mount/mount.c
  185. index 4615fc9..6d8c8ee 100644
  186. --- a/mount/mount.c
  187. +++ b/mount/mount.c
  188. @@ -61,13 +61,14 @@ static VOID PrintUsage(LPTSTR pProcess)
  189.          TEXT("\t-o <comma-separated mount options>\n")
  190.          TEXT("Mount options:\n")
  191.          TEXT("\tro\tmount as read-only\n")
  192. +        TEXT("\tport=#\tTCP port to use (defaults to 2049)\n")
  193.          TEXT("\trsize=#\tread buffer size in bytes\n")
  194.          TEXT("\twsize=#\twrite buffer size in bytes\n")
  195.          TEXT("\tsec=krb5:krb5i:krb5p\tspecify gss security flavor\n")
  196.          TEXT("\twritethru\tturns off rdbss caching for writes\n")
  197.          TEXT("\tnocache\tturns off rdbss caching\n")
  198.          TEXT("\ttimeout=#\tspecify upcall timeout value in seconds (default 120s)\n"),
  199. -        pProcess, pProcess, pProcess);
  200. +        pProcess);
  201.  }
  202.  
  203.  DWORD __cdecl _tmain(DWORD argc, LPTSTR argv[])
  204. diff --git a/sys/nfs41_driver.c b/sys/nfs41_driver.c
  205. index da9327f..080679e 100644
  206. --- a/sys/nfs41_driver.c
  207. +++ b/sys/nfs41_driver.c
  208. @@ -166,6 +166,7 @@ typedef struct _updowncall_entry {
  209.      union {
  210.          struct {
  211.              PUNICODE_STRING srv_name;
  212. +           DWORD port;
  213.              PUNICODE_STRING root;
  214.              PFILE_FS_ATTRIBUTE_INFORMATION FsAttrs;
  215.              DWORD sec_flavor;
  216. @@ -314,6 +315,7 @@ DECLARE_CONST_UNICODE_STRING(SLASH, L"\\");
  217.  DECLARE_CONST_UNICODE_STRING(EMPTY_STRING, L"");
  218.  
  219.  #define SERVER_NAME_BUFFER_SIZE         1024
  220. +#define MOUNT_CONFIG_NFS_PORT_DEFAULT   2049
  221.  #define MOUNT_CONFIG_RW_SIZE_MIN        1024
  222.  #define MOUNT_CONFIG_RW_SIZE_DEFAULT    1048576
  223.  #define MOUNT_CONFIG_RW_SIZE_MAX        1048576
  224. @@ -328,6 +330,7 @@ typedef struct _NFS41_MOUNT_CONFIG {
  225.      BOOLEAN nocache;
  226.      WCHAR srv_buffer[SERVER_NAME_BUFFER_SIZE];
  227.      UNICODE_STRING SrvName;
  228. +    DWORD Port;
  229.      WCHAR mntpt_buffer[MAX_PATH];
  230.      UNICODE_STRING MntPt;
  231.      WCHAR sec_flavor[MAX_SEC_FLAVOR_LEN];
  232. @@ -364,6 +367,15 @@ typedef struct _NFS41_V_NET_ROOT_EXTENSION {
  233.      FILE_FS_ATTRIBUTE_INFORMATION FsAttrs;
  234.      DWORD                   sec_flavor;
  235.      DWORD                   timeout;
  236. +    /*
  237. +     * gisburn: FIXME: Putting |port| here is wrong:
  238. +     * TCP port information should be encoded in the server name
  239. +     * (e.g. \\server@port\nfs4\path, to make sure we do not get
  240. +     * conflicts in case of (ssh) port forwarding
  241. +     * (see https://learn.microsoft.com/en-gb/windows/win32/api/davclnt/nf-davclnt-davgethttpfromuncpath
  242. +     * how to specify ports in an UNC path)
  243. +     */
  244. +    DWORD                   port;
  245.      USHORT                  MountPathLen;
  246.      BOOLEAN                 read_only;
  247.      BOOLEAN                 write_thru;
  248. @@ -615,13 +627,15 @@ NTSTATUS marshal_nfs41_mount(
  249.          goto out;
  250.      }
  251.      header_len = *len + length_as_utf8(entry->u.Mount.srv_name) +
  252. -        length_as_utf8(entry->u.Mount.root) + 3 * sizeof(DWORD);
  253. +        length_as_utf8(entry->u.Mount.root) + 4 * sizeof(DWORD);
  254.      if (header_len > buf_len) {
  255.          status = STATUS_INSUFFICIENT_RESOURCES;
  256.          goto out;
  257.      }
  258.      status = marshall_unicode_as_utf8(&tmp, entry->u.Mount.srv_name);
  259.      if (status) goto out;
  260. +    RtlCopyMemory(tmp, &entry->u.Mount.port, sizeof(DWORD));
  261. +    tmp += sizeof(DWORD);
  262.      status = marshall_unicode_as_utf8(&tmp, entry->u.Mount.root);
  263.      if (status) goto out;
  264.      RtlCopyMemory(tmp, &entry->u.Mount.sec_flavor, sizeof(DWORD));
  265. @@ -633,8 +647,9 @@ NTSTATUS marshal_nfs41_mount(
  266.      *len = header_len;
  267.  
  268.  #ifdef DEBUG_MARSHAL_DETAIL
  269. -    DbgP("marshal_nfs41_mount: server name=%wZ mount point=%wZ sec_flavor=%s "
  270. -         "rsize=%d wsize=%d\n", entry->u.Mount.srv_name, entry->u.Mount.root,
  271. +    DbgP("marshal_nfs41_mount: server name=%wZ port=%d mount point=%wZ "
  272. +         "sec_flavor=%s rsize=%d wsize=%d\n",
  273. +        entry->u.Mount.srv_name, entry->u.Mount.port, entry->u.Mount.root,
  274.           secflavorop2name(entry->u.Mount.sec_flavor), entry->u.Mount.rsize,
  275.           entry->u.Mount.wsize);
  276.  #endif
  277. @@ -2566,14 +2581,15 @@ NTSTATUS nfs41_mount(
  278.  
  279.  #ifdef DEBUG_MOUNT
  280.      DbgEn();
  281. -    DbgP("Server Name %wZ Mount Point %wZ SecFlavor %d\n",
  282. -        &config->SrvName, &config->MntPt, sec_flavor);
  283. +    DbgP("Server Name %wZ Port %d Mount Point %wZ SecFlavor %d\n",
  284. +        &config->SrvName, config->Port, &config->MntPt, sec_flavor);
  285.  #endif
  286.      status = nfs41_UpcallCreate(NFS41_MOUNT, NULL, *session,
  287.          INVALID_HANDLE_VALUE, *version, &config->MntPt, &entry);
  288.      if (status) goto out;
  289.  
  290.      entry->u.Mount.srv_name = &config->SrvName;
  291. +    entry->u.Mount.port = config->Port;
  292.      entry->u.Mount.root = &config->MntPt;
  293.      entry->u.Mount.rsize = config->ReadSize;
  294.      entry->u.Mount.wsize = config->WriteSize;
  295. @@ -2606,6 +2622,7 @@ void nfs41_MountConfig_InitDefaults(
  296.  {
  297.      RtlZeroMemory(Config, sizeof(NFS41_MOUNT_CONFIG));
  298.  
  299. +    Config->Port = MOUNT_CONFIG_NFS_PORT_DEFAULT;
  300.      Config->ReadSize = MOUNT_CONFIG_RW_SIZE_DEFAULT;
  301.      Config->WriteSize = MOUNT_CONFIG_RW_SIZE_DEFAULT;
  302.      Config->ReadOnly = FALSE;
  303. @@ -2724,6 +2741,11 @@ NTSTATUS nfs41_MountConfig_ParseOptions(
  304.              else
  305.                  RtlCopyUnicodeString(&Config->SrvName, &usValue);
  306.          }
  307. +        else if (wcsncmp(L"port", Name, NameLen) == 0) {
  308. +            status = nfs41_MountConfig_ParseDword(Option, &usValue,
  309. +                &Config->Port, 1,
  310. +                65535);
  311. +        }
  312.          else if (wcsncmp(L"mntpt", Name, NameLen) == 0) {
  313.              if (usValue.Length > Config->MntPt.MaximumLength)
  314.                  status = STATUS_NAME_TOO_LONG;
  315. @@ -2910,6 +2932,8 @@ NTSTATUS nfs41_CreateVNetRoot(
  316.      nfs41_MountConfig_InitDefaults(Config);
  317.  
  318.      if (pCreateNetRootContext->RxContext->Create.EaLength) {
  319. +        /* Codepath for nfs_mount.exe */
  320. +
  321.          /* parse the extended attributes for mount options */
  322.          status = nfs41_MountConfig_ParseOptions(
  323.              pCreateNetRootContext->RxContext->Create.EaBuffer,
  324. @@ -2920,13 +2944,25 @@ NTSTATUS nfs41_CreateVNetRoot(
  325.          pVNetRootContext->read_only = Config->ReadOnly;
  326.          pVNetRootContext->write_thru = Config->write_thru;
  327.          pVNetRootContext->nocache = Config->nocache;        
  328. +       pVNetRootContext->port = Config->Port;
  329.      } else {
  330. +        /* Codepath for \\server:port\nfs4\path */
  331. +
  332.          /* use the SRV_CALL name (without leading \) as the hostname */
  333.          Config->SrvName.Buffer = pSrvCall->pSrvCallName->Buffer + 1;
  334.          Config->SrvName.Length =
  335.              pSrvCall->pSrvCallName->Length - sizeof(WCHAR);
  336.          Config->SrvName.MaximumLength =
  337.              pSrvCall->pSrvCallName->MaximumLength - sizeof(WCHAR);
  338. +        /*
  339. +         * gisburn: FIXME: Using |port| here is wrong:
  340. +         * TCP port information should be encoded in the server name
  341. +         * (e.g. \\server@port\nfs4\path, to make sure we do not get
  342. +         * conflicts in case of (ssh) port forwarding
  343. +        * (see https://learn.microsoft.com/en-gb/windows/win32/api/davclnt/nf-davclnt-davgethttpfromuncpath
  344. +        * how to specify ports in an UNC path)
  345. +         */
  346. +       Config->Port = pVNetRootContext->port;
  347.      }
  348.      pVNetRootContext->MountPathLen = Config->MntPt.Length;
  349.      pVNetRootContext->timeout = Config->timeout;

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