release
[hcoop/debian/courier-authlib.git] / authshadow.c
CommitLineData
d9898ee8 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 "authstaticlist.h"
22
23static const char rcsid[]="$Id: authshadow.c,v 1.15 2004/11/14 02:58:16 mrsam Exp $";
24
25
26extern int auth_shadow_pre(const char *userid, const char *service,
27 int (*callback)(struct authinfo *, void *),
28 void *arg);
29
30extern void auth_pwd_enumerate( void(*cb_func)(const char *name,
31 uid_t uid,
32 gid_t gid,
33 const char *homedir,
34 const char *maildir,
35 const char *options,
36 void *void_arg),
37 void *void_arg);
38
39
40int auth_shadow(const char *service, const char *authtype, char *authdata,
41 int (*callback_func)(struct authinfo *, void *),
42 void *callback_arg)
43{
44 const char *user, *pass;
45
46 if (strcmp(authtype, AUTHTYPE_LOGIN) ||
47 (user=strtok(authdata, "\n")) == 0 ||
48 (pass=strtok(0, "\n")) == 0)
49 {
50 errno=EPERM;
51 return (-1);
52 }
53
54 return auth_sys_common(&auth_shadow_pre, user, pass,
55 service, callback_func, callback_arg);
56}
57
58
59static void auth_shadow_cleanup()
60{
61#if HAVE_ENDPWENT
62
63 endpwent();
64#endif
65
66#if HAVE_ENDSPENT
67
68 endspent();
69#endif
70}
71
72static struct authstaticinfo authshadow_info={
73 "authshadow",
74 auth_shadow,
75 auth_shadow_pre,
76 auth_shadow_cleanup,
77 auth_syspasswd,
78 auth_shadow_cleanup,
79 auth_pwd_enumerate,
80};
81
82
83struct authstaticinfo *courier_authshadow_init()
84{
85 return &authshadow_info;
86}