root/source4/torture/rpc/unixinfo.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. test_sidtouid
  2. test_uidtosid
  3. test_getpwuid
  4. test_sidtogid
  5. test_gidtosid
  6. torture_rpc_unixinfo

   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/torture.h"
  23 #include "torture/rpc/rpc.h"
  24 #include "librpc/gen_ndr/ndr_unixinfo_c.h"
  25 #include "libcli/security/security.h"
  26 
  27 /**
  28   test the SidToUid interface
  29 */
  30 static bool test_sidtouid(struct torture_context *tctx, struct dcerpc_pipe *p)
     /* [<][>][^][v][top][bottom][index][help] */
  31 {
  32         NTSTATUS status;
  33         struct unixinfo_SidToUid r;
  34         struct dom_sid *sid;
  35         uint64_t uid;
  36         
  37         sid = dom_sid_parse_talloc(tctx, "S-1-5-32-1234-5432");
  38         r.in.sid = *sid;
  39         r.out.uid = &uid;
  40 
  41         status = dcerpc_unixinfo_SidToUid(p, tctx, &r);
  42         if (NT_STATUS_EQUAL(NT_STATUS_NONE_MAPPED, status)) {
  43         } else torture_assert_ntstatus_ok(tctx, status, "SidToUid failed");
  44 
  45         return true;
  46 }
  47 
  48 /*
  49   test the UidToSid interface
  50 */
  51 static bool test_uidtosid(struct torture_context *tctx, struct dcerpc_pipe *p)
     /* [<][>][^][v][top][bottom][index][help] */
  52 {
  53         struct unixinfo_UidToSid r;
  54         struct dom_sid sid;
  55 
  56         r.in.uid = 1000;
  57         r.out.sid = &sid;
  58 
  59         torture_assert_ntstatus_ok(tctx, dcerpc_unixinfo_UidToSid(p, tctx, &r), 
  60                                    "UidToSid failed");
  61 
  62         return true;
  63 }
  64 
  65 static bool test_getpwuid(struct torture_context *tctx, 
     /* [<][>][^][v][top][bottom][index][help] */
  66                           struct dcerpc_pipe *p)
  67 {
  68         uint64_t uids[512];
  69         uint32_t num_uids = ARRAY_SIZE(uids);
  70         uint32_t i;
  71         struct unixinfo_GetPWUid r;
  72         NTSTATUS result;
  73 
  74         for (i=0; i<num_uids; i++) {
  75                 uids[i] = i;
  76         }
  77         
  78         r.in.count = &num_uids;
  79         r.in.uids = uids;
  80         r.out.count = &num_uids;
  81         r.out.infos = talloc_array(tctx, struct unixinfo_GetPWUidInfo, num_uids);
  82 
  83         result = dcerpc_unixinfo_GetPWUid(p, tctx, &r);
  84 
  85         torture_assert_ntstatus_ok(tctx, result, "GetPWUid failed");
  86         
  87         return true;
  88 }
  89 
  90 /*
  91   test the SidToGid interface
  92 */
  93 static bool test_sidtogid(struct torture_context *tctx, struct dcerpc_pipe *p)
     /* [<][>][^][v][top][bottom][index][help] */
  94 {
  95         NTSTATUS status;
  96         struct unixinfo_SidToGid r;
  97         struct dom_sid *sid;
  98         uint64_t gid;
  99 
 100         sid = dom_sid_parse_talloc(tctx, "S-1-5-32-1234-5432");
 101         r.in.sid = *sid;
 102         r.out.gid = &gid;
 103 
 104         status = dcerpc_unixinfo_SidToGid(p, tctx, &r);
 105         if (NT_STATUS_EQUAL(NT_STATUS_NONE_MAPPED, status)) {
 106         } else torture_assert_ntstatus_ok(tctx, status, "SidToGid failed");
 107 
 108         return true;
 109 }
 110 
 111 /*
 112   test the GidToSid interface
 113 */
 114 static bool test_gidtosid(struct torture_context *tctx, struct dcerpc_pipe *p)
     /* [<][>][^][v][top][bottom][index][help] */
 115 {
 116         struct unixinfo_GidToSid r;
 117         struct dom_sid sid;
 118 
 119         r.in.gid = 1000;
 120         r.out.sid = &sid;
 121 
 122         torture_assert_ntstatus_ok(tctx, dcerpc_unixinfo_GidToSid(p, tctx, &r), 
 123                                    "GidToSid failed");
 124 
 125         return true;
 126 }
 127 
 128 struct torture_suite *torture_rpc_unixinfo(TALLOC_CTX *mem_ctx)
     /* [<][>][^][v][top][bottom][index][help] */
 129 {
 130         struct torture_suite *suite;
 131         struct torture_rpc_tcase *tcase;
 132 
 133         suite = torture_suite_create(mem_ctx, "UNIXINFO");
 134         tcase = torture_suite_add_rpc_iface_tcase(suite, "unixinfo", 
 135                                                   &ndr_table_unixinfo);
 136 
 137         torture_rpc_tcase_add_test(tcase, "sidtouid", test_sidtouid);
 138         torture_rpc_tcase_add_test(tcase, "uidtosid", test_uidtosid);
 139         torture_rpc_tcase_add_test(tcase, "getpwuid", test_getpwuid);
 140         torture_rpc_tcase_add_test(tcase, "sidtogid", test_sidtogid);
 141         torture_rpc_tcase_add_test(tcase, "gidtosid", test_gidtosid);
 142 
 143         return suite;
 144 }

/* [<][>][^][v][top][bottom][index][help] */