X-Git-Url: http://git.samba.org/samba.git/?p=sfrench%2Fsamba-autobuild%2F.git;a=blobdiff_plain;f=source%2Futils%2Fnet.c;h=34f580f4d1c058c43f203ddade03b316fc157a2a;hp=27b64aa96e55b3cd107ab083df9b13b70b17d202;hb=407e6e695b8366369b7c76af1ff76869b45347b3;hpb=51df47c772f8bdd5a2c3a1e9814e625406e79b5f diff --git a/source/utils/net.c b/source/utils/net.c index 27b64aa96e5..34f580f4d1c 100644 --- a/source/utils/net.c +++ b/source/utils/net.c @@ -13,7 +13,7 @@ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -65,6 +65,7 @@ const char *opt_workgroup = NULL; int opt_long_list_entries = 0; int opt_reboot = 0; int opt_force = 0; +int opt_stdin = 0; int opt_port = 0; int opt_verbose = 0; int opt_maxusers = -1; @@ -76,6 +77,7 @@ const char *opt_target_workgroup = NULL; int opt_machine_pass = 0; BOOL opt_localgroup = False; BOOL opt_domaingroup = False; +static BOOL do_talloc_report=False; const char *opt_newntname = ""; int opt_rid = 0; int opt_acls = 0; @@ -83,6 +85,7 @@ int opt_attrs = 0; int opt_timestamps = 0; const char *opt_exclude = NULL; const char *opt_destination = NULL; +BOOL opt_testmode = False; BOOL opt_have_ip = False; struct in_addr opt_dest_ip; @@ -158,6 +161,7 @@ int net_run_function2(int argc, const char **argv, const char *whoami, /**************************************************************************** connect to \\server\service ****************************************************************************/ + NTSTATUS connect_to_service(struct cli_state **c, struct in_addr *server_ip, const char *server_name, const char *service_name, @@ -171,13 +175,13 @@ NTSTATUS connect_to_service(struct cli_state **c, struct in_addr *server_ip, opt_password = SMB_STRDUP(pass); } } - + nt_status = cli_full_connection(c, NULL, server_name, server_ip, opt_port, service_name, service_type, opt_user_name, opt_workgroup, opt_password, 0, Undefined, NULL); - + if (NT_STATUS_IS_OK(nt_status)) { return nt_status; } else { @@ -233,21 +237,58 @@ NTSTATUS connect_to_ipc_anonymous(struct cli_state **c, } } +/**************************************************************************** + Return malloced user@realm for krb5 login. +****************************************************************************/ + +static char *get_user_and_realm(const char *username) +{ + char *user_and_realm = NULL; + + if (!username) { + return NULL; + } + if (strchr_m(username, '@')) { + user_and_realm = SMB_STRDUP(username); + } else { + if (asprintf(&user_and_realm, "%s@%s", username, lp_realm()) == -1) { + user_and_realm = NULL; + } + } + return user_and_realm; +} + /**************************************************************************** connect to \\server\ipc$ using KRB5 ****************************************************************************/ + NTSTATUS connect_to_ipc_krb5(struct cli_state **c, struct in_addr *server_ip, const char *server_name) { NTSTATUS nt_status; + char *user_and_realm = NULL; + + if (!opt_password && !opt_machine_pass) { + char *pass = getpass("Password:"); + if (pass) { + opt_password = SMB_STRDUP(pass); + } + } + + user_and_realm = get_user_and_realm(opt_user_name); + if (!user_and_realm) { + return NT_STATUS_NO_MEMORY; + } nt_status = cli_full_connection(c, NULL, server_name, server_ip, opt_port, "IPC$", "IPC", - opt_user_name, opt_workgroup, + user_and_realm, opt_workgroup, opt_password, CLI_FULL_CONNECTION_USE_KERBEROS, Undefined, NULL); + SAFE_FREE(user_and_realm); + if (NT_STATUS_IS_OK(nt_status)) { return nt_status; } else { @@ -479,7 +520,7 @@ static int net_group(int argc, const char **argv) static int net_join(int argc, const char **argv) { - if (net_ads_check() == 0) { + if (net_ads_check_our_domain() == 0) { if (net_ads_join(argc, argv) == 0) return 0; else @@ -490,19 +531,30 @@ static int net_join(int argc, const char **argv) static int net_changetrustpw(int argc, const char **argv) { - if (net_ads_check() == 0) + if (net_ads_check_our_domain() == 0) return net_ads_changetrustpw(argc, argv); return net_rpc_changetrustpw(argc, argv); } +static void set_line_buffering(FILE *f) +{ + setvbuf(f, NULL, _IOLBF, 0); +} + static int net_changesecretpw(int argc, const char **argv) { char *trust_pw; uint32 sec_channel_type = SEC_CHAN_WKSTA; if(opt_force) { - trust_pw = getpass("Enter machine password: "); + if (opt_stdin) { + set_line_buffering(stdin); + set_line_buffering(stdout); + set_line_buffering(stderr); + } + + trust_pw = get_pass("Enter machine password: ", opt_stdin); if (!secrets_store_machine_password(trust_pw, lp_workgroup(), sec_channel_type)) { d_fprintf(stderr, "Unable to write the machine account password in the secrets database"); @@ -551,7 +603,7 @@ static int net_getlocalsid(int argc, const char **argv) name = global_myname(); } - if(!initialize_password_db(False)) { + if(!initialize_password_db(False, NULL)) { DEBUG(0, ("WARNING: Could not open passdb - local sid may not reflect passdb\n" "backend knowlege (such as the sid stored in LDAP)\n")); } @@ -621,7 +673,7 @@ static int net_getdomainsid(int argc, const char **argv) DOM_SID domain_sid; fstring sid_str; - if(!initialize_password_db(False)) { + if(!initialize_password_db(False, NULL)) { DEBUG(0, ("WARNING: Could not open passdb - domain sid may not reflect passdb\n" "backend knowlege (such as the sid stored in LDAP)\n")); } @@ -820,6 +872,7 @@ static struct functable net_func[] = { {"STATUS", net_status}, {"USERSHARE", net_usershare}, {"USERSIDLIST", net_usersidlist}, + {"CONF", net_conf}, #ifdef WITH_FAKE_KASERVER {"AFS", net_afs}, #endif @@ -856,10 +909,12 @@ static struct functable net_func[] = { {"long", 'l', POPT_ARG_NONE, &opt_long_list_entries}, {"reboot", 'r', POPT_ARG_NONE, &opt_reboot}, {"force", 'f', POPT_ARG_NONE, &opt_force}, + {"stdin", 'i', POPT_ARG_NONE, &opt_stdin}, {"timeout", 't', POPT_ARG_INT, &opt_timeout}, {"machine-pass",'P', POPT_ARG_NONE, &opt_machine_pass}, {"myworkgroup", 'W', POPT_ARG_STRING, &opt_workgroup}, {"verbose", 'v', POPT_ARG_NONE, &opt_verbose}, + {"test", 'T', POPT_ARG_NONE, &opt_testmode}, /* Options for 'net groupmap set' */ {"local", 'L', POPT_ARG_NONE, &opt_localgroup}, {"domain", 'D', POPT_ARG_NONE, &opt_domaingroup}, @@ -871,6 +926,7 @@ static struct functable net_func[] = { {"timestamps", 0, POPT_ARG_NONE, &opt_timestamps}, {"exclude", 'e', POPT_ARG_STRING, &opt_exclude}, {"destination", 0, POPT_ARG_STRING, &opt_destination}, + {"tallocreport", 0, POPT_ARG_NONE, &do_talloc_report}, POPT_COMMON_SAMBA { 0, 0, 0, 0} @@ -934,6 +990,10 @@ static struct functable net_func[] = { } } + if (do_talloc_report) { + talloc_enable_leak_report(); + } + if (opt_requester_name) { set_global_myname(opt_requester_name); }