File: user-setup-ask

package info (click to toggle)
user-setup 1.11
  • links: PTS
  • area: main
  • in suites: etch-m68k
  • size: 868 kB
  • ctags: 5
  • sloc: sh: 342; makefile: 30
file content (214 lines) | stat: -rwxr-xr-x 5,630 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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#!/bin/sh -e

. /usr/share/debconf/confmodule

db_capb "backup"

if [ "$1" ]; then
	ROOT="$1"
else
	ROOT=
fi
export ROOT

. /usr/lib/user-setup/functions.sh

# For the convenience of heavy testers
set_special_users() {
	local realname
	case "$fullname" in
	    fjp)	realname="Frans Pop" ;;
	    tbm)	realname="Martin Michlmayr" ;;
	    *)		return 1 ;;
	esac
	db_set passwd/user-fullname "$realname"
	userdefault=$fullname
	db_fset passwd/username seen true
	return 0
}

# Main loop starts here. Use a state machine to allow jumping back to
# previous questions.
STATE=0
while :; do
	case "$STATE" in
	0)
		# Ask how the password files should be set up.
		db_input low passwd/shadow || true
		# Ask if root should be allowed to login.
		db_input medium passwd/root-login || true
	;;
	1)
		db_get passwd/root-login
		if [ "$RET" = false ]; then
			# root password will be locked
			db_set passwd/root-password ""
			db_set passwd/root-password-crypted "!"
		elif ! root_password; then
			# First check whether the root password was preseeded
			# crypted to an actual password (not locked)
			db_get passwd/root-password-crypted || true
			if ! test "$RET" || [ "x$RET" = "x!" ]; then
				# No preseed of the root password hash
				# we will prompt the user
				db_set passwd/root-password-crypted ""
				db_input critical passwd/root-password || true
				db_input critical passwd/root-password-again || true
			fi
		fi
	;;
	2)
		db_get passwd/root-login
		if [ "$RET" = false ]; then
			# root password will be locked
			db_set passwd/root-password-again ""
		elif ! root_password; then
			# First check whether the root password was preseeded crypted
			db_get passwd/root-password-crypted || true
			if ! test "$RET" ; then
				# Compare the two passwords, loop back if not
				# identical, or if empty.
				db_get passwd/root-password
				ROOT_PW="$RET"
				if [ -z "$ROOT_PW" ]; then
					db_fset user-setup/password-empty seen false
					db_input critical user-setup/password-empty
					db_fset passwd/root-password seen false
					db_fset passwd/root-password-again seen false
					STATE=0
					continue
				fi
				db_get passwd/root-password-again
				if [ "$ROOT_PW" != "$RET" ]; then
					db_fset user-setup/password-mismatch seen false
					db_input critical user-setup/password-mismatch
					db_fset passwd/root-password seen false
					db_fset passwd/root-password-again seen false
					STATE=0
					continue
				fi
				ROOT_PW=''
			fi
		fi
	;;
	3)
		# Ask if a non-root user should be made, if there is not
		# already one.
		db_get passwd/root-login
		if [ "$RET" = false ]; then
			# always make non-root user; this user will be able
			# to sudo to root
			db_set passwd/make-user true
		elif ! is_system_user; then
			db_input medium passwd/make-user || true
		fi
	;;
	4)
		# Prompt for user info.
		db_get passwd/make-user
		if [ "$RET" = true ] && ! is_system_user; then
			db_input critical passwd/user-fullname || true
		fi
	;;
	5)
		# Prompt for user info.
		db_get passwd/make-user
		if [ "$RET" = true ] && ! is_system_user; then
			LOOP=""
			db_get passwd/username
			if [ -z "$RET" ]; then
				db_get passwd/user-fullname
				fullname=$RET
				if ! set_special_users; then
					userdefault=$(echo "$fullname" | sed 's/ .*//' | LC_ALL=C tr A-Z a-z)
				fi
				if test -n "$userdefault" && \
					LC_ALL=C expr "$userdefault" : '[a-z][-a-z0-9]*$' >/dev/null; then
					db_set passwd/username "$userdefault"
				fi
			fi
			db_input critical passwd/username || true
		fi
	;;
	6)
		# Verify user.
		db_get passwd/make-user
		if [ "$RET" = true ] && ! is_system_user; then
			# Verify the user name, loop with message if bad.
			db_get passwd/username
			USER="$RET"
			if ! LC_ALL=C expr "$USER" : '[a-z][-a-z0-9]*$' >/dev/null; then
				db_fset passwd/username seen false
				db_fset passwd/username-bad seen false
				db_input critical passwd/username-bad
				STATE=3
				continue
			fi
			
			if grep -v '^#' /usr/lib/user-setup/reserved-usernames | \
			   grep -q "^$USER\$"; then
				db_fset passwd/username seen false
				db_fset passwd/username-reserved seen false
				db_subst passwd/username-reserved USERNAME "$USER"
				db_input critical passwd/username-reserved
				STATE=3
				continue
			fi

			db_get passwd/user-password-crypted || true
			if ! test "$RET" ; then
				db_input critical passwd/user-password || true
				db_input critical passwd/user-password-again || true
			fi
		fi
	;;
	7)
		db_get passwd/make-user
		if [ "$RET" = true ] && ! is_system_user; then
			db_get passwd/user-password-crypted || true
			if ! test "$RET" ; then
				# Compare the two passwords, loop with message if not
				# identical, or if empty.
				db_get passwd/user-password
				USER_PW="$RET"
				db_get passwd/user-password-again
				if [ "$USER_PW" != "$RET" ]; then
					db_set passwd/user-password ""
					db_set passwd/user-password-again ""
					db_fset user-setup/password-mismatch seen false
					db_input critical user-setup/password-mismatch
					db_fset passwd/user-password seen false
					db_fset passwd/user-password-again seen false
					STATE=6
					continue
				fi
				if [ -z "$USER_PW" ]; then
					db_set passwd/user-password ""
					db_set passwd/user-password-again ""
					db_fset user-setup/password-empty seen false
					db_input critical user-setup/password-empty
					db_fset passwd/user-password seen false
					db_fset passwd/user-password-again seen false
					STATE=6
					continue
				fi
			fi
		fi
	;;
	*)
		break
	;;
	esac

	if db_go; then
		STATE=$(($STATE + 1))
	else
		STATE=$(($STATE - 1))
	fi
	#echo "ON STATE: $STATE"
done

if test "$STATE" = -1 
then
	exit 10
fi