s3-net Allow 'net ads dns register' to take an optional hostname argument
authorAndrew Bartlett <abartlet@samba.org>
Fri, 10 Dec 2010 04:08:53 +0000 (15:08 +1100)
committerKarolin Seeger <kseeger@samba.org>
Sat, 5 Mar 2011 13:34:43 +0000 (14:34 +0100)
This allows the administrator to more carefully chose what name to register.

Andrew Bartlett
(cherry picked from commit c2a1ad9047508cf2745a9019e6783c8b8f7ef475)
(cherry picked from commit 10c5a59315ef69eeb4d8bc19237de9787284a63d)

Signed-off-by: Stefan Metzmacher <metze@samba.org>
(cherry picked from commit bce7e8c8e11321d98a30a8b6bb79a392a5e644ba)

source3/utils/net_ads.c

index b618ab81b9169e2a64871f636bc8e500b7d00eee..6b354ed66f598a38569249a446ef6f305c53c3c4 100644 (file)
@@ -1197,14 +1197,18 @@ done:
        return status;
 }
 
-static NTSTATUS net_update_dns(TALLOC_CTX *mem_ctx, ADS_STRUCT *ads)
+static NTSTATUS net_update_dns(TALLOC_CTX *mem_ctx, ADS_STRUCT *ads, const char *hostname)
 {
        int num_addrs;
        struct sockaddr_storage *iplist = NULL;
        fstring machine_name;
        NTSTATUS status;
 
-       name_to_fqdn( machine_name, global_myname() );
+       if (hostname) {
+               fstrcpy(machine_name, hostname);
+       } else {
+               name_to_fqdn( machine_name, global_myname() );
+       }
        strlower_m( machine_name );
 
        /* Get our ip address (not the 127.0.0.x address but a real ip
@@ -1394,7 +1398,7 @@ int net_ads_join(struct net_context *c, int argc, const char **argv)
                        ads_kinit_password( ads_dns );
                }
 
-               if ( !ads_dns || !NT_STATUS_IS_OK(net_update_dns( ctx, ads_dns )) ) {
+               if ( !ads_dns || !NT_STATUS_IS_OK(net_update_dns( ctx, ads_dns, NULL)) ) {
                        d_fprintf( stderr, _("DNS update failed!\n") );
                }
 
@@ -1431,9 +1435,9 @@ static int net_ads_dns_register(struct net_context *c, int argc, const char **ar
        talloc_enable_leak_report();
 #endif
 
-       if (argc > 0 || c->display_usage) {
+       if (argc > 1 || c->display_usage) {
                d_printf(  "%s\n"
-                          "net ads dns register\n"
+                          "net ads dns register [hostname]\n"
                           "    %s\n",
                         _("Usage:"),
                         _("Register hostname with DNS\n"));
@@ -1452,7 +1456,7 @@ 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)) ) {
+       if ( !NT_STATUS_IS_OK(net_update_dns(ctx, ads, argc == 1 ? argv[0] : NULL)) ) {
                d_fprintf( stderr, _("DNS update failed!\n") );
                ads_destroy( &ads );
                TALLOC_FREE( ctx );