pastebin - collaborative debugging tool
rovema.kpaste.net RSS

Difference between
modified post ab62a by Anonymous on Thu 28th Sep 2023 14:28
original post 7d0b by Anonymous on Tue 19th Sep 2023 17:07
Download diff
Show old version | new version | both versions

    
11
#!/bin/bash
22
33
#
44
# msnfs41client.bash - simple Cygwin frontent for the msnfsv41
55
# NFSv4.1 filesystem driver
66
#
77
88
#
99
# Written by Roland Mainz <roland.mainz@nrubsig.org>
1010
#
1111
1212
#
1313
# Examples:
1414
#
1515
# 1. Mount for current users:
1616
# (requires PsExec from https://download.sysinternals.com/files/PSTools.zip
1717
# in /home/roland_mainz/work/win_pstools/)
1818
# * Usage:
1919
# Shell1: cd /cygdrive/c/Users/roland_mainz/Downloads/ms-nfs41-client-x64/ms-nfs41-client-x64 && bash ../msnfs41client.bash run_deamon
2020
# Shell2: cd /cygdrive/c/Users/roland_mainz/Downloads/ms-nfs41-client-x64/ms-nfs41-client-x64 && bash ../msnfs41client.bash mount_homedir
2121
#
2222
# 2. Mount for all users:
2323
# * Requires:
2424
# - Windows admin rights (Cygwin --> Run terminal as Adminstrator)
2525
# - PsExec from https://download.sysinternals.com/files/PSTools.zip in /home/roland_mainz/work/win_pstools/)
2626
# * Usage:
2727
# Shell1: cd /cygdrive/c/Users/roland_mainz/Downloads/ms-nfs41-client-x64/ms-nfs41-client-x64 && bash ../msnfs41client.bash sys_run_deamon
2828
# Shell2: cd /cygdrive/c/Users/roland_mainz/Downloads/ms-nfs41-client-x64/ms-nfs41-client-x64 && bash ../msnfs41client.bash sys_mount_homedir
2929
#
3030
3131
function is_windows_admin_account
3232
{
3333
	#
3434
	# Test whether we have the Windows permissions to install DLLs
3535
	# and the kernel module
3636
	#
3737
	# Usually Windows Adminstrator rights are indicated by the
3838
	# membership in group "544(Administratoren)" (Cygwin maps
3939
	# "SID S-1-5-32-544" to GID 544)
4040
	#
4141
	if [[ "$(id -G)" =~ (^|[[:space:]]+)544([[:space:]]+|$) ]] ; then
4242
		return 0
4343
	fi
4444
	return 1
4545
}
4646
4747
function nfsclient_install
4848
{
4949
	set -o nounset
5050
	set -o xtrace
5151
	set -o errexit
5252
5353
	if ! is_windows_admin_account ; then
5454
		printf $"%s: Install requires Windows Adminstator permissions.\n" "$0"
5555
		return 1
5656
	fi
5757
5858
	# make sure all binaries are executable, Windows cmd does
5959
	# not care, but Cygwin&bash do.
6060
	# If *.ddl are not executable nfs*.exe fail with 0xc0000022
6161
	chmod a+x *.exe *.dll
6262
6363
	if false ; then
6464
		# install.bat needs PATH to include $PWD
6565
		PATH="$PWD:$PATH" cmd /c install.bat
6666
	else
6767
		nfs_install
6868
		rundll32 setupapi.dll,InstallHinfSection DefaultInstall 132 ./nfs41rdr.inf
6969
	fi
7070
7171
	cp etc_netconfig /cygdrive/c/etc/netconfig
7272
	cp ms-nfs41-idmap.conf /cygdrive/c/etc/.
7373
7474
	bcdedit /set testsigning on
7575
	regtool -s set '/HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services/Tcpip/Parameters/Domain' 'GLOBAL.LOC'
7676
7777
	sc query Dfsc
7878
	sc stop Dfsc || true
7979
	sc config Dfsc start=disabled
8080
8181
	sc query nfs41_driver
8282
	domainname
8383
8484
	# check whether the driver really has been installed
8585
	md5sum \
8686
		"$PWD/nfs41_driver.sys" \
8787
		'/cygdrive/c/Windows/System32/drivers/nfs41_driver.sys'
8888
8989
	return 0
9090
}
9191
9292
function nfsclient_rundeamon
9393
{
9494
	set -o xtrace
9595
	set -o nounset
9696
97-
	nfsd_debug -d 2  --noldap --gid 1616 --uid 1616
97+
	nfsd_debug -d 0 --noldap --gid 1616 --uid 1616
9898
	return $?
9999
}
100100
101101
function nfsclient_system_rundeamon
102102
{
103103
	set -o xtrace
104104
	set -o nounset
105105
106-
	su_system nfsd_debug -d 2 --noldap --gid 1616 --uid 1616
106+
	su_system nfsd_debug -d 0 --noldap --gid 1616 --uid 1616
107107
	return $?
108108
}
109109
110110
function nfsclient_mount_homedir
111111
{
112112
	set -o xtrace
113113
	set -o nounset
114114
	set -o errexit
115115
116-
	nfs_mount -p -o sec=sys H 'derfwpc5131:/export/home/rmainz'
116+
	#nfs_mount -p -o sec=sys H 'derfwpc5131:/export/home/rmainz'
117+
	# fixme: Specifying IPv6 addresses do not work yet, as soon as
117123
	mkdir -p '/home/rmainz'
118124
	mount -o bind,posix=1 '/cygdrive/h' '/home/rmainz'
119125
	return $?
120126
}
121127
122128
function nfsclient_system_mount_homedir
123129
{
124130
	set -o xtrace
125131
	set -o nounset
126132
	set -o errexit
127133
128-
	su_system nfs_mount -p -o sec=sys H 'derfwpc5131:/export/home/rmainz'
134+
	#su_system nfs_mount -p -o sec=sys H 'derfwpc5131:/export/home/rmainz'
135+
	# fixme: Specifying IPv6 addresses do not work yet, as soon as
129141
130142
	return $?
131143
}
132144
133145
function nfsclient_umount_homedir
134146
{
135147
	set -o xtrace
136148
	set -o nounset
137149
	typeset -i res
138150
139151
	nfs_mount -d H
140152
	(( res=$? ))
141153
142154
	if (( res == 0 )) ; then
143155
		# remove bind mount
144156
		umount '/home/rmainz' && rmdir '/home/rmainz'
145157
	fi
146158
147159
	return $res
148160
}
149161
150162
function require_cmd
151163
{
152164
	typeset cmd="$1"
153165
154166
	if ! which "$cmd" >'/dev/null' 2>&1 ; then
155167
		printf $"%s: %q not found in %q\n" "$0" "$cmd" "$PWD" 1>&2
156168
		return 1
157169
	fi
158170
	return 0
159171
}
160172
161173
# execute cmd as Windows user "SYSTEM"
162174
function su_system
163175
{
164176
	typeset cmd="$1"
165177
	shift
166178
167179
	typeset abspath_cmd="$(which "$cmd")"
168180
	if [[ ! -x "$abspath_cmd" ]] ; then
169181
		printf "%s: Command %q not found." $"su_system" "$abspath_cmd" 1>&2
170182
		return 127
171183
	fi
172184
173185
	PsExec \
174186
		-accepteula -nobanner \
175187
		-s \
176188
		-w "$(cygpath -w "$PWD")" \
177189
		"$(cygpath -w "$abspath_cmd")" "$@"
178190
}
179191
192+
function sys_terminal
181193
{
194+
	# su_system does not work, mintty requires PsExec -i
183200
201+
function main
184205
	# "$PATH:/usr/bin:/bin" is used for PsExec where $PATH might be empty
185206
	export PATH="$PWD:$PATH:/usr/bin:/bin"
186207
187208
	# my own path to pstools
188209
	PATH+=':/home/roland_mainz/work/win_pstools/'
189210
190211
	case "$cmd" in
191212
		'install')
