Fix all warnings in source3 with gcc4.3.
[ira/wip.git] / source3 / utils / net_lookup.c
index 20298faa299520b36268960f26a114628690ebb8..66f673b8d32fc7dbbb760ca07666e11ba4773ac5 100644 (file)
@@ -19,7 +19,7 @@
 #include "includes.h"
 #include "utils/net.h"
 
-int net_lookup_usage(int argc, const char **argv)
+int net_lookup_usage(struct net_context *c, int argc, const char **argv)
 {
        d_printf(
 "  net lookup [host] HOSTNAME[#<type>]\n\tgives IP for a hostname\n\n"
@@ -36,7 +36,7 @@ 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)
+static int net_lookup_host(struct net_context *c, int argc, const char **argv)
 {
        struct sockaddr_storage ss;
        int name_type = 0x20;
@@ -45,7 +45,7 @@ static int net_lookup_host(int argc, const char **argv)
        char *p;
 
        if (argc == 0)
-               return net_lookup_usage(argc, argv);
+               return net_lookup_usage(c, argc, argv);
 
        p = strchr_m(name,'#');
        if (p) {
@@ -88,7 +88,7 @@ static void print_ldap_srvlist(struct dns_rr_srv *dclist, int numdcs )
 }
 #endif
 
-static int net_lookup_ldap(int argc, const char **argv)
+static int net_lookup_ldap(struct net_context *c, int argc, const char **argv)
 {
 #ifdef HAVE_ADS
        const char *domain;
@@ -104,7 +104,7 @@ static int net_lookup_ldap(int argc, const char **argv)
        if (argc > 0)
                domain = argv[0];
        else
-               domain = opt_target_workgroup;
+               domain = c->opt_target_workgroup;
 
        sitename = sitename_fetch(domain);
 
@@ -171,7 +171,7 @@ static int net_lookup_ldap(int argc, const char **argv)
        return -1;
 }
 
-static int net_lookup_dc(int argc, const char **argv)
+static int net_lookup_dc(struct net_context *c, int argc, const char **argv)
 {
        struct ip_service *ip_list;
        struct sockaddr_storage ss;
@@ -185,7 +185,7 @@ static int net_lookup_dc(int argc, const char **argv)
        if (sec_ads) {
                domain = lp_realm();
        } else {
-               domain = opt_target_workgroup;
+               domain = c->opt_target_workgroup;
        }
 
        if (argc > 0)
@@ -196,7 +196,9 @@ static int net_lookup_dc(int argc, const char **argv)
                return -1;
 
        print_sockaddr(addr, sizeof(addr), &ss);
-       asprintf(&pdc_str, "%s", addr);
+       if (asprintf(&pdc_str, "%s", addr) == -1) {
+               return -1;
+       }
        d_printf("%s\n", pdc_str);
 
        sitename = sitename_fetch(domain);
@@ -216,7 +218,7 @@ static int net_lookup_dc(int argc, const char **argv)
        return 0;
 }
 
-static int net_lookup_pdc(int argc, const char **argv)
+static int net_lookup_pdc(struct net_context *c, int argc, const char **argv)
 {
        struct sockaddr_storage ss;
        char *pdc_str = NULL;
@@ -226,7 +228,7 @@ static int net_lookup_pdc(int argc, const char **argv)
        if (lp_security() == SEC_ADS) {
                domain = lp_realm();
        } else {
-               domain = opt_target_workgroup;
+               domain = c->opt_target_workgroup;
        }
 
        if (argc > 0)
@@ -237,17 +239,19 @@ static int net_lookup_pdc(int argc, const char **argv)
                return -1;
 
        print_sockaddr(addr, sizeof(addr), &ss);
-       asprintf(&pdc_str, "%s", addr);
+       if (asprintf(&pdc_str, "%s", addr) == -1) {
+               return -1;
+       }
        d_printf("%s\n", pdc_str);
        SAFE_FREE(pdc_str);
        return 0;
 }
 
 
-static int net_lookup_master(int argc, const char **argv)
+static int net_lookup_master(struct net_context *c, int argc, const char **argv)
 {
        struct sockaddr_storage master_ss;
-       const char *domain=opt_target_workgroup;
+       const char *domain = c->opt_target_workgroup;
        char addr[INET6_ADDRSTRLEN];
 
        if (argc > 0)
@@ -260,7 +264,7 @@ static int net_lookup_master(int argc, const char **argv)
        return 0;
 }
 
-static int net_lookup_kdc(int argc, const char **argv)
+static int net_lookup_kdc(struct net_context *c, int argc, const char **argv)
 {
 #ifdef HAVE_KRB5
        krb5_error_code rc;
@@ -273,7 +277,7 @@ static int net_lookup_kdc(int argc, const char **argv)
        initialize_krb5_error_table();
        rc = krb5_init_context(&ctx);
        if (rc) {
-               DEBUG(1,("krb5_init_context failed (%s)\n", 
+               DEBUG(1,("krb5_init_context failed (%s)\n",
                         error_message(rc)));
                return -1;
        }
@@ -311,7 +315,7 @@ static int net_lookup_kdc(int argc, const char **argv)
        return -1;
 }
 
-static int net_lookup_name(int argc, const char **argv)
+static int net_lookup_name(struct net_context *c, int argc, const char **argv)
 {
        const char *dom, *name;
        DOM_SID sid;
@@ -333,7 +337,7 @@ static int net_lookup_name(int argc, const char **argv)
        return 0;
 }
 
-static int net_lookup_sid(int argc, const char **argv)
+static int net_lookup_sid(struct net_context *c, int argc, const char **argv)
 {
        const char *dom, *name;
        DOM_SID sid;
@@ -360,14 +364,15 @@ static int net_lookup_sid(int argc, const char **argv)
        return 0;
 }
 
-static int net_lookup_dsgetdcname(int argc, const char **argv)
+static int net_lookup_dsgetdcname(struct net_context *c, int argc, const char **argv)
 {
        NTSTATUS status;
        const char *domain_name = NULL;
-       char *site_name = NULL;
+       const char *site_name = NULL;
        uint32_t flags = 0;
-       struct DS_DOMAIN_CONTROLLER_INFO *info = NULL;
+       struct netr_DsRGetDCNameInfo *info = NULL;
        TALLOC_CTX *mem_ctx;
+       char *s = NULL;
 
        if (argc < 1 || argc > 3) {
                d_printf("usage: net lookup dsgetdcname "
@@ -390,36 +395,28 @@ static int net_lookup_dsgetdcname(int argc, const char **argv)
        }
 
        if (argc == 3) {
-               site_name = SMB_STRDUP(argv[2]);
-               if (!site_name) {
-                       TALLOC_FREE(mem_ctx);
-                       return -1;
-               }
-       }
-
-       if (!site_name) {
-               site_name = sitename_fetch(domain_name);
+               site_name = argv[2];
        }
 
-       status = DsGetDcName(mem_ctx, NULL, domain_name, NULL, site_name,
+       status = dsgetdcname(mem_ctx, NULL, domain_name, NULL, site_name,
                             flags, &info);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("failed with: %s\n", nt_errstr(status));
-               SAFE_FREE(site_name);
                TALLOC_FREE(mem_ctx);
                return -1;
        }
 
-       display_ds_domain_controller_info(mem_ctx, info);
+       s = NDR_PRINT_STRUCT_STRING(mem_ctx, netr_DsRGetDCNameInfo, info);
+       printf("%s\n", s);
+       TALLOC_FREE(s);
 
-       SAFE_FREE(site_name);
        TALLOC_FREE(mem_ctx);
        return 0;
 }
 
 
 /* lookup hosts or IP addresses using internal samba lookup fns */
-int net_lookup(int argc, const char **argv)
+int net_lookup(struct net_context *c, int argc, const char **argv)
 {
        int i;
 
@@ -438,17 +435,17 @@ int net_lookup(int argc, const char **argv)
 
        if (argc < 1) {
                d_printf("\nUsage: \n");
-               return net_lookup_usage(argc, argv);
+               return net_lookup_usage(c, 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);
+                       return table[i].fn(c, argc-1, argv+1);
        }
 
-       /* Default to lookup a hostname so 'net lookup foo#1b' can be 
+       /* 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 
+          is a bit confusing as non #00 names can't really be
           considered hosts as such. */
 
-       return net_lookup_host(argc, argv);
+       return net_lookup_host(c, argc, argv);
 }