Ignore:
Timestamp:
Jul 2, 2011, 3:35:33 PM (14 years ago)
Author:
Herwig Bauernfeind
Message:

Samba 3.5: Update trunk to 3.5.8

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/server/source3/utils/net_ads.c

    r590 r596  
    11981198}
    11991199
    1200 static NTSTATUS net_update_dns(TALLOC_CTX *mem_ctx, ADS_STRUCT *ads)
    1201 {
    1202         int num_addrs;
    1203         struct sockaddr_storage *iplist = NULL;
     1200static NTSTATUS net_update_dns_ext(TALLOC_CTX *mem_ctx, ADS_STRUCT *ads,
     1201                                   const char *hostname,
     1202                                   struct sockaddr_storage *iplist,
     1203                                   int num_addrs)
     1204{
     1205        struct sockaddr_storage *iplist_alloc = NULL;
    12041206        fstring machine_name;
    12051207        NTSTATUS status;
    12061208
    1207         name_to_fqdn( machine_name, global_myname() );
     1209        if (hostname) {
     1210                fstrcpy(machine_name, hostname);
     1211        } else {
     1212                name_to_fqdn( machine_name, global_myname() );
     1213        }
    12081214        strlower_m( machine_name );
    12091215
    1210         /* Get our ip address (not the 127.0.0.x address but a real ip
    1211          * address) */
    1212 
    1213         num_addrs = get_my_ip_address( &iplist );
    1214         if ( num_addrs <= 0 ) {
    1215                 DEBUG(4,("net_update_dns: Failed to find my non-loopback IP "
    1216                          "addresses!\n"));
    1217                 return NT_STATUS_INVALID_PARAMETER;
     1216        if (num_addrs == 0 || iplist == NULL) {
     1217                /*
     1218                 * Get our ip address
     1219                 * (not the 127.0.0.x address but a real ip address)
     1220                 */
     1221                num_addrs = get_my_ip_address(&iplist_alloc);
     1222                if ( num_addrs <= 0 ) {
     1223                        DEBUG(4, ("net_update_dns_ext: Failed to find my "
     1224                                  "non-loopback IP addresses!\n"));
     1225                        return NT_STATUS_INVALID_PARAMETER;
     1226                }
     1227                iplist = iplist_alloc;
    12181228        }
    12191229
    12201230        status = net_update_dns_internal(mem_ctx, ads, machine_name,
    12211231                                         iplist, num_addrs);
    1222         SAFE_FREE( iplist );
     1232
     1233        SAFE_FREE(iplist_alloc);
     1234        return status;
     1235}
     1236
     1237static NTSTATUS net_update_dns(TALLOC_CTX *mem_ctx, ADS_STRUCT *ads, const char *hostname)
     1238{
     1239        NTSTATUS status;
     1240
     1241        status = net_update_dns_ext(mem_ctx, ads, hostname, NULL, 0);
    12231242        return status;
    12241243}
     
    13771396
    13781397#if defined(WITH_DNS_UPDATES)
     1398        /*
     1399         * In a clustered environment, don't do dynamic dns updates:
     1400         * Registering the set of ip addresses that are assigned to
     1401         * the interfaces of the node that performs the join does usually
     1402         * not have the desired effect, since the local interfaces do not
     1403         * carry the complete set of the cluster's public IP addresses.
     1404         * And it can also contain internal addresses that should not
     1405         * be visible to the outside at all.
     1406         * In order to do dns updates in a clustererd setup, use
     1407         * net ads dns register.
     1408         */
     1409        if (lp_clustering()) {
     1410                d_fprintf(stderr, _("Not doing automatic DNS update in a"
     1411                                    "clustered setup.\n"));
     1412                goto done;
     1413        }
     1414
    13791415        if (r->out.domain_is_ad) {
    13801416                /* We enter this block with user creds */
     
    13951431                }
    13961432
    1397                 if ( !ads_dns || !NT_STATUS_IS_OK(net_update_dns( ctx, ads_dns )) ) {
     1433                if ( !ads_dns || !NT_STATUS_IS_OK(net_update_dns( ctx, ads_dns, NULL)) ) {
    13981434                        d_fprintf( stderr, _("DNS update failed!\n") );
    13991435                }
     
    14031439        }
    14041440#endif
     1441
     1442done:
    14051443        TALLOC_FREE(r);
    14061444        TALLOC_FREE( ctx );
     
    14261464        ADS_STRUCT *ads;
    14271465        ADS_STATUS status;
     1466        NTSTATUS ntstatus;
    14281467        TALLOC_CTX *ctx;
     1468        const char *hostname = NULL;
     1469        const char **addrs_list = NULL;
     1470        struct sockaddr_storage *addrs = NULL;
     1471        int num_addrs = 0;
     1472        int count;
    14291473
    14301474#ifdef DEVELOPER
     
    14321476#endif
    14331477
    1434         if (argc > 0 || c->display_usage) {
     1478        if (argc <= 1 && lp_clustering() && lp_cluster_addresses() == NULL) {
     1479                d_fprintf(stderr, _("Refusing DNS updates with automatic "
     1480                                    "detection of addresses in a clustered "
     1481                                    "setup.\n"));
     1482                c->display_usage = true;
     1483        }
     1484
     1485        if (c->display_usage) {
    14351486                d_printf(  "%s\n"
    1436                            "net ads dns register\n"
     1487                           "net ads dns register [hostname [IP [IP...]]]\n"
    14371488                           "    %s\n",
    14381489                         _("Usage:"),
     
    14441495                d_fprintf(stderr, _("Could not initialise talloc context\n"));
    14451496                return -1;
     1497        }
     1498
     1499        if (argc >= 1) {
     1500                hostname = argv[0];
     1501        }
     1502
     1503        if (argc > 1) {
     1504                num_addrs = argc - 1;
     1505                addrs_list = &argv[1];
     1506        } else if (lp_clustering()) {
     1507                addrs_list = lp_cluster_addresses();
     1508                num_addrs = str_list_length(addrs_list);
     1509        }
     1510
     1511        if (num_addrs > 0) {
     1512                addrs = talloc_zero_array(ctx, struct sockaddr_storage, num_addrs);
     1513                if (addrs == NULL) {
     1514                        d_fprintf(stderr, _("Error allocating memory!\n"));
     1515                        talloc_free(ctx);
     1516                        return -1;
     1517                }
     1518        }
     1519
     1520        for (count = 0; count < num_addrs; count++) {
     1521                if (!interpret_string_addr(&addrs[count], addrs_list[count], 0)) {
     1522                        d_fprintf(stderr, "%s '%s'.\n",
     1523                                          _("Cannot interpret address"),
     1524                                          addrs_list[count]);
     1525                        talloc_free(ctx);
     1526                        return -1;
     1527                }
    14461528        }
    14471529
     
    14531535        }
    14541536
    1455         if ( !NT_STATUS_IS_OK(net_update_dns(ctx, ads)) ) {
     1537        ntstatus = net_update_dns_ext(ctx, ads, hostname, addrs, num_addrs);
     1538        if (!NT_STATUS_IS_OK(ntstatus)) {
    14561539                d_fprintf( stderr, _("DNS update failed!\n") );
    14571540                ads_destroy( &ads );
Note: See TracChangeset for help on using the changeset viewer.