#include "ntdomain.h"
#include "client.h"
-#include "rpcclient.h"
/*
* Size of new password account encoding string. This is enough space to
*/
#include "includes.h"
-
-extern pstring server;
+#include "rpcclient.h"
/* Check DFS is supported by the remote server */
-static NTSTATUS cmd_dfs_exist(struct cli_state *cli, int argc, char **argv)
+static NTSTATUS cmd_dfs_exist(struct cli_state *cli, TALLOC_CTX *mem_ctx,
+ int argc, char **argv)
{
- TALLOC_CTX *mem_ctx;
BOOL dfs_exists;
NTSTATUS result;
return NT_STATUS_OK;
}
- if (!(mem_ctx = talloc_init())) {
- DEBUG(0,("cmd_dfs_exist: talloc_init failed\n"));
- return NT_STATUS_UNSUCCESSFUL;
- }
-
- /* Initialise RPC connection */
-
- if (!cli_nt_session_open (cli, PIPE_NETDFS)) {
- DEBUG(0, ("Could not initialize netdfs pipe!\n"));
- result = NT_STATUS_UNSUCCESSFUL;
- goto done;
- }
-
result = cli_dfs_exist(cli, mem_ctx, &dfs_exists);
if (NT_STATUS_IS_OK(result))
printf("dfs is %spresent\n", dfs_exists ? "" : "not ");
- cli_nt_session_close(cli);
-
-done:
- talloc_destroy(mem_ctx);
return result;
}
-static NTSTATUS cmd_dfs_add(struct cli_state *cli, int argc, char **argv)
+static NTSTATUS cmd_dfs_add(struct cli_state *cli, TALLOC_CTX *mem_ctx,
+ int argc, char **argv)
{
- TALLOC_CTX *mem_ctx;
NTSTATUS result;
char *entrypath, *servername, *sharename, *comment;
uint32 flags = 0;
sharename = argv[3];
comment = argv[4];
- if (!(mem_ctx = talloc_init())) {
- DEBUG(0,("cmd_dfs_add: talloc_init failed\n"));
- return NT_STATUS_UNSUCCESSFUL;
- }
-
- /* Initialise RPC connection */
-
- if (!cli_nt_session_open (cli, PIPE_NETDFS)) {
- DEBUG(0, ("Could not initialize netdfs pipe!\n"));
- result = NT_STATUS_UNSUCCESSFUL;
- goto done;
- }
-
result = cli_dfs_add(cli, mem_ctx, entrypath, servername,
sharename, comment, flags);
- cli_nt_session_close(cli);
-
-done:
- talloc_destroy(mem_ctx);
return result;
}
-static NTSTATUS cmd_dfs_remove(struct cli_state *cli, int argc, char **argv)
+static NTSTATUS cmd_dfs_remove(struct cli_state *cli, TALLOC_CTX *mem_ctx,
+ int argc, char **argv)
{
- TALLOC_CTX *mem_ctx;
NTSTATUS result;
char *entrypath, *servername, *sharename;
servername = argv[2];
sharename = argv[3];
- if (!(mem_ctx = talloc_init())) {
- DEBUG(0,("cmd_dfs_remove: talloc_init failed\n"));
- return NT_STATUS_UNSUCCESSFUL;
- }
-
- /* Initialise RPC connection */
-
- if (!cli_nt_session_open (cli, PIPE_NETDFS)) {
- DEBUG(0, ("Could not initialize netdfs pipe!\n"));
- result = NT_STATUS_UNSUCCESSFUL;
- goto done;
- }
-
result = cli_dfs_remove(cli, mem_ctx, entrypath, servername,
sharename);
- cli_nt_session_close(cli);
-
-done:
- talloc_destroy(mem_ctx);
return result;
}
/* Enumerate dfs shares */
-static NTSTATUS cmd_dfs_enum(struct cli_state *cli, int argc, char **argv)
+static NTSTATUS cmd_dfs_enum(struct cli_state *cli, TALLOC_CTX *mem_ctx,
+ int argc, char **argv)
{
- TALLOC_CTX *mem_ctx;
DFS_INFO_CTR ctr;
NTSTATUS result;
uint32 info_level = 1;
if (argc == 2)
info_level = atoi(argv[1]);
- if (!(mem_ctx = talloc_init())) {
- DEBUG(0,("cmd_dfs_enum: talloc_init failed\n"));
- return NT_STATUS_NO_MEMORY;
- }
-
- /* Initialise RPC connection */
-
- if (!cli_nt_session_open (cli, PIPE_NETDFS)) {
- DEBUG(0, ("Could not initialize netdfs pipe!\n"));
- result = NT_STATUS_UNSUCCESSFUL;
- goto done;
- }
-
- /* Call RPC function */
-
result = cli_dfs_enum(cli, mem_ctx, info_level, &ctr);
- if (NT_STATUS_IS_OK(result)) {
- /* Print results */
- display_dfs_info_ctr(&ctr);
- }
- cli_nt_session_close(cli);
+ if (NT_STATUS_IS_OK(result))
+ display_dfs_info_ctr(&ctr);
-done:
- talloc_destroy(mem_ctx);
return result;
}
-static NTSTATUS cmd_dfs_getinfo(struct cli_state *cli, int argc, char **argv)
+static NTSTATUS cmd_dfs_getinfo(struct cli_state *cli, TALLOC_CTX *mem_ctx,
+ int argc, char **argv)
{
- TALLOC_CTX *mem_ctx;
NTSTATUS result;
char *entrypath, *servername, *sharename;
uint32 info_level = 1;
DFS_INFO_CTR ctr;
if (argc < 4 || argc > 5) {
- printf("Usage: %s entrypath servername sharename [info_level]\n", argv[0]);
+ printf("Usage: %s entrypath servername sharename "
+ "[info_level]\n", argv[0]);
return NT_STATUS_OK;
}
if (argc == 5)
info_level = atoi(argv[4]);
- if (!(mem_ctx = talloc_init())) {
- DEBUG(0,("cmd_dfs_getinfo: talloc_init failed\n"));
- return NT_STATUS_UNSUCCESSFUL;
- }
-
- /* Initialise RPC connection */
-
- if (!cli_nt_session_open (cli, PIPE_NETDFS)) {
- DEBUG(0, ("Could not initialize netdfs pipe!\n"));
- result = NT_STATUS_UNSUCCESSFUL;
- goto done;
- }
-
- /* Call RPC function */
-
result = cli_dfs_get_info(cli, mem_ctx, entrypath, servername,
sharename, info_level, &ctr);
- if (NT_STATUS_IS_OK(result)) {
- /* Print results */
- display_dfs_info_ctr(&ctr);
- }
- cli_nt_session_close(cli);
+ if (NT_STATUS_IS_OK(result))
+ display_dfs_info_ctr(&ctr);
-done:
- talloc_destroy(mem_ctx);
return result;
}
{ "DFS" },
- { "dfsexist", cmd_dfs_exist, "Query DFS support", "" },
- { "dfsadd", cmd_dfs_add, "Add a DFS share", "" },
- { "dfsremove", cmd_dfs_remove, "Remove a DFS share", "" },
- { "dfsgetinfo", cmd_dfs_getinfo, "Query DFS share info", "" },
- { "dfsenum", cmd_dfs_enum, "Enumerate dfs shares", "" },
+ { "dfsexist", cmd_dfs_exist, PIPE_NETDFS, "Query DFS support", "" },
+ { "dfsadd", cmd_dfs_add, PIPE_NETDFS, "Add a DFS share", "" },
+ { "dfsremove", cmd_dfs_remove, PIPE_NETDFS, "Remove a DFS share", "" },
+ { "dfsgetinfo", cmd_dfs_getinfo, PIPE_NETDFS, "Query DFS share info", "" },
+ { "dfsenum", cmd_dfs_enum, PIPE_NETDFS, "Enumerate dfs shares", "" },
{ NULL }
};
*/
#include "includes.h"
-
-extern pstring server;
+#include "rpcclient.h"
/* Look up domain related information on a remote host */
-static NTSTATUS cmd_lsa_query_info_policy(struct cli_state *cli, int argc, char **argv)
+
+static NTSTATUS cmd_lsa_query_info_policy(struct cli_state *cli,
+ TALLOC_CTX *mem_ctx, int argc,
+ char **argv)
{
POLICY_HND pol;
NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
- BOOL got_policy_hnd = False;
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 NT_STATUS_OK;
}
- if (!(mem_ctx = talloc_init())) {
- DEBUG(0,("cmd_lsa_query_info_poicy: talloc_init failed\n"));
- return NT_STATUS_UNSUCCESSFUL;
- }
-
- if (argc == 2) {
+ if (argc == 2)
info_class = atoi(argv[1]);
- }
- /* Initialise RPC connection */
- if (!cli_nt_session_open (cli, PIPE_LSARPC)) {
- DEBUG(0, ("Could not initialize samr pipe!\n"));
- talloc_destroy(mem_ctx);
- return NT_STATUS_UNSUCCESSFUL;
- }
-
result = cli_lsa_open_policy(cli, mem_ctx, True,
SEC_RIGHTS_MAXIMUM_ALLOWED,
&pol);
- if (!NT_STATUS_IS_OK(result)) {
- goto done;
- }
- got_policy_hnd = True;
+ if (!NT_STATUS_IS_OK(result))
+ goto done;
/* Lookup info policy */
result = cli_lsa_query_info_policy(cli, mem_ctx, &pol, info_class,
domain_name, &dom_sid);
- if (!NT_STATUS_IS_OK(result)) {
+
+ if (!NT_STATUS_IS_OK(result))
goto done;
- }
sid_to_string(sid_str, &dom_sid);
- if (domain_name[0]) {
+ if (domain_name[0])
printf("domain %s has sid %s\n", domain_name, sid_str);
- } else {
+ else
printf("could not query info for level %d\n", info_class);
- }
-
-done:
-
- if (got_policy_hnd) {
- cli_lsa_close(cli, mem_ctx, &pol);
- }
-
- cli_nt_session_close(cli);
- talloc_destroy(mem_ctx);
+ done:
return result;
}
/* Resolve a list of names to a list of sids */
-static NTSTATUS cmd_lsa_lookup_names(struct cli_state *cli, int argc, char **argv)
+static NTSTATUS cmd_lsa_lookup_names(struct cli_state *cli,
+ TALLOC_CTX *mem_ctx, int argc,
+ char **argv)
{
POLICY_HND pol;
NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
- BOOL got_policy_hnd = False;
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 NT_STATUS_OK;
}
- if (!(mem_ctx = talloc_init())) {
- DEBUG(0,("cmd_lsa_lookup_names: talloc_init failed\n"));
- return NT_STATUS_UNSUCCESSFUL;
- }
-
- /* Initialise RPC connection */
- if (!cli_nt_session_open (cli, PIPE_LSARPC)) {
- DEBUG(0, ("Could not initialize samr pipe!\n"));
- talloc_destroy(mem_ctx);
- return NT_STATUS_UNSUCCESSFUL;
- }
-
-
result = cli_lsa_open_policy(cli, mem_ctx, True,
SEC_RIGHTS_MAXIMUM_ALLOWED,
&pol);
- if (!NT_STATUS_IS_OK(result)) {
- goto done;
- }
- got_policy_hnd = True;
+ if (!NT_STATUS_IS_OK(result))
+ goto done;
/* Lookup the names */
result = cli_lsa_lookup_names(cli, mem_ctx, &pol, argc - 1,
&argv[1], &sids, &types, &num_names);
- if (!NT_STATUS_IS_OK(result)) {
+
+ if (!NT_STATUS_IS_OK(result))
goto done;
- }
/* Print results */
}
done:
-
- if (got_policy_hnd) {
- cli_lsa_close(cli, mem_ctx, &pol);
- }
-
- cli_nt_session_close(cli);
- talloc_destroy(mem_ctx);
-
return result;
}
/* Resolve a list of SIDs to a list of names */
-static NTSTATUS cmd_lsa_lookup_sids(struct cli_state *cli, int argc, char **argv)
+static NTSTATUS cmd_lsa_lookup_sids(struct cli_state *cli, TALLOC_CTX *mem_ctx,
+ int argc, char **argv)
{
POLICY_HND pol;
NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
- BOOL got_policy_hnd = False;
DOM_SID *sids;
char **names;
uint32 *types;
int num_names, i;
- TALLOC_CTX *mem_ctx;
if (argc == 1) {
printf("Usage: %s [sid1 [sid2 [...]]]\n", argv[0]);
return NT_STATUS_OK;
}
- if (!(mem_ctx = talloc_init())) {
- DEBUG(0,("cmd_lsa_lookup_sids: talloc_init failed\n"));
- return NT_STATUS_UNSUCCESSFUL;
- }
-
- /* Initialise RPC connection */
- if (!cli_nt_session_open (cli, PIPE_LSARPC)) {
- DEBUG(0, ("Could not initialize samr pipe!\n"));
- talloc_destroy(mem_ctx);
- return NT_STATUS_UNSUCCESSFUL;
- }
-
result = cli_lsa_open_policy(cli, mem_ctx, True,
SEC_RIGHTS_MAXIMUM_ALLOWED,
&pol);
- if (!NT_STATUS_IS_OK(result)) {
- goto done;
- }
- got_policy_hnd = True;
+ if (!NT_STATUS_IS_OK(result))
+ goto done;
/* Convert arguments to sids */
sids = (DOM_SID *)talloc(mem_ctx, sizeof(DOM_SID) * (argc - 1));
if (!sids) {
- printf("out of memory\n");
+ printf("could not allocate memory for %d sids\n", argc - 1);
goto done;
}
- for (i = 0; i < argc - 1; i++) {
+ for (i = 0; i < argc - 1; i++)
string_to_sid(&sids[i], argv[i + 1]);
- }
/* Lookup the SIDs */
result = cli_lsa_lookup_sids(cli, mem_ctx, &pol, argc - 1, sids,
&names, &types, &num_names);
- if (!NT_STATUS_IS_OK(result)) {
+
+ if (!NT_STATUS_IS_OK(result))
goto done;
- }
/* Print results */
"*unknown*", types[i]);
}
-#if 0 /* JERRY */
- SAFE_FREE(sids);
- SAFE_FREE(types);
-
- for (i = 0; i < num_names; i++) {
- SAFE_FREE(names[i]);
- }
-
- SAFE_FREE(names);
-#endif
-
done:
-
- if (got_policy_hnd) {
- cli_lsa_close(cli, mem_ctx, &pol);
- }
-
- cli_nt_session_close(cli);
- talloc_destroy (mem_ctx);
-
return result;
}
/* Enumerate list of trusted domains */
-static NTSTATUS cmd_lsa_enum_trust_dom(struct cli_state *cli, int argc, char **argv)
+static NTSTATUS cmd_lsa_enum_trust_dom(struct cli_state *cli,
+ TALLOC_CTX *mem_ctx, int argc,
+ char **argv)
{
POLICY_HND pol;
NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
- BOOL got_policy_hnd = False;
DOM_SID *domain_sids;
char **domain_names;
uint32 enum_ctx = 0;
uint32 num_domains;
int i;
- TALLOC_CTX *mem_ctx;
if (argc != 1) {
printf("Usage: %s\n", argv[0]);
return NT_STATUS_OK;
}
- if (!(mem_ctx = talloc_init())) {
- DEBUG(0,("cmd_lsa_enum_trust_dom: talloc_init failed\n"));
- return NT_STATUS_UNSUCCESSFUL;
- }
-
- /* Initialise RPC connection */
- if (!cli_nt_session_open (cli, PIPE_LSARPC)) {
- DEBUG(0, ("Could not initialize samr pipe!\n"));
- talloc_destroy(mem_ctx);
- return NT_STATUS_UNSUCCESSFUL;
- }
-
result = cli_lsa_open_policy(cli, mem_ctx, True,
SEC_RIGHTS_MAXIMUM_ALLOWED,
&pol);
- if (!NT_STATUS_IS_OK(result)) {
- goto done;
- }
- got_policy_hnd = True;
+ if (!NT_STATUS_IS_OK(result))
+ goto done;
/* Lookup list of trusted domains */
result = cli_lsa_enum_trust_dom(cli, mem_ctx, &pol, &enum_ctx,
&num_domains, &domain_names,
&domain_sids);
- if (!NT_STATUS_IS_OK(result)) {
+
+ if (!NT_STATUS_IS_OK(result))
goto done;
- }
/* Print results */
}
done:
-
- if (got_policy_hnd) {
- cli_lsa_close(cli, mem_ctx, &pol);
- }
-
- cli_nt_session_close(cli);
- talloc_destroy(mem_ctx);
-
return result;
}
{ "LSARPC" },
- { "lsaquery", cmd_lsa_query_info_policy, "Query info policy", "" },
- { "lookupsids", cmd_lsa_lookup_sids, "Convert SIDs to names", "" },
- { "lookupnames", cmd_lsa_lookup_names, "Convert names to SIDs", "" },
- { "enumtrust", cmd_lsa_enum_trust_dom, "Enumerate trusted domains", "" },
+ { "lsaquery", cmd_lsa_query_info_policy, PIPE_LSARPC, "Query info policy", "" },
+ { "lookupsids", cmd_lsa_lookup_sids, PIPE_LSARPC, "Convert SIDs to names", "" },
+ { "lookupnames", cmd_lsa_lookup_names, PIPE_LSARPC, "Convert names to SIDs", "" },
+ { "enumtrust", cmd_lsa_enum_trust_dom, PIPE_LSARPC, "Enumerate trusted domains", "" },
{ NULL }
};
*/
#include "includes.h"
+#include "rpcclient.h"
-static NTSTATUS cmd_netlogon_logon_ctrl2(struct cli_state *cli, int argc,
- char **argv)
+static NTSTATUS cmd_netlogon_logon_ctrl2(struct cli_state *cli,
+ TALLOC_CTX *mem_ctx, int argc,
+ char **argv)
{
uint32 query_level = 1;
- TALLOC_CTX *mem_ctx;
NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
if (argc > 1) {
- printf("Usage: %s\n", argv[0]);
+ fprintf(stderr, "Usage: %s\n", argv[0]);
return NT_STATUS_OK;
}
- if (!(mem_ctx = talloc_init())) {
- DEBUG(0,("cmd_srvsvc_srv_query_info: talloc_init failed\n"));
- goto done;
- }
-
- /* Initialise RPC connection */
-
- if (!cli_nt_session_open (cli, PIPE_NETLOGON)) {
- DEBUG(0, ("Could not initialize srvsvc pipe!\n"));
- goto done;
- }
-
result = cli_netlogon_logon_ctrl2(cli, mem_ctx, query_level);
- if (!NT_STATUS_IS_OK(result)) {
+
+ if (!NT_STATUS_IS_OK(result))
goto done;
- }
/* Display results */
return result;
}
-static NTSTATUS cmd_netlogon_logon_ctrl(struct cli_state *cli, int argc,
- char **argv)
+static NTSTATUS cmd_netlogon_logon_ctrl(struct cli_state *cli,
+ TALLOC_CTX *mem_ctx, int argc,
+ char **argv)
{
#if 0
uint32 query_level = 1;
#endif
- TALLOC_CTX *mem_ctx;
NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
if (argc > 1) {
- printf("Usage: %s\n", argv[0]);
+ fprintf(stderr, "Usage: %s\n", argv[0]);
return NT_STATUS_OK;
}
- if (!(mem_ctx = talloc_init())) {
- DEBUG(0,("cmd_srvsvc_srv_query_info: talloc_init failed\n"));
- goto done;
- }
-
- /* Initialise RPC connection */
-
- if (!cli_nt_session_open (cli, PIPE_NETLOGON)) {
- DEBUG(0, ("Could not initialize netlogon pipe!\n"));
- goto done;
- }
-
#if 0
result = cli_netlogon_logon_ctrl(cli, mem_ctx, query_level);
if (!NT_STATUS_IS_OK(result)) {
/* Display results */
- done:
return result;
}
unistr2_to_ascii(name,
&deltas[i].domain_info.uni_dom_name,
sizeof(name) - 1);
- DEBUG(0, ("Domain: %s\n", name));
+ printf("Domain: %s\n", name);
break;
case SAM_DELTA_GROUP_INFO:
unistr2_to_ascii(name,
&deltas[i].group_info.uni_grp_name,
sizeof(name) - 1);
- DEBUG(0, ("Group: %s\n", name));
+ printf("Group: %s\n", name);
break;
case SAM_DELTA_ACCOUNT_INFO:
unistr2_to_ascii(name,
&deltas[i].account_info.uni_acct_name,
sizeof(name) - 1);
- DEBUG(0, ("Account: %s\n", name));
+ printf("Account: %s\n", name);
break;
case SAM_DELTA_ALIAS_INFO:
unistr2_to_ascii(name,
&deltas[i].alias_info.uni_als_name,
sizeof(name) - 1);
- DEBUG(0, ("Alias: %s\n", name));
+ printf("Alias: %s\n", name);
break;
case SAM_DELTA_ALIAS_MEM: {
SAM_ALIAS_MEM_INFO *alias = &deltas[i].als_mem_info;
sid_to_string(sid_str, &alias->sids[j].sid);
- DEBUG(0, ("%s\n", sid_str));
+ printf("%s\n", sid_str);
}
break;
}
SAM_GROUP_MEM_INFO *group = &deltas[i].grp_mem_info;
for (j = 0; j < group->num_members; j++)
- DEBUG(0, ("rid 0x%x, attrib 0x%08x\n",
- group->rids[j], group->attribs[j]));
+ printf("rid 0x%x, attrib 0x%08x\n",
+ group->rids[j], group->attribs[j]);
break;
}
case SAM_DELTA_SAM_STAMP: {
SAM_DELTA_STAMP *stamp = &deltas[i].stamp;
- DEBUG(0, ("sam sequence update: 0x%04x\n",
- stamp->seqnum));
+ printf("sam sequence update: 0x%04x\n",
+ stamp->seqnum);
break;
}
default:
- DEBUG(0, ("unknown delta type 0x%02x\n",
- hdr_deltas[i].type));
+ printf("unknown delta type 0x%02x\n",
+ hdr_deltas[i].type);
break;
}
}
/* Perform sam synchronisation */
-static NTSTATUS cmd_netlogon_sam_sync(struct cli_state *cli, int argc,
- char **argv)
+static NTSTATUS cmd_netlogon_sam_sync(struct cli_state *cli,
+ TALLOC_CTX *mem_ctx, int argc,
+ char **argv)
{
NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
unsigned char trust_passwd[16];
- TALLOC_CTX *mem_ctx;
uint32 database_id = 0, num_deltas;
SAM_DELTA_HDR *hdr_deltas;
SAM_DELTA_CTR *deltas;
if (argc > 2) {
- printf("Usage: %s [database_id]\n", argv[0]);
+ fprintf(stderr, "Usage: %s [database_id]\n", argv[0]);
return NT_STATUS_OK;
}
database_id = atoi(argv[1]);
if (!secrets_init()) {
- DEBUG(0, ("Unable to initialise secrets database\n"));
+ fprintf(stderr, "Unable to initialise secrets database\n");
return result;
}
- if (!(mem_ctx = talloc_init())) {
- DEBUG(0,("talloc_init failed\n"));
- return result;
- }
-
- /* Initialise RPC connection */
-
- if (!cli_nt_session_open (cli, PIPE_NETLOGON)) {
- DEBUG(0, ("Could not initialize netlogon pipe!\n"));
- goto done;
- }
-
/* Initialise session credentials */
if (!secrets_fetch_trust_account_password(lp_workgroup(), trust_passwd,
NULL)) {
- DEBUG(0, ("could not fetch trust account password\n"));
+ fprintf(stderr, "could not fetch trust account password\n");
goto done;
}
result = cli_nt_setup_creds(cli, trust_passwd);
if (!NT_STATUS_IS_OK(result)) {
- DEBUG(0, ("Error initialising session creds\n"));
+ fprintf(stderr, "Error initialising session creds\n");
goto done;
}
result = cli_netlogon_sam_sync(cli, mem_ctx, database_id,
&num_deltas, &hdr_deltas, &deltas);
- if (!NT_STATUS_IS_OK(result)) {
+
+ if (!NT_STATUS_IS_OK(result))
goto done;
- }
/* Display results */
display_sam_sync(num_deltas, hdr_deltas, deltas);
done:
- cli_nt_session_close(cli);
- talloc_destroy(mem_ctx);
-
return result;
}
/* Perform sam delta synchronisation */
-static NTSTATUS cmd_netlogon_sam_deltas(struct cli_state *cli, int argc,
- char **argv)
+static NTSTATUS cmd_netlogon_sam_deltas(struct cli_state *cli,
+ TALLOC_CTX *mem_ctx, int argc,
+ char **argv)
{
NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
unsigned char trust_passwd[16];
- TALLOC_CTX *mem_ctx = NULL;
uint32 database_id, num_deltas, tmp;
SAM_DELTA_HDR *hdr_deltas;
SAM_DELTA_CTR *deltas;
UINT64_S seqnum;
if (argc != 3) {
- printf("Usage: %s database_id seqnum\n", argv[0]);
+ fprintf(stderr, "Usage: %s database_id seqnum\n", argv[0]);
return NT_STATUS_OK;
}
seqnum.high = 0;
if (!secrets_init()) {
- DEBUG(0, ("Unable to initialise secrets database\n"));
+ fprintf(stderr, "Unable to initialise secrets database\n");
goto done;
}
- if (!(mem_ctx = talloc_init())) {
- DEBUG(0,("talloc_init failed\n"));
- goto done;
- }
-
- /* Initialise RPC connection */
-
- if (!cli_nt_session_open (cli, PIPE_NETLOGON)) {
- DEBUG(0, ("Could not initialize netlogon pipe!\n"));
- goto done;
- }
-
/* Initialise session credentials */
if (!secrets_fetch_trust_account_password(lp_workgroup(), trust_passwd,
NULL)) {
- DEBUG(0, ("could not fetch trust account password\n"));
+ fprintf(stderr, "could not fetch trust account password\n");
goto done;
}
result = cli_nt_setup_creds(cli, trust_passwd);
if (!NT_STATUS_IS_OK(result)) {
- DEBUG(0, ("Error initialising session creds\n"));
+ fprintf(stderr, "Error initialising session creds\n");
goto done;
}
result = cli_netlogon_sam_deltas(cli, mem_ctx, database_id,
seqnum, &num_deltas,
&hdr_deltas, &deltas);
- if (!NT_STATUS_IS_OK(result)) {
+
+ if (!NT_STATUS_IS_OK(result))
goto done;
- }
/* Display results */
display_sam_sync(num_deltas, hdr_deltas, deltas);
done:
- cli_nt_session_close(cli);
- talloc_destroy(mem_ctx);
-
return result;
}
{ "NETLOGON" },
- { "logonctrl2", cmd_netlogon_logon_ctrl2, "Logon Control 2", "" },
- { "logonctrl", cmd_netlogon_logon_ctrl, "Logon Control", "" },
- { "samsync", cmd_netlogon_sam_sync, "Sam Synchronisation", "" },
- { "samdeltas", cmd_netlogon_sam_deltas, "Query Sam Deltas", "" },
+ { "logonctrl2", cmd_netlogon_logon_ctrl2, PIPE_NETLOGON, "Logon Control 2", "" },
+ { "logonctrl", cmd_netlogon_logon_ctrl, PIPE_NETLOGON, "Logon Control", "" },
+ { "samsync", cmd_netlogon_sam_sync, PIPE_NETLOGON, "Sam Synchronisation", "" },
+ { "samdeltas", cmd_netlogon_sam_deltas, PIPE_NETLOGON, "Query Sam Deltas", "" },
{ NULL }
};
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
-#ifdef SYSLOG
-#undef SYSLOG
-#endif
-
#include "includes.h"
-
-extern int smb_tidx;
-
-extern FILE* out_hnd;
+#include "rpcclient.h"
/*
* keys. of the form:
/****************************************************************************
nt registry shutdown
****************************************************************************/
-static NTSTATUS cmd_reg_shutdown(struct cli_state *cli, int argc, char **argv)
+static NTSTATUS cmd_reg_shutdown(struct cli_state *cli, TALLOC_CTX *mem_ctx,
+ int argc, char **argv)
{
NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
fstring msg;
int opt;
int ret;
char *srv_name;
- TALLOC_CTX *mem_ctx;
ret = asprintf (&srv_name, "\\\\%s", cli->desthost);
if (ret < 0) {
}
strupper(srv_name);
- 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_WINREG)) {
- fprintf (stderr, "Could not initialize winreg pipe!\n");
- goto done;
- }
-
*msg = 0;
optind = 0; /* TODO: test if this hack works on other systems too --simo */
else
DEBUG(5,("cmd_reg_shutdown: query failed\n"));
- cli_nt_session_close(cli);
-
-done:
- talloc_destroy(mem_ctx);
-
return result;
}
/****************************************************************************
abort a shutdown
****************************************************************************/
-static NTSTATUS cmd_reg_abort_shutdown(struct cli_state *cli, int argc, char **argv)
+static NTSTATUS cmd_reg_abort_shutdown(struct cli_state *cli,
+ TALLOC_CTX *mem_ctx, int argc,
+ char **argv)
{
NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
int ret;
char *srv_name;
- TALLOC_CTX *mem_ctx;
ret = asprintf(&srv_name, "\\\\%s", cli->desthost);
if (ret < 0) {
}
strupper(srv_name);
- 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_WINREG)) {
- fprintf (stderr, "Could not initialize winreg pipe!\n");
- goto done;
- }
-
result = cli_reg_abort_shutdown(cli, mem_ctx, srv_name);
if (NT_STATUS_IS_OK(result))
else
DEBUG(5,("cmd_reg_abort_shutdown: query failed\n"));
- cli_nt_session_close(cli);
-
-done:
- talloc_destroy(mem_ctx);
-
return result;
}
{ "REG" },
- { "shutdown", cmd_reg_shutdown, "Remote Shutdown",
+ { "shutdown", cmd_reg_shutdown, PIPE_WINREG, "Remote Shutdown",
"[-m message] [-t timeout] [-r] [-f] (-r == reboot, -f == force)" },
- { "abortshutdown", cmd_reg_abort_shutdown, "Abort Shutdown",
+ { "abortshutdown", cmd_reg_abort_shutdown, PIPE_WINREG, "Abort Shutdown",
"" },
/*
{ "regenum", cmd_reg_enum, "Registry Enumeration",
*/
#include "includes.h"
+#include "rpcclient.h"
extern DOM_SID domain_sid;
/**********************************************************************
* Query user information
*/
-static NTSTATUS cmd_samr_query_user(struct cli_state *cli, int argc, char **argv)
+static NTSTATUS cmd_samr_query_user(struct cli_state *cli,
+ TALLOC_CTX *mem_ctx,
+ int argc, char **argv)
{
POLICY_HND connect_pol, domain_pol, user_pol;
NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
uint32 info_level = 21;
- BOOL got_connect_pol = False,
- got_domain_pol = False,
- got_user_pol = False;
SAM_USERINFO_CTR *user_ctr;
- fstring server;
- TALLOC_CTX *mem_ctx;
+ fstring server;
uint32 user_rid;
-
if (argc != 2) {
printf("Usage: %s rid\n", argv[0]);
return NT_STATUS_OK;
sscanf(argv[1], "%i", &user_rid);
- if (!(mem_ctx=talloc_init()))
- {
- DEBUG(0,("cmd_samr_query_user: talloc_init returned NULL!\n"));
- return NT_STATUS_UNSUCCESSFUL;
- }
-
fetch_domain_sid(cli);
- /* Initialise RPC connection */
- if (!cli_nt_session_open (cli, PIPE_SAMR)) {
- fprintf (stderr, "Could not initialize samr pipe!\n");
- talloc_destroy(mem_ctx);
- return NT_STATUS_UNSUCCESSFUL;
- }
-
slprintf (server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
strupper (server);
result = cli_samr_connect(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
&connect_pol);
- if (!NT_STATUS_IS_OK(result)) {
- goto done;
- }
- got_connect_pol = True;
+ if (!NT_STATUS_IS_OK(result))
+ goto done;
result = cli_samr_open_domain(cli, mem_ctx, &connect_pol,
MAXIMUM_ALLOWED_ACCESS,
&domain_sid, &domain_pol);
- if (!NT_STATUS_IS_OK(result)) {
- goto done;
- }
- got_domain_pol = True;
+ if (!NT_STATUS_IS_OK(result))
+ goto done;
result = cli_samr_open_user(cli, mem_ctx, &domain_pol,
MAXIMUM_ALLOWED_ACCESS,
user_rid, &user_pol);
- if (!NT_STATUS_IS_OK(result)) {
- goto done;
- }
- got_user_pol = True;
+ if (!NT_STATUS_IS_OK(result))
+ goto done;
ZERO_STRUCT(user_ctr);
result = cli_samr_query_userinfo(cli, mem_ctx, &user_pol,
info_level, &user_ctr);
- if (!NT_STATUS_IS_OK(result)) {
+
+ if (!NT_STATUS_IS_OK(result))
goto done;
- }
display_sam_user_info_21(user_ctr->info.id21);
done:
- 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;
}
/***********************************************************************
* Query group information
*/
-static NTSTATUS cmd_samr_query_group(struct cli_state *cli, int argc, char **argv)
+static NTSTATUS cmd_samr_query_group(struct cli_state *cli,
+ TALLOC_CTX *mem_ctx,
+ int argc, char **argv)
{
POLICY_HND connect_pol, domain_pol, group_pol;
NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
uint32 info_level = 1;
- BOOL got_connect_pol = False, got_domain_pol = False,
- got_group_pol = False;
GROUP_INFO_CTR group_ctr;
fstring server;
- TALLOC_CTX *mem_ctx;
uint32 group_rid;
if (argc != 2) {
group_rid = atoi(argv[1]);
- if (!(mem_ctx=talloc_init())) {
- DEBUG(0,("cmd_samr_query_group: talloc_init returned NULL!\n"));
- return NT_STATUS_UNSUCCESSFUL;
- }
-
fetch_domain_sid(cli);
- /* Initialise RPC connection */
- if (!cli_nt_session_open (cli, PIPE_SAMR)) {
- fprintf (stderr, "Could not initialize samr pipe!\n");
- talloc_destroy(mem_ctx);
- return NT_STATUS_UNSUCCESSFUL;
- }
-
slprintf (server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
strupper (server);
result = cli_samr_connect(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
&connect_pol);
- if (!NT_STATUS_IS_OK(result)) {
- goto done;
- }
- got_connect_pol = True;
+ if (!NT_STATUS_IS_OK(result))
+ goto done;
result = cli_samr_open_domain(cli, mem_ctx, &connect_pol,
MAXIMUM_ALLOWED_ACCESS,
&domain_sid, &domain_pol);
- if (!NT_STATUS_IS_OK(result)) {
- goto done;
- }
- got_domain_pol = True;
+ if (!NT_STATUS_IS_OK(result))
+ goto done;
result = cli_samr_open_group(cli, mem_ctx, &domain_pol,
MAXIMUM_ALLOWED_ACCESS,
group_rid, &group_pol);
- if (!NT_STATUS_IS_OK(result)) {
- goto done;
- }
- got_group_pol = True;
+ if (!NT_STATUS_IS_OK(result))
+ goto done;
ZERO_STRUCT(group_ctr);
display_group_info_ctr(&group_ctr);
done:
- 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;
}
/* Query groups a user is a member of */
-static NTSTATUS cmd_samr_query_usergroups(struct cli_state *cli, int argc, char **argv)
+static NTSTATUS cmd_samr_query_usergroups(struct cli_state *cli,
+ TALLOC_CTX *mem_ctx,
+ int argc, char **argv)
{
POLICY_HND connect_pol,
domain_pol,
user_pol;
NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
- BOOL got_connect_pol = False,
- got_domain_pol = False,
- got_user_pol = False;
uint32 num_groups,
user_rid;
DOM_GID *user_gids;
int i;
fstring server;
- TALLOC_CTX *mem_ctx;
if (argc != 2) {
printf("Usage: %s rid\n", argv[0]);
return NT_STATUS_OK;
}
- if (!(mem_ctx=talloc_init()))
- {
- DEBUG(0,("cmd_samr_query_usergroups: talloc_init returned NULL!\n"));
- return NT_STATUS_NO_MEMORY;
- }
-
sscanf(argv[1], "%i", &user_rid);
fetch_domain_sid(cli);
- /* Initialise RPC connection */
- if (!cli_nt_session_open (cli, PIPE_SAMR)) {
- fprintf (stderr, "Could not initialize samr pipe!\n");
- talloc_destroy(mem_ctx);
- return NT_STATUS_UNSUCCESSFUL;
- }
-
slprintf (server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
strupper (server);
goto done;
}
- got_connect_pol = True;
-
result = cli_samr_open_domain(cli, mem_ctx, &connect_pol,
MAXIMUM_ALLOWED_ACCESS,
&domain_sid, &domain_pol);
goto done;
}
- got_domain_pol = True;
-
result = cli_samr_open_user(cli, mem_ctx, &domain_pol,
MAXIMUM_ALLOWED_ACCESS,
user_rid, &user_pol);
goto done;
}
- got_user_pol = True;
-
result = cli_samr_query_usergroups(cli, mem_ctx, &user_pol,
&num_groups, &user_gids);
if (!NT_STATUS_IS_OK(result)) {
}
done:
- 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;
}
/* Query members of a group */
-static NTSTATUS cmd_samr_query_groupmem(struct cli_state *cli, int argc, char **argv)
+static NTSTATUS cmd_samr_query_groupmem(struct cli_state *cli,
+ TALLOC_CTX *mem_ctx,
+ int argc, char **argv)
{
POLICY_HND connect_pol, domain_pol, group_pol;
NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
- BOOL got_connect_pol = False,
- got_domain_pol = False,
- got_group_pol = False;
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 NT_STATUS_OK;
}
- if (!(mem_ctx=talloc_init()))
- {
- DEBUG(0,("cmd_samr_query_groupmem: talloc_init returned NULL!\n"));
- return NT_STATUS_NO_MEMORY;
- }
-
sscanf(argv[1], "%i", &group_rid);
fetch_domain_sid(cli);
- /* Initialise RPC connection */
- if (!cli_nt_session_open (cli, PIPE_SAMR)) {
- fprintf (stderr, "Could not initialize samr pipe!\n");
- talloc_destroy(mem_ctx);
- return NT_STATUS_UNSUCCESSFUL;
- }
-
slprintf (server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
strupper (server);
goto done;
}
- got_connect_pol = True;
-
result = cli_samr_open_domain(cli, mem_ctx, &connect_pol,
MAXIMUM_ALLOWED_ACCESS,
&domain_sid, &domain_pol);
goto done;
}
- got_domain_pol = True;
-
result = cli_samr_open_group(cli, mem_ctx, &domain_pol,
MAXIMUM_ALLOWED_ACCESS,
group_rid, &group_pol);
goto done;
}
- got_group_pol = True;
-
result = cli_samr_query_groupmem(cli, mem_ctx, &group_pol,
&num_members, &group_rids,
&group_attrs);
}
done:
- 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;
}
/* Enumerate domain groups */
-static NTSTATUS cmd_samr_enum_dom_groups(struct cli_state *cli, int argc,
- char **argv)
+static NTSTATUS cmd_samr_enum_dom_groups(struct cli_state *cli,
+ TALLOC_CTX *mem_ctx,
+ int argc, char **argv)
{
POLICY_HND connect_pol, domain_pol;
NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
- BOOL got_connect_pol = False, got_domain_pol = False;
- TALLOC_CTX *mem_ctx;
uint32 start_idx, size, num_dom_groups, i;
struct acct_info *dom_groups;
return NT_STATUS_OK;
}
- if (!(mem_ctx = talloc_init())) {
- DEBUG(0, ("cmd_samr_enum_dom_groups: talloc_init returned "
- "NULL!\n"));
- return NT_STATUS_UNSUCCESSFUL;
- }
-
fetch_domain_sid(cli);
- /* Initialise RPC connection */
-
- if (!cli_nt_session_open (cli, PIPE_SAMR)) {
- fprintf (stderr, "Could not initialize samr pipe!\n");
- talloc_destroy(mem_ctx);
- return NT_STATUS_UNSUCCESSFUL;
- }
-
/* Get sam policy handle */
result = cli_samr_connect(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
goto done;
}
- got_connect_pol = True;
-
/* Get domain policy handle */
result = cli_samr_open_domain(cli, mem_ctx, &connect_pol,
goto done;
}
- got_domain_pol = True;
-
/* Enumerate domain groups */
start_idx = 0;
dom_groups[i].rid);
done:
- 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;
}
/* Query alias membership */
-static NTSTATUS cmd_samr_query_aliasmem(struct cli_state *cli, int argc,
- char **argv)
+static NTSTATUS cmd_samr_query_aliasmem(struct cli_state *cli,
+ TALLOC_CTX *mem_ctx,
+ int argc, char **argv)
{
POLICY_HND connect_pol, domain_pol, alias_pol;
- BOOL got_connect_pol = False, got_domain_pol = False,
- got_alias_pol = False;
- TALLOC_CTX *mem_ctx;
NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
uint32 alias_rid, num_members, i;
DOM_SID *alias_sids;
return NT_STATUS_OK;
}
- if (!(mem_ctx=talloc_init())) {
- DEBUG(0,("cmd_samr_query_aliasmem: talloc_init() "
- "returned NULL!\n"));
- return NT_STATUS_UNSUCCESSFUL;
- }
-
sscanf(argv[1], "%i", &alias_rid);
- /* Initialise RPC connection */
-
fetch_domain_sid(cli);
- if (!cli_nt_session_open (cli, PIPE_SAMR)) {
- fprintf (stderr, "Could not initialize samr pipe!\n");
- talloc_destroy(mem_ctx);
- return NT_STATUS_UNSUCCESSFUL;
- }
-
/* Open SAMR handle */
result = cli_samr_connect(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
goto done;
}
- got_connect_pol = True;
-
/* Open handle on domain */
result = cli_samr_open_domain(cli, mem_ctx, &connect_pol,
goto done;
}
- got_domain_pol = True;
-
/* Open handle on alias */
result = cli_samr_open_alias(cli, mem_ctx, &domain_pol,
goto done;
}
- got_alias_pol = True;
-
result = cli_samr_query_aliasmem(cli, mem_ctx, &alias_pol,
&num_members, &alias_sids);
if (!NT_STATUS_IS_OK(result)) {
}
done:
- if (got_alias_pol) cli_samr_close(cli, mem_ctx, &alias_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;
}
/* Query display info */
-static NTSTATUS cmd_samr_query_dispinfo(struct cli_state *cli, int argc,
- char **argv)
+static NTSTATUS cmd_samr_query_dispinfo(struct cli_state *cli,
+ TALLOC_CTX *mem_ctx,
+ int argc, char **argv)
{
POLICY_HND connect_pol, domain_pol;
NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
- BOOL got_connect_pol = False, got_domain_pol = False;
- TALLOC_CTX *mem_ctx;
uint32 start_idx, max_entries, num_entries, i;
uint16 info_level = 1;
SAM_DISPINFO_CTR ctr;
return NT_STATUS_OK;
}
- if (!(mem_ctx = talloc_init())) {
- DEBUG(0, ("cmd_samr_query_dispinfo: talloc_init returned "
- "NULL!\n"));
- return NT_STATUS_NO_MEMORY;
- }
-
fetch_domain_sid(cli);
- /* Initialise RPC connection */
-
- if (!cli_nt_session_open (cli, PIPE_SAMR)) {
- fprintf (stderr, "Could not initialize samr pipe!\n");
- talloc_destroy(mem_ctx);
- return NT_STATUS_UNSUCCESSFUL;
- }
-
/* Get sam policy handle */
result = cli_samr_connect(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
goto done;
}
- got_connect_pol = True;
-
/* Get domain policy handle */
result = cli_samr_open_domain(cli, mem_ctx, &connect_pol,
goto done;
}
- got_domain_pol = True;
-
/* Query display info */
start_idx = 0;
}
done:
- 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;
}
/* Query domain info */
-static NTSTATUS cmd_samr_query_dominfo(struct cli_state *cli, int argc,
- char **argv)
+static NTSTATUS cmd_samr_query_dominfo(struct cli_state *cli,
+ TALLOC_CTX *mem_ctx,
+ int argc, char **argv)
{
POLICY_HND connect_pol, domain_pol;
NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
- BOOL got_connect_pol = False, got_domain_pol = False;
- TALLOC_CTX *mem_ctx;
uint16 switch_value = 2;
SAM_UNK_CTR ctr;
if (argc == 2)
switch_value = atoi(argv[1]);
- if (!(mem_ctx = talloc_init())) {
- DEBUG(0, ("cmd_samr_query_dispinfo: talloc_init returned "
- "NULL!\n"));
- return NT_STATUS_UNSUCCESSFUL;
- }
-
fetch_domain_sid(cli);
- /* Initialise RPC connection */
-
- if (!cli_nt_session_open (cli, PIPE_SAMR)) {
- fprintf (stderr, "Could not initialize samr pipe!\n");
- talloc_destroy(mem_ctx);
- return NT_STATUS_UNSUCCESSFUL;
- }
-
/* Get sam policy handle */
result = cli_samr_connect(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
goto done;
}
- got_connect_pol = True;
-
/* Get domain policy handle */
result = cli_samr_open_domain(cli, mem_ctx, &connect_pol,
goto done;
}
- got_domain_pol = True;
-
/* Query domain info */
result = cli_samr_query_dom_info(cli, mem_ctx, &domain_pol,
}
done:
- 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;
}
/* Create domain user */
-static NTSTATUS cmd_samr_create_dom_user(struct cli_state *cli, int argc,
- char **argv)
+static NTSTATUS cmd_samr_create_dom_user(struct cli_state *cli,
+ TALLOC_CTX *mem_ctx,
+ int argc, char **argv)
{
POLICY_HND connect_pol, domain_pol, user_pol;
NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
- BOOL got_connect_pol = False, got_domain_pol = False,
- got_user_pol = False;
- TALLOC_CTX *mem_ctx;
char *acct_name;
uint16 acb_info;
uint32 unknown, user_rid;
acct_name = argv[1];
- if (!(mem_ctx = talloc_init())) {
- DEBUG(0, ("cmd_samr_query_dispinfo: talloc_init returned "
- "NULL!\n"));
- return NT_STATUS_UNSUCCESSFUL;
- }
-
fetch_domain_sid(cli);
- /* Initialise RPC connection */
-
- if (!cli_nt_session_open (cli, PIPE_SAMR)) {
- fprintf (stderr, "Could not initialize samr pipe!\n");
- talloc_destroy(mem_ctx);
- return NT_STATUS_UNSUCCESSFUL;
- }
-
/* Get sam policy handle */
result = cli_samr_connect(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
goto done;
}
- got_connect_pol = True;
-
/* Get domain policy handle */
result = cli_samr_open_domain(cli, mem_ctx, &connect_pol,
goto done;
}
- got_domain_pol = True;
-
/* Create domain user */
acb_info = ACB_NORMAL;
goto done;
}
- got_user_pol = True;
-
done:
- 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;
}
/* Lookup sam names */
-static NTSTATUS cmd_samr_lookup_names(struct cli_state *cli, int argc,
- char **argv)
+static NTSTATUS cmd_samr_lookup_names(struct cli_state *cli,
+ TALLOC_CTX *mem_ctx,
+ int argc, char **argv)
{
- TALLOC_CTX *mem_ctx;
NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
POLICY_HND connect_pol, domain_pol;
- BOOL got_connect_pol = False, got_domain_pol = False;
- uint32 flags = 0x000003e8;
+ uint32 flags = 0x000003e8; /* Unknown */
uint32 num_rids, num_names, *name_types, *rids;
char **names;
int i;
return NT_STATUS_OK;
}
- if (!(mem_ctx = talloc_init())) {
- DEBUG(0, ("cmd_samr_lookup_names: talloc_init failed\n"));
- return result;
- }
-
fetch_domain_sid(cli);
- /* Initialise RPC connection */
-
- if (!cli_nt_session_open (cli, PIPE_SAMR)) {
- fprintf (stderr, "Could not initialize samr pipe!\n");
- talloc_destroy(mem_ctx);
- return NT_STATUS_UNSUCCESSFUL;
- }
-
/* Get sam policy and domain handles */
result = cli_samr_connect(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
&connect_pol);
+
if (!NT_STATUS_IS_OK(result)) {
goto done;
}
- got_connect_pol = True;
-
result = cli_samr_open_domain(cli, mem_ctx, &connect_pol,
MAXIMUM_ALLOWED_ACCESS,
&domain_sid, &domain_pol);
+
if (!NT_STATUS_IS_OK(result)) {
goto done;
}
- got_domain_pol = True;
-
/* Look up names */
num_names = argc - 1;
result = cli_samr_lookup_names(cli, mem_ctx, &domain_pol,
flags, num_names, names,
&num_rids, &rids, &name_types);
+
if (!NT_STATUS_IS_OK(result)) {
goto done;
}
name_types[i]);
done:
- 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;
}
/* Lookup sam rids */
-static NTSTATUS cmd_samr_lookup_rids(struct cli_state *cli, int argc,
- char **argv)
+static NTSTATUS cmd_samr_lookup_rids(struct cli_state *cli,
+ TALLOC_CTX *mem_ctx,
+ int argc, char **argv)
{
- TALLOC_CTX *mem_ctx;
NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
POLICY_HND connect_pol, domain_pol;
- BOOL got_connect_pol = False, got_domain_pol = False;
- uint32 flags = 0x000003e8;
+ uint32 flags = 0x000003e8; /* Unknown */
uint32 num_rids, num_names, *rids, *name_types;
char **names;
int i;
return NT_STATUS_OK;
}
- if (!(mem_ctx = talloc_init())) {
- DEBUG(0, ("cmd_samr_lookup_rids: talloc_init failed\n"));
- return result;
- }
-
fetch_domain_sid(cli);
- /* Initialise RPC connection */
-
- if (!cli_nt_session_open (cli, PIPE_SAMR)) {
- fprintf (stderr, "Could not initialize samr pipe!\n");
- talloc_destroy(mem_ctx);
- return NT_STATUS_UNSUCCESSFUL;
- }
-
/* Get sam policy and domain handles */
result = cli_samr_connect(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
&connect_pol);
+
if (!NT_STATUS_IS_OK(result)) {
goto done;
}
- got_connect_pol = True;
-
result = cli_samr_open_domain(cli, mem_ctx, &connect_pol,
MAXIMUM_ALLOWED_ACCESS,
&domain_sid, &domain_pol);
+
if (!NT_STATUS_IS_OK(result)) {
goto done;
}
- got_domain_pol = True;
-
/* Look up rids */
num_rids = argc - 1;
result = cli_samr_lookup_rids(cli, mem_ctx, &domain_pol,
flags, num_rids, rids,
&num_names, &names, &name_types);
+
if (!NT_STATUS_IS_OK(result)) {
goto done;
}
printf("rid %x: %s (%d)\n", rids[i], names[i], name_types[i]);
done:
- 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;
}
/* Delete domain user */
-static NTSTATUS cmd_samr_delete_dom_user(struct cli_state *cli, int argc,
- char **argv)
+static NTSTATUS cmd_samr_delete_dom_user(struct cli_state *cli,
+ TALLOC_CTX *mem_ctx,
+ int argc, char **argv)
{
- TALLOC_CTX *mem_ctx;
NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
POLICY_HND connect_pol, domain_pol, user_pol;
return NT_STATUS_OK;
}
- if (!(mem_ctx = talloc_init())) {
- DEBUG(0, ("cmd_samr_delete_dom_user: talloc_init failed\n"));
- return result;
- }
-
fetch_domain_sid(cli);
- /* Initialise RPC connection */
-
- if (!cli_nt_session_open (cli, PIPE_SAMR)) {
- DEBUG(0, ("cmd_samr_delete_dom_user: could not open samr pipe!\n"));
- talloc_destroy(mem_ctx);
- return NT_STATUS_UNSUCCESSFUL;
- }
-
/* Get sam policy and domain handles */
result = cli_samr_connect(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS,
&connect_pol);
+
if (!NT_STATUS_IS_OK(result)) {
goto done;
}
result = cli_samr_open_domain(cli, mem_ctx, &connect_pol,
MAXIMUM_ALLOWED_ACCESS,
&domain_sid, &domain_pol);
+
if (!NT_STATUS_IS_OK(result)) {
goto done;
}
{
uint32 *user_rids, num_rids, *name_types;
- uint32 flags = 0x000003e8;
+ uint32 flags = 0x000003e8; /* Unknown */
result = cli_samr_lookup_names(cli, mem_ctx, &domain_pol,
flags, 1, &argv[1],
&num_rids, &user_rids,
&name_types);
+
if (!NT_STATUS_IS_OK(result)) {
goto done;
}
result = cli_samr_open_user(cli, mem_ctx, &domain_pol,
MAXIMUM_ALLOWED_ACCESS,
user_rids[0], &user_pol);
+
if (!NT_STATUS_IS_OK(result)) {
goto done;
}
/* Delete user */
result = cli_samr_delete_dom_user(cli, mem_ctx, &user_pol);
+
if (!NT_STATUS_IS_OK(result)) {
goto done;
}
/* Display results */
done:
- cli_nt_session_close(cli);
- talloc_destroy(mem_ctx);
-
return result;
}
*/
#include "includes.h"
-
-extern pstring server;
-extern pstring global_myname;
-extern pstring username, password;
-extern pstring workgroup;
+#include "rpcclient.h"
struct table_node {
char *long_archi;
/**********************************************************************
* dummy function -- placeholder
*/
-static NTSTATUS cmd_spoolss_not_implemented (struct cli_state *cli,
- int argc, char **argv)
+static NTSTATUS cmd_spoolss_not_implemented(struct cli_state *cli,
+ TALLOC_CTX *mem_ctx,
+ int argc, char **argv)
{
printf ("(*) This command is not currently implemented.\n");
return NT_STATUS_OK;
/***********************************************************************
* Get printer information
*/
-static NTSTATUS cmd_spoolss_open_printer_ex(struct cli_state *cli, int argc, char **argv)
+static NTSTATUS cmd_spoolss_open_printer_ex(struct cli_state *cli,
+ TALLOC_CTX *mem_ctx,
+ int argc, char **argv)
{
NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
pstring printername;
fstring servername, user;
POLICY_HND hnd;
- TALLOC_CTX *mem_ctx;
if (argc != 2) {
printf("Usage: %s <printername>\n", argv[0]);
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 (servername, sizeof(fstring)-1, "\\\\%s", cli->desthost);
strupper (servername);
fstrcpy (user, cli->user_name);
fstrcpy (printername, argv[1]);
-
- /* Initialise RPC connection */
- if (!cli_nt_session_open (cli, PIPE_SPOOLSS)) {
- fprintf (stderr, "Could not initialize spoolss pipe!\n");
- talloc_destroy(mem_ctx);
- return NT_STATUS_UNSUCCESSFUL;
- }
-
/* Open the printer handle */
result = cli_spoolss_open_printer_ex (cli, mem_ctx, printername, "",
MAXIMUM_ALLOWED_ACCESS, servername, user, &hnd);
}
}
- cli_nt_session_close(cli);
- talloc_destroy(mem_ctx);
-
return result;
}
/* Enumerate printers */
-static NTSTATUS cmd_spoolss_enum_printers(struct cli_state *cli, int argc, char **argv)
+static NTSTATUS cmd_spoolss_enum_printers(struct cli_state *cli,
+ TALLOC_CTX *mem_ctx,
+ int argc, char **argv)
{
NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
uint32 info_level = 1;
PRINTER_INFO_CTR ctr;
int returned;
uint32 i = 0;
- TALLOC_CTX *mem_ctx;
if (argc > 2)
{
return NT_STATUS_OK;
}
- 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]);
}
- /* Initialise RPC connection */
- if (!cli_nt_session_open (cli, PIPE_SPOOLSS)) {
- fprintf (stderr, "Could not initialize spoolss pipe!\n");
- talloc_destroy(mem_ctx);
- return NT_STATUS_UNSUCCESSFUL;
- }
-
/* Enumerate printers -- Should we enumerate types other
than PRINTER_ENUM_LOCAL? Maybe accept as a parameter? --jerry */
ZERO_STRUCT(ctr);
}
}
- cli_nt_session_close(cli);
- talloc_destroy(mem_ctx);
-
return result;
}
/* Enumerate ports */
-static NTSTATUS cmd_spoolss_enum_ports(struct cli_state *cli, int argc, char **argv)
+static NTSTATUS cmd_spoolss_enum_ports(struct cli_state *cli,
+ TALLOC_CTX *mem_ctx,
+ int argc, char **argv)
{
NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
uint32 info_level = 1;
PORT_INFO_CTR ctr;
int returned;
- TALLOC_CTX *mem_ctx;
if (argc > 2) {
printf("Usage: %s [level]\n", argv[0]);
return NT_STATUS_OK;
}
- 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]);
}
- /* Initialise RPC connection */
- if (!cli_nt_session_open (cli, PIPE_SPOOLSS)) {
- fprintf (stderr, "Could not initialize spoolss pipe!\n");
- talloc_destroy(mem_ctx);
- return NT_STATUS_UNSUCCESSFUL;
- }
-
/* Enumerate ports */
ZERO_STRUCT(ctr);
}
}
- cli_nt_session_close(cli);
- talloc_destroy(mem_ctx);
-
return result;
}
/***********************************************************************
* Get printer information
*/
-static NTSTATUS cmd_spoolss_getprinter(struct cli_state *cli, int argc, char **argv)
+static NTSTATUS cmd_spoolss_getprinter(struct cli_state *cli,
+ TALLOC_CTX *mem_ctx,
+ int argc, char **argv)
{
POLICY_HND pol;
NTSTATUS result;
fstring printername,
servername,
user;
- TALLOC_CTX *mem_ctx;
if (argc == 1 || argc > 3) {
printf("Usage: %s <printername> [level]\n", argv[0]);
return NT_STATUS_OK;
}
- 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");
- talloc_destroy(mem_ctx);
- return NT_STATUS_UNSUCCESSFUL;
- }
-
/* Open a printer handle */
if (argc == 3) {
info_level = atoi(argv[2]);
if (opened_hnd)
cli_spoolss_close_printer(cli, mem_ctx, &pol);
- cli_nt_session_close(cli);
- talloc_destroy(mem_ctx);
-
return result;
}
/***********************************************************************
* Get printer information
*/
-static NTSTATUS cmd_spoolss_getdriver(struct cli_state *cli, int argc, char **argv)
+static NTSTATUS cmd_spoolss_getdriver(struct cli_state *cli,
+ TALLOC_CTX *mem_ctx,
+ int argc, char **argv)
{
POLICY_HND pol;
NTSTATUS result;
servername,
user;
uint32 i;
- TALLOC_CTX *mem_ctx;
if ((argc == 1) || (argc > 3))
{
return NT_STATUS_OK;
}
- 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))
- {
- fprintf (stderr, "Could not initialize spoolss pipe!\n");
- talloc_destroy(mem_ctx);
- return NT_STATUS_UNSUCCESSFUL;
- }
-
/* get the arguments need to open the printer handle */
slprintf (servername, sizeof(fstring)-1, "\\\\%s", cli->desthost);
strupper (servername);
}
}
-
/* cleanup */
if (opened_hnd)
cli_spoolss_close_printer (cli, mem_ctx, &pol);
- cli_nt_session_close (cli);
- talloc_destroy(mem_ctx);
return result;
/***********************************************************************
* Get printer information
*/
-static NTSTATUS cmd_spoolss_enum_drivers(struct cli_state *cli, int argc, char **argv)
+static NTSTATUS cmd_spoolss_enum_drivers(struct cli_state *cli,
+ TALLOC_CTX *mem_ctx,
+ int argc, char **argv)
{
NTSTATUS result = NT_STATUS_OK;
uint32 info_level = 1;
fstring servername;
uint32 i, j,
returned;
- TALLOC_CTX *mem_ctx;
if (argc > 2)
{
return NT_STATUS_OK;
}
- if (!(mem_ctx=talloc_init()))
- {
- DEBUG(0,("cmd_spoolss_enum_drivers: talloc_init returned NULL!\n"));
- return NT_STATUS_NO_MEMORY;
- }
-
- /* Initialise RPC connection */
- if (!cli_nt_session_open (cli, PIPE_SPOOLSS))
- {
- fprintf (stderr, "Could not initialize spoolss pipe!\n");
- talloc_destroy(mem_ctx);
- return NT_STATUS_UNSUCCESSFUL;
- }
-
/* get the arguments need to open the printer handle */
slprintf (servername, sizeof(fstring)-1, "\\\\%s", cli->desthost);
strupper (servername);
}
}
-
- /* cleanup */
- cli_nt_session_close (cli);
- talloc_destroy(mem_ctx);
-
return result;
}
/***********************************************************************
* Get printer driver directory information
*/
-static NTSTATUS cmd_spoolss_getdriverdir(struct cli_state *cli, int argc, char **argv)
+static NTSTATUS cmd_spoolss_getdriverdir(struct cli_state *cli,
+ TALLOC_CTX *mem_ctx,
+ int argc, char **argv)
{
NTSTATUS result;
fstring env;
DRIVER_DIRECTORY_CTR ctr;
- TALLOC_CTX *mem_ctx;
if (argc > 2)
{
return NT_STATUS_OK;
}
- /* Initialise RPC connection */
- if (!cli_nt_session_open (cli, PIPE_SPOOLSS))
- {
- 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)
fstrcpy (env, argv[1]);
display_printdriverdir_1 (ctr.info1);
- /* cleanup */
- cli_nt_session_close (cli);
- talloc_destroy(mem_ctx);
-
return result;
-
}
/*******************************************************************************
}
-static NTSTATUS cmd_spoolss_addprinterdriver (struct cli_state *cli, int argc, char **argv)
+static NTSTATUS cmd_spoolss_addprinterdriver(struct cli_state *cli,
+ TALLOC_CTX *mem_ctx,
+ int argc, char **argv)
{
NTSTATUS result;
uint32 level = 3;
DRIVER_INFO_3 info3;
fstring arch;
fstring driver_name;
- TALLOC_CTX *mem_ctx = NULL;
/* parse the command arguements */
if (argc != 3)
return NT_STATUS_OK;
}
-
- if (!(mem_ctx=talloc_init()))
- {
- DEBUG(0,("cmd_spoolss_addprinterdriver: talloc_init returned NULL!\n"));
- return NT_STATUS_NO_MEMORY;
- }
-
- /* Initialise RPC connection */
- if (!cli_nt_session_open (cli, PIPE_SPOOLSS))
- {
- fprintf (stderr, "Could not initialize spoolss pipe!\n");
- talloc_destroy(mem_ctx);
- return NT_STATUS_UNSUCCESSFUL;
- }
-
/* Fill in the DRIVER_INFO_3 struct */
ZERO_STRUCT(info3);
rpcstr_pull(driver_name, info3.name.buffer, sizeof(driver_name), 0, STR_TERMINATE);
printf ("Printer Driver %s successfully installed.\n", driver_name);
- /* cleanup */
- cli_nt_session_close (cli);
- talloc_destroy(mem_ctx);
-
return result;
-
}
-static NTSTATUS cmd_spoolss_addprinterex (struct cli_state *cli, int argc, char **argv)
+static NTSTATUS cmd_spoolss_addprinterex(struct cli_state *cli,
+ TALLOC_CTX *mem_ctx,
+ int argc, char **argv)
{
NTSTATUS result;
uint32 level = 2;
PRINTER_INFO_CTR ctr;
PRINTER_INFO_2 info2;
fstring servername;
- TALLOC_CTX *mem_ctx = NULL;
/* parse the command arguements */
if (argc != 5)
return NT_STATUS_OK;
}
- if (!(mem_ctx=talloc_init()))
- {
- DEBUG(0,("cmd_spoolss_addprinterex: talloc_init returned NULL!\n"));
- return NT_STATUS_NO_MEMORY;
- }
-
-
slprintf (servername, sizeof(fstring)-1, "\\\\%s", cli->desthost);
strupper (servername);
- /* Initialise RPC connection */
- if (!cli_nt_session_open (cli, PIPE_SPOOLSS))
- {
- fprintf (stderr, "Could not initialize spoolss pipe!\n");
- talloc_destroy(mem_ctx);
- return NT_STATUS_UNSUCCESSFUL;
- }
-
-
/* Fill in the DRIVER_INFO_3 struct */
ZERO_STRUCT(info2);
#if 0 /* JERRY */
ctr.printers_2 = &info2;
result = cli_spoolss_addprinterex (cli, mem_ctx, level, &ctr);
if (!NT_STATUS_IS_OK(result)) {
- cli_nt_session_close (cli);
return result;
}
printf ("Printer %s successfully installed.\n", argv[1]);
- /* cleanup */
- cli_nt_session_close (cli);
- talloc_destroy(mem_ctx);
-
return result;
-
}
-static NTSTATUS cmd_spoolss_setdriver (struct cli_state *cli, int argc, char **argv)
+static NTSTATUS cmd_spoolss_setdriver(struct cli_state *cli,
+ TALLOC_CTX *mem_ctx,
+ int argc, char **argv)
{
POLICY_HND pol;
NTSTATUS result;
fstring servername,
printername,
user;
- TALLOC_CTX *mem_ctx = NULL;
/* parse the command arguements */
if (argc != 3)
return NT_STATUS_OK;
}
- if (!(mem_ctx=talloc_init()))
- {
- DEBUG(0,("cmd_spoolss_setdriver: talloc_init returned NULL!\n"));
- return NT_STATUS_NO_MEMORY;
- }
-
slprintf (servername, sizeof(fstring)-1, "\\\\%s", cli->desthost);
strupper (servername);
slprintf (printername, sizeof(fstring)-1, "%s\\%s", servername, argv[1]);
fstrcpy (user, cli->user_name);
- /* Initialise RPC connection */
- if (!cli_nt_session_open (cli, PIPE_SPOOLSS))
- {
- fprintf (stderr, "Could not initialize spoolss pipe!\n");
- talloc_destroy(mem_ctx);
- return NT_STATUS_UNSUCCESSFUL;
- }
-
-
/* get a printer handle */
result = cli_spoolss_open_printer_ex(cli, mem_ctx, printername, "",
MAXIMUM_ALLOWED_ACCESS, servername, user, &pol);
/* cleanup */
if (opened_hnd)
cli_spoolss_close_printer(cli, mem_ctx, &pol);
- cli_nt_session_close (cli);
- talloc_destroy(mem_ctx);
return result;
}
-static NTSTATUS cmd_spoolss_deletedriver (struct cli_state *cli, int argc, char **argv)
+static NTSTATUS cmd_spoolss_deletedriver(struct cli_state *cli,
+ TALLOC_CTX *mem_ctx,
+ int argc, char **argv)
{
NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
fstring servername;
- TALLOC_CTX *mem_ctx = NULL;
int i;
/* parse the command arguements */
return NT_STATUS_OK;
}
- if (!(mem_ctx=talloc_init()))
- {
- DEBUG(0,("cmd_spoolss_deletedriver: talloc_init returned NULL!\n"));
- return NT_STATUS_UNSUCCESSFUL;
- }
-
slprintf (servername, sizeof(fstring)-1, "\\\\%s", cli->desthost);
strupper (servername);
- /* Initialise RPC connection */
- if (!cli_nt_session_open (cli, PIPE_SPOOLSS))
- {
- fprintf (stderr, "Could not initialize spoolss pipe!\n");
- talloc_destroy(mem_ctx);
- return NT_STATUS_UNSUCCESSFUL;
- }
-
/* delete the driver for all architectures */
for (i=0; archi_table[i].long_archi; i++)
{
printf ("Driver %s removed for arch [%s].\n", argv[1], archi_table[i].long_archi);
}
-
- /* cleanup */
- cli_nt_session_close (cli);
- talloc_destroy(mem_ctx);
-
return NT_STATUS_OK;
}
{ "SPOOLSS" },
- { "adddriver", cmd_spoolss_addprinterdriver, "Add a print driver", "" },
- { "addprinter", cmd_spoolss_addprinterex, "Add a printer", "" },
- { "deldriver", cmd_spoolss_deletedriver, "Delete a printer driver", "" },
- { "enumdata", cmd_spoolss_not_implemented, "Enumerate printer data (*)", "" },
- { "enumjobs", cmd_spoolss_not_implemented, "Enumerate print jobs (*)", "" },
- { "enumports", cmd_spoolss_enum_ports, "Enumerate printer ports", "" },
- { "enumdrivers", cmd_spoolss_enum_drivers, "Enumerate installed printer drivers", "" },
- { "enumprinters", cmd_spoolss_enum_printers, "Enumerate printers", "" },
- { "getdata", cmd_spoolss_not_implemented, "Get print driver data (*)", "" },
- { "getdriver", cmd_spoolss_getdriver, "Get print driver information", "" },
- { "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", "" },
+ { "adddriver", cmd_spoolss_addprinterdriver, PIPE_SPOOLSS, "Add a print driver", "" },
+ { "addprinter", cmd_spoolss_addprinterex, PIPE_SPOOLSS, "Add a printer", "" },
+ { "deldriver", cmd_spoolss_deletedriver, PIPE_SPOOLSS, "Delete a printer driver", "" },
+ { "enumdata", cmd_spoolss_not_implemented, PIPE_SPOOLSS, "Enumerate printer data (*)", "" },
+ { "enumjobs", cmd_spoolss_not_implemented, PIPE_SPOOLSS, "Enumerate print jobs (*)", "" },
+ { "enumports", cmd_spoolss_enum_ports, PIPE_SPOOLSS, "Enumerate printer ports", "" },
+ { "enumdrivers", cmd_spoolss_enum_drivers, PIPE_SPOOLSS, "Enumerate installed printer drivers", "" },
+ { "enumprinters", cmd_spoolss_enum_printers, PIPE_SPOOLSS, "Enumerate printers", "" },
+ { "getdata", cmd_spoolss_not_implemented, PIPE_SPOOLSS, "Get print driver data (*)", "" },
+ { "getdriver", cmd_spoolss_getdriver, PIPE_SPOOLSS, "Get print driver information", "" },
+ { "getdriverdir", cmd_spoolss_getdriverdir, PIPE_SPOOLSS, "Get print driver upload directory", "" },
+ { "getprinter", cmd_spoolss_getprinter, PIPE_SPOOLSS, "Get printer info", "" },
+ { "openprinter", cmd_spoolss_open_printer_ex, PIPE_SPOOLSS, "Open printer handle", "" },
+ { "setdriver", cmd_spoolss_setdriver, PIPE_SPOOLSS, "Set printer driver", "" },
{ NULL }
};
*/
#include "includes.h"
+#include "rpcclient.h"
/* Display server query info */
/* Server query info */
-static NTSTATUS cmd_srvsvc_srv_query_info(struct cli_state *cli, int argc,
- char **argv)
+static NTSTATUS cmd_srvsvc_srv_query_info(struct cli_state *cli,
+ TALLOC_CTX *mem_ctx,
+ int argc, char **argv)
{
uint32 info_level = 101;
SRV_INFO_CTR ctr;
- TALLOC_CTX *mem_ctx;
NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
if (argc > 2) {
if (argc == 2)
info_level = atoi(argv[1]);
- if (!(mem_ctx = talloc_init())) {
- DEBUG(0,("cmd_srvsvc_srv_query_info: talloc_init failed\n"));
- return result;
- }
-
- /* Initialise RPC connection */
-
- if (!cli_nt_session_open (cli, PIPE_SRVSVC)) {
- DEBUG(0, ("Could not initialize srvsvc pipe!\n"));
- goto done;
- }
-
result = cli_srvsvc_net_srv_get_info(cli, mem_ctx, info_level,
&ctr);
+
if (!NT_STATUS_IS_OK(result)) {
goto done;
}
}
done:
- talloc_destroy(mem_ctx);
-
return result;
}
{ "SRVSVC" },
- { "srvinfo", cmd_srvsvc_srv_query_info, "Server query info", "" },
+ { "srvinfo", cmd_srvsvc_srv_query_info, PIPE_SRVSVC, "Server query info", "" },
{ NULL }
};
*/
#include "includes.h"
+#include "rpcclient.h"
extern pstring debugf;
/* Display help on commands */
-static NTSTATUS cmd_help(struct cli_state *cli, int argc, char **argv)
+static NTSTATUS cmd_help(struct cli_state *cli, TALLOC_CTX *mem_ctx,
+ int argc, char **argv)
{
struct cmd_list *tmp;
struct cmd_set *tmp_set;
/* Change the debug level */
-static NTSTATUS cmd_debuglevel(struct cli_state *cli, int argc, char **argv)
+static NTSTATUS cmd_debuglevel(struct cli_state *cli, TALLOC_CTX *mem_ctx,
+ int argc, char **argv)
{
if (argc > 2) {
printf("Usage: %s [debuglevel]\n", argv[0]);
return NT_STATUS_OK;
}
-static NTSTATUS cmd_quit(struct cli_state *cli, int argc, char **argv)
+static NTSTATUS cmd_quit(struct cli_state *cli, TALLOC_CTX *mem_ctx,
+ int argc, char **argv)
{
exit(0);
return NT_STATUS_OK; /* NOTREACHED */
NULL
};
-void add_command_set(struct cmd_set *cmd_set)
+static void add_command_set(struct cmd_set *cmd_set)
{
struct cmd_list *entry;
DLIST_ADD(cmd_list, entry);
}
-static NTSTATUS do_cmd(struct cli_state *cli, struct cmd_set *cmd_entry, char *cmd)
+static NTSTATUS do_cmd(struct cli_state *cli, struct cmd_set *cmd_entry,
+ char *cmd)
{
char *p = cmd, **argv = NULL;
- NTSTATUS result;
+ NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
pstring buf;
int argc = 0, i;
/* Create argument list */
argv = (char **)malloc(sizeof(char *) * argc);
+ memset(argv, 0, sizeof(char *) * argc);
if (!argv) {
fprintf(stderr, "out of memory\n");
- return NT_STATUS_NO_MEMORY;
+ result = NT_STATUS_NO_MEMORY;
+ goto done;
}
p = cmd;
}
/* Call the function */
+
if (cmd_entry->fn) {
- result = cmd_entry->fn(cli, argc, argv);
- }
- else {
+ TALLOC_CTX *mem_ctx;
+
+ /* Create mem_ctx */
+
+ if (!(mem_ctx = talloc_init())) {
+ DEBUG(0, ("talloc_init() failed\n"));
+ goto done;
+ }
+
+ /* Open pipe */
+
+ if (cmd_entry->pipe)
+ if (!cli_nt_session_open(cli, cmd_entry->pipe)) {
+ DEBUG(0, ("Could not initialise %s\n",
+ cmd_entry->pipe));
+ goto done;
+ }
+
+ /* Run command */
+
+ result = cmd_entry->fn(cli, mem_ctx, argc, argv);
+
+ /* Cleanup */
+
+ if (cmd_entry->pipe)
+ cli_nt_session_close(cli);
+
+ talloc_destroy(mem_ctx);
+
+ } else {
fprintf (stderr, "Invalid command\n");
- result = NT_STATUS_INVALID_PARAMETER;
- }
+ goto done;
+ }
+ done:
/* Cleanup */
- for (i = 0; i < argc; i++) {
- SAFE_FREE(argv[i]);
- }
+
+ if (argv) {
+ for (i = 0; i < argc; i++)
+ SAFE_FREE(argv[i]);
- SAFE_FREE(argv);
+ SAFE_FREE(argv);
+ }
return result;
}
while(temp_set->name) {
if (strequal(buf, temp_set->name)) {
- found = True;
+ found = True;
result = do_cmd(cli, temp_set, cmd);
+
goto done;
}
temp_set++;