Coverage Report

Created: 2026-04-01 06:26

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/samba/source4/libcli/raw/rawacl.c
Line
Count
Source
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
struct smbcli_request *smb_raw_query_secdesc_send(struct smbcli_tree *tree,
30
              union smb_fileinfo *io)
31
0
{
32
0
  struct smb_nttrans nt;
33
0
  uint8_t params[8];
34
35
0
  nt.in.max_setup = 0;
36
0
  nt.in.max_param = 4;
37
0
  nt.in.max_data = 0xFFFF;
38
0
  nt.in.setup_count = 0;
39
0
  nt.in.function = NT_TRANSACT_QUERY_SECURITY_DESC;
40
0
  nt.in.setup = NULL;
41
42
0
  SSVAL(params, 0, io->query_secdesc.in.file.fnum);
43
0
  SSVAL(params, 2, 0); /* padding */
44
0
  SIVAL(params, 4, io->query_secdesc.in.secinfo_flags);
45
46
0
  nt.in.params.data = params;
47
0
  nt.in.params.length = 8;
48
49
0
  nt.in.data = data_blob(NULL, 0);
50
51
0
  return smb_raw_nttrans_send(tree, &nt);
52
0
}
53
54
55
/****************************************************************************
56
fetch file ACL (async recv)
57
****************************************************************************/
58
NTSTATUS smb_raw_query_secdesc_recv(struct smbcli_request *req,
59
            TALLOC_CTX *mem_ctx,
60
            union smb_fileinfo *io)
61
0
{
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
0
  status = smb_raw_nttrans_recv(req, mem_ctx, &nt);
68
0
  if (!NT_STATUS_IS_OK(status)) {
69
0
    return status;
70
0
  }
71
72
  /* check that the basics are valid */
73
0
  if (nt.out.params.length != 4 ||
74
0
      IVAL(nt.out.params.data, 0) > nt.out.data.length) {
75
0
    return NT_STATUS_INVALID_PARAMETER;
76
0
  }
77
78
0
  nt.out.data.length = IVAL(nt.out.params.data, 0);
79
80
0
  ndr = ndr_pull_init_blob(&nt.out.data, mem_ctx);
81
0
  if (!ndr) {
82
0
    return NT_STATUS_INVALID_PARAMETER;
83
0
  }
84
85
0
  io->query_secdesc.out.sd = talloc(mem_ctx, struct security_descriptor);
86
0
  if (!io->query_secdesc.out.sd) {
87
0
    return NT_STATUS_NO_MEMORY;
88
0
  }
89
0
  ndr_err = ndr_pull_security_descriptor(ndr, NDR_SCALARS|NDR_BUFFERS,
90
0
                 io->query_secdesc.out.sd);
91
0
  if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
92
0
    return ndr_map_error2ntstatus(ndr_err);
93
0
  }
94
95
0
  return NT_STATUS_OK;
96
0
}
97
98
99
/****************************************************************************
100
fetch file ACL (sync interface)
101
****************************************************************************/
102
NTSTATUS smb_raw_query_secdesc(struct smbcli_tree *tree,
103
             TALLOC_CTX *mem_ctx,
104
             union smb_fileinfo *io)
105
0
{
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
0
}
109
110
111
112
/****************************************************************************
113
set file ACL (async send)
114
****************************************************************************/
115
struct smbcli_request *smb_raw_set_secdesc_send(struct smbcli_tree *tree,
116
            union smb_setfileinfo *io)
117
0
{
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
0
  nt.in.max_setup = 0;
125
0
  nt.in.max_param = 0;
126
0
  nt.in.max_data = 0;
127
0
  nt.in.setup_count = 0;
128
0
  nt.in.function = NT_TRANSACT_SET_SECURITY_DESC;
129
0
  nt.in.setup = NULL;
130
131
0
  SSVAL(params, 0, io->set_secdesc.in.file.fnum);
132
0
  SSVAL(params, 2, 0); /* padding */
133
0
  SIVAL(params, 4, io->set_secdesc.in.secinfo_flags);
134
135
0
  nt.in.params.data = params;
136
0
  nt.in.params.length = 8;
137
138
0
  ndr = ndr_push_init_ctx(NULL);
139
0
  if (!ndr) return NULL;
140
141
0
  ndr_err = ndr_push_security_descriptor(ndr, NDR_SCALARS|NDR_BUFFERS, io->set_secdesc.in.sd);
142
0
  if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
143
0
    talloc_free(ndr);
144
0
    return NULL;
145
0
  }
146
147
0
  nt.in.data = ndr_push_blob(ndr);
148
149
0
  req = smb_raw_nttrans_send(tree, &nt);
150
151
0
  talloc_free(ndr);
152
0
  return req;
153
0
}
154
155
/****************************************************************************
156
set file ACL (sync interface)
157
****************************************************************************/
158
NTSTATUS smb_raw_set_secdesc(struct smbcli_tree *tree,
159
           union smb_setfileinfo *io)
160
0
{
161
0
  struct smbcli_request *req = smb_raw_set_secdesc_send(tree, io);
162
0
  return smbcli_request_simple_recv(req);
163
0
}