pastebin - collaborative debugging tool
rovema.kpaste.net RSS

Difference between
modified post 3b62679d by Anonymous on Thu 5th Oct 2023 14:05
original post e57f50ddcb by Anonymous on Fri 29th Sep 2023 17:26
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
	mkdir -p /cygdrive/c/etc
7272
	cp etc_netconfig /cygdrive/c/etc/netconfig
7373
	cp ms-nfs41-idmap.conf /cygdrive/c/etc/.
7474
7575
	bcdedit /set testsigning on
7676
	regtool -s set '/HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services/Tcpip/Parameters/Domain' 'GLOBAL.LOC'
7777
7878
	sc query Dfsc
7979
	sc stop Dfsc || true
8080
	sc config Dfsc start=disabled
8181
8282
	sc query nfs41_driver
8383
	domainname
8484
85+
	openfiles /local ON
8587
	# check whether the driver really has been installed
8688
	md5sum \
8789
		"$PWD/nfs41_driver.sys" \
8890
		'/cygdrive/c/Windows/System32/drivers/nfs41_driver.sys'
8991
9092
	return 0
9193
}
9294
9395
function nfsclient_rundeamon
9496
{
9597
	set -o xtrace
9698
	set -o nounset
9799
98-
	nfsd_debug -d 0 --noldap --gid 1616 --uid 1616
100+
	gdb -ex=run --args nfsd_debug -d 0 --noldap --gid 1616 --uid 1616
99101
	return $?
100102
}
101103
102104
function nfsclient_system_rundeamon
103105
{
104106
	set -o xtrace
105107
	set -o nounset
106108
107-
	su_system nfsd_debug -d 0 --noldap --gid 1616 --uid 1616
109+
	su_system gdb -ex=run --args nfsd_debug -d 0 --noldap --gid 1616 --uid 1616
108110
	return $?
109111
}
110112
111113
function nfsclient_mount_homedir
112114
{
113115
	set -o xtrace
114116
	set -o nounset
115117
	set -o errexit
116118
117119
	#nfs_mount -p -o sec=sys H 'derfwpc5131:/export/home/rmainz'
118120
	# fixme: Specifying IPv6 addresses do not work yet, as soon as
119121
	# they come as UNC paths (e.g.
120122
	# $ cd '//[fe80::219:99ff:feae:73ce]@2049/nfs4/export/home/rmainz' #
121123
	# they get corrupted once they arrive in nfsd_debug.exe)
122124
	#nfs_mount -p -o sec=sys H '[fe80::219:99ff:feae:73ce]:/export/home/rmainz'
123125
	nfs_mount -p -o sec=sys H 'derfwpc5131_ipv6:/export/home/rmainz'
124126
	mkdir -p '/home/rmainz'
125127
	mount -o bind,posix=1 '/cygdrive/h' '/home/rmainz'
126128
	return $?
127129
}
128130
129131
function nfsclient_system_mount_homedir
130132
{
131133
	set -o xtrace
132134
	set -o nounset
133135
	set -o errexit
134136
135137
	# purge any leftover persistent mappings to device H:
136138
	su_system net use H: /delete || true
137139
138140
	#su_system nfs_mount -p -o sec=sys H 'derfwpc5131:/export/home/rmainz'
139141
	# fixme: Specifying IPv6 addresses do not work yet, as soon as
140142
	# they come as UNC paths (e.g.
141143
	# $ cd '//[fe80::219:99ff:feae:73ce]@2049/nfs4/export/home/rmainz' #
142144
	# they get corrupted once they arrive in nfsd_debug.exe)
143145
	#su_system nfs_mount -p -o sec=sys H '[fe80::219:99ff:feae:73ce]:/export/home/rmainz'
144146
	su_system nfs_mount -p -o sec=sys H 'derfwpc5131_ipv6:/export/home/rmainz'
145147
146148
	return $?
147149
}
148150
149151
function nfsclient_umount_homedir
150152
{
151153
	set -o xtrace
152154
	set -o nounset
153155
	typeset -i res
154156
155157
	nfs_mount -d H
156158
	(( res=$? ))
157159
158160
	if (( res == 0 )) ; then
159161
		# remove bind mount
160162
		umount '/home/rmainz' && rmdir '/home/rmainz'
161163
	fi
162164
163165
	return $res
164166
}
165167
166168
function require_cmd
167169
{
168170
	typeset cmd="$1"
169171
170172
	if ! which "$cmd" >'/dev/null' 2>&1 ; then
171173
		printf $"%s: %q not found in %q\n" "$0" "$cmd" "$PWD" 1>&2
172174
		return 1
173175
	fi
174176
	return 0
175177
}
176178
177179
# execute cmd as Windows user "SYSTEM"
178180
function su_system
179181
{
180182
	typeset cmd="$1"
181183
	shift
182184
183185
	typeset abspath_cmd="$(which "$cmd")"
184186
	if [[ ! -x "$abspath_cmd" ]] ; then
185187
		printf "%s: Command %q not found." $"su_system" "$abspath_cmd" 1>&2
186188
		return 127
187189
	fi
188190
189191
	PsExec \
190192
		-accepteula -nobanner \
191193
		-s \
192194
		-w "$(cygpath -w "$PWD")" \
193195
		"$(cygpath -w "$abspath_cmd")" "$@"
194196
}
195197
196198
function sys_terminal
197199
{
198200
	# su_system does not work, mintty requires PsExec -i
199201
	PsExec -accepteula -nobanner \
200202
		-i \
201203
		-s -w "$(cygpath -w "$PWD")" \
202204
		'C:\cygwin64\bin\mintty.exe'
203205
}
204206
205207
function main
206208
{
207209
	typeset cmd="$1"
208210
209211
	# "$PATH:/usr/bin:/bin" is used for PsExec where $PATH might be empty
210212
	export PATH="$PWD:$PATH:/usr/bin:/bin"
211213
212214
	# my own path to pstools
213215
	PATH+=':/home/roland_mainz/work/win_pstools/'
214216
215217
	case "$cmd" in
216218
		'install')
