LCOV - code coverage report
Current view: top level - source4/torture/libnet - userinfo.c (source / functions) Hit Total Coverage
Test: coverage report for master 70ed9daf Lines: 60 92 65.2 %
Date: 2024-01-11 09:59:51 Functions: 3 3 100.0 %

          Line data    Source code
       1             : /*
       2             :    Unix SMB/CIFS implementation.
       3             :    Test suite for libnet calls.
       4             : 
       5             :    Copyright (C) Rafal Szczesniak 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 "libnet/libnet.h"
      24             : #include "libcli/security/security.h"
      25             : #include "librpc/gen_ndr/ndr_samr_c.h"
      26             : #include "param/param.h"
      27             : #include "torture/libnet/proto.h"
      28             : 
      29             : 
      30             : #define TEST_USERNAME  "libnetuserinfotest"
      31             : 
      32           1 : static bool test_userinfo(struct torture_context *tctx,
      33             :                           struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
      34             :                           struct policy_handle *domain_handle,
      35             :                           struct dom_sid2 *domain_sid, const char* user_name,
      36             :                           uint32_t *rid)
      37             : {
      38           1 :         const uint16_t level = 5;
      39           0 :         NTSTATUS status;
      40           0 :         struct libnet_rpc_userinfo user;
      41           0 :         struct dom_sid *user_sid;
      42             : 
      43           1 :         user_sid = dom_sid_add_rid(mem_ctx, domain_sid, *rid);
      44             : 
      45           1 :         ZERO_STRUCT(user);
      46             : 
      47           1 :         user.in.domain_handle = *domain_handle;
      48           1 :         user.in.sid           = dom_sid_string(mem_ctx, user_sid);
      49           1 :         user.in.level         = level;       /* this should be extended */
      50             : 
      51           1 :         torture_comment(tctx, "Testing sync libnet_rpc_userinfo (SID argument)\n");
      52           1 :         status = libnet_rpc_userinfo(tctx->ev, p->binding_handle, mem_ctx, &user);
      53           1 :         torture_assert_ntstatus_ok(tctx, status, "Calling sync libnet_rpc_userinfo() failed");
      54             : 
      55           1 :         ZERO_STRUCT(user);
      56             : 
      57           1 :         user.in.domain_handle = *domain_handle;
      58           1 :         user.in.sid           = NULL;
      59           1 :         user.in.username      = user_name;
      60           1 :         user.in.level         = level;
      61             : 
      62           1 :         torture_comment(tctx, "Testing sync libnet_rpc_userinfo (username argument)\n");
      63           1 :         status = libnet_rpc_userinfo(tctx->ev, p->binding_handle, mem_ctx, &user);
      64           1 :         torture_assert_ntstatus_ok(tctx, status, "Calling sync libnet_rpc_userinfo failed");
      65             : 
      66           1 :         return true;
      67             : }
      68             : 
      69             : 
      70           1 : static bool test_userinfo_async(struct torture_context *tctx,
      71             :                                 struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
      72             :                                 struct policy_handle *domain_handle,
      73             :                                 struct dom_sid2 *domain_sid, const char* user_name,
      74             :                                 uint32_t *rid)
      75             : {
      76           1 :         const uint16_t level = 10;
      77           0 :         NTSTATUS status;
      78           0 :         struct composite_context *c;
      79           0 :         struct libnet_rpc_userinfo user;
      80           0 :         struct dom_sid *user_sid;
      81             : 
      82           1 :         user_sid = dom_sid_add_rid(mem_ctx, domain_sid, *rid);
      83             : 
      84           1 :         ZERO_STRUCT(user);
      85             : 
      86           1 :         user.in.domain_handle = *domain_handle;
      87           1 :         user.in.sid           = dom_sid_string(mem_ctx, user_sid);
      88           1 :         user.in.level         = level;       /* this should be extended */
      89             : 
      90           1 :         torture_comment(tctx, "Testing async libnet_rpc_userinfo (SID argument)\n");
      91             : 
      92           1 :         c = libnet_rpc_userinfo_send(mem_ctx, tctx->ev, p->binding_handle, &user, msg_handler);
      93           1 :         torture_assert(tctx, c != NULL, "Failed to call async libnet_rpc_userinfo_send");
      94             : 
      95           1 :         status = libnet_rpc_userinfo_recv(c, mem_ctx, &user);
      96           1 :         torture_assert_ntstatus_ok(tctx, status, "Calling async libnet_rpc_userinfo_recv failed");
      97             : 
      98           1 :         ZERO_STRUCT(user);
      99             : 
     100           1 :         user.in.domain_handle = *domain_handle;
     101           1 :         user.in.sid           = NULL;
     102           1 :         user.in.username      = user_name;
     103           1 :         user.in.level         = level;
     104             : 
     105           1 :         torture_comment(tctx, "Testing async libnet_rpc_userinfo (username argument)\n");
     106             : 
     107           1 :         c = libnet_rpc_userinfo_send(mem_ctx, tctx->ev, p->binding_handle, &user, msg_handler);
     108           1 :         torture_assert(tctx, c != NULL, "Failed to call async libnet_rpc_userinfo_send");
     109             : 
     110           1 :         status = libnet_rpc_userinfo_recv(c, mem_ctx, &user);
     111           1 :         torture_assert_ntstatus_ok(tctx, status, "Calling async libnet_rpc_userinfo_recv failed");
     112             : 
     113           1 :         return true;
     114             : }
     115             : 
     116             : 
     117           1 : bool torture_userinfo(struct torture_context *torture)
     118             : {
     119           0 :         NTSTATUS status;
     120           0 :         struct dcerpc_pipe *p;
     121           0 :         TALLOC_CTX *mem_ctx;
     122           1 :         bool ret = true;
     123           0 :         struct policy_handle h;
     124           0 :         struct lsa_String name;
     125           0 :         struct dom_sid2 sid;
     126           0 :         uint32_t rid;
     127           0 :         struct dcerpc_binding_handle *b;
     128             : 
     129           1 :         mem_ctx = talloc_init("test_userinfo");
     130             : 
     131           1 :         status = torture_rpc_connection(torture,
     132             :                                         &p,
     133             :                                         &ndr_table_samr);
     134             : 
     135           1 :         if (!NT_STATUS_IS_OK(status)) {
     136           0 :                 return false;
     137             :         }
     138           1 :         b = p->binding_handle;
     139             : 
     140           1 :         name.string = lpcfg_workgroup(torture->lp_ctx);
     141             : 
     142             :         /*
     143             :          * Testing synchronous version
     144             :          */
     145           1 :         if (!test_domain_open(torture, b, &name, mem_ctx, &h, &sid)) {
     146           0 :                 ret = false;
     147           0 :                 goto done;
     148             :         }
     149             : 
     150           1 :         if (!test_user_create(torture, b, mem_ctx, &h, TEST_USERNAME, &rid)) {
     151           0 :                 ret = false;
     152           0 :                 goto done;
     153             :         }
     154             : 
     155           1 :         if (!test_userinfo(torture, p, mem_ctx, &h, &sid, TEST_USERNAME, &rid)) {
     156           0 :                 ret = false;
     157           0 :                 goto done;
     158             :         }
     159             : 
     160           1 :         if (!test_user_cleanup(torture, b, mem_ctx, &h, TEST_USERNAME)) {
     161           0 :                 ret = false;
     162           0 :                 goto done;
     163             :         }
     164             : 
     165             :         /*
     166             :          * Testing asynchronous version and monitor messages
     167             :          */
     168           1 :         if (!test_domain_open(torture, b, &name, mem_ctx, &h, &sid)) {
     169           0 :                 ret = false;
     170           0 :                 goto done;
     171             :         }
     172             : 
     173           1 :         if (!test_user_create(torture, b, mem_ctx, &h, TEST_USERNAME, &rid)) {
     174           0 :                 ret = false;
     175           0 :                 goto done;
     176             :         }
     177             : 
     178           1 :         if (!test_userinfo_async(torture, p, mem_ctx, &h, &sid, TEST_USERNAME, &rid)) {
     179           0 :                 ret = false;
     180           0 :                 goto done;
     181             :         }
     182             : 
     183           1 :         if (!test_user_cleanup(torture, b, mem_ctx, &h, TEST_USERNAME)) {
     184           0 :                 ret = false;
     185           0 :                 goto done;
     186             :         }
     187             : 
     188           1 : done:
     189           1 :         talloc_free(mem_ctx);
     190             : 
     191           1 :         return ret;
     192             : }

Generated by: LCOV version 1.14