LCOV - code coverage report
Current view: top level - source3/lib - lsa.c (source / functions) Hit Total Coverage
Test: coverage report for support-claim-type-attributes 6b5c566e Lines: 17 22 77.3 %
Date: 2023-11-21 12:31:41 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /*
       2             :  * Helper functions related to the LSA server
       3             :  *
       4             :  *  This program is free software; you can redistribute it and/or modify
       5             :  *  it under the terms of the GNU General Public License as published by
       6             :  *  the Free Software Foundation; either version 3 of the License, or
       7             :  *  (at your option) any later version.
       8             :  *
       9             :  *  This program is distributed in the hope that it will be useful,
      10             :  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
      11             :  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      12             :  *  GNU General Public License for more details.
      13             :  *
      14             :  *  You should have received a copy of the GNU General Public License
      15             :  *  along with this program; if not, see <http://www.gnu.org/licenses/>.
      16             :  */
      17             : 
      18             : /***************************************************************************
      19             :  init_lsa_ref_domain_list - adds a domain if it's not already in, returns index.
      20             : ***************************************************************************/
      21             : 
      22             : #include "replace.h"
      23             : #include "lib/util/data_blob.h"
      24             : #include "lib/util/time.h"
      25             : #include "libcli/security/dom_sid.h"
      26             : #include "librpc/gen_ndr/lsa.h"
      27             : #include "lsa.h"
      28             : 
      29        8086 : int init_lsa_ref_domain_list(TALLOC_CTX *mem_ctx,
      30             :                              struct lsa_RefDomainList *ref,
      31             :                              const char *dom_name,
      32             :                              struct dom_sid *dom_sid)
      33             : {
      34        8086 :         int num = 0;
      35             : 
      36        8086 :         if (dom_name != NULL) {
      37        8951 :                 for (num = 0; num < ref->count; num++) {
      38        3361 :                         if (dom_sid_equal(dom_sid, ref->domains[num].sid)) {
      39        2496 :                                 return num;
      40             :                         }
      41             :                 }
      42             :         } else {
      43           0 :                 num = ref->count;
      44             :         }
      45             : 
      46        5590 :         if (num >= LSA_REF_DOMAIN_LIST_MULTIPLIER) {
      47             :                 /* index not found, already at maximum domain limit */
      48           0 :                 return -1;
      49             :         }
      50             : 
      51        5590 :         ref->count = num + 1;
      52        5590 :         ref->max_size = LSA_REF_DOMAIN_LIST_MULTIPLIER;
      53             : 
      54        5590 :         ref->domains = talloc_realloc(mem_ctx, ref->domains,
      55             :                                             struct lsa_DomainInfo, ref->count);
      56        5590 :         if (!ref->domains) {
      57           0 :                 return -1;
      58             :         }
      59             : 
      60        5590 :         ZERO_STRUCT(ref->domains[num]);
      61             : 
      62        5590 :         ref->domains[num].name.string = talloc_strdup(mem_ctx, dom_name);
      63        5590 :         if (!ref->domains[num].name.string) {
      64           0 :                 return -1;
      65             :         }
      66             : 
      67        5590 :         ref->domains[num].sid = dom_sid_dup(mem_ctx, dom_sid);
      68        5590 :         if (!ref->domains[num].sid) {
      69           0 :                 return -1;
      70             :         }
      71             : 
      72        5590 :         return num;
      73             : }

Generated by: LCOV version 1.14