summaryrefslogtreecommitdiffstats
path: root/usr.sbin/bsdconfig/usermgmt/share/user.subr
blob: 5fd65fbe088b56898743600a9386aecd6354852c (plain)
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
if [ ! "$_USERMGMT_USER_SUBR" ]; then _USERMGMT_USER_SUBR=1
#
# Copyright (c) 2012 Ron McDowell
# Copyright (c) 2012-2014 Devin Teske
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
# $FreeBSD$
#
############################################################ INCLUDES

BSDCFG_SHARE="/usr/share/bsdconfig"
. $BSDCFG_SHARE/common.subr || exit 1
f_dprintf "%s: loading includes..." usermgmt/user.subr
f_include $BSDCFG_SHARE/dialog.subr
f_include $BSDCFG_SHARE/strings.subr
f_include $BSDCFG_SHARE/usermgmt/group_input.subr
f_include $BSDCFG_SHARE/usermgmt/user_input.subr

BSDCFG_LIBE="/usr/libexec/bsdconfig" APP_DIR="070.usermgmt"
f_include_lang $BSDCFG_LIBE/$APP_DIR/include/messages.subr

############################################################ CONFIGURATION

# set some reasonable defaults if /etc/adduser.conf does not exist.
[ -f /etc/adduser.conf ] && f_include /etc/adduser.conf
: ${defaultclass:=""}
: ${defaultshell:="/bin/sh"}
: ${homeprefix:="/home"}
: ${passwdtype:="yes"}
: ${udotdir:="/usr/share/skel"}
: ${uexpire:=""}
	# Default account expire time. Format is similar to upwexpire variable.
: ${ugecos:="User &"}
: ${upwexpire:=""}
	# The default password expiration time. Format of the date is either a
	# UNIX time in decimal, or a date in dd-mmm-yy[yy] format, where dd is
	# the day, mmm is the month in either numeric or alphabetic format, and
	# yy[yy] is either a two or four digit year. This variable also accepts
	# a relative date in the form of n[mhdwoy] where n is a decimal, octal
	# (leading 0) or hexadecimal (leading 0x) digit followed by the number
	# of Minutes, Hours, Days, Weeks, Months or Years from the current date
	# at which the expiration time is to be set.

#
# uexpire and upwexpire from adduser.conf(5) differ only slightly from what
# pw(8) accepts as `date' argument(s); pw(8) requires a leading `+' for the
# relative date syntax (n[mhdwoy]).
#
case "$uexpire" in *[mhdwoy])
	f_isinteger "${uexpire%[mhdwoy]}" && uexpire="+$uexpire"
esac
case "$upwexpire" in *[mhdwoy])
	f_isinteger "${upwexpire%[mhdwoy]}" && upwexpire="+$upwexpire"
esac

############################################################ FUNCTIONS

# f_user_create_homedir $user
#
# Create home directory for $user.
#
f_user_create_homedir()
{
	local funcname=f_user_create_homedir
	local user="$1"

	[ "$user" ] || return $FAILURE

	local user_account_expire user_class user_gecos user_gid user_home_dir
	local user_member_groups user_name user_password user_password_expire
	local user_shell user_uid # Variables created by f_input_user() below
	f_input_user "$user" || return $FAILURE

	f_dprintf "Creating home directory \`%s' for user \`%s'" \
	          "$user_home_dir" "$user"

	local _user_gid _user_home_dir _user_uid
	f_shell_escape "$user_gid"      _user_gid
	f_shell_escape "$user_home_dir" _user_home_dir
	f_shell_escape "$user_uid"      _user_uid
	f_eval_catch $funcname mkdir "mkdir -p '%s'" "$_user_home_dir" ||
		return $FAILURE
	f_eval_catch $funcname chown "chown '%i:%i' '%s'" \
		"$_user_uid" "$_user_gid" "$_user_home_dir" || return $FAILURE
}

# f_user_copy_dotfiles $user
#
# Copy `skel' dot-files from $udotdir (global inherited from /etc/adduser.conf)
# to the home-directory of $user. Attempts to create the home-directory first
# if it doesn't exist.
#
f_user_copy_dotfiles()
{
	local funcname=f_user_copy_dotfiles
	local user="$1"

	[ "$udotdir" ] || return $FAILURE
	[ "$user"    ] || return $FAILURE

	local user_account_expire user_class user_gecos user_gid user_home_dir
	local user_member_groups user_name user_password user_password_expire
	local user_shell user_uid # Variables created by f_input_user() below
	f_input_user "$user" || return $FAILURE

	f_dprintf "Copying dot-files from \`%s' to \`%s'" \
	          "$udotdir" "$user_home_dir"

	# Attempt to create the home directory if it doesn't exist
	[ -d "$user_home_dir" ] ||
		f_user_create_homedir "$user" || return $FAILURE

	local _user_gid _user_home_dir _user_uid
	f_shell_escape "$user_gid"      _user_gid
	f_shell_escape "$user_home_dir" _user_home_dir
	f_shell_escape "$user_uid"      _user_uid

	local - # Localize `set' to this function
	set +f # Enable glob pattern-matching for paths
	cd "$udotdir" || return $FAILURE

	local _file file retval
	for file in dot.*; do
		[ -e "$file" ] || continue # no-match

		f_shell_escape "$file" "_file"
		f_eval_catch $funcname cp "cp -n '%s' '%s'" \
			"$_file" "$_user_home_dir/${_file#dot}"
		retval=$?
		[ $retval -eq $SUCCESS ] || break
		f_eval_catch $funcname chown \
			"chown -h '%i:%i' '%s'" \
			"$_user_uid" "$_user_gid" \
			"$_user_home_dir/${_file#dot}"
		retval=$?
		[ $retval -eq $SUCCESS ] || break
	done

	cd -
	return $retval
}

