1 /* $Id: authsasl.c,v 1.5 2008/07/10 02:43:55 mrsam Exp $ */
4 ** Copyright 1998 - 2008 Double Precision, Inc. See COPYING for
5 ** distribution information.
8 #include "courier_auth_config.h"
9 #include "courierauthsasl.h"
10 #include "authsaslclient.h"
16 /* Use the SASL_LIST macro to build authsasl_list */
18 #define NO_SERVER_FUNC()
20 #define SERVER_FUNC(b) int b(const char *, const char *, \
21 char *(*)(const char *, void *), \
32 #define SERVER_FUNC(n) n
35 #define NO_SERVER_FUNC() 0
37 #define SASL(a,b,c) {a, b},
39 struct authsasl_info authsasl_list
[] = {
45 int auth_sasl(const char *method
,
46 const char *initreply
,
47 char *(*callback_func
)(const char *, void *),
49 char **authtype_ptr
, /* Returned - AUTHTYPE */
55 if ((p
=malloc(strlen(method
)+1)) == 0)
59 *q
=toupper((int)(unsigned char)*q
);
61 for (i
=0; authsasl_list
[i
].sasl_method
; i
++)
63 if (strcmp(p
, authsasl_list
[i
].sasl_method
) == 0 &&
64 authsasl_list
[i
].sasl_func
)
67 return ( (*authsasl_list
[i
].sasl_func
)
69 initreply
, callback_func
,
71 authtype_ptr
, authdata_ptr
));
76 return (AUTHSASL_ERROR
);
79 int auth_sasl_ex(const char *method
,
80 const char *initresponse
,
81 const char *externalauth
,
82 char *(*callback_func
)(const char *, void *),
84 char **authtype_ptr
, /* Returned - AUTHTYPE */
90 if (strcmp(method
, "EXTERNAL"))
91 return auth_sasl(method
, initresponse
, callback_func
,
96 if (initresponse
&& *initresponse
)
97 return AUTHSASL_ERROR
;
99 if (!externalauth
|| !*externalauth
)
100 return AUTHSASL_ERROR
;
104 uid
=callback_func("", callback_arg
);
109 return (AUTHSASL_ABORTED
);
112 n
=authsasl_frombase64(uid
);
117 return AUTHSASL_ABORTED
;
124 return AUTHSASL_ABORTED
;
129 if ((*authtype_ptr
=strdup("EXTERNAL")) == NULL
)
130 return AUTHSASL_ABORTED
;
132 if ((*authdata_ptr
=strdup(externalauth
)) == NULL
)
135 return AUTHSASL_ABORTED
;