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