d9898ee8 |
1 | |
2 | /* |
3 | ** Copyright 2000 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 | int authsaslclient_plain(const struct authsaslclientinfo *info) |
17 | { |
18 | char *q, *r; |
19 | int i; |
20 | const char *userid, *password; |
21 | size_t userid_l, password_l; |
22 | |
23 | userid=info->userid ? info->userid:""; |
24 | password=info->password ? info->password:""; |
25 | |
26 | userid_l=strlen(userid); |
27 | password_l=strlen(password); |
28 | |
29 | q=malloc(userid_l+password_l+2); |
30 | |
31 | if (!q) |
32 | { |
33 | perror("malloc"); |
34 | return (AUTHSASL_ERROR); |
35 | } |
36 | q[0]=0; |
37 | strcpy(q+1, userid); |
38 | memcpy(q+2+userid_l, password, password_l); |
39 | |
40 | r=authsasl_tobase64(q, userid_l+password_l+2); |
41 | free(q); |
42 | |
43 | if (!r) |
44 | { |
45 | perror("malloc"); |
46 | return (AUTHSASL_ERROR); |
47 | } |
48 | |
49 | i=(*info->plain_conv_func)("PLAIN", r, info->conv_func_arg); |
50 | free(r); |
51 | return (i); |
52 | } |