-/* $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 <stdlib.h>
#include <ctype.h>
#include <string.h>
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)
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;
+}