Annotation of embedaddon/strongswan/src/swanctl/commands/flush_certs.c, revision 1.1

1.1     ! misho       1: /*
        !             2:  * Copyright (C) 2016 Andreas Steffen
        !             3:  * HSR Hochschule fuer Technik Rapperswil
        !             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: #include <errno.h>
        !            17: 
        !            18: #include "command.h"
        !            19: 
        !            20: static int flush_certs(vici_conn_t *conn)
        !            21: {
        !            22:        vici_req_t *req;
        !            23:        vici_res_t *res;
        !            24:        command_format_options_t format = COMMAND_FORMAT_NONE;
        !            25:        char *arg, *type = NULL;
        !            26:        int ret;
        !            27: 
        !            28:        while (TRUE)
        !            29:        {
        !            30:                switch (command_getopt(&arg))
        !            31:                {
        !            32:                        case 'h':
        !            33:                                return command_usage(NULL);
        !            34:                        case 't':
        !            35:                                type = arg;
        !            36:                                continue;
        !            37:                        case 'P':
        !            38:                                format |= COMMAND_FORMAT_PRETTY;
        !            39:                                /* fall through to raw */
        !            40:                        case 'r':
        !            41:                                format |= COMMAND_FORMAT_RAW;
        !            42:                                continue;
        !            43:                        case EOF:
        !            44:                                break;
        !            45:                        default:
        !            46:                                return command_usage("invalid --flush-certs option");
        !            47:                }
        !            48:                break;
        !            49:        }
        !            50:        req = vici_begin("flush-certs");
        !            51: 
        !            52:        if (type)
        !            53:        {
        !            54:                vici_add_key_valuef(req, "type", "%s", type);
        !            55:        }
        !            56:        res = vici_submit(req, conn);
        !            57: 
        !            58:        if (!res)
        !            59:        {
        !            60:                ret = errno;
        !            61:                fprintf(stderr, "flush-certs request failed: %s\n", strerror(errno));
        !            62:                return ret;
        !            63:        }
        !            64:        if (format & COMMAND_FORMAT_RAW)
        !            65:        {
        !            66:                vici_dump(res, "flush-certs reply", format & COMMAND_FORMAT_PRETTY,
        !            67:                                  stdout);
        !            68:        }
        !            69:        vici_free_res(res);
        !            70: 
        !            71:        return 0;
        !            72: }
        !            73: 
        !            74: /**
        !            75:  * Register the command.
        !            76:  */
        !            77: static void __attribute__ ((constructor))reg()
        !            78: {
        !            79:        command_register((command_t) {
        !            80:                flush_certs, 'f', "flush-certs", "flush cached certificates",
        !            81:                {"[--type x509|x509_ac|x509_crl|ocsp_response|pubkey]",
        !            82:                 "[--raw|--pretty]"},
        !            83:                {
        !            84:                        {"help",                'h', 0, "show usage information"},
        !            85:                        {"type",                't', 1, "filter by certificate type"},
        !            86:                        {"raw",                 'r', 0, "dump raw response message"},
        !            87:                        {"pretty",              'P', 0, "dump raw response message in pretty print"},
        !            88:                }
        !            89:        });
        !            90: }

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