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
|
DocumentId: $Id: TODO 2021 2005-04-17 18:21:29Z ola $
Author: $Author: ola $
Ola Lundqvist <opal@debian.org>
Date: $Date: 2005-04-17 20:21:29 +0200 (sön, 17 apr 2005) $
Summary:
To do on this toolkit.
* Implement the automatic mysql handling.
* Better skel file handling. Especially for configuration files.
* Better patch handling (maybe use code from source patching , like kernel
patching) to allow patches to be removed even if the original package is
not updated. Is this already done? When should it be done?
* Better handling of /home and other variables for each user. Use the code
from ssh and apply to other places. Right now it is a bit to much
hard-coded.
* Fix the warning message about unknown variables for adduser. This should
really be moved to some other place.
* Add a dpsyco-delete for deleting files?
##########################################################################
Secondly, when updating users, the code fails to add a gecos field (or
a decent password, but I'll come to that). I feelthat is because it
uses adduser instead of useradd, which is more flexible.
Thirdly, the code does dangerous things with the home dirs of users
that it simply should NEVER do. It must NOT eliminate the home
directory by default! That's incredibly dangerous (and probably wildly
against debian policy?).
I suggest that you use the files containing user details to contain more
data.
CRYPT -> encrypted password
USERHOME -> forced home dir
USERID -> forced uid
USERGID -> forced gid (plural, to join other groups?)
USERSHELL-> choice of shell.
NAME -> gecos field
Then you fill in the gecos data using "chfn", and you use useradd -p to
set the password, instead of relying on adduser.
Also, the code contains huge "if" blocks that are the wrong way round,
with the exceptional case at the end instead of the beginning. The
exception shoudl be treated first, and discarded, leaving the rest of
the code to treat the normal case without further indenting.
Assuming proper rephrasing to discard exceptions first, the main code
would go like this:
@@ -139,5 +125,121 @@
usermod -c "$NAME" $AU
fi
fi
+ continue # exceptional case discarded, continue inline
+ fi
+
+ # the user is not in the to-be-eliminated list
+ if grep "^$AU:" $PWDF > /dev/null 2>&1 ; then
+ # the user is in the passwd
+ if [ $UPID -ge $FIRST_SYSTEM_UID ] ; then
+ # PTB 6/9/04 be quiet
+ : echo "User $AU ($UPID) does already exist, FIX THIS MANUALLY!!!"
+ fi
+ continue
+ fi
+
+ # CREATING USER.
+ dpsyco-restorehome $AU
+
+ CRYPTOPTS=""
+ if [ -n "$CRYPT" ]; then
+ CRYPTOPTS="-p $CRYPT"
+ fi
+
+ if [ -n "$USERHOME" ]; then
+ HOMEOPTS="-d $USERHOME"
+ else
+ USERHOME="$DHOME/$AU"
+ HOMEOPTS="-d $DHOME/$AU"
+ fi
+
+ UIDOPTS=""
+ if [ -n "$USERID" ]; then
+ UIDOPTS="-u $USERID"
+ fi
+
+ if [ -n "$USERGID" ]; then
+ GROUPOPTS="-g $USERGID"
+ else
+ if [ -n "$USERID" ]; then
+ USERGID="$USERID"
+ GROUPOPTS="-g $USERID"
+ fi
+ fi
+
+ SHOPTS=""
+ if [ -n "$USERSHELL" ]; then
+ SHOPTS="-s $USERSHELL"
+ fi
+
+ if [ -n "$CRYPT" ]; then # use useradd, not adduser
+ useradd $HOMEOPTS $GROUPOPTS $UIDOPTS $CRYPTOPTS $SHOPTS $AU
+ if [ -n "$NAME" ]; then
+ ifs="$IFS"
+ IFS=","
+ set -- $NAME
+ IFS="$ifs"
+ FULL_NAME="$1"
+ ROOM_NO="$2"
+ WORK_PH="$3"
+ HOME_PH="$4"
+ shift 4
+ OTHER=""
+ OTHERCOUNT=""
+ for i; do
+ if [ "$OTHERCOUNT" ]; then
+ OTHER="$OTHER,$i"
+ else
+ OTHER="$i"
+ OTHERCOUNT=1
+ fi
+ shift
+ done
+ chfn $AU
+ fi
+ if [ -n "$FULL_NAME" ]; then
+ chfn -f "$FULL_NAME" $AU
+ fi
+ if [ -n "$ROOM_NO" ]; then
+ chfn -r "$ROOM_NO" $AU
+ fi
+ if [ -n "$WORK_PH" ]; then
+ chfn -w "$WORK_PH" $AU
+ fi
+ if [ -n "$HOME_PH" ]; then
+ chfn -h "$HOME_PH" $AU
+ fi
+ if [ -n "$OTHER" ]; then
+ chfn -o "$OTHER" $AU
+ fi
+ else # previous use of adduser
+ adduser --conf $DPADDUSERCFG --gecos "$NAME" --disabled-password $AU
+ fi
+ if [ -n "$USERGID" ]; then
+ : changeowner $AU $USERGID "$USERHOME"
+ else
+ : changeowner $AU $AU "$USERHOME"
+ fi
+
+ if [ -f $USERHOME.mail ] ; then
+ echo "Restore user $AU incoming mail."
+ if [ -e /var/mail/$AU ] ; then
+ cat $USERHOME.mail >> /var/mail/$AU
+ rm $USERHOME.mail
+ else
+ mv $USERHOME.mail /var/mail/$AU
+ fi
+ changeowner $AU mail "/var/mail/$AU"
+ fi
+
+ if [ -f $USERHOME.mailspool ] ; then
+ echo "Restore user $AU incoming mailspool."
+ if [ -e /var/spool/mail/$AU ] ; then
+ cat $USERHOME.mailspool >> /var/spool/mail/$AU
+ rm $USERHOME.mailspool
+ else
+ mv $USERHOME.mailspool /var/spool/mail/$AU
+ fi
+ changeowner $AU mail "/var/spool/mail/$AU"
fi
done
Peter
|