192213
			nfsclient_install
193214
			return $?
194215
			;;
195216
		'run_deamon' | 'run_daemon')
196217
			require_cmd 'nfsd.exe' || return 1
197218
			require_cmd 'nfsd_debug.exe' || return 1
198219
			require_cmd 'nfs_mount.exe' || return 1
199220
			nfsclient_rundeamon
200221
			return $?
201222
			;;
202223
		'sys_run_deamon' | 'sys_run_daemon')
203224
			require_cmd 'PsExec.exe' || return 1
204225
			require_cmd 'nfsd.exe' || return 1
205226
			require_cmd 'nfsd_debug.exe' || return 1
206227
			require_cmd 'nfs_mount.exe' || return 1
207-
			is_windows_admin_account || return 1
228+
			if ! is_windows_admin_account ; then
229+
				printf $"%s: %q requires Windows Adminstator permissions.\n" "$0" "$cmd"
208232
			nfsclient_system_rundeamon
209233
			return $?
210234
			;;
211235
		'sys_mount_homedir')
212236
			require_cmd 'nfs_mount.exe' || return 1
213-
			is_windows_admin_account || return 1
237+
			if ! is_windows_admin_account ; then
238+
				printf $"%s: %q requires Windows Adminstator permissions.\n" "$0" "$cmd"
214241
			nfsclient_system_mount_homedir
215242
			return $?
216243
			;;
217244
		'mount_homedir')
218245
			require_cmd 'nfs_mount.exe' || return 1
219246
			nfsclient_mount_homedir
220247
			return $?
221248
			;;
222249
		'umount_homedir')
223250
			require_cmd 'nfs_mount.exe' || return 1
224251
			nfsclient_umount_homedir
225252
			return $?
226253
			;;
227-
		*)
254+
		# misc
228-
			printf $"%s: Unknown cmd %q\n" "$0" "$cmd" 1>&2
255+
		'sys_terminal')
256+
			require_cmd 'mintty.exe' || return 1
229259
			return 1
260+
			fi
230263
			;;
264+
		*)
232266
	return 1
267+
			;;
233270
}
234271
235272
236273
#
237274
# main
238275
#
239276
main "$@"
240277
exit $?
241278
242279
# EOF.
243280

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