pastebin - collaborative debugging tool
rovema.kpaste.net RSS


msnfs41client.bash - simple Cygwin frontent for the msnfsv41 NFSv4.1 filesystem driver
Posted by Anonymous on Thu 5th Oct 2023 14:05
raw | new post
modification of post by Anonymous (view diff)

  1. #!/bin/bash
  2.  
  3. #
  4. # msnfs41client.bash - simple Cygwin frontent for the msnfsv41
  5. # NFSv4.1 filesystem driver
  6. #
  7.  
  8. #
  9. # Written by Roland Mainz <roland.mainz@nrubsig.org>
  10. #
  11.  
  12. #
  13. # Examples:
  14. #
  15. # 1. Mount for current users:
  16. # (requires PsExec from https://download.sysinternals.com/files/PSTools.zip
  17. # in /home/roland_mainz/work/win_pstools/)
  18. # * Usage:
  19. # Shell1: cd /cygdrive/c/Users/roland_mainz/Downloads/ms-nfs41-client-x64/ms-nfs41-client-x64 && bash ../msnfs41client.bash run_deamon
  20. # Shell2: cd /cygdrive/c/Users/roland_mainz/Downloads/ms-nfs41-client-x64/ms-nfs41-client-x64 && bash ../msnfs41client.bash mount_homedir
  21. #
  22. # 2. Mount for all users:
  23. # * Requires:
  24. # - Windows admin rights (Cygwin --> Run terminal as Adminstrator)
  25. # - PsExec from https://download.sysinternals.com/files/PSTools.zip in /home/roland_mainz/work/win_pstools/)
  26. # * Usage:
  27. # Shell1: cd /cygdrive/c/Users/roland_mainz/Downloads/ms-nfs41-client-x64/ms-nfs41-client-x64 && bash ../msnfs41client.bash sys_run_deamon
  28. # Shell2: cd /cygdrive/c/Users/roland_mainz/Downloads/ms-nfs41-client-x64/ms-nfs41-client-x64 && bash ../msnfs41client.bash sys_mount_homedir
  29. #
  30.  
  31. function is_windows_admin_account
  32. {
  33.         #
  34.         # Test whether we have the Windows permissions to install DLLs
  35.         # and the kernel module
  36.         #
  37.         # Usually Windows Adminstrator rights are indicated by the
  38.         # membership in group "544(Administratoren)" (Cygwin maps
  39.         # "SID S-1-5-32-544" to GID 544)
  40.         #
  41.         if [[ "$(id -G)" =~ (^|[[:space:]]+)544([[:space:]]+|$) ]] ; then
  42.                 return 0
  43.         fi
  44.         return 1
  45. }
  46.  
  47. function nfsclient_install
  48. {
  49.         set -o nounset
  50.         set -o xtrace
  51.         set -o errexit
  52.  
  53.         if ! is_windows_admin_account ; then
  54.                 printf $"%s: Install requires Windows Adminstator permissions.\n" "$0"
  55.                 return 1
  56.         fi
  57.  
  58.         # make sure all binaries are executable, Windows cmd does
  59.         # not care, but Cygwin&bash do.
  60.         # If *.ddl are not executable nfs*.exe fail with 0xc0000022
  61.         chmod a+x *.exe *.dll
  62.  
  63.         if false ; then
  64.                 # install.bat needs PATH to include $PWD
  65.                 PATH="$PWD:$PATH" cmd /c install.bat
  66.         else
  67.                 nfs_install
  68.                 rundll32 setupapi.dll,InstallHinfSection DefaultInstall 132 ./nfs41rdr.inf
  69.         fi
  70.  
  71.         mkdir -p /cygdrive/c/etc
  72.         cp etc_netconfig /cygdrive/c/etc/netconfig
  73.         cp ms-nfs41-idmap.conf /cygdrive/c/etc/.
  74.  
  75.         bcdedit /set testsigning on
  76.         regtool -s set '/HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services/Tcpip/Parameters/Domain' 'GLOBAL.LOC'
  77.  
  78.         sc query Dfsc
  79.         sc stop Dfsc || true
  80.         sc config Dfsc start=disabled
  81.  
  82.         sc query nfs41_driver
  83.         domainname
  84.  
  85.         openfiles /local ON
  86.  
  87.         # check whether the driver really has been installed
  88.         md5sum \
  89.                 "$PWD/nfs41_driver.sys" \
  90.                 '/cygdrive/c/Windows/System32/drivers/nfs41_driver.sys'
  91.  
  92.         return 0
  93. }
  94.  
  95. function nfsclient_rundeamon
  96. {
  97.         set -o xtrace
  98.         set -o nounset
  99.  
  100.         gdb -ex=run --args nfsd_debug -d 0 --noldap --gid 1616 --uid 1616
  101.         return $?
  102. }
  103.  
  104. function nfsclient_system_rundeamon
  105. {
  106.         set -o xtrace
  107.         set -o nounset
  108.  
  109.         su_system gdb -ex=run --args nfsd_debug -d 0 --noldap --gid 1616 --uid 1616
  110.         return $?
  111. }
  112.  
  113. function nfsclient_mount_homedir
  114. {
  115.         set -o xtrace
  116.         set -o nounset
  117.         set -o errexit
  118.  
  119.         #nfs_mount -p -o sec=sys H 'derfwpc5131:/export/home/rmainz'
  120.         # fixme: Specifying IPv6 addresses do not work yet, as soon as
  121.         # they come as UNC paths (e.g.
  122.         # $ cd '//[fe80::219:99ff:feae:73ce]@2049/nfs4/export/home/rmainz' #
  123.         # they get corrupted once they arrive in nfsd_debug.exe)
  124.         #nfs_mount -p -o sec=sys H '[fe80::219:99ff:feae:73ce]:/export/home/rmainz'
  125.         nfs_mount -p -o sec=sys H 'derfwpc5131_ipv6:/export/home/rmainz'
  126.         mkdir -p '/home/rmainz'
  127.         mount -o bind,posix=1 '/cygdrive/h' '/home/rmainz'
  128.         return $?
  129. }
  130.  
  131. function nfsclient_system_mount_homedir
  132. {
  133.         set -o xtrace
  134.         set -o nounset
  135.         set -o errexit
  136.  
  137.         # purge any leftover persistent mappings to device H:
  138.         su_system net use H: /delete || true
  139.  
  140.         #su_system nfs_mount -p -o sec=sys H 'derfwpc5131:/export/home/rmainz'
  141.         # fixme: Specifying IPv6 addresses do not work yet, as soon as
  142.         # they come as UNC paths (e.g.
  143.         # $ cd '//[fe80::219:99ff:feae:73ce]@2049/nfs4/export/home/rmainz' #
  144.         # they get corrupted once they arrive in nfsd_debug.exe)
  145.         #su_system nfs_mount -p -o sec=sys H '[fe80::219:99ff:feae:73ce]:/export/home/rmainz'
  146.         su_system nfs_mount -p -o sec=sys H 'derfwpc5131_ipv6:/export/home/rmainz'
  147.  
  148.         return $?
  149. }
  150.  
  151. function nfsclient_umount_homedir
  152. {
  153.         set -o xtrace
  154.         set -o nounset
  155.         typeset -i res
  156.  
  157.         nfs_mount -d H
  158.         (( res=$? ))
  159.  
  160.         if (( res == 0 )) ; then
  161.                 # remove bind mount
  162.                 umount '/home/rmainz' && rmdir '/home/rmainz'
  163.         fi
  164.  
  165.         return $res
  166. }
  167.  
  168. function require_cmd
  169. {
  170.         typeset cmd="$1"
  171.  
  172.         if ! which "$cmd" >'/dev/null' 2>&1 ; then
  173.                 printf $"%s: %q not found in %q\n" "$0" "$cmd" "$PWD" 1>&2
  174.                 return 1
  175.         fi
  176.         return 0
  177. }
  178.  
  179. # execute cmd as Windows user "SYSTEM"
  180. function su_system
  181. {
  182.         typeset cmd="$1"
  183.         shift
  184.        
  185.         typeset abspath_cmd="$(which "$cmd")"
  186.         if [[ ! -x "$abspath_cmd" ]] ; then
  187.                 printf "%s: Command %q not found." $"su_system" "$abspath_cmd" 1>&2
  188.                 return 127
  189.         fi
  190.  
  191.         PsExec \
  192.                 -accepteula -nobanner \
  193.                 -s \
  194.                 -w "$(cygpath -w "$PWD")" \
  195.                 "$(cygpath -w "$abspath_cmd")" "$@"
  196. }
  197.  
  198. function sys_terminal
  199. {
  200.         # su_system does not work, mintty requires PsExec -i
  201.         PsExec -accepteula -nobanner \
  202.                 -i \
  203.                 -s -w "$(cygpath -w "$PWD")" \
  204.                 'C:\cygwin64\bin\mintty.exe'
  205. }
  206.  
  207. function main
  208. {
  209.         typeset cmd="$1"
  210.  
  211.         # "$PATH:/usr/bin:/bin" is used for PsExec where $PATH might be empty
  212.         export PATH="$PWD:$PATH:/usr/bin:/bin"
  213.        
  214.         # my own path to pstools
  215.         PATH+=':/home/roland_mainz/work/win_pstools/'
  216.  
  217.         case "$cmd" in
  218.                 'install')
  219.                         nfsclient_install
  220.                         return $?
  221.                         ;;
  222.                 'run_deamon' | 'run_daemon')
  223.                         require_cmd 'nfsd.exe' || return 1
  224.                         require_cmd 'nfsd_debug.exe' || return 1
  225.                         require_cmd 'nfs_mount.exe' || return 1
  226.                         nfsclient_rundeamon
  227.                         return $?
  228.                         ;;
  229.                 'sys_run_deamon' | 'sys_run_daemon')
  230.                         require_cmd 'PsExec.exe' || return 1
  231.                         require_cmd 'nfsd.exe' || return 1
  232.                         require_cmd 'nfsd_debug.exe' || return 1
  233.                         require_cmd 'nfs_mount.exe' || return 1
  234.                         if ! is_windows_admin_account ; then
  235.                                 printf $"%s: %q requires Windows Adminstator permissions.\n" "$0" "$cmd"
  236.                                 return 1
  237.                         fi
  238.                         nfsclient_system_rundeamon
  239.                         return $?
  240.                         ;;
  241.                 'sys_mount_homedir')
  242.                         require_cmd 'nfs_mount.exe' || return 1
  243.                         if ! is_windows_admin_account ; then
  244.                                 printf $"%s: %q requires Windows Adminstator permissions.\n" "$0" "$cmd"
  245.                                 return 1
  246.                         fi
  247.                         nfsclient_system_mount_homedir
  248.                         return $?
  249.                         ;;
  250.                 'mount_homedir')
  251.                         require_cmd 'nfs_mount.exe' || return 1
  252.                         nfsclient_mount_homedir
  253.                         return $?
  254.                         ;;
  255.                 'umount_homedir')
  256.                         require_cmd 'nfs_mount.exe' || return 1
  257.                         nfsclient_umount_homedir
  258.                         return $?
  259.                         ;;
  260.                 # misc
  261.                 'sys_terminal')
  262.                         require_cmd 'mintty.exe' || return 1
  263.                         if ! is_windows_admin_account ; then
  264.                                 printf $"%s: %q requires Windows Adminstator permissions.\n" "$0" "$cmd"
  265.                                 return 1
  266.                         fi
  267.                         sys_terminal
  268.                         return $?
  269.                         ;;
  270.                 *)
  271.                         printf $"%s: Unknown cmd %q\n" "$0" "$cmd" 1>&2
  272.                         return 1
  273.                         ;;
  274.         esac
  275.         return 1
  276. }
  277.  
  278.  
  279. #
  280. # main
  281. #
  282. main "$@"
  283. exit $?
  284.  
  285. # EOF.

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