1 /*************************************************
2 * Exim - an Internet mail transport agent *
3 *************************************************/
5 /* Copyright (c) The Exim Maintainers 2023 */
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.
19 /* Options specific to the external authentication mechanism. */
21 optionlist auth_external_options[] = {
22 { "client_send", opt_stringptr, OPT_OFF(auth_external_options_block, client_send) },
23 { "server_param2", opt_stringptr, OPT_OFF(auth_external_options_block, server_param2) },
24 { "server_param3", opt_stringptr, OPT_OFF(auth_external_options_block, server_param3) },
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_external_options_count = nelem(auth_external_options);
32 /* Default private options block for the authentication method. */
34 auth_external_options_block auth_external_option_defaults = {
35 .server_param2 = NULL,
36 .server_param3 = NULL,
45 void auth_external_init(auth_instance *ablock) {}
46 int auth_external_server(auth_instance *ablock, uschar *data) {return 0;}
47 int auth_external_client(auth_instance *ablock, void * sx,
48 int timeout, uschar *buffer, int buffsize) {return 0;}
50 #else /*!MACRO_PREDEF*/
55 /*************************************************
56 * Initialization entry point *
57 *************************************************/
59 /* Called for each instance, after its options have been read, to
60 enable consistency checks to be done, or anything else that needs
64 auth_external_init(auth_instance *ablock)
66 auth_external_options_block * ob = (auth_external_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_external_server(auth_instance * ablock, uschar * data)
83 auth_external_options_block * ob = (auth_external_options_block *)ablock->options_block;
86 /* If data was supplied on the AUTH command, decode it, and split it up into
87 multiple items at binary zeros. The strings are put into $auth1, $auth2, etc,
88 up to a maximum. To retain backwards compatibility, they are also put int $1,
89 $2, etc. If the data consists of the string "=" it indicates a single, empty
93 if ((rc = auth_read_input(data)) != OK)
96 /* Now go through the list of prompt strings. Skip over any whose data has
97 already been provided as part of the AUTH command. For the rest, send them
98 out as prompts, and get a data item back. If the data item is "*", abandon the
99 authentication attempt. Otherwise, split it into items as above. */
101 if (expand_nmax == 0) /* skip if rxd data */
102 if ((rc = auth_prompt(CUS"")) != OK)
105 if (ob->server_param2)
107 uschar * s = expand_string(ob->server_param2);
108 auth_vars[expand_nmax = 1] = s;
109 expand_nstring[++expand_nmax] = s;
110 expand_nlength[expand_nmax] = Ustrlen(s);
111 if (ob->server_param3)
113 s = expand_string(ob->server_param3);
114 auth_vars[expand_nmax] = s;
115 expand_nstring[++expand_nmax] = s;
116 expand_nlength[expand_nmax] = Ustrlen(s);
120 return auth_check_serv_cond(ablock);
125 /*************************************************
126 * Client entry point *
127 *************************************************/
129 /* For interface, see auths/README */
132 auth_external_client(
133 auth_instance *ablock, /* authenticator block */
134 void * sx, /* smtp connextion */
135 int timeout, /* command timeout */
136 uschar *buffer, /* buffer for reading response */
137 int buffsize) /* size of buffer */
139 auth_external_options_block *ob =
140 (auth_external_options_block *)(ablock->options_block);
141 const uschar * text = ob->client_send;
144 /* We output an AUTH command with one expanded argument, the client_send option */
146 if ((rc = auth_client_item(sx, ablock, &text, AUTH_ITEM_FIRST | AUTH_ITEM_LAST,
147 timeout, buffer, buffsize)) != OK)
148 return rc == DEFER ? FAIL : rc;
150 if (text) auth_vars[0] = string_copy(text);
156 #endif /*!MACRO_PREDEF*/
157 /* End of external.c */