smbstatus: correctly denote not fully authenticated sessions
authorRalph Boehme <slow@samba.org>
Tue, 4 Jul 2017 10:22:00 +0000 (12:22 +0200)
committerJeremy Allison <jra@samba.org>
Mon, 27 Nov 2017 21:08:17 +0000 (22:08 +0100)
Currently for sessions where authentication is still in progress we
print uid and gid as -1.

With this change we nicely list them like this:

PID  Username   Group    Machine                          Protocol Version ....
6604 (auth in progress)  127.0.0.1 (ipv4:127.0.0.1:47930) SMB3_11 ....

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/utils/status.c

index dd196b64a470c664caab098f045eb1d59ce2f936..dfb1d921a4230f4af0a2c67c1c4186aa2b81398b 100644 (file)
@@ -365,7 +365,7 @@ static int traverse_sessionid(const char *key, struct sessionid *session,
                              void *private_data)
 {
        TALLOC_CTX *mem_ctx = (TALLOC_CTX *)private_data;
-       fstring uid_str, gid_str;
+       fstring uid_gid_str;
        struct server_id_buf tmp;
        char *machine_hostname = NULL;
        int result = 0;
@@ -380,33 +380,40 @@ static int traverse_sessionid(const char *key, struct sessionid *session,
 
        Ucrit_addPid(session->pid);
 
-       fstrcpy(uid_str, "-1");
-
-       if (session->uid != -1) {
-               if (numeric_only) {
-                       fstr_sprintf(uid_str, "%u", (unsigned int)session->uid);
+       if (numeric_only) {
+               fstr_sprintf(uid_gid_str, "%-12u %-12u",
+                            (unsigned int)session->uid,
+                            (unsigned int)session->gid);
+       } else {
+               if (session->uid == -1 && session->gid == -1) {
+                       /*
+                        * The session is not fully authenticated yet.
+                        */
+                       fstrcpy(uid_gid_str, "(auth in progress)");
                } else {
-                       const char *uid_name = uidtoname(session->uid);
-
-                       if (uid_name == NULL) {
-                               return -1;
+                       /*
+                        * In theory it should not happen that one of
+                        * session->uid and session->gid is valid (ie != -1)
+                        * while the other is not (ie = -1), so we a check for
+                        * that case that bails out would be reasonable.
+                        */
+                       const char *uid_name = "-1";
+                       const char *gid_name = "-1";
+
+                       if (session->uid != -1) {
+                               uid_name = uidtoname(session->uid);
+                               if (uid_name == NULL) {
+                                       return -1;
+                               }
                        }
-                       fstrcpy(uid_str, uid_name);
-               }
-       }
-
-       fstrcpy(gid_str, "-1");
-
-       if (session->gid != -1) {
-               if (numeric_only) {
-                       fstr_sprintf(gid_str, "%u", (unsigned int)session->gid);
-               } else {
-                       const char *gid_name = gidtoname(session->gid);
-
-                       if (gid_name == NULL) {
-                               return -1;
+                       if (session->gid != -1) {
+                               gid_name = gidtoname(session->gid);
+                               if (gid_name == NULL) {
+                                       return -1;
+                               }
                        }
-                       fstrcpy(gid_str, gidtoname(session->gid));
+                       fstr_sprintf(uid_gid_str, "%-12s %-12s",
+                                    uid_name, gid_name);
                }
        }
 
@@ -467,9 +474,9 @@ static int traverse_sessionid(const char *key, struct sessionid *session,
        }
 
 
-       d_printf("%-7s %-12s %-12s %-41s %-17s %-20s %-21s\n",
+       d_printf("%-7s %-25s %-41s %-17s %-20s %-21s\n",
                 server_id_str_buf(session->pid, &tmp),
-                uid_str, gid_str,
+                uid_gid_str,
                 machine_hostname,
                 session_dialect_str(session->connection_dialect),
                 encryption,