Annotation of embedaddon/strongswan/src/swanctl/swanctl.c, revision 1.1.1.1

1.1       misho       1: /*
                      2:  * Copyright (C) 2018 Tobias Brunner
                      3:  * HSR Hochschule fuer Technik Rapperswil
                      4:  *
                      5:  * Copyright (C) 2014 Martin Willi
                      6:  * Copyright (C) 2014 revosec AG
                      7:  *
                      8:  * This program is free software; you can redistribute it and/or modify it
                      9:  * under the terms of the GNU General Public License as published by the
                     10:  * Free Software Foundation; either version 2 of the License, or (at your
                     11:  * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
                     12:  *
                     13:  * This program is distributed in the hope that it will be useful, but
                     14:  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
                     15:  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
                     16:  * for more details.
                     17:  */
                     18: 
                     19: #include "swanctl.h"
                     20: #include "command.h"
                     21: 
                     22: #include <unistd.h>
                     23: 
                     24: #include <library.h>
                     25: 
                     26: /*
                     27:  * Described in header
                     28:  */
                     29: char *swanctl_dir;
                     30: 
                     31: /*
                     32:  * Described in header
                     33:  */
                     34: settings_t *load_swanctl_conf(char *file)
                     35: {
                     36:        settings_t *cfg;
                     37:        char buf[PATH_MAX];
                     38: 
                     39:        if (!file)
                     40:        {
                     41:                if (!strlen(swanctl_dir))
                     42:                {
                     43:                        free(swanctl_dir);
                     44:                        swanctl_dir = strdup(getcwd(buf, sizeof(buf)));
                     45:                }
                     46:                file = buf;
                     47:                snprintf(buf, sizeof(buf), "%s%s%s", swanctl_dir,
                     48:                                 DIRECTORY_SEPARATOR, SWANCTL_CONF);
                     49:        }
                     50: 
                     51:        cfg = settings_create(file);
                     52:        if (!cfg)
                     53:        {
                     54:                fprintf(stderr, "parsing '%s' failed\n", file);
                     55:                return NULL;
                     56:        }
                     57:        free(swanctl_dir);
                     58:        swanctl_dir = path_dirname(file);
                     59:        return cfg;
                     60: }
                     61: 
                     62: /**
                     63:  * Cleanup library atexit()
                     64:  */
                     65: static void cleanup()
                     66: {
                     67:        free(swanctl_dir);
                     68:        lib->processor->cancel(lib->processor);
                     69:        library_deinit();
                     70: }
                     71: 
                     72: /**
                     73:  * Library initialization and operation parsing
                     74:  */
                     75: int main(int argc, char *argv[])
                     76: {
                     77:        atexit(cleanup);
                     78:        if (!library_init(NULL, "swanctl"))
                     79:        {
                     80:                exit(SS_RC_LIBSTRONGSWAN_INTEGRITY);
                     81:        }
                     82:        if (lib->integrity &&
                     83:                !lib->integrity->check_file(lib->integrity, "swanctl", argv[0]))
                     84:        {
                     85:                fprintf(stderr, "integrity check of swanctl failed\n");
                     86:                exit(SS_RC_DAEMON_INTEGRITY);
                     87:        }
                     88:        if (!lib->plugins->load(lib->plugins,
                     89:                        lib->settings->get_str(lib->settings, "swanctl.load", PLUGINS)))
                     90:        {
                     91:                exit(SS_RC_INITIALIZATION_FAILED);
                     92:        }
                     93: 
                     94:        swanctl_dir = strdup(getenv("SWANCTL_DIR") ?: SWANCTLDIR);
                     95: 
                     96:        dbg_default_set_level(0);
                     97:        lib->processor->set_threads(lib->processor, 4);
                     98:        dbg_default_set_level(1);
                     99: 
                    100:        return command_dispatch(argc, argv);
                    101: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>