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