Skip to content

Instantly share code, notes, and snippets.

@ChatchaiJ
Created December 8, 2015 06:53
Show Gist options
  • Save ChatchaiJ/d50af8cb98079cf747d5 to your computer and use it in GitHub Desktop.
Save ChatchaiJ/d50af8cb98079cf747d5 to your computer and use it in GitHub Desktop.
Set nextfreeunixid in ldap server
#!/bin/sh
# --------------------------------------------------------------------- #
# setnextfreeunixid : Set nextfreeunixid in ldap server allow #
# smbldap-tools to start adding account at the #
# appropriate place. #
# #
# version 0.1 : cj (2004-12-20) initial. #
# --------------------------------------------------------------------- #
[ `id -u` != 0 ] && echo "Need root priviledge!" && exit
[ -z "$1" ] && echo "Usage: $0 newid" && exit
BASEDN="dc=local,dc=net"
ADMINDN="cn=admin,$BASEDN"
SECRET=`cat /etc/ldap.secret`
lowerlimit=1000
upperlimit=65000
tmpfile=/tmp/$$.`basename $0`.log
id="$1"
[ $id -lt $lowerlimit ] && echo "id must greater than $lowerlimit" && exit
[ $id -gt $upperlimit ] && echo "id should less than $upperlimit" && exit
oldid=`ldapsearch -x sn=nextfreeunixid | grep uidNumber | cut -f2 -d' '`
[ $id -eq $oldid ] && echo "id already be $id, not change!" && exit
echo "# $tmpfile" > $tmpfile
echo "dn: cn=NextFreeUnixId,$BASEDN" >> $tmpfile
echo "changetype: modify" >> $tmpfile
echo "delete: uidNumber" >> $tmpfile
echo "uidNumber: $oldid" >> $tmpfile
echo "-" >> $tmpfile
echo "add: uidNumber" >> $tmpfile
echo "uidNumber: $id" >> $tmpfile
ldapmodify -D $ADMINDN -w $SECRET -x -ZZ -f $tmpfile
rm -f $tmpfile
# --------------------------------------------------------------------- #
# end of file #
# --------------------------------------------------------------------- #
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment