s3:net ads dns register: add support for specifying addresse on the commandline ...
authorMichael Adam <obnox@samba.org>
Thu, 16 Dec 2010 00:49:14 +0000 (01:49 +0100)
committerKarolin Seeger <kseeger@samba.org>
Sat, 5 Mar 2011 13:34:44 +0000 (14:34 +0100)
In the clustering case, this is also made the only possiblity to do dns updates,
since the list addresses on the local interfaces is not suitable in that case.

This fixes the "net ads dns register" part of bug #7871.
It might be extended by a parsing of the "cluster addresses" setting.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
(cherry picked from commit 5e83a05009787d8a2086db1adc1ed58d61b3725d)
(cherry picked from commit 9ed3d33fb3d7365a127ea2752032840272697902)
(cherry picked from commit 5e708489d56bc7a2b0a033a38e62bed519249b33)

source3/utils/net_ads.c

index 75b115e28bcd63590cb95e2b3f92c8b966bb8500..a432570cc014db6c5515c2e95b5ba484ac81b894 100644 (file)
@@ -1463,15 +1463,27 @@ static int net_ads_dns_register(struct net_context *c, int argc, const char **ar
 #if defined(WITH_DNS_UPDATES)
        ADS_STRUCT *ads;
        ADS_STATUS status;
+       NTSTATUS ntstatus;
        TALLOC_CTX *ctx;
+       const char *hostname = NULL;
+       struct sockaddr_storage *addrs = NULL;
+       int num_addrs = 0;
+       int count;
 
 #ifdef DEVELOPER
        talloc_enable_leak_report();
 #endif
 
-       if (argc > 1 || c->display_usage) {
+       if (argc <= 1 && lp_clustering()) {
+               d_fprintf(stderr, _("Refusing DNS updates with automatic "
+                                   "detection of addresses in a clustered "
+                                   "setup.\n"));
+               c->display_usage = true;
+       }
+
+       if (c->display_usage) {
                d_printf(  "%s\n"
-                          "net ads dns register [hostname]\n"
+                          "net ads dns register [hostname [IP [IP...]]]\n"
                           "    %s\n",
                         _("Usage:"),
                         _("Register hostname with DNS\n"));
@@ -1483,6 +1495,30 @@ static int net_ads_dns_register(struct net_context *c, int argc, const char **ar
                return -1;
        }
 
+       if (argc >= 1) {
+               hostname = argv[0];
+       }
+
+       if (argc > 1) {
+               num_addrs = argc - 1;
+               addrs = talloc_zero_array(ctx, struct sockaddr_storage, num_addrs);
+               if (addrs == NULL) {
+                       d_fprintf(stderr, _("Error allocating memory!\n"));
+                       talloc_free(ctx);
+                       return -1;
+               }
+       }
+
+       for (count = 0; count < num_addrs; count++) {
+               if (!interpret_string_addr(&addrs[count], argv[count+1], 0)) {
+                       d_fprintf(stderr, "%s '%s'.\n",
+                                         _("Cannot interpret address"),
+                                         argv[count+1]);
+                       talloc_free(ctx);
+                       return -1;
+               }
+       }
+
        status = ads_startup(c, true, &ads);
        if ( !ADS_ERR_OK(status) ) {
                DEBUG(1, ("error on ads_startup: %s\n", ads_errstr(status)));
@@ -1490,7 +1526,8 @@ static int net_ads_dns_register(struct net_context *c, int argc, const char **ar
                return -1;
        }
 
-       if ( !NT_STATUS_IS_OK(net_update_dns(ctx, ads, argc == 1 ? argv[0] : NULL)) ) {
+       ntstatus = net_update_dns_ext(ctx, ads, hostname, addrs, num_addrs);
+       if (!NT_STATUS_IS_OK(ntstatus)) {
                d_fprintf( stderr, _("DNS update failed!\n") );
                ads_destroy( &ads );
                TALLOC_FREE( ctx );