Changeset 596 for trunk/server/source3/utils/net_ads.c
- Timestamp:
- Jul 2, 2011, 3:35:33 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/server/source3/utils/net_ads.c
r590 r596 1198 1198 } 1199 1199 1200 static NTSTATUS net_update_dns(TALLOC_CTX *mem_ctx, ADS_STRUCT *ads) 1201 { 1202 int num_addrs; 1203 struct sockaddr_storage *iplist = NULL; 1200 static 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; 1204 1206 fstring machine_name; 1205 1207 NTSTATUS status; 1206 1208 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 } 1208 1214 strlower_m( machine_name ); 1209 1215 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; 1218 1228 } 1219 1229 1220 1230 status = net_update_dns_internal(mem_ctx, ads, machine_name, 1221 1231 iplist, num_addrs); 1222 SAFE_FREE( iplist ); 1232 1233 SAFE_FREE(iplist_alloc); 1234 return status; 1235 } 1236 1237 static 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); 1223 1242 return status; 1224 1243 } … … 1377 1396 1378 1397 #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 1379 1415 if (r->out.domain_is_ad) { 1380 1416 /* We enter this block with user creds */ … … 1395 1431 } 1396 1432 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)) ) { 1398 1434 d_fprintf( stderr, _("DNS update failed!\n") ); 1399 1435 } … … 1403 1439 } 1404 1440 #endif 1441 1442 done: 1405 1443 TALLOC_FREE(r); 1406 1444 TALLOC_FREE( ctx ); … … 1426 1464 ADS_STRUCT *ads; 1427 1465 ADS_STATUS status; 1466 NTSTATUS ntstatus; 1428 1467 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; 1429 1473 1430 1474 #ifdef DEVELOPER … … 1432 1476 #endif 1433 1477 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) { 1435 1486 d_printf( "%s\n" 1436 "net ads dns register \n"1487 "net ads dns register [hostname [IP [IP...]]]\n" 1437 1488 " %s\n", 1438 1489 _("Usage:"), … … 1444 1495 d_fprintf(stderr, _("Could not initialise talloc context\n")); 1445 1496 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 } 1446 1528 } 1447 1529 … … 1453 1535 } 1454 1536 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)) { 1456 1539 d_fprintf( stderr, _("DNS update failed!\n") ); 1457 1540 ads_destroy( &ads );
Note:
See TracChangeset
for help on using the changeset viewer.