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_AS_LDBCONTEXT(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_AS_DN(py_ldb_dn);
53 static PyObject *py_ldb_get_exception(void)
55 PyObject *mod = PyImport_ImportModule("ldb");
56 PyObject *result = NULL;
60 result = PyObject_GetAttrString(mod, "LdbError");
65 static void PyErr_SetLdbError(PyObject *error, int ret, struct ldb_context *ldb_ctx)
67 if (ret == LDB_ERR_PYTHON_EXCEPTION)
68 return; /* Python exception should already be set, just keep that */
70 PyErr_SetObject(error,
71 Py_BuildValue(discard_const_p(char, "(i,s)"), ret,
72 ldb_ctx == NULL?ldb_strerror(ret):ldb_errstring(ldb_ctx)));
75 static PyObject *py_samdb_server_site_name(PyObject *self, PyObject *args)
77 PyObject *py_ldb, *result;
78 struct ldb_context *ldb;
82 if (!PyArg_ParseTuple(args, "O", &py_ldb))
85 PyErr_LDB_OR_RAISE(py_ldb, ldb);
87 mem_ctx = talloc_new(NULL);
88 if (mem_ctx == NULL) {
93 site = samdb_server_site_name(ldb, mem_ctx);
95 PyErr_SetString(PyExc_RuntimeError, "Failed to find server site");
100 result = PyUnicode_FromString(site);
101 talloc_free(mem_ctx);
105 static PyObject *py_dsdb_convert_schema_to_openldap(PyObject *self,
108 char *target_str, *mapping;
110 struct ldb_context *ldb;
114 if (!PyArg_ParseTuple(args, "Oss", &py_ldb, &target_str, &mapping))
117 PyErr_LDB_OR_RAISE(py_ldb, ldb);
119 retstr = dsdb_convert_schema_to_openldap(ldb, target_str, mapping);
120 if (retstr == NULL) {
121 PyErr_SetString(PyExc_RuntimeError,
122 "dsdb_convert_schema_to_openldap failed");
126 ret = PyUnicode_FromString(retstr);
131 static PyObject *py_samdb_set_domain_sid(PyLdbObject *self, PyObject *args)
133 PyObject *py_ldb, *py_sid;
134 struct ldb_context *ldb;
137 const char *sid_str = NULL;
139 if (!PyArg_ParseTuple(args, "OO", &py_ldb, &py_sid))
142 PyErr_LDB_OR_RAISE(py_ldb, ldb);
144 sid_str = PyUnicode_AsUTF8(py_sid);
145 if (sid_str == NULL) {
150 sid = dom_sid_parse_talloc(NULL, sid_str);
156 ret = samdb_set_domain_sid(ldb, sid);
159 PyErr_SetString(PyExc_RuntimeError, "set_domain_sid failed");
165 static PyObject *py_samdb_set_ntds_settings_dn(PyLdbObject *self, PyObject *args)
167 PyObject *py_ldb, *py_ntds_settings_dn;
168 struct ldb_context *ldb;
169 struct ldb_dn *ntds_settings_dn;
173 if (!PyArg_ParseTuple(args, "OO", &py_ldb, &py_ntds_settings_dn))
176 PyErr_LDB_OR_RAISE(py_ldb, ldb);
178 tmp_ctx = talloc_new(NULL);
179 if (tmp_ctx == NULL) {
184 if (!pyldb_Object_AsDn(tmp_ctx, py_ntds_settings_dn, ldb, &ntds_settings_dn)) {
185 /* exception thrown by "pyldb_Object_AsDn" */
186 talloc_free(tmp_ctx);
190 ret = samdb_set_ntds_settings_dn(ldb, ntds_settings_dn);
191 talloc_free(tmp_ctx);
193 PyErr_SetString(PyExc_RuntimeError, "set_ntds_settings_dn failed");
199 static PyObject *py_samdb_get_domain_sid(PyLdbObject *self, PyObject *args)
202 struct ldb_context *ldb;
203 const struct dom_sid *sid;
204 struct dom_sid_buf buf;
207 if (!PyArg_ParseTuple(args, "O", &py_ldb))
210 PyErr_LDB_OR_RAISE(py_ldb, ldb);
212 sid = samdb_domain_sid(ldb);
214 PyErr_SetString(PyExc_RuntimeError, "samdb_domain_sid failed");
218 ret = PyUnicode_FromString(dom_sid_str_buf(sid, &buf));
222 static PyObject *py_samdb_ntds_invocation_id(PyObject *self, PyObject *args)
224 PyObject *py_ldb, *result;
225 struct ldb_context *ldb;
226 const struct GUID *guid;
229 if (!PyArg_ParseTuple(args, "O", &py_ldb)) {
233 PyErr_LDB_OR_RAISE(py_ldb, ldb);
235 guid = samdb_ntds_invocation_id(ldb);
237 PyErr_SetString(PyExc_RuntimeError,
238 "Failed to find NTDS invocation ID");
242 retstr = GUID_string(NULL, guid);
243 if (retstr == NULL) {
247 result = PyUnicode_FromString(retstr);
252 static PyObject *py_dsdb_get_oid_from_attid(PyObject *self, PyObject *args)
255 struct ldb_context *ldb;
257 struct dsdb_schema *schema;
263 if (!PyArg_ParseTuple(args, "OI", &py_ldb, &attid))
266 PyErr_LDB_OR_RAISE(py_ldb, ldb);
268 mem_ctx = talloc_new(NULL);
274 schema = dsdb_get_schema(ldb, mem_ctx);
276 PyErr_SetString(PyExc_RuntimeError, "Failed to find a schema from ldb \n");
277 talloc_free(mem_ctx);
281 status = dsdb_schema_pfm_oid_from_attid(schema->prefixmap, attid,
283 if (!W_ERROR_IS_OK(status)) {
284 PyErr_SetWERROR(status);
285 talloc_free(mem_ctx);
289 ret = PyUnicode_FromString(oid);
291 talloc_free(mem_ctx);
297 static PyObject *py_dsdb_get_attid_from_lDAPDisplayName(PyObject *self, PyObject *args)
299 PyObject *py_ldb, *is_schema_nc;
300 struct ldb_context *ldb;
301 struct dsdb_schema *schema;
302 const char *ldap_display_name;
303 bool schema_nc = false;
304 const struct dsdb_attribute *a;
307 if (!PyArg_ParseTuple(args, "OsO", &py_ldb, &ldap_display_name, &is_schema_nc))
310 PyErr_LDB_OR_RAISE(py_ldb, ldb);
313 if (!PyBool_Check(is_schema_nc)) {
314 PyErr_SetString(PyExc_TypeError, "Expected boolean is_schema_nc");
317 if (is_schema_nc == Py_True) {
322 schema = dsdb_get_schema(ldb, NULL);
325 PyErr_SetString(PyExc_RuntimeError, "Failed to find a schema from ldb");
329 a = dsdb_attribute_by_lDAPDisplayName(schema, ldap_display_name);
331 PyErr_Format(PyExc_KeyError, "Failed to find attribute '%s'", ldap_display_name);
335 attid = dsdb_attribute_get_attid(a, schema_nc);
337 return PyLong_FromUnsignedLong(attid);
341 return the systemFlags as int from the attribute name
343 static PyObject *py_dsdb_get_systemFlags_from_lDAPDisplayName(PyObject *self, PyObject *args)
346 struct ldb_context *ldb;
347 struct dsdb_schema *schema;
348 const char *ldap_display_name;
349 const struct dsdb_attribute *attribute;
351 if (!PyArg_ParseTuple(args, "Os", &py_ldb, &ldap_display_name))
354 PyErr_LDB_OR_RAISE(py_ldb, ldb);
356 schema = dsdb_get_schema(ldb, NULL);
359 PyErr_SetString(PyExc_RuntimeError, "Failed to find a schema from ldb");
363 attribute = dsdb_attribute_by_lDAPDisplayName(schema, ldap_display_name);
364 if (attribute == NULL) {
365 PyErr_Format(PyExc_KeyError, "Failed to find attribute '%s'", ldap_display_name);
369 return PyLong_FromLong(attribute->systemFlags);
373 return the linkID from the attribute name
375 static PyObject *py_dsdb_get_linkId_from_lDAPDisplayName(PyObject *self, PyObject *args)
378 struct ldb_context *ldb;
379 struct dsdb_schema *schema;
380 const char *ldap_display_name;
381 const struct dsdb_attribute *attribute;
383 if (!PyArg_ParseTuple(args, "Os", &py_ldb, &ldap_display_name))
386 PyErr_LDB_OR_RAISE(py_ldb, ldb);
388 schema = dsdb_get_schema(ldb, NULL);
391 PyErr_SetString(PyExc_RuntimeError, "Failed to find a schema from ldb");
395 attribute = dsdb_attribute_by_lDAPDisplayName(schema, ldap_display_name);
396 if (attribute == NULL) {
397 PyErr_Format(PyExc_KeyError, "Failed to find attribute '%s'", ldap_display_name);
401 return PyLong_FromLong(attribute->linkID);
405 return the backlink attribute name (if any) for an attribute
407 static PyObject *py_dsdb_get_backlink_from_lDAPDisplayName(PyObject *self, PyObject *args)
410 struct ldb_context *ldb;
411 struct dsdb_schema *schema;
412 const char *ldap_display_name;
413 const struct dsdb_attribute *attribute, *target_attr;
415 if (!PyArg_ParseTuple(args, "Os", &py_ldb, &ldap_display_name))
418 PyErr_LDB_OR_RAISE(py_ldb, ldb);
420 schema = dsdb_get_schema(ldb, NULL);
423 PyErr_SetString(PyExc_RuntimeError, "Failed to find a schema from ldb");
427 attribute = dsdb_attribute_by_lDAPDisplayName(schema, ldap_display_name);
428 if (attribute == NULL) {
429 PyErr_Format(PyExc_KeyError, "Failed to find attribute '%s'", ldap_display_name);
433 if (attribute->linkID == 0) {
437 target_attr = dsdb_attribute_by_linkID(schema, attribute->linkID ^ 1);
438 if (target_attr == NULL) {
439 /* when we add pseudo-backlinks we'll need to handle
444 return PyUnicode_FromString(target_attr->lDAPDisplayName);
448 static PyObject *py_dsdb_get_lDAPDisplayName_by_attid(PyObject *self, PyObject *args)
451 struct ldb_context *ldb;
452 struct dsdb_schema *schema;
453 const struct dsdb_attribute *a;
456 if (!PyArg_ParseTuple(args, "OI", &py_ldb, &attid))
459 PyErr_LDB_OR_RAISE(py_ldb, ldb);
461 schema = dsdb_get_schema(ldb, NULL);
464 PyErr_SetString(PyExc_RuntimeError, "Failed to find a schema from ldb");
468 a = dsdb_attribute_by_attributeID_id(schema, attid);
470 PyErr_Format(PyExc_KeyError, "Failed to find attribute '0x%08x'", attid);
474 return PyUnicode_FromString(a->lDAPDisplayName);
479 return the attribute syntax oid as a string from the attribute name
481 static PyObject *py_dsdb_get_syntax_oid_from_lDAPDisplayName(PyObject *self, PyObject *args)
484 struct ldb_context *ldb;
485 struct dsdb_schema *schema;
486 const char *ldap_display_name;
487 const struct dsdb_attribute *attribute;
489 if (!PyArg_ParseTuple(args, "Os", &py_ldb, &ldap_display_name))
492 PyErr_LDB_OR_RAISE(py_ldb, ldb);
494 schema = dsdb_get_schema(ldb, NULL);
497 PyErr_SetString(PyExc_RuntimeError, "Failed to find a schema from ldb");
501 attribute = dsdb_attribute_by_lDAPDisplayName(schema, ldap_display_name);
502 if (attribute == NULL) {
503 PyErr_Format(PyExc_KeyError, "Failed to find attribute '%s'", ldap_display_name);
507 return PyUnicode_FromString(attribute->syntax->ldap_oid);
511 convert a python string to a DRSUAPI drsuapi_DsReplicaAttribute attribute
513 static PyObject *py_dsdb_DsReplicaAttribute(PyObject *self, PyObject *args)
515 PyObject *py_ldb, *el_list, *ret;
516 struct ldb_context *ldb;
517 char *ldap_display_name;
518 const struct dsdb_attribute *a;
519 struct dsdb_schema *schema;
520 struct dsdb_syntax_ctx syntax_ctx;
521 struct ldb_message_element *el;
522 struct drsuapi_DsReplicaAttribute *attr;
527 if (!PyArg_ParseTuple(args, "OsO", &py_ldb, &ldap_display_name, &el_list)) {
531 PyErr_LDB_OR_RAISE(py_ldb, ldb);
533 schema = dsdb_get_schema(ldb, NULL);
535 PyErr_SetString(PyExc_RuntimeError, "Failed to find a schema from ldb");
539 a = dsdb_attribute_by_lDAPDisplayName(schema, ldap_display_name);
541 PyErr_Format(PyExc_KeyError, "Failed to find attribute '%s'", ldap_display_name);
545 dsdb_syntax_ctx_init(&syntax_ctx, ldb, schema);
546 syntax_ctx.is_schema_nc = false;
548 tmp_ctx = talloc_new(ldb);
549 if (tmp_ctx == NULL) {
554 /* If we were not given an LdbMessageElement */
555 if (!PyList_Check(el_list)) {
556 if (!py_check_dcerpc_type(el_list, "ldb", "MessageElement")) {
557 PyErr_SetString(py_ldb_get_exception(),
558 "list of strings or ldb MessageElement object required");
563 * el may not be a valid talloc context, it
564 * could be part of an array
566 el = pyldb_MessageElement_AsMessageElement(el_list);
568 el = talloc_zero(tmp_ctx, struct ldb_message_element);
571 talloc_free(tmp_ctx);
575 el->name = ldap_display_name;
576 el->num_values = PyList_Size(el_list);
578 el->values = talloc_array(el, struct ldb_val, el->num_values);
579 if (el->values == NULL) {
581 talloc_free(tmp_ctx);
585 for (i = 0; i < el->num_values; i++) {
586 PyObject *item = PyList_GetItem(el_list, i);
587 if (!(PyBytes_Check(item))) {
588 PyErr_Format(PyExc_TypeError,
589 "ldif_element type should be "
592 talloc_free(tmp_ctx);
596 (uint8_t *)PyBytes_AsString(item);
597 el->values[i].length = PyBytes_Size(item);
601 attr = talloc_zero(tmp_ctx, struct drsuapi_DsReplicaAttribute);
604 talloc_free(tmp_ctx);
608 werr = a->syntax->ldb_to_drsuapi(&syntax_ctx, a, el, attr, attr);
609 PyErr_WERROR_NOT_OK_RAISE(werr);
611 ret = py_return_ndr_struct("samba.dcerpc.drsuapi", "DsReplicaAttribute", attr, attr);
613 talloc_free(tmp_ctx);
620 normalise a ldb attribute list
622 static PyObject *py_dsdb_normalise_attributes(PyObject *self, PyObject *args)
624 PyObject *py_ldb, *el_list, *py_ret;
625 struct ldb_context *ldb;
626 char *ldap_display_name;
627 const struct dsdb_attribute *a;
628 struct dsdb_schema *schema;
629 struct dsdb_syntax_ctx syntax_ctx;
630 struct ldb_message_element *el, *new_el;
631 struct drsuapi_DsReplicaAttribute *attr;
632 PyLdbMessageElementObject *ret;
636 PyTypeObject *py_type = NULL;
637 PyObject *module = NULL;
639 if (!PyArg_ParseTuple(args, "OsO", &py_ldb, &ldap_display_name, &el_list)) {
643 PyErr_LDB_OR_RAISE(py_ldb, ldb);
645 schema = dsdb_get_schema(ldb, NULL);
647 PyErr_SetString(PyExc_RuntimeError, "Failed to find a schema from ldb");
651 a = dsdb_attribute_by_lDAPDisplayName(schema, ldap_display_name);
653 PyErr_Format(PyExc_KeyError, "Failed to find attribute '%s'", ldap_display_name);
657 dsdb_syntax_ctx_init(&syntax_ctx, ldb, schema);
658 syntax_ctx.is_schema_nc = false;
660 tmp_ctx = talloc_new(ldb);
661 if (tmp_ctx == NULL) {
666 if (!PyList_Check(el_list)) {
667 if (!py_check_dcerpc_type(el_list, "ldb", "MessageElement")) {
668 PyErr_SetString(py_ldb_get_exception(),
669 "list of strings or ldb MessageElement object required");
674 * el may not be a valid talloc context, it
675 * could be part of an array
677 el = pyldb_MessageElement_AsMessageElement(el_list);
679 el = talloc_zero(tmp_ctx, struct ldb_message_element);
682 talloc_free(tmp_ctx);
686 el->name = ldap_display_name;
687 el->num_values = PyList_Size(el_list);
689 el->values = talloc_array(el, struct ldb_val, el->num_values);
690 if (el->values == NULL) {
692 talloc_free(tmp_ctx);
696 for (i = 0; i < el->num_values; i++) {
697 PyObject *item = PyList_GetItem(el_list, i);
698 if (!PyBytes_Check(item)) {
699 PyErr_Format(PyExc_TypeError,
700 "ldif_element type should be "
703 talloc_free(tmp_ctx);
706 el->values[i].data = (uint8_t *)PyBytes_AsString(item);
707 el->values[i].length = PyBytes_Size(item);
711 new_el = talloc_zero(tmp_ctx, struct ldb_message_element);
712 if (new_el == NULL) {
714 talloc_free(tmp_ctx);
718 /* Normalise "objectClass" attribute if needed */
719 if (ldb_attr_cmp(a->lDAPDisplayName, "objectClass") == 0) {
721 iret = dsdb_sort_objectClass_attr(ldb, schema, el, new_el, new_el);
722 if (iret != LDB_SUCCESS) {
723 PyErr_SetString(PyExc_RuntimeError, ldb_errstring(ldb));
724 talloc_free(tmp_ctx);
729 /* first run ldb_to_drsuapi, then convert back again. This has
730 * the effect of normalising the attributes
733 attr = talloc_zero(tmp_ctx, struct drsuapi_DsReplicaAttribute);
736 talloc_free(tmp_ctx);
740 werr = a->syntax->ldb_to_drsuapi(&syntax_ctx, a, el, attr, attr);
741 PyErr_WERROR_NOT_OK_RAISE(werr);
743 /* now convert back again */
744 werr = a->syntax->drsuapi_to_ldb(&syntax_ctx, a, attr, new_el, new_el);
745 PyErr_WERROR_NOT_OK_RAISE(werr);
747 module = PyImport_ImportModule("ldb");
748 if (module == NULL) {
752 py_type = (PyTypeObject *)PyObject_GetAttrString(module, "MessageElement");
753 if (py_type == NULL) {
760 py_ret = py_type->tp_alloc(py_type, 0);
762 if (py_ret == NULL) {
766 ret = (PyLdbMessageElementObject *)py_ret;
768 ret->mem_ctx = talloc_new(NULL);
769 if (talloc_reference(ret->mem_ctx, new_el) == NULL) {
776 talloc_free(tmp_ctx);
782 static PyObject *py_dsdb_set_ntds_invocation_id(PyObject *self, PyObject *args)
784 PyObject *py_ldb, *py_guid;
787 struct ldb_context *ldb;
788 if (!PyArg_ParseTuple(args, "OO", &py_ldb, &py_guid))
791 PyErr_LDB_OR_RAISE(py_ldb, ldb);
792 GUID_from_string(PyUnicode_AsUTF8(py_guid), &guid);
794 if (GUID_all_zero(&guid)) {
795 PyErr_SetString(PyExc_RuntimeError, "set_ntds_invocation_id rejected due to all-zero invocation ID");
799 ret = samdb_set_ntds_invocation_id(ldb, &guid);
801 PyErr_SetString(PyExc_RuntimeError, "set_ntds_invocation_id failed");
807 static PyObject *py_samdb_ntds_objectGUID(PyObject *self, PyObject *args)
809 PyObject *py_ldb, *result;
810 struct ldb_context *ldb;
811 const struct GUID *guid;
814 if (!PyArg_ParseTuple(args, "O", &py_ldb)) {
818 PyErr_LDB_OR_RAISE(py_ldb, ldb);
820 guid = samdb_ntds_objectGUID(ldb);
822 PyErr_SetString(PyExc_RuntimeError, "Failed to find NTDS GUID");
826 retstr = GUID_string(NULL, guid);
827 if (retstr == NULL) {
831 result = PyUnicode_FromString(retstr);
836 static PyObject *py_dsdb_set_global_schema(PyObject *self, PyObject *args)
839 struct ldb_context *ldb;
841 if (!PyArg_ParseTuple(args, "O", &py_ldb))
844 PyErr_LDB_OR_RAISE(py_ldb, ldb);
846 ret = dsdb_set_global_schema(ldb);
847 PyErr_LDB_ERROR_IS_ERR_RAISE(py_ldb_get_exception(), ret, ldb);
852 static PyObject *py_dsdb_load_partition_usn(PyObject *self, PyObject *args)
854 PyObject *py_dn, *py_ldb, *result;
856 uint64_t highest_uSN, urgent_uSN;
857 struct ldb_context *ldb;
861 if (!PyArg_ParseTuple(args, "OO", &py_ldb, &py_dn)) {
865 PyErr_LDB_OR_RAISE(py_ldb, ldb);
867 mem_ctx = talloc_new(NULL);
868 if (mem_ctx == NULL) {
873 if (!pyldb_Object_AsDn(mem_ctx, py_dn, ldb, &dn)) {
874 talloc_free(mem_ctx);
878 ret = dsdb_load_partition_usn(ldb, dn, &highest_uSN, &urgent_uSN);
879 if (ret != LDB_SUCCESS) {
880 PyErr_Format(PyExc_RuntimeError,
881 "Failed to load partition [%s] uSN - %s",
882 ldb_dn_get_linearized(dn),
884 talloc_free(mem_ctx);
888 talloc_free(mem_ctx);
890 result = Py_BuildValue(
892 "uSNHighest", (uint64_t)highest_uSN,
893 "uSNUrgent", (uint64_t)urgent_uSN);
898 static PyObject *py_dsdb_set_am_rodc(PyObject *self, PyObject *args)
902 struct ldb_context *ldb;
905 if (!PyArg_ParseTuple(args, "Oi", &py_ldb, &py_val))
908 PyErr_LDB_OR_RAISE(py_ldb, ldb);
909 ret = samdb_set_am_rodc(ldb, (bool)py_val);
911 PyErr_SetString(PyExc_RuntimeError, "set_am_rodc failed");
917 static PyObject *py_dsdb_set_schema_from_ldif(PyObject *self, PyObject *args)
922 struct ldb_context *ldb;
924 if (!PyArg_ParseTuple(args, "Osss", &py_ldb, &pf, &df, &dn))
927 PyErr_LDB_OR_RAISE(py_ldb, ldb);
929 result = dsdb_set_schema_from_ldif(ldb, pf, df, dn);
930 PyErr_WERROR_NOT_OK_RAISE(result);
935 static PyObject *py_dsdb_set_schema_from_ldb(PyObject *self, PyObject *args)
938 struct ldb_context *ldb;
939 PyObject *py_from_ldb;
940 struct ldb_context *from_ldb;
941 struct dsdb_schema *schema;
943 char write_indices_and_attributes = SCHEMA_WRITE;
944 if (!PyArg_ParseTuple(args, "OO|b",
945 &py_ldb, &py_from_ldb, &write_indices_and_attributes))
948 PyErr_LDB_OR_RAISE(py_ldb, ldb);
950 PyErr_LDB_OR_RAISE(py_from_ldb, from_ldb);
952 schema = dsdb_get_schema(from_ldb, NULL);
954 PyErr_SetString(PyExc_RuntimeError, "Failed to set find a schema on 'from' ldb!\n");
958 ret = dsdb_reference_schema(ldb, schema, write_indices_and_attributes);
959 PyErr_LDB_ERROR_IS_ERR_RAISE(py_ldb_get_exception(), ret, ldb);
964 static PyObject *py_dsdb_write_prefixes_from_schema_to_ldb(PyObject *self, PyObject *args)
967 struct ldb_context *ldb;
969 struct dsdb_schema *schema;
971 if (!PyArg_ParseTuple(args, "O", &py_ldb))
974 PyErr_LDB_OR_RAISE(py_ldb, ldb);
976 schema = dsdb_get_schema(ldb, NULL);
978 PyErr_SetString(PyExc_RuntimeError, "Failed to set find a schema on ldb!\n");
982 result = dsdb_write_prefixes_from_schema_to_ldb(NULL, ldb, schema);
983 PyErr_WERROR_NOT_OK_RAISE(result);
989 static PyObject *py_dsdb_get_partitions_dn(PyObject *self, PyObject *args)
991 struct ldb_context *ldb;
993 PyObject *py_ldb, *ret;
995 if (!PyArg_ParseTuple(args, "O", &py_ldb))
998 PyErr_LDB_OR_RAISE(py_ldb, ldb);
1000 dn = samdb_partitions_dn(ldb, NULL);
1005 ret = pyldb_Dn_FromDn(dn);
1011 static PyObject *py_dsdb_get_nc_root(PyObject *self, PyObject *args)
1013 struct ldb_context *ldb;
1014 struct ldb_dn *dn, *nc_root;
1015 PyObject *py_ldb, *py_ldb_dn, *py_nc_root;
1018 if (!PyArg_ParseTuple(args, "OO", &py_ldb, &py_ldb_dn))
1021 PyErr_LDB_OR_RAISE(py_ldb, ldb);
1022 PyErr_LDB_DN_OR_RAISE(py_ldb_dn, dn);
1024 ret = dsdb_find_nc_root(ldb, ldb, dn, &nc_root);
1025 PyErr_LDB_ERROR_IS_ERR_RAISE(py_ldb_get_exception(), ret, ldb);
1027 py_nc_root = pyldb_Dn_FromDn(nc_root);
1028 talloc_unlink(ldb, nc_root);
1032 static PyObject *py_dsdb_get_wellknown_dn(PyObject *self, PyObject *args)
1034 struct ldb_context *ldb;
1035 struct ldb_dn *nc_dn, *wk_dn;
1037 PyObject *py_ldb, *py_nc_dn, *py_wk_dn;
1040 if (!PyArg_ParseTuple(args, "OOs", &py_ldb, &py_nc_dn, &wkguid))
1043 PyErr_LDB_OR_RAISE(py_ldb, ldb);
1044 PyErr_LDB_DN_OR_RAISE(py_nc_dn, nc_dn);
1046 ret = dsdb_wellknown_dn(ldb, ldb, nc_dn, wkguid, &wk_dn);
1047 if (ret == LDB_ERR_NO_SUCH_OBJECT) {
1048 PyErr_Format(PyExc_KeyError, "Failed to find well known DN for GUID %s", wkguid);
1052 PyErr_LDB_ERROR_IS_ERR_RAISE(py_ldb_get_exception(), ret, ldb);
1054 py_wk_dn = pyldb_Dn_FromDn(wk_dn);
1055 talloc_unlink(ldb, wk_dn);
1061 call into samdb_rodc()
1063 static PyObject *py_dsdb_am_rodc(PyObject *self, PyObject *args)
1066 struct ldb_context *ldb;
1070 if (!PyArg_ParseTuple(args, "O", &py_ldb))
1073 PyErr_LDB_OR_RAISE(py_ldb, ldb);
1075 ret = samdb_rodc(ldb, &am_rodc);
1076 if (ret != LDB_SUCCESS) {
1077 PyErr_SetString(PyExc_RuntimeError, ldb_errstring(ldb));
1081 return PyBool_FromLong(am_rodc);
1085 call into samdb_is_pdc()
1087 static PyObject *py_dsdb_am_pdc(PyObject *self, PyObject *args)
1090 struct ldb_context *ldb;
1093 if (!PyArg_ParseTuple(args, "O", &py_ldb))
1096 PyErr_LDB_OR_RAISE(py_ldb, ldb);
1098 am_pdc = samdb_is_pdc(ldb);
1099 return PyBool_FromLong(am_pdc);
1103 call DSDB_EXTENDED_CREATE_OWN_RID_SET to get a new RID set for this server
1105 static PyObject *py_dsdb_create_own_rid_set(PyObject *self, PyObject *args)
1108 struct ldb_context *ldb;
1110 struct ldb_result *ext_res;
1112 if (!PyArg_ParseTuple(args, "O", &py_ldb))
1115 PyErr_LDB_OR_RAISE(py_ldb, ldb);
1118 * Run DSDB_EXTENDED_CREATE_OWN_RID_SET to get a RID set
1121 ret = ldb_extended(ldb, DSDB_EXTENDED_CREATE_OWN_RID_SET, NULL, &ext_res);
1123 PyErr_LDB_ERROR_IS_ERR_RAISE(py_ldb_get_exception(), ret, ldb);
1125 TALLOC_FREE(ext_res);
1131 call DSDB_EXTENDED_ALLOCATE_RID to get a new RID set for this server
1133 static PyObject *py_dsdb_allocate_rid(PyObject *self, PyObject *args)
1136 struct ldb_context *ldb;
1139 struct ldb_result *ext_res = NULL;
1140 struct dsdb_extended_allocate_rid *rid_return = NULL;
1141 if (!PyArg_ParseTuple(args, "O", &py_ldb)) {
1145 PyErr_LDB_OR_RAISE(py_ldb, ldb);
1147 rid_return = talloc_zero(ldb, struct dsdb_extended_allocate_rid);
1148 if (rid_return == NULL) {
1149 return PyErr_NoMemory();
1153 * Run DSDB_EXTENDED_ALLOCATE_RID to get a new RID
1156 ret = ldb_extended(ldb, DSDB_EXTENDED_ALLOCATE_RID, rid_return, &ext_res);
1157 if (ret != LDB_SUCCESS) {
1158 TALLOC_FREE(rid_return);
1159 TALLOC_FREE(ext_res);
1160 PyErr_LDB_ERROR_IS_ERR_RAISE(py_ldb_get_exception(), ret, ldb);
1163 rid = rid_return->rid;
1164 TALLOC_FREE(rid_return);
1165 TALLOC_FREE(ext_res);
1167 return PyLong_FromLong(rid);
1170 static PyObject *py_dns_delete_tombstones(PyObject *self, PyObject *args)
1174 struct ldb_context *ldb = NULL;
1175 TALLOC_CTX *mem_ctx = NULL;
1176 char *error_string = NULL;
1178 if (!PyArg_ParseTuple(args, "O", &py_ldb)) {
1181 PyErr_LDB_OR_RAISE(py_ldb, ldb);
1183 mem_ctx = talloc_new(ldb);
1184 if (mem_ctx == NULL) {
1185 return PyErr_NoMemory();
1188 status = dns_delete_tombstones(mem_ctx, ldb, &error_string);
1190 if (!NT_STATUS_IS_OK(status)) {
1192 PyErr_Format(PyExc_RuntimeError, "%s", error_string);
1194 PyErr_SetNTSTATUS(status);
1196 TALLOC_FREE(mem_ctx);
1200 TALLOC_FREE(mem_ctx);
1204 static PyObject *py_scavenge_dns_records(PyObject *self, PyObject *args)
1208 struct ldb_context *ldb = NULL;
1209 TALLOC_CTX *mem_ctx = NULL;
1210 char *error_string = NULL;
1212 if (!PyArg_ParseTuple(args, "O", &py_ldb)) {
1215 PyErr_LDB_OR_RAISE(py_ldb, ldb);
1217 mem_ctx = talloc_new(ldb);
1218 if (mem_ctx == NULL) {
1219 return PyErr_NoMemory();
1222 status = dns_tombstone_records(mem_ctx, ldb, &error_string);
1224 if (!NT_STATUS_IS_OK(status)) {
1226 PyErr_Format(PyExc_RuntimeError, "%s", error_string);
1228 PyErr_SetNTSTATUS(status);
1230 TALLOC_FREE(mem_ctx);
1234 TALLOC_FREE(mem_ctx);
1238 static PyObject *py_dsdb_garbage_collect_tombstones(PyObject *self, PyObject *args)
1240 PyObject *py_ldb, *py_list_dn;
1241 struct ldb_context *ldb = NULL;
1244 long long _current_time, _tombstone_lifetime = LLONG_MAX;
1245 uint32_t tombstone_lifetime32;
1246 struct dsdb_ldb_dn_list_node *part = NULL;
1247 time_t current_time, tombstone_lifetime;
1248 TALLOC_CTX *mem_ctx = NULL;
1250 unsigned int num_objects_removed = 0;
1251 unsigned int num_links_removed = 0;
1252 char *error_string = NULL;
1254 if (!PyArg_ParseTuple(args, "OOL|L", &py_ldb,
1255 &py_list_dn, &_current_time, &_tombstone_lifetime)) {
1260 PyErr_LDB_OR_RAISE(py_ldb, ldb);
1262 mem_ctx = talloc_new(ldb);
1263 if (mem_ctx == NULL) {
1264 return PyErr_NoMemory();
1267 current_time = _current_time;
1269 if (_tombstone_lifetime == LLONG_MAX) {
1270 int ret = dsdb_tombstone_lifetime(ldb, &tombstone_lifetime32);
1271 if (ret != LDB_SUCCESS) {
1272 PyErr_Format(PyExc_RuntimeError,
1273 "Failed to get tombstone lifetime: %s",
1274 ldb_errstring(ldb));
1275 TALLOC_FREE(mem_ctx);
1278 tombstone_lifetime = tombstone_lifetime32;
1280 tombstone_lifetime = _tombstone_lifetime;
1283 if (!PyList_Check(py_list_dn)) {
1284 PyErr_SetString(PyExc_TypeError, "A list of DNs were expected");
1285 TALLOC_FREE(mem_ctx);
1289 length = PyList_GET_SIZE(py_list_dn);
1291 for (i = 0; i < length; i++) {
1292 const char *part_str = PyUnicode_AsUTF8(PyList_GetItem(py_list_dn, i));
1294 struct dsdb_ldb_dn_list_node *node;
1296 if (part_str == NULL) {
1297 TALLOC_FREE(mem_ctx);
1298 return PyErr_NoMemory();
1301 p = ldb_dn_new(mem_ctx, ldb, part_str);
1303 PyErr_Format(PyExc_RuntimeError, "Failed to parse DN %s", part_str);
1304 TALLOC_FREE(mem_ctx);
1307 node = talloc_zero(mem_ctx, struct dsdb_ldb_dn_list_node);
1310 DLIST_ADD_END(part, node);
1313 status = dsdb_garbage_collect_tombstones(mem_ctx, ldb,
1316 &num_objects_removed,
1320 if (!NT_STATUS_IS_OK(status)) {
1322 PyErr_Format(PyExc_RuntimeError, "%s", error_string);
1324 PyErr_SetNTSTATUS(status);
1326 TALLOC_FREE(mem_ctx);
1330 TALLOC_FREE(mem_ctx);
1332 return Py_BuildValue("(II)", num_objects_removed,
1336 static PyObject *py_dsdb_load_udv_v2(PyObject *self, PyObject *args)
1341 PyObject *py_ldb = NULL, *py_dn = NULL, *pylist = NULL;
1342 struct ldb_context *samdb = NULL;
1343 struct ldb_dn *dn = NULL;
1344 struct drsuapi_DsReplicaCursor2 *cursors = NULL;
1345 TALLOC_CTX *tmp_ctx = NULL;
1347 if (!PyArg_ParseTuple(args, "OO", &py_ldb, &py_dn)) {
1351 PyErr_LDB_OR_RAISE(py_ldb, samdb);
1353 tmp_ctx = talloc_new(samdb);
1354 if (tmp_ctx == NULL) {
1355 return PyErr_NoMemory();
1358 ok = pyldb_Object_AsDn(tmp_ctx, py_dn, samdb, &dn);
1360 TALLOC_FREE(tmp_ctx);
1364 ret = dsdb_load_udv_v2(samdb, dn, tmp_ctx, &cursors, &count);
1365 if (ret != LDB_SUCCESS) {
1366 TALLOC_FREE(tmp_ctx);
1367 PyErr_SetString(PyExc_RuntimeError,
1368 "Failed to load udv from ldb");
1372 pylist = PyList_New(count);
1373 if (pylist == NULL) {
1374 TALLOC_FREE(tmp_ctx);
1375 return PyErr_NoMemory();
1378 for (i = 0; i < count; i++) {
1379 PyObject *py_cursor;
1380 struct drsuapi_DsReplicaCursor2 *cursor;
1381 cursor = talloc(tmp_ctx, struct drsuapi_DsReplicaCursor2);
1382 if (cursor == NULL) {
1383 TALLOC_FREE(tmp_ctx);
1384 return PyErr_NoMemory();
1386 *cursor = cursors[i];
1388 py_cursor = py_return_ndr_struct("samba.dcerpc.drsuapi",
1391 if (py_cursor == NULL) {
1392 TALLOC_FREE(tmp_ctx);
1393 return PyErr_NoMemory();
1396 PyList_SetItem(pylist, i, py_cursor);
1399 TALLOC_FREE(tmp_ctx);
1403 static PyMethodDef py_dsdb_methods[] = {
1404 { "_samdb_server_site_name", (PyCFunction)py_samdb_server_site_name,
1405 METH_VARARGS, "Get the server site name as a string"},
1406 { "_dsdb_convert_schema_to_openldap",
1407 (PyCFunction)py_dsdb_convert_schema_to_openldap, METH_VARARGS,
1408 "dsdb_convert_schema_to_openldap(ldb, target_str, mapping) -> str\n"
1409 "Create an OpenLDAP schema from a schema." },
1410 { "_samdb_set_domain_sid", (PyCFunction)py_samdb_set_domain_sid,
1412 "samdb_set_domain_sid(samdb, sid)\n"
1413 "Set SID of domain to use." },
1414 { "_samdb_get_domain_sid", (PyCFunction)py_samdb_get_domain_sid,
1416 "samdb_get_domain_sid(samdb)\n"
1417 "Get SID of domain in use." },
1418 { "_samdb_ntds_invocation_id", (PyCFunction)py_samdb_ntds_invocation_id,
1419 METH_VARARGS, "get the NTDS invocation ID GUID as a string"},
1420 { "_samdb_set_ntds_settings_dn", (PyCFunction)py_samdb_set_ntds_settings_dn,
1422 "samdb_set_ntds_settings_dn(samdb, ntds_settings_dn)\n"
1423 "Set NTDS Settings DN for this LDB (allows it to be set before the DB fully exists)." },
1424 { "_dsdb_get_oid_from_attid", (PyCFunction)py_dsdb_get_oid_from_attid,
1425 METH_VARARGS, NULL },
1426 { "_dsdb_get_attid_from_lDAPDisplayName", (PyCFunction)py_dsdb_get_attid_from_lDAPDisplayName,
1427 METH_VARARGS, NULL },
1428 { "_dsdb_get_syntax_oid_from_lDAPDisplayName", (PyCFunction)py_dsdb_get_syntax_oid_from_lDAPDisplayName,
1429 METH_VARARGS, NULL },
1430 { "_dsdb_get_systemFlags_from_lDAPDisplayName", (PyCFunction)py_dsdb_get_systemFlags_from_lDAPDisplayName,
1431 METH_VARARGS, NULL },
1432 { "_dsdb_get_linkId_from_lDAPDisplayName", (PyCFunction)py_dsdb_get_linkId_from_lDAPDisplayName,
1433 METH_VARARGS, NULL },
1434 { "_dsdb_get_lDAPDisplayName_by_attid", (PyCFunction)py_dsdb_get_lDAPDisplayName_by_attid,
1435 METH_VARARGS, NULL },
1436 { "_dsdb_get_backlink_from_lDAPDisplayName", (PyCFunction)py_dsdb_get_backlink_from_lDAPDisplayName,
1437 METH_VARARGS, NULL },
1438 { "_dsdb_set_ntds_invocation_id",
1439 (PyCFunction)py_dsdb_set_ntds_invocation_id, METH_VARARGS,
1441 { "_samdb_ntds_objectGUID", (PyCFunction)py_samdb_ntds_objectGUID,
1442 METH_VARARGS, "get the NTDS objectGUID as a string"},
1443 { "_dsdb_set_global_schema", (PyCFunction)py_dsdb_set_global_schema,
1444 METH_VARARGS, NULL },
1445 { "_dsdb_load_partition_usn", (PyCFunction)py_dsdb_load_partition_usn,
1447 "get uSNHighest and uSNUrgent from the partition @REPLCHANGED"},
1448 { "_dsdb_set_am_rodc",
1449 (PyCFunction)py_dsdb_set_am_rodc, METH_VARARGS,
1452 (PyCFunction)py_dsdb_am_rodc, METH_VARARGS,
1455 (PyCFunction)py_dsdb_am_pdc, METH_VARARGS,
1457 { "_dsdb_set_schema_from_ldif", (PyCFunction)py_dsdb_set_schema_from_ldif, METH_VARARGS,
1459 { "_dsdb_set_schema_from_ldb", (PyCFunction)py_dsdb_set_schema_from_ldb, METH_VARARGS,
1461 { "_dsdb_write_prefixes_from_schema_to_ldb", (PyCFunction)py_dsdb_write_prefixes_from_schema_to_ldb, METH_VARARGS,
1463 { "_dsdb_get_partitions_dn", (PyCFunction)py_dsdb_get_partitions_dn, METH_VARARGS, NULL },
1464 { "_dsdb_get_nc_root", (PyCFunction)py_dsdb_get_nc_root, METH_VARARGS, NULL },
1465 { "_dsdb_get_wellknown_dn", (PyCFunction)py_dsdb_get_wellknown_dn, METH_VARARGS, NULL },
1466 { "_dsdb_DsReplicaAttribute", (PyCFunction)py_dsdb_DsReplicaAttribute, METH_VARARGS, NULL },
1467 { "_dsdb_normalise_attributes", (PyCFunction)py_dsdb_normalise_attributes, METH_VARARGS, NULL },
1468 { "_dsdb_garbage_collect_tombstones", (PyCFunction)py_dsdb_garbage_collect_tombstones, METH_VARARGS,
1469 "_dsdb_kcc_check_deleted(samdb, [dn], current_time, tombstone_lifetime)"
1470 " -> (num_objects_expunged, num_links_expunged)" },
1471 { "_scavenge_dns_records", (PyCFunction)py_scavenge_dns_records,
1472 METH_VARARGS, NULL},
1473 { "_dns_delete_tombstones", (PyCFunction)py_dns_delete_tombstones,
1474 METH_VARARGS, NULL},
1475 { "_dsdb_create_own_rid_set", (PyCFunction)py_dsdb_create_own_rid_set, METH_VARARGS,
1476 "_dsdb_create_own_rid_set(samdb)"
1478 { "_dsdb_allocate_rid", (PyCFunction)py_dsdb_allocate_rid, METH_VARARGS,
1479 "_dsdb_allocate_rid(samdb)"
1481 { "_dsdb_load_udv_v2", (PyCFunction)py_dsdb_load_udv_v2, METH_VARARGS, NULL },
1485 static struct PyModuleDef moduledef = {
1486 PyModuleDef_HEAD_INIT,
1488 .m_doc = "Python bindings for the directory service databases.",
1490 .m_methods = py_dsdb_methods,
1493 MODULE_INIT_FUNC(dsdb)
1497 m = PyModule_Create(&moduledef);
1502 #define ADD_DSDB_FLAG(val) PyModule_AddObject(m, #val, PyLong_FromLong(val))
1504 /* "userAccountControl" flags */
1505 ADD_DSDB_FLAG(UF_NORMAL_ACCOUNT);
1506 ADD_DSDB_FLAG(UF_TEMP_DUPLICATE_ACCOUNT);
1507 ADD_DSDB_FLAG(UF_SERVER_TRUST_ACCOUNT);
1508 ADD_DSDB_FLAG(UF_WORKSTATION_TRUST_ACCOUNT);
1509 ADD_DSDB_FLAG(UF_INTERDOMAIN_TRUST_ACCOUNT);
1510 ADD_DSDB_FLAG(UF_PASSWD_NOTREQD);
1511 ADD_DSDB_FLAG(UF_ACCOUNTDISABLE);
1513 ADD_DSDB_FLAG(UF_SCRIPT);
1514 ADD_DSDB_FLAG(UF_ACCOUNTDISABLE);
1515 ADD_DSDB_FLAG(UF_00000004);
1516 ADD_DSDB_FLAG(UF_HOMEDIR_REQUIRED);
1517 ADD_DSDB_FLAG(UF_LOCKOUT);
1518 ADD_DSDB_FLAG(UF_PASSWD_NOTREQD);
1519 ADD_DSDB_FLAG(UF_PASSWD_CANT_CHANGE);
1520 ADD_DSDB_FLAG(UF_ENCRYPTED_TEXT_PASSWORD_ALLOWED);
1521 ADD_DSDB_FLAG(UF_TEMP_DUPLICATE_ACCOUNT);
1522 ADD_DSDB_FLAG(UF_NORMAL_ACCOUNT);
1523 ADD_DSDB_FLAG(UF_00000400);
1524 ADD_DSDB_FLAG(UF_INTERDOMAIN_TRUST_ACCOUNT);
1525 ADD_DSDB_FLAG(UF_WORKSTATION_TRUST_ACCOUNT);
1526 ADD_DSDB_FLAG(UF_SERVER_TRUST_ACCOUNT);
1527 ADD_DSDB_FLAG(UF_00004000);
1528 ADD_DSDB_FLAG(UF_00008000);
1529 ADD_DSDB_FLAG(UF_DONT_EXPIRE_PASSWD);
1530 ADD_DSDB_FLAG(UF_MNS_LOGON_ACCOUNT);
1531 ADD_DSDB_FLAG(UF_SMARTCARD_REQUIRED);
1532 ADD_DSDB_FLAG(UF_TRUSTED_FOR_DELEGATION);
1533 ADD_DSDB_FLAG(UF_NOT_DELEGATED);
1534 ADD_DSDB_FLAG(UF_USE_DES_KEY_ONLY);
1535 ADD_DSDB_FLAG(UF_DONT_REQUIRE_PREAUTH);
1536 ADD_DSDB_FLAG(UF_PASSWORD_EXPIRED);
1537 ADD_DSDB_FLAG(UF_TRUSTED_TO_AUTHENTICATE_FOR_DELEGATION);
1538 ADD_DSDB_FLAG(UF_NO_AUTH_DATA_REQUIRED);
1539 ADD_DSDB_FLAG(UF_PARTIAL_SECRETS_ACCOUNT);
1540 ADD_DSDB_FLAG(UF_USE_AES_KEYS);
1542 /* groupType flags */
1543 ADD_DSDB_FLAG(GTYPE_SECURITY_BUILTIN_LOCAL_GROUP);
1544 ADD_DSDB_FLAG(GTYPE_SECURITY_GLOBAL_GROUP);
1545 ADD_DSDB_FLAG(GTYPE_SECURITY_DOMAIN_LOCAL_GROUP);
1546 ADD_DSDB_FLAG(GTYPE_SECURITY_UNIVERSAL_GROUP);
1547 ADD_DSDB_FLAG(GTYPE_DISTRIBUTION_GLOBAL_GROUP);
1548 ADD_DSDB_FLAG(GTYPE_DISTRIBUTION_DOMAIN_LOCAL_GROUP);
1549 ADD_DSDB_FLAG(GTYPE_DISTRIBUTION_UNIVERSAL_GROUP);
1551 /* "sAMAccountType" flags */
1552 ADD_DSDB_FLAG(ATYPE_NORMAL_ACCOUNT);
1553 ADD_DSDB_FLAG(ATYPE_WORKSTATION_TRUST);
1554 ADD_DSDB_FLAG(ATYPE_INTERDOMAIN_TRUST);
1555 ADD_DSDB_FLAG(ATYPE_SECURITY_GLOBAL_GROUP);
1556 ADD_DSDB_FLAG(ATYPE_SECURITY_LOCAL_GROUP);
1557 ADD_DSDB_FLAG(ATYPE_SECURITY_UNIVERSAL_GROUP);
1558 ADD_DSDB_FLAG(ATYPE_DISTRIBUTION_GLOBAL_GROUP);
1559 ADD_DSDB_FLAG(ATYPE_DISTRIBUTION_LOCAL_GROUP);
1560 ADD_DSDB_FLAG(ATYPE_DISTRIBUTION_UNIVERSAL_GROUP);
1562 /* "domainFunctionality", "forestFunctionality" flags in the rootDSE */
1563 ADD_DSDB_FLAG(DS_DOMAIN_FUNCTION_2000);
1564 ADD_DSDB_FLAG(DS_DOMAIN_FUNCTION_2003_MIXED);
1565 ADD_DSDB_FLAG(DS_DOMAIN_FUNCTION_2003);
1566 ADD_DSDB_FLAG(DS_DOMAIN_FUNCTION_2008);
1567 ADD_DSDB_FLAG(DS_DOMAIN_FUNCTION_2008_R2);
1568 ADD_DSDB_FLAG(DS_DOMAIN_FUNCTION_2012);
1569 ADD_DSDB_FLAG(DS_DOMAIN_FUNCTION_2012_R2);
1570 ADD_DSDB_FLAG(DS_DOMAIN_FUNCTION_2016);
1572 /* nc replica flags */
1573 ADD_DSDB_FLAG(INSTANCE_TYPE_IS_NC_HEAD);
1574 ADD_DSDB_FLAG(INSTANCE_TYPE_UNINSTANT);
1575 ADD_DSDB_FLAG(INSTANCE_TYPE_WRITE);
1576 ADD_DSDB_FLAG(INSTANCE_TYPE_NC_ABOVE);
1577 ADD_DSDB_FLAG(INSTANCE_TYPE_NC_COMING);
1578 ADD_DSDB_FLAG(INSTANCE_TYPE_NC_GOING);
1581 ADD_DSDB_FLAG(SYSTEM_FLAG_CR_NTDS_NC);
1582 ADD_DSDB_FLAG(SYSTEM_FLAG_CR_NTDS_DOMAIN);
1583 ADD_DSDB_FLAG(SYSTEM_FLAG_CR_NTDS_NOT_GC_REPLICATED);
1584 ADD_DSDB_FLAG(SYSTEM_FLAG_SCHEMA_BASE_OBJECT);
1585 ADD_DSDB_FLAG(SYSTEM_FLAG_ATTR_IS_RDN);
1586 ADD_DSDB_FLAG(SYSTEM_FLAG_DISALLOW_MOVE_ON_DELETE);
1587 ADD_DSDB_FLAG(SYSTEM_FLAG_DOMAIN_DISALLOW_MOVE);
1588 ADD_DSDB_FLAG(SYSTEM_FLAG_DOMAIN_DISALLOW_RENAME);
1589 ADD_DSDB_FLAG(SYSTEM_FLAG_CONFIG_ALLOW_LIMITED_MOVE);
1590 ADD_DSDB_FLAG(SYSTEM_FLAG_CONFIG_ALLOW_MOVE);
1591 ADD_DSDB_FLAG(SYSTEM_FLAG_CONFIG_ALLOW_RENAME);
1592 ADD_DSDB_FLAG(SYSTEM_FLAG_DISALLOW_DELETE);
1594 /* Kerberos encryption type constants */
1595 ADD_DSDB_FLAG(ENC_ALL_TYPES);
1596 ADD_DSDB_FLAG(ENC_CRC32);
1597 ADD_DSDB_FLAG(ENC_RSA_MD5);
1598 ADD_DSDB_FLAG(ENC_RC4_HMAC_MD5);
1599 ADD_DSDB_FLAG(ENC_HMAC_SHA1_96_AES128);
1600 ADD_DSDB_FLAG(ENC_HMAC_SHA1_96_AES256);
1602 ADD_DSDB_FLAG(SEARCH_FLAG_ATTINDEX);
1603 ADD_DSDB_FLAG(SEARCH_FLAG_PDNTATTINDEX);
1604 ADD_DSDB_FLAG(SEARCH_FLAG_ANR);
1605 ADD_DSDB_FLAG(SEARCH_FLAG_PRESERVEONDELETE);
1606 ADD_DSDB_FLAG(SEARCH_FLAG_COPY);
1607 ADD_DSDB_FLAG(SEARCH_FLAG_TUPLEINDEX);
1608 ADD_DSDB_FLAG(SEARCH_FLAG_SUBTREEATTRINDEX);
1609 ADD_DSDB_FLAG(SEARCH_FLAG_CONFIDENTIAL);
1610 ADD_DSDB_FLAG(SEARCH_FLAG_NEVERVALUEAUDIT);
1611 ADD_DSDB_FLAG(SEARCH_FLAG_RODC_ATTRIBUTE);
1613 ADD_DSDB_FLAG(DS_FLAG_ATTR_NOT_REPLICATED);
1614 ADD_DSDB_FLAG(DS_FLAG_ATTR_REQ_PARTIAL_SET_MEMBER);
1615 ADD_DSDB_FLAG(DS_FLAG_ATTR_IS_CONSTRUCTED);
1617 ADD_DSDB_FLAG(DS_NTDSSETTINGS_OPT_IS_AUTO_TOPOLOGY_DISABLED);
1618 ADD_DSDB_FLAG(DS_NTDSSETTINGS_OPT_IS_TOPL_CLEANUP_DISABLED);
1619 ADD_DSDB_FLAG(DS_NTDSSETTINGS_OPT_IS_TOPL_MIN_HOPS_DISABLED);
1620 ADD_DSDB_FLAG(DS_NTDSSETTINGS_OPT_IS_TOPL_DETECT_STALE_DISABLED);
1621 ADD_DSDB_FLAG(DS_NTDSSETTINGS_OPT_IS_INTER_SITE_AUTO_TOPOLOGY_DISABLED);
1622 ADD_DSDB_FLAG(DS_NTDSSETTINGS_OPT_IS_GROUP_CACHING_ENABLED);
1623 ADD_DSDB_FLAG(DS_NTDSSETTINGS_OPT_FORCE_KCC_WHISTLER_BEHAVIOR);
1624 ADD_DSDB_FLAG(DS_NTDSSETTINGS_OPT_IS_RAND_BH_SELECTION_DISABLED);
1625 ADD_DSDB_FLAG(DS_NTDSSETTINGS_OPT_IS_SCHEDULE_HASHING_ENABLED);
1626 ADD_DSDB_FLAG(DS_NTDSSETTINGS_OPT_IS_REDUNDANT_SERVER_TOPOLOGY_ENABLED);
1628 ADD_DSDB_FLAG(DS_NTDSDSA_OPT_IS_GC);
1629 ADD_DSDB_FLAG(DS_NTDSDSA_OPT_DISABLE_INBOUND_REPL);
1630 ADD_DSDB_FLAG(DS_NTDSDSA_OPT_DISABLE_OUTBOUND_REPL);
1631 ADD_DSDB_FLAG(DS_NTDSDSA_OPT_DISABLE_NTDSCONN_XLATE);
1632 ADD_DSDB_FLAG(DS_NTDSDSA_OPT_DISABLE_SPN_REGISTRATION);
1634 ADD_DSDB_FLAG(NTDSCONN_KCC_GC_TOPOLOGY);
1635 ADD_DSDB_FLAG(NTDSCONN_KCC_RING_TOPOLOGY);
1636 ADD_DSDB_FLAG(NTDSCONN_KCC_MINIMIZE_HOPS_TOPOLOGY);
1637 ADD_DSDB_FLAG(NTDSCONN_KCC_STALE_SERVERS_TOPOLOGY);
1638 ADD_DSDB_FLAG(NTDSCONN_KCC_OSCILLATING_CONNECTION_TOPOLOGY);
1639 ADD_DSDB_FLAG(NTDSCONN_KCC_INTERSITE_GC_TOPOLOGY);
1640 ADD_DSDB_FLAG(NTDSCONN_KCC_INTERSITE_TOPOLOGY);
1641 ADD_DSDB_FLAG(NTDSCONN_KCC_SERVER_FAILOVER_TOPOLOGY);
1642 ADD_DSDB_FLAG(NTDSCONN_KCC_SITE_FAILOVER_TOPOLOGY);
1643 ADD_DSDB_FLAG(NTDSCONN_KCC_REDUNDANT_SERVER_TOPOLOGY);
1645 ADD_DSDB_FLAG(NTDSCONN_OPT_IS_GENERATED);
1646 ADD_DSDB_FLAG(NTDSCONN_OPT_TWOWAY_SYNC);
1647 ADD_DSDB_FLAG(NTDSCONN_OPT_OVERRIDE_NOTIFY_DEFAULT);
1648 ADD_DSDB_FLAG(NTDSCONN_OPT_USE_NOTIFY);
1649 ADD_DSDB_FLAG(NTDSCONN_OPT_DISABLE_INTERSITE_COMPRESSION);
1650 ADD_DSDB_FLAG(NTDSCONN_OPT_USER_OWNED_SCHEDULE);
1651 ADD_DSDB_FLAG(NTDSCONN_OPT_RODC_TOPOLOGY);
1653 /* Site Link Object options */
1654 ADD_DSDB_FLAG(NTDSSITELINK_OPT_USE_NOTIFY);
1655 ADD_DSDB_FLAG(NTDSSITELINK_OPT_TWOWAY_SYNC);
1656 ADD_DSDB_FLAG(NTDSSITELINK_OPT_DISABLE_COMPRESSION);
1658 /* GPO policy flags */
1659 ADD_DSDB_FLAG(GPLINK_OPT_DISABLE);
1660 ADD_DSDB_FLAG(GPLINK_OPT_ENFORCE);
1661 ADD_DSDB_FLAG(GPO_FLAG_USER_DISABLE);
1662 ADD_DSDB_FLAG(GPO_FLAG_MACHINE_DISABLE);
1663 ADD_DSDB_FLAG(GPO_INHERIT);
1664 ADD_DSDB_FLAG(GPO_BLOCK_INHERITANCE);
1666 #define ADD_DSDB_STRING(val) PyModule_AddObject(m, #val, PyUnicode_FromString(val))
1668 ADD_DSDB_STRING(DSDB_SYNTAX_BINARY_DN);
1669 ADD_DSDB_STRING(DSDB_SYNTAX_STRING_DN);
1670 ADD_DSDB_STRING(DSDB_SYNTAX_OR_NAME);
1671 ADD_DSDB_STRING(DSDB_CONTROL_DBCHECK);
1672 ADD_DSDB_STRING(DSDB_CONTROL_DBCHECK_MODIFY_RO_REPLICA);
1673 ADD_DSDB_STRING(DSDB_CONTROL_DBCHECK_FIX_DUPLICATE_LINKS);
1674 ADD_DSDB_STRING(DSDB_CONTROL_DBCHECK_FIX_LINK_DN_NAME);
1675 ADD_DSDB_STRING(DSDB_CONTROL_DBCHECK_FIX_LINK_DN_SID);
1676 ADD_DSDB_STRING(DSDB_CONTROL_REPLMD_VANISH_LINKS);
1677 ADD_DSDB_STRING(DSDB_CONTROL_PERMIT_INTERDOMAIN_TRUST_UAC_OID);
1678 ADD_DSDB_STRING(DSDB_CONTROL_SKIP_DUPLICATES_CHECK_OID);
1679 ADD_DSDB_STRING(DSDB_CONTROL_BYPASS_PASSWORD_HASH_OID);
1680 ADD_DSDB_STRING(DSDB_CONTROL_INVALID_NOT_IMPLEMENTED);
1682 ADD_DSDB_STRING(DS_GUID_COMPUTERS_CONTAINER);
1683 ADD_DSDB_STRING(DS_GUID_DELETED_OBJECTS_CONTAINER);
1684 ADD_DSDB_STRING(DS_GUID_DOMAIN_CONTROLLERS_CONTAINER);
1685 ADD_DSDB_STRING(DS_GUID_FOREIGNSECURITYPRINCIPALS_CONTAINER);
1686 ADD_DSDB_STRING(DS_GUID_INFRASTRUCTURE_CONTAINER);
1687 ADD_DSDB_STRING(DS_GUID_LOSTANDFOUND_CONTAINER);
1688 ADD_DSDB_STRING(DS_GUID_MICROSOFT_PROGRAM_DATA_CONTAINER);
1689 ADD_DSDB_STRING(DS_GUID_NTDS_QUOTAS_CONTAINER);
1690 ADD_DSDB_STRING(DS_GUID_PROGRAM_DATA_CONTAINER);
1691 ADD_DSDB_STRING(DS_GUID_SYSTEMS_CONTAINER);
1692 ADD_DSDB_STRING(DS_GUID_USERS_CONTAINER);