diff options
author | David Sommerseth <dazo@users.sourceforge.net> | 2008-12-28 17:26:38 +0100 |
---|---|---|
committer | David Sommerseth <dazo@users.sourceforge.net> | 2008-12-28 17:26:38 +0100 |
commit | 927b6469a9ead439290ae4d884178c61d95f3be2 (patch) | |
tree | 3230b457e193b96c2adb1e4ca1748ee22956dd2f | |
parent | a13684246a780a27c3110818254a696385c06b93 (diff) | |
download | eurephia-927b6469a9ead439290ae4d884178c61d95f3be2.tar.gz eurephia-927b6469a9ead439290ae4d884178c61d95f3be2.tar.xz eurephia-927b6469a9ead439290ae4d884178c61d95f3be2.zip |
usercerts command: Added skeleton for a new admin command
-rw-r--r-- | eurephiadm/CMakeLists.txt | 1 | ||||
-rw-r--r-- | eurephiadm/commands.h | 6 | ||||
-rw-r--r-- | eurephiadm/commands/usercerts.c | 154 |
3 files changed, 161 insertions, 0 deletions
diff --git a/eurephiadm/CMakeLists.txt b/eurephiadm/CMakeLists.txt index e538a61..6e23585 100644 --- a/eurephiadm/CMakeLists.txt +++ b/eurephiadm/CMakeLists.txt @@ -12,6 +12,7 @@ SET(efw_ipt_SRC parse_certificate_files.c commands/users.c commands/certificates.c + commands/usercerts.c commands/edit_config.c ../common/eurephia_log.c ../common/eurephia_getsym.c diff --git a/eurephiadm/commands.h b/eurephiadm/commands.h index 2be419c..edfa194 100644 --- a/eurephiadm/commands.h +++ b/eurephiadm/commands.h @@ -48,6 +48,9 @@ int cmd_Users(eurephiaCTX *, eurephiaSESSION *, eurephiaVALUES *cfg, int argc, c void help_Certificates(); int cmd_Certificates(eurephiaCTX *, eurephiaSESSION *, eurephiaVALUES *cfg, int argc, char **argv); +void help_UserCerts(); +int cmd_UserCerts(eurephiaCTX *, eurephiaSESSION *, eurephiaVALUES *cfg, int argc, char **argv); + void help_EditConfig(); int cmd_EditConfig(eurephiaCTX *, eurephiaSESSION *, eurephiaVALUES *cfg, int argc, char **argv); @@ -69,6 +72,9 @@ static const eurephiadm_functions cmdline_functions[] = { {"certs", 1, "certadmin", NULL, "Certificate management", help_Certificates, cmd_Certificates}, + {"usercerts", 1, "useradmin", NULL, + "User account/Certificate link management", help_UserCerts, cmd_UserCerts}, + {"show-config", 1, "config", NULL, "List all config settings", NULL, cmd_ShowCfg}, diff --git a/eurephiadm/commands/usercerts.c b/eurephiadm/commands/usercerts.c new file mode 100644 index 0000000..2436546 --- /dev/null +++ b/eurephiadm/commands/usercerts.c @@ -0,0 +1,154 @@ +/* usercerts.c -- eurephiadm usercerts command: + * Management of user account <-> certificate links + * + * 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 <assert.h> + +#ifdef HAVE_LIBXML2 +#include <libxml/parser.h> +#include <libxml/tree.h> +#include <libxml/xpath.h> +#endif + +#define MODULE "eurephia::UserCerts" +#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 <certinfo.h> + +#include "../argparser.h" +#include "../field_print.h" + + +void display_usercerts_help(int page) { + switch( page ) { + case 'A': + printf("The add mode will register a new link between a user account and a certificate.\n" + "\n" + " -c | --certid Required - Certificate ID (certid)\n" + " -i | --userid Required - User accound ID (uid)\n" + "\n" + ); + break; + case 'D': + printf("The delete mode will delete a link between a user account and a certificate.\n" + "\n" + " -c | --certid Certificate ID (certid)\n" + " -i | --userid User accound ID (uid)\n" + " -n | --uicid Unique record id of certificate and user account link\n" + "\n" + ); + break; + default: + printf("Available modes for the usercerts command are:\n\n" + " -A | --add Register a new certificate and user account link\n" + " -D | --delete Delete a certificate and user account link\n" + " -l | --list List all registered links\n" + " -h | --help <mode> Help about a specific mode\n\n"); + break; + } +} + +void help_UserCerts() { + display_usercerts_help(0); +} + +int help_UserCerts2(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES *cfg, int argc, char **argv) { + e_options helpargs[] = { + {"--list", "-l", 0}, + {"--add", "-A", 0}, + {"--delete", "-D", 0}, + {NULL, NULL, 0} + }; + + int i = 1; + display_usercerts_help(eurephia_getopt(&i, argc, argv, helpargs)); + return 0; +} + +int cmd_UserCerts(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}, + {"--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_usercerts; + break; + + case 'h': + mode_fnc = help_UserCerts2; + break; + + case 'A': + // mode_fnc = add_usercert; + break; + + case 'D': + // mode_fnc = delete_usercert; + 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; +} |