smbstatus: let --json include session.{creation,expiration,auth}_time
authorStefan Metzmacher <metze@samba.org>
Tue, 9 Jan 2024 15:46:06 +0000 (16:46 +0100)
committerStefan Metzmacher <metze@samba.org>
Fri, 26 Jan 2024 17:00:32 +0000 (17:00 +0000)
This is very useful in order to predict NETWORK_SESSION_EXPIRED
messages...

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Günther Deschner <gd@samba.org>
source3/utils/status_json.c

index 161e85a3d6cc87e7549621c69e1bfe59a57a673c..ee24a3b31d97f495c96289fbee8965d81e703324 100644 (file)
@@ -485,6 +485,9 @@ int traverse_sessionid_json(struct traverse_state *state,
        struct json_object session_json;
        int result = 0;
        char *id_str = NULL;
+       struct timeval tv;
+       struct timeval_buf tv_buf;
+       char *time_str = NULL;
 
        TALLOC_CTX *tmp_ctx = talloc_stackframe();
        if (tmp_ctx == NULL) {
@@ -526,6 +529,37 @@ int traverse_sessionid_json(struct traverse_state *state,
        if (result < 0) {
                goto failure;
        }
+
+       nttime_to_timeval(&tv, session->global->creation_time);
+       time_str = timeval_str_buf(&tv, true, true, &tv_buf);
+       if (time_str == NULL) {
+               goto failure;
+       }
+       result = json_add_string(&sub_json, "creation_time", time_str);
+       if (result < 0) {
+               goto failure;
+       }
+
+       nttime_to_timeval(&tv, session->global->expiration_time);
+       time_str = timeval_str_buf(&tv, true, true, &tv_buf);
+       if (time_str == NULL) {
+               goto failure;
+       }
+       result = json_add_string(&sub_json, "expiration_time", time_str);
+       if (result < 0) {
+               goto failure;
+       }
+
+       nttime_to_timeval(&tv, session->global->auth_time);
+       time_str = timeval_str_buf(&tv, true, true, &tv_buf);
+       if (time_str == NULL) {
+               goto failure;
+       }
+       result = json_add_string(&sub_json, "auth_time", time_str);
+       if (result < 0) {
+               goto failure;
+       }
+
        result = json_add_string(&sub_json, "remote_machine", session->remote_machine);
        if (result < 0) {
                goto failure;