3 ** Copyright 1998 - 2013 Double Precision, Inc. See COPYING for
4 ** distribution information.
7 #include "courier_auth_config.h"
8 #include "courierauth.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 (!externalauth
|| !*externalauth
)
97 return AUTHSASL_ERROR
;
99 if (initresponse
&& !*initresponse
)
102 if (initresponse
&& strcmp(initresponse
, externalauth
))
103 return AUTHSASL_ERROR
;
107 uid
=callback_func("", callback_arg
);
112 return (AUTHSASL_ABORTED
);
115 n
=authsasl_frombase64(uid
);
120 return AUTHSASL_ABORTED
;
127 return AUTHSASL_ABORTED
;
132 if ((*authtype_ptr
=strdup("EXTERNAL")) == NULL
)
133 return AUTHSASL_ABORTED
;
135 if ((*authdata_ptr
=strdup(externalauth
)) == NULL
)
138 return AUTHSASL_ABORTED
;
144 char *auth_sasl_extract_userid(const char *authtype
,
145 const char *authdata
)
147 struct cram_callback_info cci
;
152 if (strcmp(authtype
, AUTHTYPE_LOGIN
) == 0)
166 if ((t
=strdup(authtype
)) == NULL
)
169 if ((d
=strdup(authdata
)) == NULL
)
175 if (auth_get_cram_silent(t
, d
, &cci
))