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;
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;
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 */
};
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);
}
* 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));
return NULL;
}
- pstrcpy(workgroup, name);
+ *pp_workgroup_out = talloc_strdup(ctx, name);
DEBUG(4, ("found master browser %s, %s\n", name, addr));
* 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 */
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);
}
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 ) {
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);
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);
}
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;
}
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 );
/****************************************************************************
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;
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;
-/*
+/*
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;
}
}
-
/****************************************************************************
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 */
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;
}
}
/****************************************************************************
cancel a print job
****************************************************************************/
+
int cli_printjob_del(struct cli_state *cli, int job)
{
char *rparam = NULL;
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 */
accessmode |= 2;
} else if ((flags & O_ACCMODE) == O_WRONLY) {
accessmode |= 1;
- }
+ }
#if defined(O_SYNC)
if ((flags & O_SYNC) == O_SYNC) {
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);
return !cli_is_error(cli);
}
-
-
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;
nt_status = rpccli_lsa_open_policy(
pipe_hnd,
- ipc_srv->cli->mem_ctx,
+ talloc_tos(),
True,
GENERIC_EXECUTE_ACCESS,
pol);
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) {
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);
smbc_closedir_ctx(SMBCCTX *context,
SMBCFILE *dir)
{
- TALLOC_CTX *frame = talloc_tos();
+ TALLOC_CTX *frame = talloc_stackframe();
if (!context || !context->internal ||
!context->internal->_initialized) {
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) {
/* 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",
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) {
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;
sid_copy(sid, &sids[0]);
done:
+ TALLOC_FREE(ctx);
return result;
}
}
}
- 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);
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)))) {
/* 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)) {
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();
}
/* 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);
}
}
- 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;
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
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",
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",
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;
/* 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;
}
/* 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]) {
}
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;
return result;
}
-
{
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",
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;
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,
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);
goto no_lsarpc_ds;
}
+ TALLOC_FREE(mem_ctx);
return;
}
"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;
}
domain->name, domain->active_directory ? "" : "NOT "));
cli_rpc_pipe_close(cli);
-
- talloc_destroy(mem_ctx);
+
+ TALLOC_FREE(mem_ctx);
domain->initialized = True;
}