more merging voodoo
[vlendec/samba-autobuild/.git] / source3 / rpc_server / srv_reg.c
1 #define OLD_NTDOMAIN 1
2 /* 
3  *  Unix SMB/Netbios implementation.
4  *  Version 1.9.
5  *  RPC Pipe client / server routines
6  *  Copyright (C) Andrew Tridgell              1992-1997,
7  *  Copyright (C) Luke Kenneth Casson Leighton 1996-1997,
8  *  Copyright (C) Paul Ashton                       1997.
9  *  Copyright (C) Hewlett-Packard Company           1999.
10  *  
11  *  This program is free software; you can redistribute it and/or modify
12  *  it under the terms of the GNU General Public License as published by
13  *  the Free Software Foundation; either version 2 of the License, or
14  *  (at your option) any later version.
15  *  
16  *  This program is distributed in the hope that it will be useful,
17  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  *  GNU General Public License for more details.
20  *  
21  *  You should have received a copy of the GNU General Public License
22  *  along with this program; if not, write to the Free Software
23  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24  */
25
26 #include "includes.h"
27
28 extern int DEBUGLEVEL;
29
30 /*******************************************************************
31  reg_reply_unknown_1
32  ********************************************************************/
33 static void reg_reply_close(REG_Q_CLOSE *q_r,
34                                 prs_struct *rdata)
35 {
36         REG_R_CLOSE r_u;
37
38         /* set up the REG unknown_1 response */
39         memset((char *)r_u.pol.data, '\0', POL_HND_SIZE);
40
41         /* close the policy handle */
42         if (close_lsa_policy_hnd(&(q_r->pol)))
43         {
44                 r_u.status = 0;
45         }
46         else
47         {
48                 r_u.status = 0xC0000000 | NT_STATUS_OBJECT_NAME_INVALID;
49         }
50
51         DEBUG(5,("reg_unknown_1: %d\n", __LINE__));
52
53         /* store the response in the SMB stream */
54         reg_io_r_close("", &r_u, rdata, 0);
55
56         DEBUG(5,("reg_unknown_1: %d\n", __LINE__));
57 }
58
59 /*******************************************************************
60  api_reg_close
61  ********************************************************************/
62 static BOOL api_reg_close(prs_struct *data, prs_struct *rdata)
63 {
64         REG_Q_CLOSE q_r;
65
66         /* grab the reg unknown 1 */
67         reg_io_q_close("", &q_r, data, 0);
68
69         /* construct reply.  always indicate success */
70         reg_reply_close(&q_r, rdata);
71
72         return True;
73 }
74
75
76 /*******************************************************************
77  reg_reply_open
78  ********************************************************************/
79 static void reg_reply_open(REG_Q_OPEN_HKLM *q_r,
80                                 prs_struct *rdata)
81 {
82         REG_R_OPEN_HKLM r_u;
83
84         r_u.status = 0x0;
85         /* get a (unique) handle.  open a policy on it. */
86         if (r_u.status == 0x0 && !open_lsa_policy_hnd(&(r_u.pol)))
87         {
88                 r_u.status = 0xC0000000 | NT_STATUS_OBJECT_NAME_NOT_FOUND;
89         }
90
91         DEBUG(5,("reg_open: %d\n", __LINE__));
92
93         /* store the response in the SMB stream */
94         reg_io_r_open_hklm("", &r_u, rdata, 0);
95
96         DEBUG(5,("reg_open: %d\n", __LINE__));
97 }
98
99 /*******************************************************************
100  api_reg_open
101  ********************************************************************/
102 static BOOL api_reg_open(prs_struct *data, prs_struct *rdata)
103 {
104         REG_Q_OPEN_HKLM q_u;
105
106         /* grab the reg open */
107         reg_io_q_open_hklm("", &q_u, data, 0);
108
109         /* construct reply.  always indicate success */
110         reg_reply_open(&q_u, rdata);
111
112         return True;
113 }
114
115
116 /*******************************************************************
117  reg_reply_open_entry
118  ********************************************************************/
119 static void reg_reply_open_entry(REG_Q_OPEN_ENTRY *q_u,
120                                 prs_struct *rdata)
121 {
122         uint32 status     = 0;
123         POLICY_HND pol;
124         REG_R_OPEN_ENTRY r_u;
125         fstring name;
126
127         DEBUG(5,("reg_open_entry: %d\n", __LINE__));
128
129         if (status == 0 && find_lsa_policy_by_hnd(&(q_u->pol)) == -1)
130         {
131                 status = 0xC000000 | NT_STATUS_INVALID_HANDLE;
132         }
133
134         if (status == 0x0 && !open_lsa_policy_hnd(&pol))
135         {
136                 status = 0xC000000 | NT_STATUS_TOO_MANY_SECRETS; /* ha ha very droll */
137         }
138
139         fstrcpy(name, dos_unistrn2(q_u->uni_name.buffer, q_u->uni_name.uni_str_len));
140
141         if (status == 0x0)
142         {
143                 DEBUG(5,("reg_open_entry: %s\n", name));
144                 /* lkcl XXXX do a check on the name, here */
145                 if (!strequal(name, "SYSTEM\\CurrentControlSet\\Control\\ProductOptions"))
146                 {
147                         status = 0xC000000 | NT_STATUS_ACCESS_DENIED;
148                 }
149         }
150
151         if (status == 0x0 && !set_lsa_policy_reg_name(&pol, name))
152         {
153                 status = 0xC000000 | NT_STATUS_TOO_MANY_SECRETS; /* ha ha very droll */
154         }
155
156         init_reg_r_open_entry(&r_u, &pol, status);
157
158         /* store the response in the SMB stream */
159         reg_io_r_open_entry("", &r_u, rdata, 0);
160
161         DEBUG(5,("reg_open_entry: %d\n", __LINE__));
162 }
163
164 /*******************************************************************
165  api_reg_open_entry
166  ********************************************************************/
167 static BOOL api_reg_open_entry(prs_struct *data, 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         /* This makes the server look like a member server to clients */
203         /* which tells clients that we have our own local user and    */
204         /* group databases and helps with ACL support.                */
205         init_reg_r_info(&r_u, 1, "ServerNT", 0x12, 0x12, status);
206
207         /* store the response in the SMB stream */
208         reg_io_r_info("", &r_u, rdata, 0);
209
210         DEBUG(5,("reg_open_entry: %d\n", __LINE__));
211 }
212
213 /*******************************************************************
214  api_reg_info
215  ********************************************************************/
216 static BOOL api_reg_info(prs_struct *data, prs_struct *rdata)
217 {
218         REG_Q_INFO q_u;
219
220         /* grab the reg unknown 0x11*/
221         reg_io_q_info("", &q_u, data, 0);
222
223         /* construct reply.  always indicate success */
224         reg_reply_info(&q_u, rdata);
225
226         return True;
227 }
228
229
230 /*******************************************************************
231  array of \PIPE\reg operations
232  ********************************************************************/
233 static struct api_struct api_reg_cmds[] =
234 {
235         { "REG_CLOSE"        , REG_CLOSE        , api_reg_close        },
236         { "REG_OPEN_ENTRY"   , REG_OPEN_ENTRY   , api_reg_open_entry   },
237         { "REG_OPEN"         , REG_OPEN_HKLM    , api_reg_open         },
238         { "REG_INFO"         , REG_INFO         , api_reg_info         },
239         { NULL,                0                , NULL                 }
240 };
241
242 /*******************************************************************
243  receives a reg pipe and responds.
244  ********************************************************************/
245 BOOL api_reg_rpc(pipes_struct *p, prs_struct *data)
246 {
247         return api_rpcTNP(p, "api_reg_rpc", api_reg_cmds, data);
248 }
249
250 #undef OLD_NTDOMAIN