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(auth_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(auth_instance *ablock)
65 auth_plaintext_options_block *ob =
66 (auth_plaintext_options_block *)(ablock->options_block);
67 if (!ablock->public_name) ablock->public_name = ablock->name;
68 if (ablock->server_condition) ablock->server = TRUE;
69 if (ob->client_send) ablock->client = TRUE;
74 /*************************************************
75 * Server entry point *
76 *************************************************/
78 /* For interface, see auths/README */
81 auth_plaintext_server(auth_instance * ablock, uschar * data)
83 auth_plaintext_options_block * ob =
84 (auth_plaintext_options_block *)(ablock->options_block);
85 const uschar * prompts = ob->server_prompts;
91 /* Expand a non-empty list of prompt strings */
94 if (!(prompts = expand_cstring(prompts)))
96 auth_defer_msg = expand_string_message;
100 /* If data was supplied on the AUTH command, decode it, and split it up into
101 multiple items at binary zeros. The strings are put into $auth1, $auth2, etc,
102 up to a maximum. To retain backwards compatibility, they are also put int $1,
103 $2, etc. If the data consists of the string "=" it indicates a single, empty
107 if ((rc = auth_read_input(data)) != OK)
110 /* Now go through the list of prompt strings. Skip over any whose data has
111 already been provided as part of the AUTH command. For the rest, send them
112 out as prompts, and get a data item back. If the data item is "*", abandon the
113 authentication attempt. Otherwise, split it into items as above. */
115 while ( (s = string_nextinlist(&prompts, &sep, NULL, 0))
116 && expand_nmax < EXPAND_MAXN)
117 if (number++ > expand_nmax)
118 if ((rc = auth_prompt(CUS s)) != OK)
121 /* We now have a number of items of data in $auth1, $auth2, etc (and also, for
122 compatibility, in $1, $2, etc). Authentication and authorization are handled
123 together for this authenticator by expanding the server_condition option. Note
124 that ablock->server_condition is always non-NULL because that's what configures
125 this authenticator as a server. */
127 return auth_check_serv_cond(ablock);
132 /*************************************************
133 * Client entry point *
134 *************************************************/
136 /* For interface, see auths/README */
139 auth_plaintext_client(
140 auth_instance *ablock, /* authenticator block */
141 void * sx, /* smtp connextion */
142 int timeout, /* command timeout */
143 uschar *buffer, /* buffer for reading response */
144 int buffsize) /* size of buffer */
146 auth_plaintext_options_block *ob =
147 (auth_plaintext_options_block *)(ablock->options_block);
148 const uschar * text = ob->client_send;
151 int auth_var_idx = 0, rc;
152 int flags = AUTH_ITEM_FIRST;
154 if (ob->client_ignore_invalid_base64)
155 flags |= AUTH_ITEM_IGN64;
157 /* The text is broken up into a number of different data items, which are
158 sent one by one. The first one is sent with the AUTH command; the remainder are
159 sent in response to subsequent prompts. Each is expanded before being sent. */
161 while ((s = string_nextinlist(&text, &sep, NULL, 0)))
164 flags |= AUTH_ITEM_LAST;
166 if ((rc = auth_client_item(sx, ablock, &s, flags, timeout, buffer, buffsize))
170 flags &= ~AUTH_ITEM_FIRST;
172 if (auth_var_idx < AUTH_VARS)
173 auth_vars[auth_var_idx++] = string_copy(s);
176 /* Control should never actually get here. */
181 #endif /*!MACRO_PREDEF*/
182 #endif /*AUTH_PLAINTEST*/
183 /* End of plaintext.c */