- diff --git a/daemon/mount.c b/daemon/mount.c
- index 55345f6..3b18cba 100644
- --- a/daemon/mount.c
- +++ b/daemon/mount.c
- @@ -37,6 +37,8 @@ static int parse_mount(unsigned char *buffer, uint32_t length, nfs41_upcall *upc
- status = get_name(&buffer, &length, &args->hostname);
- if(status) goto out;
- + status = safe_read(&buffer, &length, &args->port, sizeof(DWORD));
- + if (status) goto out;
- status = get_name(&buffer, &length, &args->path);
- if(status) goto out;
- status = safe_read(&buffer, &length, &args->sec_flavor, sizeof(DWORD));
- @@ -46,10 +48,12 @@ static int parse_mount(unsigned char *buffer, uint32_t length, nfs41_upcall *upc
- status = safe_read(&buffer, &length, &args->wsize, sizeof(DWORD));
- if (status) goto out;
- - dprintf(1, "parsing NFS14_MOUNT: srv_name=%s root=%s sec_flavor=%s "
- - "rsize=%d wsize=%d\n", args->hostname, args->path,
- + dprintf(1, "parsing NFS41_MOUNT: srv_name=%s port=%d root=%s "
- + "sec_flavor=%s rsize=%d wsize=%d\n", args->hostname, args->port, args->path,
- secflavorop2name(args->sec_flavor), args->rsize, args->wsize);
- + return status;
- out:
- + dprintf(1, "parsing NFS41_MOUNT: failed %d\n", status);
- return status;
- }
- @@ -64,7 +68,7 @@ static int handle_mount(nfs41_upcall *upcall)
- nfs41_path_fh file;
- // resolve hostname,port
- - status = nfs41_server_resolve(args->hostname, 2049, &addrs);
- + status = nfs41_server_resolve(args->hostname, (unsigned short)args->port, &addrs);
- if (status) {
- eprintf("nfs41_server_resolve() failed with %d\n", status);
- goto out;
- @@ -76,7 +80,7 @@ static int handle_mount(nfs41_upcall *upcall)
- root = upcall->root_ref;
- } else {
- // create root
- - status = nfs41_root_create(args->hostname, args->sec_flavor,
- + status = nfs41_root_create(args->hostname, args->port, args->sec_flavor,
- args->wsize + WRITE_OVERHEAD, args->rsize + READ_OVERHEAD, &root);
- if (status) {
- eprintf("nfs41_root_create() failed %d\n", status);
- diff --git a/daemon/namespace.c b/daemon/namespace.c
- index ab16f49..e3ea077 100644
- --- a/daemon/namespace.c
- +++ b/daemon/namespace.c
- @@ -36,6 +36,7 @@
- /* nfs41_root */
- int nfs41_root_create(
- IN const char *name,
- + IN uint32_t port,
- IN uint32_t sec_flavor,
- IN uint32_t wsize,
- IN uint32_t rsize,
- @@ -44,7 +45,7 @@ int nfs41_root_create(
- int status = NO_ERROR;
- nfs41_root *root;
- - dprintf(NSLVL, "--> nfs41_root_create()\n");
- + dprintf(NSLVL, "--> nfs41_root_create(name=%s, port=%d)\n", name, port);
- root = calloc(1, sizeof(nfs41_root));
- if (root == NULL) {
- @@ -60,7 +61,7 @@ int nfs41_root_create(
- root->sec_flavor = sec_flavor;
- /* generate a unique client_owner */
- - status = nfs41_client_owner(name, sec_flavor, &root->client_owner);
- + status = nfs41_client_owner(name, port, sec_flavor, &root->client_owner);
- if (status) {
- eprintf("nfs41_client_owner() failed with %d\n", status);
- free(root);
- @@ -443,6 +444,8 @@ static int referral_mount_location(
- int status = ERROR_BAD_NET_NAME;
- uint32_t i;
- + dprintf(NSLVL, "--> referral_mount_location()\n");
- +
- /* create a client and session for the first available server */
- for (i = 0; i < loc->server_count; i++) {
- /* XXX: only deals with 'address' as a hostname with default port */
- @@ -453,6 +456,9 @@ static int referral_mount_location(
- if (status == NO_ERROR)
- break;
- }
- +
- + dprintf(NSLVL, "<-- referral_mount_location() returning %d\n", status);
- +
- return status;
- }
- diff --git a/daemon/nfs41.h b/daemon/nfs41.h
- index aa679a6..3902393 100644
- --- a/daemon/nfs41.h
- +++ b/daemon/nfs41.h
- @@ -287,6 +287,7 @@ typedef struct __nfs41_root {
- /* nfs41_namespace.c */
- int nfs41_root_create(
- IN const char *name,
- + IN uint32_t port,
- IN uint32_t sec_flavor,
- IN uint32_t wsize,
- IN uint32_t rsize,
- @@ -404,6 +405,7 @@ void nfs41_server_addrs(
- /* nfs41_client.c */
- int nfs41_client_owner(
- IN const char *name,
- + IN uint32_t port,
- IN uint32_t sec_flavor,
- OUT client_owner4 *owner);
- diff --git a/daemon/nfs41_client.c b/daemon/nfs41_client.c
- index 0460fc5..f5bac1d 100644
- --- a/daemon/nfs41_client.c
- +++ b/daemon/nfs41_client.c
- @@ -353,6 +353,7 @@ out:
- int nfs41_client_owner(
- IN const char *name,
- + IN uint32_t port,
- IN uint32_t sec_flavor,
- OUT client_owner4 *owner)
- {
- @@ -405,6 +406,12 @@ int nfs41_client_owner(
- goto out_hash;
- }
- + if (!CryptHashData(hash, (const BYTE*)&port, (DWORD)sizeof(port), 0)) {
- + status = GetLastError();
- + eprintf("CryptHashData() failed with %d\n", status);
- + goto out_hash;
- + }
- +
- /* add the mac address from each applicable adapter to the hash */
- status = hash_mac_addrs(hash);
- if (status) {
- diff --git a/daemon/nfs41_server.c b/daemon/nfs41_server.c
- index d58c03a..ef8f0ac 100644
- --- a/daemon/nfs41_server.c
- +++ b/daemon/nfs41_server.c
- @@ -338,6 +338,6 @@ out:
- "error %d\n", hostname, port, status);
- else
- dprintf(SRVLVL, "<-- nfs41_server_resolve(%s:%u) returning "
- - "%s\n", hostname, port, addrs->arr[0].uaddr);
- + "OK %s\n", hostname, port, addrs->arr[0].uaddr);
- return status;
- }
- diff --git a/daemon/upcall.h b/daemon/upcall.h
- index fd26353..9cdc0a1 100644
- --- a/daemon/upcall.h
- +++ b/daemon/upcall.h
- @@ -30,6 +30,7 @@
- /* structures for upcall arguments */
- typedef struct __mount_upcall_args {
- const char *hostname;
- + DWORD port;
- const char *path;
- DWORD sec_flavor;
- DWORD rsize;
- diff --git a/libtirpc/src/pmap_getport.c b/libtirpc/src/pmap_getport.c
- index 45c8b1c..4d3a277 100644
- --- a/libtirpc/src/pmap_getport.c
- +++ b/libtirpc/src/pmap_getport.c
- @@ -62,6 +62,7 @@ pmap_getport(address, program, version, protocol)
- u_long version;
- u_int protocol;
- {
- + (void)fprintf(stderr, "pmap_getport: returning default NFS port 2049\n");
- return (u_short)2049;
- }
- #else
- @@ -106,4 +107,4 @@ pmap_getport(address, program, version, protocol)
- address->sin_port = 0;
- return (port);
- }
- -#endif /* ! _WIN32 */
- \ No newline at end of file
- +#endif /* ! _WIN32 */
- diff --git a/mount/mount.c b/mount/mount.c
- index 4615fc9..6d8c8ee 100644
- --- a/mount/mount.c
- +++ b/mount/mount.c
- @@ -61,13 +61,14 @@ static VOID PrintUsage(LPTSTR pProcess)
- TEXT("\t-o <comma-separated mount options>\n")
- TEXT("Mount options:\n")
- TEXT("\tro\tmount as read-only\n")
- + TEXT("\tport=#\tTCP port to use (defaults to 2049)\n")
- TEXT("\trsize=#\tread buffer size in bytes\n")
- TEXT("\twsize=#\twrite buffer size in bytes\n")
- TEXT("\tsec=krb5:krb5i:krb5p\tspecify gss security flavor\n")
- TEXT("\twritethru\tturns off rdbss caching for writes\n")
- TEXT("\tnocache\tturns off rdbss caching\n")
- TEXT("\ttimeout=#\tspecify upcall timeout value in seconds (default 120s)\n"),
- - pProcess, pProcess, pProcess);
- + pProcess);
- }
- DWORD __cdecl _tmain(DWORD argc, LPTSTR argv[])
- diff --git a/sys/nfs41_driver.c b/sys/nfs41_driver.c
- index da9327f..080679e 100644
- --- a/sys/nfs41_driver.c
- +++ b/sys/nfs41_driver.c
- @@ -166,6 +166,7 @@ typedef struct _updowncall_entry {
- union {
- struct {
- PUNICODE_STRING srv_name;
- + DWORD port;
- PUNICODE_STRING root;
- PFILE_FS_ATTRIBUTE_INFORMATION FsAttrs;
- DWORD sec_flavor;
- @@ -314,6 +315,7 @@ DECLARE_CONST_UNICODE_STRING(SLASH, L"\\");
- DECLARE_CONST_UNICODE_STRING(EMPTY_STRING, L"");
- #define SERVER_NAME_BUFFER_SIZE 1024
- +#define MOUNT_CONFIG_NFS_PORT_DEFAULT 2049
- #define MOUNT_CONFIG_RW_SIZE_MIN 1024
- #define MOUNT_CONFIG_RW_SIZE_DEFAULT 1048576
- #define MOUNT_CONFIG_RW_SIZE_MAX 1048576
- @@ -328,6 +330,7 @@ typedef struct _NFS41_MOUNT_CONFIG {
- BOOLEAN nocache;
- WCHAR srv_buffer[SERVER_NAME_BUFFER_SIZE];
- UNICODE_STRING SrvName;
- + DWORD Port;
- WCHAR mntpt_buffer[MAX_PATH];
- UNICODE_STRING MntPt;
- WCHAR sec_flavor[MAX_SEC_FLAVOR_LEN];
- @@ -364,6 +367,15 @@ typedef struct _NFS41_V_NET_ROOT_EXTENSION {
- FILE_FS_ATTRIBUTE_INFORMATION FsAttrs;
- DWORD sec_flavor;
- DWORD timeout;
- + /*
- + * gisburn: FIXME: Putting |port| here is wrong:
- + * TCP port information should be encoded in the server name
- + * (e.g. \\server@port\nfs4\path, to make sure we do not get
- + * conflicts in case of (ssh) port forwarding
- + * (see https://learn.microsoft.com/en-gb/windows/win32/api/davclnt/nf-davclnt-davgethttpfromuncpath
- + * how to specify ports in an UNC path)
- + */
- + DWORD port;
- USHORT MountPathLen;
- BOOLEAN read_only;
- BOOLEAN write_thru;
- @@ -615,13 +627,15 @@ NTSTATUS marshal_nfs41_mount(
- goto out;
- }
- header_len = *len + length_as_utf8(entry->u.Mount.srv_name) +
- - length_as_utf8(entry->u.Mount.root) + 3 * sizeof(DWORD);
- + length_as_utf8(entry->u.Mount.root) + 4 * sizeof(DWORD);
- if (header_len > buf_len) {
- status = STATUS_INSUFFICIENT_RESOURCES;
- goto out;
- }
- status = marshall_unicode_as_utf8(&tmp, entry->u.Mount.srv_name);
- if (status) goto out;
- + RtlCopyMemory(tmp, &entry->u.Mount.port, sizeof(DWORD));
- + tmp += sizeof(DWORD);
- status = marshall_unicode_as_utf8(&tmp, entry->u.Mount.root);
- if (status) goto out;
- RtlCopyMemory(tmp, &entry->u.Mount.sec_flavor, sizeof(DWORD));
- @@ -633,8 +647,9 @@ NTSTATUS marshal_nfs41_mount(
- *len = header_len;
- #ifdef DEBUG_MARSHAL_DETAIL
- - DbgP("marshal_nfs41_mount: server name=%wZ mount point=%wZ sec_flavor=%s "
- - "rsize=%d wsize=%d\n", entry->u.Mount.srv_name, entry->u.Mount.root,
- + DbgP("marshal_nfs41_mount: server name=%wZ port=%d mount point=%wZ "
- + "sec_flavor=%s rsize=%d wsize=%d\n",
- + entry->u.Mount.srv_name, entry->u.Mount.port, entry->u.Mount.root,
- secflavorop2name(entry->u.Mount.sec_flavor), entry->u.Mount.rsize,
- entry->u.Mount.wsize);
- #endif
- @@ -2566,14 +2581,15 @@ NTSTATUS nfs41_mount(
- #ifdef DEBUG_MOUNT
- DbgEn();
- - DbgP("Server Name %wZ Mount Point %wZ SecFlavor %d\n",
- - &config->SrvName, &config->MntPt, sec_flavor);
- + DbgP("Server Name %wZ Port %d Mount Point %wZ SecFlavor %d\n",
- + &config->SrvName, config->Port, &config->MntPt, sec_flavor);
- #endif
- status = nfs41_UpcallCreate(NFS41_MOUNT, NULL, *session,
- INVALID_HANDLE_VALUE, *version, &config->MntPt, &entry);
- if (status) goto out;
- entry->u.Mount.srv_name = &config->SrvName;
- + entry->u.Mount.port = config->Port;
- entry->u.Mount.root = &config->MntPt;
- entry->u.Mount.rsize = config->ReadSize;
- entry->u.Mount.wsize = config->WriteSize;
- @@ -2606,6 +2622,7 @@ void nfs41_MountConfig_InitDefaults(
- {
- RtlZeroMemory(Config, sizeof(NFS41_MOUNT_CONFIG));
- + Config->Port = MOUNT_CONFIG_NFS_PORT_DEFAULT;
- Config->ReadSize = MOUNT_CONFIG_RW_SIZE_DEFAULT;
- Config->WriteSize = MOUNT_CONFIG_RW_SIZE_DEFAULT;
- Config->ReadOnly = FALSE;
- @@ -2724,6 +2741,11 @@ NTSTATUS nfs41_MountConfig_ParseOptions(
- else
- RtlCopyUnicodeString(&Config->SrvName, &usValue);
- }
- + else if (wcsncmp(L"port", Name, NameLen) == 0) {
- + status = nfs41_MountConfig_ParseDword(Option, &usValue,
- + &Config->Port, 1,
- + 65535);
- + }
- else if (wcsncmp(L"mntpt", Name, NameLen) == 0) {
- if (usValue.Length > Config->MntPt.MaximumLength)
- status = STATUS_NAME_TOO_LONG;
- @@ -2910,6 +2932,8 @@ NTSTATUS nfs41_CreateVNetRoot(
- nfs41_MountConfig_InitDefaults(Config);
- if (pCreateNetRootContext->RxContext->Create.EaLength) {
- + /* Codepath for nfs_mount.exe */
- +
- /* parse the extended attributes for mount options */
- status = nfs41_MountConfig_ParseOptions(
- pCreateNetRootContext->RxContext->Create.EaBuffer,
- @@ -2920,13 +2944,25 @@ NTSTATUS nfs41_CreateVNetRoot(
- pVNetRootContext->read_only = Config->ReadOnly;
- pVNetRootContext->write_thru = Config->write_thru;
- pVNetRootContext->nocache = Config->nocache;
- + pVNetRootContext->port = Config->Port;
- } else {
- + /* Codepath for \\server:port\nfs4\path */
- +
- /* use the SRV_CALL name (without leading \) as the hostname */
- Config->SrvName.Buffer = pSrvCall->pSrvCallName->Buffer + 1;
- Config->SrvName.Length =
- pSrvCall->pSrvCallName->Length - sizeof(WCHAR);
- Config->SrvName.MaximumLength =
- pSrvCall->pSrvCallName->MaximumLength - sizeof(WCHAR);
- + /*
- + * gisburn: FIXME: Using |port| here is wrong:
- + * TCP port information should be encoded in the server name
- + * (e.g. \\server@port\nfs4\path, to make sure we do not get
- + * conflicts in case of (ssh) port forwarding
- + * (see https://learn.microsoft.com/en-gb/windows/win32/api/davclnt/nf-davclnt-davgethttpfromuncpath
- + * how to specify ports in an UNC path)
- + */
- + Config->Port = pVNetRootContext->port;
- }
- pVNetRootContext->MountPathLen = Config->MntPt.Length;
- pVNetRootContext->timeout = Config->timeout;
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)
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.