1 /*************************************************
2 * Exim - an Internet mail transport agent *
3 *************************************************/
5 /* Copyright (c) University of Cambridge 1995 - 2018 */
6 /* See the file NOTICE for conditions of use and distribution. */
12 /* Options specific to the plaintext authentication mechanism. */
14 optionlist auth_plaintext_options[] = {
15 { "client_ignore_invalid_base64", opt_bool,
16 (void *)(offsetof(auth_plaintext_options_block, client_ignore_invalid_base64)) },
17 { "client_send", opt_stringptr,
18 (void *)(offsetof(auth_plaintext_options_block, client_send)) },
19 { "server_prompts", opt_stringptr,
20 (void *)(offsetof(auth_plaintext_options_block, server_prompts)) }
23 /* Size of the options list. An extern variable has to be used so that its
24 address can appear in the tables drtables.c. */
26 int auth_plaintext_options_count =
27 sizeof(auth_plaintext_options)/sizeof(optionlist);
29 /* Default private options block for the plaintext authentication method. */
31 auth_plaintext_options_block auth_plaintext_option_defaults = {
32 NULL, /* server_prompts */
33 NULL, /* client_send */
34 FALSE /* client_ignore_invalid_base64 */
41 void auth_plaintext_init(auth_instance *ablock) {}
42 int auth_plaintext_server(auth_instance *ablock, uschar *data) {return 0;}
43 int auth_plaintext_client(auth_instance *ablock, void * sx, int timeout,
44 uschar *buffer, int buffsize) {return 0;}
46 #else /*!MACRO_PREDEF*/
50 /*************************************************
51 * Initialization entry point *
52 *************************************************/
54 /* Called for each instance, after its options have been read, to
55 enable consistency checks to be done, or anything else that needs
59 auth_plaintext_init(auth_instance *ablock)
61 auth_plaintext_options_block *ob =
62 (auth_plaintext_options_block *)(ablock->options_block);
63 if (ablock->public_name == NULL) ablock->public_name = ablock->name;
64 if (ablock->server_condition != NULL) ablock->server = TRUE;
65 if (ob->client_send != NULL) ablock->client = TRUE;
70 /*************************************************
71 * Server entry point *
72 *************************************************/
74 /* For interface, see auths/README */
77 auth_plaintext_server(auth_instance *ablock, uschar *data)
79 auth_plaintext_options_block *ob =
80 (auth_plaintext_options_block *)(ablock->options_block);
81 const uschar *prompts = ob->server_prompts;
82 uschar *clear, *end, *s;
87 /* Expand a non-empty list of prompt strings */
90 if (!(prompts = expand_cstring(prompts)))
92 auth_defer_msg = expand_string_message;
96 /* If data was supplied on the AUTH command, decode it, and split it up into
97 multiple items at binary zeros. The strings are put into $auth1, $auth2, etc,
98 up to a maximum. To retain backwards compatibility, they are also put int $1,
99 $2, etc. If the data consists of the string "=" it indicates a single, empty
103 if ((rc = auth_read_input(data)) != OK)
106 /* Now go through the list of prompt strings. Skip over any whose data has
107 already been provided as part of the AUTH command. For the rest, send them
108 out as prompts, and get a data item back. If the data item is "*", abandon the
109 authentication attempt. Otherwise, split it into items as above. */
111 while ( (s = string_nextinlist(&prompts, &sep, big_buffer, big_buffer_size))
112 && expand_nmax < EXPAND_MAXN)
113 if (number++ > expand_nmax)
114 if ((rc = auth_prompt(CUS s)) != OK)
117 /* We now have a number of items of data in $auth1, $auth2, etc (and also, for
118 compatibility, in $1, $2, etc). Authentication and authorization are handled
119 together for this authenticator by expanding the server_condition option. Note
120 that ablock->server_condition is always non-NULL because that's what configures
121 this authenticator as a server. */
123 return auth_check_serv_cond(ablock);
128 /*************************************************
129 * Client entry point *
130 *************************************************/
132 /* For interface, see auths/README */
135 auth_plaintext_client(
136 auth_instance *ablock, /* authenticator block */
137 void * sx, /* smtp connextion */
138 int timeout, /* command timeout */
139 uschar *buffer, /* buffer for reading response */
140 int buffsize) /* size of buffer */
142 auth_plaintext_options_block *ob =
143 (auth_plaintext_options_block *)(ablock->options_block);
144 const uschar * text = ob->client_send;
148 int auth_var_idx = 0, rc;
149 int flags = AUTH_ITEM_FIRST;
151 if (ob->client_ignore_invalid_base64)
152 flags |= AUTH_ITEM_IGN64;
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. */
158 while ((s = string_nextinlist(&text, &sep, NULL, 0)))
161 flags |= AUTH_ITEM_LAST;
163 if ((rc = auth_client_item(sx, ablock, &s, flags, timeout, buffer, buffsize))
167 flags &= ~AUTH_ITEM_FIRST;
169 if (auth_var_idx < AUTH_VARS)
170 auth_vars[auth_var_idx++] = string_copy(s);
173 /* Control should never actually get here. */
178 #endif /*!MACRO_PREDEF*/
179 /* End of plaintext.c */