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

