this now works as a add|delete share command :-)
[Samba.git] / source / libsmb / clisecdesc.c
blob69c7d5f73fda2cfc1899f21943db9a9d97dc17ae
1 /*
2 Unix SMB/Netbios implementation.
3 Version 3.0
4 client security descriptor functions
5 Copyright (C) Andrew Tridgell 2000
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 2 of the License, or
10 (at your option) any later version.
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.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #define NO_SYSLOG
24 #include "includes.h"
28 /****************************************************************************
29 query the security descriptor for a open file
30 ****************************************************************************/
31 SEC_DESC *cli_query_secdesc(struct cli_state *cli,int fd, TALLOC_CTX *mem_ctx)
33 char param[8];
34 char *rparam=NULL, *rdata=NULL;
35 int rparam_count=0, rdata_count=0;
36 prs_struct pd;
37 SEC_DESC *psd = NULL;
39 SIVAL(param, 0, fd);
40 SSVAL(param, 4, 0x7);
42 if (!cli_send_nt_trans(cli,
43 NT_TRANSACT_QUERY_SECURITY_DESC,
44 0,
45 NULL, 0, 0,
46 param, 8, 4,
47 NULL, 0, 0x10000)) {
48 DEBUG(1,("Failed to send NT_TRANSACT_QUERY_SECURITY_DESC\n"));
49 goto cleanup;
53 if (!cli_receive_nt_trans(cli,
54 &rparam, &rparam_count,
55 &rdata, &rdata_count)) {
56 DEBUG(1,("Failed to recv NT_TRANSACT_QUERY_SECURITY_DESC\n"));
57 goto cleanup;
60 prs_init(&pd, rdata_count, mem_ctx, UNMARSHALL);
61 prs_append_data(&pd, rdata, rdata_count);
62 pd.data_offset = 0;
64 if (!sec_io_desc("sd data", &psd, &pd, 1)) {
65 DEBUG(1,("Failed to parse secdesc\n"));
66 goto cleanup;
69 cleanup:
71 safe_free(rparam);
72 safe_free(rdata);
74 prs_mem_free(&pd);
75 return psd;
78 /****************************************************************************
79 set the security descriptor for a open file
80 ****************************************************************************/
81 BOOL cli_set_secdesc(struct cli_state *cli,int fd, SEC_DESC *sd)
83 char param[8];
84 char *rparam=NULL, *rdata=NULL;
85 int rparam_count=0, rdata_count=0;
86 TALLOC_CTX *mem_ctx;
87 prs_struct pd;
88 BOOL ret = False;
90 if ((mem_ctx = talloc_init()) == NULL) {
91 DEBUG(0,("talloc_init failed.\n"));
92 goto cleanup;
95 prs_init(&pd, 0, mem_ctx, MARSHALL);
96 prs_give_memory(&pd, NULL, 0, True);
98 if (!sec_io_desc("sd data", &sd, &pd, 1)) {
99 DEBUG(1,("Failed to marshall secdesc\n"));
100 goto cleanup;
103 SIVAL(param, 0, fd);
104 SSVAL(param, 4, 0x7);
106 if (!cli_send_nt_trans(cli,
107 NT_TRANSACT_SET_SECURITY_DESC,
109 NULL, 0, 0,
110 param, 8, 0,
111 pd.data_p, pd.data_offset, 0)) {
112 DEBUG(1,("Failed to send NT_TRANSACT_SET_SECURITY_DESC\n"));
113 goto cleanup;
117 if (!cli_receive_nt_trans(cli,
118 &rparam, &rparam_count,
119 &rdata, &rdata_count)) {
120 DEBUG(1,("NT_TRANSACT_SET_SECURITY_DESC failed\n"));
121 goto cleanup;
124 ret = True;
126 cleanup:
128 safe_free(rparam);
129 safe_free(rdata);
131 talloc_destroy(mem_ctx);
133 prs_mem_free(&pd);
134 return ret;