static void run_shell(struct torture_context *tctx) { char *cline; int argc; const char **argv; int ret; while (1) { cline = smb_readline("torture> ", NULL, NULL); if (cline == NULL) return; ret = poptParseArgvString(cline, &argc, &argv); if (ret != 0) { fprintf(stderr, "Error parsing line\n"); continue; } if (!strcmp(argv[0], "quit")) { return; } else if (!strcmp(argv[0], "set")) { if (argc < 3) { fprintf(stderr, "Usage: set <variable> <value>\n"); } else { char *name = talloc_asprintf(NULL, "torture:%s", argv[1]); lp_set_cmdline(tctx->lp_ctx, name, argv[2]); talloc_free(name); } } else if (!strcmp(argv[0], "help")) { fprintf(stderr, "Available commands:\n" " help - This help command\n" " run - Run test\n" " set - Change variables\n" "\n"); } else if (!strcmp(argv[0], "run")) { if (argc < 2) { fprintf(stderr, "Usage: run TEST-NAME [OPTIONS...]\n"); } else { run_test(tctx, argv[1]); } } free(cline); } }
int net_rpc_shell(struct net_context *c, int argc, const char **argv) { NTSTATUS status; struct rpc_sh_ctx *ctx; if (argc != 0 || c->display_usage) { d_printf("%s\nnet rpc shell\n", _("Usage:")); return -1; } if (libnetapi_net_init(&c->netapi_ctx) != 0) { return -1; } libnetapi_set_username(c->netapi_ctx, c->opt_user_name); libnetapi_set_password(c->netapi_ctx, c->opt_password); if (c->opt_kerberos) { libnetapi_set_use_kerberos(c->netapi_ctx); } ctx = talloc(NULL, struct rpc_sh_ctx); if (ctx == NULL) { d_fprintf(stderr, _("talloc failed\n")); return -1; } status = net_make_ipc_connection(c, 0, &(ctx->cli)); if (!NT_STATUS_IS_OK(status)) { d_fprintf(stderr, _("Could not open connection: %s\n"), nt_errstr(status)); return -1; } ctx->cmds = sh_cmds; ctx->whoami = "net rpc"; ctx->parent = NULL; status = net_get_remote_domain_sid(ctx->cli, ctx, &ctx->domain_sid, &ctx->domain_name); if (!NT_STATUS_IS_OK(status)) { return -1; } d_printf(_("Talking to domain %s (%s)\n"), ctx->domain_name, sid_string_tos(ctx->domain_sid)); this_ctx = ctx; while(1) { char *prompt = NULL; char *line = NULL; int ret; if (asprintf(&prompt, "%s> ", this_ctx->whoami) < 0) { break; } line = smb_readline(prompt, NULL, completion_fn); SAFE_FREE(prompt); if (line == NULL) { break; } ret = poptParseArgvString(line, &argc, &argv); if (ret == POPT_ERROR_NOARG) { SAFE_FREE(line); continue; } if (ret != 0) { d_fprintf(stderr, _("cmdline invalid: %s\n"), poptStrerror(ret)); SAFE_FREE(line); return false; } if ((line[0] != '\n') && (!net_sh_process(c, this_ctx, argc, argv))) { SAFE_FREE(line); break; } SAFE_FREE(line); } cli_shutdown(ctx->cli); TALLOC_FREE(ctx); return 0; }
int main(int argc, char *argv[]) { static char *cmdstr = NULL; struct cmd_set **cmd_set; static struct vfs_state vfs; int i; static char *filename = NULL; /* make sure the vars that get altered (4th field) are in a fixed location or certain compilers complain */ poptContext pc; struct poptOption long_options[] = { POPT_AUTOHELP {"file", 'f', POPT_ARG_STRING, &filename, 0, }, {"command", 'c', POPT_ARG_STRING, &cmdstr, 0, "Execute specified list of commands" }, POPT_COMMON_SAMBA POPT_TABLEEND }; setlinebuf(stdout); pc = poptGetContext("vfstest", argc, (const char **) argv, long_options, 0); while(poptGetNextOpt(pc) != -1); poptFreeContext(pc); /* TODO: check output */ reload_services(False); /* the following functions are part of the Samba debugging facilities. See lib/debug.c */ setup_logging("vfstest", True); /* Load command lists */ cmd_set = vfstest_command_list; while(*cmd_set) { add_command_set(*cmd_set); add_command_set(separator_command); cmd_set++; } /* some basic initialization stuff */ sec_init(); conn_init(); vfs.conn = conn_new(); string_set(&vfs.conn->user,"vfstest"); for (i=0; i < 1024; i++) vfs.files[i] = NULL; /* some advanced initiliazation stuff */ smbd_vfs_init(vfs.conn); /* Do we have a file input? */ if (filename && filename[0]) { process_file(&vfs, filename); return 0; } /* Do anything specified with -c */ if (cmdstr && cmdstr[0]) { char *cmd; char *p = cmdstr; while((cmd=next_command(&p)) != NULL) { process_cmd(&vfs, cmd); } return 0; } /* Loop around accepting commands */ while(1) { pstring prompt; char *line; slprintf(prompt, sizeof(prompt) - 1, "vfstest $> "); line = smb_readline(prompt, NULL, completion_fn); if (line == NULL) break; if (line[0] != '\n') process_cmd(&vfs, line); } free(vfs.conn); return 0; }
int main(int argc, char **argv) { int opt; const char *file = NULL; poptContext pc; const char *remote = NULL; struct regshell_context *ctx; struct tevent_context *ev_ctx; bool ret = true; struct poptOption long_options[] = { POPT_AUTOHELP {"file", 'F', POPT_ARG_STRING, &file, 0, "open hive file", NULL }, {"remote", 'R', POPT_ARG_STRING, &remote, 0, "connect to specified remote server", NULL}, POPT_COMMON_SAMBA POPT_COMMON_CREDENTIALS POPT_COMMON_VERSION { NULL } }; pc = poptGetContext(argv[0], argc, (const char **) argv, long_options,0); while((opt = poptGetNextOpt(pc)) != -1) { } ctx = talloc_zero(NULL, struct regshell_context); ev_ctx = s4_event_context_init(ctx); if (remote != NULL) { ctx->registry = reg_common_open_remote(remote, ev_ctx, cmdline_lp_ctx, cmdline_credentials); } else if (file != NULL) { ctx->current = reg_common_open_file(file, ev_ctx, cmdline_lp_ctx, cmdline_credentials); if (ctx->current == NULL) return 1; ctx->registry = ctx->current->context; ctx->path = talloc_strdup(ctx, ""); ctx->predef = NULL; ctx->root = ctx->current; } else { ctx->registry = reg_common_open_local(cmdline_credentials, ev_ctx, cmdline_lp_ctx); } if (ctx->registry == NULL) return 1; if (ctx->current == NULL) { unsigned int i; for (i = 0; (reg_predefined_keys[i].handle != 0) && (ctx->current == NULL); i++) { WERROR err; err = reg_get_predefined_key(ctx->registry, reg_predefined_keys[i].handle, &ctx->current); if (W_ERROR_IS_OK(err)) { ctx->predef = talloc_strdup(ctx, reg_predefined_keys[i].name); ctx->path = talloc_strdup(ctx, ""); ctx->root = ctx->current; break; } else { ctx->current = NULL; ctx->root = NULL; } } } if (ctx->current == NULL) { fprintf(stderr, "Unable to access any of the predefined keys\n"); return 1; } poptFreeContext(pc); while (true) { char *line, *prompt; if (asprintf(&prompt, "%s\\%s> ", ctx->predef?ctx->predef:"", ctx->path) < 0) { ret = false; break; } current_key = ctx->current; /* No way to pass a void * pointer via readline :-( */ line = smb_readline(prompt, NULL, reg_completion); if (line == NULL) { free(prompt); break; } if (line[0] != '\n') { ret = W_ERROR_IS_OK(process_cmd(ctx, line)); } free(line); free(prompt); } talloc_free(ctx); return (ret?0:1); }