s3: Add cli_writeall
[Samba.git] / source3 / libsmb / clisecdesc.c
blob5543ce50330784b0004f6de42cef5f0fe1dfa3eb
1 /*
2 Unix SMB/CIFS implementation.
3 client security descriptor functions
4 Copyright (C) Andrew Tridgell 2000
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "includes.h"
22 /****************************************************************************
23 query the security descriptor for a open file
24 ****************************************************************************/
25 struct security_descriptor *cli_query_secdesc(struct cli_state *cli, uint16_t fnum,
26 TALLOC_CTX *mem_ctx)
28 uint8_t param[8];
29 uint8_t *rdata=NULL;
30 uint32_t rdata_count=0;
31 struct security_descriptor *psd = NULL;
32 NTSTATUS status;
34 SIVAL(param, 0, fnum);
35 SIVAL(param, 4, 0x7);
37 status = cli_trans(talloc_tos(), cli, SMBnttrans,
38 NULL, -1, /* name, fid */
39 NT_TRANSACT_QUERY_SECURITY_DESC, 0, /* function, flags */
40 NULL, 0, 0, /* setup, length, max */
41 param, 8, 4, /* param, length, max */
42 NULL, 0, 0x10000, /* data, length, max */
43 NULL, /* recv_flags2 */
44 NULL, 0, NULL, /* rsetup, length */
45 NULL, 0, NULL,
46 &rdata, 0, &rdata_count);
48 if (!NT_STATUS_IS_OK(status)) {
49 DEBUG(1, ("NT_TRANSACT_QUERY_SECURITY_DESC failed: %s\n",
50 nt_errstr(status)));
51 goto cleanup;
54 status = unmarshall_sec_desc(mem_ctx, (uint8 *)rdata, rdata_count,
55 &psd);
57 if (!NT_STATUS_IS_OK(status)) {
58 DEBUG(10, ("unmarshall_sec_desc failed: %s\n",
59 nt_errstr(status)));
60 goto cleanup;
63 cleanup:
65 TALLOC_FREE(rdata);
67 return psd;
70 /****************************************************************************
71 set the security descriptor for a open file
72 ****************************************************************************/
73 NTSTATUS cli_set_secdesc(struct cli_state *cli, uint16_t fnum,
74 struct security_descriptor *sd)
76 uint8_t param[8];
77 uint32 sec_info = 0;
78 uint8 *data;
79 size_t len;
80 NTSTATUS status;
82 status = marshall_sec_desc(talloc_tos(), sd, &data, &len);
83 if (!NT_STATUS_IS_OK(status)) {
84 DEBUG(10, ("marshall_sec_desc failed: %s\n",
85 nt_errstr(status)));
86 return status;
89 SIVAL(param, 0, fnum);
91 if (sd->dacl)
92 sec_info |= SECINFO_DACL;
93 if (sd->owner_sid)
94 sec_info |= SECINFO_OWNER;
95 if (sd->group_sid)
96 sec_info |= SECINFO_GROUP;
97 SSVAL(param, 4, sec_info);
99 status = cli_trans(talloc_tos(), cli, SMBnttrans,
100 NULL, -1, /* name, fid */
101 NT_TRANSACT_SET_SECURITY_DESC, 0,
102 NULL, 0, 0, /* setup */
103 param, 8, 0, /* param */
104 data, len, 0, /* data */
105 NULL, /* recv_flags2 */
106 NULL, 0, NULL, /* rsetup */
107 NULL, 0, NULL, /* rparam */
108 NULL, 0, NULL); /* rdata */
109 TALLOC_FREE(data);
110 if (!NT_STATUS_IS_OK(status)) {
111 DEBUG(1, ("Failed to send NT_TRANSACT_SET_SECURITY_DESC: %s\n",
112 nt_errstr(status)));
114 return status;