-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi,
Was there eny reason why you couldn't use getpwent/setpwent on
/etc/passwd?
- ----- Original Message -----
From:
Hi all!
Thanks for your help now I have a nice solution... It is a combination of the ideas of Dirk Jansen and Ralf Ronneburger - I added the c-source below. Maybe the security could be improved - I do a lot of plaintext-password-stuff in memory...Any suggestions? It would also be good the read the stdout/stderr of useradd and smbpasswd so that I could deal with errors and so on, but I am not yet sure how to realize that...
---
/* Little c-tool that creates a */ /* linux- and a samba-user "bar" (username) with using */ /* the 'useradd' and 'smbpasswd' command. */ /* For both users the password is set to "foo" (key). */
#define _XOPEN_SOURCE #include
#include #include #include #include #include #include #define SAMBA_USER 1 /* also want samba-user? */ #define bin_to_ascii(c) ((c)>=38?((c)-38+'a'):(c)>=12?((c)-12+'A'):(c)+'.')
int main() { time_t tm; char key[13]="foo"; char salt[2]; char username[64]="bar"; char useraddstr[256]="useradd -m -p "; //-p gives encrypted pass to useradd char popenstr[256]="smbpasswd -a -s "; //-s enables stdin FILE *fhd_w;
time(&tm); salt[0] = bin_to_ascii (tm & 0x3f); salt[1] = bin_to_ascii ((tm >> 6) & 0x3f);
strcat(useraddstr,crypt(key,salt)); if(!SAMBA_USER) strcpy(key, "010101010101010"); //erase key :) strcpy(salt,"010101010101010"); //erase salt :) strcat(useraddstr," "); strcat(useraddstr,username);
if(system(useraddstr) == 0 ) printf("Linux-User %s created.\n",username); else { printf("Error. No user created.\n"); exit(EXIT_FAILURE); }
if(SAMBA_USER) { strcat(popenstr,username);
printf("Creating Samba-User...\n"); if( (fhd_w = popen(popenstr,"w")) ==NULL ) printf("popen-error\n"); fprintf(fhd_w,"%s\n",key); //"enter" password :) fprintf(fhd_w,"%s\n",key); //confirm it pclose(fhd_w); strcpy(key, "010101010101010"); //erase key :) } exit(EXIT_SUCCESS); }
-- To unsubscribe, e-mail: suse-security-unsubscribe@suse.com For additional commands, e-mail: suse-security-help@suse.com Security-related bug reports go to security@suse.de, not here
-----BEGIN PGP SIGNATURE----- Version: PGP 7.1 iQA/AwUBPLLOKDyvc2N6Oeg+EQJ5xACfW3h47TPbIFumVy3xjt86Yqlr2q4An0xO sF2Ny1UhnWQw8fMZgZNMHmSh =Jph7 -----END PGP SIGNATURE-----