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

1.1       misho       1: /*
                      2:  * Copyright (C) 2014 Martin Willi
                      3:  * Copyright (C) 2014 revosec AG
                      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.  See <http://www.fsf.org/copyleft/gpl.txt>.
                      9:  *
                     10:  * This program is distributed in the hope that it will be useful, but
                     11:  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
                     12:  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
                     13:  * for more details.
                     14:  */
                     15: 
                     16: #define _GNU_SOURCE
                     17: #include <stdio.h>
                     18: #include <errno.h>
                     19: #include <unistd.h>
                     20: #include <sys/stat.h>
                     21: 
                     22: #include "command.h"
                     23: #include "swanctl.h"
                     24: #include "load_creds.h"
                     25: #include "load_authorities.h"
                     26: #include "load_pools.h"
                     27: #include "load_conns.h"
                     28: 
                     29: static int load_all(vici_conn_t *conn)
                     30: {
                     31:        bool clear = FALSE, noprompt = FALSE;
                     32:        command_format_options_t format = COMMAND_FORMAT_NONE;
                     33:        settings_t *cfg;
                     34:        char *arg, *file = NULL;
                     35:        int ret = 0;
                     36: 
                     37:        while (TRUE)
                     38:        {
                     39:                switch (command_getopt(&arg))
                     40:                {
                     41:                        case 'h':
                     42:                                return command_usage(NULL);
                     43:                        case 'c':
                     44:                                clear = TRUE;
                     45:                                continue;
                     46:                        case 'n':
                     47:                                noprompt = TRUE;
                     48:                                continue;
                     49:                        case 'P':
                     50:                                format |= COMMAND_FORMAT_PRETTY;
                     51:                                /* fall through to raw */
                     52:                        case 'r':
                     53:                                format |= COMMAND_FORMAT_RAW;
                     54:                                continue;
                     55:                        case 'f':
                     56:                                file = arg;
                     57:                                continue;
                     58:                        case EOF:
                     59:                                break;
                     60:                        default:
                     61:                                return command_usage("invalid --load-all option");
                     62:                }
                     63:                break;
                     64:        }
                     65: 
                     66:        cfg = load_swanctl_conf(file);
                     67:        if (!cfg)
                     68:        {
                     69:                return EINVAL;
                     70:        }
                     71: 
                     72:        if (ret == 0)
                     73:        {
                     74:                ret = load_creds_cfg(conn, format, cfg, clear, noprompt);
                     75:        }
                     76:        if (ret == 0)
                     77:        {
                     78:                ret = load_authorities_cfg(conn, format, cfg);
                     79:        }
                     80:        if (ret == 0)
                     81:        {
                     82:                ret = load_pools_cfg(conn, format, cfg);
                     83:        }
                     84:        if (ret == 0)
                     85:        {
                     86:                ret = load_conns_cfg(conn, format, cfg);
                     87:        }
                     88: 
                     89:        cfg->destroy(cfg);
                     90: 
                     91:        return ret;
                     92: }
                     93: 
                     94: /**
                     95:  * Register the command.
                     96:  */
                     97: static void __attribute__ ((constructor))reg()
                     98: {
                     99:        command_register((command_t) {
                    100:                load_all, 'q', "load-all",
                    101:                "load credentials, authorities, pools and connections",
                    102:                {"[--raw|--pretty] [--clear] [--noprompt]"},
                    103:                {
                    104:                        {"help",                'h', 0, "show usage information"},
                    105:                        {"clear",               'c', 0, "clear previously loaded credentials"},
                    106:                        {"noprompt",    'n', 0, "do not prompt for passwords"},
                    107:                        {"raw",                 'r', 0, "dump raw response message"},
                    108:                        {"pretty",              'P', 0, "dump raw response message in pretty print"},
                    109:                        {"file",                'f', 1, "custom path to swanctl.conf"},
                    110:                }
                    111:        });
                    112: }

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