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