File: 150-access-init.exp

package info (click to toggle)
modules 5.6.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 23,036 kB
  • sloc: exp: 79,659; sh: 6,142; tcl: 5,900; makefile: 1,493; ansic: 474; python: 265; csh: 202; perl: 47; ruby: 44; lisp: 13
file content (118 lines) | stat: -rw-r--r-- 4,898 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
##############################################################################
#   Modules Revision 3.0
#   Providing a flexible user environment
#
#   File:		modules.00-init/%M%
#   Revision:		%I%
#   First Edition:	2019/05/05
#   Last Mod.:		%U%, %G%
#
#   Authors:		Xavier Delaruelle, xavier.delaruelle@cea.fr
#
#   Description:	Testuite testsequence
#   Command:		load, display
#   Modulefiles:
#   Sub-Command:
#
#   Comment:	%C{
#           Tests startup of the modulecmd script when access to its
#           external files is forbidden
#       }C%
#
##############################################################################

# cannot test access if cannot change file permission
if {!$is_file_perms_editable} {
    send_user "\tskipping access tests as file permissions cannot be changed\n"
# cannot test access if superuser privileges are in use
} elseif {$tcl_platform(user) eq "root"} {
    send_user "\tskipping access tests as tests are run by superuser\n"
# cannot test access if restricted file permissions have no effect
} elseif {$is_locked_dir_file_readable && $is_locked_file_readable} {
    send_user "\tskipping access tests as locked files or directories are still readable\n"
} else {

set ans [list]

if {[info exists tclextlib_file]} {
    # restrict read access to Tcl extension library
    change_file_perms $tclextlib_file ugo-rx
    lappend ans "DEBUG setState: cmdline set to '$MODULECMD sh --no-pager -D -V'"
    if {$::install_multilibsupport eq {y}} {
        lappend ans "DEBUG setState: machine set to '$::tcl_platform(machine)'"
    }
    lappend ans "DEBUG setConf: tcl_ext_lib set to '$tclextlib_file'"
    lappend ans "DEBUG setConf: siteconfig set to '$siteconfig_filere'(\\nDEBUG sourceSiteConfig: Source site configuration \\($siteconfig_filere\\))?(\\nDEBUG setState: siteconfig_loaded set to '1')?"
    lappend ans "DEBUG setConf: locked_configs set to '$install_lockedconfigs'"
    lappend ans "DEBUG setState: supported_shells set to 'sh bash ksh zsh csh tcsh fish cmd tcl perl python ruby lisp cmake r pwsh'"
    lappend ans "DEBUG setState: shell set to 'sh'"
    lappend ans "DEBUG setState: subcmd set to ''"
    lappend ans "DEBUG setState: subcmd_args set to ''"
    lappend ans "DEBUG setState: init_error_report set to '1'"
    lappend ans "DEBUG setConf: verbosity set to 'debug'"
    lappend ans "DEBUG setConf: term_background set to '$install_termbg'"
    lappend ans "(DEBUG initConfColors: Ignore invalid default.*\\n)?DEBUG setConf: colors set to '.*'"
    lappend ans "DEBUG setConf: color set to '0'"
    lappend ans "DEBUG setConf: pager set to '$install_pagercmd'"
    lappend ans "DEBUG setState: shelltype set to 'sh'"
    lappend ans "DEBUG setState: paginate set to '0'"
    lappend ans "DEBUG setState: report_format set to 'regular'"
    lappend ans "DEBUG setState: reportfd set to 'stderr'"
    lappend ans "DEBUG setState: timer set to '0'"
    lappend ans $vers_reportre
    lappend ans "DEBUG setConf: logger set to '$::install_loggercmd'"
    lappend ans "DEBUG setState: logging set to '0'"
    lappend ans "DEBUG setState: logfd set to ''"
    lappend ans "DEBUG setState: error_count set to '0'"
    testouterr_cmd_re sh {--no-pager -D -V} {} [join $ans \n]
    restore_file_perms $tclextlib_file

    # replace Tcl extension library by a non lib file
    file rename $tclextlib_file $tclextlib_file.orig
    file copy lib/envmodules.c $tclextlib_file
    set tclextlib_file_abs_re [regsub -all "\(\[.+?\]\)" [file normalize $tclextlib_file] {\\\1}]
    if {$os_name eq {darwin}} {
        set tserr "$error_msgs: dlopen\\\($tclextlib_file_abs_re,.*"
    } else {
        set tserr "$error_msgs: couldn't load file \"$tclextlib_file_abs_re\":.*"
    }
    testouterr_cmd_re sh {-V} {} $tserr
    file delete $tclextlib_file
    file rename $tclextlib_file.orig $tclextlib_file
}

# restrict read access to site-specific configuration script
if {[file readable $siteconfig_file] && [file owned $siteconfig_file]} {
    change_file_perms $siteconfig_file ugo-rx
    testouterr_cmd_re sh {-V} {} $vers_reportre
    restore_file_perms $siteconfig_file
}

skip_if_quick_mode

# restrict read access to additional site-specific configuration script
if {![is_config_locked extra_siteconfig]} {
    set addsiteconfig_file $env(TESTSUITEDIR)/example/siteconfig.tcl-2
    setenv_var MODULES_SITECONFIG $addsiteconfig_file
    change_file_perms $addsiteconfig_file ugo-rx
    testouterr_cmd_re sh {-V} {} $vers_reportre
    restore_file_perms $addsiteconfig_file
    unsetenv_var MODULES_SITECONFIG
}

# restrict read access to MODULERCFILE
set modulerc_file $env(TESTSUITEDIR)/etc/modulerc
setenv_var MODULERCFILE $modulerc_file
change_file_perms $modulerc_file ugo-rx
testouterr_cmd_re sh {list} {} $no_loaded
restore_file_perms $modulerc_file
setenv_var MODULERCFILE $ORIG_MODULERCFILE


#
# Cleanup
#

reset_test_env

}