0
|
1 /*
|
|
2 Loosely based on auth_passwd.c from popa3d by
|
|
3 Solar Designer <solar@openwall.com>
|
|
4
|
|
5 Copyright (C) 2002 Timo Sirainen
|
|
6 */
|
|
7
|
|
8 #define _XOPEN_SOURCE 4
|
|
9 #define _XOPEN_SOURCE_EXTENDED
|
|
10 #define _XPG4_2
|
|
11
|
|
12 #include "common.h"
|
|
13
|
|
14 #ifdef USERINFO_PASSWD
|
|
15
|
|
16 #include "userinfo.h"
|
|
17 #include "userinfo-passwd.h"
|
|
18
|
|
19 #include <unistd.h>
|
|
20
|
|
21 void passwd_fill_cookie_reply(struct passwd *pw, AuthCookieReplyData *reply)
|
|
22 {
|
|
23 i_assert(sizeof(reply->user) > strlen(pw->pw_name));
|
|
24 i_assert(sizeof(reply->home) > strlen(pw->pw_dir));
|
|
25
|
|
26 reply->uid = pw->pw_uid;
|
|
27 reply->gid = pw->pw_gid;
|
|
28
|
|
29 strcpy(reply->user, pw->pw_name);
|
|
30 strcpy(reply->home, pw->pw_dir);
|
|
31 }
|
|
32
|
|
33 static int passwd_verify_plain(const char *user, const char *password,
|
|
34 AuthCookieReplyData *reply)
|
|
35 {
|
|
36 struct passwd *pw;
|
|
37 char *passdup;
|
|
38 int result;
|
|
39
|
|
40 pw = getpwnam(user);
|
|
41 if (pw == NULL || !IS_VALID_PASSWD(pw->pw_passwd))
|
|
42 return FALSE;
|
|
43
|
|
44 /* check if the password is valid */
|
|
45 passdup = (char *) t_strdup(password);
|
|
46 result = strcmp(crypt(passdup, pw->pw_passwd), pw->pw_passwd) == 0;
|
|
47
|
|
48 /* clear the passwords from memory */
|
|
49 memset(passdup, 0, strlen(passdup));
|
|
50 memset(pw->pw_passwd, 0, strlen(pw->pw_passwd));
|
|
51
|
|
52 if (!result)
|
|
53 return FALSE;
|
|
54
|
|
55 /* password ok, save the user info */
|
|
56 passwd_fill_cookie_reply(pw, reply);
|
|
57 return TRUE;
|
|
58 }
|
|
59
|
|
60 static void passwd_deinit(void)
|
|
61 {
|
|
62 endpwent();
|
|
63 }
|
|
64
|
|
65 UserInfoModule userinfo_passwd = {
|
|
66 NULL,
|
|
67 passwd_deinit,
|
|
68
|
|
69 passwd_verify_plain,
|
|
70 NULL
|
|
71 };
|
|
72
|
|
73 #endif
|