e8a60449aa8412ced9ff62ce39c49979dc8aee13
[tinc] / src / tincd.c
1 /*
2     tincd.c -- the main file for tincd
3     Copyright (C) 1998-2005 Ivo Timmermans
4                   2000-2018 Guus Sliepen <guus@tinc-vpn.org>
5                   2008      Max Rijevski <maksuf@gmail.com>
6                   2009      Michael Tokarev <mjt@tls.msk.ru>
7                   2010      Julien Muchembled <jm@jmuchemb.eu>
8                   2010      Timothy Redaelli <timothy@redaelli.eu>
9
10     This program is free software; you can redistribute it and/or modify
11     it under the terms of the GNU General Public License as published by
12     the Free Software Foundation; either version 2 of the License, or
13     (at your option) any later version.
14
15     This program is distributed in the hope that it will be useful,
16     but WITHOUT ANY WARRANTY; without even the implied warranty of
17     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18     GNU General Public License for more details.
19
20     You should have received a copy of the GNU General Public License along
21     with this program; if not, write to the Free Software Foundation, Inc.,
22     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 */
24
25 #include "system.h"
26
27 /* Darwin (MacOS/X) needs the following definition... */
28 #ifndef _P1003_1B_VISIBLE
29 #define _P1003_1B_VISIBLE
30 #endif
31
32 #ifdef HAVE_SYS_MMAN_H
33 #include <sys/mman.h>
34 #endif
35
36 #include <openssl/rand.h>
37 #include <openssl/rsa.h>
38 #include <openssl/pem.h>
39 #include <openssl/evp.h>
40 #ifndef OPENSSL_NO_ENGINE
41 #include <openssl/engine.h>
42 #endif
43 #include <openssl/bn.h>
44
45 #ifdef HAVE_LZO
46 #include LZO1X_H
47 #endif
48
49 #ifndef HAVE_MINGW
50 #include <pwd.h>
51 #include <grp.h>
52 #include <time.h>
53 #endif
54
55 #ifdef HAVE_GETOPT_LONG
56 #include <getopt.h>
57 #else
58 #include "getopt.h"
59 #endif
60
61 #include "pidfile.h"
62
63 #include "conf.h"
64 #include "device.h"
65 #include "logger.h"
66 #include "net.h"
67 #include "netutl.h"
68 #include "process.h"
69 #include "protocol.h"
70 #include "utils.h"
71 #include "xalloc.h"
72
73 /* The name this program was run with. */
74 char *program_name = NULL;
75
76 /* If nonzero, display usage information and exit. */
77 bool show_help = false;
78
79 /* If nonzero, print the version on standard output and exit.  */
80 bool show_version = false;
81
82 /* If nonzero, it will attempt to kill a running tincd and exit. */
83 int kill_tincd = 0;
84
85 /* If nonzero, generate public/private keypair for this host/net. */
86 int generate_keys = 0;
87
88 /* If nonzero, use null ciphers and skip all key exchanges. */
89 bool bypass_security = false;
90
91 /* If nonzero, disable swapping for this process. */
92 bool do_mlock = false;
93
94 /* If nonzero, chroot to netdir after startup. */
95 static bool do_chroot = false;
96
97 /* If !NULL, do setuid to given user after startup */
98 static const char *switchuser = NULL;
99
100 /* If nonzero, write log entries to a separate file. */
101 bool use_logfile = false;
102
103 char *identname = NULL;                         /* program name for syslog */
104 char *pidfilename = NULL;                       /* pid file location */
105 char *logfilename = NULL;                       /* log file location */
106 char **g_argv;                                  /* a copy of the cmdline arguments */
107
108 static int status = 1;
109
110 static struct option const long_options[] = {
111         {"config", required_argument, NULL, 'c'},
112         {"kill", optional_argument, NULL, 'k'},
113         {"net", required_argument, NULL, 'n'},
114         {"help", no_argument, NULL, 1},
115         {"version", no_argument, NULL, 2},
116         {"no-detach", no_argument, NULL, 'D'},
117         {"generate-keys", optional_argument, NULL, 'K'},
118         {"debug", optional_argument, NULL, 'd'},
119         {"bypass-security", no_argument, NULL, 3},
120         {"mlock", no_argument, NULL, 'L'},
121         {"chroot", no_argument, NULL, 'R'},
122         {"user", required_argument, NULL, 'U'},
123         {"logfile", optional_argument, NULL, 4},
124         {"pidfile", required_argument, NULL, 5},
125         {"option", required_argument, NULL, 'o'},
126         {NULL, 0, NULL, 0}
127 };
128
129 #ifdef HAVE_MINGW
130 static struct WSAData wsa_state;
131 CRITICAL_SECTION mutex;
132 int main2(int argc, char **argv);
133 #endif
134
135 static void usage(bool status) {
136         if(status)
137                 fprintf(stderr, "Try `%s --help\' for more information.\n",
138                         program_name);
139         else {
140                 printf("Usage: %s [option]...\n\n", program_name);
141                 printf("  -c, --config=DIR               Read configuration options from DIR.\n"
142                        "  -D, --no-detach                Don't fork and detach.\n"
143                        "  -d, --debug[=LEVEL]            Increase debug level or set it to LEVEL.\n"
144                        "  -k, --kill[=SIGNAL]            Attempt to kill a running tincd and exit.\n"
145                        "  -n, --net=NETNAME              Connect to net NETNAME.\n"
146                        "  -K, --generate-keys[=BITS]     Generate public/private RSA keypair.\n"
147                        "  -L, --mlock                    Lock tinc into main memory.\n"
148                        "      --logfile[=FILENAME]       Write log entries to a logfile.\n"
149                        "      --pidfile=FILENAME         Write PID to FILENAME.\n"
150                        "  -o, --option=[HOST.]KEY=VALUE  Set global/host configuration value.\n"
151                        "  -R, --chroot                   chroot to NET dir at startup.\n"
152                        "  -U, --user=USER                setuid to given USER at startup.\n"
153                        "      --help                     Display this help and exit.\n"
154                        "      --version                  Output version information and exit.\n\n");
155                 printf("Report bugs to tinc@tinc-vpn.org.\n");
156         }
157 }
158
159 static bool parse_options(int argc, char **argv) {
160         config_t *cfg;
161         int r;
162         int option_index = 0;
163         int lineno = 0;
164
165         cmdline_conf = list_alloc((list_action_t)free_config);
166
167         while((r = getopt_long(argc, argv, "c:DLd::k::n:o:K::RU:", long_options, &option_index)) != EOF) {
168                 switch(r) {
169                 case 0:                         /* long option */
170                         break;
171
172                 case 'c':                               /* config file */
173                         if(confbase) {
174                                 fprintf(stderr, "Only one configuration directory can be given.\n");
175                                 usage(true);
176                                 return false;
177                         }
178
179                         confbase = xstrdup(optarg);
180                         break;
181
182                 case 'D':                               /* no detach */
183                         do_detach = false;
184                         break;
185
186                 case 'L':                               /* no detach */
187 #ifndef HAVE_MLOCKALL
188                         logger(LOG_ERR, "%s not supported on this platform", "mlockall()");
189                         return false;
190 #else
191                         do_mlock = true;
192                         break;
193 #endif
194
195                 case 'd':                               /* increase debug level */
196                         if(!optarg && optind < argc && *argv[optind] != '-') {
197                                 optarg = argv[optind++];
198                         }
199
200                         if(optarg) {
201                                 debug_level = atoi(optarg);
202                         } else {
203                                 debug_level++;
204                         }
205
206                         break;
207
208                 case 'k':                               /* kill old tincds */
209 #ifndef HAVE_MINGW
210                         if(!optarg && optind < argc && *argv[optind] != '-') {
211                                 optarg = argv[optind++];
212                         }
213
214                         if(optarg) {
215                                 if(!strcasecmp(optarg, "HUP")) {
216                                         kill_tincd = SIGHUP;
217                                 } else if(!strcasecmp(optarg, "TERM")) {
218                                         kill_tincd = SIGTERM;
219                                 } else if(!strcasecmp(optarg, "KILL")) {
220                                         kill_tincd = SIGKILL;
221                                 } else if(!strcasecmp(optarg, "USR1")) {
222                                         kill_tincd = SIGUSR1;
223                                 } else if(!strcasecmp(optarg, "USR2")) {
224                                         kill_tincd = SIGUSR2;
225                                 } else if(!strcasecmp(optarg, "WINCH")) {
226                                         kill_tincd = SIGWINCH;
227                                 } else if(!strcasecmp(optarg, "INT")) {
228                                         kill_tincd = SIGINT;
229                                 } else if(!strcasecmp(optarg, "ALRM")) {
230                                         kill_tincd = SIGALRM;
231                                 } else if(!strcasecmp(optarg, "ABRT")) {
232                                         kill_tincd = SIGABRT;
233                                 } else {
234                                         kill_tincd = atoi(optarg);
235
236                                         if(!kill_tincd) {
237                                                 fprintf(stderr, "Invalid argument `%s'; SIGNAL must be a number or one of HUP, TERM, KILL, USR1, USR2, WINCH, INT or ALRM.\n",
238                                                         optarg);
239                                                 usage(true);
240                                                 return false;
241                                         }
242                                 }
243                         } else {
244                                 kill_tincd = SIGTERM;
245                         }
246
247 #else
248                         kill_tincd = 1;
249 #endif
250                         break;
251
252                 case 'n':                               /* net name given */
253
254                         /* netname "." is special: a "top-level name" */
255                         if(netname) {
256                                 fprintf(stderr, "Only one netname can be given.\n");
257                                 usage(true);
258                                 return false;
259                         }
260
261                         if(optarg && strcmp(optarg, ".")) {
262                                 netname = xstrdup(optarg);
263                         }
264
265                         break;
266
267                 case 'o':                               /* option */
268                         cfg = parse_config_line(optarg, NULL, ++lineno);
269
270                         if(!cfg) {
271                                 return false;
272                         }
273
274                         list_insert_tail(cmdline_conf, cfg);
275                         break;
276
277                 case 'K':                               /* generate public/private keypair */
278                         if(!optarg && optind < argc && *argv[optind] != '-') {
279                                 optarg = argv[optind++];
280                         }
281
282                         if(optarg) {
283                                 generate_keys = atoi(optarg);
284
285                                 if(generate_keys < 512) {
286                                         fprintf(stderr, "Invalid argument `%s'; BITS must be a number equal to or greater than 512.\n",
287                                                 optarg);
288                                         usage(true);
289                                         return false;
290                                 }
291
292                                 generate_keys &= ~7;    /* Round it to bytes */
293                         } else {
294                                 generate_keys = 2048;
295                         }
296
297                         break;
298
299                 case 'R':                               /* chroot to NETNAME dir */
300                         do_chroot = true;
301                         break;
302
303                 case 'U':                               /* setuid to USER */
304                         switchuser = optarg;
305                         break;
306
307                 case 1:                                 /* show help */
308                         show_help = true;
309                         break;
310
311                 case 2:                                 /* show version */
312                         show_version = true;
313                         break;
314
315                 case 3:                                 /* bypass security */
316                         bypass_security = true;
317                         break;
318
319                 case 4:                                 /* write log entries to a file */
320                         use_logfile = true;
321
322                         if(!optarg && optind < argc && *argv[optind] != '-') {
323                                 optarg = argv[optind++];
324                         }
325
326                         if(optarg) {
327                                 if(logfilename) {
328                                         fprintf(stderr, "Only one logfile can be given.\n");
329                                         usage(true);
330                                         return false;
331                                 }
332
333                                 logfilename = xstrdup(optarg);
334                         }
335
336                         break;
337
338                 case 5:                                 /* write PID to a file */
339                         if(pidfilename) {
340                                 fprintf(stderr, "Only one pidfile can be given.\n");
341                                 usage(true);
342                                 return false;
343                         }
344
345                         pidfilename = xstrdup(optarg);
346                         break;
347
348                 case '?':
349                         usage(true);
350                         return false;
351
352                 default:
353                         break;
354                 }
355         }
356
357         if(optind < argc) {
358                 fprintf(stderr, "%s: unrecognized argument '%s'\n", argv[0], argv[optind]);
359                 usage(true);
360                 return false;
361         }
362
363         return true;
364 }
365
366 /* This function prettyprints the key generation process */
367
368 static int indicator(int a, int b, BN_GENCB *cb) {
369         (void)cb;
370
371         switch(a) {
372         case 0:
373                 fprintf(stderr, ".");
374                 break;
375
376         case 1:
377                 fprintf(stderr, "+");
378                 break;
379
380         case 2:
381                 fprintf(stderr, "-");
382                 break;
383
384         case 3:
385                 switch(b) {
386                 case 0:
387                         fprintf(stderr, " p\n");
388                         break;
389
390                 case 1:
391                         fprintf(stderr, " q\n");
392                         break;
393
394                 default:
395                         fprintf(stderr, "?");
396                 }
397
398                 break;
399
400         default:
401                 fprintf(stderr, "?");
402         }
403
404         return 1;
405 }
406
407 #ifndef HAVE_BN_GENCB_NEW
408 BN_GENCB *BN_GENCB_new(void) {
409         return xmalloc_and_zero(sizeof(BN_GENCB));
410 }
411
412 void BN_GENCB_free(BN_GENCB *cb) {
413         free(cb);
414 }
415 #endif
416
417 /*
418   Generate a public/private RSA keypair, and ask for a file to store
419   them in.
420 */
421 static bool keygen(int bits) {
422         BIGNUM *e = NULL;
423         RSA *rsa_key;
424         FILE *f;
425         char filename[PATH_MAX];
426         BN_GENCB *cb;
427         int result;
428
429         fprintf(stderr, "Generating %d bits keys:\n", bits);
430
431         cb = BN_GENCB_new();
432
433         if(!cb) {
434                 abort();
435         }
436
437         BN_GENCB_set(cb, indicator, NULL);
438
439         rsa_key = RSA_new();
440
441         if(BN_hex2bn(&e, "10001") == 0) {
442                 abort();
443         }
444
445         if(!rsa_key || !e) {
446                 abort();
447         }
448
449         result = RSA_generate_key_ex(rsa_key, bits, e, cb);
450
451         BN_free(e);
452         BN_GENCB_free(cb);
453
454         if(!result) {
455                 fprintf(stderr, "Error during key generation!\n");
456                 RSA_free(rsa_key);
457                 return false;
458         } else {
459                 fprintf(stderr, "Done.\n");
460         }
461
462         snprintf(filename, sizeof(filename), "%s/rsa_key.priv", confbase);
463         f = ask_and_open(filename, "private RSA key");
464
465         if(!f) {
466                 RSA_free(rsa_key);
467                 return false;
468         }
469
470 #ifdef HAVE_FCHMOD
471         /* Make it unreadable for others. */
472         fchmod(fileno(f), 0600);
473 #endif
474
475         fputc('\n', f);
476         PEM_write_RSAPrivateKey(f, rsa_key, NULL, NULL, 0, NULL, NULL);
477         fclose(f);
478
479         char *name = get_name();
480
481         if(name) {
482                 snprintf(filename, sizeof(filename), "%s/hosts/%s", confbase, name);
483                 free(name);
484         } else {
485                 snprintf(filename, sizeof(filename), "%s/rsa_key.pub", confbase);
486         }
487
488         f = ask_and_open(filename, "public RSA key");
489
490         if(!f) {
491                 RSA_free(rsa_key);
492                 return false;
493         }
494
495         fputc('\n', f);
496         PEM_write_RSAPublicKey(f, rsa_key);
497         fclose(f);
498
499         RSA_free(rsa_key);
500
501         return true;
502 }
503
504 /*
505   Set all files and paths according to netname
506 */
507 static void make_names(void) {
508 #ifdef HAVE_MINGW
509         HKEY key;
510         char installdir[1024] = "";
511         DWORD len = sizeof(installdir);
512 #endif
513
514         if(netname) {
515                 xasprintf(&identname, "tinc.%s", netname);
516         } else {
517                 identname = xstrdup("tinc");
518         }
519
520 #ifdef HAVE_MINGW
521
522         if(!RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\tinc", 0, KEY_READ, &key)) {
523                 if(!RegQueryValueEx(key, NULL, 0, 0, (LPBYTE)installdir, &len)) {
524                         if(!confbase) {
525                                 if(netname) {
526                                         xasprintf(&confbase, "%s/%s", installdir, netname);
527                                 } else {
528                                         xasprintf(&confbase, "%s", installdir);
529                                 }
530                         }
531
532                         if(!logfilename) {
533                                 xasprintf(&logfilename, "%s/tinc.log", confbase);
534                         }
535                 }
536
537                 RegCloseKey(key);
538
539                 if(*installdir) {
540                         return;
541                 }
542         }
543
544 #endif
545
546         if(!pidfilename) {
547                 xasprintf(&pidfilename, RUNSTATEDIR "/%s.pid", identname);
548         }
549
550         if(!logfilename) {
551                 xasprintf(&logfilename, LOCALSTATEDIR "/log/%s.log", identname);
552         }
553
554         if(netname) {
555                 if(!confbase) {
556                         xasprintf(&confbase, CONFDIR "/tinc/%s", netname);
557                 } else {
558                         logger(LOG_INFO, "Both netname and configuration directory given, using the latter...");
559                 }
560         } else {
561                 if(!confbase) {
562                         xasprintf(&confbase, CONFDIR "/tinc");
563                 }
564         }
565 }
566
567 static void free_names() {
568         free(identname);
569         free(netname);
570         free(pidfilename);
571         free(logfilename);
572         free(confbase);
573 }
574
575 static bool drop_privs() {
576 #ifdef HAVE_MINGW
577
578         if(switchuser) {
579                 logger(LOG_ERR, "%s not supported on this platform", "-U");
580                 return false;
581         }
582
583         if(do_chroot) {
584                 logger(LOG_ERR, "%s not supported on this platform", "-R");
585                 return false;
586         }
587
588 #else
589         uid_t uid = 0;
590
591         if(switchuser) {
592                 struct passwd *pw = getpwnam(switchuser);
593
594                 if(!pw) {
595                         logger(LOG_ERR, "unknown user `%s'", switchuser);
596                         return false;
597                 }
598
599                 uid = pw->pw_uid;
600
601                 if(initgroups(switchuser, pw->pw_gid) != 0 ||
602                                 setgid(pw->pw_gid) != 0) {
603                         logger(LOG_ERR, "System call `%s' failed: %s",
604                                "initgroups", strerror(errno));
605                         return false;
606                 }
607
608 #ifndef ANDROID
609 // Not supported in android NDK
610                 endgrent();
611                 endpwent();
612 #endif
613         }
614
615         if(do_chroot) {
616                 tzset();        /* for proper timestamps in logs */
617
618                 if(chroot(confbase) != 0 || chdir("/") != 0) {
619                         logger(LOG_ERR, "System call `%s' failed: %s",
620                                "chroot", strerror(errno));
621                         return false;
622                 }
623
624                 free(confbase);
625                 confbase = xstrdup("");
626         }
627
628         if(switchuser)
629                 if(setuid(uid) != 0) {
630                         logger(LOG_ERR, "System call `%s' failed: %s",
631                                "setuid", strerror(errno));
632                         return false;
633                 }
634
635 #endif
636         return true;
637 }
638
639 #ifdef HAVE_MINGW
640 # define setpriority(level) !SetPriorityClass(GetCurrentProcess(), (level))
641 #else
642 # define NORMAL_PRIORITY_CLASS 0
643 # define BELOW_NORMAL_PRIORITY_CLASS 10
644 # define HIGH_PRIORITY_CLASS -10
645 # define setpriority(level) (setpriority(PRIO_PROCESS, 0, (level)))
646 #endif
647
648 int main(int argc, char **argv) {
649         program_name = argv[0];
650
651         if(!parse_options(argc, argv)) {
652                 return 1;
653         }
654
655         if(show_version) {
656                 printf("%s version %s\n", PACKAGE, VERSION);
657                 printf("Copyright (C) 1998-2018 Ivo Timmermans, Guus Sliepen and others.\n"
658                        "See the AUTHORS file for a complete list.\n\n"
659                        "tinc comes with ABSOLUTELY NO WARRANTY.  This is free software,\n"
660                        "and you are welcome to redistribute it under certain conditions;\n"
661                        "see the file COPYING for details.\n");
662
663                 return 0;
664         }
665
666         if(show_help) {
667                 usage(false);
668                 return 0;
669         }
670
671         make_names();
672
673         if(kill_tincd) {
674                 return !kill_other(kill_tincd);
675         }
676
677         openlogger("tinc", use_logfile ? LOGMODE_FILE : LOGMODE_STDERR);
678
679         g_argv = argv;
680
681         if(getenv("LISTEN_PID") && atoi(getenv("LISTEN_PID")) == getpid()) {
682                 do_detach = false;
683         }
684
685 #ifdef HAVE_UNSETENV
686         unsetenv("LISTEN_PID");
687 #endif
688
689         init_configuration(&config_tree);
690
691 #ifndef OPENSSL_NO_ENGINE
692         ENGINE_load_builtin_engines();
693         ENGINE_register_all_complete();
694 #endif
695
696 #if OPENSSL_VERSION_NUMBER < 0x10100000L
697         OpenSSL_add_all_algorithms();
698 #endif
699
700         if(generate_keys) {
701                 read_server_config();
702                 return !keygen(generate_keys);
703         }
704
705         if(!read_server_config()) {
706                 return 1;
707         }
708
709 #ifdef HAVE_LZO
710
711         if(lzo_init() != LZO_E_OK) {
712                 logger(LOG_ERR, "Error initializing LZO compressor!");
713                 return 1;
714         }
715
716 #endif
717
718 #ifdef HAVE_MINGW
719
720         if(WSAStartup(MAKEWORD(2, 2), &wsa_state)) {
721                 logger(LOG_ERR, "System call `%s' failed: %s", "WSAStartup", winerror(GetLastError()));
722                 return 1;
723         }
724
725         if(!do_detach || !init_service()) {
726                 return main2(argc, argv);
727         } else {
728                 return 1;
729         }
730 }
731
732 int main2(int argc, char **argv) {
733         InitializeCriticalSection(&mutex);
734         EnterCriticalSection(&mutex);
735 #endif
736         char *priority = NULL;
737
738         if(!detach()) {
739                 return 1;
740         }
741
742 #ifdef HAVE_MLOCKALL
743
744         /* Lock all pages into memory if requested.
745          * This has to be done after daemon()/fork() so it works for child.
746          * No need to do that in parent as it's very short-lived. */
747         if(do_mlock && mlockall(MCL_CURRENT | MCL_FUTURE) != 0) {
748                 logger(LOG_ERR, "System call `%s' failed: %s", "mlockall",
749                        strerror(errno));
750                 return 1;
751         }
752
753 #endif
754
755         /* Setup sockets and open device. */
756
757         if(!setup_network()) {
758                 goto end;
759         }
760
761         /* Initiate all outgoing connections. */
762
763         try_outgoing_connections();
764
765         /* Change process priority */
766
767         if(get_config_string(lookup_config(config_tree, "ProcessPriority"), &priority)) {
768                 if(!strcasecmp(priority, "Normal")) {
769                         if(setpriority(NORMAL_PRIORITY_CLASS) != 0) {
770                                 logger(LOG_ERR, "System call `%s' failed: %s",
771                                        "setpriority", strerror(errno));
772                                 goto end;
773                         }
774                 } else if(!strcasecmp(priority, "Low")) {
775                         if(setpriority(BELOW_NORMAL_PRIORITY_CLASS) != 0) {
776                                 logger(LOG_ERR, "System call `%s' failed: %s",
777                                        "setpriority", strerror(errno));
778                                 goto end;
779                         }
780                 } else if(!strcasecmp(priority, "High")) {
781                         if(setpriority(HIGH_PRIORITY_CLASS) != 0) {
782                                 logger(LOG_ERR, "System call `%s' failed: %s",
783                                        "setpriority", strerror(errno));
784                                 goto end;
785                         }
786                 } else {
787                         logger(LOG_ERR, "Invalid priority `%s`!", priority);
788                         goto end;
789                 }
790         }
791
792         /* drop privileges */
793         if(!drop_privs()) {
794                 goto end;
795         }
796
797         /* Start main loop. It only exits when tinc is killed. */
798
799         status = main_loop();
800
801         /* Shutdown properly. */
802
803         ifdebug(CONNECTIONS)
804         devops.dump_stats();
805
806         close_network_connections();
807
808 end:
809         logger(LOG_NOTICE, "Terminating");
810
811 #ifndef HAVE_MINGW
812         remove_pid(pidfilename);
813 #endif
814
815         free(priority);
816
817 #if OPENSSL_VERSION_NUMBER < 0x10100000L
818         EVP_cleanup();
819         ERR_free_strings();
820 #ifndef OPENSSL_NO_ENGINE
821         ENGINE_cleanup();
822 #endif
823 #endif
824
825         exit_configuration(&config_tree);
826         list_delete_list(cmdline_conf);
827         free_names();
828
829         return status;
830 }