pastebin - collaborative debugging tool
nrubsig.kpaste.net RSS


msnfs41client: tarball generation prototype+idmapper fix 2023-12-07
Posted by Anonymous on Thu 7th Dec 2023 14:18
raw | new post
view followups (newest first): msnfs41client: diff -w tarball generation prototype+idmapper fix 2023-12-07 by Anonymous

  1. diff --git a/cygwin/Makefile b/cygwin/Makefile
  2. index b7a3b1e..41e2340 100644
  3. --- a/cygwin/Makefile
  4. +++ b/cygwin/Makefile
  5. @@ -57,7 +57,11 @@ installdest: $(VS_BUILD_DIR)/nfsd.exe \
  6.         fi
  7.         mkdir -p $(DESTDIR)
  8.         mkdir -p $(DESTDIR)/cygdrive/c/cygwin64/sbin/
  9. -       mkdir -p $(DESTDIR)/cygdrive/c/cygwin64/usr/bin
  10. +       # /usr/bin is a bind mount to C:/cygwin64/bin, so copy binaries to /cygdrive/c/cygwin64/bin
  11. +       mkdir -p $(DESTDIR)/cygdrive/c/cygwin64/bin
  12. +       # /usr/lib is a bind mount to C:/cygwin64/lib, so copy library data to /cygdrive/c/cygwin64/lib
  13. +       mkdir -p $(DESTDIR)/cygdrive/c/cygwin64/lib
  14. +       mkdir -p $(DESTDIR)/cygdrive/c/cygwin64/lib/msnfs41client
  15.         cp -r $(VS_BUILD_DIR)/nfsd.exe          $(DESTDIR)/cygdrive/c/cygwin64/sbin/nfsd_debug.exe
  16.         cp -r $(VS_BUILD_DIR)/nfsd.pdb          $(DESTDIR)/cygdrive/c/cygwin64/sbin/nfsd_debug.pdb
  17.         cp -r $(VS_BUILD_DIR)/nfs_mount.*       $(DESTDIR)/cygdrive/c/cygwin64/sbin/.
  18. @@ -68,17 +72,18 @@ installdest: $(VS_BUILD_DIR)/nfsd.exe \
  19.         cp -r $(VS_BUILD_DIR)/libtirpc.*        $(DESTDIR)/cygdrive/c/cygwin64/sbin/.
  20.         cp $(PROJECT_BASEDIR_DIR)/nfs41rdr.inf  $(DESTDIR)/cygdrive/c/cygwin64/sbin/.
  21.         cp $(PROJECT_BASEDIR_DIR)/etc_netconfig $(DESTDIR)/cygdrive/c/cygwin64/sbin/.
  22. -       cp $(PROJECT_BASEDIR_DIR)/ms-nfs41-idmap.conf $(DESTDIR)/cygdrive/c/cygwin64/sbin/.
  23. -       cp $(CYGWIN_MAKEFILE_DIR)/devel/msnfs41client.bash $(DESTDIR)/cygdrive/c/cygwin64/sbin/.
  24. +       cp $(PROJECT_BASEDIR_DIR)/ms-nfs41-idmap.conf           $(DESTDIR)/cygdrive/c/cygwin64/sbin/.
  25. +       cp $(CYGWIN_MAKEFILE_DIR)/devel/msnfs41client.bash      $(DESTDIR)/cygdrive/c/cygwin64/sbin/.
  26. +       cp $(PROJECT_BASEDIR_DIR)/cygwin_idmapper.ksh           $(DESTDIR)/cygdrive/c/cygwin64/lib/msnfs41client/.
  27.         cp $(CYGWIN_MAKEFILE_DIR)/utils/mount_sshnfs/mount_sshnfs.ksh $(DESTDIR)/cygdrive/c/cygwin64/sbin/mount_sshnfs
  28.         chmod a+x $(DESTDIR)/cygdrive/c/cygwin64/sbin/mount_sshnfs
  29.         cp $(CYGWIN_MAKEFILE_DIR)/utils/sshnfs/sshnfs.ksh $(DESTDIR)/cygdrive/c/cygwin64/sbin/sshnfs
  30.         chmod a+x $(DESTDIR)/cygdrive/c/cygwin64/sbin/sshnfs
  31.         @ printf "# Package tests\n"
  32. -       cp tests/winfsinfo1/winfsinfo.exe $(DESTDIR)/cygdrive/c/cygwin64/usr/bin/winfsinfo.exe
  33. +       cp tests/winfsinfo1/winfsinfo.exe $(DESTDIR)/cygdrive/c/cygwin64/bin/winfsinfo.exe
  34.         @ printf "# Package ksh93&co (if available) since Cygwin does not ship with it yet\n"
  35. -       [[ -x /usr/bin/ksh93.exe ]] && cp /usr/bin/ksh93.exe $(DESTDIR)/cygdrive/c/cygwin64/usr/bin/ksh93.exe
  36. -       [[ -x /usr/bin/shcomp.exe ]] && cp /usr/bin/shcomp.exe $(DESTDIR)/cygdrive/c/cygwin64/usr/bin/shcomp.exe
  37. +       [[ -x /usr/bin/ksh93.exe ]] && cp /usr/bin/ksh93.exe $(DESTDIR)/cygdrive/c/cygwin64/bin/ksh93.exe
  38. +       [[ -x /usr/bin/shcomp.exe ]] && cp /usr/bin/shcomp.exe $(DESTDIR)/cygdrive/c/cygwin64/bin/shcomp.exe
  39.         @ printf "# Set file flags\n"
  40.         (cd $(DESTDIR)/cygdrive/c/cygwin64/sbin/ ; chmod a+x *.exe *.dll *.sys *.bash)
  41.         @printf "\n#\n# TEST sbin dir is %s\n#\n" "$(DESTDIR)/cygdrive/c/cygwin64/sbin/"
  42. @@ -86,6 +91,14 @@ installdest: $(VS_BUILD_DIR)/nfsd.exe \
  43.         @printf "\n#\n# Now use\n# $$ cd '%s' && bash ./msnfs41client.bash install #\n# to install the kernel driver as Admin\n#\n" \
  44.                 "$(DESTDIR)/cygdrive/c/cygwin64/sbin/"
  45.  
  46. +bintarball: installdest
  47. +       (cd destdir && \
  48. +       tar -cvf - \
  49. +               --owner=SYSTEM \
  50. +               --group=SYSTEM \
  51. +               cygdrive/c/cygwin64 | \
  52. +                       bzip2 -9 >msnfs41client_cygwin_binaries.tar.bz2)
  53. +
  54.  #
  55.  # clean destdir/, but only if nfsd*.exe does not use it right now
  56.  #
  57. @@ -94,6 +107,6 @@ cleandest:
  58.                 printf 'DIR %q is in use by a process\n' "$DESTDIR" 1>&2 ; \
  59.                 exit 1 ; \
  60.         fi
  61. -       rm -r "$(DESTDIR)"
  62. +       rm -rf "$(DESTDIR)"
  63.  
  64.  # EOF.
  65. diff --git a/daemon/getattr.c b/daemon/getattr.c
  66. index 7c5f241..7621dba 100644
  67. --- a/daemon/getattr.c
  68. +++ b/daemon/getattr.c
  69. @@ -59,8 +59,19 @@ int nfs41_cached_getattr(
  70.  static int parse_getattr(unsigned char *buffer, uint32_t length, nfs41_upcall *upcall)
  71.  {
  72.      int status;
  73. +#if 1
  74. +    EASSERT(length > 4);
  75. +    if (length <= 4) {
  76. +        status = ERROR_INVALID_PARAMETER;
  77. +        goto out;
  78. +    }
  79. +    EASSERT(upcall->state_ref != NULL);
  80. +    if (upcall->state_ref == NULL) {
  81. +        status = ERROR_INVALID_PARAMETER;
  82. +        goto out;
  83. +    }
  84. +#endif
  85.      getattr_upcall_args *args = &upcall->args.getattr;
  86. -
  87.      status = safe_read(&buffer, &length, &args->query_class, sizeof(args->query_class));
  88.      if (status) goto out;
  89.      status = safe_read(&buffer, &length, &args->buf_len, sizeof(args->buf_len));
  90. @@ -80,6 +91,21 @@ static int handle_getattr(void *daemon_context, nfs41_upcall *upcall)
  91.      nfs41_open_state *state = upcall->state_ref;
  92.      nfs41_file_info info = { 0 };
  93.  
  94. +#if 1
  95. +    if (((char *)state->session) == ((char *)0xdddddddddddddddd)) {
  96. +        eprintf("handle_getattr: Invalid session pointer 0xdddddddddddddddd\n");
  97. +        status = ERROR_INVALID_PARAMETER;
  98. +        goto out;
  99. +    }
  100. +
  101. +    EASSERT(state->file.fh.superblock != NULL);
  102. +    if (state->file.fh.superblock == NULL) {
  103. +        /* gisburn: fixme: maybe this should be |ERROR_INTERNAL_ERROR| ? */
  104. +        status = ERROR_INVALID_PARAMETER;
  105. +        goto out;
  106. +    }
  107. +#endif
  108. +
  109.      status = nfs41_cached_getattr(state->session, &state->file, &info);
  110.      if (status) {
  111.          eprintf("nfs41_cached_getattr() failed with %d\n", status);
  112. diff --git a/daemon/idmap_cygwin.c b/daemon/idmap_cygwin.c
  113. index 64c1bff..f8bb74e 100644
  114. --- a/daemon/idmap_cygwin.c
  115. +++ b/daemon/idmap_cygwin.c
  116. @@ -40,7 +40,7 @@
  117.  
  118.  #define CYGWIN_IDMAPPER_SCRIPT \
  119.      ("C:\\cygwin64\\bin\\ksh93.exe " \
  120. -    "/home/roland_mainz/work/msnfs41_uidmapping/ms-nfs41-client/cygwin_idmapper.ksh")
  121. +    "/cygdrive/c/cygwin64/lib/msnfs41client/cygwin_idmapper.ksh")
  122.  
  123.  
  124.  #ifdef NFS41_DRIVER_FEATURE_NAMESERVICE_CYGWIN
  125. diff --git a/daemon/nfs41_daemon.c b/daemon/nfs41_daemon.c
  126. index fe0683e..a43d51e 100644
  127. --- a/daemon/nfs41_daemon.c
  128. +++ b/daemon/nfs41_daemon.c
  129. @@ -27,67 +27,67 @@
  130.  #include <devioctl.h>
  131.  #include <lmcons.h> /* UNLEN for GetUserName() */
  132.  #include <iphlpapi.h> /* for GetNetworkParam() */
  133. -#include "nfs41_driver.h" /* for NFS41_USER_DEVICE_NAME_A */
  134. -#include "nfs41_np.h" /* for NFS41NP_SHARED_MEMORY */
  135. -
  136. -#include "nfs41_daemon.h"
  137. -#include "daemon_debug.h"
  138. -#include "upcall.h"
  139. -#include "sid.h"
  140. -#include "util.h"
  141. -
  142. -/* nfs41_dg.num_worker_threads sets the actual number of worker threads */
  143. -#define MAX_NUM_THREADS 1024
  144. -#define DEFAULT_NUM_THREADS 32
  145. -DWORD NFS41D_VERSION = 0;
  146. -
  147. -static const char FILE_NETCONFIG[] = "C:\\etc\\netconfig";
  148. -
  149. -/* Globals */
  150. -nfs41_daemon_globals nfs41_dg = {
  151. -    .default_uid = NFS_USER_NOBODY_UID,
  152. -    .default_gid = NFS_GROUP_NOGROUP_GID,
  153. -    .num_worker_threads = DEFAULT_NUM_THREADS,
  154. -};
  155. -
  156. -
  157. -#ifndef STANDALONE_NFSD //make sure to define it in "sources" not here
  158. -#include "service.h"
  159. +#include "nfs41_driver.h" /* for NFS41_USER_DEVICE_NAME_A */
  160. +#include "nfs41_np.h" /* for NFS41NP_SHARED_MEMORY */
  161. +
  162. +#include "nfs41_daemon.h"
  163. +#include "daemon_debug.h"
  164. +#include "upcall.h"
  165. +#include "sid.h"
  166. +#include "util.h"
  167. +
  168. +/* nfs41_dg.num_worker_threads sets the actual number of worker threads */
  169. +#define MAX_NUM_THREADS 1024
  170. +#define DEFAULT_NUM_THREADS 32
  171. +DWORD NFS41D_VERSION = 0;
  172. +
  173. +static const char FILE_NETCONFIG[] = "C:\\etc\\netconfig";
  174. +
  175. +/* Globals */
  176. +nfs41_daemon_globals nfs41_dg = {
  177. +    .default_uid = NFS_USER_NOBODY_UID,
  178. +    .default_gid = NFS_GROUP_NOGROUP_GID,
  179. +    .num_worker_threads = DEFAULT_NUM_THREADS,
  180. +};
  181. +
  182. +
  183. +#ifndef STANDALONE_NFSD //make sure to define it in "sources" not here
  184. +#include "service.h"
  185.  HANDLE  stop_event = NULL;
  186.  #endif
  187.  typedef struct _nfs41_process_thread {
  188.      HANDLE handle;
  189. -    uint32_t tid;
  190. -} nfs41_process_thread;
  191. -
  192. -static int map_current_user_to_ids(nfs41_idmapper *idmapper, uid_t *uid, gid_t *gid)
  193. -{
  194. -    char username[UNLEN + 1];
  195. -    DWORD len = UNLEN + 1;
  196. +    uint32_t tid;
  197. +} nfs41_process_thread;
  198. +
  199. +static int map_current_user_to_ids(nfs41_idmapper *idmapper, uid_t *uid, gid_t *gid)
  200. +{
  201. +    char username[UNLEN + 1];
  202. +    DWORD len = UNLEN + 1;
  203.      int status = NO_ERROR;
  204. -
  205. -    if (!GetUserNameA(username, &len)) {
  206. -        status = GetLastError();
  207. -        eprintf("map_current_user_to_ids: GetUserName() failed with %d\n", status);
  208. -        goto out;
  209. -    }
  210. -    dprintf(1, "map_current_user_to_ids: mapping user %s\n", username);
  211. -
  212. -    if (nfs41_idmap_name_to_ids(idmapper, username, uid, gid)) {
  213. -        /* instead of failing for auth_sys, fall back to 'nobody' uid/gid */
  214. -        *uid = nfs41_dg.default_uid;
  215. -        *gid = nfs41_dg.default_gid;
  216. -    }
  217. -out:
  218. -    return status;
  219. +
  220. +    if (!GetUserNameA(username, &len)) {
  221. +        status = GetLastError();
  222. +        eprintf("map_current_user_to_ids: GetUserName() failed with %d\n", status);
  223. +        goto out;
  224. +    }
  225. +    dprintf(1, "map_current_user_to_ids: mapping user %s\n", username);
  226. +
  227. +    if (nfs41_idmap_name_to_ids(idmapper, username, uid, gid)) {
  228. +        /* instead of failing for auth_sys, fall back to 'nobody' uid/gid */
  229. +        *uid = nfs41_dg.default_uid;
  230. +        *gid = nfs41_dg.default_gid;
  231. +    }
  232. +out:
  233. +    return status;
  234.  }
  235. -
  236. -static unsigned int WINAPI thread_main(void *args)
  237. -{
  238. -    nfs41_daemon_globals *nfs41dg = (nfs41_daemon_globals *)args;
  239. -    DWORD status = 0;
  240. -    HANDLE pipe;
  241. -    // buffer used to process upcall, assumed to be fixed size.
  242. +
  243. +static unsigned int WINAPI thread_main(void *args)
  244. +{
  245. +    nfs41_daemon_globals *nfs41dg = (nfs41_daemon_globals *)args;
  246. +    DWORD status = 0;
  247. +    HANDLE pipe;
  248. +    // buffer used to process upcall, assumed to be fixed size.
  249.      // if we ever need to handle non-cached IO, need to make it dynamic
  250.      unsigned char outbuf[UPCALL_BUF_SIZE], inbuf[UPCALL_BUF_SIZE];
  251.      DWORD inbuf_len = UPCALL_BUF_SIZE, outbuf_len;
  252. @@ -113,29 +113,29 @@ static unsigned int WINAPI thread_main(void *args)
  253.          status = upcall_parse(outbuf, (uint32_t)outbuf_len, &upcall);
  254.          if (status) {
  255.              upcall.status = status;
  256. -            goto write_downcall;
  257. -        }
  258. -
  259. -        /*
  260. -         * Map current username to uid/gid
  261. -         * Each thread can handle a different user
  262. -         */
  263. -        status = map_current_user_to_ids(nfs41dg->idmapper,
  264. -            &upcall.uid, &upcall.gid);
  265. -        if (status) {
  266. -            upcall.status = status;
  267. -            goto write_downcall;
  268. +            goto write_downcall;
  269. +        }
  270. +
  271. +        /*
  272. +         * Map current username to uid/gid
  273. +         * Each thread can handle a different user
  274. +         */
  275. +        status = map_current_user_to_ids(nfs41dg->idmapper,
  276. +            &upcall.uid, &upcall.gid);
  277. +        if (status) {
  278. +            upcall.status = status;
  279. +            goto write_downcall;
  280.          }
  281.  
  282.          if (upcall.opcode == NFS41_SHUTDOWN) {
  283.              printf("Shutting down..\n");
  284. -            exit(0);
  285. -        }
  286. -
  287. -        status = upcall_handle(&nfs41_dg, &upcall);
  288. -
  289. -write_downcall:
  290. -        dprintf(1, "writing downcall: xid=%lld opcode=%s status=%d "
  291. +            exit(0);
  292. +        }
  293. +
  294. +        status = upcall_handle(&nfs41_dg, &upcall);
  295. +
  296. +write_downcall:
  297. +        dprintf(1, "writing downcall: xid=%lld opcode=%s status=%d "
  298.              "get_last_error=%d\n", upcall.xid, opcode2string(upcall.opcode),
  299.              upcall.status, upcall.last_error);
  300.  
  301. @@ -182,18 +182,18 @@ static bool_t check_for_files()
  302.      fclose(fd);
  303.      return TRUE;
  304.  }
  305. -
  306. -static void PrintUsage()
  307. -{
  308. -    (void)fprintf(stderr, "Usage: nfsd.exe -d <debug_level> "
  309. -        "--noldap "
  310. -        "--uid <non-zero value> "
  311. -        "--gid <non-zero value> "
  312. -        "--numworkerthreads <value-between 16 and %d> "
  313. -        "\n", MAX_NUM_THREADS);
  314. -}
  315. -static bool_t parse_cmdlineargs(int argc, TCHAR *argv[], nfsd_args *out)
  316. -{
  317. +
  318. +static void PrintUsage()
  319. +{
  320. +    (void)fprintf(stderr, "Usage: nfsd.exe -d <debug_level> "
  321. +        "--noldap "
  322. +        "--uid <non-zero value> "
  323. +        "--gid <non-zero value> "
  324. +        "--numworkerthreads <value-between 16 and %d> "
  325. +        "\n", MAX_NUM_THREADS);
  326. +}
  327. +static bool_t parse_cmdlineargs(int argc, TCHAR *argv[], nfsd_args *out)
  328. +{
  329.      int i;
  330.  
  331.      /* set defaults. */
  332. @@ -223,60 +223,60 @@ static bool_t parse_cmdlineargs(int argc, TCHAR *argv[], nfsd_args *out)
  333.                  ++i;
  334.                  if (i >= argc) {
  335.                      fprintf(stderr, "Missing uid value\n");
  336. -                    PrintUsage();
  337. -                    return FALSE;
  338. -                }
  339. -                nfs41_dg.default_uid = _ttoi(argv[i]);
  340. -                if (!nfs41_dg.default_uid) {
  341. -                    fprintf(stderr, "Invalid (or missing) anonymous uid value of %d\n",
  342. -                        nfs41_dg.default_uid);
  343. -                    return FALSE;
  344. -                }
  345. -            }
  346. +                    PrintUsage();
  347. +                    return FALSE;
  348. +                }
  349. +                nfs41_dg.default_uid = _ttoi(argv[i]);
  350. +                if (!nfs41_dg.default_uid) {
  351. +                    fprintf(stderr, "Invalid (or missing) anonymous uid value of %d\n",
  352. +                        nfs41_dg.default_uid);
  353. +                    return FALSE;
  354. +                }
  355. +            }
  356.              else if (_tcscmp(argv[i], TEXT("--gid")) == 0) { /* no LDAP, setting default gid */
  357.                  ++i;
  358.                  if (i >= argc) {
  359.                      fprintf(stderr, "Missing gid value\n");
  360. -                    PrintUsage();
  361. -                    return FALSE;
  362. -                }
  363. -                nfs41_dg.default_gid = _ttoi(argv[i]);
  364. -            }
  365. -            else if (_tcscmp(argv[i], TEXT("--numworkerthreads")) == 0) {
  366. -                ++i;
  367. -                if (i >= argc) {
  368. -                    fprintf(stderr, "Missing value for num_worker_threads\n");
  369. -                    PrintUsage();
  370. -                    return FALSE;
  371. -                }
  372. -                nfs41_dg.num_worker_threads = _ttoi(argv[i]);
  373. -                if (nfs41_dg.num_worker_threads < 16) {
  374. -                    fprintf(stderr, "--numworkerthreads requires at least 16 worker threads\n");
  375. -                    PrintUsage();
  376. -                    return FALSE;
  377. -                }
  378. -                if (nfs41_dg.num_worker_threads >= MAX_NUM_THREADS) {
  379. -                    fprintf(stderr,
  380. -                        "--numworkerthreads supports a maximum of "
  381. -                        "%d worker threads\n",
  382. -                        MAX_NUM_THREADS);
  383. -                    PrintUsage();
  384. -                    return FALSE;
  385. -                }
  386. -            }
  387. -            else
  388. -                fprintf(stderr, "Unrecognized option '%s', disregarding.\n", argv[i]);
  389. -        }
  390. -    }
  391. -
  392. -    (void)fprintf(stdout, "parse_cmdlineargs: debug_level %d ldap is %d "
  393. -#ifdef NFS41_DRIVER_FEATURE_NAMESERVICE_CYGWIN
  394. -        "idmap_cygwin is 1 "
  395. -#endif /* NFS41_DRIVER_FEATURE_NAMESERVICE_CYGWIN */
  396. -        "\n",
  397. -        out->debug_level, out->ldap_enable);
  398. -    return TRUE;
  399. -}
  400. +                    PrintUsage();
  401. +                    return FALSE;
  402. +                }
  403. +                nfs41_dg.default_gid = _ttoi(argv[i]);
  404. +            }
  405. +            else if (_tcscmp(argv[i], TEXT("--numworkerthreads")) == 0) {
  406. +                ++i;
  407. +                if (i >= argc) {
  408. +                    fprintf(stderr, "Missing value for num_worker_threads\n");
  409. +                    PrintUsage();
  410. +                    return FALSE;
  411. +                }
  412. +                nfs41_dg.num_worker_threads = _ttoi(argv[i]);
  413. +                if (nfs41_dg.num_worker_threads < 16) {
  414. +                    fprintf(stderr, "--numworkerthreads requires at least 16 worker threads\n");
  415. +                    PrintUsage();
  416. +                    return FALSE;
  417. +                }
  418. +                if (nfs41_dg.num_worker_threads >= MAX_NUM_THREADS) {
  419. +                    fprintf(stderr,
  420. +                        "--numworkerthreads supports a maximum of "
  421. +                        "%d worker threads\n",
  422. +                        MAX_NUM_THREADS);
  423. +                    PrintUsage();
  424. +                    return FALSE;
  425. +                }
  426. +            }
  427. +            else
  428. +                fprintf(stderr, "Unrecognized option '%s', disregarding.\n", argv[i]);
  429. +        }
  430. +    }
  431. +
  432. +    (void)fprintf(stdout, "parse_cmdlineargs: debug_level %d ldap is %d "
  433. +#ifdef NFS41_DRIVER_FEATURE_NAMESERVICE_CYGWIN
  434. +        "idmap_cygwin is 1 "
  435. +#endif /* NFS41_DRIVER_FEATURE_NAMESERVICE_CYGWIN */
  436. +        "\n",
  437. +        out->debug_level, out->ldap_enable);
  438. +    return TRUE;
  439. +}
  440.  
  441.  static void print_getaddrinfo(struct addrinfo *ptr)
  442.  {
  443. @@ -358,15 +358,15 @@ static int getdomainname()
  444.                      for (i = 0; i < len; i++)
  445.                          if (p[i] == '.')
  446.                              break;
  447. -                    if (i == len)
  448. -                        break;
  449. -                    flag = TRUE;
  450. -                    memcpy(nfs41_dg.localdomain_name, &hostname[i+1], len-i);
  451. -                    dprintf(1, "getdomainname: domainname %s %d\n",
  452. -                            nfs41_dg.localdomain_name, strlen(nfs41_dg.localdomain_name));
  453. -                    goto out_loop;
  454. -                }
  455. -                break;
  456. +                    if (i == len)
  457. +                        break;
  458. +                    flag = TRUE;
  459. +                    memcpy(nfs41_dg.localdomain_name, &hostname[i+1], len-i);
  460. +                    dprintf(1, "getdomainname: domainname %s %d\n",
  461. +                            nfs41_dg.localdomain_name, strlen(nfs41_dg.localdomain_name));
  462. +                    goto out_loop;
  463. +                }
  464. +                break;
  465.              default:
  466.                  break;
  467.              }
  468. @@ -378,15 +378,15 @@ out_loop:
  469.                  "Set this machine's domain name:\n"
  470.                  "System > ComputerName > Change > More > mydomain\n");
  471.          }
  472. -        freeaddrinfo(result);
  473. -    } else {
  474. -        dprintf(1, "domain name is %s\n", net_info->DomainName);
  475. -        memcpy(nfs41_dg.localdomain_name, net_info->DomainName,
  476. -                strlen(net_info->DomainName));
  477. -        nfs41_dg.localdomain_name[strlen(net_info->DomainName)] = '\0';
  478. -    }
  479. -out_free:
  480. -    free(net_info);
  481. +        freeaddrinfo(result);
  482. +    } else {
  483. +        dprintf(1, "domain name is %s\n", net_info->DomainName);
  484. +        memcpy(nfs41_dg.localdomain_name, net_info->DomainName,
  485. +                strlen(net_info->DomainName));
  486. +        nfs41_dg.localdomain_name[strlen(net_info->DomainName)] = '\0';
  487. +    }
  488. +out_free:
  489. +    free(net_info);
  490.  out:
  491.      return status;
  492.  }
  493. @@ -398,24 +398,38 @@ VOID ServiceStart(DWORD argc, LPTSTR *argv)
  494.  #endif
  495.  {
  496.      DWORD status = 0, len;
  497. -    // handle to our drivers
  498. -    HANDLE pipe;
  499. -    nfs41_process_thread tids[MAX_NUM_THREADS];
  500. -    int i;
  501. -    nfsd_args cmd_args;
  502. -
  503. -    if (!check_for_files())
  504. -        exit(1);
  505. -    if (!parse_cmdlineargs(argc, argv, &cmd_args))
  506. -        exit(1);
  507. -    set_debug_level(cmd_args.debug_level);
  508. -    open_log_files();
  509. -    sidcache_init();
  510. -
  511. -#ifdef _DEBUG
  512. -    /* dump memory leaks to stderr on exit; this requires the debug heap,
  513. +    // handle to our drivers
  514. +    HANDLE pipe;
  515. +    nfs41_process_thread tids[MAX_NUM_THREADS];
  516. +    int i;
  517. +    nfsd_args cmd_args;
  518. +
  519. +    if (!check_for_files())
  520. +        exit(1);
  521. +    if (!parse_cmdlineargs(argc, argv, &cmd_args))
  522. +        exit(1);
  523. +    set_debug_level(cmd_args.debug_level);
  524. +    open_log_files();
  525. +    sidcache_init();
  526. +
  527. +#ifdef _DEBUG
  528. +    /* dump memory leaks to stderr on exit; this requires the debug heap,
  529.      /* available only when built in debug mode under visual studio -cbodley */
  530. -    _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
  531. +
  532. +    int crtsetdbgflags = 0;
  533. +    crtsetdbgflags |= _CRTDBG_ALLOC_MEM_DF;  /* use debug heap */
  534. +    crtsetdbgflags |= _CRTDBG_LEAK_CHECK_DF; /* report leaks on exit */
  535. +#if 1
  536. +    /*
  537. +     * _CRTDBG_DELAY_FREE_MEM_DF - Delay freeing of memory, but fill
  538. +     * memory blocks passed to |free()| with 0xdd. We rely on that to
  539. +     * see 0xdddddddddddddddd-pointers for use-after-free and catch
  540. +     * them in stress testing instead of having to deal with a core
  541. +     * dump
  542. +     */
  543. +    crtsetdbgflags |= _CRTDBG_DELAY_FREE_MEM_DF;
  544. +#endif
  545. +    (void)_CrtSetDbgFlag(crtsetdbgflags);
  546.      _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE);
  547.  
  548.      /*
  549. @@ -434,34 +448,34 @@ VOID ServiceStart(DWORD argc, LPTSTR *argv)
  550.       * needed for acls */
  551.      if (getdomainname()) {
  552.          eprintf("Could not get domain name\n");
  553. -        exit(1);
  554. -    }
  555. -
  556. -    /*
  557. -     * Set high priority class to avoid that the daemon gets stomped
  558. -     * by other processes, which might lead to some kind of priority
  559. -     * inversion
  560. -     */
  561. -    if(SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS)) {
  562. -        dprintf(0, "Running as HIGH_PRIORITY_CLASS\n");
  563. -    }
  564. -    else {
  565. -        eprintf("Failed to enter HIGH_PRIORITY_CLASS mode\n");
  566. -    }
  567. -
  568. -#ifdef NFS41_DRIVER_FEATURE_NAMESERVICE_CYGWIN
  569. -    /* force enable for cygwin getent passwd/group testing */
  570. -    cmd_args.ldap_enable = TRUE;
  571. -    DASSERT(0/* test asserts*/, 0);
  572. -#endif /* NFS41_DRIVER_FEATURE_NAMESERVICE_CYGWIN */
  573. -
  574. -    nfs41_server_list_init();
  575. -
  576. -    if (cmd_args.ldap_enable) {
  577. -        status = nfs41_idmap_create(&(nfs41_dg.idmapper));
  578. -        if (status) {
  579. -            eprintf("id mapping initialization failed with %d\n", status);
  580. -            goto out_logs;
  581. +        exit(1);
  582. +    }
  583. +
  584. +    /*
  585. +     * Set high priority class to avoid that the daemon gets stomped
  586. +     * by other processes, which might lead to some kind of priority
  587. +     * inversion
  588. +     */
  589. +    if(SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS)) {
  590. +        dprintf(0, "Running as HIGH_PRIORITY_CLASS\n");
  591. +    }
  592. +    else {
  593. +        eprintf("Failed to enter HIGH_PRIORITY_CLASS mode\n");
  594. +    }
  595. +
  596. +#ifdef NFS41_DRIVER_FEATURE_NAMESERVICE_CYGWIN
  597. +    /* force enable for cygwin getent passwd/group testing */
  598. +    cmd_args.ldap_enable = TRUE;
  599. +    DASSERT(0/* test asserts*/, 0);
  600. +#endif /* NFS41_DRIVER_FEATURE_NAMESERVICE_CYGWIN */
  601. +
  602. +    nfs41_server_list_init();
  603. +
  604. +    if (cmd_args.ldap_enable) {
  605. +        status = nfs41_idmap_create(&(nfs41_dg.idmapper));
  606. +        if (status) {
  607. +            eprintf("id mapping initialization failed with %d\n", status);
  608. +            goto out_logs;
  609.          }
  610.      }
  611.  
  612. @@ -489,17 +503,17 @@ VOID ServiceStart(DWORD argc, LPTSTR *argv)
  613.  #ifndef STANDALONE_NFSD
  614.      stop_event = CreateEvent(NULL, TRUE, FALSE, NULL);
  615.      if (stop_event == NULL)
  616. -      goto out_pipe;
  617. -#endif
  618. -
  619. -    dprintf(1, "Starting %d worker threads...\n",
  620. -        (int)nfs41_dg.num_worker_threads);
  621. -    for (i = 0; i < nfs41_dg.num_worker_threads; i++) {
  622. -        tids[i].handle = (HANDLE)_beginthreadex(NULL, 0, thread_main,
  623. -                &nfs41_dg, 0, &tids[i].tid);
  624. -        if (tids[i].handle == INVALID_HANDLE_VALUE) {
  625. -            status = GetLastError();
  626. -            eprintf("_beginthreadex failed %d\n", status);
  627. +      goto out_pipe;
  628. +#endif
  629. +
  630. +    dprintf(1, "Starting %d worker threads...\n",
  631. +        (int)nfs41_dg.num_worker_threads);
  632. +    for (i = 0; i < nfs41_dg.num_worker_threads; i++) {
  633. +        tids[i].handle = (HANDLE)_beginthreadex(NULL, 0, thread_main,
  634. +                &nfs41_dg, 0, &tids[i].tid);
  635. +        if (tids[i].handle == INVALID_HANDLE_VALUE) {
  636. +            status = GetLastError();
  637. +            eprintf("_beginthreadex failed %d\n", status);
  638.              goto out_pipe;
  639.          }
  640.      }
  641. @@ -508,22 +522,22 @@ VOID ServiceStart(DWORD argc, LPTSTR *argv)
  642.      if (!ReportStatusToSCMgr(SERVICE_RUNNING, NO_ERROR, 0))
  643.          goto out_pipe;
  644.      WaitForSingleObject(stop_event, INFINITE);
  645. -#else
  646. -    //This can be changed to waiting on an array of handles and using waitformultipleobjects
  647. -    dprintf(1, "Parent waiting for children threads\n");
  648. -    for (i = 0; i < nfs41_dg.num_worker_threads; i++)
  649. -        WaitForSingleObject(tids[i].handle, INFINITE );
  650. -#endif
  651. -    dprintf(1, "Parent woke up!!!!\n");
  652. -
  653. -out_pipe:
  654. -    CloseHandle(pipe);
  655. -out_idmap:
  656. -    if (nfs41_dg.idmapper)
  657. -        nfs41_idmap_free(nfs41_dg.idmapper);
  658. -out_logs:
  659. -#ifndef STANDALONE_NFSD
  660. -    close_log_files();
  661. +#else
  662. +    //This can be changed to waiting on an array of handles and using waitformultipleobjects
  663. +    dprintf(1, "Parent waiting for children threads\n");
  664. +    for (i = 0; i < nfs41_dg.num_worker_threads; i++)
  665. +        WaitForSingleObject(tids[i].handle, INFINITE );
  666. +#endif
  667. +    dprintf(1, "Parent woke up!!!!\n");
  668. +
  669. +out_pipe:
  670. +    CloseHandle(pipe);
  671. +out_idmap:
  672. +    if (nfs41_dg.idmapper)
  673. +        nfs41_idmap_free(nfs41_dg.idmapper);
  674. +out_logs:
  675. +#ifndef STANDALONE_NFSD
  676. +    close_log_files();
  677.  #endif
  678.      return;
  679.  }
  680. diff --git a/daemon/nfs41_ops.c b/daemon/nfs41_ops.c
  681. index bcca070..f2a4f22 100644
  682. --- a/daemon/nfs41_ops.c
  683. +++ b/daemon/nfs41_ops.c
  684. @@ -400,6 +400,9 @@ int nfs41_open(
  685.      bool_t already_delegated = delegation->type == OPEN_DELEGATE_READ
  686.          || delegation->type == OPEN_DELEGATE_WRITE;
  687.  
  688. +    EASSERT(parent);
  689. +    EASSERT(parent->fh.superblock);
  690. +
  691.      /* depending on the claim type, OPEN expects CURRENT_FH set
  692.       * to either the parent directory, or to the file itself */
  693.      switch (claim->claim) {
  694. diff --git a/daemon/open.c b/daemon/open.c
  695. index 8c01ac1..1cbac2c 100644
  696. --- a/daemon/open.c
  697. +++ b/daemon/open.c
  698. @@ -99,6 +99,24 @@ static void open_state_free(
  699.  void nfs41_open_state_ref(
  700.      IN nfs41_open_state *state)
  701.  {
  702. +#if 1
  703. +    /*
  704. +     * gisburn: fixme: sometimes this happens under high parallel
  705. +     * usage with multiple mounts - but why ?
  706. +     * 0:038> kp
  707. +     * Child-SP          RetAddr           Call Site
  708. +     * 0000006d`431fde10 00007ff7`32f7d905 nfsd!nfs41_open_state_ref(struct __nfs41_open_state * state = 0x00000000`00000000)+0x31
  709. +     * 0000006d`431fdf30 00007ff7`32f4d284 nfsd!upcall_parse(unsigned char * buffer = 0x0000006d`431fe180 "???", unsigned int length = 8, struct __nfs41_upcall * upcall = 0x0000006d`431ff1e0)+0x2e5
  710. +     * 0000006d`431fe0b0 00007ffc`1ca24c7c nfsd!thread_main(void * args = 0x00007ff7`32fb6080)+0x144
  711. +     * 0000006d`431ffe00 00007ffc`4d4b7344 ucrtbased!thread_start<unsigned int (void * parameter = 0x0000025d`a9c6def0)+0x9c
  712. +     * 0000006d`431ffe60 00007ffc`4efc26b1 KERNEL32!BaseThreadInitThunk+0x14
  713. +     * 0000006d`431ffe90 00000000`00000000 ntdll!RtlUserThreadStart+0x21
  714. +     */
  715. +    EASSERT(state != NULL);
  716. +    if (state == NULL)
  717. +        return;
  718. +#endif
  719. +
  720.      const LONG count = InterlockedIncrement(&state->ref_count);
  721.  
  722.      dprintf(2, "nfs41_open_state_ref(%s) count %d\n", state->path.path, count);
  723. diff --git a/daemon/upcall.c b/daemon/upcall.c
  724. index bd13c61..7778429 100644
  725. --- a/daemon/upcall.c
  726. +++ b/daemon/upcall.c
  727. @@ -121,6 +121,7 @@ int upcall_parse(
  728.      /* parse the operation's arguments */
  729.      op = g_upcall_op_table[upcall->opcode];
  730.      if (op && op->parse) {
  731. +        EASSERT(length > 0);
  732.          status = op->parse(buffer, length, upcall);
  733.          if (status) {
  734.              eprintf("parsing of upcall '%s' failed with %d.\n",
  735. diff --git a/sys/nfs41_build_features.h b/sys/nfs41_build_features.h
  736. index 93ee7a9..d43334a 100644
  737. --- a/sys/nfs41_build_features.h
  738. +++ b/sys/nfs41_build_features.h
  739. @@ -32,19 +32,19 @@
  740.  /*
  741.   * NFS41_DRIVER_FEATURE_LOCAL_UIDGID_IN_NFSV3ATTRIBUTES - return local uid/gid values
  742.   */
  743. -// #define NFS41_DRIVER_FEATURE_LOCAL_UIDGID_IN_NFSV3ATTRIBUTES 1
  744. +#define NFS41_DRIVER_FEATURE_LOCAL_UIDGID_IN_NFSV3ATTRIBUTES 1
  745.  
  746.  /*
  747.   * NFS41_DRIVER_FEATURE_MAP_UNMAPPED_USER_TO_UNIXUSER_SID - give NFS
  748.   * files which do not map to a local account a SID in the
  749.   * Unix_User+x/Unix_Group+x range
  750.   */
  751. -// #define NFS41_DRIVER_FEATURE_MAP_UNMAPPED_USER_TO_UNIXUSER_SID 1
  752. +#define NFS41_DRIVER_FEATURE_MAP_UNMAPPED_USER_TO_UNIXUSER_SID 1
  753.  
  754.  /*
  755.   * NFS41_DRIVER_FEATURE_NAMESERVICE_CYGWIN - use Cygwin /usr/bin/getent
  756.   * as "name service"
  757.   */
  758. -// #define NFS41_DRIVER_FEATURE_NAMESERVICE_CYGWIN 1
  759. +#define NFS41_DRIVER_FEATURE_NAMESERVICE_CYGWIN 1
  760.  
  761.  #endif /* !_NFS41_DRIVER_BUILDFEATURES_ */
  762. diff --git a/tests/winlocktest1/winlocktest1.ksh b/tests/winlocktest1/winlocktest1.ksh
  763. old mode 100644
  764. new mode 100755

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