LDAP/nss_ldap adduser script
Andrey Simonenko
simon at comsys.ntu-kpi.kiev.ua
Tue Aug 2 13:34:42 GMT 2005
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.
More information about the freebsd-questions
mailing list