bool torture_libnetapi_init_context(struct torture_context *tctx, struct libnetapi_ctx **ctx_p) { NET_API_STATUS status; struct libnetapi_ctx *ctx; TALLOC_CTX *frame = talloc_stackframe(); if (!lp_load_global(lpcfg_configfile(tctx->lp_ctx))) { fprintf(stderr, "error loading %s\n", lpcfg_configfile(tctx->lp_ctx)); talloc_free(frame); return W_ERROR_V(WERR_GENERAL_FAILURE); } init_names(); load_interfaces(); status = libnetapi_net_init(&ctx); if (status != 0) { talloc_free(frame); return false; } libnetapi_set_username(ctx, cli_credentials_get_username(cmdline_credentials)); libnetapi_set_password(ctx, cli_credentials_get_password(cmdline_credentials)); *ctx_p = ctx; talloc_free(frame); return true; }
NET_API_STATUS libnetapi_init(struct libnetapi_ctx **context) { NET_API_STATUS ret; TALLOC_CTX *frame; if (stat_ctx && libnetapi_initialized) { *context = stat_ctx; return NET_API_STATUS_SUCCESS; } #if 0 talloc_enable_leak_report(); #endif frame = talloc_stackframe(); /* Case tables must be loaded before any string comparisons occour */ load_case_tables_library(); /* When libnetapi is invoked from an application, it does not * want to be swamped with level 10 debug messages, even if * this has been set for the server in smb.conf */ lp_set_cmdline("log level", "0"); setup_logging("libnetapi", DEBUG_STDERR); if (!lp_load(get_dyn_CONFIGFILE(), true, false, false, true)) { TALLOC_FREE(frame); fprintf(stderr, "error loading %s\n", get_dyn_CONFIGFILE() ); return W_ERROR_V(WERR_GENERAL_FAILURE); } init_names(); load_interfaces(); reopen_logs(); BlockSignals(True, SIGPIPE); ret = libnetapi_net_init(context); TALLOC_FREE(frame); return ret; }
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; }