Merge branch 'upstream' into debian
[hcoop/debian/courier-authlib.git] / authldap.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 <ctype.h>
12#include <string.h>
13#include <errno.h>
14
15#include "auth.h"
16#include "authldap.h"
17#include "authstaticlist.h"
18#include "courierauthdebug.h"
19
20static const char rcsid[]="$Id: authldap.c,v 1.22 2005/03/20 19:10:30 mrsam Exp $";
21
22extern void auth_ldap_enumerate( void(*cb_func)(const char *name,
23 uid_t uid,
24 gid_t gid,
25 const char *homedir,
26 const char *maildir,
27 const char *options,
28 void *void_arg),
29 void *void_arg);
30
31static int auth_ldap_login(const char *service, char *authdata,
32 int (*callback_func)(struct authinfo *, void *),
33 void *callback_arg)
34{
35 const char *user, *pass;
36
37 if ((user=strtok(authdata, "\n")) == 0 ||
38 (pass=strtok(0, "\n")) == 0)
39 {
40 DPRINTF("incomplete authentication data");
41 errno=EPERM;
42 return (-1);
43 }
44
45 return authldapcommon(service, user, pass, callback_func,
46 callback_arg);
47}
48
49#if HAVE_HMACLIB
50
51#include "libhmac/hmac.h"
52#include "cramlib.h"
53
54static int auth_ldap_cram(const char *service,
55 const char *authtype, char *authdata,
56 int (*callback_func)(struct authinfo *, void *),
57 void *callback_arg)
58{
59 struct cram_callback_info cci;
60
61 if (auth_get_cram(authtype, authdata, &cci))
62 return (-1);
63
64 cci.callback_func=callback_func;
65 cci.callback_arg=callback_arg;
66
67 return authldapcommon(service, cci.user, 0, &auth_cram_callback, &cci);
68}
69#endif
70
71int auth_ldap(const char *service, const char *authtype, char *authdata,
72 int (*callback_func)(struct authinfo *, void *),
73 void *callback_arg)
74{
75 if (strcmp(authtype, AUTHTYPE_LOGIN) == 0)
76 return (auth_ldap_login(service, authdata,
77 callback_func, callback_arg));
78
79#if HAVE_HMACLIB
80 return (auth_ldap_cram(service, authtype, authdata,
81 callback_func, callback_arg));
82#else
83 errno=EPERM;
84 return (-1);
85#endif
86}
87
88
89extern int auth_ldap_pre(const char *userid, const char *service,
90 int (*callback)(struct authinfo *, void *),
91 void *arg);
92
93extern int auth_ldap_changepw(const char *, const char *, const char *,
94 const char *);
95
96static struct authstaticinfo authldap_info={
97 "authldap",
98 auth_ldap,
99 auth_ldap_pre,
100 authldapclose,
101 auth_ldap_changepw,
102 authldapclose,
103 auth_ldap_enumerate};
104
105
106struct authstaticinfo *courier_authldap_init()
107{
108 return &authldap_info;
109}