Avoid Solaris compiler issue
[exim.git] / src / src / auths / external.c
CommitLineData
b53c265b
JH
1/*************************************************
2* Exim - an Internet mail transport agent *
3*************************************************/
4
5/* Copyright (c) Jeremy Harris 2019 */
6/* See the file NOTICE for conditions of use and distribution. */
7
8/* This file provides an Exim authenticator driver for
9a server to verify a client SSL certificate, using the EXTERNAL
10method defined in RFC 4422 Appendix A.
11*/
12
13
14#include "../exim.h"
15#include "external.h"
16
17/* Options specific to the external authentication mechanism. */
18
19optionlist auth_external_options[] = {
20 { "client_send", opt_stringptr,
21 (void *)(offsetof(auth_external_options_block, client_send)) },
22 { "server_param2", opt_stringptr,
23 (void *)(offsetof(auth_external_options_block, server_param2)) },
24 { "server_param3", opt_stringptr,
25 (void *)(offsetof(auth_external_options_block, server_param3)) },
26};
27
28/* Size of the options list. An extern variable has to be used so that its
29address can appear in the tables drtables.c. */
30
31int auth_external_options_count = nelem(auth_external_options);
32
33/* Default private options block for the authentication method. */
34
35auth_external_options_block auth_external_option_defaults = {
36 .server_param2 = NULL,
37 .server_param3 = NULL,
38
39 .client_send = NULL,
40};
41
42
43#ifdef MACRO_PREDEF
44
45/* Dummy values */
46void auth_external_init(auth_instance *ablock) {}
47int auth_external_server(auth_instance *ablock, uschar *data) {return 0;}
48int auth_external_client(auth_instance *ablock, void * sx,
49 int timeout, uschar *buffer, int buffsize) {return 0;}
50
51#else /*!MACRO_PREDEF*/
52
53
54
55
56/*************************************************
57* Initialization entry point *
58*************************************************/
59
60/* Called for each instance, after its options have been read, to
61enable consistency checks to be done, or anything else that needs
62to be set up. */
63
64void
65auth_external_init(auth_instance *ablock)
66{
67auth_external_options_block * ob = (auth_external_options_block *)ablock->options_block;
68if (!ablock->public_name) ablock->public_name = ablock->name;
69if (ablock->server_condition) ablock->server = TRUE;
70if (ob->client_send) ablock->client = TRUE;
71}
72
73
74
75/*************************************************
76* Server entry point *
77*************************************************/
78
79/* For interface, see auths/README */
80
81int
82auth_external_server(auth_instance * ablock, uschar * data)
83{
84auth_external_options_block * ob = (auth_external_options_block *)ablock->options_block;
85int rc;
86
87/* If data was supplied on the AUTH command, decode it, and split it up into
88multiple items at binary zeros. The strings are put into $auth1, $auth2, etc,
89up to a maximum. To retain backwards compatibility, they are also put int $1,
90$2, etc. If the data consists of the string "=" it indicates a single, empty
91string. */
92
93if (*data)
94 if ((rc = auth_read_input(data)) != OK)
95 return rc;
96
97/* Now go through the list of prompt strings. Skip over any whose data has
98already been provided as part of the AUTH command. For the rest, send them
99out as prompts, and get a data item back. If the data item is "*", abandon the
100authentication attempt. Otherwise, split it into items as above. */
101
102if (expand_nmax == 0) /* skip if rxd data */
103 if ((rc = auth_prompt(CUS"")) != OK)
104 return rc;
105
106if (ob->server_param2)
107 {
108 uschar * s = expand_string(ob->server_param2);
109 auth_vars[expand_nmax] = s;
110 expand_nstring[++expand_nmax] = s;
111 expand_nlength[expand_nmax] = Ustrlen(s);
112 if (ob->server_param3)
113 {
114 s = expand_string(ob->server_param3);
115 auth_vars[expand_nmax] = s;
116 expand_nstring[++expand_nmax] = s;
117 expand_nlength[expand_nmax] = Ustrlen(s);
118 }
119 }
120
121return auth_check_serv_cond(ablock);
122}
123
124
125
126/*************************************************
127* Client entry point *
128*************************************************/
129
130/* For interface, see auths/README */
131
132int
133auth_external_client(
134 auth_instance *ablock, /* authenticator block */
135 void * sx, /* smtp connextion */
136 int timeout, /* command timeout */
137 uschar *buffer, /* buffer for reading response */
138 int buffsize) /* size of buffer */
139{
140auth_external_options_block *ob =
141 (auth_external_options_block *)(ablock->options_block);
142const uschar * text = ob->client_send;
143int rc;
144
145/* We output an AUTH command with one expanded argument, the client_send option */
146
147if ((rc = auth_client_item(sx, ablock, &text, AUTH_ITEM_FIRST | AUTH_ITEM_LAST,
148 timeout, buffer, buffsize)) != OK)
149 return rc == DEFER ? FAIL : rc;
150
151if (text) auth_vars[0] = string_copy(text);
152return OK;
153}
154
155
156
157#endif /*!MACRO_PREDEF*/
158/* End of external.c */