X-Git-Url: https://git.hcoop.net/hcoop/debian/courier-authlib.git/blobdiff_plain/0fde1ce3109f2259ded7e8bff8d2b1c984252bc0..01037b081eab5fb3f208489dc3e052ec3a2c8ba1:/authsasl.c diff --git a/authsasl.c b/authsasl.c index 42a932e..72c31ca 100644 --- a/authsasl.c +++ b/authsasl.c @@ -1,13 +1,13 @@ -/* $Id: authsasl.c,v 1.5 2008/07/10 02:43:55 mrsam Exp $ */ /* -** Copyright 1998 - 2008 Double Precision, Inc. See COPYING for +** Copyright 1998 - 2013 Double Precision, Inc. See COPYING for ** distribution information. */ #include "courier_auth_config.h" #include "courierauthsasl.h" #include "authsaslclient.h" +#include "cramlib.h" #include #include #include @@ -93,10 +93,13 @@ int auth_sasl_ex(const char *method, authtype_ptr, authdata_ptr); - if (initresponse && *initresponse) + if (!externalauth || !*externalauth) return AUTHSASL_ERROR; - if (!externalauth || !*externalauth) + if (initresponse && !*initresponse) + initresponse=NULL; + + if (initresponse && strcmp(initresponse, externalauth)) return AUTHSASL_ERROR; if (!initresponse) @@ -137,3 +140,47 @@ int auth_sasl_ex(const char *method, return 0; } + +char *auth_sasl_extract_userid(const char *authtype, + const char *authdata) +{ + struct cram_callback_info cci; + char *p; + char *t; + char *d; + + if (strcmp(authtype, AUTHTYPE_LOGIN) == 0) + { + char *q; + + p=strdup(authdata); + + if (!p) + return NULL; + + q=strchr(p, '\n'); + if (q) *q=0; + return p; + } + + if ((t=strdup(authtype)) == NULL) + return NULL; + + if ((d=strdup(authdata)) == NULL) + { + free(t); + return NULL; + } + + if (auth_get_cram_silent(t, d, &cci)) + { + free(d); + free(t); + return (NULL); + } + + p=strdup(cci.user); + free(d); + free(t); + return p; +}