]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
swanctl: Report labels in --list-* commands
authorTobias Brunner <tobias@strongswan.org>
Tue, 21 Dec 2021 11:18:21 +0000 (12:18 +0100)
committerTobias Brunner <tobias@strongswan.org>
Thu, 14 Apr 2022 16:42:01 +0000 (18:42 +0200)
src/swanctl/commands/list_conns.c
src/swanctl/commands/list_pols.c
src/swanctl/commands/list_sas.c
src/swanctl/swanctl.c
src/swanctl/swanctl.h

index f00fb54fdb310c34bcab4c2ec8039300c7073169..e7a8db0ce28024b7023c634ee1403216b09c88b2 100644 (file)
@@ -20,6 +20,7 @@
 #include <stdio.h>
 #include <errno.h>
 
+#include "swanctl.h"
 #include "command.h"
 
 #include <collections/hashtable.h>
@@ -135,6 +136,7 @@ CALLBACK(children_sn, int,
                }
                printf("\n");
 
+               print_label("    label:  ", child->get(child, "label"));
                printf("    local:  %s\n", child->get(child, "local-ts"));
                printf("    remote: %s\n", child->get(child, "remote-ts"));
 
index f2ae221725b2ee201da745bf1a1ca9d0f4a75acc..b238b224b1887d5ae80fd3d66e1bce808a305b06 100644 (file)
@@ -18,6 +18,7 @@
 #include <errno.h>
 
 #include "command.h"
+#include "swanctl.h"
 
 #include <collections/hashtable.h>
 
@@ -85,6 +86,7 @@ CALLBACK(policies, int,
        ret = vici_parse_cb(res, NULL, policy_values, policy_list, pol);
 
        printf("%s, %s\n", name, pol->get(pol, "mode"));
+       print_label("  label:  ", pol->get(pol, "label"));
        printf("  local:  %s\n", pol->get(pol, "local-ts"));
        printf("  remote: %s\n", pol->get(pol, "remote-ts"));
 
index ca2436dd2f7c6ce1c83b746cb9d1b05193792074..48c06fd613a0bcf7d36a16c2992d9f8d006d0869 100644 (file)
@@ -43,6 +43,7 @@
 #include <errno.h>
 
 #include "command.h"
+#include "swanctl.h"
 
 #include <collections/hashtable.h>
 
@@ -81,7 +82,6 @@ CALLBACK(sa_values, int,
        return 0;
 }
 
-
 CALLBACK(sa_list, int,
        hashtable_t *sa, vici_res_t *res, char *name, void *value, int len)
 {
@@ -227,6 +227,7 @@ CALLBACK(child_sas, int,
                }
                printf("\n");
 
+               print_label("    label  ", child->get(child, "label"));
                printf("    local  %s\n", child->get(child, "local-ts"));
                printf("    remote %s\n", child->get(child, "remote-ts"));
        }
index cfc82f9d7b55c96a52f88cbaf6f5da57d07c098d..dc27646bded631817aa73ed521963ffb3fdafe1e 100644 (file)
@@ -22,6 +22,7 @@
 #include <unistd.h>
 
 #include <library.h>
+#include <selectors/sec_label.h>
 
 /*
  * Described in header
@@ -59,6 +60,27 @@ settings_t *load_swanctl_conf(char *file)
        return cfg;
 }
 
+/*
+ * Described in header
+ */
+void print_label(const char *prefix, const char *value)
+{
+       sec_label_t *label;
+       chunk_t encoding;
+
+       if (value)
+       {
+               encoding = chunk_from_hex(chunk_from_str((char*)value), NULL);
+               label = sec_label_from_encoding(encoding);
+               if (label)
+               {
+                       printf("%s%s\n", prefix, label->get_string(label));
+                       label->destroy(label);
+               }
+               chunk_free(&encoding);
+       }
+}
+
 /**
  * Cleanup library atexit()
  */
index 70f70d179b4ba333159d858aa4e0a26976beb782..c7f7a6c438973a82a83668fdeac962289095fff7 100644 (file)
@@ -111,4 +111,13 @@ extern char *swanctl_dir;
  */
 settings_t *load_swanctl_conf(char *file);
 
+/**
+ * Print the given security label (hex-encoded) on a separate line with the
+ * given prefix.
+ *
+ * @param prefix       prefix to print before the string-version of the label
+ * @param value                hex-encoded security label
+ */
+void print_label(const char *prefix, const char *value);
+
 #endif /** SWANCTL_H_ @}*/