| 1 | /*
|
|---|
| 2 | * Unix SMB/CIFS implementation.
|
|---|
| 3 | * Shell around net rpc subcommands
|
|---|
| 4 | * Copyright (C) Volker Lendecke 2006
|
|---|
| 5 | *
|
|---|
| 6 | * This program is free software; you can redistribute it and/or modify
|
|---|
| 7 | * it under the terms of the GNU General Public License as published by
|
|---|
| 8 | * the Free Software Foundation; either version 3 of the License, or
|
|---|
| 9 | * (at your option) any later version.
|
|---|
| 10 | *
|
|---|
| 11 | * This program is distributed in the hope that it will be useful,
|
|---|
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 14 | * GNU General Public License for more details.
|
|---|
| 15 | *
|
|---|
| 16 | * You should have received a copy of the GNU General Public License
|
|---|
| 17 | * along with this program; if not, see <http://www.gnu.org/licenses/>.
|
|---|
| 18 | */
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 | #include "includes.h"
|
|---|
| 22 | #include "utils/net.h"
|
|---|
| 23 |
|
|---|
| 24 | static NTSTATUS rpc_sh_info(TALLOC_CTX *mem_ctx, struct rpc_sh_ctx *ctx,
|
|---|
| 25 | struct rpc_pipe_client *pipe_hnd,
|
|---|
| 26 | int argc, const char **argv)
|
|---|
| 27 | {
|
|---|
| 28 | return rpc_info_internals(ctx->domain_sid, ctx->domain_name,
|
|---|
| 29 | ctx->cli, pipe_hnd, mem_ctx,
|
|---|
| 30 | argc, argv);
|
|---|
| 31 | }
|
|---|
| 32 |
|
|---|
| 33 | static struct rpc_sh_ctx *this_ctx;
|
|---|
| 34 |
|
|---|
| 35 | static char **completion_fn(const char *text, int start, int end)
|
|---|
| 36 | {
|
|---|
| 37 | char **cmds = NULL;
|
|---|
| 38 | int n_cmds = 0;
|
|---|
| 39 | struct rpc_sh_cmd *c;
|
|---|
| 40 |
|
|---|
| 41 | if (start != 0) {
|
|---|
| 42 | return NULL;
|
|---|
| 43 | }
|
|---|
| 44 |
|
|---|
| 45 | ADD_TO_ARRAY(NULL, char *, SMB_STRDUP(text), &cmds, &n_cmds);
|
|---|
| 46 |
|
|---|
| 47 | for (c = this_ctx->cmds; c->name != NULL; c++) {
|
|---|
| 48 | bool match = (strncmp(text, c->name, strlen(text)) == 0);
|
|---|
| 49 |
|
|---|
| 50 | if (match) {
|
|---|
| 51 | ADD_TO_ARRAY(NULL, char *, SMB_STRDUP(c->name),
|
|---|
| 52 | &cmds, &n_cmds);
|
|---|
| 53 | }
|
|---|
| 54 | }
|
|---|
| 55 |
|
|---|
| 56 | if (n_cmds == 2) {
|
|---|
| 57 | SAFE_FREE(cmds[0]);
|
|---|
| 58 | cmds[0] = cmds[1];
|
|---|
| 59 | n_cmds -= 1;
|
|---|
| 60 | }
|
|---|
| 61 |
|
|---|
| 62 | ADD_TO_ARRAY(NULL, char *, NULL, &cmds, &n_cmds);
|
|---|
| 63 | return cmds;
|
|---|
| 64 | }
|
|---|
| 65 |
|
|---|
| 66 | static NTSTATUS net_sh_run(struct rpc_sh_ctx *ctx, struct rpc_sh_cmd *cmd,
|
|---|
| 67 | int argc, const char **argv)
|
|---|
| 68 | {
|
|---|
| 69 | TALLOC_CTX *mem_ctx;
|
|---|
| 70 | struct rpc_pipe_client *pipe_hnd;
|
|---|
| 71 | NTSTATUS status;
|
|---|
| 72 |
|
|---|
| 73 | mem_ctx = talloc_new(ctx);
|
|---|
| 74 | if (mem_ctx == NULL) {
|
|---|
| 75 | d_fprintf(stderr, "talloc_new failed\n");
|
|---|
| 76 | return NT_STATUS_NO_MEMORY;
|
|---|
| 77 | }
|
|---|
| 78 |
|
|---|
| 79 | pipe_hnd = cli_rpc_pipe_open_noauth(ctx->cli, cmd->pipe_idx, &status);
|
|---|
| 80 | if (pipe_hnd == NULL) {
|
|---|
| 81 | d_fprintf(stderr, "Could not open pipe: %s\n",
|
|---|
| 82 | nt_errstr(status));
|
|---|
| 83 | return status;
|
|---|
| 84 | }
|
|---|
| 85 |
|
|---|
| 86 | status = cmd->fn(mem_ctx, ctx, pipe_hnd, argc, argv);
|
|---|
| 87 |
|
|---|
| 88 | cli_rpc_pipe_close(pipe_hnd);
|
|---|
| 89 |
|
|---|
| 90 | talloc_destroy(mem_ctx);
|
|---|
| 91 |
|
|---|
| 92 | return status;
|
|---|
| 93 | }
|
|---|
| 94 |
|
|---|
| 95 | static bool net_sh_process(struct rpc_sh_ctx *ctx,
|
|---|
| 96 | int argc, const char **argv)
|
|---|
| 97 | {
|
|---|
| 98 | struct rpc_sh_cmd *c;
|
|---|
| 99 | struct rpc_sh_ctx *new_ctx;
|
|---|
| 100 | NTSTATUS status;
|
|---|
| 101 |
|
|---|
| 102 | if (argc == 0) {
|
|---|
| 103 | return True;
|
|---|
| 104 | }
|
|---|
|
|---|