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>
Tue, 23 Jan 2024 10:12:19 +0000 (11:12 +0100)
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 9fd0585237fb80a9dde48710fc956ce5b4449164..86ae1d0704887a869b92e6771ccd1c8c985be64b 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;