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