| 1 | /* $Id: authsasl.c,v 1.3 2004/10/21 00:10:49 mrsam Exp $ */ |
| 2 | |
| 3 | /* |
| 4 | ** Copyright 1998 - 2000 Double Precision, Inc. See COPYING for |
| 5 | ** distribution information. |
| 6 | */ |
| 7 | |
| 8 | #include "courier_auth_config.h" |
| 9 | #include "courierauthsasl.h" |
| 10 | #include <stdlib.h> |
| 11 | #include <ctype.h> |
| 12 | #include <string.h> |
| 13 | #include <errno.h> |
| 14 | |
| 15 | /* Use the SASL_LIST macro to build authsasl_list */ |
| 16 | |
| 17 | #define SASL(a,b,c) int b(const char *, const char *, \ |
| 18 | char *(*)(const char *, void *), \ |
| 19 | void *, \ |
| 20 | char **, \ |
| 21 | char **); |
| 22 | SASL_LIST |
| 23 | |
| 24 | #undef SASL |
| 25 | |
| 26 | #define SASL(a,b,c) {a, b}, |
| 27 | |
| 28 | struct authsasl_info authsasl_list[] = { |
| 29 | |
| 30 | SASL_LIST |
| 31 | |
| 32 | { 0, 0}}; |
| 33 | |
| 34 | int auth_sasl(const char *method, |
| 35 | const char *initreply, |
| 36 | char *(*callback_func)(const char *, void *), |
| 37 | void *callback_arg, |
| 38 | char **authtype_ptr, /* Returned - AUTHTYPE */ |
| 39 | char **authdata_ptr) |
| 40 | { |
| 41 | int i; |
| 42 | char *p, *q; |
| 43 | |
| 44 | if ((p=malloc(strlen(method)+1)) == 0) |
| 45 | return (0); |
| 46 | strcpy(p, method); |
| 47 | for (q=p; *q; q++) |
| 48 | *q=toupper((int)(unsigned char)*q); |
| 49 | |
| 50 | for (i=0; authsasl_list[i].sasl_method; i++) |
| 51 | { |
| 52 | if (strcmp(p, authsasl_list[i].sasl_method) == 0) |
| 53 | { |
| 54 | free(p); |
| 55 | return ( (*authsasl_list[i].sasl_func) |
| 56 | (method, |
| 57 | initreply, callback_func, |
| 58 | callback_arg, |
| 59 | authtype_ptr, authdata_ptr)); |
| 60 | } |
| 61 | } |
| 62 | free(p); |
| 63 | errno=ENOENT; |
| 64 | return (AUTHSASL_ERROR); |
| 65 | } |