Hey --

I was getting cvs server set up with custom password (i.e. using
CVSROOT/passwd) and wanted to make CVS passwords different from regular
login password. The docs said the only way to specify passwords was to
copy and paste them from /etc/passwd -- but this is exactly what i was
trying to avoid.

So I wrote this tiny little program that crypts a password, which then
can be read into CVSROOT/passwd (say, "r !crypt mypass" in vi).... I am
running Red Hat 6.1, and the code makes use of new md5 password
crypting.

Hope this is useful.

-- Kostya

/*

 Crypts a password given on the command line.
 
 Compile:   gcc -o cryptpw cryptpw.c -lcrypt
 Use:       cryptpw mypassword
 
 [EMAIL PROTECTED]
 
*/


#include <crypt.h>
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <time.h>

char get_salt ()
{
    long r;
    int  c;
    
    while (1)
    {
        r = random () / (RAND_MAX / 127);
        c = (int) r;
        if (isalnum (c))
            return c;
    }
}

int main(int argc, char **argv)
{
    char *password;
    char *encrypted;
    char  salt[12]; /* "$1$y1234567\0" */
    int   i;

    if (argc != 2)
    {
        printf ("Usage: cryptpw password\n");
        return 1;
    }
    
    salt[0] = '$';
    salt[1] = '1';
    salt[2] = '$';
    
    srandom (time (NULL));
    
    for (i = 3; i < 11; ++ i)
        salt[i] = get_salt ();

    salt[11] = '\0';

    password = argv[1];
    encrypted = crypt(password, salt);

    printf (
        "Password:  %s\n"
        "Salt:      %s\n"
        "Encrypted: %s\n",
          password, salt, encrypted);
    return 0;
}

Reply via email to