1 /*
2 ** Copyright 1998 - 2004 Double Precision, Inc. See COPYING for
3 ** distribution information.
4 */
5
6 #if HAVE_CONFIG_H
7 #include "courier_auth_config.h"
8 #endif
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <string.h>
12 #include <errno.h>
13 #include <pwd.h>
14 #if HAVE_UNISTD_H
15 #include <unistd.h>
16 #endif
17 #if HAVE_SHADOW_H
18 #include <shadow.h>
19 #endif
20 #include "auth.h"
21 #include "courierauthstaticlist.h"
22
23
24
25 extern int auth_shadow_pre(const char *userid, const char *service,
26 int (*callback)(struct authinfo *, void *),
27 void *arg);
28
29 extern void auth_pwd_enumerate( void(*cb_func)(const char *name,
30 uid_t uid,
31 gid_t gid,
32 const char *homedir,
33 const char *maildir,
34 const char *options,
35 void *void_arg),
36 void *void_arg);
37
38
auth_shadow(const char * service,const char * authtype,char * authdata,int (* callback_func)(struct authinfo *,void *),void * callback_arg)39 int auth_shadow(const char *service, const char *authtype, char *authdata,
40 int (*callback_func)(struct authinfo *, void *),
41 void *callback_arg)
42 {
43 const char *user, *pass;
44
45 if (strcmp(authtype, AUTHTYPE_LOGIN) ||
46 (user=strtok(authdata, "\n")) == 0 ||
47 (pass=strtok(0, "\n")) == 0)
48 {
49 errno=EPERM;
50 return (-1);
51 }
52
53 return auth_sys_common(&auth_shadow_pre, user, pass,
54 service, callback_func, callback_arg);
55 }
56
57
auth_shadow_cleanup()58 static void auth_shadow_cleanup()
59 {
60 #if HAVE_ENDPWENT
61
62 endpwent();
63 #endif
64
65 #if HAVE_ENDSPENT
66
67 endspent();
68 #endif
69 }
70
71 static struct authstaticinfo authshadow_info={
72 "authshadow",
73 auth_shadow,
74 auth_shadow_pre,
75 auth_shadow_cleanup,
76 auth_syspasswd,
77 auth_shadow_cleanup,
78 auth_pwd_enumerate,
79 };
80
81
courier_authshadow_init()82 struct authstaticinfo *courier_authshadow_init()
83 {
84 return &authshadow_info;
85 }
86