diff options
Diffstat (limited to 'eurephiadm')
-rw-r--r-- | eurephiadm/CMakeLists.txt | 1 | ||||
-rw-r--r-- | eurephiadm/commands.h | 8 | ||||
-rw-r--r-- | eurephiadm/commands/certificates.c | 145 |
3 files changed, 153 insertions, 1 deletions
diff --git a/eurephiadm/CMakeLists.txt b/eurephiadm/CMakeLists.txt index 1a09b33..3362847 100644 --- a/eurephiadm/CMakeLists.txt +++ b/eurephiadm/CMakeLists.txt @@ -9,6 +9,7 @@ SET(efw_ipt_SRC client_context.c client_session.c commands/users.c + commands/certificates.c commands/edit_config.c ../common/eurephia_log.c ../common/eurephia_getsym.c diff --git a/eurephiadm/commands.h b/eurephiadm/commands.h index 043b2d6..2be419c 100644 --- a/eurephiadm/commands.h +++ b/eurephiadm/commands.h @@ -45,6 +45,9 @@ int cmd_ShowCfg(eurephiaCTX *, eurephiaSESSION *, eurephiaVALUES *cfg, int argc, void help_Users(); int cmd_Users(eurephiaCTX *, eurephiaSESSION *, eurephiaVALUES *cfg, int argc, char **argv); +void help_Certificates(); +int cmd_Certificates(eurephiaCTX *, eurephiaSESSION *, eurephiaVALUES *cfg, int argc, char **argv); + void help_EditConfig(); int cmd_EditConfig(eurephiaCTX *, eurephiaSESSION *, eurephiaVALUES *cfg, int argc, char **argv); @@ -61,7 +64,10 @@ static const eurephiadm_functions cmdline_functions[] = { "Logout from an open session", NULL, cmd_Logout}, {"users", 1, "useradmin", "-l", - "User management", help_Users, cmd_Users}, + "User management", help_Users, cmd_Users}, + + {"certs", 1, "certadmin", NULL, + "Certificate management", help_Certificates, cmd_Certificates}, {"show-config", 1, "config", NULL, "List all config settings", NULL, cmd_ShowCfg}, 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; +} + |