3 # SPDX-License-Identifier: BSD-2-Clause-FreeBSD
5 # Copyright (c) 2010 iXsystems, Inc. All rights reserved.
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
10 # 1. Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 # 2. Redistributions in binary form must reproduce the above copyright
13 # notice, this list of conditions and the following disclaimer in the
14 # documentation and/or other materials provided with the distribution.
16 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 # Functions which runs commands on the system
32 . ${BACKEND}/functions.sh
33 . ${BACKEND}/functions-parse.sh
36 # Function which checks and sets up auto-login for a user if specified
39 get_value_from_cfg autoLoginUser
40 if [ -n "${VAL}" -a "${INSTALLTYPE}" = "PCBSD" ]
43 # Add the auto-login user line
44 sed -i.bak "s/AutoLoginUser=/AutoLoginUser=${AUTOU}/g" ${FSMNT}/usr/local/kde4/share/config/kdm/kdmrc
46 # Add the auto-login user line
47 sed -i.bak "s/AutoLoginEnable=false/AutoLoginEnable=true/g" ${FSMNT}/usr/local/kde4/share/config/kdm/kdmrc
52 # Function which actually runs the adduser command on the filesystem
57 if [ -e "${FSMNT}/.tmpPass" ]
59 # Add a user with a supplied password
60 run_chroot_cmd "cat /.tmpPass | pw useradd ${ARGS}"
61 rc_halt "rm ${FSMNT}/.tmpPass"
63 # Add a user with no password
64 run_chroot_cmd "cat /.tmpPass | pw useradd ${ARGS}"
69 # Function which reads in the config, and adds any users specified
73 # We are ready to start setting up the users, lets read the config
77 echo $line | grep -q "^userName=" 2>/dev/null
80 get_value_from_string "${line}"
84 echo $line | grep -q "^userComment=" 2>/dev/null
87 get_value_from_string "${line}"
91 echo $line | grep -q "^userPass=" 2>/dev/null
94 get_value_from_string "${line}"
98 echo $line | grep -q "^userEncPass=" 2>/dev/null
101 get_value_from_string "${line}"
105 echo $line | grep -q "^userShell=" 2>/dev/null
108 get_value_from_string "${line}"
109 strip_white_space "$VAL"
113 echo $line | grep -q "^userHome=" 2>/dev/null
116 get_value_from_string "${line}"
120 echo $line | grep -q "^userGroups=" 2>/dev/null
123 get_value_from_string "${line}"
128 echo $line | grep -q "^commitUser" 2>/dev/null
131 # Found our flag to commit this user, lets check and do it
132 if [ -n "${USERNAME}" ]
135 # Now add this user to the system, by building our args list
136 ARGS="-n ${USERNAME}"
138 if [ -n "${USERCOMMENT}" ]
140 ARGS="${ARGS} -c \"${USERCOMMENT}\""
143 if [ -n "${USERPASS}" ]
146 echo "${USERPASS}" >${FSMNT}/.tmpPass
147 elif [ -n "${USERENCPASS}" ]
150 echo "${USERENCPASS}" >${FSMNT}/.tmpPass
153 rm ${FSMNT}/.tmpPass 2>/dev/null 2>/dev/null
156 if [ -n "${USERSHELL}" ]
158 ARGS="${ARGS} -s \"${USERSHELL}\""
160 ARGS="${ARGS} -s \"/nonexistant\""
163 if [ -n "${USERHOME}" ]
165 ARGS="${ARGS} -m -d \"${USERHOME}\""
168 if [ -n "${USERGROUPS}" ]
170 ARGS="${ARGS} -G \"${USERGROUPS}\""
175 # Unset our vars before looking for any more users
176 unset USERNAME USERCOMMENT USERPASS USERENCPASS USERSHELL USERHOME USERGROUPS
178 exit_err "ERROR: commitUser was called without any userName= entry!!!"
185 # Check if we need to enable a user to auto-login to the desktop