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