summaryrefslogtreecommitdiffstats
path: root/eurephiadm/commands/usercerts.c
diff options
context:
space:
mode:
Diffstat (limited to 'eurephiadm/commands/usercerts.c')
-rw-r--r--eurephiadm/commands/usercerts.c154
1 files changed, 154 insertions, 0 deletions
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;
+}