pastebin - collaborative debugging tool
rovema.kpaste.net RSS


msnfs41client: Patches for winsg powershell support+misc, 2025-06-20
Posted by Anonymous on Fri 20th Jun 2025 15:31
raw | new post

  1. From c6d6e4f2c3313bfc323273776e0e2d7bd001ce43 Mon Sep 17 00:00:00 2001
  2. From: Aurelien Couderc <aurelien.couderc2002@gmail.com>
  3. Date: Fri, 20 Jun 2025 12:03:09 +0200
  4. Subject: [PATCH 1/2] daemon,tests: Invalid HANDLE should have the value
  5.  INVALID_HANDLE_VALUE, not NULL
  6.  
  7. Invalid HANDLE should have the value INVALID_HANDLE_VALUE, not NULL.
  8.  
  9. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  10. ---
  11. daemon/util.c       | 7 ++++---
  12.  tests/winsg/winsg.c | 2 +-
  13.  2 files changed, 5 insertions(+), 4 deletions(-)
  14.  
  15. diff --git a/daemon/util.c b/daemon/util.c
  16. index 765fb27..3a56b7c 100644
  17. --- a/daemon/util.c
  18. +++ b/daemon/util.c
  19. @@ -435,7 +435,7 @@ subcmd_popen_context *subcmd_popen(const char *command)
  20.      if (!pinfo)
  21.          return NULL;
  22.  
  23. -    pinfo->hReadPipe = pinfo->hWritePipe = NULL;
  24. +    pinfo->hReadPipe = pinfo->hWritePipe = INVALID_HANDLE_VALUE;
  25.  
  26.  #ifdef NOT_WORKING_YET
  27.      /*
  28. @@ -507,13 +507,14 @@ subcmd_popen_context *subcmd_popen(const char *command)
  29.      }
  30.  
  31.      (void)CloseHandle(pinfo->hWritePipe);
  32. +    pinfo->hWritePipe = INVALID_HANDLE_VALUE;
  33.  
  34.      return pinfo;
  35.  fail:
  36.      if (pinfo) {
  37. -        if (pinfo->hReadPipe)
  38. +        if (pinfo->hReadPipe != INVALID_HANDLE_VALUE)
  39.              (void)CloseHandle(pinfo->hReadPipe);
  40. -        if (pinfo->hWritePipe)
  41. +        if (pinfo->hWritePipe != INVALID_HANDLE_VALUE)
  42.              (void)CloseHandle(pinfo->hWritePipe);
  43.  
  44.          free(pinfo);
  45. diff --git a/tests/winsg/winsg.c b/tests/winsg/winsg.c
  46. index bfc0b49..1ac43f6 100644
  47. --- a/tests/winsg/winsg.c
  48. +++ b/tests/winsg/winsg.c
  49. @@ -545,7 +545,7 @@ int wmain(int ac, wchar_t *av[])
  50.          (int)subcmdret));
  51.  
  52.  done:
  53. -    if (tok == INVALID_HANDLE_VALUE) {
  54. +    if (tok != INVALID_HANDLE_VALUE) {
  55.          (void)CloseHandle(tok);
  56.      }
  57.  
  58. --
  59. 2.45.1
  60.  
  61. From 883e3bf0e8e1b7b62554991ec337e29e8b37246c Mon Sep 17 00:00:00 2001
  62. From: Roland Mainz <roland.mainz@nrubsig.org>
  63. Date: Fri, 20 Jun 2025 12:48:25 +0200
  64. Subject: [PATCH 2/2] tests: winsg.exe should have a /P option for powershell
  65.  
  66. winsg.exe should have a /P option for powershell.
  67.  
  68. Reported-by: Aurelien Couderc <aurelien.couderc2002@gmail.com>
  69. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  70. ---
  71. tests/winsg/winsg.c | 45 ++++++++++++++++++++++++++++++++++++++++-----
  72.  1 file changed, 40 insertions(+), 5 deletions(-)
  73.  
  74. diff --git a/tests/winsg/winsg.c b/tests/winsg/winsg.c
  75. index 1ac43f6..21ff821 100644
  76. --- a/tests/winsg/winsg.c
  77. +++ b/tests/winsg/winsg.c
  78. @@ -59,6 +59,8 @@
  79.  #define CYGWIN_BASH_PATH L"C:\\cygwin\\bin\\bash.exe"
  80.  #endif /* _WIN64 */
  81.  #define WIN32_CMDEXE_PATH L"C:\\Windows\\system32\\cmd.exe"
  82. +#define WIN32_POWERSHELLEXE_PATH \
  83. +    L"C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"
  84.  
  85.  /*
  86.   * DECLARE_SID_BUFFER - declare a buffer for a SID value
  87. @@ -284,6 +286,7 @@ int usage(void)
  88.      (void)fwprintf(stderr,
  89.          L"Usage: winsg [-] -g group [-c command]\n"
  90.          L"Usage: winsg [-] /g group [/C command]\n"
  91. +        L"Usage: winsg [-] /g group [/P command]\n"
  92.          L"Usage: winsg -L\n"
  93.          L"Usage: winsg /? | -h | --help\n"
  94.          L"Execute command as different primary group ID\n"
  95. @@ -292,17 +295,23 @@ int usage(void)
  96.          L"\t1. Run new cmd.exe with primary group 'abc1':\n"
  97.          L"\t\twinsg /g abc1 /C\n"
  98.          L"\n"
  99. -        L"\t2. Run new Cygwin shell (bash) with primary group 'abc2':\n"
  100. +        L"\t2. Run new powershell.exe with primary group 'abc1':\n"
  101. +        L"\t\twinsg /p abc1 /P\n"
  102. +        L"\n"
  103. +        L"\t3. Run new Cygwin shell (bash) with primary group 'abc2':\n"
  104.          L"\t\twinsg -g abc2 -c\n"
  105.          L"\n"
  106. -        L"\t3. Start /bin/id from cmd.exe with primary group 'abc3':\n"
  107. +        L"\t4. Start /bin/id from cmd.exe with primary group 'abc3':\n"
  108.          L"\t\twinsg /g abc3 /C 'C:\\cygwin64\\bin\\id.exe -a'\n"
  109.          L"\n"
  110. -        L"\t4. Start /bin/id from Cygwin shell (bash) with primary "
  111. +        L"\t5. Start /bin/id from powershell.exe with primary group 'abc3':\n"
  112. +        L"\t\twinsg /g abc3 /P 'C:\\cygwin64\\bin\\id.exe -a'\n"
  113. +        L"\n"
  114. +        L"\t6. Start /bin/id from Cygwin shell (bash) with primary "
  115.              L"group 'abc4':\n"
  116.          L"\t\twinsg -g abc4 -c '/bin/id.exe -a'\n"
  117.          L"\n"
  118. -        L"\t5. List currently available groups which can be passed to "
  119. +        L"\t7. List currently available groups which can be passed to "
  120.              L"winsg -g ...\n"
  121.          L"\t\twinsg -L\n"
  122.          L"\n"
  123. @@ -317,7 +326,8 @@ enum shelltype {
  124.      SHELLTYPE_NOT_SET = 0,
  125.      SHELLTYPE_NONE,
  126.      SHELLTYPE_CMD,
  127. -    SHELLTYPE_SYSTEM
  128. +    SHELLTYPE_SYSTEM,
  129. +    SHELLTYPE_POWERSHELL
  130.  };
  131.  
  132.  int wmain(int ac, wchar_t *av[])
  133. @@ -375,6 +385,20 @@ int wmain(int ac, wchar_t *av[])
  134.              cmd_arg_index = i+1;
  135.              break;
  136.          }
  137. +        else if (!wcscmp(av[i], L"/P")) {
  138. +            /* /P can take zero or one argument */
  139. +            if ((ac-i) > 2) {
  140. +                (void)fwprintf(stderr,
  141. +                    L"%ls: Too many arguments for /P.\n", av[0]);
  142. +                retval = 1;
  143. +                goto done;
  144. +            }
  145. +
  146. +            cmd_runasgroup = true;
  147. +            st = SHELLTYPE_POWERSHELL;
  148. +            cmd_arg_index = i+1;
  149. +            break;
  150. +        }
  151.          else if ((!wcscmp(av[i], L"-g")) ||
  152.              (!wcscmp(av[i], L"/g"))) {
  153.              newgrpname = av[i+1];
  154. @@ -532,6 +556,17 @@ int wmain(int ac, wchar_t *av[])
  155.                      WIN32_CMDEXE_PATH, WIN32_CMDEXE_PATH, NULL);
  156.              }
  157.              break;
  158. +        case SHELLTYPE_POWERSHELL:
  159. +            if (av[cmd_arg_index] != NULL) {
  160. +                subcmdret = _wspawnl(_P_WAIT,
  161. +                    WIN32_POWERSHELLEXE_PATH, WIN32_POWERSHELLEXE_PATH,
  162. +                    L"-Command", av[cmd_arg_index], NULL);
  163. +            }
  164. +            else {
  165. +                subcmdret = _wspawnl(_P_WAIT,
  166. +                    WIN32_POWERSHELLEXE_PATH, WIN32_POWERSHELLEXE_PATH, NULL);
  167. +            }
  168. +            break;
  169.          case SHELLTYPE_NONE:
  170.              subcmdret = _wspawnl(_P_WAIT,
  171.                  WIN32_CMDEXE_PATH, WIN32_CMDEXE_PATH, NULL);
  172. --
  173. 2.45.1

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