| 1 |
/* |
| 2 |
* stunnel TLS offloading and load-balancing proxy |
| 3 |
* Copyright (C) 1998-2026 Michal Trojnara <[email protected]> |
| 4 |
* |
| 5 |
* This program is free software; you can redistribute it and/or modify it |
| 6 |
* under the terms of the GNU General Public License as published by the |
| 7 |
* Free Software Foundation; either version 2 of the License, or (at your |
| 8 |
* option) any later version. |
| 9 |
* |
| 10 |
* This program is distributed in the hope that it will be useful, |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 13 |
* See the GNU General Public License for more details. |
| 14 |
* |
| 15 |
* You should have received a copy of the GNU General Public License along |
| 16 |
* with this program; if not, see <http://www.gnu.org/licenses>. |
| 17 |
* |
| 18 |
* Linking stunnel statically or dynamically with other modules is making |
| 19 |
* a combined work based on stunnel. Thus, the terms and conditions of |
| 20 |
* the GNU General Public License cover the whole combination. |
| 21 |
* |
| 22 |
* In addition, as a special exception, the copyright holder of stunnel |
| 23 |
* gives you permission to combine stunnel with free software programs or |
| 24 |
* libraries that are released under the GNU LGPL and with code included |
| 25 |
* in the standard release of OpenSSL under the OpenSSL License (or |
| 26 |
* modified versions of such code, with unchanged license). You may copy |
| 27 |
* and distribute such a system following the terms of the GNU GPL for |
| 28 |
* stunnel and the licenses of the other code concerned. |
| 29 |
* |
| 30 |
* Note that people who make modified versions of stunnel are not obligated |
| 31 |
* to grant this special exception for their modified versions; it is their |
| 32 |
* choice whether to do so. The GNU General Public License gives permission |
| 33 |
* to release a modified version without this exception; this exception |
| 34 |
* also makes it possible to release a modified version which carries |
| 35 |
* forward this exception. |
| 36 |
*/ |
| 37 |
|
| 38 |
#include "prototypes.h" |
| 39 |
|
| 40 |
#if OPENSSL_VERSION_NUMBER >= 0x10101000L |
| 41 |
#if OPENSSL_VERSION_NUMBER >= 0x30500000L |
| 42 |
#define DEFAULT_CURVES "X25519MLKEM768:X25519:P-256:X448:P-521:P-384" |
| 43 |
#else /* OPENSSL_VERSION_NUMBER>=0x30500000L */ |
| 44 |
#define DEFAULT_CURVES "X25519:P-256:X448:P-521:P-384" |
| 45 |
#endif /* OPENSSL_VERSION_NUMBER>=0x30500000L */ |
| 46 |
#define DEFAULT_CURVES_FIPS "P-256:P-521:P-384" |
| 47 |
#else /* OpenSSL version < 1.1.1 */ |
| 48 |
#define DEFAULT_CURVES "prime256v1" |
| 49 |
#define DEFAULT_CURVES_FIPS DEFAULT_CURVES |
| 50 |
#endif /* OpenSSL version >= 1.1.1 */ |
| 51 |
|
| 52 |
#if defined(_WIN32_WCE) && !defined(CONFDIR) |
| 53 |
#define CONFDIR "\\stunnel" |
| 54 |
#endif |
| 55 |
|
| 56 |
#define CONFLINELEN (16*1024) |
| 57 |
|
| 58 |
#define INVALID_SSL_OPTION ((uint64_t)-1) |
| 59 |
|
| 60 |
typedef enum { |
| 61 |
CMD_SET_DEFAULTS, /* set default values */ |
| 62 |
CMD_SET_COPY, /* duplicate from new_service_options */ |
| 63 |
CMD_FREE, /* deallocate memory */ |
| 64 |
CMD_SET_VALUE, /* set a user-specified value */ |
| 65 |
CMD_INITIALIZE, /* initialize the global options or a section */ |
| 66 |
CMD_PRINT_DEFAULTS, /* print default values */ |
| 67 |
CMD_PRINT_HELP /* print help */ |
| 68 |
} CMD; |
| 69 |
|
| 70 |
NOEXPORT int options_file(char *, CONF_TYPE, SERVICE_OPTIONS **); |
| 71 |
NOEXPORT int init_section(int, SERVICE_OPTIONS **); |
| 72 |
#ifdef USE_WIN32 |
| 73 |
struct dirent { |
| 74 |
char d_name[MAX_PATH]; |
| 75 |
}; |
| 76 |
int scandir(const char *, struct dirent ***, |
| 77 |
int (*)(const struct dirent *), |
| 78 |
int (*)(const struct dirent **, const struct dirent **)); |
| 79 |
int alphasort(const struct dirent **, const struct dirent **); |
| 80 |
#endif |
| 81 |
NOEXPORT const char *parse_global_option(CMD, GLOBAL_OPTIONS *, char *, char *); |
| 82 |
NOEXPORT const char *parse_service_option(CMD, SERVICE_OPTIONS **, char *, char *); |
| 83 |
|
| 84 |
#ifndef OPENSSL_NO_TLSEXT |
| 85 |
NOEXPORT const char *sni_init(SERVICE_OPTIONS *); |
| 86 |
NOEXPORT void sni_free(SERVICE_OPTIONS *); |
| 87 |
#endif /* !defined(OPENSSL_NO_TLSEXT) */ |
| 88 |
|
| 89 |
#if OPENSSL_VERSION_NUMBER>=0x10100000L |
| 90 |
NOEXPORT int str_to_proto_version(const char *); |
| 91 |
#else /* OPENSSL_VERSION_NUMBER<0x10100000L */ |
| 92 |
NOEXPORT char *tls_methods_set(SERVICE_OPTIONS *, const char *); |
| 93 |
NOEXPORT char *tls_methods_check(SERVICE_OPTIONS *); |
| 94 |
#endif /* OPENSSL_VERSION_NUMBER<0x10100000L */ |
| 95 |
|
| 96 |
NOEXPORT const char *parse_debug_level(char *, SERVICE_OPTIONS *); |
| 97 |
|
| 98 |
#ifndef OPENSSL_NO_PSK |
| 99 |
NOEXPORT PSK_KEYS *psk_read(char *); |
| 100 |
NOEXPORT PSK_KEYS *psk_dup(PSK_KEYS *); |
| 101 |
NOEXPORT void psk_free(PSK_KEYS *); |
| 102 |
#endif /* !defined(OPENSSL_NO_PSK) */ |
| 103 |
|
| 104 |
#if OPENSSL_VERSION_NUMBER>=0x10000000L |
| 105 |
NOEXPORT TICKET_KEY *key_read(char *, const char *); |
| 106 |
NOEXPORT TICKET_KEY *key_dup(TICKET_KEY *); |
| 107 |
NOEXPORT void key_free(TICKET_KEY *); |
| 108 |
#endif /* OpenSSL 1.0.0 or later */ |
| 109 |
|
| 110 |
typedef struct { |
| 111 |
const char *name; |
| 112 |
uint64_t value; |
| 113 |
} SSL_OPTION; |
| 114 |
|
| 115 |
static const SSL_OPTION ssl_opts[]={ |
| 116 |
#ifdef SSL_OP_ALL |
| 117 |
{"ALL", SSL_OP_ALL}, |
| 118 |
#endif |
| 119 |
#ifdef SSL_OP_ALLOW_CLIENT_RENEGOTIATION |
| 120 |
{"ALLOW_CLIENT_RENEGOTIATION", SSL_OP_ALLOW_CLIENT_RENEGOTIATION}, |
| 121 |
#endif |
| 122 |
#ifdef SSL_OP_ALLOW_NO_DHE_KEX |
| 123 |
{"ALLOW_NO_DHE_KEX", SSL_OP_ALLOW_NO_DHE_KEX}, |
| 124 |
#endif |
| 125 |
#ifdef SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION |
| 126 |
{"ALLOW_UNSAFE_LEGACY_RENEGOTIATION", SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION}, |
| 127 |
#endif |
| 128 |
#ifdef SSL_OP_CIPHER_SERVER_PREFERENCE |
| 129 |
{"CIPHER_SERVER_PREFERENCE", SSL_OP_CIPHER_SERVER_PREFERENCE}, |
| 130 |
#endif |
| 131 |
#ifdef SSL_OP_CISCO_ANYCONNECT |
| 132 |
{"CISCO_ANYCONNECT", SSL_OP_CISCO_ANYCONNECT}, |
| 133 |
#endif |
| 134 |
#ifdef SSL_OP_CLEANSE_PLAINTEXT |
| 135 |
{"CLEANSE_PLAINTEXT", SSL_OP_CLEANSE_PLAINTEXT}, |
| 136 |
#endif |
| 137 |
#ifdef SSL_OP_COOKIE_EXCHANGE |
| 138 |
{"COOKIE_EXCHANGE", SSL_OP_COOKIE_EXCHANGE}, |
| 139 |
#endif |
| 140 |
#ifdef SSL_OP_CRYPTOPRO_TLSEXT_BUG |
| 141 |
{"CRYPTOPRO_TLSEXT_BUG", SSL_OP_CRYPTOPRO_TLSEXT_BUG}, |
| 142 |
#endif |
| 143 |
#ifdef SSL_OP_DISABLE_TLSEXT_CA_NAMES |
| 144 |
{"DISABLE_TLSEXT_CA_NAMES", SSL_OP_DISABLE_TLSEXT_CA_NAMES}, |
| 145 |
#endif |
| 146 |
#ifdef SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS |
| 147 |
{"DONT_INSERT_EMPTY_FRAGMENTS", SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS}, |
| 148 |
#endif |
| 149 |
#ifdef SSL_OP_ENABLE_KTLS |
| 150 |
{"ENABLE_KTLS", SSL_OP_ENABLE_KTLS}, |
| 151 |
#endif |
| 152 |
#ifdef SSL_OP_ENABLE_MIDDLEBOX_COMPAT |
| 153 |
{"ENABLE_MIDDLEBOX_COMPAT", SSL_OP_ENABLE_MIDDLEBOX_COMPAT}, |
| 154 |
#endif |
| 155 |
#ifdef SSL_OP_EPHEMERAL_RSA |
| 156 |
{"EPHEMERAL_RSA", SSL_OP_EPHEMERAL_RSA}, |
| 157 |
#endif |
| 158 |
#ifdef SSL_OP_IGNORE_UNEXPECTED_EOF |
| 159 |
{"IGNORE_UNEXPECTED_EOF", SSL_OP_IGNORE_UNEXPECTED_EOF}, |
| 160 |
#endif |
| 161 |
#ifdef SSL_OP_LEGACY_SERVER_CONNECT |
| 162 |
{"LEGACY_SERVER_CONNECT", SSL_OP_LEGACY_SERVER_CONNECT}, |
| 163 |
#endif |
| 164 |
#ifdef SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER |
| 165 |
{"MICROSOFT_BIG_SSLV3_BUFFER", SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER}, |
| 166 |
#endif |
| 167 |
#ifdef SSL_OP_MICROSOFT_SESS_ID_BUG |
| 168 |
{"MICROSOFT_SESS_ID_BUG", SSL_OP_MICROSOFT_SESS_ID_BUG}, |
| 169 |
#endif |
| 170 |
#ifdef SSL_OP_MSIE_SSLV2_RSA_PADDING |
| 171 |
{"MSIE_SSLV2_RSA_PADDING", SSL_OP_MSIE_SSLV2_RSA_PADDING}, |
| 172 |
#endif |
| 173 |
#ifdef SSL_OP_NETSCAPE_CA_DN_BUG |
| 174 |
{"NETSCAPE_CA_DN_BUG", SSL_OP_NETSCAPE_CA_DN_BUG}, |
| 175 |
#endif |
| 176 |
#ifdef SSL_OP_NETSCAPE_CHALLENGE_BUG |
| 177 |
{"NETSCAPE_CHALLENGE_BUG", SSL_OP_NETSCAPE_CHALLENGE_BUG}, |
| 178 |
#endif |
| 179 |
#ifdef SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG |
| 180 |
{"NETSCAPE_DEMO_CIPHER_CHANGE_BUG", SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG}, |
| 181 |
#endif |
| 182 |
#ifdef SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG |
| 183 |
{"NETSCAPE_REUSE_CIPHER_CHANGE_BUG", SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG}, |
| 184 |
#endif |
| 185 |
#ifdef SSL_OP_NO_ANTI_REPLAY |
| 186 |
{"NO_ANTI_REPLAY", SSL_OP_NO_ANTI_REPLAY}, |
| 187 |
#endif |
| 188 |
#ifdef SSL_OP_NO_COMPRESSION |
| 189 |
{"NO_COMPRESSION", SSL_OP_NO_COMPRESSION}, |
| 190 |
#endif |
| 191 |
#ifdef SSL_OP_NO_DTLS_MASK |
| 192 |
{"NO_DTLS_MASK", SSL_OP_NO_DTLS_MASK}, |
| 193 |
#endif |
| 194 |
#ifdef SSL_OP_NO_DTLSv1 |
| 195 |
{"NO_DTLSv1", SSL_OP_NO_DTLSv1}, |
| 196 |
#endif |
| 197 |
#ifdef SSL_OP_NO_DTLSv1_2 |
| 198 |
{"NO_DTLSv1_2", SSL_OP_NO_DTLSv1_2}, |
| 199 |
#endif |
| 200 |
#ifdef SSL_OP_NO_ENCRYPT_THEN_MAC |
| 201 |
{"NO_ENCRYPT_THEN_MAC", SSL_OP_NO_ENCRYPT_THEN_MAC}, |
| 202 |
#endif |
| 203 |
#ifdef SSL_OP_NO_EXTENDED_MASTER_SECRET |
| 204 |
{"NO_EXTENDED_MASTER_SECRET", SSL_OP_NO_EXTENDED_MASTER_SECRET}, |
| 205 |
#endif |
| 206 |
#ifdef SSL_OP_NO_QUERY_MTU |
| 207 |
{"NO_QUERY_MTU", SSL_OP_NO_QUERY_MTU}, |
| 208 |
#endif |
| 209 |
#ifdef SSL_OP_NO_RENEGOTIATION |
| 210 |
{"NO_RENEGOTIATION", SSL_OP_NO_RENEGOTIATION}, |
| 211 |
#endif |
| 212 |
#ifdef SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION |
| 213 |
{"NO_SESSION_RESUMPTION_ON_RENEGOTIATION", SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION}, |
| 214 |
#endif |
| 215 |
#ifdef SSL_OP_NO_SSL_MASK |
| 216 |
{"NO_SSL_MASK", SSL_OP_NO_SSL_MASK}, |
| 217 |
#endif |
| 218 |
#ifdef SSL_OP_NO_SSLv2 |
| 219 |
{"NO_SSLv2", SSL_OP_NO_SSLv2}, |
| 220 |
#endif |
| 221 |
#ifdef SSL_OP_NO_SSLv3 |
| 222 |
{"NO_SSLv3", SSL_OP_NO_SSLv3}, |
| 223 |
#endif |
| 224 |
#ifdef SSL_OP_NO_TICKET |
| 225 |
{"NO_TICKET", SSL_OP_NO_TICKET}, |
| 226 |
#endif |
| 227 |
#ifdef SSL_OP_NO_TLSv1 |
| 228 |
{"NO_TLSv1", SSL_OP_NO_TLSv1}, |
| 229 |
#endif |
| 230 |
#ifdef SSL_OP_NO_TLSv1_1 |
| 231 |
{"NO_TLSv1_1", SSL_OP_NO_TLSv1_1}, |
| 232 |
#endif |
| 233 |
#ifdef SSL_OP_NO_TLSv1_2 |
| 234 |
{"NO_TLSv1_2", SSL_OP_NO_TLSv1_2}, |
| 235 |
#endif |
| 236 |
#ifdef SSL_OP_NO_TLSv1_3 |
| 237 |
{"NO_TLSv1_3", SSL_OP_NO_TLSv1_3}, |
| 238 |
#endif |
| 239 |
#ifdef SSL_OP_PKCS1_CHECK_1 |
| 240 |
{"PKCS1_CHECK_1", SSL_OP_PKCS1_CHECK_1}, |
| 241 |
#endif |
| 242 |
#ifdef SSL_OP_PKCS1_CHECK_2 |
| 243 |
{"PKCS1_CHECK_2", SSL_OP_PKCS1_CHECK_2}, |
| 244 |
#endif |
| 245 |
#ifdef SSL_OP_PRIORITIZE_CHACHA |
| 246 |
{"PRIORITIZE_CHACHA", SSL_OP_PRIORITIZE_CHACHA}, |
| 247 |
#endif |
| 248 |
#ifdef SSL_OP_SAFARI_ECDHE_ECDSA_BUG |
| 249 |
{"SAFARI_ECDHE_ECDSA_BUG", SSL_OP_SAFARI_ECDHE_ECDSA_BUG}, |
| 250 |
#endif |
| 251 |
#ifdef SSL_OP_SINGLE_DH_USE |
| 252 |
{"SINGLE_DH_USE", SSL_OP_SINGLE_DH_USE}, |
| 253 |
#endif |
| 254 |
#ifdef SSL_OP_SINGLE_ECDH_USE |
| 255 |
{"SINGLE_ECDH_USE", SSL_OP_SINGLE_ECDH_USE}, |
| 256 |
#endif |
| 257 |
#ifdef SSL_OP_SSLEAY_080_CLIENT_DH_BUG |
| 258 |
{"SSLEAY_080_CLIENT_DH_BUG", SSL_OP_SSLEAY_080_CLIENT_DH_BUG}, |
| 259 |
#endif |
| 260 |
#ifdef SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG |
| 261 |
{"SSLREF2_REUSE_CERT_TYPE_BUG", SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG}, |
| 262 |
#endif |
| 263 |
#ifdef SSL_OP_TLS_BLOCK_PADDING_BUG |
| 264 |
{"TLS_BLOCK_PADDING_BUG", SSL_OP_TLS_BLOCK_PADDING_BUG}, |
| 265 |
#endif |
| 266 |
#ifdef SSL_OP_TLS_D5_BUG |
| 267 |
{"TLS_D5_BUG", SSL_OP_TLS_D5_BUG}, |
| 268 |
#endif |
| 269 |
#ifdef SSL_OP_TLSEXT_PADDING |
| 270 |
{"TLSEXT_PADDING", SSL_OP_TLSEXT_PADDING}, |
| 271 |
#endif |
| 272 |
#ifdef SSL_OP_TLS_ROLLBACK_BUG |
| 273 |
{"TLS_ROLLBACK_BUG", SSL_OP_TLS_ROLLBACK_BUG}, |
| 274 |
#endif |
| 275 |
#ifdef SSL_OP_ENABLE_KTLS_TX_ZEROCOPY_SENDFILE |
| 276 |
{"ENABLE_KTLS_TX_ZEROCOPY_SENDFILE", SSL_OP_ENABLE_KTLS_TX_ZEROCOPY_SENDFILE}, |
| 277 |
#endif |
| 278 |
#ifdef SSL_OP_LEGACY_EC_POINT_FORMATS |
| 279 |
{"LEGACY_EC_POINT_FORMATS", SSL_OP_LEGACY_EC_POINT_FORMATS}, |
| 280 |
#endif |
| 281 |
#ifdef SSL_OP_NO_RX_CERTIFICATE_COMPRESSION |
| 282 |
{"NO_RX_CERTIFICATE_COMPRESSION", SSL_OP_NO_RX_CERTIFICATE_COMPRESSION}, |
| 283 |
#endif |
| 284 |
#ifdef SSL_OP_NO_TX_CERTIFICATE_COMPRESSION |
| 285 |
{"NO_TX_CERTIFICATE_COMPRESSION", SSL_OP_NO_TX_CERTIFICATE_COMPRESSION}, |
| 286 |
#endif |
| 287 |
#ifdef SSL_OP_PREFER_NO_DHE_KEX |
| 288 |
{"PREFER_NO_DHE_KEX", SSL_OP_PREFER_NO_DHE_KEX}, |
| 289 |
#endif |
| 290 |
#ifdef SSL_OP_SERVER_PREFERENCE |
| 291 |
{"SERVER_PREFERENCE", SSL_OP_SERVER_PREFERENCE}, |
| 292 |
#endif |
| 293 |
#ifdef SSL_OP_ECH_GREASE |
| 294 |
{"ECH_GREASE", SSL_OP_ECH_GREASE}, |
| 295 |
#endif |
| 296 |
#ifdef SSL_OP_ECH_GREASE_RETRY_CONFIG |
| 297 |
{"ECH_GREASE_RETRY_CONFIG", SSL_OP_ECH_GREASE_RETRY_CONFIG}, |
| 298 |
#endif |
| 299 |
#ifdef SSL_OP_ECH_IGNORE_CID |
| 300 |
{"ECH_IGNORE_CID", SSL_OP_ECH_IGNORE_CID}, |
| 301 |
#endif |
| 302 |
#ifdef SSL_OP_ECH_TRIALDECRYPT |
| 303 |
{"ECH_TRIALDECRYPT", SSL_OP_ECH_TRIALDECRYPT}, |
| 304 |
#endif |
| 305 |
{NULL, 0} |
| 306 |
}; |
| 307 |
|
| 308 |
NOEXPORT uint64_t parse_ssl_option(char *); |
| 309 |
NOEXPORT void print_ssl_options(void); |
| 310 |
|
| 311 |
NOEXPORT SOCK_OPT *socket_options_init(void); |
| 312 |
NOEXPORT void socket_option_set_int(SOCK_OPT *, const char *, int, int); |
| 313 |
NOEXPORT SOCK_OPT *socket_options_dup(SOCK_OPT *); |
| 314 |
NOEXPORT void socket_options_free(SOCK_OPT *); |
| 315 |
NOEXPORT int socket_options_print(void); |
| 316 |
NOEXPORT char *socket_option_text(VAL_TYPE, OPT_UNION *); |
| 317 |
NOEXPORT int socket_option_parse(SOCK_OPT *, char *); |
| 318 |
|
| 319 |
#ifndef OPENSSL_NO_OCSP |
| 320 |
NOEXPORT unsigned long parse_ocsp_flag(char *); |
| 321 |
#endif /* !defined(OPENSSL_NO_OCSP) */ |
| 322 |
|
| 323 |
#ifndef OPENSSL_NO_ENGINE |
| 324 |
NOEXPORT void engine_reset_list(void); |
| 325 |
NOEXPORT const char *engine_auto(void); |
| 326 |
NOEXPORT const char *engine_open(const char *); |
| 327 |
NOEXPORT const char *engine_ctrl(const char *, const char *); |
| 328 |
NOEXPORT const char *engine_default(const char *); |
| 329 |
NOEXPORT const char *engine_init(void); |
| 330 |
NOEXPORT ENGINE *engine_get_by_id(const char *); |
| 331 |
NOEXPORT ENGINE *engine_get_by_num(const int); |
| 332 |
#endif /* !defined(OPENSSL_NO_ENGINE) */ |
| 333 |
|
| 334 |
#if OPENSSL_VERSION_NUMBER>=0x30500000L |
| 335 |
NOEXPORT int provider_parameter(OSSL_PROVIDER *, void *); |
| 336 |
#endif /* OPENSSL_VERSION_NUMBER>=0x30500000L */ |
| 337 |
|
| 338 |
NOEXPORT const char *include_config(char *, SERVICE_OPTIONS **); |
| 339 |
|
| 340 |
NOEXPORT void print_syntax(void); |
| 341 |
|
| 342 |
NOEXPORT void name_list_append(NAME_LIST **, char *); |
| 343 |
NOEXPORT void name_list_dup(NAME_LIST **, NAME_LIST *); |
| 344 |
NOEXPORT void name_list_free(NAME_LIST **); |
| 345 |
NOEXPORT void connect_session_free(SERVICE_OPTIONS *); |
| 346 |
#ifndef USE_WIN32 |
| 347 |
NOEXPORT char **arg_alloc(char *); |
| 348 |
NOEXPORT char **arg_dup(char **); |
| 349 |
NOEXPORT void arg_free(char **arg); |
| 350 |
#endif |
| 351 |
|
| 352 |
static char *configuration_file=NULL; |
| 353 |
|
| 354 |
GLOBAL_OPTIONS global_options; |
| 355 |
SERVICE_OPTIONS service_options; |
| 356 |
unsigned number_of_sections=0; |
| 357 |
|
| 358 |
static GLOBAL_OPTIONS new_global_options; |
| 359 |
static SERVICE_OPTIONS new_service_options; |
| 360 |
|
| 361 |
static const char *option_not_found= |
| 362 |
"Specified option name is not valid here"; |
| 363 |
|
| 364 |
static const char *stunnel_cipher_list= |
| 365 |
"HIGH:!aNULL:!SSLv2:!DH:!kDHEPSK"; |
| 366 |
#ifdef USE_FIPS |
| 367 |
static const char *fips_cipher_list= |
| 368 |
"FIPS:!DH:!kDHEPSK"; |
| 369 |
#endif /* USE_FIPS */ |
| 370 |
|
| 371 |
#ifndef OPENSSL_NO_TLS1_3 |
| 372 |
static const char *stunnel_ciphersuites= |
| 373 |
"TLS_AES_256_GCM_SHA384:TLS_AES_128_GCM_SHA256:TLS_CHACHA20_POLY1305_SHA256"; |
| 374 |
#endif /* TLS 1.3 */ |
| 375 |
|
| 376 |
#if OPENSSL_VERSION_NUMBER>=0x30500000L |
| 377 |
static int provider_found; |
| 378 |
#endif /* OPENSSL_VERSION_NUMBER>=0x30500000L */ |
| 379 |
|
| 380 |
/**************************************** parse commandline parameters */ |
| 381 |
|
| 382 |
/* return values: |
| 383 |
0 - configuration accepted |
| 384 |
1 - error |
| 385 |
2 - information printed |
| 386 |
*/ |
| 387 |
|
| 388 |
int options_cmdline(char *arg1, char *arg2) { |
| 389 |
const char *name; |
| 390 |
CONF_TYPE type; |
| 391 |
|
| 392 |
#ifdef USE_WIN32 |
| 393 |
(void)arg2; /* squash the unused parameter warning */ |
| 394 |
#endif |
| 395 |
if(!arg1) { |
| 396 |
name= |
| 397 |
#ifdef CONFDIR |
| 398 |
CONFDIR |
| 399 |
#ifdef USE_WIN32 |
| 400 |
"\\" |
| 401 |
#else |
| 402 |
"/" |
| 403 |
#endif |
| 404 |
#endif |
| 405 |
"stunnel.conf"; |
| 406 |
type=CONF_FILE; |
| 407 |
} else if(!strcasecmp(arg1, "-help")) { |
| 408 |
parse_global_option(CMD_PRINT_HELP, NULL, NULL, NULL); |
| 409 |
parse_service_option(CMD_PRINT_HELP, NULL, NULL, NULL); |
| 410 |
log_flush(LOG_MODE_INFO); |
| 411 |
return 2; |
| 412 |
} else if(!strcasecmp(arg1, "-version")) { |
| 413 |
parse_global_option(CMD_PRINT_DEFAULTS, NULL, NULL, NULL); |
| 414 |
parse_service_option(CMD_PRINT_DEFAULTS, NULL, NULL, NULL); |
| 415 |
log_flush(LOG_MODE_INFO); |
| 416 |
return 2; |
| 417 |
} else if(!strcasecmp(arg1, "-sockets")) { |
| 418 |
socket_options_print(); |
| 419 |
log_flush(LOG_MODE_INFO); |
| 420 |
return 2; |
| 421 |
} else if(!strcasecmp(arg1, "-options")) { |
| 422 |
print_ssl_options(); |
| 423 |
log_flush(LOG_MODE_INFO); |
| 424 |
return 2; |
| 425 |
} else |
| 426 |
#ifndef USE_WIN32 |
| 427 |
if(!strcasecmp(arg1, "-fd")) { |
| 428 |
if(!arg2) { |
| 429 |
s_log(LOG_ERR, "No file descriptor specified"); |
| 430 |
print_syntax(); |
| 431 |
return 1; |
| 432 |
} |
| 433 |
name=arg2; |
| 434 |
type=CONF_FD; |
| 435 |
} else |
| 436 |
#endif |
| 437 |
{ |
| 438 |
name=arg1; |
| 439 |
type=CONF_FILE; |
| 440 |
} |
| 441 |
|
| 442 |
if(type==CONF_FILE) { |
| 443 |
#ifdef HAVE_REALPATH |
| 444 |
char *buffer=NULL, *real_path; |
| 445 |
#ifdef MAXPATHLEN |
| 446 |
/* a workaround for pre-POSIX.1-2008 4.4BSD and Solaris */ |
| 447 |
buffer=malloc(MAXPATHLEN); |
| 448 |
#endif |
| 449 |
real_path=realpath(name, buffer); |
| 450 |
if(!real_path) { |
| 451 |
free(buffer); |
| 452 |
s_log(LOG_ERR, "Invalid configuration file name \"%s\"", name); |
| 453 |
ioerror("realpath"); |
| 454 |
return 1; |
| 455 |
} |
| 456 |
configuration_file=str_dup(real_path); |
| 457 |
free(real_path); |
| 458 |
#else |
| 459 |
configuration_file=str_dup(name); |
| 460 |
#endif |
| 461 |
#ifndef USE_WIN32 |
| 462 |
} else if(type==CONF_FD) { |
| 463 |
configuration_file=str_dup(name); |
| 464 |
#endif |
| 465 |
} |
| 466 |
return options_parse(type); |
| 467 |
} |
| 468 |
|
| 469 |
/**************************************** parse configuration file */ |
| 470 |
|
| 471 |
int options_parse(CONF_TYPE type) { |
| 472 |
SERVICE_OPTIONS *section; |
| 473 |
|
| 474 |
options_defaults(); |
| 475 |
section=&new_service_options; |
| 476 |
/* options_file() is a recursive function, so the last section of the |
| 477 |
* configuration file section needs to be initialized separately */ |
| 478 |
if(options_file(configuration_file, type, §ion) || |
| 479 |
init_section(1, §ion)) { |
| 480 |
s_log(LOG_ERR, "Configuration failed"); |
| 481 |
options_free(0); /* free the new options */ |
| 482 |
return 1; |
| 483 |
} |
| 484 |
s_log(LOG_NOTICE, "Configuration successful"); |
| 485 |
return 0; |
| 486 |
} |
| 487 |
|
| 488 |
NOEXPORT int options_file(char *path, CONF_TYPE type, |
| 489 |
SERVICE_OPTIONS **section_ptr) { |
| 490 |
DISK_FILE *df; |
| 491 |
char line_text[CONFLINELEN]; |
| 492 |
const char *errstr; |
| 493 |
char config_line[CONFLINELEN], *config_opt, *config_arg; |
| 494 |
int i, line_number=0; |
| 495 |
const u_char utf8_bom[]={0xef, 0xbb, 0xbf}; |
| 496 |
#ifndef USE_WIN32 |
| 497 |
int fd; |
| 498 |
char *tmp_str; |
| 499 |
#endif |
| 500 |
|
| 501 |
s_log(LOG_NOTICE, "Reading configuration from %s %s", |
| 502 |
type==CONF_FD ? "descriptor" : "file", path); |
| 503 |
#ifndef USE_WIN32 |
| 504 |
if(type==CONF_FD) { /* file descriptor */ |
| 505 |
fd=(int)strtol(path, &tmp_str, 10); |
| 506 |
if(tmp_str==path || *tmp_str) { /* not a number */ |
| 507 |
s_log(LOG_ERR, "Invalid file descriptor number"); |
| 508 |
print_syntax(); |
| 509 |
return 1; |
| 510 |
} |
| 511 |
df=file_fdopen(fd, FILE_MODE_READ); |
| 512 |
} else |
| 513 |
#endif |
| 514 |
df=file_open(path, FILE_MODE_READ); |
| 515 |
if(!df) { |
| 516 |
s_log(LOG_ERR, "Cannot open configuration file"); |
| 517 |
if(type!=CONF_RELOAD) |
| 518 |
print_syntax(); |
| 519 |
return 1; |
| 520 |
} |
| 521 |
|
| 522 |
while(file_getline(df, line_text, CONFLINELEN)>=0) { |
| 523 |
memcpy(config_line, line_text, CONFLINELEN); |
| 524 |
++line_number; |
| 525 |
config_opt=config_line; |
| 526 |
if(line_number==1) { |
| 527 |
if(!memcmp(config_opt, utf8_bom, sizeof utf8_bom)) { |
| 528 |
s_log(LOG_NOTICE, "UTF-8 byte order mark detected"); |
| 529 |
config_opt+=sizeof utf8_bom; |
| 530 |
} else { |
| 531 |
s_log(LOG_NOTICE, "UTF-8 byte order mark not detected"); |
| 532 |
} |
| 533 |
} |
| 534 |
|
| 535 |
while(isspace((unsigned char)*config_opt)) |
| 536 |
++config_opt; /* remove initial whitespaces */ |
| 537 |
for(i=(int)strlen(config_opt)-1; i>=0 && isspace((unsigned char)config_opt[i]); --i) |
| 538 |
config_opt[i]='\0'; /* remove trailing whitespaces */ |
| 539 |
if(config_opt[0]=='\0' || config_opt[0]=='#' || config_opt[0]==';') /* empty or comment */ |
| 540 |
continue; |
| 541 |
|
| 542 |
if(config_opt[0]=='[' && config_opt[strlen(config_opt)-1]==']') { /* new section */ |
| 543 |
if(init_section(0, section_ptr)) { |
| 544 |
file_close(df); |
| 545 |
return 1; |
| 546 |
} |
| 547 |
|
| 548 |
/* append a new SERVICE_OPTIONS structure to the list */ |
| 549 |
{ |
| 550 |
SERVICE_OPTIONS *new_section; |
| 551 |
new_section=str_alloc_detached(sizeof(SERVICE_OPTIONS)); |
| 552 |
new_section->next=NULL; |
| 553 |
(*section_ptr)->next=new_section; |
| 554 |
*section_ptr=new_section; |
| 555 |
} |
| 556 |
|
| 557 |
/* initialize the newly allocated section */ |
| 558 |
++config_opt; |
| 559 |
config_opt[strlen(config_opt)-1]='\0'; |
| 560 |
(*section_ptr)->servname=str_dup_detached(config_opt); |
| 561 |
(*section_ptr)->session=NULL; |
| 562 |
parse_service_option(CMD_SET_COPY, section_ptr, NULL, NULL); |
| 563 |
continue; |
| 564 |
} |
| 565 |
|
| 566 |
config_arg=strchr(config_line, '='); |
| 567 |
if(!config_arg) { |
| 568 |
s_log(LOG_ERR, "%s:%d: \"%s\": No '=' found", |
| 569 |
path, line_number, line_text); |
| 570 |
file_close(df); |
| 571 |
return 1; |
| 572 |
} |
| 573 |
*config_arg++='\0'; /* split into option name and argument value */ |
| 574 |
for(i=(int)strlen(config_opt)-1; i>=0 && isspace((unsigned char)config_opt[i]); --i) |
| 575 |
config_opt[i]='\0'; /* remove trailing whitespaces */ |
| 576 |
while(isspace((unsigned char)*config_arg)) |
| 577 |
++config_arg; /* remove initial whitespaces */ |
| 578 |
|
| 579 |
errstr=option_not_found; |
| 580 |
/* try global options first (e.g. for 'debug') */ |
| 581 |
if(!new_service_options.next) |
| 582 |
errstr=parse_global_option(CMD_SET_VALUE, &new_global_options, config_opt, config_arg); |
| 583 |
if(errstr==option_not_found) |
| 584 |
errstr=parse_service_option(CMD_SET_VALUE, section_ptr, config_opt, config_arg); |
| 585 |
if(errstr) { |
| 586 |
s_log(LOG_ERR, "%s:%d: \"%s\": %s", |
| 587 |
path, line_number, line_text, errstr); |
| 588 |
file_close(df); |
| 589 |
return 1; |
| 590 |
} |
| 591 |
} |
| 592 |
file_close(df); |
| 593 |
return 0; |
| 594 |
} |
| 595 |
|
| 596 |
NOEXPORT int init_section(int eof, SERVICE_OPTIONS **section_ptr) { |
| 597 |
const char *errstr; |
| 598 |
|
| 599 |
#ifndef USE_WIN32 |
| 600 |
(*section_ptr)->option.log_stderr=new_global_options.option.log_stderr; |
| 601 |
#endif /* USE_WIN32 */ |
| 602 |
|
| 603 |
if(*section_ptr==&new_service_options) { |
| 604 |
/* end of global options or inetd mode -> initialize globals */ |
| 605 |
errstr=parse_global_option(CMD_INITIALIZE, &new_global_options, NULL, NULL); |
| 606 |
if(errstr) { |
| 607 |
s_log(LOG_ERR, "Global options: %s", errstr); |
| 608 |
return 1; |
| 609 |
} |
| 610 |
} |
| 611 |
|
| 612 |
if(*section_ptr!=&new_service_options || eof) { |
| 613 |
/* end service section or inetd mode -> initialize service */ |
| 614 |
errstr=parse_service_option(CMD_INITIALIZE, section_ptr, NULL, NULL); |
| 615 |
if(errstr) { |
| 616 |
if(*section_ptr==&new_service_options) |
| 617 |
s_log(LOG_ERR, "Inetd mode: %s", errstr); |
| 618 |
else |
| 619 |
s_log(LOG_ERR, "Service [%s]: %s", |
| 620 |
(*section_ptr)->servname, errstr); |
| 621 |
return 1; |
| 622 |
} |
| 623 |
} |
| 624 |
return 0; |
| 625 |
} |
| 626 |
|
| 627 |
#ifdef USE_WIN32 |
| 628 |
|
| 629 |
int scandir(const char *dirp, struct dirent ***namelist, |
| 630 |
int (*filter)(const struct dirent *), |
| 631 |
int (*compar)(const struct dirent **, const struct dirent **)) { |
| 632 |
WIN32_FIND_DATA data; |
| 633 |
HANDLE h; |
| 634 |
unsigned num=0, allocated=0; |
| 635 |
LPTSTR path, pattern; |
| 636 |
char *name; |
| 637 |
DWORD saved_errno; |
| 638 |
|
| 639 |
(void)filter; /* squash the unused parameter warning */ |
| 640 |
(void)compar; /* squash the unused parameter warning */ |
| 641 |
path=str2tstr(dirp); |
| 642 |
pattern=str_tprintf(TEXT("%s\\*"), path); |
| 643 |
str_free(path); |
| 644 |
h=FindFirstFile(pattern, &data); |
| 645 |
saved_errno=GetLastError(); |
| 646 |
str_free(pattern); |
| 647 |
SetLastError(saved_errno); |
| 648 |
if(h==INVALID_HANDLE_VALUE) |
| 649 |
return -1; |
| 650 |
*namelist=NULL; |
| 651 |
do { |
| 652 |
if(num>=allocated) { |
| 653 |
struct dirent **tmp; |
| 654 |
|
| 655 |
allocated+=16; |
| 656 |
tmp=realloc(*namelist, allocated*sizeof(**namelist)); |
| 657 |
if(!tmp) { |
| 658 |
FindClose(h); |
| 659 |
return -1; |
| 660 |
} |
| 661 |
*namelist=tmp; |
| 662 |
} |
| 663 |
(*namelist)[num]=malloc(sizeof(struct dirent)); |
| 664 |
if(!(*namelist)[num]) { |
| 665 |
FindClose(h); |
| 666 |
return -1; |
| 667 |
} |
| 668 |
name=tstr2str(data.cFileName); |
| 669 |
strncpy((*namelist)[num]->d_name, name, MAX_PATH-1); |
| 670 |
(*namelist)[num]->d_name[MAX_PATH-1]='\0'; |
| 671 |
str_free(name); |
| 672 |
++num; |
| 673 |
} while(FindNextFile(h, &data)); |
| 674 |
FindClose(h); |
| 675 |
return (int)num; |
| 676 |
} |
| 677 |
|
| 678 |
int alphasort(const struct dirent **a, const struct dirent **b) { |
| 679 |
(void)a; /* squash the unused parameter warning */ |
| 680 |
(void)b; /* squash the unused parameter warning */ |
| 681 |
/* most Windows filesystem return sorted data */ |
| 682 |
return 0; |
| 683 |
} |
| 684 |
|
| 685 |
#endif |
| 686 |
|
| 687 |
void options_defaults(void) { |
| 688 |
SERVICE_OPTIONS *service; |
| 689 |
|
| 690 |
/* initialize globals *before* opening the config file */ |
| 691 |
memset(&new_global_options, 0, sizeof(GLOBAL_OPTIONS)); |
| 692 |
memset(&new_service_options, 0, sizeof(SERVICE_OPTIONS)); |
| 693 |
new_service_options.next=NULL; |
| 694 |
|
| 695 |
parse_global_option(CMD_SET_DEFAULTS, &new_global_options, NULL, NULL); |
| 696 |
service=&new_service_options; |
| 697 |
parse_service_option(CMD_SET_DEFAULTS, &service, NULL, NULL); |
| 698 |
} |
| 699 |
|
| 700 |
void options_apply(void) { /* apply default/validated configuration */ |
| 701 |
unsigned num=0; |
| 702 |
SERVICE_OPTIONS *section; |
| 703 |
|
| 704 |
CRYPTO_THREAD_write_lock(stunnel_locks[LOCK_SECTIONS]); |
| 705 |
|
| 706 |
memcpy(&global_options, &new_global_options, sizeof(GLOBAL_OPTIONS)); |
| 707 |
memset(&new_global_options, 0, sizeof(GLOBAL_OPTIONS)); |
| 708 |
|
| 709 |
/* service_options are used for inetd mode and to enumerate services */ |
| 710 |
for(section=new_service_options.next; section; section=section->next) |
| 711 |
section->section_number=num++; |
| 712 |
memcpy(&service_options, &new_service_options, sizeof(SERVICE_OPTIONS)); |
| 713 |
memset(&new_service_options, 0, sizeof(SERVICE_OPTIONS)); |
| 714 |
number_of_sections=num; |
| 715 |
|
| 716 |
CRYPTO_THREAD_unlock(stunnel_locks[LOCK_SECTIONS]); |
| 717 |
} |
| 718 |
|
| 719 |
void options_free(int current) { |
| 720 |
GLOBAL_OPTIONS *global=current?&global_options:&new_global_options; |
| 721 |
SERVICE_OPTIONS *service=current?&service_options:&new_service_options; |
| 722 |
|
| 723 |
parse_global_option(CMD_FREE, global, NULL, NULL); |
| 724 |
|
| 725 |
CRYPTO_THREAD_write_lock(stunnel_locks[LOCK_SECTIONS]); |
| 726 |
while(service) { |
| 727 |
SERVICE_OPTIONS *tmp=service; |
| 728 |
service=service->next; |
| 729 |
tmp->next=NULL; |
| 730 |
service_free(tmp); |
| 731 |
} |
| 732 |
CRYPTO_THREAD_unlock(stunnel_locks[LOCK_SECTIONS]); |
| 733 |
} |
| 734 |
|
| 735 |
SERVICE_OPTIONS *service_up_ref(SERVICE_OPTIONS *section) { |
| 736 |
#ifdef USE_OS_THREADS |
| 737 |
int ref; |
| 738 |
|
| 739 |
CRYPTO_atomic_add(§ion->ref, 1, &ref, stunnel_locks[LOCK_REF]); |
| 740 |
#else |
| 741 |
++(section->ref); |
| 742 |
#endif |
| 743 |
return section; |
| 744 |
} |
| 745 |
|
| 746 |
void service_free(SERVICE_OPTIONS *section) { |
| 747 |
int ref; |
| 748 |
|
| 749 |
#ifdef USE_OS_THREADS |
| 750 |
CRYPTO_atomic_add(§ion->ref, -1, &ref, stunnel_locks[LOCK_REF]); |
| 751 |
#else |
| 752 |
ref=--(section->ref); |
| 753 |
#endif |
| 754 |
if(ref<0) |
| 755 |
fatal("Negative section reference counter"); |
| 756 |
if(ref==0) { |
| 757 |
parse_service_option(CMD_FREE, §ion, NULL, NULL); |
| 758 |
} |
| 759 |
} |
| 760 |
|
| 761 |
/**************************************** global options */ |
| 762 |
|
| 763 |
NOEXPORT const char *parse_global_option(CMD cmd, GLOBAL_OPTIONS *options, char *opt, char *arg) { |
| 764 |
void *tmp; |
| 765 |
|
| 766 |
if(cmd==CMD_PRINT_DEFAULTS || cmd==CMD_PRINT_HELP) { |
| 767 |
s_log(LOG_NOTICE, " "); |
| 768 |
s_log(LOG_NOTICE, "Global options:"); |
| 769 |
} |
| 770 |
|
| 771 |
/* chroot */ |
| 772 |
#ifdef HAVE_CHROOT |
| 773 |
switch(cmd) { |
| 774 |
case CMD_SET_DEFAULTS: |
| 775 |
options->chroot_dir=NULL; |
| 776 |
break; |
| 777 |
case CMD_SET_COPY: /* not used for global options */ |
| 778 |
break; |
| 779 |
case CMD_FREE: |
| 780 |
tmp=options->chroot_dir; |
| 781 |
options->chroot_dir=NULL; |
| 782 |
str_free(tmp); |
| 783 |
break; |
| 784 |
case CMD_SET_VALUE: |
| 785 |
if(strcasecmp(opt, "chroot")) |
| 786 |
break; |
| 787 |
options->chroot_dir=str_dup(arg); |
| 788 |
return NULL; /* OK */ |
| 789 |
case CMD_INITIALIZE: |
| 790 |
break; |
| 791 |
case CMD_PRINT_DEFAULTS: |
| 792 |
break; |
| 793 |
case CMD_PRINT_HELP: |
| 794 |
s_log(LOG_NOTICE, "%-22s = directory to chroot stunnel process", "chroot"); |
| 795 |
break; |
| 796 |
} |
| 797 |
#endif /* HAVE_CHROOT */ |
| 798 |
|
| 799 |
/* compression */ |
| 800 |
#ifndef OPENSSL_NO_COMP |
| 801 |
switch(cmd) { |
| 802 |
case CMD_SET_DEFAULTS: |
| 803 |
options->compression=COMP_NONE; |
| 804 |
break; |
| 805 |
case CMD_SET_COPY: /* not used for global options */ |
| 806 |
break; |
| 807 |
case CMD_FREE: |
| 808 |
break; |
| 809 |
case CMD_SET_VALUE: |
| 810 |
if(strcasecmp(opt, "compression")) |
| 811 |
break; |
| 812 |
#if OPENSSL_VERSION_NUMBER<0x10100000L |
| 813 |
/* only allow compression with OpenSSL 0.9.8 or later |
| 814 |
* with OpenSSL #1468 zlib memory leak fixed */ |
| 815 |
if(OpenSSL_version_num()<0x00908051L) /* 0.9.8e-beta1 */ |
| 816 |
return "Compression unsupported due to a memory leak"; |
| 817 |
#endif /* OpenSSL version < 1.1.0 */ |
| 818 |
if(!strcasecmp(arg, "deflate")) |
| 819 |
options->compression=COMP_DEFLATE; |
| 820 |
else if(!strcasecmp(arg, "zlib")) |
| 821 |
options->compression=COMP_ZLIB; |
| 822 |
#if OPENSSL_VERSION_NUMBER>=0x30200000L |
| 823 |
else if(!strcasecmp(arg, "zstd")) |
| 824 |
options->compression=COMP_ZSTD; |
| 825 |
else if(!strcasecmp(arg, "brotli")) |
| 826 |
options->compression=COMP_BROTLI; |
| 827 |
#endif /* OpenSSL version >= 3.2.0 */ |
| 828 |
else |
| 829 |
return "Specified compression type is not available"; |
| 830 |
return NULL; /* OK */ |
| 831 |
case CMD_INITIALIZE: |
| 832 |
break; |
| 833 |
case CMD_PRINT_DEFAULTS: |
| 834 |
break; |
| 835 |
case CMD_PRINT_HELP: |
| 836 |
s_log(LOG_NOTICE, "%-22s = compression type", |
| 837 |
"compression"); |
| 838 |
break; |
| 839 |
} |
| 840 |
#endif /* !defined(OPENSSL_NO_COMP) */ |
| 841 |
|
| 842 |
/* EGD */ |
| 843 |
switch(cmd) { |
| 844 |
case CMD_SET_DEFAULTS: |
| 845 |
#ifdef EGD_SOCKET |
| 846 |
options->egd_sock=EGD_SOCKET; |
| 847 |
#else |
| 848 |
options->egd_sock=NULL; |
| 849 |
#endif |
| 850 |
break; |
| 851 |
case CMD_SET_COPY: /* not used for global options */ |
| 852 |
break; |
| 853 |
case CMD_FREE: |
| 854 |
tmp=options->egd_sock; |
| 855 |
options->egd_sock=NULL; |
| 856 |
str_free(tmp); |
| 857 |
break; |
| 858 |
case CMD_SET_VALUE: |
| 859 |
if(strcasecmp(opt, "EGD")) |
| 860 |
break; |
| 861 |
options->egd_sock=str_dup(arg); |
| 862 |
return NULL; /* OK */ |
| 863 |
case CMD_INITIALIZE: |
| 864 |
break; |
| 865 |
case CMD_PRINT_DEFAULTS: |
| 866 |
#ifdef EGD_SOCKET |
| 867 |
s_log(LOG_NOTICE, "%-22s = %s", "EGD", EGD_SOCKET); |
| 868 |
#endif |
| 869 |
break; |
| 870 |
case CMD_PRINT_HELP: |
| 871 |
s_log(LOG_NOTICE, "%-22s = path to Entropy Gathering Daemon socket", "EGD"); |
| 872 |
break; |
| 873 |
} |
| 874 |
|
| 875 |
#ifndef OPENSSL_NO_ENGINE |
| 876 |
|
| 877 |
/* engine */ |
| 878 |
switch(cmd) { |
| 879 |
case CMD_SET_DEFAULTS: |
| 880 |
engine_reset_list(); |
| 881 |
break; |
| 882 |
case CMD_SET_COPY: /* not used for global options */ |
| 883 |
break; |
| 884 |
case CMD_FREE: |
| 885 |
/* FIXME: investigate if we can free it */ |
| 886 |
break; |
| 887 |
case CMD_SET_VALUE: |
| 888 |
if(strcasecmp(opt, "engine")) |
| 889 |
break; |
| 890 |
if(!strcasecmp(arg, "auto")) |
| 891 |
return engine_auto(); |
| 892 |
else |
| 893 |
return engine_open(arg); |
| 894 |
case CMD_INITIALIZE: |
| 895 |
engine_init(); |
| 896 |
break; |
| 897 |
case CMD_PRINT_DEFAULTS: |
| 898 |
break; |
| 899 |
case CMD_PRINT_HELP: |
| 900 |
s_log(LOG_NOTICE, "%-22s = auto|engine_id", |
| 901 |
"engine"); |
| 902 |
break; |
| 903 |
} |
| 904 |
|
| 905 |
/* engineCtrl */ |
| 906 |
switch(cmd) { |
| 907 |
case CMD_SET_DEFAULTS: |
| 908 |
break; |
| 909 |
case CMD_SET_COPY: /* not used for global options */ |
| 910 |
break; |
| 911 |
case CMD_FREE: |
| 912 |
break; |
| 913 |
case CMD_SET_VALUE: |
| 914 |
if(strcasecmp(opt, "engineCtrl")) |
| 915 |
break; |
| 916 |
{ |
| 917 |
char *tmp_str=strchr(arg, ':'); |
| 918 |
if(tmp_str) |
| 919 |
*tmp_str++='\0'; |
| 920 |
return engine_ctrl(arg, tmp_str); |
| 921 |
} |
| 922 |
case CMD_INITIALIZE: |
| 923 |
break; |
| 924 |
case CMD_PRINT_DEFAULTS: |
| 925 |
break; |
| 926 |
case CMD_PRINT_HELP: |
| 927 |
s_log(LOG_NOTICE, "%-22s = cmd[:arg]", |
| 928 |
"engineCtrl"); |
| 929 |
break; |
| 930 |
} |
| 931 |
|
| 932 |
/* engineDefault */ |
| 933 |
switch(cmd) { |
| 934 |
case CMD_SET_DEFAULTS: |
| 935 |
break; |
| 936 |
case CMD_SET_COPY: /* not used for global options */ |
| 937 |
break; |
| 938 |
case CMD_FREE: |
| 939 |
break; |
| 940 |
case CMD_SET_VALUE: |
| 941 |
if(strcasecmp(opt, "engineDefault")) |
| 942 |
break; |
| 943 |
return engine_default(arg); |
| 944 |
case CMD_INITIALIZE: |
| 945 |
break; |
| 946 |
case CMD_PRINT_DEFAULTS: |
| 947 |
break; |
| 948 |
case CMD_PRINT_HELP: |
| 949 |
s_log(LOG_NOTICE, "%-22s = TASK_LIST", |
| 950 |
"engineDefault"); |
| 951 |
break; |
| 952 |
} |
| 953 |
|
| 954 |
#endif /* !defined(OPENSSL_NO_ENGINE) */ |
| 955 |
|
| 956 |
/* fips */ |
| 957 |
switch(cmd) { |
| 958 |
case CMD_SET_DEFAULTS: |
| 959 |
#ifdef USE_FIPS |
| 960 |
options->option.fips=fips_default()?1:0; |
| 961 |
#endif /* USE_FIPS */ |
| 962 |
break; |
| 963 |
case CMD_SET_COPY: /* not used for global options */ |
| 964 |
break; |
| 965 |
case CMD_FREE: |
| 966 |
break; |
| 967 |
case CMD_SET_VALUE: |
| 968 |
if(strcasecmp(opt, "fips")) |
| 969 |
break; |
| 970 |
if(!strcasecmp(arg, "yes")) { |
| 971 |
#ifdef USE_FIPS |
| 972 |
options->option.fips=1; |
| 973 |
#else |
| 974 |
return "FIPS support is not available"; |
| 975 |
#endif /* USE_FIPS */ |
| 976 |
} else if(!strcasecmp(arg, "no")) { |
| 977 |
#ifdef USE_FIPS |
| 978 |
if(fips_default()) |
| 979 |
return "Failed to override system-wide FIPS mode"; |
| 980 |
options->option.fips=0; |
| 981 |
#endif /* USE_FIPS */ |
| 982 |
} else { |
| 983 |
return "The argument needs to be either 'yes' or 'no'"; |
| 984 |
} |
| 985 |
return NULL; /* OK */ |
| 986 |
case CMD_INITIALIZE: |
| 987 |
break; |
| 988 |
case CMD_PRINT_DEFAULTS: |
| 989 |
#ifdef USE_FIPS |
| 990 |
if(fips_available()) |
| 991 |
s_log(LOG_NOTICE, "%-22s = %s", "fips", fips_default()?"yes":"no"); |
| 992 |
#endif /* USE_FIPS */ |
| 993 |
break; |
| 994 |
case CMD_PRINT_HELP: |
| 995 |
#ifdef USE_FIPS |
| 996 |
if(fips_available()) |
| 997 |
s_log(LOG_NOTICE, "%-22s = yes|no FIPS 140-2 mode", |
| 998 |
"fips"); |
| 999 |
#endif /* USE_FIPS */ |
| 1000 |
break; |
| 1001 |
} |
| 1002 |
|
| 1003 |
/* foreground */ |
| 1004 |
#ifndef USE_WIN32 |
| 1005 |
switch(cmd) { |
| 1006 |
case CMD_SET_DEFAULTS: |
| 1007 |
options->option.foreground=0; |
| 1008 |
options->option.log_stderr=0; |
| 1009 |
break; |
| 1010 |
case CMD_SET_COPY: /* not used for global options */ |
| 1011 |
break; |
| 1012 |
case CMD_FREE: |
| 1013 |
break; |
| 1014 |
case CMD_SET_VALUE: |
| 1015 |
if(strcasecmp(opt, "foreground")) |
| 1016 |
break; |
| 1017 |
if(!strcasecmp(arg, "yes")) { |
| 1018 |
options->option.foreground=1; |
| 1019 |
options->option.log_stderr=1; |
| 1020 |
} else if(!strcasecmp(arg, "quiet")) { |
| 1021 |
options->option.foreground=1; |
| 1022 |
options->option.log_stderr=0; |
| 1023 |
} else if(!strcasecmp(arg, "no")) { |
| 1024 |
options->option.foreground=0; |
| 1025 |
options->option.log_stderr=0; |
| 1026 |
} else |
| 1027 |
return "The argument needs to be either 'yes', 'quiet' or 'no'"; |
| 1028 |
return NULL; /* OK */ |
| 1029 |
case CMD_INITIALIZE: |
| 1030 |
break; |
| 1031 |
case CMD_PRINT_DEFAULTS: |
| 1032 |
break; |
| 1033 |
case CMD_PRINT_HELP: |
| 1034 |
s_log(LOG_NOTICE, "%-22s = yes|quiet|no foreground mode (don't fork, log to stderr)", |
| 1035 |
"foreground"); |
| 1036 |
break; |
| 1037 |
} |
| 1038 |
#else |
| 1039 |
switch(cmd) { |
| 1040 |
case CMD_SET_DEFAULTS: |
| 1041 |
break; |
| 1042 |
case CMD_SET_COPY: /* not used for global options */ |
| 1043 |
break; |
| 1044 |
case CMD_FREE: |
| 1045 |
break; |
| 1046 |
case CMD_SET_VALUE: |
| 1047 |
if(strcasecmp(opt, "foreground")) |
| 1048 |
break; |
| 1049 |
if(!strcasecmp(arg, "yes")) { |
| 1050 |
/* ignore */ |
| 1051 |
} else if(!strcasecmp(arg, "quiet")) { |
| 1052 |
/* ignore */ |
| 1053 |
} else if(!strcasecmp(arg, "no")) { |
| 1054 |
return "The argument needs to be 'yes' or 'quiet'"; |
| 1055 |
} else |
| 1056 |
return "The argument needs to be 'yes' or 'quiet'"; |
| 1057 |
return NULL; /* OK */ |
| 1058 |
case CMD_INITIALIZE: |
| 1059 |
break; |
| 1060 |
case CMD_PRINT_DEFAULTS: |
| 1061 |
break; |
| 1062 |
case CMD_PRINT_HELP: |
| 1063 |
s_log(LOG_NOTICE, "%-22s = foreground mode", "foreground"); |
| 1064 |
break; |
| 1065 |
} |
| 1066 |
#endif |
| 1067 |
|
| 1068 |
#ifdef ICON_IMAGE |
| 1069 |
|
| 1070 |
/* iconActive */ |
| 1071 |
switch(cmd) { |
| 1072 |
case CMD_SET_DEFAULTS: |
| 1073 |
options->icon[ICON_ACTIVE]=load_icon_default(ICON_ACTIVE); |
| 1074 |
break; |
| 1075 |
case CMD_SET_COPY: /* not used for global options */ |
| 1076 |
break; |
| 1077 |
case CMD_FREE: |
| 1078 |
/* FIXME: investigate if we can free it */ |
| 1079 |
break; |
| 1080 |
case CMD_SET_VALUE: |
| 1081 |
if(strcasecmp(opt, "iconActive")) |
| 1082 |
break; |
| 1083 |
options->icon[ICON_ACTIVE]=load_icon_file(arg); |
| 1084 |
if(!options->icon[ICON_ACTIVE]) |
| 1085 |
return "Failed to load the specified icon"; |
| 1086 |
return NULL; /* OK */ |
| 1087 |
case CMD_INITIALIZE: |
| 1088 |
break; |
| 1089 |
case CMD_PRINT_DEFAULTS: |
| 1090 |
break; |
| 1091 |
case CMD_PRINT_HELP: |
| 1092 |
s_log(LOG_NOTICE, "%-22s = icon when connections are established", "iconActive"); |
| 1093 |
break; |
| 1094 |
} |
| 1095 |
|
| 1096 |
/* iconError */ |
| 1097 |
switch(cmd) { |
| 1098 |
case CMD_SET_DEFAULTS: |
| 1099 |
options->icon[ICON_ERROR]=load_icon_default(ICON_ERROR); |
| 1100 |
break; |
| 1101 |
case CMD_SET_COPY: /* not used for global options */ |
| 1102 |
break; |
| 1103 |
case CMD_FREE: |
| 1104 |
/* FIXME: investigate if we can free it */ |
| 1105 |
break; |
| 1106 |
case CMD_SET_VALUE: |
| 1107 |
if(strcasecmp(opt, "iconError")) |
| 1108 |
break; |
| 1109 |
options->icon[ICON_ERROR]=load_icon_file(arg); |
| 1110 |
if(!options->icon[ICON_ERROR]) |
| 1111 |
return "Failed to load the specified icon"; |
| 1112 |
return NULL; /* OK */ |
| 1113 |
case CMD_INITIALIZE: |
| 1114 |
break; |
| 1115 |
case CMD_PRINT_DEFAULTS: |
| 1116 |
break; |
| 1117 |
case CMD_PRINT_HELP: |
| 1118 |
s_log(LOG_NOTICE, "%-22s = icon for invalid configuration file", "iconError"); |
| 1119 |
break; |
| 1120 |
} |
| 1121 |
|
| 1122 |
/* iconIdle */ |
| 1123 |
switch(cmd) { |
| 1124 |
case CMD_SET_DEFAULTS: |
| 1125 |
options->icon[ICON_IDLE]=load_icon_default(ICON_IDLE); |
| 1126 |
break; |
| 1127 |
case CMD_SET_COPY: /* not used for global options */ |
| 1128 |
break; |
| 1129 |
case CMD_FREE: |
| 1130 |
/* FIXME: investigate if we can free it */ |
| 1131 |
break; |
| 1132 |
case CMD_SET_VALUE: |
| 1133 |
if(strcasecmp(opt, "iconIdle")) |
| 1134 |
break; |
| 1135 |
options->icon[ICON_IDLE]=load_icon_file(arg); |
| 1136 |
if(!options->icon[ICON_IDLE]) |
| 1137 |
return "Failed to load the specified icon"; |
| 1138 |
return NULL; /* OK */ |
| 1139 |
case CMD_INITIALIZE: |
| 1140 |
break; |
| 1141 |
case CMD_PRINT_DEFAULTS: |
| 1142 |
break; |
| 1143 |
case CMD_PRINT_HELP: |
| 1144 |
s_log(LOG_NOTICE, "%-22s = icon when no connections were established", "iconIdle"); |
| 1145 |
break; |
| 1146 |
} |
| 1147 |
|
| 1148 |
#endif /* ICON_IMAGE */ |
| 1149 |
|
| 1150 |
/* log */ |
| 1151 |
switch(cmd) { |
| 1152 |
case CMD_SET_DEFAULTS: |
| 1153 |
options->log_file_mode=FILE_MODE_APPEND; |
| 1154 |
break; |
| 1155 |
case CMD_SET_COPY: /* not used for global options */ |
| 1156 |
break; |
| 1157 |
case CMD_FREE: |
| 1158 |
break; |
| 1159 |
case CMD_SET_VALUE: |
| 1160 |
if(strcasecmp(opt, "log")) |
| 1161 |
break; |
| 1162 |
if(!strcasecmp(arg, "append")) |
| 1163 |
options->log_file_mode=FILE_MODE_APPEND; |
| 1164 |
else if(!strcasecmp(arg, "overwrite")) |
| 1165 |
options->log_file_mode=FILE_MODE_OVERWRITE; |
| 1166 |
else |
| 1167 |
return "The argument needs to be either 'append' or 'overwrite'"; |
| 1168 |
return NULL; /* OK */ |
| 1169 |
case CMD_INITIALIZE: |
| 1170 |
break; |
| 1171 |
case CMD_PRINT_DEFAULTS: |
| 1172 |
break; |
| 1173 |
case CMD_PRINT_HELP: |
| 1174 |
s_log(LOG_NOTICE, "%-22s = append|overwrite log file", |
| 1175 |
"log"); |
| 1176 |
break; |
| 1177 |
} |
| 1178 |
|
| 1179 |
/* output */ |
| 1180 |
switch(cmd) { |
| 1181 |
case CMD_SET_DEFAULTS: |
| 1182 |
options->output_file=NULL; |
| 1183 |
break; |
| 1184 |
case CMD_SET_COPY: /* not used for global options */ |
| 1185 |
break; |
| 1186 |
case CMD_FREE: |
| 1187 |
tmp=options->output_file; |
| 1188 |
options->output_file=NULL; |
| 1189 |
str_free(tmp); |
| 1190 |
break; |
| 1191 |
case CMD_SET_VALUE: |
| 1192 |
if(strcasecmp(opt, "output")) |
| 1193 |
break; |
| 1194 |
options->output_file=str_dup(arg); |
| 1195 |
return NULL; /* OK */ |
| 1196 |
case CMD_INITIALIZE: |
| 1197 |
#ifndef USE_WIN32 |
| 1198 |
if(!options->option.foreground /* daemonize() used */ && |
| 1199 |
options->output_file /* log file enabled */ && |
| 1200 |
options->output_file[0]!='/' /* relative path */) |
| 1201 |
return "Log file must include full path name"; |
| 1202 |
#endif |
| 1203 |
break; |
| 1204 |
case CMD_PRINT_DEFAULTS: |
| 1205 |
break; |
| 1206 |
case CMD_PRINT_HELP: |
| 1207 |
s_log(LOG_NOTICE, "%-22s = file to append log messages", "output"); |
| 1208 |
break; |
| 1209 |
} |
| 1210 |
|
| 1211 |
/* pid */ |
| 1212 |
#ifndef USE_WIN32 |
| 1213 |
switch(cmd) { |
| 1214 |
case CMD_SET_DEFAULTS: |
| 1215 |
options->pidfile=NULL; /* do not create a pid file */ |
| 1216 |
break; |
| 1217 |
case CMD_SET_COPY: /* not used for global options */ |
| 1218 |
break; |
| 1219 |
case CMD_FREE: |
| 1220 |
tmp=options->pidfile; |
| 1221 |
options->pidfile=NULL; |
| 1222 |
str_free(tmp); |
| 1223 |
break; |
| 1224 |
case CMD_SET_VALUE: |
| 1225 |
if(strcasecmp(opt, "pid")) |
| 1226 |
break; |
| 1227 |
if(arg[0]) /* is argument not empty? */ |
| 1228 |
options->pidfile=str_dup(arg); |
| 1229 |
else |
| 1230 |
options->pidfile=NULL; /* empty -> do not create a pid file */ |
| 1231 |
return NULL; /* OK */ |
| 1232 |
case CMD_INITIALIZE: |
| 1233 |
if(!options->option.foreground /* daemonize() used */ && |
| 1234 |
options->pidfile /* pid file enabled */ && |
| 1235 |
options->pidfile[0]!='/' /* relative path */) |
| 1236 |
return "Pid file must include full path name"; |
| 1237 |
break; |
| 1238 |
case CMD_PRINT_DEFAULTS: |
| 1239 |
break; |
| 1240 |
case CMD_PRINT_HELP: |
| 1241 |
s_log(LOG_NOTICE, "%-22s = pid file", "pid"); |
| 1242 |
break; |
| 1243 |
} |
| 1244 |
#endif |
| 1245 |
|
| 1246 |
#if OPENSSL_VERSION_NUMBER>=0x30000000L |
| 1247 |
/* provider */ |
| 1248 |
switch(cmd) { |
| 1249 |
case CMD_SET_DEFAULTS: |
| 1250 |
break; |
| 1251 |
case CMD_SET_COPY: /* not used for global options */ |
| 1252 |
break; |
| 1253 |
case CMD_FREE: |
| 1254 |
break; |
| 1255 |
case CMD_SET_VALUE: |
| 1256 |
if(strcasecmp(opt, "provider")) |
| 1257 |
break; |
| 1258 |
if(!OSSL_PROVIDER_try_load(NULL, arg, 1)) |
| 1259 |
return "Failed to load provider"; |
| 1260 |
return NULL; /* OK */ |
| 1261 |
case CMD_INITIALIZE: |
| 1262 |
break; |
| 1263 |
case CMD_PRINT_DEFAULTS: |
| 1264 |
break; |
| 1265 |
case CMD_PRINT_HELP: |
| 1266 |
s_log(LOG_NOTICE, "%-22s = OpenSSL provider to load", "provider"); |
| 1267 |
break; |
| 1268 |
} |
| 1269 |
#endif /* OPENSSL_VERSION_NUMBER>=0x30000000L */ |
| 1270 |
|
| 1271 |
#if OPENSSL_VERSION_NUMBER>=0x30500000L |
| 1272 |
/* providerParameter */ |
| 1273 |
switch(cmd) { |
| 1274 |
case CMD_SET_DEFAULTS: |
| 1275 |
break; |
| 1276 |
case CMD_SET_COPY: /* not used for global options */ |
| 1277 |
break; |
| 1278 |
case CMD_FREE: |
| 1279 |
break; |
| 1280 |
case CMD_SET_VALUE: |
| 1281 |
if(strcasecmp(opt, "providerParameter")) |
| 1282 |
break; |
| 1283 |
provider_found=0; |
| 1284 |
if(!OSSL_PROVIDER_do_all(NULL, provider_parameter, arg)) |
| 1285 |
return "Malformed parameter"; |
| 1286 |
if(!provider_found) |
| 1287 |
return "Provider not found"; |
| 1288 |
return NULL; /* OK */ |
| 1289 |
case CMD_INITIALIZE: |
| 1290 |
break; |
| 1291 |
case CMD_PRINT_DEFAULTS: |
| 1292 |
break; |
| 1293 |
case CMD_PRINT_HELP: |
| 1294 |
s_log(LOG_NOTICE, "%-22s = provider:parameter=value", "providerParameter"); |
| 1295 |
break; |
| 1296 |
} |
| 1297 |
#endif /* OPENSSL_VERSION_NUMBER>=0x30500000L */ |
| 1298 |
|
| 1299 |
/* RNDbytes */ |
| 1300 |
switch(cmd) { |
| 1301 |
case CMD_SET_DEFAULTS: |
| 1302 |
options->random_bytes=RANDOM_BYTES; |
| 1303 |
break; |
| 1304 |
case CMD_SET_COPY: /* not used for global options */ |
| 1305 |
break; |
| 1306 |
case CMD_FREE: |
| 1307 |
break; |
| 1308 |
case CMD_SET_VALUE: |
| 1309 |
if(strcasecmp(opt, "RNDbytes")) |
| 1310 |
break; |
| 1311 |
{ |
| 1312 |
char *tmp_str; |
| 1313 |
options->random_bytes=(long)strtol(arg, &tmp_str, 10); |
| 1314 |
if(tmp_str==arg || *tmp_str) /* not a number */ |
| 1315 |
return "Illegal number of bytes to read from random seed files"; |
| 1316 |
} |
| 1317 |
return NULL; /* OK */ |
| 1318 |
case CMD_INITIALIZE: |
| 1319 |
break; |
| 1320 |
case CMD_PRINT_DEFAULTS: |
| 1321 |
s_log(LOG_NOTICE, "%-22s = %d", "RNDbytes", RANDOM_BYTES); |
| 1322 |
break; |
| 1323 |
case CMD_PRINT_HELP: |
| 1324 |
s_log(LOG_NOTICE, "%-22s = bytes to read from random seed files", "RNDbytes"); |
| 1325 |
break; |
| 1326 |
} |
| 1327 |
|
| 1328 |
/* RNDfile */ |
| 1329 |
switch(cmd) { |
| 1330 |
case CMD_SET_DEFAULTS: |
| 1331 |
#ifdef RANDOM_FILE |
| 1332 |
options->rand_file=str_dup(RANDOM_FILE); |
| 1333 |
#else |
| 1334 |
options->rand_file=NULL; |
| 1335 |
#endif |
| 1336 |
break; |
| 1337 |
case CMD_SET_COPY: /* not used for global options */ |
| 1338 |
break; |
| 1339 |
case CMD_FREE: |
| 1340 |
tmp=options->rand_file; |
| 1341 |
options->rand_file=NULL; |
| 1342 |
str_free(tmp); |
| 1343 |
break; |
| 1344 |
case CMD_SET_VALUE: |
| 1345 |
if(strcasecmp(opt, "RNDfile")) |
| 1346 |
break; |
| 1347 |
options->rand_file=str_dup(arg); |
| 1348 |
return NULL; /* OK */ |
| 1349 |
case CMD_INITIALIZE: |
| 1350 |
break; |
| 1351 |
case CMD_PRINT_DEFAULTS: |
| 1352 |
#ifdef RANDOM_FILE |
| 1353 |
s_log(LOG_NOTICE, "%-22s = %s", "RNDfile", RANDOM_FILE); |
| 1354 |
#endif |
| 1355 |
break; |
| 1356 |
case CMD_PRINT_HELP: |
| 1357 |
s_log(LOG_NOTICE, "%-22s = path to file with random seed data", "RNDfile"); |
| 1358 |
break; |
| 1359 |
} |
| 1360 |
|
| 1361 |
/* RNDoverwrite */ |
| 1362 |
switch(cmd) { |
| 1363 |
case CMD_SET_DEFAULTS: |
| 1364 |
options->option.rand_write=1; |
| 1365 |
break; |
| 1366 |
case CMD_SET_COPY: /* not used for global options */ |
| 1367 |
break; |
| 1368 |
case CMD_FREE: |
| 1369 |
break; |
| 1370 |
case CMD_SET_VALUE: |
| 1371 |
if(strcasecmp(opt, "RNDoverwrite")) |
| 1372 |
break; |
| 1373 |
if(!strcasecmp(arg, "yes")) |
| 1374 |
options->option.rand_write=1; |
| 1375 |
else if(!strcasecmp(arg, "no")) |
| 1376 |
options->option.rand_write=0; |
| 1377 |
else |
| 1378 |
return "The argument needs to be either 'yes' or 'no'"; |
| 1379 |
return NULL; /* OK */ |
| 1380 |
case CMD_INITIALIZE: |
| 1381 |
break; |
| 1382 |
case CMD_PRINT_DEFAULTS: |
| 1383 |
s_log(LOG_NOTICE, "%-22s = yes", "RNDoverwrite"); |
| 1384 |
break; |
| 1385 |
case CMD_PRINT_HELP: |
| 1386 |
s_log(LOG_NOTICE, "%-22s = yes|no overwrite seed datafiles with new random data", |
| 1387 |
"RNDoverwrite"); |
| 1388 |
break; |
| 1389 |
} |
| 1390 |
|
| 1391 |
/* setEnv */ |
| 1392 |
switch(cmd) { |
| 1393 |
case CMD_SET_DEFAULTS: |
| 1394 |
break; |
| 1395 |
case CMD_SET_COPY: /* not used for global options */ |
| 1396 |
break; |
| 1397 |
case CMD_FREE: |
| 1398 |
break; |
| 1399 |
case CMD_SET_VALUE: |
| 1400 |
if(strcasecmp(opt, "setEnv")) |
| 1401 |
break; |
| 1402 |
{ |
| 1403 |
char *value; |
| 1404 |
|
| 1405 |
value=strchr(arg, '='); |
| 1406 |
if(value) |
| 1407 |
*value++='\0'; |
| 1408 |
else |
| 1409 |
value=""; |
| 1410 |
#ifdef USE_WIN32 |
| 1411 |
if(_putenv_s(arg, value)) |
| 1412 |
#else |
| 1413 |
if(*value ? setenv(arg, value, 1) : unsetenv(arg)) |
| 1414 |
#endif |
| 1415 |
return "Memory allocation failed"; |
| 1416 |
} |
| 1417 |
return NULL; /* OK */ |
| 1418 |
case CMD_INITIALIZE: |
| 1419 |
break; |
| 1420 |
case CMD_PRINT_DEFAULTS: |
| 1421 |
break; |
| 1422 |
case CMD_PRINT_HELP: |
| 1423 |
s_log(LOG_NOTICE, "%-22s = name=value of an environment variable", "setEnv"); |
| 1424 |
break; |
| 1425 |
} |
| 1426 |
|
| 1427 |
/* syslog */ |
| 1428 |
#ifndef USE_WIN32 |
| 1429 |
switch(cmd) { |
| 1430 |
case CMD_SET_DEFAULTS: |
| 1431 |
options->option.log_syslog=1; |
| 1432 |
break; |
| 1433 |
case CMD_SET_COPY: /* not used for global options */ |
| 1434 |
break; |
| 1435 |
case CMD_FREE: |
| 1436 |
break; |
| 1437 |
case CMD_SET_VALUE: |
| 1438 |
if(strcasecmp(opt, "syslog")) |
| 1439 |
break; |
| 1440 |
if(!strcasecmp(arg, "yes")) |
| 1441 |
options->option.log_syslog=1; |
| 1442 |
else if(!strcasecmp(arg, "no")) |
| 1443 |
options->option.log_syslog=0; |
| 1444 |
else |
| 1445 |
return "The argument needs to be either 'yes' or 'no'"; |
| 1446 |
return NULL; /* OK */ |
| 1447 |
case CMD_INITIALIZE: |
| 1448 |
break; |
| 1449 |
case CMD_PRINT_DEFAULTS: |
| 1450 |
break; |
| 1451 |
case CMD_PRINT_HELP: |
| 1452 |
s_log(LOG_NOTICE, "%-22s = yes|no send logging messages to syslog", |
| 1453 |
"syslog"); |
| 1454 |
break; |
| 1455 |
} |
| 1456 |
#else |
| 1457 |
switch(cmd) { |
| 1458 |
case CMD_SET_DEFAULTS: |
| 1459 |
break; |
| 1460 |
case CMD_SET_COPY: /* not used for global options */ |
| 1461 |
break; |
| 1462 |
case CMD_FREE: |
| 1463 |
break; |
| 1464 |
case CMD_SET_VALUE: |
| 1465 |
if(strcasecmp(opt, "syslog")) |
| 1466 |
break; |
| 1467 |
if(strcasecmp(arg, "no")) |
| 1468 |
return "The argument needs to be 'no'"; |
| 1469 |
return NULL; /* OK */ |
| 1470 |
case CMD_INITIALIZE: |
| 1471 |
break; |
| 1472 |
case CMD_PRINT_DEFAULTS: |
| 1473 |
break; |
| 1474 |
case CMD_PRINT_HELP: |
| 1475 |
s_log(LOG_NOTICE, "%-22s = unused syslog", |
| 1476 |
"syslog"); |
| 1477 |
break; |
| 1478 |
} |
| 1479 |
#endif |
| 1480 |
|
| 1481 |
/* taskbar */ |
| 1482 |
#ifdef USE_WIN32 |
| 1483 |
switch(cmd) { |
| 1484 |
case CMD_SET_DEFAULTS: |
| 1485 |
options->option.taskbar=1; |
| 1486 |
break; |
| 1487 |
case CMD_SET_COPY: /* not used for global options */ |
| 1488 |
break; |
| 1489 |
case CMD_FREE: |
| 1490 |
break; |
| 1491 |
case CMD_SET_VALUE: |
| 1492 |
if(strcasecmp(opt, "taskbar")) |
| 1493 |
break; |
| 1494 |
if(!strcasecmp(arg, "yes")) |
| 1495 |
options->option.taskbar=1; |
| 1496 |
else if(!strcasecmp(arg, "no")) |
| 1497 |
options->option.taskbar=0; |
| 1498 |
else |
| 1499 |
return "The argument needs to be either 'yes' or 'no'"; |
| 1500 |
return NULL; /* OK */ |
| 1501 |
case CMD_INITIALIZE: |
| 1502 |
break; |
| 1503 |
case CMD_PRINT_DEFAULTS: |
| 1504 |
s_log(LOG_NOTICE, "%-22s = yes", "taskbar"); |
| 1505 |
break; |
| 1506 |
case CMD_PRINT_HELP: |
| 1507 |
s_log(LOG_NOTICE, "%-22s = yes|no enable the taskbar icon", "taskbar"); |
| 1508 |
break; |
| 1509 |
} |
| 1510 |
#endif |
| 1511 |
|
| 1512 |
/* final checks */ |
| 1513 |
switch(cmd) { |
| 1514 |
case CMD_SET_DEFAULTS: |
| 1515 |
break; |
| 1516 |
case CMD_SET_COPY: |
| 1517 |
break; |
| 1518 |
case CMD_FREE: |
| 1519 |
memset(options, 0, sizeof(GLOBAL_OPTIONS)); |
| 1520 |
break; |
| 1521 |
case CMD_SET_VALUE: |
| 1522 |
return option_not_found; |
| 1523 |
case CMD_INITIALIZE: |
| 1524 |
/* FIPS needs to be initialized as early as possible */ |
| 1525 |
if(ssl_configure(options)) /* configure global TLS settings */ |
| 1526 |
return "Failed to initialize TLS"; |
| 1527 |
case CMD_PRINT_DEFAULTS: |
| 1528 |
break; |
| 1529 |
case CMD_PRINT_HELP: |
| 1530 |
break; |
| 1531 |
} |
| 1532 |
return NULL; /* OK */ |
| 1533 |
} |
| 1534 |
|
| 1535 |
/**************************************** service-level options */ |
| 1536 |
|
| 1537 |
NOEXPORT const char *parse_service_option(CMD cmd, SERVICE_OPTIONS **section_ptr, |
| 1538 |
char *opt, char *arg) { |
| 1539 |
SERVICE_OPTIONS *section; |
| 1540 |
int endpoints=0; |
| 1541 |
#ifndef USE_WIN32 |
| 1542 |
struct group *gr; |
| 1543 |
struct passwd *pw; |
| 1544 |
#endif |
| 1545 |
|
| 1546 |
section=section_ptr ? *section_ptr : NULL; |
| 1547 |
|
| 1548 |
if(cmd==CMD_SET_DEFAULTS || cmd==CMD_SET_COPY) { |
| 1549 |
section->ref=1; |
| 1550 |
if(section==&service_options) |
| 1551 |
s_log(LOG_ERR, "INTERNAL ERROR: Initializing deployed section defaults"); |
| 1552 |
else if(section==&new_service_options) |
| 1553 |
s_log(LOG_INFO, "Initializing inetd mode configuration"); |
| 1554 |
else |
| 1555 |
s_log(LOG_INFO, "Initializing service [%s]", section->servname); |
| 1556 |
} else if(cmd==CMD_FREE) { |
| 1557 |
if(section==&service_options) |
| 1558 |
s_log(LOG_DEBUG, "Deallocating deployed section defaults"); |
| 1559 |
else if(section==&new_service_options) |
| 1560 |
s_log(LOG_DEBUG, "Deallocating temporary section defaults"); |
| 1561 |
else |
| 1562 |
s_log(LOG_DEBUG, "Deallocating section [%s]", section->servname); |
| 1563 |
} else if(cmd==CMD_PRINT_DEFAULTS || cmd==CMD_PRINT_HELP) { |
| 1564 |
s_log(LOG_NOTICE, " "); |
| 1565 |
s_log(LOG_NOTICE, "Service-level options:"); |
| 1566 |
} |
| 1567 |
|
| 1568 |
/* accept */ |
| 1569 |
switch(cmd) { |
| 1570 |
case CMD_SET_DEFAULTS: |
| 1571 |
addrlist_clear(§ion->local_addr, 1); |
| 1572 |
section->local_fd=NULL; |
| 1573 |
break; |
| 1574 |
case CMD_SET_COPY: |
| 1575 |
addrlist_clear(§ion->local_addr, 1); |
| 1576 |
section->local_fd=NULL; |
| 1577 |
name_list_dup(§ion->local_addr.names, |
| 1578 |
new_service_options.local_addr.names); |
| 1579 |
section->option.default_local_addr=1; |
| 1580 |
break; |
| 1581 |
case CMD_FREE: |
| 1582 |
name_list_free(§ion->local_addr.names); |
| 1583 |
str_free(section->local_addr.addr); |
| 1584 |
str_free(section->local_fd); |
| 1585 |
break; |
| 1586 |
case CMD_SET_VALUE: |
| 1587 |
if(strcasecmp(opt, "accept")) |
| 1588 |
break; |
| 1589 |
section->option.accept=1; |
| 1590 |
if(section->option.default_local_addr) { |
| 1591 |
name_list_free(§ion->local_addr.names); |
| 1592 |
addrlist_clear(§ion->local_addr, 1); |
| 1593 |
section->local_fd=NULL; |
| 1594 |
section->option.default_local_addr=0; |
| 1595 |
} |
| 1596 |
name_list_append(§ion->local_addr.names, arg); |
| 1597 |
return NULL; /* OK */ |
| 1598 |
case CMD_INITIALIZE: |
| 1599 |
if(section->local_addr.names) { |
| 1600 |
unsigned i; |
| 1601 |
if(!addrlist_resolve(§ion->local_addr)) |
| 1602 |
return "Cannot resolve accept target"; |
| 1603 |
section->local_fd=str_alloc_detached(section->local_addr.num*sizeof(SOCKET)); |
| 1604 |
for(i=0; i<section->local_addr.num; ++i) |
| 1605 |
section->local_fd[i]=INVALID_SOCKET; |
| 1606 |
++endpoints; |
| 1607 |
} |
| 1608 |
break; |
| 1609 |
case CMD_PRINT_DEFAULTS: |
| 1610 |
break; |
| 1611 |
case CMD_PRINT_HELP: |
| 1612 |
s_log(LOG_NOTICE, "%-22s = [host:]port accept connections on specified host:port", |
| 1613 |
"accept"); |
| 1614 |
break; |
| 1615 |
} |
| 1616 |
|
| 1617 |
#ifndef OPENSSL_NO_ENGINE |
| 1618 |
/* CAengine */ |
| 1619 |
switch(cmd) { |
| 1620 |
case CMD_SET_DEFAULTS: |
| 1621 |
section->ca_engine=NULL; |
| 1622 |
break; |
| 1623 |
case CMD_SET_COPY: |
| 1624 |
name_list_dup(§ion->ca_engine, |
| 1625 |
new_service_options.ca_engine); |
| 1626 |
section->option.default_ca_engine=0; |
| 1627 |
break; |
| 1628 |
case CMD_FREE: |
| 1629 |
name_list_free(§ion->ca_engine); |
| 1630 |
break; |
| 1631 |
case CMD_SET_VALUE: |
| 1632 |
if(strcasecmp(opt, "CAengine")) |
| 1633 |
break; |
| 1634 |
if(section->option.default_ca_engine) { |
| 1635 |
name_list_free(§ion->ca_engine); |
| 1636 |
section->option.default_ca_engine=0; |
| 1637 |
} |
| 1638 |
name_list_append(§ion->ca_engine, arg); |
| 1639 |
return NULL; /* OK */ |
| 1640 |
case CMD_INITIALIZE: |
| 1641 |
break; |
| 1642 |
case CMD_PRINT_DEFAULTS: |
| 1643 |
break; |
| 1644 |
case CMD_PRINT_HELP: |
| 1645 |
s_log(LOG_NOTICE, "%-22s = engine-specific CA certificate identifier for 'verify' option", |
| 1646 |
"CAengine"); |
| 1647 |
break; |
| 1648 |
} |
| 1649 |
#endif /* !OPENSSL_NO_ENGINE */ |
| 1650 |
|
| 1651 |
/* CApath */ |
| 1652 |
switch(cmd) { |
| 1653 |
case CMD_SET_DEFAULTS: |
| 1654 |
#if 0 |
| 1655 |
section->ca_dir=(char *)X509_get_default_cert_dir(); |
| 1656 |
#endif |
| 1657 |
section->ca_dir=NULL; |
| 1658 |
break; |
| 1659 |
case CMD_SET_COPY: |
| 1660 |
section->ca_dir=str_dup_detached(new_service_options.ca_dir); |
| 1661 |
break; |
| 1662 |
case CMD_FREE: |
| 1663 |
str_free(section->ca_dir); |
| 1664 |
break; |
| 1665 |
case CMD_SET_VALUE: |
| 1666 |
if(strcasecmp(opt, "CApath")) |
| 1667 |
break; |
| 1668 |
str_free(section->ca_dir); |
| 1669 |
if(arg[0]) /* not empty */ |
| 1670 |
section->ca_dir=str_dup_detached(arg); |
| 1671 |
else |
| 1672 |
section->ca_dir=NULL; |
| 1673 |
return NULL; /* OK */ |
| 1674 |
case CMD_INITIALIZE: |
| 1675 |
break; |
| 1676 |
case CMD_PRINT_DEFAULTS: |
| 1677 |
#if 0 |
| 1678 |
s_log(LOG_NOTICE, "%-22s = %s", "CApath", |
| 1679 |
section->ca_dir ? section->ca_dir : "(none)"); |
| 1680 |
#endif |
| 1681 |
break; |
| 1682 |
case CMD_PRINT_HELP: |
| 1683 |
s_log(LOG_NOTICE, "%-22s = CA certificate directory for 'verify' option", |
| 1684 |
"CApath"); |
| 1685 |
break; |
| 1686 |
} |
| 1687 |
|
| 1688 |
/* CAfile */ |
| 1689 |
switch(cmd) { |
| 1690 |
case CMD_SET_DEFAULTS: |
| 1691 |
#if 0 |
| 1692 |
section->ca_file=(char *)X509_get_default_certfile(); |
| 1693 |
#endif |
| 1694 |
section->ca_file=NULL; |
| 1695 |
break; |
| 1696 |
case CMD_SET_COPY: |
| 1697 |
section->ca_file=str_dup_detached(new_service_options.ca_file); |
| 1698 |
break; |
| 1699 |
case CMD_FREE: |
| 1700 |
str_free(section->ca_file); |
| 1701 |
break; |
| 1702 |
case CMD_SET_VALUE: |
| 1703 |
if(strcasecmp(opt, "CAfile")) |
| 1704 |
break; |
| 1705 |
str_free(section->ca_file); |
| 1706 |
if(arg[0]) /* not empty */ |
| 1707 |
section->ca_file=str_dup_detached(arg); |
| 1708 |
else |
| 1709 |
section->ca_file=NULL; |
| 1710 |
return NULL; /* OK */ |
| 1711 |
case CMD_INITIALIZE: |
| 1712 |
break; |
| 1713 |
case CMD_PRINT_DEFAULTS: |
| 1714 |
#if 0 |
| 1715 |
s_log(LOG_NOTICE, "%-22s = %s", "CAfile", |
| 1716 |
section->ca_file ? section->ca_file : "(none)"); |
| 1717 |
#endif |
| 1718 |
break; |
| 1719 |
case CMD_PRINT_HELP: |
| 1720 |
s_log(LOG_NOTICE, "%-22s = CA certificate file for 'verify' option", |
| 1721 |
"CAfile"); |
| 1722 |
break; |
| 1723 |
} |
| 1724 |
|
| 1725 |
#if OPENSSL_VERSION_NUMBER>=0x30000000L |
| 1726 |
/* CAstore */ |
| 1727 |
switch(cmd) { |
| 1728 |
case CMD_SET_DEFAULTS: |
| 1729 |
section->ca_store=NULL; |
| 1730 |
break; |
| 1731 |
case CMD_SET_COPY: |
| 1732 |
section->ca_store=str_dup_detached(new_service_options.ca_store); |
| 1733 |
break; |
| 1734 |
case CMD_FREE: |
| 1735 |
str_free(section->ca_store); |
| 1736 |
break; |
| 1737 |
case CMD_SET_VALUE: |
| 1738 |
if(strcasecmp(opt, "CAstore")) |
| 1739 |
break; |
| 1740 |
str_free(section->ca_store); |
| 1741 |
if(arg[0]) /* not empty */ |
| 1742 |
section->ca_store=str_dup_detached(arg); |
| 1743 |
else |
| 1744 |
section->ca_store=NULL; |
| 1745 |
return NULL; /* OK */ |
| 1746 |
case CMD_INITIALIZE: |
| 1747 |
break; |
| 1748 |
case CMD_PRINT_DEFAULTS: |
| 1749 |
break; |
| 1750 |
case CMD_PRINT_HELP: |
| 1751 |
s_log(LOG_NOTICE, "%-22s = URI to store of CA certificates", |
| 1752 |
"CAstore"); |
| 1753 |
break; |
| 1754 |
} |
| 1755 |
#endif /* OPENSSL_VERSION_NUMBER>=0x30000000L */ |
| 1756 |
|
| 1757 |
/* cert */ |
| 1758 |
switch(cmd) { |
| 1759 |
case CMD_SET_DEFAULTS: |
| 1760 |
section->cert=NULL; |
| 1761 |
break; |
| 1762 |
case CMD_SET_COPY: |
| 1763 |
name_list_dup(§ion->cert, |
| 1764 |
new_service_options.cert); |
| 1765 |
section->option.default_cert=1; |
| 1766 |
break; |
| 1767 |
case CMD_FREE: |
| 1768 |
name_list_free(§ion->cert); |
| 1769 |
break; |
| 1770 |
case CMD_SET_VALUE: |
| 1771 |
if(strcasecmp(opt, "cert")) |
| 1772 |
break; |
| 1773 |
if(section->option.default_cert) { |
| 1774 |
name_list_free(§ion->cert); |
| 1775 |
section->option.default_cert=0; |
| 1776 |
} |
| 1777 |
name_list_append(§ion->cert, arg); |
| 1778 |
return NULL; /* OK */ |
| 1779 |
case CMD_INITIALIZE: |
| 1780 |
#ifndef OPENSSL_NO_PSK |
| 1781 |
if(section->psk_keys) |
| 1782 |
break; |
| 1783 |
#endif /* !defined(OPENSSL_NO_PSK) */ |
| 1784 |
#ifndef OPENSSL_NO_ENGINE |
| 1785 |
if(section->engine) |
| 1786 |
break; |
| 1787 |
#endif /* !defined(OPENSSL_NO_ENGINE) */ |
| 1788 |
if(!section->option.client && !section->cert) |
| 1789 |
return "TLS server needs a certificate"; |
| 1790 |
break; |
| 1791 |
case CMD_PRINT_DEFAULTS: |
| 1792 |
break; /* no default certificate */ |
| 1793 |
case CMD_PRINT_HELP: |
| 1794 |
s_log(LOG_NOTICE, "%-22s = certificate chain", "cert"); |
| 1795 |
break; |
| 1796 |
} |
| 1797 |
|
| 1798 |
#if OPENSSL_VERSION_NUMBER>=0x10002000L |
| 1799 |
|
| 1800 |
/* checkEmail */ |
| 1801 |
switch(cmd) { |
| 1802 |
case CMD_SET_DEFAULTS: |
| 1803 |
section->check_email=NULL; |
| 1804 |
break; |
| 1805 |
case CMD_SET_COPY: |
| 1806 |
name_list_dup(§ion->check_email, |
| 1807 |
new_service_options.check_email); |
| 1808 |
section->option.default_check_email=1; |
| 1809 |
break; |
| 1810 |
case CMD_FREE: |
| 1811 |
name_list_free(§ion->check_email); |
| 1812 |
break; |
| 1813 |
case CMD_SET_VALUE: |
| 1814 |
if(strcasecmp(opt, "checkEmail")) |
| 1815 |
break; |
| 1816 |
if(section->option.default_check_email) { |
| 1817 |
name_list_free(§ion->check_email); |
| 1818 |
section->option.default_check_email=0; |
| 1819 |
} |
| 1820 |
name_list_append(§ion->check_email, arg); |
| 1821 |
return NULL; /* OK */ |
| 1822 |
case CMD_INITIALIZE: |
| 1823 |
if(section->check_email && !section->option.verify_chain && !section->option.verify_peer) |
| 1824 |
return "Either \"verifyChain\" or \"verifyPeer\" has to be enabled"; |
| 1825 |
break; |
| 1826 |
case CMD_PRINT_DEFAULTS: |
| 1827 |
break; |
| 1828 |
case CMD_PRINT_HELP: |
| 1829 |
s_log(LOG_NOTICE, "%-22s = peer certificate email address", |
| 1830 |
"checkEmail"); |
| 1831 |
break; |
| 1832 |
} |
| 1833 |
|
| 1834 |
/* checkHost */ |
| 1835 |
switch(cmd) { |
| 1836 |
case CMD_SET_DEFAULTS: |
| 1837 |
section->check_host=NULL; |
| 1838 |
break; |
| 1839 |
case CMD_SET_COPY: |
| 1840 |
name_list_dup(§ion->check_host, |
| 1841 |
new_service_options.check_host); |
| 1842 |
section->option.default_check_host=1; |
| 1843 |
break; |
| 1844 |
case CMD_FREE: |
| 1845 |
name_list_free(§ion->check_host); |
| 1846 |
break; |
| 1847 |
case CMD_SET_VALUE: |
| 1848 |
if(strcasecmp(opt, "checkHost")) |
| 1849 |
break; |
| 1850 |
if(section->option.default_check_host) { |
| 1851 |
name_list_free(§ion->check_host); |
| 1852 |
section->option.default_check_host=0; |
| 1853 |
} |
| 1854 |
name_list_append(§ion->check_host, arg); |
| 1855 |
return NULL; /* OK */ |
| 1856 |
case CMD_INITIALIZE: |
| 1857 |
if(section->check_host && !section->option.verify_chain && !section->option.verify_peer) |
| 1858 |
return "Either \"verifyChain\" or \"verifyPeer\" has to be enabled"; |
| 1859 |
break; |
| 1860 |
case CMD_PRINT_DEFAULTS: |
| 1861 |
break; |
| 1862 |
case CMD_PRINT_HELP: |
| 1863 |
s_log(LOG_NOTICE, "%-22s = peer certificate host name pattern", |
| 1864 |
"checkHost"); |
| 1865 |
break; |
| 1866 |
} |
| 1867 |
|
| 1868 |
/* checkIP */ |
| 1869 |
switch(cmd) { |
| 1870 |
case CMD_SET_DEFAULTS: |
| 1871 |
section->check_ip=NULL; |
| 1872 |
break; |
| 1873 |
case CMD_SET_COPY: |
| 1874 |
name_list_dup(§ion->check_ip, |
| 1875 |
new_service_options.check_ip); |
| 1876 |
section->option.default_check_ip=1; |
| 1877 |
break; |
| 1878 |
case CMD_FREE: |
| 1879 |
name_list_free(§ion->check_ip); |
| 1880 |
break; |
| 1881 |
case CMD_SET_VALUE: |
| 1882 |
if(strcasecmp(opt, "checkIP")) |
| 1883 |
break; |
| 1884 |
if(section->option.default_check_ip) { |
| 1885 |
name_list_free(§ion->check_ip); |
| 1886 |
section->option.default_check_ip=0; |
| 1887 |
} |
| 1888 |
name_list_append(§ion->check_ip, arg); |
| 1889 |
return NULL; /* OK */ |
| 1890 |
case CMD_INITIALIZE: |
| 1891 |
if(section->check_ip && !section->option.verify_chain && !section->option.verify_peer) |
| 1892 |
return "Either \"verifyChain\" or \"verifyPeer\" has to be enabled"; |
| 1893 |
break; |
| 1894 |
case CMD_PRINT_DEFAULTS: |
| 1895 |
break; |
| 1896 |
case CMD_PRINT_HELP: |
| 1897 |
s_log(LOG_NOTICE, "%-22s = peer certificate IP address", |
| 1898 |
"checkIP"); |
| 1899 |
break; |
| 1900 |
} |
| 1901 |
|
| 1902 |
#endif /* OPENSSL_VERSION_NUMBER>=0x10002000L */ |
| 1903 |
|
| 1904 |
/* ciphers */ |
| 1905 |
switch(cmd) { |
| 1906 |
case CMD_SET_DEFAULTS: |
| 1907 |
section->cipher_list=NULL; |
| 1908 |
break; |
| 1909 |
case CMD_SET_COPY: |
| 1910 |
section->cipher_list=str_dup_detached(new_service_options.cipher_list); |
| 1911 |
break; |
| 1912 |
case CMD_FREE: |
| 1913 |
str_free(section->cipher_list); |
| 1914 |
break; |
| 1915 |
case CMD_SET_VALUE: |
| 1916 |
if(strcasecmp(opt, "ciphers")) |
| 1917 |
break; |
| 1918 |
str_free(section->cipher_list); |
| 1919 |
section->cipher_list=str_dup_detached(arg); |
| 1920 |
return NULL; /* OK */ |
| 1921 |
case CMD_INITIALIZE: |
| 1922 |
if(!section->cipher_list) { |
| 1923 |
/* this is only executed for global options, because |
| 1924 |
* section->cipher_list is no longer NULL in sections */ |
| 1925 |
#ifdef USE_FIPS |
| 1926 |
if(new_global_options.option.fips) |
| 1927 |
section->cipher_list=str_dup_detached(fips_cipher_list); |
| 1928 |
else |
| 1929 |
#endif /* USE_FIPS */ |
| 1930 |
section->cipher_list=str_dup_detached(stunnel_cipher_list); |
| 1931 |
} |
| 1932 |
break; |
| 1933 |
case CMD_PRINT_DEFAULTS: |
| 1934 |
#ifdef USE_FIPS |
| 1935 |
if(fips_available()) { |
| 1936 |
s_log(LOG_NOTICE, "%-22s = %s %s", "ciphers", |
| 1937 |
fips_cipher_list, "(with \"fips = yes\")"); |
| 1938 |
s_log(LOG_NOTICE, "%-22s = %s %s", "ciphers", |
| 1939 |
stunnel_cipher_list, "(with \"fips = no\")"); |
| 1940 |
} else |
| 1941 |
#endif /* USE_FIPS */ |
| 1942 |
{ |
| 1943 |
s_log(LOG_NOTICE, "%-22s = %s", "ciphers", stunnel_cipher_list); |
| 1944 |
} |
| 1945 |
break; |
| 1946 |
case CMD_PRINT_HELP: |
| 1947 |
s_log(LOG_NOTICE, "%-22s = permitted ciphers for TLS 1.2 or older", "ciphers"); |
| 1948 |
break; |
| 1949 |
} |
| 1950 |
|
| 1951 |
#ifndef OPENSSL_NO_TLS1_3 |
| 1952 |
/* ciphersuites */ |
| 1953 |
switch(cmd) { |
| 1954 |
case CMD_SET_DEFAULTS: |
| 1955 |
section->ciphersuites=NULL; |
| 1956 |
break; |
| 1957 |
case CMD_SET_COPY: |
| 1958 |
section->ciphersuites=str_dup_detached(new_service_options.ciphersuites); |
| 1959 |
break; |
| 1960 |
case CMD_FREE: |
| 1961 |
str_free(section->ciphersuites); |
| 1962 |
break; |
| 1963 |
case CMD_SET_VALUE: |
| 1964 |
if(strcasecmp(opt, "ciphersuites")) |
| 1965 |
break; |
| 1966 |
str_free(section->ciphersuites); |
| 1967 |
section->ciphersuites=str_dup_detached(arg); |
| 1968 |
return NULL; /* OK */ |
| 1969 |
case CMD_INITIALIZE: |
| 1970 |
if(!section->ciphersuites) { |
| 1971 |
/* this is only executed for global options, because |
| 1972 |
* section->ciphersuites is no longer NULL in sections */ |
| 1973 |
section->ciphersuites=str_dup_detached(stunnel_ciphersuites); |
| 1974 |
} |
| 1975 |
break; |
| 1976 |
case CMD_PRINT_DEFAULTS: |
| 1977 |
s_log(LOG_NOTICE, "%-22s = %s %s", "ciphersuites", stunnel_ciphersuites, "(with TLSv1.3)"); |
| 1978 |
break; |
| 1979 |
case CMD_PRINT_HELP: |
| 1980 |
s_log(LOG_NOTICE, "%-22s = permitted ciphersuites for TLS 1.3", "ciphersuites"); |
| 1981 |
break; |
| 1982 |
} |
| 1983 |
#endif /* TLS 1.3 */ |
| 1984 |
|
| 1985 |
/* client */ |
| 1986 |
switch(cmd) { |
| 1987 |
case CMD_SET_DEFAULTS: |
| 1988 |
section->option.client=0; |
| 1989 |
break; |
| 1990 |
case CMD_SET_COPY: |
| 1991 |
section->option.client=new_service_options.option.client; |
| 1992 |
break; |
| 1993 |
case CMD_FREE: |
| 1994 |
break; |
| 1995 |
case CMD_SET_VALUE: |
| 1996 |
if(strcasecmp(opt, "client")) |
| 1997 |
break; |
| 1998 |
if(!strcasecmp(arg, "yes")) |
| 1999 |
section->option.client=1; |
| 2000 |
else if(!strcasecmp(arg, "no")) |
| 2001 |
section->option.client=0; |
| 2002 |
else |
| 2003 |
return "The argument needs to be either 'yes' or 'no'"; |
| 2004 |
return NULL; /* OK */ |
| 2005 |
case CMD_INITIALIZE: |
| 2006 |
break; |
| 2007 |
case CMD_PRINT_DEFAULTS: |
| 2008 |
break; |
| 2009 |
case CMD_PRINT_HELP: |
| 2010 |
s_log(LOG_NOTICE, "%-22s = yes|no client mode (remote service uses TLS)", |
| 2011 |
"client"); |
| 2012 |
break; |
| 2013 |
} |
| 2014 |
|
| 2015 |
#if OPENSSL_VERSION_NUMBER>=0x10002000L |
| 2016 |
|
| 2017 |
/* config */ |
| 2018 |
switch(cmd) { |
| 2019 |
case CMD_SET_DEFAULTS: |
| 2020 |
section->config=NULL; |
| 2021 |
break; |
| 2022 |
case CMD_SET_COPY: |
| 2023 |
name_list_dup(§ion->config, new_service_options.config); |
| 2024 |
section->option.default_config=1; |
| 2025 |
break; |
| 2026 |
case CMD_FREE: |
| 2027 |
name_list_free(§ion->config); |
| 2028 |
break; |
| 2029 |
case CMD_SET_VALUE: |
| 2030 |
if(strcasecmp(opt, "config")) |
| 2031 |
break; |
| 2032 |
if(section->option.default_config) { |
| 2033 |
name_list_free(§ion->config); |
| 2034 |
section->option.default_config=0; |
| 2035 |
} |
| 2036 |
name_list_append(§ion->config, arg); |
| 2037 |
return NULL; /* OK */ |
| 2038 |
case CMD_INITIALIZE: |
| 2039 |
break; |
| 2040 |
case CMD_PRINT_DEFAULTS: |
| 2041 |
break; |
| 2042 |
case CMD_PRINT_HELP: |
| 2043 |
s_log(LOG_NOTICE, "%-22s = command[:parameter] to execute", |
| 2044 |
"config"); |
| 2045 |
break; |
| 2046 |
} |
| 2047 |
|
| 2048 |
#endif /* OPENSSL_VERSION_NUMBER>=0x10002000L */ |
| 2049 |
|
| 2050 |
/* connect */ |
| 2051 |
switch(cmd) { |
| 2052 |
case CMD_SET_DEFAULTS: |
| 2053 |
addrlist_clear(§ion->connect_addr, 0); |
| 2054 |
section->connect_session=NULL; |
| 2055 |
break; |
| 2056 |
case CMD_SET_COPY: |
| 2057 |
addrlist_clear(§ion->connect_addr, 0); |
| 2058 |
section->connect_session=NULL; |
| 2059 |
name_list_dup(§ion->connect_addr.names, |
| 2060 |
new_service_options.connect_addr.names); |
| 2061 |
section->option.default_connect_addr=1; |
| 2062 |
break; |
| 2063 |
case CMD_FREE: |
| 2064 |
name_list_free(§ion->connect_addr.names); |
| 2065 |
str_free(section->connect_addr.addr); |
| 2066 |
connect_session_free(section); |
| 2067 |
break; |
| 2068 |
case CMD_SET_VALUE: |
| 2069 |
if(strcasecmp(opt, "connect")) |
| 2070 |
break; |
| 2071 |
if(section->option.default_connect_addr) { |
| 2072 |
name_list_free(§ion->connect_addr.names); |
| 2073 |
addrlist_clear(§ion->connect_addr, 0); |
| 2074 |
section->connect_session=NULL; |
| 2075 |
section->option.default_connect_addr=0; |
| 2076 |
} |
| 2077 |
name_list_append(§ion->connect_addr.names, arg); |
| 2078 |
return NULL; /* OK */ |
| 2079 |
case CMD_INITIALIZE: |
| 2080 |
if(section->connect_addr.names) { |
| 2081 |
if(!section->option.delayed_lookup && |
| 2082 |
!addrlist_resolve(§ion->connect_addr)) { |
| 2083 |
s_log(LOG_INFO, |
| 2084 |
"Cannot resolve connect target - delaying DNS lookup"); |
| 2085 |
section->connect_addr.num=0; |
| 2086 |
section->redirect_addr.num=0; |
| 2087 |
section->option.delayed_lookup=1; |
| 2088 |
} |
| 2089 |
if(!section->option.delayed_lookup && |
| 2090 |
section->option.client && |
| 2091 |
section->connect_addr.num>1) |
| 2092 |
section->connect_session= |
| 2093 |
str_alloc_detached(section->connect_addr.num*sizeof(SSL_SESSION *)); |
| 2094 |
++endpoints; |
| 2095 |
} |
| 2096 |
break; |
| 2097 |
case CMD_PRINT_DEFAULTS: |
| 2098 |
break; |
| 2099 |
case CMD_PRINT_HELP: |
| 2100 |
s_log(LOG_NOTICE, "%-22s = [host:]port to connect", |
| 2101 |
"connect"); |
| 2102 |
break; |
| 2103 |
} |
| 2104 |
|
| 2105 |
/* CRLpath */ |
| 2106 |
switch(cmd) { |
| 2107 |
case CMD_SET_DEFAULTS: |
| 2108 |
section->crl_dir=NULL; |
| 2109 |
break; |
| 2110 |
case CMD_SET_COPY: |
| 2111 |
section->crl_dir=str_dup_detached(new_service_options.crl_dir); |
| 2112 |
break; |
| 2113 |
case CMD_FREE: |
| 2114 |
str_free(section->crl_dir); |
| 2115 |
break; |
| 2116 |
case CMD_SET_VALUE: |
| 2117 |
if(strcasecmp(opt, "CRLpath")) |
| 2118 |
break; |
| 2119 |
str_free(section->crl_dir); |
| 2120 |
if(arg[0]) /* not empty */ |
| 2121 |
section->crl_dir=str_dup_detached(arg); |
| 2122 |
else |
| 2123 |
section->crl_dir=NULL; |
| 2124 |
return NULL; /* OK */ |
| 2125 |
case CMD_INITIALIZE: |
| 2126 |
break; |
| 2127 |
case CMD_PRINT_DEFAULTS: |
| 2128 |
break; |
| 2129 |
case CMD_PRINT_HELP: |
| 2130 |
s_log(LOG_NOTICE, "%-22s = CRL directory", "CRLpath"); |
| 2131 |
break; |
| 2132 |
} |
| 2133 |
|
| 2134 |
/* CRLfile */ |
| 2135 |
switch(cmd) { |
| 2136 |
case CMD_SET_DEFAULTS: |
| 2137 |
section->crl_file=NULL; |
| 2138 |
break; |
| 2139 |
case CMD_SET_COPY: |
| 2140 |
section->crl_file=str_dup_detached(new_service_options.crl_file); |
| 2141 |
break; |
| 2142 |
case CMD_FREE: |
| 2143 |
str_free(section->crl_file); |
| 2144 |
break; |
| 2145 |
case CMD_SET_VALUE: |
| 2146 |
if(strcasecmp(opt, "CRLfile")) |
| 2147 |
break; |
| 2148 |
str_free(section->crl_file); |
| 2149 |
if(arg[0]) /* not empty */ |
| 2150 |
section->crl_file=str_dup_detached(arg); |
| 2151 |
else |
| 2152 |
section->crl_file=NULL; |
| 2153 |
return NULL; /* OK */ |
| 2154 |
case CMD_INITIALIZE: |
| 2155 |
break; |
| 2156 |
case CMD_PRINT_DEFAULTS: |
| 2157 |
break; |
| 2158 |
case CMD_PRINT_HELP: |
| 2159 |
s_log(LOG_NOTICE, "%-22s = CRL file", "CRLfile"); |
| 2160 |
break; |
| 2161 |
} |
| 2162 |
|
| 2163 |
#ifndef OPENSSL_NO_ECDH |
| 2164 |
|
| 2165 |
/* curves */ |
| 2166 |
switch(cmd) { |
| 2167 |
case CMD_SET_DEFAULTS: |
| 2168 |
section->curves = NULL; |
| 2169 |
break; |
| 2170 |
case CMD_SET_COPY: |
| 2171 |
section->curves=str_dup_detached(new_service_options.curves); |
| 2172 |
break; |
| 2173 |
case CMD_FREE: |
| 2174 |
str_free(section->curves); |
| 2175 |
break; |
| 2176 |
case CMD_SET_VALUE: |
| 2177 |
if(strcasecmp(opt, "curves") && strcasecmp(opt, "curve")) |
| 2178 |
break; |
| 2179 |
str_free(section->curves); |
| 2180 |
section->curves=str_dup_detached(arg); |
| 2181 |
return NULL; /* OK */ |
| 2182 |
case CMD_INITIALIZE: |
| 2183 |
if(!section->curves) { |
| 2184 |
/* this is only executed for global options, because |
| 2185 |
* section->curves is no longer NULL in sections */ |
| 2186 |
#ifdef USE_FIPS |
| 2187 |
if(new_global_options.option.fips) |
| 2188 |
#ifdef SSL_SYSTEM_DEFAULT_CIPHER_LIST |
| 2189 |
section->curves=str_dup_detached(DEFAULT_CURVES_FIPS); |
| 2190 |
#else /* standard OpenSSL */ |
| 2191 |
if(OpenSSL_version_num()>=0x30400000L) |
| 2192 |
section->curves=str_dup_detached(DEFAULT_CURVES_FIPS); |
| 2193 |
else |
| 2194 |
section->curves=str_dup_detached(DEFAULT_CURVES); |
| 2195 |
#endif /* Red Hat OpenSSL */ |
| 2196 |
else |
| 2197 |
#endif /* USE_FIPS */ |
| 2198 |
section->curves=str_dup_detached(DEFAULT_CURVES); |
| 2199 |
} |
| 2200 |
break; |
| 2201 |
case CMD_PRINT_DEFAULTS: |
| 2202 |
#ifdef USE_FIPS |
| 2203 |
if(fips_available()) { |
| 2204 |
s_log(LOG_NOTICE, "%-22s = %s %s", "curves", |
| 2205 |
DEFAULT_CURVES_FIPS, "(with \"fips = yes\")"); |
| 2206 |
s_log(LOG_NOTICE, "%-22s = %s %s", "curves", |
| 2207 |
DEFAULT_CURVES, "(with \"fips = no\")"); |
| 2208 |
} else |
| 2209 |
#endif /* USE_FIPS */ |
| 2210 |
{ |
| 2211 |
s_log(LOG_NOTICE, "%-22s = %s", "curves", DEFAULT_CURVES); |
| 2212 |
} |
| 2213 |
break; |
| 2214 |
case CMD_PRINT_HELP: |
| 2215 |
s_log(LOG_NOTICE, "%-22s = ECDH curve names", "curves"); |
| 2216 |
break; |
| 2217 |
} |
| 2218 |
|
| 2219 |
#endif /* !defined(OPENSSL_NO_ECDH) */ |
| 2220 |
|
| 2221 |
/* debug */ |
| 2222 |
switch(cmd) { |
| 2223 |
case CMD_SET_DEFAULTS: |
| 2224 |
section->log_level=LOG_NOTICE; |
| 2225 |
#if !defined (USE_WIN32) && !defined (__vms) |
| 2226 |
new_global_options.log_facility=LOG_DAEMON; |
| 2227 |
#endif |
| 2228 |
break; |
| 2229 |
case CMD_SET_COPY: |
| 2230 |
section->log_level=new_service_options.log_level; |
| 2231 |
break; |
| 2232 |
case CMD_FREE: |
| 2233 |
break; |
| 2234 |
case CMD_SET_VALUE: |
| 2235 |
if(strcasecmp(opt, "debug")) |
| 2236 |
break; |
| 2237 |
return parse_debug_level(arg, section); |
| 2238 |
case CMD_INITIALIZE: |
| 2239 |
break; |
| 2240 |
case CMD_PRINT_DEFAULTS: |
| 2241 |
#if !defined (USE_WIN32) && !defined (__vms) |
| 2242 |
s_log(LOG_NOTICE, "%-22s = %s", "debug", "daemon.notice"); |
| 2243 |
#else |
| 2244 |
s_log(LOG_NOTICE, "%-22s = %s", "debug", "notice"); |
| 2245 |
#endif |
| 2246 |
break; |
| 2247 |
case CMD_PRINT_HELP: |
| 2248 |
#if !defined (USE_WIN32) && !defined (__vms) |
| 2249 |
s_log(LOG_NOTICE, "%-22s = [facility].level (e.g. daemon.info)", "debug"); |
| 2250 |
#else |
| 2251 |
s_log(LOG_NOTICE, "%-22s = level (e.g. info)", "debug"); |
| 2252 |
#endif |
| 2253 |
break; |
| 2254 |
} |
| 2255 |
|
| 2256 |
/* delay */ |
| 2257 |
switch(cmd) { |
| 2258 |
case CMD_SET_DEFAULTS: |
| 2259 |
section->option.delayed_lookup=0; |
| 2260 |
break; |
| 2261 |
case CMD_SET_COPY: |
| 2262 |
section->option.delayed_lookup=new_service_options.option.delayed_lookup; |
| 2263 |
break; |
| 2264 |
case CMD_FREE: |
| 2265 |
break; |
| 2266 |
case CMD_SET_VALUE: |
| 2267 |
if(strcasecmp(opt, "delay")) |
| 2268 |
break; |
| 2269 |
if(!strcasecmp(arg, "yes")) |
| 2270 |
section->option.delayed_lookup=1; |
| 2271 |
else if(!strcasecmp(arg, "no")) |
| 2272 |
section->option.delayed_lookup=0; |
| 2273 |
else |
| 2274 |
return "The argument needs to be either 'yes' or 'no'"; |
| 2275 |
return NULL; /* OK */ |
| 2276 |
case CMD_INITIALIZE: |
| 2277 |
break; |
| 2278 |
case CMD_PRINT_DEFAULTS: |
| 2279 |
break; |
| 2280 |
case CMD_PRINT_HELP: |
| 2281 |
s_log(LOG_NOTICE, |
| 2282 |
"%-22s = yes|no delay DNS lookup for 'connect' option", |
| 2283 |
"delay"); |
| 2284 |
break; |
| 2285 |
} |
| 2286 |
|
| 2287 |
#ifndef OPENSSL_NO_ENGINE |
| 2288 |
|
| 2289 |
/* engineId */ |
| 2290 |
switch(cmd) { |
| 2291 |
case CMD_SET_DEFAULTS: |
| 2292 |
break; |
| 2293 |
case CMD_SET_COPY: |
| 2294 |
section->engine=new_service_options.engine; |
| 2295 |
break; |
| 2296 |
case CMD_FREE: |
| 2297 |
break; |
| 2298 |
case CMD_SET_VALUE: |
| 2299 |
if(strcasecmp(opt, "engineId")) |
| 2300 |
break; |
| 2301 |
section->engine=engine_get_by_id(arg); |
| 2302 |
if(!section->engine) |
| 2303 |
return "Engine ID not found"; |
| 2304 |
return NULL; /* OK */ |
| 2305 |
case CMD_INITIALIZE: |
| 2306 |
break; |
| 2307 |
case CMD_PRINT_DEFAULTS: |
| 2308 |
break; |
| 2309 |
case CMD_PRINT_HELP: |
| 2310 |
s_log(LOG_NOTICE, "%-22s = ID of engine to read the key from", |
| 2311 |
"engineId"); |
| 2312 |
break; |
| 2313 |
} |
| 2314 |
|
| 2315 |
/* engineNum */ |
| 2316 |
switch(cmd) { |
| 2317 |
case CMD_SET_DEFAULTS: |
| 2318 |
break; |
| 2319 |
case CMD_SET_COPY: |
| 2320 |
section->engine=new_service_options.engine; |
| 2321 |
break; |
| 2322 |
case CMD_FREE: |
| 2323 |
break; |
| 2324 |
case CMD_SET_VALUE: |
| 2325 |
if(strcasecmp(opt, "engineNum")) |
| 2326 |
break; |
| 2327 |
{ |
| 2328 |
char *tmp_str; |
| 2329 |
int tmp_int=(int)strtol(arg, &tmp_str, 10); |
| 2330 |
if(tmp_str==arg || *tmp_str) /* not a number */ |
| 2331 |
return "Illegal engine number"; |
| 2332 |
section->engine=engine_get_by_num(tmp_int-1); |
| 2333 |
} |
| 2334 |
if(!section->engine) |
| 2335 |
return "Illegal engine number"; |
| 2336 |
return NULL; /* OK */ |
| 2337 |
case CMD_INITIALIZE: |
| 2338 |
break; |
| 2339 |
case CMD_PRINT_DEFAULTS: |
| 2340 |
break; |
| 2341 |
case CMD_PRINT_HELP: |
| 2342 |
s_log(LOG_NOTICE, "%-22s = number of engine to read the key from", |
| 2343 |
"engineNum"); |
| 2344 |
break; |
| 2345 |
} |
| 2346 |
|
| 2347 |
#endif /* !defined(OPENSSL_NO_ENGINE) */ |
| 2348 |
|
| 2349 |
/* exec */ |
| 2350 |
switch(cmd) { |
| 2351 |
case CMD_SET_DEFAULTS: |
| 2352 |
section->exec_name=NULL; |
| 2353 |
break; |
| 2354 |
case CMD_SET_COPY: |
| 2355 |
section->exec_name=str_dup_detached(new_service_options.exec_name); |
| 2356 |
break; |
| 2357 |
case CMD_FREE: |
| 2358 |
str_free(section->exec_name); |
| 2359 |
break; |
| 2360 |
case CMD_SET_VALUE: |
| 2361 |
if(strcasecmp(opt, "exec")) |
| 2362 |
break; |
| 2363 |
str_free(section->exec_name); |
| 2364 |
section->exec_name=str_dup_detached(arg); |
| 2365 |
#ifdef USE_WIN32 |
| 2366 |
section->exec_args=str_dup_detached(arg); |
| 2367 |
#else |
| 2368 |
if(!section->exec_args) { |
| 2369 |
section->exec_args=str_alloc_detached(2*sizeof(char *)); |
| 2370 |
section->exec_args[0]=str_dup_detached(section->exec_name); |
| 2371 |
section->exec_args[1]=NULL; /* null-terminate */ |
| 2372 |
} |
| 2373 |
#endif |
| 2374 |
return NULL; /* OK */ |
| 2375 |
case CMD_INITIALIZE: |
| 2376 |
if(section->exec_name) |
| 2377 |
++endpoints; |
| 2378 |
break; |
| 2379 |
case CMD_PRINT_DEFAULTS: |
| 2380 |
break; |
| 2381 |
case CMD_PRINT_HELP: |
| 2382 |
s_log(LOG_NOTICE, "%-22s = file execute local inetd-type program", |
| 2383 |
"exec"); |
| 2384 |
break; |
| 2385 |
} |
| 2386 |
|
| 2387 |
/* execArgs */ |
| 2388 |
switch(cmd) { |
| 2389 |
case CMD_SET_DEFAULTS: |
| 2390 |
section->exec_args=NULL; |
| 2391 |
break; |
| 2392 |
case CMD_SET_COPY: |
| 2393 |
#ifdef USE_WIN32 |
| 2394 |
section->exec_args=str_dup_detached(new_service_options.exec_args); |
| 2395 |
#else |
| 2396 |
section->exec_args=arg_dup(new_service_options.exec_args); |
| 2397 |
#endif |
| 2398 |
break; |
| 2399 |
case CMD_FREE: |
| 2400 |
#ifdef USE_WIN32 |
| 2401 |
str_free(section->exec_args); |
| 2402 |
#else |
| 2403 |
arg_free(section->exec_args); |
| 2404 |
#endif |
| 2405 |
break; |
| 2406 |
case CMD_SET_VALUE: |
| 2407 |
if(strcasecmp(opt, "execArgs")) |
| 2408 |
break; |
| 2409 |
#ifdef USE_WIN32 |
| 2410 |
str_free(section->exec_args); |
| 2411 |
section->exec_args=str_dup_detached(arg); |
| 2412 |
#else |
| 2413 |
arg_free(section->exec_args); |
| 2414 |
section->exec_args=arg_alloc(arg); |
| 2415 |
#endif |
| 2416 |
return NULL; /* OK */ |
| 2417 |
case CMD_INITIALIZE: |
| 2418 |
break; |
| 2419 |
case CMD_PRINT_DEFAULTS: |
| 2420 |
break; |
| 2421 |
case CMD_PRINT_HELP: |
| 2422 |
s_log(LOG_NOTICE, "%-22s = arguments for 'exec' (including $0)", |
| 2423 |
"execArgs"); |
| 2424 |
break; |
| 2425 |
} |
| 2426 |
|
| 2427 |
/* failover */ |
| 2428 |
switch(cmd) { |
| 2429 |
case CMD_SET_DEFAULTS: |
| 2430 |
section->failover=FAILOVER_PRIO; |
| 2431 |
section->rr=0; |
| 2432 |
break; |
| 2433 |
case CMD_SET_COPY: |
| 2434 |
section->failover=new_service_options.failover; |
| 2435 |
section->rr=new_service_options.rr; |
| 2436 |
break; |
| 2437 |
case CMD_FREE: |
| 2438 |
break; |
| 2439 |
case CMD_SET_VALUE: |
| 2440 |
if(strcasecmp(opt, "failover")) |
| 2441 |
break; |
| 2442 |
if(!strcasecmp(arg, "rr")) |
| 2443 |
section->failover=FAILOVER_RR; |
| 2444 |
else if(!strcasecmp(arg, "prio")) |
| 2445 |
section->failover=FAILOVER_PRIO; |
| 2446 |
else |
| 2447 |
return "The argument needs to be either 'rr' or 'prio'"; |
| 2448 |
return NULL; /* OK */ |
| 2449 |
case CMD_INITIALIZE: |
| 2450 |
if(section->option.delayed_lookup) |
| 2451 |
section->failover=FAILOVER_PRIO; |
| 2452 |
break; |
| 2453 |
case CMD_PRINT_DEFAULTS: |
| 2454 |
break; |
| 2455 |
case CMD_PRINT_HELP: |
| 2456 |
s_log(LOG_NOTICE, "%-22s = rr|prio failover strategy", |
| 2457 |
"failover"); |
| 2458 |
break; |
| 2459 |
} |
| 2460 |
|
| 2461 |
/* ident */ |
| 2462 |
switch(cmd) { |
| 2463 |
case CMD_SET_DEFAULTS: |
| 2464 |
section->username=NULL; |
| 2465 |
break; |
| 2466 |
case CMD_SET_COPY: |
| 2467 |
section->username=str_dup_detached(new_service_options.username); |
| 2468 |
break; |
| 2469 |
case CMD_FREE: |
| 2470 |
str_free(section->username); |
| 2471 |
break; |
| 2472 |
case CMD_SET_VALUE: |
| 2473 |
if(strcasecmp(opt, "ident")) |
| 2474 |
break; |
| 2475 |
str_free(section->username); |
| 2476 |
section->username=str_dup_detached(arg); |
| 2477 |
return NULL; /* OK */ |
| 2478 |
case CMD_INITIALIZE: |
| 2479 |
break; |
| 2480 |
case CMD_PRINT_DEFAULTS: |
| 2481 |
break; |
| 2482 |
case CMD_PRINT_HELP: |
| 2483 |
s_log(LOG_NOTICE, "%-22s = username for IDENT (RFC 1413) checking", "ident"); |
| 2484 |
break; |
| 2485 |
} |
| 2486 |
|
| 2487 |
/* include */ |
| 2488 |
switch(cmd) { |
| 2489 |
case CMD_SET_DEFAULTS: |
| 2490 |
break; |
| 2491 |
case CMD_SET_COPY: |
| 2492 |
break; |
| 2493 |
case CMD_FREE: |
| 2494 |
break; |
| 2495 |
case CMD_SET_VALUE: |
| 2496 |
if(strcasecmp(opt, "include")) |
| 2497 |
break; |
| 2498 |
return include_config(arg, section_ptr); |
| 2499 |
case CMD_INITIALIZE: |
| 2500 |
break; |
| 2501 |
case CMD_PRINT_DEFAULTS: |
| 2502 |
break; |
| 2503 |
case CMD_PRINT_HELP: |
| 2504 |
s_log(LOG_NOTICE, "%-22s = directory with configuration file snippets", |
| 2505 |
"include"); |
| 2506 |
break; |
| 2507 |
} |
| 2508 |
|
| 2509 |
/* key */ |
| 2510 |
switch(cmd) { |
| 2511 |
case CMD_SET_DEFAULTS: |
| 2512 |
section->key=NULL; |
| 2513 |
break; |
| 2514 |
case CMD_SET_COPY: |
| 2515 |
section->key=str_dup_detached(new_service_options.key); |
| 2516 |
break; |
| 2517 |
case CMD_FREE: |
| 2518 |
str_free(section->key); |
| 2519 |
break; |
| 2520 |
case CMD_SET_VALUE: |
| 2521 |
if(strcasecmp(opt, "key")) |
| 2522 |
break; |
| 2523 |
str_free(section->key); |
| 2524 |
section->key=str_dup_detached(arg); |
| 2525 |
return NULL; /* OK */ |
| 2526 |
case CMD_INITIALIZE: |
| 2527 |
break; |
| 2528 |
case CMD_PRINT_DEFAULTS: |
| 2529 |
break; |
| 2530 |
case CMD_PRINT_HELP: |
| 2531 |
s_log(LOG_NOTICE, "%-22s = certificate private key", "key"); |
| 2532 |
break; |
| 2533 |
} |
| 2534 |
|
| 2535 |
/* libwrap */ |
| 2536 |
#ifdef USE_LIBWRAP |
| 2537 |
switch(cmd) { |
| 2538 |
case CMD_SET_DEFAULTS: |
| 2539 |
section->option.libwrap=0; /* disable libwrap by default */ |
| 2540 |
break; |
| 2541 |
case CMD_SET_COPY: |
| 2542 |
section->option.libwrap=new_service_options.option.libwrap; |
| 2543 |
break; |
| 2544 |
case CMD_FREE: |
| 2545 |
break; |
| 2546 |
case CMD_SET_VALUE: |
| 2547 |
if(strcasecmp(opt, "libwrap")) |
| 2548 |
break; |
| 2549 |
if(!strcasecmp(arg, "yes")) |
| 2550 |
section->option.libwrap=1; |
| 2551 |
else if(!strcasecmp(arg, "no")) |
| 2552 |
section->option.libwrap=0; |
| 2553 |
else |
| 2554 |
return "The argument needs to be either 'yes' or 'no'"; |
| 2555 |
return NULL; /* OK */ |
| 2556 |
case CMD_INITIALIZE: |
| 2557 |
break; |
| 2558 |
case CMD_PRINT_DEFAULTS: |
| 2559 |
break; |
| 2560 |
case CMD_PRINT_HELP: |
| 2561 |
s_log(LOG_NOTICE, "%-22s = yes|no use /etc/hosts.allow and /etc/hosts.deny", |
| 2562 |
"libwrap"); |
| 2563 |
break; |
| 2564 |
} |
| 2565 |
#endif /* USE_LIBWRAP */ |
| 2566 |
|
| 2567 |
/* local */ |
| 2568 |
switch(cmd) { |
| 2569 |
case CMD_SET_DEFAULTS: |
| 2570 |
section->option.local=0; |
| 2571 |
break; |
| 2572 |
case CMD_SET_COPY: |
| 2573 |
section->option.local=new_service_options.option.local; |
| 2574 |
memcpy(§ion->source_addr, &new_service_options.source_addr, |
| 2575 |
sizeof(SOCKADDR_UNION)); |
| 2576 |
break; |
| 2577 |
case CMD_FREE: |
| 2578 |
break; |
| 2579 |
case CMD_SET_VALUE: |
| 2580 |
if(strcasecmp(opt, "local")) |
| 2581 |
break; |
| 2582 |
if(!hostport2addr(§ion->source_addr, arg, "0", 1)) |
| 2583 |
return "Failed to resolve local address"; |
| 2584 |
section->option.local=1; |
| 2585 |
return NULL; /* OK */ |
| 2586 |
case CMD_INITIALIZE: |
| 2587 |
break; |
| 2588 |
case CMD_PRINT_DEFAULTS: |
| 2589 |
break; |
| 2590 |
case CMD_PRINT_HELP: |
| 2591 |
s_log(LOG_NOTICE, "%-22s = IP address to be used as source for remote" |
| 2592 |
" connections", "local"); |
| 2593 |
break; |
| 2594 |
} |
| 2595 |
|
| 2596 |
/* logId */ |
| 2597 |
switch(cmd) { |
| 2598 |
case CMD_SET_DEFAULTS: |
| 2599 |
section->log_id=LOG_ID_SEQUENTIAL; |
| 2600 |
break; |
| 2601 |
case CMD_SET_COPY: |
| 2602 |
section->log_id=new_service_options.log_id; |
| 2603 |
break; |
| 2604 |
case CMD_FREE: |
| 2605 |
break; |
| 2606 |
case CMD_SET_VALUE: |
| 2607 |
if(strcasecmp(opt, "logId")) |
| 2608 |
break; |
| 2609 |
if(!strcasecmp(arg, "sequential")) |
| 2610 |
section->log_id=LOG_ID_SEQUENTIAL; |
| 2611 |
else if(!strcasecmp(arg, "unique")) |
| 2612 |
section->log_id=LOG_ID_UNIQUE; |
| 2613 |
else if(!strcasecmp(arg, "thread")) |
| 2614 |
section->log_id=LOG_ID_THREAD; |
| 2615 |
else if(!strcasecmp(arg, "process")) |
| 2616 |
section->log_id=LOG_ID_PROCESS; |
| 2617 |
else |
| 2618 |
return "Invalid connection identifier type"; |
| 2619 |
return NULL; /* OK */ |
| 2620 |
case CMD_INITIALIZE: |
| 2621 |
break; |
| 2622 |
case CMD_PRINT_DEFAULTS: |
| 2623 |
s_log(LOG_NOTICE, "%-22s = %s", "logId", "sequential"); |
| 2624 |
break; |
| 2625 |
case CMD_PRINT_HELP: |
| 2626 |
s_log(LOG_NOTICE, "%-22s = connection identifier type", |
| 2627 |
"logId"); |
| 2628 |
break; |
| 2629 |
} |
| 2630 |
|
| 2631 |
#ifndef OPENSSL_NO_OCSP |
| 2632 |
|
| 2633 |
/* OCSP */ |
| 2634 |
switch(cmd) { |
| 2635 |
case CMD_SET_DEFAULTS: |
| 2636 |
section->ocsp_url=NULL; |
| 2637 |
break; |
| 2638 |
case CMD_SET_COPY: |
| 2639 |
section->ocsp_url=str_dup_detached(new_service_options.ocsp_url); |
| 2640 |
break; |
| 2641 |
case CMD_FREE: |
| 2642 |
str_free(section->ocsp_url); |
| 2643 |
break; |
| 2644 |
case CMD_SET_VALUE: |
| 2645 |
if(strcasecmp(opt, "ocsp")) |
| 2646 |
break; |
| 2647 |
str_free(section->ocsp_url); |
| 2648 |
section->ocsp_url=str_dup_detached(arg); |
| 2649 |
return NULL; /* OK */ |
| 2650 |
case CMD_INITIALIZE: |
| 2651 |
if((section->ocsp_url || section->option.aia) && |
| 2652 |
!section->option.verify_chain) |
| 2653 |
return "\"verifyChain\" has to be enabled for OCSP support"; |
| 2654 |
break; |
| 2655 |
case CMD_PRINT_DEFAULTS: |
| 2656 |
break; |
| 2657 |
case CMD_PRINT_HELP: |
| 2658 |
s_log(LOG_NOTICE, "%-22s = OCSP responder URL", "OCSP"); |
| 2659 |
break; |
| 2660 |
} |
| 2661 |
|
| 2662 |
/* OCSPaia */ |
| 2663 |
switch(cmd) { |
| 2664 |
case CMD_SET_DEFAULTS: |
| 2665 |
section->option.aia=0; /* disable AIA by default */ |
| 2666 |
break; |
| 2667 |
case CMD_SET_COPY: |
| 2668 |
section->option.aia=new_service_options.option.aia; |
| 2669 |
break; |
| 2670 |
case CMD_FREE: |
| 2671 |
break; |
| 2672 |
case CMD_SET_VALUE: |
| 2673 |
if(strcasecmp(opt, "OCSPaia")) |
| 2674 |
break; |
| 2675 |
if(!strcasecmp(arg, "yes")) |
| 2676 |
section->option.aia=1; |
| 2677 |
else if(!strcasecmp(arg, "no")) |
| 2678 |
section->option.aia=0; |
| 2679 |
else |
| 2680 |
return "The argument needs to be either 'yes' or 'no'"; |
| 2681 |
return NULL; /* OK */ |
| 2682 |
case CMD_INITIALIZE: |
| 2683 |
break; |
| 2684 |
case CMD_PRINT_DEFAULTS: |
| 2685 |
break; |
| 2686 |
case CMD_PRINT_HELP: |
| 2687 |
s_log(LOG_NOTICE, |
| 2688 |
"%-22s = yes|no check the AIA responders from certificates", |
| 2689 |
"OCSPaia"); |
| 2690 |
break; |
| 2691 |
} |
| 2692 |
|
| 2693 |
/* OCSPflag */ |
| 2694 |
switch(cmd) { |
| 2695 |
case CMD_SET_DEFAULTS: |
| 2696 |
section->ocsp_flags=0; |
| 2697 |
break; |
| 2698 |
case CMD_SET_COPY: |
| 2699 |
section->ocsp_flags=new_service_options.ocsp_flags; |
| 2700 |
break; |
| 2701 |
case CMD_FREE: |
| 2702 |
break; |
| 2703 |
case CMD_SET_VALUE: |
| 2704 |
if(strcasecmp(opt, "OCSPflag")) |
| 2705 |
break; |
| 2706 |
{ |
| 2707 |
unsigned long tmp_ulong=parse_ocsp_flag(arg); |
| 2708 |
if(!tmp_ulong) |
| 2709 |
return "Illegal OCSP flag"; |
| 2710 |
section->ocsp_flags|=tmp_ulong; |
| 2711 |
} |
| 2712 |
return NULL; |
| 2713 |
case CMD_INITIALIZE: |
| 2714 |
break; |
| 2715 |
case CMD_PRINT_DEFAULTS: |
| 2716 |
break; |
| 2717 |
case CMD_PRINT_HELP: |
| 2718 |
s_log(LOG_NOTICE, "%-22s = OCSP responder flags", "OCSPflag"); |
| 2719 |
break; |
| 2720 |
} |
| 2721 |
|
| 2722 |
/* OCSPnonce */ |
| 2723 |
switch(cmd) { |
| 2724 |
case CMD_SET_DEFAULTS: |
| 2725 |
section->option.nonce=0; /* disable OCSP nonce by default */ |
| 2726 |
break; |
| 2727 |
case CMD_SET_COPY: |
| 2728 |
section->option.nonce=new_service_options.option.nonce; |
| 2729 |
break; |
| 2730 |
case CMD_FREE: |
| 2731 |
break; |
| 2732 |
case CMD_SET_VALUE: |
| 2733 |
if(strcasecmp(opt, "OCSPnonce")) |
| 2734 |
break; |
| 2735 |
if(!strcasecmp(arg, "yes")) |
| 2736 |
section->option.nonce=1; |
| 2737 |
else if(!strcasecmp(arg, "no")) |
| 2738 |
section->option.nonce=0; |
| 2739 |
else |
| 2740 |
return "The argument needs to be either 'yes' or 'no'"; |
| 2741 |
return NULL; /* OK */ |
| 2742 |
case CMD_INITIALIZE: |
| 2743 |
break; |
| 2744 |
case CMD_PRINT_DEFAULTS: |
| 2745 |
break; |
| 2746 |
case CMD_PRINT_HELP: |
| 2747 |
s_log(LOG_NOTICE, |
| 2748 |
"%-22s = yes|no send and verify the OCSP nonce extension", |
| 2749 |
"OCSPnonce"); |
| 2750 |
break; |
| 2751 |
} |
| 2752 |
|
| 2753 |
/* OCSPrequire */ |
| 2754 |
switch(cmd) { |
| 2755 |
case CMD_SET_DEFAULTS: |
| 2756 |
section->option.ocsp_require=1; /* enabled by default */ |
| 2757 |
break; |
| 2758 |
case CMD_SET_COPY: |
| 2759 |
section->option.ocsp_require=new_service_options.option.ocsp_require; |
| 2760 |
break; |
| 2761 |
case CMD_FREE: |
| 2762 |
break; |
| 2763 |
case CMD_SET_VALUE: |
| 2764 |
if(strcasecmp(opt, "OCSPrequire")) |
| 2765 |
break; |
| 2766 |
if(!strcasecmp(arg, "yes")) |
| 2767 |
section->option.ocsp_require=1; |
| 2768 |
else if(!strcasecmp(arg, "no")) |
| 2769 |
section->option.ocsp_require=0; |
| 2770 |
else |
| 2771 |
return "The argument needs to be either 'yes' or 'no'"; |
| 2772 |
return NULL; /* OK */ |
| 2773 |
case CMD_INITIALIZE: |
| 2774 |
break; |
| 2775 |
case CMD_PRINT_DEFAULTS: |
| 2776 |
break; |
| 2777 |
case CMD_PRINT_HELP: |
| 2778 |
s_log(LOG_NOTICE, |
| 2779 |
"%-22s = yes|no require a conclusive OCSP response", |
| 2780 |
"OCSPrequire"); |
| 2781 |
break; |
| 2782 |
} |
| 2783 |
|
| 2784 |
#endif /* !defined(OPENSSL_NO_OCSP) */ |
| 2785 |
|
| 2786 |
/* options */ |
| 2787 |
switch(cmd) { |
| 2788 |
case CMD_SET_DEFAULTS: |
| 2789 |
section->ssl_options_set=0; |
| 2790 |
#if OPENSSL_VERSION_NUMBER>=0x009080dfL |
| 2791 |
section->ssl_options_clear=0; |
| 2792 |
#endif /* OpenSSL 0.9.8m or later */ |
| 2793 |
break; |
| 2794 |
case CMD_SET_COPY: |
| 2795 |
section->ssl_options_set=new_service_options.ssl_options_set; |
| 2796 |
#if OPENSSL_VERSION_NUMBER>=0x009080dfL |
| 2797 |
section->ssl_options_clear=new_service_options.ssl_options_clear; |
| 2798 |
#endif /* OpenSSL 0.9.8m or later */ |
| 2799 |
break; |
| 2800 |
case CMD_FREE: |
| 2801 |
break; |
| 2802 |
case CMD_SET_VALUE: |
| 2803 |
if(strcasecmp(opt, "options")) |
| 2804 |
break; |
| 2805 |
#if OPENSSL_VERSION_NUMBER>=0x009080dfL |
| 2806 |
if(*arg=='-') { |
| 2807 |
uint64_t tmp=parse_ssl_option(arg+1); |
| 2808 |
|
| 2809 |
if(tmp==INVALID_SSL_OPTION) |
| 2810 |
return "Illegal TLS option"; |
| 2811 |
section->ssl_options_clear|=tmp; |
| 2812 |
return NULL; /* OK */ |
| 2813 |
} |
| 2814 |
#endif /* OpenSSL 0.9.8m or later */ |
| 2815 |
{ |
| 2816 |
uint64_t tmp=parse_ssl_option(arg); |
| 2817 |
|
| 2818 |
if(tmp==INVALID_SSL_OPTION) |
| 2819 |
return "Illegal TLS option"; |
| 2820 |
section->ssl_options_set|=tmp; |
| 2821 |
} |
| 2822 |
return NULL; /* OK */ |
| 2823 |
case CMD_INITIALIZE: |
| 2824 |
break; |
| 2825 |
case CMD_PRINT_DEFAULTS: |
| 2826 |
s_log(LOG_NOTICE, "%-22s = %s", "options", "NO_SSLv2"); |
| 2827 |
s_log(LOG_NOTICE, "%-22s = %s", "options", "NO_SSLv3"); |
| 2828 |
break; |
| 2829 |
case CMD_PRINT_HELP: |
| 2830 |
s_log(LOG_NOTICE, "%-22s = TLS option to set/reset", "options"); |
| 2831 |
break; |
| 2832 |
} |
| 2833 |
|
| 2834 |
/* protocol */ |
| 2835 |
switch(cmd) { |
| 2836 |
case CMD_SET_DEFAULTS: |
| 2837 |
section->protocol=NULL; |
| 2838 |
break; |
| 2839 |
case CMD_SET_COPY: |
| 2840 |
section->protocol=str_dup_detached(new_service_options.protocol); |
| 2841 |
break; |
| 2842 |
case CMD_FREE: |
| 2843 |
str_free(section->protocol); |
| 2844 |
break; |
| 2845 |
case CMD_SET_VALUE: |
| 2846 |
if(strcasecmp(opt, "protocol")) |
| 2847 |
break; |
| 2848 |
str_free(section->protocol); |
| 2849 |
section->protocol=str_dup_detached(arg); |
| 2850 |
return NULL; /* OK */ |
| 2851 |
case CMD_INITIALIZE: |
| 2852 |
/* protocol_init() also initializes: |
| 2853 |
section->option.connect_before_ssl |
| 2854 |
section->option.protocol_endpoint */ |
| 2855 |
{ |
| 2856 |
const char *tmp_str=protocol_init(section); |
| 2857 |
if(tmp_str) |
| 2858 |
return tmp_str; |
| 2859 |
} |
| 2860 |
endpoints+=section->option.protocol_endpoint; |
| 2861 |
break; |
| 2862 |
case CMD_PRINT_DEFAULTS: |
| 2863 |
break; |
| 2864 |
case CMD_PRINT_HELP: |
| 2865 |
s_log(LOG_NOTICE, "%-22s = protocol to negotiate before TLS initialization", |
| 2866 |
"protocol"); |
| 2867 |
s_log(LOG_NOTICE, "%25scurrently supported: cifs, connect, imap,", ""); |
| 2868 |
s_log(LOG_NOTICE, "%25s nntp, pgsql, pop3, proxy, smtp, socks", ""); |
| 2869 |
break; |
| 2870 |
} |
| 2871 |
|
| 2872 |
/* protocolAuthentication */ |
| 2873 |
switch(cmd) { |
| 2874 |
case CMD_SET_DEFAULTS: |
| 2875 |
section->protocol_authentication=str_dup_detached("basic"); |
| 2876 |
break; |
| 2877 |
case CMD_SET_COPY: |
| 2878 |
section->protocol_authentication= |
| 2879 |
str_dup_detached(new_service_options.protocol_authentication); |
| 2880 |
break; |
| 2881 |
case CMD_FREE: |
| 2882 |
str_free(section->protocol_authentication); |
| 2883 |
break; |
| 2884 |
case CMD_SET_VALUE: |
| 2885 |
if(strcasecmp(opt, "protocolAuthentication")) |
| 2886 |
break; |
| 2887 |
str_free(section->protocol_authentication); |
| 2888 |
section->protocol_authentication=str_dup_detached(arg); |
| 2889 |
return NULL; /* OK */ |
| 2890 |
case CMD_INITIALIZE: |
| 2891 |
break; |
| 2892 |
case CMD_PRINT_DEFAULTS: |
| 2893 |
break; |
| 2894 |
case CMD_PRINT_HELP: |
| 2895 |
s_log(LOG_NOTICE, "%-22s = authentication type for protocol negotiations", |
| 2896 |
"protocolAuthentication"); |
| 2897 |
break; |
| 2898 |
} |
| 2899 |
|
| 2900 |
/* protocolDomain */ |
| 2901 |
switch(cmd) { |
| 2902 |
case CMD_SET_DEFAULTS: |
| 2903 |
section->protocol_domain=NULL; |
| 2904 |
break; |
| 2905 |
case CMD_SET_COPY: |
| 2906 |
section->protocol_domain= |
| 2907 |
str_dup_detached(new_service_options.protocol_domain); |
| 2908 |
break; |
| 2909 |
case CMD_FREE: |
| 2910 |
str_free(section->protocol_domain); |
| 2911 |
break; |
| 2912 |
case CMD_SET_VALUE: |
| 2913 |
if(strcasecmp(opt, "protocolDomain")) |
| 2914 |
break; |
| 2915 |
str_free(section->protocol_domain); |
| 2916 |
section->protocol_domain=str_dup_detached(arg); |
| 2917 |
return NULL; /* OK */ |
| 2918 |
case CMD_INITIALIZE: |
| 2919 |
break; |
| 2920 |
case CMD_PRINT_DEFAULTS: |
| 2921 |
break; |
| 2922 |
case CMD_PRINT_HELP: |
| 2923 |
s_log(LOG_NOTICE, "%-22s = domain for protocol negotiations", |
| 2924 |
"protocolDomain"); |
| 2925 |
break; |
| 2926 |
} |
| 2927 |
|
| 2928 |
/* protocolHeader */ |
| 2929 |
switch(cmd) { |
| 2930 |
case CMD_SET_DEFAULTS: |
| 2931 |
section->protocol_header=NULL; |
| 2932 |
break; |
| 2933 |
case CMD_SET_COPY: |
| 2934 |
name_list_dup(§ion->protocol_header, |
| 2935 |
new_service_options.protocol_header); |
| 2936 |
section->option.default_protocol_header=1; |
| 2937 |
break; |
| 2938 |
case CMD_FREE: |
| 2939 |
name_list_free(§ion->protocol_header); |
| 2940 |
break; |
| 2941 |
case CMD_SET_VALUE: |
| 2942 |
if(strcasecmp(opt, "protocolHeader")) |
| 2943 |
break; |
| 2944 |
if(section->option.default_protocol_header) { |
| 2945 |
name_list_free(§ion->protocol_header); |
| 2946 |
section->option.default_protocol_header=0; |
| 2947 |
} |
| 2948 |
name_list_append(§ion->protocol_header, arg); |
| 2949 |
return NULL; /* OK */ |
| 2950 |
case CMD_INITIALIZE: |
| 2951 |
break; |
| 2952 |
case CMD_PRINT_DEFAULTS: |
| 2953 |
break; |
| 2954 |
case CMD_PRINT_HELP: |
| 2955 |
s_log(LOG_NOTICE, "%-22s = custom header for protocol negotiations", |
| 2956 |
"protocolHeader"); |
| 2957 |
break; |
| 2958 |
} |
| 2959 |
|
| 2960 |
/* protocolHost */ |
| 2961 |
switch(cmd) { |
| 2962 |
case CMD_SET_DEFAULTS: |
| 2963 |
section->protocol_host=NULL; |
| 2964 |
break; |
| 2965 |
case CMD_SET_COPY: |
| 2966 |
section->protocol_host= |
| 2967 |
str_dup_detached(new_service_options.protocol_host); |
| 2968 |
break; |
| 2969 |
case CMD_FREE: |
| 2970 |
str_free(section->protocol_host); |
| 2971 |
break; |
| 2972 |
case CMD_SET_VALUE: |
| 2973 |
if(strcasecmp(opt, "protocolHost")) |
| 2974 |
break; |
| 2975 |
str_free(section->protocol_host); |
| 2976 |
section->protocol_host=str_dup_detached(arg); |
| 2977 |
return NULL; /* OK */ |
| 2978 |
case CMD_INITIALIZE: |
| 2979 |
break; |
| 2980 |
case CMD_PRINT_DEFAULTS: |
| 2981 |
break; |
| 2982 |
case CMD_PRINT_HELP: |
| 2983 |
s_log(LOG_NOTICE, "%-22s = host:port for protocol negotiations", |
| 2984 |
"protocolHost"); |
| 2985 |
break; |
| 2986 |
} |
| 2987 |
|
| 2988 |
/* protocolPassword */ |
| 2989 |
switch(cmd) { |
| 2990 |
case CMD_SET_DEFAULTS: |
| 2991 |
section->protocol_password=NULL; |
| 2992 |
break; |
| 2993 |
case CMD_SET_COPY: |
| 2994 |
section->protocol_password= |
| 2995 |
str_dup_detached(new_service_options.protocol_password); |
| 2996 |
break; |
| 2997 |
case CMD_FREE: |
| 2998 |
str_free(section->protocol_password); |
| 2999 |
break; |
| 3000 |
case CMD_SET_VALUE: |
| 3001 |
if(strcasecmp(opt, "protocolPassword")) |
| 3002 |
break; |
| 3003 |
str_free(section->protocol_password); |
| 3004 |
section->protocol_password=str_dup_detached(arg); |
| 3005 |
return NULL; /* OK */ |
| 3006 |
case CMD_INITIALIZE: |
| 3007 |
break; |
| 3008 |
case CMD_PRINT_DEFAULTS: |
| 3009 |
break; |
| 3010 |
case CMD_PRINT_HELP: |
| 3011 |
s_log(LOG_NOTICE, "%-22s = password for protocol negotiations", |
| 3012 |
"protocolPassword"); |
| 3013 |
break; |
| 3014 |
} |
| 3015 |
|
| 3016 |
/* protocolUsername */ |
| 3017 |
switch(cmd) { |
| 3018 |
case CMD_SET_DEFAULTS: |
| 3019 |
section->protocol_username=NULL; |
| 3020 |
break; |
| 3021 |
case CMD_SET_COPY: |
| 3022 |
section->protocol_username= |
| 3023 |
str_dup_detached(new_service_options.protocol_username); |
| 3024 |
break; |
| 3025 |
case CMD_FREE: |
| 3026 |
str_free(section->protocol_username); |
| 3027 |
break; |
| 3028 |
case CMD_SET_VALUE: |
| 3029 |
if(strcasecmp(opt, "protocolUsername")) |
| 3030 |
break; |
| 3031 |
str_free(section->protocol_username); |
| 3032 |
section->protocol_username=str_dup_detached(arg); |
| 3033 |
return NULL; /* OK */ |
| 3034 |
case CMD_INITIALIZE: |
| 3035 |
break; |
| 3036 |
case CMD_PRINT_DEFAULTS: |
| 3037 |
break; |
| 3038 |
case CMD_PRINT_HELP: |
| 3039 |
s_log(LOG_NOTICE, "%-22s = username for protocol negotiations", |
| 3040 |
"protocolUsername"); |
| 3041 |
break; |
| 3042 |
} |
| 3043 |
|
| 3044 |
#ifndef OPENSSL_NO_PSK |
| 3045 |
|
| 3046 |
/* PSKidentity */ |
| 3047 |
switch(cmd) { |
| 3048 |
case CMD_SET_DEFAULTS: |
| 3049 |
section->psk_identity=NULL; |
| 3050 |
section->psk_selected=NULL; |
| 3051 |
section->psk_sorted.val=NULL; |
| 3052 |
section->psk_sorted.num=0; |
| 3053 |
break; |
| 3054 |
case CMD_SET_COPY: |
| 3055 |
section->psk_identity= |
| 3056 |
str_dup_detached(new_service_options.psk_identity); |
| 3057 |
break; |
| 3058 |
case CMD_FREE: |
| 3059 |
str_free(section->psk_identity); |
| 3060 |
str_free(section->psk_sorted.val); |
| 3061 |
break; |
| 3062 |
case CMD_SET_VALUE: |
| 3063 |
if(strcasecmp(opt, "PSKidentity")) |
| 3064 |
break; |
| 3065 |
str_free(section->psk_identity); |
| 3066 |
section->psk_identity=str_dup_detached(arg); |
| 3067 |
return NULL; /* OK */ |
| 3068 |
case CMD_INITIALIZE: |
| 3069 |
if(!section->psk_keys) /* PSK not configured */ |
| 3070 |
break; |
| 3071 |
psk_sort(§ion->psk_sorted, section->psk_keys); |
| 3072 |
if(section->option.client) { |
| 3073 |
if(section->psk_identity) { |
| 3074 |
section->psk_selected= |
| 3075 |
psk_find(§ion->psk_sorted, section->psk_identity); |
| 3076 |
if(!section->psk_selected) |
| 3077 |
return "No key found for the specified PSK identity"; |
| 3078 |
} else { /* take the first specified identity as default */ |
| 3079 |
section->psk_selected=section->psk_keys; |
| 3080 |
} |
| 3081 |
} else { |
| 3082 |
if(section->psk_identity) |
| 3083 |
s_log(LOG_NOTICE, |
| 3084 |
"PSK identity is ignored in the server mode"); |
| 3085 |
} |
| 3086 |
break; |
| 3087 |
case CMD_PRINT_DEFAULTS: |
| 3088 |
break; |
| 3089 |
case CMD_PRINT_HELP: |
| 3090 |
s_log(LOG_NOTICE, "%-22s = identity for PSK authentication", |
| 3091 |
"PSKidentity"); |
| 3092 |
break; |
| 3093 |
} |
| 3094 |
|
| 3095 |
/* PSKsecrets */ |
| 3096 |
switch(cmd) { |
| 3097 |
case CMD_SET_DEFAULTS: |
| 3098 |
section->psk_keys=NULL; |
| 3099 |
break; |
| 3100 |
case CMD_SET_COPY: |
| 3101 |
section->psk_keys=psk_dup(new_service_options.psk_keys); |
| 3102 |
break; |
| 3103 |
case CMD_FREE: |
| 3104 |
psk_free(section->psk_keys); |
| 3105 |
break; |
| 3106 |
case CMD_SET_VALUE: |
| 3107 |
if(strcasecmp(opt, "PSKsecrets")) |
| 3108 |
break; |
| 3109 |
section->psk_keys=psk_read(arg); |
| 3110 |
if(!section->psk_keys) |
| 3111 |
return "Failed to read PSK secrets"; |
| 3112 |
return NULL; /* OK */ |
| 3113 |
case CMD_INITIALIZE: |
| 3114 |
break; |
| 3115 |
case CMD_PRINT_DEFAULTS: |
| 3116 |
break; |
| 3117 |
case CMD_PRINT_HELP: |
| 3118 |
s_log(LOG_NOTICE, "%-22s = secrets for PSK authentication", |
| 3119 |
"PSKsecrets"); |
| 3120 |
break; |
| 3121 |
} |
| 3122 |
|
| 3123 |
#endif /* !defined(OPENSSL_NO_PSK) */ |
| 3124 |
|
| 3125 |
/* pty */ |
| 3126 |
#ifndef USE_WIN32 |
| 3127 |
switch(cmd) { |
| 3128 |
case CMD_SET_DEFAULTS: |
| 3129 |
section->option.pty=0; |
| 3130 |
break; |
| 3131 |
case CMD_SET_COPY: |
| 3132 |
section->option.pty=new_service_options.option.pty; |
| 3133 |
break; |
| 3134 |
case CMD_FREE: |
| 3135 |
break; |
| 3136 |
case CMD_SET_VALUE: |
| 3137 |
if(strcasecmp(opt, "pty")) |
| 3138 |
break; |
| 3139 |
if(!strcasecmp(arg, "yes")) |
| 3140 |
section->option.pty=1; |
| 3141 |
else if(!strcasecmp(arg, "no")) |
| 3142 |
section->option.pty=0; |
| 3143 |
else |
| 3144 |
return "The argument needs to be either 'yes' or 'no'"; |
| 3145 |
return NULL; /* OK */ |
| 3146 |
case CMD_INITIALIZE: |
| 3147 |
break; |
| 3148 |
case CMD_PRINT_DEFAULTS: |
| 3149 |
break; |
| 3150 |
case CMD_PRINT_HELP: |
| 3151 |
s_log(LOG_NOTICE, "%-22s = yes|no allocate pseudo terminal for 'exec' option", |
| 3152 |
"pty"); |
| 3153 |
break; |
| 3154 |
} |
| 3155 |
#endif |
| 3156 |
|
| 3157 |
/* redirect */ |
| 3158 |
switch(cmd) { |
| 3159 |
case CMD_SET_DEFAULTS: |
| 3160 |
addrlist_clear(§ion->redirect_addr, 0); |
| 3161 |
break; |
| 3162 |
case CMD_SET_COPY: |
| 3163 |
addrlist_clear(§ion->redirect_addr, 0); |
| 3164 |
name_list_dup(§ion->redirect_addr.names, |
| 3165 |
new_service_options.redirect_addr.names); |
| 3166 |
section->option.default_redirect_addr=1; |
| 3167 |
break; |
| 3168 |
case CMD_FREE: |
| 3169 |
name_list_free(§ion->redirect_addr.names); |
| 3170 |
str_free(section->redirect_addr.addr); |
| 3171 |
break; |
| 3172 |
case CMD_SET_VALUE: |
| 3173 |
if(strcasecmp(opt, "redirect")) |
| 3174 |
break; |
| 3175 |
if(section->option.default_redirect_addr) { |
| 3176 |
name_list_free(§ion->redirect_addr.names); |
| 3177 |
str_free(section->redirect_addr.addr); |
| 3178 |
addrlist_clear(§ion->redirect_addr, 0); |
| 3179 |
section->option.default_redirect_addr=0; |
| 3180 |
} |
| 3181 |
name_list_append(§ion->redirect_addr.names, arg); |
| 3182 |
return NULL; /* OK */ |
| 3183 |
case CMD_INITIALIZE: |
| 3184 |
if(section->redirect_addr.names) { |
| 3185 |
if(section->option.client) |
| 3186 |
return "\"redirect\" is unsupported in client sections"; |
| 3187 |
if(section->option.connect_before_ssl) |
| 3188 |
return "\"redirect\" is incompatible with the specified protocol negotiation"; |
| 3189 |
if(!section->option.delayed_lookup && |
| 3190 |
!addrlist_resolve(§ion->redirect_addr)) { |
| 3191 |
s_log(LOG_INFO, |
| 3192 |
"Cannot resolve redirect target - delaying DNS lookup"); |
| 3193 |
section->connect_addr.num=0; |
| 3194 |
section->redirect_addr.num=0; |
| 3195 |
section->option.delayed_lookup=1; |
| 3196 |
} |
| 3197 |
if(!section->option.verify_chain && !section->option.verify_peer) |
| 3198 |
return "Either \"verifyChain\" or \"verifyPeer\" has to be enabled for \"redirect\" to work"; |
| 3199 |
} |
| 3200 |
break; |
| 3201 |
case CMD_PRINT_DEFAULTS: |
| 3202 |
break; |
| 3203 |
case CMD_PRINT_HELP: |
| 3204 |
s_log(LOG_NOTICE, |
| 3205 |
"%-22s = [host:]port to redirect on authentication failures", |
| 3206 |
"redirect"); |
| 3207 |
break; |
| 3208 |
} |
| 3209 |
|
| 3210 |
/* renegotiation */ |
| 3211 |
switch(cmd) { |
| 3212 |
case CMD_SET_DEFAULTS: |
| 3213 |
section->option.renegotiation=1; |
| 3214 |
break; |
| 3215 |
case CMD_SET_COPY: |
| 3216 |
section->option.renegotiation=new_service_options.option.renegotiation; |
| 3217 |
break; |
| 3218 |
case CMD_FREE: |
| 3219 |
break; |
| 3220 |
case CMD_SET_VALUE: |
| 3221 |
if(strcasecmp(opt, "renegotiation")) |
| 3222 |
break; |
| 3223 |
if(!strcasecmp(arg, "yes")) |
| 3224 |
section->option.renegotiation=1; |
| 3225 |
else if(!strcasecmp(arg, "no")) |
| 3226 |
section->option.renegotiation=0; |
| 3227 |
else |
| 3228 |
return "The argument needs to be either 'yes' or 'no'"; |
| 3229 |
return NULL; /* OK */ |
| 3230 |
case CMD_INITIALIZE: |
| 3231 |
break; |
| 3232 |
case CMD_PRINT_DEFAULTS: |
| 3233 |
break; |
| 3234 |
case CMD_PRINT_HELP: |
| 3235 |
s_log(LOG_NOTICE, "%-22s = yes|no support renegotiation", |
| 3236 |
"renegotiation"); |
| 3237 |
break; |
| 3238 |
} |
| 3239 |
|
| 3240 |
/* requireCert */ |
| 3241 |
switch(cmd) { |
| 3242 |
case CMD_SET_DEFAULTS: |
| 3243 |
section->option.require_cert=0; |
| 3244 |
break; |
| 3245 |
case CMD_SET_COPY: |
| 3246 |
section->option.require_cert=new_service_options.option.require_cert; |
| 3247 |
break; |
| 3248 |
case CMD_FREE: |
| 3249 |
break; |
| 3250 |
case CMD_SET_VALUE: |
| 3251 |
if(strcasecmp(opt, "requireCert")) |
| 3252 |
break; |
| 3253 |
if(!strcasecmp(arg, "yes")) { |
| 3254 |
section->option.request_cert=1; |
| 3255 |
section->option.require_cert=1; |
| 3256 |
} else if(!strcasecmp(arg, "no")) { |
| 3257 |
section->option.require_cert=0; |
| 3258 |
} else { |
| 3259 |
return "The argument needs to be either 'yes' or 'no'"; |
| 3260 |
} |
| 3261 |
return NULL; /* OK */ |
| 3262 |
case CMD_INITIALIZE: |
| 3263 |
break; |
| 3264 |
case CMD_PRINT_DEFAULTS: |
| 3265 |
break; |
| 3266 |
case CMD_PRINT_HELP: |
| 3267 |
s_log(LOG_NOTICE, "%-22s = yes|no require client certificate", |
| 3268 |
"requireCert"); |
| 3269 |
break; |
| 3270 |
} |
| 3271 |
|
| 3272 |
/* reset */ |
| 3273 |
switch(cmd) { |
| 3274 |
case CMD_SET_DEFAULTS: |
| 3275 |
section->option.reset=1; /* enabled by default */ |
| 3276 |
break; |
| 3277 |
case CMD_SET_COPY: |
| 3278 |
section->option.reset=new_service_options.option.reset; |
| 3279 |
break; |
| 3280 |
case CMD_FREE: |
| 3281 |
break; |
| 3282 |
case CMD_SET_VALUE: |
| 3283 |
if(strcasecmp(opt, "reset")) |
| 3284 |
break; |
| 3285 |
if(!strcasecmp(arg, "yes")) |
| 3286 |
section->option.reset=1; |
| 3287 |
else if(!strcasecmp(arg, "no")) |
| 3288 |
section->option.reset=0; |
| 3289 |
else |
| 3290 |
return "The argument needs to be either 'yes' or 'no'"; |
| 3291 |
return NULL; /* OK */ |
| 3292 |
case CMD_INITIALIZE: |
| 3293 |
break; |
| 3294 |
case CMD_PRINT_DEFAULTS: |
| 3295 |
break; |
| 3296 |
case CMD_PRINT_HELP: |
| 3297 |
s_log(LOG_NOTICE, "%-22s = yes|no send TCP RST on error", |
| 3298 |
"reset"); |
| 3299 |
break; |
| 3300 |
} |
| 3301 |
|
| 3302 |
/* retry */ |
| 3303 |
switch(cmd) { |
| 3304 |
case CMD_SET_DEFAULTS: |
| 3305 |
section->retry=-1; |
| 3306 |
break; |
| 3307 |
case CMD_SET_COPY: |
| 3308 |
section->retry=new_service_options.retry; |
| 3309 |
break; |
| 3310 |
case CMD_FREE: |
| 3311 |
break; |
| 3312 |
case CMD_SET_VALUE: |
| 3313 |
if(strcasecmp(opt, "retry")) |
| 3314 |
break; |
| 3315 |
if(!strcasecmp(arg, "yes")) { |
| 3316 |
section->retry=1000; /* 1 second */ |
| 3317 |
} else if(!strcasecmp(arg, "no")) { |
| 3318 |
section->retry=-1; /* disabled */ |
| 3319 |
} else { |
| 3320 |
char *tmp_str; |
| 3321 |
section->retry=(long)strtol(arg, &tmp_str, 10); |
| 3322 |
if(tmp_str==arg || *tmp_str || section->retry < 0) |
| 3323 |
return "Illegal retry delay"; |
| 3324 |
} |
| 3325 |
return NULL; /* OK */ |
| 3326 |
case CMD_INITIALIZE: |
| 3327 |
break; |
| 3328 |
case CMD_PRINT_DEFAULTS: |
| 3329 |
break; |
| 3330 |
case CMD_PRINT_HELP: |
| 3331 |
s_log(LOG_NOTICE, "%-22s = yes|no retry connect+exec section", |
| 3332 |
"retry"); |
| 3333 |
break; |
| 3334 |
} |
| 3335 |
|
| 3336 |
#if OPENSSL_VERSION_NUMBER>=0x10100000L |
| 3337 |
/* securityLevel */ |
| 3338 |
switch(cmd) { |
| 3339 |
case CMD_SET_DEFAULTS: |
| 3340 |
section->security_level=-1; |
| 3341 |
break; |
| 3342 |
case CMD_SET_COPY: |
| 3343 |
section->security_level=new_service_options.security_level; |
| 3344 |
break; |
| 3345 |
case CMD_FREE: |
| 3346 |
break; |
| 3347 |
case CMD_SET_VALUE: |
| 3348 |
if(strcasecmp(opt, "securityLevel")) |
| 3349 |
break; |
| 3350 |
{ |
| 3351 |
char *tmp_str; |
| 3352 |
int tmp_int =(int)strtol(arg, &tmp_str, 10); |
| 3353 |
if(tmp_str==arg || *tmp_str || tmp_int<0 || tmp_int>5) /* not a correct number */ |
| 3354 |
return "Illegal security level"; |
| 3355 |
section->security_level = tmp_int; |
| 3356 |
} |
| 3357 |
return NULL; /* OK */ |
| 3358 |
case CMD_INITIALIZE: |
| 3359 |
break; |
| 3360 |
case CMD_PRINT_DEFAULTS: |
| 3361 |
s_log(LOG_NOTICE, "%-22s = %d", "securityLevel", DEFAULT_SECURITY_LEVEL); |
| 3362 |
break; |
| 3363 |
case CMD_PRINT_HELP: |
| 3364 |
s_log(LOG_NOTICE, "%-22s = set the security level", "securityLevel"); |
| 3365 |
break; |
| 3366 |
} |
| 3367 |
#endif /* OpenSSL 1.1.0 or later */ |
| 3368 |
|
| 3369 |
#ifndef USE_WIN32 |
| 3370 |
/* service */ |
| 3371 |
switch(cmd) { |
| 3372 |
case CMD_SET_DEFAULTS: |
| 3373 |
section->servname=str_dup_detached("stunnel"); |
| 3374 |
break; |
| 3375 |
case CMD_SET_COPY: |
| 3376 |
/* servname is *not* copied from the global section */ |
| 3377 |
break; |
| 3378 |
case CMD_FREE: |
| 3379 |
/* deallocation is performed at the end CMD_FREE */ |
| 3380 |
break; |
| 3381 |
case CMD_SET_VALUE: |
| 3382 |
if(strcasecmp(opt, "service")) |
| 3383 |
break; |
| 3384 |
str_free(section->servname); |
| 3385 |
section->servname=str_dup_detached(arg); |
| 3386 |
return NULL; /* OK */ |
| 3387 |
case CMD_INITIALIZE: |
| 3388 |
break; |
| 3389 |
case CMD_PRINT_DEFAULTS: |
| 3390 |
break; |
| 3391 |
case CMD_PRINT_HELP: |
| 3392 |
s_log(LOG_NOTICE, "%-22s = service name", "service"); |
| 3393 |
break; |
| 3394 |
} |
| 3395 |
#endif |
| 3396 |
|
| 3397 |
#ifndef USE_WIN32 |
| 3398 |
/* setgid */ |
| 3399 |
switch(cmd) { |
| 3400 |
case CMD_SET_DEFAULTS: |
| 3401 |
section->gid=0; |
| 3402 |
break; |
| 3403 |
case CMD_SET_COPY: |
| 3404 |
section->gid=new_service_options.gid; |
| 3405 |
break; |
| 3406 |
case CMD_FREE: |
| 3407 |
break; |
| 3408 |
case CMD_SET_VALUE: |
| 3409 |
if(strcasecmp(opt, "setgid")) |
| 3410 |
break; |
| 3411 |
gr=getgrnam(arg); |
| 3412 |
if(gr) { |
| 3413 |
section->gid=gr->gr_gid; |
| 3414 |
return NULL; /* OK */ |
| 3415 |
} |
| 3416 |
{ |
| 3417 |
char *tmp_str; |
| 3418 |
section->gid=(gid_t)strtol(arg, &tmp_str, 10); |
| 3419 |
if(tmp_str==arg || *tmp_str) /* not a number */ |
| 3420 |
return "Illegal GID"; |
| 3421 |
} |
| 3422 |
return NULL; /* OK */ |
| 3423 |
case CMD_INITIALIZE: |
| 3424 |
break; |
| 3425 |
case CMD_PRINT_DEFAULTS: |
| 3426 |
break; |
| 3427 |
case CMD_PRINT_HELP: |
| 3428 |
s_log(LOG_NOTICE, "%-22s = groupname for setgid()", "setgid"); |
| 3429 |
break; |
| 3430 |
} |
| 3431 |
#endif |
| 3432 |
|
| 3433 |
#ifndef USE_WIN32 |
| 3434 |
/* setuid */ |
| 3435 |
switch(cmd) { |
| 3436 |
case CMD_SET_DEFAULTS: |
| 3437 |
section->uid=0; |
| 3438 |
break; |
| 3439 |
case CMD_SET_COPY: |
| 3440 |
section->uid=new_service_options.uid; |
| 3441 |
break; |
| 3442 |
case CMD_FREE: |
| 3443 |
break; |
| 3444 |
case CMD_SET_VALUE: |
| 3445 |
if(strcasecmp(opt, "setuid")) |
| 3446 |
break; |
| 3447 |
pw=getpwnam(arg); |
| 3448 |
if(pw) { |
| 3449 |
section->uid=pw->pw_uid; |
| 3450 |
return NULL; /* OK */ |
| 3451 |
} |
| 3452 |
{ |
| 3453 |
char *tmp_str; |
| 3454 |
section->uid=(uid_t)strtol(arg, &tmp_str, 10); |
| 3455 |
if(tmp_str==arg || *tmp_str) /* not a number */ |
| 3456 |
return "Illegal UID"; |
| 3457 |
} |
| 3458 |
return NULL; /* OK */ |
| 3459 |
case CMD_INITIALIZE: |
| 3460 |
break; |
| 3461 |
case CMD_PRINT_DEFAULTS: |
| 3462 |
break; |
| 3463 |
case CMD_PRINT_HELP: |
| 3464 |
s_log(LOG_NOTICE, "%-22s = username for setuid()", "setuid"); |
| 3465 |
break; |
| 3466 |
} |
| 3467 |
#endif |
| 3468 |
|
| 3469 |
/* sessionCacheSize */ |
| 3470 |
switch(cmd) { |
| 3471 |
case CMD_SET_DEFAULTS: |
| 3472 |
section->session_size=1000L; |
| 3473 |
break; |
| 3474 |
case CMD_SET_COPY: |
| 3475 |
section->session_size=new_service_options.session_size; |
| 3476 |
break; |
| 3477 |
case CMD_FREE: |
| 3478 |
break; |
| 3479 |
case CMD_SET_VALUE: |
| 3480 |
if(strcasecmp(opt, "sessionCacheSize")) |
| 3481 |
break; |
| 3482 |
{ |
| 3483 |
char *tmp_str; |
| 3484 |
section->session_size=strtol(arg, &tmp_str, 10); |
| 3485 |
if(tmp_str==arg || *tmp_str) /* not a number */ |
| 3486 |
return "Illegal session cache size"; |
| 3487 |
} |
| 3488 |
return NULL; /* OK */ |
| 3489 |
case CMD_INITIALIZE: |
| 3490 |
break; |
| 3491 |
case CMD_PRINT_DEFAULTS: |
| 3492 |
s_log(LOG_NOTICE, "%-22s = %ld", "sessionCacheSize", 1000L); |
| 3493 |
break; |
| 3494 |
case CMD_PRINT_HELP: |
| 3495 |
s_log(LOG_NOTICE, "%-22s = session cache size", "sessionCacheSize"); |
| 3496 |
break; |
| 3497 |
} |
| 3498 |
|
| 3499 |
/* sessionCacheTimeout */ |
| 3500 |
switch(cmd) { |
| 3501 |
case CMD_SET_DEFAULTS: |
| 3502 |
section->session_timeout=300L; |
| 3503 |
break; |
| 3504 |
case CMD_SET_COPY: |
| 3505 |
section->session_timeout=new_service_options.session_timeout; |
| 3506 |
break; |
| 3507 |
case CMD_FREE: |
| 3508 |
break; |
| 3509 |
case CMD_SET_VALUE: |
| 3510 |
if(strcasecmp(opt, "sessionCacheTimeout") && strcasecmp(opt, "session")) |
| 3511 |
break; |
| 3512 |
{ |
| 3513 |
char *tmp_str; |
| 3514 |
section->session_timeout=strtol(arg, &tmp_str, 10); |
| 3515 |
if(tmp_str==arg || *tmp_str) /* not a number */ |
| 3516 |
return "Illegal session cache timeout"; |
| 3517 |
} |
| 3518 |
return NULL; /* OK */ |
| 3519 |
case CMD_INITIALIZE: |
| 3520 |
break; |
| 3521 |
case CMD_PRINT_DEFAULTS: |
| 3522 |
s_log(LOG_NOTICE, "%-22s = %ld seconds", "sessionCacheTimeout", 300L); |
| 3523 |
break; |
| 3524 |
case CMD_PRINT_HELP: |
| 3525 |
s_log(LOG_NOTICE, "%-22s = session cache timeout (in seconds)", |
| 3526 |
"sessionCacheTimeout"); |
| 3527 |
break; |
| 3528 |
} |
| 3529 |
|
| 3530 |
/* sessionResume */ |
| 3531 |
switch(cmd) { |
| 3532 |
case CMD_SET_DEFAULTS: |
| 3533 |
section->option.session_resume=1; /* enabled by default */ |
| 3534 |
break; |
| 3535 |
case CMD_SET_COPY: |
| 3536 |
section->option.session_resume=new_service_options.option.session_resume; |
| 3537 |
break; |
| 3538 |
case CMD_FREE: |
| 3539 |
break; |
| 3540 |
case CMD_SET_VALUE: |
| 3541 |
if(strcasecmp(opt, "sessionResume")) |
| 3542 |
break; |
| 3543 |
if(!strcasecmp(arg, "yes")) |
| 3544 |
section->option.session_resume=1; |
| 3545 |
else if(!strcasecmp(arg, "no")) |
| 3546 |
section->option.session_resume=0; |
| 3547 |
else |
| 3548 |
return "The argument needs to be either 'yes' or 'no'"; |
| 3549 |
return NULL; /* OK */ |
| 3550 |
case CMD_INITIALIZE: |
| 3551 |
break; |
| 3552 |
case CMD_PRINT_DEFAULTS: |
| 3553 |
break; |
| 3554 |
case CMD_PRINT_HELP: |
| 3555 |
s_log(LOG_NOTICE, "%-22s = yes|no enable session resumption", |
| 3556 |
"sessionResume"); |
| 3557 |
break; |
| 3558 |
} |
| 3559 |
|
| 3560 |
/* sessiond */ |
| 3561 |
switch(cmd) { |
| 3562 |
case CMD_SET_DEFAULTS: |
| 3563 |
section->option.sessiond=0; |
| 3564 |
memset(§ion->sessiond_addr, 0, sizeof(SOCKADDR_UNION)); |
| 3565 |
section->sessiond_addr.in.sin_family=AF_INET; |
| 3566 |
break; |
| 3567 |
case CMD_SET_COPY: |
| 3568 |
section->option.sessiond=new_service_options.option.sessiond; |
| 3569 |
memcpy(§ion->sessiond_addr, &new_service_options.sessiond_addr, |
| 3570 |
sizeof(SOCKADDR_UNION)); |
| 3571 |
break; |
| 3572 |
case CMD_FREE: |
| 3573 |
break; |
| 3574 |
case CMD_SET_VALUE: |
| 3575 |
if(strcasecmp(opt, "sessiond")) |
| 3576 |
break; |
| 3577 |
section->option.sessiond=1; |
| 3578 |
#ifdef SSL_OP_NO_TICKET |
| 3579 |
/* disable RFC4507 support introduced in OpenSSL 0.9.8f */ |
| 3580 |
/* this prevents session callbacks from being executed */ |
| 3581 |
section->ssl_options_set|=SSL_OP_NO_TICKET; |
| 3582 |
#endif |
| 3583 |
if(!name2addr(§ion->sessiond_addr, arg, 0)) |
| 3584 |
return "Failed to resolve sessiond server address"; |
| 3585 |
return NULL; /* OK */ |
| 3586 |
case CMD_INITIALIZE: |
| 3587 |
break; |
| 3588 |
case CMD_PRINT_DEFAULTS: |
| 3589 |
break; |
| 3590 |
case CMD_PRINT_HELP: |
| 3591 |
s_log(LOG_NOTICE, "%-22s = [host:]port use sessiond at host:port", |
| 3592 |
"sessiond"); |
| 3593 |
break; |
| 3594 |
} |
| 3595 |
|
| 3596 |
#ifndef OPENSSL_NO_TLSEXT |
| 3597 |
/* sni */ |
| 3598 |
switch(cmd) { |
| 3599 |
case CMD_SET_DEFAULTS: |
| 3600 |
section->servername_list_head=NULL; |
| 3601 |
section->servername_list_tail=NULL; |
| 3602 |
break; |
| 3603 |
case CMD_SET_COPY: |
| 3604 |
section->sni= |
| 3605 |
str_dup_detached(new_service_options.sni); |
| 3606 |
break; |
| 3607 |
case CMD_FREE: |
| 3608 |
str_free(section->sni); |
| 3609 |
sni_free(section); |
| 3610 |
break; |
| 3611 |
case CMD_SET_VALUE: |
| 3612 |
if(strcasecmp(opt, "sni")) |
| 3613 |
break; |
| 3614 |
str_free(section->sni); |
| 3615 |
section->sni=str_dup_detached(arg); |
| 3616 |
return NULL; /* OK */ |
| 3617 |
case CMD_INITIALIZE: |
| 3618 |
{ |
| 3619 |
const char *tmp_str=sni_init(section); |
| 3620 |
if(tmp_str) |
| 3621 |
return tmp_str; |
| 3622 |
} |
| 3623 |
if(!section->option.client && section->sni) |
| 3624 |
++endpoints; |
| 3625 |
break; |
| 3626 |
case CMD_PRINT_DEFAULTS: |
| 3627 |
break; |
| 3628 |
case CMD_PRINT_HELP: |
| 3629 |
s_log(LOG_NOTICE, "%-22s = primary_service:host_name for an SNI virtual service", |
| 3630 |
"sni"); |
| 3631 |
break; |
| 3632 |
} |
| 3633 |
#endif /* !defined(OPENSSL_NO_TLSEXT) */ |
| 3634 |
|
| 3635 |
/* socket */ |
| 3636 |
switch(cmd) { |
| 3637 |
case CMD_SET_DEFAULTS: |
| 3638 |
section->sock_opts=socket_options_init(); |
| 3639 |
break; |
| 3640 |
case CMD_SET_COPY: |
| 3641 |
section->sock_opts=socket_options_dup(new_service_options.sock_opts); |
| 3642 |
break; |
| 3643 |
case CMD_FREE: |
| 3644 |
socket_options_free(section->sock_opts); |
| 3645 |
break; |
| 3646 |
case CMD_SET_VALUE: |
| 3647 |
if(strcasecmp(opt, "socket")) |
| 3648 |
break; |
| 3649 |
if(socket_option_parse(section->sock_opts, arg)) |
| 3650 |
return "Illegal socket option"; |
| 3651 |
return NULL; /* OK */ |
| 3652 |
case CMD_INITIALIZE: |
| 3653 |
break; |
| 3654 |
case CMD_PRINT_DEFAULTS: |
| 3655 |
break; |
| 3656 |
case CMD_PRINT_HELP: |
| 3657 |
s_log(LOG_NOTICE, "%-22s = a|l|r:option=value[:value]", "socket"); |
| 3658 |
s_log(LOG_NOTICE, "%25sset an option on accept/local/remote socket", ""); |
| 3659 |
break; |
| 3660 |
} |
| 3661 |
|
| 3662 |
#if OPENSSL_VERSION_NUMBER>=0x10100000L |
| 3663 |
|
| 3664 |
/* sslVersion */ |
| 3665 |
switch(cmd) { |
| 3666 |
case CMD_SET_DEFAULTS: |
| 3667 |
/* handled in sslVersionMax and sslVersionMin */ |
| 3668 |
break; |
| 3669 |
case CMD_SET_COPY: |
| 3670 |
/* handled in sslVersionMax and sslVersionMin */ |
| 3671 |
break; |
| 3672 |
case CMD_FREE: |
| 3673 |
break; |
| 3674 |
case CMD_SET_VALUE: |
| 3675 |
if(strcasecmp(opt, "sslVersion")) |
| 3676 |
break; |
| 3677 |
section->max_proto_version= |
| 3678 |
section->min_proto_version=str_to_proto_version(arg); |
| 3679 |
if(section->max_proto_version==-1) |
| 3680 |
return "Invalid protocol version"; |
| 3681 |
return NULL; /* OK */ |
| 3682 |
case CMD_INITIALIZE: |
| 3683 |
if(section->max_proto_version && section->min_proto_version && |
| 3684 |
section->max_proto_version<section->min_proto_version) |
| 3685 |
return "Invalid protocol version range"; |
| 3686 |
break; |
| 3687 |
case CMD_PRINT_DEFAULTS: |
| 3688 |
break; |
| 3689 |
case CMD_PRINT_HELP: |
| 3690 |
s_log(LOG_NOTICE, "%-22s = all" |
| 3691 |
"|SSLv3|TLSv1|TLSv1.1|TLSv1.2" |
| 3692 |
#ifdef TLS1_3_VERSION |
| 3693 |
"|TLSv1.3" |
| 3694 |
#endif |
| 3695 |
" TLS version", "sslVersion"); |
| 3696 |
break; |
| 3697 |
} |
| 3698 |
|
| 3699 |
/* sslVersionMax */ |
| 3700 |
switch(cmd) { |
| 3701 |
case CMD_SET_DEFAULTS: |
| 3702 |
section->max_proto_version=0; /* highest supported */ |
| 3703 |
break; |
| 3704 |
case CMD_SET_COPY: |
| 3705 |
section->max_proto_version=new_service_options.max_proto_version; |
| 3706 |
break; |
| 3707 |
case CMD_FREE: |
| 3708 |
break; |
| 3709 |
case CMD_SET_VALUE: |
| 3710 |
if(strcasecmp(opt, "sslVersionMax")) |
| 3711 |
break; |
| 3712 |
section->max_proto_version=str_to_proto_version(arg); |
| 3713 |
if(section->max_proto_version==-1) |
| 3714 |
return "Invalid protocol version"; |
| 3715 |
return NULL; /* OK */ |
| 3716 |
case CMD_INITIALIZE: |
| 3717 |
break; |
| 3718 |
case CMD_PRINT_DEFAULTS: |
| 3719 |
break; |
| 3720 |
case CMD_PRINT_HELP: |
| 3721 |
s_log(LOG_NOTICE, "%-22s = all" |
| 3722 |
"|SSLv3|TLSv1|TLSv1.1|TLSv1.2" |
| 3723 |
#ifdef TLS1_3_VERSION |
| 3724 |
"|TLSv1.3" |
| 3725 |
#endif |
| 3726 |
" TLS version", "sslVersionMax"); |
| 3727 |
break; |
| 3728 |
} |
| 3729 |
|
| 3730 |
/* sslVersionMin */ |
| 3731 |
switch(cmd) { |
| 3732 |
case CMD_SET_DEFAULTS: |
| 3733 |
section->min_proto_version=0; /* lowest supported */ |
| 3734 |
break; |
| 3735 |
case CMD_SET_COPY: |
| 3736 |
section->min_proto_version=new_service_options.min_proto_version; |
| 3737 |
break; |
| 3738 |
case CMD_FREE: |
| 3739 |
break; |
| 3740 |
case CMD_SET_VALUE: |
| 3741 |
if(strcasecmp(opt, "sslVersionMin")) |
| 3742 |
break; |
| 3743 |
section->min_proto_version=str_to_proto_version(arg); |
| 3744 |
if(section->min_proto_version==-1) |
| 3745 |
return "Invalid protocol version"; |
| 3746 |
return NULL; /* OK */ |
| 3747 |
case CMD_INITIALIZE: |
| 3748 |
break; |
| 3749 |
case CMD_PRINT_DEFAULTS: |
| 3750 |
break; |
| 3751 |
case CMD_PRINT_HELP: |
| 3752 |
s_log(LOG_NOTICE, "%-22s = all" |
| 3753 |
"|SSLv3|TLSv1|TLSv1.1|TLSv1.2" |
| 3754 |
#ifdef TLS1_3_VERSION |
| 3755 |
"|TLSv1.3" |
| 3756 |
#endif |
| 3757 |
" TLS version", "sslVersionMin"); |
| 3758 |
break; |
| 3759 |
} |
| 3760 |
|
| 3761 |
#else /* OPENSSL_VERSION_NUMBER<0x10100000L */ |
| 3762 |
|
| 3763 |
/* sslVersion */ |
| 3764 |
switch(cmd) { |
| 3765 |
case CMD_SET_DEFAULTS: |
| 3766 |
tls_methods_set(section, NULL); |
| 3767 |
break; |
| 3768 |
case CMD_SET_COPY: |
| 3769 |
section->client_method=new_service_options.client_method; |
| 3770 |
section->server_method=new_service_options.server_method; |
| 3771 |
break; |
| 3772 |
case CMD_FREE: |
| 3773 |
break; |
| 3774 |
case CMD_SET_VALUE: |
| 3775 |
if(strcasecmp(opt, "sslVersion")) |
| 3776 |
break; |
| 3777 |
return tls_methods_set(section, arg); |
| 3778 |
case CMD_INITIALIZE: |
| 3779 |
{ |
| 3780 |
char *tmp_str=tls_methods_check(section); |
| 3781 |
if(tmp_str) |
| 3782 |
return tmp_str; |
| 3783 |
} |
| 3784 |
break; |
| 3785 |
case CMD_PRINT_DEFAULTS: |
| 3786 |
break; |
| 3787 |
case CMD_PRINT_HELP: |
| 3788 |
s_log(LOG_NOTICE, "%-22s = all" |
| 3789 |
"|SSLv2|SSLv3|TLSv1" |
| 3790 |
#if OPENSSL_VERSION_NUMBER>=0x10001000L |
| 3791 |
"|TLSv1.1|TLSv1.2" |
| 3792 |
#endif /* OPENSSL_VERSION_NUMBER>=0x10001000L */ |
| 3793 |
" TLS method", "sslVersion"); |
| 3794 |
break; |
| 3795 |
} |
| 3796 |
|
| 3797 |
#endif /* OPENSSL_VERSION_NUMBER<0x10100000L */ |
| 3798 |
|
| 3799 |
#ifndef USE_FORK |
| 3800 |
/* stack */ |
| 3801 |
switch(cmd) { |
| 3802 |
case CMD_SET_DEFAULTS: |
| 3803 |
section->stack_size=DEFAULT_STACK_SIZE; |
| 3804 |
break; |
| 3805 |
case CMD_SET_COPY: |
| 3806 |
section->stack_size=new_service_options.stack_size; |
| 3807 |
break; |
| 3808 |
case CMD_FREE: |
| 3809 |
break; |
| 3810 |
case CMD_SET_VALUE: |
| 3811 |
if(strcasecmp(opt, "stack")) |
| 3812 |
break; |
| 3813 |
{ |
| 3814 |
char *tmp_str; |
| 3815 |
section->stack_size=(size_t)strtol(arg, &tmp_str, 10); |
| 3816 |
if(tmp_str==arg || *tmp_str) /* not a number */ |
| 3817 |
return "Illegal thread stack size"; |
| 3818 |
} |
| 3819 |
return NULL; /* OK */ |
| 3820 |
case CMD_INITIALIZE: |
| 3821 |
break; |
| 3822 |
case CMD_PRINT_DEFAULTS: |
| 3823 |
s_log(LOG_NOTICE, "%-22s = %d bytes", "stack", DEFAULT_STACK_SIZE); |
| 3824 |
break; |
| 3825 |
case CMD_PRINT_HELP: |
| 3826 |
s_log(LOG_NOTICE, "%-22s = thread stack size (in bytes)", "stack"); |
| 3827 |
break; |
| 3828 |
} |
| 3829 |
#endif |
| 3830 |
|
| 3831 |
#if OPENSSL_VERSION_NUMBER>=0x10000000L |
| 3832 |
|
| 3833 |
/* ticketKeySecret */ |
| 3834 |
switch(cmd) { |
| 3835 |
case CMD_SET_DEFAULTS: |
| 3836 |
section->ticket_key=NULL; |
| 3837 |
break; |
| 3838 |
case CMD_SET_COPY: |
| 3839 |
section->ticket_key=key_dup(new_service_options.ticket_key); |
| 3840 |
break; |
| 3841 |
case CMD_FREE: |
| 3842 |
key_free(section->ticket_key); |
| 3843 |
break; |
| 3844 |
case CMD_SET_VALUE: |
| 3845 |
if(strcasecmp(opt, "ticketKeySecret")) |
| 3846 |
break; |
| 3847 |
section->ticket_key=key_read(arg, "ticketKeySecret"); |
| 3848 |
if(!section->ticket_key) |
| 3849 |
return "Failed to read ticketKeySecret"; |
| 3850 |
return NULL; /* OK */ |
| 3851 |
case CMD_INITIALIZE: |
| 3852 |
if(!section->ticket_key) /* ticketKeySecret not configured */ |
| 3853 |
break; |
| 3854 |
if(section->option.client){ |
| 3855 |
s_log(LOG_NOTICE, |
| 3856 |
"ticketKeySecret is ignored in the client mode"); |
| 3857 |
break; |
| 3858 |
} |
| 3859 |
if(section->ticket_key && !section->ticket_mac) |
| 3860 |
return "\"ticketKeySecret\" and \"ticketMacSecret\" must be set together"; |
| 3861 |
break; |
| 3862 |
case CMD_PRINT_DEFAULTS: |
| 3863 |
break; |
| 3864 |
case CMD_PRINT_HELP: |
| 3865 |
s_log(LOG_NOTICE, "%-22s = secret key for encryption/decryption TLSv1.3 tickets", |
| 3866 |
"ticketKeySecret"); |
| 3867 |
break; |
| 3868 |
} |
| 3869 |
|
| 3870 |
/* ticketMacSecret */ |
| 3871 |
switch(cmd) { |
| 3872 |
case CMD_SET_DEFAULTS: |
| 3873 |
section->ticket_mac=NULL; |
| 3874 |
break; |
| 3875 |
case CMD_SET_COPY: |
| 3876 |
section->ticket_mac=key_dup(new_service_options.ticket_mac); |
| 3877 |
break; |
| 3878 |
case CMD_FREE: |
| 3879 |
key_free(section->ticket_mac); |
| 3880 |
break; |
| 3881 |
case CMD_SET_VALUE: |
| 3882 |
if(strcasecmp(opt, "ticketMacSecret")) |
| 3883 |
break; |
| 3884 |
section->ticket_mac=key_read(arg, "ticketMacSecret"); |
| 3885 |
if(!section->ticket_mac) |
| 3886 |
return "Failed to read ticketMacSecret"; |
| 3887 |
return NULL; /* OK */ |
| 3888 |
case CMD_INITIALIZE: |
| 3889 |
if(!section->ticket_mac) /* ticketMacSecret not configured */ |
| 3890 |
break; |
| 3891 |
if(section->option.client){ |
| 3892 |
s_log(LOG_NOTICE, |
| 3893 |
"ticketMacSecret is ignored in the client mode"); |
| 3894 |
break; |
| 3895 |
} |
| 3896 |
if(section->ticket_mac && !section->ticket_key) |
| 3897 |
return "\"ticketKeySecret\" and \"ticketMacSecret\" must be set together"; |
| 3898 |
break; |
| 3899 |
case CMD_PRINT_DEFAULTS: |
| 3900 |
break; |
| 3901 |
case CMD_PRINT_HELP: |
| 3902 |
s_log(LOG_NOTICE, "%-22s = key for HMAC operations on TLSv1.3 tickets", |
| 3903 |
"ticketMacSecret"); |
| 3904 |
break; |
| 3905 |
} |
| 3906 |
|
| 3907 |
#endif /* OpenSSL 1.0.0 or later */ |
| 3908 |
|
| 3909 |
/* TIMEOUTbusy */ |
| 3910 |
switch(cmd) { |
| 3911 |
case CMD_SET_DEFAULTS: |
| 3912 |
section->timeout_busy=300; /* 5 minutes */ |
| 3913 |
break; |
| 3914 |
case CMD_SET_COPY: |
| 3915 |
section->timeout_busy=new_service_options.timeout_busy; |
| 3916 |
break; |
| 3917 |
case CMD_FREE: |
| 3918 |
break; |
| 3919 |
case CMD_SET_VALUE: |
| 3920 |
if(strcasecmp(opt, "TIMEOUTbusy")) |
| 3921 |
break; |
| 3922 |
{ |
| 3923 |
char *tmp_str; |
| 3924 |
section->timeout_busy=(int)strtol(arg, &tmp_str, 10); |
| 3925 |
if(tmp_str==arg || *tmp_str) /* not a number */ |
| 3926 |
return "Illegal busy timeout"; |
| 3927 |
} |
| 3928 |
return NULL; /* OK */ |
| 3929 |
case CMD_INITIALIZE: |
| 3930 |
break; |
| 3931 |
case CMD_PRINT_DEFAULTS: |
| 3932 |
s_log(LOG_NOTICE, "%-22s = %d seconds", "TIMEOUTbusy", 300); |
| 3933 |
break; |
| 3934 |
case CMD_PRINT_HELP: |
| 3935 |
s_log(LOG_NOTICE, "%-22s = seconds to wait for expected data", "TIMEOUTbusy"); |
| 3936 |
break; |
| 3937 |
} |
| 3938 |
|
| 3939 |
/* TIMEOUTclose */ |
| 3940 |
switch(cmd) { |
| 3941 |
case CMD_SET_DEFAULTS: |
| 3942 |
section->timeout_close=60; /* 1 minute */ |
| 3943 |
break; |
| 3944 |
case CMD_SET_COPY: |
| 3945 |
section->timeout_close=new_service_options.timeout_close; |
| 3946 |
break; |
| 3947 |
case CMD_FREE: |
| 3948 |
break; |
| 3949 |
case CMD_SET_VALUE: |
| 3950 |
if(strcasecmp(opt, "TIMEOUTclose")) |
| 3951 |
break; |
| 3952 |
{ |
| 3953 |
char *tmp_str; |
| 3954 |
section->timeout_close=(int)strtol(arg, &tmp_str, 10); |
| 3955 |
if(tmp_str==arg || *tmp_str) /* not a number */ |
| 3956 |
return "Illegal close timeout"; |
| 3957 |
} |
| 3958 |
return NULL; /* OK */ |
| 3959 |
case CMD_INITIALIZE: |
| 3960 |
break; |
| 3961 |
case CMD_PRINT_DEFAULTS: |
| 3962 |
s_log(LOG_NOTICE, "%-22s = %d seconds", "TIMEOUTclose", 60); |
| 3963 |
break; |
| 3964 |
case CMD_PRINT_HELP: |
| 3965 |
s_log(LOG_NOTICE, "%-22s = seconds to wait for close_notify", |
| 3966 |
"TIMEOUTclose"); |
| 3967 |
break; |
| 3968 |
} |
| 3969 |
|
| 3970 |
/* TIMEOUTconnect */ |
| 3971 |
switch(cmd) { |
| 3972 |
case CMD_SET_DEFAULTS: |
| 3973 |
section->timeout_connect=10; /* 10 seconds */ |
| 3974 |
break; |
| 3975 |
case CMD_SET_COPY: |
| 3976 |
section->timeout_connect=new_service_options.timeout_connect; |
| 3977 |
break; |
| 3978 |
case CMD_FREE: |
| 3979 |
break; |
| 3980 |
case CMD_SET_VALUE: |
| 3981 |
if(strcasecmp(opt, "TIMEOUTconnect")) |
| 3982 |
break; |
| 3983 |
{ |
| 3984 |
char *tmp_str; |
| 3985 |
section->timeout_connect=(int)strtol(arg, &tmp_str, 10); |
| 3986 |
if(tmp_str==arg || *tmp_str) /* not a number */ |
| 3987 |
return "Illegal connect timeout"; |
| 3988 |
} |
| 3989 |
return NULL; /* OK */ |
| 3990 |
case CMD_INITIALIZE: |
| 3991 |
break; |
| 3992 |
case CMD_PRINT_DEFAULTS: |
| 3993 |
s_log(LOG_NOTICE, "%-22s = %d seconds", "TIMEOUTconnect", 10); |
| 3994 |
break; |
| 3995 |
case CMD_PRINT_HELP: |
| 3996 |
s_log(LOG_NOTICE, "%-22s = seconds to connect remote host", "TIMEOUTconnect"); |
| 3997 |
break; |
| 3998 |
} |
| 3999 |
|
| 4000 |
/* TIMEOUTidle */ |
| 4001 |
switch(cmd) { |
| 4002 |
case CMD_SET_DEFAULTS: |
| 4003 |
section->timeout_idle=43200; /* 12 hours */ |
| 4004 |
break; |
| 4005 |
case CMD_SET_COPY: |
| 4006 |
section->timeout_idle=new_service_options.timeout_idle; |
| 4007 |
break; |
| 4008 |
case CMD_FREE: |
| 4009 |
break; |
| 4010 |
case CMD_SET_VALUE: |
| 4011 |
if(strcasecmp(opt, "TIMEOUTidle")) |
| 4012 |
break; |
| 4013 |
{ |
| 4014 |
char *tmp_str; |
| 4015 |
section->timeout_idle=(int)strtol(arg, &tmp_str, 10); |
| 4016 |
if(tmp_str==arg || *tmp_str) /* not a number */ |
| 4017 |
return "Illegal idle timeout"; |
| 4018 |
return NULL; /* OK */ |
| 4019 |
} |
| 4020 |
case CMD_INITIALIZE: |
| 4021 |
break; |
| 4022 |
case CMD_PRINT_DEFAULTS: |
| 4023 |
s_log(LOG_NOTICE, "%-22s = %d seconds", "TIMEOUTidle", 43200); |
| 4024 |
break; |
| 4025 |
case CMD_PRINT_HELP: |
| 4026 |
s_log(LOG_NOTICE, "%-22s = seconds to keep an idle connection", "TIMEOUTidle"); |
| 4027 |
break; |
| 4028 |
} |
| 4029 |
|
| 4030 |
/* TIMEOUTocsp */ |
| 4031 |
#ifndef OPENSSL_NO_OCSP |
| 4032 |
switch(cmd) { |
| 4033 |
case CMD_SET_DEFAULTS: |
| 4034 |
section->timeout_ocsp=5; /* 5 seconds */ |
| 4035 |
break; |
| 4036 |
case CMD_SET_COPY: |
| 4037 |
section->timeout_ocsp=new_service_options.timeout_ocsp; |
| 4038 |
break; |
| 4039 |
case CMD_FREE: |
| 4040 |
break; |
| 4041 |
case CMD_SET_VALUE: |
| 4042 |
if(strcasecmp(opt, "TIMEOUTocsp")) |
| 4043 |
break; |
| 4044 |
{ |
| 4045 |
char *tmp_str; |
| 4046 |
section->timeout_ocsp=(int)strtol(arg, &tmp_str, 10); |
| 4047 |
if(tmp_str==arg || *tmp_str) /* not a number */ |
| 4048 |
return "Illegal OCSP connect timeout"; |
| 4049 |
} |
| 4050 |
return NULL; /* OK */ |
| 4051 |
case CMD_INITIALIZE: |
| 4052 |
break; |
| 4053 |
case CMD_PRINT_DEFAULTS: |
| 4054 |
s_log(LOG_NOTICE, "%-22s = %d seconds", "TIMEOUTocsp", 5); |
| 4055 |
break; |
| 4056 |
case CMD_PRINT_HELP: |
| 4057 |
s_log(LOG_NOTICE, "%-22s = seconds to connect OCSP responder", "TIMEOUTocsp"); |
| 4058 |
break; |
| 4059 |
} |
| 4060 |
#endif /* !OPENSSL_NO_OCSP */ |
| 4061 |
|
| 4062 |
/* transparent */ |
| 4063 |
#ifndef USE_WIN32 |
| 4064 |
switch(cmd) { |
| 4065 |
case CMD_SET_DEFAULTS: |
| 4066 |
section->option.transparent_src=0; |
| 4067 |
section->option.transparent_dst=0; |
| 4068 |
break; |
| 4069 |
case CMD_SET_COPY: |
| 4070 |
section->option.transparent_src=new_service_options.option.transparent_src; |
| 4071 |
section->option.transparent_dst=new_service_options.option.transparent_dst; |
| 4072 |
break; |
| 4073 |
case CMD_FREE: |
| 4074 |
break; |
| 4075 |
case CMD_SET_VALUE: |
| 4076 |
if(strcasecmp(opt, "transparent")) |
| 4077 |
break; |
| 4078 |
if(!strcasecmp(arg, "none") || !strcasecmp(arg, "no")) { |
| 4079 |
section->option.transparent_src=0; |
| 4080 |
section->option.transparent_dst=0; |
| 4081 |
} else if(!strcasecmp(arg, "source") || !strcasecmp(arg, "yes")) { |
| 4082 |
section->option.transparent_src=1; |
| 4083 |
section->option.transparent_dst=0; |
| 4084 |
} else if(!strcasecmp(arg, "destination")) { |
| 4085 |
section->option.transparent_src=0; |
| 4086 |
section->option.transparent_dst=1; |
| 4087 |
} else if(!strcasecmp(arg, "both")) { |
| 4088 |
section->option.transparent_src=1; |
| 4089 |
section->option.transparent_dst=1; |
| 4090 |
} else |
| 4091 |
return "Selected transparent proxy mode is not available"; |
| 4092 |
return NULL; /* OK */ |
| 4093 |
case CMD_INITIALIZE: |
| 4094 |
if(section->option.transparent_dst) |
| 4095 |
++endpoints; |
| 4096 |
break; |
| 4097 |
case CMD_PRINT_DEFAULTS: |
| 4098 |
break; |
| 4099 |
case CMD_PRINT_HELP: |
| 4100 |
s_log(LOG_NOTICE, |
| 4101 |
"%-22s = none|source|destination|both transparent proxy mode", |
| 4102 |
"transparent"); |
| 4103 |
break; |
| 4104 |
} |
| 4105 |
#endif |
| 4106 |
|
| 4107 |
/* verify */ |
| 4108 |
switch(cmd) { |
| 4109 |
case CMD_SET_DEFAULTS: |
| 4110 |
section->option.request_cert=0; |
| 4111 |
break; |
| 4112 |
case CMD_SET_COPY: |
| 4113 |
section->option.request_cert=new_service_options.option.request_cert; |
| 4114 |
break; |
| 4115 |
case CMD_FREE: |
| 4116 |
break; |
| 4117 |
case CMD_SET_VALUE: |
| 4118 |
if(strcasecmp(opt, "verify")) |
| 4119 |
break; |
| 4120 |
{ |
| 4121 |
char *tmp_str; |
| 4122 |
int tmp_int=(int)strtol(arg, &tmp_str, 10); |
| 4123 |
if(tmp_str==arg || *tmp_str || tmp_int<0 || tmp_int>4) |
| 4124 |
return "Bad verify level"; |
| 4125 |
section->option.request_cert=1; |
| 4126 |
section->option.require_cert=(tmp_int>=2); |
| 4127 |
section->option.verify_chain=(tmp_int>=1 && tmp_int<=3); |
| 4128 |
section->option.verify_peer=(tmp_int>=3); |
| 4129 |
} |
| 4130 |
return NULL; /* OK */ |
| 4131 |
case CMD_INITIALIZE: |
| 4132 |
#ifndef OPENSSL_NO_ENGINE |
| 4133 |
if((section->option.verify_chain || section->option.verify_peer) && |
| 4134 |
!section->ca_engine && !section->ca_file && !section->ca_dir |
| 4135 |
#if OPENSSL_VERSION_NUMBER>=0x30000000L |
| 4136 |
&& !section->ca_store) |
| 4137 |
return "Either \"CAengine\", \"CAfile\", \"CApath\" or \"CAstore\" has to be configured"; |
| 4138 |
#else /* OPENSSL_VERSION_NUMBER>=0x30000000L */ |
| 4139 |
) |
| 4140 |
return "Either \"CAengine\", \"CAfile\" or \"CApath\" has to be configured"; |
| 4141 |
#endif /* OPENSSL_VERSION_NUMBER>=0x30000000L */ |
| 4142 |
#else /* OPENSSL_NO_ENGINE */ |
| 4143 |
if((section->option.verify_chain || section->option.verify_peer) && |
| 4144 |
!section->ca_file && !section->ca_dir |
| 4145 |
#if OPENSSL_VERSION_NUMBER>=0x30000000L |
| 4146 |
&& !section->ca_store) |
| 4147 |
return "Either \"CAfile\", \"CApath\" or \"CAstore\" has to be configured"; |
| 4148 |
#else /* OPENSSL_VERSION_NUMBER>=0x30000000L */ |
| 4149 |
) |
| 4150 |
return "Either \"CAfile\" or \"CApath\" has to be configured"; |
| 4151 |
#endif /* OPENSSL_VERSION_NUMBER>=0x30000000L */ |
| 4152 |
#endif /* OPENSSL_NO_ENGINE */ |
| 4153 |
break; |
| 4154 |
case CMD_PRINT_DEFAULTS: |
| 4155 |
s_log(LOG_NOTICE, "%-22s = none", "verify"); |
| 4156 |
break; |
| 4157 |
case CMD_PRINT_HELP: |
| 4158 |
s_log(LOG_NOTICE, |
| 4159 |
"%-22s = level of peer certificate verification", "verify"); |
| 4160 |
break; |
| 4161 |
} |
| 4162 |
|
| 4163 |
/* verifyChain */ |
| 4164 |
switch(cmd) { |
| 4165 |
case CMD_SET_DEFAULTS: |
| 4166 |
section->option.verify_chain=0; |
| 4167 |
break; |
| 4168 |
case CMD_SET_COPY: |
| 4169 |
section->option.verify_chain=new_service_options.option.verify_chain; |
| 4170 |
break; |
| 4171 |
case CMD_FREE: |
| 4172 |
break; |
| 4173 |
case CMD_SET_VALUE: |
| 4174 |
if(strcasecmp(opt, "verifyChain")) |
| 4175 |
break; |
| 4176 |
if(!strcasecmp(arg, "yes")) { |
| 4177 |
section->option.request_cert=1; |
| 4178 |
section->option.require_cert=1; |
| 4179 |
section->option.verify_chain=1; |
| 4180 |
} else if(!strcasecmp(arg, "no")) { |
| 4181 |
section->option.verify_chain=0; |
| 4182 |
} else { |
| 4183 |
return "The argument needs to be either 'yes' or 'no'"; |
| 4184 |
} |
| 4185 |
return NULL; /* OK */ |
| 4186 |
case CMD_INITIALIZE: |
| 4187 |
break; |
| 4188 |
case CMD_PRINT_DEFAULTS: |
| 4189 |
break; |
| 4190 |
case CMD_PRINT_HELP: |
| 4191 |
s_log(LOG_NOTICE, "%-22s = yes|no verify certificate chain", |
| 4192 |
"verifyChain"); |
| 4193 |
break; |
| 4194 |
} |
| 4195 |
|
| 4196 |
/* verifyPeer */ |
| 4197 |
switch(cmd) { |
| 4198 |
case CMD_SET_DEFAULTS: |
| 4199 |
section->option.verify_peer=0; |
| 4200 |
break; |
| 4201 |
case CMD_SET_COPY: |
| 4202 |
section->option.verify_peer=new_service_options.option.verify_peer; |
| 4203 |
break; |
| 4204 |
case CMD_FREE: |
| 4205 |
break; |
| 4206 |
case CMD_SET_VALUE: |
| 4207 |
if(strcasecmp(opt, "verifyPeer")) |
| 4208 |
break; |
| 4209 |
if(!strcasecmp(arg, "yes")) { |
| 4210 |
section->option.request_cert=1; |
| 4211 |
section->option.require_cert=1; |
| 4212 |
section->option.verify_peer=1; |
| 4213 |
} else if(!strcasecmp(arg, "no")) { |
| 4214 |
section->option.verify_peer=0; |
| 4215 |
} else { |
| 4216 |
return "The argument needs to be either 'yes' or 'no'"; |
| 4217 |
} |
| 4218 |
return NULL; /* OK */ |
| 4219 |
case CMD_INITIALIZE: |
| 4220 |
break; |
| 4221 |
case CMD_PRINT_DEFAULTS: |
| 4222 |
break; |
| 4223 |
case CMD_PRINT_HELP: |
| 4224 |
s_log(LOG_NOTICE, "%-22s = yes|no verify peer certificate", |
| 4225 |
"verifyPeer"); |
| 4226 |
break; |
| 4227 |
} |
| 4228 |
|
| 4229 |
/* final checks */ |
| 4230 |
switch(cmd) { |
| 4231 |
case CMD_SET_DEFAULTS: |
| 4232 |
break; |
| 4233 |
case CMD_SET_COPY: |
| 4234 |
break; |
| 4235 |
case CMD_FREE: |
| 4236 |
context_cleanup(section); |
| 4237 |
str_free(section->servname); |
| 4238 |
if(section==&service_options || section==&new_service_options) |
| 4239 |
memset(section, 0, sizeof(SERVICE_OPTIONS)); |
| 4240 |
else |
| 4241 |
str_free(section); |
| 4242 |
break; |
| 4243 |
case CMD_SET_VALUE: |
| 4244 |
return option_not_found; |
| 4245 |
case CMD_INITIALIZE: |
| 4246 |
if(section!=&new_service_options) { /* daemon mode checks */ |
| 4247 |
if(endpoints!=2) |
| 4248 |
return "Each service must define two endpoints"; |
| 4249 |
} else { /* inetd mode checks */ |
| 4250 |
if(section->option.accept) |
| 4251 |
return "'accept' option is only allowed in a [section]"; |
| 4252 |
/* no need to check for section->sni in inetd mode, |
| 4253 |
as it requires valid sections to be set */ |
| 4254 |
if(endpoints!=1) |
| 4255 |
return "Inetd mode must define one endpoint"; |
| 4256 |
} |
| 4257 |
#ifdef SSL_OP_NO_TICKET |
| 4258 |
/* disable RFC4507 support introduced in OpenSSL 0.9.8f */ |
| 4259 |
/* OpenSSL 1.1.1 is required to serialize application data |
| 4260 |
* into session tickets */ |
| 4261 |
/* server mode sections need it for the "redirect" option |
| 4262 |
* and connect address session persistence */ |
| 4263 |
if(OpenSSL_version_num()<0x10101000L && |
| 4264 |
!section->option.client && |
| 4265 |
!section->option.connect_before_ssl) |
| 4266 |
section->ssl_options_set|=SSL_OP_NO_TICKET; |
| 4267 |
#endif /* SSL_OP_NO_TICKET */ |
| 4268 |
if(context_init(section)) /* initialize TLS context */ |
| 4269 |
return "Failed to initialize TLS context"; |
| 4270 |
break; |
| 4271 |
case CMD_PRINT_DEFAULTS: |
| 4272 |
break; |
| 4273 |
case CMD_PRINT_HELP: |
| 4274 |
break; |
| 4275 |
} |
| 4276 |
|
| 4277 |
return NULL; /* OK */ |
| 4278 |
} |
| 4279 |
|
| 4280 |
/**************************************** validate and initialize configuration */ |
| 4281 |
|
| 4282 |
#ifndef OPENSSL_NO_TLSEXT |
| 4283 |
|
| 4284 |
NOEXPORT const char *sni_init(SERVICE_OPTIONS *section) { |
| 4285 |
char *tmp_str; |
| 4286 |
SERVICE_OPTIONS *tmpsrv; |
| 4287 |
|
| 4288 |
/* server mode: update servername_list based on the SNI option */ |
| 4289 |
if(!section->option.client && section->sni) { |
| 4290 |
tmp_str=strchr(section->sni, ':'); |
| 4291 |
if(!tmp_str) |
| 4292 |
return "Invalid SNI parameter format"; |
| 4293 |
*tmp_str++='\0'; |
| 4294 |
for(tmpsrv=new_service_options.next; tmpsrv; tmpsrv=tmpsrv->next) |
| 4295 |
if(!strcmp(tmpsrv->servname, section->sni)) |
| 4296 |
break; |
| 4297 |
if(!tmpsrv) |
| 4298 |
return "SNI section name not found"; |
| 4299 |
if(tmpsrv->option.client) |
| 4300 |
return "SNI primary service is a TLS client"; |
| 4301 |
if(tmpsrv->servername_list_tail) { |
| 4302 |
tmpsrv->servername_list_tail->next=str_alloc_detached(sizeof(SERVERNAME_LIST)); |
| 4303 |
tmpsrv->servername_list_tail=tmpsrv->servername_list_tail->next; |
| 4304 |
} else { /* first virtual service */ |
| 4305 |
tmpsrv->servername_list_head= |
| 4306 |
tmpsrv->servername_list_tail= |
| 4307 |
str_alloc_detached(sizeof(SERVERNAME_LIST)); |
| 4308 |
tmpsrv->ssl_options_set|= |
| 4309 |
SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION; |
| 4310 |
} |
| 4311 |
/* a secondary section reference is needed to prevent a race condition |
| 4312 |
while switching to a section after configuration file reload */ |
| 4313 |
service_up_ref(section); |
| 4314 |
tmpsrv->servername_list_tail->servername=str_dup_detached(tmp_str); |
| 4315 |
tmpsrv->servername_list_tail->opt=section; |
| 4316 |
tmpsrv->servername_list_tail->next=NULL; |
| 4317 |
/* always negotiate a new session on renegotiation, as the TLS |
| 4318 |
* context settings (including access control) may be different */ |
| 4319 |
section->ssl_options_set|= |
| 4320 |
SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION; |
| 4321 |
} |
| 4322 |
|
| 4323 |
/* client mode: setup SNI default based on 'protocolHost' and 'connect' options */ |
| 4324 |
if(section->option.client && !section->sni) { |
| 4325 |
/* setup host_name for SNI, prefer SNI and protocolHost if specified */ |
| 4326 |
if(section->protocol_host) /* 'protocolHost' option */ |
| 4327 |
section->sni=str_dup_detached(section->protocol_host); |
| 4328 |
else if(section->connect_addr.names) /* 'connect' option */ |
| 4329 |
section->sni=str_dup_detached(section->connect_addr.names->name); /* first hostname */ |
| 4330 |
if(section->sni) { /* either 'protocolHost' or 'connect' specified */ |
| 4331 |
tmp_str=strrchr(section->sni, ':'); |
| 4332 |
if(tmp_str) { /* 'host:port' -> drop ':port' */ |
| 4333 |
*tmp_str='\0'; |
| 4334 |
} else { /* 'port' -> default to 'localhost' */ |
| 4335 |
str_free(section->sni); |
| 4336 |
section->sni=str_dup_detached("localhost"); |
| 4337 |
} |
| 4338 |
} |
| 4339 |
} |
| 4340 |
return NULL; |
| 4341 |
} |
| 4342 |
|
| 4343 |
NOEXPORT void sni_free(SERVICE_OPTIONS *section) { |
| 4344 |
SERVERNAME_LIST *curr=section->servername_list_head; |
| 4345 |
while(curr) { |
| 4346 |
SERVERNAME_LIST *next=curr->next; |
| 4347 |
str_free(curr->servername); |
| 4348 |
service_free(curr->opt); /* free the secondary section */ |
| 4349 |
str_free(curr); |
| 4350 |
curr=next; |
| 4351 |
} |
| 4352 |
section->servername_list_head=NULL; |
| 4353 |
section->servername_list_tail=NULL; |
| 4354 |
} |
| 4355 |
|
| 4356 |
#endif /* !defined(OPENSSL_NO_TLSEXT) */ |
| 4357 |
|
| 4358 |
/**************************************** modern TLS version handling */ |
| 4359 |
|
| 4360 |
#if OPENSSL_VERSION_NUMBER>=0x10100000L |
| 4361 |
|
| 4362 |
NOEXPORT int str_to_proto_version(const char *name) { |
| 4363 |
if(!strcasecmp(name, "all")) |
| 4364 |
return 0; |
| 4365 |
if(!strcasecmp(name, "SSLv3")) |
| 4366 |
return SSL3_VERSION; |
| 4367 |
if(!strcasecmp(name, "TLSv1")) |
| 4368 |
return TLS1_VERSION; |
| 4369 |
if(!strcasecmp(name, "TLSv1.1")) |
| 4370 |
return TLS1_1_VERSION; |
| 4371 |
if(!strcasecmp(name, "TLSv1.2")) |
| 4372 |
return TLS1_2_VERSION; |
| 4373 |
#ifdef TLS1_3_VERSION |
| 4374 |
if(!strcasecmp(name, "TLSv1.3")) |
| 4375 |
return TLS1_3_VERSION; |
| 4376 |
#endif |
| 4377 |
return -1; |
| 4378 |
} |
| 4379 |
|
| 4380 |
/**************************************** deprecated TLS version handling */ |
| 4381 |
|
| 4382 |
#else /* OPENSSL_VERSION_NUMBER<0x10100000L */ |
| 4383 |
|
| 4384 |
#ifdef __GNUC__ |
| 4385 |
#pragma GCC diagnostic push |
| 4386 |
#pragma GCC diagnostic ignored "-Wdeprecated-declarations" |
| 4387 |
#endif /* __GNUC__ */ |
| 4388 |
|
| 4389 |
NOEXPORT char *tls_methods_set(SERVICE_OPTIONS *section, const char *arg) { |
| 4390 |
if(!arg) { /* defaults */ |
| 4391 |
section->client_method=(SSL_METHOD *)SSLv23_client_method(); |
| 4392 |
section->server_method=(SSL_METHOD *)SSLv23_server_method(); |
| 4393 |
} else if(!strcasecmp(arg, "all")) { |
| 4394 |
section->client_method=(SSL_METHOD *)SSLv23_client_method(); |
| 4395 |
section->server_method=(SSL_METHOD *)SSLv23_server_method(); |
| 4396 |
} else if(!strcasecmp(arg, "SSLv2")) { |
| 4397 |
#ifndef OPENSSL_NO_SSL2 |
| 4398 |
section->client_method=(SSL_METHOD *)SSLv2_client_method(); |
| 4399 |
section->server_method=(SSL_METHOD *)SSLv2_server_method(); |
| 4400 |
#else /* OPENSSL_NO_SSL2 */ |
| 4401 |
return "SSLv2 not supported"; |
| 4402 |
#endif /* !OPENSSL_NO_SSL2 */ |
| 4403 |
} else if(!strcasecmp(arg, "SSLv3")) { |
| 4404 |
#ifndef OPENSSL_NO_SSL3 |
| 4405 |
section->client_method=(SSL_METHOD *)SSLv3_client_method(); |
| 4406 |
section->server_method=(SSL_METHOD *)SSLv3_server_method(); |
| 4407 |
#else /* OPENSSL_NO_SSL3 */ |
| 4408 |
return "SSLv3 not supported"; |
| 4409 |
#endif /* !OPENSSL_NO_SSL3 */ |
| 4410 |
} else if(!strcasecmp(arg, "TLSv1")) { |
| 4411 |
#ifndef OPENSSL_NO_TLS1 |
| 4412 |
section->client_method=(SSL_METHOD *)TLSv1_client_method(); |
| 4413 |
section->server_method=(SSL_METHOD *)TLSv1_server_method(); |
| 4414 |
#else /* OPENSSL_NO_TLS1 */ |
| 4415 |
return "TLSv1 not supported"; |
| 4416 |
#endif /* !OPENSSL_NO_TLS1 */ |
| 4417 |
} else if(!strcasecmp(arg, "TLSv1.1")) { |
| 4418 |
#ifndef OPENSSL_NO_TLS1_1 |
| 4419 |
section->client_method=(SSL_METHOD *)TLSv1_1_client_method(); |
| 4420 |
section->server_method=(SSL_METHOD *)TLSv1_1_server_method(); |
| 4421 |
#else /* OPENSSL_NO_TLS1_1 */ |
| 4422 |
return "TLSv1.1 not supported"; |
| 4423 |
#endif /* !OPENSSL_NO_TLS1_1 */ |
| 4424 |
} else if(!strcasecmp(arg, "TLSv1.2")) { |
| 4425 |
#ifndef OPENSSL_NO_TLS1_2 |
| 4426 |
section->client_method=(SSL_METHOD *)TLSv1_2_client_method(); |
| 4427 |
section->server_method=(SSL_METHOD *)TLSv1_2_server_method(); |
| 4428 |
#else /* OPENSSL_NO_TLS1_2 */ |
| 4429 |
return "TLSv1.2 not supported"; |
| 4430 |
#endif /* !OPENSSL_NO_TLS1_2 */ |
| 4431 |
} else |
| 4432 |
return "Incorrect version of TLS protocol"; |
| 4433 |
return NULL; /* OK */ |
| 4434 |
} |
| 4435 |
|
| 4436 |
NOEXPORT char *tls_methods_check(SERVICE_OPTIONS *section) { |
| 4437 |
#ifdef USE_FIPS |
| 4438 |
if(new_global_options.option.fips) { |
| 4439 |
#ifndef OPENSSL_NO_SSL2 |
| 4440 |
if(section->option.client ? |
| 4441 |
section->client_method==(SSL_METHOD *)SSLv2_client_method() : |
| 4442 |
section->server_method==(SSL_METHOD *)SSLv2_server_method()) |
| 4443 |
return "\"sslVersion = SSLv2\" not supported in FIPS mode"; |
| 4444 |
#endif /* !OPENSSL_NO_SSL2 */ |
| 4445 |
#ifndef OPENSSL_NO_SSL3 |
| 4446 |
if(section->option.client ? |
| 4447 |
section->client_method==(SSL_METHOD *)SSLv3_client_method() : |
| 4448 |
section->server_method==(SSL_METHOD *)SSLv3_server_method()) |
| 4449 |
return "\"sslVersion = SSLv3\" not supported in FIPS mode"; |
| 4450 |
#endif /* !OPENSSL_NO_SSL3 */ |
| 4451 |
} |
| 4452 |
#else /* USE_FIPS */ |
| 4453 |
(void)section; /* squash the unused parameter warning */ |
| 4454 |
#endif /* USE_FIPS */ |
| 4455 |
return NULL; |
| 4456 |
} |
| 4457 |
|
| 4458 |
#ifdef __GNUC__ |
| 4459 |
#pragma GCC diagnostic pop |
| 4460 |
#endif /* __GNUC__ */ |
| 4461 |
|
| 4462 |
#endif /* OPENSSL_VERSION_NUMBER<0x10100000L */ |
| 4463 |
|
| 4464 |
/**************************************** facility/debug level */ |
| 4465 |
|
| 4466 |
typedef struct { |
| 4467 |
const char *name; |
| 4468 |
int value; |
| 4469 |
} facilitylevel; |
| 4470 |
|
| 4471 |
NOEXPORT const char *parse_debug_level(char *arg, SERVICE_OPTIONS *section) { |
| 4472 |
facilitylevel *fl; |
| 4473 |
|
| 4474 |
/* facilities only make sense on unix */ |
| 4475 |
#if !defined (USE_WIN32) && !defined (__vms) |
| 4476 |
facilitylevel facilities[]={ |
| 4477 |
{"auth", LOG_AUTH}, {"cron", LOG_CRON}, {"daemon", LOG_DAEMON}, |
| 4478 |
{"kern", LOG_KERN}, {"lpr", LOG_LPR}, {"mail", LOG_MAIL}, |
| 4479 |
{"news", LOG_NEWS}, {"syslog", LOG_SYSLOG}, {"user", LOG_USER}, |
| 4480 |
{"uucp", LOG_UUCP}, {"local0", LOG_LOCAL0}, {"local1", LOG_LOCAL1}, |
| 4481 |
{"local2", LOG_LOCAL2}, {"local3", LOG_LOCAL3}, {"local4", LOG_LOCAL4}, |
| 4482 |
{"local5", LOG_LOCAL5}, {"local6", LOG_LOCAL6}, {"local7", LOG_LOCAL7}, |
| 4483 |
|
| 4484 |
/* some facilities are not defined on all Unices */ |
| 4485 |
#ifdef LOG_AUTHPRIV |
| 4486 |
{"authpriv", LOG_AUTHPRIV}, |
| 4487 |
#endif |
| 4488 |
#ifdef LOG_FTP |
| 4489 |
{"ftp", LOG_FTP}, |
| 4490 |
#endif |
| 4491 |
#ifdef LOG_NTP |
| 4492 |
{"ntp", LOG_NTP}, |
| 4493 |
#endif |
| 4494 |
{NULL, 0} |
| 4495 |
}; |
| 4496 |
#endif /* USE_WIN32, __vms */ |
| 4497 |
|
| 4498 |
facilitylevel levels[]={ |
| 4499 |
{"emerg", LOG_EMERG}, {"alert", LOG_ALERT}, |
| 4500 |
{"crit", LOG_CRIT}, {"err", LOG_ERR}, |
| 4501 |
{"warning", LOG_WARNING}, {"notice", LOG_NOTICE}, |
| 4502 |
{"info", LOG_INFO}, {"debug", LOG_DEBUG}, |
| 4503 |
{NULL, -1} |
| 4504 |
}; |
| 4505 |
|
| 4506 |
/* facilities only make sense on Unix */ |
| 4507 |
#if !defined (USE_WIN32) && !defined (__vms) |
| 4508 |
if(section==&new_service_options && strchr(arg, '.')) { |
| 4509 |
/* a facility was specified in the global options */ |
| 4510 |
new_global_options.log_facility=-1; |
| 4511 |
arg=strtok(arg, "."); /* break it up */ |
| 4512 |
|
| 4513 |
for(fl=facilities; fl->name; ++fl) { |
| 4514 |
if(!strcasecmp(fl->name, arg)) { |
| 4515 |
new_global_options.log_facility=fl->value; |
| 4516 |
break; |
| 4517 |
} |
| 4518 |
} |
| 4519 |
if(new_global_options.log_facility==-1) |
| 4520 |
return "Illegal syslog facility"; |
| 4521 |
arg=strtok(NULL, "."); /* set to the remainder */ |
| 4522 |
} |
| 4523 |
#endif /* USE_WIN32, __vms */ |
| 4524 |
|
| 4525 |
/* time to check the syslog level */ |
| 4526 |
if(arg && strlen(arg)==1 && *arg>='0' && *arg<='7') { |
| 4527 |
section->log_level=*arg-'0'; |
| 4528 |
return NULL; /* OK */ |
| 4529 |
} |
| 4530 |
section->log_level=8; /* illegal level */ |
| 4531 |
for(fl=levels; fl->name; ++fl) { |
| 4532 |
if(!strcasecmp(fl->name, arg)) { |
| 4533 |
section->log_level=fl->value; |
| 4534 |
break; |
| 4535 |
} |
| 4536 |
} |
| 4537 |
if(section->log_level==8) |
| 4538 |
return "Illegal debug level"; /* FAILED */ |
| 4539 |
return NULL; /* OK */ |
| 4540 |
} |
| 4541 |
|
| 4542 |
/**************************************** TLS options */ |
| 4543 |
|
| 4544 |
NOEXPORT uint64_t parse_ssl_option(char *arg) { |
| 4545 |
const SSL_OPTION *option; |
| 4546 |
|
| 4547 |
for(option=ssl_opts; option->name; ++option) |
| 4548 |
if(!strcasecmp(option->name, arg)) |
| 4549 |
return option->value; |
| 4550 |
return INVALID_SSL_OPTION; /* FAILED */ |
| 4551 |
} |
| 4552 |
|
| 4553 |
NOEXPORT void print_ssl_options(void) { |
| 4554 |
const SSL_OPTION *option; |
| 4555 |
|
| 4556 |
s_log(LOG_NOTICE, " "); |
| 4557 |
s_log(LOG_NOTICE, "Supported TLS options:"); |
| 4558 |
for(option=ssl_opts; option->name; ++option) |
| 4559 |
s_log(LOG_NOTICE, "options = %s", option->name); |
| 4560 |
} |
| 4561 |
|
| 4562 |
/**************************************** read PSK file */ |
| 4563 |
|
| 4564 |
#ifndef OPENSSL_NO_PSK |
| 4565 |
|
| 4566 |
NOEXPORT PSK_KEYS *psk_read(char *key_file) { |
| 4567 |
DISK_FILE *df; |
| 4568 |
char line[CONFLINELEN], *key_str; |
| 4569 |
unsigned char *key_buf; |
| 4570 |
long key_len; |
| 4571 |
PSK_KEYS *head=NULL, *tail=NULL, *curr; |
| 4572 |
int line_number=0; |
| 4573 |
|
| 4574 |
if(file_permissions(key_file)) |
| 4575 |
return NULL; |
| 4576 |
df=file_open(key_file, FILE_MODE_READ); |
| 4577 |
if(!df) { |
| 4578 |
s_log(LOG_ERR, "Cannot open PSKsecrets file"); |
| 4579 |
return NULL; |
| 4580 |
} |
| 4581 |
while(file_getline(df, line, CONFLINELEN)>=0) { |
| 4582 |
++line_number; |
| 4583 |
if(!line[0]) /* empty line */ |
| 4584 |
continue; |
| 4585 |
key_str=strchr(line, ':'); |
| 4586 |
if(!key_str) { |
| 4587 |
s_log(LOG_ERR, |
| 4588 |
"PSKsecrets line %d: Not in identity:key format", |
| 4589 |
line_number); |
| 4590 |
file_close(df); |
| 4591 |
psk_free(head); |
| 4592 |
return NULL; |
| 4593 |
} |
| 4594 |
*key_str++='\0'; |
| 4595 |
if(strlen(line)+1>PSK_MAX_IDENTITY_LEN) { /* with the trailing '\0' */ |
| 4596 |
s_log(LOG_ERR, |
| 4597 |
"PSKsecrets line %d: Identity longer than %d characters", |
| 4598 |
line_number, PSK_MAX_IDENTITY_LEN); |
| 4599 |
file_close(df); |
| 4600 |
psk_free(head); |
| 4601 |
return NULL; |
| 4602 |
} |
| 4603 |
key_buf=OPENSSL_hexstr2buf(key_str, &key_len); |
| 4604 |
if(key_buf) { /* a valid hexadecimal value */ |
| 4605 |
s_log(LOG_INFO, "PSKsecrets line %d: " |
| 4606 |
"%ld-byte hexadecimal key configured for identity \"%s\"", |
| 4607 |
line_number, key_len, line); |
| 4608 |
} else { /* not a valid hexadecimal value -> copy as a string */ |
| 4609 |
key_len=(long)strlen(key_str); |
| 4610 |
key_buf=OPENSSL_malloc((size_t)key_len); |
| 4611 |
memcpy(key_buf, key_str, (size_t)key_len); |
| 4612 |
s_log(LOG_INFO, "PSKsecrets line %d: " |
| 4613 |
"%ld-byte ASCII key configured for identity \"%s\"", |
| 4614 |
line_number, key_len, line); |
| 4615 |
} |
| 4616 |
if(key_len>PSK_MAX_PSK_LEN) { |
| 4617 |
s_log(LOG_ERR, |
| 4618 |
"PSKsecrets line %d: Key longer than %d bytes", |
| 4619 |
line_number, PSK_MAX_PSK_LEN); |
| 4620 |
OPENSSL_free(key_buf); |
| 4621 |
file_close(df); |
| 4622 |
psk_free(head); |
| 4623 |
return NULL; |
| 4624 |
} |
| 4625 |
if(key_len<16) { |
| 4626 |
/* shorter keys are unlikely to have sufficient entropy */ |
| 4627 |
s_log(LOG_ERR, |
| 4628 |
"PSKsecrets line %d: Key shorter than 16 bytes", |
| 4629 |
line_number); |
| 4630 |
OPENSSL_free(key_buf); |
| 4631 |
file_close(df); |
| 4632 |
psk_free(head); |
| 4633 |
return NULL; |
| 4634 |
} |
| 4635 |
curr=str_alloc_detached(sizeof(PSK_KEYS)); |
| 4636 |
curr->identity=str_dup_detached(line); |
| 4637 |
curr->key_val=str_alloc_detached((size_t)key_len); |
| 4638 |
memcpy(curr->key_val, key_buf, (size_t)key_len); |
| 4639 |
OPENSSL_free(key_buf); |
| 4640 |
curr->key_len=(unsigned)key_len; |
| 4641 |
curr->next=NULL; |
| 4642 |
if(head) |
| 4643 |
tail->next=curr; |
| 4644 |
else |
| 4645 |
head=curr; |
| 4646 |
tail=curr; |
| 4647 |
} |
| 4648 |
file_close(df); |
| 4649 |
return head; |
| 4650 |
} |
| 4651 |
|
| 4652 |
NOEXPORT PSK_KEYS *psk_dup(PSK_KEYS *src) { |
| 4653 |
PSK_KEYS *head=NULL, *tail=NULL, *curr; |
| 4654 |
|
| 4655 |
for(; src; src=src->next) { |
| 4656 |
curr=str_alloc_detached(sizeof(PSK_KEYS)); |
| 4657 |
curr->identity=str_dup_detached(src->identity); |
| 4658 |
curr->key_val=str_alloc_detached(src->key_len); |
| 4659 |
memcpy(curr->key_val, src->key_val, src->key_len); |
| 4660 |
curr->key_len=src->key_len; |
| 4661 |
curr->next=NULL; |
| 4662 |
if(head) |
| 4663 |
tail->next=curr; |
| 4664 |
else |
| 4665 |
head=curr; |
| 4666 |
tail=curr; |
| 4667 |
} |
| 4668 |
return head; |
| 4669 |
} |
| 4670 |
|
| 4671 |
NOEXPORT void psk_free(PSK_KEYS *head) { |
| 4672 |
while(head) { |
| 4673 |
PSK_KEYS *next=head->next; |
| 4674 |
str_free_const(head->identity); |
| 4675 |
str_free(head->key_val); |
| 4676 |
str_free(head); |
| 4677 |
head=next; |
| 4678 |
} |
| 4679 |
} |
| 4680 |
|
| 4681 |
#endif |
| 4682 |
|
| 4683 |
/**************************************** read ticket key */ |
| 4684 |
|
| 4685 |
#if OPENSSL_VERSION_NUMBER>=0x10000000L |
| 4686 |
|
| 4687 |
NOEXPORT TICKET_KEY *key_read(char *arg, const char *option) { |
| 4688 |
char *key_str; |
| 4689 |
unsigned char *key_buf; |
| 4690 |
long key_len; |
| 4691 |
TICKET_KEY *head=NULL; |
| 4692 |
|
| 4693 |
key_str=str_dup_detached(arg); |
| 4694 |
key_buf=OPENSSL_hexstr2buf(key_str, &key_len); |
| 4695 |
if(key_buf) |
| 4696 |
if((key_len == 16) || (key_len == 32)) /* a valid 16 or 32 byte hexadecimal value */ |
| 4697 |
s_log(LOG_INFO, "%s configured", option); |
| 4698 |
else { /* not a valid length */ |
| 4699 |
s_log(LOG_ERR, "%s value has %ld bytes instead of required 16 or 32 bytes", |
| 4700 |
option, key_len); |
| 4701 |
OPENSSL_free(key_buf); |
| 4702 |
key_free(head); |
| 4703 |
return NULL; |
| 4704 |
} |
| 4705 |
else { /* not a valid hexadecimal form */ |
| 4706 |
s_log(LOG_ERR, "Required %s is 16 or 32 byte hexadecimal key", option); |
| 4707 |
key_free(head); |
| 4708 |
return NULL; |
| 4709 |
} |
| 4710 |
head=str_alloc_detached(sizeof(TICKET_KEY)); |
| 4711 |
head->key_val=str_alloc_detached((size_t)key_len); |
| 4712 |
memcpy(head->key_val, key_buf, (size_t)key_len); |
| 4713 |
OPENSSL_free(key_buf); |
| 4714 |
head->key_len=(int)key_len; |
| 4715 |
return head; |
| 4716 |
} |
| 4717 |
|
| 4718 |
NOEXPORT TICKET_KEY *key_dup(TICKET_KEY *src) { |
| 4719 |
TICKET_KEY *head=NULL; |
| 4720 |
|
| 4721 |
if (src) { |
| 4722 |
head=str_alloc_detached(sizeof(TICKET_KEY)); |
| 4723 |
head->key_val=(unsigned char *)str_dup_detached((char *)src->key_val); |
| 4724 |
head->key_len=src->key_len; |
| 4725 |
} |
| 4726 |
return head; |
| 4727 |
} |
| 4728 |
|
| 4729 |
NOEXPORT void key_free(TICKET_KEY *head) { |
| 4730 |
if (head) { |
| 4731 |
str_free(head->key_val); |
| 4732 |
str_free(head); |
| 4733 |
} |
| 4734 |
} |
| 4735 |
|
| 4736 |
#endif /* OpenSSL 1.0.0 or later */ |
| 4737 |
|
| 4738 |
/**************************************** socket options */ |
| 4739 |
|
| 4740 |
#define VAL_TAB {NULL, NULL, NULL} |
| 4741 |
|
| 4742 |
SOCK_OPT sock_opts_def[]={ |
| 4743 |
{"SO_DEBUG", SOL_SOCKET, SO_DEBUG, TYPE_FLAG, VAL_TAB}, |
| 4744 |
{"SO_DONTROUTE", SOL_SOCKET, SO_DONTROUTE, TYPE_FLAG, VAL_TAB}, |
| 4745 |
{"SO_KEEPALIVE", SOL_SOCKET, SO_KEEPALIVE, TYPE_FLAG, VAL_TAB}, |
| 4746 |
{"SO_LINGER", SOL_SOCKET, SO_LINGER, TYPE_LINGER, VAL_TAB}, |
| 4747 |
{"SO_OOBINLINE", SOL_SOCKET, SO_OOBINLINE, TYPE_FLAG, VAL_TAB}, |
| 4748 |
{"SO_RCVBUF", SOL_SOCKET, SO_RCVBUF, TYPE_INT, VAL_TAB}, |
| 4749 |
{"SO_SNDBUF", SOL_SOCKET, SO_SNDBUF, TYPE_INT, VAL_TAB}, |
| 4750 |
#ifdef SO_RCVLOWAT |
| 4751 |
{"SO_RCVLOWAT", SOL_SOCKET, SO_RCVLOWAT, TYPE_INT, VAL_TAB}, |
| 4752 |
#endif |
| 4753 |
#ifdef SO_SNDLOWAT |
| 4754 |
{"SO_SNDLOWAT", SOL_SOCKET, SO_SNDLOWAT, TYPE_INT, VAL_TAB}, |
| 4755 |
#endif |
| 4756 |
#ifdef SO_RCVTIMEO |
| 4757 |
{"SO_RCVTIMEO", SOL_SOCKET, SO_RCVTIMEO, TYPE_TIMEVAL, VAL_TAB}, |
| 4758 |
#endif |
| 4759 |
#ifdef SO_SNDTIMEO |
| 4760 |
{"SO_SNDTIMEO", SOL_SOCKET, SO_SNDTIMEO, TYPE_TIMEVAL, VAL_TAB}, |
| 4761 |
#endif |
| 4762 |
#ifdef USE_WIN32 |
| 4763 |
{"SO_EXCLUSIVEADDRUSE", SOL_SOCKET, SO_EXCLUSIVEADDRUSE, TYPE_FLAG, VAL_TAB}, |
| 4764 |
#endif |
| 4765 |
{"SO_REUSEADDR", SOL_SOCKET, SO_REUSEADDR, TYPE_FLAG, VAL_TAB}, |
| 4766 |
#ifdef SO_BINDTODEVICE |
| 4767 |
{"SO_BINDTODEVICE", SOL_SOCKET, SO_BINDTODEVICE, TYPE_STRING, VAL_TAB}, |
| 4768 |
#endif |
| 4769 |
#ifdef SOL_TCP |
| 4770 |
#ifdef TCP_KEEPCNT |
| 4771 |
{"TCP_KEEPCNT", SOL_TCP, TCP_KEEPCNT, TYPE_INT, VAL_TAB}, |
| 4772 |
#endif |
| 4773 |
#ifdef TCP_KEEPIDLE |
| 4774 |
{"TCP_KEEPIDLE", SOL_TCP, TCP_KEEPIDLE, TYPE_INT, VAL_TAB}, |
| 4775 |
#endif |
| 4776 |
#ifdef TCP_KEEPINTVL |
| 4777 |
{"TCP_KEEPINTVL", SOL_TCP, TCP_KEEPINTVL, TYPE_INT, VAL_TAB}, |
| 4778 |
#endif |
| 4779 |
#endif /* SOL_TCP */ |
| 4780 |
#ifdef IP_TOS |
| 4781 |
{"IP_TOS", IPPROTO_IP, IP_TOS, TYPE_INT, VAL_TAB}, |
| 4782 |
#endif |
| 4783 |
#ifdef IP_TTL |
| 4784 |
{"IP_TTL", IPPROTO_IP, IP_TTL, TYPE_INT, VAL_TAB}, |
| 4785 |
#endif |
| 4786 |
#ifdef IP_MAXSEG |
| 4787 |
{"TCP_MAXSEG", IPPROTO_TCP, TCP_MAXSEG, TYPE_INT, VAL_TAB}, |
| 4788 |
#endif |
| 4789 |
{"TCP_NODELAY", IPPROTO_TCP, TCP_NODELAY, TYPE_FLAG, VAL_TAB}, |
| 4790 |
#ifdef IP_FREEBIND |
| 4791 |
{"IP_FREEBIND", IPPROTO_IP, IP_FREEBIND, TYPE_FLAG, VAL_TAB}, |
| 4792 |
#endif |
| 4793 |
#ifdef IP_BINDANY |
| 4794 |
{"IP_BINDANY", IPPROTO_IP, IP_BINDANY, TYPE_FLAG, VAL_TAB}, |
| 4795 |
#endif |
| 4796 |
#ifdef IPV6_BINDANY |
| 4797 |
{"IPV6_BINDANY", IPPROTO_IPV6, IPV6_BINDANY, TYPE_FLAG, VAL_TAB}, |
| 4798 |
#endif |
| 4799 |
#ifdef IPV6_V6ONLY |
| 4800 |
{"IPV6_V6ONLY", IPPROTO_IPV6, IPV6_V6ONLY, TYPE_FLAG, VAL_TAB}, |
| 4801 |
#endif |
| 4802 |
{NULL, 0, 0, TYPE_NONE, VAL_TAB} |
| 4803 |
}; |
| 4804 |
|
| 4805 |
NOEXPORT SOCK_OPT *socket_options_init(void) { |
| 4806 |
#ifdef USE_WIN32 |
| 4807 |
DWORD version; |
| 4808 |
int major, minor; |
| 4809 |
#endif |
| 4810 |
|
| 4811 |
SOCK_OPT *opt=str_alloc_detached(sizeof sock_opts_def); |
| 4812 |
memcpy(opt, sock_opts_def, sizeof sock_opts_def); |
| 4813 |
|
| 4814 |
#ifdef USE_WIN32 |
| 4815 |
#ifdef _MSC_VER |
| 4816 |
#pragma warning(disable: 4996) |
| 4817 |
#endif |
| 4818 |
version=GetVersion(); |
| 4819 |
major=LOBYTE(LOWORD(version)); |
| 4820 |
minor=HIBYTE(LOWORD(version)); |
| 4821 |
s_log(LOG_DEBUG, "Running on Windows %d.%d", major, minor); |
| 4822 |
|
| 4823 |
if(major>5) /* Vista or later */ |
| 4824 |
socket_option_set_int(opt, "SO_EXCLUSIVEADDRUSE", 0, 1); /* accepting socket */ |
| 4825 |
#else |
| 4826 |
socket_option_set_int(opt, "SO_REUSEADDR", 0, 1); /* accepting socket */ |
| 4827 |
#endif |
| 4828 |
socket_option_set_int(opt, "TCP_NODELAY", 1, 1); /* local socket */ |
| 4829 |
socket_option_set_int(opt, "TCP_NODELAY", 2, 1); /* remote socket */ |
| 4830 |
return opt; |
| 4831 |
} |
| 4832 |
|
| 4833 |
NOEXPORT void socket_option_set_int(SOCK_OPT *opt, const char *name, int type, int value) { |
| 4834 |
for(; opt->opt_str; ++opt) { |
| 4835 |
if(!strcmp(name, opt->opt_str)) { |
| 4836 |
opt->opt_val[type]=str_alloc_detached(sizeof(OPT_UNION)); |
| 4837 |
opt->opt_val[type]->i_val=value; |
| 4838 |
} |
| 4839 |
} |
| 4840 |
} |
| 4841 |
|
| 4842 |
NOEXPORT SOCK_OPT *socket_options_dup(SOCK_OPT *src) { |
| 4843 |
SOCK_OPT *dst=str_alloc_detached(sizeof sock_opts_def); |
| 4844 |
SOCK_OPT *ptr; |
| 4845 |
|
| 4846 |
memcpy(dst, sock_opts_def, sizeof sock_opts_def); |
| 4847 |
for(ptr=dst; src->opt_str; ++src, ++ptr) { |
| 4848 |
int type; |
| 4849 |
for(type=0; type<3; ++type) { |
| 4850 |
if(src->opt_val[type]) { |
| 4851 |
ptr->opt_val[type]=str_alloc_detached(sizeof(OPT_UNION)); |
| 4852 |
memcpy(ptr->opt_val[type], |
| 4853 |
src->opt_val[type], sizeof(OPT_UNION)); |
| 4854 |
} |
| 4855 |
} |
| 4856 |
} |
| 4857 |
return dst; |
| 4858 |
} |
| 4859 |
|
| 4860 |
NOEXPORT void socket_options_free(SOCK_OPT *opt) { |
| 4861 |
SOCK_OPT *ptr; |
| 4862 |
if(!opt) { |
| 4863 |
s_log(LOG_ERR, "INTERNAL ERROR: Socket options not initialized"); |
| 4864 |
return; |
| 4865 |
} |
| 4866 |
for(ptr=opt; ptr->opt_str; ++ptr) { |
| 4867 |
int type; |
| 4868 |
for(type=0; type<3; ++type) |
| 4869 |
str_free(ptr->opt_val[type]); |
| 4870 |
} |
| 4871 |
str_free(opt); |
| 4872 |
} |
| 4873 |
|
| 4874 |
NOEXPORT int socket_options_print(void) { |
| 4875 |
SOCK_OPT *opt, *ptr; |
| 4876 |
|
| 4877 |
s_log(LOG_NOTICE, " "); |
| 4878 |
s_log(LOG_NOTICE, "Socket option defaults:"); |
| 4879 |
s_log(LOG_NOTICE, |
| 4880 |
" Option Name | Accept | Local | Remote |OS default"); |
| 4881 |
s_log(LOG_NOTICE, |
| 4882 |
" --------------------+----------+----------+----------+----------"); |
| 4883 |
|
| 4884 |
opt=socket_options_init(); |
| 4885 |
for(ptr=opt; ptr->opt_str; ++ptr) { |
| 4886 |
SOCKET fd; |
| 4887 |
socklen_t optlen; |
| 4888 |
OPT_UNION val; |
| 4889 |
char *ta, *tl, *tr, *td; |
| 4890 |
|
| 4891 |
/* get OS default value */ |
| 4892 |
#if defined(AF_INET6) && defined(IPPROTO_IPV6) |
| 4893 |
if(ptr->opt_level==IPPROTO_IPV6) |
| 4894 |
fd=socket(AF_INET6, SOCK_STREAM, 0); |
| 4895 |
else |
| 4896 |
#endif |
| 4897 |
fd=socket(AF_INET, SOCK_STREAM, 0); |
| 4898 |
optlen=sizeof val; |
| 4899 |
if(getsockopt(fd, ptr->opt_level, |
| 4900 |
ptr->opt_name, (void *)&val, &optlen)) { |
| 4901 |
switch(get_last_socket_error()) { |
| 4902 |
case S_ENOPROTOOPT: |
| 4903 |
case S_EOPNOTSUPP: |
| 4904 |
td=str_dup("write-only"); |
| 4905 |
break; |
| 4906 |
default: |
| 4907 |
s_log(LOG_ERR, "Failed to get %s OS default", ptr->opt_str); |
| 4908 |
sockerror("getsockopt"); |
| 4909 |
closesocket(fd); |
| 4910 |
return 1; /* FAILED */ |
| 4911 |
} |
| 4912 |
} else |
| 4913 |
td=socket_option_text(ptr->opt_type, &val); |
| 4914 |
closesocket(fd); |
| 4915 |
|
| 4916 |
/* get stunnel default values */ |
| 4917 |
ta=socket_option_text(ptr->opt_type, ptr->opt_val[0]); |
| 4918 |
tl=socket_option_text(ptr->opt_type, ptr->opt_val[1]); |
| 4919 |
tr=socket_option_text(ptr->opt_type, ptr->opt_val[2]); |
| 4920 |
|
| 4921 |
/* print collected data and free the allocated memory */ |
| 4922 |
s_log(LOG_NOTICE, " %-20s|%10s|%10s|%10s|%10s", |
| 4923 |
ptr->opt_str, ta, tl, tr, td); |
| 4924 |
str_free(ta); str_free(tl); str_free(tr); str_free(td); |
| 4925 |
} |
| 4926 |
socket_options_free(opt); |
| 4927 |
return 0; /* OK */ |
| 4928 |
} |
| 4929 |
|
| 4930 |
NOEXPORT char *socket_option_text(VAL_TYPE type, OPT_UNION *val) { |
| 4931 |
if(!val) |
| 4932 |
return str_dup(" -- "); |
| 4933 |
switch(type) { |
| 4934 |
case TYPE_FLAG: |
| 4935 |
return str_printf("%s", val->i_val ? "yes" : "no"); |
| 4936 |
case TYPE_INT: |
| 4937 |
return str_printf("%d", val->i_val); |
| 4938 |
case TYPE_LINGER: |
| 4939 |
return str_printf("%d:%d", |
| 4940 |
val->linger_val.l_onoff, val->linger_val.l_linger); |
| 4941 |
case TYPE_TIMEVAL: |
| 4942 |
return str_printf("%d:%d", |
| 4943 |
(int)val->timeval_val.tv_sec, (int)val->timeval_val.tv_usec); |
| 4944 |
case TYPE_STRING: |
| 4945 |
return str_printf("%s", val->c_val); |
| 4946 |
case TYPE_NONE: |
| 4947 |
return str_dup(" none "); /* internal error? */ |
| 4948 |
} |
| 4949 |
return str_dup(" Ooops? "); /* internal error? */ |
| 4950 |
} |
| 4951 |
|
| 4952 |
NOEXPORT int socket_option_parse(SOCK_OPT *opt, char *arg) { |
| 4953 |
int socket_type; /* 0-accept, 1-local, 2-remote */ |
| 4954 |
char *opt_val_str, *opt_val2_str, *tmp_str; |
| 4955 |
OPT_UNION opt_val; |
| 4956 |
|
| 4957 |
if(arg[1]!=':') |
| 4958 |
return 1; /* FAILED */ |
| 4959 |
switch(arg[0]) { |
| 4960 |
case 'a': |
| 4961 |
socket_type=0; break; |
| 4962 |
case 'l': |
| 4963 |
socket_type=1; break; |
| 4964 |
case 'r': |
| 4965 |
socket_type=2; break; |
| 4966 |
default: |
| 4967 |
return 1; /* FAILED */ |
| 4968 |
} |
| 4969 |
arg+=2; |
| 4970 |
opt_val_str=strchr(arg, '='); |
| 4971 |
if(!opt_val_str) /* no '='? */ |
| 4972 |
return 1; /* FAILED */ |
| 4973 |
*opt_val_str++='\0'; |
| 4974 |
|
| 4975 |
for(; opt->opt_str && strcmp(arg, opt->opt_str); ++opt) |
| 4976 |
; |
| 4977 |
if(!opt->opt_str) |
| 4978 |
return 1; /* FAILED */ |
| 4979 |
|
| 4980 |
switch(opt->opt_type) { |
| 4981 |
case TYPE_FLAG: |
| 4982 |
if(!strcasecmp(opt_val_str, "yes") || !strcmp(opt_val_str, "1")) { |
| 4983 |
opt_val.i_val=1; |
| 4984 |
break; /* OK */ |
| 4985 |
} |
| 4986 |
if(!strcasecmp(opt_val_str, "no") || !strcmp(opt_val_str, "0")) { |
| 4987 |
opt_val.i_val=0; |
| 4988 |
break; /* OK */ |
| 4989 |
} |
| 4990 |
return 1; /* FAILED */ |
| 4991 |
case TYPE_INT: |
| 4992 |
opt_val.i_val=(int)strtol(opt_val_str, &tmp_str, 10); |
| 4993 |
if(tmp_str==arg || *tmp_str) /* not a number */ |
| 4994 |
return 1; /* FAILED */ |
| 4995 |
break; /* OK */ |
| 4996 |
case TYPE_LINGER: |
| 4997 |
opt_val2_str=strchr(opt_val_str, ':'); |
| 4998 |
if(opt_val2_str) { |
| 4999 |
*opt_val2_str++='\0'; |
| 5000 |
opt_val.linger_val.l_linger= |
| 5001 |
(u_short)strtol(opt_val2_str, &tmp_str, 10); |
| 5002 |
if(tmp_str==arg || *tmp_str) /* not a number */ |
| 5003 |
return 1; /* FAILED */ |
| 5004 |
} else { |
| 5005 |
opt_val.linger_val.l_linger=0; |
| 5006 |
} |
| 5007 |
opt_val.linger_val.l_onoff= |
| 5008 |
(u_short)strtol(opt_val_str, &tmp_str, 10); |
| 5009 |
if(tmp_str==arg || *tmp_str) /* not a number */ |
| 5010 |
return 1; /* FAILED */ |
| 5011 |
break; /* OK */ |
| 5012 |
case TYPE_TIMEVAL: |
| 5013 |
opt_val2_str=strchr(opt_val_str, ':'); |
| 5014 |
if(opt_val2_str) { |
| 5015 |
*opt_val2_str++='\0'; |
| 5016 |
opt_val.timeval_val.tv_usec= |
| 5017 |
(int)strtol(opt_val2_str, &tmp_str, 10); |
| 5018 |
if(tmp_str==arg || *tmp_str) /* not a number */ |
| 5019 |
return 1; /* FAILED */ |
| 5020 |
} else { |
| 5021 |
opt_val.timeval_val.tv_usec=0; |
| 5022 |
} |
| 5023 |
opt_val.timeval_val.tv_sec= |
| 5024 |
(int)strtol(opt_val_str, &tmp_str, 10); |
| 5025 |
if(tmp_str==arg || *tmp_str) /* not a number */ |
| 5026 |
return 1; /* FAILED */ |
| 5027 |
break; /* OK */ |
| 5028 |
case TYPE_STRING: |
| 5029 |
if(strlen(opt_val_str)+1>sizeof(OPT_UNION)) |
| 5030 |
return 1; /* FAILED */ |
| 5031 |
strcpy(opt_val.c_val, opt_val_str); |
| 5032 |
break; /* OK */ |
| 5033 |
default: |
| 5034 |
return 1; /* FAILED */ |
| 5035 |
} |
| 5036 |
str_free(opt->opt_val[socket_type]); |
| 5037 |
opt->opt_val[socket_type]=str_alloc_detached(sizeof(OPT_UNION)); |
| 5038 |
memcpy(opt->opt_val[socket_type], &opt_val, sizeof(OPT_UNION)); |
| 5039 |
return 0; |
| 5040 |
} |
| 5041 |
|
| 5042 |
/**************************************** OCSP */ |
| 5043 |
|
| 5044 |
#ifndef OPENSSL_NO_OCSP |
| 5045 |
|
| 5046 |
NOEXPORT unsigned long parse_ocsp_flag(char *arg) { |
| 5047 |
struct { |
| 5048 |
const char *name; |
| 5049 |
unsigned long value; |
| 5050 |
} ocsp_opts[]={ |
| 5051 |
{"NOCERTS", OCSP_NOCERTS}, |
| 5052 |
{"NOINTERN", OCSP_NOINTERN}, |
| 5053 |
{"NOSIGS", OCSP_NOSIGS}, |
| 5054 |
{"NOCHAIN", OCSP_NOCHAIN}, |
| 5055 |
{"NOVERIFY", OCSP_NOVERIFY}, |
| 5056 |
{"NOEXPLICIT", OCSP_NOEXPLICIT}, |
| 5057 |
{"NOCASIGN", OCSP_NOCASIGN}, |
| 5058 |
{"NODELEGATED", OCSP_NODELEGATED}, |
| 5059 |
{"NOCHECKS", OCSP_NOCHECKS}, |
| 5060 |
{"TRUSTOTHER", OCSP_TRUSTOTHER}, |
| 5061 |
{"RESPID_KEY", OCSP_RESPID_KEY}, |
| 5062 |
{"NOTIME", OCSP_NOTIME}, |
| 5063 |
{NULL, 0} |
| 5064 |
}, *option; |
| 5065 |
|
| 5066 |
for(option=ocsp_opts; option->name; ++option) |
| 5067 |
if(!strcasecmp(option->name, arg)) |
| 5068 |
return option->value; |
| 5069 |
return 0; /* FAILED */ |
| 5070 |
} |
| 5071 |
|
| 5072 |
#endif /* !defined(OPENSSL_NO_OCSP) */ |
| 5073 |
|
| 5074 |
/**************************************** engine */ |
| 5075 |
|
| 5076 |
#ifndef OPENSSL_NO_ENGINE |
| 5077 |
|
| 5078 |
#define MAX_ENGINES 256 |
| 5079 |
static ENGINE *engines[MAX_ENGINES]; /* table of engines for config parser */ |
| 5080 |
static int current_engine; |
| 5081 |
static int engine_initialized; |
| 5082 |
|
| 5083 |
NOEXPORT void engine_reset_list(void) { |
| 5084 |
current_engine=-1; |
| 5085 |
engine_initialized=1; |
| 5086 |
} |
| 5087 |
|
| 5088 |
NOEXPORT const char *engine_auto(void) { |
| 5089 |
ENGINE *e; |
| 5090 |
|
| 5091 |
s_log(LOG_INFO, "Enabling automatic engine support"); |
| 5092 |
ENGINE_register_all_complete(); |
| 5093 |
/* rebuild the internal list of engines */ |
| 5094 |
engine_reset_list(); |
| 5095 |
for(e=ENGINE_get_first(); e; e=ENGINE_get_next(e)) { |
| 5096 |
if(++current_engine>=MAX_ENGINES) |
| 5097 |
return "Too many open engines"; |
| 5098 |
engines[current_engine]=e; |
| 5099 |
s_log(LOG_INFO, "Engine #%d (%s) registered", |
| 5100 |
current_engine+1, ENGINE_get_id(e)); |
| 5101 |
} |
| 5102 |
s_log(LOG_INFO, "Automatic engine support enabled"); |
| 5103 |
return NULL; /* OK */ |
| 5104 |
} |
| 5105 |
|
| 5106 |
NOEXPORT const char *engine_open(const char *name) { |
| 5107 |
ENGINE *e; |
| 5108 |
struct { |
| 5109 |
void (*vlog)(int, const char *, va_list); |
| 5110 |
} vlog_callback; |
| 5111 |
|
| 5112 |
engine_init(); /* initialize the previous engine (if any) */ |
| 5113 |
if(++current_engine>=MAX_ENGINES) |
| 5114 |
return "Too many open engines"; |
| 5115 |
|
| 5116 |
s_log(LOG_DEBUG, "Enabling support for engine \"%s\"", name); |
| 5117 |
e=ENGINE_by_id(name); |
| 5118 |
if(!e) { |
| 5119 |
ssl_error(NULL, "ENGINE_by_id"); |
| 5120 |
return "Failed to open the engine"; |
| 5121 |
} |
| 5122 |
engine_initialized=0; |
| 5123 |
|
| 5124 |
vlog_callback.vlog=&s_vlog; |
| 5125 |
if(ENGINE_ctrl_cmd(e, "VLOG_A", 0, &vlog_callback, NULL, 0)) { |
| 5126 |
s_log(LOG_NOTICE, "Logging initialized on engine #%d (%s)", |
| 5127 |
current_engine+1, ENGINE_get_id(e)); |
| 5128 |
} else { |
| 5129 |
ERR_clear_error(); |
| 5130 |
s_log(LOG_INFO, "Logging not supported by engine #%d (%s)", |
| 5131 |
current_engine+1, ENGINE_get_id(e)); |
| 5132 |
} |
| 5133 |
|
| 5134 |
if(ENGINE_ctrl(e, ENGINE_CTRL_SET_USER_INTERFACE, 0, ui_stunnel, NULL)) { |
| 5135 |
s_log(LOG_NOTICE, "UI set for engine #%d (%s)", |
| 5136 |
current_engine+1, ENGINE_get_id(e)); |
| 5137 |
} else { |
| 5138 |
ERR_clear_error(); |
| 5139 |
s_log(LOG_INFO, "UI not supported by engine #%d (%s)", |
| 5140 |
current_engine+1, ENGINE_get_id(e)); |
| 5141 |
} |
| 5142 |
|
| 5143 |
engines[current_engine]=e; |
| 5144 |
return NULL; /* OK */ |
| 5145 |
} |
| 5146 |
|
| 5147 |
NOEXPORT const char *engine_ctrl(const char *cmd, const char *arg) { |
| 5148 |
if(current_engine<0) |
| 5149 |
return "No engine was defined"; |
| 5150 |
if(!strcasecmp(cmd, "INIT")) /* special control command */ |
| 5151 |
return engine_init(); |
| 5152 |
if(arg) |
| 5153 |
s_log(LOG_DEBUG, "Executing engine control command %s:%s", cmd, arg); |
| 5154 |
else |
| 5155 |
s_log(LOG_DEBUG, "Executing engine control command %s", cmd); |
| 5156 |
if(!ENGINE_ctrl_cmd_string(engines[current_engine], cmd, arg, 0)) { |
| 5157 |
ssl_error(NULL, "ENGINE_ctrl_cmd_string"); |
| 5158 |
return "Failed to execute the engine control command"; |
| 5159 |
} |
| 5160 |
return NULL; /* OK */ |
| 5161 |
} |
| 5162 |
|
| 5163 |
NOEXPORT const char *engine_default(const char *list) { |
| 5164 |
if(current_engine<0) |
| 5165 |
return "No engine was defined"; |
| 5166 |
if(!ENGINE_set_default_string(engines[current_engine], list)) { |
| 5167 |
ssl_error(NULL, "ENGINE_set_default_string"); |
| 5168 |
return "Failed to set engine as default"; |
| 5169 |
} |
| 5170 |
s_log(LOG_INFO, "Engine #%d (%s) set as default for %s", |
| 5171 |
current_engine+1, ENGINE_get_id(engines[current_engine]), list); |
| 5172 |
return NULL; |
| 5173 |
} |
| 5174 |
|
| 5175 |
NOEXPORT const char *engine_init(void) { |
| 5176 |
if(engine_initialized) /* either first or already initialized */ |
| 5177 |
return NULL; /* OK */ |
| 5178 |
s_log(LOG_DEBUG, "Initializing engine #%d (%s)", |
| 5179 |
current_engine+1, ENGINE_get_id(engines[current_engine])); |
| 5180 |
if(!ENGINE_init(engines[current_engine])) { |
| 5181 |
if(ERR_peek_last_error()) /* really an error */ |
| 5182 |
ssl_error(NULL, "ENGINE_init"); |
| 5183 |
else |
| 5184 |
s_log(LOG_ERR, "Engine #%d (%s) not initialized", |
| 5185 |
current_engine+1, ENGINE_get_id(engines[current_engine])); |
| 5186 |
return "Engine initialization failed"; |
| 5187 |
} |
| 5188 |
#if 0 |
| 5189 |
/* it is a bad idea to set the engine as default for all sections */ |
| 5190 |
/* the "engine=auto" or "engineDefault" options should be used instead */ |
| 5191 |
if(!ENGINE_set_default(engines[current_engine], ENGINE_METHOD_ALL)) { |
| 5192 |
ssl_error(NULL, "ENGINE_set_default"); |
| 5193 |
return "Selecting default engine failed"; |
| 5194 |
} |
| 5195 |
#endif |
| 5196 |
|
| 5197 |
s_log(LOG_INFO, "Engine #%d (%s) initialized", |
| 5198 |
current_engine+1, ENGINE_get_id(engines[current_engine])); |
| 5199 |
engine_initialized=1; |
| 5200 |
return NULL; /* OK */ |
| 5201 |
} |
| 5202 |
|
| 5203 |
NOEXPORT ENGINE *engine_get_by_id(const char *id) { |
| 5204 |
int i; |
| 5205 |
|
| 5206 |
for(i=0; i<=current_engine; ++i) |
| 5207 |
if(!strcmp(id, ENGINE_get_id(engines[i]))) |
| 5208 |
return engines[i]; |
| 5209 |
return NULL; |
| 5210 |
} |
| 5211 |
|
| 5212 |
NOEXPORT ENGINE *engine_get_by_num(const int i) { |
| 5213 |
if(i<0 || i>current_engine) |
| 5214 |
return NULL; |
| 5215 |
return engines[i]; |
| 5216 |
} |
| 5217 |
|
| 5218 |
#endif /* !defined(OPENSSL_NO_ENGINE) */ |
| 5219 |
|
| 5220 |
/**************************************** provider */ |
| 5221 |
|
| 5222 |
#if OPENSSL_VERSION_NUMBER>=0x30500000L |
| 5223 |
|
| 5224 |
NOEXPORT int provider_parameter(OSSL_PROVIDER *provider, void *cbdata) { |
| 5225 |
char *prov=str_dup(cbdata), *name, *value; |
| 5226 |
int retval=0; |
| 5227 |
|
| 5228 |
name=strchr(prov, ':'); |
| 5229 |
if(!name) |
| 5230 |
goto cleanup; |
| 5231 |
*name++='\0'; |
| 5232 |
value=strchr(name, '='); |
| 5233 |
if(!value) |
| 5234 |
goto cleanup; |
| 5235 |
*value++='\0'; |
| 5236 |
|
| 5237 |
if(!strcmp(OSSL_PROVIDER_get0_name(provider), prov)) |
| 5238 |
if(OSSL_PROVIDER_add_conf_parameter(provider, name, value)) |
| 5239 |
provider_found=1; |
| 5240 |
retval=1; |
| 5241 |
|
| 5242 |
cleanup: |
| 5243 |
str_free(prov); |
| 5244 |
return retval; |
| 5245 |
} |
| 5246 |
|
| 5247 |
#endif /* OPENSSL_VERSION_NUMBER>=0x30500000L */ |
| 5248 |
|
| 5249 |
/**************************************** include config directory */ |
| 5250 |
|
| 5251 |
NOEXPORT const char *include_config(char *directory, SERVICE_OPTIONS **section_ptr) { |
| 5252 |
struct dirent **namelist; |
| 5253 |
int i, num, err=0; |
| 5254 |
|
| 5255 |
num=scandir(directory, &namelist, NULL, alphasort); |
| 5256 |
if(num<0) { |
| 5257 |
ioerror("scandir"); |
| 5258 |
return "Failed to include directory"; |
| 5259 |
} |
| 5260 |
for(i=0; i<num; ++i) { |
| 5261 |
if(!err) { |
| 5262 |
struct stat sb; |
| 5263 |
char *name=str_printf( |
| 5264 |
#ifdef USE_WIN32 |
| 5265 |
"%s\\%s", |
| 5266 |
#else |
| 5267 |
"%s/%s", |
| 5268 |
#endif |
| 5269 |
directory, namelist[i]->d_name); |
| 5270 |
if(!stat(name, &sb) && S_ISREG(sb.st_mode)) |
| 5271 |
err=options_file(name, CONF_FILE, section_ptr); |
| 5272 |
else |
| 5273 |
s_log(LOG_DEBUG, "\"%s\" is not a file", name); |
| 5274 |
str_free(name); |
| 5275 |
} |
| 5276 |
free(namelist[i]); |
| 5277 |
} |
| 5278 |
free(namelist); |
| 5279 |
if(err) |
| 5280 |
return "Failed to include a file"; |
| 5281 |
return NULL; |
| 5282 |
} |
| 5283 |
|
| 5284 |
/**************************************** fatal error */ |
| 5285 |
|
| 5286 |
NOEXPORT void print_syntax(void) { |
| 5287 |
s_log(LOG_NOTICE, " "); |
| 5288 |
s_log(LOG_NOTICE, "Syntax:"); |
| 5289 |
s_log(LOG_NOTICE, "stunnel " |
| 5290 |
#ifdef USE_WIN32 |
| 5291 |
#ifndef _WIN32_WCE |
| 5292 |
"[ [-install | -uninstall | -start | -stop | -reload | -reopen | -exit] " |
| 5293 |
#endif |
| 5294 |
"[-quiet] " |
| 5295 |
#endif |
| 5296 |
"[<filename>] ] " |
| 5297 |
#ifndef USE_WIN32 |
| 5298 |
"-fd <n> " |
| 5299 |
#endif |
| 5300 |
"| -help | -version | -sockets | -options"); |
| 5301 |
s_log(LOG_NOTICE, " <filename> - use specified config file"); |
| 5302 |
#ifdef USE_WIN32 |
| 5303 |
#ifndef _WIN32_WCE |
| 5304 |
s_log(LOG_NOTICE, " -install - install NT service"); |
| 5305 |
s_log(LOG_NOTICE, " -uninstall - uninstall NT service"); |
| 5306 |
s_log(LOG_NOTICE, " -start - start NT service"); |
| 5307 |
s_log(LOG_NOTICE, " -stop - stop NT service"); |
| 5308 |
s_log(LOG_NOTICE, " -reload - reload configuration for NT service"); |
| 5309 |
s_log(LOG_NOTICE, " -reopen - reopen log file for NT service"); |
| 5310 |
s_log(LOG_NOTICE, " -exit - exit an already started stunnel"); |
| 5311 |
#endif |
| 5312 |
s_log(LOG_NOTICE, " -quiet - don't display message boxes"); |
| 5313 |
#else |
| 5314 |
s_log(LOG_NOTICE, " -fd <n> - read the config file from a file descriptor"); |
| 5315 |
#endif |
| 5316 |
s_log(LOG_NOTICE, " -help - get config file help"); |
| 5317 |
s_log(LOG_NOTICE, " -version - display version and defaults"); |
| 5318 |
s_log(LOG_NOTICE, " -sockets - display default socket options"); |
| 5319 |
s_log(LOG_NOTICE, " -options - display supported TLS options"); |
| 5320 |
} |
| 5321 |
|
| 5322 |
/**************************************** various supporting functions */ |
| 5323 |
|
| 5324 |
NOEXPORT void name_list_append(NAME_LIST **ptr, char *name) { |
| 5325 |
while(*ptr) /* find the null pointer */ |
| 5326 |
ptr=&(*ptr)->next; |
| 5327 |
*ptr=str_alloc_detached(sizeof(NAME_LIST)); |
| 5328 |
(*ptr)->name=str_dup_detached(name); |
| 5329 |
(*ptr)->next=NULL; |
| 5330 |
} |
| 5331 |
|
| 5332 |
NOEXPORT void name_list_dup(NAME_LIST **dst, NAME_LIST *src) { |
| 5333 |
*dst=NULL; |
| 5334 |
for(; src; src=src->next) |
| 5335 |
name_list_append(dst, src->name); |
| 5336 |
} |
| 5337 |
|
| 5338 |
NOEXPORT void name_list_free(NAME_LIST **dst) { |
| 5339 |
NAME_LIST *ptr; |
| 5340 |
|
| 5341 |
ptr=*dst; |
| 5342 |
*dst=NULL; /* detach */ |
| 5343 |
while(ptr) { |
| 5344 |
NAME_LIST *next=ptr->next; |
| 5345 |
str_free(ptr->name); |
| 5346 |
str_free(ptr); |
| 5347 |
ptr=next; |
| 5348 |
} |
| 5349 |
} |
| 5350 |
|
| 5351 |
NOEXPORT void connect_session_free(SERVICE_OPTIONS *section) { |
| 5352 |
unsigned i; |
| 5353 |
|
| 5354 |
if(!section->connect_session) |
| 5355 |
return; |
| 5356 |
for(i=0; i<section->connect_addr.num; i++) |
| 5357 |
if(section->connect_session[i]) |
| 5358 |
SSL_SESSION_free(section->connect_session[i]); |
| 5359 |
str_free(section->connect_session); |
| 5360 |
section->connect_session=NULL; |
| 5361 |
} |
| 5362 |
|
| 5363 |
#ifndef USE_WIN32 |
| 5364 |
|
| 5365 |
/* allocate 'exec' arguments */ |
| 5366 |
/* TODO: support quotes */ |
| 5367 |
NOEXPORT char **arg_alloc(char *str) { |
| 5368 |
size_t max_arg, i; |
| 5369 |
char **tmp, **retval; |
| 5370 |
|
| 5371 |
max_arg=strlen(str)/2+1; |
| 5372 |
tmp=str_alloc((max_arg+1)*sizeof(char *)); |
| 5373 |
|
| 5374 |
i=0; |
| 5375 |
while(*str && i<max_arg) { |
| 5376 |
tmp[i++]=str; |
| 5377 |
while(*str && !isspace((unsigned char)*str)) |
| 5378 |
++str; |
| 5379 |
while(*str && isspace((unsigned char)*str)) |
| 5380 |
*str++='\0'; |
| 5381 |
} |
| 5382 |
tmp[i]=NULL; /* null-terminate the table */ |
| 5383 |
|
| 5384 |
retval=arg_dup(tmp); |
| 5385 |
str_free(tmp); |
| 5386 |
return retval; |
| 5387 |
} |
| 5388 |
|
| 5389 |
NOEXPORT char **arg_dup(char **src) { |
| 5390 |
size_t i, n; |
| 5391 |
char **dst; |
| 5392 |
|
| 5393 |
if(!src) |
| 5394 |
return NULL; |
| 5395 |
for(n=0; src[n]; ++n) |
| 5396 |
; |
| 5397 |
dst=str_alloc_detached((n+1)*sizeof(char *)); |
| 5398 |
for(i=0; i<n; ++i) |
| 5399 |
dst[i]=str_dup_detached(src[i]); |
| 5400 |
dst[n]=NULL; |
| 5401 |
return dst; |
| 5402 |
} |
| 5403 |
|
| 5404 |
NOEXPORT void arg_free(char **arg) { |
| 5405 |
size_t i; |
| 5406 |
|
| 5407 |
if(arg) { |
| 5408 |
for(i=0; arg[i]; ++i) |
| 5409 |
str_free(arg[i]); |
| 5410 |
str_free(arg); |
| 5411 |
} |
| 5412 |
} |
| 5413 |
|
| 5414 |
#endif |
| 5415 |
|
| 5416 |
/* end of options.c */ |