Commit | Line | Data |
---|---|---|
0756eb3c PH |
1 | /************************************************* |
2 | * Exim - an Internet mail transport agent * | |
3 | *************************************************/ | |
4 | ||
f9ba5e22 | 5 | /* Copyright (c) University of Cambridge 1995 - 2018 */ |
1e1ddfac | 6 | /* Copyright (c) The Exim Maintainers 2020 */ |
0756eb3c PH |
7 | /* See the file NOTICE for conditions of use and distribution. */ |
8 | ||
9 | #include "../exim.h" | |
10 | #include "plaintext.h" | |
11 | ||
12 | ||
13 | /* Options specific to the plaintext authentication mechanism. */ | |
14 | ||
15 | optionlist auth_plaintext_options[] = { | |
4730f942 | 16 | { "client_ignore_invalid_base64", opt_bool, |
13a4b4c1 | 17 | OPT_OFF(auth_plaintext_options_block, client_ignore_invalid_base64) }, |
0756eb3c | 18 | { "client_send", opt_stringptr, |
13a4b4c1 | 19 | OPT_OFF(auth_plaintext_options_block, client_send) }, |
0756eb3c | 20 | { "server_prompts", opt_stringptr, |
13a4b4c1 | 21 | OPT_OFF(auth_plaintext_options_block, server_prompts) } |
0756eb3c PH |
22 | }; |
23 | ||
24 | /* Size of the options list. An extern variable has to be used so that its | |
25 | address can appear in the tables drtables.c. */ | |
26 | ||
27 | int auth_plaintext_options_count = | |
28 | sizeof(auth_plaintext_options)/sizeof(optionlist); | |
29 | ||
30 | /* Default private options block for the plaintext authentication method. */ | |
31 | ||
32 | auth_plaintext_options_block auth_plaintext_option_defaults = { | |
0756eb3c | 33 | NULL, /* server_prompts */ |
4730f942 PH |
34 | NULL, /* client_send */ |
35 | FALSE /* client_ignore_invalid_base64 */ | |
0756eb3c PH |
36 | }; |
37 | ||
38 | ||
d185889f JH |
39 | #ifdef MACRO_PREDEF |
40 | ||
41 | /* Dummy values */ | |
42 | void auth_plaintext_init(auth_instance *ablock) {} | |
43 | int auth_plaintext_server(auth_instance *ablock, uschar *data) {return 0;} | |
251b9eb4 JH |
44 | int auth_plaintext_client(auth_instance *ablock, void * sx, int timeout, |
45 | uschar *buffer, int buffsize) {return 0;} | |
d185889f JH |
46 | |
47 | #else /*!MACRO_PREDEF*/ | |
48 | ||
49 | ||
50 | ||
0756eb3c PH |
51 | /************************************************* |
52 | * Initialization entry point * | |
53 | *************************************************/ | |
54 | ||
55 | /* Called for each instance, after its options have been read, to | |
56 | enable consistency checks to be done, or anything else that needs | |
57 | to be set up. */ | |
58 | ||
59 | void | |
60 | auth_plaintext_init(auth_instance *ablock) | |
61 | { | |
62 | auth_plaintext_options_block *ob = | |
63 | (auth_plaintext_options_block *)(ablock->options_block); | |
64 | if (ablock->public_name == NULL) ablock->public_name = ablock->name; | |
16ff981e | 65 | if (ablock->server_condition != NULL) ablock->server = TRUE; |
0756eb3c PH |
66 | if (ob->client_send != NULL) ablock->client = TRUE; |
67 | } | |
68 | ||
69 | ||
70 | ||
71 | /************************************************* | |
72 | * Server entry point * | |
73 | *************************************************/ | |
74 | ||
75 | /* For interface, see auths/README */ | |
76 | ||
77 | int | |
dca6d121 | 78 | auth_plaintext_server(auth_instance * ablock, uschar * data) |
0756eb3c | 79 | { |
dca6d121 | 80 | auth_plaintext_options_block * ob = |
0756eb3c | 81 | (auth_plaintext_options_block *)(ablock->options_block); |
dca6d121 JH |
82 | const uschar * prompts = ob->server_prompts; |
83 | uschar * s; | |
0756eb3c | 84 | int number = 1; |
dca6d121 | 85 | int rc; |
0756eb3c PH |
86 | int sep = 0; |
87 | ||
88 | /* Expand a non-empty list of prompt strings */ | |
89 | ||
37942ad8 JH |
90 | if (prompts) |
91 | if (!(prompts = expand_cstring(prompts))) | |
0756eb3c PH |
92 | { |
93 | auth_defer_msg = expand_string_message; | |
94 | return DEFER; | |
95 | } | |
0756eb3c PH |
96 | |
97 | /* If data was supplied on the AUTH command, decode it, and split it up into | |
f78eb7c6 PH |
98 | multiple items at binary zeros. The strings are put into $auth1, $auth2, etc, |
99 | up to a maximum. To retain backwards compatibility, they are also put int $1, | |
100 | $2, etc. If the data consists of the string "=" it indicates a single, empty | |
101 | string. */ | |
0756eb3c | 102 | |
37942ad8 JH |
103 | if (*data) |
104 | if ((rc = auth_read_input(data)) != OK) | |
105 | return rc; | |
0756eb3c PH |
106 | |
107 | /* Now go through the list of prompt strings. Skip over any whose data has | |
108 | already been provided as part of the AUTH command. For the rest, send them | |
109 | out as prompts, and get a data item back. If the data item is "*", abandon the | |
110 | authentication attempt. Otherwise, split it into items as above. */ | |
111 | ||
37942ad8 JH |
112 | while ( (s = string_nextinlist(&prompts, &sep, big_buffer, big_buffer_size)) |
113 | && expand_nmax < EXPAND_MAXN) | |
114 | if (number++ > expand_nmax) | |
115 | if ((rc = auth_prompt(CUS s)) != OK) | |
116 | return rc; | |
0756eb3c | 117 | |
f78eb7c6 | 118 | /* We now have a number of items of data in $auth1, $auth2, etc (and also, for |
16ff981e PH |
119 | compatibility, in $1, $2, etc). Authentication and authorization are handled |
120 | together for this authenticator by expanding the server_condition option. Note | |
121 | that ablock->server_condition is always non-NULL because that's what configures | |
122 | this authenticator as a server. */ | |
0756eb3c | 123 | |
16ff981e | 124 | return auth_check_serv_cond(ablock); |
0756eb3c PH |
125 | } |
126 | ||
127 | ||
128 | ||
129 | /************************************************* | |
130 | * Client entry point * | |
131 | *************************************************/ | |
132 | ||
133 | /* For interface, see auths/README */ | |
134 | ||
135 | int | |
136 | auth_plaintext_client( | |
137 | auth_instance *ablock, /* authenticator block */ | |
251b9eb4 | 138 | void * sx, /* smtp connextion */ |
0756eb3c PH |
139 | int timeout, /* command timeout */ |
140 | uschar *buffer, /* buffer for reading response */ | |
141 | int buffsize) /* size of buffer */ | |
142 | { | |
143 | auth_plaintext_options_block *ob = | |
144 | (auth_plaintext_options_block *)(ablock->options_block); | |
37942ad8 JH |
145 | const uschar * text = ob->client_send; |
146 | const uschar * s; | |
0756eb3c | 147 | int sep = 0; |
37942ad8 JH |
148 | int auth_var_idx = 0, rc; |
149 | int flags = AUTH_ITEM_FIRST; | |
150 | ||
151 | if (ob->client_ignore_invalid_base64) | |
152 | flags |= AUTH_ITEM_IGN64; | |
0756eb3c PH |
153 | |
154 | /* The text is broken up into a number of different data items, which are | |
155 | sent one by one. The first one is sent with the AUTH command; the remainder are | |
156 | sent in response to subsequent prompts. Each is expanded before being sent. */ | |
157 | ||
37942ad8 | 158 | while ((s = string_nextinlist(&text, &sep, NULL, 0))) |
0756eb3c | 159 | { |
251b9eb4 | 160 | if (!text) |
37942ad8 | 161 | flags |= AUTH_ITEM_LAST; |
4730f942 | 162 | |
37942ad8 JH |
163 | if ((rc = auth_client_item(sx, ablock, &s, flags, timeout, buffer, buffsize)) |
164 | != DEFER) | |
165 | return rc; | |
4730f942 | 166 | |
37942ad8 | 167 | flags &= ~AUTH_ITEM_FIRST; |
4730f942 PH |
168 | |
169 | if (auth_var_idx < AUTH_VARS) | |
37942ad8 | 170 | auth_vars[auth_var_idx++] = string_copy(s); |
0756eb3c PH |
171 | } |
172 | ||
173 | /* Control should never actually get here. */ | |
174 | ||
175 | return FAIL; | |
176 | } | |
177 | ||
d185889f | 178 | #endif /*!MACRO_PREDEF*/ |
0756eb3c | 179 | /* End of plaintext.c */ |