*BSD News Article 69500


Return to BSD News archive

Path: euryale.cc.adfa.oz.au!newshost.anu.edu.au!harbinger.cc.monash.edu.au!news.mel.connect.com.au!munnari.OZ.AU!news.ecn.uoknor.edu!news.wildstar.net!cancer.vividnet.com!hunter.premier.net!bofh.dot!news.mathworks.com!newsfeed.internetmci.com!in2.uu.net!mayumi.iphil.net!map
From: map@marikit.iphil.net (Miguel A.L. Paraz)
Newsgroups: comp.unix.bsd.freebsd.misc
Subject: Re: Removing Users from FreeBSD 2.0
Date: 27 May 1996 07:27:40 GMT
Organization: IPhil Communications
Lines: 57
Message-ID: <slrn4qim1t.pol.map@marikit.iphil.net>
References: <4nvobf$dvu@news.starnet.net> <4nvuc8$622@atlas.uniserve.com> <slrn4qd93g.e7m.map@marikit.iphil.net>
Reply-To: map@iphil.net
NNTP-Posting-Host: marikit.iphil.net
X-Newsreader: slrn (0.8.6.1)

How about this script -- let's call it 'deluser'.
Very crude, though - and no consistency checks!

#!/usr/bin/perl
#
# delete a user by deleting from passwd, master.passwd, and
# rebuilding the database.

if ($#ARGV == -1)
{
    die ("username required.");
}

# Load the files, except for the required line.
open (H, "/etc/passwd");
while (<H>)
{
    /(.*?):/;
    push (@passwd, $_) if ($1 ne $ARGV[0]);
}
close (H);

open (H, "/etc/master.passwd");
while (<H>)
{
    /(.*?):/;
    push (@master_passwd, $_) if ($1 ne $ARGV[0]);
}
close (H);

# Make sure no one else is using the files.
# THIS IS THE TRICKY PART

# Back them up.
system ("/bin/cp /etc/passwd /etc/passwd.bak");
system ("/bin/cp /etc/master.passwd /etc/master.passwd.bak");

# Rewrite them.
open (H, ">/etc/passwd");
print H @passwd;
close (H);

open (H, ">/etc/master.passwd");
print H @master_passwd;
close (H);



-- 
miguel a.l. paraz <map@iphil.net>        iphil communications, makati city, 
tech problems, to <support@iphil.net>    philippines.