File: utils_test

package info (click to toggle)
libuser 1%3A0.56.9.dfsg.1-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 6,604 kB
  • ctags: 1,619
  • sloc: ansic: 15,970; sh: 10,210; xml: 2,060; python: 1,740; yacc: 782; makefile: 258; sed: 16
file content (193 lines) | stat: -rwxr-xr-x 6,513 bytes parent folder | download | duplicates (2)
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#! /bin/sh
# Automated libuser utilities regression tester
#
# Copyright (c) 2004, 2005 Red Hat, Inc. All rights reserved.
#
# This is free software; you can redistribute it and/or modify it under
# the terms of the GNU Library General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU Library General Public
# License along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
# Author: Miloslav Trmac <mitr@redhat.com>

srcdir=$srcdir/tests

workdir=$(pwd)/test_files

trap 'status=$?; rm -rf "$workdir"; exit $status' 0
trap '(exit 1); exit 1' 1 2 13 15

rm -rf "$workdir"
mkdir "$workdir"

# Set up an the environment
mkdir "$workdir"/files
> "$workdir"/files/passwd
> "$workdir"/files/shadow
> "$workdir"/files/group
> "$workdir"/files/gshadow

# Set up the client
LIBUSER_CONF=$workdir/libuser.conf
export LIBUSER_CONF
sed "s|@WORKDIR@|$workdir|g; s|@TOP_BUILDDIR@|$(pwd)|g" \
    < "$srcdir"/utils.conf.in > "$LIBUSER_CONF"
PATH=$(pwd)/apps:$PATH

