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.c117
1 files changed, 62 insertions, 55 deletions
diff --git a/eurephiadm/commands/usercerts.c b/eurephiadm/commands/usercerts.c
index c7babad..60590be 100644
--- a/eurephiadm/commands/usercerts.c
+++ b/eurephiadm/commands/usercerts.c
@@ -232,7 +232,8 @@ int list_usercerts(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES *cfg,
*/
int add_del_usercert(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES *cfg, int argc, char **argv) {
xmlDoc *usercert_xml = NULL, *resxml = NULL;
- xmlNode *usercert_n = NULL, *res_n = NULL;
+ xmlNode *usercert_n = NULL;
+ eurephiaRESULT *res = NULL;
int i = 0, rc = 0, actmode = 0;
char *certid = NULL, *uid = NULL, *uicid = NULL, *actmode_str = NULL, *accessprofile = NULL;
@@ -269,20 +270,20 @@ int add_del_usercert(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES *cf
case 'i':
if( atoi_nullsafe(optargs[0]) < 1 ) {
fprintf(stderr, "%s: User ID must be a positive number (>0)\n", MODULE);
- rc = 1;
- goto exit;
+ rc = 1;
+ goto exit;
}
- xmlNewChild(usercert_n, NULL, (xmlChar *) "uid", (xmlChar *) optargs[0]);
+ xmlNewChild(usercert_n, NULL, (xmlChar *) "uid", (xmlChar *) optargs[0]);
uid = optargs[0];
break;
case 'c':
if( atoi_nullsafe(optargs[0]) < 1 ) {
fprintf(stderr,"%s: Certificate ID must be a positive number (>0)\n",MODULE);
- rc = 1;
- goto exit;
+ rc = 1;
+ goto exit;
}
- xmlNewChild(usercert_n, NULL, (xmlChar *) "certid", (xmlChar *) optargs[0]);
+ xmlNewChild(usercert_n, NULL, (xmlChar *) "certid", (xmlChar *) optargs[0]);
certid = optargs[0];
break;
@@ -290,73 +291,79 @@ int add_del_usercert(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES *cf
case 'a':
if( atoi_nullsafe(optargs[0]) < 1 ) {
fprintf(stderr, "%s: Firewall profile ID must be a positive number (>0)\n",
- MODULE);
- rc = 1;
- goto exit;
+ MODULE);
+ rc = 1;
+ goto exit;
}
- xmlNewChild(usercert_n, NULL, (xmlChar *) "accessprofile", (xmlChar *) optargs[0]);
+ xmlNewChild(usercert_n, NULL, (xmlChar *) "accessprofile", (xmlChar *) optargs[0]);
accessprofile = optargs[0];
break;
#endif
case 'n':
if( actmode != 'D' ) {
fprintf(stderr, "%s: --uicid cannot be used with --add\n", MODULE);
- rc = 1;
- goto exit;
+ rc = 1;
+ goto exit;
}
if( atoi_nullsafe(optargs[0]) < 1 ) {
fprintf(stderr, "%s: uicid must be a positive number (>0)\n",
- MODULE);
- rc = 1;
- goto exit;
+ MODULE);
+ rc = 1;
+ goto exit;
}
- xmlNewChild(usercert_n, NULL, (xmlChar *) "uicid", (xmlChar *) optargs[0]);
+ xmlNewChild(usercert_n, NULL, (xmlChar *) "uicid", (xmlChar *) optargs[0]);
uicid = optargs[0];
break;
case 'h':
display_usercerts_help(actmode);
- rc = 0;
- goto exit;
+ rc = 0;
+ goto exit;
default:
- rc = 1;
- goto exit;
+ rc = 1;
+ goto exit;
}
}
if( (actmode == 'A') && ((certid == NULL) || (uid == NULL)) ) {
fprintf(stderr, "%s: You must provide both a user ID (--uid) and "
- "a certificate ID (--certid)\n", MODULE);
- rc = 1;
- goto exit;
+ "a certificate ID (--certid)\n", MODULE);
+ rc = 1;
+ goto exit;
}
if( (actmode == 'D') && (certid == NULL) && (uid == NULL)
- && (uicid == NULL) && (accessprofile == NULL)) {
+ && (uicid == NULL) && (accessprofile == NULL)) {
fprintf(stderr, "%s: You must provide at least --uid, --certid, "
- "--uicid or --accessprofile\n", MODULE);
- rc = 1;
- goto exit;
+ "--uicid or --accessprofile\n", MODULE);
+ rc = 1;
+ goto exit;
}
- resxml = eDBadminUserCertsLink(ctx, usercert_xml);
+ resxml = eDBadminUserCertsLink(ctx, usercert_xml);
if( resxml == NULL ) {
fprintf(stderr, "%s: Failed to update user <-> certificate link\n", MODULE);
rc = 1;
- goto exit;
- }
+ goto exit;
+ }
- res_n = eurephiaXML_getRoot(ctx, resxml, NULL, 1);
- if( xmlStrcmp(res_n->name, (xmlChar *) "Error") == 0 ) {
- fprintf(stderr, "%s: %s\n", MODULE, xmlExtractContent(res_n));
- rc = 1;
+ res = eurephiaXML_ParseResultMsg(ctx, resxml);
+ if( res == NULL ) {
+ fprintf(stderr, "%s: Failed to update user <-> certificate link. No result available.",
+ MODULE);
} else {
- fprintf(stdout, "%s: %s\n", MODULE, xmlExtractContent(res_n));
- rc = 0;
+ if( res->resultType == exmlERROR ) {
+ fprintf(stderr, "%s: %s\n", MODULE, res->message);
+ rc = 1;
+ } else {
+ fprintf(stdout, "%s: %s\n", MODULE, res->message);
+ rc = 0;
+ }
}
- xmlFreeDoc(resxml);
+ free_nullsafe(ctx, res);
+ xmlFreeDoc(resxml);
exit:
xmlFreeDoc(usercert_xml);
@@ -403,11 +410,11 @@ int set_fwprofile(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES *cfg,
case 'a':
if( atoi_nullsafe(optargs[0]) < 1 ) {
fprintf(stderr, "%s: Firewall profile ID must be a positive number (>0)\n",
- MODULE);
- rc = 1;
- goto exit;
+ MODULE);
+ rc = 1;
+ goto exit;
}
- xmlNewChild(fmap_n, NULL, (xmlChar *) "accessprofile", (xmlChar *) optargs[0]);
+ xmlNewChild(fmap_n, NULL, (xmlChar *) "accessprofile", (xmlChar *) optargs[0]);
accprf = 1; // Access profile is set
break;
@@ -418,46 +425,46 @@ int set_fwprofile(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES *cfg,
uicid = atoi_nullsafe(optargs[0]);
if( uicid < 1 ) {
fprintf(stderr, "%s: uicid must be a positive number (>0)\n",
- MODULE);
- rc = 1;
- goto exit;
+ MODULE);
+ rc = 1;
+ goto exit;
}
xmlNewProp(usercert_n, (xmlChar *) "uicid", (xmlChar *) optargs[0]);
break;
case 'h':
display_usercerts_help('S');
- rc = 0;
- goto exit;
+ rc = 0;
+ goto exit;
default:
- rc = 1;
- goto exit;
+ rc = 1;
+ goto exit;
}
}
if( (uicid < 1) || (accprf != 1) ) {
fprintf(stderr, "%s: You must provide --uicid and --accessprofile\n", MODULE);
- rc = 1;
- goto exit;
+ rc = 1;
+ goto exit;
}
res_xml = eDBadminUserCertsLink(ctx, usercert_xml);
if( res_xml == NULL ) {
fprintf(stderr, "%s: Failed to update firewall access profile for user-cert link\n", MODULE);
rc = 1;
- goto exit;
- }
+ goto exit;
+ }
res_n = eurephiaXML_getRoot(ctx, res_xml, NULL, 1);
- if( xmlStrcmp(res_n->name, (xmlChar *) "Error") == 0 ) {
+ 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(res_xml);
+ xmlFreeDoc(res_xml);
exit:
xmlFreeDoc(usercert_xml);