217219
			nfsclient_install
218220
			return $?
219221
			;;
220222
		'run_deamon' | 'run_daemon')
221223
			require_cmd 'nfsd.exe' || return 1
222224
			require_cmd 'nfsd_debug.exe' || return 1
223225
			require_cmd 'nfs_mount.exe' || return 1
224226
			nfsclient_rundeamon
225227
			return $?
226228
			;;
227229
		'sys_run_deamon' | 'sys_run_daemon')
228230
			require_cmd 'PsExec.exe' || return 1
229231
			require_cmd 'nfsd.exe' || return 1
230232
			require_cmd 'nfsd_debug.exe' || return 1
231233
			require_cmd 'nfs_mount.exe' || return 1
232234
			if ! is_windows_admin_account ; then
233235
				printf $"%s: %q requires Windows Adminstator permissions.\n" "$0" "$cmd"
234236
				return 1
235237
			fi
236238
			nfsclient_system_rundeamon
237239
			return $?
238240
			;;
239241
		'sys_mount_homedir')
240242
			require_cmd 'nfs_mount.exe' || return 1
241243
			if ! is_windows_admin_account ; then
242244
				printf $"%s: %q requires Windows Adminstator permissions.\n" "$0" "$cmd"
243245
				return 1
244246
			fi
245247
			nfsclient_system_mount_homedir
246248
			return $?
247249
			;;
248250
		'mount_homedir')
249251
			require_cmd 'nfs_mount.exe' || return 1
250252
			nfsclient_mount_homedir
251253
			return $?
252254
			;;
253255
		'umount_homedir')
254256
			require_cmd 'nfs_mount.exe' || return 1
255257
			nfsclient_umount_homedir
256258
			return $?
257259
			;;
258260
		# misc
259261
		'sys_terminal')
260262
			require_cmd 'mintty.exe' || return 1
261263
			if ! is_windows_admin_account ; then
262264
				printf $"%s: %q requires Windows Adminstator permissions.\n" "$0" "$cmd"
263265
				return 1
264266
			fi
265267
			sys_terminal
266268
			return $?
267269
			;;
268270
		*)
269271
			printf $"%s: Unknown cmd %q\n" "$0" "$cmd" 1>&2
270272
			return 1
271273
			;;
272274
	esac
273275
	return 1
274276
}
275277
276278
277279
#
278280
# main
279281
#
280282
main "$@"
281283
exit $?
282284
283285
# EOF.
284286

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