Cleanup references to module objects returned from PyImport_ImportModule
[gd/samba-autobuild/.git] / source4 / dsdb / pydsdb.c
1 /* 
2    Unix SMB/CIFS implementation.
3    Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007-2010
4    Copyright (C) Matthias Dieter Wallnöfer          2009
5    
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 3 of the License, or
9    (at your option) any later version.
10    
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15    
16    You should have received a copy of the GNU General Public License
17    along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include <Python.h>
21 #include "python/py3compat.h"
22 #include "includes.h"
23 #include <ldb.h>
24 #include <pyldb.h>
25 #include "dsdb/samdb/samdb.h"
26 #include "libcli/security/security.h"
27 #include "librpc/ndr/libndr.h"
28 #include "system/kerberos.h"
29 #include "auth/kerberos/kerberos.h"
30 #include "librpc/rpc/pyrpc_util.h"
31 #include "lib/policy/policy.h"
32 #include "param/pyparam.h"
33 #include "lib/util/dlinklist.h"
34 #include "dsdb/kcc/garbage_collect_tombstones.h"
35 #include "dsdb/kcc/scavenge_dns_records.h"
36
37
38 /* FIXME: These should be in a header file somewhere */
39 #define PyErr_LDB_OR_RAISE(py_ldb, ldb) \
40         if (!py_check_dcerpc_type(py_ldb, "ldb", "Ldb")) { \
41                 PyErr_SetString(PyExc_TypeError, "Ldb connection object required"); \
42                 return NULL; \
43         } \
44         ldb = pyldb_Ldb_AsLdbContext(py_ldb);
45
46 #define PyErr_LDB_DN_OR_RAISE(py_ldb_dn, dn) \
47         if (!py_check_dcerpc_type(py_ldb_dn, "ldb", "Dn")) { \
48                 PyErr_SetString(PyExc_TypeError, "ldb Dn object required"); \
49                 return NULL; \
50         } \
51         dn = pyldb_Dn_AsDn(py_ldb_dn);
52
53 static PyObject *py_ldb_get_exception(void)
54 {
55         PyObject *mod = PyImport_ImportModule("ldb");
56         PyObject *result = NULL;
57         if (mod == NULL)
58                 return NULL;
59
60         result = PyObject_GetAttrString(mod, "LdbError");
61         Py_CLEAR(mod);
62         return result;
63 }
64
65 static void PyErr_SetLdbError(PyObject *error, int ret, struct ldb_context *ldb_ctx)
66 {
67         if (ret == LDB_ERR_PYTHON_EXCEPTION)
68                 return; /* Python exception should already be set, just keep that */
69
70         PyErr_SetObject(error, 
71                         Py_BuildValue(discard_const_p(char, "(i,s)"), ret,
72                         ldb_ctx == NULL?ldb_strerror(ret):ldb_errstring(ldb_ctx)));
73 }
74
75 static PyObject *py_samdb_server_site_name(PyObject *self, PyObject *args)
76 {
77         PyObject *py_ldb, *result;
78         struct ldb_context *ldb;
79         const char *site;
80         TALLOC_CTX *mem_ctx;
81
82         if (!PyArg_ParseTuple(args, "O", &py_ldb))
83                 return NULL;
84
85         PyErr_LDB_OR_RAISE(py_ldb, ldb);
86
87         mem_ctx = talloc_new(NULL);
88         if (mem_ctx == NULL) {
89                 PyErr_NoMemory();
90                 return NULL;
91         }
92
93         site = samdb_server_site_name(ldb, mem_ctx);
94         if (site == NULL) {
95                 PyErr_SetString(PyExc_RuntimeError, "Failed to find server site");
96                 talloc_free(mem_ctx);
97                 return NULL;
98         }
99
100         result = PyStr_FromString(site);
101         talloc_free(mem_ctx);
102         return result;
103 }
104
105 static PyObject *py_dsdb_convert_schema_to_openldap(PyObject *self,
106                                                     PyObject *args)
107 {
108         char *target_str, *mapping;
109         PyObject *py_ldb;
110         struct ldb_context *ldb;
111         PyObject *ret;
112         char *retstr;
113
114         if (!PyArg_ParseTuple(args, "Oss", &py_ldb, &target_str, &mapping))
115                 return NULL;
116
117         PyErr_LDB_OR_RAISE(py_ldb, ldb);
118
119         retstr = dsdb_convert_schema_to_openldap(ldb, target_str, mapping);
120         if (retstr == NULL) {
121                 PyErr_SetString(PyExc_RuntimeError,
122                                                 "dsdb_convert_schema_to_openldap failed");
123                 return NULL;
124         } 
125
126         ret = PyStr_FromString(retstr);
127         talloc_free(retstr);
128         return ret;
129 }
130
131 static PyObject *py_samdb_set_domain_sid(PyLdbObject *self, PyObject *args)
132
133         PyObject *py_ldb, *py_sid;
134         struct ldb_context *ldb;
135         struct dom_sid *sid;
136         bool ret;
137
138         if (!PyArg_ParseTuple(args, "OO", &py_ldb, &py_sid))
139                 return NULL;
140         
141         PyErr_LDB_OR_RAISE(py_ldb, ldb);
142
143         sid = dom_sid_parse_talloc(NULL, PyStr_AsString(py_sid));
144         if (sid == NULL) {
145                 PyErr_NoMemory();
146                 return NULL;
147         }
148
149         ret = samdb_set_domain_sid(ldb, sid);
150         talloc_free(sid);
151         if (!ret) {
152                 PyErr_SetString(PyExc_RuntimeError, "set_domain_sid failed");
153                 return NULL;
154         } 
155         Py_RETURN_NONE;
156 }
157
158 static PyObject *py_samdb_set_ntds_settings_dn(PyLdbObject *self, PyObject *args)
159
160         PyObject *py_ldb, *py_ntds_settings_dn;
161         struct ldb_context *ldb;
162         struct ldb_dn *ntds_settings_dn;
163         TALLOC_CTX *tmp_ctx;
164         bool ret;
165
166         if (!PyArg_ParseTuple(args, "OO", &py_ldb, &py_ntds_settings_dn))
167                 return NULL;
168
169         PyErr_LDB_OR_RAISE(py_ldb, ldb);
170
171         tmp_ctx = talloc_new(NULL);
172         if (tmp_ctx == NULL) {
173                 PyErr_NoMemory();
174                 return NULL;
175         }
176
177         if (!pyldb_Object_AsDn(tmp_ctx, py_ntds_settings_dn, ldb, &ntds_settings_dn)) {
178                 /* exception thrown by "pyldb_Object_AsDn" */
179                 talloc_free(tmp_ctx);
180                 return NULL;
181         }
182
183         ret = samdb_set_ntds_settings_dn(ldb, ntds_settings_dn);
184         talloc_free(tmp_ctx);
185         if (!ret) {
186                 PyErr_SetString(PyExc_RuntimeError, "set_ntds_settings_dn failed");
187                 return NULL;
188         } 
189         Py_RETURN_NONE;
190 }
191
192 static PyObject *py_samdb_get_domain_sid(PyLdbObject *self, PyObject *args)
193
194         PyObject *py_ldb;
195         struct ldb_context *ldb;
196         const struct dom_sid *sid;
197         struct dom_sid_buf buf;
198         PyObject *ret;
199
200         if (!PyArg_ParseTuple(args, "O", &py_ldb))
201                 return NULL;
202
203         PyErr_LDB_OR_RAISE(py_ldb, ldb);
204
205         sid = samdb_domain_sid(ldb);
206         if (!sid) {
207                 PyErr_SetString(PyExc_RuntimeError, "samdb_domain_sid failed");
208                 return NULL;
209         }
210
211         ret = PyStr_FromString(dom_sid_str_buf(sid, &buf));
212         return ret;
213 }
214
215 static PyObject *py_samdb_ntds_invocation_id(PyObject *self, PyObject *args)
216 {
217         PyObject *py_ldb, *result;
218         struct ldb_context *ldb;
219         const struct GUID *guid;
220         char *retstr;
221
222         if (!PyArg_ParseTuple(args, "O", &py_ldb)) {
223                 return NULL;
224         }
225
226         PyErr_LDB_OR_RAISE(py_ldb, ldb);
227
228         guid = samdb_ntds_invocation_id(ldb);
229         if (guid == NULL) {
230                 PyErr_SetString(PyExc_RuntimeError,
231                                                 "Failed to find NTDS invocation ID");
232                 return NULL;
233         }
234
235         retstr = GUID_string(NULL, guid);
236         if (retstr == NULL) {
237                 PyErr_NoMemory();
238                 return NULL;
239         }
240         result = PyStr_FromString(retstr);
241         talloc_free(retstr);
242         return result;
243 }
244
245 static PyObject *py_dsdb_get_oid_from_attid(PyObject *self, PyObject *args)
246 {
247         PyObject *py_ldb;
248         struct ldb_context *ldb;
249         uint32_t attid;
250         struct dsdb_schema *schema;
251         const char *oid;
252         PyObject *ret;
253         WERROR status;
254         TALLOC_CTX *mem_ctx;
255
256         if (!PyArg_ParseTuple(args, "OI", &py_ldb, &attid))
257                 return NULL;
258
259         PyErr_LDB_OR_RAISE(py_ldb, ldb);
260
261         mem_ctx = talloc_new(NULL);
262         if (!mem_ctx) {
263                 PyErr_NoMemory();
264                 return NULL;
265         }
266
267         schema = dsdb_get_schema(ldb, mem_ctx);
268         if (!schema) {
269                 PyErr_SetString(PyExc_RuntimeError, "Failed to find a schema from ldb \n");
270                 talloc_free(mem_ctx);
271                 return NULL;
272         }
273         
274         status = dsdb_schema_pfm_oid_from_attid(schema->prefixmap, attid,
275                                                 mem_ctx, &oid);
276         if (!W_ERROR_IS_OK(status)) {
277                 PyErr_SetWERROR(status);
278                 talloc_free(mem_ctx);
279                 return NULL;
280         }
281
282         ret = PyStr_FromString(oid);
283
284         talloc_free(mem_ctx);
285
286         return ret;
287 }
288
289
290 static PyObject *py_dsdb_get_attid_from_lDAPDisplayName(PyObject *self, PyObject *args)
291 {
292         PyObject *py_ldb, *is_schema_nc;
293         struct ldb_context *ldb;
294         struct dsdb_schema *schema;
295         const char *ldap_display_name;
296         bool schema_nc = false;
297         const struct dsdb_attribute *a;
298         uint32_t attid;
299
300         if (!PyArg_ParseTuple(args, "OsO", &py_ldb, &ldap_display_name, &is_schema_nc))
301                 return NULL;
302
303         PyErr_LDB_OR_RAISE(py_ldb, ldb);
304
305         if (is_schema_nc) {
306                 if (!PyBool_Check(is_schema_nc)) {
307                         PyErr_SetString(PyExc_TypeError, "Expected boolean is_schema_nc");
308                         return NULL;
309                 }
310                 if (is_schema_nc == Py_True) {
311                         schema_nc = true;
312                 }
313         }
314
315         schema = dsdb_get_schema(ldb, NULL);
316
317         if (!schema) {
318                 PyErr_SetString(PyExc_RuntimeError, "Failed to find a schema from ldb");
319                 return NULL;
320         }
321
322         a = dsdb_attribute_by_lDAPDisplayName(schema, ldap_display_name);
323         if (a == NULL) {
324                 PyErr_Format(PyExc_KeyError, "Failed to find attribute '%s'", ldap_display_name);
325                 return NULL;
326         }
327
328         attid = dsdb_attribute_get_attid(a, schema_nc);
329
330         return PyLong_FromUnsignedLong(attid);
331 }
332
333 /*
334   return the systemFlags as int from the attribute name
335  */
336 static PyObject *py_dsdb_get_systemFlags_from_lDAPDisplayName(PyObject *self, PyObject *args)
337 {
338         PyObject *py_ldb;
339         struct ldb_context *ldb;
340         struct dsdb_schema *schema;
341         const char *ldap_display_name;
342         const struct dsdb_attribute *attribute;
343
344         if (!PyArg_ParseTuple(args, "Os", &py_ldb, &ldap_display_name))
345                 return NULL;
346
347         PyErr_LDB_OR_RAISE(py_ldb, ldb);
348
349         schema = dsdb_get_schema(ldb, NULL);
350
351         if (!schema) {
352                 PyErr_SetString(PyExc_RuntimeError, "Failed to find a schema from ldb");
353                 return NULL;
354         }
355
356         attribute = dsdb_attribute_by_lDAPDisplayName(schema, ldap_display_name);
357         if (attribute == NULL) {
358                 PyErr_Format(PyExc_KeyError, "Failed to find attribute '%s'", ldap_display_name);
359                 return NULL;
360         }
361
362         return PyInt_FromLong(attribute->systemFlags);
363 }
364
365 /*
366   return the linkID from the attribute name
367  */
368 static PyObject *py_dsdb_get_linkId_from_lDAPDisplayName(PyObject *self, PyObject *args)
369 {
370         PyObject *py_ldb;
371         struct ldb_context *ldb;
372         struct dsdb_schema *schema;
373         const char *ldap_display_name;
374         const struct dsdb_attribute *attribute;
375
376         if (!PyArg_ParseTuple(args, "Os", &py_ldb, &ldap_display_name))
377                 return NULL;
378
379         PyErr_LDB_OR_RAISE(py_ldb, ldb);
380
381         schema = dsdb_get_schema(ldb, NULL);
382
383         if (!schema) {
384                 PyErr_SetString(PyExc_RuntimeError, "Failed to find a schema from ldb");
385                 return NULL;
386         }
387
388         attribute = dsdb_attribute_by_lDAPDisplayName(schema, ldap_display_name);
389         if (attribute == NULL) {
390                 PyErr_Format(PyExc_KeyError, "Failed to find attribute '%s'", ldap_display_name);
391                 return NULL;
392         }
393
394         return PyInt_FromLong(attribute->linkID);
395 }
396
397 /*
398   return the backlink attribute name (if any) for an attribute
399  */
400 static PyObject *py_dsdb_get_backlink_from_lDAPDisplayName(PyObject *self, PyObject *args)
401 {
402         PyObject *py_ldb;
403         struct ldb_context *ldb;
404         struct dsdb_schema *schema;
405         const char *ldap_display_name;
406         const struct dsdb_attribute *attribute, *target_attr;
407
408         if (!PyArg_ParseTuple(args, "Os", &py_ldb, &ldap_display_name))
409                 return NULL;
410
411         PyErr_LDB_OR_RAISE(py_ldb, ldb);
412
413         schema = dsdb_get_schema(ldb, NULL);
414
415         if (!schema) {
416                 PyErr_SetString(PyExc_RuntimeError, "Failed to find a schema from ldb");
417                 return NULL;
418         }
419
420         attribute = dsdb_attribute_by_lDAPDisplayName(schema, ldap_display_name);
421         if (attribute == NULL) {
422                 PyErr_Format(PyExc_KeyError, "Failed to find attribute '%s'", ldap_display_name);
423                 return NULL;
424         }
425
426         if (attribute->linkID == 0) {
427                 Py_RETURN_NONE;
428         }
429
430         target_attr = dsdb_attribute_by_linkID(schema, attribute->linkID ^ 1);
431         if (target_attr == NULL) {
432                 /* when we add pseudo-backlinks we'll need to handle
433                    them here */
434                 Py_RETURN_NONE;
435         }
436
437         return PyStr_FromString(target_attr->lDAPDisplayName);
438 }
439
440
441 static PyObject *py_dsdb_get_lDAPDisplayName_by_attid(PyObject *self, PyObject *args)
442 {
443         PyObject *py_ldb;
444         struct ldb_context *ldb;
445         struct dsdb_schema *schema;
446         const struct dsdb_attribute *a;
447         uint32_t attid;
448
449         if (!PyArg_ParseTuple(args, "OI", &py_ldb, &attid))
450                 return NULL;
451
452         PyErr_LDB_OR_RAISE(py_ldb, ldb);
453
454         schema = dsdb_get_schema(ldb, NULL);
455
456         if (!schema) {
457                 PyErr_SetString(PyExc_RuntimeError, "Failed to find a schema from ldb");
458                 return NULL;
459         }
460
461         a = dsdb_attribute_by_attributeID_id(schema, attid);
462         if (a == NULL) {
463                 PyErr_Format(PyExc_KeyError, "Failed to find attribute '0x%08x'", attid);
464                 return NULL;
465         }
466
467         return PyStr_FromString(a->lDAPDisplayName);
468 }
469
470
471 /*
472   return the attribute syntax oid as a string from the attribute name
473  */
474 static PyObject *py_dsdb_get_syntax_oid_from_lDAPDisplayName(PyObject *self, PyObject *args)
475 {
476         PyObject *py_ldb;
477         struct ldb_context *ldb;
478         struct dsdb_schema *schema;
479         const char *ldap_display_name;
480         const struct dsdb_attribute *attribute;
481
482         if (!PyArg_ParseTuple(args, "Os", &py_ldb, &ldap_display_name))
483                 return NULL;
484
485         PyErr_LDB_OR_RAISE(py_ldb, ldb);
486
487         schema = dsdb_get_schema(ldb, NULL);
488
489         if (!schema) {
490                 PyErr_SetString(PyExc_RuntimeError, "Failed to find a schema from ldb");
491                 return NULL;
492         }
493
494         attribute = dsdb_attribute_by_lDAPDisplayName(schema, ldap_display_name);
495         if (attribute == NULL) {
496                 PyErr_Format(PyExc_KeyError, "Failed to find attribute '%s'", ldap_display_name);
497                 return NULL;
498         }
499
500         return PyStr_FromString(attribute->syntax->ldap_oid);
501 }
502
503 /*
504   convert a python string to a DRSUAPI drsuapi_DsReplicaAttribute attribute
505  */
506 static PyObject *py_dsdb_DsReplicaAttribute(PyObject *self, PyObject *args)
507 {
508         PyObject *py_ldb, *el_list, *ret;
509         struct ldb_context *ldb;
510         char *ldap_display_name;
511         const struct dsdb_attribute *a;
512         struct dsdb_schema *schema;
513         struct dsdb_syntax_ctx syntax_ctx;
514         struct ldb_message_element *el;
515         struct drsuapi_DsReplicaAttribute *attr;
516         TALLOC_CTX *tmp_ctx;
517         WERROR werr;
518         Py_ssize_t i;
519
520         if (!PyArg_ParseTuple(args, "OsO", &py_ldb, &ldap_display_name, &el_list)) {
521                 return NULL;
522         }
523
524         PyErr_LDB_OR_RAISE(py_ldb, ldb);
525
526         schema = dsdb_get_schema(ldb, NULL);
527         if (!schema) {
528                 PyErr_SetString(PyExc_RuntimeError, "Failed to find a schema from ldb");
529                 return NULL;
530         }
531
532         a = dsdb_attribute_by_lDAPDisplayName(schema, ldap_display_name);
533         if (a == NULL) {
534                 PyErr_Format(PyExc_KeyError, "Failed to find attribute '%s'", ldap_display_name);
535                 return NULL;
536         }
537
538         dsdb_syntax_ctx_init(&syntax_ctx, ldb, schema);
539         syntax_ctx.is_schema_nc = false;
540
541         tmp_ctx = talloc_new(ldb);
542         if (tmp_ctx == NULL) {
543                 PyErr_NoMemory();
544                 return NULL;
545         }
546
547         /* If we were not given an LdbMessageElement */
548         if (!PyList_Check(el_list)) {
549                 if (!py_check_dcerpc_type(el_list, "ldb", "MessageElement")) {
550                         PyErr_SetString(py_ldb_get_exception(),
551                                         "list of strings or ldb MessageElement object required");
552                         return NULL;
553                 }
554                 /*
555                  * NOTE:
556                  * el may not be a valid talloc context, it
557                  * could be part of an array
558                  */
559                 el = pyldb_MessageElement_AsMessageElement(el_list);
560         } else {
561                 el = talloc_zero(tmp_ctx, struct ldb_message_element);
562                 if (el == NULL) {
563                         PyErr_NoMemory();
564                         talloc_free(tmp_ctx);
565                         return NULL;
566                 }
567
568                 el->name = ldap_display_name;
569                 el->num_values = PyList_Size(el_list);
570
571                 el->values = talloc_array(el, struct ldb_val, el->num_values);
572                 if (el->values == NULL) {
573                         PyErr_NoMemory();
574                         talloc_free(tmp_ctx);
575                         return NULL;
576                 }
577
578                 for (i = 0; i < el->num_values; i++) {
579                         PyObject *item = PyList_GetItem(el_list, i);
580                         if (!(PyBytes_Check(item))) {
581                                 PyErr_Format(PyExc_TypeError,
582                                              "ldif_element type should be "
583                                              PY_DESC_PY3_BYTES
584                                              );
585                                 talloc_free(tmp_ctx);
586                                 return NULL;
587                         }
588                         el->values[i].data =
589                                 (uint8_t *)PyBytes_AsString(item);
590                         el->values[i].length = PyBytes_Size(item);
591                 }
592         }
593
594         attr = talloc_zero(tmp_ctx, struct drsuapi_DsReplicaAttribute);
595         if (attr == NULL) {
596                 PyErr_NoMemory();
597                 talloc_free(tmp_ctx);
598                 return NULL;
599         }
600
601         werr = a->syntax->ldb_to_drsuapi(&syntax_ctx, a, el, attr, attr);
602         PyErr_WERROR_NOT_OK_RAISE(werr);
603
604         ret = py_return_ndr_struct("samba.dcerpc.drsuapi", "DsReplicaAttribute", attr, attr);
605
606         talloc_free(tmp_ctx);
607
608         return ret;
609 }
610
611
612 /*
613   normalise a ldb attribute list
614  */
615 static PyObject *py_dsdb_normalise_attributes(PyObject *self, PyObject *args)
616 {
617         PyObject *py_ldb, *el_list, *py_ret;
618         struct ldb_context *ldb;
619         char *ldap_display_name;
620         const struct dsdb_attribute *a;
621         struct dsdb_schema *schema;
622         struct dsdb_syntax_ctx syntax_ctx;
623         struct ldb_message_element *el, *new_el;
624         struct drsuapi_DsReplicaAttribute *attr;
625         PyLdbMessageElementObject *ret;
626         TALLOC_CTX *tmp_ctx;
627         WERROR werr;
628         Py_ssize_t i;
629         PyTypeObject *py_type = NULL;
630         PyObject *module = NULL;
631
632         if (!PyArg_ParseTuple(args, "OsO", &py_ldb, &ldap_display_name, &el_list)) {
633                 return NULL;
634         }
635
636         PyErr_LDB_OR_RAISE(py_ldb, ldb);
637
638         schema = dsdb_get_schema(ldb, NULL);
639         if (!schema) {
640                 PyErr_SetString(PyExc_RuntimeError, "Failed to find a schema from ldb");
641                 return NULL;
642         }
643
644         a = dsdb_attribute_by_lDAPDisplayName(schema, ldap_display_name);
645         if (a == NULL) {
646                 PyErr_Format(PyExc_KeyError, "Failed to find attribute '%s'", ldap_display_name);
647                 return NULL;
648         }
649
650         dsdb_syntax_ctx_init(&syntax_ctx, ldb, schema);
651         syntax_ctx.is_schema_nc = false;
652
653         tmp_ctx = talloc_new(ldb);
654         if (tmp_ctx == NULL) {
655                 PyErr_NoMemory();
656                 return NULL;
657         }
658
659         if (!PyList_Check(el_list)) {
660                 if (!py_check_dcerpc_type(el_list, "ldb", "MessageElement")) {
661                         PyErr_SetString(py_ldb_get_exception(),
662                                         "list of strings or ldb MessageElement object required");
663                         return NULL;
664                 }
665                 /*
666                  * NOTE:
667                  * el may not be a valid talloc context, it
668                  * could be part of an array
669                  */
670                 el = pyldb_MessageElement_AsMessageElement(el_list);
671         } else {
672                 el = talloc_zero(tmp_ctx, struct ldb_message_element);
673                 if (el == NULL) {
674                         PyErr_NoMemory();
675                         talloc_free(tmp_ctx);
676                         return NULL;
677                 }
678
679                 el->name = ldap_display_name;
680                 el->num_values = PyList_Size(el_list);
681
682                 el->values = talloc_array(el, struct ldb_val, el->num_values);
683                 if (el->values == NULL) {
684                         PyErr_NoMemory();
685                         talloc_free(tmp_ctx);
686                         return NULL;
687                 }
688
689                 for (i = 0; i < el->num_values; i++) {
690                         PyObject *item = PyList_GetItem(el_list, i);
691                         if (!PyBytes_Check(item)) {
692                                 PyErr_Format(PyExc_TypeError,
693                                              "ldif_element type should be "
694                                              PY_DESC_PY3_BYTES
695                                              );
696                                 talloc_free(tmp_ctx);
697                                 return NULL;
698                         }
699                         el->values[i].data = (uint8_t *)PyBytes_AsString(item);
700                         el->values[i].length = PyBytes_Size(item);
701                 }
702         }
703
704         new_el = talloc_zero(tmp_ctx, struct ldb_message_element);
705         if (new_el == NULL) {
706                 PyErr_NoMemory();
707                 talloc_free(tmp_ctx);
708                 return NULL;
709         }
710
711         /* Normalise "objectClass" attribute if needed */
712         if (ldb_attr_cmp(a->lDAPDisplayName, "objectClass") == 0) {
713                 int iret;
714                 iret = dsdb_sort_objectClass_attr(ldb, schema, el, new_el, new_el);
715                 if (iret != LDB_SUCCESS) {
716                         PyErr_SetString(PyExc_RuntimeError, ldb_errstring(ldb));
717                         talloc_free(tmp_ctx);
718                         return NULL;
719                 }
720         }
721
722         /* first run ldb_to_drsuapi, then convert back again. This has
723          * the effect of normalising the attributes
724          */
725
726         attr = talloc_zero(tmp_ctx, struct drsuapi_DsReplicaAttribute);
727         if (attr == NULL) {
728                 PyErr_NoMemory();
729                 talloc_free(tmp_ctx);
730                 return NULL;
731         }
732
733         werr = a->syntax->ldb_to_drsuapi(&syntax_ctx, a, el, attr, attr);
734         PyErr_WERROR_NOT_OK_RAISE(werr);
735
736         /* now convert back again */
737         werr = a->syntax->drsuapi_to_ldb(&syntax_ctx, a, attr, new_el, new_el);
738         PyErr_WERROR_NOT_OK_RAISE(werr);
739
740         module = PyImport_ImportModule("ldb");
741         if (module == NULL) {
742                 return NULL;
743         }
744
745         py_type = (PyTypeObject *)PyObject_GetAttrString(module, "MessageElement");
746         if (py_type == NULL) {
747                 Py_DECREF(module);
748                 return NULL;
749         }
750
751         Py_CLEAR(module);
752
753         py_ret = py_type->tp_alloc(py_type, 0);
754         Py_CLEAR(py_type);
755         if (py_ret == NULL) {
756                 PyErr_NoMemory();
757                 return NULL;
758         }
759         ret = (PyLdbMessageElementObject *)py_ret;
760
761         ret->mem_ctx = talloc_new(NULL);
762         if (talloc_reference(ret->mem_ctx, new_el) == NULL) {
763                 Py_CLEAR(py_ret);
764                 PyErr_NoMemory();
765                 return NULL;
766         }
767         ret->el = new_el;
768
769         talloc_free(tmp_ctx);
770
771         return py_ret;
772 }
773
774
775 static PyObject *py_dsdb_set_ntds_invocation_id(PyObject *self, PyObject *args)
776 {
777         PyObject *py_ldb, *py_guid;
778         bool ret;
779         struct GUID guid;
780         struct ldb_context *ldb;
781         if (!PyArg_ParseTuple(args, "OO", &py_ldb, &py_guid))
782                 return NULL;
783
784         PyErr_LDB_OR_RAISE(py_ldb, ldb);
785         GUID_from_string(PyStr_AsString(py_guid), &guid);
786
787         if (GUID_all_zero(&guid)) {
788                 PyErr_SetString(PyExc_RuntimeError, "set_ntds_invocation_id rejected due to all-zero invocation ID");
789                 return NULL;
790         }
791
792         ret = samdb_set_ntds_invocation_id(ldb, &guid);
793         if (!ret) {
794                 PyErr_SetString(PyExc_RuntimeError, "set_ntds_invocation_id failed");
795                 return NULL;
796         }
797         Py_RETURN_NONE;
798 }
799
800 static PyObject *py_samdb_ntds_objectGUID(PyObject *self, PyObject *args)
801 {
802         PyObject *py_ldb, *result;
803         struct ldb_context *ldb;
804         const struct GUID *guid;
805         char *retstr;
806
807         if (!PyArg_ParseTuple(args, "O", &py_ldb)) {
808                 return NULL;
809         }
810
811         PyErr_LDB_OR_RAISE(py_ldb, ldb);
812
813         guid = samdb_ntds_objectGUID(ldb);
814         if (guid == NULL) {
815                 PyErr_SetString(PyExc_RuntimeError, "Failed to find NTDS GUID");
816                 return NULL;
817         }
818
819         retstr = GUID_string(NULL, guid);
820         if (retstr == NULL) {
821                 PyErr_NoMemory();
822                 return NULL;
823         }
824         result = PyStr_FromString(retstr);
825         talloc_free(retstr);
826         return result;
827 }
828
829 static PyObject *py_dsdb_set_global_schema(PyObject *self, PyObject *args)
830 {
831         PyObject *py_ldb;
832         struct ldb_context *ldb;
833         int ret;
834         if (!PyArg_ParseTuple(args, "O", &py_ldb))
835                 return NULL;
836
837         PyErr_LDB_OR_RAISE(py_ldb, ldb);
838
839         ret = dsdb_set_global_schema(ldb);
840         PyErr_LDB_ERROR_IS_ERR_RAISE(py_ldb_get_exception(), ret, ldb);
841
842         Py_RETURN_NONE;
843 }
844
845 static PyObject *py_dsdb_load_partition_usn(PyObject *self, PyObject *args)
846 {
847         PyObject *py_dn, *py_ldb, *result;
848         struct ldb_dn *dn;
849         uint64_t highest_uSN, urgent_uSN;
850         struct ldb_context *ldb;
851         TALLOC_CTX *mem_ctx;
852         int ret;
853
854         if (!PyArg_ParseTuple(args, "OO", &py_ldb, &py_dn)) {
855                 return NULL;
856         }
857
858         PyErr_LDB_OR_RAISE(py_ldb, ldb);
859
860         mem_ctx = talloc_new(NULL);
861         if (mem_ctx == NULL) {
862                 PyErr_NoMemory();
863                 return NULL;
864         }
865
866         if (!pyldb_Object_AsDn(mem_ctx, py_dn, ldb, &dn)) {
867                 talloc_free(mem_ctx);
868                 return NULL;
869         }
870
871         ret = dsdb_load_partition_usn(ldb, dn, &highest_uSN, &urgent_uSN);
872         if (ret != LDB_SUCCESS) {
873            PyErr_Format(PyExc_RuntimeError,
874                         "Failed to load partition [%s] uSN - %s",
875                         ldb_dn_get_linearized(dn),
876                         ldb_errstring(ldb));
877            talloc_free(mem_ctx);
878            return NULL;
879         }
880
881         talloc_free(mem_ctx);
882
883         result = PyDict_New();
884
885         PyDict_SetItemString(result, "uSNHighest", PyInt_FromLong((uint64_t)highest_uSN));
886         PyDict_SetItemString(result, "uSNUrgent", PyInt_FromLong((uint64_t)urgent_uSN));
887
888
889         return result;
890 }
891
892 static PyObject *py_dsdb_set_am_rodc(PyObject *self, PyObject *args)
893 {
894         PyObject *py_ldb;
895         bool ret;
896         struct ldb_context *ldb;
897         int py_val;
898
899         if (!PyArg_ParseTuple(args, "Oi", &py_ldb, &py_val))
900                 return NULL;
901
902         PyErr_LDB_OR_RAISE(py_ldb, ldb);
903         ret = samdb_set_am_rodc(ldb, (bool)py_val);
904         if (!ret) {
905                 PyErr_SetString(PyExc_RuntimeError, "set_am_rodc failed");
906                 return NULL;
907         }
908         Py_RETURN_NONE;
909 }
910
911 static PyObject *py_dsdb_set_schema_from_ldif(PyObject *self, PyObject *args)
912 {
913         WERROR result;
914         char *pf, *df, *dn;
915         PyObject *py_ldb;
916         struct ldb_context *ldb;
917
918         if (!PyArg_ParseTuple(args, "Osss", &py_ldb, &pf, &df, &dn))
919                 return NULL;
920
921         PyErr_LDB_OR_RAISE(py_ldb, ldb);
922
923         result = dsdb_set_schema_from_ldif(ldb, pf, df, dn);
924         PyErr_WERROR_NOT_OK_RAISE(result);
925
926         Py_RETURN_NONE;
927 }
928
929 static PyObject *py_dsdb_set_schema_from_ldb(PyObject *self, PyObject *args)
930 {
931         PyObject *py_ldb;
932         struct ldb_context *ldb;
933         PyObject *py_from_ldb;
934         struct ldb_context *from_ldb;
935         struct dsdb_schema *schema;
936         int ret;
937         char write_indices_and_attributes = SCHEMA_WRITE;
938         if (!PyArg_ParseTuple(args, "OO|b",
939                               &py_ldb, &py_from_ldb, &write_indices_and_attributes))
940                 return NULL;
941
942         PyErr_LDB_OR_RAISE(py_ldb, ldb);
943
944         PyErr_LDB_OR_RAISE(py_from_ldb, from_ldb);
945
946         schema = dsdb_get_schema(from_ldb, NULL);
947         if (!schema) {
948                 PyErr_SetString(PyExc_RuntimeError, "Failed to set find a schema on 'from' ldb!\n");
949                 return NULL;
950         }
951
952         ret = dsdb_reference_schema(ldb, schema, write_indices_and_attributes);
953         PyErr_LDB_ERROR_IS_ERR_RAISE(py_ldb_get_exception(), ret, ldb);
954
955         Py_RETURN_NONE;
956 }
957
958 static PyObject *py_dsdb_write_prefixes_from_schema_to_ldb(PyObject *self, PyObject *args)
959 {
960         PyObject *py_ldb;
961         struct ldb_context *ldb;
962         WERROR result;
963         struct dsdb_schema *schema;
964
965         if (!PyArg_ParseTuple(args, "O", &py_ldb))
966                 return NULL;
967
968         PyErr_LDB_OR_RAISE(py_ldb, ldb);
969
970         schema = dsdb_get_schema(ldb, NULL);
971         if (!schema) {
972                 PyErr_SetString(PyExc_RuntimeError, "Failed to set find a schema on ldb!\n");
973                 return NULL;
974         }
975
976         result = dsdb_write_prefixes_from_schema_to_ldb(NULL, ldb, schema);
977         PyErr_WERROR_NOT_OK_RAISE(result);
978
979         Py_RETURN_NONE;
980 }
981
982
983 static PyObject *py_dsdb_get_partitions_dn(PyObject *self, PyObject *args)
984 {
985         struct ldb_context *ldb;
986         struct ldb_dn *dn;
987         PyObject *py_ldb, *ret;
988
989         if (!PyArg_ParseTuple(args, "O", &py_ldb))
990                 return NULL;
991
992         PyErr_LDB_OR_RAISE(py_ldb, ldb);
993
994         dn = samdb_partitions_dn(ldb, NULL);
995         if (dn == NULL) {
996                 PyErr_NoMemory();
997                 return NULL;
998         }
999         ret = pyldb_Dn_FromDn(dn);
1000         talloc_free(dn);
1001         return ret;
1002 }
1003
1004
1005 static PyObject *py_dsdb_get_nc_root(PyObject *self, PyObject *args)
1006 {
1007         struct ldb_context *ldb;
1008         struct ldb_dn *dn, *nc_root;
1009         PyObject *py_ldb, *py_ldb_dn, *py_nc_root;
1010         int ret;
1011
1012         if (!PyArg_ParseTuple(args, "OO", &py_ldb, &py_ldb_dn))
1013                 return NULL;
1014
1015         PyErr_LDB_OR_RAISE(py_ldb, ldb);
1016         PyErr_LDB_DN_OR_RAISE(py_ldb_dn, dn);
1017
1018         ret = dsdb_find_nc_root(ldb, ldb, dn, &nc_root);
1019         PyErr_LDB_ERROR_IS_ERR_RAISE(py_ldb_get_exception(), ret, ldb);
1020
1021         py_nc_root = pyldb_Dn_FromDn(nc_root);
1022         talloc_unlink(ldb, nc_root);
1023         return py_nc_root;
1024 }
1025
1026 static PyObject *py_dsdb_get_wellknown_dn(PyObject *self, PyObject *args)
1027 {
1028         struct ldb_context *ldb;
1029         struct ldb_dn *nc_dn, *wk_dn;
1030         char *wkguid;
1031         PyObject *py_ldb, *py_nc_dn, *py_wk_dn;
1032         int ret;
1033
1034         if (!PyArg_ParseTuple(args, "OOs", &py_ldb, &py_nc_dn, &wkguid))
1035                 return NULL;
1036
1037         PyErr_LDB_OR_RAISE(py_ldb, ldb);
1038         PyErr_LDB_DN_OR_RAISE(py_nc_dn, nc_dn);
1039
1040         ret = dsdb_wellknown_dn(ldb, ldb, nc_dn, wkguid, &wk_dn);
1041         if (ret == LDB_ERR_NO_SUCH_OBJECT) {
1042                 PyErr_Format(PyExc_KeyError, "Failed to find well known DN for GUID %s", wkguid);
1043                 return NULL;
1044         }
1045
1046         PyErr_LDB_ERROR_IS_ERR_RAISE(py_ldb_get_exception(), ret, ldb);
1047
1048         py_wk_dn = pyldb_Dn_FromDn(wk_dn);
1049         talloc_unlink(ldb, wk_dn);
1050         return py_wk_dn;
1051 }
1052
1053
1054 /*
1055   call into samdb_rodc()
1056  */
1057 static PyObject *py_dsdb_am_rodc(PyObject *self, PyObject *args)
1058 {
1059         PyObject *py_ldb;
1060         struct ldb_context *ldb;
1061         int ret;
1062         bool am_rodc;
1063
1064         if (!PyArg_ParseTuple(args, "O", &py_ldb))
1065                 return NULL;
1066
1067         PyErr_LDB_OR_RAISE(py_ldb, ldb);
1068
1069         ret = samdb_rodc(ldb, &am_rodc);
1070         if (ret != LDB_SUCCESS) {
1071                 PyErr_SetString(PyExc_RuntimeError, ldb_errstring(ldb));
1072                 return NULL;
1073         }
1074
1075         return PyBool_FromLong(am_rodc);
1076 }
1077
1078 /*
1079   call into samdb_is_pdc()
1080  */
1081 static PyObject *py_dsdb_am_pdc(PyObject *self, PyObject *args)
1082 {
1083         PyObject *py_ldb;
1084         struct ldb_context *ldb;
1085         bool am_pdc;
1086
1087         if (!PyArg_ParseTuple(args, "O", &py_ldb))
1088                 return NULL;
1089
1090         PyErr_LDB_OR_RAISE(py_ldb, ldb);
1091
1092         am_pdc = samdb_is_pdc(ldb);
1093         return PyBool_FromLong(am_pdc);
1094 }
1095
1096 /*
1097   call DSDB_EXTENDED_CREATE_OWN_RID_SET to get a new RID set for this server
1098  */
1099 static PyObject *py_dsdb_create_own_rid_set(PyObject *self, PyObject *args)
1100 {
1101         PyObject *py_ldb;
1102         struct ldb_context *ldb;
1103         int ret;
1104         struct ldb_result *ext_res;
1105
1106         if (!PyArg_ParseTuple(args, "O", &py_ldb))
1107                 return NULL;
1108
1109         PyErr_LDB_OR_RAISE(py_ldb, ldb);
1110
1111         /*
1112          * Run DSDB_EXTENDED_CREATE_OWN_RID_SET to get a RID set
1113          */
1114
1115         ret = ldb_extended(ldb, DSDB_EXTENDED_CREATE_OWN_RID_SET, NULL, &ext_res);
1116
1117         PyErr_LDB_ERROR_IS_ERR_RAISE(py_ldb_get_exception(), ret, ldb);
1118
1119         TALLOC_FREE(ext_res);
1120
1121         Py_RETURN_NONE;
1122 }
1123
1124 /*
1125   call DSDB_EXTENDED_ALLOCATE_RID to get a new RID set for this server
1126  */
1127 static PyObject *py_dsdb_allocate_rid(PyObject *self, PyObject *args)
1128 {
1129         PyObject *py_ldb;
1130         struct ldb_context *ldb;
1131         int ret;
1132         uint32_t rid;
1133         struct ldb_result *ext_res = NULL;
1134         struct dsdb_extended_allocate_rid *rid_return = NULL;
1135         if (!PyArg_ParseTuple(args, "O", &py_ldb)) {
1136                 return NULL;
1137         }
1138
1139         PyErr_LDB_OR_RAISE(py_ldb, ldb);
1140
1141         rid_return = talloc_zero(ldb, struct dsdb_extended_allocate_rid);
1142         if (rid_return == NULL) {
1143                 return PyErr_NoMemory();
1144         }
1145
1146         /*
1147          * Run DSDB_EXTENDED_ALLOCATE_RID to get a new RID
1148          */
1149
1150         ret = ldb_extended(ldb, DSDB_EXTENDED_ALLOCATE_RID, rid_return, &ext_res);
1151         if (ret != LDB_SUCCESS) {
1152                 TALLOC_FREE(rid_return);
1153                 TALLOC_FREE(ext_res);
1154                 PyErr_LDB_ERROR_IS_ERR_RAISE(py_ldb_get_exception(), ret, ldb);
1155         }
1156
1157         rid = rid_return->rid;
1158         TALLOC_FREE(rid_return);
1159         TALLOC_FREE(ext_res);
1160
1161         return PyInt_FromLong(rid);
1162 }
1163
1164 static PyObject *py_dns_delete_tombstones(PyObject *self, PyObject *args)
1165 {
1166         PyObject *py_ldb;
1167         NTSTATUS status;
1168         struct ldb_context *ldb = NULL;
1169         TALLOC_CTX *mem_ctx = NULL;
1170         char *error_string = NULL;
1171
1172         if (!PyArg_ParseTuple(args, "O", &py_ldb)) {
1173                 return NULL;
1174         }
1175         PyErr_LDB_OR_RAISE(py_ldb, ldb);
1176
1177         mem_ctx = talloc_new(ldb);
1178         if (mem_ctx == NULL) {
1179                 return PyErr_NoMemory();
1180         }
1181
1182         status = dns_delete_tombstones(mem_ctx, ldb, &error_string);
1183
1184         if (!NT_STATUS_IS_OK(status)) {
1185                 if (error_string) {
1186                         PyErr_Format(PyExc_RuntimeError, "%s", error_string);
1187                 } else {
1188                         PyErr_SetNTSTATUS(status);
1189                 }
1190                 TALLOC_FREE(mem_ctx);
1191                 return NULL;
1192         }
1193
1194         TALLOC_FREE(mem_ctx);
1195         Py_RETURN_NONE;
1196 }
1197
1198 static PyObject *py_scavenge_dns_records(PyObject *self, PyObject *args)
1199 {
1200         PyObject *py_ldb;
1201         NTSTATUS status;
1202         struct ldb_context *ldb = NULL;
1203         TALLOC_CTX *mem_ctx = NULL;
1204         char *error_string = NULL;
1205
1206         if (!PyArg_ParseTuple(args, "O", &py_ldb)) {
1207                 return NULL;
1208         }
1209         PyErr_LDB_OR_RAISE(py_ldb, ldb);
1210
1211         mem_ctx = talloc_new(ldb);
1212         if (mem_ctx == NULL) {
1213                 return PyErr_NoMemory();
1214         }
1215
1216         status = dns_tombstone_records(mem_ctx, ldb, &error_string);
1217
1218         if (!NT_STATUS_IS_OK(status)) {
1219                 if (error_string) {
1220                         PyErr_Format(PyExc_RuntimeError, "%s", error_string);
1221                 } else {
1222                         PyErr_SetNTSTATUS(status);
1223                 }
1224                 TALLOC_FREE(mem_ctx);
1225                 return NULL;
1226         }
1227
1228         TALLOC_FREE(mem_ctx);
1229         Py_RETURN_NONE;
1230 }
1231
1232 static PyObject *py_dsdb_garbage_collect_tombstones(PyObject *self, PyObject *args)
1233 {
1234         PyObject *py_ldb, *py_list_dn;
1235         struct ldb_context *ldb = NULL;
1236         Py_ssize_t i;
1237         Py_ssize_t length;
1238         long long _current_time, _tombstone_lifetime = LLONG_MAX;
1239         uint32_t tombstone_lifetime32;
1240         struct dsdb_ldb_dn_list_node *part = NULL;
1241         time_t current_time, tombstone_lifetime;
1242         TALLOC_CTX *mem_ctx = NULL;
1243         NTSTATUS status;
1244         unsigned int num_objects_removed = 0;
1245         unsigned int num_links_removed = 0;
1246         char *error_string = NULL;
1247
1248         if (!PyArg_ParseTuple(args, "OOL|L", &py_ldb,
1249                               &py_list_dn, &_current_time, &_tombstone_lifetime)) {
1250                 return NULL;
1251         }
1252
1253
1254         PyErr_LDB_OR_RAISE(py_ldb, ldb);
1255
1256         mem_ctx = talloc_new(ldb);
1257         if (mem_ctx == NULL) {
1258                 return PyErr_NoMemory();
1259         }
1260
1261         current_time = _current_time;
1262
1263         if (_tombstone_lifetime == LLONG_MAX) {
1264                 int ret = dsdb_tombstone_lifetime(ldb, &tombstone_lifetime32);
1265                 if (ret != LDB_SUCCESS) {
1266                         PyErr_Format(PyExc_RuntimeError,
1267                                      "Failed to get tombstone lifetime: %s",
1268                                      ldb_errstring(ldb));
1269                         TALLOC_FREE(mem_ctx);
1270                         return NULL;
1271                 }
1272                 tombstone_lifetime = tombstone_lifetime32;
1273         } else {
1274                 tombstone_lifetime = _tombstone_lifetime;
1275         }
1276
1277         if (!PyList_Check(py_list_dn)) {
1278                 PyErr_SetString(PyExc_TypeError, "A list of DNs were expected");
1279                 TALLOC_FREE(mem_ctx);
1280                 return NULL;
1281         }
1282
1283         length = PyList_GET_SIZE(py_list_dn);
1284
1285         for (i = 0; i < length; i++) {
1286                 const char *part_str = PyStr_AsString(PyList_GetItem(py_list_dn, i));
1287                 struct ldb_dn *p;
1288                 struct dsdb_ldb_dn_list_node *node;
1289
1290                 if (part_str == NULL) {
1291                         TALLOC_FREE(mem_ctx);
1292                         return PyErr_NoMemory();
1293                 }
1294
1295                 p = ldb_dn_new(mem_ctx, ldb, part_str);
1296                 if (p == NULL) {
1297                         PyErr_Format(PyExc_RuntimeError, "Failed to parse DN %s", part_str);
1298                         TALLOC_FREE(mem_ctx);
1299                         return NULL;
1300                 }
1301                 node = talloc_zero(mem_ctx, struct dsdb_ldb_dn_list_node);
1302                 node->dn = p;
1303
1304                 DLIST_ADD_END(part, node);
1305         }
1306
1307         status = dsdb_garbage_collect_tombstones(mem_ctx, ldb,
1308                                                  part, current_time,
1309                                                  tombstone_lifetime,
1310                                                  &num_objects_removed,
1311                                                  &num_links_removed,
1312                                                  &error_string);
1313
1314         if (!NT_STATUS_IS_OK(status)) {
1315                 if (error_string) {
1316                         PyErr_Format(PyExc_RuntimeError, "%s", error_string);
1317                 } else {
1318                         PyErr_SetNTSTATUS(status);
1319                 }
1320                 TALLOC_FREE(mem_ctx);
1321                 return NULL;
1322         }
1323
1324         TALLOC_FREE(mem_ctx);
1325
1326         return Py_BuildValue("(II)", num_objects_removed,
1327                             num_links_removed);
1328 }
1329
1330 static PyObject *py_dsdb_load_udv_v2(PyObject *self, PyObject *args)
1331 {
1332         uint32_t count;
1333         int ret, i;
1334         bool ok;
1335         PyObject *py_ldb = NULL, *py_dn = NULL, *pylist = NULL;
1336         struct ldb_context *samdb = NULL;
1337         struct ldb_dn *dn = NULL;
1338         struct drsuapi_DsReplicaCursor2 *cursors = NULL;
1339         TALLOC_CTX *tmp_ctx = NULL;
1340
1341         if (!PyArg_ParseTuple(args, "OO", &py_ldb, &py_dn)) {
1342                 return NULL;
1343         }
1344
1345         PyErr_LDB_OR_RAISE(py_ldb, samdb);
1346
1347         tmp_ctx = talloc_new(samdb);
1348         if (tmp_ctx == NULL) {
1349                 return PyErr_NoMemory();
1350         }
1351
1352         ok = pyldb_Object_AsDn(tmp_ctx, py_dn, samdb, &dn);
1353         if (!ok) {
1354                 TALLOC_FREE(tmp_ctx);
1355                 return NULL;
1356         }
1357
1358         ret = dsdb_load_udv_v2(samdb, dn, tmp_ctx, &cursors, &count);
1359         if (ret != LDB_SUCCESS) {
1360                 TALLOC_FREE(tmp_ctx);
1361                 PyErr_SetString(PyExc_RuntimeError,
1362                                 "Failed to load udv from ldb");
1363                 return NULL;
1364         }
1365
1366         pylist = PyList_New(count);
1367         if (pylist == NULL) {
1368                 TALLOC_FREE(tmp_ctx);
1369                 return PyErr_NoMemory();
1370         }
1371
1372         for (i = 0; i < count; i++) {
1373                 PyObject *py_cursor;
1374                 struct drsuapi_DsReplicaCursor2 *cursor;
1375                 cursor = talloc(tmp_ctx, struct drsuapi_DsReplicaCursor2);
1376                 if (cursor == NULL) {
1377                         TALLOC_FREE(tmp_ctx);
1378                         return PyErr_NoMemory();
1379                 }
1380                 *cursor = cursors[i];
1381
1382                 py_cursor = py_return_ndr_struct("samba.dcerpc.drsuapi",
1383                                                  "DsReplicaCursor2",
1384                                                  cursor, cursor);
1385                 if (py_cursor == NULL) {
1386                         TALLOC_FREE(tmp_ctx);
1387                         return PyErr_NoMemory();
1388                 }
1389
1390                 PyList_SetItem(pylist, i, py_cursor);
1391         }
1392
1393         TALLOC_FREE(tmp_ctx);
1394         return pylist;
1395 }
1396
1397 static PyMethodDef py_dsdb_methods[] = {
1398         { "_samdb_server_site_name", (PyCFunction)py_samdb_server_site_name,
1399                 METH_VARARGS, "Get the server site name as a string"},
1400         { "_dsdb_convert_schema_to_openldap",
1401                 (PyCFunction)py_dsdb_convert_schema_to_openldap, METH_VARARGS, 
1402                 "dsdb_convert_schema_to_openldap(ldb, target_str, mapping) -> str\n"
1403                 "Create an OpenLDAP schema from a schema." },
1404         { "_samdb_set_domain_sid", (PyCFunction)py_samdb_set_domain_sid,
1405                 METH_VARARGS,
1406                 "samdb_set_domain_sid(samdb, sid)\n"
1407                 "Set SID of domain to use." },
1408         { "_samdb_get_domain_sid", (PyCFunction)py_samdb_get_domain_sid,
1409                 METH_VARARGS,
1410                 "samdb_get_domain_sid(samdb)\n"
1411                 "Get SID of domain in use." },
1412         { "_samdb_ntds_invocation_id", (PyCFunction)py_samdb_ntds_invocation_id,
1413                 METH_VARARGS, "get the NTDS invocation ID GUID as a string"},
1414         { "_samdb_set_ntds_settings_dn", (PyCFunction)py_samdb_set_ntds_settings_dn,
1415                 METH_VARARGS,
1416                 "samdb_set_ntds_settings_dn(samdb, ntds_settings_dn)\n"
1417                 "Set NTDS Settings DN for this LDB (allows it to be set before the DB fully exists)." },
1418         { "_dsdb_get_oid_from_attid", (PyCFunction)py_dsdb_get_oid_from_attid,
1419                 METH_VARARGS, NULL },
1420         { "_dsdb_get_attid_from_lDAPDisplayName", (PyCFunction)py_dsdb_get_attid_from_lDAPDisplayName,
1421                 METH_VARARGS, NULL },
1422         { "_dsdb_get_syntax_oid_from_lDAPDisplayName", (PyCFunction)py_dsdb_get_syntax_oid_from_lDAPDisplayName,
1423                 METH_VARARGS, NULL },
1424         { "_dsdb_get_systemFlags_from_lDAPDisplayName", (PyCFunction)py_dsdb_get_systemFlags_from_lDAPDisplayName,
1425                 METH_VARARGS, NULL },
1426         { "_dsdb_get_linkId_from_lDAPDisplayName", (PyCFunction)py_dsdb_get_linkId_from_lDAPDisplayName,
1427                 METH_VARARGS, NULL },
1428         { "_dsdb_get_lDAPDisplayName_by_attid", (PyCFunction)py_dsdb_get_lDAPDisplayName_by_attid,
1429                 METH_VARARGS, NULL },
1430         { "_dsdb_get_backlink_from_lDAPDisplayName", (PyCFunction)py_dsdb_get_backlink_from_lDAPDisplayName,
1431                 METH_VARARGS, NULL },
1432         { "_dsdb_set_ntds_invocation_id",
1433                 (PyCFunction)py_dsdb_set_ntds_invocation_id, METH_VARARGS,
1434                 NULL },
1435         { "_samdb_ntds_objectGUID", (PyCFunction)py_samdb_ntds_objectGUID,
1436                 METH_VARARGS, "get the NTDS objectGUID as a string"},
1437         { "_dsdb_set_global_schema", (PyCFunction)py_dsdb_set_global_schema,
1438                 METH_VARARGS, NULL },
1439         { "_dsdb_load_partition_usn", (PyCFunction)py_dsdb_load_partition_usn,
1440                 METH_VARARGS,
1441                 "get uSNHighest and uSNUrgent from the partition @REPLCHANGED"},
1442         { "_dsdb_set_am_rodc",
1443                 (PyCFunction)py_dsdb_set_am_rodc, METH_VARARGS,
1444                 NULL },
1445         { "_am_rodc",
1446                 (PyCFunction)py_dsdb_am_rodc, METH_VARARGS,
1447                 NULL },
1448         { "_am_pdc",
1449                 (PyCFunction)py_dsdb_am_pdc, METH_VARARGS,
1450                 NULL },
1451         { "_dsdb_set_schema_from_ldif", (PyCFunction)py_dsdb_set_schema_from_ldif, METH_VARARGS,
1452                 NULL },
1453         { "_dsdb_set_schema_from_ldb", (PyCFunction)py_dsdb_set_schema_from_ldb, METH_VARARGS,
1454                 NULL },
1455         { "_dsdb_write_prefixes_from_schema_to_ldb", (PyCFunction)py_dsdb_write_prefixes_from_schema_to_ldb, METH_VARARGS,
1456                 NULL },
1457         { "_dsdb_get_partitions_dn", (PyCFunction)py_dsdb_get_partitions_dn, METH_VARARGS, NULL },
1458         { "_dsdb_get_nc_root", (PyCFunction)py_dsdb_get_nc_root, METH_VARARGS, NULL },
1459         { "_dsdb_get_wellknown_dn", (PyCFunction)py_dsdb_get_wellknown_dn, METH_VARARGS, NULL },
1460         { "_dsdb_DsReplicaAttribute", (PyCFunction)py_dsdb_DsReplicaAttribute, METH_VARARGS, NULL },
1461         { "_dsdb_normalise_attributes", (PyCFunction)py_dsdb_normalise_attributes, METH_VARARGS, NULL },
1462         { "_dsdb_garbage_collect_tombstones", (PyCFunction)py_dsdb_garbage_collect_tombstones, METH_VARARGS,
1463                 "_dsdb_kcc_check_deleted(samdb, [dn], current_time, tombstone_lifetime)"
1464                 " -> (num_objects_expunged, num_links_expunged)" },
1465         { "_scavenge_dns_records", (PyCFunction)py_scavenge_dns_records,
1466                 METH_VARARGS, NULL},
1467         { "_dns_delete_tombstones", (PyCFunction)py_dns_delete_tombstones,
1468                 METH_VARARGS, NULL},
1469         { "_dsdb_create_own_rid_set", (PyCFunction)py_dsdb_create_own_rid_set, METH_VARARGS,
1470                 "_dsdb_create_own_rid_set(samdb)"
1471                 " -> None" },
1472         { "_dsdb_allocate_rid", (PyCFunction)py_dsdb_allocate_rid, METH_VARARGS,
1473                 "_dsdb_allocate_rid(samdb)"
1474                 " -> RID" },
1475         { "_dsdb_load_udv_v2", (PyCFunction)py_dsdb_load_udv_v2, METH_VARARGS, NULL },
1476         { NULL }
1477 };
1478
1479 static struct PyModuleDef moduledef = {
1480     PyModuleDef_HEAD_INIT,
1481     .m_name = "dsdb",
1482     .m_doc = "Python bindings for the directory service databases.",
1483     .m_size = -1,
1484     .m_methods = py_dsdb_methods,
1485 };
1486
1487 MODULE_INIT_FUNC(dsdb)
1488 {
1489         PyObject *m;
1490
1491         m = PyModule_Create(&moduledef);
1492
1493         if (m == NULL)
1494                 return NULL;
1495
1496 #define ADD_DSDB_FLAG(val)  PyModule_AddObject(m, #val, PyInt_FromLong(val))
1497
1498         /* "userAccountControl" flags */
1499         ADD_DSDB_FLAG(UF_NORMAL_ACCOUNT);
1500         ADD_DSDB_FLAG(UF_TEMP_DUPLICATE_ACCOUNT);
1501         ADD_DSDB_FLAG(UF_SERVER_TRUST_ACCOUNT);
1502         ADD_DSDB_FLAG(UF_WORKSTATION_TRUST_ACCOUNT);
1503         ADD_DSDB_FLAG(UF_INTERDOMAIN_TRUST_ACCOUNT);
1504         ADD_DSDB_FLAG(UF_PASSWD_NOTREQD);
1505         ADD_DSDB_FLAG(UF_ACCOUNTDISABLE);
1506
1507         ADD_DSDB_FLAG(UF_SCRIPT);
1508         ADD_DSDB_FLAG(UF_ACCOUNTDISABLE);
1509         ADD_DSDB_FLAG(UF_00000004);
1510         ADD_DSDB_FLAG(UF_HOMEDIR_REQUIRED);
1511         ADD_DSDB_FLAG(UF_LOCKOUT);
1512         ADD_DSDB_FLAG(UF_PASSWD_NOTREQD);
1513         ADD_DSDB_FLAG(UF_PASSWD_CANT_CHANGE);
1514         ADD_DSDB_FLAG(UF_ENCRYPTED_TEXT_PASSWORD_ALLOWED);
1515         ADD_DSDB_FLAG(UF_TEMP_DUPLICATE_ACCOUNT);
1516         ADD_DSDB_FLAG(UF_NORMAL_ACCOUNT);
1517         ADD_DSDB_FLAG(UF_00000400);
1518         ADD_DSDB_FLAG(UF_INTERDOMAIN_TRUST_ACCOUNT);
1519         ADD_DSDB_FLAG(UF_WORKSTATION_TRUST_ACCOUNT);
1520         ADD_DSDB_FLAG(UF_SERVER_TRUST_ACCOUNT);
1521         ADD_DSDB_FLAG(UF_00004000);
1522         ADD_DSDB_FLAG(UF_00008000);
1523         ADD_DSDB_FLAG(UF_DONT_EXPIRE_PASSWD);
1524         ADD_DSDB_FLAG(UF_MNS_LOGON_ACCOUNT);
1525         ADD_DSDB_FLAG(UF_SMARTCARD_REQUIRED);
1526         ADD_DSDB_FLAG(UF_TRUSTED_FOR_DELEGATION);
1527         ADD_DSDB_FLAG(UF_NOT_DELEGATED);
1528         ADD_DSDB_FLAG(UF_USE_DES_KEY_ONLY);
1529         ADD_DSDB_FLAG(UF_DONT_REQUIRE_PREAUTH);
1530         ADD_DSDB_FLAG(UF_PASSWORD_EXPIRED);
1531         ADD_DSDB_FLAG(UF_TRUSTED_TO_AUTHENTICATE_FOR_DELEGATION);
1532         ADD_DSDB_FLAG(UF_NO_AUTH_DATA_REQUIRED);
1533         ADD_DSDB_FLAG(UF_PARTIAL_SECRETS_ACCOUNT);
1534         ADD_DSDB_FLAG(UF_USE_AES_KEYS);
1535
1536         /* groupType flags */
1537         ADD_DSDB_FLAG(GTYPE_SECURITY_BUILTIN_LOCAL_GROUP);
1538         ADD_DSDB_FLAG(GTYPE_SECURITY_GLOBAL_GROUP);
1539         ADD_DSDB_FLAG(GTYPE_SECURITY_DOMAIN_LOCAL_GROUP);
1540         ADD_DSDB_FLAG(GTYPE_SECURITY_UNIVERSAL_GROUP);
1541         ADD_DSDB_FLAG(GTYPE_DISTRIBUTION_GLOBAL_GROUP);
1542         ADD_DSDB_FLAG(GTYPE_DISTRIBUTION_DOMAIN_LOCAL_GROUP);
1543         ADD_DSDB_FLAG(GTYPE_DISTRIBUTION_UNIVERSAL_GROUP);
1544
1545         /* "sAMAccountType" flags */
1546         ADD_DSDB_FLAG(ATYPE_NORMAL_ACCOUNT);
1547         ADD_DSDB_FLAG(ATYPE_WORKSTATION_TRUST);
1548         ADD_DSDB_FLAG(ATYPE_INTERDOMAIN_TRUST);
1549         ADD_DSDB_FLAG(ATYPE_SECURITY_GLOBAL_GROUP);
1550         ADD_DSDB_FLAG(ATYPE_SECURITY_LOCAL_GROUP);
1551         ADD_DSDB_FLAG(ATYPE_SECURITY_UNIVERSAL_GROUP);
1552         ADD_DSDB_FLAG(ATYPE_DISTRIBUTION_GLOBAL_GROUP);
1553         ADD_DSDB_FLAG(ATYPE_DISTRIBUTION_LOCAL_GROUP);
1554         ADD_DSDB_FLAG(ATYPE_DISTRIBUTION_UNIVERSAL_GROUP);
1555
1556         /* "domainFunctionality", "forestFunctionality" flags in the rootDSE */
1557         ADD_DSDB_FLAG(DS_DOMAIN_FUNCTION_2000);
1558         ADD_DSDB_FLAG(DS_DOMAIN_FUNCTION_2003_MIXED);
1559         ADD_DSDB_FLAG(DS_DOMAIN_FUNCTION_2003);
1560         ADD_DSDB_FLAG(DS_DOMAIN_FUNCTION_2008);
1561         ADD_DSDB_FLAG(DS_DOMAIN_FUNCTION_2008_R2);
1562         ADD_DSDB_FLAG(DS_DOMAIN_FUNCTION_2012);
1563         ADD_DSDB_FLAG(DS_DOMAIN_FUNCTION_2012_R2);
1564         ADD_DSDB_FLAG(DS_DOMAIN_FUNCTION_2016);
1565
1566         /* nc replica flags */
1567         ADD_DSDB_FLAG(INSTANCE_TYPE_IS_NC_HEAD);
1568         ADD_DSDB_FLAG(INSTANCE_TYPE_UNINSTANT);
1569         ADD_DSDB_FLAG(INSTANCE_TYPE_WRITE);
1570         ADD_DSDB_FLAG(INSTANCE_TYPE_NC_ABOVE);
1571         ADD_DSDB_FLAG(INSTANCE_TYPE_NC_COMING);
1572         ADD_DSDB_FLAG(INSTANCE_TYPE_NC_GOING);
1573
1574         /* "systemFlags" */
1575         ADD_DSDB_FLAG(SYSTEM_FLAG_CR_NTDS_NC);
1576         ADD_DSDB_FLAG(SYSTEM_FLAG_CR_NTDS_DOMAIN);
1577         ADD_DSDB_FLAG(SYSTEM_FLAG_CR_NTDS_NOT_GC_REPLICATED);
1578         ADD_DSDB_FLAG(SYSTEM_FLAG_SCHEMA_BASE_OBJECT);
1579         ADD_DSDB_FLAG(SYSTEM_FLAG_ATTR_IS_RDN);
1580         ADD_DSDB_FLAG(SYSTEM_FLAG_DISALLOW_MOVE_ON_DELETE);
1581         ADD_DSDB_FLAG(SYSTEM_FLAG_DOMAIN_DISALLOW_MOVE);
1582         ADD_DSDB_FLAG(SYSTEM_FLAG_DOMAIN_DISALLOW_RENAME);
1583         ADD_DSDB_FLAG(SYSTEM_FLAG_CONFIG_ALLOW_LIMITED_MOVE);
1584         ADD_DSDB_FLAG(SYSTEM_FLAG_CONFIG_ALLOW_MOVE);
1585         ADD_DSDB_FLAG(SYSTEM_FLAG_CONFIG_ALLOW_RENAME);
1586         ADD_DSDB_FLAG(SYSTEM_FLAG_DISALLOW_DELETE);
1587
1588         /* Kerberos encryption type constants */
1589         ADD_DSDB_FLAG(ENC_ALL_TYPES);
1590         ADD_DSDB_FLAG(ENC_CRC32);
1591         ADD_DSDB_FLAG(ENC_RSA_MD5);
1592         ADD_DSDB_FLAG(ENC_RC4_HMAC_MD5);
1593         ADD_DSDB_FLAG(ENC_HMAC_SHA1_96_AES128);
1594         ADD_DSDB_FLAG(ENC_HMAC_SHA1_96_AES256);
1595
1596         ADD_DSDB_FLAG(SEARCH_FLAG_ATTINDEX);
1597         ADD_DSDB_FLAG(SEARCH_FLAG_PDNTATTINDEX);
1598         ADD_DSDB_FLAG(SEARCH_FLAG_ANR);
1599         ADD_DSDB_FLAG(SEARCH_FLAG_PRESERVEONDELETE);
1600         ADD_DSDB_FLAG(SEARCH_FLAG_COPY);
1601         ADD_DSDB_FLAG(SEARCH_FLAG_TUPLEINDEX);
1602         ADD_DSDB_FLAG(SEARCH_FLAG_SUBTREEATTRINDEX);
1603         ADD_DSDB_FLAG(SEARCH_FLAG_CONFIDENTIAL);
1604         ADD_DSDB_FLAG(SEARCH_FLAG_NEVERVALUEAUDIT);
1605         ADD_DSDB_FLAG(SEARCH_FLAG_RODC_ATTRIBUTE);
1606
1607         ADD_DSDB_FLAG(DS_FLAG_ATTR_NOT_REPLICATED);
1608         ADD_DSDB_FLAG(DS_FLAG_ATTR_REQ_PARTIAL_SET_MEMBER);
1609         ADD_DSDB_FLAG(DS_FLAG_ATTR_IS_CONSTRUCTED);
1610
1611         ADD_DSDB_FLAG(DS_NTDSSETTINGS_OPT_IS_AUTO_TOPOLOGY_DISABLED);
1612         ADD_DSDB_FLAG(DS_NTDSSETTINGS_OPT_IS_TOPL_CLEANUP_DISABLED);
1613         ADD_DSDB_FLAG(DS_NTDSSETTINGS_OPT_IS_TOPL_MIN_HOPS_DISABLED);
1614         ADD_DSDB_FLAG(DS_NTDSSETTINGS_OPT_IS_TOPL_DETECT_STALE_DISABLED);
1615         ADD_DSDB_FLAG(DS_NTDSSETTINGS_OPT_IS_INTER_SITE_AUTO_TOPOLOGY_DISABLED);
1616         ADD_DSDB_FLAG(DS_NTDSSETTINGS_OPT_IS_GROUP_CACHING_ENABLED);
1617         ADD_DSDB_FLAG(DS_NTDSSETTINGS_OPT_FORCE_KCC_WHISTLER_BEHAVIOR);
1618         ADD_DSDB_FLAG(DS_NTDSSETTINGS_OPT_IS_RAND_BH_SELECTION_DISABLED);
1619         ADD_DSDB_FLAG(DS_NTDSSETTINGS_OPT_IS_SCHEDULE_HASHING_ENABLED);
1620         ADD_DSDB_FLAG(DS_NTDSSETTINGS_OPT_IS_REDUNDANT_SERVER_TOPOLOGY_ENABLED);
1621
1622         ADD_DSDB_FLAG(DS_NTDSDSA_OPT_IS_GC);
1623         ADD_DSDB_FLAG(DS_NTDSDSA_OPT_DISABLE_INBOUND_REPL);
1624         ADD_DSDB_FLAG(DS_NTDSDSA_OPT_DISABLE_OUTBOUND_REPL);
1625         ADD_DSDB_FLAG(DS_NTDSDSA_OPT_DISABLE_NTDSCONN_XLATE);
1626         ADD_DSDB_FLAG(DS_NTDSDSA_OPT_DISABLE_SPN_REGISTRATION);
1627
1628         ADD_DSDB_FLAG(NTDSCONN_KCC_GC_TOPOLOGY);
1629         ADD_DSDB_FLAG(NTDSCONN_KCC_RING_TOPOLOGY);
1630         ADD_DSDB_FLAG(NTDSCONN_KCC_MINIMIZE_HOPS_TOPOLOGY);
1631         ADD_DSDB_FLAG(NTDSCONN_KCC_STALE_SERVERS_TOPOLOGY);
1632         ADD_DSDB_FLAG(NTDSCONN_KCC_OSCILLATING_CONNECTION_TOPOLOGY);
1633         ADD_DSDB_FLAG(NTDSCONN_KCC_INTERSITE_GC_TOPOLOGY);
1634         ADD_DSDB_FLAG(NTDSCONN_KCC_INTERSITE_TOPOLOGY);
1635         ADD_DSDB_FLAG(NTDSCONN_KCC_SERVER_FAILOVER_TOPOLOGY);
1636         ADD_DSDB_FLAG(NTDSCONN_KCC_SITE_FAILOVER_TOPOLOGY);
1637         ADD_DSDB_FLAG(NTDSCONN_KCC_REDUNDANT_SERVER_TOPOLOGY);
1638
1639         ADD_DSDB_FLAG(NTDSCONN_OPT_IS_GENERATED);
1640         ADD_DSDB_FLAG(NTDSCONN_OPT_TWOWAY_SYNC);
1641         ADD_DSDB_FLAG(NTDSCONN_OPT_OVERRIDE_NOTIFY_DEFAULT);
1642         ADD_DSDB_FLAG(NTDSCONN_OPT_USE_NOTIFY);
1643         ADD_DSDB_FLAG(NTDSCONN_OPT_DISABLE_INTERSITE_COMPRESSION);
1644         ADD_DSDB_FLAG(NTDSCONN_OPT_USER_OWNED_SCHEDULE);
1645         ADD_DSDB_FLAG(NTDSCONN_OPT_RODC_TOPOLOGY);
1646
1647         /* Site Link Object options */
1648         ADD_DSDB_FLAG(NTDSSITELINK_OPT_USE_NOTIFY);
1649         ADD_DSDB_FLAG(NTDSSITELINK_OPT_TWOWAY_SYNC);
1650         ADD_DSDB_FLAG(NTDSSITELINK_OPT_DISABLE_COMPRESSION);
1651
1652         /* GPO policy flags */
1653         ADD_DSDB_FLAG(GPLINK_OPT_DISABLE);
1654         ADD_DSDB_FLAG(GPLINK_OPT_ENFORCE);
1655         ADD_DSDB_FLAG(GPO_FLAG_USER_DISABLE);
1656         ADD_DSDB_FLAG(GPO_FLAG_MACHINE_DISABLE);
1657         ADD_DSDB_FLAG(GPO_INHERIT);
1658         ADD_DSDB_FLAG(GPO_BLOCK_INHERITANCE);
1659
1660 #define ADD_DSDB_STRING(val)  PyModule_AddObject(m, #val, PyStr_FromString(val))
1661
1662         ADD_DSDB_STRING(DSDB_SYNTAX_BINARY_DN);
1663         ADD_DSDB_STRING(DSDB_SYNTAX_STRING_DN);
1664         ADD_DSDB_STRING(DSDB_SYNTAX_OR_NAME);
1665         ADD_DSDB_STRING(DSDB_CONTROL_DBCHECK);
1666         ADD_DSDB_STRING(DSDB_CONTROL_DBCHECK_MODIFY_RO_REPLICA);
1667         ADD_DSDB_STRING(DSDB_CONTROL_DBCHECK_FIX_DUPLICATE_LINKS);
1668         ADD_DSDB_STRING(DSDB_CONTROL_DBCHECK_FIX_LINK_DN_NAME);
1669         ADD_DSDB_STRING(DSDB_CONTROL_DBCHECK_FIX_LINK_DN_SID);
1670         ADD_DSDB_STRING(DSDB_CONTROL_REPLMD_VANISH_LINKS);
1671         ADD_DSDB_STRING(DSDB_CONTROL_PERMIT_INTERDOMAIN_TRUST_UAC_OID);
1672         ADD_DSDB_STRING(DSDB_CONTROL_SKIP_DUPLICATES_CHECK_OID);
1673         ADD_DSDB_STRING(DSDB_CONTROL_BYPASS_PASSWORD_HASH_OID);
1674         ADD_DSDB_STRING(DSDB_CONTROL_INVALID_NOT_IMPLEMENTED);
1675
1676         ADD_DSDB_STRING(DS_GUID_COMPUTERS_CONTAINER);
1677         ADD_DSDB_STRING(DS_GUID_DELETED_OBJECTS_CONTAINER);
1678         ADD_DSDB_STRING(DS_GUID_DOMAIN_CONTROLLERS_CONTAINER);
1679         ADD_DSDB_STRING(DS_GUID_FOREIGNSECURITYPRINCIPALS_CONTAINER);
1680         ADD_DSDB_STRING(DS_GUID_INFRASTRUCTURE_CONTAINER);
1681         ADD_DSDB_STRING(DS_GUID_LOSTANDFOUND_CONTAINER);
1682         ADD_DSDB_STRING(DS_GUID_MICROSOFT_PROGRAM_DATA_CONTAINER);
1683         ADD_DSDB_STRING(DS_GUID_NTDS_QUOTAS_CONTAINER);
1684         ADD_DSDB_STRING(DS_GUID_PROGRAM_DATA_CONTAINER);
1685         ADD_DSDB_STRING(DS_GUID_SYSTEMS_CONTAINER);
1686         ADD_DSDB_STRING(DS_GUID_USERS_CONTAINER);
1687
1688         return m;
1689 }