Import Debian changes 0.69.0-2
[hcoop/debian/courier-authlib.git] / authcustom.c
CommitLineData
d9898ee8 1/*
ac40fd9e 2** Copyright 1998 - 2008 Double Precision, Inc. See COPYING for
d9898ee8 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 "authcustom.h"
0e333c05 17#include "courierauth.h"
b0322a85 18#include "courierauthstaticlist.h"
0e333c05 19#include "libhmac/hmac.h"
d9898ee8 20
d9898ee8 21
22static int auth_custom_login(const char *service, char *authdata,
23 int (*callback_func)(struct authinfo *, void *),
24 int *callback_arg)
25{
26 const char *user, *pass;
27
28 if ((user=strtok(authdata, "\n")) == 0 ||
29 (pass=strtok(0, "\n")) == 0)
30 {
31 errno=EPERM;
32 return (-1);
33 }
34
35 return authcustomcommon(user, pass, callback_func, callback_arg);
36}
37
d9898ee8 38static int auth_custom_cram(const char *service,
39 const char *authtype,
40 char *authdata,
41 int (*callback_func)(struct authinfo *, void *),
42 void *callback_arg)
43{
44 struct cram_callback_info cci;
45
46 if (auth_get_cram(authtype, authdata, &cci))
47 return (-1);
48
49 cci.callback_func=callback_func;
50 cci.callback_arg=callback_arg;
51
52 return authcustomcommon(cci.user, 0, &auth_cram_callback, &cci);
53}
d9898ee8 54
55int auth_custom(const char *service, const char *authtype, char *authdata,
56 int (*callback_func)(struct authinfo *, void *),
57 void *callback_arg)
58{
59 if (strcmp(authtype, AUTHTYPE_LOGIN) == 0)
60 return (auth_custom_login(service, authdata,
61 callback_func, callback_arg));
62
d9898ee8 63 return (auth_custom_cram(service, authtype, authdata,
64 callback_func, callback_arg));
d9898ee8 65}
66
67
68extern int auth_custom_pre(const char *userid, const char *service,
69 int (*callback)(struct authinfo *, void *),
70 void *arg);
71
72static int auth_custom_chgpwd(const char *service,
73 const char *uid,
74 const char *oldpwd,
75 const char *newpwd)
76{
77 /*
78 ** Insert code to change the account's password here.
79 **
80 ** return 0 if changed.
81 **
82 ** return 1 if failed.
83 ** Set errno to EPERM if we had a temporary failure (such as invalid
84 ** old pwd).
85 **
86 ** Set errno to EINVAL if we failed because we did not recognize uid.
87 */
88
89 errno=EINVAL;
90 return (-1);
91}
92
93static void auth_custom_idle()
94{
95 /*
96 ** Insert code to temporarily deallocate resources after remaining
97 ** idle (as part of authdaemond) for more than 5 minutes.
98 */
99}
100
101static struct authstaticinfo authcustom_info={
102 "authcustom",
103 auth_custom,
104 auth_custom_pre,
105 authcustomclose,
106 auth_custom_chgpwd,
107 auth_custom_idle};
108
109
110struct authstaticinfo *courier_authcustom_init()
111{
112 return &authcustom_info;
113}