r19761: This may need work, but here is an initial implementation of
[Samba.git] / source / rpc_server / drsuapi / dcesrv_drsuapi.c
blobe101195d9cd748a4d8e43afbc880cee439efd0ba
1 /*
2 Unix SMB/CIFS implementation.
4 endpoint server for the drsuapi pipe
6 Copyright (C) Stefan Metzmacher 2004
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.
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.
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.
23 #include "includes.h"
24 #include "librpc/gen_ndr/ndr_drsuapi.h"
25 #include "rpc_server/dcerpc_server.h"
26 #include "rpc_server/common/common.h"
27 #include "rpc_server/drsuapi/dcesrv_drsuapi.h"
28 #include "dsdb/samdb/samdb.h"
30 /*
31 drsuapi_DsBind
33 static WERROR drsuapi_DsBind(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
34 struct drsuapi_DsBind *r)
36 struct drsuapi_bind_state *b_state;
37 struct dcesrv_handle *handle;
38 struct drsuapi_DsBindInfoCtr *bind_info;
39 struct GUID site_guid;
41 r->out.bind_info = NULL;
42 ZERO_STRUCTP(r->out.bind_handle);
44 b_state = talloc(dce_call->conn, struct drsuapi_bind_state);
45 W_ERROR_HAVE_NO_MEMORY(b_state);
47 b_state->sam_ctx = samdb_connect(b_state, dce_call->conn->auth_state.session_info);
48 if (!b_state->sam_ctx) {
49 talloc_free(b_state);
50 return WERR_FOOBAR;
53 handle = dcesrv_handle_new(dce_call->context, DRSUAPI_BIND_HANDLE);
54 if (!handle) {
55 talloc_free(b_state);
56 return WERR_NOMEM;
59 handle->data = talloc_steal(handle, b_state);
61 bind_info = talloc(mem_ctx, struct drsuapi_DsBindInfoCtr);
62 W_ERROR_HAVE_NO_MEMORY(bind_info);
64 ZERO_STRUCT(site_guid);
66 bind_info->length = 28;
67 bind_info->info.info28.supported_extensions = 0;
68 bind_info->info.info28.site_guid = site_guid;
69 bind_info->info.info28.u1 = 0;
70 bind_info->info.info28.repl_epoch = 0;
72 r->out.bind_info = bind_info;
73 *r->out.bind_handle = handle->wire_handle;
75 return WERR_OK;
79 /*
80 drsuapi_DsUnbind
82 static WERROR drsuapi_DsUnbind(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
83 struct drsuapi_DsUnbind *r)
85 struct dcesrv_handle *h;
87 *r->out.bind_handle = *r->in.bind_handle;
89 DCESRV_PULL_HANDLE_WERR(h, r->in.bind_handle, DRSUAPI_BIND_HANDLE);
91 talloc_free(h);
93 ZERO_STRUCTP(r->out.bind_handle);
95 return WERR_OK;
99 /*
100 drsuapi_DsReplicaSync
102 static WERROR drsuapi_DsReplicaSync(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
103 struct drsuapi_DsReplicaSync *r)
105 /* TODO: implement this call correct!
106 * for now we just say yes,
107 * because we have no output parameter
109 return WERR_OK;
114 drsuapi_DsGetNCChanges
116 static WERROR drsuapi_DsGetNCChanges(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
117 struct drsuapi_DsGetNCChanges *r)
119 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
124 drsuapi_DsReplicaUpdateRefs
126 static WERROR drsuapi_DsReplicaUpdateRefs(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
127 struct drsuapi_DsReplicaUpdateRefs *r)
129 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
134 DRSUAPI_REPLICA_ADD
136 static WERROR DRSUAPI_REPLICA_ADD(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
137 struct DRSUAPI_REPLICA_ADD *r)
139 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
144 DRSUAPI_REPLICA_DEL
146 static WERROR DRSUAPI_REPLICA_DEL(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
147 struct DRSUAPI_REPLICA_DEL *r)
149 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
154 DRSUAPI_REPLICA_MODIFY
156 static WERROR DRSUAPI_REPLICA_MODIFY(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
157 struct DRSUAPI_REPLICA_MODIFY *r)
159 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
164 DRSUAPI_VERIFY_NAMES
166 static WERROR DRSUAPI_VERIFY_NAMES(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
167 struct DRSUAPI_VERIFY_NAMES *r)
169 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
174 drsuapi_DsGetMemberships
176 static WERROR drsuapi_DsGetMemberships(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
177 struct drsuapi_DsGetMemberships *r)
179 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
184 DRSUAPI_INTER_DOMAIN_MOVE
186 static WERROR DRSUAPI_INTER_DOMAIN_MOVE(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
187 struct DRSUAPI_INTER_DOMAIN_MOVE *r)
189 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
194 DRSUAPI_GET_NT4_CHANGELOG
196 static WERROR DRSUAPI_GET_NT4_CHANGELOG(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
197 struct DRSUAPI_GET_NT4_CHANGELOG *r)
199 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
204 drsuapi_DsCrackNames
206 WERROR drsuapi_DsCrackNames(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
207 struct drsuapi_DsCrackNames *r)
209 WERROR status;
210 struct drsuapi_bind_state *b_state;
211 struct dcesrv_handle *h;
213 r->out.level = r->in.level;
214 ZERO_STRUCT(r->out.ctr);
216 DCESRV_PULL_HANDLE_WERR(h, r->in.bind_handle, DRSUAPI_BIND_HANDLE);
217 b_state = h->data;
219 switch (r->in.level) {
220 case 1: {
221 struct drsuapi_DsNameCtr1 *ctr1;
222 struct drsuapi_DsNameInfo1 *names;
223 int count;
224 int i;
226 ctr1 = talloc(mem_ctx, struct drsuapi_DsNameCtr1);
227 W_ERROR_HAVE_NO_MEMORY(ctr1);
229 count = r->in.req.req1.count;
230 names = talloc_array(mem_ctx, struct drsuapi_DsNameInfo1, count);
231 W_ERROR_HAVE_NO_MEMORY(names);
233 for (i=0; i < count; i++) {
234 status = DsCrackNameOneName(b_state->sam_ctx, mem_ctx,
235 r->in.req.req1.format_flags,
236 r->in.req.req1.format_offered,
237 r->in.req.req1.format_desired,
238 r->in.req.req1.names[i].str,
239 &names[i]);
240 if (!W_ERROR_IS_OK(status)) {
241 return status;
245 ctr1->count = count;
246 ctr1->array = names;
247 r->out.ctr.ctr1 = ctr1;
249 return WERR_OK;
253 return WERR_UNKNOWN_LEVEL;
257 drsuapi_DsWriteAccountSpn
259 static WERROR drsuapi_DsWriteAccountSpn(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
260 struct drsuapi_DsWriteAccountSpn *r)
262 struct drsuapi_bind_state *b_state;
263 struct dcesrv_handle *h;
265 r->out.level = r->in.level;
267 DCESRV_PULL_HANDLE_WERR(h, r->in.bind_handle, DRSUAPI_BIND_HANDLE);
268 b_state = h->data;
270 switch (r->in.level) {
271 case 1: {
272 struct drsuapi_DsWriteAccountSpnRequest1 *req;
273 struct ldb_message *msg;
274 int count, i, ret;
275 req = &r->in.req.req1;
276 count = req->count;
278 msg = ldb_msg_new(mem_ctx);
279 if (msg == NULL) {
280 return WERR_NOMEM;
283 msg->dn = ldb_dn_explode(msg, req->object_dn);
284 if (msg->dn == NULL) {
285 r->out.res.res1.status = WERR_OK;
286 return WERR_OK;
289 /* construct mods */
290 for (i = 0; i < count; i++) {
291 samdb_msg_add_string(b_state->sam_ctx,
292 msg, msg, "servicePrincipalName",
293 req->spn_names[i].str);
295 for (i=0;i<msg->num_elements;i++) {
296 switch (req->operation) {
297 case DRSUAPI_DS_SPN_OPERATION_ADD:
298 msg->elements[i].flags = LDB_FLAG_MOD_ADD;
299 break;
300 case DRSUAPI_DS_SPN_OPERATION_REPLACE:
301 msg->elements[i].flags = LDB_FLAG_MOD_REPLACE;
302 break;
303 case DRSUAPI_DS_SPN_OPERATION_DELETE:
304 msg->elements[i].flags = LDB_FLAG_MOD_DELETE;
305 break;
309 /* Apply to database */
311 ret = samdb_modify(b_state->sam_ctx, mem_ctx, msg);
312 if (ret != 0) {
313 DEBUG(0,("Failed to modify SPNs on %s: %s\n",
314 ldb_dn_linearize(mem_ctx, msg->dn),
315 ldb_errstring(b_state->sam_ctx)));
316 r->out.res.res1.status = WERR_ACCESS_DENIED;
317 } else {
318 r->out.res.res1.status = WERR_OK;
321 return WERR_OK;
325 return WERR_UNKNOWN_LEVEL;
330 DRSUAPI_REMOVE_DS_SERVER
332 static WERROR DRSUAPI_REMOVE_DS_SERVER(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
333 struct DRSUAPI_REMOVE_DS_SERVER *r)
335 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
340 DRSUAPI_REMOVE_DS_DOMAIN
342 static WERROR DRSUAPI_REMOVE_DS_DOMAIN(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
343 struct DRSUAPI_REMOVE_DS_DOMAIN *r)
345 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
350 drsuapi_DsGetDomainControllerInfo
352 static WERROR drsuapi_DsGetDomainControllerInfo(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
353 struct drsuapi_DsGetDomainControllerInfo *r)
355 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
360 drsuapi_DsAddEntry
362 static WERROR drsuapi_DsAddEntry(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
363 struct drsuapi_DsAddEntry *r)
365 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
370 DRSUAPI_EXECUTE_KCC
372 static WERROR DRSUAPI_EXECUTE_KCC(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
373 struct DRSUAPI_EXECUTE_KCC *r)
375 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
380 drsuapi_DsReplicaGetInfo
382 static WERROR drsuapi_DsReplicaGetInfo(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
383 struct drsuapi_DsReplicaGetInfo *r)
385 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
390 DRSUAPI_ADD_SID_HISTORY
392 static WERROR DRSUAPI_ADD_SID_HISTORY(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
393 struct DRSUAPI_ADD_SID_HISTORY *r)
395 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
399 drsuapi_DsGetMemberships2
401 static WERROR drsuapi_DsGetMemberships2(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
402 struct drsuapi_DsGetMemberships2 *r)
404 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
408 DRSUAPI_REPLICA_VERIFY_OBJECTS
410 static WERROR DRSUAPI_REPLICA_VERIFY_OBJECTS(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
411 struct DRSUAPI_REPLICA_VERIFY_OBJECTS *r)
413 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
418 DRSUAPI_GET_OBJECT_EXISTENCE
420 static WERROR DRSUAPI_GET_OBJECT_EXISTENCE(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
421 struct DRSUAPI_GET_OBJECT_EXISTENCE *r)
423 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
428 DRSUAPI_QUERY_SITES_BY_COST
430 static WERROR DRSUAPI_QUERY_SITES_BY_COST(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
431 struct DRSUAPI_QUERY_SITES_BY_COST *r)
433 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
437 /* include the generated boilerplate */
438 #include "librpc/gen_ndr/ndr_drsuapi_s.c"