summaryrefslogtreecommitdiff
path: root/source3/rpcclient/rpcclient.c
diff options
context:
space:
mode:
authorTim Potter <tpot@samba.org>2001-10-12 05:56:23 +0000
committerTim Potter <tpot@samba.org>2001-10-12 05:56:23 +0000
commit439c7e0ca2ceb866cac4f0fbed65e157aa12482d (patch)
tree485198a7c227c05736986cdcaf82e42ec016e296 /source3/rpcclient/rpcclient.c
parentd726eb216ad431d2bbd4ee07f4098b72446cdca2 (diff)
downloadsamba-439c7e0ca2ceb866cac4f0fbed65e157aa12482d.tar.gz
samba-439c7e0ca2ceb866cac4f0fbed65e157aa12482d.tar.bz2
samba-439c7e0ca2ceb866cac4f0fbed65e157aa12482d.zip
Some old stuff hanging around since the CIFS conference. Big cleanup of
rpcclient code. Refactored cmd_* functions to move common mem_ctx and pipe opening stuff up one level. Moved rpcclient.h into rpcclient directory and out of includes/smb.h (This used to be commit a40facba9651f9fb1dcc9e143f92ca298a324312)
Diffstat (limited to 'source3/rpcclient/rpcclient.c')
-rw-r--r--source3/rpcclient/rpcclient.c73
1 files changed, 56 insertions, 17 deletions
diff --git a/source3/rpcclient/rpcclient.c b/source3/rpcclient/rpcclient.c
index a5fb42796b..77bf413723 100644
--- a/source3/rpcclient/rpcclient.c
+++ b/source3/rpcclient/rpcclient.c
@@ -21,6 +21,7 @@
*/
#include "includes.h"
+#include "rpcclient.h"
extern pstring debugf;
@@ -266,7 +267,8 @@ void init_rpcclient_creds(struct ntuser_creds *creds, char* username,
/* 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;
@@ -324,7 +326,8 @@ static NTSTATUS cmd_help(struct cli_state *cli, int argc, char **argv)
/* 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]);
@@ -340,7 +343,8 @@ static NTSTATUS cmd_debuglevel(struct cli_state *cli, int argc, char **argv)
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 */
@@ -389,7 +393,7 @@ static struct cmd_set *rpcclient_command_list[] = {
NULL
};
-void add_command_set(struct cmd_set *cmd_set)
+static void add_command_set(struct cmd_set *cmd_set)
{
struct cmd_list *entry;
@@ -404,10 +408,11 @@ void add_command_set(struct cmd_set *cmd_set)
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;
@@ -428,10 +433,12 @@ static NTSTATUS do_cmd(struct cli_state *cli, struct cmd_set *cmd_entry, char *c
/* 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;
@@ -441,21 +448,52 @@ static NTSTATUS do_cmd(struct cli_state *cli, struct cmd_set *cmd_entry, char *c
}
/* 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;
}
@@ -490,8 +528,9 @@ static NTSTATUS process_cmd(struct cli_state *cli, char *cmd)
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++;