s3/docs: Fix typo.
[Samba.git] / source / libsmb / clisecdesc.c
blobadc6fba9afa767d3ab706f75016e6ae498fa9a14
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 SEC_DESC *cli_query_secdesc(struct cli_state *cli, int fnum,
26 TALLOC_CTX *mem_ctx)
28 char param[8];
29 char *rparam=NULL, *rdata=NULL;
30 unsigned int rparam_count=0, rdata_count=0;
31 SEC_DESC *psd = NULL;
32 NTSTATUS status;
34 SIVAL(param, 0, fnum);
35 SIVAL(param, 4, 0x7);
37 if (!cli_send_nt_trans(cli,
38 NT_TRANSACT_QUERY_SECURITY_DESC,
39 0,
40 NULL, 0, 0,
41 param, 8, 4,
42 NULL, 0, 0x10000)) {
43 DEBUG(1,("Failed to send NT_TRANSACT_QUERY_SECURITY_DESC\n"));
44 goto cleanup;
48 if (!cli_receive_nt_trans(cli,
49 &rparam, &rparam_count,
50 &rdata, &rdata_count)) {
51 DEBUG(1,("Failed to recv NT_TRANSACT_QUERY_SECURITY_DESC\n"));
52 goto cleanup;
55 if (cli_is_error(cli))
56 goto cleanup;
58 status = unmarshall_sec_desc(mem_ctx, (uint8 *)rdata, rdata_count,
59 &psd);
61 if (!NT_STATUS_IS_OK(status)) {
62 DEBUG(10, ("unmarshall_sec_desc failed: %s\n",
63 nt_errstr(status)));
64 goto cleanup;
67 cleanup:
69 SAFE_FREE(rparam);
70 SAFE_FREE(rdata);
72 return psd;
75 /****************************************************************************
76 set the security descriptor for a open file
77 ****************************************************************************/
78 bool cli_set_secdesc(struct cli_state *cli, int fnum, SEC_DESC *sd)
80 char param[8];
81 char *rparam=NULL, *rdata=NULL;
82 unsigned int rparam_count=0, rdata_count=0;
83 uint32 sec_info = 0;
84 TALLOC_CTX *frame = talloc_stackframe();
85 bool ret = False;
86 uint8 *data;
87 size_t len;
88 NTSTATUS status;
90 status = marshall_sec_desc(talloc_tos(), sd, &data, &len);
91 if (!NT_STATUS_IS_OK(status)) {
92 DEBUG(10, ("marshall_sec_desc failed: %s\n",
93 nt_errstr(status)));
94 goto cleanup;
97 SIVAL(param, 0, fnum);
99 if (sd->dacl)
100 sec_info |= DACL_SECURITY_INFORMATION;
101 if (sd->owner_sid)
102 sec_info |= OWNER_SECURITY_INFORMATION;
103 if (sd->group_sid)
104 sec_info |= GROUP_SECURITY_INFORMATION;
105 SSVAL(param, 4, sec_info);
107 if (!cli_send_nt_trans(cli,
108 NT_TRANSACT_SET_SECURITY_DESC,
110 NULL, 0, 0,
111 param, 8, 0,
112 (char *)data, len, 0)) {
113 DEBUG(1,("Failed to send NT_TRANSACT_SET_SECURITY_DESC\n"));
114 goto cleanup;
118 if (!cli_receive_nt_trans(cli,
119 &rparam, &rparam_count,
120 &rdata, &rdata_count)) {
121 DEBUG(1,("NT_TRANSACT_SET_SECURITY_DESC failed\n"));
122 goto cleanup;
125 ret = True;
127 cleanup:
129 SAFE_FREE(rparam);
130 SAFE_FREE(rdata);
132 TALLOC_FREE(frame);
134 return ret;