diff options
author | David Sommerseth <dazo@users.sourceforge.net> | 2008-12-20 00:27:00 +0100 |
---|---|---|
committer | David Sommerseth <dazo@users.sourceforge.net> | 2008-12-20 00:27:00 +0100 |
commit | fbf85c0b1b49d8df1e5164a1ed90b215e64c36f2 (patch) | |
tree | ce861b67063456abab3d35c89f895255baed5a7f /eurephiadm/commands | |
parent | 47dcc0dd75a00a8cc8eaceb02814562b01c2941a (diff) | |
download | eurephia-fbf85c0b1b49d8df1e5164a1ed90b215e64c36f2.tar.gz eurephia-fbf85c0b1b49d8df1e5164a1ed90b215e64c36f2.tar.xz eurephia-fbf85c0b1b49d8df1e5164a1ed90b215e64c36f2.zip |
Added skeleton for certs command
Diffstat (limited to 'eurephiadm/commands')
-rw-r--r-- | eurephiadm/commands/certificates.c | 145 |
1 files changed, 145 insertions, 0 deletions
diff --git a/eurephiadm/commands/certificates.c b/eurephiadm/commands/certificates.c new file mode 100644 index 0000000..8a73c11 --- /dev/null +++ b/eurephiadm/commands/certificates.c @@ -0,0 +1,145 @@ +/* certificates.c -- eurephiadm command: certs + * Certificate management + * + * GPLv2 - Copyright (C) 2008 David Sommerseth <dazo@users.sourceforge.net> + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; version 2 + * of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <unistd.h> +#include <errno.h> +#include <assert.h> + +#ifdef HAVE_LIBXML2 +#include <libxml/parser.h> +#include <libxml/tree.h> +#include <libxml/xpath.h> +#endif + +#define MODULE "eurephia::Certificates" +#include <eurephia_nullsafe.h> +#include <eurephia_context.h> +#include <eurephia_log.h> +#include <eurephia_xml.h> +#include <eurephia_values_struct.h> +#include <eurephiadb_session_struct.h> +#include <eurephia_admin_struct.h> +#include <eurephiadb_mapping.h> +#include <eurephiadb_driver.h> + +#include "../argparser.h" + +void display_certs_help(int page) { + printf("Help page not implemented yet\n"); +} + +void help_Certificates() { + display_certs_help(0); +} + +int help_Certificates2(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES *cfg, int argc, char **argv) { + e_options helpargs[] = { + {"--list", "-l", 0}, + {"--show", "-s", 0}, + {"--activate", "-a", 0}, + {"--deactivate", "-d", 0}, + {"--add", "-A", 0}, + {"--delete", "-D", 0}, + {"--password", "-p", 0}, + {NULL, NULL, 0} + }; + + int i = 1; + display_certs_help(eurephia_getopt(&i, argc, argv, helpargs)); + return 0; +} + +int add_cert(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES *cfg, int argc, char **argv) { + return 1; +} + + +int cmd_Certificates(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES *cfg, int argc, char **argv) { + char **mode_argv; + int i, mode_argc = 0, rc = 0; + int (*mode_fnc) (eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES *cfg, int argc, char **argv); + + e_options modeargs[] = { + {"--list", "-l", 0}, + {"--show", "-s", 0}, + {"--add", "-A", 0}, + {"--delete", "-D", 0}, + {"--help", "-h", 0}, + {NULL, NULL, 0} + }; + + assert((ctx != NULL) && (ctx->dbc != NULL) && (ctx->dbc->config != NULL)); + mode_fnc = NULL; + for( i = 1; i < argc; i++ ) { + switch( eurephia_getopt(&i, argc, argv, modeargs) ) { + case 'l': + // mode_fnc = list_certs; + break; + + case 's': + // mode_fnc = show_certs; + break; + + case 'h': + mode_fnc = help_Certificates2; + break; + + case 'A': + mode_fnc = add_cert; + break; + + case 'D': + // mode_fnc = delete_cert; + break; + + default: + break; + } + if( mode_fnc != NULL ) { + break; + } + } + + // If we do not have any known mode defined, exit with error + if( mode_fnc == NULL ) { + fprintf(stderr, "%s: Unknown argument. No mode given\n", MODULE); + return 1; + } + + // Allocate memory for our arguments being sent to the mode function + mode_argv = (char **) calloc(sizeof(char *), (argc - i)+2); + assert(mode_argv != NULL); + + // Copy over only the arguments needed for the mode + mode_argc = eurephia_arraycp(i, argc, argv, mode_argv, (argc - i)); + + // Call the mode function + rc = mode_fnc(ctx, sess, cfg, mode_argc, mode_argv); + free_nullsafe(mode_argv); + + return rc; +} + |