1 
2 /*
3 ** Copyright 2000-2008 Double Precision, Inc.  See COPYING for
4 ** distribution information.
5 */
6 
7 #include	"courier_auth_config.h"
8 #include	"courierauthsasl.h"
9 #include	"authsaslclient.h"
10 #include	<stdlib.h>
11 #include	<stdio.h>
12 #include	<ctype.h>
13 #include	<string.h>
14 #include	<errno.h>
15 
16 /* Use the SASL_LIST macro to build authsaslclientlist */
17 
18 #define	SASL(a,b,c) {a, c},
19 
20 struct authsaslclientlist_info authsaslclientlist[] = {
21 
22 SASL_LIST
23 
24 	{ 0, 0}};
25 
auth_sasl_client(const struct authsaslclientinfo * info)26 int auth_sasl_client(const struct authsaslclientinfo *info)
27 {
28 char *methodbuf;
29 int	i;
30 
31 	if (!info->sasl_funcs
32 	    ||!info->conv_func
33 	    ||!info->start_conv_func
34 	    || !info->plain_conv_func)	return (AUTHSASL_NOMETHODS);
35 
36 	if ((methodbuf=malloc(strlen(info->sasl_funcs)+1)) == 0)
37 	{
38 		perror("malloc");
39 		return (AUTHSASL_NOMETHODS);
40 	}
41 
42 	for (i=0; authsaslclientlist[i].name; i++)
43 	{
44 	char	*p;
45 
46 		strcpy(methodbuf, info->sasl_funcs);
47 		for (p=methodbuf; *p; p++)
48 			*p=toupper((int)(unsigned char)*p);
49 		for (p=methodbuf; (p=strtok(p, " \t\r\n")) != 0; p=0)
50 			if (strcmp(p, authsaslclientlist[i].name) == 0)
51 			{
52 				free(methodbuf);
53 				return ( (*authsaslclientlist[i].func)(info));
54 			}
55 	}
56 	free(methodbuf);
57 	return (AUTHSASL_NOMETHODS);
58 }
59