pastebin - collaborative debugging tool
rovema.kpaste.net RSS


nfs_mount.exe -o port=... option prototype
Posted by Anonymous on Tue 19th Sep 2023 17:08
raw | new post
view followups (newest first): nfs_mount.exe -o port=... option prototype by Anonymous

  1. diff --git a/daemon/mount.c b/daemon/mount.c
  2. index 55345f6..50b986b 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 NFS14_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 NFS14_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..11917e2 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..01d19ac 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. diff --git a/daemon/nfs41_server.c b/daemon/nfs41_server.c
  129. index d58c03a..ef8f0ac 100644
  130. --- a/daemon/nfs41_server.c
  131. +++ b/daemon/nfs41_server.c
  132. @@ -338,6 +338,6 @@ out:
  133.              "error %d\n", hostname, port, status);
  134.      else
  135.          dprintf(SRVLVL, "<-- nfs41_server_resolve(%s:%u) returning "
  136. -            "%s\n", hostname, port, addrs->arr[0].uaddr);
  137. +            "OK %s\n", hostname, port, addrs->arr[0].uaddr);
  138.      return status;
  139.  }
  140. diff --git a/daemon/upcall.h b/daemon/upcall.h
  141. index fd26353..cf85598 100644
  142. --- a/daemon/upcall.h
  143. +++ b/daemon/upcall.h
  144. @@ -30,6 +30,7 @@
  145.  /* structures for upcall arguments */
  146.  typedef struct __mount_upcall_args {
  147.      const char *hostname;
  148. +    DWORD       port;
  149.      const char *path;
  150.      DWORD       sec_flavor;
  151.      DWORD       rsize;
  152. diff --git a/mount/mount.c b/mount/mount.c
  153. index 4615fc9..6d8c8ee 100644
  154. --- a/mount/mount.c
  155. +++ b/mount/mount.c
  156. @@ -61,13 +61,14 @@ static VOID PrintUsage(LPTSTR pProcess)
  157.          TEXT("\t-o <comma-separated mount options>\n")
  158.          TEXT("Mount options:\n")
  159.          TEXT("\tro\tmount as read-only\n")
  160. +        TEXT("\tport=#\tTCP port to use (defaults to 2049)\n")
  161.          TEXT("\trsize=#\tread buffer size in bytes\n")
  162.          TEXT("\twsize=#\twrite buffer size in bytes\n")
  163.          TEXT("\tsec=krb5:krb5i:krb5p\tspecify gss security flavor\n")
  164.          TEXT("\twritethru\tturns off rdbss caching for writes\n")
  165.          TEXT("\tnocache\tturns off rdbss caching\n")
  166.          TEXT("\ttimeout=#\tspecify upcall timeout value in seconds (default 120s)\n"),
  167. -        pProcess, pProcess, pProcess);
  168. +        pProcess);
  169.  }
  170.  
  171.  DWORD __cdecl _tmain(DWORD argc, LPTSTR argv[])
  172. diff --git a/sys/nfs41_driver.c b/sys/nfs41_driver.c
  173. index da9327f..242b020 100644
  174. --- a/sys/nfs41_driver.c
  175. +++ b/sys/nfs41_driver.c
  176. @@ -166,6 +166,7 @@ typedef struct _updowncall_entry {
  177.      union {
  178.          struct {
  179.              PUNICODE_STRING srv_name;
  180. +           DWORD port;
  181.              PUNICODE_STRING root;
  182.              PFILE_FS_ATTRIBUTE_INFORMATION FsAttrs;
  183.              DWORD sec_flavor;
  184. @@ -314,6 +315,7 @@ DECLARE_CONST_UNICODE_STRING(SLASH, L"\\");
  185.  DECLARE_CONST_UNICODE_STRING(EMPTY_STRING, L"");
  186.  
  187.  #define SERVER_NAME_BUFFER_SIZE         1024
  188. +#define MOUNT_CONFIG_NFS_PORT_DEFAULT   2049
  189.  #define MOUNT_CONFIG_RW_SIZE_MIN        1024
  190.  #define MOUNT_CONFIG_RW_SIZE_DEFAULT    1048576
  191.  #define MOUNT_CONFIG_RW_SIZE_MAX        1048576
  192. @@ -328,6 +330,7 @@ typedef struct _NFS41_MOUNT_CONFIG {
  193.      BOOLEAN nocache;
  194.      WCHAR srv_buffer[SERVER_NAME_BUFFER_SIZE];
  195.      UNICODE_STRING SrvName;
  196. +    DWORD Port;
  197.      WCHAR mntpt_buffer[MAX_PATH];
  198.      UNICODE_STRING MntPt;
  199.      WCHAR sec_flavor[MAX_SEC_FLAVOR_LEN];
  200. @@ -615,13 +618,15 @@ NTSTATUS marshal_nfs41_mount(
  201.          goto out;
  202.      }
  203.      header_len = *len + length_as_utf8(entry->u.Mount.srv_name) +
  204. -        length_as_utf8(entry->u.Mount.root) + 3 * sizeof(DWORD);
  205. +        length_as_utf8(entry->u.Mount.root) + 4 * sizeof(DWORD);
  206.      if (header_len > buf_len) {
  207.          status = STATUS_INSUFFICIENT_RESOURCES;
  208.          goto out;
  209.      }
  210.      status = marshall_unicode_as_utf8(&tmp, entry->u.Mount.srv_name);
  211.      if (status) goto out;
  212. +    RtlCopyMemory(tmp, &entry->u.Mount.port, sizeof(DWORD));
  213. +    tmp += sizeof(DWORD);
  214.      status = marshall_unicode_as_utf8(&tmp, entry->u.Mount.root);
  215.      if (status) goto out;
  216.      RtlCopyMemory(tmp, &entry->u.Mount.sec_flavor, sizeof(DWORD));
  217. @@ -633,8 +638,9 @@ NTSTATUS marshal_nfs41_mount(
  218.      *len = header_len;
  219.  
  220.  #ifdef DEBUG_MARSHAL_DETAIL
  221. -    DbgP("marshal_nfs41_mount: server name=%wZ mount point=%wZ sec_flavor=%s "
  222. -         "rsize=%d wsize=%d\n", entry->u.Mount.srv_name, entry->u.Mount.root,
  223. +    DbgP("marshal_nfs41_mount: server name=%wZ port=%d mount point=%wZ "
  224. +         "sec_flavor=%s rsize=%d wsize=%d\n",
  225. +        entry->u.Mount.srv_name, entry->u.Mount.port, entry->u.Mount.root,
  226.           secflavorop2name(entry->u.Mount.sec_flavor), entry->u.Mount.rsize,
  227.           entry->u.Mount.wsize);
  228.  #endif
  229. @@ -2574,6 +2580,7 @@ NTSTATUS nfs41_mount(
  230.      if (status) goto out;
  231.  
  232.      entry->u.Mount.srv_name = &config->SrvName;
  233. +    entry->u.Mount.port = config->Port;
  234.      entry->u.Mount.root = &config->MntPt;
  235.      entry->u.Mount.rsize = config->ReadSize;
  236.      entry->u.Mount.wsize = config->WriteSize;
  237. @@ -2606,6 +2613,7 @@ void nfs41_MountConfig_InitDefaults(
  238.  {
  239.      RtlZeroMemory(Config, sizeof(NFS41_MOUNT_CONFIG));
  240.  
  241. +    Config->Port = MOUNT_CONFIG_NFS_PORT_DEFAULT;
  242.      Config->ReadSize = MOUNT_CONFIG_RW_SIZE_DEFAULT;
  243.      Config->WriteSize = MOUNT_CONFIG_RW_SIZE_DEFAULT;
  244.      Config->ReadOnly = FALSE;
  245. @@ -2724,6 +2732,11 @@ NTSTATUS nfs41_MountConfig_ParseOptions(
  246.              else
  247.                  RtlCopyUnicodeString(&Config->SrvName, &usValue);
  248.          }
  249. +        else if (wcsncmp(L"port", Name, NameLen) == 0) {
  250. +            status = nfs41_MountConfig_ParseDword(Option, &usValue,
  251. +                &Config->Port, 1,
  252. +                65535);
  253. +        }
  254.          else if (wcsncmp(L"mntpt", Name, NameLen) == 0) {
  255.              if (usValue.Length > Config->MntPt.MaximumLength)
  256.                  status = STATUS_NAME_TOO_LONG;

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