3 # Copyright (c) 2010 iXsystems, Inc. All rights reserved.
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions
8 # 1. Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer.
10 # 2. Redistributions in binary form must reproduce the above copyright
11 # notice, this list of conditions and the following disclaimer in the
12 # documentation and/or other materials provided with the distribution.
14 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 # Functions which runs commands on the system
30 . ${BACKEND}/functions.sh
31 . ${BACKEND}/functions-parse.sh
34 # Function which checks and sets up auto-login for a user if specified
37 get_value_from_cfg autoLoginUser
38 if [ -n "${VAL}" -a "${INSTALLTYPE}" = "PCBSD" ]
41 # Add the auto-login user line
42 sed -i.bak "s/AutoLoginUser=/AutoLoginUser=${AUTOU}/g" ${FSMNT}/usr/local/kde4/share/config/kdm/kdmrc
44 # Add the auto-login user line
45 sed -i.bak "s/AutoLoginEnable=false/AutoLoginEnable=true/g" ${FSMNT}/usr/local/kde4/share/config/kdm/kdmrc
50 # Function which actually runs the adduser command on the filesystem
55 if [ -e "${FSMNT}/.tmpPass" ]
57 # Add a user with a supplied password
58 run_chroot_cmd "cat /.tmpPass | pw useradd ${ARGS}"
59 rc_halt "rm ${FSMNT}/.tmpPass"
61 # Add a user with no password
62 run_chroot_cmd "cat /.tmpPass | pw useradd ${ARGS}"
67 # Function which reads in the config, and adds any users specified
71 # We are ready to start setting up the users, lets read the config
75 echo $line | grep -q "^userName=" 2>/dev/null
78 get_value_from_string "${line}"
82 echo $line | grep -q "^userComment=" 2>/dev/null
85 get_value_from_string "${line}"
89 echo $line | grep -q "^userPass=" 2>/dev/null
92 get_value_from_string "${line}"
96 echo $line | grep -q "^userEncPass=" 2>/dev/null
99 get_value_from_string "${line}"
103 echo $line | grep -q "^userShell=" 2>/dev/null
106 get_value_from_string "${line}"
107 strip_white_space "$VAL"
111 echo $line | grep -q "^userHome=" 2>/dev/null
114 get_value_from_string "${line}"
118 echo $line | grep -q "^userGroups=" 2>/dev/null
121 get_value_from_string "${line}"
126 echo $line | grep -q "^commitUser" 2>/dev/null
129 # Found our flag to commit this user, lets check and do it
130 if [ -n "${USERNAME}" ]
133 # Now add this user to the system, by building our args list
134 ARGS="-n ${USERNAME}"
136 if [ -n "${USERCOMMENT}" ]
138 ARGS="${ARGS} -c \"${USERCOMMENT}\""
141 if [ -n "${USERPASS}" ]
144 echo "${USERPASS}" >${FSMNT}/.tmpPass
145 elif [ -n "${USERENCPASS}" ]
148 echo "${USERENCPASS}" >${FSMNT}/.tmpPass
151 rm ${FSMNT}/.tmpPass 2>/dev/null 2>/dev/null
154 if [ -n "${USERSHELL}" ]
156 ARGS="${ARGS} -s \"${USERSHELL}\""
158 ARGS="${ARGS} -s \"/nonexistant\""
161 if [ -n "${USERHOME}" ]
163 ARGS="${ARGS} -m -d \"${USERHOME}\""
166 if [ -n "${USERGROUPS}" ]
168 ARGS="${ARGS} -G \"${USERGROUPS}\""
173 # Unset our vars before looking for any more users
174 unset USERNAME USERCOMMENT USERPASS USERENCPASS USERSHELL USERHOME USERGROUPS
176 exit_err "ERROR: commitUser was called without any userName= entry!!!"
183 # Check if we need to enable a user to auto-login to the desktop