Merge of new 2.2 code into HEAD (Gerald I hate you :-) :-). Allows new SAMR
[kai/samba.git] / source / rpc_server / srv_lsa.c
1 /* 
2  *  Unix SMB/Netbios implementation.
3  *  Version 1.9.
4  *  RPC Pipe client / server routines
5  *  Copyright (C) Andrew Tridgell              1992-1997,
6  *  Copyright (C) Luke Kenneth Casson Leighton 1996-1997,
7  *  Copyright (C) Paul Ashton                       1997.
8  *  Copyright (C) Jeremy Allison                    2001.
9  *
10  *  This program is free software; you can redistribute it and/or modify
11  *  it under the terms of the GNU General Public License as published by
12  *  the Free Software Foundation; either version 2 of the License, or
13  *  (at your option) any later version.
14  *  
15  *  This program is distributed in the hope that it will be useful,
16  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  *  GNU General Public License for more details.
19  *  
20  *  You should have received a copy of the GNU General Public License
21  *  along with this program; if not, write to the Free Software
22  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23  */
24
25 /* This is the interface to the lsa server code. */
26
27 #include "includes.h"
28
29 extern int DEBUGLEVEL;
30
31 /***************************************************************************
32  api_lsa_open_policy2
33  ***************************************************************************/
34
35 static BOOL api_lsa_open_policy2(pipes_struct *p)
36 {
37         LSA_Q_OPEN_POL2 q_u;
38         LSA_R_OPEN_POL2 r_u;
39         prs_struct *data = &p->in_data.data;
40         prs_struct *rdata = &p->out_data.rdata;
41
42         ZERO_STRUCT(q_u);
43         ZERO_STRUCT(r_u);
44
45         /* grab the server, object attributes and desired access flag...*/
46         if(!lsa_io_q_open_pol2("", &q_u, data, 0)) {
47                 DEBUG(0,("api_lsa_open_policy2: unable to unmarshall LSA_Q_OPEN_POL2.\n"));
48                 return False;
49         }
50
51         r_u.status = _lsa_open_policy2(p, &q_u, &r_u);
52
53         /* store the response in the SMB stream */
54         if(!lsa_io_r_open_pol2("", &r_u, rdata, 0)) {
55                 DEBUG(0,("api_lsa_open_policy2: unable to marshall LSA_R_OPEN_POL2.\n"));
56                 return False;
57         }
58
59         return True;
60 }
61
62 /***************************************************************************
63 api_lsa_open_policy
64  ***************************************************************************/
65
66 static BOOL api_lsa_open_policy(pipes_struct *p)
67 {
68         LSA_Q_OPEN_POL q_u;
69         LSA_R_OPEN_POL r_u;
70         prs_struct *data = &p->in_data.data;
71         prs_struct *rdata = &p->out_data.rdata;
72
73         ZERO_STRUCT(q_u);
74         ZERO_STRUCT(r_u);
75
76         /* grab the server, object attributes and desired access flag...*/
77         if(!lsa_io_q_open_pol("", &q_u, data, 0)) {
78                 DEBUG(0,("api_lsa_open_policy: unable to unmarshall LSA_Q_OPEN_POL.\n"));
79                 return False;
80         }
81
82         r_u.status = _lsa_open_policy(p, &q_u, &r_u);
83
84         /* store the response in the SMB stream */
85         if(!lsa_io_r_open_pol("", &r_u, rdata, 0)) {
86                 DEBUG(0,("api_lsa_open_policy: unable to marshall LSA_R_OPEN_POL.\n"));
87                 return False;
88         }
89
90         return True;
91 }
92
93 /***************************************************************************
94  api_lsa_enum_trust_dom
95  ***************************************************************************/
96
97 static BOOL api_lsa_enum_trust_dom(pipes_struct *p)
98 {
99         LSA_Q_ENUM_TRUST_DOM q_u;
100         LSA_R_ENUM_TRUST_DOM r_u;
101         prs_struct *data = &p->in_data.data;
102         prs_struct *rdata = &p->out_data.rdata;
103
104         ZERO_STRUCT(q_u);
105         ZERO_STRUCT(r_u);
106
107         /* grab the enum trust domain context etc. */
108         if(!lsa_io_q_enum_trust_dom("", &q_u, data, 0))
109                 return False;
110
111         r_u.status = _lsa_enum_trust_dom(p, &q_u, &r_u);
112
113         if(!lsa_io_r_enum_trust_dom("", &r_u, rdata, 0))
114                 return False;
115
116         return True;
117 }
118
119 /***************************************************************************
120  api_lsa_query_info
121  ***************************************************************************/
122
123 static BOOL api_lsa_query_info(pipes_struct *p)
124 {
125         LSA_Q_QUERY_INFO q_u;
126         LSA_R_QUERY_INFO r_u;
127         prs_struct *data = &p->in_data.data;
128         prs_struct *rdata = &p->out_data.rdata;
129
130         ZERO_STRUCT(q_u);
131         ZERO_STRUCT(r_u);
132
133         /* grab the info class and policy handle */
134         if(!lsa_io_q_query("", &q_u, data, 0)) {
135                 DEBUG(0,("api_lsa_query_info: failed to unmarshall LSA_Q_QUERY_INFO.\n"));
136                 return False;
137         }
138
139         r_u.status = _lsa_query_info(p, &q_u, &r_u);
140
141         /* store the response in the SMB stream */
142         if(!lsa_io_r_query("", &r_u, rdata, 0)) {
143                 DEBUG(0,("api_lsa_query_info: failed to marshall LSA_R_QUERY_INFO.\n"));
144                 return False;
145         }
146
147         return True;
148 }
149
150 /***************************************************************************
151  api_lsa_lookup_sids
152  ***************************************************************************/
153
154 static BOOL api_lsa_lookup_sids(pipes_struct *p)
155 {
156         LSA_Q_LOOKUP_SIDS q_u;
157         LSA_R_LOOKUP_SIDS r_u;
158         prs_struct *data = &p->in_data.data;
159         prs_struct *rdata = &p->out_data.rdata;
160
161         ZERO_STRUCT(q_u);
162         ZERO_STRUCT(r_u);
163
164         /* grab the info class and policy handle */
165         if(!lsa_io_q_lookup_sids("", &q_u, data, 0)) {
166                 DEBUG(0,("api_lsa_lookup_sids: failed to unmarshall LSA_Q_LOOKUP_SIDS.\n"));
167                 return False;
168         }
169
170         r_u.status = _lsa_lookup_sids(p, &q_u, &r_u);
171
172         if(!lsa_io_r_lookup_sids("", &r_u, rdata, 0)) {
173                 DEBUG(0,("api_lsa_lookup_sids: Failed to marshall LSA_R_LOOKUP_SIDS.\n"));
174                 return False;
175         }
176
177         return True;
178 }
179
180 /***************************************************************************
181  api_lsa_lookup_names
182  ***************************************************************************/
183
184 static BOOL api_lsa_lookup_names(pipes_struct *p)
185 {
186         LSA_Q_LOOKUP_NAMES q_u;
187         LSA_R_LOOKUP_NAMES r_u;
188         prs_struct *data = &p->in_data.data;
189         prs_struct *rdata = &p->out_data.rdata;
190
191         ZERO_STRUCT(q_u);
192         ZERO_STRUCT(r_u);
193
194         /* grab the info class and policy handle */
195         if(!lsa_io_q_lookup_names("", &q_u, data, 0)) {
196                 DEBUG(0,("api_lsa_lookup_names: failed to unmarshall LSA_Q_LOOKUP_NAMES.\n"));
197                 return False;
198         }
199
200         r_u.status = _lsa_lookup_names(p, &q_u, &r_u);
201
202         /* store the response in the SMB stream */
203         if(!lsa_io_r_lookup_names("", &r_u, rdata, 0)) {
204                 DEBUG(0,("api_lsa_lookup_names: Failed to marshall LSA_R_LOOKUP_NAMES.\n"));
205                 return False;
206         }
207
208         return True;
209 }
210
211 /***************************************************************************
212  api_lsa_close.
213  ***************************************************************************/
214
215 static BOOL api_lsa_close(pipes_struct *p)
216 {
217         LSA_Q_CLOSE q_u;
218         LSA_R_CLOSE r_u;
219         prs_struct *data = &p->in_data.data;
220         prs_struct *rdata = &p->out_data.rdata;
221
222         ZERO_STRUCT(q_u);
223         ZERO_STRUCT(r_u);
224
225         if (!lsa_io_q_close("", &q_u, data, 0)) {
226                 DEBUG(0,("api_lsa_close: lsa_io_q_close failed.\n"));
227                 return False;
228         }
229
230         r_u.status = _lsa_close(p, &q_u, &r_u);
231
232         /* store the response in the SMB stream */
233         if (!lsa_io_r_close("", &r_u, rdata, 0)) {
234                 DEBUG(0,("api_lsa_close: lsa_io_r_close failed.\n"));
235                 return False;
236         }
237
238         return True;
239 }
240
241 /***************************************************************************
242  api_lsa_open_secret.
243  ***************************************************************************/
244
245 static BOOL api_lsa_open_secret(pipes_struct *p)
246 {
247         LSA_Q_OPEN_SECRET q_u;
248         LSA_R_OPEN_SECRET r_u;
249         prs_struct *data = &p->in_data.data;
250         prs_struct *rdata = &p->out_data.rdata;
251
252         ZERO_STRUCT(q_u);
253         ZERO_STRUCT(r_u);
254
255         if(!lsa_io_q_open_secret("", &q_u, data, 0)) {
256                 DEBUG(0,("api_lsa_open_secret: failed to unmarshall LSA_Q_OPEN_SECRET.\n"));
257                 return False;
258         }
259
260         r_u.status = _lsa_open_secret(p, &q_u, &r_u);
261
262         /* store the response in the SMB stream */
263         if(!lsa_io_r_open_secret("", &r_u, rdata, 0)) {
264                 DEBUG(0,("api_lsa_open_secret: Failed to marshall LSA_R_OPEN_SECRET.\n"));
265                 return False;
266         }
267
268         return True;
269 }
270
271 /***************************************************************************
272  \PIPE\ntlsa commands
273  ***************************************************************************/
274
275 static struct api_struct api_lsa_cmds[] =
276 {
277         { "LSA_OPENPOLICY2"     , LSA_OPENPOLICY2     , api_lsa_open_policy2   },
278         { "LSA_OPENPOLICY"      , LSA_OPENPOLICY      , api_lsa_open_policy    },
279         { "LSA_QUERYINFOPOLICY" , LSA_QUERYINFOPOLICY , api_lsa_query_info     },
280         { "LSA_ENUMTRUSTDOM"    , LSA_ENUMTRUSTDOM    , api_lsa_enum_trust_dom },
281         { "LSA_CLOSE"           , LSA_CLOSE           , api_lsa_close          },
282         { "LSA_OPENSECRET"      , LSA_OPENSECRET      , api_lsa_open_secret    },
283         { "LSA_LOOKUPSIDS"      , LSA_LOOKUPSIDS      , api_lsa_lookup_sids    },
284         { "LSA_LOOKUPNAMES"     , LSA_LOOKUPNAMES     , api_lsa_lookup_names   },
285         { NULL                  , 0                   , NULL                   }
286 };
287
288 /***************************************************************************
289  api_ntLsarpcTNP
290  ***************************************************************************/
291 BOOL api_ntlsa_rpc(pipes_struct *p)
292 {
293         return api_rpcTNP(p, "api_ntlsa_rpc", api_lsa_cmds);
294 }