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