PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : user in passwd eintragen



waldi
18-03-2002, 19:22
hi leute!
ich hab ne liste von paar hundert usern den ich einen account auf meinem server eintragen will.
abei ist usernahme und password jefalls durch -#- getrennt.
Ich hab das mit ner while schleife und useradd probiert.
mein problem ist nur das useradd verschlüsselte pwds haben will und nicht unverschlüsselt wie sie in meiner liste sind.

Wie kann ich ein C prog schreiben das die liste ausliest und die user hinzufügt.

BITTE helft mir!

Gruß martin

SeeksTheMoon
18-03-2002, 20:15
Dir hilft sicher die /usr/lib/bcc/include/pwd.h

anda_skoa
19-03-2002, 11:37
oder man 3 crypt

Ciao,
_

waldi
19-03-2002, 16:54
hi leute!
ich hab erstmal versucht das ganze mit crypt auszubauen.
ich habe die <unistd.h> includiert wenn aber die funktiuon crypt(test, out);
kommt meint gcc undefined reference to 'crypt'
Waran liegt das??

Gruß martin

tkortkamp
19-03-2002, 18:46
Hi!

Die crypt-Funktion ist in der Bibliothek libcrypt. Sie ist im Header crypt.h deklariert. Du musst also crypt.h inkludieren und dein Programm mit -lcrypt übersetzen.

c ya,
Tobias

anda_skoa
19-03-2002, 19:24
Genauer gesagt, mit der crypt Bibliothek linken.

undefined reference ist eine Fehlermeldung des Linkers.

Lösung siehe voriges Posting.

Ciao,
_

waldi
20-03-2002, 15:02
Danke erstmal!
ich bekomme aber immer einen segmentation failed wenn ich das prog versuche zu starteten.

könnt ihr mir mal ein ganz einfaches beseispiel für diese crypt funktion posten.

Danke!!!

martin

tkortkamp
20-03-2002, 17:33
Diese beiden Beispiele habe ich auf Metalshell (http://www.metalshell.com) gefunden.



/* crypt.c written by detour@metalshell.com
*
* example of using the crypt lib to encrypt
* a plain text password, entered at runtime.
*
* remember to compile with -lcrypt
* gcc -lcrypt -o crypt crypt.c
*
* http://www.metalshell.com/
*
*/

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>

char *crypt(const char *key, const char *salt);
extern char *getpass();

int main() {
char rndChar[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwx yz0123456789./";
char salt[3];
char *password;

/* Seed the random timer */
srandom(time(0));

/* Random salt. (First two char's of the encrypted string) */
salt[0] = rndChar[random() % 64];
salt[1] = rndChar[random() % 64];
salt[3] = 0;

/* getpass() turns off character echoing and disables
signals by special characters */
password = getpass("Password: ");

printf("%s\n", crypt(password, salt));
}




/* decrypt.c written by detour@metalshell.com
*
* example of using the crypt lib to decrypt
* a DES password encrypted with crypt()
*
* remember to compile with -lcrypt
* gcc -lcrypt -o decrypt decrypt.c
*
* http://www.metalshell.com/
*
*/

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>

char *crypt(const char *key, const char *salt);
extern char *getpass();

void stripnl(char *str);

int main() {
char salt[3];
char *password;
char encpasswd[15];

/* Get the password that was encrypted using crypt */
printf("Enter encrypted password string: ");
fgets(encpasswd, sizeof(encpasswd), stdin);
stripnl(encpasswd);

/* Extract the salt from the encrypted password */
salt[0] = encpasswd[0];
salt[1] = encpasswd[1];
salt[2] = 0;

/* Get the plain text password, encrypt it with the same
salt and then compare them. */
password = getpass("Enter the password: ");
if(!strcmp(crypt(password, salt), encpasswd))
printf("Password validated.\n");
else printf("Password not valid.\n");

}

void stripnl(char *str) {
while(strlen(str) && ( (str[strlen(str) - 1] == 13) ||
( str[strlen(str) - 1] == 10 ))) {
str[strlen(str) - 1] = 0;
}
}


c ya,
Tobias