[debian-lan-devel] [SCM] Debian-LAN development and packaging branch, master, updated. 0.7-27-gd5bd8c6

Andreas B. Mundt andi at debian.org
Thu Feb 14 13:50:40 UTC 2013


The following commit has been merged in the master branch:
commit d5bd8c6b4d8fc9115860c4e1ab6ad01f66bc4bdb
Author: Andreas B. Mundt <andi at debian.org>
Date:   Wed Feb 13 18:28:49 2013 +0100

    Improve add2gosa script.  Map LDAP structure on home directory tree.
    
    By default, the structure within the GOsa tree 'ou=gosa,dc=intern' is
    now mapped on the structure of the home directory tree.  A user with:
       'dn: uid=someone,ou=people,ou=2013,ou=students,ou=gosa,dc=intern'
    will find his home directory in:
       '/lan/mainserver/home0/students/2013/someone'
    
    The feature can be switched off by applying the '--no-map' option.

diff --git a/fai/config/files/usr/local/sbin/add2gosa/GOSA b/fai/config/files/usr/local/sbin/add2gosa/GOSA
index 901a1c3..491d9e3 100755
--- a/fai/config/files/usr/local/sbin/add2gosa/GOSA
+++ b/fai/config/files/usr/local/sbin/add2gosa/GOSA
@@ -37,18 +37,18 @@ user2LDAP() {
 
     # Group GID
     _GID=$(_findnextgid)
-    [ -z "_GID" ] && end_die "Cannot guess next free group id"
+    [ -z "_GID" ] && end_die "Cannot guess next free group ID."
 
     # Add group to LDAP
     _extractldif 4 | _filterldif | _utf8encode | _ldapadd
-    [ $? -eq 0 ] || end_die "Error adding group $_GROUP to LDAP"
-    echo_log "Successfully added group $_GROUP to LDAP"
+    [ $? -eq 0 ] || end_die "Error adding group '$_GROUP' to LDAP."
+    echo_log "Successfully added group '$_GROUP' to LDAP."
 
     ###################
 
     # User UID
     _UID=$(_findnextuid)
-    [ -z "_UID" ] && end_die "Cannot guess next free user id"
+    [ -z "_UID" ] && end_die "Cannot guess next free user ID."
 
     # Compute homedir
     _HOMEDIR=$(echo "$UHOMES" | sed "s|%u|$_USER|g")
@@ -59,22 +59,22 @@ user2LDAP() {
         -e "s|<FNAME>|$FNAME|g" \
         -e "s|<PWHASH>|$PWHASH|g" \
         | _filterldif | _utf8encode | _ldapadd
-    [ $? -eq 0 ] || end_die "Error adding user $_USER to LDAP"
-    echo_log "Successfully added user $_USER to LDAP"
+    [ $? -eq 0 ] || end_die "Error adding user '$_USER' to LDAP."
+    echo_log "Successfully added user '$_USER' to LDAP."
 
     # Create Home dir
     if [ -e "$_HOMEDIR" ] ; then
-        warn_log "Skipped home directory creation for user $_USER (already exists)"
+        warn_log "Skipped home directory creation for user '$_USER' (already exists)."
     else
-        # Create home by skel or mkdir
         if [ -d "$HOMESKEL" ] ; then
+            mkdir -p $(dirname "$_HOMEDIR") 2>>"$LOGFILE" 1>/dev/null
             cp -pR "$HOMESKEL/" "$_HOMEDIR" 2>>"$LOGFILE" 1>/dev/null
         else
             mkdir -p "$_HOMEDIR" 2>>"$LOGFILE" 1>/dev/null
         fi
         chmod "$HOMEPERMS" "$_HOMEDIR" 2>>"$LOGFILE" 1>/dev/null
         chown -R "$_UID":"$_GID" "$_HOMEDIR" 2>>"$LOGFILE" 1>/dev/null
-        echo_log "Successfully created home directory for user $_USER"
+        echo_log "Successfully created home directory '$_HOMEDIR' for user '$_USER'."
     fi
     set -e
 }
@@ -116,13 +116,19 @@ SUFFIX=${SUFFIX#,} # remove ',' if $GOSAOU=""
 GIDSTART="10000"
 UIDSTART="10000"
 
+## Map LDAP structure on the home directory tree if not switched off:
+if [ -n "$GOSAOU" ] && [ "$3" != "--no-map" ] ; then
+    HSUFFIX=$(echo -n "${GOSAOU}," | tac -s "," | sed -e "s|ou=||g" -e "s|,|\/|g" )
+    UHOMES=${UHOMES/\%u/${HSUFFIX}%u}
+fi
+
 ## Password restrictions (compliant with kerberos policy):
 MINLEN=4  # minimal password length (max 8 with slappasswd as password generator)
 MINCLS=2  # minimal number of character classes
 
 if [ ! -r "$FILE" ] ; then
     cat <<EOF
-Usage: add2gosa <file> [ou=<GOsa Department>]
+Usage: add2gosa <file> [ou=<GOsa Department>[,ou=...] [--no-map]]
 Where <file> contains rows of first and last names:
 
     <First Name> <Last Name>
@@ -133,15 +139,23 @@ generated password is appended to the line during processing, the line
 commented.
 
 Optionally it is possible to specify an organizational unit within the
-GOsa tree.  The users will be added to that department.
+GOsa tree.  The users will be added to that department.  The location
+of the home directory created will map the structure of the
+organizational units in LDAP.  This feature can be switched off with
+the --no-map option.
 
 Examples:
 
-    add2gosa <file>              # add users to GOsa base
-    add2gosa <file> ou=students  # add users to department 'students'
+  * add users to GOsa base, home directory: '/<default>/<username>':
+
+           add2gosa <file>
+
+  * add users to department 'ou=2013,ou=students', home directory
+    '/<default>/students/2013/<username>':
 
-The department must exist before adding users.
+           add2gosa <file> ou=2013,ou=students
 
+The department has to be created in GOsa before adding users.
 EOF
     exit 1
 fi

-- 
Debian-LAN development and packaging



More information about the debian-lan-devel mailing list