1 /*************************************************
2 * Exim - an Internet mail transport agent *
3 *************************************************/
5 /* Copyright (c) Jeremy Harris 2019-2020 */
6 /* See the file NOTICE for conditions of use and distribution. */
7 /* SPDX-License-Identifier: GPL-2.0-only */
9 /* This file provides an Exim authenticator driver for
10 a server to verify a client SSL certificate, using the EXTERNAL
11 method defined in RFC 4422 Appendix A.
18 /* Options specific to the external authentication mechanism. */
20 optionlist auth_external_options[] = {
21 { "client_send", opt_stringptr, OPT_OFF(auth_external_options_block, client_send) },
22 { "server_param2", opt_stringptr, OPT_OFF(auth_external_options_block, server_param2) },
23 { "server_param3", opt_stringptr, OPT_OFF(auth_external_options_block, server_param3) },
26 /* Size of the options list. An extern variable has to be used so that its
27 address can appear in the tables drtables.c. */
29 int auth_external_options_count = nelem(auth_external_options);
31 /* Default private options block for the authentication method. */
33 auth_external_options_block auth_external_option_defaults = {
34 .server_param2 = NULL,
35 .server_param3 = NULL,
44 void auth_external_init(auth_instance *ablock) {}
45 int auth_external_server(auth_instance *ablock, uschar *data) {return 0;}
46 int auth_external_client(auth_instance *ablock, void * sx,
47 int timeout, uschar *buffer, int buffsize) {return 0;}
49 #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_external_init(auth_instance *ablock)
65 auth_external_options_block * ob = (auth_external_options_block *)ablock->options_block;
66 if (!ablock->public_name) ablock->public_name = ablock->name;
67 if (ablock->server_condition) ablock->server = TRUE;
68 if (ob->client_send) ablock->client = TRUE;
73 /*************************************************
74 * Server entry point *
75 *************************************************/
77 /* For interface, see auths/README */
80 auth_external_server(auth_instance * ablock, uschar * data)
82 auth_external_options_block * ob = (auth_external_options_block *)ablock->options_block;
85 /* If data was supplied on the AUTH command, decode it, and split it up into
86 multiple items at binary zeros. The strings are put into $auth1, $auth2, etc,
87 up to a maximum. To retain backwards compatibility, they are also put int $1,
88 $2, etc. If the data consists of the string "=" it indicates a single, empty
92 if ((rc = auth_read_input(data)) != OK)
95 /* Now go through the list of prompt strings. Skip over any whose data has
96 already been provided as part of the AUTH command. For the rest, send them
97 out as prompts, and get a data item back. If the data item is "*", abandon the
98 authentication attempt. Otherwise, split it into items as above. */
100 if (expand_nmax == 0) /* skip if rxd data */
101 if ((rc = auth_prompt(CUS"")) != OK)
104 if (ob->server_param2)
106 uschar * s = expand_string(ob->server_param2);
107 auth_vars[expand_nmax] = s;
108 expand_nstring[++expand_nmax] = s;
109 expand_nlength[expand_nmax] = Ustrlen(s);
110 if (ob->server_param3)
112 s = expand_string(ob->server_param3);
113 auth_vars[expand_nmax] = s;
114 expand_nstring[++expand_nmax] = s;
115 expand_nlength[expand_nmax] = Ustrlen(s);
119 return auth_check_serv_cond(ablock);
124 /*************************************************
125 * Client entry point *
126 *************************************************/
128 /* For interface, see auths/README */
131 auth_external_client(
132 auth_instance *ablock, /* authenticator block */
133 void * sx, /* smtp connextion */
134 int timeout, /* command timeout */
135 uschar *buffer, /* buffer for reading response */
136 int buffsize) /* size of buffer */
138 auth_external_options_block *ob =
139 (auth_external_options_block *)(ablock->options_block);
140 const uschar * text = ob->client_send;
143 /* We output an AUTH command with one expanded argument, the client_send option */
145 if ((rc = auth_client_item(sx, ablock, &text, AUTH_ITEM_FIRST | AUTH_ITEM_LAST,
146 timeout, buffer, buffsize)) != OK)
147 return rc == DEFER ? FAIL : rc;
149 if (text) auth_vars[0] = string_copy(text);
155 #endif /*!MACRO_PREDEF*/
156 /* End of external.c */