s3:connections: add a CNUM_OFFSET for mapping between cnum and the bitmap index
authorMichael Adam <obnox@samba.org>
Wed, 6 Jun 2012 13:12:08 +0000 (15:12 +0200)
committerMichael Adam <obnox@samba.org>
Wed, 6 Jun 2012 17:37:13 +0000 (19:37 +0200)
This moves the start of the range of valid cnum values up from 0 to CNUM_OFFSET
(currently 1), so that in a later step we can use 0 as invalid cnum value
instead of the current -1. This will allow us to change the type of cnum to
uint32_t from a mix of int and unsigned.

Pair-Programmed-With: Stefan Metzmacher <metze@samba.org>

source3/include/smb.h
source3/smbd/conn.c

index 732a5308ff06cf3f1bb832fed7e41b205b5a794f..5ee2b1fb44238db303c959bf7b32ae3f36851a23 100644 (file)
@@ -672,6 +672,8 @@ enum acl_compatibility {ACL_COMPAT_AUTO, ACL_COMPAT_WINNT, ACL_COMPAT_WIN2K};
 #define UID_FIELD_INVALID 0
 #define VUID_OFFSET 100 /* Amount to bias returned vuid numbers */
 
+#define CNUM_OFFSET 1 /* shift for bitmap index */
+
 /* 
  * Size of buffer to use when moving files across filesystems. 
  */
index 1344bac7a801614cb0a592fcadf19b775fdf2413..53d85531223a1341568d3409ff8b9c17eff6d4d7 100644 (file)
@@ -98,6 +98,7 @@ connection_struct *conn_new(struct smbd_server_connection *sconn)
 {
        connection_struct *conn;
        int i;
+       uint32_t cnum;
         int find_offset = 1;
 
        if (sconn->using_smb2) {
@@ -156,7 +157,8 @@ find_again:
         * which is limited to 16 bits (we skip 0xffff which is the
         * NULL TID).
         */
-       if (i > 65534) {
+       cnum = i + CNUM_OFFSET;
+       if (cnum >= 0xFFFF) {
                DEBUG(0, ("Maximum connection limit reached\n"));
                return NULL;
        }
@@ -168,7 +170,7 @@ find_again:
                return NULL;
        }
        conn->sconn = sconn;
-       conn->cnum = i;
+       conn->cnum = cnum;
        conn->force_group_gid = (gid_t)-1;
 
        bitmap_set(sconn->smb1.tcons.bmap, i);
@@ -293,12 +295,16 @@ void conn_free(connection_struct *conn)
        }
 
        if (!conn->sconn->using_smb2 &&
-           conn->sconn->smb1.tcons.bmap != NULL) {
+           conn->sconn->smb1.tcons.bmap != NULL &&
+           conn->cnum >= CNUM_OFFSET &&
+           conn->cnum < 0xFFFF)
+       {
+               int i = conn->cnum - CNUM_OFFSET;
                /*
                 * Can be NULL for fake connections created by
                 * create_conn_struct()
                 */
-               bitmap_clear(conn->sconn->smb1.tcons.bmap, conn->cnum);
+               bitmap_clear(conn->sconn->smb1.tcons.bmap, i);
        }
 
        DLIST_REMOVE(conn->sconn->connections, conn);