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"
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"); \
44 ldb = pyldb_Ldb_AsLdbContext(py_ldb);
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"); \
51 dn = pyldb_Dn_AsDn(py_ldb_dn);
53 static PyObject *py_ldb_get_exception(void)
55 PyObject *mod = PyImport_ImportModule("ldb");
59 return PyObject_GetAttrString(mod, "LdbError");
62 static void PyErr_SetLdbError(PyObject *error, int ret, struct ldb_context *ldb_ctx)
64 if (ret == LDB_ERR_PYTHON_EXCEPTION)
65 return; /* Python exception should already be set, just keep that */
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)));
72 static PyObject *py_samdb_server_site_name(PyObject *self, PyObject *args)
74 PyObject *py_ldb, *result;
75 struct ldb_context *ldb;
79 if (!PyArg_ParseTuple(args, "O", &py_ldb))
82 PyErr_LDB_OR_RAISE(py_ldb, ldb);
84 mem_ctx = talloc_new(NULL);
85 if (mem_ctx == NULL) {
90 site = samdb_server_site_name(ldb, mem_ctx);
92 PyErr_SetString(PyExc_RuntimeError, "Failed to find server site");
97 result = PyStr_FromString(site);
102 static PyObject *py_dsdb_convert_schema_to_openldap(PyObject *self,
105 char *target_str, *mapping;
107 struct ldb_context *ldb;
111 if (!PyArg_ParseTuple(args, "Oss", &py_ldb, &target_str, &mapping))
114 PyErr_LDB_OR_RAISE(py_ldb, ldb);
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");
123 ret = PyStr_FromString(retstr);
128 static PyObject *py_samdb_set_domain_sid(PyLdbObject *self, PyObject *args)
130 PyObject *py_ldb, *py_sid;
131 struct ldb_context *ldb;
135 if (!PyArg_ParseTuple(args, "OO", &py_ldb, &py_sid))
138 PyErr_LDB_OR_RAISE(py_ldb, ldb);
140 sid = dom_sid_parse_talloc(NULL, PyStr_AsString(py_sid));
146 ret = samdb_set_domain_sid(ldb, sid);
149 PyErr_SetString(PyExc_RuntimeError, "set_domain_sid failed");
155 static PyObject *py_samdb_set_ntds_settings_dn(PyLdbObject *self, PyObject *args)
157 PyObject *py_ldb, *py_ntds_settings_dn;
158 struct ldb_context *ldb;
159 struct ldb_dn *ntds_settings_dn;
163 if (!PyArg_ParseTuple(args, "OO", &py_ldb, &py_ntds_settings_dn))
166 PyErr_LDB_OR_RAISE(py_ldb, ldb);
168 tmp_ctx = talloc_new(NULL);
169 if (tmp_ctx == NULL) {
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);
180 ret = samdb_set_ntds_settings_dn(ldb, ntds_settings_dn);
181 talloc_free(tmp_ctx);
183 PyErr_SetString(PyExc_RuntimeError, "set_ntds_settings_dn failed");
189 static PyObject *py_samdb_get_domain_sid(PyLdbObject *self, PyObject *args)
192 struct ldb_context *ldb;
193 const struct dom_sid *sid;
194 struct dom_sid_buf buf;
197 if (!PyArg_ParseTuple(args, "O", &py_ldb))
200 PyErr_LDB_OR_RAISE(py_ldb, ldb);
202 sid = samdb_domain_sid(ldb);
204 PyErr_SetString(PyExc_RuntimeError, "samdb_domain_sid failed");
208 ret = PyStr_FromString(dom_sid_str_buf(sid, &buf));
212 static PyObject *py_samdb_ntds_invocation_id(PyObject *self, PyObject *args)
214 PyObject *py_ldb, *result;
215 struct ldb_context *ldb;
216 const struct GUID *guid;
219 if (!PyArg_ParseTuple(args, "O", &py_ldb)) {
223 PyErr_LDB_OR_RAISE(py_ldb, ldb);
225 guid = samdb_ntds_invocation_id(ldb);
227 PyErr_SetString(PyExc_RuntimeError,
228 "Failed to find NTDS invocation ID");
232 retstr = GUID_string(NULL, guid);
233 if (retstr == NULL) {
237 result = PyStr_FromString(retstr);
242 static PyObject *py_dsdb_get_oid_from_attid(PyObject *self, PyObject *args)
245 struct ldb_context *ldb;
247 struct dsdb_schema *schema;
253 if (!PyArg_ParseTuple(args, "OI", &py_ldb, &attid))
256 PyErr_LDB_OR_RAISE(py_ldb, ldb);
258 mem_ctx = talloc_new(NULL);
264 schema = dsdb_get_schema(ldb, mem_ctx);
266 PyErr_SetString(PyExc_RuntimeError, "Failed to find a schema from ldb \n");
267 talloc_free(mem_ctx);
271 status = dsdb_schema_pfm_oid_from_attid(schema->prefixmap, attid,
273 if (!W_ERROR_IS_OK(status)) {
274 PyErr_SetWERROR(status);
275 talloc_free(mem_ctx);
279 ret = PyStr_FromString(oid);
281 talloc_free(mem_ctx);
287 static PyObject *py_dsdb_get_attid_from_lDAPDisplayName(PyObject *self, PyObject *args)
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;
297 if (!PyArg_ParseTuple(args, "OsO", &py_ldb, &ldap_display_name, &is_schema_nc))
300 PyErr_LDB_OR_RAISE(py_ldb, ldb);
303 if (!PyBool_Check(is_schema_nc)) {
304 PyErr_SetString(PyExc_TypeError, "Expected boolean is_schema_nc");
307 if (is_schema_nc == Py_True) {
312 schema = dsdb_get_schema(ldb, NULL);
315 PyErr_SetString(PyExc_RuntimeError, "Failed to find a schema from ldb");
319 a = dsdb_attribute_by_lDAPDisplayName(schema, ldap_display_name);
321 PyErr_Format(PyExc_KeyError, "Failed to find attribute '%s'", ldap_display_name);
325 attid = dsdb_attribute_get_attid(a, schema_nc);
327 return PyLong_FromUnsignedLong(attid);
331 return the systemFlags as int from the attribute name
333 static PyObject *py_dsdb_get_systemFlags_from_lDAPDisplayName(PyObject *self, PyObject *args)
336 struct ldb_context *ldb;
337 struct dsdb_schema *schema;
338 const char *ldap_display_name;
339 const struct dsdb_attribute *attribute;
341 if (!PyArg_ParseTuple(args, "Os", &py_ldb, &ldap_display_name))
344 PyErr_LDB_OR_RAISE(py_ldb, ldb);
346 schema = dsdb_get_schema(ldb, NULL);
349 PyErr_SetString(PyExc_RuntimeError, "Failed to find a schema from ldb");
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);
359 return PyInt_FromLong(attribute->systemFlags);
363 return the linkID from the attribute name
365 static PyObject *py_dsdb_get_linkId_from_lDAPDisplayName(PyObject *self, PyObject *args)
368 struct ldb_context *ldb;
369 struct dsdb_schema *schema;
370 const char *ldap_display_name;
371 const struct dsdb_attribute *attribute;
373 if (!PyArg_ParseTuple(args, "Os", &py_ldb, &ldap_display_name))
376 PyErr_LDB_OR_RAISE(py_ldb, ldb);
378 schema = dsdb_get_schema(ldb, NULL);
381 PyErr_SetString(PyExc_RuntimeError, "Failed to find a schema from ldb");
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);
391 return PyInt_FromLong(attribute->linkID);
395 return the backlink attribute name (if any) for an attribute
397 static PyObject *py_dsdb_get_backlink_from_lDAPDisplayName(PyObject *self, PyObject *args)
400 struct ldb_context *ldb;
401 struct dsdb_schema *schema;
402 const char *ldap_display_name;
403 const struct dsdb_attribute *attribute, *target_attr;
405 if (!PyArg_ParseTuple(args, "Os", &py_ldb, &ldap_display_name))
408 PyErr_LDB_OR_RAISE(py_ldb, ldb);
410 schema = dsdb_get_schema(ldb, NULL);
413 PyErr_SetString(PyExc_RuntimeError, "Failed to find a schema from ldb");
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);
423 if (attribute->linkID == 0) {
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
434 return PyStr_FromString(target_attr->lDAPDisplayName);
438 static PyObject *py_dsdb_get_lDAPDisplayName_by_attid(PyObject *self, PyObject *args)
441 struct ldb_context *ldb;
442 struct dsdb_schema *schema;
443 const struct dsdb_attribute *a;
446 if (!PyArg_ParseTuple(args, "OI", &py_ldb, &attid))
449 PyErr_LDB_OR_RAISE(py_ldb, ldb);
451 schema = dsdb_get_schema(ldb, NULL);
454 PyErr_SetString(PyExc_RuntimeError, "Failed to find a schema from ldb");
458 a = dsdb_attribute_by_attributeID_id(schema, attid);
460 PyErr_Format(PyExc_KeyError, "Failed to find attribute '0x%08x'", attid);
464 return PyStr_FromString(a->lDAPDisplayName);
469 return the attribute syntax oid as a string from the attribute name
471 static PyObject *py_dsdb_get_syntax_oid_from_lDAPDisplayName(PyObject *self, PyObject *args)
474 struct ldb_context *ldb;
475 struct dsdb_schema *schema;
476 const char *ldap_display_name;
477 const struct dsdb_attribute *attribute;
479 if (!PyArg_ParseTuple(args, "Os", &py_ldb, &ldap_display_name))
482 PyErr_LDB_OR_RAISE(py_ldb, ldb);
484 schema = dsdb_get_schema(ldb, NULL);
487 PyErr_SetString(PyExc_RuntimeError, "Failed to find a schema from ldb");
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);
497 return PyStr_FromString(attribute->syntax->ldap_oid);
501 convert a python string to a DRSUAPI drsuapi_DsReplicaAttribute attribute
503 static PyObject *py_dsdb_DsReplicaAttribute(PyObject *self, PyObject *args)
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;
517 if (!PyArg_ParseTuple(args, "OsO", &py_ldb, &ldap_display_name, &el_list)) {
521 PyErr_LDB_OR_RAISE(py_ldb, ldb);
523 schema = dsdb_get_schema(ldb, NULL);
525 PyErr_SetString(PyExc_RuntimeError, "Failed to find a schema from ldb");
529 a = dsdb_attribute_by_lDAPDisplayName(schema, ldap_display_name);
531 PyErr_Format(PyExc_KeyError, "Failed to find attribute '%s'", ldap_display_name);
535 dsdb_syntax_ctx_init(&syntax_ctx, ldb, schema);
536 syntax_ctx.is_schema_nc = false;
538 tmp_ctx = talloc_new(ldb);
539 if (tmp_ctx == NULL) {
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");
553 * el may not be a valid talloc context, it
554 * could be part of an array
556 el = pyldb_MessageElement_AsMessageElement(el_list);
558 el = talloc_zero(tmp_ctx, struct ldb_message_element);
561 talloc_free(tmp_ctx);
565 el->name = ldap_display_name;
566 el->num_values = PyList_Size(el_list);
568 el->values = talloc_array(el, struct ldb_val, el->num_values);
569 if (el->values == NULL) {
571 talloc_free(tmp_ctx);
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 "
582 talloc_free(tmp_ctx);
586 (uint8_t *)PyBytes_AsString(item);
587 el->values[i].length = PyBytes_Size(item);
591 attr = talloc_zero(tmp_ctx, struct drsuapi_DsReplicaAttribute);
594 talloc_free(tmp_ctx);
598 werr = a->syntax->ldb_to_drsuapi(&syntax_ctx, a, el, attr, attr);
599 PyErr_WERROR_NOT_OK_RAISE(werr);
601 ret = py_return_ndr_struct("samba.dcerpc.drsuapi", "DsReplicaAttribute", attr, attr);
603 talloc_free(tmp_ctx);
610 normalise a ldb attribute list
612 static PyObject *py_dsdb_normalise_attributes(PyObject *self, PyObject *args)
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;
626 PyTypeObject *py_type = NULL;
627 PyObject *module = NULL;
629 if (!PyArg_ParseTuple(args, "OsO", &py_ldb, &ldap_display_name, &el_list)) {
633 PyErr_LDB_OR_RAISE(py_ldb, ldb);
635 schema = dsdb_get_schema(ldb, NULL);
637 PyErr_SetString(PyExc_RuntimeError, "Failed to find a schema from ldb");
641 a = dsdb_attribute_by_lDAPDisplayName(schema, ldap_display_name);
643 PyErr_Format(PyExc_KeyError, "Failed to find attribute '%s'", ldap_display_name);
647 dsdb_syntax_ctx_init(&syntax_ctx, ldb, schema);
648 syntax_ctx.is_schema_nc = false;
650 tmp_ctx = talloc_new(ldb);
651 if (tmp_ctx == NULL) {
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");
664 * el may not be a valid talloc context, it
665 * could be part of an array
667 el = pyldb_MessageElement_AsMessageElement(el_list);
669 el = talloc_zero(tmp_ctx, struct ldb_message_element);
672 talloc_free(tmp_ctx);
676 el->name = ldap_display_name;
677 el->num_values = PyList_Size(el_list);
679 el->values = talloc_array(el, struct ldb_val, el->num_values);
680 if (el->values == NULL) {
682 talloc_free(tmp_ctx);
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 "
693 talloc_free(tmp_ctx);
696 el->values[i].data = (uint8_t *)PyBytes_AsString(item);
697 el->values[i].length = PyBytes_Size(item);
701 new_el = talloc_zero(tmp_ctx, struct ldb_message_element);
702 if (new_el == NULL) {
704 talloc_free(tmp_ctx);
708 /* Normalise "objectClass" attribute if needed */
709 if (ldb_attr_cmp(a->lDAPDisplayName, "objectClass") == 0) {
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);
719 /* first run ldb_to_drsuapi, then convert back again. This has
720 * the effect of normalising the attributes
723 attr = talloc_zero(tmp_ctx, struct drsuapi_DsReplicaAttribute);
726 talloc_free(tmp_ctx);
730 werr = a->syntax->ldb_to_drsuapi(&syntax_ctx, a, el, attr, attr);
731 PyErr_WERROR_NOT_OK_RAISE(werr);
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);
737 module = PyImport_ImportModule("ldb");
738 if (module == NULL) {
742 py_type = (PyTypeObject *)PyObject_GetAttrString(module, "MessageElement");
743 if (py_type == NULL) {
746 py_ret = py_type->tp_alloc(py_type, 0);
747 if (py_ret == NULL) {
752 ret = (PyLdbMessageElementObject *)py_ret;
754 ret->mem_ctx = talloc_new(NULL);
755 if (talloc_reference(ret->mem_ctx, new_el) == NULL) {
763 talloc_free(tmp_ctx);
769 static PyObject *py_dsdb_set_ntds_invocation_id(PyObject *self, PyObject *args)
771 PyObject *py_ldb, *py_guid;
774 struct ldb_context *ldb;
775 if (!PyArg_ParseTuple(args, "OO", &py_ldb, &py_guid))
778 PyErr_LDB_OR_RAISE(py_ldb, ldb);
779 GUID_from_string(PyStr_AsString(py_guid), &guid);
781 if (GUID_all_zero(&guid)) {
782 PyErr_SetString(PyExc_RuntimeError, "set_ntds_invocation_id rejected due to all-zero invocation ID");
786 ret = samdb_set_ntds_invocation_id(ldb, &guid);
788 PyErr_SetString(PyExc_RuntimeError, "set_ntds_invocation_id failed");
794 static PyObject *py_samdb_ntds_objectGUID(PyObject *self, PyObject *args)
796 PyObject *py_ldb, *result;
797 struct ldb_context *ldb;
798 const struct GUID *guid;
801 if (!PyArg_ParseTuple(args, "O", &py_ldb)) {
805 PyErr_LDB_OR_RAISE(py_ldb, ldb);
807 guid = samdb_ntds_objectGUID(ldb);
809 PyErr_SetString(PyExc_RuntimeError, "Failed to find NTDS GUID");
813 retstr = GUID_string(NULL, guid);
814 if (retstr == NULL) {
818 result = PyStr_FromString(retstr);
823 static PyObject *py_dsdb_set_global_schema(PyObject *self, PyObject *args)
826 struct ldb_context *ldb;
828 if (!PyArg_ParseTuple(args, "O", &py_ldb))
831 PyErr_LDB_OR_RAISE(py_ldb, ldb);
833 ret = dsdb_set_global_schema(ldb);
834 PyErr_LDB_ERROR_IS_ERR_RAISE(py_ldb_get_exception(), ret, ldb);
839 static PyObject *py_dsdb_load_partition_usn(PyObject *self, PyObject *args)
841 PyObject *py_dn, *py_ldb, *result;
843 uint64_t highest_uSN, urgent_uSN;
844 struct ldb_context *ldb;
848 if (!PyArg_ParseTuple(args, "OO", &py_ldb, &py_dn)) {
852 PyErr_LDB_OR_RAISE(py_ldb, ldb);
854 mem_ctx = talloc_new(NULL);
855 if (mem_ctx == NULL) {
860 if (!pyldb_Object_AsDn(mem_ctx, py_dn, ldb, &dn)) {
861 talloc_free(mem_ctx);
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),
871 talloc_free(mem_ctx);
875 talloc_free(mem_ctx);
877 result = PyDict_New();
879 PyDict_SetItemString(result, "uSNHighest", PyInt_FromLong((uint64_t)highest_uSN));
880 PyDict_SetItemString(result, "uSNUrgent", PyInt_FromLong((uint64_t)urgent_uSN));
886 static PyObject *py_dsdb_set_am_rodc(PyObject *self, PyObject *args)
890 struct ldb_context *ldb;
893 if (!PyArg_ParseTuple(args, "Oi", &py_ldb, &py_val))
896 PyErr_LDB_OR_RAISE(py_ldb, ldb);
897 ret = samdb_set_am_rodc(ldb, (bool)py_val);
899 PyErr_SetString(PyExc_RuntimeError, "set_am_rodc failed");
905 static PyObject *py_dsdb_set_schema_from_ldif(PyObject *self, PyObject *args)
910 struct ldb_context *ldb;
912 if (!PyArg_ParseTuple(args, "Osss", &py_ldb, &pf, &df, &dn))
915 PyErr_LDB_OR_RAISE(py_ldb, ldb);
917 result = dsdb_set_schema_from_ldif(ldb, pf, df, dn);
918 PyErr_WERROR_NOT_OK_RAISE(result);
923 static PyObject *py_dsdb_set_schema_from_ldb(PyObject *self, PyObject *args)
926 struct ldb_context *ldb;
927 PyObject *py_from_ldb;
928 struct ldb_context *from_ldb;
929 struct dsdb_schema *schema;
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))
936 PyErr_LDB_OR_RAISE(py_ldb, ldb);
938 PyErr_LDB_OR_RAISE(py_from_ldb, from_ldb);
940 schema = dsdb_get_schema(from_ldb, NULL);
942 PyErr_SetString(PyExc_RuntimeError, "Failed to set find a schema on 'from' ldb!\n");
946 ret = dsdb_reference_schema(ldb, schema, write_indices_and_attributes);
947 PyErr_LDB_ERROR_IS_ERR_RAISE(py_ldb_get_exception(), ret, ldb);
952 static PyObject *py_dsdb_write_prefixes_from_schema_to_ldb(PyObject *self, PyObject *args)
955 struct ldb_context *ldb;
957 struct dsdb_schema *schema;
959 if (!PyArg_ParseTuple(args, "O", &py_ldb))
962 PyErr_LDB_OR_RAISE(py_ldb, ldb);
964 schema = dsdb_get_schema(ldb, NULL);
966 PyErr_SetString(PyExc_RuntimeError, "Failed to set find a schema on ldb!\n");
970 result = dsdb_write_prefixes_from_schema_to_ldb(NULL, ldb, schema);
971 PyErr_WERROR_NOT_OK_RAISE(result);
977 static PyObject *py_dsdb_get_partitions_dn(PyObject *self, PyObject *args)
979 struct ldb_context *ldb;
981 PyObject *py_ldb, *ret;
983 if (!PyArg_ParseTuple(args, "O", &py_ldb))
986 PyErr_LDB_OR_RAISE(py_ldb, ldb);
988 dn = samdb_partitions_dn(ldb, NULL);
993 ret = pyldb_Dn_FromDn(dn);
999 static PyObject *py_dsdb_get_nc_root(PyObject *self, PyObject *args)
1001 struct ldb_context *ldb;
1002 struct ldb_dn *dn, *nc_root;
1003 PyObject *py_ldb, *py_ldb_dn, *py_nc_root;
1006 if (!PyArg_ParseTuple(args, "OO", &py_ldb, &py_ldb_dn))
1009 PyErr_LDB_OR_RAISE(py_ldb, ldb);
1010 PyErr_LDB_DN_OR_RAISE(py_ldb_dn, dn);
1012 ret = dsdb_find_nc_root(ldb, ldb, dn, &nc_root);
1013 PyErr_LDB_ERROR_IS_ERR_RAISE(py_ldb_get_exception(), ret, ldb);
1015 py_nc_root = pyldb_Dn_FromDn(nc_root);
1016 talloc_unlink(ldb, nc_root);
1020 static PyObject *py_dsdb_get_wellknown_dn(PyObject *self, PyObject *args)
1022 struct ldb_context *ldb;
1023 struct ldb_dn *nc_dn, *wk_dn;
1025 PyObject *py_ldb, *py_nc_dn, *py_wk_dn;
1028 if (!PyArg_ParseTuple(args, "OOs", &py_ldb, &py_nc_dn, &wkguid))
1031 PyErr_LDB_OR_RAISE(py_ldb, ldb);
1032 PyErr_LDB_DN_OR_RAISE(py_nc_dn, nc_dn);
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);
1040 PyErr_LDB_ERROR_IS_ERR_RAISE(py_ldb_get_exception(), ret, ldb);
1042 py_wk_dn = pyldb_Dn_FromDn(wk_dn);
1043 talloc_unlink(ldb, wk_dn);
1049 call into samdb_rodc()
1051 static PyObject *py_dsdb_am_rodc(PyObject *self, PyObject *args)
1054 struct ldb_context *ldb;
1058 if (!PyArg_ParseTuple(args, "O", &py_ldb))
1061 PyErr_LDB_OR_RAISE(py_ldb, ldb);
1063 ret = samdb_rodc(ldb, &am_rodc);
1064 if (ret != LDB_SUCCESS) {
1065 PyErr_SetString(PyExc_RuntimeError, ldb_errstring(ldb));
1069 return PyBool_FromLong(am_rodc);
1073 call into samdb_is_pdc()
1075 static PyObject *py_dsdb_am_pdc(PyObject *self, PyObject *args)
1078 struct ldb_context *ldb;
1081 if (!PyArg_ParseTuple(args, "O", &py_ldb))
1084 PyErr_LDB_OR_RAISE(py_ldb, ldb);
1086 am_pdc = samdb_is_pdc(ldb);
1087 return PyBool_FromLong(am_pdc);
1091 call DSDB_EXTENDED_CREATE_OWN_RID_SET to get a new RID set for this server
1093 static PyObject *py_dsdb_create_own_rid_set(PyObject *self, PyObject *args)
1096 struct ldb_context *ldb;
1098 struct ldb_result *ext_res;
1100 if (!PyArg_ParseTuple(args, "O", &py_ldb))
1103 PyErr_LDB_OR_RAISE(py_ldb, ldb);
1106 * Run DSDB_EXTENDED_CREATE_OWN_RID_SET to get a RID set
1109 ret = ldb_extended(ldb, DSDB_EXTENDED_CREATE_OWN_RID_SET, NULL, &ext_res);
1111 PyErr_LDB_ERROR_IS_ERR_RAISE(py_ldb_get_exception(), ret, ldb);
1113 TALLOC_FREE(ext_res);
1119 call DSDB_EXTENDED_ALLOCATE_RID to get a new RID set for this server
1121 static PyObject *py_dsdb_allocate_rid(PyObject *self, PyObject *args)
1124 struct ldb_context *ldb;
1127 struct ldb_result *ext_res = NULL;
1128 struct dsdb_extended_allocate_rid *rid_return = NULL;
1129 if (!PyArg_ParseTuple(args, "O", &py_ldb)) {
1133 PyErr_LDB_OR_RAISE(py_ldb, ldb);
1135 rid_return = talloc_zero(ldb, struct dsdb_extended_allocate_rid);
1136 if (rid_return == NULL) {
1137 return PyErr_NoMemory();
1141 * Run DSDB_EXTENDED_ALLOCATE_RID to get a new RID
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);
1151 rid = rid_return->rid;
1152 TALLOC_FREE(rid_return);
1153 TALLOC_FREE(ext_res);
1155 return PyInt_FromLong(rid);
1158 static PyObject *py_dns_delete_tombstones(PyObject *self, PyObject *args)
1162 struct ldb_context *ldb = NULL;
1163 TALLOC_CTX *mem_ctx = NULL;
1164 char *error_string = NULL;
1166 if (!PyArg_ParseTuple(args, "O", &py_ldb)) {
1169 PyErr_LDB_OR_RAISE(py_ldb, ldb);
1171 mem_ctx = talloc_new(ldb);
1172 if (mem_ctx == NULL) {
1173 return PyErr_NoMemory();
1176 status = dns_delete_tombstones(mem_ctx, ldb, &error_string);
1178 if (!NT_STATUS_IS_OK(status)) {
1180 PyErr_Format(PyExc_RuntimeError, "%s", error_string);
1182 PyErr_SetNTSTATUS(status);
1184 TALLOC_FREE(mem_ctx);
1188 TALLOC_FREE(mem_ctx);
1192 static PyObject *py_scavenge_dns_records(PyObject *self, PyObject *args)
1196 struct ldb_context *ldb = NULL;
1197 TALLOC_CTX *mem_ctx = NULL;
1198 char *error_string = NULL;
1200 if (!PyArg_ParseTuple(args, "O", &py_ldb)) {
1203 PyErr_LDB_OR_RAISE(py_ldb, ldb);
1205 mem_ctx = talloc_new(ldb);
1206 if (mem_ctx == NULL) {
1207 return PyErr_NoMemory();
1210 status = dns_tombstone_records(mem_ctx, ldb, &error_string);
1212 if (!NT_STATUS_IS_OK(status)) {
1214 PyErr_Format(PyExc_RuntimeError, "%s", error_string);
1216 PyErr_SetNTSTATUS(status);
1218 TALLOC_FREE(mem_ctx);
1222 TALLOC_FREE(mem_ctx);
1226 static PyObject *py_dsdb_garbage_collect_tombstones(PyObject *self, PyObject *args)
1228 PyObject *py_ldb, *py_list_dn;
1229 struct ldb_context *ldb = NULL;
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;
1238 unsigned int num_objects_removed = 0;
1239 unsigned int num_links_removed = 0;
1240 char *error_string = NULL;
1242 if (!PyArg_ParseTuple(args, "OOL|L", &py_ldb,
1243 &py_list_dn, &_current_time, &_tombstone_lifetime)) {
1248 PyErr_LDB_OR_RAISE(py_ldb, ldb);
1250 mem_ctx = talloc_new(ldb);
1251 if (mem_ctx == NULL) {
1252 return PyErr_NoMemory();
1255 current_time = _current_time;
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);
1266 tombstone_lifetime = tombstone_lifetime32;
1268 tombstone_lifetime = _tombstone_lifetime;
1271 if (!PyList_Check(py_list_dn)) {
1272 PyErr_SetString(PyExc_TypeError, "A list of DNs were expected");
1273 TALLOC_FREE(mem_ctx);
1277 length = PyList_GET_SIZE(py_list_dn);
1279 for (i = 0; i < length; i++) {
1280 const char *part_str = PyStr_AsString(PyList_GetItem(py_list_dn, i));
1282 struct dsdb_ldb_dn_list_node *node;
1284 if (part_str == NULL) {
1285 TALLOC_FREE(mem_ctx);
1286 return PyErr_NoMemory();
1289 p = ldb_dn_new(mem_ctx, ldb, part_str);
1291 PyErr_Format(PyExc_RuntimeError, "Failed to parse DN %s", part_str);
1292 TALLOC_FREE(mem_ctx);
1295 node = talloc_zero(mem_ctx, struct dsdb_ldb_dn_list_node);
1298 DLIST_ADD_END(part, node);
1301 status = dsdb_garbage_collect_tombstones(mem_ctx, ldb,
1304 &num_objects_removed,
1308 if (!NT_STATUS_IS_OK(status)) {
1310 PyErr_Format(PyExc_RuntimeError, "%s", error_string);
1312 PyErr_SetNTSTATUS(status);
1314 TALLOC_FREE(mem_ctx);
1318 TALLOC_FREE(mem_ctx);
1320 return Py_BuildValue("(II)", num_objects_removed,
1324 static PyObject *py_dsdb_load_udv_v2(PyObject *self, PyObject *args)
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;
1335 if (!PyArg_ParseTuple(args, "OO", &py_ldb, &py_dn)) {
1339 PyErr_LDB_OR_RAISE(py_ldb, samdb);
1341 tmp_ctx = talloc_new(samdb);
1342 if (tmp_ctx == NULL) {
1343 return PyErr_NoMemory();
1346 ok = pyldb_Object_AsDn(tmp_ctx, py_dn, samdb, &dn);
1348 TALLOC_FREE(tmp_ctx);
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");
1360 pylist = PyList_New(count);
1361 if (pylist == NULL) {
1362 TALLOC_FREE(tmp_ctx);
1363 return PyErr_NoMemory();
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();
1374 *cursor = cursors[i];
1376 py_cursor = py_return_ndr_struct("samba.dcerpc.drsuapi",
1379 if (py_cursor == NULL) {
1380 TALLOC_FREE(tmp_ctx);
1381 return PyErr_NoMemory();
1384 PyList_SetItem(pylist, i, py_cursor);
1387 TALLOC_FREE(tmp_ctx);
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,
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,
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,
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,
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,
1435 "get uSNHighest and uSNUrgent from the partition @REPLCHANGED"},
1436 { "_dsdb_set_am_rodc",
1437 (PyCFunction)py_dsdb_set_am_rodc, METH_VARARGS,
1440 (PyCFunction)py_dsdb_am_rodc, METH_VARARGS,
1443 (PyCFunction)py_dsdb_am_pdc, METH_VARARGS,
1445 { "_dsdb_set_schema_from_ldif", (PyCFunction)py_dsdb_set_schema_from_ldif, METH_VARARGS,
1447 { "_dsdb_set_schema_from_ldb", (PyCFunction)py_dsdb_set_schema_from_ldb, METH_VARARGS,
1449 { "_dsdb_write_prefixes_from_schema_to_ldb", (PyCFunction)py_dsdb_write_prefixes_from_schema_to_ldb, METH_VARARGS,
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)"
1466 { "_dsdb_allocate_rid", (PyCFunction)py_dsdb_allocate_rid, METH_VARARGS,
1467 "_dsdb_allocate_rid(samdb)"
1469 { "_dsdb_load_udv_v2", (PyCFunction)py_dsdb_load_udv_v2, METH_VARARGS, NULL },
1473 static struct PyModuleDef moduledef = {
1474 PyModuleDef_HEAD_INIT,
1476 .m_doc = "Python bindings for the directory service databases.",
1478 .m_methods = py_dsdb_methods,
1481 MODULE_INIT_FUNC(dsdb)
1485 m = PyModule_Create(&moduledef);
1490 #define ADD_DSDB_FLAG(val) PyModule_AddObject(m, #val, PyInt_FromLong(val))
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
1654 #define ADD_DSDB_STRING(val) PyModule_AddObject(m, #val, PyStr_FromString(val))
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);
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);