View Single Post
  #3  
Old 19th April 2007, 19:13
cfajohnson cfajohnson is offline
Junior Member
 
Join Date: Apr 2007
Location: Toronto, Canada
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default


Most of what you are doing can be done with useradd itself. Read the man page.

The (moderately) tricky part is encrypting the password. I use a compiled C program as a front end to crypt(3):

/********************************
NAME: crypt.c
AUTHOR: Chris F.A. Johnson
DATE: 2003-01-23
********************************/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>

int
main(int argc, char *argv[])
{
char *passwd;
char buf[1024];
char *salt;

if (argc > 1)
{
salt = argv[1];
puts(salt);
}
else
{
/* salt = "$1$!@#$%^&*"; */
salt = NULL;
}

fgets(buf,sizeof(buf),stdin);
if ( buf[strlen(buf)-1] == '\n' )
{
buf[strlen(buf) - 1] = '\0';
}
printf( "%s\n", encrypt(buf, salt));

return 0;
}
/********************************/

Do not use vi in a script. Describe what you want to do, and script it directly.
Reply With Quote