Remove the explicit TALLOC_CTX * from cli_struct.
authorJeremy Allison <jra@samba.org>
Thu, 29 Nov 2007 21:24:54 +0000 (13:24 -0800)
committerJeremy Allison <jra@samba.org>
Thu, 29 Nov 2007 21:24:54 +0000 (13:24 -0800)
Make us very explicit about how long a talloc ctx
should last.
Jeremy.
(This used to be commit ba9e2be2b5a59684e854609f9d82ea1633448c62)

18 files changed:
source3/include/client.h
source3/include/smb.h
source3/lib/time.c
source3/libsmb/cliconnect.c
source3/libsmb/clidfs.c
source3/libsmb/clientgen.c
source3/libsmb/clierror.c
source3/libsmb/clioplock.c
source3/libsmb/cliprint.c
source3/libsmb/clirap.c
source3/libsmb/libsmbclient.c
source3/libsmb/passchange.c
source3/rpc_client/cli_pipe.c
source3/rpc_server/srv_spoolss_nt.c
source3/smbd/change_trust_pw.c
source3/utils/smbcquotas.c
source3/utils/smbtree.c
source3/winbindd/winbindd_cm.c

index dd8bb0dba917661195607ad0852eb60ae9ab8f00..c601e1a91c6ba32f3d696d4610b3cc575fb31184 100644 (file)
@@ -135,7 +135,10 @@ struct cli_state {
        uint32 posix_capabilities;
        bool dfsroot;
 
-       TALLOC_CTX *mem_ctx;
+#if 0
+       TALLOC_CTX *longterm_mem_ctx;
+       TALLOC_CTX *call_mem_ctx;
+#endif
 
        smb_sign_info sign_info;
 
@@ -170,8 +173,8 @@ typedef struct file_info {
        struct timespec mtime_ts;
        struct timespec atime_ts;
        struct timespec ctime_ts;
-       pstring name;
-       pstring dir;
+       char name[1024];
+       char dir[1024]; /* Should use allocated PATH_MAX here.... */
        char short_name[13*3]; /* the *3 is to cope with multi-byte */
 } file_info;
 
index be339f2e3862b61146e744481847637a9a30e352..f85c7344bc749dda0e68c0b5f8c3f816e599db22 100644 (file)
@@ -79,6 +79,7 @@ enum smb_read_errors {
        SMB_READ_ERROR,
        SMB_WRITE_ERROR, /* This error code can go into the client smb_rw_error. */
        SMB_READ_BAD_SIG,
+       SMB_NO_MEMORY,
        SMB_DO_NOT_DO_TDIS /* cli_close_connection() check for this when smbfs wants to keep tree connected */
 };
 
index e29308fcd0d92f3350336fd41096b5fcf74069f6..5301e3a55a4049bd6908ecc90cb13e76eb08e9c0 100644 (file)
@@ -1181,17 +1181,17 @@ void cli_put_dos_date3(struct cli_state *cli, char *buf, int offset, time_t unix
        put_dos_date3(buf, offset, unixdate, cli->serverzone);
 }
 
-time_t cli_make_unix_date(struct cli_state *cli, void *date_ptr)
+time_t cli_make_unix_date(struct cli_state *cli, const void *date_ptr)
 {
        return make_unix_date(date_ptr, cli->serverzone);
 }
 
-time_t cli_make_unix_date2(struct cli_state *cli, void *date_ptr)
+time_t cli_make_unix_date2(struct cli_state *cli, const void *date_ptr)
 {
        return make_unix_date2(date_ptr, cli->serverzone);
 }
 
-time_t cli_make_unix_date3(struct cli_state *cli, void *date_ptr)
+time_t cli_make_unix_date3(struct cli_state *cli, const void *date_ptr)
 {
        return make_unix_date3(date_ptr, cli->serverzone);
 }
index f0b03a85cf222f54cfaf5878bbfac057534afdf6..e3800bfb33e2a6e671ed52354c8f7d27c0cad711 100644 (file)
@@ -1803,13 +1803,18 @@ struct cli_state *get_ipc_connect(char *server,
  * entire network browse list)
  */
 
-struct cli_state *get_ipc_connect_master_ip(struct ip_service *mb_ip, pstring workgroup, struct user_auth_info *user_info)
+struct cli_state *get_ipc_connect_master_ip(TALLOC_CTX *ctx,
+                               struct ip_service *mb_ip,
+                               struct user_auth_info *user_info,
+                               char **pp_workgroup_out)
 {
        char addr[INET6_ADDRSTRLEN];
         fstring name;
        struct cli_state *cli;
        struct sockaddr_storage server_ss;
 
+       *pp_workgroup_out = NULL;
+
        print_sockaddr(addr, sizeof(addr), &mb_ip->ss);
         DEBUG(99, ("Looking up name of master browser %s\n",
                    addr));
@@ -1838,7 +1843,7 @@ struct cli_state *get_ipc_connect_master_ip(struct ip_service *mb_ip, pstring wo
                 return NULL;
         }
 
-       pstrcpy(workgroup, name);
+       *pp_workgroup_out = talloc_strdup(ctx, name);
 
        DEBUG(4, ("found master browser %s, %s\n", name, addr));
 
@@ -1853,12 +1858,16 @@ struct cli_state *get_ipc_connect_master_ip(struct ip_service *mb_ip, pstring wo
  * connect to it.
  */
 
-struct cli_state *get_ipc_connect_master_ip_bcast(pstring workgroup, struct user_auth_info *user_info)
+struct cli_state *get_ipc_connect_master_ip_bcast(TALLOC_CTX *ctx,
+                                       struct user_auth_info *user_info,
+                                       char **pp_workgroup_out)
 {
        struct ip_service *ip_list;
        struct cli_state *cli;
        int i, count;
 
+       *pp_workgroup_out = NULL;
+
         DEBUG(99, ("Do broadcast lookup for workgroups on local network\n"));
 
         /* Go looking for workgroups by broadcasting on the local network */
@@ -1874,7 +1883,8 @@ struct cli_state *get_ipc_connect_master_ip_bcast(pstring workgroup, struct user
                print_sockaddr(addr, sizeof(addr), &ip_list[i].ss);
                DEBUG(99, ("Found master browser %s\n", addr));
 
-               cli = get_ipc_connect_master_ip(&ip_list[i], workgroup, user_info);
+               cli = get_ipc_connect_master_ip(ctx, &ip_list[i],
+                               user_info, pp_workgroup_out);
                if (cli)
                        return(cli);
        }
index 037c0d6b26b1f67e87922ab7a0c5f969d7566699..469cb231d2a321c3a568f39ed74efa8fc962b595 100644 (file)
@@ -245,9 +245,12 @@ static struct cli_state *cli_cm_connect( const char *server,
                                        bool show_hdr)
 {
        struct client_connection *node;
-       
-       node = SMB_XMALLOC_P( struct client_connection );
-       
+
+       node = SMB_CALLOC_ARRAY( struct client_connection, 1);
+       if (!node) {
+               return NULL;
+       }
+
        node->cli = do_connect( server, share, show_hdr );
 
        if ( !node->cli ) {
index ee1a0fe3dbfc72e762d0b005822a0a43c82d56c0..1a6fb8f93fb9149dfe4ce1377a861f05ca74582d 100644 (file)
@@ -492,9 +492,6 @@ struct cli_state *cli_initialise(void)
        if (!cli->outbuf || !cli->inbuf)
                 goto error;
 
-       if ((cli->mem_ctx = talloc_init("cli based talloc")) == NULL)
-                goto error;
-
        memset(cli->outbuf, 0, cli->bufsize);
        memset(cli->inbuf, 0, cli->bufsize);
 
@@ -605,11 +602,6 @@ void cli_shutdown(struct cli_state *cli)
        data_blob_free(&cli->secblob);
        data_blob_free(&cli->user_session_key);
 
-       if (cli->mem_ctx) {
-               talloc_destroy(cli->mem_ctx);
-               cli->mem_ctx = NULL;
-       }
-
        if (cli->fd != -1) {
                close(cli->fd);
        }
index c9c5a6cd302eac1133cb45642ac744feb8477c42..587abade59dc212dee4a5f29287848c1aca99f6f 100644 (file)
@@ -84,6 +84,8 @@ static NTSTATUS cli_smb_rw_error_to_ntstatus(struct cli_state *cli)
                        return NT_STATUS_UNEXPECTED_NETWORK_ERROR;
                case SMB_READ_BAD_SIG:
                        return NT_STATUS_INVALID_PARAMETER;
+               case SMB_NO_MEMORY:
+                       return NT_STATUS_NO_MEMORY;
                default:
                        break;
        }
@@ -133,6 +135,10 @@ const char *cli_errstr(struct cli_state *cli)
                                slprintf(cli_error_message, sizeof(cli_error_message) - 1,
                                        "Server packet had invalid SMB signature!");
                                break;
+                       case SMB_NO_MEMORY:
+                               slprintf(cli_error_message, sizeof(cli_error_message) - 1,
+                                       "Out of memory");
+                               break;
                        default:
                                slprintf(cli_error_message, sizeof(cli_error_message) - 1,
                                        "Unknown error code %d\n", cli->smb_rw_error );
index effd4a5565aed10530565d376b51b1ffdcb94f41..2e54f5a781b1fc5ba4c5e897bd40e1c7e3de8ea6 100644 (file)
 /****************************************************************************
 send an ack for an oplock break request
 ****************************************************************************/
+
 bool cli_oplock_ack(struct cli_state *cli, int fnum, unsigned char level)
 {
        char *oldbuf = cli->outbuf;
-       pstring buf;
+       char buf[smb_size+16];
        bool ret;
 
        cli->outbuf = buf;
@@ -47,7 +48,7 @@ bool cli_oplock_ack(struct cli_state *cli, int fnum, unsigned char level)
        SSVAL(buf,smb_vwv6,0); /* unlockcount */
        SSVAL(buf,smb_vwv7,0); /* lockcount */
 
-        ret = cli_send_smb(cli);       
+        ret = cli_send_smb(cli);
 
        cli->outbuf = oldbuf;
 
index cab890b08bda6ed9648e182e637bebbe86fdeba5..7fbdb97c016daaf7130b10d2ec0cef19f38e35c5 100644 (file)
@@ -1,18 +1,18 @@
-/* 
+/*
    Unix SMB/CIFS implementation.
    client print routines
    Copyright (C) Andrew Tridgell 1994-1998
-   
+
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
-   
+
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
-   
+
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 /*****************************************************************************
  Convert a character pointer in a cli_call_api() response to a form we can use.
- This function contains code to prevent core dumps if the server returns 
+ This function contains code to prevent core dumps if the server returns
  invalid data.
 *****************************************************************************/
-static const char *fix_char_ptr(unsigned int datap, unsigned int converter, 
+static const char *fix_char_ptr(unsigned int datap, unsigned int converter,
                          char *rdata, int rdrcnt)
 {
-       if (datap == 0) {       /* turn NULL pointers into zero length strings */
+       if (datap == 0) {
+               /* turn NULL pointers into zero length strings */
                return "";
        } else {
                unsigned int offset = datap - converter;
@@ -42,41 +43,41 @@ static const char *fix_char_ptr(unsigned int datap, unsigned int converter,
        }
 }
 
-
 /****************************************************************************
 call fn() on each entry in a print queue
 ****************************************************************************/
-int cli_print_queue(struct cli_state *cli, 
+
+int cli_print_queue(struct cli_state *cli,
                    void (*fn)(struct print_job_info *))
 {
        char *rparam = NULL;
        char *rdata = NULL;
        char *p;
        unsigned int rdrcnt, rprcnt;
-       pstring param;
+       char param[1024];
        int result_code=0;
        int i = -1;
-       
+
        memset(param,'\0',sizeof(param));
 
        p = param;
        SSVAL(p,0,76);         /* API function number 76 (DosPrintJobEnum) */
        p += 2;
-       pstrcpy_base(p,"zWrLeh", param);   /* parameter description? */
+       safe_strcpy_base(p,"zWrLeh", param, sizeof(param));   /* parameter description? */
        p = skip_string(param,sizeof(param),p);
-       pstrcpy_base(p,"WWzWWDDzz", param);  /* returned data format */
+       safe_strcpy_base(p,"WWzWWDDzz", param, sizeof(param));  /* returned data format */
        p = skip_string(param,sizeof(param),p);
-       pstrcpy_base(p,cli->share, param);    /* name of queue */
+       safe_strcpy_base(p,cli->share, param, sizeof(param));    /* name of queue */
        p = skip_string(param,sizeof(param),p);
        SSVAL(p,0,2);   /* API function level 2, PRJINFO_2 data structure */
        SSVAL(p,2,1000); /* size of bytes of returned data buffer */
        p += 4;
-       pstrcpy_base(p,"", param);   /* subformat */
+       safe_strcpy_base(p,"", param,sizeof(param));   /* subformat */
        p = skip_string(param,sizeof(param),p);
 
        DEBUG(4,("doing cli_print_queue for %s\n", cli->share));
 
-       if (cli_api(cli, 
+       if (cli_api(cli,
                    param, PTR_DIFF(p,param), 1024,  /* Param, length, maxlen */
                    NULL, 0, CLI_BUFFER_SIZE,            /* data, length, maxlen */
                    &rparam, &rprcnt,                /* return params, length */
@@ -87,21 +88,21 @@ int cli_print_queue(struct cli_state *cli,
 
                if (result_code == 0) {
                        struct print_job_info job;
-                       
-                       p = rdata; 
+
+                       p = rdata;
 
                        for (i = 0; i < SVAL(rparam,4); ++i) {
                                job.id = SVAL(p,0);
                                job.priority = SVAL(p,2);
                                fstrcpy(job.user,
-                                       fix_char_ptr(SVAL(p,4), converter, 
+                                       fix_char_ptr(SVAL(p,4), converter,
                                                     rdata, rdrcnt));
                                job.t = cli_make_unix_date3(cli, p + 12);
                                job.size = IVAL(p,16);
-                               fstrcpy(job.name,fix_char_ptr(SVAL(p,24), 
-                                                             converter, 
+                               fstrcpy(job.name,fix_char_ptr(SVAL(p,24),
+                                                             converter,
                                                              rdata, rdrcnt));
-                               fn(&job);                               
+                               fn(&job);
                                p += 28;
                        }
                }
@@ -117,6 +118,7 @@ int cli_print_queue(struct cli_state *cli,
 /****************************************************************************
   cancel a print job
   ****************************************************************************/
+
 int cli_printjob_del(struct cli_state *cli, int job)
 {
        char *rparam = NULL;
@@ -124,21 +126,21 @@ int cli_printjob_del(struct cli_state *cli, int job)
        char *p;
        unsigned int rdrcnt,rprcnt;
        int ret = -1;
-       pstring param;
+       char param[1024];
 
        memset(param,'\0',sizeof(param));
 
        p = param;
        SSVAL(p,0,81);          /* DosPrintJobDel() */
        p += 2;
-       pstrcpy_base(p,"W", param);
+       safe_strcpy_base(p,"W", param,sizeof(param));
        p = skip_string(param,sizeof(param),p);
-       pstrcpy_base(p,"", param);
+       safe_strcpy_base(p,"", param,sizeof(param));
        p = skip_string(param,sizeof(param),p);
-       SSVAL(p,0,job);     
+       SSVAL(p,0,job);
        p += 2;
-       
-       if (cli_api(cli, 
+
+       if (cli_api(cli,
                    param, PTR_DIFF(p,param), 1024,  /* Param, length, maxlen */
                    NULL, 0, CLI_BUFFER_SIZE,            /* data, length, maxlen */
                    &rparam, &rprcnt,                /* return params, length */
@@ -178,7 +180,7 @@ int cli_spl_open(struct cli_state *cli, const char *fname, int flags, int share_
                accessmode |= 2;
        } else if ((flags & O_ACCMODE) == O_WRONLY) {
                accessmode |= 1;
-       } 
+       }
 
 #if defined(O_SYNC)
        if ((flags & O_SYNC) == O_SYNC) {
@@ -213,7 +215,7 @@ int cli_spl_open(struct cli_state *cli, const char *fname, int flags, int share_
                        FLAG_REQUEST_OPLOCK|FLAG_REQUEST_BATCH_OPLOCK);
                SSVAL(cli->outbuf,smb_vwv2,SVAL(cli->outbuf,smb_vwv2) | 6);
        }
-  
+
        p = smb_buf(cli->outbuf);
        p += clistr_push(cli, p, fname, -1, STR_TERMINATE);
 
@@ -256,5 +258,3 @@ bool cli_spl_close(struct cli_state *cli, int fnum)
 
        return !cli_is_error(cli);
 }
-
-
index 848a8d54822dee08dd4234eb7c7e12528d3ebe18..c877dfa2abecdebb9705d838c0b38af53bdc0ad5 100644 (file)
@@ -399,7 +399,7 @@ bool cli_qpathinfo(struct cli_state *cli, const char *fname,
        char *rparam=NULL, *rdata=NULL;
        int count=8;
        bool ret;
-       time_t (*date_fn)(struct cli_state *, void *);
+       time_t (*date_fn)(struct cli_state *, const void *);
        char *p;
 
        p = param;
index ee560b65c34e44beddee097cc3653dc380f50ef1..4f2503731d7ced21275bd68d6cb339af03bbb5c7 100644 (file)
@@ -1008,7 +1008,7 @@ smbc_attr_server(SMBCCTX *context,
         
                         nt_status = rpccli_lsa_open_policy(
                                 pipe_hnd,
-                                ipc_srv->cli->mem_ctx,
+                                talloc_tos(),
                                 True, 
                                 GENERIC_EXECUTE_ACCESS,
                                 pol);
@@ -1964,7 +1964,7 @@ smbc_lseek_ctx(SMBCCTX *context,
        fstring server, share, user, password;
        pstring path, targetpath;
        struct cli_state *targetcli;
-       TALLOC_CTX *frame = talloc_tos();
+       TALLOC_CTX *frame = talloc_stackframe();
 
        if (!context || !context->internal ||
            !context->internal->_initialized) {
@@ -2767,18 +2767,23 @@ smbc_opendir_ctx(SMBCCTX *context,
 
                 for (i = 0; i < count && i < max_lmb_count; i++) {
                        char addr[INET6_ADDRSTRLEN];
+                       char *wg_ptr = NULL;
+
                        print_sockaddr(addr, sizeof(addr), &ip_list[i].ss);
                         DEBUG(99, ("Found master browser %d of %d: %s\n",
                                    i+1, MAX(count, max_lmb_count),
                                    addr));
 
-                        cli = get_ipc_connect_master_ip(&ip_list[i],
-                                                        workgroup, &u_info);
+                        cli = get_ipc_connect_master_ip(talloc_tos(),
+                                                       &ip_list[i],
+                                                        &u_info,
+                                                       &wg_ptr);
                        /* cli == NULL is the master browser refused to talk or
                           could not be found */
                        if ( !cli )
                                continue;
 
+                       pstrcpy(workgroup, wg_ptr);
                         fstrcpy(server, cli->desthost);
                         cli_shutdown(cli);
 
@@ -3089,7 +3094,7 @@ static int
 smbc_closedir_ctx(SMBCCTX *context,
                   SMBCFILE *dir)
 {
-       TALLOC_CTX *frame = talloc_tos();
+       TALLOC_CTX *frame = talloc_stackframe();
 
         if (!context || !context->internal ||
            !context->internal->_initialized) {
@@ -4025,6 +4030,8 @@ convert_sid_to_string(struct cli_state *ipc_cli,
        char **names = NULL;
        enum lsa_SidType *types = NULL;
        struct rpc_pipe_client *pipe_hnd = find_lsa_pipe_hnd(ipc_cli);
+       TALLOC_CTX *ctx;
+
        sid_to_string(str, sid);
 
        if (numeric) {
@@ -4037,13 +4044,17 @@ convert_sid_to_string(struct cli_state *ipc_cli,
  
        /* Ask LSA to convert the sid to a name */
 
-       if (!NT_STATUS_IS_OK(rpccli_lsa_lookup_sids(pipe_hnd, ipc_cli->mem_ctx,  
+       ctx = talloc_stackframe();
+
+       if (!NT_STATUS_IS_OK(rpccli_lsa_lookup_sids(pipe_hnd, ctx,
                                                 pol, 1, sid, &domains, 
                                                 &names, &types)) ||
            !domains || !domains[0] || !names || !names[0]) {
+               TALLOC_FREE(ctx);
                return;
        }
 
+       TALLOC_FREE(ctx);
        /* Converted OK */
 
        slprintf(str, sizeof(fstring) - 1, "%s%s%s",
@@ -4062,6 +4073,7 @@ convert_string_to_sid(struct cli_state *ipc_cli,
        enum lsa_SidType *types = NULL;
        DOM_SID *sids = NULL;
        bool result = True;
+       TALLOC_CTX *ctx;
        struct rpc_pipe_client *pipe_hnd = find_lsa_pipe_hnd(ipc_cli);
 
        if (!pipe_hnd) {
@@ -4077,7 +4089,8 @@ convert_string_to_sid(struct cli_state *ipc_cli,
                 goto done;
         }
 
-       if (!NT_STATUS_IS_OK(rpccli_lsa_lookup_names(pipe_hnd, ipc_cli->mem_ctx, 
+       ctx = talloc_stackframe();
+       if (!NT_STATUS_IS_OK(rpccli_lsa_lookup_names(pipe_hnd, ctx,
                                                  pol, 1, &str, NULL, 1, &sids, 
                                                  &types))) {
                result = False;
@@ -4087,6 +4100,7 @@ convert_string_to_sid(struct cli_state *ipc_cli,
        sid_copy(sid, &sids[0]);
  done:
 
+       TALLOC_FREE(ctx);
        return result;
 }
 
index 9941b728aeb3b2fbe13c7b50dfe8cd0362ba581c..468750f8012a78627e209035d4287607b097b6ab 100644 (file)
@@ -177,7 +177,7 @@ NTSTATUS remote_password_change(const char *remote_machine, const char *user_nam
                }
        }
 
-       if (NT_STATUS_IS_OK(result = rpccli_samr_chgpasswd_user(pipe_hnd, cli->mem_ctx, user_name, 
+       if (NT_STATUS_IS_OK(result = rpccli_samr_chgpasswd_user(pipe_hnd, pipe_hnd->mem_ctx, user_name, 
                                                             new_passwd, old_passwd))) {
                /* Great - it all worked! */
                cli_shutdown(cli);
@@ -207,7 +207,7 @@ NTSTATUS remote_password_change(const char *remote_machine, const char *user_nam
 
        if ( pipe_hnd &&
                (NT_STATUS_IS_OK(result = rpccli_samr_chgpasswd_user(pipe_hnd,
-                                               cli->mem_ctx,
+                                               pipe_hnd->mem_ctx,
                                                user_name, 
                                                new_passwd,
                                                old_passwd)))) {
index c93e26ccbcfa26efc597a350afef99f6b73ba822..05ef2ad1511a3d6acb0ab96aef6180e5fbe3536d 100644 (file)
@@ -1975,7 +1975,7 @@ static NTSTATUS rpc_finish_spnego_ntlmssp_bind(struct rpc_pipe_client *cli,
 
        /* Initialize the returning data struct. */
        prs_mem_free(rbuf);
-       prs_init(rbuf, 0, cli->cli->mem_ctx, UNMARSHALL);
+       prs_init(rbuf, 0, cli->mem_ctx, UNMARSHALL);
 
        nt_status = rpc_api_pipe(cli, &rpc_out, rbuf, RPC_ALTCONTRESP);
        if (!NT_STATUS_IS_OK(nt_status)) {
@@ -2048,7 +2048,7 @@ static NTSTATUS rpc_pipe_bind(struct rpc_pipe_client *cli,
                return NT_STATUS_INVALID_PARAMETER;
        }
 
-       prs_init(&rpc_out, 0, cli->cli->mem_ctx, MARSHALL);
+       prs_init(&rpc_out, 0, cli->mem_ctx, MARSHALL);
 
        rpc_call_id = get_rpc_call_id();
 
@@ -2064,7 +2064,7 @@ static NTSTATUS rpc_pipe_bind(struct rpc_pipe_client *cli,
        }
 
        /* Initialize the incoming data struct. */
-       prs_init(&rbuf, 0, cli->cli->mem_ctx, UNMARSHALL);
+       prs_init(&rbuf, 0, cli->mem_ctx, UNMARSHALL);
 
        /* send data on \PIPE\.  receive a response */
        status = rpc_api_pipe(cli, &rpc_out, &rbuf, RPC_BINDACK);
@@ -2745,7 +2745,7 @@ struct rpc_pipe_client *cli_rpc_pipe_open_krb5(struct cli_state *cli,
                }
        }
 
-       result->auth.a_u.kerberos_auth = TALLOC_ZERO_P(cli->mem_ctx, struct kerberos_auth_struct);
+       result->auth.a_u.kerberos_auth = TALLOC_ZERO_P(result->mem_ctx, struct kerberos_auth_struct);
        if (!result->auth.a_u.kerberos_auth) {
                cli_rpc_pipe_close(result);
                *perr = NT_STATUS_NO_MEMORY;
@@ -2769,30 +2769,3 @@ struct rpc_pipe_client *cli_rpc_pipe_open_krb5(struct cli_state *cli,
        return NULL;
 #endif
 }
-
-#if 0 /* Moved to libsmb/clientgen.c */
-/****************************************************************************
- External interface.
- Close an open named pipe over SMB. Free any authentication data.
- ****************************************************************************/
-
- void cli_rpc_pipe_close(struct rpc_pipe_client *cli)
-{
-       if (!cli_close(cli->cli, cli->fnum)) {
-               DEBUG(0,("cli_rpc_pipe_close: cli_close failed on pipe %s "
-                        "to machine %s.  Error was %s\n",
-                        cli->pipe_name),
-                        cli->cli->desthost,
-                        cli_errstr(cli->cli)));
-       }
-
-       if (cli->auth.cli_auth_data_free_func) {
-               (*cli->auth.cli_auth_data_free_func)(&cli->auth);
-       }
-       DEBUG(10,("cli_rpc_pipe_close: closed pipe %s to machine %s\n",
-               cli->pipe_name, cli->cli->desthost ));
-
-       DLIST_REMOVE(cli->cli->pipe_list, cli);
-       talloc_destroy(cli->mem_ctx);   
-}
-#endif
index b01f10b71dd9d3f47774336555476f5c61f930fa..a17a8ebf26b277ce50ab93caadabd7bf61865123 100644 (file)
@@ -153,7 +153,9 @@ static void srv_spoolss_replycloseprinter(int snum, POLICY_HND *handle)
                return;
        }
 
-       result = rpccli_spoolss_reply_close_printer(notify_cli_pipe, notify_cli_pipe->cli->mem_ctx, handle);
+       result = rpccli_spoolss_reply_close_printer(notify_cli_pipe,
+                               talloc_tos(),
+                               handle);
 
        if (!W_ERROR_IS_OK(result))
                DEBUG(0,("srv_spoolss_replycloseprinter: reply_close_printer failed [%s].\n",
@@ -2639,8 +2641,12 @@ static bool srv_spoolss_replyopenprinter(int snum, const char *printer,
 
        smb_connections++;
 
-       result = rpccli_spoolss_reply_open_printer(notify_cli_pipe, notify_cli_pipe->cli->mem_ctx, printer, localprinter,
-                       type, handle);
+       result = rpccli_spoolss_reply_open_printer(notify_cli_pipe,
+                       talloc_tos(),
+                       printer,
+                       localprinter,
+                       type,
+                       handle);
 
        if (!W_ERROR_IS_OK(result))
                DEBUG(5,("srv_spoolss_reply_open_printer: Client RPC returned [%s]\n",
index 8ed0975781cab13e7cd21b0bed70d1fb0551ac2c..fc58e97ea78863f2114e34b59791196fdd83ec32 100644 (file)
@@ -82,7 +82,7 @@ NTSTATUS change_trust_account_password( const char *domain, const char *remote_m
                goto failed;
        }
 
-       nt_status = trust_pw_find_change_and_store_it(netlogon_pipe, cli->mem_ctx, domain);
+       nt_status = trust_pw_find_change_and_store_it(netlogon_pipe, netlogon_pipe->mem_ctx, domain);
   
        cli_shutdown(cli);
        cli = NULL;
index ae793c28f94265aaa08bea6612727a3d701102eb..6ae63f4c683bf3c9ab382672222f343cd0d3664a 100644 (file)
@@ -62,7 +62,7 @@ static bool cli_open_policy_hnd(void)
                /* Some systems don't support SEC_RIGHTS_MAXIMUM_ALLOWED,
                   but NT sends 0x2000000 so we might as well do it too. */
 
-               if (!NT_STATUS_IS_OK(rpccli_lsa_open_policy(global_pipe_hnd, cli_ipc->mem_ctx, True, 
+               if (!NT_STATUS_IS_OK(rpccli_lsa_open_policy(global_pipe_hnd, talloc_tos(), True, 
                                                         GENERIC_EXECUTE_ACCESS, &pol))) {
                        return False;
                }
@@ -87,7 +87,7 @@ static void SidToString(fstring str, DOM_SID *sid, bool _numeric)
        /* Ask LSA to convert the sid to a name */
 
        if (!cli_open_policy_hnd() ||
-           !NT_STATUS_IS_OK(rpccli_lsa_lookup_sids(global_pipe_hnd, cli_ipc->mem_ctx,  
+           !NT_STATUS_IS_OK(rpccli_lsa_lookup_sids(global_pipe_hnd, talloc_tos(),
                                                 &pol, 1, sid, &domains, 
                                                 &names, &types)) ||
            !domains || !domains[0] || !names || !names[0]) {
@@ -114,7 +114,7 @@ static bool StringToSid(DOM_SID *sid, const char *str)
        }
 
        if (!cli_open_policy_hnd() ||
-           !NT_STATUS_IS_OK(rpccli_lsa_lookup_names(global_pipe_hnd, cli_ipc->mem_ctx, 
+           !NT_STATUS_IS_OK(rpccli_lsa_lookup_names(global_pipe_hnd, talloc_tos(),
                                                  &pol, 1, &str, NULL, 1, &sids, 
                                                  &types))) {
                result = False;
@@ -559,4 +559,3 @@ FSQFLAGS:QUOTA_ENABLED/DENY_DISK/LOG_SOFTLIMIT/LOG_HARD_LIMIT", "SETSTRING" },
 
        return result;
 }
-
index 0e0c993f4e012d6f912cc08ccafa9ac92d836330..bcacddc4147c6b2dce9594d969541c19b36f30db 100644 (file)
@@ -71,13 +71,17 @@ static bool get_workgroups(struct user_auth_info *user_info)
 {
         struct cli_state *cli;
         struct sockaddr_storage server_ss;
-       pstring master_workgroup;
+       TALLOC_CTX *ctx = talloc_tos();
+       char *master_workgroup = NULL;
 
         /* Try to connect to a #1d name of our current workgroup.  If that
            doesn't work broadcast for a master browser and then jump off
            that workgroup. */
 
-       pstrcpy(master_workgroup, lp_workgroup());
+       master_workgroup = talloc_strdup(ctx, lp_workgroup());
+       if (!master_workgroup) {
+               return false;
+       }
 
         if (!use_bcast && !find_master_ip(lp_workgroup(), &server_ss)) {
                 DEBUG(4, ("Unable to find master browser for workgroup %s, falling back to broadcast\n", 
@@ -90,7 +94,9 @@ static bool get_workgroups(struct user_auth_info *user_info)
                                return False;
                }
 
-               if (!(cli = get_ipc_connect_master_ip_bcast(master_workgroup, user_info))) {
+               if (!(cli = get_ipc_connect_master_ip_bcast(talloc_tos(),
+                                                       user_info,
+                                                       &master_workgroup))) {
                        DEBUG(4, ("Unable to find master browser by "
                                  "broadcast\n"));
                        return False;
index f8e76b0299a6b74be72bdb6494dc91f2ef0a0d7c..7da7a82343ce8d87ebb6c67e0a89664f20fae1d2 100644 (file)
@@ -1744,6 +1744,13 @@ static void set_dc_type_and_flags_connect( struct winbindd_domain *domain )
                return;
        }
 
+       mem_ctx = talloc_init("set_dc_type_and_flags on domain %s\n",
+                             domain->name);
+       if (!mem_ctx) {
+               DEBUG(1, ("set_dc_type_and_flags_connect: talloc_init() failed\n"));
+               return;
+       }
+
        DEBUG(5, ("set_dc_type_and_flags_connect: domain %s\n", domain->name ));
 
        cli = cli_rpc_pipe_open_noauth(domain->conn.cli, PI_LSARPC_DS,
@@ -1761,7 +1768,7 @@ static void set_dc_type_and_flags_connect( struct winbindd_domain *domain )
                goto no_lsarpc_ds;
        }
 
-       result = rpccli_ds_getprimarydominfo(cli, cli->cli->mem_ctx,
+       result = rpccli_ds_getprimarydominfo(cli, mem_ctx,
                                             DsRolePrimaryDomainInfoBasic,
                                             &ctr);
        cli_rpc_pipe_close(cli);
@@ -1780,6 +1787,7 @@ static void set_dc_type_and_flags_connect( struct winbindd_domain *domain )
                        goto no_lsarpc_ds;
                }
 
+               TALLOC_FREE(mem_ctx);
                return;
        }
        
@@ -1798,14 +1806,7 @@ no_lsarpc_ds:
                          "PI_LSARPC on domain %s: (%s)\n",
                          domain->name, nt_errstr(result)));
                cli_rpc_pipe_close(cli);
-               return;
-       }
-
-       mem_ctx = talloc_init("set_dc_type_and_flags on domain %s\n",
-                             domain->name);
-       if (!mem_ctx) {
-               DEBUG(1, ("set_dc_type_and_flags_connect: talloc_init() failed\n"));
-               cli_rpc_pipe_close(cli);
+               TALLOC_FREE(mem_ctx);
                return;
        }
 
@@ -1866,8 +1867,8 @@ done:
                  domain->name, domain->active_directory ? "" : "NOT "));
 
        cli_rpc_pipe_close(cli);
-       
-       talloc_destroy(mem_ctx);
+
+       TALLOC_FREE(mem_ctx);
 
        domain->initialized = True;
 }