- From d8cb3ea640106245914e2d97808e4109286223f9 Mon Sep 17 00:00:00 2001
- From: Roland Mainz <roland.mainz@nrubsig.org>
- Date: Thu, 5 Dec 2024 01:47:36 +0100
- Subject: [PATCH 1/4] cygwin,mount: Implement multiple URL encoding methods
- Implement multiple URL encoding methods in nfs_mount.exe
- and nfsurlconv.ksh
- Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
- ---
- cygwin/utils/nfsurlconv/nfsurlconv.ksh | 20 +++++++--
- mount/enum.c | 22 +++++-----
- mount/mount.c | 58 ++++++++++++++++++++++----
- 3 files changed, 79 insertions(+), 21 deletions(-)
- diff --git a/cygwin/utils/nfsurlconv/nfsurlconv.ksh b/cygwin/utils/nfsurlconv/nfsurlconv.ksh
- index 505fb56..f92792e 100644
- --- a/cygwin/utils/nfsurlconv/nfsurlconv.ksh
- +++ b/cygwin/utils/nfsurlconv/nfsurlconv.ksh
- @@ -287,12 +287,13 @@ function main
- # fixme: Need better text layout for $ nfsurlconv --man #
- typeset -r nfsurlconv_usage=$'+
- - [-?\n@(#)\$Id: nfsurlconv (Roland Mainz) 2024-11-25 \$\n]
- + [-?\n@(#)\$Id: nfsurlconv (Roland Mainz) 2024-12-04 \$\n]
- [-author?Roland Mainz <roland.mainz@nrubsig.org>]
- [+NAME?nfsurlconv - convert hostname,port,path from/to a nfs://-URL]
- [+DESCRIPTION?\bnfsurlconv\b convert { hostname, port, path } from/to a nfs://-URL.]
- [D:debug?Enable debugging.]
- - [S!:posixshellsafe?urlencode shell special characters.]
- + [U:urlencoding?Encoding method used \brfc1738\b or
- + \bposixshell\b/\bposixshellsafe\b (default).]:[encoding]
- hostnameportpath2nfsurl hostname port path
- hostnamepath2nfsurl hostname path
- @@ -352,8 +353,19 @@ urlparameter=( name=param2 value=pvalue2 )
- 'D')
- # fixme: Implement debugging option
- ;;
- - 'S')
- - (( encode_posix_shell_safe=0 ))
- + 'U')
- + case "$OPTARG" in
- + 'rfc1738')
- + (( encode_posix_shell_safe=0 ))
- + ;;
- + 'posixshell' | 'posixshellsafe' | 'default')
- + (( encode_posix_shell_safe=1 ))
- + ;;
- + *)
- + print -u2 -f $"%s: Unknown -U encoding %q\n" "$progname" "$OPTARG"
- + return 1
- + ;;
- + esac
- ;;
- *)
- usage "${progname}" "${nfsurlconv_usage}"
- diff --git a/mount/enum.c b/mount/enum.c
- index b2938ef..d3cec03 100644
- --- a/mount/enum.c
- +++ b/mount/enum.c
- @@ -43,8 +43,9 @@ void PrintErrorMessage(IN DWORD dwError);
- /* fixme: this function needs a cleanup */
- static __inline
- void PrintMountLine(
- - LPCWSTR local,
- - LPCWSTR remote)
- + IN LPCWSTR local,
- + IN LPCWSTR remote,
- + IN BOOL printURLShellSafe)
- {
- size_t remote_len = wcslen(remote);
- wchar_t *cygwin_unc_buffer =
- @@ -106,9 +107,8 @@ void PrintMountLine(
- * in POSIX shells, e.g. '!', '(', ')', '*', "'", "$".
- * Fixme: This should be a command-line option
- */
- -#define SHELL_SAFE_URLS 1
- -#ifdef SHELL_SAFE_URLS
- -#define ISVALIDURLCHAR(c) \
- +
- +#define ISVALIDSHELLSAFEURLCHAR(c) \
- ( \
- ((c) >= '0' && (c) <= '9') || \
- ((c) >= 'a' && (c) <= 'z') || \
- @@ -116,7 +116,6 @@ void PrintMountLine(
- ((c) == '-') || ((c) == '_') || ((c) == '.') || \
- ((c) == '/') \
- )
- -#else
- #define ISVALIDURLCHAR(c) \
- ( \
- ((c) >= '0' && (c) <= '9') || \
- @@ -126,7 +125,6 @@ void PrintMountLine(
- ((c) == '!') || ((c) == '*') || ((c) == '\'') || \
- ((c) == '(') || ((c) == ')') || ((c) == ',') || ((c) == '/') \
- )
- -#endif /* SHELL_SAFE_URLS */
- unsigned int slash_counter = 0;
- char *utf8unc = wcs2utf8str(cygwin_unc_buffer);
- @@ -183,7 +181,9 @@ void PrintMountLine(
- if ((uc == '@') && (slash_counter == 0)) {
- *us++ = ':';
- }
- - else if (ISVALIDURLCHAR(uc)) {
- + else if (printURLShellSafe?
- + (ISVALIDSHELLSAFEURLCHAR(uc)):
- + (ISVALIDURLCHAR(uc))) {
- *us++ = uc;
- }
- else {
- @@ -227,7 +227,8 @@ void PrintMountLine(
- #define ENUM_RESOURCE_BUFFER_SIZE (16*1024)
- DWORD EnumMounts(
- - IN LPNETRESOURCEW pContainer)
- + IN LPNETRESOURCEW pContainer,
- + IN BOOL printURLShellSafe)
- {
- DWORD result = NO_ERROR;
- LPNETRESOURCEW pResources;
- @@ -265,7 +266,8 @@ DWORD EnumMounts(
- NFS41_PROVIDER_NAME_U))
- {
- PrintMountLine(pResources[i].lpLocalName,
- - pResources[i].lpRemoteName);
- + pResources[i].lpRemoteName,
- + printURLShellSafe);
- dwTotal++;
- }
- }
- diff --git a/mount/mount.c b/mount/mount.c
- index 5b872a2..2bc1ebb 100644
- --- a/mount/mount.c
- +++ b/mount/mount.c
- @@ -55,7 +55,8 @@
- #define MOUNT_CONFIG_NFS_PORT_DEFAULT 2049
- DWORD EnumMounts(
- - IN LPNETRESOURCEW pContainer);
- + IN LPNETRESOURCEW pContainer,
- + IN BOOL printURLShellSafe);
- static DWORD ParseRemoteName(
- IN bool use_nfspubfh,
- @@ -101,6 +102,8 @@ void PrintMountUsage(LPWSTR pProcess)
- "\t-o. --options <comma-separated mount options>\n"
- "\t-r, --read-only\tAlias for -o ro (read-only mount)\n"
- "\t-w, --rw, --read-write\tAlias for -o rw (read-write mount)\n"
- + "\t-U, --urlencoding\tDefine encoding used by URLs\n"
- + "\t\t('rfc1738', 'posixshell'/'posixshellsafe', 'default')\n"
- "* Mount options:\n"
- "\tpublic\tconnect to the server using the public file handle lookup protocol.\n"
- @@ -556,17 +559,55 @@ out:
- static
- int list_nfs_mounts_main(int argc, wchar_t *argv[])
- {
- - DWORD result;
- + int i;
- + DWORD result = NO_ERROR;
- + BOOL bShellSafeURLEncoding = TRUE;
- +
- + /*
- + * parse command line
- + * (-h, --help, /? is handled by |mount_main()|)
- + */
- + for (i = 1; i < argc; i++) {
- + if ((!wcscmp(argv[i], L"-U")) ||
- + (!wcscmp(argv[i], L"--urlencoding"))) {
- + ++i;
- + if (i >= argc) {
- + result = ERROR_BAD_ARGUMENTS;
- + (void)fwprintf(stderr, L"URL encoding type missing "
- + L"after '-U'/'--urlencoding'.\n");
- + goto out;
- + }
- - /* Unused for now */
- - (void)argc;
- - (void)argv;
- + if (!wcscmp(argv[i], L"rfc1738")) {
- + bShellSafeURLEncoding = FALSE;
- + }
- + else if ((!wcscmp(argv[i], L"posixshellsafe")) ||
- + (!wcscmp(argv[i], L"posixshell")) ||
- + (!wcscmp(argv[i], L"default"))) {
- + bShellSafeURLEncoding = TRUE;
- + }
- + else {
- + result = ERROR_BAD_ARGUMENTS;
- + (void)fwprintf(stderr, L"URL encoding type '%ls' "
- + L"not supported.\n", argv[i]);
- + goto out;
- + }
- + }
- + else {
- + (void)fwprintf(stderr, L"Unrecognized option "
- + L"'%ls'.\n",
- + argv[i]);
- + result = ERROR_BAD_ARGUMENTS;
- + goto out;
- + }
- + }
- /* list open nfs shares */
- - result = EnumMounts(NULL);
- + result = EnumMounts(NULL, bShellSafeURLEncoding);
- if (result)
- PrintErrorMessage(GetLastError());
- +out:
- return result;
- }
- @@ -595,7 +636,10 @@ int __cdecl wmain(int argc, wchar_t *argv[])
- (void)_CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE);
- (void)_CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE);
- - if (argc == 1) {
- + if ((argc == 1) ||
- + (((argc >= 2) && (argc <= 3)) &&
- + ((!wcscmp(argv[1], L"-U")) ||
- + (!wcscmp(argv[1], L"--urlencoding"))))) {
- result = list_nfs_mounts_main(argc, argv);
- goto out;
- }
- --
- 2.45.1
- From 1bd6fd6e5a3fbaabd6ac021f15448433a5da1375 Mon Sep 17 00:00:00 2001
- From: Roland Mainz <roland.mainz@nrubsig.org>
- Date: Thu, 5 Dec 2024 01:52:16 +0100
- Subject: [PATCH 2/4] mount: nfs_mount.exe -t nfs ... should not result in an
- error
- nfs_mount.exe -t nfs ... should not result in an error.
- Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
- ---
- mount/mount.c | 6 ++++++
- 1 file changed, 6 insertions(+)
- diff --git a/mount/mount.c b/mount/mount.c
- index 2bc1ebb..1cf71f8 100644
- --- a/mount/mount.c
- +++ b/mount/mount.c
- @@ -373,6 +373,12 @@ opt_o_argv_i_again:
- }
- if (!wcscmp(argv[i], L"nfs")) {
- + /*
- + * "nfs" is the only supported filesystem type
- + * in nfs_mount.exe
- + */
- + }
- + else {
- result = ERROR_BAD_ARGUMENTS;
- (void)fwprintf(stderr, L"Filesystem type '%ls' "
- L"not supported.\n\n.", argv[i]);
- --
- 2.45.1
- From e78ee7653e3c693cc76080ba19d44220f09817b5 Mon Sep 17 00:00:00 2001
- From: Roland Mainz <roland.mainz@nrubsig.org>
- Date: Thu, 5 Dec 2024 02:01:37 +0100
- Subject: [PATCH 3/4] mount: nfs_mount.exe should be less noisy in case of
- wrong arguments
- nfs_mount.exe should be less noisy in case of wrong arguments,
- printing always the whole usage message is not what the UNIX/Linux
- tools would do.
- Reported-by: Cedric Blancher <cedric.blancher@gmail.com>
- Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
- ---
- mount/mount.c | 26 ++++++++++----------------
- 1 file changed, 10 insertions(+), 16 deletions(-)
- diff --git a/mount/mount.c b/mount/mount.c
- index 1cf71f8..1b7d7ca 100644
- --- a/mount/mount.c
- +++ b/mount/mount.c
- @@ -250,15 +250,14 @@ int mount_main(int argc, wchar_t *argv[])
- {
- result = ERROR_BAD_ARGUMENTS;
- (void)fwprintf(stderr,
- - L"Mount options missing after '-o'.\n\n");
- - PrintMountUsage(argv[0]);
- + L"Mount options missing after '-o'.\n");
- goto out_free;
- }
- if (num_mntopts >= (MAX_MNTOPTS-1)) {
- result = ERROR_BAD_ARGUMENTS;
- (void)fwprintf(stderr,
- - L"Too many -o options.\n\n");
- + L"Too many -o options.\n");
- goto out_free;
- }
- @@ -336,7 +335,7 @@ opt_o_argv_i_again:
- (!wcscmp(argv[i], L"--read-only"))) {
- if (num_mntopts >= (MAX_MNTOPTS-1)) {
- result = ERROR_BAD_ARGUMENTS;
- - (void)fwprintf(stderr, L"Too many options.\n\n");
- + (void)fwprintf(stderr, L"Too many options.\n");
- goto out_free;
- }
- @@ -348,7 +347,7 @@ opt_o_argv_i_again:
- (!wcscmp(argv[i], L"--read-write"))) {
- if (num_mntopts >= (MAX_MNTOPTS-1)) {
- result = ERROR_BAD_ARGUMENTS;
- - (void)fwprintf(stderr, L"Too many options.\n\n");
- + (void)fwprintf(stderr, L"Too many options.\n");
- goto out_free;
- }
- @@ -367,8 +366,7 @@ opt_o_argv_i_again:
- {
- result = ERROR_BAD_ARGUMENTS;
- (void)fwprintf(stderr, L"Filesystem type missing "
- - L"after '-t'/'-F'.\n\n");
- - PrintMountUsage(argv[0]);
- + L"after '-t'/'-F'.\n");
- goto out_free;
- }
- @@ -381,8 +379,7 @@ opt_o_argv_i_again:
- else {
- result = ERROR_BAD_ARGUMENTS;
- (void)fwprintf(stderr, L"Filesystem type '%ls' "
- - L"not supported.\n\n.", argv[i]);
- - PrintMountUsage(argv[0]);
- + L"not supported.\n", argv[i]);
- goto out_free;
- }
- }
- @@ -423,9 +420,8 @@ opt_o_argv_i_again:
- if (!ParseDriveLetter(pLocalName, szLocalName)) {
- result = ERROR_BAD_ARGUMENTS;
- (void)fwprintf(stderr, L"Invalid drive letter '%ls'. "
- - L"Expected 'C' or 'C:'.\n\n",
- + L"Expected 'C' or 'C:'.\n",
- pLocalName);
- - PrintMountUsage(argv[0]);
- goto out_free;
- }
- }
- @@ -447,8 +443,7 @@ opt_o_argv_i_again:
- if (pRemoteName == NULL)
- {
- result = ERROR_BAD_NET_NAME;
- - (void)fwprintf(stderr, L"Missing argument for remote path.\n\n");
- - PrintMountUsage(argv[0]);
- + (void)fwprintf(stderr, L"Missing argument for remote path.\n");
- goto out_free;
- }
- @@ -548,9 +543,8 @@ int umount_main(int argc, wchar_t *argv[])
- if (!ParseDriveLetter(pLocalName, szLocalName)) {
- result = ERROR_BAD_ARGUMENTS;
- (void)fwprintf(stderr, L"Invalid drive letter '%ls'. "
- - L"Expected 'C' or 'C:'.\n\n",
- + L"Expected 'C' or 'C:'.\n",
- pLocalName);
- - PrintUmountUsage(argv[0]);
- goto out;
- }
- @@ -778,7 +772,7 @@ static DWORD ParseRemoteName(
- if (!premotename_utf8) {
- result = GetLastError();
- (void)fwprintf(stderr,
- - L"wcs2utf8str() failed, lasterr=%d\n.",
- + L"wcs2utf8str() failed, lasterr=%d\n",
- (int)result);
- goto out;
- }
- --
- 2.45.1
- From 40b85aa2367eb9d1039543ccb0e2000753a8476b Mon Sep 17 00:00:00 2001
- From: Roland Mainz <roland.mainz@nrubsig.org>
- Date: Thu, 5 Dec 2024 02:09:05 +0100
- Subject: [PATCH 4/4] mount: Usage message for remote path should include
- nfs://-URL
- Usage message for remote path should include nfs://-URL
- Reported-by: Cedric Blancher <cedric.blancher@gmail.com>
- Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
- ---
- mount/mount.c | 2 +-
- 1 file changed, 1 insertion(+), 1 deletion(-)
- diff --git a/mount/mount.c b/mount/mount.c
- index 1b7d7ca..b0a39bb 100644
- --- a/mount/mount.c
- +++ b/mount/mount.c
- @@ -914,7 +914,7 @@ static DWORD ParseRemoteName(
- pEnd = wcsrchr(premotename, L':');
- if (pEnd == NULL || pEnd[1] != L'\\') {
- (void)fwprintf(stderr, L"Failed to parse the remote path. "
- - L"Expected 'hostname:\\path'.\n");
- + L"Expected 'hostname:\\path' or nfs://-URL.\n");
- result = ERROR_BAD_ARGUMENTS;
- goto out;
- }
- --
- 2.45.1
msnfs41client: Patches for nfs_mount, URL encoding methods, nfs_mount usage fixes+misc, 2024-12-05
Posted by Anonymous on Thu 5th Dec 2024 01:17
raw | new post
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.