The big character set handling changeover!
[kai/samba.git] / source3 / rpc_server / srv_reg_nt.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) Hewlett-Packard Company           1999.
9  *  Copyright (C) Jeremy Allison                                        2001.
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 /* Implementation of registry functions. */
27
28 #include "includes.h"
29
30 extern int DEBUGLEVEL;
31
32 struct reg_info
33 {
34     /* for use by \PIPE\winreg */
35     fstring name; /* name of registry key */
36 };
37
38 static void free_reg_info(void *ptr)
39 {
40         struct reg_info *info = (struct reg_info *)ptr;
41
42         safe_free(info);
43 }
44
45 /*******************************************************************
46  reg_reply_unknown_1
47  ********************************************************************/
48
49 uint32 _reg_close(pipes_struct *p, REG_Q_CLOSE *q_u, REG_R_CLOSE *r_u)
50 {
51         /* set up the REG unknown_1 response */
52         ZERO_STRUCT(r_u->pol);
53
54         /* close the policy handle */
55         if (!close_policy_hnd(p, &q_u->pol))
56                 return NT_STATUS_OBJECT_NAME_INVALID;
57
58         return NT_STATUS_NOPROBLEMO;
59 }
60
61 /*******************************************************************
62  reg_reply_open
63  ********************************************************************/
64
65 uint32 _reg_open(pipes_struct *p, REG_Q_OPEN_HKLM *q_u, REG_R_OPEN_HKLM *r_u)
66 {
67         if (!create_policy_hnd(p, &r_u->pol, free_reg_info, NULL))
68                 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
69
70         return NT_STATUS_NOPROBLEMO;
71 }
72
73 /*******************************************************************
74  reg_reply_open_entry
75  ********************************************************************/
76
77 uint32 _reg_open_entry(pipes_struct *p, REG_Q_OPEN_ENTRY *q_u, REG_R_OPEN_ENTRY *r_u)
78 {
79         POLICY_HND pol;
80         fstring name;
81         struct reg_info *info = NULL;
82
83         DEBUG(5,("reg_open_entry: %d\n", __LINE__));
84
85         if (!find_policy_by_hnd(p, &q_u->pol, NULL))
86                 return NT_STATUS_INVALID_HANDLE;
87
88         rpcstr_pull(name,q_u->uni_name.buffer,sizeof(name),q_u->uni_name.uni_str_len*2,0);
89
90         DEBUG(5,("reg_open_entry: %s\n", name));
91
92         /* lkcl XXXX do a check on the name, here */
93         if (!strequal(name, "SYSTEM\\CurrentControlSet\\Control\\ProductOptions") &&
94             !strequal(name, "System\\CurrentControlSet\\services\\Netlogon\\parameters\\"))
95                         return NT_STATUS_ACCESS_DENIED;
96
97         if ((info = (struct reg_info *)malloc(sizeof(struct reg_info))) == NULL)
98                 return NT_STATUS_NO_MEMORY;
99
100         ZERO_STRUCTP(info);
101         fstrcpy(info->name, name);
102
103         if (!create_policy_hnd(p, &pol, free_reg_info, (void *)info))
104                 return NT_STATUS_TOO_MANY_SECRETS; /* ha ha very droll */
105
106         init_reg_r_open_entry(r_u, &pol, NT_STATUS_NOPROBLEMO);
107
108         DEBUG(5,("reg_open_entry: %d\n", __LINE__));
109
110         return r_u->status;
111 }
112
113 /*******************************************************************
114  reg_reply_info
115  ********************************************************************/
116
117 uint32 _reg_info(pipes_struct *p, REG_Q_INFO *q_u, REG_R_INFO *r_u)
118 {
119         uint32 status = NT_STATUS_NOPROBLEMO;
120         char *key = NULL;
121         uint32 type=0x1; /* key type: REG_SZ */
122
123         UNISTR2 *uni_key = NULL;
124         BUFFER2 *buf = NULL;
125         fstring name;
126
127         DEBUG(5,("_reg_info: %d\n", __LINE__));
128
129         if (find_policy_by_hnd(p, &q_u->pol, NULL) == -1)
130                 return NT_STATUS_INVALID_HANDLE;
131
132         rpcstr_pull(name, q_u->uni_type.buffer, sizeof(name), q_u->uni_type.uni_str_len*2, 0);
133
134         DEBUG(5,("reg_info: checking key: %s\n", name));
135
136         uni_key = (UNISTR2 *)talloc_zero(p->mem_ctx, sizeof(UNISTR2));
137         buf = (BUFFER2 *)talloc_zero(p->mem_ctx, sizeof(BUFFER2));
138
139         if (!uni_key || !buf)
140                 return NT_STATUS_NO_MEMORY;
141
142         if ( strequal(name, "RefusePasswordChange") ) {
143                 type=0xF770;
144                 status = ERRbadfile;
145                 init_unistr2(uni_key, "", 0);
146                 init_buffer2(buf, (uint8*) uni_key->buffer, uni_key->uni_str_len*2);
147                 
148                 buf->buf_max_len=4;
149
150                 goto out;
151         }
152
153         switch (lp_server_role()) {
154         case ROLE_DOMAIN_PDC:
155         case ROLE_DOMAIN_BDC:
156                 key = "LanmanNT";
157                 break;
158         case ROLE_STANDALONE:
159                 key = "ServerNT";
160                 break;
161         case ROLE_DOMAIN_MEMBER:
162                 key = "WinNT";
163                 break;
164         }
165
166         /* This makes the server look like a member server to clients */
167         /* which tells clients that we have our own local user and    */
168         /* group databases and helps with ACL support.                */
169
170         init_unistr2(uni_key, key, strlen(key)+1);
171         init_buffer2(buf, (uint8*)uni_key->buffer, uni_key->uni_str_len*2);
172   
173  out:
174         init_reg_r_info(q_u->ptr_buf, r_u, buf, type, status);
175
176         DEBUG(5,("reg_open_entry: %d\n", __LINE__));
177
178         return status;
179 }