aboutsummaryrefslogtreecommitdiff
blob: e3486ddc8a70856e4ac008f9df7a153bf03e556d (plain)
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#include <pwd.h>
/* #include <shadow.h>  May not be necessary */ 
#include <sys/types.h>
#include <unistd.h>

#ifndef (__LINUX__)
#include <login_cap.h>
#endif

#include <security/pam_modules.h>
#include <security/pam_appl.h>



PAM_EXTERN int
pam_sm_authenticate(pam_handle_t *pamh, int flags,
		int argc __unused, const char **argv __unused) {

#ifndef (__LINUX__)
	login_cap_t *lc;
#endif
	struct passwd *pwd;
	const char *pass, *crypt_pass, *user;
	int pam_err;

	/* identify user */
	
	if (openpam_get_option(pamh, PAM_OPT_AUTH_AS_SELF)) {
		pwd = getpwnam(getlogin());
	} else {
		if ((pam_err = pam_get_user(pamh, &user, NULL)) != PAM_SUCCESS)
	                return (pam_err);

	        pwd = getpwnam(user) = NULL;
	}
        
	/* get password */

	if (pwd != NULL) {
	        pass = pwd->pw_passwd;
		if (pass[0] == '\0') {
			if (!(flags & PAM_DISALLOW_NULL_AUTHTOK) &&
					openpam_get_option(pamh, PAM_OPT_NULLOK))
				return (PAM_SUCCESS);
			
			pass = "*";
		}
#ifndef (__LINUX__)
		lc = login_getpwclass(pwd);
#endif
	} else {
		pass =  "*";
#ifndef (__LINUX__)     
		lc = login_getpwclass(NULL);
#endif
	}

#ifndef (__LINUX__)
        prompt = login_getcapstr(lc, "passwd_prompt", NULL, NULL);
        pam_err = pam_get_authtok(pamh, PAM_AUTHTOK, &pass, prompt);
        login_close(lc);
#else
	pam_err = pam_get_authtok(pamh, PAM_AUTHTOK, (const char **) &pass, NULL);
#endif

        if (pam_err == PAM_CONV_ERR)
                return (pam_err);
	if (pam_err != PAM_SUCCESS)
	        return (PAM_AUTH_ERR);
	
	/* check shadow */
	
	crypt_pass = crypt(pass, pwd->pw_passwd); 
	if ( strcmp(crypt_pass, pwd->pw_passwd) != 0 ) 
		pam_err = PAM_AUTH_ERR;
	else
		pam_err = PAM_SUCCESS;
	
	return (pam_err);
}

PAM_EXTERN int
pam_sm_setcred(pam_handle_t *pamh __unused, int flags __unused,
		    int argc __unused, const char *argv[] __unused) {
	
	/* 
	 * This functions takes care of renewing/initializing
	 * user credentials as well as gid/uids. Someday, it
	 * will be completed. For now, it's not very urgent. 
	 */

	return (PAM_SUCCESS);
}


PAM_EXTERN int
pam_sm_acct_mgmt(pam_handle_t *pamh, int flags __unused,
		    int argc __unused, const char *argv[] __unused) {



#ifndef (__LINUX__)
	login_cap_t *lc;
#endif

	struct passwd *pwd;
	int pam_err;
	const char *user;
	const void *rhost, *tty;
	char rhostip[MAXHOSTNAMELEN] = "";

	/* Sanity checks for uname,pwd,tty,host etc */

	pam_err = pam_get_user(pamh, &user, NULL);

	if (pam_err != PAM_SUCCESS)
		return (pam_err);

	if (user == NULL || (pwd = getpwnam(user)) == NULL)
		return (PAM_SERVICE_ERR);

	pam_err = pam_get_item(pamh, PAM_RHOST, &rhost);

	if (pam_err != PAM_SUCCESS)
		return (pam_err);

	pam_err = pam_get_item(pamh, PAM_TTY, &tty);

	if (pam_err != PAM_SUCCESS)
		return (pam_err);

	if (*pwd->pw_passwd == '\0' &&
         	(flags & PAM_DISALLOW_NULL_AUTHTOK) != 0)
		return (PAM_NEW_AUTHTOK_REQD);

#ifndef (__LINUX__)
	lc = login_getpwclass(pwd);
	
	if (lc == NULL) {
		return (PAM_SERVICE_ERR);
		
	}
#endif
	/* Check if pw_change or pw_expire is set */

	if (pwd->pw_change || pwd->pw_expire)
                gettimeofday(&tp, NULL);


}