void message_register(int msg_type,
void (*fn)(int msg_type, pid_t pid, void *buf, size_t len));
void message_deregister(int msg_type);
-BOOL message_send_all(int msg_type, void *buf, size_t len, BOOL duplicates_allowed);
+BOOL message_send_all(TDB_CONTEXT *conn_tdb, int msg_type, void *buf, size_t len, BOOL duplicates_allowed);
/*The following definitions come from lib/ms_fnmatch.c */
void init_q_lookup_names(TALLOC_CTX *mem_ctx, LSA_Q_LOOKUP_NAMES *q_l,
POLICY_HND *hnd, int num_names, char **names);
BOOL lsa_io_q_lookup_names(char *desc, LSA_Q_LOOKUP_NAMES *q_r, prs_struct *ps, int depth);
-BOOL lsa_io_r_lookup_names(TALLOC_CTX *mem_ctx, char *desc,
- LSA_R_LOOKUP_NAMES *r_r, prs_struct *ps, int depth);
+BOOL lsa_io_r_lookup_names(char *desc, LSA_R_LOOKUP_NAMES *r_r, prs_struct *ps, int depth);
void init_lsa_q_close(LSA_Q_CLOSE *q_c, POLICY_HND *hnd);
BOOL lsa_io_q_close(char *desc, LSA_Q_CLOSE *q_c, prs_struct *ps, int depth);
BOOL lsa_io_r_close(char *desc, LSA_R_CLOSE *r_c, prs_struct *ps, int depth);
/*The following definitions come from smbd/connection.c */
+TDB_CONTEXT *conn_tdb_ctx(void);
BOOL yield_connection(connection_struct *conn,char *name,int max_connections);
BOOL claim_connection(connection_struct *conn,char *name,int max_connections,BOOL Clear);
It isn't very efficient, but should be OK for the sorts of applications that
use it. When we need efficient broadcast we can add it.
****************************************************************************/
-BOOL message_send_all(int msg_type, void *buf, size_t len, BOOL duplicates_allowed)
+BOOL message_send_all(TDB_CONTEXT *conn_tdb, int msg_type, void *buf, size_t len, BOOL duplicates_allowed)
{
- TDB_CONTEXT *the_tdb;
-
- the_tdb = tdb_open(lock_path("connections.tdb"), 0, 0, O_RDONLY, 0);
- if (!the_tdb) {
- DEBUG(2,("Failed to open connections database in message_send_all\n"));
- return False;
- }
-
msg_all.msg_type = msg_type;
msg_all.buf = buf;
msg_all.len = len;
msg_all.duplicates = duplicates_allowed;
- tdb_traverse(the_tdb, traverse_fn, NULL);
- tdb_close(the_tdb);
+ tdb_traverse(conn_tdb, traverse_fn, NULL);
return True;
}
{
struct talloc_chunk *c;
+ if (!t)
+ return;
+
while (t->list) {
c = t->list->next;
free(t->list->ptr);
/* destroy a whole pool including the context */
void talloc_destroy(TALLOC_CTX *t)
{
+ if (!t)
+ return;
talloc_destroy_pool(t);
free(t);
}
if (!lsa_io_q_open_pol("", &q, &qbuf, 0) ||
!rpc_api_pipe_req(cli, LSA_OPENPOLICY, &qbuf, &rbuf)) {
+ prs_mem_free(&qbuf);
+ prs_mem_free(&rbuf);
return NT_STATUS_UNSUCCESSFUL;
}
/* Unmarshall response */
if (!lsa_io_r_open_pol("", &r, &rbuf, 0)) {
+ prs_mem_free(&qbuf);
+ prs_mem_free(&rbuf);
return NT_STATUS_UNSUCCESSFUL;
}
*hnd = r.pol;
}
+ prs_mem_free(&qbuf);
+ prs_mem_free(&rbuf);
return result;
}
if (!lsa_io_q_close("", &q, &qbuf, 0) ||
!rpc_api_pipe_req(cli, LSA_CLOSE, &qbuf, &rbuf)) {
+ prs_mem_free(&qbuf);
+ prs_mem_free(&rbuf);
return NT_STATUS_UNSUCCESSFUL;
}
/* Unmarshall response */
if (!lsa_io_r_close("", &r, &rbuf, 0)) {
+ prs_mem_free(&qbuf);
+ prs_mem_free(&rbuf);
return NT_STATUS_UNSUCCESSFUL;
}
*hnd = r.pol;
}
+ prs_mem_free(&qbuf);
+ prs_mem_free(&rbuf);
return result;
}
if (!lsa_io_q_lookup_sids("", &q, &qbuf, 0) ||
!rpc_api_pipe_req(cli, LSA_LOOKUPSIDS, &qbuf, &rbuf)) {
+ prs_mem_free(&qbuf);
+ prs_mem_free(&rbuf);
return NT_STATUS_UNSUCCESSFUL;
}
r.names = &t_names;
if (!lsa_io_r_lookup_sids("", &r, &rbuf, 0)) {
+ prs_mem_free(&qbuf);
+ prs_mem_free(&rbuf);
return NT_STATUS_UNSUCCESSFUL;
}
}
done:
+ prs_mem_free(&qbuf);
+ prs_mem_free(&rbuf);
+
return result;
}
if (!lsa_io_q_lookup_names("", &q, &qbuf, 0) ||
!rpc_api_pipe_req(cli, LSA_LOOKUPNAMES, &qbuf, &rbuf)) {
+ prs_mem_free(&qbuf);
+ prs_mem_free(&rbuf);
return NT_STATUS_UNSUCCESSFUL;
}
ZERO_STRUCT(ref);
r.dom_ref = &ref;
- if (!lsa_io_r_lookup_names(cli->mem_ctx, "", &r, &rbuf, 0)) {
+ if (!lsa_io_r_lookup_names("", &r, &rbuf, 0)) {
+ prs_mem_free(&qbuf);
+ prs_mem_free(&rbuf);
return NT_STATUS_UNSUCCESSFUL;
}
}
done:
+ prs_mem_free(&qbuf);
+ prs_mem_free(&rbuf);
+
return result;
}
cli->inbuf = (char *)malloc(cli->bufsize);
if (!cli->outbuf || !cli->inbuf)
{
- return False;
+ return NULL;
}
if ((cli->mem_ctx = talloc_init()) == NULL) {
free(cli->outbuf);
free(cli->inbuf);
- return False;
+ return NULL;
}
memset(cli->outbuf, '\0', cli->bufsize);
TALLOC_CTX *mem_ctx;
prs_struct pd;
SEC_DESC *psd = NULL;
- SEC_DESC *ret;
SIVAL(param, 0, fd);
SSVAL(param, 4, 0x7);
param, 8, 4,
NULL, 0, 0x10000)) {
DEBUG(1,("Failed to send NT_TRANSACT_QUERY_SECURITY_DESC\n"));
- return NULL;
+ goto cleanup;
}
&rparam, &rparam_count,
&rdata, &rdata_count)) {
DEBUG(1,("Failed to recv NT_TRANSACT_QUERY_SECURITY_DESC\n"));
- return NULL;
+ goto cleanup;
}
if ((mem_ctx = talloc_init()) == NULL) {
DEBUG(0,("talloc_init failed.\n"));
- return NULL;
+ goto cleanup;
}
prs_init(&pd, rdata_count, 4, mem_ctx, UNMARSHALL);
if (!sec_io_desc("sd data", &psd, &pd, 1)) {
DEBUG(1,("Failed to parse secdesc\n"));
- talloc_destroy(mem_ctx);
- return NULL;
+ goto cleanup;
}
- ret = dup_sec_desc(psd);
+ cleanup:
+
talloc_destroy(mem_ctx);
- return ret;
+ safe_free(rparam);
+ safe_free(rdata);
+
+ prs_mem_free(&pd);
+ return psd;
}
int rparam_count=0, rdata_count=0;
TALLOC_CTX *mem_ctx;
prs_struct pd;
+ BOOL ret = False;
if ((mem_ctx = talloc_init()) == NULL) {
DEBUG(0,("talloc_init failed.\n"));
- return False;
+ goto cleanup;
}
prs_init(&pd, 0, 4, mem_ctx, MARSHALL);
if (!sec_io_desc("sd data", &sd, &pd, 1)) {
DEBUG(1,("Failed to marshall secdesc\n"));
- return False;
+ goto cleanup;
}
SIVAL(param, 0, fd);
param, 8, 0,
pd.data_p, pd.data_offset, 0)) {
DEBUG(1,("Failed to send NT_TRANSACT_SET_SECURITY_DESC\n"));
- return False;
+ goto cleanup;
}
&rparam, &rparam_count,
&rdata, &rdata_count)) {
DEBUG(1,("NT_TRANSACT_SET_SECURITY_DESC failed\n"));
- return False;
+ goto cleanup;
}
- if (rparam) free(rparam);
- if (rdata) free(rdata);
+ ret = True;
+
+ cleanup:
+
+ safe_free(rparam);
+ safe_free(rdata);
talloc_destroy(mem_ctx);
- return True;
+ prs_mem_free(&pd);
+ return ret;
}
if (cli_error(cli, &eclass, &ecode, NULL))
{
- if(cli->nt_pipe_fnum == 0 || !(eclass == ERRDOS && ecode == ERRmoredata))
+ if(cli->nt_pipe_fnum == 0)
return(False);
+
+ if(!(eclass == ERRDOS && ecode == ERRmoredata)) {
+ if (eclass != 0 && (ecode != (0x80000000 | STATUS_BUFFER_OVERFLOW)))
+ return(False);
+ }
}
/* parse out the lengths */
if( qcount != get_queue_status(snum, &old_status)) {
DEBUG(10,("print_queue_update: queue status change %d jobs -> %d jobs for printer %s\n",
old_status.qcount, qcount, printer_name ));
- message_send_all(MSG_PRINTER_NOTIFY, printer_name, strlen(printer_name) + 1, False);
+ message_send_all(conn_tdb_ctx(), MSG_PRINTER_NOTIFY, printer_name, strlen(printer_name) + 1, False);
}
/* store the new queue status structure */
printer_name = PRINTERNAME(snum);
- message_send_all(MSG_PRINTER_NOTIFY, printer_name, strlen(printer_name) + 1, False);
+ message_send_all(conn_tdb_ctx(), MSG_PRINTER_NOTIFY, printer_name, strlen(printer_name) + 1, False);
return !print_job_exists(jobid);
}
printer_name = PRINTERNAME(snum);
- message_send_all(MSG_PRINTER_NOTIFY, printer_name, strlen(printer_name) + 1, False);
+ message_send_all(conn_tdb_ctx(), MSG_PRINTER_NOTIFY, printer_name, strlen(printer_name) + 1, False);
/* how do we tell if this succeeded? */
printer_name = PRINTERNAME(snum);
- message_send_all(MSG_PRINTER_NOTIFY, printer_name, strlen(printer_name) + 1, False);
+ message_send_all(conn_tdb_ctx(),MSG_PRINTER_NOTIFY, printer_name, strlen(printer_name) + 1, False);
return True;
}
printer_name = PRINTERNAME(snum);
- message_send_all(MSG_PRINTER_NOTIFY, printer_name, strlen(printer_name) + 1, False);
+ message_send_all(conn_tdb_ctx(),MSG_PRINTER_NOTIFY, printer_name, strlen(printer_name) + 1, False);
return True;
}
printer_name = PRINTERNAME(snum);
- message_send_all(MSG_PRINTER_NOTIFY, printer_name, strlen(printer_name) + 1, False);
+ message_send_all(conn_tdb_ctx(),MSG_PRINTER_NOTIFY, printer_name, strlen(printer_name) + 1, False);
return True;
}
printer_name = PRINTERNAME(snum);
- message_send_all(MSG_PRINTER_NOTIFY, printer_name, strlen(printer_name) + 1, False);
+ message_send_all(conn_tdb_ctx(),MSG_PRINTER_NOTIFY, printer_name, strlen(printer_name) + 1, False);
return True;
}
printer_name = PRINTERNAME(snum);
- message_send_all(MSG_PRINTER_NOTIFY, printer_name, strlen(printer_name) + 1, False);
+ message_send_all(conn_tdb_ctx(),MSG_PRINTER_NOTIFY, printer_name, strlen(printer_name) + 1, False);
return True;
}
r_l.dom_ref = &ref;
r_l.dom_rid = t_rids;
- lsa_io_r_lookup_names(ctx, "", &r_l, &rbuf, 0);
+ lsa_io_r_lookup_names("", &r_l, &rbuf, 0);
p = rbuf.data_offset != 0;
if (p && r_l.status != 0) {
/* Mallocate memory if we're unpacking from the wire */
if (UNMARSHALLING(ps)) {
- if ((sen->ptr_sid = (uint32 *)malloc(
+ if ((sen->ptr_sid = (uint32 *)prs_alloc_mem( ps,
sen->num_entries * sizeof(uint32))) == NULL) {
DEBUG(3, ("init_lsa_sid_enum(): out of memory for "
"ptr_sid\n"));
return False;
}
- if ((sen->sid = (DOM_SID2 *)malloc(
+ if ((sen->sid = (DOM_SID2 *)prs_alloc_mem( ps,
sen->num_entries * sizeof(DOM_SID2))) == NULL) {
DEBUG(3, ("init_lsa_sid_enum(): out of memory for "
"sids\n"));
if (UNMARSHALLING(ps)) {
if ((trn->name = (LSA_TRANS_NAME *)
- malloc(trn->num_entries *
+ prs_alloc_mem(ps, trn->num_entries *
sizeof(LSA_TRANS_NAME))) == NULL) {
return False;
}
if ((trn->uni_name = (UNISTR2 *)
- malloc(trn->num_entries *
+ prs_alloc_mem(ps, trn->num_entries *
sizeof(UNISTR2))) == NULL) {
return False;
}
if(!smb_io_pol_hnd("", &q_r->pol, ps, depth)) /* policy handle */
return False;
+ if(!prs_align(ps))
+ return False;
if(!prs_uint32("num_entries ", ps, depth, &q_r->num_entries))
return False;
if(!prs_uint32("num_entries2 ", ps, depth, &q_r->num_entries2))
return False;
+ if (UNMARSHALLING(ps)) {
+ if (q_r->num_entries) {
+ if ((q_r->hdr_name = (UNIHDR *)prs_alloc_mem(ps,
+ q_r->num_entries * sizeof(UNIHDR))) == NULL)
+ return False;
+ if ((q_r->uni_name = (UNISTR2 *)prs_alloc_mem(ps,
+ q_r->num_entries * sizeof(UNISTR2))) == NULL)
+ return False;
+ }
+ }
+
for (i = 0; i < q_r->num_entries; i++) {
+ if(!prs_align(ps))
+ return False;
if(!smb_io_unihdr("hdr_name", &q_r->hdr_name[i], ps, depth)) /* pointer names */
return False;
}
for (i = 0; i < q_r->num_entries; i++) {
- if(!smb_io_unistr2("dom_name", &q_r->uni_name[i], q_r->hdr_name[i].buffer, ps, depth)) /* names to be looked up */
- return False;
if(!prs_align(ps))
return False;
+ if(!smb_io_unistr2("dom_name", &q_r->uni_name[i], q_r->hdr_name[i].buffer, ps, depth)) /* names to be looked up */
+ return False;
}
+ if(!prs_align(ps))
+ return False;
if(!prs_uint32("num_trans_entries ", ps, depth, &q_r->num_trans_entries))
return False;
if(!prs_uint32("ptr_trans_sids ", ps, depth, &q_r->ptr_trans_sids))
reads or writes a structure.
********************************************************************/
-BOOL lsa_io_r_lookup_names(TALLOC_CTX *mem_ctx, char *desc,
- LSA_R_LOOKUP_NAMES *r_r, prs_struct *ps, int depth)
+BOOL lsa_io_r_lookup_names(char *desc, LSA_R_LOOKUP_NAMES *r_r, prs_struct *ps, int depth)
{
int i;
return False;
}
- if ((r_r->dom_rid = (DOM_RID2 *)
- talloc(mem_ctx, r_r->num_entries2 * sizeof(DOM_RID2)))
- == NULL) {
- DEBUG(3, ("lsa_io_r_lookup_names(): out of memory\n"));
- return False;
+ if (UNMARSHALLING(ps)) {
+ if ((r_r->dom_rid = (DOM_RID2 *)prs_alloc_mem(ps, r_r->num_entries2 * sizeof(DOM_RID2)))
+ == NULL) {
+ DEBUG(3, ("lsa_io_r_lookup_names(): out of memory\n"));
+ return False;
+ }
}
for (i = 0; i < r_r->num_entries2; i++)
{
hdr->uni_str_len = 2 * len;
hdr->uni_max_len = 2 * len;
- hdr->buffer = len != 0;
+ hdr->buffer = len != 0 ? 1 : 0;
}
/*******************************************************************
{
ZERO_STRUCTP(str);
- /* Set up string lengths. */
-
+ /* set up string lengths. */
str->uni_max_len = (uint32)len;
str->undoc = 0;
str->uni_str_len = (uint32)len;
len *= sizeof(uint16);
str->buffer = (uint16 *)talloc(parse_misc_talloc, len);
- if ((str->buffer == NULL) && (len > 0)) {
+ if ((str->buffer == NULL) && (len > 0))
+ {
smb_panic("init_unistr2: malloc fail\n");
return;
}
return False;
}
- /* Free memory - perhaps this should be done using talloc()? */
-
- safe_free(names.name);
- safe_free(names.uni_name);
-
return True;
}
DOM_R_REF ref;
DOM_RID2 rids[MAX_LOOKUP_SIDS];
uint32 mapped_count = 0;
- TALLOC_CTX *mem_ctx = talloc_init();
BOOL result = True;
- if (!mem_ctx) return False;
-
ZERO_STRUCT(r_l);
ZERO_STRUCT(ref);
ZERO_ARRAY(rids);
init_reply_lookup_names(&r_l, &ref, num_entries, rids, mapped_count);
/* store the response in the SMB stream */
- if(!lsa_io_r_lookup_names(mem_ctx, "", &r_l, rdata, 0)) {
+ if(!lsa_io_r_lookup_names("", &r_l, rdata, 0)) {
DEBUG(0,("lsa_reply_lookup_names: Failed to marshall LSA_R_LOOKUP_NAMES.\n"));
result = False;
}
- talloc_destroy(mem_ctx);
return result;
}
if(!lsa_io_q_lookup_sids("", &q_l, data, 0)) {
DEBUG(0,("api_lsa_lookup_sids: failed to unmarshall LSA_Q_LOOKUP_SIDS.\n"));
result = False;
- goto done;
}
/* construct reply. return status is always 0x0 */
if(!lsa_reply_lookup_sids(rdata, q_l.sids.sid, q_l.sids.num_entries)) {
result = False;
- goto done;
}
-
- done:
- safe_free(q_l.sids.ptr_sid);
- safe_free(q_l.sids.sid);
-
return result;
}
return False;
}
- SMB_ASSERT_ARRAY(q_l.uni_name, q_l.num_entries);
-
return lsa_reply_lookup_names(rdata, q_l.uni_name, q_l.num_entries);
}
/*srv_spoolss_receive_message(printer);*/
DEBUG(10,("srv_spoolss_sendnotify: Sending message about printer %s\n", printer ));
- message_send_all(MSG_PRINTER_NOTIFY, printer, strlen(printer) + 1, False); /* Null terminate... */
+ message_send_all(conn_tdb_ctx(), MSG_PRINTER_NOTIFY, printer, strlen(printer) + 1, False); /* Null terminate... */
return True;
}
static void utmp_claim(const struct connections_data *crec, const connection_struct *conn);
#endif
+/****************************************************************************
+ Return the connection tdb context (used for message send all).
+****************************************************************************/
+
+TDB_CONTEXT *conn_tdb_ctx(void)
+{
+ return tdb;
+}
+
/****************************************************************************
delete a connection record
****************************************************************************/
}
/* convert a string to a SID, either numeric or username/group */
-static BOOL StringToSid(DOM_SID *sid, fstring str)
+static BOOL StringToSid(DOM_SID *sid, char *str)
{
uint32 *types = NULL;
DOM_SID *sids = NULL;
int num_sids;
- BOOL result = False;
+ BOOL result = True;
/* Short cut */
if (open_policy_hnd() &&
cli_lsa_lookup_names(&lsa_cli, &pol, 1, &str, &sids, &types,
- &num_sids) == NT_STATUS_NOPROBLEMO) {
+ &num_sids) != NT_STATUS_NOPROBLEMO) {
result = string_to_sid(sid, str);
goto done;
}
safe_free(types);
done:
+
return result;
}
if (strncmp(tok,"ACL:", 4) == 0) {
SEC_ACE ace;
- if (!parse_ace(&ace, tok+4) ||
- !add_ace(&dacl, &ace)) {
- printf("Failed to parse ACL\n");
+ if (!parse_ace(&ace, tok+4)) {
+ printf("Failed to parse ACL %s\n", tok);
+ return NULL;
+ }
+ if(!add_ace(&dacl, &ace)) {
+ printf("Failed to add ACL %s\n", tok);
return NULL;
}
continue;
if (!cli_set_secdesc(cli, fnum, sd)) {
printf("ERROR: secdesc set failed: %s\n", cli_errstr(cli));
- return;
}
free_sec_desc(&sd);
if (!(c=cli_initialise(NULL)) || (cli_set_port(c, 139) == 0) ||
!cli_connect(c, server_n, &ip)) {
DEBUG(0,("Connection to %s failed\n", server_n));
+ cli_shutdown(c);
+ safe_free(c);
return NULL;
}
if (!cli_session_request(c, &calling, &called)) {
DEBUG(0,("session request to %s failed\n", called.name));
cli_shutdown(c);
+ safe_free(c);
if (strcmp(called.name, "*SMBSERVER")) {
make_nmb_name(&called , "*SMBSERVER", 0x20);
goto again;
if (!cli_negprot(c)) {
DEBUG(0,("protocol negotiation failed\n"));
cli_shutdown(c);
+ safe_free(c);
return NULL;
}
password, strlen(password),
lp_workgroup())) {
DEBUG(0,("session setup failed: %s\n", cli_errstr(c)));
+ cli_shutdown(c);
+ safe_free(c);
return NULL;
}
password, strlen(password)+1)) {
DEBUG(0,("tree connect failed: %s\n", cli_errstr(c)));
cli_shutdown(c);
+ safe_free(c);
return NULL;
}
static BOOL send_message(char *dest, int msg_type, void *buf, int len, BOOL duplicates)
{
pid_t pid;
+ TDB_CONTEXT *the_tdb;
+
+ the_tdb = tdb_open(lock_path("connections.tdb"), 0, 0, O_RDONLY, 0);
+ if (!the_tdb) {
+ fprintf(stderr,"Failed to open connections database in send_message.\n");
+ return False;
+ }
/* "smbd" is the only broadcast operation */
if (strequal(dest,"smbd")) {
- return message_send_all(msg_type, buf, len, duplicates);
+ return message_send_all(the_tdb,msg_type, buf, len, duplicates);
} else if (strequal(dest,"nmbd")) {
pid = pidfile_pid(dest);
if (pid == 0) {