r12595: There was no comment on the mailing list, so kill the 'ldapsrv:samdb'
[bbaumbach/samba-autobuild/.git] / source4 / ldap_server / ldap_simple_ldb.c
1 /* 
2    Unix SMB/CIFS implementation.
3    LDAP server SIMPLE LDB implementation
4    Copyright (C) Stefan Metzmacher 2004
5    Copyright (C) Simo Sorce 2004
6    
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11    
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16    
17    You should have received a copy of the GNU General Public License
18    along with this program; if not, write to the Free Software
19    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22 #include "includes.h"
23 #include "ldap_server/ldap_server.h"
24 #include "lib/ldb/include/ldb.h"
25 #include "lib/ldb/include/ldb_errors.h"
26 #include "auth/auth.h"
27 #include "db_wrap.h"
28 #include "dsdb/samdb/samdb.h"
29
30 #define VALID_DN_SYNTAX(dn,i) do {\
31         if (!(dn)) {\
32                 return NT_STATUS_NO_MEMORY;\
33         } else if ((dn)->comp_num < (i)) {\
34                 result = LDAP_INVALID_DN_SYNTAX;\
35                 errstr = "Invalid DN (" #i " components needed for '" #dn "')";\
36                 goto reply;\
37         }\
38 } while(0)
39
40
41 /*
42   map an error code from ldb to ldap
43 */
44 static int sldb_map_error(struct ldapsrv_partition *partition, int ldb_ret,
45                           const char **errstr)
46 {
47         struct ldb_context *samdb = talloc_get_type(partition->private, 
48                                                     struct ldb_context);
49         *errstr = ldb_errstring(samdb);
50
51         /* its 1:1 for now */
52         return ldb_ret;
53 }
54
55 /*
56   connect to the sam database
57 */
58 NTSTATUS sldb_Init(struct ldapsrv_partition *partition, struct ldapsrv_connection *conn) 
59 {
60         TALLOC_CTX *mem_ctx = talloc_new(partition);
61         struct ldb_context *ldb;
62         ldb = samdb_connect(mem_ctx, conn->session_info);
63         if (ldb == NULL) {
64                 talloc_free(mem_ctx);
65                 return NT_STATUS_INTERNAL_DB_CORRUPTION;
66         }
67         talloc_steal(partition, ldb);
68         partition->private = ldb;
69         talloc_free(mem_ctx);
70         return NT_STATUS_OK;
71 }
72
73 /*
74   Re-connect to the ldb after a bind (this does not handle the bind
75   itself, but just notes the change in credentials)
76 */
77 NTSTATUS sldb_Bind(struct ldapsrv_partition *partition, struct ldapsrv_connection *conn) 
78 {
79         struct ldb_context *samdb = partition->private;
80         NTSTATUS status;
81         status = sldb_Init(partition, conn);
82         if (NT_STATUS_IS_OK(status)) {
83                 /* don't leak the old LDB */
84                 talloc_free(samdb);
85         }
86         return status;
87 }
88
89 static NTSTATUS sldb_Search(struct ldapsrv_partition *partition, struct ldapsrv_call *call,
90                             struct ldap_SearchRequest *r)
91 {
92         void *local_ctx;
93         struct ldb_dn *basedn;
94         struct ldap_Result *done;
95         struct ldap_SearchResEntry *ent;
96         struct ldapsrv_reply *ent_r, *done_r;
97         int result = LDAP_SUCCESS;
98         struct ldb_context *samdb;
99         struct ldb_result *res = NULL;
100         int i, j, y, ret;
101         int success_limit = 1;
102         enum ldb_scope scope = LDB_SCOPE_DEFAULT;
103         const char **attrs = NULL;
104         const char *errstr = NULL;
105         struct ldb_request lreq;
106
107         local_ctx = talloc_named(call, 0, "sldb_Search local memory context");
108         NT_STATUS_HAVE_NO_MEMORY(local_ctx);
109
110         samdb = talloc_get_type(partition->private, struct ldb_context);
111
112         basedn = ldb_dn_explode(local_ctx, r->basedn);
113         VALID_DN_SYNTAX(basedn, 0);
114
115         DEBUG(10, ("sldb_Search: basedn: [%s]\n", r->basedn));
116         DEBUG(10, ("sldb_Search: filter: [%s]\n", ldb_filter_from_tree(call, r->tree)));
117
118         switch (r->scope) {
119                 case LDAP_SEARCH_SCOPE_BASE:
120                         DEBUG(10,("sldb_Search: scope: [BASE]\n"));
121                         scope = LDB_SCOPE_BASE;
122                         success_limit = 0;
123                         break;
124                 case LDAP_SEARCH_SCOPE_SINGLE:
125                         DEBUG(10,("sldb_Search: scope: [ONE]\n"));
126                         scope = LDB_SCOPE_ONELEVEL;
127                         success_limit = 0;
128                         break;
129                 case LDAP_SEARCH_SCOPE_SUB:
130                         DEBUG(10,("sldb_Search: scope: [SUB]\n"));
131                         scope = LDB_SCOPE_SUBTREE;
132                         success_limit = 0;
133                         break;
134         }
135
136         if (r->num_attributes >= 1) {
137                 attrs = talloc_array(samdb, const char *, r->num_attributes+1);
138                 NT_STATUS_HAVE_NO_MEMORY(attrs);
139
140                 for (i=0; i < r->num_attributes; i++) {
141                         DEBUG(10,("sldb_Search: attrs: [%s]\n",r->attributes[i]));
142                         attrs[i] = r->attributes[i];
143                 }
144                 attrs[i] = NULL;
145         }
146
147         DEBUG(5,("ldb_request dn=%s filter=%s\n", 
148                  r->basedn, ldb_filter_from_tree(call, r->tree)));
149
150         ZERO_STRUCT(lreq);
151         lreq.operation = LDB_REQ_SEARCH;
152         lreq.op.search.base = basedn;
153         lreq.op.search.scope = scope;
154         lreq.op.search.tree = r->tree;
155         lreq.op.search.attrs = attrs;
156
157         ret = ldb_request(samdb, &lreq);
158
159         res = talloc_steal(samdb, lreq.op.search.res);
160
161         if (ret == LDB_SUCCESS) {
162                 for (i = 0; i < res->count; i++) {
163                         ent_r = ldapsrv_init_reply(call, LDAP_TAG_SearchResultEntry);
164                         NT_STATUS_HAVE_NO_MEMORY(ent_r);
165
166                         ent = &ent_r->msg->r.SearchResultEntry;
167                         ent->dn = ldb_dn_linearize(ent_r, res->msgs[i]->dn);
168                         ent->num_attributes = 0;
169                         ent->attributes = NULL;
170                         if (res->msgs[i]->num_elements == 0) {
171                                 goto queue_reply;
172                         }
173                         ent->num_attributes = res->msgs[i]->num_elements;
174                         ent->attributes = talloc_array(ent_r, struct ldb_message_element, ent->num_attributes);
175                         NT_STATUS_HAVE_NO_MEMORY(ent->attributes);
176                         for (j=0; j < ent->num_attributes; j++) {
177                                 ent->attributes[j].name = talloc_steal(ent->attributes, res->msgs[i]->elements[j].name);
178                                 ent->attributes[j].num_values = 0;
179                                 ent->attributes[j].values = NULL;
180                                 if (r->attributesonly && (res->msgs[i]->elements[j].num_values == 0)) {
181                                         continue;
182                                 }
183                                 ent->attributes[j].num_values = res->msgs[i]->elements[j].num_values;
184                                 ent->attributes[j].values = talloc_array(ent->attributes,
185                                                                 DATA_BLOB, ent->attributes[j].num_values);
186                                 NT_STATUS_HAVE_NO_MEMORY(ent->attributes[j].values);
187                                 for (y=0; y < ent->attributes[j].num_values; y++) {
188                                         ent->attributes[j].values[y].length = res->msgs[i]->elements[j].values[y].length;
189                                         ent->attributes[j].values[y].data = talloc_steal(ent->attributes[j].values,
190                                                                                 res->msgs[i]->elements[j].values[y].data);
191                                 }
192                         }
193 queue_reply:
194                         ldapsrv_queue_reply(call, ent_r);
195                 }
196         }
197
198 reply:
199         done_r = ldapsrv_init_reply(call, LDAP_TAG_SearchResultDone);
200         NT_STATUS_HAVE_NO_MEMORY(done_r);
201
202         if (ret == LDB_SUCCESS) {
203                 if (res->count >= success_limit) {
204                         DEBUG(10,("sldb_Search: results: [%d]\n", res->count));
205                         result = LDAP_SUCCESS;
206                         errstr = NULL;
207                 } else if (res->count == 0) {
208                         DEBUG(10,("sldb_Search: no results\n"));
209                         result = LDAP_NO_SUCH_OBJECT;
210                         errstr = ldb_errstring(samdb);
211                 }
212         } else {
213                 DEBUG(10,("sldb_Search: error\n"));
214                 result = ret;
215                 errstr = ldb_errstring(samdb);
216         }
217
218         done = &done_r->msg->r.SearchResultDone;
219         done->dn = NULL;
220         done->resultcode = result;
221         done->errormessage = (errstr?talloc_strdup(done_r, errstr):NULL);
222         done->referral = NULL;
223
224         talloc_free(local_ctx);
225
226         ldapsrv_queue_reply(call, done_r);
227         return NT_STATUS_OK;
228 }
229
230 static NTSTATUS sldb_Add(struct ldapsrv_partition *partition, struct ldapsrv_call *call,
231                          struct ldap_AddRequest *r)
232 {
233         void *local_ctx;
234         struct ldb_dn *dn;
235         struct ldap_Result *add_result;
236         struct ldapsrv_reply *add_reply;
237         int ldb_ret;
238         struct ldb_context *samdb;
239         struct ldb_message *msg = NULL;
240         int result = LDAP_SUCCESS;
241         const char *errstr = NULL;
242         int i,j;
243
244         local_ctx = talloc_named(call, 0, "sldb_Add local memory context");
245         NT_STATUS_HAVE_NO_MEMORY(local_ctx);
246
247         samdb = talloc_get_type(partition->private, struct ldb_context);
248
249         dn = ldb_dn_explode(local_ctx, r->dn);
250         VALID_DN_SYNTAX(dn,1);
251
252         DEBUG(10, ("sldb_add: dn: [%s]\n", r->dn));
253
254         msg = talloc(local_ctx, struct ldb_message);
255         NT_STATUS_HAVE_NO_MEMORY(msg);
256
257         msg->dn = dn;
258         msg->private_data = NULL;
259         msg->num_elements = 0;
260         msg->elements = NULL;
261
262         if (r->num_attributes > 0) {
263                 msg->num_elements = r->num_attributes;
264                 msg->elements = talloc_array(msg, struct ldb_message_element, msg->num_elements);
265                 NT_STATUS_HAVE_NO_MEMORY(msg->elements);
266
267                 for (i=0; i < msg->num_elements; i++) {
268                         msg->elements[i].name = discard_const_p(char, r->attributes[i].name);
269                         msg->elements[i].flags = 0;
270                         msg->elements[i].num_values = 0;
271                         msg->elements[i].values = NULL;
272                         
273                         if (r->attributes[i].num_values > 0) {
274                                 msg->elements[i].num_values = r->attributes[i].num_values;
275                                 msg->elements[i].values = talloc_array(msg, struct ldb_val, msg->elements[i].num_values);
276                                 NT_STATUS_HAVE_NO_MEMORY(msg->elements[i].values);
277
278                                 for (j=0; j < msg->elements[i].num_values; j++) {
279                                         if (!(r->attributes[i].values[j].length > 0)) {
280                                                 result = LDAP_OTHER;
281                                                 errstr = "Empty attribute values are not allowed";
282                                                 goto reply;
283                                         }
284                                         msg->elements[i].values[j].length = r->attributes[i].values[j].length;
285                                         msg->elements[i].values[j].data = r->attributes[i].values[j].data;                      
286                                 }
287                         } else {
288                                 result = LDAP_OTHER;
289                                 errstr = "No attribute values are not allowed";
290                                 goto reply;
291                         }
292                 }
293         } else {
294                 result = LDAP_OTHER;
295                 errstr = "No attributes are not allowed";
296                 goto reply;
297         }
298
299 reply:
300         add_reply = ldapsrv_init_reply(call, LDAP_TAG_AddResponse);
301         NT_STATUS_HAVE_NO_MEMORY(add_reply);
302
303         if (result == LDAP_SUCCESS) {
304                 ldb_ret = ldb_add(samdb, msg);
305                 result = sldb_map_error(partition, ldb_ret, &errstr);
306         }
307
308         add_result = &add_reply->msg->r.AddResponse;
309         add_result->dn = NULL;
310         add_result->resultcode = result;
311         add_result->errormessage = (errstr?talloc_strdup(add_reply,errstr):NULL);
312         add_result->referral = NULL;
313
314         talloc_free(local_ctx);
315
316         ldapsrv_queue_reply(call, add_reply);
317         return NT_STATUS_OK;
318 }
319
320 static NTSTATUS sldb_Del(struct ldapsrv_partition *partition, struct ldapsrv_call *call,
321                                      struct ldap_DelRequest *r)
322 {
323         void *local_ctx;
324         struct ldb_dn *dn;
325         struct ldap_Result *del_result;
326         struct ldapsrv_reply *del_reply;
327         int ldb_ret;
328         struct ldb_context *samdb;
329         const char *errstr = NULL;
330         int result = LDAP_SUCCESS;
331
332         local_ctx = talloc_named(call, 0, "sldb_Del local memory context");
333         NT_STATUS_HAVE_NO_MEMORY(local_ctx);
334
335         samdb = talloc_get_type(partition->private, struct ldb_context);
336
337         dn = ldb_dn_explode(local_ctx, r->dn);
338         VALID_DN_SYNTAX(dn,1);
339
340         DEBUG(10, ("sldb_Del: dn: [%s]\n", r->dn));
341
342 reply:
343         del_reply = ldapsrv_init_reply(call, LDAP_TAG_DelResponse);
344         NT_STATUS_HAVE_NO_MEMORY(del_reply);
345
346         if (result == LDAP_SUCCESS) {
347                 ldb_ret = ldb_delete(samdb, dn);
348                 result = sldb_map_error(partition, ldb_ret, &errstr);
349         }
350
351         del_result = &del_reply->msg->r.DelResponse;
352         del_result->dn = NULL;
353         del_result->resultcode = result;
354         del_result->errormessage = (errstr?talloc_strdup(del_reply,errstr):NULL);
355         del_result->referral = NULL;
356
357         talloc_free(local_ctx);
358
359         ldapsrv_queue_reply(call, del_reply);
360         return NT_STATUS_OK;
361 }
362
363 static NTSTATUS sldb_Modify(struct ldapsrv_partition *partition, struct ldapsrv_call *call,
364                                      struct ldap_ModifyRequest *r)
365 {
366         void *local_ctx;
367         struct ldb_dn *dn;
368         struct ldap_Result *modify_result;
369         struct ldapsrv_reply *modify_reply;
370         int ldb_ret;
371         struct ldb_context *samdb;
372         struct ldb_message *msg = NULL;
373         int result = LDAP_SUCCESS;
374         const char *errstr = NULL;
375         int i,j;
376
377         local_ctx = talloc_named(call, 0, "sldb_Modify local memory context");
378         NT_STATUS_HAVE_NO_MEMORY(local_ctx);
379
380         samdb = talloc_get_type(partition->private, struct ldb_context);
381
382         dn = ldb_dn_explode(local_ctx, r->dn);
383         VALID_DN_SYNTAX(dn, 1);
384
385         DEBUG(10, ("sldb_modify: dn: [%s]\n", r->dn));
386
387         msg = talloc(local_ctx, struct ldb_message);
388         NT_STATUS_HAVE_NO_MEMORY(msg);
389
390         msg->dn = dn;
391         msg->private_data = NULL;
392         msg->num_elements = 0;
393         msg->elements = NULL;
394
395         if (r->num_mods > 0) {
396                 msg->num_elements = r->num_mods;
397                 msg->elements = talloc_array(msg, struct ldb_message_element, r->num_mods);
398                 NT_STATUS_HAVE_NO_MEMORY(msg->elements);
399
400                 for (i=0; i < msg->num_elements; i++) {
401                         msg->elements[i].name = discard_const_p(char, r->mods[i].attrib.name);
402                         msg->elements[i].num_values = 0;
403                         msg->elements[i].values = NULL;
404
405                         switch (r->mods[i].type) {
406                         default:
407                                 result = LDAP_PROTOCOL_ERROR;
408                                 errstr = "Invalid LDAP_MODIFY_* type";
409                                 goto reply;
410                         case LDAP_MODIFY_ADD:
411                                 msg->elements[i].flags = LDB_FLAG_MOD_ADD;
412                                 break;
413                         case LDAP_MODIFY_DELETE:
414                                 msg->elements[i].flags = LDB_FLAG_MOD_DELETE;
415                                 break;
416                         case LDAP_MODIFY_REPLACE:
417                                 msg->elements[i].flags = LDB_FLAG_MOD_REPLACE;
418                                 break;
419                         }
420
421                         msg->elements[i].num_values = r->mods[i].attrib.num_values;
422                         if (msg->elements[i].num_values > 0) {
423                                 msg->elements[i].values = talloc_array(msg, struct ldb_val, msg->elements[i].num_values);
424                                 NT_STATUS_HAVE_NO_MEMORY(msg->elements[i].values);
425
426                                 for (j=0; j < msg->elements[i].num_values; j++) {
427                                         if (!(r->mods[i].attrib.values[j].length > 0)) {
428                                                 result = LDAP_OTHER;
429                                                 errstr = "Empty attribute values are not allowed";
430                                                 goto reply;
431                                         }
432                                         msg->elements[i].values[j].length = r->mods[i].attrib.values[j].length;
433                                         msg->elements[i].values[j].data = r->mods[i].attrib.values[j].data;                     
434                                 }
435                         }
436                 }
437         } else {
438                 result = LDAP_OTHER;
439                 errstr = "No mods are not allowed";
440                 goto reply;
441         }
442
443 reply:
444         modify_reply = ldapsrv_init_reply(call, LDAP_TAG_ModifyResponse);
445         NT_STATUS_HAVE_NO_MEMORY(modify_reply);
446
447         if (result == LDAP_SUCCESS) {
448                 ldb_ret = ldb_modify(samdb, msg);
449                 result = sldb_map_error(partition, ldb_ret, &errstr);
450         }
451
452         modify_result = &modify_reply->msg->r.AddResponse;
453         modify_result->dn = NULL;
454         modify_result->resultcode = result;
455         modify_result->errormessage = (errstr?talloc_strdup(modify_reply,errstr):NULL);
456         modify_result->referral = NULL;
457
458         talloc_free(local_ctx);
459
460         ldapsrv_queue_reply(call, modify_reply);
461         return NT_STATUS_OK;
462 }
463
464 static NTSTATUS sldb_Compare(struct ldapsrv_partition *partition, struct ldapsrv_call *call,
465                                      struct ldap_CompareRequest *r)
466 {
467         void *local_ctx;
468         struct ldb_dn *dn;
469         struct ldap_Result *compare;
470         struct ldapsrv_reply *compare_r;
471         int result = LDAP_SUCCESS;
472         struct ldb_context *samdb;
473         struct ldb_result *res = NULL;
474         const char *attrs[1];
475         const char *errstr = NULL;
476         const char *filter = NULL;
477         int ret;
478
479         local_ctx = talloc_named(call, 0, "sldb_Compare local_memory_context");
480         NT_STATUS_HAVE_NO_MEMORY(local_ctx);
481
482         samdb = talloc_get_type(partition->private, struct ldb_context);
483
484         dn = ldb_dn_explode(local_ctx, r->dn);
485         VALID_DN_SYNTAX(dn, 1);
486
487         DEBUG(10, ("sldb_Compare: dn: [%s]\n", r->dn));
488         filter = talloc_asprintf(local_ctx, "(%s=%*s)", r->attribute, 
489                                  (int)r->value.length, r->value.data);
490         NT_STATUS_HAVE_NO_MEMORY(filter);
491
492         DEBUGADD(10, ("sldb_Compare: attribute: [%s]\n", filter));
493
494         attrs[0] = NULL;
495
496 reply:
497         compare_r = ldapsrv_init_reply(call, LDAP_TAG_CompareResponse);
498         NT_STATUS_HAVE_NO_MEMORY(compare_r);
499
500         if (result == LDAP_SUCCESS) {
501                 ret = ldb_search(samdb, dn, LDB_SCOPE_BASE, filter, attrs, &res);
502                 talloc_steal(samdb, res);
503                 if (ret != LDB_SUCCESS) {
504                         result = LDAP_OTHER;
505                         errstr = ldb_errstring(samdb);
506                         DEBUG(10,("sldb_Compare: error: %s\n", errstr));
507                 } else if (res->count == 0) {
508                         DEBUG(10,("sldb_Compare: doesn't matched\n"));
509                         result = LDAP_COMPARE_FALSE;
510                         errstr = NULL;
511                 } else if (res->count == 1) {
512                         DEBUG(10,("sldb_Compare: matched\n"));
513                         result = LDAP_COMPARE_TRUE;
514                         errstr = NULL;
515                 } else if (res->count > 1) {
516                         result = LDAP_OTHER;
517                         errstr = "too many objects match";
518                         DEBUG(10,("sldb_Compare: %d results: %s\n", res->count, errstr));
519                 }
520         }
521
522         compare = &compare_r->msg->r.CompareResponse;
523         compare->dn = NULL;
524         compare->resultcode = result;
525         compare->errormessage = (errstr?talloc_strdup(compare_r,errstr):NULL);
526         compare->referral = NULL;
527
528         talloc_free(local_ctx);
529
530         ldapsrv_queue_reply(call, compare_r);
531         return NT_STATUS_OK;
532 }
533
534 static NTSTATUS sldb_ModifyDN(struct ldapsrv_partition *partition, struct ldapsrv_call *call, struct ldap_ModifyDNRequest *r)
535 {
536         void *local_ctx;
537         struct ldb_dn *olddn, *newdn, *newrdn;
538         struct ldb_dn *parentdn = NULL;
539         struct ldap_Result *modifydn;
540         struct ldapsrv_reply *modifydn_r;
541         int ldb_ret;
542         struct ldb_context *samdb;
543         const char *errstr = NULL;
544         int result = LDAP_SUCCESS;
545
546         local_ctx = talloc_named(call, 0, "sldb_ModifyDN local memory context");
547         NT_STATUS_HAVE_NO_MEMORY(local_ctx);
548
549         samdb = talloc_get_type(partition->private, struct ldb_context);
550
551         olddn = ldb_dn_explode(local_ctx, r->dn);
552         VALID_DN_SYNTAX(olddn, 2);
553
554         newrdn = ldb_dn_explode(local_ctx, r->newrdn);
555         VALID_DN_SYNTAX(newrdn, 1);
556
557         DEBUG(10, ("sldb_ModifyDN: olddn: [%s]\n", r->dn));
558         DEBUG(10, ("sldb_ModifyDN: newrdn: [%s]\n", r->newrdn));
559
560         /* we can't handle the rename if we should not remove the old dn */
561         if (!r->deleteolddn) {
562                 result = LDAP_UNWILLING_TO_PERFORM;
563                 errstr = "Old RDN must be deleted";
564                 goto reply;
565         }
566
567         if (newrdn->comp_num > 1) {
568                 result = LDAP_NAMING_VIOLATION;
569                 errstr = "Error new RDN invalid";
570                 goto reply;
571         }
572
573         if (r->newsuperior) {
574                 parentdn = ldb_dn_explode(local_ctx, r->newsuperior);
575                 VALID_DN_SYNTAX(parentdn, 0);
576                 DEBUG(10, ("sldb_ModifyDN: newsuperior: [%s]\n", r->newsuperior));
577                 
578                 if (parentdn->comp_num < 1) {
579                         result = LDAP_AFFECTS_MULTIPLE_DSAS;
580                         errstr = "Error new Superior DN invalid";
581                         goto reply;
582                 }
583         }
584
585         if (!parentdn) {
586                 parentdn = ldb_dn_get_parent(local_ctx, olddn);
587                 NT_STATUS_HAVE_NO_MEMORY(parentdn);
588         }
589
590         newdn = ldb_dn_make_child(local_ctx, ldb_dn_get_rdn(local_ctx, newrdn), parentdn);
591         NT_STATUS_HAVE_NO_MEMORY(newdn);
592
593 reply:
594         modifydn_r = ldapsrv_init_reply(call, LDAP_TAG_ModifyDNResponse);
595         NT_STATUS_HAVE_NO_MEMORY(modifydn_r);
596
597         if (result == LDAP_SUCCESS) {
598                 ldb_ret = ldb_rename(samdb, olddn, newdn);
599                 result = sldb_map_error(partition, ldb_ret, &errstr);
600         }
601
602         modifydn = &modifydn_r->msg->r.ModifyDNResponse;
603         modifydn->dn = NULL;
604         modifydn->resultcode = result;
605         modifydn->errormessage = (errstr?talloc_strdup(modifydn_r,errstr):NULL);
606         modifydn->referral = NULL;
607
608         talloc_free(local_ctx);
609
610         ldapsrv_queue_reply(call, modifydn_r);
611         return NT_STATUS_OK;
612 }
613
614 static const struct ldapsrv_partition_ops sldb_ops = {
615         .Init           = sldb_Init,
616         .Bind           = sldb_Bind,
617         .Search         = sldb_Search,
618         .Add            = sldb_Add,
619         .Del            = sldb_Del,
620         .Modify         = sldb_Modify,
621         .Compare        = sldb_Compare,
622         .ModifyDN       = sldb_ModifyDN
623 };
624
625 const struct ldapsrv_partition_ops *ldapsrv_get_sldb_partition_ops(void)
626 {
627         return &sldb_ops;
628 }