Ignore:
Timestamp:
Nov 24, 2016, 1:14:11 PM (9 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: update vendor to version 4.4.3

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vendor/current/source4/dsdb/dns/dns_update.c

    r740 r988  
    3636#include "param/param.h"
    3737#include "system/filesys.h"
     38#include "dsdb/common/util.h"
    3839#include "libcli/composite/composite.h"
    3940#include "libcli/security/dom_sid.h"
    4041#include "librpc/gen_ndr/ndr_irpc.h"
     42#include "libds/common/roles.h"
     43
     44NTSTATUS server_service_dnsupdate_init(void);
    4145
    4246struct dnsupdate_service {
     
    7882        TALLOC_FREE(subreq);
    7983        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);
    8185        } else {
    8286                service->confupdate.status = NT_STATUS_OK;
     
    98102        int ret;
    99103        size_t size;
    100         struct ldb_result *res;
     104        struct ldb_result *res1, *res2;
    101105        const char *tmp_path, *path, *path_static;
    102106        char *static_policies;
    103107        int fd;
    104108        unsigned int i;
    105         const char *attrs[] = { "sAMAccountName", NULL };
     109        const char *attrs1[] = { "msDS-HasDomainNCs", NULL };
     110        const char *attrs2[] = { "name", NULL };
    106111        const char *realm = lpcfg_realm(service->task->lp_ctx);
    107112        TALLOC_CTX *tmp_ctx = talloc_new(service);
    108113        const char * const *rndc_command = lpcfg_rndc_command(service->task->lp_ctx);
     114        const char **dc_list;
     115        int dc_count=0;
    109116
    110117        /* abort any pending script run */
    111118        TALLOC_FREE(service->confupdate.subreq);
    112119
    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)))");
    116126        if (ret != LDB_SUCCESS) {
    117127                DEBUG(0,(__location__ ": Unable to find DCs list - %s", ldb_errstring(service->samdb)));
     
    120130        }
    121131
     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
    122171        path = lpcfg_parm_string(service->task->lp_ctx, NULL, "dnsupdate", "path");
    123172        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");
    125174        }
    126175
    127176        path_static = lpcfg_parm_string(service->task->lp_ctx, NULL, "dnsupdate", "extra_static_grant_rules");
    128177        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");
    130179        }
    131180
     
    155204        }
    156205        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]);
    165210        }
    166211        dprintf(fd, "};\n");
     
    241286        TALLOC_FREE(subreq);
    242287        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);
    244289        } else {
    245290                service->nameupdate.status = NT_STATUS_OK;
     
    270315        TALLOC_FREE(subreq);
    271316        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);
    273318        } else {
    274319                service->nameupdate.status = NT_STATUS_OK;
     
    354399        struct dnsupdate_RODC *r;
    355400        char *tmp_path;
     401        char *tmp_path2;
    356402        int fd;
    357403};
     
    363409        }
    364410        unlink(st->tmp_path);
     411        if (st->tmp_path2 != NULL) {
     412                unlink(st->tmp_path2);
     413        }
    365414        return 0;
    366415}
     
    380429        talloc_free(req);
    381430        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);
    383432                DEBUG(2,(__location__ ": RODC DNS Update failed: %s\n", nt_errstr(st->r->out.result)));
    384433        } else {
     
    409458        int i, ret;
    410459        struct GUID ntds_guid;
    411         const char *site, *dnsdomain, *dnsforest, *ntdsguid, *hostname;
     460        const char *site, *dnsdomain, *dnsforest, *ntdsguid;
     461        const char *hostname = NULL;
    412462        struct ldb_dn *sid_dn;
    413463        const char *attrs[] = { "dNSHostName", NULL };
     
    439489
    440490        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        }
    441498
    442499        sid_dn = ldb_dn_new_fmt(st, s->samdb, "<SID=%s>", dom_sid_string(st, r->in.dom_sid));
     
    532589                                "--update-list",
    533590                                st->tmp_path,
     591                                "--update-cache",
     592                                st->tmp_path2,
    534593                                NULL);
    535594        NT_STATUS_HAVE_NO_MEMORY(req);
     
    551610        struct dnsupdate_service *service;
    552611
    553         if (lpcfg_server_role(task->lp_ctx) != ROLE_DOMAIN_CONTROLLER) {
     612        if (lpcfg_server_role(task->lp_ctx) != ROLE_ACTIVE_DIRECTORY_DC) {
    554613                /* not useful for non-DC */
    555614                return;
Note: See TracChangeset for help on using the changeset viewer.