# f_user_add [$user]
#
# Create a login account. If both $user (as a first argument) and $VAR_USER are
# unset or NULL and we are running interactively, prompt the end-user to enter
# the name of a new login account and (if $VAR_NO_CONFIRM is unset or NULL)
# prompt the end-user to answer some questions about the new account. Variables
# that can be used to script user input:
#
# 	VAR_USER [Optional if running interactively]
# 		The login to add. Ignored if given non-NULL first-argument.
# 	VAR_USER_ACCOUNT_EXPIRE [Optional]
# 		The account expiration time. Format is similar to
# 		VAR_USER_PASSWORD_EXPIRE variable below. Default is to never
# 		expire the account.
# 	VAR_USER_DOTFILES_CREATE [Optional]
# 		If non-NULL, populate the user's home directory with the
# 		template files found in $udotdir (`/usr/share/skel' default).
# 	VAR_USER_GECOS [Optional]
# 		Often the full name of the account holder. Default is NULL.
# 	VAR_USER_GID [Optional]
# 		Numerical primary-group ID to use. If NULL or unset, the group
# 		ID is automatically chosen.
# 	VAR_USER_GROUPS [Optional]
# 		Comma-separated list of additional groups to which the user is
# 		a member of. Default is NULL (no additional groups).
# 	VAR_USER_HOME [Optional]
# 		The home directory to set. If NULL or unset, the home directory
# 		is automatically calculated.
# 	VAR_USER_HOME_CREATE [Optional]
# 		If non-NULL, create the user's home directory if it doesn't
# 		already exist.
# 	VAR_USER_LOGIN_CLASS [Optional]
# 		Login class to use when creating the login. Default is NULL.
# 	VAR_USER_PASSWORD [Optional]
# 		Unencrypted password to use. If unset or NULL, password
# 		authentication for the login is disabled.
# 	VAR_USER_PASSWORD_EXPIRE [Optional]
# 		The password expiration time. Format of the date is either a
# 		UNIX time in decimal, or a date in dd-mmm-yy[yy] format, where
# 		dd is the day, mmm is the month in either numeric or alphabetic
# 		format, and yy[yy] is either a two or four digit year. This
# 		variable also accepts a relative date in the form of +n[mhdwoy]
# 		where n is a decimal, octal (leading 0) or hexadecimal (leading
# 		0x) digit followed by the number of Minutes, Hours, Days,
# 		Weeks, Months or Years from the current date at which the
# 		expiration time is to be set. Default is to never expire the
# 		account password.
# 	VAR_USER_SHELL [Optional]
# 		Path to login shell to use. Default is `/bin/sh'.
# 	VAR_USER_UID [Optional]
# 		Numerical user ID to use. If NULL or unset, the user ID is
# 		automatically chosen.
#
# Returns success if the user account was successfully created.
#
f_user_add()
{
	local funcname=f_user_add
	local title # Calculated below
	local alert=f_show_msg no_confirm=

	f_getvar $VAR_NO_CONFIRM no_confirm
	[ "$no_confirm" ] && alert=f_show_info

	local input
	f_getvar 3:-\$$VAR_USER input "$1"

	#
	# NB: pw(8) has a ``feature'' wherein `-n name' can be taken as UID
	# instead of name. Work-around is to also pass `-u UID' at the same
	# time (any UID will do; but `-1' is appropriate for this context).
	#
	if [ "$input" ] && f_quietly pw usershow -n "$input" -u -1; then
		f_show_err "$msg_login_already_used" "$input"
		return $FAILURE
	fi

	local user_name="$input"
	while f_interactive && [ ! "$user_name" ]; do
		f_dialog_input_name user_name "$user_name" ||
			return $SUCCESS
		[ "$user_name" ] ||
			f_show_err "$msg_please_enter_a_user_name"
	done
	if [ ! "$user_name" ]; then
		f_show_err "$msg_no_user_specified"
		return $FAILURE
	fi

	local user_account_expire user_class user_gecos user_gid user_home_dir
	local user_member_groups user_password user_password_expire user_shell
	local user_uid user_dotfiles_create= user_home_create=
	f_getvar $VAR_USER_ACCOUNT_EXPIRE-\$uexpire    user_account_expire
	f_getvar $VAR_USER_DOTFILES_CREATE:+\$msg_yes  user_dotfiles_create
	f_getvar $VAR_USER_GECOS-\$ugecos              user_gecos
	f_getvar $VAR_USER_GID                         user_gid
	f_getvar $VAR_USER_GROUPS                      user_member_groups
	f_getvar $VAR_USER_HOME:-\${homeprefix%/}/\$user_name \
	                                               user_home_dir
	f_getvar $VAR_USER_HOME_CREATE:+\$msg_yes      user_home_create
	f_getvar $VAR_USER_LOGIN_CLASS-\$defaultclass  user_class
	f_getvar $VAR_USER_PASSWORD                    user_password
	f_getvar $VAR_USER_PASSWORD_EXPIRE-\$upwexpire user_password_expire
	f_getvar $VAR_USER_SHELL-\$defaultshell        user_shell
	f_getvar $VAR_USER_UID                         user_uid

	# Create home-dir if no script-override and does not exist
	f_isset $VAR_USER_HOME_CREATE || [ -d "$user_home_dir" ] ||
		user_home_create="$msg_yes"
	# Copy dotfiles if home-dir creation is desired, does not yet exist,
	# and no script-override has been set
	f_isset $VAR_USER_DOTFILES_CREATE ||
		[ "$user_home_create" != "$msg_yes" ] ||
		[ -d "$user_home_dir" ] || user_dotfiles_create="$msg_yes"
	# Create home-dir if copying dotfiles but home-dir does not exist
	[ "$user_dotfiles_create" -a ! -d "$user_home_dir" ] &&
		user_home_create="$msg_yes"

	# Set flags for meaningful NULL values if-provided
	local no_account_expire= no_password_expire= null_gecos= null_members=
	local user_password_disable=
	f_isset $VAR_USER_ACCOUNT_EXPIRE &&
		[ ! "$user_account_expire"  ] && no_account_expire=1
	f_isset $VAR_USER_GECOS &&
		[ ! "$user_gecos"           ] && null_gecos=1
	f_isset $VAR_USER_GROUPS &&
		[ ! "$user_member_groups"   ] && null_members=1
	f_isset $VAR_USER_PASSWORD &&
		[ ! "$user_password"        ] && user_password_disable=1
	f_isset $VAR_USER_PASSWORD_EXPIRE &&
		[ ! "$user_password_expire" ] && no_password_expire=1

	if f_interactive && [ ! "$no_confirm" ]; then
		f_dialog_noyes \
			"$msg_use_default_values_for_all_account_details"
		retval=$?
		if [ $retval -eq $DIALOG_ESC ]; then
			return $SUCCESS
		elif [ $retval -ne $DIALOG_OK ]; then
			#
			# Ask series of questions to pre-fill the editor screen
			#
			# Defaults used in each dialog should allow the user to
			# simply hit ENTER to proceed, because cancelling any
			# single dialog will cause them to be returned to the
			# previous menu.
			#

			f_dialog_input_gecos user_gecos "$user_gecos" ||
				return $FAILURE
			if [ "$passwdtype" = "yes" ]; then
				f_dialog_input_password user_password \
					user_password_disable ||
					return $FAILURE
			fi
			f_dialog_input_uid user_uid "$user_uid" ||
				return $FAILURE
			f_dialog_input_gid user_gid "$user_gid" ||
				return $FAILURE
			f_dialog_input_member_groups user_member_groups \
				"$user_member_groups" || return $FAILURE
			f_dialog_input_class user_class "$user_class" ||
				return $FAILURE
			f_dialog_input_expire_password user_password_expire \
				"$user_password_expire" || return $FAILURE
			f_dialog_input_expire_account user_account_expire \
				"$user_account_expire" || return $FAILURE
			f_dialog_input_home_dir user_home_dir \
				"$user_home_dir" || return $FAILURE
			if [ ! -d "$user_home_dir" ]; then
				f_dialog_input_home_create user_home_create ||
					return $FAILURE
				if [ "$user_home_create" = "$msg_yes" ]; then
					f_dialog_input_dotfiles_create \
						user_dotfiles_create ||
						return $FAILURE
				fi
			fi
			f_dialog_input_shell user_shell "$user_shell" ||
				return $FAILURE
		fi
	fi

	#
	# Loop until the user decides to Exit, Cancel, or presses ESC
	#
	title="$msg_add $msg_user: $user_name"
	if f_interactive; then
		local mtag retval defaultitem=
		while :; do
			f_dialog_title "$title"
			f_dialog_menu_user_add "$defaultitem"
			retval=$?
			f_dialog_title_restore
			f_dialog_menutag_fetch mtag
			f_dprintf "retval=%u mtag=[%s]" $retval "$mtag"
			defaultitem="$mtag"

			# Return if user either pressed ESC or chose Cancel/No
			[ $retval -eq $DIALOG_OK ] || return $FAILURE

			case "$mtag" in
			X) # Add/Exit
			   local var
			   for var in account_expire class gecos gid home_dir \
			   	member_groups name password_expire shell uid \
			   ; do
			   	local _user_$var
			   	eval f_shell_escape \"\$user_$var\" _user_$var
			   done

			   local cmd="pw useradd -n '$_user_name'"
			   [ "$user_gid"   ] && cmd="$cmd -g '$_user_gid'"
			   [ "$user_shell" ] && cmd="$cmd -s '$_user_shell'"
			   [ "$user_uid"   ] && cmd="$cmd -u '$_user_uid'"
			   [ "$user_account_expire" -o \
			     "$no_account_expire" ] &&
			   	cmd="$cmd -e '$_user_account_expire'"
			   [ "$user_class" -o "$null_class" ] &&
			   	cmd="$cmd -L '$_user_class'"
			   [ "$user_gecos" -o "$null_gecos" ] &&
			   	cmd="$cmd -c '$_user_gecos'"
			   [ "$user_home_dir" ] &&
			   	cmd="$cmd -d '$_user_home_dir'"
			   [ "$user_member_groups" ] &&
			   	cmd="$cmd -G '$_user_member_groups'"
			   [ "$user_password_expire" -o \
			     "$no_password_expire" ] &&
			   	cmd="$cmd -p '$_user_password_expire'"

			   # Execute the command
			   if [ "$user_password_disable" ]; then
			   	f_eval_catch $funcname pw '%s -h -' "$cmd"
			   elif [ "$user_password" ]; then
			   	echo "$user_password" | f_eval_catch \
			   		$funcname pw '%s -h 0' "$cmd"
			   else
			   	f_eval_catch $funcname pw '%s' "$cmd"
			   fi || continue

			   # Create home directory if desired
			   [ "${user_home_create:-$msg_no}" != "$msg_no" ] &&
			   	f_user_create_homedir "$user_name"

			   # Copy dotfiles if desired
			   [ "${user_dotfiles_create:-$msg_no}" != \
			     "$msg_no" ] && f_user_copy_dotfiles "$user_name"

			   break # to success
			   ;;
			1) # Login (prompt for new login name)
			   f_dialog_input_name input "$user_name" ||
			   	continue
			   if f_quietly pw usershow -n "$input" -u -1; then
			   	f_show_err "$msg_login_already_used" "$input"
			   	continue
			   fi
			   user_name="$input"
			   title="$msg_add $msg_user: $user_name"
			   user_home_dir="${homeprefix%/}/$user_name"
			   ;;
			2) # Full Name
			   f_dialog_input_gecos user_gecos "$user_gecos" &&
			   	[ ! "$user_gecos" ] && null_gecos=1 ;;
			3) # Password
			   f_dialog_input_password \
			   	user_password user_password_disable ;;
			4) # User ID
			   f_dialog_input_uid user_uid "$user_uid" ;;
			5) # Group ID
			   f_dialog_input_gid user_gid "$user_gid" ;;
			6) # Member of Groups
			   f_dialog_input_member_groups \
			   	user_member_groups "$user_member_groups" &&
			   	[ ! "$user_member_groups" ] &&
			   	null_members=1 ;;
			7) # Login Class
			   f_dialog_input_class user_class "$user_class" &&
			   	[ ! "$user_class" ] && null_class=1 ;;
			8) # Password Expires On
			   f_dialog_input_expire_password \
			   	user_password_expire "$user_password_expire" &&
			   	[ ! "$user_password_expire" ] &&
			   	no_password_expire=1 ;;
			9) # Account Expires On
			   f_dialog_input_expire_account \
			   	user_account_expire "$user_account_expire" &&
			   	[ ! "$user_account_expire" ] &&
			   	no_account_expire=1 ;;
			A) # Home Directory
			   f_dialog_input_home_dir \
			   	user_home_dir "$user_home_dir" ;;
			B) # Shell
			   f_dialog_input_shell user_shell "$user_shell" ;;
			C) # Create Home Directory?
			   if [ "${user_home_create:-$msg_no}" != "$msg_no" ]
			   then
			   	user_home_create="$msg_no"
			   else
			   	user_home_create="$msg_yes"
			   fi ;;
			D) # Create Dotfiles?
			   if [ "${user_dotfiles_create:-$msg_no}" != \
			        "$msg_no" ]
			   then
			   	user_dotfiles_create="$msg_no"
			   else
			   	user_dotfiles_create="$msg_yes"
			   fi ;;
			esac
		done
	else
		local var
		for var in account_expire class gecos gid home_dir \
			member_groups name password_expire shell uid \
		; do
			local _user_$var
			eval f_shell_escape \"\$user_$var\" _user_$var
		done

		# Form the command
		local cmd="pw useradd -n '$_user_name'"
		[ "$user_gid"      ] && cmd="$cmd -g '$_user_gid'"
		[ "$user_home_dir" ] && cmd="$cmd -d '$_user_home_dir'"
		[ "$user_shell"    ] && cmd="$cmd -s '$_user_shell'"
		[ "$user_uid"      ] && cmd="$cmd -u '$_user_uid'"
		[ "$user_account_expire" -o "$no_account_expire" ] &&
			cmd="$cmd -e '$_user_account_expire'"
		[ "$user_class" -o "$null_class" ] &&
			cmd="$cmd -L '$_user_class'"
		[ "$user_gecos" -o "$null_gecos" ] &&
			cmd="$cmd -c '$_user_gecos'"
		[ "$user_member_groups" -o "$null_members" ] &&
			cmd="$cmd -G '$_user_member_groups'"
		[ "$user_password_expire" -o "$no_password_expire" ] &&
			cmd="$cmd -p '$_user_password_expire'"

		# Execute the command
		local retval err
		if [ "$user_password_disable" ]; then
			f_eval_catch -k err $funcname pw '%s -h -' "$cmd"
		elif [ "$user_password" ]; then
			err=$( echo "$user_password" | f_eval_catch -de \
				$funcname pw '%s -h 0' "$cmd" 2>&1 )
		else
			f_eval_catch -k err $funcname pw '%s' "$cmd"
		fi
		retval=$?
		if [ $retval -ne $SUCCESS ]; then
			f_show_err "%s" "$err"
			return $retval
		fi

		# Create home directory if desired
		[ "${user_home_create:-$msg_no}" != "$msg_no" ] &&
			f_user_create_homedir "$user_name"

		# Copy dotfiles if desired
		[ "${user_dotfiles_create:-$msg_no}" != "$msg_no" ] &&
			f_user_copy_dotfiles "$user_name"
	fi

	f_dialog_title "$title"
	$alert "$msg_login_added"
	f_dialog_title_restore
	[ "$no_confirm" -a "$USE_DIALOG" ] && sleep 1

	return $SUCCESS
}

