[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: some more little bugs in 0.91



> Mike:
>    Even after changing permissions/ownership from
>      -rwxr-xr-x   1 root     bin          9220 Dec 12 00:14 movemail*
>    to
>      -rwxr-sr-x   1 root     mail         9220 Dec 12 00:14 movemail*
>    the problem still occurs.  The problem manifests itself as an emacs
>    error message: "Renaming: permission denied,
>    /var/spool/mail/deisher, /var/spool/mail/deisher+".  
> 
> Check /var/spool/mail/deisher, it should be
> -rw-rw----   1 deisher  mail        

Aha!  That's it.  Thanks for pointing that out.  The culprit is the
adduser script!  Here's a fixed version:

#! /bin/sh
#
# adduser 1.0: a utility to add users to the system
#
# Copyright (C) 1994 Ian A. Murdock <imurdock@shell.portal.com>
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
# Written for the Debian Linux distribution (01/21/94).  Feel free to use
# it in YOUR distribution, too. :)  Please note that this is just a simple
# script that _somewhat_ automates the really boring and repetitive task
# of creating new user accounts.  It makes no attempt to be sophisticated.
# Let me know if you improve it in any way.
#
# I need to write a man page for this.

# Everything happens too fast, so don't let the user interrupt.
trap "" 1 2 3 15

# Set a few important variables before getting started.
NUMARG=$#
LOGIN="$1"
EXIST=0

PASSWD="/etc/passwd"
PBAK="/etc/passwd-"		# Some programs use /etc/passwd-, others use
				# /etc/passwd.OLD.  Take your pick.

MGID=12				# group id for mail files

PLOCK="/etc/ptmp"		# Standard method of locking the password file.
DEFAULTS="/etc/default/adduser"

# What do we do if $DEFAULTS doesn't exist? 
no_defaults ()
{
	DSHELL="/bin/bash"
	DHOME="/home"
	SKEL="/etc/skel"
	SPOOL="/var/spool/mail"
	FIRST_UID=100
	USERS_GID=100
}

# A few sanity checks...
if [ `whoami` != "root" ]; then
	echo "Only root may add users to the system." ; exit 1
fi

if [ $NUMARG = 0 ]; then
	echo "You need to specify the login to add; for example, \`adduser" \
		"imurdock'." ; exit 1
fi

id $LOGIN >/dev/null 2>/dev/null && EXIST=1

if [ $EXIST = 1 ]; then
	echo "The login $LOGIN already exists."
	exit 1
fi

if [ -f $PLOCK ]; then
	echo "$PASSWD is locked.  Try again later." ; exit 1
fi

# And now the program begins: 
if [ -f $DEFAULTS ]; then
	echo -n "Reading in $DEFAULTS..." ; source $DEFAULTS ; echo "done."
else
	echo "No defaults file found.  Using built-in defaults." ; no_defaults
fi

echo "" ; echo -n "Looking for first available UID..."
NUID=`cut -f 3 -d ":" /etc/passwd | sort -n | tail -1` ; NUID=`expr $NUID + 1`
if [ $NUID -lt $FIRST_UID ]; then
	NUID=$FIRST_UID
fi
NGID=$USERS_GID
echo "done.  Using UID $NUID and GID $NGID."

echo "" ; echo -n "Adding login: $LOGIN..."
touch $PLOCK ; cp $PASSWD $PBAK
echo "$LOGIN:x:$NUID:$NGID::$DHOME/$LOGIN:$DSHELL" >> /etc/passwd
rm -f $PLOCK
echo "done."

echo -n "Creating home directory: $DHOME/$LOGIN..."
mkdir $DHOME/$LOGIN
cp $SKEL/.* $SKEL/* $DHOME/$LOGIN >/dev/null 2>/dev/null
chown -R $NUID.$NGID $DHOME/$LOGIN
echo "done."

echo -n "Creating mailbox: $SPOOL/$LOGIN..."
touch $SPOOL/$LOGIN ; chmod 660 $SPOOL/$LOGIN ; chown $NUID.$MGID $SPOOL/$LOGIN
echo "done."

passwd $LOGIN
#chfn $LOGIN

# EOF



Reply to: