1 /*************************************************
2 * Exim - an Internet mail transport agent *
3 *************************************************/
5 /* Copyright (c) The Exim Maintainers 2020 - 2024 */
6 /* Copyright (c) University of Cambridge 1995 - 2018 */
7 /* See the file NOTICE for conditions of use and distribution. */
8 /* SPDX-License-Identifier: GPL-2.0-or-later */
12 #ifdef AUTH_PLAINTEXT /* Remainder of file */
13 #include "plaintext.h"
16 /* Options specific to the plaintext authentication mechanism. */
18 optionlist auth_plaintext_options[] = {
19 { "client_ignore_invalid_base64", opt_bool,
20 OPT_OFF(auth_plaintext_options_block, client_ignore_invalid_base64) },
21 { "client_send", opt_stringptr,
22 OPT_OFF(auth_plaintext_options_block, client_send) },
23 { "server_prompts", opt_stringptr,
24 OPT_OFF(auth_plaintext_options_block, server_prompts) }
27 /* Size of the options list. An extern variable has to be used so that its
28 address can appear in the tables drtables.c. */
30 int auth_plaintext_options_count =
31 sizeof(auth_plaintext_options)/sizeof(optionlist);
33 /* Default private options block for the plaintext authentication method. */
35 auth_plaintext_options_block auth_plaintext_option_defaults = {
36 NULL, /* server_prompts */
37 NULL, /* client_send */
38 FALSE /* client_ignore_invalid_base64 */
45 void auth_plaintext_init(driver_instance *ablock) {}
46 int auth_plaintext_server(auth_instance *ablock, uschar *data) {return 0;}
47 int auth_plaintext_client(auth_instance *ablock, void * sx, int timeout,
48 uschar *buffer, int buffsize) {return 0;}
50 #else /*!MACRO_PREDEF*/
54 /*************************************************
55 * Initialization entry point *
56 *************************************************/
58 /* Called for each instance, after its options have been read, to
59 enable consistency checks to be done, or anything else that needs
63 auth_plaintext_init(driver_instance * a)
65 auth_instance * ablock = (auth_instance *)a;
66 auth_plaintext_options_block * ob = a->options_block;
68 if (!ablock->public_name)
69 ablock->public_name = ablock->drinst.name;
70 if (ablock->server_condition)
71 ablock->server = TRUE;
73 ablock->client = TRUE;
78 /*************************************************
79 * Server entry point *
80 *************************************************/
82 /* For interface, see auths/README */
85 auth_plaintext_server(auth_instance * ablock, uschar * data)
87 auth_plaintext_options_block * ob = ablock->drinst.options_block;
88 const uschar * prompts = ob->server_prompts;
94 /* Expand a non-empty list of prompt strings */
97 if (!(prompts = expand_cstring(prompts)))
99 auth_defer_msg = expand_string_message;
103 /* If data was supplied on the AUTH command, decode it, and split it up into
104 multiple items at binary zeros. The strings are put into $auth1, $auth2, etc,
105 up to a maximum. To retain backwards compatibility, they are also put int $1,
106 $2, etc. If the data consists of the string "=" it indicates a single, empty
110 if ((rc = auth_read_input(data)) != OK)
113 /* Now go through the list of prompt strings. Skip over any whose data has
114 already been provided as part of the AUTH command. For the rest, send them
115 out as prompts, and get a data item back. If the data item is "*", abandon the
116 authentication attempt. Otherwise, split it into items as above. */
118 while ( (s = string_nextinlist(&prompts, &sep, NULL, 0))
119 && expand_nmax < EXPAND_MAXN)
120 if (number++ > expand_nmax)
121 if ((rc = auth_prompt(CUS s)) != OK)
124 /* We now have a number of items of data in $auth1, $auth2, etc (and also, for
125 compatibility, in $1, $2, etc). Authentication and authorization are handled
126 together for this authenticator by expanding the server_condition option. Note
127 that ablock->server_condition is always non-NULL because that's what configures
128 this authenticator as a server. */
130 return auth_check_serv_cond(ablock);
135 /*************************************************
136 * Client entry point *
137 *************************************************/
139 /* For interface, see auths/README */
142 auth_plaintext_client(
143 auth_instance *ablock, /* authenticator block */
144 void * sx, /* smtp connextion */
145 int timeout, /* command timeout */
146 uschar *buffer, /* buffer for reading response */
147 int buffsize) /* size of buffer */
149 auth_plaintext_options_block * ob = ablock->drinst.options_block;
150 const uschar * text = ob->client_send;
153 int auth_var_idx = 0, rc;
154 int flags = AUTH_ITEM_FIRST;
156 if (ob->client_ignore_invalid_base64)
157 flags |= AUTH_ITEM_IGN64;
159 /* The text is broken up into a number of different data items, which are
160 sent one by one. The first one is sent with the AUTH command; the remainder are
161 sent in response to subsequent prompts. Each is expanded before being sent. */
163 while ((s = string_nextinlist(&text, &sep, NULL, 0)))
166 flags |= AUTH_ITEM_LAST;
168 if ((rc = auth_client_item(sx, ablock, &s, flags, timeout, buffer, buffsize))
172 flags &= ~AUTH_ITEM_FIRST;
174 if (auth_var_idx < AUTH_VARS)
175 auth_vars[auth_var_idx++] = string_copy(s);
178 /* Control should never actually get here. */
183 #endif /*!MACRO_PREDEF*/
184 #endif /*AUTH_PLAINTEST*/
185 /* End of plaintext.c */