# f_user_delete [$user]
#
# Delete a user. If both $user (as a first argument) and $VAR_USER are unset or
# NULL and we are running interactively, prompt the end-user to select a user
# account from a list of those available. Variables that can be used to script
# user input:
#
# 	VAR_USER [Optional if running interactively]
# 		The user to delete. Ignored if given non-NULL first-argument.
#
# Returns success if the user account was successfully deleted.
#
f_user_delete()
{
	local funcname=f_user_delete
	local title # Calculated below
	local alert=f_show_msg no_confirm=

	f_getvar $VAR_NO_CONFIRM no_confirm
	[ "$no_confirm" ] && alert=f_show_info

	local input
	f_getvar 3:-\$$VAR_USER input "$1"

	if f_interactive && [ ! "$input" ]; then
		f_dialog_menu_user_list || return $SUCCESS
		f_dialog_menutag_fetch input
		[ "$input" = "X $msg_exit" ] && return $SUCCESS
	elif [ ! "$input" ]; then
		f_show_err "$msg_no_user_specified"
		return $FAILURE
	fi

	local user_account_expire user_class user_gecos user_gid user_home_dir
	local user_member_groups user_name user_password user_password_expire
	local user_shell user_uid # Variables created by f_input_user() below
	if [ "$input" ] && ! f_input_user "$input"; then
		f_show_err "$msg_login_not_found" "$input"
		return $FAILURE
	fi

	local user_group_delete= user_home_delete=
	f_getvar $VAR_USER_GROUP_DELETE:-\$msg_no user_group_delete
	f_getvar $VAR_USER_HOME_DELETE:-\$msg_no  user_home_delete

	# Attempt to translate user GID into a group name
	local user_group
	if user_group=$( pw groupshow -g "$user_gid" 2> /dev/null ); then
		user_group="${user_group%%:*}"
		# Default to delete the primary group if no script-override and
		# exists with same name as the user (same logic used by pw(8))
		f_isset $VAR_USER_GROUP_DELETE ||
			[ "$user_group" != "$user_name" ] ||
			user_group_delete="$msg_yes"
	fi

	#
	# Loop until the user decides to Exit, Cancel, or presses ESC
	#
	title="$msg_delete $msg_user: $user_name"
	if f_interactive; then
		local mtag retval defaultitem=
		while :; do
			f_dialog_title "$title"
			f_dialog_menu_user_delete "$user_name" "$defaultitem"
			retval=$?
			f_dialog_title_restore
			f_dialog_menutag_fetch mtag
			f_dprintf "retval=%u mtag=[%s]" $retval "$mtag"
			defaultitem="$mtag"

			# Return if user either pressed ESC or chose Cancel/No
			[ $retval -eq $DIALOG_OK ] || return $FAILURE

			case "$mtag" in
			X) # Delete/Exit
			   f_shell_escape "$user_uid" _user_uid

			   # Save group information in case pw(8) deletes it
			   # and we wanted to keep it (to be restored below)
			   if [ "${user_group_delete:-$msg_no}" = "$msg_no" ]
			   then
			   	local v vars="gid members name password"
			   	for v in $vars; do local group_$var; done
			   	f_input_group "$user_group"

			   	# Remove user-to-delete from group members
			   	# NB: Otherwise group restoration could fail
			   	local name length=0 _members=
			  	while [ $length -ne ${#group_members} ]; do
			   		name="${group_members%%,*}"
			   		[ "$name" != "$user_name" ] &&
			   			_members="$_members,$name"
			   		length=${#group_members}
			   		group_members="${group_members#*,}"
			   	done
			   	group_members="${_members#,}"

			   	# Create escaped variables for f_eval_catch()
			   	for v in $vars; do
			   		local _group_$v
			   		eval f_shell_escape \
			   			\"\$group_$v\" _group_$v
			   	done
			   fi

			   # Delete the user (if asked to delete home directory
			   # display [X]dialog notification to show activity)
			   local cmd="pw userdel -u '$_user_uid'"
			   if [ "$user_home_delete" = "$msg_yes" -a \
			        "$USE_XDIALOG" ]
			   then
			   	local err
			   	err=$(
			   		exec 9>&1
			   		f_eval_catch -e $funcname pw \
			   		  "%s -r" "$cmd" \
			   		  >&$DIALOG_TERMINAL_PASSTHRU_FD 2>&9 |
			   		  f_xdialog_info \
			   		  	"$msg_deleting_home_directory"
			   	)
			   	[ ! "$err" ]
			   elif [ "$user_home_delete" = "$msg_yes" ]; then
			   	f_dialog_info "$msg_deleting_home_directory"
			   	f_eval_catch $funcname pw '%s -r' "$cmd"
			   else
			   	f_eval_catch $funcname pw '%s' "$cmd"
			   fi || continue

			   #
			   # pw(8) may conditionally delete the primary group,
			   # which may not be what is desired.
			   #
			   # If we've been asked to delete the group and pw(8)
			   # chose not to, delete it. Otherwise, if we're told
			   # to NOT delete the group, we may need to restore it
			   # since pw(8) doesn't have a flag to tell `userdel'
			   # to not delete the group.
			   # 
			   # NB: If primary group and user have different names
			   # the group may not have been deleted (again, see PR
			   # 169471 and SVN r263114 for details).
			   #
			   if [ "${user_group_delete:-$msg_no}" != "$msg_no" ]
			   then
			   	f_quietly pw groupshow -g "$user_gid" &&
			   	f_eval_catch $funcname pw \
			   		"pw groupdel -g '%s'" "$_user_gid"
			   elif ! f_quietly pw groupshow -g "$group_gid" &&
			        [ "$group_name" -a "$group_gid" ]
			   then
			   	# Group deleted by pw(8), so restore it
			   	local cmd="pw groupadd -n '$_group_name'"
			   	cmd="$cmd -g '$_group_gid'"
			   	cmd="$cmd -M '$_group_members'"

			   	# Get the group password (pw(8) groupshow does
			  	# NOT provide this (even if running privileged)
			   	local group_password_enc
			   	group_password_enc=$( getent group | awk -F: '
			   		!/^[[:space:]]*(#|$)/ && \
			   		    $1 == ENVIRON["group_name"] && \
			   		    $3 == ENVIRON["group_gid"] && \
			   		    $4 == ENVIRON["group_members"] \
			   		{ print $2; exit }
			   	' )
			   	if [ "$group_password_enc" ]; then
			   		echo "$group_password_enc" |
			   			f_eval_catch $funcname \
			   				pw '%s -H 0' "$cmd"
			   	else
			   		f_eval_catch $funcname \
			   			pw '%s -h -' "$cmd"
			   	fi
			   fi

			   break # to success
			   ;;
			1) # Login (select different login from list)
			   f_dialog_menu_user_list "$user_name" || continue
			   f_dialog_menutag_fetch mtag

			   [ "$mtag" = "X $msg_exit" ] && continue

			   if ! f_input_user "$mtag"; then
			   	f_show_err "$msg_login_not_found" "$mtag"
			   	# Attempt to fall back to previous selection
			   	f_input_user "$input" || return $FAILURE
			   else
			   	input="$mtag"
			   fi
			   title="$msg_delete $msg_user: $user_name"
			   ;;
			C) # Delete Primary Group?
			   if [ "${user_group_delete:-$msg_no}" != "$msg_no" ]
			   then
			   	user_group_delete="$msg_no"
			   else
			   	user_group_delete="$msg_yes"
			   fi ;;
			D) # Delete Home Directory?
			   if [ "${user_home_delete:-$msg_no}" != "$msg_no" ]
			   then
			   	user_home_delete="$msg_no"
			   else
			   	user_home_delete="$msg_yes"
			   fi ;;
			esac
		done
	else
		f_shell_escape "$user_uid" _user_uid

		# Save group information in case pw(8) deletes it
		# and we wanted to keep it (to be restored below)
		if [ "${user_group_delete:-$msg_no}" = "$msg_no" ]; then
			local v vars="gid members name password"
			for v in $vars; do local group_$v; done
			f_input_group "$user_group"

			# Remove user we're about to delete from group members
			# NB: Otherwise group restoration could fail
			local name length=0 _members=
			while [ $length -ne ${#group_members} ]; do
				name="${group_members%%,*}"
				[ "$name" != "$user_name" ] &&
					_members="$_members,$name"
				length=${#group_members}
				group_members="${group_members#*,}"
			done
			group_members="${_members#,}"

			# Create escaped variables for later f_eval_catch()
			for v in $vars; do
				local _group_$v
				eval f_shell_escape \"\$group_$v\" _group_$v
			done
		fi

		# Delete the user (if asked to delete home directory
		# display [X]dialog notification to show activity)
		local err cmd="pw userdel -u '$_user_uid'"
		if [ "$user_home_delete" = "$msg_yes" -a "$USE_XDIALOG" ]; then
			err=$(
				exec 9>&1
				f_eval_catch -de $funcname pw \
					'%s -r' "$cmd" 2>&9 | f_xdialog_info \
					"$msg_deleting_home_directory"
			)
			[ ! "$err" ]
		elif [ "$user_home_delete" = "$msg_yes" ]; then
			f_dialog_info "$msg_deleting_home_directory"
			f_eval_catch -k err $funcname pw '%s -r' "$cmd"
		else
			f_eval_catch -k err $funcname pw '%s' "$cmd"
		fi
		local retval=$?
		if [ $retval -ne $SUCCESS ]; then
			f_show_err "%s" "$err"
			return $retval
		fi

		#
		# pw(8) may conditionally delete the primary group, which may
		# not be what is desired.
		#
		# If we've been asked to delete the group and pw(8) chose not
		# to, delete it. Otherwise, if we're told to NOT delete the
		# group, we may need to restore it since pw(8) doesn't have a
		# flag to tell `userdel' to not delete the group.
		# 
		# NB: If primary group and user have different names the group
		# may not have been deleted (again, see PR 169471 and SVN
		# r263114 for details).
		#
		if [ "${user_group_delete:-$msg_no}" != "$msg_no" ]
		then
			f_quietly pw groupshow -g "$user_gid" &&
			f_eval_catch $funcname pw \
				"pw groupdel -g '%s'" "$_user_gid"
		elif ! f_quietly pw groupshow -g "$group_gid" &&
		     [ "$group_name" -a "$group_gid" ]
		then
			# Group deleted by pw(8), so restore it
			local cmd="pw groupadd -n '$_group_name'"
			cmd="$cmd -g '$_group_gid'"
			cmd="$cmd -M '$_group_members'"
			local group_password_enc
			group_password_enc=$( getent group | awk -F: '
				!/^[[:space:]]*(#|$)/ && \
				    $1 == ENVIRON["group_name"] && \
				    $3 == ENVIRON["group_gid"] && \
				    $4 == ENVIRON["group_members"] \
				{ print $2; exit }
			' )
			if [ "$group_password_enc" ]; then
				echo "$group_password_enc" |
					f_eval_catch $funcname \
						pw '%s -H 0' "$cmd"
			else
				f_eval_catch $funcname \
					pw '%s -h -' "$cmd"
			fi
		fi
	fi

	f_dialog_title "$title"
	$alert "$msg_login_deleted"
	f_dialog_title_restore
	[ "$no_confirm" -a "$USE_DIALOG" ] && sleep 1

	return $SUCCESS
}

# f_user_edit [$user]
#
# Modify a login account. If both $user (as a first argument) and $VAR_USER are
# unset or NULL and we are running interactively, prompt the end-user to select
# a login account from a list of those available. Variables that can be used to
# script user input:
#
# 	VAR_USER [Optional if running interactively]
# 		The login to modify. Ignored if given non-NULL first-argument.
# 	VAR_USER_ACCOUNT_EXPIRE [Optional]
# 		The account expiration time. Format is similar to
# 		VAR_USER_PASSWORD_EXPIRE variable below. If unset, account
# 		expiry is unchanged. If set but NULL, account expiration is
# 		disabled (same as setting a value of `0').
# 	VAR_USER_DOTFILES_CREATE [Optional]
# 		If non-NULL, re-populate the user's home directory with the
# 		template files found in $udotdir (`/usr/share/skel' default).
# 	VAR_USER_GECOS [Optional]
# 		Often the full name of the account holder. If unset, the GECOS
# 		field is unmodified. If set but NULL, the field is blanked.
# 	VAR_USER_GID [Optional]
# 		Numerical primary-group ID to set. If NULL or unset, the group
# 		ID is unchanged.
# 	VAR_USER_GROUPS [Optional]
# 		Comma-separated list of additional groups to which the user is
# 		a member of. If set but NULL, group memberships are reset (this
# 		login will not be a member of any additional groups besides the
# 		primary group). If unset, group membership is unmodified.
# 	VAR_USER_HOME [Optional]
# 		The home directory to set. If NULL or unset, the home directory
# 		is unchanged.
# 	VAR_USER_HOME_CREATE [Optional]
# 		If non-NULL, create the user's home directory if it doesn't
# 		already exist.
# 	VAR_USER_LOGIN_CLASS [Optional]
# 		Login class to set. If unset, the login class is unchanged. If
# 		set but NULL, the field is blanked.
# 	VAR_USER_PASSWORD [Optional]
# 		Unencrypted password to set. If unset, the login password is
# 		unmodified. If set but NULL, password authentication for the
# 		login is disabled.
# 	VAR_USER_PASSWORD_EXPIRE [Optional]
# 		The password expiration time. Format of the date is either a
# 		UNIX time in decimal, or a date in dd-mmm-yy[yy] format, where
# 		dd is the day, mmm is the month in either numeric or alphabetic
# 		format, and yy[yy] is either a two or four digit year. This
# 		variable also accepts a relative date in the form of +n[mhdwoy]
# 		where n is a decimal, octal (leading 0) or hexadecimal (leading
# 		0x) digit followed by the number of Minutes, Hours, Days,
# 		Weeks, Months or Years from the current date at which the
# 		expiration time is to be set. If unset, password expiry is
# 		unchanged. If set but NULL, password expiration is disabled
# 		(same as setting a value of `0').
# 	VAR_USER_SHELL [Optional]
# 		Path to login shell to set. If NULL or unset, the shell is
# 		unchanged.
# 	VAR_USER_UID [Optional]
# 		Numerical user ID to set. If NULL or unset, the user ID is
# 		unchanged.
#
# Returns success if the user account was successfully modified.
#
f_user_edit()
{
	local funcname=f_user_edit
	local title # Calculated below
	local alert=f_show_msg no_confirm=

	f_getvar $VAR_NO_CONFIRM no_confirm
	[ "$no_confirm" ] && alert=f_show_info

	local input
	f_getvar 3:-\$$VAR_USER input "$1"

	#
	# NB: pw(8) has a ``feature'' wherein `-n name' can be taken as UID
	# instead of name. Work-around is to also pass `-u UID' at the same
	# time (any UID will do; but `-1' is appropriate for this context).
	#
	if [ "$input" ] && ! f_quietly pw usershow -n "$input" -u -1; then
		f_show_err "$msg_login_not_found" "$input"
		return $FAILURE
	fi

	if f_interactive && [ ! "$input" ]; then
		f_dialog_menu_user_list || return $SUCCESS
		f_dialog_menutag_fetch input
		[ "$input" = "X $msg_exit" ] && return $SUCCESS
	elif [ ! "$input" ]; then
		f_show_err "$msg_no_user_specified"
		return $FAILURE
	fi

	local user_account_expire user_class user_gecos user_gid user_home_dir
	local user_member_groups user_name user_password user_password_expire
	local user_shell user_uid # Variables created by f_input_user() below
	if ! f_input_user "$input"; then
		f_show_err "$msg_login_not_found" "$input"
		return $FAILURE
	fi

	#
	# Override values probed by f_input_user() with desired values
	#
	f_isset $VAR_USER_GID   && f_getvar $VAR_USER_GID   user_gid
	f_isset $VAR_USER_HOME  && f_getvar $VAR_USER_HOME  user_home_dir
	f_isset $VAR_USER_SHELL && f_getvar $VAR_USER_SHELL user_shell
	f_isset $VAR_USER_UID   && f_getvar $VAR_USER_UID   user_uid
	local user_dotfiles_create= user_home_create=
	f_getvar $VAR_USER_DOTFILES_CREATE:+\$msg_yes user_dotfiles_create
	f_getvar $VAR_USER_HOME_CREATE:+\$msg_yes     user_home_create
	local no_account_expire=
	if f_isset $VAR_USER_ACCOUNT_EXPIRE; then
		f_getvar $VAR_USER_ACCOUNT_EXPIRE user_account_expire
		[ "$user_account_expire" ] || no_account_expire=1
	fi
	local null_gecos=
	if f_isset $VAR_USER_GECOS; then
		f_getvar $VAR_USER_GECOS user_gecos
		[ "$user_gecos" ] || null_gecos=1
	fi
	local null_members=
	if f_isset $VAR_USER_GROUPS; then
		f_getvar $VAR_USER_GROUPS user_member_groups
		[ "$user_member_groups" ] || null_members=1
	fi
	local null_class=
	if f_isset $VAR_USER_LOGIN_CLASS; then
		f_getvar $VAR_USER_LOGIN_CLASS user_class
		[ "$user_class" ] || null_class=1
	fi
	local user_password_disable=
	if f_isset $VAR_USER_PASSWORD; then
		f_getvar $VAR_USER_PASSWORD user_password
		[ "$user_password" ] || user_password_disable=1
	fi
	local no_password_expire=
	if f_isset $VAR_USER_PASSWORD_EXPIRE; then
		f_getvar $VAR_USER_PASSWORD_EXPIRE user_password_expire
		[ "$user_password_expire" ] || no_password_expire=1
	fi

	#
	# Loop until the user decides to Exit, Cancel, or presses ESC
	#
	title="$msg_edit_view $msg_user: $user_name"
	if f_interactive; then
		local mtag retval defaultitem=
		while :; do
			f_dialog_title "$title"
			f_dialog_menu_user_edit "$defaultitem"
			retval=$?
			f_dialog_title_restore
			f_dialog_menutag_fetch mtag
			f_dprintf "retval=%u mtag=[%s]" $retval "$mtag"
			defaultitem="$mtag"

			# Return if user either pressed ESC or chose Cancel/No
			[ $retval -eq $DIALOG_OK ] || return $FAILURE

			case "$mtag" in
			X) # Save/Exit
			   local var
			   for var in account_expire class gecos gid home_dir \
			   	member_groups name password_expire shell uid \
			   ; do
			   	local _user_$var
			   	eval f_shell_escape \"\$user_$var\" _user_$var
			   done

			   local cmd="pw usermod -n '$_user_name'"
			   [ "$user_gid"   ] && cmd="$cmd -g '$_user_gid'"
			   [ "$user_shell" ] && cmd="$cmd -s '$_user_shell'"
			   [ "$user_uid"   ] && cmd="$cmd -u '$_user_uid'"
			   [ "$user_account_expire" -o \
			     "$no_account_expire" ] &&
			   	cmd="$cmd -e '$_user_account_expire'"
			   [ "$user_class" -o "$null_class" ] &&
			   	cmd="$cmd -L '$_user_class'"
			   [ "$user_gecos" -o "$null_gecos" ] &&
			   	cmd="$cmd -c '$_user_gecos'"
			   [ "$user_home_dir"  ] &&
			   	cmd="$cmd -d '$_user_home_dir'"
			   [ "$user_member_groups" -o "$null_members" ] &&
			   	cmd="$cmd -G '$_user_member_groups'"
			   [ "$user_password_expire" -o \
			     "$no_password_expire" ] &&
			   	cmd="$cmd -p '$_user_password_expire'"

			   # Execute the command
			   if [ "$user_password_disable" ]; then
			   	f_eval_catch $funcname pw '%s -h -' "$cmd"
			   elif [ "$user_password" ]; then
			   	echo "$user_password" | f_eval_catch \
			   		$funcname pw '%s -h 0' "$cmd"
			   else
			   	f_eval_catch $funcname pw '%s' "$cmd"
			   fi || continue

			   # Create home directory if desired
			   [ "${user_home_create:-$msg_no}" != "$msg_no" ] &&
			   	f_user_create_homedir "$user_name"

			   # Copy dotfiles if desired
			   [ "${user_dotfiles_create:-$msg_no}" != \
			     "$msg_no" ] && f_user_copy_dotfiles "$user_name"

			   break # to success
			   ;;
			1) # Login (select different login from list)
			   f_dialog_menu_user_list "$user_name" || continue
			   f_dialog_menutag_fetch mtag

			   [ "$mtag" = "X $msg_exit" ] && continue

			   if ! f_input_user "$mtag"; then
			   	f_show_err "$msg_login_not_found" "$mtag"
			   	# Attempt to fall back to previous selection
			   	f_input_user "$input" || return $FAILURE
			   else
			   	input="$mtag"
			   fi
			   title="$msg_edit_view $msg_user: $user_name"
			   ;;
			2) # Full Name
			   f_dialog_input_gecos user_gecos "$user_gecos" &&
			   	[ ! "$user_gecos" ] && null_gecos=1 ;;
			3) # Password
			   f_dialog_input_password \
			   	user_password user_password_disable ;;
			4) # User ID
			   f_dialog_input_uid user_uid "$user_uid" ;;
			5) # Group ID
			   f_dialog_input_gid user_gid "$user_gid" ;;
			6) # Member of Groups
			   f_dialog_input_member_groups \
			   	user_member_groups "$user_member_groups" &&
			   	[ ! "$user_member_groups" ] &&
			   	null_members=1 ;;
			7) # Login Class
			   f_dialog_input_class user_class "$user_class" &&
			   	[ ! "$user_class" ] && null_class=1 ;;
			8) # Password Expires On
			   f_dialog_input_expire_password \
			   	user_password_expire "$user_password_expire" &&
			   	[ ! "$user_password_expire" ] &&
			   	no_password_expire=1 ;;
			9) # Account Expires On
			   f_dialog_input_expire_account \
			   	user_account_expire "$user_account_expire" &&
			   	[ ! "$user_account_expire" ] &&
			   	no_account_expire=1 ;;
			A) # Home Directory
			   f_dialog_input_home_dir \
			   	user_home_dir "$user_home_dir" ;;
			B) # Shell
			   f_dialog_input_shell user_shell "$user_shell" ;;
			C) # Create Home Directory?
			   if [ "${user_home_create:-$msg_no}" != "$msg_no" ]
			   then
			   	user_home_create="$msg_no"
			   else
			   	user_home_create="$msg_yes"
			   fi ;;
			D) # Create Dotfiles?
			   if [ "${user_dotfiles_create:-$msg_no}" != \
			        "$msg_no" ]
			   then
			   	user_dotfiles_create="$msg_no"
			   else
			   	user_dotfiles_create="$msg_yes"
			   fi ;;
			esac
		done
	else
		local var
		for var in account_expire class gecos gid home_dir \
			member_groups name password_expire shell uid \
		; do
			local _user_$var
			eval f_shell_escape \"\$user_$var\" _user_$var
		done

		# Form the command
		local cmd="pw usermod -n '$_user_name'"
		[ "$user_gid"      ] && cmd="$cmd -g '$_user_gid'"
		[ "$user_home_dir" ] && cmd="$cmd -d '$_user_home_dir'"
		[ "$user_shell"    ] && cmd="$cmd -s '$_user_shell'"
		[ "$user_uid"      ] && cmd="$cmd -u '$_user_uid'"
		[ "$user_account_expire" -o "$no_account_expire" ] &&
			cmd="$cmd -e '$_user_account_expire'"
		[ "$user_class" -o "$null_class" ] &&
			cmd="$cmd -L '$_user_class'"
		[ "$user_gecos" -o "$null_gecos" ] &&
			cmd="$cmd -c '$_user_gecos'"
		[ "$user_member_groups" -o "$null_members" ] &&
			cmd="$cmd -G '$_user_member_groups'"
		[ "$user_password_expire" -o "$no_password_expire" ] &&
			cmd="$cmd -p '$_user_password_expire'"

		# Execute the command
		local retval err
		if [ "$user_password_disable" ]; then
			f_eval_catch -k err $funcname pw '%s -h -' "$cmd"
		elif [ "$user_password" ]; then
			err=$( echo "$user_password" | f_eval_catch -de \
				$funcname pw '%s -h 0' "$cmd" 2>&1 )
		else
			f_eval_catch -k err $funcname pw '%s' "$cmd"
		fi
		retval=$?
		if [ $retval -ne $SUCCESS ]; then
			f_show_err "%s" "$err"
			return $retval
		fi

		# Create home directory if desired
		[ "${user_home_create:-$msg_no}" != "$msg_no" ] &&
			f_user_create_homedir "$user_name"

		# Copy dotfiles if desired
		[ "${user_dotfiles_create:-$msg_no}" != "$msg_no" ] &&
			f_user_copy_dotfiles "$user_name"
	fi

	f_dialog_title "$title"
	$alert "$msg_login_updated"
	f_dialog_title_restore
	[ "$no_confirm" -a "$USE_DIALOG" ] && sleep 1

	return $SUCCESS
}

############################################################ MAIN

f_dprintf "%s: Successfully loaded." usermgmt/user.subr

fi # ! $_USERMGMT_USER_SUBR
OpenPOWER on IntegriCloud