2 Unix SMB/CIFS implementation.
3 Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007-2010
4 Copyright (C) Matthias Dieter Wallnöfer 2009
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.
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.
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/>.
21 #include "python/py3compat.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"
39 /* FIXME: These should be in a header file somewhere */
40 #define PyErr_LDB_OR_RAISE(py_ldb, ldb) \
41 if (!py_check_dcerpc_type(py_ldb, "ldb", "Ldb")) { \
42 PyErr_SetString(PyExc_TypeError, "Ldb connection object required"); \
45 ldb = pyldb_Ldb_AS_LDBCONTEXT(py_ldb);
47 #define PyErr_LDB_DN_OR_RAISE(py_ldb_dn, dn) \
48 if (!py_check_dcerpc_type(py_ldb_dn, "ldb", "Dn")) { \
49 PyErr_SetString(PyExc_TypeError, "ldb Dn object required"); \
52 dn = pyldb_Dn_AS_DN(py_ldb_dn);
54 static PyObject *py_ldb_get_exception(void)
56 PyObject *mod = PyImport_ImportModule("ldb");
57 PyObject *result = NULL;
61 result = PyObject_GetAttrString(mod, "LdbError");
66 static void PyErr_SetLdbError(PyObject *error, int ret, struct ldb_context *ldb_ctx)
68 if (ret == LDB_ERR_PYTHON_EXCEPTION)
69 return; /* Python exception should already be set, just keep that */
71 PyErr_SetObject(error,
72 Py_BuildValue(discard_const_p(char, "(i,s)"), ret,
73 ldb_ctx == NULL?ldb_strerror(ret):ldb_errstring(ldb_ctx)));
76 static PyObject *py_samdb_server_site_name(PyObject *self, PyObject *args)
78 PyObject *py_ldb, *result;
79 struct ldb_context *ldb;
83 if (!PyArg_ParseTuple(args, "O", &py_ldb))
86 PyErr_LDB_OR_RAISE(py_ldb, ldb);
88 mem_ctx = talloc_new(NULL);
89 if (mem_ctx == NULL) {
94 site = samdb_server_site_name(ldb, mem_ctx);
96 PyErr_SetString(PyExc_RuntimeError, "Failed to find server site");
101 result = PyUnicode_FromString(site);
102 talloc_free(mem_ctx);
106 static PyObject *py_dsdb_convert_schema_to_openldap(PyObject *self,
109 char *target_str, *mapping;
111 struct ldb_context *ldb;
115 if (!PyArg_ParseTuple(args, "Oss", &py_ldb, &target_str, &mapping))
118 PyErr_LDB_OR_RAISE(py_ldb, ldb);
120 retstr = dsdb_convert_schema_to_openldap(ldb, target_str, mapping);
121 if (retstr == NULL) {
122 PyErr_SetString(PyExc_RuntimeError,
123 "dsdb_convert_schema_to_openldap failed");
127 ret = PyUnicode_FromString(retstr);
132 static PyObject *py_samdb_set_domain_sid(PyLdbObject *self, PyObject *args)
134 PyObject *py_ldb, *py_sid;
135 struct ldb_context *ldb;
138 const char *sid_str = NULL;
140 if (!PyArg_ParseTuple(args, "OO", &py_ldb, &py_sid))
143 PyErr_LDB_OR_RAISE(py_ldb, ldb);
145 sid_str = PyUnicode_AsUTF8(py_sid);
146 if (sid_str == NULL) {
151 sid = dom_sid_parse_talloc(NULL, sid_str);
157 ret = samdb_set_domain_sid(ldb, sid);
160 PyErr_SetString(PyExc_RuntimeError, "set_domain_sid failed");
166 static PyObject *py_samdb_set_ntds_settings_dn(PyLdbObject *self, PyObject *args)
168 PyObject *py_ldb, *py_ntds_settings_dn;
169 struct ldb_context *ldb;
170 struct ldb_dn *ntds_settings_dn;
174 if (!PyArg_ParseTuple(args, "OO", &py_ldb, &py_ntds_settings_dn))
177 PyErr_LDB_OR_RAISE(py_ldb, ldb);
179 tmp_ctx = talloc_new(NULL);
180 if (tmp_ctx == NULL) {
185 if (!pyldb_Object_AsDn(tmp_ctx, py_ntds_settings_dn, ldb, &ntds_settings_dn)) {
186 /* exception thrown by "pyldb_Object_AsDn" */
187 talloc_free(tmp_ctx);
191 ret = samdb_set_ntds_settings_dn(ldb, ntds_settings_dn);
192 talloc_free(tmp_ctx);
194 PyErr_SetString(PyExc_RuntimeError, "set_ntds_settings_dn failed");
200 static PyObject *py_samdb_get_domain_sid(PyLdbObject *self, PyObject *args)
203 struct ldb_context *ldb;
204 const struct dom_sid *sid;
205 struct dom_sid_buf buf;
208 if (!PyArg_ParseTuple(args, "O", &py_ldb))
211 PyErr_LDB_OR_RAISE(py_ldb, ldb);
213 sid = samdb_domain_sid(ldb);
215 PyErr_SetString(PyExc_RuntimeError, "samdb_domain_sid failed");
219 ret = PyUnicode_FromString(dom_sid_str_buf(sid, &buf));
223 static PyObject *py_samdb_ntds_invocation_id(PyObject *self, PyObject *args)
225 PyObject *py_ldb, *result;
226 struct ldb_context *ldb;
227 const struct GUID *guid;
230 if (!PyArg_ParseTuple(args, "O", &py_ldb)) {
234 PyErr_LDB_OR_RAISE(py_ldb, ldb);
236 guid = samdb_ntds_invocation_id(ldb);
238 PyErr_SetString(PyExc_RuntimeError,
239 "Failed to find NTDS invocation ID");
243 retstr = GUID_string(NULL, guid);
244 if (retstr == NULL) {
248 result = PyUnicode_FromString(retstr);
253 static PyObject *py_dsdb_get_oid_from_attid(PyObject *self, PyObject *args)
256 struct ldb_context *ldb;
258 struct dsdb_schema *schema;
264 if (!PyArg_ParseTuple(args, "OI", &py_ldb, &attid))
267 PyErr_LDB_OR_RAISE(py_ldb, ldb);
269 mem_ctx = talloc_new(NULL);
275 schema = dsdb_get_schema(ldb, mem_ctx);
277 PyErr_SetString(PyExc_RuntimeError, "Failed to find a schema from ldb \n");
278 talloc_free(mem_ctx);
282 status = dsdb_schema_pfm_oid_from_attid(schema->prefixmap, attid,
284 if (!W_ERROR_IS_OK(status)) {
285 PyErr_SetWERROR(status);
286 talloc_free(mem_ctx);
290 ret = PyUnicode_FromString(oid);
292 talloc_free(mem_ctx);
298 static PyObject *py_dsdb_get_attid_from_lDAPDisplayName(PyObject *self, PyObject *args)
300 PyObject *py_ldb, *is_schema_nc;
301 struct ldb_context *ldb;
302 struct dsdb_schema *schema;
303 const char *ldap_display_name;
304 bool schema_nc = false;
305 const struct dsdb_attribute *a;
308 if (!PyArg_ParseTuple(args, "OsO", &py_ldb, &ldap_display_name, &is_schema_nc))
311 PyErr_LDB_OR_RAISE(py_ldb, ldb);
314 if (!PyBool_Check(is_schema_nc)) {
315 PyErr_SetString(PyExc_TypeError, "Expected boolean is_schema_nc");
318 if (is_schema_nc == Py_True) {
323 schema = dsdb_get_schema(ldb, NULL);
326 PyErr_SetString(PyExc_RuntimeError, "Failed to find a schema from ldb");
330 a = dsdb_attribute_by_lDAPDisplayName(schema, ldap_display_name);
332 PyErr_Format(PyExc_KeyError, "Failed to find attribute '%s'", ldap_display_name);
336 attid = dsdb_attribute_get_attid(a, schema_nc);
338 return PyLong_FromUnsignedLong(attid);
342 return the systemFlags as int from the attribute name
344 static PyObject *py_dsdb_get_systemFlags_from_lDAPDisplayName(PyObject *self, PyObject *args)
347 struct ldb_context *ldb;
348 struct dsdb_schema *schema;
349 const char *ldap_display_name;
350 const struct dsdb_attribute *attribute;
352 if (!PyArg_ParseTuple(args, "Os", &py_ldb, &ldap_display_name))
355 PyErr_LDB_OR_RAISE(py_ldb, ldb);
357 schema = dsdb_get_schema(ldb, NULL);
360 PyErr_SetString(PyExc_RuntimeError, "Failed to find a schema from ldb");
364 attribute = dsdb_attribute_by_lDAPDisplayName(schema, ldap_display_name);
365 if (attribute == NULL) {
366 PyErr_Format(PyExc_KeyError, "Failed to find attribute '%s'", ldap_display_name);
370 return PyLong_FromLong(attribute->systemFlags);
374 return the linkID from the attribute name
376 static PyObject *py_dsdb_get_linkId_from_lDAPDisplayName(PyObject *self, PyObject *args)
379 struct ldb_context *ldb;
380 struct dsdb_schema *schema;
381 const char *ldap_display_name;
382 const struct dsdb_attribute *attribute;
384 if (!PyArg_ParseTuple(args, "Os", &py_ldb, &ldap_display_name))
387 PyErr_LDB_OR_RAISE(py_ldb, ldb);
389 schema = dsdb_get_schema(ldb, NULL);
392 PyErr_SetString(PyExc_RuntimeError, "Failed to find a schema from ldb");
396 attribute = dsdb_attribute_by_lDAPDisplayName(schema, ldap_display_name);
397 if (attribute == NULL) {
398 PyErr_Format(PyExc_KeyError, "Failed to find attribute '%s'", ldap_display_name);
402 return PyLong_FromLong(attribute->linkID);
406 return the backlink attribute name (if any) for an attribute
408 static PyObject *py_dsdb_get_backlink_from_lDAPDisplayName(PyObject *self, PyObject *args)
411 struct ldb_context *ldb;
412 struct dsdb_schema *schema;
413 const char *ldap_display_name;
414 const struct dsdb_attribute *attribute, *target_attr;
416 if (!PyArg_ParseTuple(args, "Os", &py_ldb, &ldap_display_name))
419 PyErr_LDB_OR_RAISE(py_ldb, ldb);
421 schema = dsdb_get_schema(ldb, NULL);
424 PyErr_SetString(PyExc_RuntimeError, "Failed to find a schema from ldb");
428 attribute = dsdb_attribute_by_lDAPDisplayName(schema, ldap_display_name);
429 if (attribute == NULL) {
430 PyErr_Format(PyExc_KeyError, "Failed to find attribute '%s'", ldap_display_name);
434 if (attribute->linkID == 0) {
438 target_attr = dsdb_attribute_by_linkID(schema, attribute->linkID ^ 1);
439 if (target_attr == NULL) {
440 /* when we add pseudo-backlinks we'll need to handle
445 return PyUnicode_FromString(target_attr->lDAPDisplayName);
449 static PyObject *py_dsdb_get_lDAPDisplayName_by_attid(PyObject *self, PyObject *args)
452 struct ldb_context *ldb;
453 struct dsdb_schema *schema;
454 const struct dsdb_attribute *a;
457 if (!PyArg_ParseTuple(args, "OI", &py_ldb, &attid))
460 PyErr_LDB_OR_RAISE(py_ldb, ldb);
462 schema = dsdb_get_schema(ldb, NULL);
465 PyErr_SetString(PyExc_RuntimeError, "Failed to find a schema from ldb");
469 a = dsdb_attribute_by_attributeID_id(schema, attid);
471 PyErr_Format(PyExc_KeyError, "Failed to find attribute '0x%08x'", attid);
475 return PyUnicode_FromString(a->lDAPDisplayName);
480 return the attribute syntax oid as a string from the attribute name
482 static PyObject *py_dsdb_get_syntax_oid_from_lDAPDisplayName(PyObject *self, PyObject *args)
485 struct ldb_context *ldb;
486 struct dsdb_schema *schema;
487 const char *ldap_display_name;
488 const struct dsdb_attribute *attribute;
490 if (!PyArg_ParseTuple(args, "Os", &py_ldb, &ldap_display_name))
493 PyErr_LDB_OR_RAISE(py_ldb, ldb);
495 schema = dsdb_get_schema(ldb, NULL);
498 PyErr_SetString(PyExc_RuntimeError, "Failed to find a schema from ldb");
502 attribute = dsdb_attribute_by_lDAPDisplayName(schema, ldap_display_name);
503 if (attribute == NULL) {
504 PyErr_Format(PyExc_KeyError, "Failed to find attribute '%s'", ldap_display_name);
508 return PyUnicode_FromString(attribute->syntax->ldap_oid);
512 convert a python string to a DRSUAPI drsuapi_DsReplicaAttribute attribute
514 static PyObject *py_dsdb_DsReplicaAttribute(PyObject *self, PyObject *args)
516 PyObject *py_ldb, *el_list, *ret;
517 struct ldb_context *ldb;
518 char *ldap_display_name;
519 const struct dsdb_attribute *a;
520 struct dsdb_schema *schema;
521 struct dsdb_syntax_ctx syntax_ctx;
522 struct ldb_message_element *el;
523 struct drsuapi_DsReplicaAttribute *attr;
528 if (!PyArg_ParseTuple(args, "OsO", &py_ldb, &ldap_display_name, &el_list)) {
532 PyErr_LDB_OR_RAISE(py_ldb, ldb);
534 schema = dsdb_get_schema(ldb, NULL);
536 PyErr_SetString(PyExc_RuntimeError, "Failed to find a schema from ldb");
540 a = dsdb_attribute_by_lDAPDisplayName(schema, ldap_display_name);
542 PyErr_Format(PyExc_KeyError, "Failed to find attribute '%s'", ldap_display_name);
546 dsdb_syntax_ctx_init(&syntax_ctx, ldb, schema);
547 syntax_ctx.is_schema_nc = false;
549 tmp_ctx = talloc_new(ldb);
550 if (tmp_ctx == NULL) {
555 /* If we were not given an LdbMessageElement */
556 if (!PyList_Check(el_list)) {
557 if (!py_check_dcerpc_type(el_list, "ldb", "MessageElement")) {
558 PyErr_SetString(py_ldb_get_exception(),
559 "list of strings or ldb MessageElement object required");
564 * el may not be a valid talloc context, it
565 * could be part of an array
567 el = pyldb_MessageElement_AsMessageElement(el_list);
569 el = talloc_zero(tmp_ctx, struct ldb_message_element);
572 talloc_free(tmp_ctx);
576 el->name = ldap_display_name;
577 el->num_values = PyList_Size(el_list);
579 el->values = talloc_array(el, struct ldb_val, el->num_values);
580 if (el->values == NULL) {
582 talloc_free(tmp_ctx);
586 for (i = 0; i < el->num_values; i++) {
587 PyObject *item = PyList_GetItem(el_list, i);
588 if (!(PyBytes_Check(item))) {
589 PyErr_Format(PyExc_TypeError,
590 "ldif_element type should be "
593 talloc_free(tmp_ctx);
597 (uint8_t *)PyBytes_AsString(item);
598 el->values[i].length = PyBytes_Size(item);
602 attr = talloc_zero(tmp_ctx, struct drsuapi_DsReplicaAttribute);
605 talloc_free(tmp_ctx);
609 werr = a->syntax->ldb_to_drsuapi(&syntax_ctx, a, el, attr, attr);
610 PyErr_WERROR_NOT_OK_RAISE(werr);
612 ret = py_return_ndr_struct("samba.dcerpc.drsuapi", "DsReplicaAttribute", attr, attr);
614 talloc_free(tmp_ctx);
621 normalise a ldb attribute list
623 static PyObject *py_dsdb_normalise_attributes(PyObject *self, PyObject *args)
625 PyObject *py_ldb, *el_list, *py_ret;
626 struct ldb_context *ldb;
627 char *ldap_display_name;
628 const struct dsdb_attribute *a;
629 struct dsdb_schema *schema;
630 struct dsdb_syntax_ctx syntax_ctx;
631 struct ldb_message_element *el, *new_el;
632 struct drsuapi_DsReplicaAttribute *attr;
633 PyLdbMessageElementObject *ret;
637 PyTypeObject *py_type = NULL;
638 PyObject *module = NULL;
640 if (!PyArg_ParseTuple(args, "OsO", &py_ldb, &ldap_display_name, &el_list)) {
644 PyErr_LDB_OR_RAISE(py_ldb, ldb);
646 schema = dsdb_get_schema(ldb, NULL);
648 PyErr_SetString(PyExc_RuntimeError, "Failed to find a schema from ldb");
652 a = dsdb_attribute_by_lDAPDisplayName(schema, ldap_display_name);
654 PyErr_Format(PyExc_KeyError, "Failed to find attribute '%s'", ldap_display_name);
658 dsdb_syntax_ctx_init(&syntax_ctx, ldb, schema);
659 syntax_ctx.is_schema_nc = false;
661 tmp_ctx = talloc_new(ldb);
662 if (tmp_ctx == NULL) {
667 if (!PyList_Check(el_list)) {
668 if (!py_check_dcerpc_type(el_list, "ldb", "MessageElement")) {
669 PyErr_SetString(py_ldb_get_exception(),
670 "list of strings or ldb MessageElement object required");
675 * el may not be a valid talloc context, it
676 * could be part of an array
678 el = pyldb_MessageElement_AsMessageElement(el_list);
680 el = talloc_zero(tmp_ctx, struct ldb_message_element);
683 talloc_free(tmp_ctx);
687 el->name = ldap_display_name;
688 el->num_values = PyList_Size(el_list);
690 el->values = talloc_array(el, struct ldb_val, el->num_values);
691 if (el->values == NULL) {
693 talloc_free(tmp_ctx);
697 for (i = 0; i < el->num_values; i++) {
698 PyObject *item = PyList_GetItem(el_list, i);
699 if (!PyBytes_Check(item)) {
700 PyErr_Format(PyExc_TypeError,
701 "ldif_element type should be "
704 talloc_free(tmp_ctx);
707 el->values[i].data = (uint8_t *)PyBytes_AsString(item);
708 el->values[i].length = PyBytes_Size(item);
712 new_el = talloc_zero(tmp_ctx, struct ldb_message_element);
713 if (new_el == NULL) {
715 talloc_free(tmp_ctx);
719 /* Normalise "objectClass" attribute if needed */
720 if (ldb_attr_cmp(a->lDAPDisplayName, "objectClass") == 0) {
722 iret = dsdb_sort_objectClass_attr(ldb, schema, el, new_el, new_el);
723 if (iret != LDB_SUCCESS) {
724 PyErr_SetString(PyExc_RuntimeError, ldb_errstring(ldb));
725 talloc_free(tmp_ctx);
730 /* first run ldb_to_drsuapi, then convert back again. This has
731 * the effect of normalising the attributes
734 attr = talloc_zero(tmp_ctx, struct drsuapi_DsReplicaAttribute);
737 talloc_free(tmp_ctx);
741 werr = a->syntax->ldb_to_drsuapi(&syntax_ctx, a, el, attr, attr);
742 PyErr_WERROR_NOT_OK_RAISE(werr);
744 /* now convert back again */
745 werr = a->syntax->drsuapi_to_ldb(&syntax_ctx, a, attr, new_el, new_el);
746 PyErr_WERROR_NOT_OK_RAISE(werr);
748 module = PyImport_ImportModule("ldb");
749 if (module == NULL) {
753 py_type = (PyTypeObject *)PyObject_GetAttrString(module, "MessageElement");
754 if (py_type == NULL) {
761 py_ret = py_type->tp_alloc(py_type, 0);
763 if (py_ret == NULL) {
767 ret = (PyLdbMessageElementObject *)py_ret;
769 ret->mem_ctx = talloc_new(NULL);
770 if (talloc_reference(ret->mem_ctx, new_el) == NULL) {
777 talloc_free(tmp_ctx);
783 static PyObject *py_dsdb_set_ntds_invocation_id(PyObject *self, PyObject *args)
785 PyObject *py_ldb, *py_guid;
788 struct ldb_context *ldb;
789 if (!PyArg_ParseTuple(args, "OO", &py_ldb, &py_guid))
792 PyErr_LDB_OR_RAISE(py_ldb, ldb);
793 GUID_from_string(PyUnicode_AsUTF8(py_guid), &guid);
795 if (GUID_all_zero(&guid)) {
796 PyErr_SetString(PyExc_RuntimeError, "set_ntds_invocation_id rejected due to all-zero invocation ID");
800 ret = samdb_set_ntds_invocation_id(ldb, &guid);
802 PyErr_SetString(PyExc_RuntimeError, "set_ntds_invocation_id failed");
808 static PyObject *py_samdb_ntds_objectGUID(PyObject *self, PyObject *args)
810 PyObject *py_ldb, *result;
811 struct ldb_context *ldb;
812 const struct GUID *guid;
815 if (!PyArg_ParseTuple(args, "O", &py_ldb)) {
819 PyErr_LDB_OR_RAISE(py_ldb, ldb);
821 guid = samdb_ntds_objectGUID(ldb);
823 PyErr_SetString(PyExc_RuntimeError, "Failed to find NTDS GUID");
827 retstr = GUID_string(NULL, guid);
828 if (retstr == NULL) {
832 result = PyUnicode_FromString(retstr);
837 static PyObject *py_dsdb_set_global_schema(PyObject *self, PyObject *args)
840 struct ldb_context *ldb;
842 if (!PyArg_ParseTuple(args, "O", &py_ldb))
845 PyErr_LDB_OR_RAISE(py_ldb, ldb);
847 ret = dsdb_set_global_schema(ldb);
848 PyErr_LDB_ERROR_IS_ERR_RAISE(py_ldb_get_exception(), ret, ldb);
853 static PyObject *py_dsdb_load_partition_usn(PyObject *self, PyObject *args)
855 PyObject *py_dn, *py_ldb, *result;
857 uint64_t highest_uSN, urgent_uSN;
858 struct ldb_context *ldb;
862 if (!PyArg_ParseTuple(args, "OO", &py_ldb, &py_dn)) {
866 PyErr_LDB_OR_RAISE(py_ldb, ldb);
868 mem_ctx = talloc_new(NULL);
869 if (mem_ctx == NULL) {
874 if (!pyldb_Object_AsDn(mem_ctx, py_dn, ldb, &dn)) {
875 talloc_free(mem_ctx);
879 ret = dsdb_load_partition_usn(ldb, dn, &highest_uSN, &urgent_uSN);
880 if (ret != LDB_SUCCESS) {
881 PyErr_Format(PyExc_RuntimeError,
882 "Failed to load partition [%s] uSN - %s",
883 ldb_dn_get_linearized(dn),
885 talloc_free(mem_ctx);
889 talloc_free(mem_ctx);
891 result = Py_BuildValue(
893 "uSNHighest", (uint64_t)highest_uSN,
894 "uSNUrgent", (uint64_t)urgent_uSN);
899 static PyObject *py_dsdb_set_am_rodc(PyObject *self, PyObject *args)
903 struct ldb_context *ldb;
906 if (!PyArg_ParseTuple(args, "Oi", &py_ldb, &py_val))
909 PyErr_LDB_OR_RAISE(py_ldb, ldb);
910 ret = samdb_set_am_rodc(ldb, (bool)py_val);
912 PyErr_SetString(PyExc_RuntimeError, "set_am_rodc failed");
918 static PyObject *py_dsdb_set_schema_from_ldif(PyObject *self, PyObject *args)
923 struct ldb_context *ldb;
925 if (!PyArg_ParseTuple(args, "Osss", &py_ldb, &pf, &df, &dn))
928 PyErr_LDB_OR_RAISE(py_ldb, ldb);
930 result = dsdb_set_schema_from_ldif(ldb, pf, df, dn);
931 PyErr_WERROR_NOT_OK_RAISE(result);
936 static PyObject *py_dsdb_set_schema_from_ldb(PyObject *self, PyObject *args)
939 struct ldb_context *ldb;
940 PyObject *py_from_ldb;
941 struct ldb_context *from_ldb;
942 struct dsdb_schema *schema;
944 char write_indices_and_attributes = SCHEMA_WRITE;
945 if (!PyArg_ParseTuple(args, "OO|b",
946 &py_ldb, &py_from_ldb, &write_indices_and_attributes))
949 PyErr_LDB_OR_RAISE(py_ldb, ldb);
951 PyErr_LDB_OR_RAISE(py_from_ldb, from_ldb);
953 schema = dsdb_get_schema(from_ldb, NULL);
955 PyErr_SetString(PyExc_RuntimeError, "Failed to set find a schema on 'from' ldb!\n");
959 ret = dsdb_reference_schema(ldb, schema, write_indices_and_attributes);
960 PyErr_LDB_ERROR_IS_ERR_RAISE(py_ldb_get_exception(), ret, ldb);
965 static PyObject *py_dsdb_write_prefixes_from_schema_to_ldb(PyObject *self, PyObject *args)
968 struct ldb_context *ldb;
970 struct dsdb_schema *schema;
972 if (!PyArg_ParseTuple(args, "O", &py_ldb))
975 PyErr_LDB_OR_RAISE(py_ldb, ldb);
977 schema = dsdb_get_schema(ldb, NULL);
979 PyErr_SetString(PyExc_RuntimeError, "Failed to set find a schema on ldb!\n");
983 result = dsdb_write_prefixes_from_schema_to_ldb(NULL, ldb, schema);
984 PyErr_WERROR_NOT_OK_RAISE(result);
990 static PyObject *py_dsdb_get_partitions_dn(PyObject *self, PyObject *args)
992 struct ldb_context *ldb;
994 PyObject *py_ldb, *ret;
996 if (!PyArg_ParseTuple(args, "O", &py_ldb))
999 PyErr_LDB_OR_RAISE(py_ldb, ldb);
1001 dn = samdb_partitions_dn(ldb, NULL);
1006 ret = pyldb_Dn_FromDn(dn);
1012 static PyObject *py_dsdb_get_nc_root(PyObject *self, PyObject *args)
1014 struct ldb_context *ldb;
1015 struct ldb_dn *dn, *nc_root;
1016 PyObject *py_ldb, *py_ldb_dn, *py_nc_root;
1019 if (!PyArg_ParseTuple(args, "OO", &py_ldb, &py_ldb_dn))
1022 PyErr_LDB_OR_RAISE(py_ldb, ldb);
1023 PyErr_LDB_DN_OR_RAISE(py_ldb_dn, dn);
1025 ret = dsdb_find_nc_root(ldb, ldb, dn, &nc_root);
1026 PyErr_LDB_ERROR_IS_ERR_RAISE(py_ldb_get_exception(), ret, ldb);
1028 py_nc_root = pyldb_Dn_FromDn(nc_root);
1029 talloc_unlink(ldb, nc_root);
1033 static PyObject *py_dsdb_get_wellknown_dn(PyObject *self, PyObject *args)
1035 struct ldb_context *ldb;
1036 struct ldb_dn *nc_dn, *wk_dn;
1038 PyObject *py_ldb, *py_nc_dn, *py_wk_dn;
1041 if (!PyArg_ParseTuple(args, "OOs", &py_ldb, &py_nc_dn, &wkguid))
1044 PyErr_LDB_OR_RAISE(py_ldb, ldb);
1045 PyErr_LDB_DN_OR_RAISE(py_nc_dn, nc_dn);
1047 ret = dsdb_wellknown_dn(ldb, ldb, nc_dn, wkguid, &wk_dn);
1048 if (ret == LDB_ERR_NO_SUCH_OBJECT) {
1049 PyErr_Format(PyExc_KeyError, "Failed to find well known DN for GUID %s", wkguid);
1053 PyErr_LDB_ERROR_IS_ERR_RAISE(py_ldb_get_exception(), ret, ldb);
1055 py_wk_dn = pyldb_Dn_FromDn(wk_dn);
1056 talloc_unlink(ldb, wk_dn);
1062 call into samdb_rodc()
1064 static PyObject *py_dsdb_am_rodc(PyObject *self, PyObject *args)
1067 struct ldb_context *ldb;
1071 if (!PyArg_ParseTuple(args, "O", &py_ldb))
1074 PyErr_LDB_OR_RAISE(py_ldb, ldb);
1076 ret = samdb_rodc(ldb, &am_rodc);
1077 if (ret != LDB_SUCCESS) {
1078 PyErr_SetString(PyExc_RuntimeError, ldb_errstring(ldb));
1082 return PyBool_FromLong(am_rodc);
1086 call into samdb_is_pdc()
1088 static PyObject *py_dsdb_am_pdc(PyObject *self, PyObject *args)
1091 struct ldb_context *ldb;
1094 if (!PyArg_ParseTuple(args, "O", &py_ldb))
1097 PyErr_LDB_OR_RAISE(py_ldb, ldb);
1099 am_pdc = samdb_is_pdc(ldb);
1100 return PyBool_FromLong(am_pdc);
1104 call DSDB_EXTENDED_CREATE_OWN_RID_SET to get a new RID set for this server
1106 static PyObject *py_dsdb_create_own_rid_set(PyObject *self, PyObject *args)
1109 struct ldb_context *ldb;
1111 struct ldb_result *ext_res;
1113 if (!PyArg_ParseTuple(args, "O", &py_ldb))
1116 PyErr_LDB_OR_RAISE(py_ldb, ldb);
1119 * Run DSDB_EXTENDED_CREATE_OWN_RID_SET to get a RID set
1122 ret = ldb_extended(ldb, DSDB_EXTENDED_CREATE_OWN_RID_SET, NULL, &ext_res);
1124 PyErr_LDB_ERROR_IS_ERR_RAISE(py_ldb_get_exception(), ret, ldb);
1126 TALLOC_FREE(ext_res);
1132 call DSDB_EXTENDED_ALLOCATE_RID to get a new RID set for this server
1134 static PyObject *py_dsdb_allocate_rid(PyObject *self, PyObject *args)
1137 struct ldb_context *ldb;
1140 struct ldb_result *ext_res = NULL;
1141 struct dsdb_extended_allocate_rid *rid_return = NULL;
1142 if (!PyArg_ParseTuple(args, "O", &py_ldb)) {
1146 PyErr_LDB_OR_RAISE(py_ldb, ldb);
1148 rid_return = talloc_zero(ldb, struct dsdb_extended_allocate_rid);
1149 if (rid_return == NULL) {
1150 return PyErr_NoMemory();
1154 * Run DSDB_EXTENDED_ALLOCATE_RID to get a new RID
1157 ret = ldb_extended(ldb, DSDB_EXTENDED_ALLOCATE_RID, rid_return, &ext_res);
1158 if (ret != LDB_SUCCESS) {
1159 TALLOC_FREE(rid_return);
1160 TALLOC_FREE(ext_res);
1161 PyErr_LDB_ERROR_IS_ERR_RAISE(py_ldb_get_exception(), ret, ldb);
1164 rid = rid_return->rid;
1165 TALLOC_FREE(rid_return);
1166 TALLOC_FREE(ext_res);
1168 return PyLong_FromLong(rid);
1171 static PyObject *py_dns_delete_tombstones(PyObject *self, PyObject *args)
1175 struct ldb_context *ldb = NULL;
1176 TALLOC_CTX *mem_ctx = NULL;
1177 char *error_string = NULL;
1179 if (!PyArg_ParseTuple(args, "O", &py_ldb)) {
1182 PyErr_LDB_OR_RAISE(py_ldb, ldb);
1184 mem_ctx = talloc_new(ldb);
1185 if (mem_ctx == NULL) {
1186 return PyErr_NoMemory();
1189 status = dns_delete_tombstones(mem_ctx, ldb, &error_string);
1191 if (!NT_STATUS_IS_OK(status)) {
1193 PyErr_Format(PyExc_RuntimeError, "%s", error_string);
1195 PyErr_SetNTSTATUS(status);
1197 TALLOC_FREE(mem_ctx);
1201 TALLOC_FREE(mem_ctx);
1205 static PyObject *py_scavenge_dns_records(PyObject *self, PyObject *args)
1209 struct ldb_context *ldb = NULL;
1210 TALLOC_CTX *mem_ctx = NULL;
1211 char *error_string = NULL;
1213 if (!PyArg_ParseTuple(args, "O", &py_ldb)) {
1216 PyErr_LDB_OR_RAISE(py_ldb, ldb);
1218 mem_ctx = talloc_new(ldb);
1219 if (mem_ctx == NULL) {
1220 return PyErr_NoMemory();
1223 status = dns_tombstone_records(mem_ctx, ldb, &error_string);
1225 if (!NT_STATUS_IS_OK(status)) {
1227 PyErr_Format(PyExc_RuntimeError, "%s", error_string);
1229 PyErr_SetNTSTATUS(status);
1231 TALLOC_FREE(mem_ctx);
1235 TALLOC_FREE(mem_ctx);
1239 static PyObject *py_dsdb_garbage_collect_tombstones(PyObject *self, PyObject *args)
1241 PyObject *py_ldb, *py_list_dn;
1242 struct ldb_context *ldb = NULL;
1245 long long _current_time, _tombstone_lifetime = LLONG_MAX;
1246 uint32_t tombstone_lifetime32;
1247 struct dsdb_ldb_dn_list_node *part = NULL;
1248 time_t current_time, tombstone_lifetime;
1249 TALLOC_CTX *mem_ctx = NULL;
1251 unsigned int num_objects_removed = 0;
1252 unsigned int num_links_removed = 0;
1253 char *error_string = NULL;
1255 if (!PyArg_ParseTuple(args, "OOL|L", &py_ldb,
1256 &py_list_dn, &_current_time, &_tombstone_lifetime)) {
1261 PyErr_LDB_OR_RAISE(py_ldb, ldb);
1263 mem_ctx = talloc_new(ldb);
1264 if (mem_ctx == NULL) {
1265 return PyErr_NoMemory();
1268 current_time = _current_time;
1270 if (_tombstone_lifetime == LLONG_MAX) {
1271 int ret = dsdb_tombstone_lifetime(ldb, &tombstone_lifetime32);
1272 if (ret != LDB_SUCCESS) {
1273 PyErr_Format(PyExc_RuntimeError,
1274 "Failed to get tombstone lifetime: %s",
1275 ldb_errstring(ldb));
1276 TALLOC_FREE(mem_ctx);
1279 tombstone_lifetime = tombstone_lifetime32;
1281 tombstone_lifetime = _tombstone_lifetime;
1284 if (!PyList_Check(py_list_dn)) {
1285 PyErr_SetString(PyExc_TypeError, "A list of DNs were expected");
1286 TALLOC_FREE(mem_ctx);
1290 length = PyList_GET_SIZE(py_list_dn);
1292 for (i = 0; i < length; i++) {
1293 const char *part_str = PyUnicode_AsUTF8(PyList_GetItem(py_list_dn, i));
1295 struct dsdb_ldb_dn_list_node *node;
1297 if (part_str == NULL) {
1298 TALLOC_FREE(mem_ctx);
1299 return PyErr_NoMemory();
1302 p = ldb_dn_new(mem_ctx, ldb, part_str);
1304 PyErr_Format(PyExc_RuntimeError, "Failed to parse DN %s", part_str);
1305 TALLOC_FREE(mem_ctx);
1308 node = talloc_zero(mem_ctx, struct dsdb_ldb_dn_list_node);
1311 DLIST_ADD_END(part, node);
1314 status = dsdb_garbage_collect_tombstones(mem_ctx, ldb,
1317 &num_objects_removed,
1321 if (!NT_STATUS_IS_OK(status)) {
1323 PyErr_Format(PyExc_RuntimeError, "%s", error_string);
1325 PyErr_SetNTSTATUS(status);
1327 TALLOC_FREE(mem_ctx);
1331 TALLOC_FREE(mem_ctx);
1333 return Py_BuildValue("(II)", num_objects_removed,
1337 static PyObject *py_dsdb_load_udv_v2(PyObject *self, PyObject *args)
1342 PyObject *py_ldb = NULL, *py_dn = NULL, *pylist = NULL;
1343 struct ldb_context *samdb = NULL;
1344 struct ldb_dn *dn = NULL;
1345 struct drsuapi_DsReplicaCursor2 *cursors = NULL;
1346 TALLOC_CTX *tmp_ctx = NULL;
1348 if (!PyArg_ParseTuple(args, "OO", &py_ldb, &py_dn)) {
1352 PyErr_LDB_OR_RAISE(py_ldb, samdb);
1354 tmp_ctx = talloc_new(samdb);
1355 if (tmp_ctx == NULL) {
1356 return PyErr_NoMemory();
1359 ok = pyldb_Object_AsDn(tmp_ctx, py_dn, samdb, &dn);
1361 TALLOC_FREE(tmp_ctx);
1365 ret = dsdb_load_udv_v2(samdb, dn, tmp_ctx, &cursors, &count);
1366 if (ret != LDB_SUCCESS) {
1367 TALLOC_FREE(tmp_ctx);
1368 PyErr_SetString(PyExc_RuntimeError,
1369 "Failed to load udv from ldb");
1373 pylist = PyList_New(count);
1374 if (pylist == NULL) {
1375 TALLOC_FREE(tmp_ctx);
1376 return PyErr_NoMemory();
1379 for (i = 0; i < count; i++) {
1380 PyObject *py_cursor;
1381 struct drsuapi_DsReplicaCursor2 *cursor;
1382 cursor = talloc(tmp_ctx, struct drsuapi_DsReplicaCursor2);
1383 if (cursor == NULL) {
1384 TALLOC_FREE(tmp_ctx);
1385 return PyErr_NoMemory();
1387 *cursor = cursors[i];
1389 py_cursor = py_return_ndr_struct("samba.dcerpc.drsuapi",
1392 if (py_cursor == NULL) {
1393 TALLOC_FREE(tmp_ctx);
1394 return PyErr_NoMemory();
1397 PyList_SetItem(pylist, i, py_cursor);
1400 TALLOC_FREE(tmp_ctx);
1404 static PyMethodDef py_dsdb_methods[] = {
1405 { "_samdb_server_site_name", (PyCFunction)py_samdb_server_site_name,
1406 METH_VARARGS, "Get the server site name as a string"},
1407 { "_dsdb_convert_schema_to_openldap",
1408 (PyCFunction)py_dsdb_convert_schema_to_openldap, METH_VARARGS,
1409 "dsdb_convert_schema_to_openldap(ldb, target_str, mapping) -> str\n"
1410 "Create an OpenLDAP schema from a schema." },
1411 { "_samdb_set_domain_sid", (PyCFunction)py_samdb_set_domain_sid,
1413 "samdb_set_domain_sid(samdb, sid)\n"
1414 "Set SID of domain to use." },
1415 { "_samdb_get_domain_sid", (PyCFunction)py_samdb_get_domain_sid,
1417 "samdb_get_domain_sid(samdb)\n"
1418 "Get SID of domain in use." },
1419 { "_samdb_ntds_invocation_id", (PyCFunction)py_samdb_ntds_invocation_id,
1420 METH_VARARGS, "get the NTDS invocation ID GUID as a string"},
1421 { "_samdb_set_ntds_settings_dn", (PyCFunction)py_samdb_set_ntds_settings_dn,
1423 "samdb_set_ntds_settings_dn(samdb, ntds_settings_dn)\n"
1424 "Set NTDS Settings DN for this LDB (allows it to be set before the DB fully exists)." },
1425 { "_dsdb_get_oid_from_attid", (PyCFunction)py_dsdb_get_oid_from_attid,
1426 METH_VARARGS, NULL },
1427 { "_dsdb_get_attid_from_lDAPDisplayName", (PyCFunction)py_dsdb_get_attid_from_lDAPDisplayName,
1428 METH_VARARGS, NULL },
1429 { "_dsdb_get_syntax_oid_from_lDAPDisplayName", (PyCFunction)py_dsdb_get_syntax_oid_from_lDAPDisplayName,
1430 METH_VARARGS, NULL },
1431 { "_dsdb_get_systemFlags_from_lDAPDisplayName", (PyCFunction)py_dsdb_get_systemFlags_from_lDAPDisplayName,
1432 METH_VARARGS, NULL },
1433 { "_dsdb_get_linkId_from_lDAPDisplayName", (PyCFunction)py_dsdb_get_linkId_from_lDAPDisplayName,
1434 METH_VARARGS, NULL },
1435 { "_dsdb_get_lDAPDisplayName_by_attid", (PyCFunction)py_dsdb_get_lDAPDisplayName_by_attid,
1436 METH_VARARGS, NULL },
1437 { "_dsdb_get_backlink_from_lDAPDisplayName", (PyCFunction)py_dsdb_get_backlink_from_lDAPDisplayName,
1438 METH_VARARGS, NULL },
1439 { "_dsdb_set_ntds_invocation_id",
1440 (PyCFunction)py_dsdb_set_ntds_invocation_id, METH_VARARGS,
1442 { "_samdb_ntds_objectGUID", (PyCFunction)py_samdb_ntds_objectGUID,
1443 METH_VARARGS, "get the NTDS objectGUID as a string"},
1444 { "_dsdb_set_global_schema", (PyCFunction)py_dsdb_set_global_schema,
1445 METH_VARARGS, NULL },
1446 { "_dsdb_load_partition_usn", (PyCFunction)py_dsdb_load_partition_usn,
1448 "get uSNHighest and uSNUrgent from the partition @REPLCHANGED"},
1449 { "_dsdb_set_am_rodc",
1450 (PyCFunction)py_dsdb_set_am_rodc, METH_VARARGS,
1453 (PyCFunction)py_dsdb_am_rodc, METH_VARARGS,
1456 (PyCFunction)py_dsdb_am_pdc, METH_VARARGS,
1458 { "_dsdb_set_schema_from_ldif", (PyCFunction)py_dsdb_set_schema_from_ldif, METH_VARARGS,
1460 { "_dsdb_set_schema_from_ldb", (PyCFunction)py_dsdb_set_schema_from_ldb, METH_VARARGS,
1462 { "_dsdb_write_prefixes_from_schema_to_ldb", (PyCFunction)py_dsdb_write_prefixes_from_schema_to_ldb, METH_VARARGS,
1464 { "_dsdb_get_partitions_dn", (PyCFunction)py_dsdb_get_partitions_dn, METH_VARARGS, NULL },
1465 { "_dsdb_get_nc_root", (PyCFunction)py_dsdb_get_nc_root, METH_VARARGS, NULL },
1466 { "_dsdb_get_wellknown_dn", (PyCFunction)py_dsdb_get_wellknown_dn, METH_VARARGS, NULL },
1467 { "_dsdb_DsReplicaAttribute", (PyCFunction)py_dsdb_DsReplicaAttribute, METH_VARARGS, NULL },
1468 { "_dsdb_normalise_attributes", (PyCFunction)py_dsdb_normalise_attributes, METH_VARARGS, NULL },
1469 { "_dsdb_garbage_collect_tombstones", (PyCFunction)py_dsdb_garbage_collect_tombstones, METH_VARARGS,
1470 "_dsdb_kcc_check_deleted(samdb, [dn], current_time, tombstone_lifetime)"
1471 " -> (num_objects_expunged, num_links_expunged)" },
1472 { "_scavenge_dns_records", (PyCFunction)py_scavenge_dns_records,
1473 METH_VARARGS, NULL},
1474 { "_dns_delete_tombstones", (PyCFunction)py_dns_delete_tombstones,
1475 METH_VARARGS, NULL},
1476 { "_dsdb_create_own_rid_set", (PyCFunction)py_dsdb_create_own_rid_set, METH_VARARGS,
1477 "_dsdb_create_own_rid_set(samdb)"
1479 { "_dsdb_allocate_rid", (PyCFunction)py_dsdb_allocate_rid, METH_VARARGS,
1480 "_dsdb_allocate_rid(samdb)"
1482 { "_dsdb_load_udv_v2", (PyCFunction)py_dsdb_load_udv_v2, METH_VARARGS, NULL },
1486 static struct PyModuleDef moduledef = {
1487 PyModuleDef_HEAD_INIT,
1489 .m_doc = "Python bindings for the directory service databases.",
1491 .m_methods = py_dsdb_methods,
1494 MODULE_INIT_FUNC(dsdb)
1498 m = PyModule_Create(&moduledef);
1503 #define ADD_DSDB_FLAG(val) PyModule_AddObject(m, #val, PyLong_FromLong(val))
1505 /* "userAccountControl" flags */
1506 ADD_DSDB_FLAG(UF_NORMAL_ACCOUNT);
1507 ADD_DSDB_FLAG(UF_TEMP_DUPLICATE_ACCOUNT);
1508 ADD_DSDB_FLAG(UF_SERVER_TRUST_ACCOUNT);
1509 ADD_DSDB_FLAG(UF_WORKSTATION_TRUST_ACCOUNT);
1510 ADD_DSDB_FLAG(UF_INTERDOMAIN_TRUST_ACCOUNT);
1511 ADD_DSDB_FLAG(UF_PASSWD_NOTREQD);
1512 ADD_DSDB_FLAG(UF_ACCOUNTDISABLE);
1514 ADD_DSDB_FLAG(UF_SCRIPT);
1515 ADD_DSDB_FLAG(UF_ACCOUNTDISABLE);
1516 ADD_DSDB_FLAG(UF_00000004);
1517 ADD_DSDB_FLAG(UF_HOMEDIR_REQUIRED);
1518 ADD_DSDB_FLAG(UF_LOCKOUT);
1519 ADD_DSDB_FLAG(UF_PASSWD_NOTREQD);
1520 ADD_DSDB_FLAG(UF_PASSWD_CANT_CHANGE);
1521 ADD_DSDB_FLAG(UF_ENCRYPTED_TEXT_PASSWORD_ALLOWED);
1522 ADD_DSDB_FLAG(UF_TEMP_DUPLICATE_ACCOUNT);
1523 ADD_DSDB_FLAG(UF_NORMAL_ACCOUNT);
1524 ADD_DSDB_FLAG(UF_00000400);
1525 ADD_DSDB_FLAG(UF_INTERDOMAIN_TRUST_ACCOUNT);
1526 ADD_DSDB_FLAG(UF_WORKSTATION_TRUST_ACCOUNT);
1527 ADD_DSDB_FLAG(UF_SERVER_TRUST_ACCOUNT);
1528 ADD_DSDB_FLAG(UF_00004000);
1529 ADD_DSDB_FLAG(UF_00008000);
1530 ADD_DSDB_FLAG(UF_DONT_EXPIRE_PASSWD);
1531 ADD_DSDB_FLAG(UF_MNS_LOGON_ACCOUNT);
1532 ADD_DSDB_FLAG(UF_SMARTCARD_REQUIRED);
1533 ADD_DSDB_FLAG(UF_TRUSTED_FOR_DELEGATION);
1534 ADD_DSDB_FLAG(UF_NOT_DELEGATED);
1535 ADD_DSDB_FLAG(UF_USE_DES_KEY_ONLY);
1536 ADD_DSDB_FLAG(UF_DONT_REQUIRE_PREAUTH);
1537 ADD_DSDB_FLAG(UF_PASSWORD_EXPIRED);
1538 ADD_DSDB_FLAG(UF_TRUSTED_TO_AUTHENTICATE_FOR_DELEGATION);
1539 ADD_DSDB_FLAG(UF_NO_AUTH_DATA_REQUIRED);
1540 ADD_DSDB_FLAG(UF_PARTIAL_SECRETS_ACCOUNT);
1541 ADD_DSDB_FLAG(UF_USE_AES_KEYS);
1543 /* groupType flags */
1544 ADD_DSDB_FLAG(GTYPE_SECURITY_BUILTIN_LOCAL_GROUP);
1545 ADD_DSDB_FLAG(GTYPE_SECURITY_GLOBAL_GROUP);
1546 ADD_DSDB_FLAG(GTYPE_SECURITY_DOMAIN_LOCAL_GROUP);
1547 ADD_DSDB_FLAG(GTYPE_SECURITY_UNIVERSAL_GROUP);
1548 ADD_DSDB_FLAG(GTYPE_DISTRIBUTION_GLOBAL_GROUP);
1549 ADD_DSDB_FLAG(GTYPE_DISTRIBUTION_DOMAIN_LOCAL_GROUP);
1550 ADD_DSDB_FLAG(GTYPE_DISTRIBUTION_UNIVERSAL_GROUP);
1552 /* "sAMAccountType" flags */
1553 ADD_DSDB_FLAG(ATYPE_NORMAL_ACCOUNT);
1554 ADD_DSDB_FLAG(ATYPE_WORKSTATION_TRUST);
1555 ADD_DSDB_FLAG(ATYPE_INTERDOMAIN_TRUST);
1556 ADD_DSDB_FLAG(ATYPE_SECURITY_GLOBAL_GROUP);
1557 ADD_DSDB_FLAG(ATYPE_SECURITY_LOCAL_GROUP);
1558 ADD_DSDB_FLAG(ATYPE_SECURITY_UNIVERSAL_GROUP);
1559 ADD_DSDB_FLAG(ATYPE_DISTRIBUTION_GLOBAL_GROUP);
1560 ADD_DSDB_FLAG(ATYPE_DISTRIBUTION_LOCAL_GROUP);
1561 ADD_DSDB_FLAG(ATYPE_DISTRIBUTION_UNIVERSAL_GROUP);
1563 /* "domainFunctionality", "forestFunctionality" flags in the rootDSE */
1564 ADD_DSDB_FLAG(DS_DOMAIN_FUNCTION_2000);
1565 ADD_DSDB_FLAG(DS_DOMAIN_FUNCTION_2003_MIXED);
1566 ADD_DSDB_FLAG(DS_DOMAIN_FUNCTION_2003);
1567 ADD_DSDB_FLAG(DS_DOMAIN_FUNCTION_2008);
1568 ADD_DSDB_FLAG(DS_DOMAIN_FUNCTION_2008_R2);
1569 ADD_DSDB_FLAG(DS_DOMAIN_FUNCTION_2012);
1570 ADD_DSDB_FLAG(DS_DOMAIN_FUNCTION_2012_R2);
1571 ADD_DSDB_FLAG(DS_DOMAIN_FUNCTION_2016);
1573 /* nc replica flags */
1574 ADD_DSDB_FLAG(INSTANCE_TYPE_IS_NC_HEAD);
1575 ADD_DSDB_FLAG(INSTANCE_TYPE_UNINSTANT);
1576 ADD_DSDB_FLAG(INSTANCE_TYPE_WRITE);
1577 ADD_DSDB_FLAG(INSTANCE_TYPE_NC_ABOVE);
1578 ADD_DSDB_FLAG(INSTANCE_TYPE_NC_COMING);
1579 ADD_DSDB_FLAG(INSTANCE_TYPE_NC_GOING);
1582 ADD_DSDB_FLAG(SYSTEM_FLAG_CR_NTDS_NC);
1583 ADD_DSDB_FLAG(SYSTEM_FLAG_CR_NTDS_DOMAIN);
1584 ADD_DSDB_FLAG(SYSTEM_FLAG_CR_NTDS_NOT_GC_REPLICATED);
1585 ADD_DSDB_FLAG(SYSTEM_FLAG_SCHEMA_BASE_OBJECT);
1586 ADD_DSDB_FLAG(SYSTEM_FLAG_ATTR_IS_RDN);
1587 ADD_DSDB_FLAG(SYSTEM_FLAG_DISALLOW_MOVE_ON_DELETE);
1588 ADD_DSDB_FLAG(SYSTEM_FLAG_DOMAIN_DISALLOW_MOVE);
1589 ADD_DSDB_FLAG(SYSTEM_FLAG_DOMAIN_DISALLOW_RENAME);
1590 ADD_DSDB_FLAG(SYSTEM_FLAG_CONFIG_ALLOW_LIMITED_MOVE);
1591 ADD_DSDB_FLAG(SYSTEM_FLAG_CONFIG_ALLOW_MOVE);
1592 ADD_DSDB_FLAG(SYSTEM_FLAG_CONFIG_ALLOW_RENAME);
1593 ADD_DSDB_FLAG(SYSTEM_FLAG_DISALLOW_DELETE);
1595 /* Kerberos encryption type constants */
1596 ADD_DSDB_FLAG(ENC_ALL_TYPES);
1597 ADD_DSDB_FLAG(ENC_CRC32);
1598 ADD_DSDB_FLAG(ENC_RSA_MD5);
1599 ADD_DSDB_FLAG(ENC_RC4_HMAC_MD5);
1600 ADD_DSDB_FLAG(ENC_HMAC_SHA1_96_AES128);
1601 ADD_DSDB_FLAG(ENC_HMAC_SHA1_96_AES256);
1603 ADD_DSDB_FLAG(SEARCH_FLAG_ATTINDEX);
1604 ADD_DSDB_FLAG(SEARCH_FLAG_PDNTATTINDEX);
1605 ADD_DSDB_FLAG(SEARCH_FLAG_ANR);
1606 ADD_DSDB_FLAG(SEARCH_FLAG_PRESERVEONDELETE);
1607 ADD_DSDB_FLAG(SEARCH_FLAG_COPY);
1608 ADD_DSDB_FLAG(SEARCH_FLAG_TUPLEINDEX);
1609 ADD_DSDB_FLAG(SEARCH_FLAG_SUBTREEATTRINDEX);
1610 ADD_DSDB_FLAG(SEARCH_FLAG_CONFIDENTIAL);
1611 ADD_DSDB_FLAG(SEARCH_FLAG_NEVERVALUEAUDIT);
1612 ADD_DSDB_FLAG(SEARCH_FLAG_RODC_ATTRIBUTE);
1614 ADD_DSDB_FLAG(DS_FLAG_ATTR_NOT_REPLICATED);
1615 ADD_DSDB_FLAG(DS_FLAG_ATTR_REQ_PARTIAL_SET_MEMBER);
1616 ADD_DSDB_FLAG(DS_FLAG_ATTR_IS_CONSTRUCTED);
1618 ADD_DSDB_FLAG(DS_NTDSSETTINGS_OPT_IS_AUTO_TOPOLOGY_DISABLED);
1619 ADD_DSDB_FLAG(DS_NTDSSETTINGS_OPT_IS_TOPL_CLEANUP_DISABLED);
1620 ADD_DSDB_FLAG(DS_NTDSSETTINGS_OPT_IS_TOPL_MIN_HOPS_DISABLED);
1621 ADD_DSDB_FLAG(DS_NTDSSETTINGS_OPT_IS_TOPL_DETECT_STALE_DISABLED);
1622 ADD_DSDB_FLAG(DS_NTDSSETTINGS_OPT_IS_INTER_SITE_AUTO_TOPOLOGY_DISABLED);
1623 ADD_DSDB_FLAG(DS_NTDSSETTINGS_OPT_IS_GROUP_CACHING_ENABLED);
1624 ADD_DSDB_FLAG(DS_NTDSSETTINGS_OPT_FORCE_KCC_WHISTLER_BEHAVIOR);
1625 ADD_DSDB_FLAG(DS_NTDSSETTINGS_OPT_IS_RAND_BH_SELECTION_DISABLED);
1626 ADD_DSDB_FLAG(DS_NTDSSETTINGS_OPT_IS_SCHEDULE_HASHING_ENABLED);
1627 ADD_DSDB_FLAG(DS_NTDSSETTINGS_OPT_IS_REDUNDANT_SERVER_TOPOLOGY_ENABLED);
1629 ADD_DSDB_FLAG(DS_NTDSDSA_OPT_IS_GC);
1630 ADD_DSDB_FLAG(DS_NTDSDSA_OPT_DISABLE_INBOUND_REPL);
1631 ADD_DSDB_FLAG(DS_NTDSDSA_OPT_DISABLE_OUTBOUND_REPL);
1632 ADD_DSDB_FLAG(DS_NTDSDSA_OPT_DISABLE_NTDSCONN_XLATE);
1633 ADD_DSDB_FLAG(DS_NTDSDSA_OPT_DISABLE_SPN_REGISTRATION);
1635 ADD_DSDB_FLAG(NTDSCONN_KCC_GC_TOPOLOGY);
1636 ADD_DSDB_FLAG(NTDSCONN_KCC_RING_TOPOLOGY);
1637 ADD_DSDB_FLAG(NTDSCONN_KCC_MINIMIZE_HOPS_TOPOLOGY);
1638 ADD_DSDB_FLAG(NTDSCONN_KCC_STALE_SERVERS_TOPOLOGY);
1639 ADD_DSDB_FLAG(NTDSCONN_KCC_OSCILLATING_CONNECTION_TOPOLOGY);
1640 ADD_DSDB_FLAG(NTDSCONN_KCC_INTERSITE_GC_TOPOLOGY);
1641 ADD_DSDB_FLAG(NTDSCONN_KCC_INTERSITE_TOPOLOGY);
1642 ADD_DSDB_FLAG(NTDSCONN_KCC_SERVER_FAILOVER_TOPOLOGY);
1643 ADD_DSDB_FLAG(NTDSCONN_KCC_SITE_FAILOVER_TOPOLOGY);
1644 ADD_DSDB_FLAG(NTDSCONN_KCC_REDUNDANT_SERVER_TOPOLOGY);
1646 ADD_DSDB_FLAG(NTDSCONN_OPT_IS_GENERATED);
1647 ADD_DSDB_FLAG(NTDSCONN_OPT_TWOWAY_SYNC);
1648 ADD_DSDB_FLAG(NTDSCONN_OPT_OVERRIDE_NOTIFY_DEFAULT);
1649 ADD_DSDB_FLAG(NTDSCONN_OPT_USE_NOTIFY);
1650 ADD_DSDB_FLAG(NTDSCONN_OPT_DISABLE_INTERSITE_COMPRESSION);
1651 ADD_DSDB_FLAG(NTDSCONN_OPT_USER_OWNED_SCHEDULE);
1652 ADD_DSDB_FLAG(NTDSCONN_OPT_RODC_TOPOLOGY);
1654 /* Site Link Object options */
1655 ADD_DSDB_FLAG(NTDSSITELINK_OPT_USE_NOTIFY);
1656 ADD_DSDB_FLAG(NTDSSITELINK_OPT_TWOWAY_SYNC);
1657 ADD_DSDB_FLAG(NTDSSITELINK_OPT_DISABLE_COMPRESSION);
1659 /* GPO policy flags */
1660 ADD_DSDB_FLAG(GPLINK_OPT_DISABLE);
1661 ADD_DSDB_FLAG(GPLINK_OPT_ENFORCE);
1662 ADD_DSDB_FLAG(GPO_FLAG_USER_DISABLE);
1663 ADD_DSDB_FLAG(GPO_FLAG_MACHINE_DISABLE);
1664 ADD_DSDB_FLAG(GPO_INHERIT);
1665 ADD_DSDB_FLAG(GPO_BLOCK_INHERITANCE);
1667 #define ADD_DSDB_STRING(val) PyModule_AddObject(m, #val, PyUnicode_FromString(val))
1669 ADD_DSDB_STRING(DSDB_SYNTAX_BINARY_DN);
1670 ADD_DSDB_STRING(DSDB_SYNTAX_STRING_DN);
1671 ADD_DSDB_STRING(DSDB_SYNTAX_OR_NAME);
1672 ADD_DSDB_STRING(DSDB_CONTROL_DBCHECK);
1673 ADD_DSDB_STRING(DSDB_CONTROL_DBCHECK_MODIFY_RO_REPLICA);
1674 ADD_DSDB_STRING(DSDB_CONTROL_DBCHECK_FIX_DUPLICATE_LINKS);
1675 ADD_DSDB_STRING(DSDB_CONTROL_DBCHECK_FIX_LINK_DN_NAME);
1676 ADD_DSDB_STRING(DSDB_CONTROL_DBCHECK_FIX_LINK_DN_SID);
1677 ADD_DSDB_STRING(DSDB_CONTROL_REPLMD_VANISH_LINKS);
1678 ADD_DSDB_STRING(DSDB_CONTROL_PERMIT_INTERDOMAIN_TRUST_UAC_OID);
1679 ADD_DSDB_STRING(DSDB_CONTROL_SKIP_DUPLICATES_CHECK_OID);
1680 ADD_DSDB_STRING(DSDB_CONTROL_BYPASS_PASSWORD_HASH_OID);
1681 ADD_DSDB_STRING(DSDB_CONTROL_INVALID_NOT_IMPLEMENTED);
1683 ADD_DSDB_STRING(DS_GUID_COMPUTERS_CONTAINER);
1684 ADD_DSDB_STRING(DS_GUID_DELETED_OBJECTS_CONTAINER);
1685 ADD_DSDB_STRING(DS_GUID_DOMAIN_CONTROLLERS_CONTAINER);
1686 ADD_DSDB_STRING(DS_GUID_FOREIGNSECURITYPRINCIPALS_CONTAINER);
1687 ADD_DSDB_STRING(DS_GUID_INFRASTRUCTURE_CONTAINER);
1688 ADD_DSDB_STRING(DS_GUID_LOSTANDFOUND_CONTAINER);
1689 ADD_DSDB_STRING(DS_GUID_MICROSOFT_PROGRAM_DATA_CONTAINER);
1690 ADD_DSDB_STRING(DS_GUID_NTDS_QUOTAS_CONTAINER);
1691 ADD_DSDB_STRING(DS_GUID_PROGRAM_DATA_CONTAINER);
1692 ADD_DSDB_STRING(DS_GUID_SYSTEMS_CONTAINER);
1693 ADD_DSDB_STRING(DS_GUID_USERS_CONTAINER);