LCOV - code coverage report
Current view: top level - source4/dsdb/samdb/ldb_modules - netlogon.c (source / functions) Hit Total Coverage
Test: coverage report for abartlet/fix-coverage dd10fb34 Lines: 193 221 87.3 %
Date: 2021-09-23 10:06:22 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /* 
       2             :    Unix SMB/CIFS implementation.
       3             : 
       4             :    CLDAP server - netlogon handling
       5             : 
       6             :    Copyright (C) Andrew Tridgell        2005
       7             :    Copyright (C) Andrew Bartlett <abartlet@samba.org> 2008
       8             :    
       9             :    This program is free software; you can redistribute it and/or modify
      10             :    it under the terms of the GNU General Public License as published by
      11             :    the Free Software Foundation; either version 3 of the License, or
      12             :    (at your option) any later version.
      13             :    
      14             :    This program is distributed in the hope that it will be useful,
      15             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      16             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      17             :    GNU General Public License for more details.
      18             :    
      19             :    You should have received a copy of the GNU General Public License
      20             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.
      21             : */
      22             : 
      23             : #include "includes.h"
      24             : #include <ldb.h>
      25             : #include <ldb_errors.h>
      26             : #include "lib/events/events.h"
      27             : #include "samba/service_task.h"
      28             : #include "librpc/gen_ndr/ndr_misc.h"
      29             : #include "libcli/ldap/ldap_ndr.h"
      30             : #include "libcli/security/security.h"
      31             : #include "dsdb/samdb/samdb.h"
      32             : #include "dsdb/samdb/ldb_modules/util.h"
      33             : #include "auth/auth.h"
      34             : #include "ldb_wrap.h"
      35             : #include "system/network.h"
      36             : #include "lib/socket/netif.h"
      37             : #include "param/param.h"
      38             : #include "../lib/tsocket/tsocket.h"
      39             : #include "libds/common/flag_mapping.h"
      40             : #include "lib/util/util_net.h"
      41             : 
      42             : #undef strcasecmp
      43             : 
      44             : /*
      45             :   fill in the cldap netlogon union for a given version
      46             : */
      47        2730 : NTSTATUS fill_netlogon_samlogon_response(struct ldb_context *sam_ctx,
      48             :                                          TALLOC_CTX *mem_ctx,
      49             :                                          const char *domain,
      50             :                                          const char *netbios_domain,
      51             :                                          struct dom_sid *domain_sid,
      52             :                                          const char *domain_guid,
      53             :                                          const char *user,
      54             :                                          uint32_t acct_control,
      55             :                                          const char *src_address,
      56             :                                          uint32_t version,
      57             :                                          struct loadparm_context *lp_ctx,
      58             :                                          struct netlogon_samlogon_response *netlogon,
      59             :                                          bool fill_on_blank_request)
      60             : {
      61        2730 :         const char *dom_attrs[] = {"objectGUID", NULL};
      62        2730 :         const char *none_attrs[] = {NULL};
      63        2730 :         struct ldb_result *dom_res = NULL;
      64             :         int ret;
      65        2730 :         const char **services = lpcfg_server_services(lp_ctx);
      66             :         uint32_t server_type;
      67             :         const char *pdc_name;
      68             :         struct GUID domain_uuid;
      69             :         const char *dns_domain;
      70             :         const char *forest_domain;
      71             :         const char *pdc_dns_name;
      72             :         const char *flatname;
      73             :         const char *server_site;
      74             :         const char *client_site;
      75             :         const char *pdc_ip;
      76        2730 :         struct ldb_dn *domain_dn = NULL;
      77             :         struct interface *ifaces;
      78        2730 :         bool user_known = false, am_rodc = false;
      79        2730 :         uint32_t uac = 0;
      80             :         NTSTATUS status;
      81             : 
      82             :         /* the domain parameter could have an optional trailing "." */
      83        2730 :         if (domain && domain[strlen(domain)-1] == '.') {
      84           0 :                 domain = talloc_strndup(mem_ctx, domain, strlen(domain)-1);
      85           0 :                 NT_STATUS_HAVE_NO_MEMORY(domain);
      86             :         }
      87             : 
      88             :         /* Lookup using long or short domainname */
      89        2730 :         if (domain && (strcasecmp_m(domain, lpcfg_dnsdomain(lp_ctx)) == 0)) {
      90        2476 :                 domain_dn = ldb_get_default_basedn(sam_ctx);
      91             :         }
      92        2730 :         if (netbios_domain && (strcasecmp_m(netbios_domain, lpcfg_sam_name(lp_ctx)) == 0)) {
      93         103 :                 domain_dn = ldb_get_default_basedn(sam_ctx);
      94             :         }
      95        2730 :         if (domain_dn) {
      96        2579 :                 const char *domain_identifier = domain != NULL ? domain
      97        2579 :                                                         : netbios_domain;
      98        2579 :                 ret = ldb_search(sam_ctx, mem_ctx, &dom_res,
      99             :                                  domain_dn, LDB_SCOPE_BASE, dom_attrs,
     100             :                                  "objectClass=domain");
     101        2579 :                 if (ret != LDB_SUCCESS) {
     102           0 :                         DEBUG(2,("Error finding domain '%s'/'%s' in sam: %s\n",
     103             :                                  domain_identifier,
     104             :                                  ldb_dn_get_linearized(domain_dn),
     105             :                                  ldb_errstring(sam_ctx)));
     106           0 :                         return NT_STATUS_NO_SUCH_DOMAIN;
     107             :                 }
     108        2579 :                 if (dom_res->count != 1) {
     109           0 :                         DEBUG(2,("Error finding domain '%s'/'%s' in sam\n",
     110             :                                  domain_identifier,
     111             :                                  ldb_dn_get_linearized(domain_dn)));
     112           0 :                         return NT_STATUS_NO_SUCH_DOMAIN;
     113             :                 }
     114             :         }
     115             : 
     116             :         /* Lookup using GUID or SID */
     117        2730 :         if ((dom_res == NULL) && (domain_guid || domain_sid)) {
     118           8 :                 if (domain_guid) {
     119             :                         struct GUID binary_guid;
     120             :                         struct ldb_val guid_val;
     121             : 
     122             :                         /* By this means, we ensure we don't have funny stuff in the GUID */
     123             : 
     124           8 :                         status = GUID_from_string(domain_guid, &binary_guid);
     125           8 :                         if (!NT_STATUS_IS_OK(status)) {
     126           0 :                                 return status;
     127             :                         }
     128             : 
     129             :                         /* And this gets the result into the binary format we want anyway */
     130           8 :                         status = GUID_to_ndr_blob(&binary_guid, mem_ctx, &guid_val);
     131           8 :                         if (!NT_STATUS_IS_OK(status)) {
     132           0 :                                 return status;
     133             :                         }
     134           8 :                         ret = ldb_search(sam_ctx, mem_ctx, &dom_res,
     135             :                                                  NULL, LDB_SCOPE_SUBTREE, 
     136             :                                                  dom_attrs, 
     137             :                                                  "(&(objectCategory=DomainDNS)(objectGUID=%s))", 
     138             :                                                  ldb_binary_encode(mem_ctx, guid_val));
     139             :                 } else { /* domain_sid case */
     140           0 :                         ret = ldb_search(sam_ctx, mem_ctx, &dom_res,
     141             :                                          NULL, LDB_SCOPE_SUBTREE,
     142             :                                          dom_attrs,
     143             :                                          "(&(objectCategory=DomainDNS)(objectSid=%s))",
     144             :                                          dom_sid_string(mem_ctx, domain_sid));
     145             :                 }
     146             :                 
     147           8 :                 if (ret != LDB_SUCCESS) {
     148           0 :                         DEBUG(2,("Unable to find a correct reference to GUID '%s' or SID '%s' in sam: %s\n",
     149             :                                  domain_guid, dom_sid_string(mem_ctx, domain_sid),
     150             :                                  ldb_errstring(sam_ctx)));
     151           0 :                         return NT_STATUS_NO_SUCH_DOMAIN;
     152           8 :                 } else if (dom_res->count == 1) {
     153             :                         /* Ok, now just check it is our domain */
     154           4 :                         if (ldb_dn_compare(ldb_get_default_basedn(sam_ctx),
     155           4 :                                            dom_res->msgs[0]->dn) != 0) {
     156           0 :                                 DEBUG(2,("The GUID '%s' or SID '%s' doesn't identify our domain\n",
     157             :                                          domain_guid,
     158             :                                          dom_sid_string(mem_ctx, domain_sid)));
     159           0 :                                 return NT_STATUS_NO_SUCH_DOMAIN;
     160             :                         }
     161             :                 } else {
     162           4 :                         DEBUG(2,("Unable to find a correct reference to GUID '%s' or SID '%s' in sam\n",
     163             :                                  domain_guid, dom_sid_string(mem_ctx, domain_sid)));
     164           4 :                         return NT_STATUS_NO_SUCH_DOMAIN;
     165             :                 }
     166             :         }
     167             : 
     168        2726 :         if (dom_res == NULL && fill_on_blank_request) {
     169             :                 /* blank inputs gives our domain - tested against
     170             :                    w2k8r2. Without this ADUC on Win7 won't start */
     171         141 :                 domain_dn = ldb_get_default_basedn(sam_ctx);
     172         141 :                 ret = ldb_search(sam_ctx, mem_ctx, &dom_res,
     173             :                                  domain_dn, LDB_SCOPE_BASE, dom_attrs,
     174             :                                  "objectClass=domain");
     175         141 :                 if (ret != LDB_SUCCESS) {
     176           0 :                         DEBUG(2,("Error finding domain '%s'/'%s' in sam: %s\n",
     177             :                                  lpcfg_dnsdomain(lp_ctx),
     178             :                                  ldb_dn_get_linearized(domain_dn),
     179             :                                  ldb_errstring(sam_ctx)));
     180           0 :                         return NT_STATUS_NO_SUCH_DOMAIN;
     181             :                 }
     182             :         }
     183             : 
     184        2726 :         if (dom_res == NULL) {
     185           2 :                 DEBUG(2,(__location__ ": Unable to get domain information with no inputs\n"));
     186           2 :                 return NT_STATUS_NO_SUCH_DOMAIN;
     187             :         }
     188             : 
     189             :         /* work around different inputs for not-specified users */
     190        2724 :         if (!user) {
     191        2021 :                 user = "";
     192             :         }
     193             : 
     194             :         /* Enquire about any valid username with just a CLDAP packet -
     195             :          * if kerberos didn't also do this, the security folks would
     196             :          * scream... */
     197        2724 :         if (user[0]) {
     198             :                 /* Only allow some bits to be enquired:  [MS-ATDS] 7.3.3.2 */
     199         700 :                 if (acct_control == (uint32_t)-1) {
     200         590 :                         acct_control = 0;
     201             :                 }
     202             :                 /*
     203             :                  * ACB_AUTOLOCK/UF_LOCKOUT seems to be a special
     204             :                  * hack for SEC_CHAN_DNS_DOMAIN.
     205             :                  *
     206             :                  * It's used together with user = "example.com."
     207             :                  */
     208         700 :                 if (acct_control != ACB_AUTOLOCK) {
     209         664 :                         acct_control &= (ACB_TEMPDUP | ACB_NORMAL | ACB_DOMTRUST | ACB_WSTRUST | ACB_SVRTRUST);
     210             :                 }
     211         700 :                 uac = ds_acb2uf(acct_control);
     212             :         }
     213             : 
     214        2665 :         if (uac == UF_LOCKOUT) {
     215          36 :                 struct ldb_message *tdo_msg = NULL;
     216             : 
     217             :                 /*
     218             :                  * ACB_AUTOLOCK/UF_LOCKOUT seems to be a special
     219             :                  * hack for SEC_CHAN_DNS_DOMAIN.
     220             :                  *
     221             :                  * It's used together with user = "example.com."
     222             :                  */
     223          36 :                 status = dsdb_trust_search_tdo_by_type(sam_ctx,
     224             :                                                        SEC_CHAN_DNS_DOMAIN,
     225             :                                                        user, none_attrs,
     226             :                                                        mem_ctx, &tdo_msg);
     227          36 :                 if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
     228           0 :                         user_known = false;
     229          36 :                 } else if (NT_STATUS_IS_OK(status)) {
     230          36 :                         TALLOC_FREE(tdo_msg);
     231          36 :                         user_known = true;
     232             :                 } else {
     233           0 :                         DEBUG(2,("Unable to find reference to TDO '%s' - %s\n",
     234             :                                  user, nt_errstr(status)));
     235           0 :                         return status;
     236             :                 }
     237        2688 :         } else if (user[0]) {
     238         664 :                 struct ldb_result *user_res = NULL;
     239             : 
     240             :                 /* We must exclude disabled accounts, but otherwise do the bitwise match the client asked for */
     241        1319 :                 ret = ldb_search(sam_ctx, mem_ctx, &user_res,
     242         664 :                                          dom_res->msgs[0]->dn, LDB_SCOPE_SUBTREE, 
     243             :                                          none_attrs, 
     244             :                                          "(&(objectClass=user)(samAccountName=%s)"
     245             :                                          "(!(userAccountControl:" LDB_OID_COMPARATOR_AND ":=%u))"
     246             :                                          "(userAccountControl:" LDB_OID_COMPARATOR_OR ":=%u))", 
     247             :                                          ldb_binary_encode_string(mem_ctx, user),
     248             :                                          UF_ACCOUNTDISABLE, uac);
     249         664 :                 if (ret != LDB_SUCCESS) {
     250           0 :                         DEBUG(2,("Unable to find reference to user '%s' with ACB 0x%8x under %s: %s\n",
     251             :                                  user, acct_control, ldb_dn_get_linearized(dom_res->msgs[0]->dn),
     252             :                                  ldb_errstring(sam_ctx)));
     253           0 :                         return NT_STATUS_NO_SUCH_USER;
     254         664 :                 } else if (user_res->count == 1) {
     255          60 :                         user_known = true;
     256             :                 } else {
     257         601 :                         user_known = false;
     258             :                 }
     259         664 :                 TALLOC_FREE(user_res);
     260             :         } else {
     261        1965 :                 user_known = true;
     262             :         }
     263             : 
     264        2724 :         server_type = DS_SERVER_DS;
     265             : 
     266        2724 :         if (samdb_is_pdc(sam_ctx)) {
     267        2720 :                 server_type |= DS_SERVER_PDC;
     268             :         }
     269             : 
     270        2724 :         if (samdb_is_gc(sam_ctx)) {
     271        2724 :                 server_type |= DS_SERVER_GC;
     272             :         }
     273             : 
     274        2724 :         if (str_list_check(services, "ldap")) {
     275        2724 :                 server_type |= DS_SERVER_LDAP;
     276             :         }
     277             : 
     278        2724 :         if (str_list_check(services, "kdc")) {
     279        2724 :                 server_type |= DS_SERVER_KDC;
     280             :         }
     281             : 
     282        2724 :         if (str_list_check(services, "ntp_signd")) {
     283        2724 :                 server_type |= DS_SERVER_TIMESERV | DS_SERVER_GOOD_TIMESERV;
     284             :         }
     285             : 
     286        2724 :         if (samdb_rodc(sam_ctx, &am_rodc) == LDB_SUCCESS && !am_rodc) {
     287        2724 :                 server_type |= DS_SERVER_WRITABLE;
     288             :         }
     289             : 
     290        2724 :         if (dsdb_functional_level(sam_ctx) >= DS_DOMAIN_FUNCTION_2008) {
     291        2658 :                 if (server_type & DS_SERVER_WRITABLE) {
     292        2658 :                         server_type |= DS_SERVER_FULL_SECRET_DOMAIN_6;
     293             :                 } else {
     294           0 :                         server_type |= DS_SERVER_SELECT_SECRET_DOMAIN_6;
     295             :                 }
     296             :         }
     297             : 
     298        2724 :         if (version & (NETLOGON_NT_VERSION_5EX|NETLOGON_NT_VERSION_5EX_WITH_IP)) {
     299        2513 :                 pdc_name = lpcfg_netbios_name(lp_ctx);
     300             :         } else {
     301         211 :                 pdc_name = talloc_asprintf(mem_ctx, "\\\\%s",
     302             :                                            lpcfg_netbios_name(lp_ctx));
     303         211 :                 NT_STATUS_HAVE_NO_MEMORY(pdc_name);
     304             :         }
     305        2724 :         domain_uuid      = samdb_result_guid(dom_res->msgs[0], "objectGUID");
     306        2724 :         dns_domain       = lpcfg_dnsdomain(lp_ctx);
     307        2724 :         forest_domain    = samdb_forest_name(sam_ctx, mem_ctx);
     308        2724 :         NT_STATUS_HAVE_NO_MEMORY(forest_domain);
     309        2724 :         pdc_dns_name     = talloc_asprintf(mem_ctx, "%s.%s", 
     310             :                                            strlower_talloc(mem_ctx, 
     311             :                                                            lpcfg_netbios_name(lp_ctx)),
     312             :                                            dns_domain);
     313        2724 :         NT_STATUS_HAVE_NO_MEMORY(pdc_dns_name);
     314        2724 :         flatname         = lpcfg_workgroup(lp_ctx);
     315             : 
     316        2724 :         server_site      = samdb_server_site_name(sam_ctx, mem_ctx);
     317        2724 :         NT_STATUS_HAVE_NO_MEMORY(server_site);
     318        2724 :         client_site      = samdb_client_site_name(sam_ctx, mem_ctx,
     319             :                                                   src_address, NULL,
     320             :                                                   true);
     321        2724 :         NT_STATUS_HAVE_NO_MEMORY(client_site);
     322        2724 :         if (strcasecmp(server_site, client_site) == 0) {
     323        2590 :                 server_type |= DS_SERVER_CLOSEST;
     324             :         }
     325             : 
     326        2724 :         load_interface_list(mem_ctx, lp_ctx, &ifaces);
     327        2724 :         if (src_address) {
     328        2608 :                 pdc_ip = iface_list_best_ip(ifaces, src_address);
     329             :         } else {
     330         116 :                 pdc_ip = iface_list_first_v4(ifaces);
     331             :         }
     332        2724 :         if (pdc_ip == NULL || !is_ipaddress_v4(pdc_ip)) {
     333             :                 /* this matches windows behaviour */
     334         355 :                 pdc_ip = "127.0.0.1";
     335             :         }
     336             : 
     337        2724 :         ZERO_STRUCTP(netlogon);
     338             : 
     339             :         /* check if either of these bits is present */
     340        2724 :         if (version & (NETLOGON_NT_VERSION_5EX|NETLOGON_NT_VERSION_5EX_WITH_IP)) {
     341        2513 :                 uint32_t extra_flags = 0;
     342        2513 :                 netlogon->ntver = NETLOGON_NT_VERSION_5EX;
     343             : 
     344             :                 /* could check if the user exists */
     345        2513 :                 if (user_known) {
     346        2111 :                         netlogon->data.nt5_ex.command      = LOGON_SAM_LOGON_RESPONSE_EX;
     347             :                 } else {
     348         402 :                         netlogon->data.nt5_ex.command      = LOGON_SAM_LOGON_USER_UNKNOWN_EX;
     349             :                 }
     350        2513 :                 netlogon->data.nt5_ex.pdc_name     = pdc_name;
     351        2513 :                 netlogon->data.nt5_ex.user_name    = user;
     352        2513 :                 netlogon->data.nt5_ex.domain_name  = flatname;
     353        2513 :                 netlogon->data.nt5_ex.domain_uuid  = domain_uuid;
     354        2513 :                 netlogon->data.nt5_ex.forest       = forest_domain;
     355        2513 :                 netlogon->data.nt5_ex.dns_domain   = dns_domain;
     356        2513 :                 netlogon->data.nt5_ex.pdc_dns_name = pdc_dns_name;
     357        2513 :                 netlogon->data.nt5_ex.server_site  = server_site;
     358        2513 :                 netlogon->data.nt5_ex.client_site  = client_site;
     359        2513 :                 if (version & NETLOGON_NT_VERSION_5EX_WITH_IP) {
     360             :                         /* note that this is always a IPV4 address */
     361         544 :                         extra_flags = NETLOGON_NT_VERSION_5EX_WITH_IP;
     362         544 :                         netlogon->data.nt5_ex.sockaddr.sockaddr_family    = 2;
     363         544 :                         netlogon->data.nt5_ex.sockaddr.pdc_ip       = pdc_ip;
     364         544 :                         netlogon->data.nt5_ex.sockaddr.remaining = data_blob_talloc_zero(mem_ctx, 8);
     365             :                 }
     366        2513 :                 netlogon->data.nt5_ex.server_type  = server_type;
     367        2513 :                 netlogon->data.nt5_ex.nt_version   = NETLOGON_NT_VERSION_1|NETLOGON_NT_VERSION_5EX|extra_flags;
     368        2513 :                 netlogon->data.nt5_ex.lmnt_token   = 0xFFFF;
     369        2513 :                 netlogon->data.nt5_ex.lm20_token   = 0xFFFF;
     370             : 
     371         211 :         } else if (version & NETLOGON_NT_VERSION_5) {
     372          73 :                 netlogon->ntver = NETLOGON_NT_VERSION_5;
     373             : 
     374             :                 /* could check if the user exists */
     375          73 :                 if (user_known) {
     376           3 :                         netlogon->data.nt5.command      = LOGON_SAM_LOGON_RESPONSE;
     377             :                 } else {
     378          70 :                         netlogon->data.nt5.command      = LOGON_SAM_LOGON_USER_UNKNOWN;
     379             :                 }
     380          73 :                 netlogon->data.nt5.pdc_name     = pdc_name;
     381          73 :                 netlogon->data.nt5.user_name    = user;
     382          73 :                 netlogon->data.nt5.domain_name  = flatname;
     383          73 :                 netlogon->data.nt5.domain_uuid  = domain_uuid;
     384          73 :                 netlogon->data.nt5.forest       = forest_domain;
     385          73 :                 netlogon->data.nt5.dns_domain   = dns_domain;
     386          73 :                 netlogon->data.nt5.pdc_dns_name = pdc_dns_name;
     387          73 :                 netlogon->data.nt5.pdc_ip       = pdc_ip;
     388          73 :                 netlogon->data.nt5.server_type  = server_type;
     389          73 :                 netlogon->data.nt5.nt_version   = NETLOGON_NT_VERSION_1|NETLOGON_NT_VERSION_5;
     390          73 :                 netlogon->data.nt5.lmnt_token   = 0xFFFF;
     391          73 :                 netlogon->data.nt5.lm20_token   = 0xFFFF;
     392             : 
     393             :         } else /* (version & NETLOGON_NT_VERSION_1) and all other cases */ {
     394         138 :                 netlogon->ntver = NETLOGON_NT_VERSION_1;
     395             :                 /* could check if the user exists */
     396         138 :                 if (user_known) {
     397           9 :                         netlogon->data.nt4.command      = LOGON_SAM_LOGON_RESPONSE;
     398             :                 } else {
     399         129 :                         netlogon->data.nt4.command      = LOGON_SAM_LOGON_USER_UNKNOWN;
     400             :                 }
     401         138 :                 netlogon->data.nt4.pdc_name    = pdc_name;
     402         138 :                 netlogon->data.nt4.user_name   = user;
     403         138 :                 netlogon->data.nt4.domain_name = flatname;
     404         138 :                 netlogon->data.nt4.nt_version  = NETLOGON_NT_VERSION_1;
     405         138 :                 netlogon->data.nt4.lmnt_token  = 0xFFFF;
     406         138 :                 netlogon->data.nt4.lm20_token  = 0xFFFF;
     407             :         }
     408             : 
     409        2724 :         return NT_STATUS_OK;
     410             : }
     411             : 
     412        2432 : NTSTATUS parse_netlogon_request(struct ldb_parse_tree *tree,
     413             :                                 struct loadparm_context *lp_ctx,
     414             :                                 TALLOC_CTX *tmp_ctx,
     415             :                                 const char **domain,
     416             :                                 const char **host,
     417             :                                 const char **user,
     418             :                                 const char **domain_guid,
     419             :                                 struct dom_sid **domain_sid,
     420             :                                 int *acct_control,
     421             :                                 int *version)
     422             : {
     423             :         unsigned int i;
     424             : 
     425        2432 :         *domain = NULL;
     426        2432 :         *host = NULL;
     427        2432 :         *user = NULL;
     428        2432 :         *domain_guid = NULL;
     429        2432 :         *domain_sid = NULL;
     430        2432 :         *acct_control = -1;
     431        2432 :         *version = NETLOGON_NT_VERSION_5;
     432             : 
     433        2432 :         if (tree->operation != LDB_OP_AND) goto failed;
     434             : 
     435             :         /* extract the query elements */
     436        9026 :         for (i=0;i<tree->u.list.num_elements;i++) {
     437        6636 :                 struct ldb_parse_tree *t = tree->u.list.elements[i];
     438        6636 :                 if (t->operation != LDB_OP_EQUALITY) goto failed;
     439        6634 :                 if (strcasecmp(t->u.equality.attr, "DnsDomain") == 0) {
     440        3068 :                         *domain = talloc_strndup(tmp_ctx,
     441        1796 :                                                 (const char *)t->u.equality.value.data,
     442             :                                                 t->u.equality.value.length);
     443             :                 }
     444        6634 :                 if (strcasecmp(t->u.equality.attr, "Host") == 0) {
     445        1208 :                         *host = talloc_strndup(tmp_ctx,
     446         606 :                                               (const char *)t->u.equality.value.data,
     447             :                                               t->u.equality.value.length);
     448             :                 }
     449        6634 :                 if (strcasecmp(t->u.equality.attr, "DomainGuid") == 0) {
     450             :                         NTSTATUS enc_status;
     451             :                         struct GUID guid;
     452          20 :                         enc_status = ldap_decode_ndr_GUID(tmp_ctx, 
     453             :                                                           t->u.equality.value, &guid);
     454          20 :                         if (NT_STATUS_IS_OK(enc_status)) {
     455          20 :                                 *domain_guid = GUID_string(tmp_ctx, &guid);
     456             :                         }
     457             :                 }
     458        6634 :                 if (strcasecmp(t->u.equality.attr, "DomainSid") == 0) {
     459             :                         enum ndr_err_code ndr_err;
     460             : 
     461           0 :                         *domain_sid = talloc(tmp_ctx, struct dom_sid);
     462           0 :                         if (*domain_sid == NULL) {
     463           0 :                                 goto failed;
     464             :                         }
     465           0 :                         ndr_err = ndr_pull_struct_blob(&t->u.equality.value,
     466             :                                                        *domain_sid, *domain_sid,
     467             :                                                        (ndr_pull_flags_fn_t)ndr_pull_dom_sid);
     468           0 :                         if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
     469           0 :                                 talloc_free(*domain_sid);
     470           0 :                                 goto failed;
     471             :                         }
     472             :                 }
     473        6634 :                 if (strcasecmp(t->u.equality.attr, "User") == 0) {
     474        1328 :                         *user = talloc_strndup(tmp_ctx,
     475         664 :                                                (const char *)t->u.equality.value.data,
     476             :                                                t->u.equality.value.length);
     477             :                 }
     478        8446 :                 if (strcasecmp(t->u.equality.attr, "NtVer") == 0 &&
     479        2427 :                     t->u.equality.value.length == 4) {
     480        2427 :                         *version = IVAL(t->u.equality.value.data, 0);
     481             :                 }
     482        7258 :                 if (strcasecmp(t->u.equality.attr, "AAC") == 0 &&
     483        1117 :                     t->u.equality.value.length == 4) {
     484        1117 :                         *acct_control = IVAL(t->u.equality.value.data, 0);
     485             :                 }
     486             :         }
     487             : 
     488        2426 :         if ((*domain == NULL) && (*domain_guid == NULL) && (*domain_sid == NULL)) {
     489         626 :                 *domain = lpcfg_dnsdomain(lp_ctx);
     490             :         }
     491             : 
     492        2426 :         return NT_STATUS_OK;
     493             : 
     494           6 : failed:
     495           6 :         return NT_STATUS_UNSUCCESSFUL;
     496             : }

Generated by: LCOV version 1.13