LARGE_ID=2147483648
(
set -e
# lgroupadd:
lgroupadd -g "$(expr $LARGE_ID + 110)" group1_1
#  untested: -r

# lgroupdel:
lgroupadd group2_1
lgroupdel group2_1

# lgroupmod:
lgroupadd -g "$(expr $LARGE_ID + 310)" group3_1
lgroupmod -A user3_1,user3_2 -g "$(expr $LARGE_ID + 311)" -L \
    -M user3_3,user3_4 -n group3_2 -p '01vokOibos3pg' group3_1
lgroupmod -a user3_1,user3_1notexist -m user3_3,user3_2notexist -L group3_2
lgroupadd -g "$(expr $LARGE_ID + 330)" group3_3
lgroupmod -p '!!02yd6IWnPes66' group3_3
lgroupmod -U group3_3
#  Handling of GID change for primary and secondary groups
lgroupadd -g "$(expr $LARGE_ID + 340)" group3_4
luseradd -M -g group3_4 -u "$(expr $LARGE_ID + 350)" user3_5
lgroupadd -g "$(expr $LARGE_ID + 350)" group3_5
luseradd -M -g group3_5 -u "$(expr $LARGE_ID + 360)" user3_6
lgroupmod -M user3_6 group3_4
lgroupmod -g "$(expr $LARGE_ID + 341)" group3_4
#  untested: -P

# lchage:
lgroupadd -g "$(expr $LARGE_ID + 410)" user4_1
luseradd -M -u "$(expr $LARGE_ID + 410)" user4_1
lchage -d 400 -E 410 -I 420 -m 430 -M 440 -W 450 user4_1
LC_ALL=C lchage -l user4_1 > "$workdir"/lchage_output
diff - "$workdir"/lchage_output <<\EOF
Account is locked.
Minimum:	430
Maximum:	440
Warning:	450
Inactive:	420
Last Change:	02/05/71
Password Expires:	04/20/72
Password Inactive:	06/14/73
Account Expires:	02/15/71
EOF

# lchfn: untested (requires system account)
# lchsh: untested (requires system account)

# lid:
lgroupadd -g "$(expr $LARGE_ID + 510)" group5_1
lgroupadd -g "$(expr $LARGE_ID + 520)" group5_2
lgroupadd -g "$(expr $LARGE_ID + 530)" group5_3
luseradd -M -g group5_1 -u "$(expr $LARGE_ID + 510)" user5_1
luseradd -M -g group5_3 -u "$(expr $LARGE_ID + 520)" user5_2
lgroupmod -M user5_1,user5_2 group5_2
lgroupmod -M user5_2 group5_1
lid user5_1 > "$workdir"/lid_output1
diff - "$workdir"/lid_output1 <<EOF
 group5_1(gid=$(expr $LARGE_ID + 510))
 group5_2(gid=$(expr $LARGE_ID + 520))
EOF
lid -n user5_1 > "$workdir"/lid_output2
diff - "$workdir"/lid_output2 <<\EOF
 group5_1
 group5_2
EOF
lid -g group5_1 > "$workdir"/lid_output3
diff - "$workdir"/lid_output3 <<EOF
 user5_1(uid=$(expr $LARGE_ID + 510))
 user5_2(uid=$(expr $LARGE_ID + 520))
EOF
lid -g -n group5_1 > "$workdir"/lid_output4
diff - "$workdir"/lid_output4 <<\EOF
 user5_1
 user5_2
EOF

# lnewusers:
lgroupadd -g "$(expr $LARGE_ID + 620)" user6_2
lgroupadd -g "$(expr $LARGE_ID + 630)" group6_3
LC_ALL=C lnewusers -M -n 2> "$workdir"/lnewusers_output <<EOF
user6_1:password:$(expr $LARGE_ID + 610):$(expr $LARGE_ID + 610):GECOS6_1:HomeDir6_1:Shell6_1
user6_2:password:$(expr $LARGE_ID + 620)::::
Invalid line
user6_3:password:$(expr $LARGE_ID + 630):$(expr $LARGE_ID + 630):::
user6_4:password:$(expr $LARGE_ID + 640):group6_4:::
EOF
diff - "$workdir"/lnewusers_output <<\EOF
Error creating account for `Invalid line': line improperly formatted.
EOF

# lpasswd: untested (requires system account)

# luseradd:
lgroupadd -g "$(expr $LARGE_ID + 710)" group7_1
luseradd -c GECOS7_1 -d HomeDir7_1 -g group7_1 -M -p '03dgZm5nZvqOc' \
    -s Shell7_1 -u "$(expr $LARGE_ID + 710)" user7_1
#  untested: -k, -r, -n, -P

# luserdel:
lgroupadd -g "$(expr $LARGE_ID + 810)" group8_1
luseradd -g group8_1 -M user8_1
luserdel user8_1
luseradd -M user8_2
luserdel user8_2
lgroupadd -g "$(expr $LARGE_ID + 830)" user8_3
luseradd -M user8_3
luserdel -G user8_3

# lusermod:
lgroupadd -g "$(expr $LARGE_ID + 910)" group9_1
luseradd -g group9_1 -u "$(expr $LARGE_ID + 910)" -M user9_1
lgroupadd -g "$(expr $LARGE_ID + 920)" group9_2
lusermod -c GECOS9_1 -d HomeDir9_1 -g "$(expr $LARGE_ID + 920)" -l user9_2 \
    -p '04aqostCGmvZM' -s Shell9_1 -u "$(expr $LARGE_ID + 911)" user9_1
lusermod -L user9_2
lgroupadd -g "$(expr $LARGE_ID + 930)" group9_3
luseradd -g group9_3 -u "$(expr $LARGE_ID + 930)" -M user9_3
lusermod -p '!!05FdoegP8UniQ' user9_3
lusermod -U user9_3
#  Handling of username change for primary and secondary groups
lgroupadd -g "$(expr $LARGE_ID + 940)" group9_4
lgroupadd -g "$(expr $LARGE_ID + 950)" group9_5
luseradd -g "$(expr $LARGE_ID + 940)" -u "$(expr $LARGE_ID + 940)" -M user9_4
lgroupmod -M user9_4 group9_5
lusermod -l user9_5 user9_4
#  lusermod -g warns if the group does not exist
lgroupadd -g "$(expr $LARGE_ID + 960)" group9_6
luseradd -g group9_6 -u "$(expr $LARGE_ID + 960)" -M user9_6
LC_ALL=C lusermod -g "$(expr $LARGE_ID + 961)" user9_6 \
    2>"$workdir"/lusermod_output
diff - "$workdir"/lusermod_output <<EOF
Warning: Group with ID $(expr $LARGE_ID + 961) does not exist.
EOF
#  untested: -m, -P

sed 's/^group6_4:x:[0123456789]*:$/group6_4:x:GID:/' < "$workdir"/files/group \
    > "$workdir"/group
diff -u "$srcdir"/utils_group "$workdir"/group
diff -u "$srcdir"/utils_gshadow "$workdir"/files/gshadow
sed 's/^\(user6_4:x:[^:]*\):[0123456789]*:\(.*\)$/\1:GID:\2/' \
    < "$workdir"/files/passwd > "$workdir"/passwd
diff -u "$srcdir"/utils_passwd "$workdir"/passwd
sed -e 's/^\([^:]*:[^:]*\):[0123456789]\{5,\}:\(.*\)$/\1:DATE:\2/' \
    -e 's/^\([^:]*\):\$1\$[^:]*:\(.*\)$/\1:HASH:\2/' \
    < "$workdir"/files/shadow > "$workdir"/shadow
diff -u "$srcdir"/utils_shadow "$workdir"/shadow
)