LCOV - code coverage report
Current view: top level - source4/torture/rpc - unixinfo.c (source / functions) Hit Total Coverage
Test: coverage report for abartlet/fix-coverage dd10fb34 Lines: 53 53 100.0 %
Date: 2021-09-23 10:06:22 Functions: 6 6 100.0 %

          Line data    Source code
       1             : /* 
       2             :    Unix SMB/CIFS implementation.
       3             :    test suite for unixinfo rpc operations
       4             : 
       5             :    Copyright (C) Volker Lendecke 2005
       6             :    
       7             :    This program is free software; you can redistribute it and/or modify
       8             :    it under the terms of the GNU General Public License as published by
       9             :    the Free Software Foundation; either version 3 of the License, or
      10             :    (at your option) any later version.
      11             :    
      12             :    This program is distributed in the hope that it will be useful,
      13             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      14             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      15             :    GNU General Public License for more details.
      16             :    
      17             :    You should have received a copy of the GNU General Public License
      18             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.
      19             : */
      20             : 
      21             : #include "includes.h"
      22             : #include "torture/rpc/torture_rpc.h"
      23             : #include "librpc/gen_ndr/ndr_unixinfo_c.h"
      24             : #include "libcli/security/security.h"
      25             : 
      26             : /**
      27             :   test the SidToUid interface
      28             : */
      29           3 : static bool test_sidtouid(struct torture_context *tctx, struct dcerpc_pipe *p)
      30             : {
      31             :         struct unixinfo_SidToUid r;
      32             :         struct dom_sid *sid;
      33             :         uint64_t uid;
      34           3 :         struct dcerpc_binding_handle *b = p->binding_handle;
      35             :         
      36           3 :         sid = dom_sid_parse_talloc(tctx, "S-1-5-32-1234-5432");
      37           3 :         r.in.sid = *sid;
      38           3 :         r.out.uid = &uid;
      39             : 
      40           3 :         torture_assert_ntstatus_ok(tctx, dcerpc_unixinfo_SidToUid_r(b, tctx, &r),
      41             :                 "SidToUid failed");
      42           3 :         if (NT_STATUS_EQUAL(NT_STATUS_NONE_MAPPED, r.out.result)) {
      43           3 :         } else torture_assert_ntstatus_ok(tctx, r.out.result, "SidToUid failed");
      44             : 
      45           3 :         return true;
      46             : }
      47             : 
      48             : /*
      49             :   test the UidToSid interface
      50             : */
      51           3 : static bool test_uidtosid(struct torture_context *tctx, struct dcerpc_pipe *p)
      52             : {
      53             :         struct unixinfo_UidToSid r;
      54             :         struct dom_sid sid;
      55           3 :         struct dcerpc_binding_handle *b = p->binding_handle;
      56             : 
      57           3 :         r.in.uid = 1000;
      58           3 :         r.out.sid = &sid;
      59             : 
      60           3 :         torture_assert_ntstatus_ok(tctx, dcerpc_unixinfo_UidToSid_r(b, tctx, &r),
      61             :                                    "UidToSid failed");
      62           3 :         torture_assert_ntstatus_ok(tctx, r.out.result, "UidToSid failed");
      63           3 :         return true;
      64             : }
      65             : 
      66           3 : static bool test_getpwuid(struct torture_context *tctx, 
      67             :                           struct dcerpc_pipe *p)
      68             : {
      69             :         uint64_t uids[512];
      70           3 :         uint32_t num_uids = ARRAY_SIZE(uids);
      71             :         uint32_t i;
      72             :         struct unixinfo_GetPWUid r;
      73           3 :         struct dcerpc_binding_handle *b = p->binding_handle;
      74             : 
      75        1539 :         for (i=0; i<num_uids; i++) {
      76        1536 :                 uids[i] = i;
      77             :         }
      78             :         
      79           3 :         r.in.count = &num_uids;
      80           3 :         r.in.uids = uids;
      81           3 :         r.out.count = &num_uids;
      82           3 :         r.out.infos = talloc_array(tctx, struct unixinfo_GetPWUidInfo, num_uids);
      83             : 
      84           3 :         torture_assert_ntstatus_ok(tctx, dcerpc_unixinfo_GetPWUid_r(b, tctx, &r),
      85             :                 "GetPWUid failed");
      86             : 
      87           3 :         torture_assert_ntstatus_ok(tctx, r.out.result, "GetPWUid failed");
      88             :         
      89           3 :         return true;
      90             : }
      91             : 
      92             : /*
      93             :   test the SidToGid interface
      94             : */
      95           3 : static bool test_sidtogid(struct torture_context *tctx, struct dcerpc_pipe *p)
      96             : {
      97             :         struct unixinfo_SidToGid r;
      98             :         struct dom_sid *sid;
      99             :         uint64_t gid;
     100           3 :         struct dcerpc_binding_handle *b = p->binding_handle;
     101             : 
     102           3 :         sid = dom_sid_parse_talloc(tctx, "S-1-5-32-1234-5432");
     103           3 :         r.in.sid = *sid;
     104           3 :         r.out.gid = &gid;
     105             : 
     106           3 :         torture_assert_ntstatus_ok(tctx, dcerpc_unixinfo_SidToGid_r(b, tctx, &r),
     107             :                 "SidToGid failed");
     108           3 :         if (NT_STATUS_EQUAL(NT_STATUS_NONE_MAPPED, r.out.result)) {
     109           3 :         } else torture_assert_ntstatus_ok(tctx, r.out.result, "SidToGid failed");
     110             : 
     111           3 :         return true;
     112             : }
     113             : 
     114             : /*
     115             :   test the GidToSid interface
     116             : */
     117           3 : static bool test_gidtosid(struct torture_context *tctx, struct dcerpc_pipe *p)
     118             : {
     119             :         struct unixinfo_GidToSid r;
     120             :         struct dom_sid sid;
     121           3 :         struct dcerpc_binding_handle *b = p->binding_handle;
     122             : 
     123           3 :         r.in.gid = 1000;
     124           3 :         r.out.sid = &sid;
     125             : 
     126           3 :         torture_assert_ntstatus_ok(tctx, dcerpc_unixinfo_GidToSid_r(b, tctx, &r),
     127             :                                    "GidToSid failed");
     128           3 :         torture_assert_ntstatus_ok(tctx, r.out.result, "GidToSid failed");
     129             : 
     130           3 :         return true;
     131             : }
     132             : 
     133        2355 : struct torture_suite *torture_rpc_unixinfo(TALLOC_CTX *mem_ctx)
     134             : {
     135             :         struct torture_suite *suite;
     136             :         struct torture_rpc_tcase *tcase;
     137             : 
     138        2355 :         suite = torture_suite_create(mem_ctx, "unixinfo");
     139        2355 :         tcase = torture_suite_add_rpc_iface_tcase(suite, "unixinfo", 
     140             :                                                   &ndr_table_unixinfo);
     141             : 
     142        2355 :         torture_rpc_tcase_add_test(tcase, "sidtouid", test_sidtouid);
     143        2355 :         torture_rpc_tcase_add_test(tcase, "uidtosid", test_uidtosid);
     144        2355 :         torture_rpc_tcase_add_test(tcase, "getpwuid", test_getpwuid);
     145        2355 :         torture_rpc_tcase_add_test(tcase, "sidtogid", test_sidtogid);
     146        2355 :         torture_rpc_tcase_add_test(tcase, "gidtosid", test_gidtosid);
     147             : 
     148        2355 :         return suite;
     149             : }

Generated by: LCOV version 1.13