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