Date: Tue, 2 Aug 2005 16:32:15 +0300 From: Andrey Simonenko <simon@comsys.ntu-kpi.kiev.ua> To: Joerg Pulz <Joerg.Pulz@frm2.tum.de> Cc: martin@orbweavers.co.uk, freebsd-questions@freebsd.org Subject: Re: LDAP/nss_ldap adduser script Message-ID: <20050802133215.GA1812@pm514-9.comsys.ntu-kpi.kiev.ua> In-Reply-To: <20050802141953.K72944@hades.admin.frm2> References: <3040.217.37.3.201.1122457154.squirrel@www.orbweavers.co.uk> <20050802111343.GA1545@pm514-9.comsys.ntu-kpi.kiev.ua> <3930.217.37.3.201.1122984256.squirrel@www.orbweavers.co.uk> <20050802141953.K72944@hades.admin.frm2>
next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, Aug 02, 2005 at 02:24:26PM +0200, Joerg Pulz wrote: > >user_base=`awk '/nss_base_passwd/ {print $2}' /etc/ldap.conf | cut -f1 -d?` > >get_next_uid() { > > > > lastuid=`ldapsearch -LLL -b "$user_base" > >"objectclass=posixAccount" |\ > > awk '/uidNumber/ {print $2}' | sort | tail -n1` > > if [ -z "$lastuid" ]; then > > uid=$startuid > > else > > uid=`expr $lastuid + 1` > > fi > >} #!/bin/sh uid_min=1000 uid_max=2000 get_uid() { uid=${uid_min} sort -g list-uid | while read uid_used; do if [ ${uid} -eq ${uid_used} ]; then uid=`expr ${uid} + 1` if [ ${uid} -eq ${uid_max} ]; then echo "Out of UID numbers"; exit 1 fi else echo "${uid}" break; fi done } uid=`get_uid` if [ $? -ne 0 ]; then echo ${uid} exit 1 fi echo "Lowest unused UID: ${uid}" > so, why all this scripting?? you could simply use the following line to > get the next free uid (as long as the system is configured to use LDAP > accounts) Because everyone has own environment and not enough details about his/her environment give many solutions, sometimes not optimal for another environment. Yours idea is good (if LDAP accounts work on the system), especially that pw uses bitmap to find first unused UID (if reuseuids is 'yes'). > the 'cut' is necessary as 'pw usernext' reports the next free uid:gid in > combination (is this a bug??) This is documented in pw(8) manual page.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20050802133215.GA1812>