Changeset 988 for vendor/current/source4/dsdb/dns
- Timestamp:
- Nov 24, 2016, 1:14:11 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vendor/current/source4/dsdb/dns/dns_update.c
r740 r988 36 36 #include "param/param.h" 37 37 #include "system/filesys.h" 38 #include "dsdb/common/util.h" 38 39 #include "libcli/composite/composite.h" 39 40 #include "libcli/security/dom_sid.h" 40 41 #include "librpc/gen_ndr/ndr_irpc.h" 42 #include "libds/common/roles.h" 43 44 NTSTATUS server_service_dnsupdate_init(void); 41 45 42 46 struct dnsupdate_service { … … 78 82 TALLOC_FREE(subreq); 79 83 if (ret != 0) { 80 service->confupdate.status = map_nt_error_from_unix (sys_errno);84 service->confupdate.status = map_nt_error_from_unix_common(sys_errno); 81 85 } else { 82 86 service->confupdate.status = NT_STATUS_OK; … … 98 102 int ret; 99 103 size_t size; 100 struct ldb_result *res ;104 struct ldb_result *res1, *res2; 101 105 const char *tmp_path, *path, *path_static; 102 106 char *static_policies; 103 107 int fd; 104 108 unsigned int i; 105 const char *attrs[] = { "sAMAccountName", NULL }; 109 const char *attrs1[] = { "msDS-HasDomainNCs", NULL }; 110 const char *attrs2[] = { "name", NULL }; 106 111 const char *realm = lpcfg_realm(service->task->lp_ctx); 107 112 TALLOC_CTX *tmp_ctx = talloc_new(service); 108 113 const char * const *rndc_command = lpcfg_rndc_command(service->task->lp_ctx); 114 const char **dc_list; 115 int dc_count=0; 109 116 110 117 /* abort any pending script run */ 111 118 TALLOC_FREE(service->confupdate.subreq); 112 119 113 ret = ldb_search(service->samdb, tmp_ctx, &res, NULL, LDB_SCOPE_SUBTREE, 114 attrs, "(|(samaccountname=administrator)(&(primaryGroupID=%u)(objectClass=computer)))", 115 DOMAIN_RID_DCS); 120 /* find the DNs for all the non-RODC DCs in the forest */ 121 ret = dsdb_search(service->samdb, tmp_ctx, &res1, ldb_get_config_basedn(service->samdb), 122 LDB_SCOPE_SUBTREE, 123 attrs1, 124 0, 125 "(&(objectclass=NTDSDSA)(!(msDS-isRODC=TRUE)))"); 116 126 if (ret != LDB_SUCCESS) { 117 127 DEBUG(0,(__location__ ": Unable to find DCs list - %s", ldb_errstring(service->samdb))); … … 120 130 } 121 131 132 dc_list = talloc_array(tmp_ctx, const char *, 0); 133 for (i=0; i<res1->count; i++) { 134 struct ldb_dn *server_dn = res1->msgs[i]->dn; 135 struct ldb_dn *domain_dn; 136 const char *acct_name, *full_account, *dns_domain; 137 138 /* this is a nasty hack to form the account name of 139 * this DC. We do it this way as we don't necessarily 140 * have access to the domain NC, so all we have to go 141 * on is what is in the configuration partition 142 */ 143 144 domain_dn = ldb_msg_find_attr_as_dn(service->samdb, tmp_ctx, res1->msgs[i], "msDS-HasDomainNCs"); 145 if (domain_dn == NULL) continue; 146 147 ldb_dn_remove_child_components(server_dn, 1); 148 ret = dsdb_search_dn(service->samdb, tmp_ctx, &res2, server_dn, attrs2, 0); 149 if (ret != LDB_SUCCESS) { 150 continue; 151 } 152 153 acct_name = ldb_msg_find_attr_as_string(res2->msgs[0], "name", NULL); 154 if (acct_name == NULL) continue; 155 156 dns_domain = samdb_dn_to_dns_domain(tmp_ctx, domain_dn); 157 if (dns_domain == NULL) { 158 continue; 159 } 160 161 full_account = talloc_asprintf(tmp_ctx, "%s$@%s", acct_name, dns_domain); 162 if (full_account == NULL) continue; 163 164 dc_list = talloc_realloc(tmp_ctx, dc_list, const char *, dc_count+1); 165 if (dc_list == NULL) { 166 continue; 167 } 168 dc_list[dc_count++] = full_account; 169 } 170 122 171 path = lpcfg_parm_string(service->task->lp_ctx, NULL, "dnsupdate", "path"); 123 172 if (path == NULL) { 124 path = private_path(tmp_ctx, service->task->lp_ctx, "named.conf.update");173 path = lpcfg_private_path(tmp_ctx, service->task->lp_ctx, "named.conf.update"); 125 174 } 126 175 127 176 path_static = lpcfg_parm_string(service->task->lp_ctx, NULL, "dnsupdate", "extra_static_grant_rules"); 128 177 if (path_static == NULL) { 129 path_static = private_path(tmp_ctx, service->task->lp_ctx, "named.conf.update.static");178 path_static = lpcfg_private_path(tmp_ctx, service->task->lp_ctx, "named.conf.update.static"); 130 179 } 131 180 … … 155 204 } 156 205 dprintf(fd, "\tgrant %s ms-self * A AAAA;\n", realm); 157 158 for (i=0; i<res->count; i++) { 159 const char *acctname; 160 acctname = ldb_msg_find_attr_as_string(res->msgs[i], 161 "sAMAccountName", NULL); 162 if (!acctname) continue; 163 dprintf(fd, "\tgrant %s@%s wildcard * A AAAA SRV CNAME;\n", 164 acctname, realm); 206 dprintf(fd, "\tgrant Administrator@%s wildcard * A AAAA SRV CNAME;\n", realm); 207 208 for (i=0; i<dc_count; i++) { 209 dprintf(fd, "\tgrant %s wildcard * A AAAA SRV CNAME;\n", dc_list[i]); 165 210 } 166 211 dprintf(fd, "};\n"); … … 241 286 TALLOC_FREE(subreq); 242 287 if (ret != 0) { 243 service->nameupdate.status = map_nt_error_from_unix (sys_errno);288 service->nameupdate.status = map_nt_error_from_unix_common(sys_errno); 244 289 } else { 245 290 service->nameupdate.status = NT_STATUS_OK; … … 270 315 TALLOC_FREE(subreq); 271 316 if (ret != 0) { 272 service->nameupdate.status = map_nt_error_from_unix (sys_errno);317 service->nameupdate.status = map_nt_error_from_unix_common(sys_errno); 273 318 } else { 274 319 service->nameupdate.status = NT_STATUS_OK; … … 354 399 struct dnsupdate_RODC *r; 355 400 char *tmp_path; 401 char *tmp_path2; 356 402 int fd; 357 403 }; … … 363 409 } 364 410 unlink(st->tmp_path); 411 if (st->tmp_path2 != NULL) { 412 unlink(st->tmp_path2); 413 } 365 414 return 0; 366 415 } … … 380 429 talloc_free(req); 381 430 if (ret != 0) { 382 st->r->out.result = map_nt_error_from_unix (sys_errno);431 st->r->out.result = map_nt_error_from_unix_common(sys_errno); 383 432 DEBUG(2,(__location__ ": RODC DNS Update failed: %s\n", nt_errstr(st->r->out.result))); 384 433 } else { … … 409 458 int i, ret; 410 459 struct GUID ntds_guid; 411 const char *site, *dnsdomain, *dnsforest, *ntdsguid, *hostname; 460 const char *site, *dnsdomain, *dnsforest, *ntdsguid; 461 const char *hostname = NULL; 412 462 struct ldb_dn *sid_dn; 413 463 const char *attrs[] = { "dNSHostName", NULL }; … … 439 489 440 490 talloc_set_destructor(st, dnsupdate_RODC_destructor); 491 492 st->tmp_path2 = talloc_asprintf(st, "%s.cache", st->tmp_path); 493 if (!st->tmp_path2) { 494 talloc_free(st); 495 r->out.result = NT_STATUS_NO_MEMORY; 496 return NT_STATUS_OK; 497 } 441 498 442 499 sid_dn = ldb_dn_new_fmt(st, s->samdb, "<SID=%s>", dom_sid_string(st, r->in.dom_sid)); … … 532 589 "--update-list", 533 590 st->tmp_path, 591 "--update-cache", 592 st->tmp_path2, 534 593 NULL); 535 594 NT_STATUS_HAVE_NO_MEMORY(req); … … 551 610 struct dnsupdate_service *service; 552 611 553 if (lpcfg_server_role(task->lp_ctx) != ROLE_ DOMAIN_CONTROLLER) {612 if (lpcfg_server_role(task->lp_ctx) != ROLE_ACTIVE_DIRECTORY_DC) { 554 613 /* not useful for non-DC */ 555 614 return;
Note:
See TracChangeset
for help on using the changeset viewer.