1 /*************************************************
2 * Exim - an Internet mail transport agent *
3 *************************************************/
5 /* Copyright (c) University of Cambridge 1995 - 2018 */
6 /* Copyright (c) The Exim Maintainers 2020 - 2021 */
7 /* See the file NOTICE for conditions of use and distribution. */
8 /* SPDX-License-Identifier: GPL-2.0-or-later */
11 #include "plaintext.h"
14 /* Options specific to the plaintext authentication mechanism. */
16 optionlist auth_plaintext_options[] = {
17 { "client_ignore_invalid_base64", opt_bool,
18 OPT_OFF(auth_plaintext_options_block, client_ignore_invalid_base64) },
19 { "client_send", opt_stringptr,
20 OPT_OFF(auth_plaintext_options_block, client_send) },
21 { "server_prompts", opt_stringptr,
22 OPT_OFF(auth_plaintext_options_block, server_prompts) }
25 /* Size of the options list. An extern variable has to be used so that its
26 address can appear in the tables drtables.c. */
28 int auth_plaintext_options_count =
29 sizeof(auth_plaintext_options)/sizeof(optionlist);
31 /* Default private options block for the plaintext authentication method. */
33 auth_plaintext_options_block auth_plaintext_option_defaults = {
34 NULL, /* server_prompts */
35 NULL, /* client_send */
36 FALSE /* client_ignore_invalid_base64 */
43 void auth_plaintext_init(auth_instance *ablock) {}
44 int auth_plaintext_server(auth_instance *ablock, uschar *data) {return 0;}
45 int auth_plaintext_client(auth_instance *ablock, void * sx, int timeout,
46 uschar *buffer, int buffsize) {return 0;}
48 #else /*!MACRO_PREDEF*/
52 /*************************************************
53 * Initialization entry point *
54 *************************************************/
56 /* Called for each instance, after its options have been read, to
57 enable consistency checks to be done, or anything else that needs
61 auth_plaintext_init(auth_instance *ablock)
63 auth_plaintext_options_block *ob =
64 (auth_plaintext_options_block *)(ablock->options_block);
65 if (!ablock->public_name) ablock->public_name = ablock->name;
66 if (ablock->server_condition) ablock->server = TRUE;
67 if (ob->client_send) ablock->client = TRUE;
72 /*************************************************
73 * Server entry point *
74 *************************************************/
76 /* For interface, see auths/README */
79 auth_plaintext_server(auth_instance * ablock, uschar * data)
81 auth_plaintext_options_block * ob =
82 (auth_plaintext_options_block *)(ablock->options_block);
83 const uschar * prompts = ob->server_prompts;
89 /* Expand a non-empty list of prompt strings */
92 if (!(prompts = expand_cstring(prompts)))
94 auth_defer_msg = expand_string_message;
98 /* If data was supplied on the AUTH command, decode it, and split it up into
99 multiple items at binary zeros. The strings are put into $auth1, $auth2, etc,
100 up to a maximum. To retain backwards compatibility, they are also put int $1,
101 $2, etc. If the data consists of the string "=" it indicates a single, empty
105 if ((rc = auth_read_input(data)) != OK)
108 /* Now go through the list of prompt strings. Skip over any whose data has
109 already been provided as part of the AUTH command. For the rest, send them
110 out as prompts, and get a data item back. If the data item is "*", abandon the
111 authentication attempt. Otherwise, split it into items as above. */
113 while ( (s = string_nextinlist(&prompts, &sep, NULL, 0))
114 && expand_nmax < EXPAND_MAXN)
115 if (number++ > expand_nmax)
116 if ((rc = auth_prompt(CUS s)) != OK)
119 /* We now have a number of items of data in $auth1, $auth2, etc (and also, for
120 compatibility, in $1, $2, etc). Authentication and authorization are handled
121 together for this authenticator by expanding the server_condition option. Note
122 that ablock->server_condition is always non-NULL because that's what configures
123 this authenticator as a server. */
125 return auth_check_serv_cond(ablock);
130 /*************************************************
131 * Client entry point *
132 *************************************************/
134 /* For interface, see auths/README */
137 auth_plaintext_client(
138 auth_instance *ablock, /* authenticator block */
139 void * sx, /* smtp connextion */
140 int timeout, /* command timeout */
141 uschar *buffer, /* buffer for reading response */
142 int buffsize) /* size of buffer */
144 auth_plaintext_options_block *ob =
145 (auth_plaintext_options_block *)(ablock->options_block);
146 const uschar * text = ob->client_send;
149 int auth_var_idx = 0, rc;
150 int flags = AUTH_ITEM_FIRST;
152 if (ob->client_ignore_invalid_base64)
153 flags |= AUTH_ITEM_IGN64;
155 /* The text is broken up into a number of different data items, which are
156 sent one by one. The first one is sent with the AUTH command; the remainder are
157 sent in response to subsequent prompts. Each is expanded before being sent. */
159 while ((s = string_nextinlist(&text, &sep, NULL, 0)))
162 flags |= AUTH_ITEM_LAST;
164 if ((rc = auth_client_item(sx, ablock, &s, flags, timeout, buffer, buffsize))
168 flags &= ~AUTH_ITEM_FIRST;
170 if (auth_var_idx < AUTH_VARS)
171 auth_vars[auth_var_idx++] = string_copy(s);
174 /* Control should never actually get here. */
179 #endif /*!MACRO_PREDEF*/
180 /* End of plaintext.c */