diff options
author | Gerald Carter <jerry@samba.org> | 2001-04-28 00:32:56 +0000 |
---|---|---|
committer | Gerald Carter <jerry@samba.org> | 2001-04-28 00:32:56 +0000 |
commit | e40449fa720d0934abd06cd0b0b05d0ca0f4e257 (patch) | |
tree | 3a66b67b2037a773ddad2d27bfd8d74250682159 /source3/rpcclient | |
parent | b238f4a2ffeb225d16857b594355dc60c976e3e0 (diff) | |
download | samba-e40449fa720d0934abd06cd0b0b05d0ca0f4e257.tar.gz samba-e40449fa720d0934abd06cd0b0b05d0ca0f4e257.tar.bz2 samba-e40449fa720d0934abd06cd0b0b05d0ca0f4e257.zip |
rpcclient merge from 2.2 (including Jeremy's non-void return fix)
(This used to be commit 0a6ceed279cc8111008b21f75c6791efbd993f4b)
Diffstat (limited to 'source3/rpcclient')
-rw-r--r-- | source3/rpcclient/cmd_lsarpc.c | 66 | ||||
-rw-r--r-- | source3/rpcclient/cmd_samr.c | 90 | ||||
-rw-r--r-- | source3/rpcclient/cmd_spoolss.c | 223 | ||||
-rw-r--r-- | source3/rpcclient/rpcclient.c | 94 |
4 files changed, 386 insertions, 87 deletions
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); } } + |