r4484: - use the nTMixedDomain attribute to check if our domain is mixed mode or not
[samba.git] / source4 / rpc_server / dssetup / dcesrv_dssetup.c
1 /* 
2    Unix SMB/CIFS implementation.
3
4    endpoint server for the dssetup pipe
5
6    Copyright (C) Andrew Tridgell 2004
7    
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2 of the License, or
11    (at your option) any later version.
12    
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17    
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 #include "includes.h"
24 #include "rpc_server/dcerpc_server.h"
25 #include "librpc/gen_ndr/ndr_dssetup.h"
26 #include "rpc_server/common/common.h"
27
28
29 /* 
30   dssetup_DsRoleGetPrimaryDomainInformation 
31 */
32 static WERROR dssetup_DsRoleGetPrimaryDomainInformation(struct dcesrv_call_state *dce_call, 
33                                                         TALLOC_CTX *mem_ctx,
34                                                         struct dssetup_DsRoleGetPrimaryDomainInformation *r)
35 {
36         ZERO_STRUCT(r->out);
37
38         switch (r->in.level) {
39         case DS_ROLE_BASIC_INFORMATION:
40         {
41                 void *sam_ctx;
42                 const char * const attrs[] = { "dnsDomain", "nTMixedDomain", "objectGUID", "name", NULL };
43                 int ret;
44                 struct ldb_message **res;
45                 union dssetup_DsRoleInfo *info;
46                 enum dssetup_DsRole role = DS_ROLE_STANDALONE_SERVER;
47                 uint32 flags = 0;
48                 const char *domain = NULL;
49                 const char *dns_domain = NULL;
50                 const char *forest = NULL;
51                 struct GUID domain_guid;
52
53                 ZERO_STRUCT(domain_guid);
54
55                 info = talloc_p(mem_ctx, union dssetup_DsRoleInfo);
56                 W_ERROR_HAVE_NO_MEMORY(info);
57
58                 /* TODO: we need to find out what we should return as standalone server */
59
60                 switch (lp_server_role()) {
61                 case ROLE_STANDALONE:
62                         role            = DS_ROLE_STANDALONE_SERVER;
63                         break;
64                 case ROLE_DOMAIN_MEMBER:
65                         role            = DS_ROLE_MEMBER_SERVER;
66                         break;
67                 case ROLE_DOMAIN_BDC:
68                         role            = DS_ROLE_BACKUP_DC;
69                         break;
70                 case ROLE_DOMAIN_PDC:
71                         role            = DS_ROLE_PRIMARY_DC;
72                         break;
73                 }
74
75                 switch (lp_server_role()) {
76                 case ROLE_STANDALONE:
77                         domain          = talloc_strdup(mem_ctx, lp_workgroup());
78                         W_ERROR_HAVE_NO_MEMORY(domain);
79                         break;
80                 case ROLE_DOMAIN_MEMBER:
81                         domain          = talloc_strdup(mem_ctx, lp_workgroup());
82                         W_ERROR_HAVE_NO_MEMORY(domain);
83                         /* TODO: what is with dns_domain and forest and guid? */
84                         break;
85                 case ROLE_DOMAIN_BDC:
86                 case ROLE_DOMAIN_PDC:
87                         sam_ctx = samdb_connect(mem_ctx);
88                         if (!sam_ctx) {
89                                 return WERR_SERVER_UNAVAILABLE;
90                         }
91
92                         ret = samdb_search(sam_ctx, mem_ctx, NULL, &res, attrs,
93                                            "(&(objectClass=domainDNS)(!(objectClass=builtinDomain)))");
94                         if (ret != 1) {
95                                 return WERR_SERVER_UNAVAILABLE;
96                         }
97
98                         flags           = DS_ROLE_PRIMARY_DS_RUNNING;
99
100                         if (samdb_result_uint(res[0], "nTMixedDomain", 0) == 1) {
101                                 flags           |= DS_ROLE_PRIMARY_DS_MIXED_MODE;
102                         }
103
104                         domain          = samdb_result_string(res[0], "name", NULL);
105                         dns_domain      = samdb_result_string(res[0], "dnsDomain", NULL);
106                         forest          = samdb_result_string(res[0], "dnsDomain", NULL);
107
108                         flags           |= DS_ROLE_PRIMARY_DOMAIN_GUID_PRESENT;
109                         domain_guid     = samdb_result_guid(res[0], "objectGUID");
110                         break;
111                 }
112
113                 info->basic.role        = role; 
114                 info->basic.flags       = flags;
115                 info->basic.domain      = domain;
116                 info->basic.dns_domain  = dns_domain;
117                 info->basic.forest      = forest;
118                 info->basic.domain_guid = domain_guid;
119
120                 r->out.info = info;
121                 return WERR_OK;
122         }
123         case DS_ROLE_UPGRADE_STATUS:
124         {
125                 union dssetup_DsRoleInfo *info;
126
127                 info = talloc_p(mem_ctx, union dssetup_DsRoleInfo);
128                 W_ERROR_HAVE_NO_MEMORY(info);
129
130                 info->upgrade.upgrading     = DS_ROLE_NOT_UPGRADING;
131                 info->upgrade.previous_role = DS_ROLE_PREVIOUS_UNKNOWN;
132
133                 r->out.info = info;
134                 return WERR_OK;
135         }
136         case DS_ROLE_OP_STATUS:
137         {
138                 union dssetup_DsRoleInfo *info;
139
140                 info = talloc_p(mem_ctx, union dssetup_DsRoleInfo);
141                 W_ERROR_HAVE_NO_MEMORY(info);
142
143                 info->opstatus.status = DS_ROLE_OP_IDLE;
144
145                 r->out.info = info;
146                 return WERR_OK;
147         }
148         default:
149                 return WERR_INVALID_PARAM;
150         }
151
152         return WERR_INVALID_PARAM;
153 }
154
155
156 /*****************************************
157 NOTE! The remaining calls below were
158 removed in w2k3, so the DCESRV_FAULT()
159 replies are the correct implementation. Do
160 not try and fill these in with anything else
161 ******************************************/
162
163 /* 
164   dssetup_DsRoleDnsNameToFlatName 
165 */
166 static WERROR dssetup_DsRoleDnsNameToFlatName(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
167                                         struct dssetup_DsRoleDnsNameToFlatName *r)
168 {
169         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
170 }
171
172
173 /* 
174   dssetup_DsRoleDcAsDc 
175 */
176 static WERROR dssetup_DsRoleDcAsDc(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
177                              struct dssetup_DsRoleDcAsDc *r)
178 {
179         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
180 }
181
182
183 /* 
184   dssetup_DsRoleDcAsReplica 
185 */
186 static WERROR dssetup_DsRoleDcAsReplica(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
187                                   struct dssetup_DsRoleDcAsReplica *r)
188 {
189         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
190 }
191
192
193 /* 
194   dssetup_DsRoleDemoteDc 
195 */
196 static WERROR dssetup_DsRoleDemoteDc(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
197                                struct dssetup_DsRoleDemoteDc *r)
198 {
199         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
200 }
201
202
203 /* 
204   dssetup_DsRoleGetDcOperationProgress 
205 */
206 static WERROR dssetup_DsRoleGetDcOperationProgress(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
207                                              struct dssetup_DsRoleGetDcOperationProgress *r)
208 {
209         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
210 }
211
212
213 /* 
214   dssetup_DsRoleGetDcOperationResults 
215 */
216 static WERROR dssetup_DsRoleGetDcOperationResults(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
217                                             struct dssetup_DsRoleGetDcOperationResults *r)
218 {
219         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
220 }
221
222
223 /* 
224   dssetup_DsRoleCancel 
225 */
226 static WERROR dssetup_DsRoleCancel(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
227                              struct dssetup_DsRoleCancel *r)
228 {
229         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
230 }
231
232
233 /* 
234   dssetup_DsRoleServerSaveStateForUpgrade 
235 */
236 static WERROR dssetup_DsRoleServerSaveStateForUpgrade(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
237                                                 struct dssetup_DsRoleServerSaveStateForUpgrade *r)
238 {
239         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
240 }
241
242
243 /* 
244   dssetup_DsRoleUpgradeDownlevelServer 
245 */
246 static WERROR dssetup_DsRoleUpgradeDownlevelServer(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
247                                              struct dssetup_DsRoleUpgradeDownlevelServer *r)
248 {
249         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
250 }
251
252
253 /* 
254   dssetup_DsRoleAbortDownlevelServerUpgrade 
255 */
256 static WERROR dssetup_DsRoleAbortDownlevelServerUpgrade(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
257                                                   struct dssetup_DsRoleAbortDownlevelServerUpgrade *r)
258 {
259         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
260 }
261
262
263 /* include the generated boilerplate */
264 #include "librpc/gen_ndr/ndr_dssetup_s.c"