From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fee84,23011c8812c1d8db X-Google-Attributes: gidfee84,public X-Google-Thread: f678f,23011c8812c1d8db X-Google-Attributes: gidf678f,public From: Bob Mazanec Subject: Re: Password maint. scripts Date: 1997/06/19 Message-ID: <33A95E4C.15FB@healthcare.com>#1/1 X-Deja-AN: 251133576 References: <5o6h15$i40$1@ancud.chilesat.net> Organization: Healthcare Communications, Inc. Newsgroups: comp.unix.osf.misc,comp.unix.osf.osf1 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? # 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?