diff options
author | Gerald Carter <jerry@samba.org> | 2001-04-28 00:32:56 +0000 |
---|---|---|
committer | Gerald Carter <jerry@samba.org> | 2001-04-28 00:32:56 +0000 |
commit | e40449fa720d0934abd06cd0b0b05d0ca0f4e257 (patch) | |
tree | 3a66b67b2037a773ddad2d27bfd8d74250682159 /source3/libsmb | |
parent | b238f4a2ffeb225d16857b594355dc60c976e3e0 (diff) | |
download | samba-e40449fa720d0934abd06cd0b0b05d0ca0f4e257.tar.gz samba-e40449fa720d0934abd06cd0b0b05d0ca0f4e257.tar.bz2 samba-e40449fa720d0934abd06cd0b0b05d0ca0f4e257.zip |
rpcclient merge from 2.2 (including Jeremy's non-void return fix)
(This used to be commit 0a6ceed279cc8111008b21f75c6791efbd993f4b)
Diffstat (limited to 'source3/libsmb')
-rw-r--r-- | source3/libsmb/cli_lsarpc.c | 104 | ||||
-rw-r--r-- | source3/libsmb/cli_samr.c | 121 | ||||
-rw-r--r-- | source3/libsmb/cli_spoolss.c | 237 |
3 files changed, 300 insertions, 162 deletions
diff --git a/source3/libsmb/cli_lsarpc.c b/source3/libsmb/cli_lsarpc.c index 7f5431e4b3..d2174f8d37 100644 --- a/source3/libsmb/cli_lsarpc.c +++ b/source3/libsmb/cli_lsarpc.c @@ -84,8 +84,13 @@ void cli_lsa_shutdown(struct cli_state *cli) /* Open a LSA policy handle */ -uint32 cli_lsa_open_policy(struct cli_state *cli, BOOL sec_qos, - uint32 des_access, POLICY_HND *pol) +uint32 cli_lsa_open_policy( + struct cli_state *cli, + TALLOC_CTX *mem_ctx, + BOOL sec_qos, + uint32 des_access, + POLICY_HND *pol +) { prs_struct qbuf, rbuf; LSA_Q_OPEN_POL q; @@ -98,8 +103,8 @@ uint32 cli_lsa_open_policy(struct cli_state *cli, BOOL sec_qos, /* Initialise parse structures */ - prs_init(&qbuf, MAX_PDU_FRAG_LEN, cli->mem_ctx, MARSHALL); - prs_init(&rbuf, 0, cli->mem_ctx, UNMARSHALL); + prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL); + prs_init(&rbuf, 0, mem_ctx, UNMARSHALL); /* Initialise input parameters */ @@ -140,7 +145,11 @@ uint32 cli_lsa_open_policy(struct cli_state *cli, BOOL sec_qos, /* Close a LSA policy handle */ -uint32 cli_lsa_close(struct cli_state *cli, POLICY_HND *pol) +uint32 cli_lsa_close( + struct cli_state *cli, + TALLOC_CTX *mem_ctx, + POLICY_HND *pol +) { prs_struct qbuf, rbuf; LSA_Q_CLOSE q; @@ -152,8 +161,8 @@ uint32 cli_lsa_close(struct cli_state *cli, POLICY_HND *pol) /* Initialise parse structures */ - prs_init(&qbuf, MAX_PDU_FRAG_LEN, cli->mem_ctx, MARSHALL); - prs_init(&rbuf, 0, cli->mem_ctx, UNMARSHALL); + prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL); + prs_init(&rbuf, 0, mem_ctx, UNMARSHALL); /* Marshall data and send request */ @@ -187,9 +196,16 @@ uint32 cli_lsa_close(struct cli_state *cli, POLICY_HND *pol) /* Lookup a list of sids */ -uint32 cli_lsa_lookup_sids(struct cli_state *cli, POLICY_HND *pol, - int num_sids, DOM_SID *sids, char ***names, - uint32 **types, int *num_names) +uint32 cli_lsa_lookup_sids( + struct cli_state *cli, + TALLOC_CTX *mem_ctx, + POLICY_HND *pol, + int num_sids, + DOM_SID *sids, + char ***names, + uint32 **types, + int *num_names +) { prs_struct qbuf, rbuf; LSA_Q_LOOKUP_SIDS q; @@ -204,12 +220,12 @@ uint32 cli_lsa_lookup_sids(struct cli_state *cli, POLICY_HND *pol, /* Initialise parse structures */ - prs_init(&qbuf, MAX_PDU_FRAG_LEN, cli->mem_ctx, MARSHALL); - prs_init(&rbuf, 0, cli->mem_ctx, UNMARSHALL); + prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL); + prs_init(&rbuf, 0, mem_ctx, UNMARSHALL); /* Marshall data and send request */ - init_q_lookup_sids(cli->mem_ctx, &q, pol, num_sids, sids, 1); + init_q_lookup_sids(mem_ctx, &q, pol, num_sids, sids, 1); if (!lsa_io_q_lookup_sids("", &q, &qbuf, 0) || !rpc_api_pipe_req(cli, LSA_LOOKUPSIDS, &qbuf, &rbuf)) { @@ -246,14 +262,14 @@ uint32 cli_lsa_lookup_sids(struct cli_state *cli, POLICY_HND *pol, (*num_names) = r.names->num_entries; - if (!((*names) = (char **)malloc(sizeof(char *) * + if (!((*names) = (char **)talloc(mem_ctx, sizeof(char *) * r.names->num_entries))) { DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n")); result = NT_STATUS_UNSUCCESSFUL; goto done; } - if (!((*types) = (uint32 *)malloc(sizeof(uint32) * + if (!((*types) = (uint32 *)talloc(mem_ctx, sizeof(uint32) * r.names->num_entries))) { DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n")); result = NT_STATUS_UNSUCCESSFUL; @@ -294,9 +310,16 @@ uint32 cli_lsa_lookup_sids(struct cli_state *cli, POLICY_HND *pol, /* Lookup a list of names */ -uint32 cli_lsa_lookup_names(struct cli_state *cli, POLICY_HND *pol, - int num_names, char **names, DOM_SID **sids, - uint32 **types, int *num_sids) +uint32 cli_lsa_lookup_names( + struct cli_state *cli, + TALLOC_CTX *mem_ctx, + POLICY_HND *pol, + int num_names, + char **names, + DOM_SID **sids, + uint32 **types, + int *num_sids +) { prs_struct qbuf, rbuf; LSA_Q_LOOKUP_NAMES q; @@ -310,12 +333,12 @@ uint32 cli_lsa_lookup_names(struct cli_state *cli, POLICY_HND *pol, /* Initialise parse structures */ - prs_init(&qbuf, MAX_PDU_FRAG_LEN, cli->mem_ctx, MARSHALL); - prs_init(&rbuf, 0, cli->mem_ctx, UNMARSHALL); + prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL); + prs_init(&rbuf, 0, mem_ctx, UNMARSHALL); /* Marshall data and send request */ - init_q_lookup_names(cli->mem_ctx, &q, pol, num_names, names); + init_q_lookup_names(mem_ctx, &q, pol, num_names, names); if (!lsa_io_q_lookup_names("", &q, &qbuf, 0) || !rpc_api_pipe_req(cli, LSA_LOOKUPNAMES, &qbuf, &rbuf)) { @@ -349,14 +372,14 @@ uint32 cli_lsa_lookup_names(struct cli_state *cli, POLICY_HND *pol, (*num_sids) = r.num_entries; - if (!((*sids = (DOM_SID *)malloc(sizeof(DOM_SID) * + if (!((*sids = (DOM_SID *)talloc(mem_ctx, sizeof(DOM_SID) * r.num_entries)))) { DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n")); result = NT_STATUS_UNSUCCESSFUL; goto done; } - if (!((*types = (uint32 *)malloc(sizeof(uint32) * + if (!((*types = (uint32 *)talloc(mem_ctx, sizeof(uint32) * r.num_entries)))) { DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n")); result = NT_STATUS_UNSUCCESSFUL; @@ -395,9 +418,14 @@ uint32 cli_lsa_lookup_names(struct cli_state *cli, POLICY_HND *pol, /* Query info policy */ -uint32 cli_lsa_query_info_policy(struct cli_state *cli, POLICY_HND *pol, - uint16 info_class, fstring domain_name, - DOM_SID * domain_sid) +uint32 cli_lsa_query_info_policy( + struct cli_state *cli, + TALLOC_CTX *mem_ctx, + POLICY_HND *pol, + uint16 info_class, + fstring domain_name, + DOM_SID * domain_sid +) { prs_struct qbuf, rbuf; LSA_Q_QUERY_INFO q; @@ -409,8 +437,8 @@ uint32 cli_lsa_query_info_policy(struct cli_state *cli, POLICY_HND *pol, /* Initialise parse structures */ - prs_init(&qbuf, MAX_PDU_FRAG_LEN, cli->mem_ctx, MARSHALL); - prs_init(&rbuf, 0, cli->mem_ctx, UNMARSHALL); + prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL); + prs_init(&rbuf, 0, mem_ctx, UNMARSHALL); /* Marshall data and send request */ @@ -479,9 +507,15 @@ uint32 cli_lsa_query_info_policy(struct cli_state *cli, POLICY_HND *pol, /* Enumerate list of trusted domains */ -uint32 cli_lsa_enum_trust_dom(struct cli_state *cli, POLICY_HND *pol, - uint32 *enum_ctx, uint32 *num_domains, - char ***domain_names, DOM_SID **domain_sids) +uint32 cli_lsa_enum_trust_dom( + struct cli_state *cli, + TALLOC_CTX *mem_ctx, + POLICY_HND *pol, + uint32 *enum_ctx, + uint32 *num_domains, + char ***domain_names, + DOM_SID **domain_sids +) { prs_struct qbuf, rbuf; LSA_Q_ENUM_TRUST_DOM q; @@ -494,8 +528,8 @@ uint32 cli_lsa_enum_trust_dom(struct cli_state *cli, POLICY_HND *pol, /* Initialise parse structures */ - prs_init(&qbuf, MAX_PDU_FRAG_LEN, cli->mem_ctx, MARSHALL); - prs_init(&rbuf, 0, cli->mem_ctx, UNMARSHALL); + prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL); + prs_init(&rbuf, 0, mem_ctx, UNMARSHALL); /* Marshall data and send request */ @@ -527,14 +561,14 @@ uint32 cli_lsa_enum_trust_dom(struct cli_state *cli, POLICY_HND *pol, /* Return output parameters */ - if (!((*domain_names) = (char **)malloc(sizeof(char *) * + if (!((*domain_names) = (char **)talloc(mem_ctx, sizeof(char *) * r.num_domains))) { DEBUG(0, ("cli_lsa_enum_trust_dom(): out of memory\n")); result = NT_STATUS_UNSUCCESSFUL; goto done; } - if (!((*domain_sids) = (DOM_SID *)malloc(sizeof(DOM_SID) * + if (!((*domain_sids) = (DOM_SID *)talloc(mem_ctx, sizeof(DOM_SID) * r.num_domains))) { DEBUG(0, ("cli_lsa_enum_trust_dom(): out of memory\n")); result = NT_STATUS_UNSUCCESSFUL; diff --git a/source3/libsmb/cli_samr.c b/source3/libsmb/cli_samr.c index 4c53bd0584..a822611445 100644 --- a/source3/libsmb/cli_samr.c +++ b/source3/libsmb/cli_samr.c @@ -84,8 +84,13 @@ void cli_samr_shutdown(struct cli_state *cli) /* Connect to SAMR database */ -uint32 cli_samr_connect(struct cli_state *cli, char *srv_name, - uint32 access_mask, POLICY_HND *connect_pol) +uint32 cli_samr_connect( + struct cli_state *cli, + TALLOC_CTX *mem_ctx, + char *srv_name, + uint32 access_mask, + POLICY_HND *connect_pol +) { prs_struct qbuf, rbuf; SAMR_Q_CONNECT q; @@ -97,8 +102,8 @@ uint32 cli_samr_connect(struct cli_state *cli, char *srv_name, /* Initialise parse structures */ - prs_init(&qbuf, MAX_PDU_FRAG_LEN, cli->mem_ctx, MARSHALL); - prs_init(&rbuf, 0, cli->mem_ctx, UNMARSHALL); + prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL); + prs_init(&rbuf, 0, mem_ctx, UNMARSHALL); /* Marshall data and send request */ @@ -132,7 +137,11 @@ uint32 cli_samr_connect(struct cli_state *cli, char *srv_name, /* Close SAMR handle */ -uint32 cli_samr_close(struct cli_state *cli, POLICY_HND *connect_pol) +uint32 cli_samr_close( + struct cli_state *cli, + TALLOC_CTX *mem_ctx, + POLICY_HND *connect_pol +) { prs_struct qbuf, rbuf; SAMR_Q_CLOSE_HND q; @@ -144,8 +153,8 @@ uint32 cli_samr_close(struct cli_state *cli, POLICY_HND *connect_pol) /* Initialise parse structures */ - prs_init(&qbuf, MAX_PDU_FRAG_LEN, cli->mem_ctx, MARSHALL); - prs_init(&rbuf, 0, cli->mem_ctx, UNMARSHALL); + prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL); + prs_init(&rbuf, 0, mem_ctx, UNMARSHALL); /* Marshall data and send request */ @@ -179,9 +188,14 @@ uint32 cli_samr_close(struct cli_state *cli, POLICY_HND *connect_pol) /* Open handle on a domain */ -uint32 cli_samr_open_domain(struct cli_state *cli, POLICY_HND *connect_pol, - uint32 access_mask, DOM_SID *domain_sid, - POLICY_HND *domain_pol) +uint32 cli_samr_open_domain( + struct cli_state *cli, + TALLOC_CTX *mem_ctx, + POLICY_HND *connect_pol, + uint32 access_mask, + DOM_SID *domain_sid, + POLICY_HND *domain_pol +) { prs_struct qbuf, rbuf; SAMR_Q_OPEN_DOMAIN q; @@ -193,8 +207,8 @@ uint32 cli_samr_open_domain(struct cli_state *cli, POLICY_HND *connect_pol, /* Initialise parse structures */ - prs_init(&qbuf, MAX_PDU_FRAG_LEN, cli->mem_ctx, MARSHALL); - prs_init(&rbuf, 0, cli->mem_ctx, UNMARSHALL); + prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL); + prs_init(&rbuf, 0, mem_ctx, UNMARSHALL); /* Marshall data and send request */ @@ -228,9 +242,14 @@ uint32 cli_samr_open_domain(struct cli_state *cli, POLICY_HND *connect_pol, /* Open handle on a user */ -uint32 cli_samr_open_user(struct cli_state *cli, POLICY_HND *domain_pol, - uint32 access_mask, uint32 user_rid, - POLICY_HND *user_pol) +uint32 cli_samr_open_user( + struct cli_state *cli, + TALLOC_CTX *mem_ctx, + POLICY_HND *domain_pol, + uint32 access_mask, + uint32 user_rid, + POLICY_HND *user_pol +) { prs_struct qbuf, rbuf; SAMR_Q_OPEN_USER q; @@ -242,8 +261,8 @@ uint32 cli_samr_open_user(struct cli_state *cli, POLICY_HND *domain_pol, /* Initialise parse structures */ - prs_init(&qbuf, MAX_PDU_FRAG_LEN, cli->mem_ctx, MARSHALL); - prs_init(&rbuf, 0, cli->mem_ctx, UNMARSHALL); + prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL); + prs_init(&rbuf, 0, mem_ctx, UNMARSHALL); /* Marshall data and send request */ @@ -277,9 +296,14 @@ uint32 cli_samr_open_user(struct cli_state *cli, POLICY_HND *domain_pol, /* Open handle on a group */ -uint32 cli_samr_open_group(struct cli_state *cli, POLICY_HND *domain_pol, - uint32 access_mask, uint32 group_rid, - POLICY_HND *group_pol) +uint32 cli_samr_open_group( + struct cli_state *cli, + TALLOC_CTX *mem_ctx, + POLICY_HND *domain_pol, + uint32 access_mask, + uint32 group_rid, + POLICY_HND *group_pol +) { prs_struct qbuf, rbuf; SAMR_Q_OPEN_GROUP q; @@ -291,8 +315,8 @@ uint32 cli_samr_open_group(struct cli_state *cli, POLICY_HND *domain_pol, /* Initialise parse structures */ - prs_init(&qbuf, MAX_PDU_FRAG_LEN, cli->mem_ctx, MARSHALL); - prs_init(&rbuf, 0, cli->mem_ctx, UNMARSHALL); + prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL); + prs_init(&rbuf, 0, mem_ctx, UNMARSHALL); /* Marshall data and send request */ @@ -326,8 +350,13 @@ uint32 cli_samr_open_group(struct cli_state *cli, POLICY_HND *domain_pol, /* Query user info */ -uint32 cli_samr_query_userinfo(struct cli_state *cli, POLICY_HND *user_pol, - uint16 switch_value, SAM_USERINFO_CTR *ctr) +uint32 cli_samr_query_userinfo( + struct cli_state *cli, + TALLOC_CTX *mem_ctx, + POLICY_HND *user_pol, + uint16 switch_value, + SAM_USERINFO_CTR *ctr +) { prs_struct qbuf, rbuf; SAMR_Q_QUERY_USERINFO q; @@ -339,8 +368,8 @@ uint32 cli_samr_query_userinfo(struct cli_state *cli, POLICY_HND *user_pol, /* Initialise parse structures */ - prs_init(&qbuf, MAX_PDU_FRAG_LEN, cli->mem_ctx, MARSHALL); - prs_init(&rbuf, 0, cli->mem_ctx, UNMARSHALL); + prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL); + prs_init(&rbuf, 0, mem_ctx, UNMARSHALL); /* Marshall data and send request */ @@ -374,8 +403,13 @@ uint32 cli_samr_query_userinfo(struct cli_state *cli, POLICY_HND *user_pol, /* Query group info */ -uint32 cli_samr_query_groupinfo(struct cli_state *cli, POLICY_HND *group_pol, - uint32 info_level, GROUP_INFO_CTR *ctr) +uint32 cli_samr_query_groupinfo( + struct cli_state *cli, + TALLOC_CTX *mem_ctx, + POLICY_HND *group_pol, + uint32 info_level, + GROUP_INFO_CTR *ctr +) { prs_struct qbuf, rbuf; SAMR_Q_QUERY_GROUPINFO q; @@ -387,8 +421,8 @@ uint32 cli_samr_query_groupinfo(struct cli_state *cli, POLICY_HND *group_pol, /* Initialise parse structures */ - prs_init(&qbuf, MAX_PDU_FRAG_LEN, cli->mem_ctx, MARSHALL); - prs_init(&rbuf, 0, cli->mem_ctx, UNMARSHALL); + prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL); + prs_init(&rbuf, 0, mem_ctx, UNMARSHALL); /* Marshall data and send request */ @@ -422,8 +456,13 @@ uint32 cli_samr_query_groupinfo(struct cli_state *cli, POLICY_HND *group_pol, /* Query user groups */ -uint32 cli_samr_query_usergroups(struct cli_state *cli, POLICY_HND *user_pol, - uint32 *num_groups, DOM_GID **gid) +uint32 cli_samr_query_usergroups( + struct cli_state *cli, + TALLOC_CTX *mem_ctx, + POLICY_HND *user_pol, + uint32 *num_groups, + DOM_GID **gid +) { prs_struct qbuf, rbuf; SAMR_Q_QUERY_USERGROUPS q; @@ -435,8 +474,8 @@ uint32 cli_samr_query_usergroups(struct cli_state *cli, POLICY_HND *user_pol, /* Initialise parse structures */ - prs_init(&qbuf, MAX_PDU_FRAG_LEN, cli->mem_ctx, MARSHALL); - prs_init(&rbuf, 0, cli->mem_ctx, UNMARSHALL); + prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL); + prs_init(&rbuf, 0, mem_ctx, UNMARSHALL); /* Marshall data and send request */ @@ -471,8 +510,14 @@ uint32 cli_samr_query_usergroups(struct cli_state *cli, POLICY_HND *user_pol, /* Query user groups */ -uint32 cli_samr_query_groupmem(struct cli_state *cli, POLICY_HND *group_pol, - uint32 *num_mem, uint32 **rid, uint32 **attr) +uint32 cli_samr_query_groupmem( + struct cli_state *cli, + TALLOC_CTX *mem_ctx, + POLICY_HND *group_pol, + uint32 *num_mem, + uint32 **rid, + uint32 **attr +) { prs_struct qbuf, rbuf; SAMR_Q_QUERY_GROUPMEM q; @@ -484,8 +529,8 @@ uint32 cli_samr_query_groupmem(struct cli_state *cli, POLICY_HND *group_pol, /* Initialise parse structures */ - prs_init(&qbuf, MAX_PDU_FRAG_LEN, cli->mem_ctx, MARSHALL); - prs_init(&rbuf, 0, cli->mem_ctx, UNMARSHALL); + prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL); + prs_init(&rbuf, 0, mem_ctx, UNMARSHALL); /* Marshall data and send request */ diff --git a/source3/libsmb/cli_spoolss.c b/source3/libsmb/cli_spoolss.c index db761e57bf..f68483dabe 100644 --- a/source3/libsmb/cli_spoolss.c +++ b/source3/libsmb/cli_spoolss.c @@ -87,10 +87,16 @@ void cli_spoolss_shutdown(struct cli_state *cli) /* Open printer ex */ -uint32 cli_spoolss_open_printer_ex(struct cli_state *cli, char *printername, - char *datatype, uint32 access_required, - char *station, char *username, - POLICY_HND *pol) +uint32 cli_spoolss_open_printer_ex( + struct cli_state *cli, + TALLOC_CTX *mem_ctx, + char *printername, + char *datatype, + uint32 access_required, + char *station, + char *username, + POLICY_HND *pol +) { prs_struct qbuf, rbuf; SPOOL_Q_OPEN_PRINTER_EX q; @@ -102,8 +108,8 @@ uint32 cli_spoolss_open_printer_ex(struct cli_state *cli, char *printername, /* Initialise parse structures */ - prs_init(&qbuf, MAX_PDU_FRAG_LEN, cli->mem_ctx, MARSHALL); - prs_init(&rbuf, 0, cli->mem_ctx, UNMARSHALL); + prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL); + prs_init(&rbuf, 0, mem_ctx, UNMARSHALL); /* Initialise input parameters */ @@ -140,7 +146,11 @@ uint32 cli_spoolss_open_printer_ex(struct cli_state *cli, char *printername, /* Close a printer handle */ -uint32 cli_spoolss_close_printer(struct cli_state *cli, POLICY_HND *pol) +uint32 cli_spoolss_close_printer( + struct cli_state *cli, + TALLOC_CTX *mem_ctx, + POLICY_HND *pol +) { prs_struct qbuf, rbuf; SPOOL_Q_CLOSEPRINTER q; @@ -152,8 +162,8 @@ uint32 cli_spoolss_close_printer(struct cli_state *cli, POLICY_HND *pol) /* Initialise parse structures */ - prs_init(&qbuf, MAX_PDU_FRAG_LEN, cli->mem_ctx, MARSHALL); - prs_init(&rbuf, 0, cli->mem_ctx, UNMARSHALL); + prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL); + prs_init(&rbuf, 0, mem_ctx, UNMARSHALL); /* Initialise input parameters */ @@ -201,8 +211,12 @@ static void init_buffer(NEW_BUFFER *buffer, uint32 size, TALLOC_CTX *ctx) /* Decode various printer info levels - perhaps this should live in parse_spoolss.c? */ -static void decode_printer_info_0(NEW_BUFFER *buffer, uint32 returned, - PRINTER_INFO_0 **info) +static void decode_printer_info_0( + TALLOC_CTX *mem_ctx, + NEW_BUFFER *buffer, + uint32 returned, + PRINTER_INFO_0 **info +) { uint32 i; PRINTER_INFO_0 *inf; @@ -218,13 +232,17 @@ static void decode_printer_info_0(NEW_BUFFER *buffer, uint32 returned, *info=inf; } -static void decode_printer_info_1(NEW_BUFFER *buffer, uint32 returned, - PRINTER_INFO_1 **info) +static void decode_printer_info_1( + TALLOC_CTX *mem_ctx, + NEW_BUFFER *buffer, + uint32 returned, + PRINTER_INFO_1 **info +) { uint32 i; PRINTER_INFO_1 *inf; - inf=(PRINTER_INFO_1 *)malloc(returned*sizeof(PRINTER_INFO_1)); + inf=(PRINTER_INFO_1 *)talloc(mem_ctx, returned*sizeof(PRINTER_INFO_1)); buffer->prs.data_offset=0; @@ -235,13 +253,17 @@ static void decode_printer_info_1(NEW_BUFFER *buffer, uint32 returned, *info=inf; } -static void decode_printer_info_2(NEW_BUFFER *buffer, uint32 returned, - PRINTER_INFO_2 **info) +static void decode_printer_info_2( + TALLOC_CTX *mem_ctx, + NEW_BUFFER *buffer, + uint32 returned, + PRINTER_INFO_2 **info +) { uint32 i; PRINTER_INFO_2 *inf; - inf=(PRINTER_INFO_2 *)malloc(returned*sizeof(PRINTER_INFO_2)); + inf=(PRINTER_INFO_2 *)talloc(mem_ctx, returned*sizeof(PRINTER_INFO_2)); buffer->prs.data_offset=0; @@ -254,13 +276,17 @@ static void decode_printer_info_2(NEW_BUFFER *buffer, uint32 returned, *info=inf; } -static void decode_printer_info_3(NEW_BUFFER *buffer, uint32 returned, - PRINTER_INFO_3 **info) +static void decode_printer_info_3( + TALLOC_CTX *mem_ctx, + NEW_BUFFER *buffer, + uint32 returned, + PRINTER_INFO_3 **info +) { uint32 i; PRINTER_INFO_3 *inf; - inf=(PRINTER_INFO_3 *)malloc(returned*sizeof(PRINTER_INFO_3)); + inf=(PRINTER_INFO_3 *)talloc(mem_ctx, returned*sizeof(PRINTER_INFO_3)); buffer->prs.data_offset=0; @@ -275,13 +301,17 @@ static void decode_printer_info_3(NEW_BUFFER *buffer, uint32 returned, /********************************************************************** Decode a PORT_INFO_1 struct from a NEW_BUFFER **********************************************************************/ -static void decode_port_info_1(NEW_BUFFER *buffer, uint32 returned, - PORT_INFO_1 **info) +static void decode_port_info_1( + TALLOC_CTX *mem_ctx, + NEW_BUFFER *buffer, + uint32 returned, + PORT_INFO_1 **info +) { uint32 i; PORT_INFO_1 *inf; - inf=(PORT_INFO_1*)malloc(returned*sizeof(PORT_INFO_1)); + inf=(PORT_INFO_1*)talloc(mem_ctx, returned*sizeof(PORT_INFO_1)); prs_set_offset(&buffer->prs, 0); @@ -295,13 +325,16 @@ static void decode_port_info_1(NEW_BUFFER *buffer, uint32 returned, /********************************************************************** Decode a PORT_INFO_2 struct from a NEW_BUFFER **********************************************************************/ -static void decode_port_info_2(NEW_BUFFER *buffer, uint32 returned, - PORT_INFO_2 **info) +static void decode_port_info_2( + TALLOC_CTX *mem_ctx, + NEW_BUFFER *buffer, + uint32 returned, + PORT_INFO_2 **info) { uint32 i; PORT_INFO_2 *inf; - inf=(PORT_INFO_2*)malloc(returned*sizeof(PORT_INFO_2)); + inf=(PORT_INFO_2*)talloc(mem_ctx, returned*sizeof(PORT_INFO_2)); prs_set_offset(&buffer->prs, 0); @@ -312,13 +345,17 @@ static void decode_port_info_2(NEW_BUFFER *buffer, uint32 returned, *info=inf; } -static void decode_printer_driver_1(NEW_BUFFER *buffer, uint32 returned, - DRIVER_INFO_1 **info) +static void decode_printer_driver_1( + TALLOC_CTX *mem_ctx, + NEW_BUFFER *buffer, + uint32 returned, + DRIVER_INFO_1 **info +) { uint32 i; DRIVER_INFO_1 *inf; - inf=(DRIVER_INFO_1 *)malloc(returned*sizeof(DRIVER_INFO_1)); + inf=(DRIVER_INFO_1 *)talloc(mem_ctx, returned*sizeof(DRIVER_INFO_1)); buffer->prs.data_offset=0; @@ -329,13 +366,17 @@ static void decode_printer_driver_1(NEW_BUFFER *buffer, uint32 returned, *info=inf; } -static void decode_printer_driver_2(NEW_BUFFER *buffer, uint32 returned, - DRIVER_INFO_2 **info) +static void decode_printer_driver_2( + TALLOC_CTX *mem_ctx, + NEW_BUFFER *buffer, + uint32 returned, + DRIVER_INFO_2 **info +) { uint32 i; DRIVER_INFO_2 *inf; - inf=(DRIVER_INFO_2 *)malloc(returned*sizeof(DRIVER_INFO_2)); + inf=(DRIVER_INFO_2 *)talloc(mem_ctx, returned*sizeof(DRIVER_INFO_2)); buffer->prs.data_offset=0; @@ -347,6 +388,7 @@ static void decode_printer_driver_2(NEW_BUFFER *buffer, uint32 returned, } static void decode_printer_driver_3( + TALLOC_CTX *mem_ctx, NEW_BUFFER *buffer, uint32 returned, DRIVER_INFO_3 **info @@ -355,7 +397,7 @@ static void decode_printer_driver_3( uint32 i; DRIVER_INFO_3 *inf; - inf=(DRIVER_INFO_3 *)malloc(returned*sizeof(DRIVER_INFO_3)); + inf=(DRIVER_INFO_3 *)talloc(mem_ctx, returned*sizeof(DRIVER_INFO_3)); buffer->prs.data_offset=0; @@ -367,6 +409,7 @@ static void decode_printer_driver_3( } static void decode_printerdriverdir_1 ( + TALLOC_CTX *mem_ctx, NEW_BUFFER *buffer, uint32 returned, DRIVER_DIRECTORY_1 **info @@ -374,7 +417,7 @@ static void decode_printerdriverdir_1 ( { DRIVER_DIRECTORY_1 *inf; - inf=(DRIVER_DIRECTORY_1 *)malloc(sizeof(DRIVER_DIRECTORY_1)); + inf=(DRIVER_DIRECTORY_1 *)talloc(mem_ctx, sizeof(DRIVER_DIRECTORY_1)); prs_set_offset(&buffer->prs, 0); @@ -386,9 +429,14 @@ static void decode_printerdriverdir_1 ( /* Enumerate printers */ -uint32 cli_spoolss_enum_printers(struct cli_state *cli, uint32 flags, - uint32 level, int *returned, - PRINTER_INFO_CTR *ctr) +uint32 cli_spoolss_enum_printers( + struct cli_state *cli, + TALLOC_CTX *mem_ctx, + uint32 flags, + uint32 level, + int *returned, + PRINTER_INFO_CTR *ctr +) { prs_struct qbuf, rbuf; SPOOL_Q_ENUMPRINTERS q; @@ -407,10 +455,10 @@ uint32 cli_spoolss_enum_printers(struct cli_state *cli, uint32 flags, do { /* Initialise input parameters */ - init_buffer(&buffer, needed, cli->mem_ctx); + init_buffer(&buffer, needed, mem_ctx); - prs_init(&qbuf, MAX_PDU_FRAG_LEN, cli->mem_ctx, MARSHALL); - prs_init(&rbuf, 0, cli->mem_ctx, UNMARSHALL); + prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL); + prs_init(&rbuf, 0, mem_ctx, UNMARSHALL); make_spoolss_q_enumprinters(&q, flags, server, level, &buffer, needed); @@ -430,21 +478,20 @@ uint32 cli_spoolss_enum_printers(struct cli_state *cli, uint32 flags, /* Return output parameters */ - if ((result = r.status) == NT_STATUS_NOPROBLEMO && r.returned > 0) { - - *returned = r.returned; + if (((result=r.status) == NT_STATUS_NOPROBLEMO) && (*returned = r.returned)) + { switch (level) { case 1: - decode_printer_info_1(r.buffer, r.returned, + decode_printer_info_1(mem_ctx, r.buffer, r.returned, &ctr->printers_1); break; case 2: - decode_printer_info_2(r.buffer, r.returned, + decode_printer_info_2(mem_ctx, r.buffer, r.returned, &ctr->printers_2); break; case 3: - decode_printer_info_3(r.buffer, r.returned, + decode_printer_info_3(mem_ctx, r.buffer, r.returned, &ctr->printers_3); break; } @@ -460,8 +507,13 @@ uint32 cli_spoolss_enum_printers(struct cli_state *cli, uint32 flags, } /* Enumerate printer ports */ -uint32 cli_spoolss_enum_ports(struct cli_state *cli, uint32 level, - int *returned, PORT_INFO_CTR *ctr) +uint32 cli_spoolss_enum_ports( + struct cli_state *cli, + TALLOC_CTX *mem_ctx, + uint32 level, + int *returned, + PORT_INFO_CTR *ctr +) { prs_struct qbuf, rbuf; SPOOL_Q_ENUMPORTS q; @@ -480,10 +532,10 @@ uint32 cli_spoolss_enum_ports(struct cli_state *cli, uint32 level, do { /* Initialise input parameters */ - init_buffer(&buffer, needed, cli->mem_ctx); + init_buffer(&buffer, needed, mem_ctx); - prs_init(&qbuf, MAX_PDU_FRAG_LEN, cli->mem_ctx, MARSHALL); - prs_init(&rbuf, 0, cli->mem_ctx, UNMARSHALL); + prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL); + prs_init(&rbuf, 0, mem_ctx, UNMARSHALL); make_spoolss_q_enumports(&q, server, level, &buffer, needed); @@ -509,11 +561,11 @@ uint32 cli_spoolss_enum_ports(struct cli_state *cli, uint32 level, switch (level) { case 1: - decode_port_info_1(r.buffer, r.returned, + decode_port_info_1(mem_ctx, r.buffer, r.returned, &ctr->port.info_1); break; case 2: - decode_port_info_2(r.buffer, r.returned, + decode_port_info_2(mem_ctx, r.buffer, r.returned, &ctr->port.info_2); break; } @@ -531,6 +583,7 @@ uint32 cli_spoolss_enum_ports(struct cli_state *cli, uint32 level, /* Get printer info */ uint32 cli_spoolss_getprinter( struct cli_state *cli, + TALLOC_CTX *mem_ctx, POLICY_HND *pol, uint32 level, PRINTER_INFO_CTR *ctr @@ -549,12 +602,12 @@ uint32 cli_spoolss_getprinter( do { /* Initialise input parameters */ - init_buffer(&buffer, needed, cli->mem_ctx); + init_buffer(&buffer, needed, mem_ctx); - prs_init(&qbuf, MAX_PDU_FRAG_LEN, cli->mem_ctx, MARSHALL); - prs_init(&rbuf, 0, cli->mem_ctx, UNMARSHALL); + prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL); + prs_init(&rbuf, 0, mem_ctx, UNMARSHALL); - make_spoolss_q_getprinter(&q, pol, level, &buffer, needed); + make_spoolss_q_getprinter(mem_ctx, &q, pol, level, &buffer, needed); /* Marshall data and send request */ if (!spoolss_io_q_getprinter("", &q, &qbuf, 0) || @@ -574,16 +627,16 @@ uint32 cli_spoolss_getprinter( switch (level) { case 0: - decode_printer_info_0(r.buffer, 1, &ctr->printers_0); + decode_printer_info_0(mem_ctx, r.buffer, 1, &ctr->printers_0); break; case 1: - decode_printer_info_1(r.buffer, 1, &ctr->printers_1); + decode_printer_info_1(mem_ctx, r.buffer, 1, &ctr->printers_1); break; case 2: - decode_printer_info_2(r.buffer, 1, &ctr->printers_2); + decode_printer_info_2(mem_ctx, r.buffer, 1, &ctr->printers_2); break; case 3: - decode_printer_info_3(r.buffer, 1, &ctr->printers_3); + decode_printer_info_3(mem_ctx, r.buffer, 1, &ctr->printers_3); break; } } @@ -602,6 +655,7 @@ uint32 cli_spoolss_getprinter( */ uint32 cli_spoolss_setprinter( struct cli_state *cli, + TALLOC_CTX *mem_ctx, POLICY_HND *pol, uint32 level, PRINTER_INFO_CTR *ctr, @@ -617,10 +671,10 @@ uint32 cli_spoolss_setprinter( ZERO_STRUCT(r); /* Initialise input parameters */ - prs_init(&qbuf, MAX_PDU_FRAG_LEN, cli->mem_ctx, MARSHALL); - prs_init(&rbuf, 0, cli->mem_ctx, UNMARSHALL); + prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL); + prs_init(&rbuf, 0, mem_ctx, UNMARSHALL); - make_spoolss_q_setprinter(&q, pol, level, ctr, command); + make_spoolss_q_setprinter(mem_ctx, &q, pol, level, ctr, command); /* Marshall data and send request */ result = NT_STATUS_UNSUCCESSFUL; @@ -653,6 +707,7 @@ done: */ uint32 cli_spoolss_getprinterdriver ( struct cli_state *cli, + TALLOC_CTX *mem_ctx, POLICY_HND *pol, uint32 level, char* env, @@ -677,10 +732,10 @@ uint32 cli_spoolss_getprinterdriver ( { /* Initialise input parameters */ - init_buffer(&buffer, needed, cli->mem_ctx); + init_buffer(&buffer, needed, mem_ctx); - prs_init(&qbuf, MAX_PDU_FRAG_LEN, cli->mem_ctx, MARSHALL); - prs_init(&rbuf, 0, cli->mem_ctx, UNMARSHALL); + prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL); + prs_init(&rbuf, 0, mem_ctx, UNMARSHALL); /* write the request */ @@ -707,13 +762,13 @@ uint32 cli_spoolss_getprinterdriver ( switch (level) { case 1: - decode_printer_driver_1(r.buffer, 1, &ctr->info1); + decode_printer_driver_1(mem_ctx, r.buffer, 1, &ctr->info1); break; case 2: - decode_printer_driver_2(r.buffer, 1, &ctr->info2); + decode_printer_driver_2(mem_ctx, r.buffer, 1, &ctr->info2); break; case 3: - decode_printer_driver_3(r.buffer, 1, &ctr->info3); + decode_printer_driver_3(mem_ctx, r.buffer, 1, &ctr->info3); break; } } @@ -732,6 +787,7 @@ uint32 cli_spoolss_getprinterdriver ( */ uint32 cli_spoolss_enumprinterdrivers ( struct cli_state *cli, + TALLOC_CTX *mem_ctx, uint32 level, char* env, uint32 *returned, @@ -755,10 +811,10 @@ uint32 cli_spoolss_enumprinterdrivers ( do { /* Initialise input parameters */ - init_buffer(&buffer, needed, cli->mem_ctx); + init_buffer(&buffer, needed, mem_ctx); - prs_init(&qbuf, MAX_PDU_FRAG_LEN, cli->mem_ctx, MARSHALL); - prs_init(&rbuf, 0, cli->mem_ctx, UNMARSHALL); + prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL); + prs_init(&rbuf, 0, mem_ctx, UNMARSHALL); /* write the request */ @@ -787,13 +843,13 @@ uint32 cli_spoolss_enumprinterdrivers ( switch (level) { case 1: - decode_printer_driver_1(r.buffer, r.returned, &ctr->info1); + decode_printer_driver_1(mem_ctx, r.buffer, r.returned, &ctr->info1); break; case 2: - decode_printer_driver_2(r.buffer, r.returned, &ctr->info2); + decode_printer_driver_2(mem_ctx, r.buffer, r.returned, &ctr->info2); break; case 3: - decode_printer_driver_3(r.buffer, r.returned, &ctr->info3); + decode_printer_driver_3(mem_ctx, r.buffer, r.returned, &ctr->info3); break; } } @@ -813,6 +869,7 @@ uint32 cli_spoolss_enumprinterdrivers ( */ uint32 cli_spoolss_getprinterdriverdir ( struct cli_state *cli, + TALLOC_CTX *mem_ctx, uint32 level, char* env, DRIVER_DIRECTORY_CTR *ctr @@ -835,10 +892,10 @@ uint32 cli_spoolss_getprinterdriverdir ( do { /* Initialise input parameters */ - init_buffer(&buffer, needed, cli->mem_ctx); + init_buffer(&buffer, needed, mem_ctx); - prs_init(&qbuf, MAX_PDU_FRAG_LEN, cli->mem_ctx, MARSHALL); - prs_init(&rbuf, 0, cli->mem_ctx, UNMARSHALL); + prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL); + prs_init(&rbuf, 0, mem_ctx, UNMARSHALL); /* write the request */ @@ -864,7 +921,7 @@ uint32 cli_spoolss_getprinterdriverdir ( switch (level) { case 1: - decode_printerdriverdir_1(r.buffer, 1, &ctr->info1); + decode_printerdriverdir_1(mem_ctx, r.buffer, 1, &ctr->info1); break; } } @@ -883,6 +940,7 @@ uint32 cli_spoolss_getprinterdriverdir ( */ uint32 cli_spoolss_addprinterdriver ( struct cli_state *cli, + TALLOC_CTX *mem_ctx, uint32 level, PRINTER_DRIVER_CTR *ctr ) @@ -890,22 +948,22 @@ uint32 cli_spoolss_addprinterdriver ( prs_struct qbuf, rbuf; SPOOL_Q_ADDPRINTERDRIVER q; SPOOL_R_ADDPRINTERDRIVER r; - uint32 result; + uint32 result = NT_STATUS_UNSUCCESSFUL; fstring server; ZERO_STRUCT(q); ZERO_STRUCT(r); - + slprintf (server, sizeof(fstring)-1, "\\\\%s", cli->desthost); strupper (server); /* Initialise input parameters */ - prs_init(&qbuf, MAX_PDU_FRAG_LEN, cli->mem_ctx, MARSHALL); - prs_init(&rbuf, 0, cli->mem_ctx, UNMARSHALL); + prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL); + prs_init(&rbuf, 0, mem_ctx, UNMARSHALL); /* write the request */ - make_spoolss_q_addprinterdriver (&q, server, level, ctr); + make_spoolss_q_addprinterdriver (mem_ctx, &q, server, level, ctr); /* Marshall data and send request */ result = NT_STATUS_UNSUCCESSFUL; @@ -929,7 +987,7 @@ uint32 cli_spoolss_addprinterdriver ( done: prs_mem_free(&qbuf); prs_mem_free(&rbuf); - + return result; } @@ -938,6 +996,7 @@ done: */ uint32 cli_spoolss_addprinterex ( struct cli_state *cli, + TALLOC_CTX *mem_ctx, uint32 level, PRINTER_INFO_CTR *ctr ) @@ -961,12 +1020,12 @@ uint32 cli_spoolss_addprinterex ( /* Initialise input parameters */ - prs_init(&qbuf, MAX_PDU_FRAG_LEN, cli->mem_ctx, MARSHALL); - prs_init(&rbuf, 0, cli->mem_ctx, UNMARSHALL); + prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL); + prs_init(&rbuf, 0, mem_ctx, UNMARSHALL); /* write the request */ - make_spoolss_q_addprinterex (&q, server, client, user, level, ctr); + make_spoolss_q_addprinterex (mem_ctx, &q, server, client, user, level, ctr); /* Marshall data and send request */ result = NT_STATUS_UNSUCCESSFUL; |