/**************************************************************************** main program ****************************************************************************/ int main(int argc, char *argv[]) { TALLOC_CTX *frame = talloc_stackframe(); const char **argv_const = discard_const_p(const char *, argv); struct user_auth_info *auth_info; struct poptOption long_options[] = { POPT_AUTOHELP { "broadcast", 'b', POPT_ARG_VAL, &use_bcast, True, "Use broadcast instead of using the master browser" }, { "domains", 'D', POPT_ARG_VAL, &level, LEV_WORKGROUP, "List only domains (workgroups) of tree" }, { "servers", 'S', POPT_ARG_VAL, &level, LEV_SERVER, "List domains(workgroups) and servers of tree" }, POPT_COMMON_SAMBA POPT_COMMON_CREDENTIALS POPT_TABLEEND }; poptContext pc; /* Initialise samba stuff */ load_case_tables(); setlinebuf(stdout); setup_logging(argv[0], DEBUG_STDERR); auth_info = user_auth_info_init(frame); if (auth_info == NULL) { exit(1); } popt_common_set_auth_info(auth_info); pc = poptGetContext("smbtree", argc, argv_const, long_options, POPT_CONTEXT_KEEP_FIRST); while(poptGetNextOpt(pc) != -1); poptFreeContext(pc); popt_burn_cmdline_password(argc, argv); lp_load_global(get_dyn_CONFIGFILE()); load_interfaces(); /* Parse command line args */ if (get_cmdline_auth_info_use_machine_account(auth_info) && !set_cmdline_auth_info_machine_account_creds(auth_info)) { TALLOC_FREE(frame); return 1; } set_cmdline_auth_info_getpass(auth_info); /* Now do our stuff */ if (!print_tree(auth_info)) { TALLOC_FREE(frame); return 1; } TALLOC_FREE(frame); return 0; }
int main(int argc, char **argv) { struct poptOption long_options[] = { POPT_AUTOHELP /* ... */ POPT_COMMON_SAMBA POPT_COMMON_CONNECTION POPT_COMMON_CREDENTIALS POPT_TABLEEND }; int opt; poptContext pc; struct user_auth_info *auth_info; TALLOC_CTX *frame; struct registry_context *ctx; WERROR rv; frame = talloc_stackframe(); setup_logging("regedit", DEBUG_DEFAULT_STDERR); lp_set_cmdline("log level", "0"); /* process options */ auth_info = user_auth_info_init(frame); if (auth_info == NULL) { exit(1); } popt_common_set_auth_info(auth_info); pc = poptGetContext("regedit", argc, (const char **)argv, long_options, 0); while ((opt = poptGetNextOpt(pc)) != -1) { /* TODO */ } if (!lp_load_global(get_dyn_CONFIGFILE())) { DEBUG(0, ("ERROR loading config file...\n")); exit(1); } /* some simple tests */ rv = reg_open_samba3(frame, &ctx); if (!W_ERROR_IS_OK(rv)) { TALLOC_FREE(frame); return 1; } display_window(frame, ctx); TALLOC_FREE(frame); return 0; }
static WERROR libnetapi_open_ipc_connection(struct libnetapi_ctx *ctx, const char *server_name, struct cli_state **cli) { struct user_auth_info *auth_info = NULL; struct cli_state *cli_ipc = NULL; if (!ctx || !cli || !server_name) { return WERR_INVALID_PARAM; } auth_info = user_auth_info_init(NULL); if (!auth_info) { return WERR_NOMEM; } auth_info->signing_state = Undefined; set_cmdline_auth_info_use_kerberos(auth_info, ctx->use_kerberos); set_cmdline_auth_info_username(auth_info, ctx->username); if (ctx->password) { set_cmdline_auth_info_password(auth_info, ctx->password); } else { set_cmdline_auth_info_getpass(auth_info); } if (ctx->username && ctx->username[0] && ctx->password && ctx->password[0] && ctx->use_kerberos) { set_cmdline_auth_info_fallback_after_kerberos(auth_info, true); } cli_ipc = cli_cm_open(ctx, NULL, server_name, "IPC$", auth_info, false, false, PROTOCOL_NT1, 0, 0x20); if (cli_ipc) { cli_set_username(cli_ipc, ctx->username); cli_set_password(cli_ipc, ctx->password); cli_set_domain(cli_ipc, ctx->workgroup); } TALLOC_FREE(auth_info); if (!cli_ipc) { libnetapi_set_error_string(ctx, "Failed to connect to IPC$ share on %s", server_name); return WERR_CAN_NOT_COMPLETE; } *cli = cli_ipc; return WERR_OK; }
static WERROR libnetapi_open_ipc_connection(struct libnetapi_ctx *ctx, const char *server_name, struct client_ipc_connection **pp) { struct libnetapi_private_ctx *priv_ctx; struct user_auth_info *auth_info = NULL; struct cli_state *cli_ipc = NULL; struct client_ipc_connection *p; NTSTATUS status; if (!ctx || !pp || !server_name) { return WERR_INVALID_PARAM; } priv_ctx = (struct libnetapi_private_ctx *)ctx->private_data; p = ipc_cm_find(priv_ctx, server_name); if (p) { *pp = p; return WERR_OK; } auth_info = user_auth_info_init(ctx); if (!auth_info) { return WERR_NOMEM; } auth_info->signing_state = SMB_SIGNING_DEFAULT; set_cmdline_auth_info_use_kerberos(auth_info, ctx->use_kerberos); set_cmdline_auth_info_username(auth_info, ctx->username); if (ctx->password) { set_cmdline_auth_info_password(auth_info, ctx->password); } else { set_cmdline_auth_info_getpass(auth_info); } if (ctx->username && ctx->username[0] && ctx->password && ctx->password[0] && ctx->use_kerberos) { set_cmdline_auth_info_fallback_after_kerberos(auth_info, true); } if (ctx->use_ccache) { set_cmdline_auth_info_use_ccache(auth_info, true); } status = cli_cm_open(ctx, NULL, server_name, "IPC$", auth_info, false, false, PROTOCOL_NT1, 0, 0x20, &cli_ipc); if (NT_STATUS_IS_OK(status)) { cli_set_username(cli_ipc, ctx->username); cli_set_password(cli_ipc, ctx->password); cli_set_domain(cli_ipc, ctx->workgroup); } else { cli_ipc = NULL; } TALLOC_FREE(auth_info); if (!cli_ipc) { libnetapi_set_error_string(ctx, "Failed to connect to IPC$ share on %s", server_name); return WERR_CAN_NOT_COMPLETE; } p = talloc_zero(ctx, struct client_ipc_connection); if (p == NULL) { return WERR_NOMEM; } p->cli = cli_ipc; DLIST_ADD(priv_ctx->ipc_connections, p); *pp = p; return WERR_OK; }