[BACK]Return to unix_auth.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / tcfs

Annotation of src/usr.bin/tcfs/unix_auth.c, Revision 1.1.1.1

1.1       provos      1: /*
                      2:  *     Transparent Cryptographic File System (TCFS) for NetBSD
                      3:  *     Author and mantainer:   Luigi Catuogno [luicat@tcfs.unisa.it]
                      4:  *
                      5:  *     references:             http://tcfs.dia.unisa.it
                      6:  *                             tcfs-bsd@tcfs.unisa.it
                      7:  */
                      8:
                      9: /*
                     10:  *     Base utility set v0.1
                     11:  */
                     12:
                     13: #include <stdio.h>
                     14: #include <unistd.h>
                     15: #include <sys/param.h>
                     16: #include <limits.h>
                     17: #include <string.h>
                     18: #include <pwd.h>
                     19:
                     20: #include <miscfs/tcfs/tcfs.h>
                     21: #include "tcfslib.h"
                     22: #include "tcfserrors.h"
                     23:
                     24: int
                     25: unix_auth (char **user, char **password, int flag)
                     26: {
                     27:        char *luser, *passwd;
                     28:        struct passwd *passentry;
                     29:
                     30:        luser = (char*)calloc (LOGIN_NAME_MAX, sizeof(char));
                     31:        passwd = (char*)calloc (_PASSWORD_LEN, sizeof(char));
                     32:
                     33:        if (!luser || !passwd)
                     34:                tcfs_error (ER_MEM, NULL);
                     35:
                     36:        if (flag) {
                     37:                passentry = getpwuid(getuid());
                     38:                strlcpy(luser, passentry->pw_name, LOGIN_NAME_MAX);
                     39:        } else {
                     40:                printf ("Enter user: ");
                     41:                fgets(luser, LOGIN_NAME_MAX, stdin);
                     42:                luser[strlen(luser)-1] = '\0';
                     43:                passentry = getpwnam(luser);
                     44:        }
                     45:
                     46:        passwd = getpass("Password:");
                     47:
                     48:        if (passentry == NULL) {
                     49:                bzero (passwd, strlen(passwd));
                     50:                return 0;
                     51:        }
                     52:
                     53:        if (strcmp(crypt(passwd, passentry->pw_passwd), passentry->pw_passwd))
                     54:                return (0);
                     55:
                     56:        *user = luser;
                     57:        *password = passwd;
                     58:
                     59:        return (1);
                     60: }