summaryrefslogtreecommitdiff
path: root/source3/rpcclient
diff options
context:
space:
mode:
Diffstat (limited to 'source3/rpcclient')
-rw-r--r--source3/rpcclient/cmd_ds.c2
-rw-r--r--source3/rpcclient/cmd_lsarpc.c56
-rw-r--r--source3/rpcclient/cmd_spoolss.c9
-rw-r--r--source3/rpcclient/cmd_srvsvc.c7
-rw-r--r--source3/rpcclient/rpcclient.c185
5 files changed, 115 insertions, 144 deletions
diff --git a/source3/rpcclient/cmd_ds.c b/source3/rpcclient/cmd_ds.c
index 946015c1e3..9a2114e07e 100644
--- a/source3/rpcclient/cmd_ds.c
+++ b/source3/rpcclient/cmd_ds.c
@@ -38,7 +38,7 @@ static NTSTATUS cmd_ds_dsrole_getprimarydominfo(struct cli_state *cli,
if ( ctr.basic->flags & DSROLE_PRIMARY_DS_RUNNING ) {
printf( "Directory Service is running.\n");
- printf( "Domain is in %s mode.\n", (ctr.basic->flags & DSROLE_PRIMARY_DS_MIXED_MODE) ? "mixed" : "native" );
+ printf( "Domain is in %s mode.\n", (ctr.basic->flags & DSROLE_PRIMARY_DS_MIXED_MODE) ? "mized" : "native" );
}
else
printf( "Directory Service not running on server\n");
diff --git a/source3/rpcclient/cmd_lsarpc.c b/source3/rpcclient/cmd_lsarpc.c
index 03df170c09..8afeb8e83b 100644
--- a/source3/rpcclient/cmd_lsarpc.c
+++ b/source3/rpcclient/cmd_lsarpc.c
@@ -210,11 +210,8 @@ static NTSTATUS cmd_lsa_lookup_sids(struct cli_state *cli, TALLOC_CTX *mem_ctx,
goto done;
}
- for (i = 0; i < argc - 1; i++)
- if (!string_to_sid(&sids[i], argv[i + 1])) {
- result = NT_STATUS_INVALID_SID;
- goto done;
- }
+ for (i = 0; i < argc - 1; i++)
+ string_to_sid(&sids[i], argv[i + 1]);
/* Lookup the SIDs */
@@ -300,7 +297,7 @@ static NTSTATUS cmd_lsa_enum_trust_dom(struct cli_state *cli,
/* Enumerates privileges */
static NTSTATUS cmd_lsa_enum_privilege(struct cli_state *cli,
- TALLOC_CTX *mem_ctx, int argc,
+ TALLOC_CTX *mem_ctx, int argc,
char **argv)
{
POLICY_HND pol;
@@ -391,7 +388,7 @@ static NTSTATUS cmd_lsa_get_dispname(struct cli_state *cli,
/* Enumerate the LSA SIDS */
static NTSTATUS cmd_lsa_enum_sids(struct cli_state *cli,
- TALLOC_CTX *mem_ctx, int argc,
+ TALLOC_CTX *mem_ctx, int argc,
char **argv)
{
POLICY_HND pol;
@@ -543,50 +540,6 @@ static NTSTATUS cmd_lsa_enum_acct_rights(struct cli_state *cli,
}
-/* Enumerate the accounts with a specific right */
-
-static NTSTATUS cmd_lsa_enum_acct_with_right(struct cli_state *cli,
- TALLOC_CTX *mem_ctx, int argc,
- const char **argv)
-{
- POLICY_HND dom_pol;
- NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
- DOM_SID *sids;
- uint32 count;
- const char *right;
-
- int i;
-
- if (argc != 2 ) {
- printf("Usage: %s <RIGHT>\n", argv[0]);
- return NT_STATUS_OK;
- }
-
- right = argv[1];
-
- result = cli_lsa_open_policy2(cli, mem_ctx, True,
- SEC_RIGHTS_MAXIMUM_ALLOWED,
- &dom_pol);
-
- if (!NT_STATUS_IS_OK(result))
- goto done;
-
- result = cli_lsa_enum_account_with_right(cli, mem_ctx, &dom_pol, right, &count, &sids);
-
- if (!NT_STATUS_IS_OK(result))
- goto done;
-
- printf("found %d SIDs for '%s'\n", count, right);
-
- for (i = 0; i < count; i++) {
- printf("\t%s\n", sid_string_static(&sids[i]));
- }
-
- done:
- return result;
-}
-
-
/* add some privileges to a SID via LsaAddAccountRights */
static NTSTATUS cmd_lsa_add_acct_rights(struct cli_state *cli,
@@ -750,7 +703,6 @@ struct cmd_set lsarpc_commands[] = {
{ "lsaenumsid", cmd_lsa_enum_sids, PI_LSARPC, "Enumerate the LSA SIDS", "" },
{ "lsaenumprivsaccount", cmd_lsa_enum_privsaccounts, PI_LSARPC, "Enumerate the privileges of an SID", "" },
{ "lsaenumacctrights", cmd_lsa_enum_acct_rights, PI_LSARPC, "Enumerate the rights of an SID", "" },
- { "lsaenumacctwithright",cmd_lsa_enum_acct_with_right,PI_LSARPC,"Enumerate accounts with a right", "" },
{ "lsaaddacctrights", cmd_lsa_add_acct_rights, PI_LSARPC, "Add rights to an account", "" },
{ "lsaremoveacctrights", cmd_lsa_remove_acct_rights, PI_LSARPC, "Remove rights from an account", "" },
{ "lsalookupprivvalue", cmd_lsa_lookupprivvalue, PI_LSARPC, "Get a privilege value given its name", "" },
diff --git a/source3/rpcclient/cmd_spoolss.c b/source3/rpcclient/cmd_spoolss.c
index 66f2e8dc99..0ec94c9979 100644
--- a/source3/rpcclient/cmd_spoolss.c
+++ b/source3/rpcclient/cmd_spoolss.c
@@ -41,15 +41,6 @@ static const struct table_node archi_table[]= {
{NULL, "", -1 }
};
-/**
- * @file
- *
- * rpcclient module for SPOOLSS rpc pipe.
- *
- * This generally just parses and checks command lines, and then calls
- * a cli_spoolss function.
- **/
-
/****************************************************************************
function to do the mapping between the long architecture name and
the short one.
diff --git a/source3/rpcclient/cmd_srvsvc.c b/source3/rpcclient/cmd_srvsvc.c
index 10fdfd7437..282cbb3b99 100644
--- a/source3/rpcclient/cmd_srvsvc.c
+++ b/source3/rpcclient/cmd_srvsvc.c
@@ -179,13 +179,14 @@ static void display_srv_info_102(SRV_INFO_102 *sv102)
}
/* Server query info */
+
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;
- WERROR result;
+ NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
if (argc > 2) {
printf("Usage: %s [infolevel]\n", argv[0]);
@@ -198,7 +199,7 @@ static NTSTATUS cmd_srvsvc_srv_query_info(struct cli_state *cli,
result = cli_srvsvc_net_srv_get_info(cli, mem_ctx, info_level,
&ctr);
- if (!W_ERROR_IS_OK(result)) {
+ if (!NT_STATUS_IS_OK(result)) {
goto done;
}
@@ -217,7 +218,7 @@ static NTSTATUS cmd_srvsvc_srv_query_info(struct cli_state *cli,
}
done:
- return W_ERROR_IS_OK(result) ? NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL;
+ return result;
}
static void display_share_info_1(SRV_SHARE_INFO_1 *info1)
diff --git a/source3/rpcclient/rpcclient.c b/source3/rpcclient/rpcclient.c
index 81bb62486a..2609519dc4 100644
--- a/source3/rpcclient/rpcclient.c
+++ b/source3/rpcclient/rpcclient.c
@@ -3,7 +3,6 @@
RPC pipe client
Copyright (C) Tim Potter 2000-2001
- Copyright (C) Martin Pool 2003
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -25,12 +24,7 @@
DOM_SID domain_sid;
-
-/* List to hold groups of commands.
- *
- * Commands are defined in a list of arrays: arrays are easy to
- * statically declare, and lists are easier to dynamically extend.
- */
+/* List to hold groups of commands */
static struct cmd_list {
struct cmd_list *prev, *next;
@@ -170,28 +164,21 @@ static char* next_command (char** cmdstr)
if (p)
*p = '\0';
pstrcpy(command, *cmdstr);
- *cmdstr = p + 1;
+ *cmdstr = p;
return command;
}
-
-/**
- * Find default username from environment variables.
- *
- * @param username fstring to receive username; not touched if none is
- * known.
- **/
static void get_username (char *username)
{
if (getenv("USER"))
- fstrcpy(username,getenv("USER"));
+ pstrcpy(username,getenv("USER"));
if (*username == 0 && getenv("LOGNAME"))
- fstrcpy(username,getenv("LOGNAME"));
+ pstrcpy(username,getenv("LOGNAME"));
if (*username == 0) {
- fstrcpy(username,"GUEST");
+ pstrcpy(username,"GUEST");
}
return;
@@ -384,7 +371,7 @@ static NTSTATUS cmd_quit(struct cli_state *cli, TALLOC_CTX *mem_ctx,
return NT_STATUS_OK; /* NOTREACHED */
}
-/* Built in rpcclient commands */
+/* Build in rpcclient commands */
static struct cmd_set rpcclient_commands[] = {
@@ -445,105 +432,145 @@ static void add_command_set(struct cmd_set *cmd_set)
DLIST_ADD(cmd_list, entry);
}
-
-/**
- * Call an rpcclient function, passing an argv array.
- *
- * @param cmd Command to run, as a single string.
- **/
-static NTSTATUS do_cmd(struct cli_state *cli,
- struct cmd_set *cmd_entry,
- int argc, char **argv)
+static NTSTATUS do_cmd(struct cli_state *cli, struct cmd_set *cmd_entry,
+ char *cmd)
{
- NTSTATUS result;
-
- TALLOC_CTX *mem_ctx;
+ char **argv = NULL;
+ const char *p = cmd;
+ NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
+ pstring buf;
+ int argc = 0, i;
+
+ /* Count number of arguments first time through the loop then
+ allocate memory and strdup them. */
+
+ again:
+ while(next_token(&p, buf, " ", sizeof(buf))) {
+ if (argv) {
+ argv[argc] = strdup(buf);
+ }
+
+ argc++;
+ }
+
+ if (!argv) {
- /* Create mem_ctx */
+ /* Create argument list */
- if (!(mem_ctx = talloc_init("do_cmd"))) {
- DEBUG(0, ("talloc_init() failed\n"));
- return NT_STATUS_UNSUCCESSFUL;
+ argv = (char **)malloc(sizeof(char *) * argc);
+ memset(argv, 0, sizeof(char *) * argc);
+
+ if (!argv) {
+ fprintf(stderr, "out of memory\n");
+ result = NT_STATUS_NO_MEMORY;
+ goto done;
+ }
+
+ p = cmd;
+ argc = 0;
+
+ goto again;
}
- /* Open pipe */
+ /* Call the function */
- if (cmd_entry->pipe_idx != -1)
- if (!cli_nt_session_open(cli, cmd_entry->pipe_idx)) {
- DEBUG(0, ("Could not initialize pipe\n"));
- return NT_STATUS_UNSUCCESSFUL;
- }
+ if (cmd_entry->fn) {
+ TALLOC_CTX *mem_ctx;
- /* Run command */
+ /* Create mem_ctx */
- result = cmd_entry->fn(cli, mem_ctx, argc, (char **) argv);
+ if (!(mem_ctx = talloc_init("do_cmd"))) {
+ DEBUG(0, ("talloc_init() failed\n"));
+ goto done;
+ }
- /* Cleanup */
+ /* Open pipe */
- if (cmd_entry->pipe_idx != -1)
- cli_nt_session_close(cli);
+ if (cmd_entry->pipe_idx != -1)
+ if (!cli_nt_session_open(cli, cmd_entry->pipe_idx)) {
+ DEBUG(0, ("Could not initialise pipe\n"));
+ goto done;
+ }
- talloc_destroy(mem_ctx);
+ /* Run command */
+
+ result = cmd_entry->fn(cli, mem_ctx, argc, argv);
+ /* Cleanup */
+
+ if (cmd_entry->pipe_idx != -1)
+ cli_nt_session_close(cli);
+
+ talloc_destroy(mem_ctx);
+
+ } else {
+ fprintf (stderr, "Invalid command\n");
+ goto done;
+ }
+
+ done:
+
+ /* Cleanup */
+
+ if (argv) {
+ for (i = 0; i < argc; i++)
+ SAFE_FREE(argv[i]);
+
+ SAFE_FREE(argv);
+ }
+
return result;
}
+/* Process a command entered at the prompt or as part of -c */
-/**
- * Process a command entered at the prompt or as part of -c
- *
- * @returns The NTSTATUS from running the command.
- **/
static NTSTATUS process_cmd(struct cli_state *cli, char *cmd)
{
struct cmd_list *temp_list;
+ BOOL found = False;
+ pstring buf;
+ const char *p = cmd;
NTSTATUS result = NT_STATUS_OK;
- int ret;
- int argc;
- char **argv = NULL;
+ int len = 0;
+
+ if (cmd[strlen(cmd) - 1] == '\n')
+ cmd[strlen(cmd) - 1] = '\0';
- if ((ret = poptParseArgvString(cmd, &argc, (const char ***) &argv)) != 0) {
- fprintf(stderr, "rpcclient: %s\n", poptStrerror(ret));
- return NT_STATUS_UNSUCCESSFUL;
+ if (!next_token(&p, buf, " ", sizeof(buf))) {
+ return NT_STATUS_OK;
}
+ /* strip the trainly \n if it exsists */
+ len = strlen(buf);
+ if (buf[len-1] == '\n')
+ buf[len-1] = '\0';
+
+ /* Search for matching commands */
- /* Walk through a dlist of arrays of commands. */
for (temp_list = cmd_list; temp_list; temp_list = temp_list->next) {
struct cmd_set *temp_set = temp_list->cmd_set;
- while (temp_set->name) {
- if (strequal(argv[0], temp_set->name)) {
- if (!temp_set->fn) {
- fprintf (stderr, "Invalid command\n");
- goto out_free;
- }
+ while(temp_set->name) {
+ if (strequal(buf, temp_set->name)) {
+ found = True;
+ result = do_cmd(cli, temp_set, cmd);
- result = do_cmd(cli, temp_set, argc, argv);
-
- goto out_free;
+ goto done;
}
temp_set++;
}
}
- if (argv[0]) {
- printf("command not found: %s\n", argv[0]);
+ done:
+ if (!found && buf[0]) {
+ printf("command not found: %s\n", buf);
+ return NT_STATUS_OK;
}
-out_free:
if (!NT_STATUS_IS_OK(result)) {
printf("result was %s\n", nt_errstr(result));
}
- if (argv) {
- /* NOTE: popt allocates the whole argv, including the
- * strings, as a single block. So a single free is
- * enough to release it -- we don't free the
- * individual strings. rtfm. */
- free(argv);
- }
-
return result;
}