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; }
/** * Initialises the NetApi context. This function is not re-entrant. * * @param host hostname of the Samba server * @param username service account username * @param passwd service account password * * @return true on success, false otherwise */ int authz_init(const char *host, const char *username, const char *passwd) { pthread_mutex_lock(&_ctxmtx); if (_netapictx || !host || !username || !passwd) { pthread_mutex_unlock(&_ctxmtx); return 0; } if (libnetapi_init(&_netapictx) != NET_API_STATUS_SUCCESS) { log_error("failed to initialise NetApi context"); pthread_mutex_unlock(&_ctxmtx); return 0; } libnetapi_set_username(_netapictx, username); libnetapi_set_password(_netapictx, passwd); _host = strdup(host); pthread_mutex_unlock(&_ctxmtx); log_info("initialised NetApi context"); return 1; }
int net_dom(struct net_context *c, int argc, const char **argv) { NET_API_STATUS status; struct functable func[] = { { "join", net_dom_join, NET_TRANSPORT_LOCAL, "Join a remote machine", "net dom join <domain=DOMAIN> <ou=OU> " "<account=ACCOUNT> <password=PASSWORD> <reboot>\n" " Join a remote machine" }, { "unjoin", net_dom_unjoin, NET_TRANSPORT_LOCAL, "Unjoin a remote machine", "net dom unjoin <account=ACCOUNT> <password=PASSWORD> " "<reboot>\n" " Unjoin a remote machine" }, {NULL, NULL, 0, NULL, NULL} }; status = libnetapi_init(&c->netapi_ctx); if (status != 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); } return net_run_function(c, argc, argv, "net dom", func); }
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; }