d9898ee8 |
1 | #ifndef courierauthsasl_h |
2 | #define courierauthsasl_h |
3 | |
4 | /* |
5 | ** Copyright 1998 - 2004 Double Precision, Inc. See COPYING for |
6 | ** distribution information. |
7 | */ |
8 | |
9 | #include "courier_auth_config.h" |
10 | #include <sys/types.h> |
11 | |
12 | #ifdef __cplusplus |
13 | extern "C" { |
14 | #endif |
15 | |
0fde1ce3 |
16 | static const char courierauthsasl_h_rcsid[]="$Id: courierauthsasl.h,v 1.2 2008/06/29 16:39:25 mrsam Exp $"; |
d9898ee8 |
17 | |
18 | /* |
19 | These family of functions are used to implement the SASL interface |
20 | on top of authlib. It is mainly used by the authentication user |
21 | process to build the authentication request data for authmod() |
22 | based upon the SASL challenge/response interaction. |
23 | */ |
24 | |
25 | /* |
0fde1ce3 |
26 | ** auth_sasl searches for the right method, and calls the appropriate |
d9898ee8 |
27 | ** sasl function. authsasl received the following arguments: |
28 | ** |
29 | ** initresponse -- initial response for the authentication request, |
30 | ** if provided. If provided, the actual response MUST BE PROVIDED |
31 | ** in initresponse using base64 encoding!!! |
32 | ** |
33 | ** sasl_func -- the callback function which is used to carry out the |
34 | ** SASL conversation. The function receives a single argument, the |
35 | ** base64-encoded challenge. The callback function must return |
36 | ** a malloced pointer to the base64-encoded response, or NULL to abort |
37 | ** SASL. |
38 | ** |
39 | ** authsasl returns two values, provided via call by reference: |
40 | ** the authtype and authdata, suitable for direct arguments to |
41 | ** auth_generic(). |
42 | */ |
43 | |
44 | int auth_sasl(const char *, /* Method */ |
45 | const char *, /* Initial response - base64encoded */ |
46 | char *(*)(const char *, void *), |
47 | /* Callback conversation functions */ |
48 | void *, /* Passthrough arg */ |
49 | char **, /* Returned - AUTHTYPE */ |
50 | char **); /* Returned - AUTHDATA */ |
51 | |
0fde1ce3 |
52 | /* |
53 | ** auth_sasl_ex() is a version of auth_sasl that takes an extra parameter, |
54 | ** externalauth. If method is "EXTERNAL" and externalauth is not a NULL pointer |
55 | ** and does not point to an empty string, it is recognized as a SASL EXTERRNAL |
56 | ** authentication. |
57 | */ |
58 | |
59 | int auth_sasl_ex(const char *method, |
60 | const char *initresponse, |
61 | const char *externalauth, /* out-of-band authentified identity */ |
62 | char *(*callback_func)(const char *, void *), |
63 | void *callback_arg, |
64 | char **authtype_ptr, |
65 | char **authdata_ptr); |
d9898ee8 |
66 | |
67 | /* INTERNAL FUNCTIONS BELOW */ |
68 | |
69 | /* |
70 | ** The authsasl_info is built dynamically by configure, it lists the supported |
71 | ** SASL methods. Each method is implemented by a function that's prototyped |
72 | ** like this: |
73 | ** |
74 | ** int authsasl_function(const char *method, const char *initresponse, |
75 | ** char *(*getresp)(const char *), |
76 | ** |
77 | ** char **authtype, |
78 | ** char **authdata) |
79 | ** |
80 | ** Normally, there's no need to call the appropriate function directly, as |
81 | ** authsasl() automatically searches this array, and finds one. |
82 | ** |
83 | */ |
84 | |
85 | struct authsasl_info { |
86 | const char *sasl_method; /* In uppercase */ |
87 | int (*sasl_func)(const char *method, const char *initresponse, |
88 | char *(*getresp)(const char *, void *), |
89 | void *, |
90 | char **, |
91 | char **); |
92 | } ; |
93 | |
94 | extern struct authsasl_info authsasl_list[]; |
95 | /* Some convenience functions */ |
96 | |
97 | char *authsasl_tobase64(const char *, int); |
98 | int authsasl_frombase64(char *); |
99 | |
100 | /* Return values from authsasl */ |
101 | |
102 | #define AUTHSASL_OK 0 |
103 | #define AUTHSASL_ERROR -1 /* |
104 | ** System error, usually malloc failure, |
105 | ** authsasl reports the error to stderr. |
106 | */ |
107 | |
108 | #define AUTHSASL_ABORTED -2 /* |
109 | ** SASL exchange aborted. authsasl does NOT |
110 | ** report any errors. |
111 | */ |
112 | |
113 | #ifdef __cplusplus |
114 | } |
115 | #endif |
116 | |
117 | #endif |