smbstatus: rework connection dialect printing
authorRalph Boehme <slow@samba.org>
Mon, 30 Nov 2015 09:48:12 +0000 (10:48 +0100)
committerRalph Boehme <slow@samba.org>
Fri, 22 Jan 2016 06:52:20 +0000 (07:52 +0100)
In a later change I want to print the signing cipher which depends upon
the connection dialect. So let's store the connection dialect in the
sessionid struct and move the code that maps dialect integers to strings
to smbstatus.

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/include/session.h
source3/lib/sessionid_tdb.c
source3/utils/status.c

index fe41954ab5058a915a3e84b92bb40fb88de9e4a0..92fc74f92a45609971668cd65ff3d2aab0cf6113 100644 (file)
@@ -38,6 +38,6 @@ struct sessionid {
        struct server_id pid;
        fstring ip_addr_str;
        time_t connect_start;
-       fstring protocol_ver;
+       uint16_t connection_dialect;
 };
 
index 68f9c43bb5dbd1b1bd19a51995cb3af0d5938b43..88a2ff2ce60157ab3c4a837e72f97cb9a2e26f15 100644 (file)
@@ -43,42 +43,9 @@ static int sessionid_traverse_read_fn(struct smbXsrv_session_global0 *global,
                .id_num = global->session_global_id,
                .connect_start = nt_time_to_unix(global->creation_time),
                .pid = global->channels[0].server_id,
+               .connection_dialect = global->connection_dialect,
        };
 
-       switch(global->connection_dialect){
-       case SMB2_DIALECT_REVISION_000:
-               fstrcpy(session.protocol_ver, "NT1");
-               break;
-       case SMB2_DIALECT_REVISION_202:
-               fstrcpy(session.protocol_ver, "SMB2_02");
-               break;
-       case SMB2_DIALECT_REVISION_210:
-               fstrcpy(session.protocol_ver, "SMB2_10");
-               break;
-       case SMB2_DIALECT_REVISION_222:
-               fstrcpy(session.protocol_ver, "SMB2_22");
-               break;
-       case SMB2_DIALECT_REVISION_224:
-               fstrcpy(session.protocol_ver, "SMB2_24");
-               break;
-       case SMB3_DIALECT_REVISION_300:
-               fstrcpy(session.protocol_ver, "SMB3_00");
-               break;
-       case SMB3_DIALECT_REVISION_302:
-               fstrcpy(session.protocol_ver, "SMB3_02");
-               break;
-       case SMB3_DIALECT_REVISION_310:
-               fstrcpy(session.protocol_ver, "SMB3_10");
-               break;
-       case SMB3_DIALECT_REVISION_311:
-               fstrcpy(session.protocol_ver, "SMB3_11");
-               break;
-       default:
-               fstr_sprintf(session.protocol_ver, "Unknown (0x%04x)",
-                            global->connection_dialect);
-               break;
-       }
-
        if (session_info != NULL) {
                session.uid = session_info->unix_token->uid;
                session.gid = session_info->unix_token->gid;
index 876e0f0f83d5ed33f0fb89fd116428b09f2c24ff..36c7023959966978eca0902488dbcc011a6f9f65 100644 (file)
@@ -266,6 +266,35 @@ static void print_brl(struct file_id id,
        TALLOC_FREE(share_mode);
 }
 
+static const char *session_dialect_str(uint16_t dialect)
+{
+       static fstring unkown_dialect;
+
+       switch(dialect){
+       case SMB2_DIALECT_REVISION_000:
+               return "NT1";
+       case SMB2_DIALECT_REVISION_202:
+               return "SMB2_02";
+       case SMB2_DIALECT_REVISION_210:
+               return "SMB2_10";
+       case SMB2_DIALECT_REVISION_222:
+               return "SMB2_22";
+       case SMB2_DIALECT_REVISION_224:
+               return "SMB2_24";
+       case SMB3_DIALECT_REVISION_300:
+               return "SMB3_00";
+       case SMB3_DIALECT_REVISION_302:
+               return "SMB3_02";
+       case SMB3_DIALECT_REVISION_310:
+               return "SMB3_10";
+       case SMB3_DIALECT_REVISION_311:
+               return "SMB3_11";
+       }
+
+       fstr_sprintf(unkown_dialect, "Unknown (0x%04x)", dialect);
+       return unkown_dialect;
+}
+
 static int traverse_connections(const struct connections_key *key,
                                const struct connections_data *crec,
                                void *state)
@@ -325,7 +354,8 @@ static int traverse_sessionid(const char *key, struct sessionid *session,
        d_printf("%-7s   %-12s  %-12s  %-12s (%s) %-12s\n",
                 server_id_str_buf(session->pid, &tmp),
                 uid_str, gid_str,
-                session->remote_machine, session->hostname, session->protocol_ver);
+                session->remote_machine, session->hostname,
+                session_dialect_str(session->connection_dialect));
 
        return 0;
 }