Marc,
This should do what Jon is looking for if I understand correctly. Unfortunately, the
only CVS machines I have access to are on Solaris, so I haven't been able to test it
on Linux. Should be the same, though...
Please read the commented text and let me know if you think something should be
changed... It is for Perl 5.
- jeremiah
#!/usr/local/bin/perl
# This script is very basic, not much error check or very robust. It is
# specifically for adding a new user and crypted password to the CVS
# password file. It requires that the password file is in the format
# $NEW_USER:$CIPHER_PASSWORD:$LOCAL_USER
#
# Execute this script with two command-line arguments: username and password.
# Perl will use the crypt function to encrypt the password and then will
# add the new user information to the end of the password file. If a user
# is already in the password file with the given username, then the program
# will stop and do nothing.
#
# The script needs to be edited appropriately for use on a new system.
# Specifically, the default CVSROOT needs to be specified and the name of
# the local user needs to be specified.
#
# Note that if the debug flag is off (set to 0), then there will not be
# any output unless something fails. If you turn debugging on, then it
# is directly verbose output.
#
# Please change the following vars appropriately.
#
$CVS_ROOT = "/home/jjohnson/test";
$CVS_PASSWD = "passwd"; # name of CVS password file
$LOCAL_USER = "jjohnson";
$CRYPT_SALT = "jBoss"; # only first two characters used
$DEBUG_FLAG = 0; # 1 / 0 to turn debugging ON or OFF
#
# Shouldn't need to change anything below here...
#
if( $DEBUG_FLAG ) { print "CVSROOT: $CVSROOT\nLOCAL_USER: $LOCAL_USER\n"; }
if( @ARGV != 2 ) {
print "Usage: $0 {username} {password}\n";
print "Note: there is _no_ output unless something fails.\n";
exit 1;
}
$username = $ARGV[0];
$plaintext = $ARGV[1];
#
# Crypt the password using the global SALT.
#
$password = crypt( $plaintext, $CRYPT_SALT );
if( $DEBUG_FLAG ) { print "Plaintext: $plaintext\nPassword: $password\n"; }
#
# Open the password file, check for the username. Die if the username
# already exists; otherwise, add the new line at the end.
#
if( $DEBUG_FLAG ) { print "Openning $CVS_ROOT/$CVS_PASSWD\n"; }
# check for the username
unless( open(PASSWD, "<$CVS_ROOT/$CVS_PASSWD") ) {
print "Failed to open the current password file.\n";
exit 1;
}
$existsFlag = 0;
while( <PASSWD> ) {
if( /^$username/ ) {
$existsFlag = 1;
}
}
close( PASSWD );
if( $existsFlag ) {
print "User already exists in password file.\n";
exit 1;
}
# open the file again to append
unless( open(PASSWD, ">>$CVS_ROOT/$CVS_PASSWD") ) {
print "Failed to open the current password file.\n";
exit 1;
}
if( $DEBUG_FLAG ) {
print "Appending passwd with: $username:$password:$LOCAL_USER\n";
}
print PASSWD "$username:$password:$LOCAL_USER\n";
close( PASSWD );
#
# Finally, check the file one more time to make sure info was added.
#
unless( open(PASSWD, "<$CVS_ROOT/$CVS_PASSWD") ) {
print "Failed to open the current password file.\n";
exit 1;
}
$existsFlag = 0;
while( <PASSWD> ) {
if( /^$username:$password:$LOCAL_USER/ ) {
$existsFlag = 1;
}
}
close( PASSWD );
unless( $existsFlag ) {
print "New user not found, try again.\n";
exit 1;
}
if( $DEBUG_FLAG ) { print "Success\n"; }
______________________________________________
FREE Personalized Email at Mail.com
Sign up at http://www.mail.com/?sr=signup