Théo Ertzscheid 2 жил өмнө
commit
8e2484f980
5 өөрчлөгдсөн 103 нэмэгдсэн , 0 устгасан
  1. 8 0
      .env.example
  2. 1 0
      .gitignore
  3. 19 0
      addtogroups
  4. 28 0
      createperson
  5. 47 0
      person2posix

+ 8 - 0
.env.example

@@ -0,0 +1,8 @@
+BINDDN="cn=admin,dc=example,dc=com"
+BINDPW="yourpasswordhere"
+PEOPLEDN="ou=People,dc=example,dc=com"
+GROUPSDN="ou=Groups,dc=example,dc=com"
+HOST="localhost"
+DOMAIN="example.com"
+ADD_CMD="ldapadd -x -D $BINDDN -w $BINDPW"
+MODIFY_CMD="ldapmodify -x -D $BINDDN -w $BINDPW"

+ 1 - 0
.gitignore

@@ -0,0 +1 @@
+.env

+ 19 - 0
addtogroups

@@ -0,0 +1,19 @@
+#!/bin/bash
+. .env
+uid=$1
+
+group="dn: cn=%GROUP%,$GROUPSDN
+changeType: modify
+add: member
+member: uid=%UID%,$PEOPLEDN"
+
+# remove uid ($1) from args so that only the list
+# of groups remains in $@
+shift
+
+# add user to each of the groups given
+for g in $@; do
+    echo "$group" | sed \
+	-e "s/%GROUP%/$g/" \
+	-e "s/%UID%/$uid/" #| $MODIFY_CMD
+done

+ 28 - 0
createperson

@@ -0,0 +1,28 @@
+#!/bin/bash
+. .env
+
+read -p "UID: " uid
+read -p "GivenName: " gn
+read -p "Name: " sn
+pw=$(sudo slappasswd -s salut$uid)
+
+user="dn: uid=$uid,$PEOPLEDN
+objectClass: top
+objectClass: inetOrgPerson
+sn: $sn
+gn: $gn
+cn: $gn $sn
+mail: $uid@$DOMAIN
+userPassword: $pw"
+
+echo "$user" #| $ADD_CMD
+
+read -p "User added. Do you want to add them to groups ? [o/N] " a
+
+case $a in
+    y*|o* )
+        read -p "Enter list of groups separated by spaces: " grouplist
+	./addtogroups $uid $grouplist;;
+    * )
+        exit;;
+esac

+ 47 - 0
person2posix

@@ -0,0 +1,47 @@
+#!/bin/bash
+. .env
+uid=${1}
+
+user="dn: uid=%UID%,$PEOPLEDN
+changeType: modify
+add: objectClass
+objectClass: posixAccount
+-
+add: uidNumber
+uidNumber: %NUMBER%
+-
+add: gidNumber
+gidNumber: %NUMBER%
+-
+add: homeDirectory
+homeDirectory: /home/%UID%
+-
+add: loginShell
+loginShell: /bin/bash
+-
+add: objectClass
+objectClass: shadowAccount
+-
+add: objectClass
+objectClass: ldapPublicKey"
+
+group="dn: cn=%UID%,$GROUPSDN
+objectClass: top
+objectClass: posixGroup
+cn: %UID%
+gidNumber: %NUMBER%
+memberUid: %UID%"
+
+# get the list of currently used uid numbers and add 1 to get the next one
+uidnumber=$(( $(slapcat | grep 'gidNumber: 2' | cut -d' ' -f2 | sort -u | tail -n 1) +1))
+
+# add the necessary attribbute for a posixAccount
+echo "$user" | sed \
+	-e "s/%NUMBER%/$uidnumber/" \
+	-e "s/%UID%/$uid/" #| $MODIFY_CMD
+
+# create a posic group with the same name and uid as the user
+# and add them to it
+echo "$group" | sed \
+	-e "s/%NUMBER%/$uidnumber/" \
+	-e "s/%UID%/$uid/" #| $ADD_CMD