LCOV - code coverage report
Current view: top level - source3/torture - test_idmap_cache.c (source / functions) Hit Total Coverage
Test: coverage report for master 2b515b7d Lines: 32 55 58.2 %
Date: 2024-02-28 12:06:22 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /*
       2             :  * Unix SMB/CIFS implementation.
       3             :  * Test dbwrap_watch API
       4             :  * Copyright (C) Volker Lendecke 2017
       5             :  *
       6             :  * This program is free software; you can redistribute it and/or modify
       7             :  * it under the terms of the GNU General Public License as published by
       8             :  * the Free Software Foundation; either version 3 of the License, or
       9             :  * (at your option) any later version.
      10             :  *
      11             :  * This program is distributed in the hope that it will be useful,
      12             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      13             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14             :  * GNU General Public License for more details.
      15             :  *
      16             :  * You should have received a copy of the GNU General Public License
      17             :  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
      18             :  */
      19             : 
      20             : #include "includes.h"
      21             : #include "torture/proto.h"
      22             : #include "lib/idmap_cache.h"
      23             : #include "librpc/gen_ndr/idmap.h"
      24             : #include "libcli/security/dom_sid.h"
      25             : 
      26           1 : bool run_local_idmap_cache1(int dummy)
      27             : {
      28           1 :         struct dom_sid sid, found_sid;
      29           1 :         struct unixid xid, found_xid;
      30           1 :         bool ret = false;
      31           1 :         bool expired = false;
      32             : 
      33           1 :         xid = (struct unixid) { .id = 1234, .type = ID_TYPE_UID };
      34           1 :         dom_sid_parse("S-1-5-21-2864185242-3846410404-2398417794-1235", &sid);
      35           1 :         idmap_cache_set_sid2unixid(&sid, &xid);
      36             : 
      37           1 :         ret = idmap_cache_find_sid2unixid(&sid, &found_xid, &expired);
      38           1 :         if (!ret) {
      39           0 :                 fprintf(stderr, "idmap_cache_find_sid2unixid failed\n");
      40           0 :                 goto done;
      41             :         }
      42           1 :         if (expired) {
      43           0 :                 fprintf(stderr,
      44             :                         "idmap_cache_find_sid2unixid returned an expired "
      45             :                         "value\n");
      46           0 :                 goto done;
      47             :         }
      48           1 :         if ((xid.type != found_xid.type) || (xid.id != found_xid.id)) {
      49           0 :                 fprintf(stderr,
      50             :                         "idmap_cache_find_sid2unixid returned wrong "
      51             :                         "values\n");
      52           0 :                 goto done;
      53             :         }
      54             : 
      55           1 :         ret = idmap_cache_find_xid2sid(&xid, &found_sid, &expired);
      56           1 :         if (!ret) {
      57           0 :                 fprintf(stderr, "idmap_cache_find_xid2sid failed\n");
      58           0 :                 goto done;
      59             :         }
      60           1 :         if (expired) {
      61           0 :                 fprintf(stderr,
      62             :                         "idmap_cache_find_xid2sid returned an expired "
      63             :                         "value\n");
      64           0 :                 goto done;
      65             :         }
      66           1 :         if (!dom_sid_equal(&sid, &found_sid)) {
      67           0 :                 fprintf(stderr,
      68             :                         "idmap_cache_find_xid2sid returned wrong sid\n");
      69           0 :                 goto done;
      70             :         }
      71             : 
      72           1 :         xid.type = ID_TYPE_GID;
      73             : 
      74           1 :         ret = idmap_cache_find_xid2sid(&xid, &found_sid, &expired);
      75           1 :         if (ret) {
      76           0 :                 fprintf(stderr,
      77             :                         "idmap_cache_find_xid2sid found a GID where it "
      78             :                         "should not\n");
      79           0 :                 goto done;
      80             :         }
      81             : 
      82           1 :         idmap_cache_del_sid(&sid);
      83             : 
      84           1 :         xid.type = ID_TYPE_UID;
      85           1 :         ret = idmap_cache_find_xid2sid(&xid, &found_sid, &expired);
      86           1 :         if (ret) {
      87           0 :                 fprintf(stderr,
      88             :                         "idmap_cache_find_xid2sid found a UID where it "
      89             :                         "should not\n");
      90           0 :                 goto done;
      91             :         }
      92             : 
      93             :         /*
      94             :          * Test that negative mappings can also be cached
      95             :          */
      96           1 :         sid = (struct dom_sid) {0};
      97           1 :         xid = (struct unixid) { .id = 1234, .type = ID_TYPE_UID };
      98           1 :         idmap_cache_set_sid2unixid(&sid, &xid);
      99             : 
     100           1 :         ret = idmap_cache_find_xid2sid(&xid, &found_sid, &expired);
     101           1 :         if (!ret) {
     102           0 :                 fprintf(stderr,
     103             :                         "idmap_cache_find_xid2sid failed to find "
     104             :                         "negative mapping\n");
     105           0 :                 goto done;
     106             :         }
     107           1 :         if (expired) {
     108           0 :                 fprintf(stderr,
     109             :                         "idmap_cache_find_xid2sid returned an expired "
     110             :                         "value\n");
     111           0 :                 goto done;
     112             :         }
     113           1 :         if (!dom_sid_equal(&sid, &found_sid)) {
     114           0 :                 fprintf(stderr,
     115             :                         "idmap_cache_find_xid2sid returned wrong sid\n");
     116           0 :                 goto done;
     117             :         }
     118             : 
     119           0 :         ret = true;
     120           1 : done:
     121           1 :         return ret;
     122             : }

Generated by: LCOV version 1.14