bool set_cmdline_auth_info_machine_account_creds(struct user_auth_info *auth_info) { char *pass = NULL; char *account = NULL; if (!get_cmdline_auth_info_use_machine_account(auth_info)) { return false; } if (!secrets_init()) { d_printf("ERROR: Unable to open secrets database\n"); return false; } if (asprintf(&account, "%s$@%s", lp_netbios_name(), lp_realm()) < 0) { return false; } pass = secrets_fetch_machine_password(lp_workgroup(), NULL, NULL); if (!pass) { d_printf("ERROR: Unable to fetch machine password for " "%s in domain %s\n", account, lp_workgroup()); SAFE_FREE(account); return false; } set_cmdline_auth_info_username(auth_info, account); set_cmdline_auth_info_password(auth_info, pass); SAFE_FREE(account); SAFE_FREE(pass); return true; }
/**************************************************************************** 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; }
static struct cli_state *connect_one(const char *share) { struct cli_state *c; struct sockaddr_storage ss; NTSTATUS nt_status; uint32_t flags = 0; zero_sockaddr(&ss); if (get_cmdline_auth_info_use_machine_account() && !set_cmdline_auth_info_machine_account_creds()) { return NULL; } if (get_cmdline_auth_info_use_kerberos()) { flags |= CLI_FULL_CONNECTION_USE_KERBEROS | CLI_FULL_CONNECTION_FALLBACK_AFTER_KERBEROS; } if (!get_cmdline_auth_info_got_pass()) { char *pass = getpass("Password: "******"?????", get_cmdline_auth_info_username(), lp_workgroup(), get_cmdline_auth_info_password(), flags, get_cmdline_auth_info_signing_state(), NULL); if (!NT_STATUS_IS_OK(nt_status)) { DEBUG(0,("cli_full_connection failed! (%s)\n", nt_errstr(nt_status))); return NULL; } if (get_cmdline_auth_info_smb_encrypt()) { nt_status = cli_cm_force_encryption(c, get_cmdline_auth_info_username(), get_cmdline_auth_info_password(), lp_workgroup(), share); if (!NT_STATUS_IS_OK(nt_status)) { cli_shutdown(c); return NULL; } } return c; }
static struct cli_state *connect_one(const char *share) { struct cli_state *c; NTSTATUS nt_status; uint32_t flags = 0; if (get_cmdline_auth_info_use_machine_account(smbcquotas_auth_info) && !set_cmdline_auth_info_machine_account_creds(smbcquotas_auth_info)) { return NULL; } if (get_cmdline_auth_info_use_kerberos(smbcquotas_auth_info)) { flags |= CLI_FULL_CONNECTION_USE_KERBEROS | CLI_FULL_CONNECTION_FALLBACK_AFTER_KERBEROS; } set_cmdline_auth_info_getpass(smbcquotas_auth_info); nt_status = cli_full_connection(&c, lp_netbios_name(), server, NULL, 0, share, "?????", get_cmdline_auth_info_username(smbcquotas_auth_info), lp_workgroup(), get_cmdline_auth_info_password(smbcquotas_auth_info), flags, get_cmdline_auth_info_signing_state(smbcquotas_auth_info)); if (!NT_STATUS_IS_OK(nt_status)) { DEBUG(0,("cli_full_connection failed! (%s)\n", nt_errstr(nt_status))); return NULL; } if (get_cmdline_auth_info_smb_encrypt(smbcquotas_auth_info)) { nt_status = cli_cm_force_encryption(c, get_cmdline_auth_info_username(smbcquotas_auth_info), get_cmdline_auth_info_password(smbcquotas_auth_info), lp_workgroup(), share); if (!NT_STATUS_IS_OK(nt_status)) { cli_shutdown(c); return NULL; } } return c; }
/**************************************************************************** main program ****************************************************************************/ int main(int argc,char *argv[]) { TALLOC_CTX *frame = talloc_stackframe(); struct user_auth_info local_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); dbf = x_stderr; setup_logging(argv[0],True); pc = poptGetContext("smbtree", argc, (const char **)argv, long_options, POPT_CONTEXT_KEEP_FIRST); while(poptGetNextOpt(pc) != -1); poptFreeContext(pc); lp_load(get_dyn_CONFIGFILE(),True,False,False,True); load_interfaces(); /* Parse command line args */ if (get_cmdline_auth_info_use_machine_account() && !set_cmdline_auth_info_machine_account_creds()) { TALLOC_FREE(frame); return 1; } if (!get_cmdline_auth_info_got_pass()) { char *pass = getpass("Password: "); if (pass) { set_cmdline_auth_info_password(pass); } } /* Now do our stuff */ if (!get_cmdline_auth_info_copy(&local_auth_info)) { return 1; } if (!print_tree(&local_auth_info)) { TALLOC_FREE(frame); return 1; } TALLOC_FREE(frame); return 0; }