summaryrefslogtreecommitdiffstats
path: root/eurephiadm
diff options
context:
space:
mode:
authorDavid Sommerseth <dazo@users.sourceforge.net>2009-04-02 01:36:33 +0200
committerDavid Sommerseth <dazo@users.sourceforge.net>2009-04-02 01:36:33 +0200
commitb8923339a3cdae13d313e916761f7b5e6455bc6c (patch)
tree3785804126c3fc05177c923c720d94918fc57da3 /eurephiadm
parent2077aa6897fd9d0828b13cec29a9ca7135a48dca (diff)
downloadeurephia-b8923339a3cdae13d313e916761f7b5e6455bc6c.tar.gz
eurephia-b8923339a3cdae13d313e916761f7b5e6455bc6c.tar.xz
eurephia-b8923339a3cdae13d313e916761f7b5e6455bc6c.zip
Completed eurephiadm/fwadmin with add/delete modes
Diffstat (limited to 'eurephiadm')
-rw-r--r--eurephiadm/commands/fwadmin.c114
1 files changed, 112 insertions, 2 deletions
diff --git a/eurephiadm/commands/fwadmin.c b/eurephiadm/commands/fwadmin.c
index a8957fb..6f6d6fc 100644
--- a/eurephiadm/commands/fwadmin.c
+++ b/eurephiadm/commands/fwadmin.c
@@ -63,6 +63,24 @@ void display_fwadmin_help(int page)
" -d | --digest <SHA1 digest> Certificate SHA1 digest\n\n");
break;
+ case 'A':
+ printf("The fwadmin add mode will register a new firewall profile.\n"
+ "\n"
+ " -d | --description <text> Description of the firewall destination/rule\n"
+ " -f | --fw-destination <name> The reference used by the firewall module\n"
+ "\n"
+ );
+ break;
+
+ case 'D':
+ printf("The fwadmin delete mode will delete a firewall profile.\n"
+ "\n"
+ " -a | --accessprofile <id> Description of the firewall destination/rule\n"
+ " -f | --fw-destination <name> The reference used by the firewall module\n"
+ "\n"
+ );
+ break;
+
default:
printf("Available modes for the fwadmin command are:\n\n"
" -A | --add Add a new firewall profile\n"
@@ -175,6 +193,98 @@ int list_profiles(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES *cfg,
return 0;
}
+
+int addelete_profile(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES *cfg, int argc, char **argv)
+{
+ xmlDoc *result_xml = NULL, *srch_xml = NULL;
+ xmlNode *fmap_n = NULL, *res_n = NULL, *srch_n = NULL;
+ int i = 0, rc = 1, mode = 0;
+
+ e_options addargs[] = {
+ {"--help", "-h", 0},
+ {"--description", "-d", 1},
+ {"--fw-destination", "-f", 1},
+ {NULL, NULL, 0}
+ };
+
+ e_options deleteargs[] = {
+ {"--help", "-h", 0},
+ {"--accessprofile", "-a", 1},
+ {"--fw-destination", "-f", 1},
+ {NULL, NULL, 0}
+ };
+
+
+ e_options *fwadminargs = NULL;
+
+ eurephiaXML_CreateDoc(ctx, 1, "firewall_profiles", &srch_xml, &srch_n);
+ if( (strcmp(argv[0], "--add") == 0) || (strcmp(argv[0], "-A") == 0) ) {
+ xmlNewProp(srch_n, (xmlChar *) "mode", (xmlChar *) "add");
+ fwadminargs = addargs;
+ mode = 'A';
+ } else if( (strcmp(argv[0], "--delete") == 0) || (strcmp(argv[0], "-D") == 0) ) {
+ xmlNewProp(srch_n, (xmlChar *) "mode", (xmlChar *) "delete");
+ fwadminargs = deleteargs;
+ mode = 'D';
+ } else {
+ fprintf(stderr, "%s: Invalid mode\n", MODULE);
+ xmlFreeDoc(srch_xml);
+ return 1;
+ }
+
+ fmap_n = xmlNewChild(srch_n, NULL, (xmlChar *) "fieldMapping", NULL);
+ xmlNewProp(fmap_n, (xmlChar *) "table", (xmlChar *) "firewall_profiles");
+
+ for( i = 1; i < argc; i++ ) {
+ switch( eurephia_getopt(&i, argc, argv, fwadminargs) ) {
+ case 'a':
+ xmlNewChild(fmap_n, NULL, (xmlChar *) "accessprofile", (xmlChar *) optargs[0]);
+ break;
+
+ case 'd':
+ xmlNewChild(fmap_n, NULL, (xmlChar *) "description", (xmlChar *) optargs[0]);
+ break;
+
+ case 'f':
+ xmlNewChild(fmap_n, NULL, (xmlChar *) "fwprofile", (xmlChar *) optargs[0]);
+ break;
+
+ case 'h':
+ display_fwadmin_help(mode);
+ return 0;
+
+ default:
+ return 1;
+ }
+ }
+
+ result_xml = eDBadminFirewallProfiles(ctx, srch_xml);
+ xmlFreeDoc(srch_xml);
+ if( result_xml == NULL ) {
+ fprintf(stderr, "%s: Error registering firewall profiles\n", MODULE);
+ return 1;
+ }
+
+ res_n = eurephiaXML_getRoot(ctx, result_xml, NULL, 1);
+ if( res_n == NULL ) {
+ fprintf(stderr, "%s: Error registering firewall profiles. No results returned\n", MODULE);
+ return 1;
+
+ }
+
+ if( xmlStrcmp(res_n->name, (xmlChar *) "Error") == 0 ) {
+ fprintf(stderr, "%s: %s\n", MODULE, xmlExtractContent(res_n));
+ rc = 1;
+ } else {
+ fprintf(stdout, "%s: %s\n", MODULE, xmlExtractContent(res_n));
+ rc = 0;
+ }
+ xmlFreeDoc(result_xml);
+
+ return rc;
+}
+
+
int cmd_fwAdmin(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES *cfg, int argc, char **argv)
{
char **mode_argv;
@@ -199,8 +309,8 @@ int cmd_fwAdmin(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES *cfg, in
case 'A':
case 'D':
- printf("**NOT IMPLEMENTED\n");
- return 1;
+ mode_fnc = addelete_profile;
+ break;
case 'h':
mode_fnc = help_fwAdmin2;