1 /*************************************************
2 * Exim - an Internet mail transport agent *
3 *************************************************/
5 /* Copyright (c) The Exim Maintainers 2023 - 2024 */
6 /* Copyright (c) Jeremy Harris 2019-2020 */
7 /* See the file NOTICE for conditions of use and distribution. */
8 /* SPDX-License-Identifier: GPL-2.0-or-later */
10 /* This file provides an Exim authenticator driver for
11 a server to verify a client SSL certificate, using the EXTERNAL
12 method defined in RFC 4422 Appendix A.
18 #ifdef AUTH_EXTERNAL /* Remainder of file */
21 /* Options specific to the external authentication mechanism. */
23 optionlist auth_external_options[] = {
24 { "client_send", opt_stringptr, OPT_OFF(auth_external_options_block, client_send) },
25 { "server_param2", opt_stringptr, OPT_OFF(auth_external_options_block, server_param2) },
26 { "server_param3", opt_stringptr, OPT_OFF(auth_external_options_block, server_param3) },
29 /* Size of the options list. An extern variable has to be used so that its
30 address can appear in the tables drtables.c. */
32 int auth_external_options_count = nelem(auth_external_options);
34 /* Default private options block for the authentication method. */
36 auth_external_options_block auth_external_option_defaults = {
37 .server_param2 = NULL,
38 .server_param3 = NULL,
47 void auth_external_init(driver_instance *ablock) {}
48 int auth_external_server(auth_instance *ablock, uschar *data) {return 0;}
49 int auth_external_client(auth_instance *ablock, void * sx,
50 int timeout, uschar *buffer, int buffsize) {return 0;}
52 #else /*!MACRO_PREDEF*/
57 /*************************************************
58 * Initialization entry point *
59 *************************************************/
61 /* Called for each instance, after its options have been read, to
62 enable consistency checks to be done, or anything else that needs
66 auth_external_init(driver_instance * a)
68 auth_instance * ablock = (auth_instance *)a;
69 auth_external_options_block * ob = a->options_block;
71 if (!ablock->public_name)
72 ablock->public_name = a->name;
73 if (ablock->server_condition)
74 ablock->server = TRUE;
76 ablock->client = TRUE;
81 /*************************************************
82 * Server entry point *
83 *************************************************/
85 /* For interface, see auths/README */
88 auth_external_server(auth_instance * ablock, uschar * data)
90 auth_external_options_block * ob = ablock->drinst.options_block;
93 /* If data was supplied on the AUTH command, decode it, and split it up into
94 multiple items at binary zeros. The strings are put into $auth1, $auth2, etc,
95 up to a maximum. To retain backwards compatibility, they are also put int $1,
96 $2, etc. If the data consists of the string "=" it indicates a single, empty
100 if ((rc = auth_read_input(data)) != OK)
103 /* Now go through the list of prompt strings. Skip over any whose data has
104 already been provided as part of the AUTH command. For the rest, send them
105 out as prompts, and get a data item back. If the data item is "*", abandon the
106 authentication attempt. Otherwise, split it into items as above. */
108 if (expand_nmax == 0) /* skip if rxd data */
109 if ((rc = auth_prompt(CUS"")) != OK)
112 if (ob->server_param2)
114 uschar * s = expand_string(ob->server_param2);
115 auth_vars[expand_nmax = 1] = s;
116 expand_nstring[++expand_nmax] = s;
117 expand_nlength[expand_nmax] = Ustrlen(s);
118 if (ob->server_param3)
120 s = expand_string(ob->server_param3);
121 auth_vars[expand_nmax] = s;
122 expand_nstring[++expand_nmax] = s;
123 expand_nlength[expand_nmax] = Ustrlen(s);
127 return auth_check_serv_cond(ablock);
132 /*************************************************
133 * Client entry point *
134 *************************************************/
136 /* For interface, see auths/README */
139 auth_external_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_external_options_block * ob = ablock->drinst.options_block;
147 const uschar * text = ob->client_send;
150 /* We output an AUTH command with one expanded argument, the client_send option */
152 if ((rc = auth_client_item(sx, ablock, &text, AUTH_ITEM_FIRST | AUTH_ITEM_LAST,
153 timeout, buffer, buffsize)) != OK)
154 return rc == DEFER ? FAIL : rc;
156 if (text) auth_vars[0] = string_copy(text);
162 #endif /*!MACRO_PREDEF*/
163 #endif /*AUTH_EXTERNAL*/
164 /* End of external.c */