pastebin - collaborative debugging tool
rovema.kpaste.net RSS

Difference between
modified post 648114bfd by Anonymous on Thu 21st Sep 2023 12:45
original post b120881 by Anonymous on Wed 20th Sep 2023 15:07
Download diff
Show old version | new version | both versions

    
1-
diff --git a/daemon/mount.c b/daemon/mount.c
1+
From 98d73158a24ddd85794925d5f6147efe30fe9333 Mon Sep 17 00:00:00 2001
2-
index 55345f6..3b18cba 100644
2+
From: Roland Mainz <roland.mainz@nrubsig.org>
3-
--- a/daemon/mount.c
3+
Date: Thu, 21 Sep 2023 13:13:30 +0200
4-
+++ b/daemon/mount.c
4+
Subject: [PATCH] nfs_mount.exe should support the -o port=portnum mount option
65
7-
     status = get_name(&buffer, &length, &args->hostname);
6+
Implement support for the -o port=portnum option in nfs_mount.exe,
8-
     if(status) goto out;
7+
specifying the numeric value of the server's NFSv4 service port.
9-
+    status = safe_read(&buffer, &length, &args->port, sizeof(DWORD));
8+
If the server's NFSv4 service is not available on the specified port,
10-
+    if (status) goto out;
9+
the mount request fails.
1710
18-
-    dprintf(1, "parsing NFS14_MOUNT: srv_name=%s root=%s sec_flavor=%s "
11+
This option allows the NFS version 4.x client to contact an NFS
19-
-        "rsize=%d wsize=%d\n", args->hostname, args->path,
12+
version 4 server through a firewall, or accesing NFS version 4
20-
+    dprintf(1, "parsing NFS41_MOUNT: srv_name=%s port=%d root=%s "
13+
filesystems via ssh TCP port forwarding.
2814
29-
@@ -64,7 +68,7 @@ static int handle_mount(nfs41_upcall *upcall)
15+
If this mount option is not specified, the NFS client uses the
30-
     nfs41_path_fh file;
16+
standard NFS TCP port number of 2049.
3117
32-
     // resolve hostname,port
18+
** Example usage (using Cygwin 3.5.x):
33-
-    status = nfs41_server_resolve(args->hostname, 2049, &addrs);
19+
---- snip ----
34-
+    status = nfs41_server_resolve(args->hostname, (unsigned short)args->port, &addrs);
20+
wget 'http://svn.nrubsig.org/svn/people/gisburn/scripts/mount_sshnfs/mount_sshnfs.ksh'
35-
     if (status) {
21+
36-
         eprintf("nfs41_server_resolve() failed with %d\n", status);
22+
mkdir /foobarmnt
37-
         goto out;
23+
ksh93 ./mount_sshnfs.ksh mount -o mount_sshnfs_local_forward_port=49000 ssh+nfs://gisburn@chickenmonster/export/home/gisburn /foobarmnt
38-
@@ -76,7 +80,7 @@ static int handle_mount(nfs41_upcall *upcall)
24+
39-
         root = upcall->root_ref;
25+
ls -l /foobarmnt
40-
     } else {
26+
41-
         // create root
27+
ksh93 ./mount_sshnfs.ksh umount /foobarmnt
42-
-        status = nfs41_root_create(args->hostname, args->sec_flavor,
28+
---- snip ----
43-
+        status = nfs41_root_create(args->hostname, args->port, args->sec_flavor,
29+
44-
             args->wsize + WRITE_OVERHEAD, args->rsize + READ_OVERHEAD, &root);
30+
** Limitations:
45-
         if (status) {
31+
- Right now only one custom port number can be used, see
46-
             eprintf("nfs41_root_create() failed %d\n", status);
32+
SAVE_PORT_HACK in sys/nfs41_driver.c. This will be fixed in the
47-
diff --git a/daemon/namespace.c b/daemon/namespace.c
33+
future by encoding the port number in the hostname part of the UNC
48-
index ab16f49..e3ea077 100644
34+
path, e.g. \\server@port\nfs4\path
49-
--- a/daemon/namespace.c
35+
50-
+++ b/daemon/namespace.c
36+
Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
51-
@@ -36,6 +36,7 @@
37+
---
52-
 /* nfs41_root */
38+
 daemon/mount.c              | 12 ++++++----
53-
 int nfs41_root_create(
39+
 daemon/namespace.c          | 10 ++++++--
54-
     IN const char *name,
40+
 daemon/nfs41.h              |  2 ++
55-
+    IN uint32_t port,
41+
 daemon/nfs41_client.c       |  7 ++++++
56-
     IN uint32_t sec_flavor,
42+
 daemon/nfs41_server.c       |  2 +-
57-
     IN uint32_t wsize,
43+
 daemon/upcall.h             |  1 +
58-
     IN uint32_t rsize,
44+
 libtirpc/src/pmap_getport.c |  3 ++-
59-
@@ -44,7 +45,7 @@ int nfs41_root_create(
45+
 mount/mount.c               |  3 ++-
60-
     int status = NO_ERROR;
46+
 sys/nfs41_driver.c          | 47 +++++++++++++++++++++++++++++++++----
61-
     nfs41_root *root;
47+
 9 files changed, 73 insertions(+), 14 deletions(-)
6248
63-
-    dprintf(NSLVL, "--> nfs41_root_create()\n");
49+
diff --git a/daemon/mount.c b/daemon/mount.c
64-
+    dprintf(NSLVL, "--> nfs41_root_create(name=%s, port=%d)\n", name, port);
50+
index 55345f6..3b18cba 100644
51+
--- a/daemon/mount.c
6554
66-
     root = calloc(1, sizeof(nfs41_root));
55+
     status = get_name(&buffer, &length, &args->hostname);
67-
     if (root == NULL) {
56+
     if(status) goto out;
68-
@@ -60,7 +61,7 @@ int nfs41_root_create(
57+
+    status = safe_read(&buffer, &length, &args->port, sizeof(DWORD));
69-
     root->sec_flavor = sec_flavor;
58+
+    if (status) goto out;
59+
     status = get_name(&buffer, &length, &args->path);
7065
71-
     /* generate a unique client_owner */
66+
-    dprintf(1, "parsing NFS14_MOUNT: srv_name=%s root=%s sec_flavor=%s "
72-
-    status = nfs41_client_owner(name, sec_flavor, &root->client_owner);
67+
-        "rsize=%d wsize=%d\n", args->hostname, args->path,
73-
+    status = nfs41_client_owner(name, port, sec_flavor, &root->client_owner);
68+
+    dprintf(1, "parsing NFS41_MOUNT: srv_name=%s port=%d root=%s "
74-
     if (status) {
69+
+        "sec_flavor=%s rsize=%d wsize=%d\n", args->hostname, args->port, args->path,
75-
         eprintf("nfs41_client_owner() failed with %d\n", status);
70+
         secflavorop2name(args->sec_flavor), args->rsize, args->wsize);
76-
         free(root);
71+
+    return status;
77-
@@ -443,6 +444,8 @@ static int referral_mount_location(
72+
 out:
78-
     int status = ERROR_BAD_NET_NAME;
73+
+    dprintf(1, "parsing NFS41_MOUNT: failed %d\n", status);
79-
     uint32_t i;
74+
     return status;
75+
 }
8076
81-
+    dprintf(NSLVL, "--> referral_mount_location()\n");
77+
@@ -64,7 +68,7 @@ static int handle_mount(nfs41_upcall *upcall)
82-
+
78+
     nfs41_path_fh file;
83-
     /* create a client and session for the first available server */
79+
84-
     for (i = 0; i < loc->server_count; i++) {
80+
     // resolve hostname,port
85-
         /* XXX: only deals with 'address' as a hostname with default port */
81+
-    status = nfs41_server_resolve(args->hostname, 2049, &addrs);
86-
@@ -453,6 +456,9 @@ static int referral_mount_location(
82+
+    status = nfs41_server_resolve(args->hostname, (unsigned short)args->port, &addrs);
87-
         if (status == NO_ERROR)
83+
     if (status) {
88-
             break;
84+
         eprintf("nfs41_server_resolve() failed with %d\n", status);
89-
     }
85+
         goto out;
90-
+
86+
@@ -76,7 +80,7 @@ static int handle_mount(nfs41_upcall *upcall)
91-
+    dprintf(NSLVL, "<-- referral_mount_location() returning %d\n", status);
87+
         root = upcall->root_ref;
92-
+
88+
     } else {
93-
     return status;
89+
         // create root
94-
 }
90+
-        status = nfs41_root_create(args->hostname, args->sec_flavor,
95-
91+
+        status = nfs41_root_create(args->hostname, args->port, args->sec_flavor,
96-
diff --git a/daemon/nfs41.h b/daemon/nfs41.h
92+
             args->wsize + WRITE_OVERHEAD, args->rsize + READ_OVERHEAD, &root);
97-
index aa679a6..3902393 100644
93+
         if (status) {
98-
--- a/daemon/nfs41.h
94+
             eprintf("nfs41_root_create() failed %d\n", status);
99-
+++ b/daemon/nfs41.h
95+
diff --git a/daemon/namespace.c b/daemon/namespace.c
100-
@@ -287,6 +287,7 @@ typedef struct __nfs41_root {
96+
index ab16f49..e3ea077 100644
101-
 /* nfs41_namespace.c */
97+
--- a/daemon/namespace.c
98+
+++ b/daemon/namespace.c
102101
 int nfs41_root_create(
103102
     IN const char *name,
104103
+    IN uint32_t port,
105104
     IN uint32_t sec_flavor,
106105
     IN uint32_t wsize,
107106
     IN uint32_t rsize,
108-
@@ -404,6 +405,7 @@ void nfs41_server_addrs(
107+
@@ -44,7 +45,7 @@ int nfs41_root_create(
109-
 /* nfs41_client.c */
108+
     int status = NO_ERROR;
110-
 int nfs41_client_owner(
109+
     nfs41_root *root;
115110
116-
diff --git a/daemon/nfs41_client.c b/daemon/nfs41_client.c
111+
-    dprintf(NSLVL, "--> nfs41_root_create()\n");
117-
index 0460fc5..f5bac1d 100644
112+
+    dprintf(NSLVL, "--> nfs41_root_create(name=%s, port=%d)\n", name, port);
121113
122-
 int nfs41_client_owner(
114+
     root = calloc(1, sizeof(nfs41_root));
123-
     IN const char *name,
115+
     if (root == NULL) {
124-
+    IN uint32_t port,
116+
@@ -60,7 +61,7 @@ int nfs41_root_create(
125-
     IN uint32_t sec_flavor,
117+
     root->sec_flavor = sec_flavor;
131118
132-
+    if (!CryptHashData(hash, (const BYTE*)&port, (DWORD)sizeof(port), 0)) {
119+
     /* generate a unique client_owner */
133-
+        status = GetLastError();
120+
-    status = nfs41_client_owner(name, sec_flavor, &root->client_owner);
134-
+        eprintf("CryptHashData() failed with %d\n", status);
121+
+    status = nfs41_client_owner(name, port, sec_flavor, &root->client_owner);
140122
     if (status) {
141-
diff --git a/daemon/nfs41_server.c b/daemon/nfs41_server.c
123+
         eprintf("nfs41_client_owner() failed with %d\n", status);
142-
index d58c03a..ef8f0ac 100644
124+
         free(root);
143-
--- a/daemon/nfs41_server.c
125+
@@ -443,6 +444,8 @@ static int referral_mount_location(
144-
+++ b/daemon/nfs41_server.c
126+
     int status = ERROR_BAD_NET_NAME;
145-
@@ -338,6 +338,6 @@ out:
127+
     uint32_t i;
146-
             "error %d\n", hostname, port, status);
128+
147-
     else
129+
+    dprintf(NSLVL, "--> referral_mount_location()\n");
148-
         dprintf(SRVLVL, "<-- nfs41_server_resolve(%s:%u) returning "
130+
+
149-
-            "%s\n", hostname, port, addrs->arr[0].uaddr);
131+
     /* create a client and session for the first available server */
150-
+            "OK %s\n", hostname, port, addrs->arr[0].uaddr);
132+
     for (i = 0; i < loc->server_count; i++) {
133+
         /* XXX: only deals with 'address' as a hostname with default port */
152137
 }
153-
diff --git a/daemon/upcall.h b/daemon/upcall.h
138+
+
154-
index fd26353..9cdc0a1 100644
139+
+    dprintf(NSLVL, "<-- referral_mount_location() returning %d\n", status);
155-
--- a/daemon/upcall.h
140+
+
156-
+++ b/daemon/upcall.h
141+
     return status;
157-
@@ -30,6 +30,7 @@
142+
 }
158-
 /* structures for upcall arguments */
143+
159-
 typedef struct __mount_upcall_args {
144+
diff --git a/daemon/nfs41.h b/daemon/nfs41.h
160-
     const char *hostname;
145+
index aa679a6..3902393 100644
161-
+    DWORD       port;
146+
--- a/daemon/nfs41.h
162-
     const char *path;
147+
+++ b/daemon/nfs41.h
163-
     DWORD       sec_flavor;
148+
@@ -287,6 +287,7 @@ typedef struct __nfs41_root {
164-
     DWORD       rsize;
149+
 /* nfs41_namespace.c */
165-
diff --git a/libtirpc/src/pmap_getport.c b/libtirpc/src/pmap_getport.c
150+
 int nfs41_root_create(
166-
index 45c8b1c..4d3a277 100644
151+
     IN const char *name,
167-
--- a/libtirpc/src/pmap_getport.c
152+
+    IN uint32_t port,
168-
+++ b/libtirpc/src/pmap_getport.c
153+
     IN uint32_t sec_flavor,
169-
@@ -62,6 +62,7 @@ pmap_getport(address, program, version, protocol)
154+
     IN uint32_t wsize,
170-
 	u_long version;
155+
     IN uint32_t rsize,
171-
 	u_int protocol;
156+
@@ -404,6 +405,7 @@ void nfs41_server_addrs(
172-
 {
157+
 /* nfs41_client.c */
173-
+	(void)fprintf(stderr, "pmap_getport: returning default NFS port 2049\n");
158+
 int nfs41_client_owner(
174-
 	return (u_short)2049;
159+
     IN const char *name,
175-
 }
160+
+    IN uint32_t port,
176-
 #else
161+
     IN uint32_t sec_flavor,
177-
@@ -106,4 +107,4 @@ pmap_getport(address, program, version, protocol)
162+
     OUT client_owner4 *owner);
178-
 	address->sin_port = 0;
163+
179-
 	return (port);
164+
diff --git a/daemon/nfs41_client.c b/daemon/nfs41_client.c
180-
 }
165+
index 0460fc5..f5bac1d 100644
181-
-#endif /* ! _WIN32 */
166+
--- a/daemon/nfs41_client.c
182-
\ No newline at end of file
167+
+++ b/daemon/nfs41_client.c
183-
+#endif /* ! _WIN32 */
168+
@@ -353,6 +353,7 @@ out:
184-
diff --git a/mount/mount.c b/mount/mount.c
169+
185-
index 4615fc9..6d8c8ee 100644
170+
 int nfs41_client_owner(
186-
--- a/mount/mount.c
171+
     IN const char *name,
187-
+++ b/mount/mount.c
172+
+    IN uint32_t port,
188-
@@ -61,13 +61,14 @@ static VOID PrintUsage(LPTSTR pProcess)
173+
     IN uint32_t sec_flavor,
189-
         TEXT("\t-o <comma-separated mount options>\n")
174+
     OUT client_owner4 *owner)
190-
         TEXT("Mount options:\n")
175+
 {
191-
         TEXT("\tro\tmount as read-only\n")
176+
@@ -405,6 +406,12 @@ int nfs41_client_owner(
192-
+        TEXT("\tport=#\tTCP port to use (defaults to 2049)\n")
177+
         goto out_hash;
201178
 }
202179
203-
 DWORD __cdecl _tmain(DWORD argc, LPTSTR argv[])
180+
+    if (!CryptHashData(hash, (const BYTE*)&port, (DWORD)sizeof(port), 0)) {
204-
diff --git a/sys/nfs41_driver.c b/sys/nfs41_driver.c
181+
+        status = GetLastError();
205-
index da9327f..080679e 100644
182+
+        eprintf("CryptHashData() failed with %d\n", status);
206-
--- a/sys/nfs41_driver.c
183+
+        goto out_hash;
207-
+++ b/sys/nfs41_driver.c
184+
+    }
208-
@@ -166,6 +166,7 @@ typedef struct _updowncall_entry {
185+
+
209-
     union {
186+
     /* add the mac address from each applicable adapter to the hash */
210-
         struct {
187+
     status = hash_mac_addrs(hash);
211-
             PUNICODE_STRING srv_name;
188+
     if (status) {
212-
+	    DWORD port;
189+
diff --git a/daemon/nfs41_server.c b/daemon/nfs41_server.c
213-
             PUNICODE_STRING root;
190+
index d58c03a..ef8f0ac 100644
214-
             PFILE_FS_ATTRIBUTE_INFORMATION FsAttrs;
191+
--- a/daemon/nfs41_server.c
215-
             DWORD sec_flavor;
192+
+++ b/daemon/nfs41_server.c
216-
@@ -314,6 +315,7 @@ DECLARE_CONST_UNICODE_STRING(SLASH, L"\\");
193+
@@ -338,6 +338,6 @@ out:
217-
 DECLARE_CONST_UNICODE_STRING(EMPTY_STRING, L"");
194+
             "error %d\n", hostname, port, status);
218-
195+
     else
219-
 #define SERVER_NAME_BUFFER_SIZE         1024
196+
         dprintf(SRVLVL, "<-- nfs41_server_resolve(%s:%u) returning "
220-
+#define MOUNT_CONFIG_NFS_PORT_DEFAULT   2049
197+
-            "%s\n", hostname, port, addrs->arr[0].uaddr);
221-
 #define MOUNT_CONFIG_RW_SIZE_MIN        1024
198+
+            "OK %s\n", hostname, port, addrs->arr[0].uaddr);
222-
 #define MOUNT_CONFIG_RW_SIZE_DEFAULT    1048576
199+
     return status;
223-
 #define MOUNT_CONFIG_RW_SIZE_MAX        1048576
200+
 }
224-
@@ -328,6 +330,7 @@ typedef struct _NFS41_MOUNT_CONFIG {
201+
diff --git a/daemon/upcall.h b/daemon/upcall.h
225-
     BOOLEAN nocache;
202+
index fd26353..9cdc0a1 100644
226-
     WCHAR srv_buffer[SERVER_NAME_BUFFER_SIZE];
203+
--- a/daemon/upcall.h
227-
     UNICODE_STRING SrvName;
204+
+++ b/daemon/upcall.h
228-
+    DWORD Port;
205+
@@ -30,6 +30,7 @@
229-
     WCHAR mntpt_buffer[MAX_PATH];
206+
 /* structures for upcall arguments */
230-
     UNICODE_STRING MntPt;
207+
 typedef struct __mount_upcall_args {
231-
     WCHAR sec_flavor[MAX_SEC_FLAVOR_LEN];
208+
     const char *hostname;
232-
@@ -364,6 +367,15 @@ typedef struct _NFS41_V_NET_ROOT_EXTENSION {
209+
+    DWORD       port;
233-
     FILE_FS_ATTRIBUTE_INFORMATION FsAttrs;
210+
     const char *path;
234-
     DWORD                   sec_flavor;
211+
     DWORD       sec_flavor;
235-
     DWORD                   timeout;
212+
     DWORD       rsize;
236-
+    /*
213+
diff --git a/libtirpc/src/pmap_getport.c b/libtirpc/src/pmap_getport.c
237-
+     * gisburn: FIXME: Putting |port| here is wrong:
214+
index 45c8b1c..4d3a277 100644
238-
+     * TCP port information should be encoded in the server name
215+
--- a/libtirpc/src/pmap_getport.c
239-
+     * (e.g. \\server@port\nfs4\path, to make sure we do not get
216+
+++ b/libtirpc/src/pmap_getport.c
240-
+     * conflicts in case of (ssh) port forwarding
217+
@@ -62,6 +62,7 @@ pmap_getport(address, program, version, protocol)
241-
+     * (see https://learn.microsoft.com/en-gb/windows/win32/api/davclnt/nf-davclnt-davgethttpfromuncpath
218+
 	u_long version;
242-
+     * how to specify ports in an UNC path)
219+
 	u_int protocol;
243-
+     */
220+
 {
244-
+    DWORD                   port;
221+
+	(void)fprintf(stderr, "pmap_getport: returning default NFS port 2049\n");
245-
     USHORT                  MountPathLen;
222+
 	return (u_short)2049;
250223
     }
251-
     header_len = *len + length_as_utf8(entry->u.Mount.srv_name) +
224+
 #else
252-
-        length_as_utf8(entry->u.Mount.root) + 3 * sizeof(DWORD);
225+
@@ -106,4 +107,4 @@ pmap_getport(address, program, version, protocol)
253-
+        length_as_utf8(entry->u.Mount.root) + 4 * sizeof(DWORD);
226+
 	address->sin_port = 0;
254-
     if (header_len > buf_len) {
227+
 	return (port);
257228
     }
258-
     status = marshall_unicode_as_utf8(&tmp, entry->u.Mount.srv_name);
229+
-#endif /* ! _WIN32 */
259-
     if (status) goto out;
230+
\ No newline at end of file
260-
+    RtlCopyMemory(tmp, &entry->u.Mount.port, sizeof(DWORD));
231+
+#endif /* ! _WIN32 */
261-
+    tmp += sizeof(DWORD);
232+
diff --git a/mount/mount.c b/mount/mount.c
262-
     status = marshall_unicode_as_utf8(&tmp, entry->u.Mount.root);
233+
index 4615fc9..6d8c8ee 100644
263-
     if (status) goto out;
234+
--- a/mount/mount.c
264-
     RtlCopyMemory(tmp, &entry->u.Mount.sec_flavor, sizeof(DWORD));
235+
+++ b/mount/mount.c
265-
@@ -633,8 +647,9 @@ NTSTATUS marshal_nfs41_mount(
236+
@@ -61,13 +61,14 @@ static VOID PrintUsage(LPTSTR pProcess)
266-
     *len = header_len;
237+
         TEXT("\t-o <comma-separated mount options>\n")
267-
238+
         TEXT("Mount options:\n")
268-
 #ifdef DEBUG_MARSHAL_DETAIL
239+
         TEXT("\tro\tmount as read-only\n")
269-
-    DbgP("marshal_nfs41_mount: server name=%wZ mount point=%wZ sec_flavor=%s "
240+
+        TEXT("\tport=#\tTCP port to use (defaults to 2049)\n")
270-
-         "rsize=%d wsize=%d\n", entry->u.Mount.srv_name, entry->u.Mount.root,
241+
         TEXT("\trsize=#\tread buffer size in bytes\n")
271-
+    DbgP("marshal_nfs41_mount: server name=%wZ port=%d mount point=%wZ "
242+
         TEXT("\twsize=#\twrite buffer size in bytes\n")
272-
+         "sec_flavor=%s rsize=%d wsize=%d\n",
243+
         TEXT("\tsec=krb5:krb5i:krb5p\tspecify gss security flavor\n")
273-
+	 entry->u.Mount.srv_name, entry->u.Mount.port, entry->u.Mount.root,
244+
         TEXT("\twritethru\tturns off rdbss caching for writes\n")
274-
          secflavorop2name(entry->u.Mount.sec_flavor), entry->u.Mount.rsize,
245+
         TEXT("\tnocache\tturns off rdbss caching\n")
275-
          entry->u.Mount.wsize);
246+
         TEXT("\ttimeout=#\tspecify upcall timeout value in seconds (default 120s)\n"),
276-
 #endif
247+
-        pProcess, pProcess, pProcess);
277-
@@ -2566,14 +2581,15 @@ NTSTATUS nfs41_mount(
248+
+        pProcess);
249+
 }
278250
279-
 #ifdef DEBUG_MOUNT
251+
 DWORD __cdecl _tmain(DWORD argc, LPTSTR argv[])
280-
     DbgEn();
252+
diff --git a/sys/nfs41_driver.c b/sys/nfs41_driver.c
281-
-    DbgP("Server Name %wZ Mount Point %wZ SecFlavor %d\n",
253+
index da9327f..01c0cd3 100644
282-
-        &config->SrvName, &config->MntPt, sec_flavor);
254+
--- a/sys/nfs41_driver.c
283-
+    DbgP("Server Name %wZ Port %d Mount Point %wZ SecFlavor %d\n",
255+
+++ b/sys/nfs41_driver.c
284-
+        &config->SrvName, config->Port, &config->MntPt, sec_flavor);
256+
@@ -166,6 +166,7 @@ typedef struct _updowncall_entry {
285-
 #endif
257+
     union {
286-
     status = nfs41_UpcallCreate(NFS41_MOUNT, NULL, *session,
258+
         struct {
287-
         INVALID_HANDLE_VALUE, *version, &config->MntPt, &entry);
259+
             PUNICODE_STRING srv_name;
288-
     if (status) goto out;
260+
+	    DWORD port;
261+
             PUNICODE_STRING root;
289266
290-
     entry->u.Mount.srv_name = &config->SrvName;
267+
 #define SERVER_NAME_BUFFER_SIZE         1024
291-
+    entry->u.Mount.port = config->Port;
268+
+#define MOUNT_CONFIG_NFS_PORT_DEFAULT   2049
292-
     entry->u.Mount.root = &config->MntPt;
269+
 #define MOUNT_CONFIG_RW_SIZE_MIN        1024
293-
     entry->u.Mount.rsize = config->ReadSize;
270+
 #define MOUNT_CONFIG_RW_SIZE_DEFAULT    1048576
294-
     entry->u.Mount.wsize = config->WriteSize;
271+
 #define MOUNT_CONFIG_RW_SIZE_MAX        1048576
295-
@@ -2606,6 +2622,7 @@ void nfs41_MountConfig_InitDefaults(
272+
@@ -328,6 +330,7 @@ typedef struct _NFS41_MOUNT_CONFIG {
296-
 {
273+
     BOOLEAN nocache;
297-
     RtlZeroMemory(Config, sizeof(NFS41_MOUNT_CONFIG));
274+
     WCHAR srv_buffer[SERVER_NAME_BUFFER_SIZE];
298-
275+
     UNICODE_STRING SrvName;
299-
+    Config->Port = MOUNT_CONFIG_NFS_PORT_DEFAULT;
276+
+    DWORD Port;
300-
     Config->ReadSize = MOUNT_CONFIG_RW_SIZE_DEFAULT;
277+
     WCHAR mntpt_buffer[MAX_PATH];
301-
     Config->WriteSize = MOUNT_CONFIG_RW_SIZE_DEFAULT;
278+
     UNICODE_STRING MntPt;
302-
     Config->ReadOnly = FALSE;
279+
     WCHAR sec_flavor[MAX_SEC_FLAVOR_LEN];
303-
@@ -2724,6 +2741,11 @@ NTSTATUS nfs41_MountConfig_ParseOptions(
280+
@@ -615,13 +618,15 @@ NTSTATUS marshal_nfs41_mount(
304-
             else
281+
         goto out;
306282
         }
307-
+        else if (wcsncmp(L"port", Name, NameLen) == 0) {
283+
     header_len = *len + length_as_utf8(entry->u.Mount.srv_name) +
308-
+            status = nfs41_MountConfig_ParseDword(Option, &usValue,
284+
-        length_as_utf8(entry->u.Mount.root) + 3 * sizeof(DWORD);
309-
+                &Config->Port, 1,
285+
+        length_as_utf8(entry->u.Mount.root) + 4 * sizeof(DWORD);
310-
+                65535);
286+
     if (header_len > buf_len) {
311-
+        }
287+
         status = STATUS_INSUFFICIENT_RESOURCES;
312-
         else if (wcsncmp(L"mntpt", Name, NameLen) == 0) {
288+
         goto out;
313-
             if (usValue.Length > Config->MntPt.MaximumLength)
289+
     }
314-
                 status = STATUS_NAME_TOO_LONG;
290+
     status = marshall_unicode_as_utf8(&tmp, entry->u.Mount.srv_name);
315-
@@ -2910,6 +2932,8 @@ NTSTATUS nfs41_CreateVNetRoot(
291+
     if (status) goto out;
316-
     nfs41_MountConfig_InitDefaults(Config);
292+
+    RtlCopyMemory(tmp, &entry->u.Mount.port, sizeof(DWORD));
293+
+    tmp += sizeof(DWORD);
317299
318-
     if (pCreateNetRootContext->RxContext->Create.EaLength) {
300+
 #ifdef DEBUG_MARSHAL_DETAIL
319-
+        /* Codepath for nfs_mount.exe */
301+
-    DbgP("marshal_nfs41_mount: server name=%wZ mount point=%wZ sec_flavor=%s "
320-
+
302+
-         "rsize=%d wsize=%d\n", entry->u.Mount.srv_name, entry->u.Mount.root,
321-
         /* parse the extended attributes for mount options */
303+
+    DbgP("marshal_nfs41_mount: server name=%wZ port=%d mount point=%wZ "
322-
         status = nfs41_MountConfig_ParseOptions(
304+
+         "sec_flavor=%s rsize=%d wsize=%d\n",
323-
             pCreateNetRootContext->RxContext->Create.EaBuffer,
305+
+	 entry->u.Mount.srv_name, entry->u.Mount.port, entry->u.Mount.root,
324-
@@ -2920,13 +2944,25 @@ NTSTATUS nfs41_CreateVNetRoot(
306+
          secflavorop2name(entry->u.Mount.sec_flavor), entry->u.Mount.rsize,
325-
         pVNetRootContext->read_only = Config->ReadOnly;
307+
          entry->u.Mount.wsize);
326-
         pVNetRootContext->write_thru = Config->write_thru;
308+
 #endif
327-
         pVNetRootContext->nocache = Config->nocache;
309+
@@ -2566,14 +2572,15 @@ NTSTATUS nfs41_mount(
328-
+	pVNetRootContext->port = Config->Port;
310+
329-
     } else {
311+
 #ifdef DEBUG_MOUNT
330-
+        /* Codepath for \\server:port\nfs4\path */
312+
     DbgEn();
331-
+
313+
-    DbgP("Server Name %wZ Mount Point %wZ SecFlavor %d\n",
332-
         /* use the SRV_CALL name (without leading \) as the hostname */
314+
-        &config->SrvName, &config->MntPt, sec_flavor);
333-
         Config->SrvName.Buffer = pSrvCall->pSrvCallName->Buffer + 1;
315+
+    DbgP("Server Name %wZ Port %d Mount Point %wZ SecFlavor %d\n",
334-
         Config->SrvName.Length =
316+
+        &config->SrvName, config->Port, &config->MntPt, sec_flavor);
335-
             pSrvCall->pSrvCallName->Length - sizeof(WCHAR);
317+
 #endif
336-
         Config->SrvName.MaximumLength =
318+
     status = nfs41_UpcallCreate(NFS41_MOUNT, NULL, *session,
337-
             pSrvCall->pSrvCallName->MaximumLength - sizeof(WCHAR);
319+
         INVALID_HANDLE_VALUE, *version, &config->MntPt, &entry);
338-
+        /*
320+
     if (status) goto out;
339-
+         * gisburn: FIXME: Using |port| here is wrong:
321+
340-
+         * TCP port information should be encoded in the server name
322+
     entry->u.Mount.srv_name = &config->SrvName;
341-
+         * (e.g. \\server@port\nfs4\path, to make sure we do not get
323+
+    entry->u.Mount.port = config->Port;
342-
+         * conflicts in case of (ssh) port forwarding
324+
     entry->u.Mount.root = &config->MntPt;
343-
+	 * (see https://learn.microsoft.com/en-gb/windows/win32/api/davclnt/nf-davclnt-davgethttpfromuncpath
325+
     entry->u.Mount.rsize = config->ReadSize;
344-
+	 * how to specify ports in an UNC path)
326+
     entry->u.Mount.wsize = config->WriteSize;
345-
+         */
327+
@@ -2606,6 +2613,7 @@ void nfs41_MountConfig_InitDefaults(
346-
+	Config->Port = pVNetRootContext->port;
328+
 {
347-
     }
329+
     RtlZeroMemory(Config, sizeof(NFS41_MOUNT_CONFIG));
350330
351-
331+
+    Config->Port = MOUNT_CONFIG_NFS_PORT_DEFAULT;
352-
332+
     Config->ReadSize = MOUNT_CONFIG_RW_SIZE_DEFAULT;
353-
333+
     Config->WriteSize = MOUNT_CONFIG_RW_SIZE_DEFAULT;
354-
334+
     Config->ReadOnly = FALSE;
355-
335+
@@ -2724,6 +2732,11 @@ NTSTATUS nfs41_MountConfig_ParseOptions(
356-
336+
             else
357-
337+
                 RtlCopyUnicodeString(&Config->SrvName, &usValue);
358-
338+
         }
359-
339+
+        else if (wcsncmp(L"port", Name, NameLen) == 0) {
360-
340+
+            status = nfs41_MountConfig_ParseDword(Option, &usValue,
361-
341+
+                &Config->Port, 1,
362-
342+
+                65535);
363-
343+
+        }
364-
344+
         else if (wcsncmp(L"mntpt", Name, NameLen) == 0) {
365-
345+
             if (usValue.Length > Config->MntPt.MaximumLength)
366-
346+
                 status = STATUS_NAME_TOO_LONG;
367-
347+
@@ -2909,7 +2922,13 @@ NTSTATUS nfs41_CreateVNetRoot(
368-
348+
     }
369-
349+
     nfs41_MountConfig_InitDefaults(Config);
370350
371-
351+
+#define SAVE_PORT_HACK 1
372-
352+
+#ifdef SAVE_PORT_HACK
373-
353+
+    static DWORD saved_port = 0;
374-
354+
+#endif /* SAVE_PORT_HACK */
375-
355+
     if (pCreateNetRootContext->RxContext->Create.EaLength) {
376-
356+
+        /* Codepath for nfs_mount.exe */
377-
357+
+
378-
358+
         /* parse the extended attributes for mount options */
379-
359+
         status = nfs41_MountConfig_ParseOptions(
380-
360+
             pCreateNetRootContext->RxContext->Create.EaBuffer,
381-
361+
@@ -2920,13 +2939,31 @@ NTSTATUS nfs41_CreateVNetRoot(
382-
362+
         pVNetRootContext->read_only = Config->ReadOnly;
383-
363+
         pVNetRootContext->write_thru = Config->write_thru;
384-
364+
         pVNetRootContext->nocache = Config->nocache;
385-
365+
+#ifdef SAVE_PORT_HACK
386-
366+
+	saved_port = Config->Port;
387-
367+
+#endif /* SAVE_PORT_HACK */
388-
368+
     } else {
389-
369+
+        /* Codepath for \\server:port\nfs4\path */
390-
370+
+
391-
371+
         /* use the SRV_CALL name (without leading \) as the hostname */
392-
372+
         Config->SrvName.Buffer = pSrvCall->pSrvCallName->Buffer + 1;
393-
373+
         Config->SrvName.Length =
394-
374+
             pSrvCall->pSrvCallName->Length - sizeof(WCHAR);
395-
375+
         Config->SrvName.MaximumLength =
396-
376+
             pSrvCall->pSrvCallName->MaximumLength - sizeof(WCHAR);
397-
377+
+        /*
398-
378+
+         * gisburn: FIXME: Using |saved_port| here is wrong:
399-
379+
+         * TCP port information should be encoded in the server name
400-
380+
+         * (e.g. \\server@port\nfs4\path, to make sure we do not get
401-
381+
+         * conflicts in case of (ssh) port forwarding
402-
382+
+	 * (see https://learn.microsoft.com/en-gb/windows/win32/api/davclnt/nf-davclnt-davgethttpfromuncpath
403-
383+
+	 * how to specify ports in an UNC path)
404-
384+
+         */
405-
385+
+#ifdef SAVE_PORT_HACK
406-
386+
+	Config->Port = saved_port;
407-
387+
+#else
408-
388+
+#error Getting Config->Port information from UNC server name not implemented yet
409-
389+
+#endif /* SAVE_PORT_HACK */
410-
390+
     }
411-
391+
     pVNetRootContext->MountPathLen = Config->MntPt.Length;
412-
392+
     pVNetRootContext->timeout = Config->timeout;
413-
393+
--
414-
394+
2.39.0
415395
416396

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