From owner-freebsd-questions@FreeBSD.ORG Tue Aug 2 13:34:42 2005 Return-Path: X-Original-To: freebsd-questions@freebsd.org Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 9304F16A41F for ; Tue, 2 Aug 2005 13:34:42 +0000 (GMT) (envelope-from simon@comsys.ntu-kpi.kiev.ua) Received: from comsys.ntu-kpi.kiev.ua (comsys.ntu-kpi.kiev.ua [195.245.194.142]) by mx1.FreeBSD.org (Postfix) with ESMTP id 7466F43D48 for ; Tue, 2 Aug 2005 13:34:33 +0000 (GMT) (envelope-from simon@comsys.ntu-kpi.kiev.ua) Received: from pm514-9.comsys.ntu-kpi.kiev.ua (pm514-9.comsys.ntu-kpi.kiev.ua [10.18.54.109]) (authenticated bits=0) by comsys.ntu-kpi.kiev.ua (8.12.10/8.12.10) with ESMTP id j72DfK0R085882 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 2 Aug 2005 16:41:21 +0300 (EEST) Received: by pm514-9.comsys.ntu-kpi.kiev.ua (Postfix, from userid 1000) id 56580329; Tue, 2 Aug 2005 16:32:15 +0300 (EEST) Date: Tue, 2 Aug 2005 16:32:15 +0300 From: Andrey Simonenko To: Joerg Pulz Message-ID: <20050802133215.GA1812@pm514-9.comsys.ntu-kpi.kiev.ua> 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> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20050802141953.K72944@hades.admin.frm2> User-Agent: Mutt/1.4.2.1i X-Virus-Scanned: ClamAV 0.82/989/Sat Jul 23 00:27:30 2005 on comsys.ntu-kpi.kiev.ua X-Virus-Status: Clean Cc: martin@orbweavers.co.uk, freebsd-questions@freebsd.org Subject: Re: LDAP/nss_ldap adduser script X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 02 Aug 2005 13:34:42 -0000 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.