r4650: - make more use of bitmap and enum's
[ira/wip.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_samr.h"
26 #include "librpc/gen_ndr/ndr_dssetup.h"
27 #include "rpc_server/common/common.h"
28
29
30 /* 
31   dssetup_DsRoleGetPrimaryDomainInformation 
32 */
33 static WERROR dssetup_DsRoleGetPrimaryDomainInformation(struct dcesrv_call_state *dce_call, 
34                                                         TALLOC_CTX *mem_ctx,
35                                                         struct dssetup_DsRoleGetPrimaryDomainInformation *r)
36 {
37         union dssetup_DsRoleInfo *info;
38
39         info = talloc_p(mem_ctx, union dssetup_DsRoleInfo);
40         W_ERROR_HAVE_NO_MEMORY(info);
41
42         switch (r->in.level) {
43         case DS_ROLE_BASIC_INFORMATION:
44         {
45                 void *sam_ctx;
46                 const char * const attrs[] = { "dnsDomain", "nTMixedDomain", "objectGUID", "name", NULL };
47                 int ret;
48                 struct ldb_message **res;
49                 enum dssetup_DsRole role = DS_ROLE_STANDALONE_SERVER;
50                 uint32 flags = 0;
51                 const char *domain = NULL;
52                 const char *dns_domain = NULL;
53                 const char *forest = NULL;
54                 struct GUID domain_guid;
55
56                 ZERO_STRUCT(domain_guid);
57
58                 switch (lp_server_role()) {
59                 case ROLE_STANDALONE:
60                         role            = DS_ROLE_STANDALONE_SERVER;
61                         break;
62                 case ROLE_DOMAIN_MEMBER:
63                         role            = DS_ROLE_MEMBER_SERVER;
64                         break;
65                 case ROLE_DOMAIN_BDC:
66                         role            = DS_ROLE_BACKUP_DC;
67                         break;
68                 case ROLE_DOMAIN_PDC:
69                         role            = DS_ROLE_PRIMARY_DC;
70                         break;
71                 }
72
73                 switch (lp_server_role()) {
74                 case ROLE_STANDALONE:
75                         domain          = talloc_strdup(mem_ctx, lp_workgroup());
76                         W_ERROR_HAVE_NO_MEMORY(domain);
77                         break;
78                 case ROLE_DOMAIN_MEMBER:
79                         domain          = talloc_strdup(mem_ctx, lp_workgroup());
80                         W_ERROR_HAVE_NO_MEMORY(domain);
81                         /* TODO: what is with dns_domain and forest and guid? */
82                         break;
83                 case ROLE_DOMAIN_BDC:
84                 case ROLE_DOMAIN_PDC:
85                         sam_ctx = samdb_connect(mem_ctx);
86                         if (!sam_ctx) {
87                                 return WERR_SERVER_UNAVAILABLE;
88                         }
89
90                         ret = samdb_search(sam_ctx, mem_ctx, NULL, &res, attrs,
91                                            "(&(objectClass=domainDNS)(!(objectClass=builtinDomain)))");
92                         if (ret != 1) {
93                                 return WERR_SERVER_UNAVAILABLE;
94                         }
95
96                         flags           = DS_ROLE_PRIMARY_DS_RUNNING;
97
98                         if (samdb_result_uint(res[0], "nTMixedDomain", 0) == 1) {
99                                 flags           |= DS_ROLE_PRIMARY_DS_MIXED_MODE;
100                         }
101
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
106                         flags           |= DS_ROLE_PRIMARY_DOMAIN_GUID_PRESENT;
107                         domain_guid     = samdb_result_guid(res[0], "objectGUID");
108                         break;
109                 }
110
111                 info->basic.role        = role; 
112                 info->basic.flags       = flags;
113                 info->basic.domain      = domain;
114                 info->basic.dns_domain  = dns_domain;
115                 info->basic.forest      = forest;
116                 info->basic.domain_guid = domain_guid;
117
118                 r->out.info = info;
119                 return WERR_OK;
120         }
121         case DS_ROLE_UPGRADE_STATUS:
122         {
123                 info->upgrade.upgrading     = DS_ROLE_NOT_UPGRADING;
124                 info->upgrade.previous_role = DS_ROLE_PREVIOUS_UNKNOWN;
125
126                 r->out.info = info;
127                 return WERR_OK;
128         }
129         case DS_ROLE_OP_STATUS:
130         {
131                 info->opstatus.status = DS_ROLE_OP_IDLE;
132
133                 r->out.info = info;
134                 return WERR_OK;
135         }
136         default:
137                 return WERR_INVALID_PARAM;
138         }
139
140         return WERR_INVALID_PARAM;
141 }
142
143
144 /*****************************************
145 NOTE! The remaining calls below were
146 removed in w2k3, so the DCESRV_FAULT()
147 replies are the correct implementation. Do
148 not try and fill these in with anything else
149 ******************************************/
150
151 /* 
152   dssetup_DsRoleDnsNameToFlatName 
153 */
154 static WERROR dssetup_DsRoleDnsNameToFlatName(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
155                                         struct dssetup_DsRoleDnsNameToFlatName *r)
156 {
157         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
158 }
159
160
161 /* 
162   dssetup_DsRoleDcAsDc 
163 */
164 static WERROR dssetup_DsRoleDcAsDc(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
165                              struct dssetup_DsRoleDcAsDc *r)
166 {
167         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
168 }
169
170
171 /* 
172   dssetup_DsRoleDcAsReplica 
173 */
174 static WERROR dssetup_DsRoleDcAsReplica(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
175                                   struct dssetup_DsRoleDcAsReplica *r)
176 {
177         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
178 }
179
180
181 /* 
182   dssetup_DsRoleDemoteDc 
183 */
184 static WERROR dssetup_DsRoleDemoteDc(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
185                                struct dssetup_DsRoleDemoteDc *r)
186 {
187         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
188 }
189
190
191 /* 
192   dssetup_DsRoleGetDcOperationProgress 
193 */
194 static WERROR dssetup_DsRoleGetDcOperationProgress(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
195                                              struct dssetup_DsRoleGetDcOperationProgress *r)
196 {
197         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
198 }
199
200
201 /* 
202   dssetup_DsRoleGetDcOperationResults 
203 */
204 static WERROR dssetup_DsRoleGetDcOperationResults(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
205                                             struct dssetup_DsRoleGetDcOperationResults *r)
206 {
207         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
208 }
209
210
211 /* 
212   dssetup_DsRoleCancel 
213 */
214 static WERROR dssetup_DsRoleCancel(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
215                              struct dssetup_DsRoleCancel *r)
216 {
217         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
218 }
219
220
221 /* 
222   dssetup_DsRoleServerSaveStateForUpgrade 
223 */
224 static WERROR dssetup_DsRoleServerSaveStateForUpgrade(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
225                                                 struct dssetup_DsRoleServerSaveStateForUpgrade *r)
226 {
227         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
228 }
229
230
231 /* 
232   dssetup_DsRoleUpgradeDownlevelServer 
233 */
234 static WERROR dssetup_DsRoleUpgradeDownlevelServer(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
235                                              struct dssetup_DsRoleUpgradeDownlevelServer *r)
236 {
237         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
238 }
239
240
241 /* 
242   dssetup_DsRoleAbortDownlevelServerUpgrade 
243 */
244 static WERROR dssetup_DsRoleAbortDownlevelServerUpgrade(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
245                                                   struct dssetup_DsRoleAbortDownlevelServerUpgrade *r)
246 {
247         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
248 }
249
250
251 /* include the generated boilerplate */
252 #include "librpc/gen_ndr/ndr_dssetup_s.c"