pastebin - collaborative debugging tool
rovema.kpaste.net RSS


msnfs41client: Patches for DrMemory hits, time-based cache management debugging, cleanup+misc, 2024-05-14
Posted by Anonymous on Tue 14th May 2024 15:31
raw | new post

  1. From 13d33576cb0e85a6f8226aed9a1ef556239d8a70 Mon Sep 17 00:00:00 2001
  2. From: Roland Mainz <roland.mainz@nrubsig.org>
  3. Date: Tue, 14 May 2024 10:20:25 +0200
  4. Subject: [PATCH 1/7] cygwin: Add ucrtbase*.dll to DrMemory uninit blocklist
  5.  
  6. cygwin: Add ucrtbased.dll and ucrtbase.dll to DrMemory uninit
  7. blocklist, as it permamently reports uninit accesses for vprintf&co
  8.  
  9. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  10. ---
  11.  cygwin/devel/msnfs41client.bash | 4 ++--
  12.  1 file changed, 2 insertions(+), 2 deletions(-)
  13.  
  14. diff --git a/cygwin/devel/msnfs41client.bash b/cygwin/devel/msnfs41client.bash
  15. index 744b550..cf4c516 100644
  16. --- a/cygwin/devel/msnfs41client.bash
  17. +++ b/cygwin/devel/msnfs41client.bash
  18. @@ -223,7 +223,7 @@ function nfsclient_rundeamon
  19.                                 '-brief'
  20.                                 '-no_follow_children'
  21.                                 '-lib_blocklist_frames' '1'
  22. -                               '-check_uninit_blocklist' 'MSWSOCK,WS2_32'
  23. +                               '-check_uninit_blocklist' 'MSWSOCK,WS2_32,ucrtbased.dll,ucrtbase.dll'
  24.                                 '-malloc_callstacks'
  25.                                 '-delay_frees' '16384'
  26.                                 '-delay_frees_maxsz' $((64*1024*1024))
  27. @@ -334,7 +334,7 @@ function nfsclient_system_rundeamon
  28.                                 '-brief'
  29.                                 '-no_follow_children'
  30.                                 '-lib_blocklist_frames' '1'
  31. -                               '-check_uninit_blocklist' 'MSWSOCK,WS2_32'
  32. +                               '-check_uninit_blocklist' 'MSWSOCK,WS2_32,ucrtbased.dll,ucrtbase.dll'
  33.                                 '-malloc_callstacks'
  34.                                 '-delay_frees' '16384'
  35.                                 '-delay_frees_maxsz' $((64*1024*1024))
  36. --
  37. 2.43.0
  38.  
  39. From 91fa94f0aca0bed215942cd8892f64baf733f84a Mon Sep 17 00:00:00 2001
  40. From: Roland Mainz <roland.mainz@nrubsig.org>
  41. Date: Tue, 14 May 2024 10:22:35 +0200
  42. Subject: [PATCH 2/7] daemon: Fix DrMemory hit in |handle_mount()|
  43.  
  44. DrMemory Stack trace:
  45. ---- snip ----
  46. Error 1: UNINITIALIZED READ: reading 4 byte(s)
  47. 0 replace_memmove                        [D:\a\drmemory\drmemory\drmemory\replace.c:757]
  48. 1 nfs41_rpc_clnt_create                  [ms-nfs41-client\daemon\nfs41_rpc.c:219]
  49. 2 nfs41_root_mount_addrs                 [ms-nfs41-client\daemon\namespace.c:361]
  50. 3 handle_mount                           [ms-nfs41-client\daemon\mount.c:146]
  51. 4 upcall_handle                          [ms-nfs41-client\daemon\upcall.c:190]
  52. 5 nfsd_worker_thread_main                [ms-nfs41-client\daemon\nfs41_daemon.c:178]
  53. 6 nfsd_thread_main                       [ms-nfs41-client\daemon\nfs41_daemon.c:212]
  54. 7 ucrtbased.dll!register_onexit_function+0x12f    (0x00007fffff442d20 <ucrtbased.dll+0xb2d20>)
  55. 8 KERNEL32.dll!BaseThreadInitThunk
  56. ---- snip ----
  57.  
  58. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  59. ---
  60.  daemon/mount.c | 2 +-
  61.  1 file changed, 1 insertion(+), 1 deletion(-)
  62.  
  63. diff --git a/daemon/mount.c b/daemon/mount.c
  64. index a0fe2f7..ff46a5d 100644
  65. --- a/daemon/mount.c
  66. +++ b/daemon/mount.c
  67. @@ -65,7 +65,7 @@ static int handle_mount(void *daemon_context, nfs41_upcall *upcall)
  68.      char *s;
  69.      int port = 0;
  70.      nfs41_abs_path path;
  71. -    multi_addr4 addrs;
  72. +    multi_addr4 addrs = { 0 };
  73.      nfs41_root *root;
  74.      nfs41_client *client;
  75.      nfs41_path_fh file;
  76. --
  77. 2.43.0
  78.  
  79. From 33cc5df5d6c5ee3ac01478e615d8fa79aad8a87d Mon Sep 17 00:00:00 2001
  80. From: Roland Mainz <roland.mainz@nrubsig.org>
  81. Date: Tue, 14 May 2024 12:13:35 +0200
  82. Subject: [PATCH 3/7] daemon: Keep a valid thread impersonation token in
  83.  |nfs41_upcall|
  84.  
  85. Keep a valid thread impersonation token in |nfs41_upcall|
  86.  
  87. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  88. ---
  89.  daemon/mount.c        | 10 +---------
  90.  daemon/nfs41_daemon.c | 26 ++++++++++++++++++++------
  91.  daemon/upcall.h       | 14 ++++++++++++++
  92.  3 files changed, 35 insertions(+), 15 deletions(-)
  93.  
  94. diff --git a/daemon/mount.c b/daemon/mount.c
  95. index ff46a5d..ea59368 100644
  96. --- a/daemon/mount.c
  97. +++ b/daemon/mount.c
  98. @@ -72,23 +72,15 @@ static int handle_mount(void *daemon_context, nfs41_upcall *upcall)
  99.  
  100.      EASSERT(args->hostport != NULL);
  101.  
  102. -#define MOUNT_REJECT_REQUESTS_WITHOUT_IMPERSONATION_TOKEN 1
  103. -
  104. -#ifdef MOUNT_REJECT_REQUESTS_WITHOUT_IMPERSONATION_TOKEN
  105.      logprintf("mount(hostport='%s', path='%s') request\n",
  106.          args->hostport?args->hostport:"<NULL>",
  107.          args->path?args->path:"<NULL>");
  108.  
  109. -    HANDLE tok;
  110. -    if (OpenThreadToken(GetCurrentThread(), TOKEN_QUERY, FALSE, &tok)) {
  111. -        (void)CloseHandle(tok);
  112. -    }
  113. -    else {
  114. +    if (upcall->currentthread_token == INVALID_HANDLE_VALUE){
  115.          eprintf("handle_mount: Thread has no impersonation token\n");
  116.          status = ERROR_NO_IMPERSONATION_TOKEN;
  117.          goto out;
  118.      }
  119. -#endif /* MOUNT_REJECT_REQUESTS_WITHOUT_IMPERSONATION_TOKEN */
  120.  
  121.      if ((args->path == NULL) || (strlen(args->path) == 0)) {
  122.          DPRINTF(1, ("handle_mount: empty mount root\n"));
  123. diff --git a/daemon/nfs41_daemon.c b/daemon/nfs41_daemon.c
  124. index 207fbdc..56a960e 100644
  125. --- a/daemon/nfs41_daemon.c
  126. +++ b/daemon/nfs41_daemon.c
  127. @@ -67,12 +67,12 @@ typedef struct _nfs41_process_thread {
  128.      uint32_t tid;
  129.  } nfs41_process_thread;
  130.  
  131. -static int map_current_user_to_ids(nfs41_idmapper *idmapper, uid_t *puid, gid_t *pgid)
  132. +static int map_current_user_to_ids(nfs41_idmapper *idmapper,
  133. +    HANDLE impersonation_tok, uid_t *puid, gid_t *pgid)
  134.  {
  135.      char username[UNLEN+1];
  136.      char pgroupname[GNLEN+1];
  137.      int status = NO_ERROR;
  138. -    HANDLE impersonation_tok = GetCurrentThreadEffectiveToken();
  139.  
  140.      if (!get_token_user_name(impersonation_tok, username)) {
  141.          status = GetLastError();
  142. @@ -159,11 +159,21 @@ static unsigned int nfsd_worker_thread_main(void *args)
  143.              goto write_downcall;
  144.          }
  145.  
  146. +        if (!OpenThreadToken(GetCurrentThread(),
  147. +            TOKEN_QUERY/*|TOKEN_IMPERSONATE*/, FALSE,
  148. +            &upcall.currentthread_token)) {
  149. +            upcall.currentthread_token = INVALID_HANDLE_VALUE;
  150. +            DPRINTF(0, ("nfsd_worker_thread_main: "
  151. +                "OpenThreadToken() failed, lasterr=%d.\n",
  152. +                (int)GetLastError()));
  153. +        }
  154. +
  155.          /*
  156. -         * Map current username to uid/gid
  157. +         * Map current { user, primary_group } to { uid, gid }
  158.           * Each thread can handle a different user
  159.           */
  160.          status = map_current_user_to_ids(nfs41dg->idmapper,
  161. +            upcall.currentthread_token,
  162.              &upcall.uid, &upcall.gid);
  163.          if (status) {
  164.              upcall.status = status;
  165. @@ -184,11 +194,15 @@ write_downcall:
  166.  
  167.          upcall_marshall(&upcall, inbuf, (uint32_t)inbuf_len, (uint32_t*)&outbuf_len);
  168.  
  169. -        DPRINTF(2, ("making a downcall: outbuf_len %ld\n\n", outbuf_len));
  170.          /*
  171. -         * Note: Caller impersonation ends here - nfs41_driver.sys
  172. -         * |IOCTL_NFS41_WRITE| calls |SeStopImpersonatingClient()|
  173. +         * Note: Caller impersonation ends with |IOCTL_NFS41_WRITE| -
  174. +         * nfs41_driver.sys |IOCTL_NFS41_WRITE| calls
  175. +         * |SeStopImpersonatingClient()|
  176.           */
  177. +        (void)CloseHandle(upcall.currentthread_token);
  178. +        upcall.currentthread_token = INVALID_HANDLE_VALUE;
  179. +
  180. +        DPRINTF(2, ("making a downcall: outbuf_len %ld\n\n", outbuf_len));
  181.          status = DeviceIoControl(pipe, IOCTL_NFS41_WRITE,
  182.              inbuf, inbuf_len, NULL, 0, (LPDWORD)&outbuf_len, NULL);
  183.          if (!status) {
  184. diff --git a/daemon/upcall.h b/daemon/upcall.h
  185. index 681300d..8df1899 100644
  186. --- a/daemon/upcall.h
  187. +++ b/daemon/upcall.h
  188. @@ -202,6 +202,20 @@ typedef struct __nfs41_upcall {
  189.      uint32_t                last_error;
  190.      upcall_args             args;
  191.  
  192. +    /*
  193. +     * |currentthread_token| - (Impersonation) thread token and
  194. +     * local uid/gid of the user we are impersonating
  195. +     * This should be |INVALID_HANDLE_VALUE| if the thread
  196. +     * has no impersonation token, as we use this for access
  197. +     * checking.
  198. +     */
  199. +    HANDLE                  currentthread_token;
  200. +    /*
  201. +     * Local uid/gid of impersonated user/primary_group
  202. +     * The NFSv4 server might use different uid/gid, and our
  203. +     * idmapper is resposible for the
  204. +     * local_uid/local_gid <--> owner/owner_group translation
  205. +     */
  206.      uid_t                   uid;
  207.      gid_t                   gid;
  208.  
  209. --
  210. 2.43.0
  211.  
  212. From 596f0f0345fd17aae6284cfc9d4247da3cb91b1a Mon Sep 17 00:00:00 2001
  213. From: Roland Mainz <roland.mainz@nrubsig.org>
  214. Date: Tue, 14 May 2024 12:57:37 +0200
  215. Subject: [PATCH 4/7] daemon: Minor debug code cleanup (|const|+macros)
  216.  
  217. Minor debug code cleanup, |const|ify arguments, add macros
  218. and avoid calling into functions which do noting at a given
  219. debug level.
  220.  
  221. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  222. ---
  223.  daemon/acl.c            |  12 ++-
  224.  daemon/daemon_debug.c   | 217 ++++++++++++++++++++--------------------
  225.  daemon/daemon_debug.h   |   6 +-
  226.  daemon/nfs41_compound.c |  10 +-
  227.  daemon/nfs41_ops.c      |   5 +-
  228.  daemon/upcall.c         |   4 +-
  229.  6 files changed, 134 insertions(+), 120 deletions(-)
  230.  
  231. diff --git a/daemon/acl.c b/daemon/acl.c
  232. index 13cc81b..b7250fa 100644
  233. --- a/daemon/acl.c
  234. +++ b/daemon/acl.c
  235. @@ -719,8 +719,10 @@ static int map_dacl_2_nfs4acl(PACL acl, PSID sid, PSID gsid, nfsacl41 *nfs4_acl,
  236.          SID_NAME_USE who_sid_type = 0;
  237.  
  238.          DPRINTF(ACLLVL, ("NON-NULL dacl with %d ACEs\n", acl->AceCount));
  239. -        print_hexbuf_no_asci(ACLLVL, (unsigned char *)"ACL\n",
  240. -                            (unsigned char *)acl, acl->AclSize);
  241. +        if (DPRINTF_LEVEL_ENABLED(ACLLVL)) {
  242. +            print_hexbuf_no_asci("ACL\n",
  243. +                (const unsigned char *)acl, acl->AclSize);
  244. +        }
  245.          nfs4_acl->count = acl->AceCount;
  246.          nfs4_acl->aces = calloc(nfs4_acl->count, sizeof(nfsace4));
  247.          if (nfs4_acl->aces == NULL) {
  248. @@ -736,8 +738,10 @@ static int map_dacl_2_nfs4acl(PACL acl, PSID sid, PSID gsid, nfsacl41 *nfs4_acl,
  249.                  goto out_free;
  250.              }
  251.              tmp_pointer = (PBYTE)ace;
  252. -            print_hexbuf_no_asci(ACLLVL, (unsigned char *)"ACE\n",
  253. -                                    (unsigned char *)ace, ace->AceSize);
  254. +            if (DPRINTF_LEVEL_ENABLED(ACLLVL)) {
  255. +                print_hexbuf_no_asci("ACE\n",
  256. +                    (const unsigned char *)ace, ace->AceSize);
  257. +            }
  258.              DPRINTF(ACLLVL, ("ACE TYPE: %x\n", ace->AceType));
  259.              if (ace->AceType == ACCESS_ALLOWED_ACE_TYPE)
  260.                  nfs4_acl->aces[i].acetype = ACE4_ACCESS_ALLOWED_ACE_TYPE;
  261. diff --git a/daemon/daemon_debug.c b/daemon/daemon_debug.c
  262. index 8788d2b..790a7f7 100644
  263. --- a/daemon/daemon_debug.c
  264. +++ b/daemon/daemon_debug.c
  265. @@ -210,10 +210,9 @@ void eprintf(LPCSTR format, ...)
  266.      va_end(args);
  267.  }
  268.  
  269. -void print_hexbuf(int level, unsigned char *title, unsigned char *buf, int len)
  270. +void print_hexbuf(const char *title, const unsigned char *buf, int len)
  271.  {
  272.      int j, k;
  273. -    if (level > g_debug_level) return;
  274.      fprintf(dlog_file, "%s", title);
  275.      for(j = 0, k = 0; j < len; j++, k++) {
  276.          fprintf(dlog_file, "%02x '%c' ", buf[j], isascii(buf[j])? buf[j]:' ');
  277. @@ -224,10 +223,9 @@ void print_hexbuf(int level, unsigned char *title, unsigned char *buf, int len)
  278.      fprintf(dlog_file, "\n");
  279.  }
  280.  
  281. -void print_hexbuf_no_asci(int level, unsigned char *title, unsigned char *buf, int len)
  282. +void print_hexbuf_no_asci(const char *title, const unsigned char *buf, int len)
  283.  {
  284.      int j, k;
  285. -    if (level > g_debug_level) return;
  286.      fprintf(dlog_file, "%s", title);
  287.      for(j = 0, k = 0; j < len; j++, k++) {
  288.          fprintf(dlog_file, "%02x ", buf[j]);
  289. @@ -340,7 +338,7 @@ void print_share_mode(int level, DWORD mode)
  290.      fprintf(dlog_file, "\n");
  291.  }
  292.  
  293. -void print_file_id_both_dir_info(int level, FILE_ID_BOTH_DIR_INFO *pboth_dir_info)
  294. +void print_file_id_both_dir_info(int level, const FILE_ID_BOTH_DIR_INFO *pboth_dir_info)
  295.  {
  296.      /* printf %zd is for |size_t| */
  297.  
  298. @@ -415,91 +413,93 @@ void print_sid(const char *label, PSID sid)
  299.  const char* opcode2string(DWORD opcode)
  300.  {
  301.      switch(opcode) {
  302. -    case NFS41_SHUTDOWN:    return "NFS41_SHUTDOWN";
  303. -    case NFS41_MOUNT:       return "NFS41_MOUNT";
  304. -    case NFS41_UNMOUNT:     return "NFS41_UNMOUNT";
  305. -    case NFS41_OPEN:        return "NFS41_OPEN";
  306. -    case NFS41_CLOSE:       return "NFS41_CLOSE";
  307. -    case NFS41_READ:        return "NFS41_READ";
  308. -    case NFS41_WRITE:       return "NFS41_WRITE";
  309. -    case NFS41_LOCK:        return "NFS41_LOCK";
  310. -    case NFS41_UNLOCK:      return "NFS41_UNLOCK";
  311. -    case NFS41_DIR_QUERY:   return "NFS41_DIR_QUERY";
  312. -    case NFS41_FILE_QUERY:  return "NFS41_FILE_QUERY";
  313. -    case NFS41_FILE_SET:    return "NFS41_FILE_SET";
  314. -    case NFS41_EA_SET:      return "NFS41_EA_SET";
  315. -    case NFS41_EA_GET:      return "NFS41_EA_GET";
  316. -    case NFS41_SYMLINK:     return "NFS41_SYMLINK";
  317. -    case NFS41_VOLUME_QUERY: return "NFS41_VOLUME_QUERY";
  318. -    case NFS41_ACL_QUERY:   return "NFS41_ACL_QUERY";
  319. -    case NFS41_ACL_SET:     return "NFS41_ACL_SET";
  320. -    default:                return "UNKNOWN";
  321. +#define NFSOPCODE_TO_STRLITERAL(e) case e: return #e;
  322. +        NFSOPCODE_TO_STRLITERAL(NFS41_SHUTDOWN)
  323. +        NFSOPCODE_TO_STRLITERAL(NFS41_MOUNT)
  324. +        NFSOPCODE_TO_STRLITERAL(NFS41_UNMOUNT)
  325. +        NFSOPCODE_TO_STRLITERAL(NFS41_OPEN)
  326. +        NFSOPCODE_TO_STRLITERAL(NFS41_CLOSE)
  327. +        NFSOPCODE_TO_STRLITERAL(NFS41_READ)
  328. +        NFSOPCODE_TO_STRLITERAL(NFS41_WRITE)
  329. +        NFSOPCODE_TO_STRLITERAL(NFS41_LOCK)
  330. +        NFSOPCODE_TO_STRLITERAL(NFS41_UNLOCK)
  331. +        NFSOPCODE_TO_STRLITERAL(NFS41_DIR_QUERY)
  332. +        NFSOPCODE_TO_STRLITERAL(NFS41_FILE_QUERY)
  333. +        NFSOPCODE_TO_STRLITERAL(NFS41_FILE_SET)
  334. +        NFSOPCODE_TO_STRLITERAL(NFS41_EA_SET)
  335. +        NFSOPCODE_TO_STRLITERAL(NFS41_EA_GET)
  336. +        NFSOPCODE_TO_STRLITERAL(NFS41_SYMLINK)
  337. +        NFSOPCODE_TO_STRLITERAL(NFS41_VOLUME_QUERY)
  338. +        NFSOPCODE_TO_STRLITERAL(NFS41_ACL_QUERY)
  339. +        NFSOPCODE_TO_STRLITERAL(NFS41_ACL_SET)
  340.      }
  341. +    return "<unknown NFS41 opcode>";
  342.  }
  343.  
  344.  const char* nfs_opnum_to_string(int opnum)
  345.  {
  346.      switch (opnum)
  347.      {
  348. -    case OP_ACCESS: return "ACCESS";
  349. -    case OP_CLOSE: return "CLOSE";
  350. -    case OP_COMMIT: return "COMMIT";
  351. -    case OP_CREATE: return "CREATE";
  352. -    case OP_DELEGPURGE: return "DELEGPURGE";
  353. -    case OP_DELEGRETURN: return "DELEGRETURN";
  354. -    case OP_GETATTR: return "GETATTR";
  355. -    case OP_GETFH: return "GETFH";
  356. -    case OP_LINK: return "LINK";
  357. -    case OP_LOCK: return "LOCK";
  358. -    case OP_LOCKT: return "LOCKT";
  359. -    case OP_LOCKU: return "LOCKU";
  360. -    case OP_LOOKUP: return "LOOKUP";
  361. -    case OP_LOOKUPP: return "LOOKUPP";
  362. -    case OP_NVERIFY: return "NVERIFY";
  363. -    case OP_OPEN: return "OPEN";
  364. -    case OP_OPENATTR: return "OPENATTR";
  365. -    case OP_OPEN_CONFIRM: return "OPEN_CONFIRM";
  366. -    case OP_OPEN_DOWNGRADE: return "OPEN_DOWNGRADE";
  367. -    case OP_PUTFH: return "PUTFH";
  368. -    case OP_PUTPUBFH: return "PUTPUBFH";
  369. -    case OP_PUTROOTFH: return "PUTROOTFH";
  370. -    case OP_READ: return "READ";
  371. -    case OP_READDIR: return "READDIR";
  372. -    case OP_READLINK: return "READLINK";
  373. -    case OP_REMOVE: return "REMOVE";
  374. -    case OP_RENAME: return "RENAME";
  375. -    case OP_RENEW: return "RENEW";
  376. -    case OP_RESTOREFH: return "RESTOREFH";
  377. -    case OP_SAVEFH: return "SAVEFH";
  378. -    case OP_SECINFO: return "SECINFO";
  379. -    case OP_SETATTR: return "SETATTR";
  380. -    case OP_SETCLIENTID: return "SETCLIENTID";
  381. -    case OP_SETCLIENTID_CONFIRM: return "SETCLIENTID_CONFIRM";
  382. -    case OP_VERIFY: return "VERIFY";
  383. -    case OP_WRITE: return "WRITE";
  384. -    case OP_RELEASE_LOCKOWNER: return "RELEASE_LOCKOWNER";
  385. -    case OP_BACKCHANNEL_CTL: return "BACKCHANNEL_CTL";
  386. -    case OP_BIND_CONN_TO_SESSION: return "BIND_CONN_TO_SESSION";
  387. -    case OP_EXCHANGE_ID: return "EXCHANGE_ID";
  388. -    case OP_CREATE_SESSION: return "CREATE_SESSION";
  389. -    case OP_DESTROY_SESSION: return "DESTROY_SESSION";
  390. -    case OP_FREE_STATEID: return "FREE_STATEID";
  391. -    case OP_GET_DIR_DELEGATION: return "GET_DIR_DELEGATION";
  392. -    case OP_GETDEVICEINFO: return "GETDEVICEINFO";
  393. -    case OP_GETDEVICELIST: return "GETDEVICELIST";
  394. -    case OP_LAYOUTCOMMIT: return "LAYOUTCOMMIT";
  395. -    case OP_LAYOUTGET: return "LAYOUTGET";
  396. -    case OP_LAYOUTRETURN: return "LAYOUTRETURN";
  397. -    case OP_SECINFO_NO_NAME: return "SECINFO_NO_NAME";
  398. -    case OP_SEQUENCE: return "SEQUENCE";
  399. -    case OP_SET_SSV: return "SET_SSV";
  400. -    case OP_TEST_STATEID: return "TEST_STATEID";
  401. -    case OP_WANT_DELEGATION: return "WANT_DELEGATION";
  402. -    case OP_DESTROY_CLIENTID: return "DESTROY_CLIENTID";
  403. -    case OP_RECLAIM_COMPLETE: return "RECLAIM_COMPLETE";
  404. -    case OP_ILLEGAL: return "ILLEGAL";
  405. -    default: return "invalid nfs opnum";
  406. +#define NFSOPNUM_TO_STRLITERAL(e) case e: return #e;
  407. +        NFSOPNUM_TO_STRLITERAL(OP_ACCESS)
  408. +        NFSOPNUM_TO_STRLITERAL(OP_CLOSE)
  409. +        NFSOPNUM_TO_STRLITERAL(OP_COMMIT)
  410. +        NFSOPNUM_TO_STRLITERAL(OP_CREATE)
  411. +        NFSOPNUM_TO_STRLITERAL(OP_DELEGPURGE)
  412. +        NFSOPNUM_TO_STRLITERAL(OP_DELEGRETURN)
  413. +        NFSOPNUM_TO_STRLITERAL(OP_GETATTR)
  414. +        NFSOPNUM_TO_STRLITERAL(OP_GETFH)
  415. +        NFSOPNUM_TO_STRLITERAL(OP_LINK)
  416. +        NFSOPNUM_TO_STRLITERAL(OP_LOCK)
  417. +        NFSOPNUM_TO_STRLITERAL(OP_LOCKT)
  418. +        NFSOPNUM_TO_STRLITERAL(OP_LOCKU)
  419. +        NFSOPNUM_TO_STRLITERAL(OP_LOOKUP)
  420. +        NFSOPNUM_TO_STRLITERAL(OP_LOOKUPP)
  421. +        NFSOPNUM_TO_STRLITERAL(OP_NVERIFY)
  422. +        NFSOPNUM_TO_STRLITERAL(OP_OPEN)
  423. +        NFSOPNUM_TO_STRLITERAL(OP_OPENATTR)
  424. +        NFSOPNUM_TO_STRLITERAL(OP_OPEN_CONFIRM)
  425. +        NFSOPNUM_TO_STRLITERAL(OP_OPEN_DOWNGRADE)
  426. +        NFSOPNUM_TO_STRLITERAL(OP_PUTFH)
  427. +        NFSOPNUM_TO_STRLITERAL(OP_PUTPUBFH)
  428. +        NFSOPNUM_TO_STRLITERAL(OP_PUTROOTFH)
  429. +        NFSOPNUM_TO_STRLITERAL(OP_READ)
  430. +        NFSOPNUM_TO_STRLITERAL(OP_READDIR)
  431. +        NFSOPNUM_TO_STRLITERAL(OP_READLINK)
  432. +        NFSOPNUM_TO_STRLITERAL(OP_REMOVE)
  433. +        NFSOPNUM_TO_STRLITERAL(OP_RENAME)
  434. +        NFSOPNUM_TO_STRLITERAL(OP_RENEW)
  435. +        NFSOPNUM_TO_STRLITERAL(OP_RESTOREFH)
  436. +        NFSOPNUM_TO_STRLITERAL(OP_SAVEFH)
  437. +        NFSOPNUM_TO_STRLITERAL(OP_SECINFO)
  438. +        NFSOPNUM_TO_STRLITERAL(OP_SETATTR)
  439. +        NFSOPNUM_TO_STRLITERAL(OP_SETCLIENTID)
  440. +        NFSOPNUM_TO_STRLITERAL(OP_SETCLIENTID_CONFIRM)
  441. +        NFSOPNUM_TO_STRLITERAL(OP_VERIFY)
  442. +        NFSOPNUM_TO_STRLITERAL(OP_WRITE)
  443. +        NFSOPNUM_TO_STRLITERAL(OP_RELEASE_LOCKOWNER)
  444. +        NFSOPNUM_TO_STRLITERAL(OP_BACKCHANNEL_CTL)
  445. +        NFSOPNUM_TO_STRLITERAL(OP_BIND_CONN_TO_SESSION)
  446. +        NFSOPNUM_TO_STRLITERAL(OP_EXCHANGE_ID)
  447. +        NFSOPNUM_TO_STRLITERAL(OP_CREATE_SESSION)
  448. +        NFSOPNUM_TO_STRLITERAL(OP_DESTROY_SESSION)
  449. +        NFSOPNUM_TO_STRLITERAL(OP_FREE_STATEID)
  450. +        NFSOPNUM_TO_STRLITERAL(OP_GET_DIR_DELEGATION)
  451. +        NFSOPNUM_TO_STRLITERAL(OP_GETDEVICEINFO)
  452. +        NFSOPNUM_TO_STRLITERAL(OP_GETDEVICELIST)
  453. +        NFSOPNUM_TO_STRLITERAL(OP_LAYOUTCOMMIT)
  454. +        NFSOPNUM_TO_STRLITERAL(OP_LAYOUTGET)
  455. +        NFSOPNUM_TO_STRLITERAL(OP_LAYOUTRETURN)
  456. +        NFSOPNUM_TO_STRLITERAL(OP_SECINFO_NO_NAME)
  457. +        NFSOPNUM_TO_STRLITERAL(OP_SEQUENCE)
  458. +        NFSOPNUM_TO_STRLITERAL(OP_SET_SSV)
  459. +        NFSOPNUM_TO_STRLITERAL(OP_TEST_STATEID)
  460. +        NFSOPNUM_TO_STRLITERAL(OP_WANT_DELEGATION)
  461. +        NFSOPNUM_TO_STRLITERAL(OP_DESTROY_CLIENTID)
  462. +        NFSOPNUM_TO_STRLITERAL(OP_RECLAIM_COMPLETE)
  463. +        NFSOPNUM_TO_STRLITERAL(OP_ILLEGAL)
  464.      }
  465. +    return "<invalid nfs opnum>";
  466.  }
  467.  
  468.  const char* nfs_error_string(int status)
  469. @@ -620,39 +620,41 @@ const char* nfs_error_string(int status)
  470.      NFSERR_TO_STRLITERAL(NFS4ERR_OFFLOAD_NO_REQS)
  471.      NFSERR_TO_STRLITERAL(NFS4ERR_NOXATTR)
  472.      NFSERR_TO_STRLITERAL(NFS4ERR_XATTR2BIG)
  473. -    default: return "invalid nfs error code";
  474.      }
  475. +    return "<invalid NFS4ERR_* code>";
  476.  }
  477.  
  478.  const char* rpc_error_string(int status)
  479.  {
  480.      switch (status)
  481.      {
  482. -    case RPC_CANTENCODEARGS: return "RPC_CANTENCODEARGS";
  483. -    case RPC_CANTDECODERES: return "RPC_CANTDECODERES";
  484. -    case RPC_CANTSEND: return "RPC_CANTSEND";
  485. -    case RPC_CANTRECV: return "RPC_CANTRECV";
  486. -    case RPC_TIMEDOUT: return "RPC_TIMEDOUT";
  487. -    case RPC_INTR: return "RPC_INTR";
  488. -    case RPC_UDERROR: return "RPC_UDERROR";
  489. -    case RPC_VERSMISMATCH: return "RPC_VERSMISMATCH";
  490. -    case RPC_AUTHERROR: return "RPC_AUTHERROR";
  491. -    case RPC_PROGUNAVAIL: return "RPC_PROGUNAVAIL";
  492. -    case RPC_PROGVERSMISMATCH: return "RPC_PROGVERSMISMATCH";
  493. -    case RPC_PROCUNAVAIL: return "RPC_PROCUNAVAIL";
  494. -    case RPC_CANTDECODEARGS: return "RPC_CANTDECODEARGS";
  495. -    case RPC_SYSTEMERROR: return "RPC_SYSTEMERROR";
  496. -    default: return "invalid rpc error code";
  497. +#define RPCERR_TO_STRLITERAL(e) case e: return #e;
  498. +        RPCERR_TO_STRLITERAL(RPC_CANTENCODEARGS)
  499. +        RPCERR_TO_STRLITERAL(RPC_CANTDECODERES)
  500. +        RPCERR_TO_STRLITERAL(RPC_CANTSEND)
  501. +        RPCERR_TO_STRLITERAL(RPC_CANTRECV)
  502. +        RPCERR_TO_STRLITERAL(RPC_TIMEDOUT)
  503. +        RPCERR_TO_STRLITERAL(RPC_INTR)
  504. +        RPCERR_TO_STRLITERAL(RPC_UDERROR)
  505. +        RPCERR_TO_STRLITERAL(RPC_VERSMISMATCH)
  506. +        RPCERR_TO_STRLITERAL(RPC_AUTHERROR)
  507. +        RPCERR_TO_STRLITERAL(RPC_PROGUNAVAIL)
  508. +        RPCERR_TO_STRLITERAL(RPC_PROGVERSMISMATCH)
  509. +        RPCERR_TO_STRLITERAL(RPC_PROCUNAVAIL)
  510. +        RPCERR_TO_STRLITERAL(RPC_CANTDECODEARGS)
  511. +        RPCERR_TO_STRLITERAL(RPC_SYSTEMERROR)
  512.      }
  513. +    return "<invalid RPC_* error code>";
  514.  }
  515.  
  516.  const char* gssauth_string(int type) {
  517.      switch(type) {
  518. -    case RPCSEC_SSPI_SVC_NONE: return "RPCSEC_SSPI_SVC_NONE";
  519. -    case RPCSEC_SSPI_SVC_INTEGRITY: return "RPCSEC_SSPI_SVC_INTEGRITY";
  520. -    case RPCSEC_SSPI_SVC_PRIVACY: return "RPCSEC_SSPI_SVC_PRIVACY";
  521. -    default: return "invalid gss auth type";
  522. +#define RPCSEC_TO_STRLITERAL(e) case e: return #e;
  523. +        RPCSEC_TO_STRLITERAL(RPCSEC_SSPI_SVC_NONE)
  524. +        RPCSEC_TO_STRLITERAL(RPCSEC_SSPI_SVC_INTEGRITY)
  525. +        RPCSEC_TO_STRLITERAL(RPCSEC_SSPI_SVC_PRIVACY)
  526.      }
  527. +    return "<invalid RPCSEC_SSPI_* gss auth type>";
  528.  }
  529.  
  530.  void print_condwait_status(int level, int status)
  531. @@ -703,13 +705,14 @@ void print_sr_status_flags(int level, int flags)
  532.  const char* secflavorop2name(DWORD sec_flavor)
  533.  {
  534.      switch(sec_flavor) {
  535. -    case RPCSEC_AUTH_SYS:      return "AUTH_SYS";
  536. -    case RPCSEC_AUTHGSS_KRB5:  return "AUTHGSS_KRB5";
  537. -    case RPCSEC_AUTHGSS_KRB5I: return "AUTHGSS_KRB5I";
  538. -    case RPCSEC_AUTHGSS_KRB5P: return "AUTHGSS_KRB5P";
  539. +#define RPCSEC_AUTH_TO_STRLITERAL(e) case e: return #e;
  540. +        RPCSEC_AUTH_TO_STRLITERAL(RPCSEC_AUTH_SYS)
  541. +        RPCSEC_AUTH_TO_STRLITERAL(RPCSEC_AUTHGSS_KRB5)
  542. +        RPCSEC_AUTH_TO_STRLITERAL(RPCSEC_AUTHGSS_KRB5I)
  543. +        RPCSEC_AUTH_TO_STRLITERAL(RPCSEC_AUTHGSS_KRB5P)
  544.      }
  545.  
  546. -    return "UNKNOWN FLAVOR";
  547. +    return "<Unknown RPCSEC_AUTH* flavour>";
  548.  }
  549.  
  550.  void print_windows_access_mask(int on, ACCESS_MASK m)
  551. diff --git a/daemon/daemon_debug.h b/daemon/daemon_debug.h
  552. index e28c43e..11ec977 100644
  553. --- a/daemon/daemon_debug.h
  554. +++ b/daemon/daemon_debug.h
  555. @@ -96,13 +96,13 @@ void eprintf(LPCSTR format, ...);
  556.  
  557.  void print_windows_access_mask(int on, ACCESS_MASK m);
  558.  void print_nfs_access_mask(int on, int m);
  559. -void print_hexbuf_no_asci(int on, unsigned char *title, unsigned char *buf, int len);
  560. -void print_hexbuf(int level, unsigned char *title, unsigned char *buf, int len);
  561. +void print_hexbuf_no_asci(const char *title, const unsigned char *buf, int len);
  562. +void print_hexbuf(const char *title, const unsigned char *buf, int len);
  563.  void print_create_attributes(int level, DWORD create_opts);
  564.  void print_disposition(int level, DWORD disposition);
  565.  void print_access_mask(int level, DWORD access_mask);
  566.  void print_share_mode(int level, DWORD mode);
  567. -void print_file_id_both_dir_info(int level, FILE_ID_BOTH_DIR_INFO *p);
  568. +void print_file_id_both_dir_info(int level, const FILE_ID_BOTH_DIR_INFO *p);
  569.  void print_sid(const char *label, PSID sid);
  570.  const char* opcode2string(DWORD opcode);
  571.  const char* nfs_opnum_to_string(int opnum);
  572. diff --git a/daemon/nfs41_compound.c b/daemon/nfs41_compound.c
  573. index 5d98d97..b137437 100644
  574. --- a/daemon/nfs41_compound.c
  575. +++ b/daemon/nfs41_compound.c
  576. @@ -169,10 +169,12 @@ retry:
  577.              if (memcmp(seq->sr_resok4.sr_sessionid, args->sa_sessionid,
  578.                      NFS4_SESSIONID_SIZE)) {
  579.                  eprintf("[session] sr_sessionid != sa_sessionid\n");
  580. -                print_hexbuf(1, (unsigned char *)"sr_sessionid",
  581. -                    seq->sr_resok4.sr_sessionid, NFS4_SESSIONID_SIZE);
  582. -                print_hexbuf(1, (unsigned char *)"sa_sessionid",
  583. -                    args->sa_sessionid, NFS4_SESSIONID_SIZE);
  584. +                if (DPRINTF_LEVEL_ENABLED(1)) {
  585. +                    print_hexbuf("sr_sessionid",
  586. +                        seq->sr_resok4.sr_sessionid, NFS4_SESSIONID_SIZE);
  587. +                    print_hexbuf("sa_sessionid",
  588. +                        args->sa_sessionid, NFS4_SESSIONID_SIZE);
  589. +                }
  590.                  status = NFS4ERR_IO;
  591.                  goto out_free_slot;
  592.              }
  593. diff --git a/daemon/nfs41_ops.c b/daemon/nfs41_ops.c
  594. index 74d6e99..4699c16 100644
  595. --- a/daemon/nfs41_ops.c
  596. +++ b/daemon/nfs41_ops.c
  597. @@ -196,7 +196,10 @@ int nfs41_create_session(nfs41_client *clnt, nfs41_session *session, bool_t try_
  598.          session->fore_chan_attrs.ca_maxoperations);
  599.      }
  600.  
  601. -    print_hexbuf(1, (unsigned char *)"session id: ", session->session_id, NFS4_SESSIONID_SIZE);
  602. +    if (DPRINTF_LEVEL_ENABLED(1)) {
  603. +        print_hexbuf("session id: ",
  604. +            session->session_id, NFS4_SESSIONID_SIZE);
  605. +    }
  606.      // check that csa_sequence is same as csr_sequence
  607.      if (reply.csr_sequence != clnt->seq_id) {
  608.          eprintf("ERROR: CREATE_SESSION: csa_sequence %d != "
  609. diff --git a/daemon/upcall.c b/daemon/upcall.c
  610. index 126e740..099159b 100644
  611. --- a/daemon/upcall.c
  612. +++ b/daemon/upcall.c
  613. @@ -89,7 +89,9 @@ int upcall_parse(
  614.      }
  615.  
  616.      DPRINTF(2, ("received %d bytes upcall data: processing upcall\n", length));
  617. -    print_hexbuf(4, (unsigned char *)"upcall buffer: ", buffer, length);
  618. +    if (DPRINTF_LEVEL_ENABLED(4)) {
  619. +        print_hexbuf("upcall buffer: ", buffer, length);
  620. +    }
  621.  
  622.      /* parse common elements */
  623.      status = safe_read(&buffer, &length, &version, sizeof(uint32_t));
  624. --
  625. 2.43.0
  626.  
  627. From c341658a522be84b66ab17b9ab231cfc63b40488 Mon Sep 17 00:00:00 2001
  628. From: Roland Mainz <roland.mainz@nrubsig.org>
  629. Date: Tue, 14 May 2024 13:35:46 +0200
  630. Subject: [PATCH 5/7] daemon,sys: Add NULL opcode to |_nfs41_opcodes|
  631.  
  632. Add NULL opcode to |_nfs41_opcodes|, to avoid calling |NFS41_MOUNT|
  633. in case of zero'ed memory.
  634.  
  635. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  636. ---
  637.  daemon/daemon_debug.c |  3 ++-
  638.  daemon/daemon_debug.h |  3 ++-
  639.  daemon/upcall.c       | 12 +++++++++---
  640.  daemon/upcall.h       |  4 +++-
  641.  sys/nfs41_driver.h    |  4 +++-
  642.  5 files changed, 19 insertions(+), 7 deletions(-)
  643.  
  644. diff --git a/daemon/daemon_debug.c b/daemon/daemon_debug.c
  645. index 790a7f7..b912b9f 100644
  646. --- a/daemon/daemon_debug.c
  647. +++ b/daemon/daemon_debug.c
  648. @@ -410,10 +410,11 @@ void print_sid(const char *label, PSID sid)
  649.      }
  650.  }
  651.  
  652. -const char* opcode2string(DWORD opcode)
  653. +const char* opcode2string(nfs41_opcodes opcode)
  654.  {
  655.      switch(opcode) {
  656.  #define NFSOPCODE_TO_STRLITERAL(e) case e: return #e;
  657. +        NFSOPCODE_TO_STRLITERAL(NFS41_INVALID_OPCODE0)
  658.          NFSOPCODE_TO_STRLITERAL(NFS41_SHUTDOWN)
  659.          NFSOPCODE_TO_STRLITERAL(NFS41_MOUNT)
  660.          NFSOPCODE_TO_STRLITERAL(NFS41_UNMOUNT)
  661. diff --git a/daemon/daemon_debug.h b/daemon/daemon_debug.h
  662. index 11ec977..73dd1b1 100644
  663. --- a/daemon/daemon_debug.h
  664. +++ b/daemon/daemon_debug.h
  665. @@ -104,7 +104,8 @@ void print_access_mask(int level, DWORD access_mask);
  666.  void print_share_mode(int level, DWORD mode);
  667.  void print_file_id_both_dir_info(int level, const FILE_ID_BOTH_DIR_INFO *p);
  668.  void print_sid(const char *label, PSID sid);
  669. -const char* opcode2string(DWORD opcode);
  670. +typedef enum _nfs41_opcodes nfs41_opcodes;
  671. +const char* opcode2string(nfs41_opcodes opcode);
  672.  const char* nfs_opnum_to_string(int opnum);
  673.  const char* nfs_error_string(int status);
  674.  const char* rpc_error_string(int status);
  675. diff --git a/daemon/upcall.c b/daemon/upcall.c
  676. index 099159b..9245cf7 100644
  677. --- a/daemon/upcall.c
  678. +++ b/daemon/upcall.c
  679. @@ -48,7 +48,9 @@ extern const nfs41_upcall_op nfs41_op_volume;
  680.  extern const nfs41_upcall_op nfs41_op_getacl;
  681.  extern const nfs41_upcall_op nfs41_op_setacl;
  682.  
  683. +/* |_nfs41_opcodes| and |g_upcall_op_table| must be in sync! */
  684.  static const nfs41_upcall_op *g_upcall_op_table[] = {
  685. +    NULL,
  686.      &nfs41_op_mount,
  687.      &nfs41_op_unmount,
  688.      &nfs41_op_open,
  689. @@ -98,8 +100,11 @@ int upcall_parse(
  690.      if (status) goto out;
  691.      status = safe_read(&buffer, &length, &upcall->xid, sizeof(uint64_t));
  692.      if (status) goto out;
  693. -    status = safe_read(&buffer, &length, &upcall->opcode, sizeof(uint32_t));
  694. +    /* |sizeof(enum)| might not be the same as |sizeof(uint32_t)| */
  695. +    uint32_t upcall_upcode = 0;
  696. +    status = safe_read(&buffer, &length, &upcall_upcode, sizeof(uint32_t));
  697.      if (status) goto out;
  698. +    upcall->opcode = upcall_upcode;
  699.      status = safe_read(&buffer, &length, &upcall->root_ref, sizeof(HANDLE));
  700.      if (status) goto out;
  701.      status = safe_read(&buffer, &length, &upcall->state_ref, sizeof(HANDLE));
  702. @@ -113,9 +118,10 @@ int upcall_parse(
  703.          upcall->status = status = NFSD_VERSION_MISMATCH;
  704.          goto out;
  705.      }
  706. -    if (upcall->opcode >= g_upcall_op_table_size) {
  707. +    if (upcall_upcode >= g_upcall_op_table_size) {
  708.          status = ERROR_NOT_SUPPORTED;
  709. -        eprintf("unrecognized upcall opcode %d!\n", upcall->opcode);
  710. +        eprintf("upcall_parse: unrecognized upcall opcode %d!\n",
  711. +            upcall->opcode);
  712.          goto out;
  713.      }
  714.  
  715. diff --git a/daemon/upcall.h b/daemon/upcall.h
  716. index 8df1899..ab93317 100644
  717. --- a/daemon/upcall.h
  718. +++ b/daemon/upcall.h
  719. @@ -195,9 +195,11 @@ typedef union __upcall_args {
  720.      setacl_upcall_args      setacl;
  721.  } upcall_args;
  722.  
  723. +typedef enum _nfs41_opcodes nfs41_opcodes;
  724. +
  725.  typedef struct __nfs41_upcall {
  726.      uint64_t                xid;
  727. -    uint32_t                opcode;
  728. +    nfs41_opcodes           opcode;
  729.      uint32_t                status;
  730.      uint32_t                last_error;
  731.      upcall_args             args;
  732. diff --git a/sys/nfs41_driver.h b/sys/nfs41_driver.h
  733. index 39cee5a..68c9cad 100644
  734. --- a/sys/nfs41_driver.h
  735. +++ b/sys/nfs41_driver.h
  736. @@ -60,7 +60,9 @@
  737.   */
  738.  #define NFS41_SYS_MAX_PATH_LEN          4096
  739.  
  740. +/* |_nfs41_opcodes| and |g_upcall_op_table| must be in sync! */
  741.  typedef enum _nfs41_opcodes {
  742. +    NFS41_INVALID_OPCODE0,
  743.      NFS41_MOUNT,
  744.      NFS41_UNMOUNT,
  745.      NFS41_OPEN,
  746. @@ -79,7 +81,7 @@ typedef enum _nfs41_opcodes {
  747.      NFS41_ACL_QUERY,
  748.      NFS41_ACL_SET,
  749.      NFS41_SHUTDOWN,
  750. -    INVALID_OPCODE
  751. +    NFS41_INVALID_OPCODE1
  752.  } nfs41_opcodes;
  753.  
  754.  enum rpcsec_flavors {
  755. --
  756. 2.43.0
  757.  
  758. From 492c492e7bf6e8af35bdddb2ad3814566140b8ab Mon Sep 17 00:00:00 2001
  759. From: Roland Mainz <roland.mainz@nrubsig.org>
  760. Date: Tue, 14 May 2024 15:03:27 +0200
  761. Subject: [PATCH 6/7] daemon, sys: Add |NFS41_FILE_QUERY_TIME_BASED_COHERENCY|
  762.  for debugging
  763.  
  764. Add |NFS41_FILE_QUERY_TIME_BASED_COHERENCY| for debugging of
  765. time based coherency cache management.
  766.  
  767. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  768. ---
  769.  daemon/daemon_debug.c |  1 +
  770.  daemon/getattr.c      | 28 +++++++++++++++++++++++-----
  771.  daemon/upcall.c       |  3 ++-
  772.  sys/nfs41_driver.c    |  5 ++++-
  773.  sys/nfs41_driver.h    |  1 +
  774.  5 files changed, 31 insertions(+), 7 deletions(-)
  775.  
  776. diff --git a/daemon/daemon_debug.c b/daemon/daemon_debug.c
  777. index b912b9f..f7e144e 100644
  778. --- a/daemon/daemon_debug.c
  779. +++ b/daemon/daemon_debug.c
  780. @@ -426,6 +426,7 @@ const char* opcode2string(nfs41_opcodes opcode)
  781.          NFSOPCODE_TO_STRLITERAL(NFS41_UNLOCK)
  782.          NFSOPCODE_TO_STRLITERAL(NFS41_DIR_QUERY)
  783.          NFSOPCODE_TO_STRLITERAL(NFS41_FILE_QUERY)
  784. +        NFSOPCODE_TO_STRLITERAL(NFS41_FILE_QUERY_TIME_BASED_COHERENCY)
  785.          NFSOPCODE_TO_STRLITERAL(NFS41_FILE_SET)
  786.          NFSOPCODE_TO_STRLITERAL(NFS41_EA_SET)
  787.          NFSOPCODE_TO_STRLITERAL(NFS41_EA_GET)
  788. diff --git a/daemon/getattr.c b/daemon/getattr.c
  789. index 675ac54..9320527 100644
  790. --- a/daemon/getattr.c
  791. +++ b/daemon/getattr.c
  792. @@ -27,6 +27,7 @@
  793.  #include "nfs41_build_features.h"
  794.  #include "nfs41_ops.h"
  795.  #include "name_cache.h"
  796. +#include "nfs41_driver.h" /* only for |NFS41_FILE_QUERY*| */
  797.  #include "upcall.h"
  798.  #include "daemon_debug.h"
  799.  
  800. @@ -57,7 +58,7 @@ int nfs41_cached_getattr(
  801.      return status;
  802.  }
  803.  
  804. -/* NFS41_FILE_QUERY */
  805. +/* NFS41_FILE_QUERY, NFS41_FILE_QUERY_TIME_BASED_COHERENCY */
  806.  static int parse_getattr(unsigned char *buffer, uint32_t length, nfs41_upcall *upcall)
  807.  {
  808.      int status;
  809. @@ -65,32 +66,47 @@ static int parse_getattr(unsigned char *buffer, uint32_t length, nfs41_upcall *u
  810.  #ifdef NFS41_DRIVER_WORKAROUND_FOR_GETATTR_AFTER_CLOSE_HACKS
  811.      EASSERT(length > 4);
  812.      if (length <= 4) {
  813. +        eprintf("parse_getattr: "
  814. +            "upcall->opcode='%s' upcall->state_ref(=0x%p) "
  815. +            "length(=%d) < 4\n",
  816. +            opcode2string(upcall->opcode), upcall->state_ref,
  817. +            (int)length);
  818.          status = ERROR_INVALID_PARAMETER;
  819.          goto out;
  820.      }
  821.  
  822.      if (debug_ptr_was_recently_deleted(upcall->state_ref)) {
  823. -        eprintf("parse_getattr: upcall->state_ref(=0x%p) was "
  824. -            "recently deleted\n", upcall->state_ref);
  825. +        eprintf("parse_getattr: "
  826. +            "upcall->opcode='%s' upcall->state_ref(=0x%p) was "
  827. +            "recently deleted\n",
  828. +            opcode2string(upcall->opcode), upcall->state_ref);
  829.          status = ERROR_INVALID_PARAMETER;
  830.          goto out;
  831.      }
  832.  
  833.      EASSERT_IS_VALID_NON_NULL_PTR(upcall->state_ref);
  834.      if (!DEBUG_IS_VALID_NON_NULL_PTR(upcall->state_ref)) {
  835. +        eprintf("parse_getattr: "
  836. +            "upcall->opcode='%s' upcall->state_ref(=0x%p) not valid\n",
  837. +            opcode2string(upcall->opcode), upcall->state_ref);
  838.          status = ERROR_INVALID_PARAMETER;
  839.          goto out;
  840.      }
  841.  
  842.      if (!isvalidnfs41_open_state_ptr(upcall->state_ref)) {
  843. -        eprintf("parse_getattr: Error accessing "
  844. +        eprintf("parse_getattr: upcall->opcode='%s': Error accessing "
  845.              "upcall->state_ref(=0x%p)->session->client\n",
  846. +            opcode2string(upcall->opcode),
  847.              upcall->state_ref);
  848.          status = ERROR_INVALID_PARAMETER;
  849.          goto out;
  850.      }
  851.      EASSERT(upcall->state_ref->ref_count > 0);
  852.      if (upcall->state_ref->ref_count == 0) {
  853. +        eprintf("parse_getattr: upcall->opcode='%s': "
  854. +            "upcall->state_ref(=0x%p) ref_count==0\n",
  855. +            opcode2string(upcall->opcode),
  856. +            upcall->state_ref);
  857.          status = ERROR_INVALID_PARAMETER;
  858.          goto out;
  859.      }
  860. @@ -102,7 +118,9 @@ static int parse_getattr(unsigned char *buffer, uint32_t length, nfs41_upcall *u
  861.      status = safe_read(&buffer, &length, &args->buf_len, sizeof(args->buf_len));
  862.      if (status) goto out;
  863.  
  864. -    DPRINTF(1, ("parsing NFS41_FILE_QUERY: info_class=%d buf_len=%d file='%.*s'\n",
  865. +    DPRINTF(1, ("parsing '%s': "
  866. +        "info_class=%d buf_len=%d file='%.*s'\n",
  867. +        opcode2string(upcall->opcode),
  868.          args->query_class, args->buf_len, upcall->state_ref->path.len,
  869.          upcall->state_ref->path.path));
  870.  out:
  871. diff --git a/daemon/upcall.c b/daemon/upcall.c
  872. index 9245cf7..54cef78 100644
  873. --- a/daemon/upcall.c
  874. +++ b/daemon/upcall.c
  875. @@ -60,7 +60,8 @@ static const nfs41_upcall_op *g_upcall_op_table[] = {
  876.      &nfs41_op_lock,
  877.      &nfs41_op_unlock,
  878.      &nfs41_op_readdir,
  879. -    &nfs41_op_getattr,
  880. +    &nfs41_op_getattr, /* NFS41_FILE_QUERY */
  881. +    &nfs41_op_getattr, /* NFS41_FILE_QUERY_TIME_BASED_COHERENCY */
  882.      &nfs41_op_setattr,
  883.      &nfs41_op_getexattr,
  884.      &nfs41_op_setexattr,
  885. diff --git a/sys/nfs41_driver.c b/sys/nfs41_driver.c
  886. index e7714c5..5341263 100644
  887. --- a/sys/nfs41_driver.c
  888. +++ b/sys/nfs41_driver.c
  889. @@ -1464,6 +1464,7 @@ NTSTATUS handle_upcall(
  890.          status = marshal_nfs41_dirquery(entry, pbOut, cbOut, len);
  891.          break;
  892.      case NFS41_FILE_QUERY:
  893. +    case NFS41_FILE_QUERY_TIME_BASED_COHERENCY:
  894.          status = marshal_nfs41_filequery(entry, pbOut, cbOut, len);
  895.          break;
  896.      case NFS41_FILE_SET:
  897. @@ -2064,6 +2065,7 @@ NTSTATUS nfs41_downcall(
  898.              status = unmarshal_nfs41_dirquery(cur, &buf);
  899.              break;
  900.          case NFS41_FILE_QUERY:
  901. +        case NFS41_FILE_QUERY_TIME_BASED_COHERENCY:
  902.              unmarshal_nfs41_getattr(cur, &buf);
  903.              break;
  904.          case NFS41_EA_GET:
  905. @@ -7154,7 +7156,8 @@ VOID fcbopen_main(PVOID ctx)
  906.              pNetRootContext =
  907.                  NFS41GetNetRootExtension(cur->fcb->pNetRoot);
  908.              /* place an upcall for this srv_open */
  909. -            status = nfs41_UpcallCreate(NFS41_FILE_QUERY,
  910. +            status = nfs41_UpcallCreate(
  911. +                NFS41_FILE_QUERY_TIME_BASED_COHERENCY,
  912.                  &cur->nfs41_fobx->sec_ctx, cur->session,
  913.                  cur->nfs41_fobx->nfs41_open_state,
  914.                  pNetRootContext->nfs41d_version, NULL, &entry);
  915. diff --git a/sys/nfs41_driver.h b/sys/nfs41_driver.h
  916. index 68c9cad..147aa19 100644
  917. --- a/sys/nfs41_driver.h
  918. +++ b/sys/nfs41_driver.h
  919. @@ -73,6 +73,7 @@ typedef enum _nfs41_opcodes {
  920.      NFS41_UNLOCK,
  921.      NFS41_DIR_QUERY,
  922.      NFS41_FILE_QUERY,
  923. +    NFS41_FILE_QUERY_TIME_BASED_COHERENCY,
  924.      NFS41_FILE_SET,
  925.      NFS41_EA_GET,
  926.      NFS41_EA_SET,
  927. --
  928. 2.43.0
  929.  
  930. From be9712a5c96ba3c648c2bcf1b02b13b6b771b1f6 Mon Sep 17 00:00:00 2001
  931. From: Roland Mainz <roland.mainz@nrubsig.org>
  932. Date: Tue, 14 May 2024 16:08:35 +0200
  933. Subject: [PATCH 7/7] daemon: Add SID functions
  934.  |unixuser_sid2uid()|+|unixgroup_sid2gid()|
  935.  
  936. Add SID utility functions |unixuser_sid2uid()| and
  937. |unixgroup_sid2gid()| to get an |uid_t|/|gid_t| from an
  938. UnixUser+X/UnixGroup+X SID.
  939.  
  940. Signed-off-by: Cedric Blancher <cedric.blancher@gmail.com>
  941. ---
  942.  daemon/sid.c | 43 +++++++++++++++++++++++++++++++++++++++++++
  943.  1 file changed, 43 insertions(+)
  944.  
  945. diff --git a/daemon/sid.c b/daemon/sid.c
  946. index 20db96b..94128d9 100644
  947. --- a/daemon/sid.c
  948. +++ b/daemon/sid.c
  949. @@ -22,6 +22,7 @@
  950.  
  951.  #include <Windows.h>
  952.  #include <stdio.h>
  953. +#include <stdbool.h>
  954.  #include <time.h>
  955.  #include <strsafe.h>
  956.  #include <sddl.h>
  957. @@ -173,6 +174,48 @@ BOOL allocate_unixgroup_sid(unsigned long gid, PSID *pSid)
  958.          gid, GetLastError()));
  959.      return FALSE;
  960.  }
  961. +
  962. +bool unixuser_sid2uid(PSID psid, uid_t *puid)
  963. +{
  964. +    if (!psid)
  965. +        return false;
  966. +
  967. +    PSID_IDENTIFIER_AUTHORITY psia = GetSidIdentifierAuthority(psid);
  968. +    if ((*GetSidSubAuthorityCount(psid) == 2) &&
  969. +        (psia->Value[0] == 0) &&
  970. +        (psia->Value[1] == 0) &&
  971. +        (psia->Value[2] == 0) &&
  972. +        (psia->Value[3] == 0) &&
  973. +        (psia->Value[4] == 0) &&
  974. +        (psia->Value[5] == 22) &&
  975. +        (*GetSidSubAuthority(psid, 0) == 1)) {
  976. +        *puid = *GetSidSubAuthority(psid, 1);
  977. +        return true;
  978. +    }
  979. +
  980. +    return false;
  981. +}
  982. +
  983. +bool unixgroup_sid2gid(PSID psid, gid_t *pgid)
  984. +{
  985. +    if (!psid)
  986. +        return false;
  987. +
  988. +    PSID_IDENTIFIER_AUTHORITY psia = GetSidIdentifierAuthority(psid);
  989. +    if ((*GetSidSubAuthorityCount(psid) == 2) &&
  990. +        (psia->Value[0] == 0) &&
  991. +        (psia->Value[1] == 0) &&
  992. +        (psia->Value[2] == 0) &&
  993. +        (psia->Value[3] == 0) &&
  994. +        (psia->Value[4] == 0) &&
  995. +        (psia->Value[5] == 22) &&
  996. +        (*GetSidSubAuthority(psid, 0) == 2)) {
  997. +        *pgid = *GetSidSubAuthority(psid, 1);
  998. +        return true;
  999. +    }
  1000. +
  1001. +    return false;
  1002. +}
  1003.  #endif /* NFS41_DRIVER_FEATURE_MAP_UNMAPPED_USER_TO_UNIXUSER_SID */
  1004.  
  1005.  
  1006. --
  1007. 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