diff options
author | green <green@FreeBSD.org> | 2000-08-22 02:15:54 +0000 |
---|---|---|
committer | green <green@FreeBSD.org> | 2000-08-22 02:15:54 +0000 |
commit | 67c40ef892e23a375a1eeec51d343ef6be31f5d8 (patch) | |
tree | 7fd6719b0a54565971e388646c8ae7f62b08674b /lib/libcrypt/crypt.c | |
parent | 219e29595a8d293c1e81f0136a866f25a69d648e (diff) | |
download | FreeBSD-src-67c40ef892e23a375a1eeec51d343ef6be31f5d8.zip FreeBSD-src-67c40ef892e23a375a1eeec51d343ef6be31f5d8.tar.gz |
Add working and easy crypt(3)-switching. Yes, we need a whole new API
for crypt(3) by now. In any case:
Add crypt_set_format(3) + documentation to -lcrypt.
Add login_setcryptfmt(3) + documentation to -lutil.
Support for switching crypt formats in passwd(8).
Support for switching crypt formats in pw(8).
The simple synopsis is:
edit login.conf; add a passwd_format field set to "des" or "md5"; go nuts :)
Reviewed by: peter
Diffstat (limited to 'lib/libcrypt/crypt.c')
-rw-r--r-- | lib/libcrypt/crypt.c | 57 |
1 files changed, 50 insertions, 7 deletions
diff --git a/lib/libcrypt/crypt.c b/lib/libcrypt/crypt.c index e040be1..7a61b42 100644 --- a/lib/libcrypt/crypt.c +++ b/lib/libcrypt/crypt.c @@ -34,14 +34,57 @@ static char rcsid[] = "$FreeBSD$"; #include <string.h> #include "crypt.h" +static const struct { + const char *const name; + char *(*const func)(const char *, const char *); + const char *const magic; +} crypt_types[] = { + { + "des", + crypt_des, + NULL + }, + { + "md5", + crypt_md5, + "$1$" + }, + { + NULL, + NULL + } +}; + +static int crypt_type = 0; + +const char * +crypt_get_format(void) { + + return (crypt_types[crypt_type].name); +} + +int +crypt_set_format(char *type) { + int i; + + for (i = 0; i < sizeof(crypt_types) / sizeof(crypt_types[0]) - 1; i++) { + if (strcmp(type, crypt_types[i].name) == 0) { + crypt_type = i; + return (1); + } + } + return (0); +} + char * crypt(char *passwd, char *salt) { - if (!strncmp(salt, "$1$", 3)) - return crypt_md5(passwd, salt); -#ifdef NONEXPORTABLE_CRYPT - return crypt_des(passwd, salt); -#else - return crypt_md5(passwd, salt); -#endif + int i; + + for (i = 0; i < sizeof(crypt_types) / sizeof(crypt_types[0]) - 1; i++) { + if (crypt_types[i].magic != NULL && strncmp(salt, + crypt_types[i].magic, strlen(crypt_types[i].magic)) == 0) + return (crypt_types[i].func(passwd, salt)); + } + return (crypt_types[crypt_type].func(passwd, salt)); } |