s3:smbd: remove dirptr and dirpath from connection_struct
authorStefan Metzmacher <metze@samba.org>
Fri, 7 Aug 2009 07:31:45 +0000 (09:31 +0200)
committerStefan Metzmacher <metze@samba.org>
Fri, 7 Aug 2009 12:18:17 +0000 (14:18 +0200)
They're both only used in the context of a function,
so we can make them stack variables.

metze

source3/include/proto.h
source3/include/smb.h
source3/smbd/conn.c
source3/smbd/dir.c
source3/smbd/reply.c
source3/smbd/service.c
source3/smbd/trans2.c

index e4523a1625b89883c2b05f47478e46e7d26530e7..b00a08446ad8279a26cd2371b77b50697264d184 100644 (file)
@@ -6208,7 +6208,7 @@ struct dptr_struct *dptr_fetch(char *buf,int *num);
 struct dptr_struct *dptr_fetch_lanman2(int dptr_num);
 bool dir_check_ftype(connection_struct *conn, uint32 mode, uint32 dirtype);
 bool get_dir_entry(TALLOC_CTX *ctx,
-               connection_struct *conn,
+               struct dptr_struct *dirptr,
                const char *mask,
                uint32 dirtype,
                char **pp_fname_out,
index c33c5363f3f3e46f39b06d1c946670652bb8e0bb..b53735d36d0767505699b771ff85420fae46d11a 100644 (file)
@@ -551,12 +551,10 @@ typedef struct connection_struct {
        struct share_params *params;
        bool force_user;
        struct vuid_cache vuid_cache;
-       struct dptr_struct *dirptr;
        bool printer;
        bool ipc;
        bool read_only; /* Attributes for the current user of the share. */
        bool admin_user; /* Attributes for the current user of the share. */
-       char *dirpath;
        char *connectpath;
        char *origpath;
 
index da67db978bd0f6ed5045d64af34313b402b3f6c8..959fcd7754de3f6de6bc432c34b5c663135592da 100644 (file)
@@ -163,7 +163,6 @@ find_again:
 
        sconn->smb1.tcons.num_open++;
 
-       string_set(&conn->dirpath,"");
        string_set(&conn->connectpath,"");
        string_set(&conn->origpath,"");
        
@@ -284,7 +283,6 @@ static void conn_free_internal(connection_struct *conn)
        free_namearray(conn->veto_oplock_list);
        free_namearray(conn->aio_write_behind_list);
        
-       string_free(&conn->dirpath);
        string_free(&conn->connectpath);
        string_free(&conn->origpath);
 
index e2f8e694494c72642a446340423ad3fbb546dc6a..1c84decbde1d88f1cbe6694318d836a5e0301bcd 100644 (file)
@@ -407,8 +407,6 @@ NTSTATUS dptr_create(connection_struct *conn, const char *path, bool old_handle,
                return map_nt_error_from_unix(errno);
        }
 
-       string_set(&conn->dirpath,path);
-
        if (dirhandles_open >= MAX_OPEN_DIRECTORIES) {
                dptr_idleoldest();
        }
@@ -1030,7 +1028,7 @@ static bool smbd_dirptr_8_3_mode_fn(TALLOC_CTX *ctx,
 }
 
 bool get_dir_entry(TALLOC_CTX *ctx,
-               connection_struct *conn,
+               struct dptr_struct *dirptr,
                const char *mask,
                uint32_t dirtype,
                char **_fname,
@@ -1040,18 +1038,15 @@ bool get_dir_entry(TALLOC_CTX *ctx,
                bool check_descend,
                bool ask_sharemode)
 {
+       connection_struct *conn = dirptr->conn;
        char *fname = NULL;
        struct smb_filename *smb_fname = NULL;
        uint32_t mode = 0;
        long prev_offset;
        bool ok;
 
-       if (!conn->dirptr) {
-               return false;
-       }
-
        ok = smbd_dirptr_get_entry(ctx,
-                                  conn->dirptr,
+                                  dirptr,
                                   mask,
                                   dirtype,
                                   check_descend,
index 750915b1cb4576b2c59f67beba4e8ad5ad421174..f6028a3eef350082d3bfe9bf7ca87bca477165c3 100644 (file)
@@ -1366,6 +1366,7 @@ void reply_search(struct smb_request *req)
        bool allow_long_path_components = (req->flags2 & FLAGS2_LONG_PATH_COMPONENTS) ? True : False;
        TALLOC_CTX *ctx = talloc_tos();
        bool ask_sharemode = lp_parm_bool(SNUM(conn), "smbd", "search ask sharemode", true);
+       struct dptr_struct *dirptr = NULL;
 
        START_PROFILE(SMBsearch);
 
@@ -1446,14 +1447,15 @@ void reply_search(struct smb_request *req)
                                        mask,
                                        mask_contains_wcard,
                                        dirtype,
-                                       &conn->dirptr);
+                                       &dirptr);
                if (!NT_STATUS_IS_OK(nt_status)) {
                        reply_nterror(req, nt_status);
                        goto out;
                }
-               dptr_num = dptr_dnum(conn->dirptr);
+               dptr_num = dptr_dnum(dirptr);
        } else {
                int status_dirtype;
+               const char *dirpath;
 
                memcpy(status,p,21);
                status_dirtype = CVAL(status,0) & 0x1F;
@@ -1461,11 +1463,17 @@ void reply_search(struct smb_request *req)
                        dirtype = status_dirtype;
                }
 
-               conn->dirptr = dptr_fetch(status+12,&dptr_num);
-               if (!conn->dirptr) {
+               dirptr = dptr_fetch(status+12,&dptr_num);
+               if (!dirptr) {
                        goto SearchEmpty;
                }
-               string_set(&conn->dirpath,dptr_path(dptr_num));
+               dirpath = dptr_path(dptr_num);
+               directory = talloc_strdup(ctx, dirpath);
+               if (!directory) {
+                       reply_nterror(req, NT_STATUS_NO_MEMORY);
+                       goto out;
+               }
+
                mask = dptr_wcard(dptr_num);
                if (!mask) {
                        goto SearchEmpty;
@@ -1481,7 +1489,7 @@ void reply_search(struct smb_request *req)
        DEBUG(4,("dptr_num is %d\n",dptr_num));
 
        /* Initialize per SMBsearch/SMBffirst/SMBfunique operation data */
-       dptr_init_search_op(conn->dirptr);
+       dptr_init_search_op(dirptr);
 
        if ((dirtype&0x1F) == aVOLID) {
                char buf[DIR_STRUCT_SIZE];
@@ -1512,14 +1520,14 @@ void reply_search(struct smb_request *req)
                         /DIR_STRUCT_SIZE));
 
                DEBUG(8,("dirpath=<%s> dontdescend=<%s>\n",
-                       conn->dirpath,lp_dontdescend(SNUM(conn))));
-               if (in_list(conn->dirpath, lp_dontdescend(SNUM(conn)),True)) {
+                       directory,lp_dontdescend(SNUM(conn))));
+               if (in_list(directory, lp_dontdescend(SNUM(conn)),True)) {
                        check_descend = True;
                }
 
                for (i=numentries;(i<maxentries) && !finished;i++) {
                        finished = !get_dir_entry(ctx,
-                                                 conn,
+                                                 dirptr,
                                                  mask,
                                                  dirtype,
                                                  &fname,
@@ -1597,18 +1605,15 @@ void reply_search(struct smb_request *req)
        SSVAL(req->outbuf, smb_flg2,
              (SVAL(req->outbuf, smb_flg2) & (~FLAGS2_UNICODE_STRINGS)));
 
-       if (!directory) {
-               directory = dptr_path(dptr_num);
-       }
-
        DEBUG(4,("%s mask=%s path=%s dtype=%d nument=%u of %u\n",
                smb_fn_name(req->cmd),
                mask,
-               directory ? directory : "./",
+               directory,
                dirtype,
                numentries,
                maxentries ));
  out:
+       TALLOC_FREE(directory);
        TALLOC_FREE(smb_fname);
        END_PROFILE(SMBsearch);
        return;
index c24b2264c1d0ecf17c4f88195d20e7ce5cf258bb..fc56105adf8a92b71f60e5fb4462cbd35ff26228 100644 (file)
@@ -692,7 +692,6 @@ connection_struct *make_connection_snum(struct smbd_server_connection *sconn,
        conn->printer = (strncmp(dev,"LPT",3) == 0);
        conn->ipc = ( (strncmp(dev,"IPC",3) == 0) ||
                      ( lp_enable_asu_support() && strequal(dev,"ADMIN$")) );
-       conn->dirptr = NULL;
 
        /* Case options for the share. */
        if (lp_casesensitive(snum) == Auto) {
@@ -712,7 +711,6 @@ connection_struct *make_connection_snum(struct smbd_server_connection *sconn,
        conn->hide_list = NULL;
        conn->veto_oplock_list = NULL;
        conn->aio_write_behind_list = NULL;
-       string_set(&conn->dirpath,"");
 
        conn->read_only = lp_readonly(SNUM(conn));
        conn->admin_user = False;
index e48ffac1502e8180d5a94534f9bc75cecc638639..3f93b3d5714d5eb66ae009f7dd27d6012bd80c44 100644 (file)
@@ -1448,6 +1448,7 @@ static bool smbd_dirptr_lanman2_mode_fn(TALLOC_CTX *ctx,
 
 static bool get_lanman2_dir_entry(TALLOC_CTX *ctx,
                                connection_struct *conn,
+                               struct dptr_struct *dirptr,
                                uint16 flags2,
                                const char *path_mask,
                                uint32 dirtype,
@@ -1487,7 +1488,7 @@ static bool get_lanman2_dir_entry(TALLOC_CTX *ctx,
        state.conn = conn;
        state.info_level = info_level;
        state.check_mangled_names = lp_manglednames(conn->params);
-       state.has_wild = dptr_has_wild(conn->dirptr);
+       state.has_wild = dptr_has_wild(dirptr);
        state.got_exact_match = false;
 
        *out_of_space = False;
@@ -1497,10 +1498,6 @@ static bool get_lanman2_dir_entry(TALLOC_CTX *ctx,
        ZERO_STRUCT(adate_ts);
        ZERO_STRUCT(create_date_ts);
 
-       if (!conn->dirptr) {
-               return false;
-       }
-
        p = strrchr_m(path_mask,'/');
        if(p != NULL) {
                if(p[1] == '\0') {
@@ -1513,7 +1510,7 @@ static bool get_lanman2_dir_entry(TALLOC_CTX *ctx,
        }
 
        ok = smbd_dirptr_get_entry(ctx,
-                                  conn->dirptr,
+                                  dirptr,
                                   mask,
                                   dirtype,
                                   dont_descend,
@@ -1666,7 +1663,7 @@ static bool get_lanman2_dir_entry(TALLOC_CTX *ctx,
                                TALLOC_FREE(fname);
                                TALLOC_FREE(smb_fname);
                                /* Move the dirptr back to prev_dirpos */
-                               dptr_SeekDir(conn->dirptr, prev_dirpos);
+                               dptr_SeekDir(dirptr, prev_dirpos);
                                *out_of_space = True;
                                DEBUG(9,("get_lanman2_dir_entry: out of space\n"));
                                return False; /* Not finished - just out of space */
@@ -1964,7 +1961,7 @@ static bool get_lanman2_dir_entry(TALLOC_CTX *ctx,
 
        if (PTR_DIFF(p,pdata) > space_remaining) {
                /* Move the dirptr back to prev_dirpos */
-               dptr_SeekDir(conn->dirptr, prev_dirpos);
+               dptr_SeekDir(dirptr, prev_dirpos);
                *out_of_space = True;
                DEBUG(9,("get_lanman2_dir_entry: out of space\n"));
                return False; /* Not finished - just out of space */
@@ -2020,6 +2017,7 @@ static void call_trans2findfirst(connection_struct *conn,
        NTSTATUS ntstatus = NT_STATUS_OK;
        bool ask_sharemode = lp_parm_bool(SNUM(conn), "smbd", "search ask sharemode", true);
        TALLOC_CTX *ctx = talloc_tos();
+       struct dptr_struct *dirptr = NULL;
 
        if (total_params < 13) {
                reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
@@ -2177,24 +2175,25 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
                                mask,
                                mask_contains_wcard,
                                dirtype,
-                               &conn->dirptr);
+                               &dirptr);
 
        if (!NT_STATUS_IS_OK(ntstatus)) {
                reply_nterror(req, ntstatus);
                goto out;
        }
 
-       dptr_num = dptr_dnum(conn->dirptr);
+       dptr_num = dptr_dnum(dirptr);
        DEBUG(4,("dptr_num is %d, wcard = %s, attr = %d\n", dptr_num, mask, dirtype));
 
        /* Initialize per TRANS2_FIND_FIRST operation data */
-       dptr_init_search_op(conn->dirptr);
+       dptr_init_search_op(dirptr);
 
        /* We don't need to check for VOL here as this is returned by
                a different TRANS2 call. */
 
-       DEBUG(8,("dirpath=<%s> dontdescend=<%s>\n", conn->dirpath,lp_dontdescend(SNUM(conn))));
-       if (in_list(conn->dirpath,lp_dontdescend(SNUM(conn)),conn->case_sensitive))
+       DEBUG(8,("dirpath=<%s> dontdescend=<%s>\n",
+               directory,lp_dontdescend(SNUM(conn))));
+       if (in_list(directory,lp_dontdescend(SNUM(conn)),conn->case_sensitive))
                dont_descend = True;
 
        p = pdata;
@@ -2212,6 +2211,7 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
                } else {
                        finished = !get_lanman2_dir_entry(ctx,
                                        conn,
+                                       dirptr,
                                        req->flags2,
                                        mask,dirtype,info_level,
                                        requires_resume_key,dont_descend,
@@ -2355,6 +2355,7 @@ static void call_trans2findnext(connection_struct *conn,
        NTSTATUS ntstatus = NT_STATUS_OK;
        bool ask_sharemode = lp_parm_bool(SNUM(conn), "smbd", "search ask sharemode", true);
        TALLOC_CTX *ctx = talloc_tos();
+       struct dptr_struct *dirptr;
 
        if (total_params < 13) {
                reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
@@ -2476,12 +2477,12 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
        params = *pparams;
 
        /* Check that the dptr is valid */
-       if(!(conn->dirptr = dptr_fetch_lanman2(dptr_num))) {
+       if(!(dirptr = dptr_fetch_lanman2(dptr_num))) {
                reply_doserror(req, ERRDOS, ERRnofiles);
                return;
        }
 
-       string_set(&conn->dirpath,dptr_path(dptr_num));
+       directory = dptr_path(dptr_num);
 
        /* Get the wildcard mask from the dptr */
        if((p = dptr_wcard(dptr_num))== NULL) {
@@ -2491,24 +2492,24 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
        }
 
        mask = p;
-       directory = conn->dirpath;
 
        /* Get the attr mask from the dptr */
        dirtype = dptr_attr(dptr_num);
 
        DEBUG(3,("dptr_num is %d, mask = %s, attr = %x, dirptr=(0x%lX,%ld)\n",
                dptr_num, mask, dirtype,
-               (long)conn->dirptr,
-               dptr_TellDir(conn->dirptr)));
+               (long)dirptr,
+               dptr_TellDir(dirptr)));
 
        /* Initialize per TRANS2_FIND_NEXT operation data */
-       dptr_init_search_op(conn->dirptr);
+       dptr_init_search_op(dirptr);
 
        /* We don't need to check for VOL here as this is returned by
                a different TRANS2 call. */
 
-       DEBUG(8,("dirpath=<%s> dontdescend=<%s>\n",conn->dirpath,lp_dontdescend(SNUM(conn))));
-       if (in_list(conn->dirpath,lp_dontdescend(SNUM(conn)),conn->case_sensitive))
+       DEBUG(8,("dirpath=<%s> dontdescend=<%s>\n",
+                directory,lp_dontdescend(SNUM(conn))));
+       if (in_list(directory,lp_dontdescend(SNUM(conn)),conn->case_sensitive))
                dont_descend = True;
 
        p = pdata;
@@ -2550,7 +2551,7 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
                 * should already be at the correct place.
                 */
 
-               finished = !dptr_SearchDir(conn->dirptr, resume_name, &current_pos, &st);
+               finished = !dptr_SearchDir(dirptr, resume_name, &current_pos, &st);
        } /* end if resume_name && !continue_bit */
 
        for (i=0;(i<(int)maxentries) && !finished && !out_of_space ;i++) {
@@ -2564,6 +2565,7 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
                } else {
                        finished = !get_lanman2_dir_entry(ctx,
                                                conn,
+                                               dirptr,
                                                req->flags2,
                                                mask,dirtype,info_level,
                                                requires_resume_key,dont_descend,