diff options
Diffstat (limited to 'source3/utils')
-rw-r--r-- | source3/utils/net.c | 196 | ||||
-rw-r--r-- | source3/utils/net.h | 2 | ||||
-rw-r--r-- | source3/utils/net_ads.c | 36 | ||||
-rw-r--r-- | source3/utils/net_lookup.c | 93 | ||||
-rw-r--r-- | source3/utils/net_rpc.c | 30 | ||||
-rw-r--r-- | source3/utils/net_rpc_join.c | 6 | ||||
-rw-r--r-- | source3/utils/net_rpc_printer.c | 13 | ||||
-rw-r--r-- | source3/utils/net_time.c | 14 | ||||
-rw-r--r-- | source3/utils/netlookup.c | 10 | ||||
-rw-r--r-- | source3/utils/nmblookup.c | 400 | ||||
-rw-r--r-- | source3/utils/smbcacls.c | 15 | ||||
-rw-r--r-- | source3/utils/smbcquotas.c | 15 |
12 files changed, 469 insertions, 361 deletions
diff --git a/source3/utils/net.c b/source3/utils/net.c index 068118f476..fb82e76591 100644 --- a/source3/utils/net.c +++ b/source3/utils/net.c @@ -56,7 +56,7 @@ /* Yes, these buggers are globals.... */ const char *opt_requester_name = NULL; -const char *opt_host = NULL; +const char *opt_host = NULL; const char *opt_password = NULL; const char *opt_user_name = NULL; bool opt_user_specified = False; @@ -87,7 +87,7 @@ const char *opt_destination = NULL; int opt_testmode = False; int opt_have_ip = False; -struct in_addr opt_dest_ip; +struct sockaddr_storage opt_dest_ip; extern bool AllowDebugChange; @@ -157,12 +157,13 @@ int net_run_function2(int argc, const char **argv, const char *whoami, } /**************************************************************************** -connect to \\server\service + 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, +NTSTATUS connect_to_service(struct cli_state **c, + struct sockaddr_storage *server_ss, + const char *server_name, + const char *service_name, const char *service_type) { NTSTATUS nt_status; @@ -172,9 +173,9 @@ NTSTATUS connect_to_service(struct cli_state **c, struct in_addr *server_ip, return NT_STATUS_NO_MEMORY; } - nt_status = cli_full_connection(c, NULL, server_name, - server_ip, opt_port, - service_name, service_type, + nt_status = cli_full_connection(c, NULL, server_name, + server_ss, opt_port, + service_name, service_type, opt_user_name, opt_workgroup, opt_password, 0, Undefined, NULL); if (NT_STATUS_IS_OK(nt_status)) { @@ -184,15 +185,15 @@ NTSTATUS connect_to_service(struct cli_state **c, struct in_addr *server_ip, /* Display a nicer message depending on the result */ - if (NT_STATUS_V(nt_status) == + if (NT_STATUS_V(nt_status) == NT_STATUS_V(NT_STATUS_LOGON_FAILURE)) d_fprintf(stderr, "The username or password was not correct.\n"); - if (NT_STATUS_V(nt_status) == + if (NT_STATUS_V(nt_status) == NT_STATUS_V(NT_STATUS_ACCOUNT_LOCKED_OUT)) d_fprintf(stderr, "The account was locked out.\n"); - if (NT_STATUS_V(nt_status) == + if (NT_STATUS_V(nt_status) == NT_STATUS_V(NT_STATUS_ACCOUNT_DISABLED)) d_fprintf(stderr, "The account was disabled.\n"); @@ -200,30 +201,33 @@ NTSTATUS connect_to_service(struct cli_state **c, struct in_addr *server_ip, } } - /**************************************************************************** -connect to \\server\ipc$ + Connect to \\server\ipc$. ****************************************************************************/ -NTSTATUS connect_to_ipc(struct cli_state **c, struct in_addr *server_ip, - const char *server_name) + +NTSTATUS connect_to_ipc(struct cli_state **c, + struct sockaddr_storage *server_ss, + const char *server_name) { - return connect_to_service(c, server_ip, server_name, "IPC$", "IPC"); + return connect_to_service(c, server_ss, server_name, "IPC$", "IPC"); } /**************************************************************************** -connect to \\server\ipc$ anonymously + Connect to \\server\ipc$ anonymously. ****************************************************************************/ + NTSTATUS connect_to_ipc_anonymous(struct cli_state **c, - struct in_addr *server_ip, const char *server_name) + struct sockaddr_storage *server_ss, + const char *server_name) { NTSTATUS nt_status; - nt_status = cli_full_connection(c, opt_requester_name, server_name, - server_ip, opt_port, - "IPC$", "IPC", + nt_status = cli_full_connection(c, opt_requester_name, server_name, + server_ss, opt_port, + "IPC$", "IPC", "", "", "", 0, Undefined, NULL); - + if (NT_STATUS_IS_OK(nt_status)) { return nt_status; } else { @@ -254,11 +258,12 @@ static char *get_user_and_realm(const char *username) } /**************************************************************************** -connect to \\server\ipc$ using KRB5 + Connect to \\server\ipc$ using KRB5. ****************************************************************************/ NTSTATUS connect_to_ipc_krb5(struct cli_state **c, - struct in_addr *server_ip, const char *server_name) + struct sockaddr_storage *server_ss, + const char *server_name) { NTSTATUS nt_status; char *user_and_realm = NULL; @@ -273,13 +278,13 @@ NTSTATUS connect_to_ipc_krb5(struct cli_state **c, return NT_STATUS_NO_MEMORY; } - nt_status = cli_full_connection(c, NULL, server_name, - server_ip, opt_port, - "IPC$", "IPC", + nt_status = cli_full_connection(c, NULL, server_name, + server_ss, opt_port, + "IPC$", "IPC", 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)) { @@ -367,7 +372,7 @@ int net_use_krb_machine_account(void) int net_use_machine_account(void) { char *user_name = NULL; - + if (!secrets_init()) { d_fprintf(stderr, "ERROR: Unable to open secrets database\n"); exit(1); @@ -381,62 +386,78 @@ int net_use_machine_account(void) return 0; } -bool net_find_server(const char *domain, unsigned flags, struct in_addr *server_ip, char **server_name) +bool net_find_server(const char *domain, + unsigned flags, + struct sockaddr_storage *server_ss, + char **server_name) { const char *d = domain ? domain : opt_target_workgroup; if (opt_host) { *server_name = SMB_STRDUP(opt_host); - } + } if (opt_have_ip) { - *server_ip = opt_dest_ip; + *server_ss = opt_dest_ip; if (!*server_name) { - *server_name = SMB_STRDUP(inet_ntoa(opt_dest_ip)); + char addr[INET6_ADDRSTRLEN]; + print_sockaddr(addr, sizeof(addr), &opt_dest_ip); + *server_name = SMB_STRDUP(addr); } } else if (*server_name) { /* resolve the IP address */ - if (!resolve_name(*server_name, server_ip, 0x20)) { + if (!resolve_name(*server_name, server_ss, 0x20)) { DEBUG(1,("Unable to resolve server name\n")); - return False; + return false; } } else if (flags & NET_FLAGS_PDC) { - struct in_addr pdc_ip; - - if (get_pdc_ip(d, &pdc_ip)) { - fstring dc_name; - - if (is_zero_ip_v4(pdc_ip)) - return False; - - if ( !name_status_find(d, 0x1b, 0x20, pdc_ip, dc_name) ) - return False; - - *server_name = SMB_STRDUP(dc_name); - *server_ip = pdc_ip; + fstring dc_name; + struct sockaddr_storage pdc_ss; + + if (get_pdc_ip(d, &pdc_ss)) { + DEBUG(1,("Unable to resolve PDC server address\n")); + return false; + } + + if (is_zero_addr(&pdc_ss)) { + return false; } + + if (!name_status_find(d, 0x1b, 0x20, &pdc_ss, dc_name)) { + return False; + } + + *server_name = SMB_STRDUP(dc_name); + *server_ss = pdc_ss; } else if (flags & NET_FLAGS_DMB) { - struct in_addr msbrow_ip; + struct sockaddr_storage msbrow_ss; + char addr[INET6_ADDRSTRLEN]; + /* if (!resolve_name(MSBROWSE, &msbrow_ip, 1)) */ - if (!resolve_name(d, &msbrow_ip, 0x1B)) { + if (!resolve_name(d, &msbrow_ss, 0x1B)) { DEBUG(1,("Unable to resolve domain browser via name lookup\n")); - return False; - } else { - *server_ip = msbrow_ip; + return false; } - *server_name = SMB_STRDUP(inet_ntoa(opt_dest_ip)); + *server_ss = msbrow_ss; + print_sockaddr(addr, sizeof(addr), server_ss); + *server_name = SMB_STRDUP(addr); } else if (flags & NET_FLAGS_MASTER) { - struct in_addr brow_ips; - if (!resolve_name(d, &brow_ips, 0x1D)) { + struct sockaddr_storage brow_ss; + char addr[INET6_ADDRSTRLEN]; + if (!resolve_name(d, &brow_ss, 0x1D)) { /* go looking for workgroups */ DEBUG(1,("Unable to resolve master browser via name lookup\n")); - return False; - } else { - *server_ip = brow_ips; + return false; } - *server_name = SMB_STRDUP(inet_ntoa(opt_dest_ip)); + *server_ss = brow_ss; + print_sockaddr(addr, sizeof(addr), server_ss); + *server_name = SMB_STRDUP(addr); } else if (!(flags & NET_FLAGS_LOCALHOST_DEFAULT_INSANE)) { - (*server_ip).s_addr = htonl(INADDR_LOOPBACK); + if (!interpret_string_addr(server_ss, + "127.0.0.1", AI_NUMERICHOST)) { + DEBUG(1,("Unable to resolve 127.0.0.1\n")); + return false; + } *server_name = SMB_STRDUP("127.0.0.1"); } @@ -448,20 +469,22 @@ bool net_find_server(const char *domain, unsigned flags, struct in_addr *server_ return True; } - -bool net_find_pdc(struct in_addr *server_ip, fstring server_name, const char *domain_name) +bool net_find_pdc(struct sockaddr_storage *server_ss, + fstring server_name, + const char *domain_name) { - if (get_pdc_ip(domain_name, server_ip)) { - if (is_zero_ip_v4(*server_ip)) - return False; - - if (!name_status_find(domain_name, 0x1b, 0x20, *server_ip, server_name)) - return False; - - return True; - } - else - return False; + if (!get_pdc_ip(domain_name, server_ss)) { + return false; + } + if (is_zero_addr(server_ss)) { + return false; + } + + if (!name_status_find(domain_name, 0x1b, 0x20, server_ss, server_name)) { + return false; + } + + return true; } NTSTATUS net_make_ipc_connection(unsigned flags, struct cli_state **pcli) @@ -470,29 +493,29 @@ NTSTATUS net_make_ipc_connection(unsigned flags, struct cli_state **pcli) } NTSTATUS net_make_ipc_connection_ex(const char *domain, const char *server, - struct in_addr *ip, unsigned flags, + struct sockaddr_storage *pss, unsigned flags, struct cli_state **pcli) { char *server_name = NULL; - struct in_addr server_ip; + struct sockaddr_storage server_ss; struct cli_state *cli = NULL; NTSTATUS nt_status; - if ( !server || !ip ) { - if (!net_find_server(domain, flags, &server_ip, &server_name)) { + if ( !server || !pss ) { + if (!net_find_server(domain, flags, &server_ss, &server_name)) { d_fprintf(stderr, "Unable to find a suitable server\n"); nt_status = NT_STATUS_UNSUCCESSFUL; goto done; } } else { server_name = SMB_STRDUP( server ); - server_ip = *ip; + server_ss = *pss; } if (flags & NET_FLAGS_ANONYMOUS) { - nt_status = connect_to_ipc_anonymous(&cli, &server_ip, server_name); + nt_status = connect_to_ipc_anonymous(&cli, &server_ss, server_name); } else { - nt_status = connect_to_ipc(&cli, &server_ip, server_name); + nt_status = connect_to_ipc(&cli, &server_ss, server_name); } /* store the server in the affinity cache if it was a PDC */ @@ -989,7 +1012,7 @@ static struct functable net_func[] = { TALLOC_CTX *frame = talloc_stackframe(); - zero_ip_v4(&opt_dest_ip); + zero_addr(&opt_dest_ip, AF_INET); load_case_tables(); @@ -1007,11 +1030,12 @@ static struct functable net_func[] = { exit(0); break; case 'I': - opt_dest_ip = *interpret_addr2(poptGetOptArg(pc)); - if (is_zero_ip_v4(opt_dest_ip)) + if (!interpret_string_addr(&opt_dest_ip, + poptGetOptArg(pc), 0)) { d_fprintf(stderr, "\nInvalid ip address specified\n"); - else + } else { opt_have_ip = True; + } break; case 'U': opt_user_specified = True; diff --git a/source3/utils/net.h b/source3/utils/net.h index 177c6d3601..2ffa4d77b1 100644 --- a/source3/utils/net.h +++ b/source3/utils/net.h @@ -114,7 +114,7 @@ extern const char *opt_destination; extern int opt_testmode; extern int opt_have_ip; -extern struct in_addr opt_dest_ip; +extern struct sockaddr_storage opt_dest_ip; extern const char *share_type[]; diff --git a/source3/utils/net_ads.c b/source3/utils/net_ads.c index bfbcbbde49..81b13ba76e 100644 --- a/source3/utils/net_ads.c +++ b/source3/utils/net_ads.c @@ -78,15 +78,17 @@ static const char *assume_own_realm(void) */ static int net_ads_cldap_netlogon(ADS_STRUCT *ads) { + char addr[INET6_ADDRSTRLEN]; struct cldap_netlogon_reply reply; - if ( !ads_cldap_netlogon( inet_ntoa(ads->ldap.ip), ads->server.realm, &reply ) ) { + print_sockaddr(addr, sizeof(addr), &ads->ldap.ss); + if ( !ads_cldap_netlogon(addr, ads->server.realm, &reply ) ) { d_fprintf(stderr, "CLDAP query failed!\n"); return -1; } d_printf("Information for Domain Controller: %s\n\n", - inet_ntoa(ads->ldap.ip)); + addr); d_printf("Response Type: "); switch (reply.type) { @@ -144,7 +146,6 @@ static int net_ads_cldap_netlogon(ADS_STRUCT *ads) return 0; } - /* this implements the CLDAP based netlogon lookup requests for finding the domain controller of a ADS domain @@ -171,6 +172,7 @@ static int net_ads_lookup(int argc, const char **argv) static int net_ads_info(int argc, const char **argv) { ADS_STRUCT *ads; + char addr[INET6_ADDRSTRLEN]; if (!ADS_ERR_OK(ads_startup_nobind(False, &ads))) { d_fprintf(stderr, "Didn't find the ldap server!\n"); @@ -189,7 +191,9 @@ static int net_ads_info(int argc, const char **argv) d_fprintf( stderr, "Failed to get server's current time!\n"); } - d_printf("LDAP server: %s\n", inet_ntoa(ads->ldap.ip)); + print_sockaddr(addr, sizeof(addr), &ads->ldap.ss); + + d_printf("LDAP server: %s\n", addr); d_printf("LDAP server name: %s\n", ads->config.ldap_server_name); d_printf("Realm: %s\n", ads->config.realm); d_printf("Bind Path: %s\n", ads->config.bind_path); @@ -369,6 +373,7 @@ int net_ads_check(void) static int net_ads_workgroup(int argc, const char **argv) { ADS_STRUCT *ads; + char addr[INET6_ADDRSTRLEN]; struct cldap_netlogon_reply reply; if (!ADS_ERR_OK(ads_startup_nobind(False, &ads))) { @@ -381,7 +386,8 @@ static int net_ads_workgroup(int argc, const char **argv) ads->ldap.port = 389; } - if ( !ads_cldap_netlogon( inet_ntoa(ads->ldap.ip), ads->server.realm, &reply ) ) { + print_sockaddr(addr, sizeof(addr), &ads->ldap.ss); + if ( !ads_cldap_netlogon(addr, ads->server.realm, &reply ) ) { d_fprintf(stderr, "CLDAP query failed!\n"); return -1; } @@ -829,7 +835,7 @@ static int net_ads_leave(int argc, const char **argv) /* make RPC calls here */ - if ( !NT_STATUS_IS_OK(connect_to_ipc_krb5(&cli, &ads->ldap.ip, + if ( !NT_STATUS_IS_OK(connect_to_ipc_krb5(&cli, &ads->ldap.ss, ads->config.ldap_server_name)) ) { goto done; @@ -952,14 +958,14 @@ static NTSTATUS check_ads_config( void ) ********************************************************************/ static NTSTATUS net_join_domain(TALLOC_CTX *ctx, const char *servername, - struct in_addr *ip, char **domain, + struct sockaddr_storage *pss, char **domain, DOM_SID **dom_sid, const char *password) { NTSTATUS ret = NT_STATUS_UNSUCCESSFUL; struct cli_state *cli = NULL; - ret = connect_to_ipc_krb5(&cli, ip, servername); + ret = connect_to_ipc_krb5(&cli, pss, servername); if ( !NT_STATUS_IS_OK(ret) ) { goto done; } @@ -1475,7 +1481,7 @@ int net_ads_join(int argc, const char **argv) const char *create_in_ou = NULL; int i; fstring dc_name; - struct in_addr dcip; + struct sockaddr_storage dcss; const char *os_name = NULL; const char *os_version = NULL; @@ -1487,7 +1493,7 @@ int net_ads_join(int argc, const char **argv) /* find a DC to initialize the server affinity cache */ - get_dc_name( lp_workgroup(), lp_realm(), dc_name, &dcip ); + get_dc_name( lp_workgroup(), lp_realm(), dc_name, &dcss ); status = ads_startup(True, &ads); if (!ADS_ERR_OK(status)) { @@ -1566,7 +1572,7 @@ int net_ads_join(int argc, const char **argv) password = talloc_strdup(ctx, tmp_password); nt_status = net_join_domain(ctx, ads->config.ldap_server_name, - &ads->ldap.ip, &short_domain_name, &domain_sid, password); + &ads->ldap.ss, &short_domain_name, &domain_sid, password); if ( !NT_STATUS_IS_OK(nt_status) ) { DEBUG(1, ("call of net_join_domain failed: %s\n", get_friendly_nt_error_msg(nt_status))); @@ -1602,7 +1608,7 @@ int net_ads_join(int argc, const char **argv) /* Verify that everything is ok */ nt_status = net_rpc_join_ok(short_domain_name, - ads->config.ldap_server_name, &ads->ldap.ip); + ads->config.ldap_server_name, &ads->ldap.ss); if (!NT_STATUS_IS_OK(nt_status)) { d_fprintf(stderr, "Failed to verify membership in domain: %s!\n", @@ -1929,7 +1935,7 @@ static int net_ads_printer_publish(int argc, const char **argv) const char *servername, *printername; struct cli_state *cli; struct rpc_pipe_client *pipe_hnd; - struct in_addr server_ip; + struct sockaddr_storage server_ss; NTSTATUS nt_status; TALLOC_CTX *mem_ctx = talloc_init("net_ads_printer_publish"); ADS_MODLIST mods = ads_init_mods(mem_ctx); @@ -1957,10 +1963,10 @@ static int net_ads_printer_publish(int argc, const char **argv) /* Get printer data from SPOOLSS */ - resolve_name(servername, &server_ip, 0x20); + resolve_name(servername, &server_ss, 0x20); nt_status = cli_full_connection(&cli, global_myname(), servername, - &server_ip, 0, + &server_ss, 0, "IPC$", "IPC", opt_user_name, opt_workgroup, opt_password ? opt_password : "", diff --git a/source3/utils/net_lookup.c b/source3/utils/net_lookup.c index a1e8c1a6ed..f7af1f2bb3 100644 --- a/source3/utils/net_lookup.c +++ b/source3/utils/net_lookup.c @@ -1,5 +1,5 @@ -/* - Samba Unix/Linux SMB client library +/* + Samba Unix/Linux SMB client library net lookup command Copyright (C) 2001 Andrew Tridgell (tridge@samba.org) @@ -7,12 +7,12 @@ it under the terms of the GNU General Public License as published by 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, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ @@ -38,12 +38,13 @@ int net_lookup_usage(int argc, const char **argv) /* lookup a hostname giving an IP */ static int net_lookup_host(int argc, const char **argv) { - struct in_addr ip; + struct sockaddr_storage ss; int name_type = 0x20; + char addr[INET6_ADDRSTRLEN]; const char *name = argv[0]; char *p; - if (argc == 0) + if (argc == 0) return net_lookup_usage(argc, argv); p = strchr_m(name,'#'); @@ -51,27 +52,37 @@ static int net_lookup_host(int argc, const char **argv) *p = '\0'; sscanf(++p,"%x",&name_type); } - - if (!resolve_name(name, &ip, name_type)) { - /* we deliberately use DEBUG() here to send it to stderr + + if (!resolve_name(name, &ss, name_type)) { + /* we deliberately use DEBUG() here to send it to stderr so scripts aren't mucked up */ DEBUG(0,("Didn't find %s#%02x\n", name, name_type)); return -1; } - d_printf("%s\n", inet_ntoa(ip)); + print_sockaddr(addr, sizeof(addr), &ss); + d_printf("%s\n", addr); return 0; } #ifdef HAVE_ADS static void print_ldap_srvlist(struct dns_rr_srv *dclist, int numdcs ) { - struct in_addr ip; + struct sockaddr_storage ss; int i; for ( i=0; i<numdcs; i++ ) { - if ( resolve_name(dclist[i].hostname, &ip, 0x20) ) { - d_printf("%s:%d\n", inet_ntoa(ip), dclist[i].port); + if (resolve_name(dclist[i].hostname, &ss, 0x20) ) { + char addr[INET6_ADDRSTRLEN]; + print_sockaddr(addr, sizeof(addr), &ss); +#ifdef HAVE_IPV6 + if (ss.ss_family == AF_INET6) { + d_printf("[%s]:%d\n", addr, dclist[i].port); + } +#endif + if (ss.ss_family == AF_INET) { + d_printf("%s:%d\n", addr, dclist[i].port); + } } } } @@ -81,13 +92,14 @@ static int net_lookup_ldap(int argc, const char **argv) { #ifdef HAVE_ADS const char *domain; - struct in_addr addr; - struct hostent *hostent; + struct sockaddr_storage ss; struct dns_rr_srv *dcs = NULL; int numdcs = 0; char *sitename; TALLOC_CTX *ctx; NTSTATUS status; + int ret; + char h_name[HOST_NAME_MAX]; if (argc > 0) domain = argv[0]; @@ -113,22 +125,26 @@ static int net_lookup_ldap(int argc, const char **argv) } DEBUG(9, ("Looking up PDC for domain %s\n", domain)); - if (!get_pdc_ip(domain, &addr)) { + if (!get_pdc_ip(domain, &ss)) { TALLOC_FREE( ctx ); SAFE_FREE(sitename); return -1; } - hostent = gethostbyaddr((char *) &addr.s_addr, sizeof(addr.s_addr), - AF_INET); - if (!hostent) { + ret = getnameinfo((struct sockaddr *)&ss, + sizeof(struct sockaddr_storage), + h_name, sizeof(h_name), + NULL, 0, + NI_NAMEREQD); + + if (ret) { TALLOC_FREE( ctx ); SAFE_FREE(sitename); return -1; } - DEBUG(9, ("Found PDC with DNS name %s\n", hostent->h_name)); - domain = strchr(hostent->h_name, '.'); + DEBUG(9, ("Found PDC with DNS name %s\n", h_name)); + domain = strchr(h_name, '.'); if (!domain) { TALLOC_FREE( ctx ); SAFE_FREE(sitename); @@ -158,11 +174,12 @@ static int net_lookup_ldap(int argc, const char **argv) static int net_lookup_dc(int argc, const char **argv) { struct ip_service *ip_list; - struct in_addr addr; + struct sockaddr_storage ss; char *pdc_str = NULL; const char *domain = NULL; char *sitename = NULL; int count, i; + char addr[INET6_ADDRSTRLEN]; bool sec_ads = (lp_security() == SEC_ADS); if (sec_ads) { @@ -175,23 +192,25 @@ static int net_lookup_dc(int argc, const char **argv) domain=argv[0]; /* first get PDC */ - if (!get_pdc_ip(domain, &addr)) + if (!get_pdc_ip(domain, &ss)) return -1; - asprintf(&pdc_str, "%s", inet_ntoa(addr)); + print_sockaddr(addr, sizeof(addr), &ss); + asprintf(&pdc_str, "%s", addr); d_printf("%s\n", pdc_str); sitename = sitename_fetch(domain); - if (!NT_STATUS_IS_OK(get_sorted_dc_list(domain, sitename, &ip_list, &count, sec_ads))) { + if (!NT_STATUS_IS_OK(get_sorted_dc_list(domain, sitename, + &ip_list, &count, sec_ads))) { SAFE_FREE(pdc_str); SAFE_FREE(sitename); return 0; } SAFE_FREE(sitename); for (i=0;i<count;i++) { - char *dc_str = inet_ntoa(ip_list[i].ip); - if (!strequal(pdc_str, dc_str)) - d_printf("%s\n", dc_str); + print_sockaddr(addr, sizeof(addr), &ip_list[i].ss); + if (!strequal(pdc_str, addr)) + d_printf("%s\n", addr); } SAFE_FREE(pdc_str); return 0; @@ -199,10 +218,11 @@ static int net_lookup_dc(int argc, const char **argv) static int net_lookup_pdc(int argc, const char **argv) { - struct in_addr addr; + struct sockaddr_storage ss; char *pdc_str = NULL; const char *domain; - + char addr[INET6_ADDRSTRLEN]; + if (lp_security() == SEC_ADS) { domain = lp_realm(); } else { @@ -213,10 +233,11 @@ static int net_lookup_pdc(int argc, const char **argv) domain=argv[0]; /* first get PDC */ - if (!get_pdc_ip(domain, &addr)) + if (!get_pdc_ip(domain, &ss)) return -1; - asprintf(&pdc_str, "%s", inet_ntoa(addr)); + print_sockaddr(addr, sizeof(addr), &ss); + asprintf(&pdc_str, "%s", addr); d_printf("%s\n", pdc_str); SAFE_FREE(pdc_str); return 0; @@ -225,15 +246,17 @@ static int net_lookup_pdc(int argc, const char **argv) static int net_lookup_master(int argc, const char **argv) { - struct in_addr master_ip; + struct sockaddr_storage master_ss; const char *domain=opt_target_workgroup; + char addr[INET6_ADDRSTRLEN]; if (argc > 0) domain=argv[0]; - if (!find_master_ip(domain, &master_ip)) + if (!find_master_ip(domain, &master_ss)) return -1; - d_printf("%s\n", inet_ntoa(master_ip)); + print_sockaddr(addr, sizeof(addr), &master_ss); + d_printf("%s\n", addr); return 0; } diff --git a/source3/utils/net_rpc.c b/source3/utils/net_rpc.c index bf5e4c6b6d..5c5bb97bf6 100644 --- a/source3/utils/net_rpc.c +++ b/source3/utils/net_rpc.c @@ -3728,7 +3728,7 @@ static NTSTATUS rpc_share_migrate_files_internals(const DOM_SID *domain_sid, /* open share source */ nt_status = connect_to_service(&cp_clistate.cli_share_src, - &cli->dest_ip, cli->desthost, + &cli->dest_ss, cli->desthost, netname, "A:"); if (!NT_STATUS_IS_OK(nt_status)) goto done; @@ -5590,13 +5590,13 @@ static int rpc_trustdom_del(int argc, const char **argv) static int rpc_trustdom_establish(int argc, const char **argv) { struct cli_state *cli = NULL; - struct in_addr server_ip; + struct sockaddr_storage server_ss; struct rpc_pipe_client *pipe_hnd = NULL; POLICY_HND connect_hnd; TALLOC_CTX *mem_ctx; NTSTATUS nt_status; DOM_SID *domain_sid; - + char* domain_name; char* domain_name_pol; char* acct_name; @@ -5617,7 +5617,7 @@ static int rpc_trustdom_establish(int argc, const char **argv) /* account name used at first is our domain's name with '$' */ asprintf(&acct_name, "%s$", lp_workgroup()); strupper_m(acct_name); - + /* * opt_workgroup will be used by connection functions further, * hence it should be set to remote domain name instead of ours @@ -5625,17 +5625,17 @@ static int rpc_trustdom_establish(int argc, const char **argv) if (opt_workgroup) { opt_workgroup = smb_xstrdup(domain_name); }; - + opt_user_name = acct_name; /* find the domain controller */ - if (!net_find_pdc(&server_ip, pdc_name, domain_name)) { + if (!net_find_pdc(&server_ss, pdc_name, domain_name)) { DEBUG(0, ("Couldn't find domain controller for domain %s\n", domain_name)); return -1; } /* connect to ipc$ as username/password */ - nt_status = connect_to_ipc(&cli, &server_ip, pdc_name); + nt_status = connect_to_ipc(&cli, &server_ss, pdc_name); if (!NT_STATUS_EQUAL(nt_status, NT_STATUS_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT)) { /* Is it trusting domain account for sure ? */ @@ -5647,12 +5647,12 @@ static int rpc_trustdom_establish(int argc, const char **argv) /* store who we connected to */ saf_store( domain_name, pdc_name ); - + /* * Connect to \\server\ipc$ again (this time anonymously) */ - - nt_status = connect_to_ipc_anonymous(&cli, &server_ip, (char*)pdc_name); + + nt_status = connect_to_ipc_anonymous(&cli, &server_ss, (char*)pdc_name); if (NT_STATUS_IS_ERR(nt_status)) { DEBUG(0, ("Couldn't connect to domain %s controller. Error was %s.\n", @@ -6316,23 +6316,23 @@ bool net_rpc_check(unsigned flags) { struct cli_state *cli; bool ret = False; - struct in_addr server_ip; + struct sockaddr_storage server_ss; char *server_name = NULL; NTSTATUS status; /* flags (i.e. server type) may depend on command */ - if (!net_find_server(NULL, flags, &server_ip, &server_name)) + if (!net_find_server(NULL, flags, &server_ss, &server_name)) return False; if ((cli = cli_initialise()) == NULL) { return False; } - status = cli_connect(cli, server_name, &server_ip); + status = cli_connect(cli, server_name, &server_ss); if (!NT_STATUS_IS_OK(status)) goto done; - if (!attempt_netbios_session_request(&cli, global_myname(), - server_name, &server_ip)) + if (!attempt_netbios_session_request(&cli, global_myname(), + server_name, &server_ss)) goto done; if (!cli_negprot(cli)) goto done; diff --git a/source3/utils/net_rpc_join.c b/source3/utils/net_rpc_join.c index b32fa27284..0c25a53365 100644 --- a/source3/utils/net_rpc_join.c +++ b/source3/utils/net_rpc_join.c @@ -41,7 +41,7 @@ * **/ NTSTATUS net_rpc_join_ok(const char *domain, const char *server, - struct in_addr *ip) + struct sockaddr_storage *pss) { enum security_types sec; unsigned int conn_flags = NET_FLAGS_PDC; @@ -65,7 +65,7 @@ NTSTATUS net_rpc_join_ok(const char *domain, const char *server, } /* Connect to remote machine */ - ntret = net_make_ipc_connection_ex(domain, server, ip, conn_flags, &cli); + ntret = net_make_ipc_connection_ex(domain, server, pss, conn_flags, &cli); if (!NT_STATUS_IS_OK(ntret)) { return ntret; } @@ -425,7 +425,7 @@ int net_rpc_join_newstyle(int argc, const char **argv) } /* double-check, connection from scratch */ - result = net_rpc_join_ok(domain, cli->desthost, &cli->dest_ip); + result = net_rpc_join_ok(domain, cli->desthost, &cli->dest_ss); retval = NT_STATUS_IS_OK(result) ? 0 : -1; done: diff --git a/source3/utils/net_rpc_printer.c b/source3/utils/net_rpc_printer.c index 20821cd2e6..d14caad975 100644 --- a/source3/utils/net_rpc_printer.c +++ b/source3/utils/net_rpc_printer.c @@ -1689,7 +1689,7 @@ NTSTATUS rpc_printer_migrate_drivers_internals(const DOM_SID *domain_sid, NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; uint32 i, p; uint32 num_printers; - uint32 level = 3; + uint32 level = 3; pstring printername = "", sharename = ""; bool got_hnd_src = False; bool got_hnd_dst = False; @@ -1703,7 +1703,7 @@ NTSTATUS rpc_printer_migrate_drivers_internals(const DOM_SID *domain_sid, struct cli_state *cli_share_src = NULL; struct cli_state *cli_share_dst = NULL; fstring drivername = ""; - + ZERO_STRUCT(drv_ctr_src); ZERO_STRUCT(drv_ctr_dst); ZERO_STRUCT(info_ctr_enum); @@ -1715,21 +1715,20 @@ NTSTATUS rpc_printer_migrate_drivers_internals(const DOM_SID *domain_sid, nt_status = connect_dst_pipe(&cli_dst, &pipe_hnd_dst, PI_SPOOLSS); if (!NT_STATUS_IS_OK(nt_status)) return nt_status; - /* open print$-share on the src server */ - nt_status = connect_to_service(&cli_share_src, &cli->dest_ip, + nt_status = connect_to_service(&cli_share_src, &cli->dest_ss, cli->desthost, "print$", "A:"); - if (!NT_STATUS_IS_OK(nt_status)) + if (!NT_STATUS_IS_OK(nt_status)) goto done; got_src_driver_share = True; /* open print$-share on the dst server */ - nt_status = connect_to_service(&cli_share_dst, &cli_dst->dest_ip, + nt_status = connect_to_service(&cli_share_dst, &cli_dst->dest_ss, cli_dst->desthost, "print$", "A:"); - if (!NT_STATUS_IS_OK(nt_status)) + if (!NT_STATUS_IS_OK(nt_status)) return nt_status; got_dst_driver_share = True; diff --git a/source3/utils/net_time.c b/source3/utils/net_time.c index 510807730e..7375206af6 100644 --- a/source3/utils/net_time.c +++ b/source3/utils/net_time.c @@ -23,7 +23,7 @@ /* return the time on a server. This does not require any authentication */ -static time_t cli_servertime(const char *host, struct in_addr *ip, int *zone) +static time_t cli_servertime(const char *host, struct sockaddr_storage *pss, int *zone) { struct nmb_name calling, called; time_t ret = 0; @@ -35,7 +35,7 @@ static time_t cli_servertime(const char *host, struct in_addr *ip, int *zone) goto done; } - status = cli_connect(cli, host, ip); + status = cli_connect(cli, host, pss); if (!NT_STATUS_IS_OK(status)) { fprintf(stderr,"Can't contact server %s. Error %s\n", host, nt_errstr(status)); goto done; @@ -83,9 +83,9 @@ static const char *systime(time_t t) if (!tm) { return "unknown"; } - - fstr_sprintf(s, "%02d%02d%02d%02d%04d.%02d", - tm->tm_mon+1, tm->tm_mday, tm->tm_hour, + + fstr_sprintf(s, "%02d%02d%02d%02d%04d.%02d", + tm->tm_mon+1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_year + 1900, tm->tm_sec); return s; } @@ -110,8 +110,8 @@ static int net_time_set(int argc, const char **argv) int result; if (t == 0) return -1; - - /* yes, I know this is cheesy. Use "net time system" if you want to + + /* yes, I know this is cheesy. Use "net time system" if you want to roll your own. I'm putting this in as it works on a large number of systems and the user has a choice in whether its used or not */ asprintf(&cmd, "/bin/date %s", systime(t)); diff --git a/source3/utils/netlookup.c b/source3/utils/netlookup.c index 315a89d5a8..90f99e4c8b 100644 --- a/source3/utils/netlookup.c +++ b/source3/utils/netlookup.c @@ -56,11 +56,15 @@ static int cs_destructor(struct con_struct *p) static struct con_struct *create_cs(TALLOC_CTX *ctx, NTSTATUS *perr) { NTSTATUS nt_status; - struct in_addr loopback_ip; + struct sockaddr_storage loopback_ss; - loopback_ip.s_addr = htonl(INADDR_LOOPBACK); *perr = NT_STATUS_OK; + if (!interpret_string_addr(&loopback_ss, "127.0.0.1", AI_NUMERICHOST)) { + *perr = NT_STATUS_INVALID_PARAMETER; + return NULL; + } + if (cs) { if (cs->failed_connect) { *perr = cs->err; @@ -90,7 +94,7 @@ static struct con_struct *create_cs(TALLOC_CTX *ctx, NTSTATUS *perr) #endif nt_status = cli_full_connection(&cs->cli, global_myname(), global_myname(), - &loopback_ip, 0, + &loopback_ss, 0, "IPC$", "IPC", #if 0 opt_user_name, diff --git a/source3/utils/nmblookup.c b/source3/utils/nmblookup.c index 1a26e81206..e68c786ce9 100644 --- a/source3/utils/nmblookup.c +++ b/source3/utils/nmblookup.c @@ -1,55 +1,66 @@ -/* +/* Unix SMB/CIFS implementation. NBT client - used to lookup netbios names Copyright (C) Andrew Tridgell 1994-1998 Copyright (C) Jelmer Vernooij 2003 (Conversion to popt) - + 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 3 of the License, or (at your option) any later version. - + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. - + */ #include "includes.h" extern bool AllowDebugChange; -static bool give_flags = False; -static bool use_bcast = True; -static bool got_bcast = False; -static struct in_addr bcast_addr; -static bool recursion_desired = False; -static bool translate_addresses = False; +static bool give_flags = false; +static bool use_bcast = true; +static bool got_bcast = false; +static struct sockaddr_storage bcast_addr; +static bool recursion_desired = false; +static bool translate_addresses = false; static int ServerFD= -1; -static bool RootPort = False; -static bool find_status=False; +static bool RootPort = false; +static bool find_status = false; /**************************************************************************** - open the socket communication - **************************************************************************/ + Open the socket communication. +**************************************************************************/ + static bool open_sockets(void) { - ServerFD = open_socket_in( SOCK_DGRAM, - (RootPort ? 137 : 0), - (RootPort ? 0 : 3), - interpret_addr(lp_socket_address()), True ); + struct sockaddr_storage ss; + const char *sock_addr = lp_socket_address(); + + if (!interpret_string_addr(&ss, sock_addr, + AI_NUMERICHOST|AI_PASSIVE)) { + DEBUG(0,("open_sockets: unable to get socket address " + "from string %s", sock_addr)); + return false; + } + ServerFD = open_socket_in( SOCK_DGRAM, + (RootPort ? 137 : 0), + (RootPort ? 0 : 3), + &ss, true ); - if (ServerFD == -1) - return(False); + if (ServerFD == -1) { + return false; + } - set_socket_options( ServerFD, "SO_BROADCAST" ); + set_socket_options( ServerFD, "SO_BROADCAST" ); - DEBUG(3, ("Socket opened.\n")); - return True; + DEBUG(3, ("Socket opened.\n")); + return true; } /**************************************************************************** @@ -59,7 +70,7 @@ static char *node_status_flags(unsigned char flags) { static fstring ret; fstrcpy(ret,""); - + fstrcat(ret, (flags & 0x80) ? "<GROUP> " : " "); if ((flags & 0x60) == 0x00) fstrcat(ret,"B "); if ((flags & 0x60) == 0x20) fstrcat(ret,"P "); @@ -69,13 +80,14 @@ static char *node_status_flags(unsigned char flags) if (flags & 0x08) fstrcat(ret,"<CONFLICT> "); if (flags & 0x04) fstrcat(ret,"<ACTIVE> "); if (flags & 0x02) fstrcat(ret,"<PERMANENT> "); - + return ret; } /**************************************************************************** -turn the NMB Query flags into a string + Turn the NMB Query flags into a string. ****************************************************************************/ + static char *query_flags(int flags) { static fstring ret1; @@ -92,24 +104,32 @@ static char *query_flags(int flags) } /**************************************************************************** -do a node status query + Do a node status query. ****************************************************************************/ -static void do_node_status(int fd, const char *name, int type, struct in_addr ip) + +static void do_node_status(int fd, + const char *name, + int type, + struct sockaddr_storage *pss) { struct nmb_name nname; int count, i, j; NODE_STATUS_STRUCT *status; struct node_status_extra extra; fstring cleanname; + char addr[INET6_ADDRSTRLEN]; - d_printf("Looking up status of %s\n",inet_ntoa(ip)); + print_sockaddr(addr, sizeof(addr), pss); + d_printf("Looking up status of %s\n",addr); make_nmb_name(&nname, name, type); - status = node_status_query(fd,&nname,ip, &count, &extra); + status = node_status_query(fd, &nname, pss, &count, &extra); if (status) { for (i=0;i<count;i++) { pull_ascii_fstring(cleanname, status[i].name); for (j=0;cleanname[j];j++) { - if (!isprint((int)cleanname[j])) cleanname[j] = '.'; + if (!isprint((int)cleanname[j])) { + cleanname[j] = '.'; + } } d_printf("\t%-15s <%02x> - %s\n", cleanname,status[i].type, @@ -122,60 +142,80 @@ static void do_node_status(int fd, const char *name, int type, struct in_addr ip d_printf("\n"); SAFE_FREE(status); } else { - d_printf("No reply from %s\n\n",inet_ntoa(ip)); + d_printf("No reply from %s\n\n",addr); } } /**************************************************************************** -send out one query + Send out one query. ****************************************************************************/ + static bool query_one(const char *lookup, unsigned int lookup_type) { int j, count, flags = 0; - struct in_addr *ip_list=NULL; + struct sockaddr_storage *ip_list=NULL; if (got_bcast) { - d_printf("querying %s on %s\n", lookup, inet_ntoa(bcast_addr)); + char addr[INET6_ADDRSTRLEN]; + print_sockaddr(addr, sizeof(addr), &bcast_addr); + d_printf("querying %s on %s\n", lookup, addr); ip_list = name_query(ServerFD,lookup,lookup_type,use_bcast, - use_bcast?True:recursion_desired, - bcast_addr,&count, &flags, NULL); + use_bcast?true:recursion_desired, + &bcast_addr, &count, &flags, NULL); } else { const struct in_addr *bcast; for (j=iface_count() - 1; !ip_list && j >= 0; j--) { + char addr[INET6_ADDRSTRLEN]; + struct sockaddr_storage bcast_ss; + bcast = iface_n_bcast_v4(j); if (!bcast) { continue; } - d_printf("querying %s on %s\n", - lookup, inet_ntoa(*bcast)); + in_addr_to_sockaddr_storage(&bcast_ss, *bcast); + print_sockaddr(addr, sizeof(addr), &bcast_ss); + d_printf("querying %s on %s\n", + lookup, addr); ip_list = name_query(ServerFD,lookup,lookup_type, use_bcast, use_bcast?True:recursion_desired, - *bcast,&count, &flags, NULL); + &bcast_ss,&count, &flags, NULL); } } - if (!ip_list) return False; + if (!ip_list) { + return false; + } - if (give_flags) - d_printf("Flags: %s\n", query_flags(flags)); + if (give_flags) { + d_printf("Flags: %s\n", query_flags(flags)); + } for (j=0;j<count;j++) { + char addr[INET6_ADDRSTRLEN]; if (translate_addresses) { - struct hostent *host = gethostbyaddr((char *)&ip_list[j], sizeof(ip_list[j]), AF_INET); - if (host) { - d_printf("%s, ", host -> h_name); + char h_name[HOST_NAME_MAX]; + h_name[0] = '\0'; + if (getnameinfo((const struct sockaddr *)&ip_list[j], + sizeof(struct sockaddr_storage), + h_name, sizeof(h_name), + NULL, 0, + NI_NAMEREQD)) { + continue; } + d_printf("%s, ", h_name); } - d_printf("%s %s<%02x>\n",inet_ntoa(ip_list[j]),lookup, lookup_type); + print_sockaddr(addr, sizeof(addr), &ip_list[j]); + d_printf("%s %s<%02x>\n", addr,lookup, lookup_type); /* We can only do find_status if the ip address returned was valid - ie. name_query returned true. */ if (find_status) { - do_node_status(ServerFD, lookup, lookup_type, ip_list[j]); + do_node_status(ServerFD, lookup, + lookup_type, &ip_list[j]); } } @@ -190,130 +230,140 @@ static bool query_one(const char *lookup, unsigned int lookup_type) ****************************************************************************/ int main(int argc,char *argv[]) { - int opt; - unsigned int lookup_type = 0x0; - fstring lookup; - static bool find_master=False; - static bool lookup_by_ip = False; - poptContext pc; - TALLOC_CTX *frame = talloc_stackframe(); - - struct poptOption long_options[] = { - POPT_AUTOHELP - { "broadcast", 'B', POPT_ARG_STRING, NULL, 'B', "Specify address to use for broadcasts", "BROADCAST-ADDRESS" }, - { "flags", 'f', POPT_ARG_NONE, NULL, 'f', "List the NMB flags returned" }, - { "unicast", 'U', POPT_ARG_STRING, NULL, 'U', "Specify address to use for unicast" }, - { "master-browser", 'M', POPT_ARG_NONE, NULL, 'M', "Search for a master browser" }, - { "recursion", 'R', POPT_ARG_VAL, NULL, 'R', "Set recursion desired in package" }, - { "status", 'S', POPT_ARG_VAL, NULL, 'S', "Lookup node status as well" }, - { "translate", 'T', POPT_ARG_NONE, NULL, 'T', "Translate IP addresses into names" }, - { "root-port", 'r', POPT_ARG_VAL, NULL, 'r', "Use root port 137 (Win95 only replies to this)" }, - { "lookup-by-ip", 'A', POPT_ARG_VAL, NULL, 'A', "Do a node status on <name> as an IP Address" }, - POPT_COMMON_SAMBA - POPT_COMMON_CONNECTION - { 0, 0, 0, 0 } - }; - - *lookup = 0; - - load_case_tables(); - - setup_logging(argv[0],True); - - pc = poptGetContext("nmblookup", argc, (const char **)argv, long_options, - POPT_CONTEXT_KEEP_FIRST); - - poptSetOtherOptionHelp(pc, "<NODE> ..."); - - while ((opt = poptGetNextOpt(pc)) != -1) { - switch (opt) { - case 'f': - give_flags = true; - break; - case 'M': - find_master = true; - break; - case 'R': - recursion_desired = true; - break; - case 'S': - find_status = true; - break; - case 'r': - RootPort = true; - break; - case 'A': - lookup_by_ip = true; - break; - case 'B': - bcast_addr = *interpret_addr2(poptGetOptArg(pc)); - got_bcast = True; - use_bcast = True; - break; - case 'U': - bcast_addr = *interpret_addr2(poptGetOptArg(pc)); - got_bcast = True; - use_bcast = False; - break; - case 'T': - translate_addresses = !translate_addresses; - break; - } - } - - poptGetArg(pc); /* Remove argv[0] */ - - if(!poptPeekArg(pc)) { - poptPrintUsage(pc, stderr, 0); - exit(1); - } - - if (!lp_load(dyn_CONFIGFILE,True,False,False,True)) { - fprintf(stderr, "Can't load %s - run testparm to debug it\n", dyn_CONFIGFILE); - } - - load_interfaces(); - if (!open_sockets()) return(1); - - while(poptPeekArg(pc)) - { - char *p; - struct in_addr ip; - - fstrcpy(lookup,poptGetArg(pc)); - - if(lookup_by_ip) - { - ip = *interpret_addr2(lookup); - fstrcpy(lookup,"*"); - do_node_status(ServerFD, lookup, lookup_type, ip); - continue; - } - - if (find_master) { - if (*lookup == '-') { - fstrcpy(lookup,"\01\02__MSBROWSE__\02"); - lookup_type = 1; - } else { - lookup_type = 0x1d; - } - } - - p = strchr_m(lookup,'#'); - if (p) { - *p = '\0'; - sscanf(++p,"%x",&lookup_type); - } - - if (!query_one(lookup, lookup_type)) { - d_printf( "name_query failed to find name %s", lookup ); - if( 0 != lookup_type ) - d_printf( "#%02x", lookup_type ); - d_printf( "\n" ); - } - } - - poptFreeContext(pc); - TALLOC_FREE(frame); - return(0); + int opt; + unsigned int lookup_type = 0x0; + fstring lookup; + static bool find_master=False; + static bool lookup_by_ip = False; + poptContext pc; + TALLOC_CTX *frame = talloc_stackframe(); + + struct poptOption long_options[] = { + POPT_AUTOHELP + { "broadcast", 'B', POPT_ARG_STRING, NULL, 'B', "Specify address to use for broadcasts", "BROADCAST-ADDRESS" }, + { "flags", 'f', POPT_ARG_NONE, NULL, 'f', "List the NMB flags returned" }, + { "unicast", 'U', POPT_ARG_STRING, NULL, 'U', "Specify address to use for unicast" }, + { "master-browser", 'M', POPT_ARG_NONE, NULL, 'M', "Search for a master browser" }, + { "recursion", 'R', POPT_ARG_VAL, NULL, 'R', "Set recursion desired in package" }, + { "status", 'S', POPT_ARG_VAL, NULL, 'S', "Lookup node status as well" }, + { "translate", 'T', POPT_ARG_NONE, NULL, 'T', "Translate IP addresses into names" }, + { "root-port", 'r', POPT_ARG_VAL, NULL, 'r', "Use root port 137 (Win95 only replies to this)" }, + { "lookup-by-ip", 'A', POPT_ARG_VAL, NULL, 'A', "Do a node status on <name> as an IP Address" }, + POPT_COMMON_SAMBA + POPT_COMMON_CONNECTION + { 0, 0, 0, 0 } + }; + + *lookup = 0; + + load_case_tables(); + + setup_logging(argv[0],True); + + pc = poptGetContext("nmblookup", argc, (const char **)argv, + long_options, POPT_CONTEXT_KEEP_FIRST); + + poptSetOtherOptionHelp(pc, "<NODE> ..."); + + while ((opt = poptGetNextOpt(pc)) != -1) { + switch (opt) { + case 'f': + give_flags = true; + break; + case 'M': + find_master = true; + break; + case 'R': + recursion_desired = true; + break; + case 'S': + find_status = true; + break; + case 'r': + RootPort = true; + break; + case 'A': + lookup_by_ip = true; + break; + case 'B': + if (interpret_string_addr(&bcast_addr, + poptGetOptArg(pc), + NI_NUMERICHOST)) { + got_bcast = True; + use_bcast = True; + } + break; + case 'U': + if (interpret_string_addr(&bcast_addr, + poptGetOptArg(pc), + 0)) { + got_bcast = True; + use_bcast = False; + } + break; + case 'T': + translate_addresses = !translate_addresses; + break; + } + } + + poptGetArg(pc); /* Remove argv[0] */ + + if(!poptPeekArg(pc)) { + poptPrintUsage(pc, stderr, 0); + exit(1); + } + + if (!lp_load(dyn_CONFIGFILE,True,False,False,True)) { + fprintf(stderr, "Can't load %s - run testparm to debug it\n", + dyn_CONFIGFILE); + } + + load_interfaces(); + if (!open_sockets()) { + return(1); + } + + while(poptPeekArg(pc)) { + char *p; + struct in_addr ip; + + fstrcpy(lookup,poptGetArg(pc)); + + if(lookup_by_ip) { + struct sockaddr_storage ss; + ip = *interpret_addr2(lookup); + in_addr_to_sockaddr_storage(&ss, ip); + fstrcpy(lookup,"*"); + do_node_status(ServerFD, lookup, lookup_type, &ss); + continue; + } + + if (find_master) { + if (*lookup == '-') { + fstrcpy(lookup,"\01\02__MSBROWSE__\02"); + lookup_type = 1; + } else { + lookup_type = 0x1d; + } + } + + p = strchr_m(lookup,'#'); + if (p) { + *p = '\0'; + sscanf(++p,"%x",&lookup_type); + } + + if (!query_one(lookup, lookup_type)) { + d_printf( "name_query failed to find name %s", lookup ); + if( 0 != lookup_type ) { + d_printf( "#%02x", lookup_type ); + } + d_printf( "\n" ); + } + } + + poptFreeContext(pc); + TALLOC_FREE(frame); + return(0); } diff --git a/source3/utils/smbcacls.c b/source3/utils/smbcacls.c index b8b29b44eb..d5bf9b96e6 100644 --- a/source3/utils/smbcacls.c +++ b/source3/utils/smbcacls.c @@ -760,16 +760,17 @@ static int cacl_set(struct cli_state *cli, char *filename, } -/***************************************************** -return a connection to a server +/***************************************************** + Return a connection to a server. *******************************************************/ + static struct cli_state *connect_one(const char *share) { struct cli_state *c; - struct in_addr ip; + struct sockaddr_storage ss; NTSTATUS nt_status; - zero_ip_v4(&ip); - + zero_addr(&ss, AF_INET); + if (!cmdline_auth_info.got_pass) { char *pass = getpass("Password: "); if (pass) { @@ -779,8 +780,8 @@ static struct cli_state *connect_one(const char *share) } if (NT_STATUS_IS_OK(nt_status = cli_full_connection(&c, global_myname(), server, - &ip, 0, - share, "?????", + &ss, 0, + share, "?????", cmdline_auth_info.username, lp_workgroup(), cmdline_auth_info.password, 0, cmdline_auth_info.signing_state, NULL))) { diff --git a/source3/utils/smbcquotas.c b/source3/utils/smbcquotas.c index a3d90f823b..f185caa50f 100644 --- a/source3/utils/smbcquotas.c +++ b/source3/utils/smbcquotas.c @@ -352,16 +352,17 @@ static int do_quota(struct cli_state *cli, enum SMB_QUOTA_TYPE qtype, uint16 cmd return 0; } -/***************************************************** -return a connection to a server +/***************************************************** + Return a connection to a server. *******************************************************/ + static struct cli_state *connect_one(const char *share) { struct cli_state *c; - struct in_addr ip; + struct sockaddr_storage ss; NTSTATUS nt_status; - zero_ip_v4(&ip); - + zero_addr(&ss, AF_INET); + if (!cmdline_auth_info.got_pass) { char *pass = getpass("Password: "); if (pass) { @@ -371,8 +372,8 @@ static struct cli_state *connect_one(const char *share) } if (NT_STATUS_IS_OK(nt_status = cli_full_connection(&c, global_myname(), server, - &ip, 0, - share, "?????", + &ss, 0, + share, "?????", cmdline_auth_info.username, lp_workgroup(), cmdline_auth_info.password, 0, cmdline_auth_info.signing_state, NULL))) { |