1##############################################################################
2#   Modules Revision 3.0
3#   Providing a flexible user environment
4#
5#   File:		modules.20-locate/%M%
6#   Revision:		%I%
7#   First Edition:	2017/04/23
8#   Last Mod.:		%U%, %G%
9#
10#   Authors:		Xavier Delaruelle, xavier.delaruelle@cea.fr
11#
12#   Description:	Testuite testsequence
13#   Command:		load, display, whatis, avail
14#   Modulefiles:
15#   Sub-Command:
16#
17#   Comment:	%C{
18#			Localization of deep modulefile when access rights to get to it
19#           does not allow it
20#		}C%
21#
22##############################################################################
23
24# cannot test access if cannot change file permission
25if {!$is_file_perms_editable} {
26    send_user "\tskipping access tests as file permissions cannot be changed\n"
27# cannot test access if superuser privileges are in use
28} elseif {$tcl_platform(user) eq "root"} {
29    send_user "\tskipping access tests as tests are run by superuser\n"
30# cannot test access if restricted file permissions have no effect
31} elseif {$is_locked_dir_file_readable && $is_locked_file_readable} {
32    send_user "\tskipping access tests as locked files or directories are still readable\n"
33} else {
34
35# ensure avail tests are made using in depth mode
36setenv_var MODULES_AVAIL_INDEPTH 1
37
38#
39# Variables for this test
40#
41
42set m1 "modalias/dir1/1.0"
43set lm1 "$m1"
44set lmf1 "$modpath/$lm1"
45set m2 "modalias/dir1/2.0"
46set lm2 "modalias/dir2/2.0"
47set lmf2 "$modpath/$lm2"
48set m3 "modload/dir2/md1"
49set lm3 "modload/dir2/1.0"
50set lmf3 "$modpath/$lm3"
51set m4 "moddef"
52set lm4 "moddef/dir2/1.0"
53set lmf4 "$modpath/$lm4"
54set m5 "plain/dir2"
55set lm5 "$m5/2.0"
56set lmf5 "$modpath/$lm5"
57set rlm5 "$m5/1.0"
58set rlmf5 "$modpath/$rlm5"
59set rlmfre5 "$modpathre/$rlm5"
60set m6 "plain/dir2"
61set lm6 "$m6/1.0"
62set lmf6 "$modpath/$lm6"
63set m7 "modalias"
64set lm7 "$m7/3.0"
65set lmf7 "$modpath/$lm7"
66set m8 "$m2"
67set lmrc8 "$modpath/modalias/dir1/.modulerc"
68set m9 "$m3"
69set lmrc9 "$modpath/modload/dir2/.modulerc"
70set m10 "$m4"
71set lmrc10 "$modpath/moddef/dir2/.modulerc"
72set rlm10 "$m10/dir2/2.0"
73set rlmf10 "$modpath/$rlm10"
74set rlmfre10 "$modpathre/$rlm10"
75set m12 "$m1"
76set lmd12 [file dirname $lmf1]
77set m13 "$m2"
78set lmd13 [file dirname $lmf2]
79set m14 "$m3"
80set lmd14 [file dirname $lmf3]
81set m15 "$m4"
82set lmd15 [file dirname $lmf4]
83set m16 "$m5"
84set lmd16 [file dirname $lmf5]
85set m17 "$m13"
86set lmd17 [file dirname $lmd13]
87set m18 "$m15"
88set lmd18 [file dirname $lmd15]
89set m19 "modvirt/dir1/1.0"
90set lmd19 "$modpath/modvirt/.common"
91set m20 "modvirt/dir1/2.0"
92set m21 "modsym"
93set lm21 "$m21/dir2/2.0"
94set lmf21 "$modpath/$lm21"
95set lmfre21 "$modpathre/$lm21"
96set lmfh21 "$modpath/$m21/dir1/1.0"
97
98set pheader "$modlin $modpathre $modlin"
99set theader "$modpathre:"
100set access_msg "$error_msgs: Permission denied on"
101set hide_perms "ugo-rx"
102
103#
104# Test access to modulefile when access not granted on this modulefile
105#
106
107change_file_perms $lmf1 $hide_perms
108
109testouterr_cmd "sh" "load $m1" "ERR" "$access_msg '$lmf1'"
110testouterr_cmd "sh" "display $m1" "ERR" "$access_msg '$lmf1'"
111testouterr_cmd "sh" "whatis $m1" "ERR" "$access_msg '$lmf1'"
112testouterr_cmd "sh" "avail -t $m1" "OK" ""
113
114restore_file_perms $lmf1
115
116#
117# Test access to alias when access not granted on target modulefile
118#
119
120change_file_perms $lmf2 $hide_perms
121
122testouterr_cmd "sh" "load $m2" "ERR" "$access_msg '$lmf2'"
123testouterr_cmd "sh" "display $m2" "ERR" "$access_msg '$lmf2'"
124testouterr_cmd "sh" "whatis $m2" "ERR" "$access_msg '$lmf2'"
125# alias defined so it appears even if access to target modulefile is denied
126testouterr_cmd_re "sh" "avail -t $m2" "OK" "$theader\n$m2\\(@\\)"
127
128restore_file_perms $lmf2
129
130#
131# Test access to symbol when access not granted on target modulefile
132#
133
134change_file_perms $lmf3 $hide_perms
135
136testouterr_cmd "sh" "load $m3" "ERR" "$access_msg '$lmf3'"
137testouterr_cmd "sh" "display $m3" "ERR" "$access_msg '$lmf3'"
138testouterr_cmd "sh" "whatis $m3" "ERR" "$access_msg '$lmf3'"
139# symbol is attached to the modulefile so it does not appear if the access
140# to the target modulefile is denied
141testouterr_cmd "sh" "avail -t $m3" "OK" ""
142
143restore_file_perms $lmf3
144
145#
146# Test access to default symbol when access not granted on target modulefile
147#
148
149change_file_perms $lmf4 $hide_perms
150
151# shout error as if we were trying to access the symbol directly
152testouterr_cmd "sh" "load $m4" "ERR" [if_implicitdefault "$access_msg '$lmf4'" "$err_nodefault'$m4'"]
153testouterr_cmd "sh" "display $m4" "ERR" [if_implicitdefault "$access_msg '$lmf4'" "$err_nodefault'$m4'"]
154# no error on whatis/avail, other versions are listed
155testouterr_cmd_re "sh" "whatis $m4" "OK" "$pheader\n\\s+$m4/dir2/2.0: $m4/dir2/2.0"
156testouterr_cmd_re "sh" "avail -t $m4" "OK" "$theader\n$m4/dir2/2.0"
157
158restore_file_perms $lmf4
159
160#
161# Test access to implicit default modulefile when access not granted on target
162# modulefile
163#
164
165change_file_perms $lmf5 $hide_perms
166
167lappend ans [list set TEST $rlm5]
168lappend ans [list setpath LOADEDMODULES $rlm5]
169lappend ans [list setpath _LMFILES_ $rlmf5]
170lappend ans [list setpath MODULES_LMCONFLICT "$rlm5&$m5"]
171if {[is_conf_enabled advversspec implicitdefault]} {
172    lappend ans [list setpath MODULES_LMALTNAME $rlm5&as|plain/default&as|plain/latest&as|$m5/default&as|$m5/latest]
173}
174
175# another implicit default is chosen
176testouterr_cmd "sh" "load $m5" [if_implicitdefault $ans ERR] [if_implicitdefault {} "$err_nodefault'$m5'"]
177testouterr_cmd_re "sh" "display $m5" [if_implicitdefault OK ERR] [if_implicitdefault "$modlin\n$rlmfre5:\n\nmodule-whatis\t$rlm5\nconflict\tplain/dir2\nsetenv\t\tTEST $rlm5\n$modlin" "$err_nodefault'$m5'"]
178testouterr_cmd_re "sh" "whatis $m5" "OK" "$pheader\n\\s+$rlm5: $rlm5"
179testouterr_cmd_re "sh" "avail -t $m5" "OK" "$theader\n$rlm5"
180
181# keep file permissions as it is for next test
182
183#
184# Test access to implicit default modulefile when access not granted on target
185# modulefile and there is no other implicit default available
186#
187
188change_file_perms $lmf6 $hide_perms
189
190# nothing found
191testouterr_cmd "sh" "load $m6" "ERR" "$err_path'$m6'"
192testouterr_cmd "sh" "display $m6" "ERR" "$err_path'$m6'"
193testouterr_cmd "sh" "whatis $m6" "ERR" "$err_path'$m6'"
194testouterr_cmd "sh" "avail -t $m6" "OK" ""
195
196restore_file_perms $lmf6
197restore_file_perms $lmf5
198
199#
200# Test access to implicit default alias when access not granted on target modulefile
201#
202
203change_file_perms $lmf7 $hide_perms
204
205# shout error as if we were trying to access the alias directly
206testouterr_cmd "sh" "load $m7" "ERR" [if_implicitdefault "$access_msg '$lmf7'" "$err_nodefault'$m7'"]
207testouterr_cmd "sh" "display $m7" "ERR" [if_implicitdefault "$access_msg '$lmf7'" "$err_nodefault'$m7'"]
208# no error on whatis/avail, other versions are listed
209testouterr_cmd_re "sh" "whatis $m7" "OK" "$pheader\n\\s+$m7/dir1/1.0: $m7/dir1/1.0\n\\s+$m7/dir2/2.0: $m7/dir2/2.0"
210# alias defined so it appears even if access to target modulefile is denied
211testouterr_cmd_re "sh" "avail -t $m7" "OK" "$theader\n$m7/1.0\\(@\\)\n$m7/dir1/1.0\n$m7/dir1/2.0\\(@\\)\n$m7/dir2/2.0\n$m7/dir2/3.0\\(@\\)"
212
213restore_file_perms $lmf7
214
215#
216# Test access to alias when access not granted on modulerc defining it
217#
218
219change_file_perms $lmrc8 $hide_perms
220
221# cannot locate module
222testouterr_cmd "sh" "load $m8" "ERR" "$err_path'$m8'"
223testouterr_cmd "sh" "display $m8" "ERR" "$err_path'$m8'"
224testouterr_cmd "sh" "whatis $m8" "ERR" "$err_path'$m8'"
225testouterr_cmd "sh" "avail -t $m8" "OK" ""
226
227restore_file_perms $lmrc8
228
229#
230# Test access to symbol when access not granted on modulerc defining it
231#
232
233change_file_perms $lmrc9 $hide_perms
234
235# cannot locate module
236testouterr_cmd "sh" "load $m9" "ERR" "$err_path'$m9'"
237testouterr_cmd "sh" "display $m9" "ERR" "$err_path'$m9'"
238testouterr_cmd "sh" "whatis $m9" "ERR" "$err_path'$m9'"
239testouterr_cmd "sh" "avail -t $m9" "OK" ""
240
241restore_file_perms $lmrc9
242
243#
244# Test access to default symbol when access not granted on modulerc defining it
245#
246
247change_file_perms $lmrc10 $hide_perms
248
249set ans [list]
250lappend ans [list set TEST $rlm10]
251lappend ans [list setpath LOADEDMODULES $rlm10]
252lappend ans [list setpath _LMFILES_ $rlmf10]
253if {[is_conf_enabled advversspec implicitdefault]} {
254    lappend ans [list setpath MODULES_LMALTNAME $rlm10&as|moddef/default&as|moddef/latest&as|moddef/dir2/default&as|moddef/dir2/latest]
255}
256
257# another implicit default is chosen
258testouterr_cmd "sh" "load $m10" [if_implicitdefault $ans ERR] [if_implicitdefault {} "$err_nodefault'$m10'"]
259testouterr_cmd_re "sh" "display $m10" [if_implicitdefault OK ERR] [if_implicitdefault "$modlin\n$rlmfre10:\n\nmodule-whatis\t$rlm10\nsetenv\t\tTEST $rlm10\n$modlin" "$err_nodefault'$m10'"]
260testouterr_cmd_re "sh" "whatis $m10" "OK" "$pheader\n\\s+$m10/dir2/1.0: $m10/dir2/1.0\n\\s+$m10/dir2/2.0: $m10/dir2/2.0"
261testouterr_cmd_re "sh" "avail -t $m10" "OK" "$theader\n$m10/dir2/1.0\n$m10/dir2/2.0"
262
263restore_file_perms $lmrc10
264
265#
266# Test access to modulefile when access not granted on its upper directory
267#
268
269change_file_perms $lmd12 $hide_perms
270
271# cannot locate module
272testouterr_cmd "sh" "load $m12" "ERR" "$err_path'$m12'"
273testouterr_cmd "sh" "display $m12" "ERR" "$err_path'$m12'"
274testouterr_cmd "sh" "whatis $m12" "ERR" "$err_path'$m12'"
275testouterr_cmd "sh" "avail -t $m12" "OK" ""
276
277restore_file_perms $lmd12
278
279#
280# Test access to alias when access not granted on its upper directory
281#
282
283change_file_perms $lmd13 $hide_perms
284
285# cannot locate module
286testouterr_cmd "sh" "load $m13" "ERR" "$err_path'$lm2'"
287testouterr_cmd "sh" "display $m13" "ERR" "$err_path'$lm2'"
288testouterr_cmd "sh" "whatis $m13" "ERR" "$err_path'$lm2'"
289testouterr_cmd_re "sh" "avail -t $m13" "OK" "$theader\n$m13\\(@\\)"
290
291restore_file_perms $lmd13
292
293#
294# Test access to symbol when access not granted on its upper directory
295#
296
297change_file_perms $lmd14 $hide_perms
298
299# cannot locate module
300testouterr_cmd "sh" "load $m14" "ERR" "$err_path'$m14'"
301testouterr_cmd "sh" "display $m14" "ERR" "$err_path'$m14'"
302testouterr_cmd "sh" "whatis $m14" "ERR" "$err_path'$m14'"
303testouterr_cmd "sh" "avail -t $m14" "OK" ""
304
305restore_file_perms $lmd14
306
307#
308# Test access to default symbol when access not granted on its upper directory
309#
310
311change_file_perms $lmd15 $hide_perms
312
313# permission denied on sub-directory, so cannot locate module
314testouterr_cmd "sh" "load $m15" "ERR" "$err_path'$m15'"
315testouterr_cmd "sh" "display $m15" "ERR" "$err_path'$m15'"
316testouterr_cmd "sh" "whatis $m15" "ERR" "$err_path'$m15'"
317testouterr_cmd "sh" "avail -t $m15" "OK" ""
318
319restore_file_perms $lmd15
320
321#
322# Test access to implicit default modulefile when access not granted on its
323# upper directory
324#
325
326change_file_perms $lmd16 $hide_perms
327
328# permission denied on directory
329testouterr_cmd "sh" "load $m16" "ERR" "$access_msg '$lmd16'"
330testouterr_cmd "sh" "display $m16" "ERR" "$access_msg '$lmd16'"
331testouterr_cmd "sh" "whatis $m16" "ERR" "$access_msg '$lmd16'"
332testouterr_cmd "sh" "avail -t $m16" "OK" ""
333
334restore_file_perms $lmd16
335
336#
337# Test access to alias when access not granted on its top upper directory
338#
339
340change_file_perms $lmd17 $hide_perms
341
342# cannot locate module
343testouterr_cmd "sh" "load $m17" "ERR" "$err_path'$m17'"
344testouterr_cmd "sh" "display $m17" "ERR" "$err_path'$m17'"
345testouterr_cmd "sh" "whatis $m17" "ERR" "$err_path'$m17'"
346testouterr_cmd "sh" "avail -t $m17" "OK" ""
347
348restore_file_perms $lmd17
349
350#
351# Test access to default symbol when access not granted on its top upper directory
352#
353
354change_file_perms $lmd18 $hide_perms
355
356# permission denied on directory
357testouterr_cmd "sh" "load $m18" "ERR" "$access_msg '$lmd18'"
358testouterr_cmd "sh" "display $m18" "ERR" "$access_msg '$lmd18'"
359testouterr_cmd "sh" "whatis $m18" "ERR" "$access_msg '$lmd18'"
360testouterr_cmd "sh" "avail -t $m18" "OK" ""
361
362restore_file_perms $lmd18
363
364#
365# Test access to virtual module when access not granted on its target file
366# lying in upper directory
367#
368
369change_file_perms $lmd19 $hide_perms
370
371# permission denied on virtual target file
372testouterr_cmd "sh" "load $m19" "ERR" "$access_msg '$lmd19'"
373testouterr_cmd "sh" "display $m19" "ERR" "$access_msg '$lmd19'"
374testouterr_cmd "sh" "whatis $m19" "ERR" "$access_msg '$lmd19'"
375testouterr_cmd "sh" "avail -t $m19" "OK" ""
376
377#
378# Test access to alias when access not granted on its virtual module target
379# lying in upper directory
380#
381
382# permission denied on virtual target file
383testouterr_cmd "sh" "load $m20" "ERR" "$access_msg '$lmd19'"
384testouterr_cmd "sh" "display $m20" "ERR" "$access_msg '$lmd19'"
385testouterr_cmd "sh" "whatis $m20" "ERR" "$access_msg '$lmd19'"
386# alias defined so it appears even if access to target modulefile is denied
387testouterr_cmd_re "sh" "avail -t $m20" "OK" "$theader\n$m20\\(@\\)"
388
389restore_file_perms $lmd19
390
391
392#
393# Test access to implicit default modulefile when access not granted on sibbling
394# modulefile leading to removing sibbling directory
395#
396
397change_file_perms $lmfh21 $hide_perms
398
399set ans [list]
400lappend ans [list set TEST $lm21]
401lappend ans [list setpath LOADEDMODULES $lm21]
402lappend ans [list setpath _LMFILES_ $lmf21]
403lappend ans [list setpath MODULES_LMCONFLICT "$lm21&$m21"]
404if {[is_conf_enabled advversspec implicitdefault]} {
405    lappend ans [list setpath MODULES_LMALTNAME "$lm21&modsym/dir2/3.0&as|modsym/default&as|modsym/latest&as|modsym/dir2/default&as|modsym/dir2/latest"]
406} else {
407    lappend ans [list setpath MODULES_LMALTNAME "$lm21&modsym/dir2/3.0"]
408}
409
410# implicit default is not impacted
411testouterr_cmd "sh" "load $m21" [if_implicitdefault $ans ERR] [if_implicitdefault {} "$err_nodefault'$m21'"]
412testouterr_cmd_re "sh" "display $m21" [if_implicitdefault OK ERR] [if_implicitdefault "$modlin\n$lmfre21:\n\nmodule-whatis\t$lm21\nconflict\t$m21\nsetenv\t\tTEST $lm21\n$modlin" "$err_nodefault'$m21'"]
413testouterr_cmd_re "sh" "whatis $m21" "OK" "$pheader\n\\s+$lm21: $lm21"
414testouterr_cmd_re "sh" "avail -t $m21" "OK" "$theader\n$lm21\\(3.0\\)"
415
416restore_file_perms $lmfh21
417
418
419#
420# Cleanup
421#
422
423unsetenv_var MODULES_AVAIL_INDEPTH
424
425unset ans
426
427unset pheader
428unset theader
429unset hide_perms
430
431unset m1
432unset lm1
433unset lmf1
434unset m2
435unset lm2
436unset lmf2
437unset m3
438unset lm3
439unset lmf3
440unset m4
441unset lm4
442unset lmf4
443unset m5
444unset lm5
445unset lmf5
446unset rlm5
447unset rlmf5
448unset rlmfre5
449unset m6
450unset lm6
451unset lmf6
452unset m7
453unset lm7
454unset lmf7
455unset m8
456unset lmrc8
457unset m9
458unset lmrc9
459unset m10
460unset lmrc10
461unset rlm10
462unset rlmf10
463unset rlmfre10
464unset m12
465unset lmd12
466unset m13
467unset lmd13
468unset m14
469unset lmd14
470unset m15
471unset lmd15
472unset m16
473unset lmd16
474unset m17
475unset lmd17
476unset m18
477unset lmd18
478unset m19
479unset lmd19
480unset m20
481unset m21
482unset lm21
483unset lmf21
484unset lmfre21
485unset lmfh21
486
487}
488