Usenet comp.unix.osf.osf1 (1992-2004)
 help / color / mirror / Atom feed
From: Bob Mazanec <mazanec@healthcare.com>
Subject: Re: Password maint. scripts
Date: 1997/06/19	[thread overview]
Message-ID: <33A95E4C.15FB@healthcare.com> (raw)
In-Reply-To: 5o6h15$i40$1@ancud.chilesat.net


When writing install scripts in Perl for v3.2, I used something like
this:


#####################################################################
# Name:         createNewUser
# Purpose:      Add a user to the sytem
# Args:         $user   = login to add
#               $passwd = password
#               $uid    = UID to add
#               $group  = Group name for $user
#               $gcos   = user info
#               $shell  = user's login shell

sub createNewUser {
    local( $user, $passwd, $uid, $group, $gcos, $shell ) = @_;

  
    open( ADDUSER, '| /usr/sbin/adduser > /dev/null 2>&1' )
    || &Die( 1, "cannot run adduser" );

    print "\tAdding $user; press Control-D to continue...\n";

    # adduser asks the following questions:
    #   what is the new user's login?
    #   what is the new user's UID?
    #   what is the new user's full name?
    #   what is the new user's login group?
    #   what other groups does the new user belong to?
    #   what is the base directory for the new user's home directory?
    #   do you want to edit the user's authentication file entry?
    #   <runs passwd, which reads /dev/tty directly -- this is why the
user
    #    must hit Ctrl-D>
    print ADDUSER "$user\n"
                . "$uid\n"
                . "$gcos\n"
                . "$group\n"
                . "\n"
                . "/home\n"
                . "$shell\n"
		. "n\n";

    close ADDUSER;

    # Having created the user's entry in /etc/passwd, use vipw
    # to find the entry and hammer the password:
    &runVipw( "/^${user}:", "s/:[^:]*:/:${passwd}:/" );
}


#####################################################################
# Name:         runVipw
# Purpose:      Run vipw and send a sequence of commands at it
# Args:         @cmds   = vipw commands

sub runVipw {
    local( @cmds ) = @_;
    die "runVipw requires a command list" unless @cmds;
    local( $cmds ) = join( "\n", @cmds );

    local( $ENV{ 'EDITOR' }) = '/usr/bin/ex';
    local( $ENV{ 'TERM'   }) = 'dumb';

    open( VIPW, "| /usr/sbin/vipw > /dev/null 2>&1" )
    || &Die( 1, "cannot run vipw: $!" );
    print VIPW "$cmds\n";                           # caller's commands
    print VIPW "x\n";                               # exit
    close VIPW;
}

Icky, but true ;-)
bob

-- 
Bob Mazanec				mailto:mazanec@healthcare.com
Sr. Software Engineer			972/851-7033
Healthcare Communications, Inc.		970/249-8510
http://www.healthcare.com
Disclaimer: You think they _pay_ me to say this stuff?



      reply	other threads:[~1997-06-19  4:00 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-06-17  4:00 Password maint. scripts Eulogio Robles P.
1997-06-19  4:00 ` Bob Mazanec [this message]
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox