Annotation of src/usr.bin/tcfs/unix_auth.c, Revision 1.2
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 <sys/param.h>
14: #include <limits.h>
1.2 ! fgsch 15: #include <pwd.h>
! 16: #include <stdio.h>
! 17: #include <stdlib.h>
1.1 provos 18: #include <string.h>
1.2 ! fgsch 19: #include <unistd.h>
1.1 provos 20:
21: #include <miscfs/tcfs/tcfs.h>
22: #include "tcfslib.h"
23: #include "tcfserrors.h"
24:
25: int
26: unix_auth (char **user, char **password, int flag)
27: {
28: char *luser, *passwd;
29: struct passwd *passentry;
30:
31: luser = (char*)calloc (LOGIN_NAME_MAX, sizeof(char));
32: passwd = (char*)calloc (_PASSWORD_LEN, sizeof(char));
33:
34: if (!luser || !passwd)
35: tcfs_error (ER_MEM, NULL);
36:
37: if (flag) {
38: passentry = getpwuid(getuid());
39: strlcpy(luser, passentry->pw_name, LOGIN_NAME_MAX);
40: } else {
41: printf ("Enter user: ");
42: fgets(luser, LOGIN_NAME_MAX, stdin);
43: luser[strlen(luser)-1] = '\0';
44: passentry = getpwnam(luser);
45: }
46:
47: passwd = getpass("Password:");
48:
49: if (passentry == NULL) {
50: bzero (passwd, strlen(passwd));
51: return 0;
52: }
53:
54: if (strcmp(crypt(passwd, passentry->pw_passwd), passentry->pw_passwd))
55: return (0);
56:
57: *user = luser;
58: *password = passwd;
59:
60: return (1);
61: }