View | Details | Raw Unified | Return to bug 221416
Collapse All | Expand All

(-)b/usr.sbin/pw/pw_user.c (-4 / +2 lines)
Lines 1202-1208 pw_user_add(int argc, char **argv, char *arg1) Link Here
1202
		if (arg1[strspn(arg1, "0123456789")] == '\0')
1202
		if (arg1[strspn(arg1, "0123456789")] == '\0')
1203
			id = pw_checkid(arg1, UID_MAX);
1203
			id = pw_checkid(arg1, UID_MAX);
1204
		else
1204
		else
1205
			name = arg1;
1205
			name = pw_checkname(arg1, 0);
1206
	}
1206
	}
1207
1207
1208
	while ((ch = getopt(argc, argv, args)) != -1) {
1208
	while ((ch = getopt(argc, argv, args)) != -1) {
Lines 1214-1220 pw_user_add(int argc, char **argv, char *arg1) Link Here
1214
			quiet = true;
1214
			quiet = true;
1215
			break;
1215
			break;
1216
		case 'n':
1216
		case 'n':
1217
			name = optarg;
1217
			name = pw_checkname(optarg, 0);
1218
			break;
1218
			break;
1219
		case 'u':
1219
		case 'u':
1220
			userid = optarg;
1220
			userid = optarg;
1221
- 
1222
with spaces are rejected
1221
with spaces are rejected
1223
--
1224
usr.sbin/pw/tests/pw_useradd_test.sh | 13 +++++++++++++
1222
usr.sbin/pw/tests/pw_useradd_test.sh | 13 +++++++++++++
1225
1 file changed, 13 insertions(+)
1223
1 file changed, 13 insertions(+)
(-)b/usr.sbin/pw/tests/pw_useradd_test.sh (-2 / +13 lines)
Lines 176-181 user_add_name_too_long_body() { Link Here
176
		${PW} useradd name_very_vert_very_very_very_long
176
		${PW} useradd name_very_vert_very_very_very_long
177
}
177
}
178
178
179
atf_test_case user_add_name_with_spaces
180
user_add_name_with_spaces_body() {
181
	populate_etc_skel
182
	atf_check -s exit:65 -e match:"invalid character" \
183
		  ${PW} useradd 'test user'
184
	atf_check -s exit:1 -o empty grep "^test user:.*" $HOME/master.passwd
185
	# Try again with the -n option which uses a slightly different code path.
186
	atf_check -s exit:65 -e match:"invalid character" \
187
		  ${PW} useradd -n 'test user'
188
	atf_check -s exit:1 -o empty grep "^test user:.*" $HOME/master.passwd
189
}
190
179
atf_test_case user_add_expiration
191
atf_test_case user_add_expiration
180
user_add_expiration_body() {
192
user_add_expiration_body() {
181
	populate_etc_skel
193
	populate_etc_skel
Lines 415-420 atf_init_test_cases() { Link Here
415
	atf_add_test_case user_add_password_expiration_date_month
427
	atf_add_test_case user_add_password_expiration_date_month
416
	atf_add_test_case user_add_password_expiration_date_relative
428
	atf_add_test_case user_add_password_expiration_date_relative
417
	atf_add_test_case user_add_name_too_long
429
	atf_add_test_case user_add_name_too_long
430
	atf_add_test_case user_add_name_with_spaces
418
	atf_add_test_case user_add_expiration
431
	atf_add_test_case user_add_expiration
419
	atf_add_test_case user_add_invalid_user_entry
432
	atf_add_test_case user_add_invalid_user_entry
420
	atf_add_test_case user_add_invalid_group_entry
433
	atf_add_test_case user_add_invalid_group_entry
421
- 
422
names are caught
434
names are caught
423
--
424
usr.sbin/pw/tests/pw_useradd_test.sh | 26 ++++++++++++++++++++++++++
435
usr.sbin/pw/tests/pw_useradd_test.sh | 26 ++++++++++++++++++++++++++
425
1 file changed, 26 insertions(+)
436
1 file changed, 26 insertions(+)
(-)b/usr.sbin/pw/tests/pw_useradd_test.sh (-1 / +26 lines)
Lines 188-193 user_add_name_with_spaces_body() { Link Here
188
	atf_check -s exit:1 -o empty grep "^test user:.*" $HOME/master.passwd
188
	atf_check -s exit:1 -o empty grep "^test user:.*" $HOME/master.passwd
189
}
189
}
190
190
191
atf_test_case user_add_name_with_spaces_and_gid_specified
192
user_add_name_with_spaces_and_gid_specified_body() {
193
	populate_etc_skel
194
	gid=12345
195
	user_name="test user"
196
	# pw useradd should fail because of the space in the user
197
	# name, not because the group doesn't exist.
198
	atf_check -s exit:65 -e match:"invalid character" \
199
		  ${PW} useradd "${user_name}" -g ${gid}
200
	atf_check -s exit:1 -o empty grep "^${user_name}:.*" $HOME/master.passwd
201
	# Try again with the -n option which uses a slightly different code path.
202
	atf_check -s exit:65 -e match:"invalid character" \
203
		  ${PW} useradd -n "${user_name}" -g ${gid}
204
	atf_check -s exit:1 -o empty grep "^${user_name}:.*" $HOME/master.passwd
205
	# Make sure the user isn't added even if the group exists
206
	atf_check -s exit:0 ${PW} groupadd blafasel -g ${gid}
207
	atf_check -s exit:65 -e match:"invalid character" \
208
		  ${PW} useradd "${user_name}" -g ${gid}
209
	atf_check -s exit:1 -o empty grep "^${user_name}:.*" $HOME/master.passwd
210
	# Try again with the -n option.
211
	atf_check -s exit:65 -e match:"invalid character" \
212
		  ${PW} useradd -n "${user_name}" -g ${gid}
213
	atf_check -s exit:1 -o empty grep "^${user_name}:.*" $HOME/master.passwd
214
}
215
191
atf_test_case user_add_expiration
216
atf_test_case user_add_expiration
192
user_add_expiration_body() {
217
user_add_expiration_body() {
193
	populate_etc_skel
218
	populate_etc_skel
Lines 428-433 atf_init_test_cases() { Link Here
428
	atf_add_test_case user_add_password_expiration_date_relative
453
	atf_add_test_case user_add_password_expiration_date_relative
429
	atf_add_test_case user_add_name_too_long
454
	atf_add_test_case user_add_name_too_long
430
	atf_add_test_case user_add_name_with_spaces
455
	atf_add_test_case user_add_name_with_spaces
456
	atf_add_test_case user_add_name_with_spaces_and_gid_specified
431
	atf_add_test_case user_add_expiration
457
	atf_add_test_case user_add_expiration
432
	atf_add_test_case user_add_invalid_user_entry
458
	atf_add_test_case user_add_invalid_user_entry
433
	atf_add_test_case user_add_invalid_group_entry
459
	atf_add_test_case user_add_invalid_group_entry
434
- 

Return to bug 221416