LCOV - code coverage report
Current view: top level - source4/libcli/raw - rawacl.c (source / functions) Hit Total Coverage
Test: coverage report for master 2b515b7d Lines: 47 71 66.2 %
Date: 2024-02-28 12:06:22 Functions: 3 5 60.0 %

          Line data    Source code
       1             : /*
       2             :    Unix SMB/CIFS implementation.
       3             :    ACL get/set operations
       4             : 
       5             :    Copyright (C) Andrew Tridgell 2003-2004
       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 "libcli/raw/libcliraw.h"
      23             : #include "libcli/raw/raw_proto.h"
      24             : #include "librpc/gen_ndr/ndr_security.h"
      25             : 
      26             : /****************************************************************************
      27             : fetch file ACL (async send)
      28             : ****************************************************************************/
      29        7822 : struct smbcli_request *smb_raw_query_secdesc_send(struct smbcli_tree *tree,
      30             :                                                   union smb_fileinfo *io)
      31             : {
      32           0 :         struct smb_nttrans nt;
      33           0 :         uint8_t params[8];
      34             : 
      35        7822 :         nt.in.max_setup = 0;
      36        7822 :         nt.in.max_param = 4;
      37        7822 :         nt.in.max_data = 0xFFFF;
      38        7822 :         nt.in.setup_count = 0;
      39        7822 :         nt.in.function = NT_TRANSACT_QUERY_SECURITY_DESC;
      40        7822 :         nt.in.setup = NULL;
      41             : 
      42        7822 :         SSVAL(params, 0, io->query_secdesc.in.file.fnum);
      43        7822 :         SSVAL(params, 2, 0); /* padding */
      44        7822 :         SIVAL(params, 4, io->query_secdesc.in.secinfo_flags);
      45             : 
      46        7822 :         nt.in.params.data = params;
      47        7822 :         nt.in.params.length = 8;
      48             : 
      49        7822 :         nt.in.data = data_blob(NULL, 0);
      50             : 
      51        7822 :         return smb_raw_nttrans_send(tree, &nt);
      52             : }
      53             : 
      54             : 
      55             : /****************************************************************************
      56             : fetch file ACL (async recv)
      57             : ****************************************************************************/
      58        7822 : NTSTATUS smb_raw_query_secdesc_recv(struct smbcli_request *req,
      59             :                                     TALLOC_CTX *mem_ctx,
      60             :                                     union smb_fileinfo *io)
      61             : {
      62           0 :         NTSTATUS status;
      63           0 :         struct smb_nttrans nt;
      64           0 :         struct ndr_pull *ndr;
      65           0 :         enum ndr_err_code ndr_err;
      66             : 
      67        7822 :         status = smb_raw_nttrans_recv(req, mem_ctx, &nt);
      68        7822 :         if (!NT_STATUS_IS_OK(status)) {
      69           0 :                 return status;
      70             :         }
      71             : 
      72             :         /* check that the basics are valid */
      73        7822 :         if (nt.out.params.length != 4 ||
      74        7822 :             IVAL(nt.out.params.data, 0) > nt.out.data.length) {
      75           0 :                 return NT_STATUS_INVALID_PARAMETER;
      76             :         }
      77             : 
      78        7822 :         nt.out.data.length = IVAL(nt.out.params.data, 0);
      79             : 
      80        7822 :         ndr = ndr_pull_init_blob(&nt.out.data, mem_ctx);
      81        7822 :         if (!ndr) {
      82           0 :                 return NT_STATUS_INVALID_PARAMETER;
      83             :         }
      84             : 
      85        7822 :         io->query_secdesc.out.sd = talloc(mem_ctx, struct security_descriptor);
      86        7822 :         if (!io->query_secdesc.out.sd) {
      87           0 :                 return NT_STATUS_NO_MEMORY;
      88             :         }
      89        7822 :         ndr_err = ndr_pull_security_descriptor(ndr, NDR_SCALARS|NDR_BUFFERS,
      90             :                                                io->query_secdesc.out.sd);
      91        7822 :         if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
      92           0 :                 return ndr_map_error2ntstatus(ndr_err);
      93             :         }
      94             : 
      95        7822 :         return NT_STATUS_OK;
      96             : }
      97             : 
      98             : 
      99             : /****************************************************************************
     100             : fetch file ACL (sync interface)
     101             : ****************************************************************************/
     102           0 : NTSTATUS smb_raw_query_secdesc(struct smbcli_tree *tree,
     103             :                                TALLOC_CTX *mem_ctx,
     104             :                                union smb_fileinfo *io)
     105             : {
     106           0 :         struct smbcli_request *req = smb_raw_query_secdesc_send(tree, io);
     107           0 :         return smb_raw_query_secdesc_recv(req, mem_ctx, io);
     108             : }
     109             : 
     110             : 
     111             : 
     112             : /****************************************************************************
     113             : set file ACL (async send)
     114             : ****************************************************************************/
     115        7073 : struct smbcli_request *smb_raw_set_secdesc_send(struct smbcli_tree *tree,
     116             :                                                 union smb_setfileinfo *io)
     117             : {
     118           0 :         struct smb_nttrans nt;
     119           0 :         uint8_t params[8];
     120           0 :         struct ndr_push *ndr;
     121           0 :         struct smbcli_request *req;
     122           0 :         enum ndr_err_code ndr_err;
     123             : 
     124        7073 :         nt.in.max_setup = 0;
     125        7073 :         nt.in.max_param = 0;
     126        7073 :         nt.in.max_data = 0;
     127        7073 :         nt.in.setup_count = 0;
     128        7073 :         nt.in.function = NT_TRANSACT_SET_SECURITY_DESC;
     129        7073 :         nt.in.setup = NULL;
     130             : 
     131        7073 :         SSVAL(params, 0, io->set_secdesc.in.file.fnum);
     132        7073 :         SSVAL(params, 2, 0); /* padding */
     133        7073 :         SIVAL(params, 4, io->set_secdesc.in.secinfo_flags);
     134             : 
     135        7073 :         nt.in.params.data = params;
     136        7073 :         nt.in.params.length = 8;
     137             : 
     138        7073 :         ndr = ndr_push_init_ctx(NULL);
     139        7073 :         if (!ndr) return NULL;
     140             : 
     141        7073 :         ndr_err = ndr_push_security_descriptor(ndr, NDR_SCALARS|NDR_BUFFERS, io->set_secdesc.in.sd);
     142        7073 :         if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
     143           0 :                 talloc_free(ndr);
     144           0 :                 return NULL;
     145             :         }
     146             : 
     147        7073 :         nt.in.data = ndr_push_blob(ndr);
     148             : 
     149        7073 :         req = smb_raw_nttrans_send(tree, &nt);
     150             : 
     151        7073 :         talloc_free(ndr);
     152        7073 :         return req;
     153             : }
     154             : 
     155             : /****************************************************************************
     156             : set file ACL (sync interface)
     157             : ****************************************************************************/
     158           0 : NTSTATUS smb_raw_set_secdesc(struct smbcli_tree *tree,
     159             :                              union smb_setfileinfo *io)
     160             : {
     161           0 :         struct smbcli_request *req = smb_raw_set_secdesc_send(tree, io);
     162           0 :         return smbcli_request_simple_recv(req);
     163             : }

Generated by: LCOV version 1.14