r16892: When we want more flexibility in configuring Samba, I think that we need to
authorVolker Lendecke <vlendec@samba.org>
Sun, 9 Jul 2006 12:17:15 +0000 (12:17 +0000)
committerVolker Lendecke <vlendec@samba.org>
Sun, 9 Jul 2006 12:17:15 +0000 (12:17 +0000)
get rid of the global share array in loadparm.c. Even right now with
usershares this is a little awkward.

Step zero in a looong way there: This encapsulates the service number in
connection_struct into a 'struct share_params'. I want to get rid of the use
of anything like an index number for a share outside of loadparm.c. Inside
loadparm.c it can be organized as an array if necessary, but the rest of Samba
should only see share names and struct share_params where we can then hide the
current share definitions or some dynamic backend or whatever.

Does this sound like a reasonable plan?

Volker

source/include/smb.h
source/include/smb_macros.h
source/smbd/conn.c
source/smbd/msdfs.c
source/smbd/open.c
source/smbd/posix_acls.c
source/smbd/service.c
source/smbd/uid.c
source/torture/cmd_vfs.c

index 492077b77051e039ca476cbb93d17d88f41b973a..3109948f59ede6747e8e2d740eae234ff45cdc90 100644 (file)
@@ -540,11 +540,15 @@ struct dfree_cached_info {
 
 struct dptr_struct;
 
+struct share_params {
+       int service;
+};
+
 typedef struct connection_struct {
        struct connection_struct *next, *prev;
        TALLOC_CTX *mem_ctx;
        unsigned cnum; /* an index passed over the wire */
-       int service;
+       struct share_params *params;
        BOOL force_user;
        BOOL force_group;
        struct vuid_cache vuid_cache;
index d3e55fe42bd59ecced64bcdd8593ffd4824e685c..e296ddd140326f097a876899eac96c72aa4577b5 100644 (file)
 /* the service number for the [globals] defaults */ 
 #define GLOBAL_SECTION_SNUM    (-1)
 /* translates a connection number into a service number */
-#define SNUM(conn)             ((conn)?(conn)->service:GLOBAL_SECTION_SNUM)
+#define SNUM(conn)             ((conn)?(conn)->params->service:GLOBAL_SECTION_SNUM)
 
 
 /* access various service details */
 #define GUEST_OK(snum)     (VALID_SNUM(snum) && lp_guest_ok(snum))
 #define GUEST_ONLY(snum)   (VALID_SNUM(snum) && lp_guest_only(snum))
 #define CAN_SETDIR(snum)   (!lp_no_set_dir(snum))
-#define CAN_PRINT(conn)    ((conn) && lp_print_ok((conn)->service))
-#define MAP_HIDDEN(conn)   ((conn) && lp_map_hidden((conn)->service))
-#define MAP_SYSTEM(conn)   ((conn) && lp_map_system((conn)->service))
-#define MAP_ARCHIVE(conn)   ((conn) && lp_map_archive((conn)->service))
+#define CAN_PRINT(conn)    ((conn) && lp_print_ok(SNUM(conn)))
+#define MAP_HIDDEN(conn)   ((conn) && lp_map_hidden(SNUM(conn)))
+#define MAP_SYSTEM(conn)   ((conn) && lp_map_system(SNUM(conn)))
+#define MAP_ARCHIVE(conn)   ((conn) && lp_map_archive(SNUM(conn)))
 #define IS_HIDDEN_PATH(conn,path)  ((conn) && is_in_path((path),(conn)->hide_list,(conn)->case_sensitive))
 #define IS_VETO_PATH(conn,path)  ((conn) && is_in_path((path),(conn)->veto_list,(conn)->case_sensitive))
 #define IS_VETO_OPLOCK_PATH(conn,path)  ((conn) && is_in_path((path),(conn)->veto_oplock_list,(conn)->case_sensitive))
index d857611c355cdbe4a2d49438ba4d7c97742de811..52182f31294949fdea3322a7dd4d78b5b74e4a04 100644 (file)
@@ -57,7 +57,7 @@ BOOL conn_snum_used(int snum)
 {
        connection_struct *conn;
        for (conn=Connections;conn;conn=conn->next) {
-               if (conn->service == snum) {
+               if (conn->params->service == snum) {
                        return(True);
                }
        }
@@ -136,8 +136,10 @@ find_again:
                return NULL;
        }
 
-       if ((conn=TALLOC_ZERO_P(mem_ctx, connection_struct))==NULL) {
+       if (!(conn=TALLOC_ZERO_P(mem_ctx, connection_struct)) ||
+           !(conn->params = TALLOC_P(mem_ctx, struct share_params))) {
                DEBUG(0,("talloc_zero() failed!\n"));
+               TALLOC_FREE(mem_ctx);
                return NULL;
        }
        conn->mem_ctx = mem_ctx;
@@ -314,7 +316,7 @@ void msg_force_tdis(int msg_type, struct process_id pid, void *buf, size_t len)
 
        for (conn=Connections;conn;conn=next) {
                next=conn->next;
-               if (strequal(lp_servicename(conn->service), sharename)) {
+               if (strequal(lp_servicename(SNUM(conn)), sharename)) {
                        DEBUG(1,("Forcing close of share %s cnum=%d\n",
                                 sharename, conn->cnum));
                        close_cnum(conn, (uint16)-1);
index b22b5674d6fd651b3357038b773d9148a282d001..69da4194fda49a31584e29dcb2ca6b1311f8d5f8 100644 (file)
@@ -135,7 +135,6 @@ static BOOL create_conn_struct(connection_struct *conn, int snum, char *path)
 
        ZERO_STRUCTP(conn);
 
-       conn->service = snum;
        pstrcpy(connpath, path);
        pstring_sub(connpath , "%S", lp_servicename(snum));
 
@@ -145,6 +144,13 @@ static BOOL create_conn_struct(connection_struct *conn, int snum, char *path)
                 DEBUG(0,("talloc_init(connection_struct) failed!\n"));
                 return False;
         }
+
+       if (!(conn->params = TALLOC_P(conn->mem_ctx, struct share_params))) {
+               DEBUG(0, ("TALLOC failed\n"));
+               return False;
+       }
+       
+       conn->params->service = snum;
        
        set_conn_connectpath(conn, connpath);
 
index 8b5d1e8f8f5c4afabbaeee756049f5821c319b39..7c04cdbe7cc43ca8b4e6b5bf95dda9a4717dc1b4 100644 (file)
@@ -1472,7 +1472,7 @@ NTSTATUS open_file_ntcreate(connection_struct *conn,
 
                                /* this is a hack to speed up torture tests
                                   in 'make test' */
-                               timeout_usecs = lp_parm_int(conn->service,
+                               timeout_usecs = lp_parm_int(SNUM(conn),
                                                            "smbd","sharedelay",
                                                            SHARING_VIOLATION_USEC_WAIT);
 
index d42822186f7bd095c9bdd0b9ff86f74076adce87..73744cf26e77b0e7e66416b2863db07ca2e5fa8a 100644 (file)
@@ -4235,12 +4235,19 @@ SEC_DESC* get_nt_acl_no_snum( TALLOC_CTX *ctx, const char *fname)
        pstring filename;
        
        ZERO_STRUCT( conn );
-       conn.service = -1;
        
        if ( !(conn.mem_ctx = talloc_init( "novfs_get_nt_acl" )) ) {
                DEBUG(0,("get_nt_acl_no_snum: talloc() failed!\n"));
                return NULL;
        }
+
+       if (!(conn.params = TALLOC_P(conn.mem_ctx, struct share_params))) {
+               DEBUG(0,("get_nt_acl_no_snum: talloc() failed!\n"));
+               TALLOC_FREE(conn.mem_ctx);
+               return NULL;
+       }
+
+       conn.params->service = -1;
        
        pstrcpy( path, "/" );
        set_conn_connectpath(&conn, path);
index 8664d806dbf2b5df011598d731ab64852a3c212a..b2c58b968ef7a4b583bdbba4eea82e4577bb9ead 100644 (file)
@@ -623,7 +623,7 @@ static connection_struct *make_connection_snum(int snum, user_struct *vuser,
                    sizeof(conn->client_address)-1);
        conn->num_files_open = 0;
        conn->lastused = conn->lastused_count = time(NULL);
-       conn->service = snum;
+       conn->params->service = snum;
        conn->used = True;
        conn->printer = (strncmp(dev,"LPT",3) == 0);
        conn->ipc = ( (strncmp(dev,"IPC",3) == 0) ||
@@ -649,7 +649,7 @@ static connection_struct *make_connection_snum(int snum, user_struct *vuser,
        string_set(&conn->dirpath,"");
        string_set(&conn->user,user);
 
-       conn->read_only = lp_readonly(conn->service);
+       conn->read_only = lp_readonly(SNUM(conn));
        conn->admin_user = False;
 
        /*
index c62c9d928abac5b2e882269c277e8fc9b941ddc2..48d7f590c399d93930e346a3a6838e13bec0c010 100644 (file)
@@ -102,7 +102,7 @@ static BOOL check_user_ok(connection_struct *conn, user_struct *vuser,int snum)
 
        readonly_share = is_share_read_only_for_token(vuser->user.unix_name,
                                                      vuser->nt_user_token,
-                                                     conn->service);
+                                                     SNUM(conn));
 
        if (!readonly_share &&
            !share_access_check(conn, snum, vuser, FILE_WRITE_DATA)) {
@@ -129,7 +129,7 @@ static BOOL check_user_ok(connection_struct *conn, user_struct *vuser,int snum)
 
        ent->admin_user = token_contains_name_in_list(
                vuser->user.unix_name, NULL, vuser->nt_user_token,
-               lp_admin_users(conn->service));
+               lp_admin_users(SNUM(conn)));
 
        conn->read_only = ent->read_only;
        conn->admin_user = ent->admin_user;
index b767a94261ad84a060991a2be61bf2813bb8b2a5..6cecd693f835497d5a857af6edd69d1cb753194b 100644 (file)
@@ -94,7 +94,7 @@ static NTSTATUS cmd_show_data(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int ar
 
 static NTSTATUS cmd_connect(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, const char **argv)
 {
-       SMB_VFS_CONNECT(vfs->conn, lp_servicename(vfs->conn->service), "vfstest");
+       SMB_VFS_CONNECT(vfs->conn, lp_servicename(SNUM(vfs->conn)), "vfstest");
        return NT_STATUS_OK;
 }