Return to BSD News archive
Newsgroups: comp.unix.bsd
Path: sserve!manuel.anu.edu.au!munnari.oz.au!sgiblab!darwin.sura.net!uvaarpa!rucs!bmyers
From: bmyers@rucs2.sunlab.cs.runet.edu (B.Myers)
Subject: Re: adduser program available.
Message-ID: <BwL3oK.5H@rucs2.sunlab.cs.runet.edu>
Organization: Radford University
References: <BwFFuJ.9wv@ibmpcug.co.uk>
Date: Fri, 23 Oct 1992 17:09:55 GMT
Lines: 375
In article <BwFFuJ.9wv@ibmpcug.co.uk> adrian@rachel.ibmpcug.co.uk (Adrian Hall (Systems Manager)) writes:
>
>I got fed up of adding users by hand. So I have written a *small*
>C program to do it for me. (Since I add far too many suers to my
>system anyway, this was a good plan).
>
>Notes:
>
> (1) It uses system, so is inherently insecure. Thus
> you should probably protect the program fairly
> well as well if you are going to seriously use it.
>
> (2) It doesnt copy files into the users directory.
>
> (3) All home directories are placed in /home/<group>/<user>
>
>It is available from rachel.ibmpcug.co.uk::~ftp/src/usr.sbin/adduser
>
>Adrian
>
In article <BwFFuJ.9wv@ibmpcug.co.uk> adrian@rachel.ibmpcug.co.uk (Adrian Hall (Systems Manager)) writes:
>
>I got fed up of adding users by hand. So I have written a *small*
>C program to do it for me. (Since I add far too many suers to my
>system anyway, this was a good plan).
>
>Notes:
>
> (1) It uses system, so is inherently insecure. Thus
> you should probably protect the program fairly
> well as well if you are going to seriously use it.
>
> (2) It doesnt copy files into the users directory.
>
> (3) All home directories are placed in /home/<group>/<user>
>
>It is available from rachel.ibmpcug.co.uk::~ftp/src/usr.sbin/adduser
>
>Adrian
>
I have posted this to the net before.. and since it seems that others
like myself don't like all the hassels of adding users to their systems
by hand.. I madeup this little script to to the dirty work for you...
it is a shell script, so it should work with any 386bsd machine without
any problems (provided that you have installed the BIN01 distribution)
Hope this helps.. It sure did help me. :)
------------- CUT HERE ---------------
#!/bin/sh
#
# @(#)add_user 1.9 90/10/26 SMI
#
# add user script for use with sys-config
# arguments: uname uid gid fullname homedir shell
#
# Script by Brandon Myers.
# bmyers@rucs2.sunlab.cs.runet.edu
# to execute type:
# sh add_user uname uid gid "full name" homedir shell
myname=`basename $0`
Passwd=/etc/passwd
PATH=$PATH:/usr/bin:/bin:/usr/sbin:/sbin
export PATH
# check for root
if [ "`whoami`x" != "root"x ]; then
echo "You must be root to do $myname!"
exit 1
fi
# check for number of args
# Change to 5 if the directories are going to be in the same place
# ie. no homedir option given to the program
if [ $# -ne 6 ]; then
echo "${myname}: invalid number of arguments"
echo " usage: ${myname} uname uid gid \"fullname\" shell"
exit 1
fi
# put args into named variables
uname=$1
uid=$2
gid=$3
fullname=$4
homedir=$5 # If all directories are going to be in the same place
shell=$6 # Then change homedir=$5 to homedir=/DIR/../$1 ie: /DIR/../UNAME
# homedir will be assumed on each call
# checks for validity of arguments
# check uid
if test $uid -lt 10 ; then
echo "uid: uid must be greater than 10 and less than 60000"
exit 1
elif test $uid -gt 60000 ; then
echo "uid: uid must be greater than 10 and less than 60000"
exit 1
fi
# check gid
if test $gid -lt 10 ; then
echo "gid: gid must be greater than 10 and less than 60000"
exit 1
elif test $gid -gt 60000 ; then
echo "gid: gid must be greater than 10 and less than 60000"
exit 1
fi
# check shell
if test ! -x $shell ; then
echo "$shell: the program does not exist or is not executable"
exit 1
fi
# check homedir
# check if homedir already exists
if [ -f ${homedir} ]; then
echo "${myname}: WARNING: a file named \"${homedir}\" already exists"
echo "and is NOT a directory, NOT setting up user account"
exit 1
fi
if [ -d ${homedir} ]; then
echo "${myname}: WARNING: home directory \"${homedir}\" already exists"
echo " no files copied, NOT setting up user account"
exit 1
fi
# check if all but last path of homedir exits
#dir=`shdirname $homedir`
#if test ! -d $dir ; then
# echo "$dir: does not exist or is not a directory"
# exit 1
#fi
# check if $homedir is local
dfout=`df $dir | ( read aline; read aline; echo $aline )`
case $dfout in
/dev*) ;; # $dir is on local machine
*) echo "$dir: is not on local machine"
exit 1;;
esac
# create a null /etc/passwd entry
# first check if one already exists
if grep -s "^${uname}:" ${Passwd} ; then
echo "${myname}: ERROR: ${uname} aleady in ${Passwd}";
exit 1;
fi
# check if uid already exists
if grep -s ".*:.*:${uid}:" ${Passwd} ; then
echo "uid: ERROR: ${uid} already in ${Passwd}";
exit 1;
fi
pwent="${uname}::${uid}:${gid}::0:0:${fullname}:${homedir}:${shell}"
# XXX sould we use tmp file and rename it?
rm -f /tmp/passwdentree # remove any previous file passwdentree
( echo "${pwent}"; ) > /tmp/passwdentree
( echo -n 'G'; # Go to end of file
echo ":r /tmp/passwdentree"; # Read passwdentree as last line
echo ":wq"; ) | vipw ${Passwd} 2>&1 /dev/null
rm -f /tmp/passwdentree # remove old file
# Verify that the entree was saved.
if grep -s "^${uname}:" ${Passwd} ; then
:
else
echo "${myname}: ERROR: password entry didn't go to ${Passwd}";
exit 1;
fi
# make the home directory
/bin/mkdir ${homedir}
/usr/sbin/chown ${uname} ${homedir}
/usr/bin/chgrp ${gid} ${homedir}
# add default user startup files
cp /usr/lib/Cshrc ${homedir}/.cshrc
cp /usr/lib/Login ${homedir}/.login
cp /usr/lib/.xsession ${homedir}/.xsession
/usr/sbin/chown -R ${uname} ${homedir}
/usr/bin/chgrp -R ${gid} ${homedir}
# is ok, exit 0
exit 0
------- END --------
Hope this helps.
--
Brandon Myers
bmyers@rucs2.sunlab.cs.runet.edu
Newsgroups: comp.unix.bsd
Subject: Re: adduser program available.
Summary:
Expires:
References: <BwFFuJ.9wv@ibmpcug.co.uk>
Sender:
Followup-To:
Distribution:
Organization: Radford University
Keywords:
In article <BwFFuJ.9wv@ibmpcug.co.uk> adrian@rachel.ibmpcug.co.uk (Adrian Hall (Systems Manager)) writes:
>
>I got fed up of adding users by hand. So I have written a *small*
>C program to do it for me. (Since I add far too many suers to my
>system anyway, this was a good plan).
>
>Notes:
>
> (1) It uses system, so is inherently insecure. Thus
> you should probably protect the program fairly
> well as well if you are going to seriously use it.
>
> (2) It doesnt copy files into the users directory.
>
> (3) All home directories are placed in /home/<group>/<user>
>
>It is available from rachel.ibmpcug.co.uk::~ftp/src/usr.sbin/adduser
>
>Adrian
>
I have posted this to the net before.. and since it seems that others
like myself don't like all the hassels of adding users to their systems
by hand.. I madeup this little script to to the dirty work for you...
it is a shell script, so it should work with any 386bsd machine without
any problems (provided that you have installed the BIN01 distribution)
Hope this helps.. It sure did help me. :)
------------- CUT HERE ---------------
#!/bin/sh
#
# @(#)add_user 1.9 90/10/26 SMI
#
# add user script for use with sys-config
# arguments: uname uid gid fullname homedir shell
#
# Script by Brandon Myers.
# bmyers@rucs2.sunlab.cs.runet.edu
# to execute type:
# sh add_user uname uid gid "full name" homedir shell
myname=`basename $0`
Passwd=/etc/passwd
PATH=$PATH:/usr/bin:/bin:/usr/sbin:/sbin
export PATH
# check for root
if [ "`whoami`x" != "root"x ]; then
echo "You must be root to do $myname!"
exit 1
fi
# check for number of args
# Change to 5 if the directories are going to be in the same place
# ie. no homedir option given to the program
if [ $# -ne 6 ]; then
echo "${myname}: invalid number of arguments"
echo " usage: ${myname} uname uid gid \"fullname\" shell"
exit 1
fi
# put args into named variables
uname=$1
uid=$2
gid=$3
fullname=$4
homedir=$5 # If all directories are going to be in the same place
shell=$6 # Then change homedir=$5 to homedir=/DIR/../$1 ie: /DIR/../UNAME
# homedir will be assumed on each call
# checks for validity of arguments
# check uid
if test $uid -lt 10 ; then
echo "uid: uid must be greater than 10 and less than 60000"
exit 1
elif test $uid -gt 60000 ; then
echo "uid: uid must be greater than 10 and less than 60000"
exit 1
fi
# check gid
if test $gid -lt 10 ; then
echo "gid: gid must be greater than 10 and less than 60000"
exit 1
elif test $gid -gt 60000 ; then
echo "gid: gid must be greater than 10 and less than 60000"
exit 1
fi
# check shell
if test ! -x $shell ; then
echo "$shell: the program does not exist or is not executable"
exit 1
fi
# check homedir
# check if homedir already exists
if [ -f ${homedir} ]; then
echo "${myname}: WARNING: a file named \"${homedir}\" already exists"
echo "and is NOT a directory, NOT setting up user account"
exit 1
fi
if [ -d ${homedir} ]; then
echo "${myname}: WARNING: home directory \"${homedir}\" already exists"
echo " no files copied, NOT setting up user account"
exit 1
fi
# check if all but last path of homedir exits
#dir=`shdirname $homedir`
#if test ! -d $dir ; then
# echo "$dir: does not exist or is not a directory"
# exit 1
#fi
# check if $homedir is local
dfout=`df $dir | ( read aline; read aline; echo $aline )`
case $dfout in
/dev*) ;; # $dir is on local machine
*) echo "$dir: is not on local machine"
exit 1;;
esac
# create a null /etc/passwd entry
# first check if one already exists
if grep -s "^${uname}:" ${Passwd} ; then
echo "${myname}: ERROR: ${uname} aleady in ${Passwd}";
exit 1;
fi
# check if uid already exists
if grep -s ".*:.*:${uid}:" ${Passwd} ; then
echo "uid: ERROR: ${uid} already in ${Passwd}";
exit 1;
fi
pwent="${uname}::${uid}:${gid}::0:0:${fullname}:${homedir}:${shell}"
# XXX sould we use tmp file and rename it?
rm -f /tmp/passwdentree # remove any previous file passwdentree
( echo "${pwent}"; ) > /tmp/passwdentree
( echo -n 'G'; # Go to end of file
echo ":r /tmp/passwdentree"; # Read passwdentree as last line
echo ":wq"; ) | vipw ${Passwd} 2>&1 /dev/null
rm -f /tmp/passwdentree # remove old file
# Verify that the entree was saved.
if grep -s "^${uname}:" ${Passwd} ; then
:
else
echo "${myname}: ERROR: password entry didn't go to ${Passwd}";
exit 1;
fi
# make the home directory
/bin/mkdir ${homedir}
/usr/sbin/chown ${uname} ${homedir}
/usr/bin/chgrp ${gid} ${homedir}
# add default user startup files
cp /usr/lib/Cshrc ${homedir}/.cshrc
cp /usr/lib/Login ${homedir}/.login
cp /usr/lib/.xsession ${homedir}/.xsession
/usr/sbin/chown -R ${uname} ${homedir}
/usr/bin/chgrp -R ${gid} ${homedir}
# is ok, exit 0
exit 0
------- END --------
Hope this helps.
--
Brandon Myers
bmyers@rucs2.sunlab.cs.runet.edu