pastebin - collaborative debugging tool
rovema.kpaste.net RSS


msnfs41client: Patches for testing (group) ACLs, performance, misc, 2024-03-12
Posted by Anonymous on Tue 12th Mar 2024 11:25
raw | new post

  1. From 55dc2ac55387e25f708a924d15c4f04542bb966d Mon Sep 17 00:00:00 2001
  2. From: Roland Mainz <roland.mainz@nrubsig.org>
  3. Date: Mon, 11 Mar 2024 13:22:52 +0100
  4. Subject: [PATCH 1/6] cygwin: bintarball README should automagically get
  5.  filename+sha256 hash
  6.  
  7. The bintarball README should get the tar.bz2 tarball filename and it's
  8. sha256 hash automatically during $ make bintarball # time.
  9.  
  10. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  11. ---
  12. cygwin/Makefile              | 11 +++++++----
  13.  cygwin/README.bintarball.txt |  8 +++++---
  14.  2 files changed, 12 insertions(+), 7 deletions(-)
  15.  
  16. diff --git a/cygwin/Makefile b/cygwin/Makefile
  17. index 2ef2d29..71afd3c 100644
  18. --- a/cygwin/Makefile
  19. +++ b/cygwin/Makefile
  20. @@ -107,16 +107,19 @@ installdest: $(VS_BUILD_DIR)/nfsd.exe \
  21.                 "$(DESTDIR)/cygdrive/c/cygwin64/sbin/"
  22.  
  23.  bintarball: installdest
  24. -       set -o errexit ; \
  25. +       set -o errexit ; set -o xtrace ; \
  26.         base_filename="msnfs41client_cygwin_binaries_$$(date +%Y%m%d_%Hh%Mm)_git$$(git rev-parse --short HEAD)" ; \
  27.         ( \
  28.         cd "$(DESTDIR)" && \
  29. -       cp "../cygwin/README.bintarball.txt" "$${base_filename}.readme" && \
  30. -       tar -cvf - \
  31. +       true tar -cvf - \
  32.                 --owner=SYSTEM:18 \
  33.                 --group=SYSTEM:18 \
  34.                 cygdrive/c/cygwin64 | \
  35. -                       bzip2 -9 >"$${base_filename}.tar.bz2" \
  36. +                       bzip2 -9 >"$${base_filename}.tar.bz2" ; \
  37. +       archive_sha256hash="$$(openssl sha256 -r "$${base_filename}.tar.bz2" | while read a dummy ; do printf "%s\n" "$$a" ; done)" ; \
  38. +               sed -E <"../cygwin/README.bintarball.txt" \
  39. +                       -e "s/\\$$\{bintarball.base_filename\}/$${base_filename}/g" \
  40. +                       -e "s/\\$$\{bintarball.archive_sha256hash\}/$${archive_sha256hash}/g" >"$${base_filename}.readme" \
  41.         ) ; \
  42.         printf "\n#\n# tarball is ready now\n#\n" ; \
  43.         ls -l "$(DESTDIR)/$${base_filename}.tar.bz2" ; \
  44. diff --git a/cygwin/README.bintarball.txt b/cygwin/README.bintarball.txt
  45. index 4c52ec8..912a449 100644
  46. --- a/cygwin/README.bintarball.txt
  47. +++ b/cygwin/README.bintarball.txt
  48. @@ -98,13 +98,15 @@ NFSv4.1 client and filesystem driver for Windows 10/11
  49.  #
  50.  $ mkdir -p ~/download
  51.  $ cd ~/download
  52. -$ wget 'http://www.nrubsig.org/people/gisburn/work/msnfs41client/releases/testing/msnfs41client_cygwin_binaries_git148e927_20231214_12h31m.tar.bz2'
  53. +$ wget 'http://www.nrubsig.org/people/gisburn/work/msnfs41client/releases/testing/${bintarball.base_filename}.tar.bz2'
  54. +$ openssl sha256 "${bintarball.base_filename}.tar.bz2"
  55. +SHA2-256(${bintarball.base_filename}.tar.bz2)= ${bintarball.archive_sha256hash}
  56.  
  57.  
  58.  #
  59.  # 5. Installation (as "Administrator"):
  60.  #
  61. -$ (cd / && tar -xf ~/download/msnfs41client_cygwin_binaries_git148e927_20231214_12h31m.tar.bz2 )
  62. +$ (cd / && tar -xf ~/download/${bintarball.base_filename}.tar.bz2 )
  63.  $ /sbin/msnfs41client install
  64.  <REBOOT>
  65.  
  66. @@ -112,7 +114,7 @@ $ /sbin/msnfs41client install
  67.  #
  68.  # 6. Deinstallation:
  69.  #
  70. -$ (set -x ; cd / && tar -tf ~/download/msnfs41client_cygwin_binaries_git148e927_20231214_12h31m.tar.bz2 | while read i ; do [[ -f "$i" ]] && rm "$i" ; done)
  71. +$ (set -o xtrace ; cd / && tar -tf ~/download/${bintarball.base_filename}.tar.bz2 | while read i ; do [[ -f "$i" ]] && rm "$i" ; done)
  72.  <REBOOT>
  73.  
  74.  
  75. --
  76. 2.43.0
  77.  
  78. From da9d40e81cb2c21ca007fee47e72f5fa36c411cd Mon Sep 17 00:00:00 2001
  79. From: Roland Mainz <roland.mainz@nrubsig.org>
  80. Date: Mon, 11 Mar 2024 15:23:16 +0100
  81. Subject: [PATCH 2/6] cygwin,tests: Document usage for group ACLs
  82.  
  83. Document usage for group ACLs in bintarball README and manual test
  84. documentation.
  85.  
  86. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  87. ---
  88. cygwin/README.bintarball.txt | 17 +++++++++++++++--
  89.  tests/manual_testing.txt     | 35 +++++++++++++++++++++++++++++++++++
  90.  2 files changed, 50 insertions(+), 2 deletions(-)
  91.  
  92. diff --git a/cygwin/README.bintarball.txt b/cygwin/README.bintarball.txt
  93. index 912a449..26cc9c3 100644
  94. --- a/cygwin/README.bintarball.txt
  95. +++ b/cygwin/README.bintarball.txt
  96. @@ -203,9 +203,9 @@ $ /sbin/nfs_mount
  97.  - ACLs are supported via the normal Windows ACL tools, but on
  98.    Linux require the nfs4_getfacl/nfs4_setfacl utilities to see the
  99.    data.
  100. -  Example (assuming that Windows, Linux NFSv4 client and NFSv4
  101. +  * Example 1 (assuming that Windows, Linux NFSv4 client and NFSv4
  102.    server have a user "siegfried_wulsch"):
  103. -  - On Windows on a NFSv4 filesystem, :
  104. +  - On Windows on a NFSv4 filesystem:
  105.    $ icacls myhorribledata.txt /grant "siegfried_wulsch:WD" #
  106.    - On Linux NFSv4 clients you will then see this:
  107.    ---- snip ----
  108. @@ -216,6 +216,19 @@ $ /sbin/nfs_mount
  109.    A::EVERYONE@:rtcy
  110.    ---- snip ----
  111.  
  112. +  * Example 2 (assuming that Windows, Linux NFSv4 client and NFSv4
  113. +  server have a group "cygwingrp2"):
  114. +  - On Windows on a NFSv4 filesystem:
  115. +  $ icacls myhorribledata.txt /grant "cygwingrp2:(WDAC)" /t /c #
  116. +  - On Linux NFSv4 clients you will then see this:
  117. +  ---- snip ----
  118. +  $ nfs4_getfacl myhorribledata.txt
  119. +  A::OWNER@:rwatTcCy
  120. +  A::GROUP@:rtcy
  121. +  A:g:cygwingrp2@global.loc:rtcy
  122. +  A::EVERYONE@:rtcy
  123. +  ---- snip ----
  124. +
  125.  - nfs_mount only works when the NFSv4 server allows connections from
  126.    ports >= 1024, as Windows does not allow the Windows NFSv4 client
  127.    to use a "privileged port" (i.e. TCP port number < 1024)).
  128. diff --git a/tests/manual_testing.txt b/tests/manual_testing.txt
  129. index c9c34a6..8ebe9a6 100644
  130. --- a/tests/manual_testing.txt
  131. +++ b/tests/manual_testing.txt
  132. @@ -93,6 +93,41 @@ root@DERFWNB4966:~# usermod -a -G cygwingrp1 roland_mainz
  133.  root@DERFWNB4966:~# usermod -a -G cygwingrp2 roland_mainz
  134.  ---- snip ---
  135.  
  136. +#
  137. +# Test for group ACLs
  138. +#
  139. +Testcase:
  140. +-------- snip --------
  141. +# cd to a NFSv4.1 filesystem
  142. +$ rm -f test1.txt
  143. +$ touch test1.txt
  144. +$ icacls test1.txt /grant:r 'cygwingrp1:(WDAC)' /t /c
  145. +Bearbeitete Datei: test1.txt
  146. +1 Dateien erfolgreich verarbeitet, bei 0 Dateien ist ein Verarbeitungsfehler aufgetreten.
  147. +
  148. +$ icacls test1.txt /grant:r 'cygwingrp2:(WDAC)' /t /c
  149. +Bearbeitete Datei: test1.txt
  150. +1 Dateien erfolgreich verarbeitet, bei 0 Dateien ist ein Verarbeitungsfehler aufgetreten.
  151. +
  152. +# expectation:
  153. +# getfact output should contain both "cygwingrp1" and "cygwingrp2":
  154. +$ getfacl test1.txt
  155. +user::r--
  156. +group::r--
  157. +group:cygwingrp1:r--
  158. +group:cygwingrp2:r--
  159. +mask::r--
  160. +other::r--
  161. +-------- snip --------
  162. +
  163. +or one-liner:
  164. +-------- snip --------
  165. +# cd to a NFSv4.1 filesystem
  166. +# getfact output should contain both "cygwingrp1" and "cygwingrp2"
  167. +ksh93 -c 'rm -f test1.txt ; touch test1.txt ; icacls test1.txt /grant:r "cygwingrp1:(WDAC)" /grant:r "cygwingrp2:(WDAC)" /t /c ; getfacl test1.txt | grep -C 20 --colour -E "cygwingrp[12]"'
  168. +-------- snip --------
  169. +
  170. +
  171.  
  172.  #
  173.  # Compile each of the following package
  174. --
  175. 2.43.0
  176.  
  177. From 89e18b784b00fb8bafb7b7cd37d7f87c1ba128c9 Mon Sep 17 00:00:00 2001
  178. From: Roland Mainz <roland.mainz@nrubsig.org>
  179. Date: Mon, 11 Mar 2024 15:41:57 +0100
  180. Subject: [PATCH 3/6] sys: Add missing whitespace in |marshal_nfs41_dirquery()|
  181.  debug output
  182.  
  183. Add missing whitespace in |marshal_nfs41_dirquery()| debug output
  184.  
  185. Reported-by: Cedric Blancher <cedric.blancher@gmail.com>
  186. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  187. ---
  188. sys/nfs41_driver.c | 2 +-
  189.  1 file changed, 1 insertion(+), 1 deletion(-)
  190.  
  191. diff --git a/sys/nfs41_driver.c b/sys/nfs41_driver.c
  192. index 3d1b992..2d06e7d 100644
  193. --- a/sys/nfs41_driver.c
  194. +++ b/sys/nfs41_driver.c
  195. @@ -1020,7 +1020,7 @@ NTSTATUS marshal_nfs41_dirquery(
  196.      *len = header_len;
  197.  
  198.  #ifdef DEBUG_MARSHAL_DETAIL
  199. -    DbgP("marshal_nfs41_dirquery: filter='%wZ'class=%d len=%d "
  200. +    DbgP("marshal_nfs41_dirquery: filter='%wZ' class=%d len=%d "
  201.           "1st\\restart\\single=%d\\%d\\%d\n", entry->u.QueryFile.filter,
  202.           entry->u.QueryFile.InfoClass, entry->buf_len,
  203.           entry->u.QueryFile.initial_query, entry->u.QueryFile.restart_scan,
  204. --
  205. 2.43.0
  206.  
  207. From c8e4f68451942f757e888e901ebd3ab898d4e6f3 Mon Sep 17 00:00:00 2001
  208. From: Roland Mainz <roland.mainz@nrubsig.org>
  209. Date: Tue, 12 Mar 2024 09:35:00 +0100
  210. Subject: [PATCH 4/6] daemon: cleanup: SID code should use |ULEN|+prefix
  211.  varnames nfs/win32
  212.  
  213. Minor cleanup: SID code should use |ULEN|+prefix varnames with nfs* or
  214. win32*, depening on whether the name is from the Win32 account or NFS
  215. account namespace.
  216.  
  217. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  218. ---
  219. daemon/acl.c |   2 +-
  220.  daemon/sid.c | 129 ++++++++++++++++++++++++++-------------------------
  221.  2 files changed, 66 insertions(+), 65 deletions(-)
  222.  
  223. diff --git a/daemon/acl.c b/daemon/acl.c
  224. index c34461d..65c20e9 100644
  225. --- a/daemon/acl.c
  226. +++ b/daemon/acl.c
  227. @@ -200,7 +200,7 @@ static int handle_getacl(void *daemon_context, nfs41_upcall *upcall)
  228.      PSID *sids = NULL;
  229.      PSID osid = NULL, gsid = NULL;
  230.      DWORD sid_len;
  231. -    char owner[NFS4_OPAQUE_LIMIT], group[NFS4_OPAQUE_LIMIT];
  232. +    char owner[NFS4_OPAQUE_LIMIT+1], group[NFS4_OPAQUE_LIMIT+1];
  233.      nfsacl41 acl = { 0 };
  234.  
  235.      if (args->query & DACL_SECURITY_INFORMATION) {
  236. diff --git a/daemon/sid.c b/daemon/sid.c
  237. index cbeac13..db0df3a 100644
  238. --- a/daemon/sid.c
  239. +++ b/daemon/sid.c
  240. @@ -25,6 +25,7 @@
  241.  #include <time.h>
  242.  #include <strsafe.h>
  243.  #include <sddl.h>
  244. +#include <Lmcons.h>
  245.  
  246.  #include "nfs41_ops.h"
  247.  #include "nfs41_build_features.h"
  248. @@ -181,8 +182,8 @@ BOOL allocate_unixgroup_sid(unsigned long gid, PSID *pSid)
  249.  
  250.  typedef struct _sidcache_entry
  251.  {
  252. -#define SIDCACHE_ENTRY_NAME_SIZE (128)
  253. -    char    name[SIDCACHE_ENTRY_NAME_SIZE]; /* must fit something like "user@domain" */
  254. +#define SIDCACHE_ENTRY_NAME_SIZE (UNLEN + 1)
  255. +    char    win32name[SIDCACHE_ENTRY_NAME_SIZE]; /* must fit something like "user@domain" */
  256.      PSID    sid;
  257.      DWORD   sid_len;
  258.      char    sid_buffer[SECURITY_MAX_SID_SIZE+1];
  259. @@ -209,7 +210,7 @@ void sidcache_init(void)
  260.  }
  261.  
  262.  /* copy SID |value| into cache */
  263. -void sidcache_add(sidcache *cache, const char* name, PSID value)
  264. +void sidcache_add(sidcache *cache, const char* win32name, PSID value)
  265.  {
  266.      int i;
  267.      ssize_t freeEntryIndex;
  268. @@ -225,7 +226,7 @@ void sidcache_add(sidcache *cache, const char* name, PSID value)
  269.          if ((e->sid != NULL) &&
  270.              (e->timestamp < (currentTimestamp - SIDCACHE_TTL))) {
  271.              e->sid = NULL;
  272. -            e->name[0] = '\0';
  273. +            e->win32name[0] = '\0';
  274.              e->sid_len = 0;
  275.          }
  276.      }
  277. @@ -251,13 +252,13 @@ void sidcache_add(sidcache *cache, const char* name, PSID value)
  278.      e->sid = (PSID)e->sid_buffer;
  279.      if (!CopySid(sid_len, e->sid, value)) {
  280.          e->sid = NULL;
  281. -        e->name[0] = '\0';
  282. +        e->win32name[0] = '\0';
  283.          e->sid_len = 0;
  284.          goto done;
  285.      }
  286.  
  287.      e->sid_len = sid_len;
  288. -    (void)strcpy_s(e->name, SIDCACHE_ENTRY_NAME_SIZE, name);
  289. +    (void)strcpy(e->win32name, win32name);
  290.      e->timestamp = currentTimestamp;
  291.  
  292.      cache->cacheIndex = (cache->cacheIndex + 1) % SIDCACHE_SIZE;
  293. @@ -267,7 +268,7 @@ done:
  294.  }
  295.  
  296.  /* return |malloc()|'ed copy of SID from cache entry */
  297. -PSID *sidcache_getcached(sidcache *cache, const char *name)
  298. +PSID *sidcache_getcached(sidcache *cache, const char *win32name)
  299.  {
  300.      int i;
  301.      time_t currentTimestamp;
  302. @@ -281,7 +282,7 @@ PSID *sidcache_getcached(sidcache *cache, const char *name)
  303.          e = &cache->entries[i];
  304.  
  305.          if ((e->sid != NULL) &&
  306. -            (!strcmp(e->name, name)) &&
  307. +            (!strcmp(e->win32name, win32name)) &&
  308.              ((currentTimestamp - e->timestamp) < SIDCACHE_TTL)) {
  309.              PSID malloced_sid = malloc(e->sid_len);
  310.              if (!malloced_sid)
  311. @@ -304,22 +305,22 @@ done:
  312.  #endif /* NFS41_DRIVER_SID_CACHE */
  313.  
  314.  
  315. -int map_nfs4servername_2_sid(nfs41_daemon_globals *nfs41dg, int query, DWORD *sid_len, PSID *sid, LPCSTR name)
  316. +int map_nfs4servername_2_sid(nfs41_daemon_globals *nfs41dg, int query, DWORD *sid_len, PSID *sid, LPCSTR nfsname)
  317.  {
  318. -    const char *orig_name = name;
  319. +    const char *orig_nfsname = nfsname;
  320.  
  321.      int status = ERROR_INTERNAL_ERROR;
  322.      SID_NAME_USE sid_type = 0;
  323. -    char name_buff[256+2];
  324. -    char domain_buff[256+2];
  325. +    char nfsname_buff[UNLEN+1];
  326. +    char domain_buff[UNLEN+1];
  327.      DWORD domain_len = 0;
  328.  #ifdef NFS41_DRIVER_FEATURE_MAP_UNMAPPED_USER_TO_UNIXUSER_SID
  329.      signed long user_uid = -1;
  330.      signed long group_gid = -1;
  331.  #endif /* NFS41_DRIVER_FEATURE_MAP_UNMAPPED_USER_TO_UNIXUSER_SID */
  332.  
  333. -    DPRINTF(ACLLVL, ("--> map_nfs4servername_2_sid(query=%x,name='%s')\n",
  334. -        query, name));
  335. +    DPRINTF(ACLLVL, ("--> map_nfs4servername_2_sid(query=%x,nfsname='%s')\n",
  336. +        query, nfsname));
  337.  
  338.  #ifdef NFS41_DRIVER_FEATURE_MAP_UNMAPPED_USER_TO_UNIXUSER_SID
  339.      /* use our own idmapper script to map nfsv4 owner string to local Windows account */
  340. @@ -328,9 +329,9 @@ int map_nfs4servername_2_sid(nfs41_daemon_globals *nfs41dg, int query, DWORD *si
  341.          gid_t gdummy = -1;
  342.  
  343.  #ifdef NFS41_DRIVER_SID_CACHE
  344. -        if (*sid = sidcache_getcached(&user_sidcache, name)) {
  345. +        if (*sid = sidcache_getcached(&user_sidcache, nfsname)) {
  346.              *sid_len = GetLengthSid(*sid);
  347. -            DPRINTF(1, ("map_nfs4servername_2_sid: returning cached sid for user '%s'\n", name));
  348. +            DPRINTF(1, ("map_nfs4servername_2_sid: returning cached sid for user '%s'\n", nfsname));
  349.              status = 0;
  350.              goto out;
  351.          }
  352. @@ -339,13 +340,13 @@ int map_nfs4servername_2_sid(nfs41_daemon_globals *nfs41dg, int query, DWORD *si
  353.  #ifndef NFS41_DRIVER_SID_CACHE
  354.          /* gisburn: fixme: We must cache this, or the performance impact will be devastating!! */
  355.  #endif /* !NFS41_DRIVER_SID_CACHE */
  356. -        if (!cygwin_getent_passwd(name, name_buff, &udummy, &gdummy)) {
  357. -            if (strcmp(name, name_buff)) {
  358. +        if (!cygwin_getent_passwd(nfsname, nfsname_buff, &udummy, &gdummy)) {
  359. +            if (strcmp(nfsname, nfsname_buff)) {
  360.                  DPRINTF(1,
  361.                      ("map_nfs4servername_2_sid: remap user '%s' --> '%s'\n",
  362. -                    name,
  363. -                    name_buff));
  364. -                name = name_buff;
  365. +                    nfsname,
  366. +                    nfsname_buff));
  367. +                nfsname = nfsname_buff;
  368.              }
  369.          }
  370.      }
  371. @@ -358,9 +359,9 @@ int map_nfs4servername_2_sid(nfs41_daemon_globals *nfs41dg, int query, DWORD *si
  372.          gid_t gdummy = -1;
  373.  
  374.  #ifdef NFS41_DRIVER_SID_CACHE
  375. -        if (*sid = sidcache_getcached(&group_sidcache, name)) {
  376. +        if (*sid = sidcache_getcached(&group_sidcache, nfsname)) {
  377.              *sid_len = GetLengthSid(*sid);
  378. -            DPRINTF(1, ("map_nfs4servername_2_sid: returning cached sid for group '%s'\n", name));
  379. +            DPRINTF(1, ("map_nfs4servername_2_sid: returning cached sid for group '%s'\n", nfsname));
  380.              status = 0;
  381.              goto out;
  382.          }
  383. @@ -369,13 +370,13 @@ int map_nfs4servername_2_sid(nfs41_daemon_globals *nfs41dg, int query, DWORD *si
  384.  #ifndef NFS41_DRIVER_SID_CACHE
  385.          /* gisburn: fixme: We must cache this, or the performance impact will be devastating!! */
  386.  #endif /* !NFS41_DRIVER_SID_CACHE */
  387. -        if (!cygwin_getent_group(name, name_buff, &gdummy)) {
  388. -            if (strcmp(name, name_buff)) {
  389. +        if (!cygwin_getent_group(nfsname, nfsname_buff, &gdummy)) {
  390. +            if (strcmp(nfsname, nfsname_buff)) {
  391.                  DPRINTF(1,
  392.                      ("map_nfs4servername_2_sid: remap group '%s' --> '%s'\n",
  393. -                    name,
  394. -                    name_buff));
  395. -                name = name_buff;
  396. +                    nfsname,
  397. +                    nfsname_buff));
  398. +                nfsname = nfsname_buff;
  399.              }
  400.          }
  401.      }
  402. @@ -389,16 +390,16 @@ int map_nfs4servername_2_sid(nfs41_daemon_globals *nfs41dg, int query, DWORD *si
  403.      *sid_len = SECURITY_MAX_SID_SIZE;
  404.      domain_len = sizeof(domain_buff);
  405.  
  406. -    status = LookupAccountNameA(NULL, name, *sid, sid_len,
  407. +    status = LookupAccountNameA(NULL, nfsname, *sid, sid_len,
  408.          domain_buff, &domain_len, &sid_type);
  409.  
  410.      if (status) {
  411.          /* |LookupAccountNameA()| success */
  412.  
  413. -        DPRINTF(ACLLVL, ("map_nfs4servername_2_sid(query=%x,name='%s'): "
  414. +        DPRINTF(ACLLVL, ("map_nfs4servername_2_sid(query=%x,nfsname='%s'): "
  415.              "LookupAccountNameA() returned status=%d "
  416.              "GetLastError=%d *sid_len=%d domain_buff='%s' domain_len=%d\n",
  417. -            query, name, status, GetLastError(), *sid_len, domain_buff,
  418. +            query, nfsname, status, GetLastError(), *sid_len, domain_buff,
  419.              domain_len));
  420.  
  421.          status = 0;
  422. @@ -407,10 +408,10 @@ int map_nfs4servername_2_sid(nfs41_daemon_globals *nfs41dg, int query, DWORD *si
  423.      }
  424.  
  425.      /* |LookupAccountNameA()| failed... */
  426. -    DPRINTF(ACLLVL, ("map_nfs4servername_2_sid(query=%x,name='%s'): "
  427. +    DPRINTF(ACLLVL, ("map_nfs4servername_2_sid(query=%x,nfsname='%s'): "
  428.          "LookupAccountNameA() returned status=%d "
  429.          "GetLastError=%d\n",
  430. -        query, name, status, GetLastError()));
  431. +        query, nfsname, status, GetLastError()));
  432.  
  433.      status = GetLastError();
  434.      switch(status) {
  435. @@ -419,19 +420,19 @@ int map_nfs4servername_2_sid(nfs41_daemon_globals *nfs41dg, int query, DWORD *si
  436.           * This should never happen, as |SECURITY_MAX_SID_SIZE| is
  437.           * the largest possible SID buffer size for Windows
  438.           */
  439. -        eprintf("map_nfs4servername_2_sid(query=%x,name='%s'): "
  440. +        eprintf("map_nfs4servername_2_sid(query=%x,nfsname='%s'): "
  441.                  "LookupAccountName failed with "
  442. -                "ERROR_INSUFFICIENT_BUFFER\n", query, name);
  443. +                "ERROR_INSUFFICIENT_BUFFER\n", query, nfsname);
  444.  
  445.          status = ERROR_INTERNAL_ERROR;
  446.          goto out;
  447.          break;
  448.      case ERROR_NONE_MAPPED:
  449.  #ifdef NFS41_DRIVER_FEATURE_MAP_UNMAPPED_USER_TO_UNIXUSER_SID
  450. -        DPRINTF(1, ("map_nfs4servername_2_sid(query=%x,name='%s'): "
  451. +        DPRINTF(1, ("map_nfs4servername_2_sid(query=%x,nfsname='%s'): "
  452.              "none mapped, "
  453.              "trying Unix_User+/Unix_Group+ mapping\n",
  454. -            query, name));
  455. +            query, nfsname));
  456.  
  457.          if ((user_uid == -1) && (query & OWNER_SECURITY_INFORMATION)) {
  458.              uid_t map_uid = -1;
  459. @@ -439,14 +440,14 @@ int map_nfs4servername_2_sid(nfs41_daemon_globals *nfs41dg, int query, DWORD *si
  460.  
  461.              if (nfs41_idmap_name_to_ids(
  462.                  nfs41dg->idmapper,
  463. -                name,
  464. +                nfsname,
  465.                  &map_uid,
  466.                  &gid_dummy) == 0) {
  467.                  user_uid = map_uid;
  468.              }
  469.              else {
  470.                  DPRINTF(1, ("map_nfs4servername_2_sid(query=%x,name='%s'): nfs41_idmap_name_to_ids() failed\n",
  471. -                    query, name));
  472. +                    query, nfsname));
  473.                  /* fixme: try harder here, "1234" should to to |atol()| */
  474.              }
  475.          }
  476. @@ -456,63 +457,63 @@ int map_nfs4servername_2_sid(nfs41_daemon_globals *nfs41dg, int query, DWORD *si
  477.  
  478.              if (nfs41_idmap_group_to_gid(
  479.                  nfs41dg->idmapper,
  480. -                name,
  481. +                nfsname,
  482.                  &map_gid) == 0) {
  483.                  group_gid = map_gid;
  484.              }
  485.              else {
  486. -                DPRINTF(1, ("map_nfs4servername_2_sid(query=%x,name='%s'): nfs41_idmap_group_to_gid() failed\n",
  487. -                    query, name));
  488. +                DPRINTF(1, ("map_nfs4servername_2_sid(query=%x,nfsname='%s'): nfs41_idmap_group_to_gid() failed\n",
  489. +                    query, nfsname));
  490.                  /* fixme: try harder here, "1234" should to to |atol()| */
  491.              }
  492.          }
  493.  
  494.          if (user_uid != -1) {
  495.              if (allocate_unixuser_sid(user_uid, sid)) {
  496. -                DPRINTF(ACLLVL, ("map_nfs4servername_2_sid(query=%x,name='%s'): "
  497. +                DPRINTF(ACLLVL, ("map_nfs4servername_2_sid(query=%x,nfsname='%s'): "
  498.                      "allocate_unixuser_sid(uid=%ld) success\n",
  499. -                    query, name, user_uid));
  500. +                    query, nfsname, user_uid));
  501.                  status = ERROR_SUCCESS;
  502.                  sid_type = SidTypeUser;
  503.                  goto out_cache;
  504.              }
  505.  
  506.              status = GetLastError();
  507. -            DPRINTF(ACLLVL, ("map_nfs4servername_2_sid(query=%x,name='%s'): "
  508. +            DPRINTF(ACLLVL, ("map_nfs4servername_2_sid(query=%x,nfsname='%s'): "
  509.                  "allocate_unixuser_sid(uid=%ld) failed, error=%d\n",
  510. -                query, name, user_uid, status));
  511. +                query, nfsname, user_uid, status));
  512.              goto out;
  513.          }
  514.  
  515.          if (group_gid != -1) {
  516.              if (allocate_unixgroup_sid(group_gid, sid)) {
  517. -                DPRINTF(ACLLVL, ("map_nfs4servername_2_sid(query=%x,name='%s'): "
  518. +                DPRINTF(ACLLVL, ("map_nfs4servername_2_sid(query=%x,nfsname='%s'): "
  519.                      "allocate_unixgroup_sid(gid=%ld) success\n",
  520. -                    query, name, group_gid));
  521. +                    query, nfsname, group_gid));
  522.                  status = ERROR_SUCCESS;
  523.                  sid_type = SidTypeGroup;
  524.                  goto out_cache;
  525.              }
  526.  
  527.              status = GetLastError();
  528. -            DPRINTF(ACLLVL, ("map_nfs4servername_2_sid(query=%x,name='%s'): "
  529. +            DPRINTF(ACLLVL, ("map_nfs4servername_2_sid(query=%x,nfsname='%s'): "
  530.                  "allocate_unixgroup_sid(gid=%ld) failed, error=%d\n",
  531. -                query, name, group_gid, status));
  532. +                query, nfsname, group_gid, status));
  533.              goto out;
  534.          }
  535.  #endif /* NFS41_DRIVER_FEATURE_MAP_UNMAPPED_USER_TO_UNIXUSER_SID */
  536.  
  537. -        DPRINTF(1, ("map_nfs4servername_2_sid(query=%x,name='%s'): none mapped, "
  538. +        DPRINTF(1, ("map_nfs4servername_2_sid(query=%x,nfsname='%s'): none mapped, "
  539.              "using WinNullSid mapping\n",
  540. -            query, name));
  541. +            query, nfsname));
  542.  
  543.          status = create_unknownsid(WinNullSid, sid, sid_len);
  544.          if (status)
  545.              goto out_free_sid;
  546.          break;
  547.      default:
  548. -        DPRINTF(1, ("map_nfs4servername_2_sid(query=%x,name='%s'): error %d not handled\n",
  549. -            query, name, GetLastError()));
  550. +        DPRINTF(1, ("map_nfs4servername_2_sid(query=%x,nfsname='%s'): error %d not handled\n",
  551. +            query, nfsname, GetLastError()));
  552.          break;
  553.      }
  554.  out_cache:
  555. @@ -530,23 +531,23 @@ out_cache:
  556.               * References:
  557.               * - https://stackoverflow.com/questions/39373188/lookupaccountnamew-returns-sidtypealias-but-expected-sidtypegroup
  558.               */
  559. -            DPRINTF(1, ("map_nfs4servername_2_sid(query=%x,name='%s'): "
  560. +            DPRINTF(1, ("map_nfs4servername_2_sid(query=%x,nfsname='%s'): "
  561.                  "SID_TYPE='SidTypeAlias' mapped to 'SidTypeGroup'\n",
  562. -                query, orig_name, sid_type));
  563. +                query, orig_nfsname, sid_type));
  564.              sid_type = SidTypeGroup;
  565.          }
  566.  
  567.          switch (sid_type) {
  568.              case SidTypeUser:
  569. -                sidcache_add(&user_sidcache, orig_name, *sid);
  570. +                sidcache_add(&user_sidcache, orig_nfsname, *sid);
  571.                  break;
  572.              case SidTypeGroup:
  573. -                sidcache_add(&group_sidcache, orig_name, *sid);
  574. +                sidcache_add(&group_sidcache, orig_nfsname, *sid);
  575.                  break;
  576.              default:
  577. -                eprintf("map_nfs4servername_2_sid(query=%x,name='%s'): "
  578. +                eprintf("map_nfs4servername_2_sid(query=%x,nfsname='%s'): "
  579.                      "Unknown SID_TYPE=%d\n",
  580. -                    query, orig_name, sid_type);
  581. +                    query, orig_nfsname, sid_type);
  582.                  break;
  583.          }
  584.      }
  585. @@ -555,8 +556,8 @@ out_cache:
  586.  out:
  587.      if (DPRINTF_LEVEL_ENABLED(ACLLVL)) {
  588.          if (status) {
  589. -            dprintf_out("<-- map_nfs4servername_2_sid(query=%x,name='%s'): "
  590. -                "status=%d\n", query, name, status);
  591. +            dprintf_out("<-- map_nfs4servername_2_sid(query=%x,nfsname='%s'): "
  592. +                "status=%d\n", query, nfsname, status);
  593.          }
  594.          else {
  595.              PSTR sidstr = NULL;
  596. @@ -569,9 +570,9 @@ out:
  597.                  sidstr = errsidstrbuf;
  598.              }
  599.  
  600. -            dprintf_out("<-- map_nfs4servername_2_sid(query=%x,name='%s'): "
  601. +            dprintf_out("<-- map_nfs4servername_2_sid(query=%x,nfsname='%s'): "
  602.                  "status=%d sidstr='%s' *sid_len=%d\n",
  603. -                query, name, status, sidstr, *sid_len);
  604. +                query, nfsname, status, sidstr, *sid_len);
  605.  
  606.              if (sidstr && (sidstr != errsidstrbuf))
  607.                  LocalFree(sidstr);
  608. --
  609. 2.43.0
  610.  
  611. From 83061e52d123e4ac8291b136cbb4eb4742b2805b Mon Sep 17 00:00:00 2001
  612. From: Roland Mainz <roland.mainz@nrubsig.org>
  613. Date: Tue, 12 Mar 2024 11:51:24 +0100
  614. Subject: [PATCH 5/6] daemon: Improve |map_nfs4ace_who()| performance
  615.  
  616. Improve |map_nfs4ace_who()| performance, by avoiding calling
  617. |LookupAccountSidA()| twice, and using stack buffers instead
  618. of |malloc()|.
  619.  
  620. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  621. ---
  622. daemon/acl.c | 135 ++++++++++++++++++++++++---------------------------
  623.  1 file changed, 64 insertions(+), 71 deletions(-)
  624.  
  625. diff --git a/daemon/acl.c b/daemon/acl.c
  626. index 65c20e9..af93535 100644
  627. --- a/daemon/acl.c
  628. +++ b/daemon/acl.c
  629. @@ -24,6 +24,7 @@
  630.  #include <stdio.h>
  631.  #include <strsafe.h>
  632.  #include <sddl.h>
  633. +#include <Lmcons.h>
  634.  
  635.  #include "nfs41_ops.h"
  636.  #include "nfs41_build_features.h"
  637. @@ -35,7 +36,6 @@
  638.  #include "nfs41_xdr.h"
  639.  #include "sid.h"
  640.  
  641. -//#define DEBUG_ACLS
  642.  #define ACLLVL 2 /* dprintf level for acl logging */
  643.  
  644.  static int parse_getacl(unsigned char *buffer, uint32_t length,
  645. @@ -492,10 +492,12 @@ static void map_acemask(ACCESS_MASK mask, int file_type, uint32_t *nfs4_mask)
  646.  
  647.  static int map_nfs4ace_who(PSID sid, PSID owner_sid, PSID group_sid, char *who_out, char *domain, SID_NAME_USE *sid_type_out)
  648.  {
  649. -    int status;
  650. -    DWORD size = 0, tmp_size = 0;
  651. +    int status, lasterr;
  652.      SID_NAME_USE sid_type = 0;
  653. -    LPSTR tmp_buf = NULL, who = NULL;
  654. +    /* |(UNLEN+sizeof('\0'))*2| so we have space for user+domain */
  655. +    char who_buf[(UNLEN+1)*2];
  656. +    char domain_buf[UNLEN+1];
  657. +    DWORD who_size = sizeof(who_buf), domain_size = sizeof(domain_buf);
  658.      LPSTR sidstr = NULL;
  659.  
  660.      DPRINTF(ACLLVL, ("--> map_nfs4ace_who(sid=0x%p,owner_sid=0x%p, group_sid=0x%p)\n"));
  661. @@ -534,12 +536,12 @@ static int map_nfs4ace_who(PSID sid, PSID owner_sid, PSID group_sid, char *who_o
  662.      status = is_well_known_sid(sid, who_out);
  663.      if (status) {
  664.          if (!strncmp(who_out, ACE4_NOBODY, strlen(ACE4_NOBODY))) {
  665. -            size = (DWORD)strlen(ACE4_NOBODY);
  666. +            who_size = (DWORD)strlen(ACE4_NOBODY);
  667.              sid_type = SidTypeUser;
  668.              goto add_domain;
  669.          }
  670.  
  671. -        /* fixme: What about |sid_type| */
  672. +        /* fixme: What about |sid_type| ? */
  673.          status = ERROR_SUCCESS;
  674.          goto out;
  675.      }
  676. @@ -551,78 +553,72 @@ static int map_nfs4ace_who(PSID sid, PSID owner_sid, PSID group_sid, char *who_o
  677.          goto out;
  678.      }
  679.  
  680. -    status = LookupAccountSidA(NULL, sid, who, &size, tmp_buf,
  681. -        &tmp_size, &sid_type);
  682. -    DPRINTF(ACLLVL, ("map_nfs4ace_who: "
  683. -        "LookupAccountSid(sidtostr(sid)='%s', namelen=%d, domainlen=%d) "
  684. -        "returned %d, GetLastError=%d\n",
  685. -        sidstr, size, tmp_size, status, GetLastError()));
  686. +    status = LookupAccountSidA(NULL, sid, who_buf, &who_size, domain_buf,
  687. +                                &domain_size, &sid_type);
  688. +    lasterr = GetLastError();
  689.  
  690. -    /*
  691. -     * No SID to local account mapping. Can happen for some system
  692. -     * SIDs, and Unix_User+<uid> or Unix_Group+<gid> SIDs
  693. -     */
  694. -    switch (status) {
  695. -        /* |LookupAccountSidA()| success */
  696. -        case 0:
  697. -            break;
  698. -        /* This happens for Unix_User+<uid> or Unix_Group+<gid> SIDs */
  699. -        case ERROR_NONE_MAPPED:
  700. -        /* Catch other cases */
  701. -        case ERROR_NO_SUCH_USER:
  702. -        case ERROR_NO_SUCH_GROUP:
  703. -            goto out;
  704. -        default:
  705. -            eprintf("map_nfs4ace_who: Internal error, "
  706. -                "LookupAccountSidA() returned unexpected ERROR_%d "
  707. -                "for sidstr='%s'\n",
  708. -                status,
  709. -                sidstr);
  710. -            status = ERROR_INTERNAL_ERROR;
  711. -            goto out;
  712. +    if (status) {
  713. +        DPRINTF(ACLLVL, ("map_nfs4ace_who: "
  714. +            "LookupAccountSid(sidtostr(sid)='%s', who_buf='%s', "
  715. +            "who_size=%d, domain='%s', domain_size=%d) "
  716. +            "returned success, status=%d, GetLastError=%d\n",
  717. +            sidstr, who_buf, who_size,
  718. +            domain_buf, domain_size, status, lasterr));
  719.      }
  720. +    else {
  721. +        DPRINTF(ACLLVL, ("map_nfs4ace_who: "
  722. +            "LookupAccountSid(sidtostr(sid)='%s', who_size=%d, "
  723. +            "domain_size=%d) returned failure, status=%d, "
  724. +            "GetLastError=%d\n",
  725. +            sidstr, who_size, domain_size, status, lasterr));
  726.  
  727. -    status = GetLastError();
  728. -    if (status == ERROR_NONE_MAPPED) {
  729. -        DPRINTF(1, ("LookupAccountSidA() returned success, "
  730. -            "GetLastError() returned ERROR_NONE_MAPPED\n"));
  731. -        goto out;
  732. +        /*
  733. +         * No SID to local account mapping. Can happen for some system
  734. +         * SIDs, and Unix_User+<uid> or Unix_Group+<gid> SIDs
  735. +         */
  736. +        switch (lasterr) {
  737. +            /*
  738. +             * This happens for Unix_User+<uid> or Unix_Group+<gid>
  739. +             * SIDs
  740. +             */
  741. +            case ERROR_NONE_MAPPED:
  742. +                DPRINTF(ACLLVL, ("map_nfs4ace_who: LookupAccountSidA() "
  743. +                    "returned ERROR_NONE_MAPPED for sidstr='%s'\n",
  744. +                    sidstr));
  745. +                goto out;
  746. +            /* Catch other cases */
  747. +            case ERROR_NO_SUCH_USER:
  748. +            case ERROR_NO_SUCH_GROUP:
  749. +                eprintf("map_nfs4ace_who: LookupAccountSidA() "
  750. +                    "returned ERROR_NO_SUCH_@(USER|GROUP) for "
  751. +                    "sidstr='%s'\n",
  752. +                    sidstr);
  753. +                goto out;
  754. +            default:
  755. +                eprintf("map_nfs4ace_who: Internal error, "
  756. +                    "LookupAccountSidA() returned unexpected ERROR_%d "
  757. +                    "for sidstr='%s'\n",
  758. +                    status, sidstr);
  759. +                status = ERROR_INTERNAL_ERROR;
  760. +                goto out;
  761. +        }
  762.      }
  763.  
  764. -    if (status != ERROR_INSUFFICIENT_BUFFER) {
  765. -        DPRINTF(1, ("LookupAccountSidA() returned success, "
  766. -            "GetLastError() returned %d\n", status));
  767. -        status = ERROR_INTERNAL_ERROR;
  768. -        goto out;
  769. -    }
  770. -    who = malloc(size);
  771. -    if (who == NULL) {
  772. -        status = GetLastError();
  773. -        goto out;
  774. -    }
  775. -    tmp_buf = malloc(tmp_size);
  776. -    if (tmp_buf == NULL)
  777. -        goto out_free_who;
  778. -    status = LookupAccountSidA(NULL, sid, who, &size, tmp_buf,
  779. -                                &tmp_size, &sid_type);
  780. -    free(tmp_buf);
  781. -    if (!status) {
  782. -        eprintf("map_nfs4ace_who: LookupAccountSid failed with %d\n",
  783. -                GetLastError());
  784. -        goto out_free_who;
  785. -    }
  786. -    memcpy(who_out, who, size);
  787. +    (void)memcpy(who_out, who_buf, who_size);
  788.  add_domain:
  789. -    memcpy(who_out+size, "@", sizeof(char));
  790. -    memcpy(who_out+size+1, domain, strlen(domain)+1);
  791. -    if (who) free(who);
  792. +    (void)memcpy(who_out+who_size, "@", sizeof(char));
  793. +    (void)memcpy(who_out+who_size+1, domain, strlen(domain)+1);
  794.      status = ERROR_SUCCESS;
  795.  out:
  796.      if (status) {
  797. -        DPRINTF(ACLLVL, ("<-- map_nfs4ace_who() returns %d\n", status));
  798. +        DPRINTF(ACLLVL,
  799. +            ("<-- map_nfs4ace_who() returns %d\n", status));
  800.      }
  801.      else {
  802. -        DPRINTF(ACLLVL, ("<-- map_nfs4ace_who(who_out='%s', sid_type=%d) returns %d\n", who_out, status, sid_type));
  803. +        DPRINTF(ACLLVL,
  804. +            ("<-- map_nfs4ace_who(who_out='%s', sid_type=%d) "
  805. +            "returns %d\n",
  806. +            who_out, sid_type, status));
  807.          if (sid_type_out) {
  808.              *sid_type_out = sid_type;
  809.          }
  810. @@ -630,11 +626,8 @@ out:
  811.      if (sidstr)
  812.          LocalFree(sidstr);
  813.      return status;
  814. -out_free_who:
  815. -    free(who);
  816. -    status = GetLastError();
  817. -    goto out;
  818.  }
  819. +
  820.  static int map_dacl_2_nfs4acl(PACL acl, PSID sid, PSID gsid, nfsacl41 *nfs4_acl,
  821.                                  int file_type, char *domain)
  822.  {
  823. --
  824. 2.43.0
  825.  
  826. From 23bf6de8cee5157adf28aa69620f601e0bf7fa38 Mon Sep 17 00:00:00 2001
  827. From: Roland Mainz <roland.mainz@nrubsig.org>
  828. Date: Tue, 12 Mar 2024 11:56:14 +0100
  829. Subject: [PATCH 6/6] daemon: Demote |DPRINTF()| for owner/owner_group lookup
  830.  if not cached
  831.  
  832. Demote |DPRINTF()| from debug level |0| to |ACLLVL| for
  833. owner/owner_group lookup if the data are not in name cache.
  834.  
  835. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  836. ---
  837. daemon/acl.c | 2 +-
  838.  1 file changed, 1 insertion(+), 1 deletion(-)
  839.  
  840. diff --git a/daemon/acl.c b/daemon/acl.c
  841. index af93535..0da4538 100644
  842. --- a/daemon/acl.c
  843. +++ b/daemon/acl.c
  844. @@ -242,7 +242,7 @@ use_nfs41_getattr:
  845.           */
  846.          if ((info.attrmask.arr[1] &
  847.              (FATTR4_WORD1_OWNER|FATTR4_WORD1_OWNER_GROUP)) != (FATTR4_WORD1_OWNER|FATTR4_WORD1_OWNER_GROUP)) {
  848. -            DPRINTF(0, ("handle_getattr: owner/owner_group not in cache, doing full lookup...\n"));
  849. +            DPRINTF(ACLLVL, ("handle_getattr: owner/owner_group not in cache, doing full lookup...\n"));
  850.              goto use_nfs41_getattr;
  851.          }
  852.      }
  853. --
  854. 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