smbstatus: add encryption and signing to connections
authorJule Anger <janger@samba.org>
Mon, 9 May 2022 08:11:38 +0000 (10:11 +0200)
committerJule Anger <janger@samba.org>
Mon, 8 Aug 2022 12:56:28 +0000 (12:56 +0000)
Signed-off-by: Jule Anger <janger@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
source3/utils/status.c
source3/utils/status_json.c
source3/utils/status_json.h
source3/utils/status_json_dummy.c

index e428110fb1234160a06a3529d38fbb761fb81b46..0dfb8e9b25c36b2092ee8fe1f8ac1f89b05230d7 100644 (file)
@@ -456,7 +456,9 @@ static int traverse_connections(const struct connections_data *crec,
        char *timestr = NULL;
        int result = 0;
        const char *encryption = "-";
+       enum crypto_degree encryption_degree = CRYPTO_DEGREE_NONE;
        const char *signing = "-";
+       enum crypto_degree signing_degree = CRYPTO_DEGREE_NONE;
        struct traverse_state *state = (struct traverse_state *)private_data;
 
        TALLOC_CTX *tmp_ctx = talloc_stackframe();
@@ -497,6 +499,7 @@ static int traverse_connections(const struct connections_data *crec,
                        result = -1;
                        break;
                }
+               encryption_degree = CRYPTO_DEGREE_FULL;
        }
 
        if (smbXsrv_is_signed(crec->signing_flags)) {
@@ -518,6 +521,7 @@ static int traverse_connections(const struct connections_data *crec,
                        result = -1;
                        break;
                }
+               signing_degree = CRYPTO_DEGREE_FULL;
        }
 
        if (!state->json_output) {
@@ -530,7 +534,11 @@ static int traverse_connections(const struct connections_data *crec,
                                                     signing);
        } else {
                result = traverse_connections_json(state,
-                                                  crec);
+                                                  crec,
+                                                  encryption,
+                                                  encryption_degree,
+                                                  signing,
+                                                  signing_degree);
        }
 
        TALLOC_FREE(timestr);
index 3f76cea3c7f006faf8ec388d939a3ac66499b51e..0eadd1a1867a929251d2722b4f24ecf791989c60 100644 (file)
@@ -126,8 +126,53 @@ int add_section_to_json(struct traverse_state *state,
        return result;
 }
 
+static int add_crypto_to_json(struct json_object *parent_json,
+                             const char *key,
+                             const char *cipher,
+                             enum crypto_degree degree)
+{
+       struct json_object sub_json;
+       const char *degree_str;
+       int result;
+
+       if (degree == CRYPTO_DEGREE_NONE) {
+               degree_str = "none";
+       } else if (degree == CRYPTO_DEGREE_PARTIAL) {
+               degree_str = "partial";
+       } else {
+               degree_str = "full";
+       }
+
+       sub_json = json_new_object();
+       if (json_is_invalid(&sub_json)) {
+               goto failure;
+       }
+
+       result = json_add_string(&sub_json, "cipher", cipher);
+       if (result < 0) {
+               goto failure;
+       }
+       result = json_add_string(&sub_json, "degree", degree_str);
+       if (result < 0) {
+               goto failure;
+       }
+       result = json_add_object(parent_json, key, &sub_json);
+       if (result < 0) {
+               goto failure;
+       }
+
+       return 0;
+failure:
+       json_free(&sub_json);
+       return -1;
+}
+
 int traverse_connections_json(struct traverse_state *state,
-                             const struct connections_data *crec)
+                             const struct connections_data *crec,
+                             const char *encryption_cipher,
+                             enum crypto_degree encryption_degree,
+                             const char *signing_cipher,
+                             enum crypto_degree signing_degree)
 {
        struct json_object sub_json;
        struct json_object connections_json;
@@ -189,6 +234,16 @@ int traverse_connections_json(struct traverse_state *state,
        if (result < 0) {
                goto failure;
        }
+       result = add_crypto_to_json(&sub_json, "encryption",
+                                  encryption_cipher, encryption_degree);
+       if (result < 0) {
+               goto failure;
+       }
+       result = add_crypto_to_json(&sub_json, "signing",
+                                  signing_cipher, signing_degree);
+       if (result < 0) {
+               goto failure;
+       }
 
        result = json_add_object(&connections_json, tcon_id_str, &sub_json);
        if (result < 0) {
index d21f3e6da477d4f8a1261bc598fd86b9407b1472..758fc8a6b9802e894a396832e8d11549b89ad199 100644 (file)
@@ -28,6 +28,10 @@ int add_section_to_json(struct traverse_state *state,
 int add_general_information_to_json(struct traverse_state *state);
 
 int traverse_connections_json(struct traverse_state *state,
-                             const struct connections_data *crec);
+                             const struct connections_data *crec,
+                             const char *encryption_cipher,
+                             enum crypto_degree encryption_degree,
+                             const char *signing_cipher,
+                             enum crypto_degree signing_degree);
 
 #endif
index ec341f42c4a17d0266834567835ae3e6cc17d611..471d61cdffa1514e657e71a178e8eb2a886b9fb7 100644 (file)
@@ -36,7 +36,11 @@ int add_general_information_to_json(struct traverse_state *state)
 }
 
 int traverse_connections_json(struct traverse_state *state,
-                             const struct connections_data *crec)
+                             const struct connections_data *crec,
+                             const char *encryption_cipher,
+                             enum crypto_degree encryption_degree,
+                             const char *signing_cipher,
+                             enum crypto_degree signing_degree)
 {
        return 0;
 }