r4483: - rename same structs, enums and uninons of the dssetup pipe
[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", "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           = 0;
99                         flags           |= DS_ROLE_PRIMARY_DS_RUNNING;
100                         flags           |= DS_ROLE_PRIMARY_DS_MIXED_MODE;
101                         flags           |= DS_ROLE_PRIMARY_DOMAIN_GUID_PRESENT;
102                         domain          = samdb_result_string(res[0], "name", NULL);
103                         dns_domain      = samdb_result_string(res[0], "dnsDomain", NULL);
104                         forest          = samdb_result_string(res[0], "dnsDomain", NULL);
105                         domain_guid     = samdb_result_guid(res[0], "objectGUID");
106                         break;
107                 }
108
109                 info->basic.role        = role; 
110                 info->basic.flags       = flags;
111                 info->basic.domain      = domain;
112                 info->basic.dns_domain  = dns_domain;
113                 info->basic.forest      = forest;
114                 info->basic.domain_guid = domain_guid;
115
116                 r->out.info = info;
117                 return WERR_OK;
118         }
119         case DS_ROLE_UPGRADE_STATUS:
120         {
121                 union dssetup_DsRoleInfo *info;
122
123                 info = talloc_p(mem_ctx, union dssetup_DsRoleInfo);
124                 W_ERROR_HAVE_NO_MEMORY(info);
125
126                 info->upgrade.upgrading     = DS_ROLE_NOT_UPGRADING;
127                 info->upgrade.previous_role = DS_ROLE_PREVIOUS_UNKNOWN;
128
129                 r->out.info = info;
130                 return WERR_OK;
131         }
132         case DS_ROLE_OP_STATUS:
133         {
134                 union dssetup_DsRoleInfo *info;
135
136                 info = talloc_p(mem_ctx, union dssetup_DsRoleInfo);
137                 W_ERROR_HAVE_NO_MEMORY(info);
138
139                 info->opstatus.status = DS_ROLE_OP_IDLE;
140
141                 r->out.info = info;
142                 return WERR_OK;
143         }
144         default:
145                 return WERR_INVALID_PARAM;
146         }
147
148         return WERR_INVALID_PARAM;
149 }
150
151
152 /*****************************************
153 NOTE! The remaining calls below were
154 removed in w2k3, so the DCESRV_FAULT()
155 replies are the correct implementation. Do
156 not try and fill these in with anything else
157 ******************************************/
158
159 /* 
160   dssetup_DsRoleDnsNameToFlatName 
161 */
162 static WERROR dssetup_DsRoleDnsNameToFlatName(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
163                                         struct dssetup_DsRoleDnsNameToFlatName *r)
164 {
165         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
166 }
167
168
169 /* 
170   dssetup_DsRoleDcAsDc 
171 */
172 static WERROR dssetup_DsRoleDcAsDc(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
173                              struct dssetup_DsRoleDcAsDc *r)
174 {
175         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
176 }
177
178
179 /* 
180   dssetup_DsRoleDcAsReplica 
181 */
182 static WERROR dssetup_DsRoleDcAsReplica(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
183                                   struct dssetup_DsRoleDcAsReplica *r)
184 {
185         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
186 }
187
188
189 /* 
190   dssetup_DsRoleDemoteDc 
191 */
192 static WERROR dssetup_DsRoleDemoteDc(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
193                                struct dssetup_DsRoleDemoteDc *r)
194 {
195         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
196 }
197
198
199 /* 
200   dssetup_DsRoleGetDcOperationProgress 
201 */
202 static WERROR dssetup_DsRoleGetDcOperationProgress(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
203                                              struct dssetup_DsRoleGetDcOperationProgress *r)
204 {
205         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
206 }
207
208
209 /* 
210   dssetup_DsRoleGetDcOperationResults 
211 */
212 static WERROR dssetup_DsRoleGetDcOperationResults(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
213                                             struct dssetup_DsRoleGetDcOperationResults *r)
214 {
215         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
216 }
217
218
219 /* 
220   dssetup_DsRoleCancel 
221 */
222 static WERROR dssetup_DsRoleCancel(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
223                              struct dssetup_DsRoleCancel *r)
224 {
225         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
226 }
227
228
229 /* 
230   dssetup_DsRoleServerSaveStateForUpgrade 
231 */
232 static WERROR dssetup_DsRoleServerSaveStateForUpgrade(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
233                                                 struct dssetup_DsRoleServerSaveStateForUpgrade *r)
234 {
235         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
236 }
237
238
239 /* 
240   dssetup_DsRoleUpgradeDownlevelServer 
241 */
242 static WERROR dssetup_DsRoleUpgradeDownlevelServer(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
243                                              struct dssetup_DsRoleUpgradeDownlevelServer *r)
244 {
245         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
246 }
247
248
249 /* 
250   dssetup_DsRoleAbortDownlevelServerUpgrade 
251 */
252 static WERROR dssetup_DsRoleAbortDownlevelServerUpgrade(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
253                                                   struct dssetup_DsRoleAbortDownlevelServerUpgrade *r)
254 {
255         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
256 }
257
258
259 /* include the generated boilerplate */
260 #include "librpc/gen_ndr/ndr_dssetup_s.c"