[Date Prev][Date Next] [Chronological] [Thread] [Top]

RE: Get Max uidNumber ...



A few things:
 
1. Most ldapsearch clients do not provide a -S flag. Is that "sort"? A
more portable solution might be to pipe through the sort command. If it
works, great.
 
2. Many bashes don't support arrays. You need to make sure you use bash
2.0 or higer or else it won't work. Since bash2 has other issue, many
systems don't come with that installed.
 
3. There is a handy utility called "digest" that I use w/ shell scripts
to make MD5, SHA, crypt, etc. hashes. It was written by Andre Opperman
and comes with his qmail patches on www.nrg4u.com.
 
Kevin

	-----Original Message----- 
	From: C.Lee Taylor 
	Sent: Fri 10/26/2001 8:09 AM 
	To: openldap-software@OpenLDAP.org 
	Cc: 
	Subject: Get Max uidNumber ...
	
	

	Greetings ...
	
	        I search the archives and found that there was a few
ideas how to do
	this, so I thought that I would though out my idea and see you
guys bash
	it ... no pun intended ... I know this would be slow if one was
tring to
	bring in more than a few users, but then I use it just to add a
few
	users at a time ... I also believe this would not be a good idea
to have
	more than one user adding in users, because the uidNumber could
go up
	while we import the next user.
	
	        Take look and tell me what you think ...
	
	Mailed
	Lee
	
	#!/bin/bash
	#
	ldapsecret="-w topsecret"
	ldapDN="dc=foobar, dc=com"
	
	function getMaxUid ()
	{
	     n=0
	     for i in $(ldapsearch -x -LLL $ldapsecret -D "cn=Manager,
$ldapDN"
	"(uidNumber=*)" uidNumber -S uidNumber | grep uidNumber | tail
-n1 );
	        do \
	            ldaparry[$n]=$i
	            let n+=1
	        done
	
	     if [ "${ldaparry[0]}" == "uidNumber:" ]; then
	        echo $((${ldaparry[1]}+1))
	        return 0
	     else
	        return -1
	     fi
	}
	
	
	function adduser ()
	{
	     echo "dn: uid=tempacc,ou=People,$ldapDN"
	     echo "uid: tempacc"
	     echo "cn: tempacc"
	     echo "sn: surname"
	     echo "objectClass: person"
	     echo "objectClass: organizationalPerson"
	     echo "objectClass: inetOrgPerson"
	     echo "objectClass: account"openldap-software@OpenLDAP.org
	     echo "objectClass: posixAccount"
	     echo "objectClass: top"
	     echo "objectClass: shadowAccount"
	     echo "userPassword:: e2NyeXB0fVNBMDFWamZva2VwUi4="
	     echo "shadowLastChange: 11159"
	     echo "shadowMax: 99999"
	     echo "shadowWarning: 7"
	     echo "gidNumber: 100"
	     echo "homeDirectory: /home/users/tempacc"
	     uidNumber=`getMaxUid`
	     (($uidNumber > 0))
	     if [ $? ]; then
	        echo "uidNumber: $uidNumber"
	        return 0
	     else
	        return -1
	     fi
	}
	
	adduser | ldapadd -x $ldapsecret -D "cn=Manager, $ldapDN
	
	exit 0
	
	

<<winmail.dat>>