summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
Diffstat (limited to 'source3')
-rw-r--r--source3/include/passdb.h2
-rw-r--r--source3/include/proto.h332
-rw-r--r--source3/include/rpc_client.h2
-rw-r--r--source3/include/rpc_client_proto.h232
-rw-r--r--source3/libsmb/cli_lsarpc.c104
-rw-r--r--source3/libsmb/cli_samr.c121
-rw-r--r--source3/libsmb/cli_spoolss.c237
-rw-r--r--source3/rpc_parse/parse_spoolss.c44
-rw-r--r--source3/rpcclient/cmd_lsarpc.c66
-rw-r--r--source3/rpcclient/cmd_samr.c90
-rw-r--r--source3/rpcclient/cmd_spoolss.c223
-rw-r--r--source3/rpcclient/rpcclient.c94
-rw-r--r--source3/utils/smbcacls.c6
13 files changed, 890 insertions, 663 deletions
diff --git a/source3/include/passdb.h b/source3/include/passdb.h
index 302e69105f..8836bad3e2 100644
--- a/source3/include/passdb.h
+++ b/source3/include/passdb.h
@@ -69,7 +69,7 @@ struct uidmap_ops {
int (*sid_to_id) (DOM_SID* sid, SMB_SID_T type);
/* From UNIX to NT */
- DOM_SID* (*id_to_sid) (int id);
+ DOM_SID* (*id_to_sid) (int id, SMB_SID_T type);
};
diff --git a/source3/include/proto.h b/source3/include/proto.h
index 2d2ea90bdf..33aac50332 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -774,47 +774,126 @@ unsigned long wins_srv_count( void );
struct cli_state *cli_lsa_initialise(struct cli_state *cli, char *system_name,
struct ntuser_creds *creds);
void cli_lsa_shutdown(struct cli_state *cli);
-uint32 cli_lsa_open_policy(struct cli_state *cli, BOOL sec_qos,
- uint32 des_access, POLICY_HND *pol);
-uint32 cli_lsa_close(struct cli_state *cli, POLICY_HND *pol);
-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_names(struct cli_state *cli, POLICY_HND *pol,
- int num_names, char **names, DOM_SID **sids,
- uint32 **types, int *num_sids);
-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_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_open_policy(
+ struct cli_state *cli,
+ TALLOC_CTX *mem_ctx,
+ BOOL sec_qos,
+ uint32 des_access,
+ POLICY_HND *pol
+);
+uint32 cli_lsa_close(
+ struct cli_state *cli,
+ TALLOC_CTX *mem_ctx,
+ POLICY_HND *pol
+);
+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
+);
+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
+);
+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
+);
+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
+);
/*The following definitions come from libsmb/cli_samr.c */
struct cli_state *cli_samr_initialise(struct cli_state *cli, char *system_name,
struct ntuser_creds *creds);
void cli_samr_shutdown(struct cli_state *cli);
-uint32 cli_samr_connect(struct cli_state *cli, char *srv_name,
- uint32 access_mask, POLICY_HND *connect_pol);
-uint32 cli_samr_close(struct cli_state *cli, POLICY_HND *connect_pol);
-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_user(struct cli_state *cli, POLICY_HND *domain_pol,
- uint32 access_mask, uint32 user_rid,
- POLICY_HND *user_pol);
-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_query_userinfo(struct cli_state *cli, POLICY_HND *user_pol,
- uint16 switch_value, SAM_USERINFO_CTR *ctr);
-uint32 cli_samr_query_groupinfo(struct cli_state *cli, POLICY_HND *group_pol,
- uint32 info_level, GROUP_INFO_CTR *ctr);
-uint32 cli_samr_query_usergroups(struct cli_state *cli, POLICY_HND *user_pol,
- uint32 *num_groups, DOM_GID **gid);
-uint32 cli_samr_query_groupmem(struct cli_state *cli, POLICY_HND *group_pol,
- uint32 *num_mem, uint32 **rid, uint32 **attr);
+uint32 cli_samr_connect(
+ struct cli_state *cli,
+ TALLOC_CTX *mem_ctx,
+ char *srv_name,
+ uint32 access_mask,
+ POLICY_HND *connect_pol
+);
+uint32 cli_samr_close(
+ struct cli_state *cli,
+ TALLOC_CTX *mem_ctx,
+ POLICY_HND *connect_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
+);
+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
+);
+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
+);
+uint32 cli_samr_query_userinfo(
+ struct cli_state *cli,
+ TALLOC_CTX *mem_ctx,
+ POLICY_HND *user_pol,
+ uint16 switch_value,
+ SAM_USERINFO_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
+);
+uint32 cli_samr_query_usergroups(
+ struct cli_state *cli,
+ TALLOC_CTX *mem_ctx,
+ POLICY_HND *user_pol,
+ uint32 *num_groups,
+ DOM_GID **gid
+);
+uint32 cli_samr_query_groupmem(
+ struct cli_state *cli,
+ TALLOC_CTX *mem_ctx,
+ POLICY_HND *group_pol,
+ uint32 *num_mem,
+ uint32 **rid,
+ uint32 **attr
+);
/*The following definitions come from libsmb/cli_spoolss.c */
@@ -822,24 +901,46 @@ struct cli_state *cli_spoolss_initialise(struct cli_state *cli,
char *system_name,
struct ntuser_creds *creds);
void cli_spoolss_shutdown(struct cli_state *cli);
-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_close_printer(struct cli_state *cli, POLICY_HND *pol);
-uint32 cli_spoolss_enum_printers(struct cli_state *cli, uint32 flags,
- uint32 level, int *returned,
- PRINTER_INFO_CTR *ctr);
-uint32 cli_spoolss_enum_ports(struct cli_state *cli, uint32 level,
- int *returned, PORT_INFO_CTR *ctr);
+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
+);
+uint32 cli_spoolss_close_printer(
+ struct cli_state *cli,
+ TALLOC_CTX *mem_ctx,
+ POLICY_HND *pol
+);
+uint32 cli_spoolss_enum_printers(
+ struct cli_state *cli,
+ TALLOC_CTX *mem_ctx,
+ uint32 flags,
+ uint32 level,
+ int *returned,
+ PRINTER_INFO_CTR *ctr
+);
+uint32 cli_spoolss_enum_ports(
+ struct cli_state *cli,
+ TALLOC_CTX *mem_ctx,
+ uint32 level,
+ int *returned,
+ PORT_INFO_CTR *ctr
+);
uint32 cli_spoolss_getprinter(
struct cli_state *cli,
+ TALLOC_CTX *mem_ctx,
POLICY_HND *pol,
uint32 level,
PRINTER_INFO_CTR *ctr
);
uint32 cli_spoolss_setprinter(
struct cli_state *cli,
+ TALLOC_CTX *mem_ctx,
POLICY_HND *pol,
uint32 level,
PRINTER_INFO_CTR *ctr,
@@ -847,6 +948,7 @@ uint32 cli_spoolss_setprinter(
);
uint32 cli_spoolss_getprinterdriver (
struct cli_state *cli,
+ TALLOC_CTX *mem_ctx,
POLICY_HND *pol,
uint32 level,
char* env,
@@ -854,6 +956,7 @@ uint32 cli_spoolss_getprinterdriver (
);
uint32 cli_spoolss_enumprinterdrivers (
struct cli_state *cli,
+ TALLOC_CTX *mem_ctx,
uint32 level,
char* env,
uint32 *returned,
@@ -861,17 +964,20 @@ uint32 cli_spoolss_enumprinterdrivers (
);
uint32 cli_spoolss_getprinterdriverdir (
struct cli_state *cli,
+ TALLOC_CTX *mem_ctx,
uint32 level,
char* env,
DRIVER_DIRECTORY_CTR *ctr
);
uint32 cli_spoolss_addprinterdriver (
struct cli_state *cli,
+ TALLOC_CTX *mem_ctx,
uint32 level,
PRINTER_DRIVER_CTR *ctr
);
uint32 cli_spoolss_addprinterex (
struct cli_state *cli,
+ TALLOC_CTX *mem_ctx,
uint32 level,
PRINTER_INFO_CTR *ctr
);
@@ -2232,88 +2338,6 @@ void cli_nt_set_ntlmssp_flgs(struct cli_state *cli, uint32 ntlmssp_flgs);
BOOL cli_nt_session_open(struct cli_state *cli, char *pipe_name);
void cli_nt_session_close(struct cli_state *cli);
-/*The following definitions come from rpc_client/cli_reg.c */
-
-BOOL do_reg_connect(struct cli_state *cli, char *full_keyname, char *key_name,
- POLICY_HND *reg_hnd);
-BOOL do_reg_open_hklm(struct cli_state *cli, uint16 unknown_0, uint32 level,
- POLICY_HND *hnd);
-BOOL do_reg_open_hku(struct cli_state *cli, uint16 unknown_0, uint32 level,
- POLICY_HND *hnd);
-BOOL do_reg_flush_key(struct cli_state *cli, POLICY_HND *hnd);
-BOOL do_reg_query_key(struct cli_state *cli, POLICY_HND *hnd,
- char *class, uint32 *class_len,
- uint32 *num_subkeys, uint32 *max_subkeylen,
- uint32 *max_subkeysize, uint32 *num_values,
- uint32 *max_valnamelen, uint32 *max_valbufsize,
- uint32 *sec_desc, NTTIME *mod_time);
-BOOL do_reg_unknown_1a(struct cli_state *cli, POLICY_HND *hnd, uint32 *unk);
-BOOL do_reg_query_info(struct cli_state *cli, POLICY_HND *hnd,
- char *key_value, uint32* key_type);
-BOOL do_reg_set_key_sec(struct cli_state *cli, POLICY_HND *hnd, SEC_DESC_BUF *sec_desc_buf);
-BOOL do_reg_get_key_sec(struct cli_state *cli, POLICY_HND *hnd, uint32 *sec_buf_size, SEC_DESC_BUF **ppsec_desc_buf);
-BOOL do_reg_delete_val(struct cli_state *cli, POLICY_HND *hnd, char *val_name);
-BOOL do_reg_delete_key(struct cli_state *cli, POLICY_HND *hnd, char *key_name);
-BOOL do_reg_create_key(struct cli_state *cli, POLICY_HND *hnd,
- char *key_name, char *key_class,
- SEC_ACCESS *sam_access,
- POLICY_HND *key);
-BOOL do_reg_enum_key(struct cli_state *cli, POLICY_HND *hnd,
- int key_index, char *key_name,
- uint32 *unk_1, uint32 *unk_2,
- time_t *mod_time);
-BOOL do_reg_create_val(struct cli_state *cli, POLICY_HND *hnd,
- char *val_name, uint32 type, BUFFER3 *data);
-BOOL do_reg_enum_val(struct cli_state *cli, POLICY_HND *hnd,
- int val_index, int max_valnamelen, int max_valbufsize,
- fstring val_name,
- uint32 *val_type, BUFFER2 *value);
-BOOL do_reg_open_entry(struct cli_state *cli, POLICY_HND *hnd,
- char *key_name, uint32 unk_0,
- POLICY_HND *key_hnd);
-BOOL do_reg_close(struct cli_state *cli, POLICY_HND *hnd);
-
-/*The following definitions come from rpc_client/cli_samr.c */
-
-BOOL get_samr_query_usergroups(struct cli_state *cli,
- POLICY_HND *pol_open_domain, uint32 user_rid,
- uint32 *num_groups, DOM_GID *gid);
-BOOL get_samr_query_userinfo(struct cli_state *cli,
- POLICY_HND *pol_open_domain,
- uint32 info_level,
- uint32 user_rid, SAM_USER_INFO_21 *usr);
-BOOL do_samr_chgpasswd_user(struct cli_state *cli,
- char *srv_name, char *user_name,
- char nt_newpass[516], uchar nt_oldhash[16],
- char lm_newpass[516], uchar lm_oldhash[16]);
-BOOL do_samr_unknown_38(struct cli_state *cli, char *srv_name);
-BOOL do_samr_query_dom_info(struct cli_state *cli,
- POLICY_HND *domain_pol, uint16 switch_value);
-BOOL do_samr_enum_dom_users(struct cli_state *cli,
- POLICY_HND *pol, uint16 num_entries, uint16 unk_0,
- uint16 acb_mask, uint16 unk_1, uint32 size,
- struct acct_info **sam,
- int *num_sam_users);
-BOOL do_samr_connect(struct cli_state *cli,
- char *srv_name, uint32 unknown_0,
- POLICY_HND *connect_pol);
-BOOL do_samr_open_user(struct cli_state *cli,
- POLICY_HND *pol, uint32 unk_0, uint32 rid,
- POLICY_HND *user_pol);
-BOOL do_samr_open_domain(struct cli_state *cli,
- POLICY_HND *connect_pol, uint32 rid, DOM_SID *sid,
- POLICY_HND *domain_pol);
-BOOL do_samr_query_unknown_12(struct cli_state *cli,
- POLICY_HND *pol, uint32 rid, uint32 num_gids, uint32 *gids,
- uint32 *num_aliases,
- fstring als_names [MAX_LOOKUP_SIDS],
- uint32 num_als_users[MAX_LOOKUP_SIDS]);
-BOOL do_samr_query_usergroups(struct cli_state *cli,
- POLICY_HND *pol, uint32 *num_groups, DOM_GID *gid);
-BOOL do_samr_query_userinfo(struct cli_state *cli,
- POLICY_HND *pol, uint16 switch_value, void* usr);
-BOOL do_samr_close(struct cli_state *cli, POLICY_HND *hnd);
-
/*The following definitions come from rpc_client/cli_spoolss_notify.c */
BOOL spoolss_disconnect_from_client( struct cli_state *cli);
@@ -2323,30 +2347,6 @@ BOOL cli_spoolss_reply_rrpcn(struct cli_state *cli, POLICY_HND *handle,
uint32 change_low, uint32 change_high, uint32 *status);
BOOL cli_spoolss_reply_close_printer(struct cli_state *cli, POLICY_HND *handle, uint32 *status);
-/*The following definitions come from rpc_client/cli_srvsvc.c */
-
-BOOL do_srv_net_srv_conn_enum(struct cli_state *cli,
- char *server_name, char *qual_name,
- uint32 switch_value, SRV_CONN_INFO_CTR *ctr,
- uint32 preferred_len,
- ENUM_HND *hnd);
-BOOL do_srv_net_srv_sess_enum(struct cli_state *cli,
- char *server_name, char *qual_name,
- uint32 switch_value, SRV_SESS_INFO_CTR *ctr,
- uint32 preferred_len,
- ENUM_HND *hnd);
-BOOL do_srv_net_srv_share_enum(struct cli_state *cli,
- char *server_name,
- uint32 switch_value, SRV_R_NET_SHARE_ENUM *r_o,
- uint32 preferred_len, ENUM_HND *hnd);
-BOOL do_srv_net_srv_file_enum(struct cli_state *cli,
- char *server_name, char *qual_name,
- uint32 switch_value, SRV_FILE_INFO_CTR *ctr,
- uint32 preferred_len,
- ENUM_HND *hnd);
-BOOL do_srv_net_srv_get_info(struct cli_state *cli,
- char *server_name, uint32 switch_value, SRV_INFO_CTR *ctr);
-
/*The following definitions come from rpc_client/cli_use.c */
void init_cli_use(void);
@@ -2360,12 +2360,6 @@ BOOL cli_net_use_del(const char *srv_name,
void cli_net_use_enum(uint32 *num_cons, struct use_info ***use);
void cli_use_wait_keyboard(void);
-/*The following definitions come from rpc_client/cli_wkssvc.c */
-
-BOOL do_wks_query_info(struct cli_state *cli,
- char *server_name, uint32 switch_value,
- WKS_INFO_100 *wks100);
-
/*The following definitions come from rpc_client/ncacn_np_use.c */
BOOL ncacn_np_use_del(const char *srv_name, const char *pipe_name,
@@ -3295,6 +3289,7 @@ BOOL make_spoolss_q_open_printer_ex(SPOOL_Q_OPEN_PRINTER_EX *q_u,
const fstring clientname,
const fstring user_name);
BOOL make_spoolss_q_addprinterex(
+ TALLOC_CTX *mem_ctx,
SPOOL_Q_ADDPRINTEREX *q_u,
const char *srv_name,
const char* clientname,
@@ -3302,6 +3297,7 @@ BOOL make_spoolss_q_addprinterex(
uint32 level,
PRINTER_INFO_CTR *ctr);
BOOL make_spoolss_printer_info_2(
+ TALLOC_CTX *mem_ctx,
SPOOL_PRINTER_INFO_LEVEL_2 **spool_info2,
PRINTER_INFO_2 *info
);
@@ -3383,9 +3379,14 @@ BOOL make_spoolss_q_getprinterdriver2(SPOOL_Q_GETPRINTERDRIVER2 *q_u,
NEW_BUFFER *buffer, uint32 offered);
BOOL spoolss_io_q_getprinterdriver2(char *desc, SPOOL_Q_GETPRINTERDRIVER2 *q_u, prs_struct *ps, int depth);
BOOL spoolss_io_r_getprinterdriver2(char *desc, SPOOL_R_GETPRINTERDRIVER2 *r_u, prs_struct *ps, int depth);
-BOOL make_spoolss_q_enumprinters(SPOOL_Q_ENUMPRINTERS *q_u, uint32 flags,
- fstring servername, uint32 level,
- NEW_BUFFER *buffer, uint32 offered);
+BOOL make_spoolss_q_enumprinters(
+ SPOOL_Q_ENUMPRINTERS *q_u,
+ uint32 flags,
+ fstring servername,
+ uint32 level,
+ NEW_BUFFER *buffer,
+ uint32 offered
+);
BOOL make_spoolss_q_enumports(SPOOL_Q_ENUMPORTS *q_u,
fstring servername, uint32 level,
NEW_BUFFER *buffer, uint32 offered);
@@ -3394,6 +3395,7 @@ BOOL spoolss_io_r_enumprinters(char *desc, SPOOL_R_ENUMPRINTERS *r_u, prs_struct
BOOL spoolss_io_r_getprinter(char *desc, SPOOL_R_GETPRINTER *r_u, prs_struct *ps, int depth);
BOOL spoolss_io_q_getprinter(char *desc, SPOOL_Q_GETPRINTER *q_u, prs_struct *ps, int depth);
BOOL make_spoolss_q_getprinter(
+ TALLOC_CTX *mem_ctx,
SPOOL_Q_GETPRINTER *q_u,
const POLICY_HND *hnd,
uint32 level,
@@ -3401,6 +3403,7 @@ BOOL make_spoolss_q_getprinter(
uint32 offered
);
BOOL make_spoolss_q_setprinter(
+ TALLOC_CTX *mem_ctx,
SPOOL_Q_SETPRINTER *q_u,
const POLICY_HND *hnd,
uint32 level,
@@ -3452,15 +3455,22 @@ BOOL spool_io_printer_driver_info_level_6(char *desc, SPOOL_PRINTER_DRIVER_INFO_
BOOL smb_io_unibuffer(char *desc, UNISTR2 *buffer, prs_struct *ps, int depth);
BOOL spool_io_printer_driver_info_level(char *desc, SPOOL_PRINTER_DRIVER_INFO_LEVEL *il, prs_struct *ps, int depth);
BOOL make_spoolss_q_addprinterdriver(
+ TALLOC_CTX *mem_ctx,
SPOOL_Q_ADDPRINTERDRIVER *q_u,
const char* srv_name,
uint32 level,
PRINTER_DRIVER_CTR *info);
BOOL make_spoolss_driver_info_3(
+ TALLOC_CTX *mem_ctx,
SPOOL_PRINTER_DRIVER_INFO_LEVEL_3 **spool_drv_info,
DRIVER_INFO_3 *info3
);
-BOOL make_spoolss_buffer5(BUFFER5 *buf5, uint32 len, uint16 *src);
+BOOL make_spoolss_buffer5(
+ TALLOC_CTX *mem_ctx,
+ BUFFER5 *buf5,
+ uint32 len,
+ uint16 *src
+);
BOOL spoolss_io_q_addprinterdriver(char *desc, SPOOL_Q_ADDPRINTERDRIVER *q_u, prs_struct *ps, int depth);
BOOL spoolss_io_r_addprinterdriver(char *desc, SPOOL_R_ADDPRINTERDRIVER *q_u, prs_struct *ps, int depth);
BOOL uni_2_asc_printer_driver_3(SPOOL_PRINTER_DRIVER_INFO_LEVEL_3 *uni,
diff --git a/source3/include/rpc_client.h b/source3/include/rpc_client.h
index 1d7bee4105..270545c2a3 100644
--- a/source3/include/rpc_client.h
+++ b/source3/include/rpc_client.h
@@ -22,6 +22,8 @@
#ifndef _RPC_CLIENT_H
#define _RPC_CLIENT_H
+#if 0 /* JERRY */
#include "rpc_client_proto.h"
+#endif
#endif /* _RPC_CLIENT_H */
diff --git a/source3/include/rpc_client_proto.h b/source3/include/rpc_client_proto.h
deleted file mode 100644
index aa22b1996a..0000000000
--- a/source3/include/rpc_client_proto.h
+++ /dev/null
@@ -1,232 +0,0 @@
-#ifndef _RPC_CLIENT_PROTO_H_
-#define _RPC_CLIENT_PROTO_H_
-/* This file is automatically generated with "make proto". DO NOT EDIT */
-
-
-/*The following definitions come from lib/util_list.c */
-
-BOOL copy_policy_hnd (POLICY_HND *dest, const POLICY_HND *src);
-BOOL compare_rpc_hnd_node(const RPC_HND_NODE *x,
- const RPC_HND_NODE *y);
-BOOL RpcHndList_set_connection(const POLICY_HND *hnd,
- struct cli_connection *con);
-BOOL RpcHndList_del_connection(const POLICY_HND *hnd);
-struct cli_connection* RpcHndList_get_connection(const POLICY_HND *hnd);
-
-/*The following definitions come from rpc_client/cli_connect.c */
-
-void init_connections(void);
-void free_connections(void);
-void cli_connection_free(struct cli_connection *con);
-void cli_connection_unlink(struct cli_connection *con);
-BOOL cli_connection_init(const char *srv_name, char *pipe_name,
- struct cli_connection **con);
-BOOL cli_connection_init_auth(const char *srv_name, char *pipe_name,
- struct cli_connection **con,
- cli_auth_fns * auth, void *auth_creds);
-struct _cli_auth_fns *cli_conn_get_authfns(struct cli_connection *con);
-void *cli_conn_get_auth_creds(struct cli_connection *con);
-BOOL rpc_hnd_pipe_req(const POLICY_HND * hnd, uint8 op_num,
- prs_struct * data, prs_struct * rdata);
-BOOL rpc_con_pipe_req(struct cli_connection *con, uint8 op_num,
- prs_struct * data, prs_struct * rdata);
-BOOL rpc_con_ok(struct cli_connection *con);
-
-/*The following definitions come from rpc_client/cli_login.c */
-
-BOOL cli_nt_setup_creds(struct cli_state *cli, unsigned char mach_pwd[16]);
-BOOL cli_nt_srv_pwset(struct cli_state *cli, unsigned char *new_hashof_mach_pwd);
-BOOL cli_nt_login_interactive(struct cli_state *cli, char *domain, char *username,
- uint32 smb_userid_low, char *password,
- NET_ID_INFO_CTR *ctr, NET_USER_INFO_3 *user_info3);
-BOOL cli_nt_login_network(struct cli_state *cli, char *domain, char *username,
- uint32 smb_userid_low, char lm_chal[8],
- char *lm_chal_resp, char *nt_chal_resp,
- NET_ID_INFO_CTR *ctr, NET_USER_INFO_3 *user_info3);
-BOOL cli_nt_logoff(struct cli_state *cli, NET_ID_INFO_CTR *ctr);
-
-/*The following definitions come from rpc_client/cli_lsarpc.c */
-
-BOOL do_lsa_open_policy(struct cli_state *cli,
- char *system_name, POLICY_HND *hnd,
- BOOL sec_qos);
-BOOL do_lsa_query_info_pol(struct cli_state *cli,
- POLICY_HND *hnd, uint16 info_class,
- fstring domain_name, DOM_SID *domain_sid);
-BOOL do_lsa_close(struct cli_state *cli, POLICY_HND *hnd);
-BOOL cli_lsa_get_domain_sid(struct cli_state *cli, char *server);
-uint32 lsa_open_policy(const char *system_name, POLICY_HND *hnd,
- BOOL sec_qos, uint32 des_access);
-uint32 lsa_close(POLICY_HND *hnd);
-uint32 lsa_lookup_sids(POLICY_HND *hnd, int num_sids, DOM_SID *sids,
- char ***names, uint32 **types, int *num_names);
-uint32 lsa_lookup_names(POLICY_HND *hnd, int num_names, char **names,
- DOM_SID **sids, uint32 **types, int *num_sids);
-
-/*The following definitions come from rpc_client/cli_netlogon.c */
-
-BOOL cli_net_logon_ctrl2(struct cli_state *cli, uint32 status_level);
-BOOL cli_net_auth2(struct cli_state *cli, uint16 sec_chan,
- uint32 neg_flags, DOM_CHAL *srv_chal);
-BOOL cli_net_req_chal(struct cli_state *cli, DOM_CHAL *clnt_chal, DOM_CHAL *srv_chal);
-BOOL cli_net_srv_pwset(struct cli_state *cli, uint8 hashed_mach_pwd[16]);
-BOOL cli_net_sam_logon(struct cli_state *cli, NET_ID_INFO_CTR *ctr, NET_USER_INFO_3 *user_info3);
-BOOL cli_net_sam_logoff(struct cli_state *cli, NET_ID_INFO_CTR *ctr);
-BOOL change_trust_account_password( char *domain, char *remote_machine_list);
-
-/*The following definitions come from rpc_client/cli_pipe.c */
-
-BOOL rpc_api_pipe_req(struct cli_state *cli, uint8 op_num,
- prs_struct *data, prs_struct *rdata);
-BOOL rpc_pipe_bind(struct cli_state *cli, char *pipe_name, char *my_name);
-void cli_nt_set_ntlmssp_flgs(struct cli_state *cli, uint32 ntlmssp_flgs);
-BOOL cli_nt_session_open(struct cli_state *cli, char *pipe_name);
-void cli_nt_session_close(struct cli_state *cli);
-
-/*The following definitions come from rpc_client/cli_reg.c */
-
-BOOL do_reg_connect(struct cli_state *cli, char *full_keyname, char *key_name,
- POLICY_HND *reg_hnd);
-BOOL do_reg_open_hklm(struct cli_state *cli, uint16 unknown_0, uint32 level,
- POLICY_HND *hnd);
-BOOL do_reg_open_hku(struct cli_state *cli, uint16 unknown_0, uint32 level,
- POLICY_HND *hnd);
-BOOL do_reg_flush_key(struct cli_state *cli, POLICY_HND *hnd);
-BOOL do_reg_query_key(struct cli_state *cli, POLICY_HND *hnd,
- char *class, uint32 *class_len,
- uint32 *num_subkeys, uint32 *max_subkeylen,
- uint32 *max_subkeysize, uint32 *num_values,
- uint32 *max_valnamelen, uint32 *max_valbufsize,
- uint32 *sec_desc, NTTIME *mod_time);
-BOOL do_reg_unknown_1a(struct cli_state *cli, POLICY_HND *hnd, uint32 *unk);
-BOOL do_reg_query_info(struct cli_state *cli, POLICY_HND *hnd,
- char *key_value, uint32* key_type);
-BOOL do_reg_set_key_sec(struct cli_state *cli, POLICY_HND *hnd, SEC_DESC_BUF *sec_desc_buf);
-BOOL do_reg_get_key_sec(struct cli_state *cli, POLICY_HND *hnd, uint32 *sec_buf_size, SEC_DESC_BUF **ppsec_desc_buf);
-BOOL do_reg_delete_val(struct cli_state *cli, POLICY_HND *hnd, char *val_name);
-BOOL do_reg_delete_key(struct cli_state *cli, POLICY_HND *hnd, char *key_name);
-BOOL do_reg_create_key(struct cli_state *cli, POLICY_HND *hnd,
- char *key_name, char *key_class,
- SEC_ACCESS *sam_access,
- POLICY_HND *key);
-BOOL do_reg_enum_key(struct cli_state *cli, POLICY_HND *hnd,
- int key_index, char *key_name,
- uint32 *unk_1, uint32 *unk_2,
- time_t *mod_time);
-BOOL do_reg_create_val(struct cli_state *cli, POLICY_HND *hnd,
- char *val_name, uint32 type, BUFFER3 *data);
-BOOL do_reg_enum_val(struct cli_state *cli, POLICY_HND *hnd,
- int val_index, int max_valnamelen, int max_valbufsize,
- fstring val_name,
- uint32 *val_type, BUFFER2 *value);
-BOOL do_reg_open_entry(struct cli_state *cli, POLICY_HND *hnd,
- char *key_name, uint32 unk_0,
- POLICY_HND *key_hnd);
-BOOL do_reg_close(struct cli_state *cli, POLICY_HND *hnd);
-
-/*The following definitions come from rpc_client/cli_samr.c */
-
-BOOL get_samr_query_usergroups(struct cli_state *cli,
- POLICY_HND *pol_open_domain, uint32 user_rid,
- uint32 *num_groups, DOM_GID *gid);
-BOOL get_samr_query_userinfo(struct cli_state *cli,
- POLICY_HND *pol_open_domain,
- uint32 info_level,
- uint32 user_rid, SAM_USER_INFO_21 *usr);
-BOOL do_samr_chgpasswd_user(struct cli_state *cli,
- char *srv_name, char *user_name,
- char nt_newpass[516], uchar nt_oldhash[16],
- char lm_newpass[516], uchar lm_oldhash[16]);
-BOOL do_samr_unknown_38(struct cli_state *cli, char *srv_name);
-BOOL do_samr_query_dom_info(struct cli_state *cli,
- POLICY_HND *domain_pol, uint16 switch_value);
-BOOL do_samr_enum_dom_users(struct cli_state *cli,
- POLICY_HND *pol, uint16 num_entries, uint16 unk_0,
- uint16 acb_mask, uint16 unk_1, uint32 size,
- struct acct_info **sam,
- int *num_sam_users);
-BOOL do_samr_connect(struct cli_state *cli,
- char *srv_name, uint32 unknown_0,
- POLICY_HND *connect_pol);
-BOOL do_samr_open_user(struct cli_state *cli,
- POLICY_HND *pol, uint32 unk_0, uint32 rid,
- POLICY_HND *user_pol);
-BOOL do_samr_open_domain(struct cli_state *cli,
- POLICY_HND *connect_pol, uint32 rid, DOM_SID *sid,
- POLICY_HND *domain_pol);
-BOOL do_samr_query_unknown_12(struct cli_state *cli,
- POLICY_HND *pol, uint32 rid, uint32 num_gids, uint32 *gids,
- uint32 *num_aliases,
- fstring als_names [MAX_LOOKUP_SIDS],
- uint32 num_als_users[MAX_LOOKUP_SIDS]);
-BOOL do_samr_query_usergroups(struct cli_state *cli,
- POLICY_HND *pol, uint32 *num_groups, DOM_GID *gid);
-BOOL do_samr_query_userinfo(struct cli_state *cli,
- POLICY_HND *pol, uint16 switch_value, void* usr);
-BOOL do_samr_close(struct cli_state *cli, POLICY_HND *hnd);
-
-/*The following definitions come from rpc_client/cli_spoolss_notify.c */
-
-BOOL spoolss_disconnect_from_client( struct cli_state *cli);
-BOOL spoolss_connect_to_client( struct cli_state *cli, char *remote_machine);
-BOOL cli_spoolss_reply_open_printer(struct cli_state *cli, char *printer, uint32 localprinter, uint32 type, uint32 *status, POLICY_HND *handle);
-BOOL cli_spoolss_reply_rrpcn(struct cli_state *cli, POLICY_HND *handle,
- uint32 change_low, uint32 change_high, uint32 *status);
-BOOL cli_spoolss_reply_close_printer(struct cli_state *cli, POLICY_HND *handle, uint32 *status);
-
-/*The following definitions come from rpc_client/cli_srvsvc.c */
-
-BOOL do_srv_net_srv_conn_enum(struct cli_state *cli,
- char *server_name, char *qual_name,
- uint32 switch_value, SRV_CONN_INFO_CTR *ctr,
- uint32 preferred_len,
- ENUM_HND *hnd);
-BOOL do_srv_net_srv_sess_enum(struct cli_state *cli,
- char *server_name, char *qual_name,
- uint32 switch_value, SRV_SESS_INFO_CTR *ctr,
- uint32 preferred_len,
- ENUM_HND *hnd);
-BOOL do_srv_net_srv_share_enum(struct cli_state *cli,
- char *server_name,
- uint32 switch_value, SRV_R_NET_SHARE_ENUM *r_o,
- uint32 preferred_len, ENUM_HND *hnd);
-BOOL do_srv_net_srv_file_enum(struct cli_state *cli,
- char *server_name, char *qual_name,
- uint32 switch_value, SRV_FILE_INFO_CTR *ctr,
- uint32 preferred_len,
- ENUM_HND *hnd);
-BOOL do_srv_net_srv_get_info(struct cli_state *cli,
- char *server_name, uint32 switch_value, SRV_INFO_CTR *ctr);
-
-/*The following definitions come from rpc_client/cli_use.c */
-
-void init_cli_use(void);
-void free_cli_use(void);
-struct cli_state *cli_net_use_add(const char *srv_name,
- const struct ntuser_creds *usr_creds,
- BOOL reuse, BOOL *is_new);
-BOOL cli_net_use_del(const char *srv_name,
- const struct ntuser_creds *usr_creds,
- BOOL force_close, BOOL *connection_closed);
-void cli_net_use_enum(uint32 *num_cons, struct use_info ***use);
-void cli_use_wait_keyboard(void);
-
-/*The following definitions come from rpc_client/cli_wkssvc.c */
-
-BOOL do_wks_query_info(struct cli_state *cli,
- char *server_name, uint32 switch_value,
- WKS_INFO_100 *wks100);
-
-/*The following definitions come from rpc_client/ncacn_np_use.c */
-
-BOOL ncacn_np_use_del(const char *srv_name, const char *pipe_name,
- const vuser_key * key,
- BOOL force_close, BOOL *connection_closed);
-struct ncacn_np *ncacn_np_initialise(struct ncacn_np *msrpc,
- const vuser_key * key);
-struct ncacn_np *ncacn_np_use_add(const char *pipe_name,
- const vuser_key * key,
- const char *srv_name,
- const struct ntuser_creds *ntc,
- BOOL reuse, BOOL *is_new_connection);
-#endif /* _PROTO_H_ */
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;
diff --git a/source3/rpc_parse/parse_spoolss.c b/source3/rpc_parse/parse_spoolss.c
index ff3e53273a..b18656b482 100644
--- a/source3/rpc_parse/parse_spoolss.c
+++ b/source3/rpc_parse/parse_spoolss.c
@@ -761,6 +761,7 @@ BOOL make_spoolss_q_open_printer_ex(SPOOL_Q_OPEN_PRINTER_EX *q_u,
* init a structure.
********************************************************************/
BOOL make_spoolss_q_addprinterex(
+ TALLOC_CTX *mem_ctx,
SPOOL_Q_ADDPRINTEREX *q_u,
const char *srv_name,
const char* clientname,
@@ -783,7 +784,7 @@ BOOL make_spoolss_q_addprinterex(
{
case 2:
/* init q_u->info.info2 from *info */
- if (!make_spoolss_printer_info_2(&q_u->info.info_2, ctr->printers_2))
+ if (!make_spoolss_printer_info_2(mem_ctx, &q_u->info.info_2, ctr->printers_2))
{
DEBUG(0,("make_spoolss_q_addprinterex: Unable to fill SPOOL_Q_ADDPRINTEREX struct!\n"));
return False;
@@ -818,6 +819,7 @@ create a SPOOL_PRINTER_INFO_2 stuct from a PRINTER_INFO_2 struct
*******************************************************************/
BOOL make_spoolss_printer_info_2(
+ TALLOC_CTX *mem_ctx,
SPOOL_PRINTER_INFO_LEVEL_2 **spool_info2,
PRINTER_INFO_2 *info
)
@@ -826,8 +828,7 @@ BOOL make_spoolss_printer_info_2(
SPOOL_PRINTER_INFO_LEVEL_2 *inf;
/* allocate the necessary memory */
- inf = (SPOOL_PRINTER_INFO_LEVEL_2*)malloc(sizeof(SPOOL_PRINTER_INFO_LEVEL_2));
- if (!spool_info2)
+ if (!(inf=(SPOOL_PRINTER_INFO_LEVEL_2*)talloc(mem_ctx, sizeof(SPOOL_PRINTER_INFO_LEVEL_2))))
{
DEBUG(0,("make_spoolss_printer_info_2: Unable to allocate SPOOL_PRINTER_INFO_LEVEL_2 sruct!\n"));
return False;
@@ -3256,9 +3257,14 @@ BOOL spoolss_io_r_getprinterdriver2(char *desc, SPOOL_R_GETPRINTERDRIVER2 *r_u,
* init a structure.
********************************************************************/
-BOOL make_spoolss_q_enumprinters(SPOOL_Q_ENUMPRINTERS *q_u, uint32 flags,
- fstring servername, uint32 level,
- NEW_BUFFER *buffer, uint32 offered)
+BOOL make_spoolss_q_enumprinters(
+ SPOOL_Q_ENUMPRINTERS *q_u,
+ uint32 flags,
+ fstring servername,
+ uint32 level,
+ NEW_BUFFER *buffer,
+ uint32 offered
+)
{
q_u->flags=flags;
@@ -3420,6 +3426,7 @@ BOOL spoolss_io_q_getprinter(char *desc, SPOOL_Q_GETPRINTER *q_u, prs_struct *ps
********************************************************************/
BOOL make_spoolss_q_getprinter(
+ TALLOC_CTX *mem_ctx,
SPOOL_Q_GETPRINTER *q_u,
const POLICY_HND *hnd,
uint32 level,
@@ -3444,6 +3451,7 @@ BOOL make_spoolss_q_getprinter(
* init a structure.
********************************************************************/
BOOL make_spoolss_q_setprinter(
+ TALLOC_CTX *mem_ctx,
SPOOL_Q_SETPRINTER *q_u,
const POLICY_HND *hnd,
uint32 level,
@@ -3474,7 +3482,7 @@ BOOL make_spoolss_q_setprinter(
info->printers_2->devmode = NULL;
info->printers_2->secdesc = NULL;
- make_spoolss_printer_info_2 (&q_u->info.info_2, info->printers_2);
+ make_spoolss_printer_info_2 (mem_ctx, &q_u->info.info_2, info->printers_2);
#if 0 /* JERRY TEST */
q_u->secdesc_ctr = (SEC_DESC_BUF*)malloc(sizeof(SEC_DESC_BUF));
if (!q_u->secdesc_ctr)
@@ -4700,6 +4708,7 @@ BOOL spool_io_printer_driver_info_level(char *desc, SPOOL_PRINTER_DRIVER_INFO_LE
******************************************************************/
BOOL make_spoolss_q_addprinterdriver(
+ TALLOC_CTX *mem_ctx,
SPOOL_Q_ADDPRINTERDRIVER *q_u,
const char* srv_name,
uint32 level,
@@ -4718,7 +4727,7 @@ BOOL make_spoolss_q_addprinterdriver(
{
/* info level 3 is supported by Windows 95/98, WinNT and Win2k */
case 3 :
- make_spoolss_driver_info_3(&q_u->info.info_3, info->info3);
+ make_spoolss_driver_info_3(mem_ctx, &q_u->info.info_3, info->info3);
break;
/* info level 6 is supported by WinME and Win2k */
@@ -4735,6 +4744,7 @@ BOOL make_spoolss_q_addprinterdriver(
}
BOOL make_spoolss_driver_info_3(
+ TALLOC_CTX *mem_ctx,
SPOOL_PRINTER_DRIVER_INFO_LEVEL_3 **spool_drv_info,
DRIVER_INFO_3 *info3
)
@@ -4745,11 +4755,8 @@ BOOL make_spoolss_driver_info_3(
BOOL null_char = False;
SPOOL_PRINTER_DRIVER_INFO_LEVEL_3 *inf;
- inf = (SPOOL_PRINTER_DRIVER_INFO_LEVEL_3*)
- malloc(sizeof(SPOOL_PRINTER_DRIVER_INFO_LEVEL_3));
- if (!inf)
+ if (!(inf=(SPOOL_PRINTER_DRIVER_INFO_LEVEL_3*)talloc_zero(mem_ctx, sizeof(SPOOL_PRINTER_DRIVER_INFO_LEVEL_3))))
return False;
- memset (inf, 0x0, sizeof(SPOOL_PRINTER_DRIVER_INFO_LEVEL_3));
inf->cversion = info3->version;
inf->name_ptr = (info3->name.buffer!=NULL)?1:0;
@@ -4793,7 +4800,7 @@ BOOL make_spoolss_driver_info_3(
}
inf->dependentfiles_ptr = (info3->dependentfiles != NULL) ? 1 : 0;
inf->dependentfilessize = len;
- if(!make_spoolss_buffer5(&inf->dependentfiles, len, info3->dependentfiles))
+ if(!make_spoolss_buffer5(mem_ctx, &inf->dependentfiles, len, info3->dependentfiles))
{
safe_free (inf);
return False;
@@ -4808,18 +4815,21 @@ BOOL make_spoolss_driver_info_3(
make a BUFFER5 struct from a uint16*
******************************************************************/
-BOOL make_spoolss_buffer5(BUFFER5 *buf5, uint32 len, uint16 *src)
+BOOL make_spoolss_buffer5(
+ TALLOC_CTX *mem_ctx,
+ BUFFER5 *buf5,
+ uint32 len,
+ uint16 *src
+)
{
buf5->buf_len = len;
- if((buf5->buffer=(uint16*)malloc(sizeof(uint16)*len)) == NULL)
+ if((buf5->buffer=(uint16*)talloc_memdup(mem_ctx, src, sizeof(uint16)*len)) == NULL)
{
DEBUG(0,("make_spoolss_buffer5: Unable to malloc memory for buffer!\n"));
return False;
}
- memcpy(buf5->buffer, src, sizeof(uint16)*len);
-
return True;
}
diff --git a/source3/rpcclient/cmd_lsarpc.c b/source3/rpcclient/cmd_lsarpc.c
index a574f2e128..153d5366e0 100644
--- a/source3/rpcclient/cmd_lsarpc.c
+++ b/source3/rpcclient/cmd_lsarpc.c
@@ -34,12 +34,19 @@ static uint32 cmd_lsa_query_info_policy(struct cli_state *cli, int argc, char **
DOM_SID dom_sid;
fstring sid_str, domain_name;
uint32 info_class = 3;
+ TALLOC_CTX *mem_ctx;
if (argc > 2) {
printf("Usage: %s [info_class]\n", argv[0]);
return 0;
}
+ if (!(mem_ctx=talloc_init()))
+ {
+ DEBUG(0,("cmd_lsa_query_info_poicy: talloc_init returned NULL!\n"));
+ return NT_STATUS_UNSUCCESSFUL;
+ }
+
if (argc == 2) {
info_class = atoi(argv[1]);
}
@@ -50,7 +57,7 @@ static uint32 cmd_lsa_query_info_policy(struct cli_state *cli, int argc, char **
return NT_STATUS_UNSUCCESSFUL;
}
- if ((result = cli_lsa_open_policy(cli, True,
+ if ((result = cli_lsa_open_policy(cli, mem_ctx, True,
SEC_RIGHTS_MAXIMUM_ALLOWED,
&pol)) != NT_STATUS_NOPROBLEMO) {
goto done;
@@ -60,7 +67,7 @@ static uint32 cmd_lsa_query_info_policy(struct cli_state *cli, int argc, char **
/* Lookup info policy */
- if ((result = cli_lsa_query_info_policy(cli, &pol, info_class,
+ if ((result = cli_lsa_query_info_policy(cli, mem_ctx, &pol, info_class,
domain_name, &dom_sid))
!= NT_STATUS_NOPROBLEMO) {
goto done;
@@ -73,10 +80,11 @@ static uint32 cmd_lsa_query_info_policy(struct cli_state *cli, int argc, char **
done:
if (got_policy_hnd) {
- cli_lsa_close(cli, &pol);
+ cli_lsa_close(cli, mem_ctx, &pol);
}
cli_nt_session_close(cli);
+ talloc_destroy(mem_ctx);
return result;
}
@@ -91,12 +99,19 @@ static uint32 cmd_lsa_lookup_names(struct cli_state *cli, int argc, char **argv)
DOM_SID *sids;
uint32 *types;
int num_names, i;
+ TALLOC_CTX *mem_ctx;
if (argc == 1) {
printf("Usage: %s [name1 [name2 [...]]]\n", argv[0]);
return 0;
}
+ if (!(mem_ctx=talloc_init()))
+ {
+ DEBUG(0,("cmd_lsa_lookup_names: talloc_init returned NULL!\n"));
+ return NT_STATUS_UNSUCCESSFUL;
+ }
+
/* Initialise RPC connection */
if (!cli_nt_session_open (cli, PIPE_LSARPC)) {
fprintf (stderr, "Could not initialize samr pipe!\n");
@@ -104,7 +119,7 @@ static uint32 cmd_lsa_lookup_names(struct cli_state *cli, int argc, char **argv)
}
- if ((result = cli_lsa_open_policy(cli, True,
+ if ((result = cli_lsa_open_policy(cli, mem_ctx, True,
SEC_RIGHTS_MAXIMUM_ALLOWED,
&pol)) != NT_STATUS_NOPROBLEMO) {
goto done;
@@ -114,8 +129,8 @@ static uint32 cmd_lsa_lookup_names(struct cli_state *cli, int argc, char **argv)
/* Lookup the names */
- if ((result = cli_lsa_lookup_names(
- cli, &pol, argc - 1, &argv[1], &sids, &types, &num_names) !=
+ if ((result = cli_lsa_lookup_names(cli, mem_ctx, &pol, argc - 1,
+ &argv[1], &sids, &types, &num_names) !=
NT_STATUS_NOPROBLEMO)) {
goto done;
}
@@ -130,16 +145,19 @@ static uint32 cmd_lsa_lookup_names(struct cli_state *cli, int argc, char **argv)
types[i]);
}
+#if 0 /* JERRY */
safe_free(sids);
safe_free(types);
+#endif
done:
if (got_policy_hnd) {
- cli_lsa_close(cli, &pol);
+ cli_lsa_close(cli, mem_ctx, &pol);
}
cli_nt_session_close(cli);
+ talloc_destroy(mem_ctx);
return result;
}
@@ -155,19 +173,26 @@ static uint32 cmd_lsa_lookup_sids(struct cli_state *cli, int argc, char **argv)
char **names;
uint32 *types;
int num_names, i;
+ TALLOC_CTX *mem_ctx;
if (argc == 1) {
printf("Usage: %s [sid1 [sid2 [...]]]\n", argv[0]);
return 0;
}
+ if (!(mem_ctx=talloc_init()))
+ {
+ DEBUG(0,("cmd_lsa_lookup_sids: talloc_init returned NULL!\n"));
+ return NT_STATUS_UNSUCCESSFUL;
+ }
+
/* Initialise RPC connection */
if (!cli_nt_session_open (cli, PIPE_LSARPC)) {
fprintf (stderr, "Could not initialize samr pipe!\n");
return NT_STATUS_UNSUCCESSFUL;
}
- if ((result = cli_lsa_open_policy(cli, True,
+ if ((result = cli_lsa_open_policy(cli, mem_ctx, True,
SEC_RIGHTS_MAXIMUM_ALLOWED,
&pol)) != NT_STATUS_NOPROBLEMO) {
goto done;
@@ -177,7 +202,7 @@ static uint32 cmd_lsa_lookup_sids(struct cli_state *cli, int argc, char **argv)
/* Convert arguments to sids */
- sids = (DOM_SID *)malloc(sizeof(DOM_SID) * (argc - 1));
+ sids = (DOM_SID *)talloc(mem_ctx, sizeof(DOM_SID) * (argc - 1));
if (!sids) {
printf("out of memory\n");
@@ -190,7 +215,7 @@ static uint32 cmd_lsa_lookup_sids(struct cli_state *cli, int argc, char **argv)
/* Lookup the SIDs */
- if ((result = cli_lsa_lookup_sids(cli, &pol, argc - 1, sids,
+ if ((result = cli_lsa_lookup_sids(cli, mem_ctx, &pol, argc - 1, sids,
&names, &types, &num_names) !=
NT_STATUS_NOPROBLEMO)) {
goto done;
@@ -206,6 +231,7 @@ static uint32 cmd_lsa_lookup_sids(struct cli_state *cli, int argc, char **argv)
"*unknown*", types[i]);
}
+#if 0 /* JERRY */
safe_free(sids);
safe_free(types);
@@ -214,14 +240,16 @@ static uint32 cmd_lsa_lookup_sids(struct cli_state *cli, int argc, char **argv)
}
safe_free(names);
+#endif
done:
if (got_policy_hnd) {
- cli_lsa_close(cli, &pol);
+ cli_lsa_close(cli, mem_ctx, &pol);
}
cli_nt_session_close(cli);
+ talloc_destroy (mem_ctx);
return result;
}
@@ -238,19 +266,26 @@ static uint32 cmd_lsa_enum_trust_dom(struct cli_state *cli, int argc, char **arg
uint32 enum_ctx = 0;
uint32 num_domains;
int i;
+ TALLOC_CTX *mem_ctx;
if (argc != 1) {
printf("Usage: %s\n", argv[0]);
return 0;
}
+ if (!(mem_ctx=talloc_init()))
+ {
+ DEBUG(0,("cmd_lsa_enum_trust_dom: talloc_init returned NULL!\n"));
+ return NT_STATUS_UNSUCCESSFUL;
+ }
+
/* Initialise RPC connection */
if (!cli_nt_session_open (cli, PIPE_LSARPC)) {
fprintf (stderr, "Could not initialize samr pipe!\n");
return NT_STATUS_UNSUCCESSFUL;
}
- if ((result = cli_lsa_open_policy(cli, True,
+ if ((result = cli_lsa_open_policy(cli, mem_ctx, True,
SEC_RIGHTS_MAXIMUM_ALLOWED,
&pol)) != NT_STATUS_NOPROBLEMO) {
goto done;
@@ -260,7 +295,7 @@ static uint32 cmd_lsa_enum_trust_dom(struct cli_state *cli, int argc, char **arg
/* Lookup list of trusted domains */
- if ((result = cli_lsa_enum_trust_dom(cli, &pol, &enum_ctx,
+ if ((result = cli_lsa_enum_trust_dom(cli, mem_ctx, &pol, &enum_ctx,
&num_domains, &domain_names,
&domain_sids)
!= NT_STATUS_NOPROBLEMO)) {
@@ -277,6 +312,7 @@ static uint32 cmd_lsa_enum_trust_dom(struct cli_state *cli, int argc, char **arg
"*unknown*", sid_str);
}
+#if 0 /* JERRY */
safe_free(domain_sids);
for (i = 0; i < num_domains; i++) {
@@ -284,14 +320,16 @@ static uint32 cmd_lsa_enum_trust_dom(struct cli_state *cli, int argc, char **arg
}
safe_free(domain_names);
+#endif
done:
if (got_policy_hnd) {
- cli_lsa_close(cli, &pol);
+ cli_lsa_close(cli, mem_ctx, &pol);
}
cli_nt_session_close(cli);
+ talloc_destroy(mem_ctx);
return result;
}
diff --git a/source3/rpcclient/cmd_samr.c b/source3/rpcclient/cmd_samr.c
index b3d135275a..d0706cc9b7 100644
--- a/source3/rpcclient/cmd_samr.c
+++ b/source3/rpcclient/cmd_samr.c
@@ -108,11 +108,20 @@ static uint32 cmd_samr_query_user(struct cli_state *cli, int argc, char **argv)
SAM_USERINFO_CTR user_ctr;
SAM_USER_INFO_21 info_21;
fstring server;
+ TALLOC_CTX *mem_ctx;
+
if (argc != 1) {
printf("Usage: %s\n", argv[0]);
return 0;
}
+
+ if (!(mem_ctx=talloc_init()))
+ {
+ DEBUG(0,("cmd_samr_query_user: talloc_init returned NULL!\n"));
+ return NT_STATUS_UNSUCCESSFUL;
+ }
+
/* Initialise RPC connection */
if (!cli_nt_session_open (cli, PIPE_SAMR)) {
@@ -123,7 +132,7 @@ static uint32 cmd_samr_query_user(struct cli_state *cli, int argc, char **argv)
slprintf (server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
strupper (server);
- if ((result = cli_samr_connect(cli, server, MAXIMUM_ALLOWED_ACCESS,
+ if ((result = cli_samr_connect(cli, mem_ctx, server, MAXIMUM_ALLOWED_ACCESS,
&connect_pol)) !=
NT_STATUS_NOPROBLEMO) {
goto done;
@@ -132,7 +141,7 @@ static uint32 cmd_samr_query_user(struct cli_state *cli, int argc, char **argv)
got_connect_pol = True;
fetch_domain_sid(cli);
- if ((result = cli_samr_open_domain(cli, &connect_pol,
+ if ((result = cli_samr_open_domain(cli, mem_ctx, &connect_pol,
MAXIMUM_ALLOWED_ACCESS,
&domain_sid, &domain_pol))
!= NT_STATUS_NOPROBLEMO) {
@@ -141,7 +150,7 @@ static uint32 cmd_samr_query_user(struct cli_state *cli, int argc, char **argv)
got_domain_pol = True;
- if ((result = cli_samr_open_user(cli, &domain_pol,
+ if ((result = cli_samr_open_user(cli, mem_ctx, &domain_pol,
MAXIMUM_ALLOWED_ACCESS,
0x1f4, &user_pol))
!= NT_STATUS_NOPROBLEMO) {
@@ -155,7 +164,7 @@ static uint32 cmd_samr_query_user(struct cli_state *cli, int argc, char **argv)
user_ctr.info.id21 = &info_21;
- if ((result = cli_samr_query_userinfo(cli, &user_pol, info_level,
+ if ((result = cli_samr_query_userinfo(cli, mem_ctx, &user_pol, info_level,
&user_ctr))
!= NT_STATUS_NOPROBLEMO) {
goto done;
@@ -164,11 +173,12 @@ static uint32 cmd_samr_query_user(struct cli_state *cli, int argc, char **argv)
display_sam_user_info_21(&info_21);
done:
- if (got_user_pol) cli_samr_close(cli, &user_pol);
- if (got_domain_pol) cli_samr_close(cli, &domain_pol);
- if (got_connect_pol) cli_samr_close(cli, &connect_pol);
+ if (got_user_pol) cli_samr_close(cli, mem_ctx, &user_pol);
+ if (got_domain_pol) cli_samr_close(cli, mem_ctx, &domain_pol);
+ if (got_connect_pol) cli_samr_close(cli, mem_ctx, &connect_pol);
cli_nt_session_close(cli);
+ talloc_destroy(mem_ctx);
return result;
}
@@ -227,12 +237,19 @@ static uint32 cmd_samr_query_group(struct cli_state *cli, int argc, char **argv)
got_group_pol = False;
GROUP_INFO_CTR group_ctr;
fstring server;
+ TALLOC_CTX *mem_ctx;
if (argc != 1) {
printf("Usage: %s\n", argv[0]);
return 0;
}
+ if (!(mem_ctx=talloc_init()))
+ {
+ DEBUG(0,("cmd_samr_query_group: talloc_init returned NULL!\n"));
+ return NT_STATUS_UNSUCCESSFUL;
+ }
+
/* Initialise RPC connection */
if (!cli_nt_session_open (cli, PIPE_SAMR)) {
fprintf (stderr, "Could not initialize samr pipe!\n");
@@ -242,7 +259,7 @@ static uint32 cmd_samr_query_group(struct cli_state *cli, int argc, char **argv)
slprintf (server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
strupper (server);
- if ((result = cli_samr_connect(cli, server, MAXIMUM_ALLOWED_ACCESS,
+ if ((result = cli_samr_connect(cli, mem_ctx, server, MAXIMUM_ALLOWED_ACCESS,
&connect_pol)) !=
NT_STATUS_NOPROBLEMO) {
goto done;
@@ -251,7 +268,7 @@ static uint32 cmd_samr_query_group(struct cli_state *cli, int argc, char **argv)
got_connect_pol = True;
fetch_domain_sid(cli);
- if ((result = cli_samr_open_domain(cli, &connect_pol,
+ if ((result = cli_samr_open_domain(cli, mem_ctx, &connect_pol,
MAXIMUM_ALLOWED_ACCESS,
&domain_sid, &domain_pol))
!= NT_STATUS_NOPROBLEMO) {
@@ -260,7 +277,7 @@ static uint32 cmd_samr_query_group(struct cli_state *cli, int argc, char **argv)
got_domain_pol = True;
- if ((result = cli_samr_open_group(cli, &domain_pol,
+ if ((result = cli_samr_open_group(cli, mem_ctx, &domain_pol,
MAXIMUM_ALLOWED_ACCESS,
0x202, &group_pol))
!= NT_STATUS_NOPROBLEMO) {
@@ -271,7 +288,7 @@ static uint32 cmd_samr_query_group(struct cli_state *cli, int argc, char **argv)
ZERO_STRUCT(group_ctr);
- if ((result = cli_samr_query_groupinfo(cli, &group_pol, info_level,
+ if ((result = cli_samr_query_groupinfo(cli, mem_ctx, &group_pol, info_level,
&group_ctr))
!= NT_STATUS_NOPROBLEMO) {
goto done;
@@ -280,11 +297,12 @@ static uint32 cmd_samr_query_group(struct cli_state *cli, int argc, char **argv)
display_group_info_ctr(&group_ctr);
done:
- if (got_group_pol) cli_samr_close(cli, &group_pol);
- if (got_domain_pol) cli_samr_close(cli, &domain_pol);
- if (got_connect_pol) cli_samr_close(cli, &connect_pol);
+ if (got_group_pol) cli_samr_close(cli, mem_ctx, &group_pol);
+ if (got_domain_pol) cli_samr_close(cli, mem_ctx, &domain_pol);
+ if (got_connect_pol) cli_samr_close(cli, mem_ctx, &connect_pol);
cli_nt_session_close(cli);
+ talloc_destroy(mem_ctx);
return result;
}
@@ -305,12 +323,19 @@ static uint32 cmd_samr_query_usergroups(struct cli_state *cli, int argc, char **
DOM_GID *user_gids;
int i;
fstring server;
+ TALLOC_CTX *mem_ctx;
if (argc != 2) {
printf("Usage: %s rid\n", argv[0]);
return 0;
}
+ if (!(mem_ctx=talloc_init()))
+ {
+ DEBUG(0,("cmd_samr_query_usergroups: talloc_init returned NULL!\n"));
+ return NT_STATUS_UNSUCCESSFUL;
+ }
+
sscanf(argv[1], "%i", &user_rid);
/* Initialise RPC connection */
@@ -322,7 +347,7 @@ static uint32 cmd_samr_query_usergroups(struct cli_state *cli, int argc, char **
slprintf (server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
strupper (server);
- if ((result = cli_samr_connect(cli, server, MAXIMUM_ALLOWED_ACCESS,
+ if ((result = cli_samr_connect(cli, mem_ctx, server, MAXIMUM_ALLOWED_ACCESS,
&connect_pol)) !=
NT_STATUS_NOPROBLEMO) {
goto done;
@@ -331,7 +356,7 @@ static uint32 cmd_samr_query_usergroups(struct cli_state *cli, int argc, char **
got_connect_pol = True;
fetch_domain_sid(cli);
- if ((result = cli_samr_open_domain(cli, &connect_pol,
+ if ((result = cli_samr_open_domain(cli, mem_ctx, &connect_pol,
MAXIMUM_ALLOWED_ACCESS,
&domain_sid, &domain_pol))
!= NT_STATUS_NOPROBLEMO) {
@@ -340,7 +365,7 @@ static uint32 cmd_samr_query_usergroups(struct cli_state *cli, int argc, char **
got_domain_pol = True;
- if ((result = cli_samr_open_user(cli, &domain_pol,
+ if ((result = cli_samr_open_user(cli, mem_ctx, &domain_pol,
MAXIMUM_ALLOWED_ACCESS,
user_rid, &user_pol))
!= NT_STATUS_NOPROBLEMO) {
@@ -349,7 +374,7 @@ static uint32 cmd_samr_query_usergroups(struct cli_state *cli, int argc, char **
got_user_pol = True;
- if ((result = cli_samr_query_usergroups(cli, &user_pol,
+ if ((result = cli_samr_query_usergroups(cli, mem_ctx, &user_pol,
&num_groups, &user_gids))
!= NT_STATUS_NOPROBLEMO) {
goto done;
@@ -361,11 +386,12 @@ static uint32 cmd_samr_query_usergroups(struct cli_state *cli, int argc, char **
}
done:
- if (got_user_pol) cli_samr_close(cli, &user_pol);
- if (got_domain_pol) cli_samr_close(cli, &domain_pol);
- if (got_connect_pol) cli_samr_close(cli, &connect_pol);
+ if (got_user_pol) cli_samr_close(cli, mem_ctx, &user_pol);
+ if (got_domain_pol) cli_samr_close(cli, mem_ctx, &domain_pol);
+ if (got_connect_pol) cli_samr_close(cli, mem_ctx, &connect_pol);
cli_nt_session_close(cli);
+ talloc_destroy(mem_ctx);
return result;
}
@@ -382,12 +408,19 @@ static uint32 cmd_samr_query_groupmem(struct cli_state *cli, int argc, char **ar
uint32 num_members, *group_rids, *group_attrs, group_rid;
int i;
fstring server;
+ TALLOC_CTX *mem_ctx;
if (argc != 2) {
printf("Usage: %s rid\n", argv[0]);
return 0;
}
+ if (!(mem_ctx=talloc_init()))
+ {
+ DEBUG(0,("cmd_samr_query_groupmem: talloc_init returned NULL!\n"));
+ return NT_STATUS_UNSUCCESSFUL;
+ }
+
sscanf(argv[1], "%i", &group_rid);
/* Initialise RPC connection */
@@ -399,7 +432,7 @@ static uint32 cmd_samr_query_groupmem(struct cli_state *cli, int argc, char **ar
slprintf (server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
strupper (server);
- if ((result = cli_samr_connect(cli, server, MAXIMUM_ALLOWED_ACCESS,
+ if ((result = cli_samr_connect(cli, mem_ctx, server, MAXIMUM_ALLOWED_ACCESS,
&connect_pol)) !=
NT_STATUS_NOPROBLEMO) {
goto done;
@@ -408,7 +441,7 @@ static uint32 cmd_samr_query_groupmem(struct cli_state *cli, int argc, char **ar
got_connect_pol = True;
fetch_domain_sid(cli);
- if ((result = cli_samr_open_domain(cli, &connect_pol,
+ if ((result = cli_samr_open_domain(cli, mem_ctx, &connect_pol,
MAXIMUM_ALLOWED_ACCESS,
&domain_sid, &domain_pol))
!= NT_STATUS_NOPROBLEMO) {
@@ -417,7 +450,7 @@ static uint32 cmd_samr_query_groupmem(struct cli_state *cli, int argc, char **ar
got_domain_pol = True;
- if ((result = cli_samr_open_group(cli, &domain_pol,
+ if ((result = cli_samr_open_group(cli, mem_ctx, &domain_pol,
MAXIMUM_ALLOWED_ACCESS,
group_rid, &group_pol))
!= NT_STATUS_NOPROBLEMO) {
@@ -426,7 +459,7 @@ static uint32 cmd_samr_query_groupmem(struct cli_state *cli, int argc, char **ar
got_group_pol = True;
- if ((result = cli_samr_query_groupmem(cli, &group_pol,
+ if ((result = cli_samr_query_groupmem(cli, mem_ctx, &group_pol,
&num_members, &group_rids,
&group_attrs))
!= NT_STATUS_NOPROBLEMO) {
@@ -439,11 +472,12 @@ static uint32 cmd_samr_query_groupmem(struct cli_state *cli, int argc, char **ar
}
done:
- if (got_group_pol) cli_samr_close(cli, &group_pol);
- if (got_domain_pol) cli_samr_close(cli, &domain_pol);
- if (got_connect_pol) cli_samr_close(cli, &connect_pol);
+ if (got_group_pol) cli_samr_close(cli, mem_ctx, &group_pol);
+ if (got_domain_pol) cli_samr_close(cli, mem_ctx, &domain_pol);
+ if (got_connect_pol) cli_samr_close(cli, mem_ctx, &connect_pol);
cli_nt_session_close(cli);
+ talloc_destroy(mem_ctx);
return result;
}
diff --git a/source3/rpcclient/cmd_spoolss.c b/source3/rpcclient/cmd_spoolss.c
index 157abb27f5..b4d9070edb 100644
--- a/source3/rpcclient/cmd_spoolss.c
+++ b/source3/rpcclient/cmd_spoolss.c
@@ -148,15 +148,22 @@ static uint32 cmd_spoolss_open_printer_ex(struct cli_state *cli, int argc, char
pstring printername;
fstring server, user;
POLICY_HND hnd;
+ TALLOC_CTX *mem_ctx;
if (argc != 2) {
- printf("Usage: openprinter <printername>\n");
+ printf("Usage: %s <printername>\n", argv[0]);
return NT_STATUS_NOPROBLEMO;
}
if (!cli)
return NT_STATUS_UNSUCCESSFUL;
-
+
+ if (!(mem_ctx=talloc_init()))
+ {
+ DEBUG(0,("cmd_spoolss_open_printer_ex: talloc_init returned NULL!\n"));
+ return NT_STATUS_UNSUCCESSFUL;
+ }
+
slprintf (server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
strupper (server);
@@ -171,18 +178,19 @@ static uint32 cmd_spoolss_open_printer_ex(struct cli_state *cli, int argc, char
}
/* Open the printer handle */
- result = cli_spoolss_open_printer_ex (cli, printername, "",
+ result = cli_spoolss_open_printer_ex (cli, mem_ctx, printername, "",
MAXIMUM_ALLOWED_ACCESS, server, user, &hnd);
if (result == NT_STATUS_NOPROBLEMO) {
printf ("Printer %s opened successfully\n", printername);
- result = cli_spoolss_close_printer (cli, &hnd);
+ result = cli_spoolss_close_printer (cli, mem_ctx, &hnd);
if (result != NT_STATUS_NOPROBLEMO) {
printf ("Error closing printer handle! (%s)\n", get_nt_error_msg(result));
}
}
cli_nt_session_close(cli);
+ talloc_destroy(mem_ctx);
return result;
}
@@ -335,14 +343,22 @@ static uint32 cmd_spoolss_enum_printers(struct cli_state *cli, int argc, char **
info_level = 1;
PRINTER_INFO_CTR ctr;
int returned;
- uint32 i;
-
+ uint32 i = 0;
+ TALLOC_CTX *mem_ctx;
+
if (argc > 2)
{
- printf("Usage: enumprinters [level]\n");
+ printf("Usage: %s [level]\n", argv[0]);
return NT_STATUS_NOPROBLEMO;
}
+ if (!(mem_ctx=talloc_init()))
+ {
+ DEBUG(0,("cmd_spoolss_enum_printers: talloc_init returned NULL!\n"));
+ return NT_STATUS_UNSUCCESSFUL;
+ }
+
+
if (argc == 2) {
info_level = atoi(argv[1]);
}
@@ -356,10 +372,14 @@ static uint32 cmd_spoolss_enum_printers(struct cli_state *cli, int argc, char **
/* Enumerate printers -- Should we enumerate types other
than PRINTER_ENUM_LOCAL? Maybe accept as a parameter? --jerry */
ZERO_STRUCT(ctr);
- result = cli_spoolss_enum_printers(cli, PRINTER_ENUM_LOCAL,
+ result = cli_spoolss_enum_printers(cli, mem_ctx, PRINTER_ENUM_LOCAL,
info_level, &returned, &ctr);
- if (result == NT_STATUS_NOPROBLEMO) {
+ if (result == NT_STATUS_NOPROBLEMO)
+ {
+ if (!returned)
+ printf ("No Printers printers returned.\n");
+
switch(info_level) {
case 0:
for (i=0; i<returned; i++) {
@@ -388,6 +408,7 @@ static uint32 cmd_spoolss_enum_printers(struct cli_state *cli, int argc, char **
}
cli_nt_session_close(cli);
+ talloc_destroy(mem_ctx);
return result;
}
@@ -429,11 +450,19 @@ static uint32 cmd_spoolss_enum_ports(struct cli_state *cli, int argc, char **arg
info_level = 1;
PORT_INFO_CTR ctr;
int returned;
+ TALLOC_CTX *mem_ctx;
if (argc > 2) {
- printf("Usage: enumports [level]\n");
+ printf("Usage: %s [level]\n", argv[0]);
return NT_STATUS_NOPROBLEMO;
}
+
+ if (!(mem_ctx=talloc_init()))
+ {
+ DEBUG(0,("cmd_spoolss_enum_ports: talloc_init returned NULL!\n"));
+ return NT_STATUS_UNSUCCESSFUL;
+ }
+
if (argc == 2) {
info_level = atoi(argv[1]);
@@ -448,7 +477,7 @@ static uint32 cmd_spoolss_enum_ports(struct cli_state *cli, int argc, char **arg
/* Enumerate ports */
ZERO_STRUCT(ctr);
- result = cli_spoolss_enum_ports(cli, info_level, &returned, &ctr);
+ result = cli_spoolss_enum_ports(cli, mem_ctx, info_level, &returned, &ctr);
if (result == NT_STATUS_NOPROBLEMO) {
int i;
@@ -469,6 +498,7 @@ static uint32 cmd_spoolss_enum_ports(struct cli_state *cli, int argc, char **arg
}
cli_nt_session_close(cli);
+ talloc_destroy(mem_ctx);
return result;
}
@@ -486,12 +516,20 @@ static uint32 cmd_spoolss_getprinter(struct cli_state *cli, int argc, char **arg
fstring printername,
servername,
username;
+ TALLOC_CTX *mem_ctx;
if (argc == 1 || argc > 3) {
- printf("Usage: %s printername [level]\n", argv[0]);
+ printf("Usage: %s <printername> [level]\n", argv[0]);
return NT_STATUS_NOPROBLEMO;
}
+ if (!(mem_ctx=talloc_init()))
+ {
+ DEBUG(0,("cmd_spoolss_getprinter: talloc_init returned NULL!\n"));
+ return NT_STATUS_UNSUCCESSFUL;
+ }
+
+
/* Initialise RPC connection */
if (!cli_nt_session_open (cli, PIPE_SPOOLSS)) {
fprintf (stderr, "Could not initialize spoolss pipe!\n");
@@ -505,12 +543,12 @@ static uint32 cmd_spoolss_getprinter(struct cli_state *cli, int argc, char **arg
slprintf (servername, sizeof(fstring)-1, "\\\\%s", cli->desthost);
strupper (servername);
- slprintf (printername, sizeof(fstring)-1, "\\\\%s\\%s", servername, argv[1]);
+ slprintf (printername, sizeof(fstring)-1, "%s\\%s", servername, argv[1]);
fstrcpy (username, cli->user_name);
/* get a printer handle */
if ((result = cli_spoolss_open_printer_ex(
- cli, printername, "", MAXIMUM_ALLOWED_ACCESS, servername,
+ cli, mem_ctx, printername, "", MAXIMUM_ALLOWED_ACCESS, servername,
username, &pol)) != NT_STATUS_NOPROBLEMO) {
goto done;
}
@@ -518,7 +556,7 @@ static uint32 cmd_spoolss_getprinter(struct cli_state *cli, int argc, char **arg
opened_hnd = True;
/* Get printer info */
- if ((result = cli_spoolss_getprinter(cli, &pol, info_level, &ctr))
+ if ((result = cli_spoolss_getprinter(cli, mem_ctx, &pol, info_level, &ctr))
!= NT_STATUS_NOPROBLEMO) {
goto done;
}
@@ -545,9 +583,10 @@ static uint32 cmd_spoolss_getprinter(struct cli_state *cli, int argc, char **arg
done:
if (opened_hnd)
- cli_spoolss_close_printer(cli, &pol);
+ cli_spoolss_close_printer(cli, mem_ctx, &pol);
cli_nt_session_close(cli);
+ talloc_destroy(mem_ctx);
return result;
}
@@ -676,6 +715,7 @@ static uint32 cmd_spoolss_getdriver(struct cli_state *cli, int argc, char **argv
server,
user;
uint32 i;
+ TALLOC_CTX *mem_ctx;
if ((argc == 1) || (argc > 3))
{
@@ -683,6 +723,12 @@ static uint32 cmd_spoolss_getdriver(struct cli_state *cli, int argc, char **argv
return NT_STATUS_NOPROBLEMO;
}
+ if (!(mem_ctx=talloc_init()))
+ {
+ DEBUG(0,("cmd_spoolss_getdriver: talloc_init returned NULL!\n"));
+ return NT_STATUS_UNSUCCESSFUL;
+ }
+
/* Initialise RPC connection */
if (!cli_nt_session_open (cli, PIPE_SPOOLSS))
{
@@ -699,7 +745,7 @@ static uint32 cmd_spoolss_getdriver(struct cli_state *cli, int argc, char **argv
info_level = atoi(argv[2]);
/* Open a printer handle */
- if ((result=cli_spoolss_open_printer_ex (cli, printername, "",
+ if ((result=cli_spoolss_open_printer_ex (cli, mem_ctx, printername, "",
MAXIMUM_ALLOWED_ACCESS, server, user, &pol)) != NT_STATUS_NO_PROBLEMO)
{
printf ("Error opening printer handle for %s!\n", printername);
@@ -711,7 +757,7 @@ static uint32 cmd_spoolss_getdriver(struct cli_state *cli, int argc, char **argv
/* loop through and print driver info level for each architecture */
for (i=0; archi_table[i].long_archi!=NULL; i++)
{
- result = cli_spoolss_getprinterdriver (cli, &pol, info_level,
+ result = cli_spoolss_getprinterdriver (cli, mem_ctx, &pol, info_level,
archi_table[i].long_archi, &ctr);
switch (result)
@@ -753,8 +799,9 @@ static uint32 cmd_spoolss_getdriver(struct cli_state *cli, int argc, char **argv
/* cleanup */
if (opened_hnd)
- cli_spoolss_close_printer (cli, &pol);
+ cli_spoolss_close_printer (cli, mem_ctx, &pol);
cli_nt_session_close (cli);
+ talloc_destroy(mem_ctx);
if (result==ERROR_UNKNOWN_PRINTER_DRIVER)
return NT_STATUS_NO_PROBLEMO;
@@ -768,12 +815,13 @@ static uint32 cmd_spoolss_getdriver(struct cli_state *cli, int argc, char **argv
*/
static uint32 cmd_spoolss_enum_drivers(struct cli_state *cli, int argc, char **argv)
{
- uint32 result,
+ uint32 result=0,
info_level = 1;
PRINTER_DRIVER_CTR ctr;
fstring server;
uint32 i, j,
returned;
+ TALLOC_CTX *mem_ctx;
if (argc > 2)
{
@@ -781,6 +829,12 @@ static uint32 cmd_spoolss_enum_drivers(struct cli_state *cli, int argc, char **a
return NT_STATUS_NOPROBLEMO;
}
+ if (!(mem_ctx=talloc_init()))
+ {
+ DEBUG(0,("cmd_spoolss_enum_drivers: talloc_init returned NULL!\n"));
+ return NT_STATUS_UNSUCCESSFUL;
+ }
+
/* Initialise RPC connection */
if (!cli_nt_session_open (cli, PIPE_SPOOLSS))
{
@@ -799,7 +853,7 @@ static uint32 cmd_spoolss_enum_drivers(struct cli_state *cli, int argc, char **a
for (i=0; archi_table[i].long_archi!=NULL; i++)
{
returned = 0;
- result = cli_spoolss_enumprinterdrivers (cli, info_level,
+ result = cli_spoolss_enumprinterdrivers (cli, mem_ctx, info_level,
archi_table[i].long_archi, &returned, &ctr);
if (returned == 0)
@@ -841,6 +895,7 @@ static uint32 cmd_spoolss_enum_drivers(struct cli_state *cli, int argc, char **a
/* cleanup */
cli_nt_session_close (cli);
+ talloc_destroy(mem_ctx);
if (result==ERROR_UNKNOWN_PRINTER_DRIVER)
return NT_STATUS_NO_PROBLEMO;
@@ -871,6 +926,7 @@ static uint32 cmd_spoolss_getdriverdir(struct cli_state *cli, int argc, char **a
uint32 result;
fstring env;
DRIVER_DIRECTORY_CTR ctr;
+ TALLOC_CTX *mem_ctx;
if (argc > 2)
{
@@ -884,6 +940,13 @@ static uint32 cmd_spoolss_getdriverdir(struct cli_state *cli, int argc, char **a
fprintf (stderr, "Could not initialize spoolss pipe!\n");
return NT_STATUS_UNSUCCESSFUL;
}
+
+ if (!(mem_ctx=talloc_init()))
+ {
+ DEBUG(0,("cmd_spoolss_getdriverdir: talloc_init returned NULL!\n"));
+ return NT_STATUS_UNSUCCESSFUL;
+ }
+
/* get the arguments need to open the printer handle */
if (argc == 2)
@@ -892,7 +955,7 @@ static uint32 cmd_spoolss_getdriverdir(struct cli_state *cli, int argc, char **a
fstrcpy (env, "Windows NT x86");
/* Get the directory. Only use Info level 1 */
- if ((result = cli_spoolss_getprinterdriverdir (cli, 1, env, &ctr))
+ if ((result = cli_spoolss_getprinterdriverdir (cli, mem_ctx, 1, env, &ctr))
!= NT_STATUS_NO_PROBLEMO)
{
return result;
@@ -903,6 +966,7 @@ static uint32 cmd_spoolss_getdriverdir(struct cli_state *cli, int argc, char **a
/* cleanup */
cli_nt_session_close (cli);
+ talloc_destroy(mem_ctx);
return result;
@@ -966,7 +1030,11 @@ static char* get_driver_3_param (char* str, char* delim, UNISTR* dest)
<Config File Name>:<Help File Name>:<Language Monitor Name>:\
<Default Data Type>:<Comma Separated list of Files>
*******************************************************************************/
-static BOOL init_drv_info_3_members (DRIVER_INFO_3 *info, char *args)
+static BOOL init_drv_info_3_members (
+ TALLOC_CTX *mem_ctx,
+ DRIVER_INFO_3 *info,
+ char *args
+)
{
char *str, *str2;
uint32 len, i;
@@ -997,7 +1065,7 @@ static BOOL init_drv_info_3_members (DRIVER_INFO_3 *info, char *args)
/* allocate the space; add one extra slot for a terminating NULL.
Each filename is NULL terminated and the end contains a double
NULL */
- if ((info->dependentfiles=(uint16*)malloc((len+1)*sizeof(uint16))) == NULL)
+ if ((info->dependentfiles=(uint16*)talloc(mem_ctx, (len+1)*sizeof(uint16))) == NULL)
{
DEBUG(0,("init_drv_info_3_members: Unable to malloc memory for dependenfiles\n"));
return False;
@@ -1020,6 +1088,7 @@ static uint32 cmd_spoolss_addprinterdriver (struct cli_state *cli, int argc, cha
DRIVER_INFO_3 info3;
fstring arch;
fstring driver_name;
+ TALLOC_CTX *mem_ctx = NULL;
/* parse the command arguements */
if (argc != 3)
@@ -1031,6 +1100,12 @@ static uint32 cmd_spoolss_addprinterdriver (struct cli_state *cli, int argc, cha
return NT_STATUS_NOPROBLEMO;
}
+
+ if (!(mem_ctx=talloc_init()))
+ {
+ DEBUG(0,("cmd_spoolss_addprinterdriver: talloc_init returned NULL!\n"));
+ return NT_STATUS_UNSUCCESSFUL;
+ }
/* Initialise RPC connection */
if (!cli_nt_session_open (cli, PIPE_SPOOLSS))
@@ -1050,16 +1125,15 @@ static uint32 cmd_spoolss_addprinterdriver (struct cli_state *cli, int argc, cha
else
set_drv_info_3_env(&info3, arch);
- if (!init_drv_info_3_members(&info3, argv[2]))
+ if (!init_drv_info_3_members(mem_ctx, &info3, argv[2]))
{
printf ("Error Invalid parameter list - %s.\n", argv[2]);
return NT_STATUS_INVALID_PARAMETER;
}
- /* Get the directory. Only use Info level 1 */
ctr.info3 = &info3;
- if ((result = cli_spoolss_addprinterdriver (cli, level, &ctr))
+ if ((result = cli_spoolss_addprinterdriver (cli, mem_ctx, level, &ctr))
!= NT_STATUS_NO_PROBLEMO)
{
return result;
@@ -1070,6 +1144,7 @@ static uint32 cmd_spoolss_addprinterdriver (struct cli_state *cli, int argc, cha
/* cleanup */
cli_nt_session_close (cli);
+ talloc_destroy(mem_ctx);
return result;
@@ -1083,6 +1158,7 @@ static uint32 cmd_spoolss_addprinterex (struct cli_state *cli, int argc, char **
PRINTER_INFO_CTR ctr;
PRINTER_INFO_2 info2;
fstring server;
+ TALLOC_CTX *mem_ctx = NULL;
/* parse the command arguements */
if (argc != 5)
@@ -1090,6 +1166,13 @@ static uint32 cmd_spoolss_addprinterex (struct cli_state *cli, int argc, char **
printf ("Usage: %s <name> <shared name> <driver> <port>\n", argv[0]);
return NT_STATUS_NOPROBLEMO;
}
+
+ if (!(mem_ctx=talloc_init()))
+ {
+ DEBUG(0,("cmd_spoolss_addprinterex: talloc_init returned NULL!\n"));
+ return NT_STATUS_UNSUCCESSFUL;
+ }
+
slprintf (server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
strupper (server);
@@ -1130,13 +1213,11 @@ static uint32 cmd_spoolss_addprinterex (struct cli_state *cli, int argc, char **
info2.averageppm = 0;
*/
-
-
- /* Get the directory. Only use Info level 1 */
ctr.printers_2 = &info2;
- if ((result = cli_spoolss_addprinterex (cli, level, &ctr))
+ if ((result = cli_spoolss_addprinterex (cli, mem_ctx, level, &ctr))
!= NT_STATUS_NO_PROBLEMO)
{
+ cli_nt_session_close (cli);
return result;
}
@@ -1144,11 +1225,90 @@ static uint32 cmd_spoolss_addprinterex (struct cli_state *cli, int argc, char **
/* cleanup */
cli_nt_session_close (cli);
+ talloc_destroy(mem_ctx);
return result;
}
+static uint32 cmd_spoolss_setdriver (struct cli_state *cli, int argc, char **argv)
+{
+ POLICY_HND pol;
+ uint32 result,
+ level = 2;
+ BOOL opened_hnd = False;
+ PRINTER_INFO_CTR ctr;
+ PRINTER_INFO_2 info2;
+ fstring servername,
+ printername,
+ username;
+ TALLOC_CTX *mem_ctx = NULL;
+
+ /* parse the command arguements */
+ if (argc != 3)
+ {
+ printf ("Usage: %s <printer> <driver>\n", argv[0]);
+ return NT_STATUS_NOPROBLEMO;
+ }
+
+ if (!(mem_ctx=talloc_init()))
+ {
+ DEBUG(0,("cmd_spoolss_setdriver: talloc_init returned NULL!\n"));
+ return NT_STATUS_UNSUCCESSFUL;
+ }
+
+ slprintf (servername, sizeof(fstring)-1, "\\\\%s", cli->desthost);
+ strupper (servername);
+ slprintf (printername, sizeof(fstring)-1, "%s\\%s", servername, argv[1]);
+ fstrcpy (username, cli->user_name);
+
+ /* Initialise RPC connection */
+ if (!cli_nt_session_open (cli, PIPE_SPOOLSS))
+ {
+ fprintf (stderr, "Could not initialize spoolss pipe!\n");
+ return NT_STATUS_UNSUCCESSFUL;
+ }
+
+
+ /* get a printer handle */
+ if ((result = cli_spoolss_open_printer_ex(cli, mem_ctx, printername, "",
+ MAXIMUM_ALLOWED_ACCESS, servername, username, &pol))
+ != NT_STATUS_NOPROBLEMO)
+ {
+ goto done;
+ }
+
+ opened_hnd = True;
+
+ /* Get printer info */
+ ZERO_STRUCT (info2);
+ ctr.printers_2 = &info2;
+ if ((result = cli_spoolss_getprinter(cli, mem_ctx, &pol, level, &ctr)) != NT_STATUS_NOPROBLEMO)
+ {
+ printf ("Unable to retreive printer information!\n");
+ goto done;
+ }
+
+ /* set the printer driver */
+ init_unistr(&ctr.printers_2->drivername, argv[2]);
+ if ((result = cli_spoolss_setprinter(cli, mem_ctx, &pol, level, &ctr, 0)) != NT_STATUS_NO_PROBLEMO)
+ {
+ printf ("SetPrinter call failed!\n");
+ goto done;;
+ }
+ printf ("Succesfully set %s to driver %s.\n", argv[1], argv[2]);
+
+
+done:
+ /* cleanup */
+ if (opened_hnd)
+ cli_spoolss_close_printer(cli, mem_ctx, &pol);
+ cli_nt_session_close (cli);
+ talloc_destroy(mem_ctx);
+
+ return result;
+}
+
/* List of commands exported by this module */
struct cmd_set spoolss_commands[] = {
@@ -1166,5 +1326,6 @@ struct cmd_set spoolss_commands[] = {
{ "getdriverdir", cmd_spoolss_getdriverdir, "Get print driver upload directory" },
{ "getprinter", cmd_spoolss_getprinter, "Get printer info" },
{ "openprinter", cmd_spoolss_open_printer_ex, "Open printer handle" },
+ { "setdriver", cmd_spoolss_setdriver, "Set printer driver" },
{ NULL, NULL, NULL }
};
diff --git a/source3/rpcclient/rpcclient.c b/source3/rpcclient/rpcclient.c
index 412a17c6e0..d50510212e 100644
--- a/source3/rpcclient/rpcclient.c
+++ b/source3/rpcclient/rpcclient.c
@@ -30,8 +30,72 @@ extern struct cmd_set lsarpc_commands[];
extern struct cmd_set samr_commands[];
extern struct cmd_set spoolss_commands[];
+/* List to hold groups of commands */
+static struct cmd_list {
+ struct cmd_list *prev, *next;
+ struct cmd_set *cmd_set;
+} *cmd_list;
+
DOM_SID domain_sid;
+
+/****************************************************************************
+handle completion of commands for readline
+****************************************************************************/
+static char **completion_fn(char *text, int start, int end)
+{
+#define MAX_COMPLETIONS 100
+ char **matches;
+ int i, count=0;
+ struct cmd_list *commands = cmd_list;
+
+#if 0 /* JERRY */
+ /* FIXME!!! -- what to do when completing argument? */
+ /* for words not at the start of the line fallback
+ to filename completion */
+ if (start)
+ return NULL;
+#endif
+
+ /* make sure we have a list of valid commands */
+ if (!commands)
+ return NULL;
+
+ matches = (char **)malloc(sizeof(matches[0])*MAX_COMPLETIONS);
+ if (!matches) return NULL;
+
+ matches[count++] = strdup(text);
+ if (!matches[0]) return NULL;
+
+ while (commands && count < MAX_COMPLETIONS-1)
+ {
+ if (!commands->cmd_set)
+ break;
+
+ for (i=0; commands->cmd_set[i].name; i++)
+ {
+ if ((strncmp(text, commands->cmd_set[i].name, strlen(text)) == 0) &&
+ commands->cmd_set[i].fn)
+ {
+ matches[count] = strdup(commands->cmd_set[i].name);
+ if (!matches[count])
+ return NULL;
+ count++;
+ }
+ }
+
+ commands = commands->next;
+
+ }
+
+ if (count == 2) {
+ free(matches[0]);
+ matches[0] = strdup(matches[1]);
+ }
+ matches[count] = NULL;
+ return matches;
+}
+
/***********************************************************************
* read in username/password credentials from a file
*/
@@ -137,22 +201,29 @@ void fetch_domain_sid(struct cli_state *cli)
uint32 result = 0, info_class = 5;
fstring domain_name;
static BOOL got_domain_sid;
+ TALLOC_CTX *mem_ctx;
if (got_domain_sid) return;
+ if (!(mem_ctx=talloc_init()))
+ {
+ DEBUG(0,("fetch_domain_sid: talloc_init returned NULL!\n"));
+ goto error;
+ }
+
if (!cli_nt_session_open (cli, PIPE_LSARPC)) {
fprintf(stderr, "could not initialise lsa pipe\n");
goto error;
}
- if ((result = cli_lsa_open_policy(cli, True,
+ if ((result = cli_lsa_open_policy(cli, mem_ctx, True,
SEC_RIGHTS_MAXIMUM_ALLOWED,
&pol) != NT_STATUS_NOPROBLEMO)) {
goto error;
}
- if ((result = cli_lsa_query_info_policy(cli, &pol, info_class,
+ if ((result = cli_lsa_query_info_policy(cli, mem_ctx, &pol, info_class,
domain_name, &domain_sid))
!= NT_STATUS_NOPROBLEMO) {
goto error;
@@ -160,8 +231,9 @@ void fetch_domain_sid(struct cli_state *cli)
got_domain_sid = True;
- cli_lsa_close(cli, &pol);
+ cli_lsa_close(cli, mem_ctx, &pol);
cli_nt_session_close(cli);
+ talloc_destroy(mem_ctx);
return;
@@ -192,12 +264,6 @@ void init_rpcclient_creds(struct ntuser_creds *creds, char* username,
fstrcpy(creds->domain, domain);
}
-/* List to hold groups of commands */
-
-static struct cmd_list {
- struct cmd_list *prev, *next;
- struct cmd_set *cmd_set;
-} *cmd_list;
static uint32 cmd_help(struct cli_state *cli, int argc, char **argv)
{
@@ -235,6 +301,7 @@ static uint32 cmd_debuglevel(struct cli_state *cli, int argc, char **argv)
static uint32 cmd_quit(struct cli_state *cli, int argc, char **argv)
{
exit(0);
+ return NT_STATUS_NOPROBLEMO; /* NOTREACHED */
}
/* Build in rpcclient commands */
@@ -339,7 +406,7 @@ static uint32 process_cmd(struct cli_state *cli, char *cmd)
BOOL found = False;
pstring buf;
char *p = cmd;
- uint32 result;
+ uint32 result=0;
if (!next_token(&p, buf, " ", sizeof(buf))) {
return 0;
@@ -596,15 +663,14 @@ static void usage(char *pname)
/* Loop around accepting commands */
while(1) {
- pstring prompt, cmd;
+ pstring prompt;
char *line;
- ZERO_STRUCT(cmd);
-
slprintf(prompt, sizeof(prompt) - 1, "rpcclient $> ");
- line = smb_readline(prompt, NULL, NULL);
+ line = smb_readline(prompt, NULL, completion_fn);
process_cmd(&cli, line);
}
}
+
diff --git a/source3/utils/smbcacls.c b/source3/utils/smbcacls.c
index 4803da9f33..3566ccb28c 100644
--- a/source3/utils/smbcacls.c
+++ b/source3/utils/smbcacls.c
@@ -92,7 +92,7 @@ static BOOL cacls_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 (cli_lsa_open_policy(&lsa_cli, True,
+ if (cli_lsa_open_policy(&lsa_cli, lsa_cli.mem_ctx, True,
GENERIC_EXECUTE_ACCESS, &pol)
!= NT_STATUS_NOPROBLEMO) {
return False;
@@ -118,7 +118,7 @@ static void SidToString(fstring str, DOM_SID *sid)
/* Ask LSA to convert the sid to a name */
if (!cacls_open_policy_hnd() ||
- cli_lsa_lookup_sids(&lsa_cli, &pol, 1, sid, &names, &types,
+ cli_lsa_lookup_sids(&lsa_cli, lsa_cli.mem_ctx, &pol, 1, sid, &names, &types,
&num_names) != NT_STATUS_NOPROBLEMO ||
!names || !names[0]) {
return;
@@ -146,7 +146,7 @@ static BOOL StringToSid(DOM_SID *sid, char *str)
}
if (!cacls_open_policy_hnd() ||
- cli_lsa_lookup_names(&lsa_cli, &pol, 1, &str, &sids, &types,
+ cli_lsa_lookup_names(&lsa_cli, lsa_cli.mem_ctx, &pol, 1, &str, &sids, &types,
&num_sids) != NT_STATUS_NOPROBLEMO) {
result = False;
goto done;