4bd97abb6589e0e220ff84ee98b3ddadd3ebff14
[bbaumbach/samba-autobuild/.git] / source / rpc_server / srv_reg_nt.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  *  Copyright (C) Jeremy Allison                                        2001.
11  *
12  *  This program is free software; you can redistribute it and/or modify
13  *  it under the terms of the GNU General Public License as published by
14  *  the Free Software Foundation; either version 2 of the License, or
15  *  (at your option) any later version.
16  *  
17  *  This program is distributed in the hope that it will be useful,
18  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
19  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  *  GNU General Public License for more details.
21  *  
22  *  You should have received a copy of the GNU General Public License
23  *  along with this program; if not, write to the Free Software
24  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25  */
26
27 /* Implementation of registry functions. */
28
29 #include "includes.h"
30
31 extern int DEBUGLEVEL;
32
33 /*******************************************************************
34  reg_reply_unknown_1
35  ********************************************************************/
36
37 uint32 _reg_close(pipes_struct *p, REG_Q_CLOSE *q_u, REG_R_CLOSE *r_u)
38 {
39         /* set up the REG unknown_1 response */
40         ZERO_STRUCT(r_u->pol);
41
42         /* close the policy handle */
43         if (!close_lsa_policy_hnd(&q_u->pol))
44                 return NT_STATUS_OBJECT_NAME_INVALID;
45
46         return NT_STATUS_NOPROBLEMO;
47 }
48
49 /*******************************************************************
50  reg_reply_open
51  ********************************************************************/
52
53 uint32 _reg_open(pipes_struct *p, REG_Q_OPEN_HKLM *q_u, REG_R_OPEN_HKLM *r_u)
54 {
55         if (!open_lsa_policy_hnd(&r_u->pol))
56                 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
57
58         return NT_STATUS_NOPROBLEMO;
59 }
60
61 /*******************************************************************
62  reg_reply_open_entry
63  ********************************************************************/
64
65 uint32 _reg_open_entry(pipes_struct *p, REG_Q_OPEN_ENTRY *q_u, REG_R_OPEN_ENTRY *r_u)
66 {
67         POLICY_HND pol;
68         fstring name;
69
70         DEBUG(5,("reg_open_entry: %d\n", __LINE__));
71
72         if (find_lsa_policy_by_hnd(&q_u->pol) == -1)
73                 return NT_STATUS_INVALID_HANDLE;
74
75         if (!open_lsa_policy_hnd(&pol))
76                 return NT_STATUS_TOO_MANY_SECRETS; /* ha ha very droll */
77
78         fstrcpy(name, dos_unistrn2(q_u->uni_name.buffer, q_u->uni_name.uni_str_len));
79
80         DEBUG(5,("reg_open_entry: %s\n", name));
81
82         /* lkcl XXXX do a check on the name, here */
83         if (!strequal(name, "SYSTEM\\CurrentControlSet\\Control\\ProductOptions") &&
84             !strequal(name, "System\\CurrentControlSet\\services\\Netlogon\\parameters\\"))
85                         return NT_STATUS_ACCESS_DENIED;
86
87         if (!set_lsa_policy_reg_name(&pol, name))
88                 return NT_STATUS_TOO_MANY_SECRETS; /* ha ha very droll */
89
90         init_reg_r_open_entry(r_u, &pol, NT_STATUS_NOPROBLEMO);
91
92         DEBUG(5,("reg_open_entry: %d\n", __LINE__));
93
94         return r_u->status;
95 }
96
97 /*******************************************************************
98  reg_reply_info
99  ********************************************************************/
100
101 uint32 _reg_info(pipes_struct *p, REG_Q_INFO *q_u, REG_R_INFO *r_u)
102 {
103         uint32 status = NT_STATUS_NOPROBLEMO;
104         char *key;
105         uint32 type=0x1; /* key type: REG_SZ */
106
107         UNISTR2 *uni_key = NULL;
108         BUFFER2 *buf = NULL;
109         fstring name;
110
111         DEBUG(5,("_reg_info: %d\n", __LINE__));
112
113         if (find_lsa_policy_by_hnd(&q_u->pol) == -1)
114                 return NT_STATUS_INVALID_HANDLE;
115
116         fstrcpy(name, dos_unistrn2(q_u->uni_type.buffer, q_u->uni_type.uni_str_len));
117
118         DEBUG(5,("reg_info: checking key: %s\n", name));
119
120         uni_key = (UNISTR2 *)talloc_zero(p->mem_ctx, sizeof(UNISTR2));
121         buf = (BUFFER2 *)talloc_zero(p->mem_ctx, sizeof(BUFFER2));
122
123         if (!uni_key || !buf)
124                 return NT_STATUS_NO_MEMORY;
125
126         if ( strequal(name, "RefusePasswordChange") ) {
127                 type=0xF770;
128                 status = ERRbadfile;
129                 init_unistr2(uni_key, "", 0);
130                 init_buffer2(buf, (uint8*) uni_key->buffer, uni_key->uni_str_len*2);
131                 
132                 buf->buf_max_len=4;
133
134                 goto out;
135         }
136
137         switch (lp_server_role()) {
138         case ROLE_DOMAIN_PDC:
139         case ROLE_DOMAIN_BDC:
140                 key = "LanmanNT";
141                 break;
142         case ROLE_STANDALONE:
143                 key = "ServerNT";
144                 break;
145         case ROLE_DOMAIN_MEMBER:
146                 key = "WinNT";
147                 break;
148         }
149
150         /* This makes the server look like a member server to clients */
151         /* which tells clients that we have our own local user and    */
152         /* group databases and helps with ACL support.                */
153
154         init_unistr2(uni_key, key, strlen(key)+1);
155         init_buffer2(buf, (uint8*)uni_key->buffer, uni_key->uni_str_len*2);
156   
157  out:
158         init_reg_r_info(q_u->ptr_buf, r_u, buf, type, status);
159
160         DEBUG(5,("reg_open_entry: %d\n", __LINE__));
161
162         return status;
163 }
164 #undef OLD_NTDOMAIN