X-Git-Url: http://git.samba.org/samba.git/?a=blobdiff_plain;f=source3%2Futils%2Fnet_lookup.c;h=9ddfe62508129681ee149125038ac555ed86376f;hb=39be2680e008931ff8372a978ac2d8d705c5e03a;hp=eedc2c7f929f92bce68341a73e9a00f87d84ea0a;hpb=b1bce451411486525e72ec71c5fd37fc0b463add;p=ira%2Fwip.git diff --git a/source3/utils/net_lookup.c b/source3/utils/net_lookup.c index eedc2c7f929..9ddfe625081 100644 --- a/source3/utils/net_lookup.c +++ b/source3/utils/net_lookup.c @@ -18,12 +18,12 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "includes.h" -#include "../utils/net.h" +#include "utils/net.h" int net_lookup_usage(int argc, const char **argv) { d_printf( -" net lookup host HOSTNAME \n\tgives IP for a hostname\n\n" +" net lookup [host] HOSTNAME[#]\n\tgives IP for a hostname\n\n" " net lookup ldap [domain]\n\tgives IP of domain's ldap server\n\n" " net lookup kdc [realm]\n\tgives IP of realm's kerberos KDC\n\n" " net lookup dc [domain]\n\tgives IP of domains Domain Controllers\n\n" @@ -37,14 +37,22 @@ static int net_lookup_host(int argc, const char **argv) { struct in_addr ip; int name_type = 0x20; + const char *name = argv[0]; + char *p; - if (argc == 0) return net_lookup_usage(argc, argv); - if (argc > 1) name_type = strtol(argv[1], NULL, 0); + if (argc == 0) + return net_lookup_usage(argc, argv); - if (!resolve_name(argv[0], &ip, name_type)) { + p = strchr_m(name,'#'); + if (p) { + *p = '\0'; + sscanf(++p,"%x",&name_type); + } + + if (!resolve_name(name, &ip, 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", argv[0], name_type)); + DEBUG(0,("Didn't find %s#%02x\n", name, name_type)); return -1; } @@ -124,11 +132,11 @@ static int net_lookup_ldap(int argc, const char **argv) static int net_lookup_dc(int argc, const char **argv) { - struct in_addr *ip_list, addr; + struct ip_service *ip_list; + struct in_addr addr; char *pdc_str = NULL; const char *domain=opt_target_workgroup; int count, i; - BOOL list_ordered; if (argc > 0) domain=argv[0]; @@ -140,12 +148,12 @@ static int net_lookup_dc(int argc, const char **argv) asprintf(&pdc_str, "%s", inet_ntoa(addr)); d_printf("%s\n", pdc_str); - if (!get_dc_list(domain, &ip_list, &count, &list_ordered)) { + if (!get_sorted_dc_list(domain, &ip_list, &count, False)) { SAFE_FREE(pdc_str); return 0; } for (i=0;i0) { - realm.data = (krb5_pointer) argv[0]; + realm.data = CONST_DISCARD(krb5_pointer, argv[0]); realm.length = strlen(argv[0]); } else if (lp_realm() && *lp_realm()) { realm.data = (krb5_pointer) lp_realm(); @@ -201,7 +209,7 @@ static int net_lookup_kdc(int argc, const char **argv) realm.length = strlen(realm.data); } - rc = krb5_locate_kdc(ctx, &realm, (struct sockaddr **)&addrs, &num_kdcs, 0); + rc = krb5_locate_kdc(ctx, &realm, (struct sockaddr **) &addrs, &num_kdcs, 0); if (rc) { DEBUG(1, ("krb5_locate_kdc failed (%s)\n", error_message(rc))); return -1; @@ -221,7 +229,9 @@ static int net_lookup_kdc(int argc, const char **argv) /* lookup hosts or IP addresses using internal samba lookup fns */ int net_lookup(int argc, const char **argv) { - struct functable func[] = { + int i; + + struct functable table[] = { {"HOST", net_lookup_host}, {"LDAP", net_lookup_ldap}, {"DC", net_lookup_dc}, @@ -230,5 +240,19 @@ int net_lookup(int argc, const char **argv) {NULL, NULL} }; - return net_run_function(argc, argv, func, net_lookup_usage); + if (argc < 1) { + d_printf("\nUsage: \n"); + return net_lookup_usage(argc, argv); + } + for (i=0; table[i].funcname; i++) { + if (StrCaseCmp(argv[0], table[i].funcname) == 0) + return table[i].fn(argc-1, argv+1); + } + + /* Default to lookup a hostname so 'net lookup foo#1b' can be + used instead of 'net lookup host foo#1b'. The host syntax + is a bit confusing as non #00 names can't really be + considered hosts as such. */ + + return net_lookup_host(argc, argv); }