s4:drs split addentry and getncchanges into separate files
[kai/samba-autobuild/.git] / source4 / rpc_server / drsuapi / addentry.c
1 /* 
2    Unix SMB/CIFS implementation.
3
4    implement the DsAddEntry call
5
6    Copyright (C) Stefan Metzmacher 2009
7    Copyright (C) Andrew Tridgell   2009
8    
9    This program is free software; you can redistribute it and/or modify
10    it under the terms of the GNU General Public License as published by
11    the Free Software Foundation; either version 3 of the License, or
12    (at your option) any later version.
13    
14    This program is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17    GNU General Public License for more details.
18    
19    You should have received a copy of the GNU General Public License
20    along with this program.  If not, see <http://www.gnu.org/licenses/>.
21 */
22
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 "dsdb/samdb/samdb.h"
28 #include "lib/ldb/include/ldb_errors.h"
29 #include "param/param.h"
30 #include "librpc/gen_ndr/ndr_drsblobs.h"
31 #include "auth/auth.h"
32 #include "rpc_server/drsuapi/dcesrv_drsuapi.h"
33
34 /* 
35   drsuapi_DsAddEntry
36 */
37 WERROR dcesrv_drsuapi_DsAddEntry(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
38                                  struct drsuapi_DsAddEntry *r)
39 {
40         WERROR status;
41         struct drsuapi_bind_state *b_state;
42         struct dcesrv_handle *h;
43         uint32_t num = 0;
44         struct drsuapi_DsReplicaObjectIdentifier2 *ids = NULL;
45
46         if (DEBUGLVL(4)) {
47                 NDR_PRINT_FUNCTION_DEBUG(drsuapi_DsAddEntry, NDR_IN, r);
48         }
49
50         /* TODO: check which out level the client supports */
51
52         ZERO_STRUCTP(r->out.ctr);
53         r->out.level_out = 3;
54         r->out.ctr->ctr3.level = 1;
55         r->out.ctr->ctr3.error = talloc_zero(mem_ctx, union drsuapi_DsAddEntryError);
56
57         DCESRV_PULL_HANDLE_WERR(h, r->in.bind_handle, DRSUAPI_BIND_HANDLE);
58         b_state = h->data;
59
60         switch (r->in.level) {
61         case 2:
62                 status = dsdb_origin_objects_commit(b_state->sam_ctx,
63                                                     mem_ctx,
64                                                     &r->in.req->req2.first_object,
65                                                     &num,
66                                                     &ids);
67                 if (!W_ERROR_IS_OK(status)) {
68                         r->out.ctr->ctr3.error->info1.status = status;
69                         W_ERROR_NOT_OK_RETURN(status);
70                 }
71
72                 r->out.ctr->ctr3.count = num;
73                 r->out.ctr->ctr3.objects = ids;
74
75                 return WERR_OK;
76         default:
77                 break;
78         }
79
80         return WERR_FOOBAR;
81 }