pastebin - collaborative debugging tool
rovema.kpaste.net RSS


msnfs41client: Patch for (group) ACLs, stability hacks+misc, 2024-03-07
Posted by Anonymous on Thu 7th Mar 2024 18:08
raw | new post

  1. From dbd35907572628462c4765da59f312a4e38ab6c8 Mon Sep 17 00:00:00 2001
  2. From: Roland Mainz <roland.mainz@nrubsig.org>
  3. Date: Thu, 7 Mar 2024 14:55:56 +0100
  4. Subject: [PATCH 1/5] cygwin/Makefile: Man pages be in usr/share/man, not
  5.  sbin/usr/share/man
  6.  
  7. Man pages be in installed in usr/share/man, not sbin/usr/share/man
  8. (basically a typo).
  9.  
  10. Reported-by: Martin Wege <martin.l.wege@gmail.com>
  11. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  12. ---
  13. cygwin/Makefile | 6 +++---
  14.  1 file changed, 3 insertions(+), 3 deletions(-)
  15.  
  16. diff --git a/cygwin/Makefile b/cygwin/Makefile
  17. index 44f3308..2ef2d29 100644
  18. --- a/cygwin/Makefile
  19. +++ b/cygwin/Makefile
  20. @@ -63,7 +63,7 @@ installdest: $(VS_BUILD_DIR)/nfsd.exe \
  21.         mkdir -p $(DESTDIR)/cygdrive/c/cygwin64/lib
  22.         mkdir -p $(DESTDIR)/cygdrive/c/cygwin64/lib/msnfs41client
  23.         mkdir -p $(DESTDIR)/cygdrive/c/cygwin64/usr/src/msnfs41client
  24. -       mkdir -p $(DESTDIR)/cygdrive/c/cygwin64/sbin/usr/share/man/man1
  25. +       mkdir -p $(DESTDIR)/cygdrive/c/cygwin64/usr/share/man/man1
  26.         cp -r $(VS_BUILD_DIR)/nfsd.exe          $(DESTDIR)/cygdrive/c/cygwin64/sbin/nfsd_debug.exe
  27.         cp -r $(VS_BUILD_DIR)/nfsd.pdb          $(DESTDIR)/cygdrive/c/cygwin64/sbin/nfsd_debug.pdb
  28.         cp -r $(VS_BUILD_DIR)/nfs_mount.*       $(DESTDIR)/cygdrive/c/cygwin64/sbin/.
  29. @@ -87,12 +87,12 @@ installdest: $(VS_BUILD_DIR)/nfsd.exe \
  30.         cp $(CYGWIN_MAKEFILE_DIR)/utils/mount_sshnfs/mount_sshnfs.ksh $(DESTDIR)/cygdrive/c/cygwin64/sbin/mount_sshnfs
  31.         chmod a+x $(DESTDIR)/cygdrive/c/cygwin64/sbin/mount_sshnfs
  32.         PATH+=":$(DESTDIR)/cygdrive/c/cygwin64/sbin/" \
  33. -               /usr/bin/ksh93 $(CYGWIN_MAKEFILE_DIR)/utils/mount_sshnfs/mount_sshnfs.ksh --nroff 2>"$(DESTDIR)/cygdrive/c/cygwin64/sbin/usr/share/man/man1/mount_sshnfs.1" || true
  34. +               /usr/bin/ksh93 $(CYGWIN_MAKEFILE_DIR)/utils/mount_sshnfs/mount_sshnfs.ksh --nroff 2>"$(DESTDIR)/cygdrive/c/cygwin64/usr/share/man/man1/mount_sshnfs.1" || true
  35.         cp $(CYGWIN_MAKEFILE_DIR)/utils/sshnfs/sshnfs.ksh $(DESTDIR)/cygdrive/c/cygwin64/sbin/sshnfs
  36.         chmod a+x $(DESTDIR)/cygdrive/c/cygwin64/sbin/sshnfs
  37.         cp $(CYGWIN_MAKEFILE_DIR)/utils/nfsurlconv/nfsurlconv.ksh $(DESTDIR)/cygdrive/c/cygwin64/bin/nfsurlconv
  38.         chmod a+x $(DESTDIR)/cygdrive/c/cygwin64/bin/nfsurlconv
  39. -       /usr/bin/ksh93 $(CYGWIN_MAKEFILE_DIR)/utils/nfsurlconv/nfsurlconv.ksh --nroff 2>"$(DESTDIR)/cygdrive/c/cygwin64/sbin/usr/share/man/man1/nfsurlconv.1" || true
  40. +       /usr/bin/ksh93 $(CYGWIN_MAKEFILE_DIR)/utils/nfsurlconv/nfsurlconv.ksh --nroff 2>"$(DESTDIR)/cygdrive/c/cygwin64/usr/share/man/man1/nfsurlconv.1" || true
  41.         @ printf "# Package tests\n"
  42.         cp "$(PROJECT_BASEDIR_DIR)/tests/winfsinfo1/winfsinfo.exe" $(DESTDIR)/cygdrive/c/cygwin64/bin/winfsinfo.exe
  43.         @ printf "# Package ksh93&co (if available) since Cygwin does not ship with it yet\n"
  44. --
  45. 2.43.0
  46.  
  47. From bbde5d3a4898fa4651e28c30c05f34488f508128 Mon Sep 17 00:00:00 2001
  48. From: Roland Mainz <roland.mainz@nrubsig.org>
  49. Date: Thu, 7 Mar 2024 15:00:40 +0100
  50. Subject: [PATCH 2/5] daemon: Improve |create_unknownsid()| performace
  51.  
  52. Improve |create_unknownsid()| performace by just allocating
  53. the maximum SID size (|SECURITY_MAX_SID_SIZE|), instead of
  54. calling |CreateWellKnownSid()| to get the buffer size,
  55. allocate the buffer and then do a second
  56. |CreateWellKnownSid()| to fill the buffer.
  57.  
  58. |SECURITY_MAX_SID_SIZE| is currently 68 bytes, typical SID
  59. from |CreateWellKnownSid()| needs 22 bytes, but the allocator
  60. has >= 128 byte granularity, so there is no difference in
  61. real memory usage.
  62.  
  63. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  64. ---
  65. daemon/sid.c | 38 +++++++++++++++++++-------------------
  66.  1 file changed, 19 insertions(+), 19 deletions(-)
  67.  
  68. diff --git a/daemon/sid.c b/daemon/sid.c
  69. index c12f54f..cbeac13 100644
  70. --- a/daemon/sid.c
  71. +++ b/daemon/sid.c
  72. @@ -43,35 +43,35 @@
  73.  int create_unknownsid(WELL_KNOWN_SID_TYPE type, PSID *sid, DWORD *sid_len)
  74.  {
  75.      int status;
  76. -    *sid_len = 0;
  77. -    *sid = NULL;
  78. -
  79. -    status = CreateWellKnownSid(type, NULL, *sid, sid_len);
  80. -    DPRINTF(ACLLVL,
  81. -        ("create_unknownsid: CreateWellKnownSid(type=%d) returned %d "
  82. -        "GetLastError %d sid len %d needed\n", (int)type, status,
  83. -        GetLastError(), *sid_len));
  84. -    if (status) {
  85. -        status = ERROR_INTERNAL_ERROR;
  86. -        goto err;
  87. -    }
  88. -    status = GetLastError();
  89. -    if (status != ERROR_INSUFFICIENT_BUFFER)
  90. -        goto err;
  91. +    int lasterr;
  92.  
  93. +    *sid_len = SECURITY_MAX_SID_SIZE+1;
  94.      *sid = malloc(*sid_len);
  95.      if (*sid == NULL) {
  96.          status = ERROR_INSUFFICIENT_BUFFER;
  97.          goto err;
  98.      }
  99. +
  100.      status = CreateWellKnownSid(type, NULL, *sid, sid_len);
  101. -    if (status)
  102. +    lasterr = GetLastError();
  103. +    if (status) {
  104. +        *sid_len = GetLengthSid(*sid);
  105. +
  106. +        DPRINTF(ACLLVL,
  107. +            ("create_unknownsid(type=%d): CreateWellKnownSid() "
  108. +            "returned %d GetLastError=%d *sid_len=%d\n",
  109. +            (int)type, status, lasterr, (int)*sid_len));
  110. +
  111.          return ERROR_SUCCESS;
  112. +    }
  113. +
  114. +    status = lasterr;
  115.      free(*sid);
  116. -    *sid = NULL;
  117. -    status = GetLastError();
  118.  err:
  119. -    eprintf("create_unknownsid: CreateWellKnownSid(type=%d) failed with %d\n",
  120. +    *sid = NULL;
  121. +    *sid_len = 0;
  122. +    eprintf("create_unknownsid(type=%d): "
  123. +        "CreateWellKnownSid failed with %d\n",
  124.          (int)type, status);
  125.      return status;
  126.  }
  127. --
  128. 2.43.0
  129.  
  130. From 909b1e40000735ac02d25d1372907b8ffd4c622f Mon Sep 17 00:00:00 2001
  131. From: Roland Mainz <roland.mainz@nrubsig.org>
  132. Date: Thu, 7 Mar 2024 15:28:08 +0100
  133. Subject: [PATCH 3/5] daemon: |handle_getacl()| should use name cache
  134.  
  135. |handle_getacl()| should use name cache |nfs41_cached_getattr()| API,
  136. and only fall-back to do a server roundtrip if ACL/owner/owner_group
  137. data are not available from the cache.
  138.  
  139. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  140. ---
  141. daemon/acl.c | 57 +++++++++++++++++++++++++++++++++++++++++-----------
  142.  1 file changed, 45 insertions(+), 12 deletions(-)
  143.  
  144. diff --git a/daemon/acl.c b/daemon/acl.c
  145. index a8e20f5..159c71c 100644
  146. --- a/daemon/acl.c
  147. +++ b/daemon/acl.c
  148. @@ -193,8 +193,7 @@ static int handle_getacl(void *daemon_context, nfs41_upcall *upcall)
  149.      nfs41_daemon_globals *nfs41dg = daemon_context;
  150.      getacl_upcall_args *args = &upcall->args.getacl;
  151.      nfs41_open_state *state = upcall->state_ref;
  152. -    nfs41_file_info info = { 0 };
  153. -    bitmap4 attr_request = { 0 };
  154. +    nfs41_file_info info;
  155.      LPSTR domain = NULL;
  156.      SECURITY_DESCRIPTOR sec_desc;
  157.      PACL dacl = NULL;
  158. @@ -204,20 +203,54 @@ static int handle_getacl(void *daemon_context, nfs41_upcall *upcall)
  159.      char owner[NFS4_OPAQUE_LIMIT], group[NFS4_OPAQUE_LIMIT];
  160.      nfsacl41 acl = { 0 };
  161.  
  162. -    // need to cache owner/group information XX
  163. -    attr_request.count = 2;
  164. -    attr_request.arr[1] = FATTR4_WORD1_OWNER | FATTR4_WORD1_OWNER_GROUP;
  165.      if (args->query & DACL_SECURITY_INFORMATION) {
  166. +use_nfs41_getattr:
  167. +        bitmap4 attr_request = { 0 };
  168. +        (void)memset(&info, 0, sizeof(nfs41_file_info));
  169. +        info.owner = owner;
  170. +        info.owner_group = group;
  171. +
  172. +        attr_request.count = 2;
  173. +        attr_request.arr[0] = FATTR4_WORD0_ACL;
  174. +        attr_request.arr[1] = FATTR4_WORD1_OWNER | FATTR4_WORD1_OWNER_GROUP;
  175.          info.acl = &acl;
  176. -        attr_request.arr[0] |= FATTR4_WORD0_ACL;
  177. +        status = nfs41_getattr(state->session, &state->file, &attr_request, &info);
  178. +        if (status) {
  179. +            eprintf("handle_getacl: nfs41_getattr() failed with %d\n",
  180. +                status);
  181. +            goto out;
  182. +        }
  183.      }
  184. -    info.owner = owner;
  185. -    info.owner_group = group;
  186. -    status = nfs41_getattr(state->session, &state->file, &attr_request, &info);
  187. -    if (status) {
  188. -        eprintf("handle_getacl: nfs41_cached_getattr() failed with %d\n",
  189. +    else {
  190. +        (void)memset(&info, 0, sizeof(nfs41_file_info));
  191. +        info.owner = owner;
  192. +        info.owner_group = group;
  193. +
  194. +        status = nfs41_cached_getattr(state->session, &state->file, &info);
  195. +        if (status) {
  196. +            eprintf("handle_getacl: nfs41_cached_getattr() failed with %d\n",
  197.                  status);
  198. -        goto out;
  199. +            goto out;
  200. +        }
  201. +
  202. +        EASSERT(info.attrmask.count >= 2);
  203. +
  204. +        /*
  205. +         * In rare cases owner/owner_group are not in the cache
  206. +         * (usually for new files). In this case do a full
  207. +         * roundtrip to the NFS server to get the data...
  208. +         */
  209. +        if ((info.attrmask.arr[1] &
  210. +            (FATTR4_WORD1_OWNER|FATTR4_WORD1_OWNER_GROUP)) != (FATTR4_WORD1_OWNER|FATTR4_WORD1_OWNER_GROUP)) {
  211. +            DPRINTF(0, ("handle_getattr: owner/owner_group not in cache, doing full lookup...\n"));
  212. +            goto use_nfs41_getattr;
  213. +        }
  214. +    }
  215. +
  216. +    EASSERT(info.attrmask.count >= 2);
  217. +    EASSERT((info.attrmask.arr[1] & (FATTR4_WORD1_OWNER|FATTR4_WORD1_OWNER_GROUP)) == (FATTR4_WORD1_OWNER|FATTR4_WORD1_OWNER_GROUP));
  218. +    if (args->query & DACL_SECURITY_INFORMATION) {
  219. +        EASSERT((info.attrmask.arr[0] & (FATTR4_WORD0_ACL)) == (FATTR4_WORD0_ACL));
  220.      }
  221.  
  222.      status = InitializeSecurityDescriptor(&sec_desc,
  223. --
  224. 2.43.0
  225.  
  226. From e62ab413fca9589553662783b4bc877fccde9f05 Mon Sep 17 00:00:00 2001
  227. From: Roland Mainz <roland.mainz@nrubsig.org>
  228. Date: Thu, 7 Mar 2024 15:30:32 +0100
  229. Subject: [PATCH 4/5] daemon: Add stabilty hacks to daemon/nfs41_ops.c
  230.  
  231. Add stability hacks to daemon/nfs41_ops.c to wallpaper over
  232. DrMemory "uninitialized read" issues until we have suitable
  233. resources (i.e. much faster machine) to properly hunt such
  234. issues down.
  235.  
  236. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  237. ---
  238. daemon/nfs41_ops.c | 36 +++++++++++++++++++++++++-----------
  239.  1 file changed, 25 insertions(+), 11 deletions(-)
  240.  
  241. diff --git a/daemon/nfs41_ops.c b/daemon/nfs41_ops.c
  242. index f54b72c..772a29d 100644
  243. --- a/daemon/nfs41_ops.c
  244. +++ b/daemon/nfs41_ops.c
  245. @@ -35,6 +35,20 @@
  246.  #include "daemon_debug.h"
  247.  #include "util.h"
  248.  
  249. +#ifdef NFS41_DRIVER_STABILITY_HACKS
  250. +/*
  251. + * gisburn: Fixme: Execute extra code for stability.
  252. + * We mainly use this to init structs with zeros here, until we have
  253. + * resources (time, much faster machine) to properly hunt down all
  254. + * uninitalised memory issues with DrMemory
  255. + */
  256. +#define NDSH(x) x
  257. +#define NDSH2(x,y) x,y
  258. +#else
  259. +#define NDSH(x)
  260. +#define NDSH2(x,y)
  261. +#endif /* NFS41_DRIVER_STABILITY_HACKS */
  262. +
  263.  int nfs41_exchange_id(
  264.      IN nfs41_rpc_clnt *rpc,
  265.      IN client_owner4 *owner,
  266. @@ -395,7 +409,7 @@ int nfs41_open(
  267.      nfs41_getfh_res getfh_res;
  268.      bitmap4 attr_request;
  269.      nfs41_getattr_args getattr_args;
  270. -    nfs41_getattr_res getattr_res, pgetattr_res;
  271. +    nfs41_getattr_res getattr_res NDSH(= { 0 }), pgetattr_res NDSH(= { 0 });
  272.      nfs41_savefh_res savefh_res;
  273.      nfs41_restorefh_res restorefh_res;
  274.      nfs41_file_info tmp_info, dir_info;
  275. @@ -554,7 +568,7 @@ int nfs41_create(
  276.      nfs41_create_res create_res;
  277.      nfs41_getfh_res getfh_res;
  278.      nfs41_getattr_args getattr_args;
  279. -    nfs41_getattr_res getattr_res, pgetattr_res;
  280. +    nfs41_getattr_res getattr_res NDSH(= { 0 }), pgetattr_res NDSH(= { 0 });
  281.      bitmap4 attr_request;
  282.      nfs41_file_info dir_info;
  283.      nfs41_savefh_res savefh_res;
  284. @@ -646,7 +660,7 @@ int nfs41_close(
  285.      nfs41_op_close_args close_args;
  286.      nfs41_op_close_res close_res;
  287.      nfs41_getattr_args getattr_args;
  288. -    nfs41_getattr_res getattr_res;
  289. +    nfs41_getattr_res getattr_res NDSH(= { 0 });
  290.      bitmap4 attr_request;
  291.      nfs41_file_info info;
  292.  
  293. @@ -1081,7 +1095,7 @@ int nfs41_getattr(
  294.      nfs41_putfh_args putfh_args;
  295.      nfs41_putfh_res putfh_res;
  296.      nfs41_getattr_args getattr_args;
  297. -    nfs41_getattr_res getattr_res;
  298. +    nfs41_getattr_res getattr_res NDSH(= { 0 });
  299.  
  300.      compound_init(&compound, argops, resops, "getattr");
  301.  
  302. @@ -1135,7 +1149,7 @@ int nfs41_superblock_getattr(
  303.      nfs41_putfh_args putfh_args;
  304.      nfs41_putfh_res putfh_res;
  305.      nfs41_getattr_args getattr_args;
  306. -    nfs41_getattr_res getattr_res;
  307. +    nfs41_getattr_res getattr_res NDSH(= { 0 });
  308.      nfs41_openattr_args openattr_args;
  309.      nfs41_openattr_res openattr_res;
  310.  
  311. @@ -1200,7 +1214,7 @@ int nfs41_remove(
  312.      nfs41_remove_args remove_args;
  313.      nfs41_remove_res remove_res;
  314.      nfs41_getattr_args getattr_args;
  315. -    nfs41_getattr_res getattr_res;
  316. +    nfs41_getattr_res getattr_res NDSH(= { 0 });
  317.      bitmap4 attr_request;
  318.      nfs41_file_info info;
  319.  
  320. @@ -1271,7 +1285,7 @@ int nfs41_rename(
  321.      nfs41_rename_args rename_args;
  322.      nfs41_rename_res rename_res;
  323.      nfs41_getattr_args getattr_args;
  324. -    nfs41_getattr_res src_getattr_res, dst_getattr_res;
  325. +    nfs41_getattr_res src_getattr_res NDSH(= { 0 }), dst_getattr_res NDSH(= { 0 });
  326.      nfs41_file_info src_info, dst_info;
  327.      bitmap4 attr_request;
  328.      nfs41_restorefh_res restorefh_res;
  329. @@ -1371,7 +1385,7 @@ int nfs41_setattr(
  330.      nfs41_setattr_args setattr_args;
  331.      nfs41_setattr_res setattr_res;
  332.      nfs41_getattr_args getattr_args;
  333. -    nfs41_getattr_res getattr_res;
  334. +    nfs41_getattr_res getattr_res NDSH(= { 0 });
  335.      bitmap4 attr_request;
  336.  
  337.      compound_init(&compound, argops, resops, "setattr");
  338. @@ -1457,7 +1471,7 @@ int nfs41_link(
  339.      nfs41_lookup_res lookup_res;
  340.      nfs41_getfh_res getfh_res;
  341.      nfs41_getattr_args getattr_args[2];
  342. -    nfs41_getattr_res getattr_res[2];
  343. +    nfs41_getattr_res getattr_res[2] NDSH2(= { 0, 0 });
  344.      nfs41_file_info info = { 0 };
  345.      nfs41_path_fh file;
  346.  
  347. @@ -1782,7 +1796,7 @@ enum nfsstat4 nfs41_fs_locations(
  348.      nfs41_lookup_args lookup_args;
  349.      nfs41_lookup_res lookup_res;
  350.      nfs41_getattr_args getattr_args;
  351. -    nfs41_getattr_res getattr_res;
  352. +    nfs41_getattr_res getattr_res NDSH(= { 0 });
  353.      bitmap4 attr_request = { 1, { FATTR4_WORD0_FS_LOCATIONS } };
  354.      nfs41_file_info info;
  355.  
  356. @@ -2048,7 +2062,7 @@ enum nfsstat4 pnfs_rpc_layoutcommit(
  357.      pnfs_layoutcommit_args lc_args;
  358.      pnfs_layoutcommit_res lc_res;
  359.      nfs41_getattr_args getattr_args;
  360. -    nfs41_getattr_res getattr_res;
  361. +    nfs41_getattr_res getattr_res NDSH(= { 0 });
  362.      bitmap4 attr_request;
  363.  
  364.      nfs41_superblock_getattr_mask(file->fh.superblock, &attr_request);
  365. --
  366. 2.43.0
  367.  
  368. From 68cdb89bfa7aad4841d76e7275adfbf0105a7013 Mon Sep 17 00:00:00 2001
  369. From: Roland Mainz <roland.mainz@nrubsig.org>
  370. Date: Thu, 7 Mar 2024 18:41:22 +0100
  371. Subject: [PATCH 5/5] daemon: Fix setting group ACLs via "icacls"&co.
  372.  
  373. Fix setting group ACLs (e.g. via "icacls"), as they are treated as
  374. user principals and not group principals.
  375.  
  376. The NFSv4 server was logging this warning: "nss_getpwnam: name 'mygrp'
  377. not found in domain 'mydomain'", to indicate it could not find the
  378. *USER* account "mygrp" (which only exists as GROUP account).
  379.  
  380. The fix is to set the |ACE4_IDENTIFIER_GROUP| flag in the NFSv4 ACLs
  381. so that the NFSv4 server does a group name lookup.
  382.  
  383. Testcase:
  384. -------- snip --------
  385. $ rm -f test1.txt
  386. $ touch test1.txt
  387. $ icacls test1.txt /grant:r 'cygwingrp1:(WDAC)' /t /c
  388. Bearbeitete Datei: test1.txt
  389. 1 Dateien erfolgreich verarbeitet, bei 0 Dateien ist ein Verarbeitungsfehler aufgetreten.
  390.  
  391. $ icacls test1.txt /grant:r 'cygwingrp2:(WDAC)' /t /c
  392. Bearbeitete Datei: test1.txt
  393. 1 Dateien erfolgreich verarbeitet, bei 0 Dateien ist ein Verarbeitungsfehler aufgetreten.
  394.  
  395. $ getfacl test1.txt
  396. user::r--
  397. group::r--
  398. group:cygwingrp1:r--
  399. group:cygwingrp2:r--
  400. mask::r--
  401. other::r--
  402. -------- snip --------
  403.  
  404. Reported-by: Josh Hurst <joshhurst@gmail.com>
  405. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  406. ---
  407. daemon/acl.c          | 41 +++++++++++++++++++++++++++++++++++------
  408.  daemon/idmap_cygwin.c |  6 ++++++
  409.  2 files changed, 41 insertions(+), 6 deletions(-)
  410.  
  411. diff --git a/daemon/acl.c b/daemon/acl.c
  412. index 159c71c..0a67b80 100644
  413. --- a/daemon/acl.c
  414. +++ b/daemon/acl.c
  415. @@ -490,11 +490,11 @@ static void map_acemask(ACCESS_MASK mask, int file_type, uint32_t *nfs4_mask)
  416.      print_nfs_access_mask(ACLLVL, *nfs4_mask);
  417.  }
  418.  
  419. -static int map_nfs4ace_who(PSID sid, PSID owner_sid, PSID group_sid, char *who_out, char *domain)
  420. +static int map_nfs4ace_who(PSID sid, PSID owner_sid, PSID group_sid, char *who_out, char *domain, SID_NAME_USE *sid_type_out)
  421.  {
  422.      int status;
  423.      DWORD size = 0, tmp_size = 0;
  424. -    SID_NAME_USE sid_type;
  425. +    SID_NAME_USE sid_type = 0;
  426.      LPSTR tmp_buf = NULL, who = NULL;
  427.      LPSTR sidstr = NULL;
  428.  
  429. @@ -513,6 +513,7 @@ static int map_nfs4ace_who(PSID sid, PSID owner_sid, PSID group_sid, char *who_o
  430.          if (EqualSid(sid, owner_sid)) {
  431.              DPRINTF(ACLLVL, ("map_nfs4ace_who: this is owner's sid\n"));
  432.              memcpy(who_out, ACE4_OWNER, strlen(ACE4_OWNER)+1);
  433. +            sid_type = SidTypeUser;
  434.              status = ERROR_SUCCESS;
  435.              goto out;
  436.          }
  437. @@ -525,6 +526,7 @@ static int map_nfs4ace_who(PSID sid, PSID owner_sid, PSID group_sid, char *who_o
  438.          if (EqualSid(sid, group_sid)) {
  439.              DPRINTF(ACLLVL, ("map_nfs4ace_who: this is group's sid\n"));
  440.              memcpy(who_out, ACE4_GROUP, strlen(ACE4_GROUP)+1);
  441. +            sid_type = SidTypeGroup;
  442.              status = ERROR_SUCCESS;
  443.              goto out;
  444.          }
  445. @@ -533,9 +535,11 @@ static int map_nfs4ace_who(PSID sid, PSID owner_sid, PSID group_sid, char *who_o
  446.      if (status) {
  447.          if (!strncmp(who_out, ACE4_NOBODY, strlen(ACE4_NOBODY))) {
  448.              size = (DWORD)strlen(ACE4_NOBODY);
  449. +            sid_type = SidTypeUser;
  450.              goto add_domain;
  451.          }
  452.  
  453. +        /* fixme: What about |sid_type| */
  454.          status = ERROR_SUCCESS;
  455.          goto out;
  456.      }
  457. @@ -618,7 +622,10 @@ out:
  458.          DPRINTF(ACLLVL, ("<-- map_nfs4ace_who() returns %d\n", status));
  459.      }
  460.      else {
  461. -        DPRINTF(ACLLVL, ("<-- map_nfs4ace_who(who_out='%s') returns %d\n", who_out, status));
  462. +        DPRINTF(ACLLVL, ("<-- map_nfs4ace_who(who_out='%s', sid_type=%d) returns %d\n", who_out, status, sid_type));
  463. +        if (sid_type_out) {
  464. +            *sid_type_out = sid_type;
  465. +        }
  466.      }
  467.      if (sidstr)
  468.          LocalFree(sidstr);
  469. @@ -652,6 +659,7 @@ static int map_dacl_2_nfs4acl(PACL acl, PSID sid, PSID gsid, nfsacl41 *nfs4_acl,
  470.          int i;
  471.          PACE_HEADER ace;
  472.          PBYTE tmp_pointer;
  473. +        SID_NAME_USE who_sid_type = 0;
  474.  
  475.          DPRINTF(ACLLVL, ("NON-NULL dacl with %d ACEs\n", acl->AceCount));
  476.          print_hexbuf_no_asci(ACLLVL, (unsigned char *)"ACL\n",
  477. @@ -690,10 +698,31 @@ static int map_dacl_2_nfs4acl(PACL acl, PSID sid, PSID gsid, nfsacl41 *nfs4_acl,
  478.                          &nfs4_acl->aces[i].acemask);
  479.  
  480.              tmp_pointer += sizeof(ACCESS_MASK) + sizeof(ACE_HEADER);
  481. +
  482.              status = map_nfs4ace_who(tmp_pointer, sid, gsid, nfs4_acl->aces[i].who,
  483. -                                     domain);
  484. +                                     domain, &who_sid_type);
  485.              if (status)
  486.                  goto out_free;
  487. +
  488. +            /*
  489. +             * Treat |SidTypeAlias| as (local) group
  490. +             *
  491. +             * It seems that |LookupAccount*A()| will always return
  492. +             * |SidTypeAlias| for local groups created with
  493. +             * $ net localgroup cygwingrp1 /add #
  494. +             *
  495. +             * References:
  496. +             * - https://stackoverflow.com/questions/39373188/lookupaccountnamew-returns-sidtypealias-but-expected-sidtypegroup
  497. +             */
  498. +            if ((who_sid_type == SidTypeGroup) ||
  499. +                (who_sid_type == SidTypeAlias)) {
  500. +                DPRINTF(ACLLVL, ("map_dacl_2_nfs4acl: "
  501. +                    "who_sid_type=%d, setting group flag for '%s'\n",
  502. +                    (int)who_sid_type,
  503. +                    nfs4_acl->aces[i].who));
  504. +                nfs4_acl->aces[i].aceflag |= ACE4_IDENTIFIER_GROUP;
  505. +            }
  506. +
  507.          }
  508.      }
  509.      status = ERROR_SUCCESS;
  510. @@ -730,7 +759,7 @@ static int handle_setacl(void *daemon_context, nfs41_upcall *upcall)
  511.          }
  512.  
  513.          status = map_nfs4ace_who(sid, NULL, NULL, ownerbuf,
  514. -            nfs41dg->localdomain_name);
  515. +            nfs41dg->localdomain_name, NULL);
  516.          if (status)
  517.              goto out;
  518.  
  519. @@ -749,7 +778,7 @@ static int handle_setacl(void *daemon_context, nfs41_upcall *upcall)
  520.          }
  521.  
  522.          status = map_nfs4ace_who(sid, NULL, NULL, groupbuf,
  523. -            nfs41dg->localdomain_name);
  524. +            nfs41dg->localdomain_name, NULL);
  525.          if (status)
  526.              goto out;
  527.  
  528. diff --git a/daemon/idmap_cygwin.c b/daemon/idmap_cygwin.c
  529. index 766e784..f86d038 100644
  530. --- a/daemon/idmap_cygwin.c
  531. +++ b/daemon/idmap_cygwin.c
  532. @@ -124,6 +124,9 @@ int cygwin_getent_passwd(const char *name, char *res_loginname, uid_t *res_uid,
  533.          }
  534.      }
  535.  
  536. +    if (!localaccoutname)
  537. +        goto fail;
  538. +
  539.      if (res_loginname)
  540.          (void)strcpy_s(res_loginname, VAL_LEN, localaccoutname);
  541.      *res_uid = uid;
  542. @@ -230,6 +233,9 @@ int cygwin_getent_group(const char* name, char* res_group_name, gid_t* res_gid)
  543.          }
  544.      }
  545.  
  546. +    if (!localgroupname)
  547. +        goto fail;
  548. +
  549.      if (res_group_name)
  550.          (void)strcpy_s(res_group_name, VAL_LEN, localgroupname);
  551.      *res_gid = gid;
  552. --
  553. 2.43.0

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