first pass at updating head branch to be to be the same as the SAMBA_2_0 branch
[mimir/samba.git] / source3 / rpc_server / srv_reg.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  *  
9  *  This program is free software; you can redistribute it and/or modify
10  *  it under the terms of the GNU General Public License as published by
11  *  the Free Software Foundation; either version 2 of the License, or
12  *  (at your option) any later version.
13  *  
14  *  This program is distributed in the hope that it will be useful,
15  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  *  GNU General Public License for more details.
18  *  
19  *  You should have received a copy of the GNU General Public License
20  *  along with this program; if not, write to the Free Software
21  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22  */
23
24
25 #include "includes.h"
26 #include "nterr.h"
27
28 extern int DEBUGLEVEL;
29
30
31 /*******************************************************************
32  reg_reply_unknown_1
33  ********************************************************************/
34 static void reg_reply_close(REG_Q_CLOSE *q_r,
35                                 prs_struct *rdata)
36 {
37         REG_R_CLOSE r_u;
38
39         /* set up the REG unknown_1 response */
40         memset((char *)r_u.pol.data, '\0', POL_HND_SIZE);
41
42         /* close the policy handle */
43         if (close_lsa_policy_hnd(&(q_r->pol)))
44         {
45                 r_u.status = 0;
46         }
47         else
48         {
49                 r_u.status = 0xC0000000 | NT_STATUS_OBJECT_NAME_INVALID;
50         }
51
52         DEBUG(5,("reg_unknown_1: %d\n", __LINE__));
53
54         /* store the response in the SMB stream */
55         reg_io_r_close("", &r_u, rdata, 0);
56
57         DEBUG(5,("reg_unknown_1: %d\n", __LINE__));
58 }
59
60 /*******************************************************************
61  api_reg_close
62  ********************************************************************/
63 static BOOL api_reg_close( uint16 vuid, prs_struct *data,
64                                     prs_struct *rdata )
65 {
66         REG_Q_CLOSE q_r;
67
68         /* grab the reg unknown 1 */
69         reg_io_q_close("", &q_r, data, 0);
70
71         /* construct reply.  always indicate success */
72         reg_reply_close(&q_r, rdata);
73
74         return True;
75 }
76
77
78 /*******************************************************************
79  reg_reply_open
80  ********************************************************************/
81 static void reg_reply_open(REG_Q_OPEN_HKLM *q_r,
82                                 prs_struct *rdata)
83 {
84         REG_R_OPEN_HKLM r_u;
85
86         r_u.status = 0x0;
87         /* get a (unique) handle.  open a policy on it. */
88         if (r_u.status == 0x0 && !open_lsa_policy_hnd(&(r_u.pol)))
89         {
90                 r_u.status = 0xC0000000 | NT_STATUS_OBJECT_NAME_NOT_FOUND;
91         }
92
93         DEBUG(5,("reg_open: %d\n", __LINE__));
94
95         /* store the response in the SMB stream */
96         reg_io_r_open_hklm("", &r_u, rdata, 0);
97
98         DEBUG(5,("reg_open: %d\n", __LINE__));
99 }
100
101 /*******************************************************************
102  api_reg_open
103  ********************************************************************/
104 static BOOL api_reg_open( uint16 vuid, prs_struct *data,
105                                     prs_struct *rdata )
106 {
107         REG_Q_OPEN_HKLM q_u;
108
109         /* grab the reg open */
110         reg_io_q_open_hklm("", &q_u, data, 0);
111
112         /* construct reply.  always indicate success */
113         reg_reply_open(&q_u, rdata);
114
115         return True;
116 }
117
118
119 /*******************************************************************
120  reg_reply_open_entry
121  ********************************************************************/
122 static void reg_reply_open_entry(REG_Q_OPEN_ENTRY *q_u,
123                                 prs_struct *rdata)
124 {
125         uint32 status     = 0;
126         POLICY_HND pol;
127         REG_R_OPEN_ENTRY r_u;
128         fstring name;
129
130         DEBUG(5,("reg_open_entry: %d\n", __LINE__));
131
132         if (status == 0 && find_lsa_policy_by_hnd(&(q_u->pol)) == -1)
133         {
134                 status = 0xC000000 | NT_STATUS_INVALID_HANDLE;
135         }
136
137         if (status == 0x0 && !open_lsa_policy_hnd(&pol))
138         {
139                 status = 0xC000000 | NT_STATUS_TOO_MANY_SECRETS; /* ha ha very droll */
140         }
141
142         fstrcpy(name, dos_unistrn2(q_u->uni_name.buffer, q_u->uni_name.uni_str_len));
143
144         if (status == 0x0)
145         {
146                 DEBUG(5,("reg_open_entry: %s\n", name));
147                 /* lkcl XXXX do a check on the name, here */
148         }
149
150         if (status == 0x0 && !set_lsa_policy_reg_name(&pol, name))
151         {
152                 status = 0xC000000 | NT_STATUS_TOO_MANY_SECRETS; /* ha ha very droll */
153         }
154
155         init_reg_r_open_entry(&r_u, &pol, status);
156
157         /* store the response in the SMB stream */
158         reg_io_r_open_entry("", &r_u, rdata, 0);
159
160         DEBUG(5,("reg_open_entry: %d\n", __LINE__));
161 }
162
163 /*******************************************************************
164  api_reg_open_entry
165  ********************************************************************/
166 static BOOL api_reg_open_entry( uint16 vuid, prs_struct *data,
167                                     prs_struct *rdata )
168 {
169         REG_Q_OPEN_ENTRY q_u;
170
171         /* grab the reg open entry */
172         reg_io_q_open_entry("", &q_u, data, 0);
173
174         /* construct reply. */
175         reg_reply_open_entry(&q_u, rdata);
176
177         return True;
178 }
179
180
181 /*******************************************************************
182  reg_reply_info
183  ********************************************************************/
184 static void reg_reply_info(REG_Q_INFO *q_u,
185                                 prs_struct *rdata)
186 {
187         uint32 status     = 0;
188
189         REG_R_INFO r_u;
190
191         DEBUG(5,("reg_info: %d\n", __LINE__));
192
193         if (status == 0 && find_lsa_policy_by_hnd(&(q_u->pol)) == -1)
194         {
195                 status = 0xC000000 | NT_STATUS_INVALID_HANDLE;
196         }
197
198         if (status == 0)
199         {
200         }
201
202         init_reg_r_info(&r_u, 1, "LanmanNT", 0x12, 0x12, status);
203
204         /* store the response in the SMB stream */
205         reg_io_r_info("", &r_u, rdata, 0);
206
207         DEBUG(5,("reg_open_entry: %d\n", __LINE__));
208 }
209
210 /*******************************************************************
211  api_reg_info
212  ********************************************************************/
213 static BOOL api_reg_info( uint16 vuid, prs_struct *data,
214                                     prs_struct *rdata )
215 {
216         REG_Q_INFO q_u;
217
218         /* grab the reg unknown 0x11*/
219         reg_io_q_info("", &q_u, data, 0);
220
221         /* construct reply.  always indicate success */
222         reg_reply_info(&q_u, rdata);
223
224         return True;
225 }
226
227
228 /*******************************************************************
229  array of \PIPE\reg operations
230  ********************************************************************/
231 static struct api_struct api_reg_cmds[] =
232 {
233         { "REG_CLOSE"        , REG_CLOSE        , api_reg_close        },
234         { "REG_OPEN_ENTRY"   , REG_OPEN_ENTRY   , api_reg_open_entry   },
235         { "REG_OPEN"         , REG_OPEN_HKLM    , api_reg_open         },
236         { "REG_INFO"         , REG_INFO         , api_reg_info         },
237         { NULL,                0                , NULL                 }
238 };
239
240 /*******************************************************************
241  receives a reg pipe and responds.
242  ********************************************************************/
243 BOOL api_reg_rpc(pipes_struct *p, prs_struct *data)
244 {
245         return api_rpcTNP(p, "api_reg_rpc", api_reg_cmds, data);
246 }
247