changed an error message
[jerry/samba.git] / source / libsmb / clisecdesc.c
1 /* 
2    Unix SMB/Netbios implementation.
3    Version 3.0
4    client security descriptor functions
5    Copyright (C) Andrew Tridgell 2000
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 2 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, write to the Free Software
19    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22 #define NO_SYSLOG
23
24 #include "includes.h"
25
26
27
28 /****************************************************************************
29   query the security descriptor for a open file
30   ****************************************************************************/
31 SEC_DESC *cli_query_secdesc(struct cli_state *cli,int fd)
32 {
33         char param[8];
34         char *rparam=NULL, *rdata=NULL;
35         int rparam_count=0, rdata_count=0;
36         TALLOC_CTX *mem_ctx;
37         prs_struct pd;
38         SEC_DESC *psd = NULL;
39         SEC_DESC *ret;
40
41         SIVAL(param, 0, fd);
42         SSVAL(param, 4, 0xf);
43
44         if (!cli_send_nt_trans(cli, 
45                                NT_TRANSACT_QUERY_SECURITY_DESC, 
46                                0, 
47                                NULL, 0, 0,
48                                param, 8, 4,
49                                NULL, 0, 0x10000)) {
50                 DEBUG(1,("Failed to send NT_TRANSACT_QUERY_SECURITY_DESC\n"));
51                 return NULL;
52         }
53
54
55         if (!cli_receive_nt_trans(cli, 
56                                   &rparam, &rparam_count,
57                                   &rdata, &rdata_count)) {
58                 DEBUG(1,("Failed to recv NT_TRANSACT_QUERY_SECURITY_DESC\n"));
59                 return NULL;
60         }
61
62         if ((mem_ctx = talloc_init()) == NULL) {
63                 DEBUG(0,("talloc_init failed.\n"));
64                 return NULL;
65         }
66
67         prs_init(&pd, rdata_count, 4, mem_ctx, UNMARSHALL);
68         prs_append_data(&pd, rdata, rdata_count);
69         pd.data_offset = 0;
70
71         if (!sec_io_desc("sd data", &psd, &pd, 1)) {
72                 DEBUG(1,("Failed to parse secdesc\n"));
73                 talloc_destroy(mem_ctx);
74                 return NULL;
75         }
76
77         ret = dup_sec_desc(psd);
78         talloc_destroy(mem_ctx);
79         return ret;
80 }
81
82
83
84
85 /****************************************************************************
86   set the security descriptor for a open file
87   ****************************************************************************/
88 BOOL cli_set_secdesc(struct cli_state *cli,int fd, SEC_DESC *sd)
89 {
90         char param[8];
91         char *rparam=NULL, *rdata=NULL;
92         int rparam_count=0, rdata_count=0;
93         TALLOC_CTX *mem_ctx;
94         prs_struct pd;
95
96         if ((mem_ctx = talloc_init()) == NULL) {
97                 DEBUG(0,("talloc_init failed.\n"));
98                 return False;
99         }
100
101         prs_init(&pd, 0, 4, mem_ctx, MARSHALL);
102         prs_give_memory(&pd, NULL, 0, True);
103
104         if (!sec_io_desc("sd data", &sd, &pd, 1)) {
105                 DEBUG(1,("Failed to marshall secdesc\n"));
106                 return False;
107         }
108
109         SIVAL(param, 0, fd);
110         SSVAL(param, 4, 0xf);
111
112         if (!cli_send_nt_trans(cli, 
113                                NT_TRANSACT_SET_SECURITY_DESC, 
114                                0, 
115                                NULL, 0, 0,
116                                param, 8, 0,
117                                pd.data_p, pd.data_offset, 0)) {
118                 DEBUG(1,("Failed to send NT_TRANSACT_SET_SECURITY_DESC\n"));
119                 return False;
120         }
121
122
123         if (!cli_receive_nt_trans(cli, 
124                                   &rparam, &rparam_count,
125                                   &rdata, &rdata_count)) {
126                 DEBUG(1,("NT_TRANSACT_SET_SECURITY_DESC failed\n"));
127                 return False;
128         }
129
130         if (rparam) free(rparam);
131         if (rdata) free(rdata);
132
133         talloc_destroy(mem_ctx);
134
135         return True;
136 }
137