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");
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
= PyStr_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
= PyStr_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
;
138 if (!PyArg_ParseTuple(args
, "OO", &py_ldb
, &py_sid
))
141 PyErr_LDB_OR_RAISE(py_ldb
, ldb
);
143 sid
= dom_sid_parse_talloc(NULL
, PyStr_AsString(py_sid
));
149 ret
= samdb_set_domain_sid(ldb
, sid
);
152 PyErr_SetString(PyExc_RuntimeError
, "set_domain_sid failed");
158 static PyObject
*py_samdb_set_ntds_settings_dn(PyLdbObject
*self
, PyObject
*args
)
160 PyObject
*py_ldb
, *py_ntds_settings_dn
;
161 struct ldb_context
*ldb
;
162 struct ldb_dn
*ntds_settings_dn
;
166 if (!PyArg_ParseTuple(args
, "OO", &py_ldb
, &py_ntds_settings_dn
))
169 PyErr_LDB_OR_RAISE(py_ldb
, ldb
);
171 tmp_ctx
= talloc_new(NULL
);
172 if (tmp_ctx
== NULL
) {
177 if (!pyldb_Object_AsDn(tmp_ctx
, py_ntds_settings_dn
, ldb
, &ntds_settings_dn
)) {
178 /* exception thrown by "pyldb_Object_AsDn" */
179 talloc_free(tmp_ctx
);
183 ret
= samdb_set_ntds_settings_dn(ldb
, ntds_settings_dn
);
184 talloc_free(tmp_ctx
);
186 PyErr_SetString(PyExc_RuntimeError
, "set_ntds_settings_dn failed");
192 static PyObject
*py_samdb_get_domain_sid(PyLdbObject
*self
, PyObject
*args
)
195 struct ldb_context
*ldb
;
196 const struct dom_sid
*sid
;
197 struct dom_sid_buf buf
;
200 if (!PyArg_ParseTuple(args
, "O", &py_ldb
))
203 PyErr_LDB_OR_RAISE(py_ldb
, ldb
);
205 sid
= samdb_domain_sid(ldb
);
207 PyErr_SetString(PyExc_RuntimeError
, "samdb_domain_sid failed");
211 ret
= PyStr_FromString(dom_sid_str_buf(sid
, &buf
));
215 static PyObject
*py_samdb_ntds_invocation_id(PyObject
*self
, PyObject
*args
)
217 PyObject
*py_ldb
, *result
;
218 struct ldb_context
*ldb
;
219 const struct GUID
*guid
;
222 if (!PyArg_ParseTuple(args
, "O", &py_ldb
)) {
226 PyErr_LDB_OR_RAISE(py_ldb
, ldb
);
228 guid
= samdb_ntds_invocation_id(ldb
);
230 PyErr_SetString(PyExc_RuntimeError
,
231 "Failed to find NTDS invocation ID");
235 retstr
= GUID_string(NULL
, guid
);
236 if (retstr
== NULL
) {
240 result
= PyStr_FromString(retstr
);
245 static PyObject
*py_dsdb_get_oid_from_attid(PyObject
*self
, PyObject
*args
)
248 struct ldb_context
*ldb
;
250 struct dsdb_schema
*schema
;
256 if (!PyArg_ParseTuple(args
, "OI", &py_ldb
, &attid
))
259 PyErr_LDB_OR_RAISE(py_ldb
, ldb
);
261 mem_ctx
= talloc_new(NULL
);
267 schema
= dsdb_get_schema(ldb
, mem_ctx
);
269 PyErr_SetString(PyExc_RuntimeError
, "Failed to find a schema from ldb \n");
270 talloc_free(mem_ctx
);
274 status
= dsdb_schema_pfm_oid_from_attid(schema
->prefixmap
, attid
,
276 if (!W_ERROR_IS_OK(status
)) {
277 PyErr_SetWERROR(status
);
278 talloc_free(mem_ctx
);
282 ret
= PyStr_FromString(oid
);
284 talloc_free(mem_ctx
);
290 static PyObject
*py_dsdb_get_attid_from_lDAPDisplayName(PyObject
*self
, PyObject
*args
)
292 PyObject
*py_ldb
, *is_schema_nc
;
293 struct ldb_context
*ldb
;
294 struct dsdb_schema
*schema
;
295 const char *ldap_display_name
;
296 bool schema_nc
= false;
297 const struct dsdb_attribute
*a
;
300 if (!PyArg_ParseTuple(args
, "OsO", &py_ldb
, &ldap_display_name
, &is_schema_nc
))
303 PyErr_LDB_OR_RAISE(py_ldb
, ldb
);
306 if (!PyBool_Check(is_schema_nc
)) {
307 PyErr_SetString(PyExc_TypeError
, "Expected boolean is_schema_nc");
310 if (is_schema_nc
== Py_True
) {
315 schema
= dsdb_get_schema(ldb
, NULL
);
318 PyErr_SetString(PyExc_RuntimeError
, "Failed to find a schema from ldb");
322 a
= dsdb_attribute_by_lDAPDisplayName(schema
, ldap_display_name
);
324 PyErr_Format(PyExc_KeyError
, "Failed to find attribute '%s'", ldap_display_name
);
328 attid
= dsdb_attribute_get_attid(a
, schema_nc
);
330 return PyLong_FromUnsignedLong(attid
);
334 return the systemFlags as int from the attribute name
336 static PyObject
*py_dsdb_get_systemFlags_from_lDAPDisplayName(PyObject
*self
, PyObject
*args
)
339 struct ldb_context
*ldb
;
340 struct dsdb_schema
*schema
;
341 const char *ldap_display_name
;
342 const struct dsdb_attribute
*attribute
;
344 if (!PyArg_ParseTuple(args
, "Os", &py_ldb
, &ldap_display_name
))
347 PyErr_LDB_OR_RAISE(py_ldb
, ldb
);
349 schema
= dsdb_get_schema(ldb
, NULL
);
352 PyErr_SetString(PyExc_RuntimeError
, "Failed to find a schema from ldb");
356 attribute
= dsdb_attribute_by_lDAPDisplayName(schema
, ldap_display_name
);
357 if (attribute
== NULL
) {
358 PyErr_Format(PyExc_KeyError
, "Failed to find attribute '%s'", ldap_display_name
);
362 return PyInt_FromLong(attribute
->systemFlags
);
366 return the linkID from the attribute name
368 static PyObject
*py_dsdb_get_linkId_from_lDAPDisplayName(PyObject
*self
, PyObject
*args
)
371 struct ldb_context
*ldb
;
372 struct dsdb_schema
*schema
;
373 const char *ldap_display_name
;
374 const struct dsdb_attribute
*attribute
;
376 if (!PyArg_ParseTuple(args
, "Os", &py_ldb
, &ldap_display_name
))
379 PyErr_LDB_OR_RAISE(py_ldb
, ldb
);
381 schema
= dsdb_get_schema(ldb
, NULL
);
384 PyErr_SetString(PyExc_RuntimeError
, "Failed to find a schema from ldb");
388 attribute
= dsdb_attribute_by_lDAPDisplayName(schema
, ldap_display_name
);
389 if (attribute
== NULL
) {
390 PyErr_Format(PyExc_KeyError
, "Failed to find attribute '%s'", ldap_display_name
);
394 return PyInt_FromLong(attribute
->linkID
);
398 return the backlink attribute name (if any) for an attribute
400 static PyObject
*py_dsdb_get_backlink_from_lDAPDisplayName(PyObject
*self
, PyObject
*args
)
403 struct ldb_context
*ldb
;
404 struct dsdb_schema
*schema
;
405 const char *ldap_display_name
;
406 const struct dsdb_attribute
*attribute
, *target_attr
;
408 if (!PyArg_ParseTuple(args
, "Os", &py_ldb
, &ldap_display_name
))
411 PyErr_LDB_OR_RAISE(py_ldb
, ldb
);
413 schema
= dsdb_get_schema(ldb
, NULL
);
416 PyErr_SetString(PyExc_RuntimeError
, "Failed to find a schema from ldb");
420 attribute
= dsdb_attribute_by_lDAPDisplayName(schema
, ldap_display_name
);
421 if (attribute
== NULL
) {
422 PyErr_Format(PyExc_KeyError
, "Failed to find attribute '%s'", ldap_display_name
);
426 if (attribute
->linkID
== 0) {
430 target_attr
= dsdb_attribute_by_linkID(schema
, attribute
->linkID
^ 1);
431 if (target_attr
== NULL
) {
432 /* when we add pseudo-backlinks we'll need to handle
437 return PyStr_FromString(target_attr
->lDAPDisplayName
);
441 static PyObject
*py_dsdb_get_lDAPDisplayName_by_attid(PyObject
*self
, PyObject
*args
)
444 struct ldb_context
*ldb
;
445 struct dsdb_schema
*schema
;
446 const struct dsdb_attribute
*a
;
449 if (!PyArg_ParseTuple(args
, "OI", &py_ldb
, &attid
))
452 PyErr_LDB_OR_RAISE(py_ldb
, ldb
);
454 schema
= dsdb_get_schema(ldb
, NULL
);
457 PyErr_SetString(PyExc_RuntimeError
, "Failed to find a schema from ldb");
461 a
= dsdb_attribute_by_attributeID_id(schema
, attid
);
463 PyErr_Format(PyExc_KeyError
, "Failed to find attribute '0x%08x'", attid
);
467 return PyStr_FromString(a
->lDAPDisplayName
);
472 return the attribute syntax oid as a string from the attribute name
474 static PyObject
*py_dsdb_get_syntax_oid_from_lDAPDisplayName(PyObject
*self
, PyObject
*args
)
477 struct ldb_context
*ldb
;
478 struct dsdb_schema
*schema
;
479 const char *ldap_display_name
;
480 const struct dsdb_attribute
*attribute
;
482 if (!PyArg_ParseTuple(args
, "Os", &py_ldb
, &ldap_display_name
))
485 PyErr_LDB_OR_RAISE(py_ldb
, ldb
);
487 schema
= dsdb_get_schema(ldb
, NULL
);
490 PyErr_SetString(PyExc_RuntimeError
, "Failed to find a schema from ldb");
494 attribute
= dsdb_attribute_by_lDAPDisplayName(schema
, ldap_display_name
);
495 if (attribute
== NULL
) {
496 PyErr_Format(PyExc_KeyError
, "Failed to find attribute '%s'", ldap_display_name
);
500 return PyStr_FromString(attribute
->syntax
->ldap_oid
);
504 convert a python string to a DRSUAPI drsuapi_DsReplicaAttribute attribute
506 static PyObject
*py_dsdb_DsReplicaAttribute(PyObject
*self
, PyObject
*args
)
508 PyObject
*py_ldb
, *el_list
, *ret
;
509 struct ldb_context
*ldb
;
510 char *ldap_display_name
;
511 const struct dsdb_attribute
*a
;
512 struct dsdb_schema
*schema
;
513 struct dsdb_syntax_ctx syntax_ctx
;
514 struct ldb_message_element
*el
;
515 struct drsuapi_DsReplicaAttribute
*attr
;
520 if (!PyArg_ParseTuple(args
, "OsO", &py_ldb
, &ldap_display_name
, &el_list
)) {
524 PyErr_LDB_OR_RAISE(py_ldb
, ldb
);
526 schema
= dsdb_get_schema(ldb
, NULL
);
528 PyErr_SetString(PyExc_RuntimeError
, "Failed to find a schema from ldb");
532 a
= dsdb_attribute_by_lDAPDisplayName(schema
, ldap_display_name
);
534 PyErr_Format(PyExc_KeyError
, "Failed to find attribute '%s'", ldap_display_name
);
538 dsdb_syntax_ctx_init(&syntax_ctx
, ldb
, schema
);
539 syntax_ctx
.is_schema_nc
= false;
541 tmp_ctx
= talloc_new(ldb
);
542 if (tmp_ctx
== NULL
) {
547 /* If we were not given an LdbMessageElement */
548 if (!PyList_Check(el_list
)) {
549 if (!py_check_dcerpc_type(el_list
, "ldb", "MessageElement")) {
550 PyErr_SetString(py_ldb_get_exception(),
551 "list of strings or ldb MessageElement object required");
556 * el may not be a valid talloc context, it
557 * could be part of an array
559 el
= pyldb_MessageElement_AsMessageElement(el_list
);
561 el
= talloc_zero(tmp_ctx
, struct ldb_message_element
);
564 talloc_free(tmp_ctx
);
568 el
->name
= ldap_display_name
;
569 el
->num_values
= PyList_Size(el_list
);
571 el
->values
= talloc_array(el
, struct ldb_val
, el
->num_values
);
572 if (el
->values
== NULL
) {
574 talloc_free(tmp_ctx
);
578 for (i
= 0; i
< el
->num_values
; i
++) {
579 PyObject
*item
= PyList_GetItem(el_list
, i
);
580 if (!(PyBytes_Check(item
))) {
581 PyErr_Format(PyExc_TypeError
,
582 "ldif_element type should be "
585 talloc_free(tmp_ctx
);
589 (uint8_t *)PyBytes_AsString(item
);
590 el
->values
[i
].length
= PyBytes_Size(item
);
594 attr
= talloc_zero(tmp_ctx
, struct drsuapi_DsReplicaAttribute
);
597 talloc_free(tmp_ctx
);
601 werr
= a
->syntax
->ldb_to_drsuapi(&syntax_ctx
, a
, el
, attr
, attr
);
602 PyErr_WERROR_NOT_OK_RAISE(werr
);
604 ret
= py_return_ndr_struct("samba.dcerpc.drsuapi", "DsReplicaAttribute", attr
, attr
);
606 talloc_free(tmp_ctx
);
613 normalise a ldb attribute list
615 static PyObject
*py_dsdb_normalise_attributes(PyObject
*self
, PyObject
*args
)
617 PyObject
*py_ldb
, *el_list
, *py_ret
;
618 struct ldb_context
*ldb
;
619 char *ldap_display_name
;
620 const struct dsdb_attribute
*a
;
621 struct dsdb_schema
*schema
;
622 struct dsdb_syntax_ctx syntax_ctx
;
623 struct ldb_message_element
*el
, *new_el
;
624 struct drsuapi_DsReplicaAttribute
*attr
;
625 PyLdbMessageElementObject
*ret
;
629 PyTypeObject
*py_type
= NULL
;
630 PyObject
*module
= NULL
;
632 if (!PyArg_ParseTuple(args
, "OsO", &py_ldb
, &ldap_display_name
, &el_list
)) {
636 PyErr_LDB_OR_RAISE(py_ldb
, ldb
);
638 schema
= dsdb_get_schema(ldb
, NULL
);
640 PyErr_SetString(PyExc_RuntimeError
, "Failed to find a schema from ldb");
644 a
= dsdb_attribute_by_lDAPDisplayName(schema
, ldap_display_name
);
646 PyErr_Format(PyExc_KeyError
, "Failed to find attribute '%s'", ldap_display_name
);
650 dsdb_syntax_ctx_init(&syntax_ctx
, ldb
, schema
);
651 syntax_ctx
.is_schema_nc
= false;
653 tmp_ctx
= talloc_new(ldb
);
654 if (tmp_ctx
== NULL
) {
659 if (!PyList_Check(el_list
)) {
660 if (!py_check_dcerpc_type(el_list
, "ldb", "MessageElement")) {
661 PyErr_SetString(py_ldb_get_exception(),
662 "list of strings or ldb MessageElement object required");
667 * el may not be a valid talloc context, it
668 * could be part of an array
670 el
= pyldb_MessageElement_AsMessageElement(el_list
);
672 el
= talloc_zero(tmp_ctx
, struct ldb_message_element
);
675 talloc_free(tmp_ctx
);
679 el
->name
= ldap_display_name
;
680 el
->num_values
= PyList_Size(el_list
);
682 el
->values
= talloc_array(el
, struct ldb_val
, el
->num_values
);
683 if (el
->values
== NULL
) {
685 talloc_free(tmp_ctx
);
689 for (i
= 0; i
< el
->num_values
; i
++) {
690 PyObject
*item
= PyList_GetItem(el_list
, i
);
691 if (!PyBytes_Check(item
)) {
692 PyErr_Format(PyExc_TypeError
,
693 "ldif_element type should be "
696 talloc_free(tmp_ctx
);
699 el
->values
[i
].data
= (uint8_t *)PyBytes_AsString(item
);
700 el
->values
[i
].length
= PyBytes_Size(item
);
704 new_el
= talloc_zero(tmp_ctx
, struct ldb_message_element
);
705 if (new_el
== NULL
) {
707 talloc_free(tmp_ctx
);
711 /* Normalise "objectClass" attribute if needed */
712 if (ldb_attr_cmp(a
->lDAPDisplayName
, "objectClass") == 0) {
714 iret
= dsdb_sort_objectClass_attr(ldb
, schema
, el
, new_el
, new_el
);
715 if (iret
!= LDB_SUCCESS
) {
716 PyErr_SetString(PyExc_RuntimeError
, ldb_errstring(ldb
));
717 talloc_free(tmp_ctx
);
722 /* first run ldb_to_drsuapi, then convert back again. This has
723 * the effect of normalising the attributes
726 attr
= talloc_zero(tmp_ctx
, struct drsuapi_DsReplicaAttribute
);
729 talloc_free(tmp_ctx
);
733 werr
= a
->syntax
->ldb_to_drsuapi(&syntax_ctx
, a
, el
, attr
, attr
);
734 PyErr_WERROR_NOT_OK_RAISE(werr
);
736 /* now convert back again */
737 werr
= a
->syntax
->drsuapi_to_ldb(&syntax_ctx
, a
, attr
, new_el
, new_el
);
738 PyErr_WERROR_NOT_OK_RAISE(werr
);
740 module
= PyImport_ImportModule("ldb");
741 if (module
== NULL
) {
745 py_type
= (PyTypeObject
*)PyObject_GetAttrString(module
, "MessageElement");
746 if (py_type
== NULL
) {
753 py_ret
= py_type
->tp_alloc(py_type
, 0);
755 if (py_ret
== NULL
) {
759 ret
= (PyLdbMessageElementObject
*)py_ret
;
761 ret
->mem_ctx
= talloc_new(NULL
);
762 if (talloc_reference(ret
->mem_ctx
, new_el
) == NULL
) {
769 talloc_free(tmp_ctx
);
775 static PyObject
*py_dsdb_set_ntds_invocation_id(PyObject
*self
, PyObject
*args
)
777 PyObject
*py_ldb
, *py_guid
;
780 struct ldb_context
*ldb
;
781 if (!PyArg_ParseTuple(args
, "OO", &py_ldb
, &py_guid
))
784 PyErr_LDB_OR_RAISE(py_ldb
, ldb
);
785 GUID_from_string(PyStr_AsString(py_guid
), &guid
);
787 if (GUID_all_zero(&guid
)) {
788 PyErr_SetString(PyExc_RuntimeError
, "set_ntds_invocation_id rejected due to all-zero invocation ID");
792 ret
= samdb_set_ntds_invocation_id(ldb
, &guid
);
794 PyErr_SetString(PyExc_RuntimeError
, "set_ntds_invocation_id failed");
800 static PyObject
*py_samdb_ntds_objectGUID(PyObject
*self
, PyObject
*args
)
802 PyObject
*py_ldb
, *result
;
803 struct ldb_context
*ldb
;
804 const struct GUID
*guid
;
807 if (!PyArg_ParseTuple(args
, "O", &py_ldb
)) {
811 PyErr_LDB_OR_RAISE(py_ldb
, ldb
);
813 guid
= samdb_ntds_objectGUID(ldb
);
815 PyErr_SetString(PyExc_RuntimeError
, "Failed to find NTDS GUID");
819 retstr
= GUID_string(NULL
, guid
);
820 if (retstr
== NULL
) {
824 result
= PyStr_FromString(retstr
);
829 static PyObject
*py_dsdb_set_global_schema(PyObject
*self
, PyObject
*args
)
832 struct ldb_context
*ldb
;
834 if (!PyArg_ParseTuple(args
, "O", &py_ldb
))
837 PyErr_LDB_OR_RAISE(py_ldb
, ldb
);
839 ret
= dsdb_set_global_schema(ldb
);
840 PyErr_LDB_ERROR_IS_ERR_RAISE(py_ldb_get_exception(), ret
, ldb
);
845 static PyObject
*py_dsdb_load_partition_usn(PyObject
*self
, PyObject
*args
)
847 PyObject
*py_dn
, *py_ldb
, *result
;
849 uint64_t highest_uSN
, urgent_uSN
;
850 struct ldb_context
*ldb
;
854 if (!PyArg_ParseTuple(args
, "OO", &py_ldb
, &py_dn
)) {
858 PyErr_LDB_OR_RAISE(py_ldb
, ldb
);
860 mem_ctx
= talloc_new(NULL
);
861 if (mem_ctx
== NULL
) {
866 if (!pyldb_Object_AsDn(mem_ctx
, py_dn
, ldb
, &dn
)) {
867 talloc_free(mem_ctx
);
871 ret
= dsdb_load_partition_usn(ldb
, dn
, &highest_uSN
, &urgent_uSN
);
872 if (ret
!= LDB_SUCCESS
) {
873 PyErr_Format(PyExc_RuntimeError
,
874 "Failed to load partition [%s] uSN - %s",
875 ldb_dn_get_linearized(dn
),
877 talloc_free(mem_ctx
);
881 talloc_free(mem_ctx
);
883 result
= Py_BuildValue(
885 "uSNHighest", (uint64_t)highest_uSN
,
886 "uSNUrgent", (uint64_t)urgent_uSN
);
891 static PyObject
*py_dsdb_set_am_rodc(PyObject
*self
, PyObject
*args
)
895 struct ldb_context
*ldb
;
898 if (!PyArg_ParseTuple(args
, "Oi", &py_ldb
, &py_val
))
901 PyErr_LDB_OR_RAISE(py_ldb
, ldb
);
902 ret
= samdb_set_am_rodc(ldb
, (bool)py_val
);
904 PyErr_SetString(PyExc_RuntimeError
, "set_am_rodc failed");
910 static PyObject
*py_dsdb_set_schema_from_ldif(PyObject
*self
, PyObject
*args
)
915 struct ldb_context
*ldb
;
917 if (!PyArg_ParseTuple(args
, "Osss", &py_ldb
, &pf
, &df
, &dn
))
920 PyErr_LDB_OR_RAISE(py_ldb
, ldb
);
922 result
= dsdb_set_schema_from_ldif(ldb
, pf
, df
, dn
);
923 PyErr_WERROR_NOT_OK_RAISE(result
);
928 static PyObject
*py_dsdb_set_schema_from_ldb(PyObject
*self
, PyObject
*args
)
931 struct ldb_context
*ldb
;
932 PyObject
*py_from_ldb
;
933 struct ldb_context
*from_ldb
;
934 struct dsdb_schema
*schema
;
936 char write_indices_and_attributes
= SCHEMA_WRITE
;
937 if (!PyArg_ParseTuple(args
, "OO|b",
938 &py_ldb
, &py_from_ldb
, &write_indices_and_attributes
))
941 PyErr_LDB_OR_RAISE(py_ldb
, ldb
);
943 PyErr_LDB_OR_RAISE(py_from_ldb
, from_ldb
);
945 schema
= dsdb_get_schema(from_ldb
, NULL
);
947 PyErr_SetString(PyExc_RuntimeError
, "Failed to set find a schema on 'from' ldb!\n");
951 ret
= dsdb_reference_schema(ldb
, schema
, write_indices_and_attributes
);
952 PyErr_LDB_ERROR_IS_ERR_RAISE(py_ldb_get_exception(), ret
, ldb
);
957 static PyObject
*py_dsdb_write_prefixes_from_schema_to_ldb(PyObject
*self
, PyObject
*args
)
960 struct ldb_context
*ldb
;
962 struct dsdb_schema
*schema
;
964 if (!PyArg_ParseTuple(args
, "O", &py_ldb
))
967 PyErr_LDB_OR_RAISE(py_ldb
, ldb
);
969 schema
= dsdb_get_schema(ldb
, NULL
);
971 PyErr_SetString(PyExc_RuntimeError
, "Failed to set find a schema on ldb!\n");
975 result
= dsdb_write_prefixes_from_schema_to_ldb(NULL
, ldb
, schema
);
976 PyErr_WERROR_NOT_OK_RAISE(result
);
982 static PyObject
*py_dsdb_get_partitions_dn(PyObject
*self
, PyObject
*args
)
984 struct ldb_context
*ldb
;
986 PyObject
*py_ldb
, *ret
;
988 if (!PyArg_ParseTuple(args
, "O", &py_ldb
))
991 PyErr_LDB_OR_RAISE(py_ldb
, ldb
);
993 dn
= samdb_partitions_dn(ldb
, NULL
);
998 ret
= pyldb_Dn_FromDn(dn
);
1004 static PyObject
*py_dsdb_get_nc_root(PyObject
*self
, PyObject
*args
)
1006 struct ldb_context
*ldb
;
1007 struct ldb_dn
*dn
, *nc_root
;
1008 PyObject
*py_ldb
, *py_ldb_dn
, *py_nc_root
;
1011 if (!PyArg_ParseTuple(args
, "OO", &py_ldb
, &py_ldb_dn
))
1014 PyErr_LDB_OR_RAISE(py_ldb
, ldb
);
1015 PyErr_LDB_DN_OR_RAISE(py_ldb_dn
, dn
);
1017 ret
= dsdb_find_nc_root(ldb
, ldb
, dn
, &nc_root
);
1018 PyErr_LDB_ERROR_IS_ERR_RAISE(py_ldb_get_exception(), ret
, ldb
);
1020 py_nc_root
= pyldb_Dn_FromDn(nc_root
);
1021 talloc_unlink(ldb
, nc_root
);
1025 static PyObject
*py_dsdb_get_wellknown_dn(PyObject
*self
, PyObject
*args
)
1027 struct ldb_context
*ldb
;
1028 struct ldb_dn
*nc_dn
, *wk_dn
;
1030 PyObject
*py_ldb
, *py_nc_dn
, *py_wk_dn
;
1033 if (!PyArg_ParseTuple(args
, "OOs", &py_ldb
, &py_nc_dn
, &wkguid
))
1036 PyErr_LDB_OR_RAISE(py_ldb
, ldb
);
1037 PyErr_LDB_DN_OR_RAISE(py_nc_dn
, nc_dn
);
1039 ret
= dsdb_wellknown_dn(ldb
, ldb
, nc_dn
, wkguid
, &wk_dn
);
1040 if (ret
== LDB_ERR_NO_SUCH_OBJECT
) {
1041 PyErr_Format(PyExc_KeyError
, "Failed to find well known DN for GUID %s", wkguid
);
1045 PyErr_LDB_ERROR_IS_ERR_RAISE(py_ldb_get_exception(), ret
, ldb
);
1047 py_wk_dn
= pyldb_Dn_FromDn(wk_dn
);
1048 talloc_unlink(ldb
, wk_dn
);
1054 call into samdb_rodc()
1056 static PyObject
*py_dsdb_am_rodc(PyObject
*self
, PyObject
*args
)
1059 struct ldb_context
*ldb
;
1063 if (!PyArg_ParseTuple(args
, "O", &py_ldb
))
1066 PyErr_LDB_OR_RAISE(py_ldb
, ldb
);
1068 ret
= samdb_rodc(ldb
, &am_rodc
);
1069 if (ret
!= LDB_SUCCESS
) {
1070 PyErr_SetString(PyExc_RuntimeError
, ldb_errstring(ldb
));
1074 return PyBool_FromLong(am_rodc
);
1078 call into samdb_is_pdc()
1080 static PyObject
*py_dsdb_am_pdc(PyObject
*self
, PyObject
*args
)
1083 struct ldb_context
*ldb
;
1086 if (!PyArg_ParseTuple(args
, "O", &py_ldb
))
1089 PyErr_LDB_OR_RAISE(py_ldb
, ldb
);
1091 am_pdc
= samdb_is_pdc(ldb
);
1092 return PyBool_FromLong(am_pdc
);
1096 call DSDB_EXTENDED_CREATE_OWN_RID_SET to get a new RID set for this server
1098 static PyObject
*py_dsdb_create_own_rid_set(PyObject
*self
, PyObject
*args
)
1101 struct ldb_context
*ldb
;
1103 struct ldb_result
*ext_res
;
1105 if (!PyArg_ParseTuple(args
, "O", &py_ldb
))
1108 PyErr_LDB_OR_RAISE(py_ldb
, ldb
);
1111 * Run DSDB_EXTENDED_CREATE_OWN_RID_SET to get a RID set
1114 ret
= ldb_extended(ldb
, DSDB_EXTENDED_CREATE_OWN_RID_SET
, NULL
, &ext_res
);
1116 PyErr_LDB_ERROR_IS_ERR_RAISE(py_ldb_get_exception(), ret
, ldb
);
1118 TALLOC_FREE(ext_res
);
1124 call DSDB_EXTENDED_ALLOCATE_RID to get a new RID set for this server
1126 static PyObject
*py_dsdb_allocate_rid(PyObject
*self
, PyObject
*args
)
1129 struct ldb_context
*ldb
;
1132 struct ldb_result
*ext_res
= NULL
;
1133 struct dsdb_extended_allocate_rid
*rid_return
= NULL
;
1134 if (!PyArg_ParseTuple(args
, "O", &py_ldb
)) {
1138 PyErr_LDB_OR_RAISE(py_ldb
, ldb
);
1140 rid_return
= talloc_zero(ldb
, struct dsdb_extended_allocate_rid
);
1141 if (rid_return
== NULL
) {
1142 return PyErr_NoMemory();
1146 * Run DSDB_EXTENDED_ALLOCATE_RID to get a new RID
1149 ret
= ldb_extended(ldb
, DSDB_EXTENDED_ALLOCATE_RID
, rid_return
, &ext_res
);
1150 if (ret
!= LDB_SUCCESS
) {
1151 TALLOC_FREE(rid_return
);
1152 TALLOC_FREE(ext_res
);
1153 PyErr_LDB_ERROR_IS_ERR_RAISE(py_ldb_get_exception(), ret
, ldb
);
1156 rid
= rid_return
->rid
;
1157 TALLOC_FREE(rid_return
);
1158 TALLOC_FREE(ext_res
);
1160 return PyInt_FromLong(rid
);
1163 static PyObject
*py_dns_delete_tombstones(PyObject
*self
, PyObject
*args
)
1167 struct ldb_context
*ldb
= NULL
;
1168 TALLOC_CTX
*mem_ctx
= NULL
;
1169 char *error_string
= NULL
;
1171 if (!PyArg_ParseTuple(args
, "O", &py_ldb
)) {
1174 PyErr_LDB_OR_RAISE(py_ldb
, ldb
);
1176 mem_ctx
= talloc_new(ldb
);
1177 if (mem_ctx
== NULL
) {
1178 return PyErr_NoMemory();
1181 status
= dns_delete_tombstones(mem_ctx
, ldb
, &error_string
);
1183 if (!NT_STATUS_IS_OK(status
)) {
1185 PyErr_Format(PyExc_RuntimeError
, "%s", error_string
);
1187 PyErr_SetNTSTATUS(status
);
1189 TALLOC_FREE(mem_ctx
);
1193 TALLOC_FREE(mem_ctx
);
1197 static PyObject
*py_scavenge_dns_records(PyObject
*self
, PyObject
*args
)
1201 struct ldb_context
*ldb
= NULL
;
1202 TALLOC_CTX
*mem_ctx
= NULL
;
1203 char *error_string
= NULL
;
1205 if (!PyArg_ParseTuple(args
, "O", &py_ldb
)) {
1208 PyErr_LDB_OR_RAISE(py_ldb
, ldb
);
1210 mem_ctx
= talloc_new(ldb
);
1211 if (mem_ctx
== NULL
) {
1212 return PyErr_NoMemory();
1215 status
= dns_tombstone_records(mem_ctx
, ldb
, &error_string
);
1217 if (!NT_STATUS_IS_OK(status
)) {
1219 PyErr_Format(PyExc_RuntimeError
, "%s", error_string
);
1221 PyErr_SetNTSTATUS(status
);
1223 TALLOC_FREE(mem_ctx
);
1227 TALLOC_FREE(mem_ctx
);
1231 static PyObject
*py_dsdb_garbage_collect_tombstones(PyObject
*self
, PyObject
*args
)
1233 PyObject
*py_ldb
, *py_list_dn
;
1234 struct ldb_context
*ldb
= NULL
;
1237 long long _current_time
, _tombstone_lifetime
= LLONG_MAX
;
1238 uint32_t tombstone_lifetime32
;
1239 struct dsdb_ldb_dn_list_node
*part
= NULL
;
1240 time_t current_time
, tombstone_lifetime
;
1241 TALLOC_CTX
*mem_ctx
= NULL
;
1243 unsigned int num_objects_removed
= 0;
1244 unsigned int num_links_removed
= 0;
1245 char *error_string
= NULL
;
1247 if (!PyArg_ParseTuple(args
, "OOL|L", &py_ldb
,
1248 &py_list_dn
, &_current_time
, &_tombstone_lifetime
)) {
1253 PyErr_LDB_OR_RAISE(py_ldb
, ldb
);
1255 mem_ctx
= talloc_new(ldb
);
1256 if (mem_ctx
== NULL
) {
1257 return PyErr_NoMemory();
1260 current_time
= _current_time
;
1262 if (_tombstone_lifetime
== LLONG_MAX
) {
1263 int ret
= dsdb_tombstone_lifetime(ldb
, &tombstone_lifetime32
);
1264 if (ret
!= LDB_SUCCESS
) {
1265 PyErr_Format(PyExc_RuntimeError
,
1266 "Failed to get tombstone lifetime: %s",
1267 ldb_errstring(ldb
));
1268 TALLOC_FREE(mem_ctx
);
1271 tombstone_lifetime
= tombstone_lifetime32
;
1273 tombstone_lifetime
= _tombstone_lifetime
;
1276 if (!PyList_Check(py_list_dn
)) {
1277 PyErr_SetString(PyExc_TypeError
, "A list of DNs were expected");
1278 TALLOC_FREE(mem_ctx
);
1282 length
= PyList_GET_SIZE(py_list_dn
);
1284 for (i
= 0; i
< length
; i
++) {
1285 const char *part_str
= PyStr_AsString(PyList_GetItem(py_list_dn
, i
));
1287 struct dsdb_ldb_dn_list_node
*node
;
1289 if (part_str
== NULL
) {
1290 TALLOC_FREE(mem_ctx
);
1291 return PyErr_NoMemory();
1294 p
= ldb_dn_new(mem_ctx
, ldb
, part_str
);
1296 PyErr_Format(PyExc_RuntimeError
, "Failed to parse DN %s", part_str
);
1297 TALLOC_FREE(mem_ctx
);
1300 node
= talloc_zero(mem_ctx
, struct dsdb_ldb_dn_list_node
);
1303 DLIST_ADD_END(part
, node
);
1306 status
= dsdb_garbage_collect_tombstones(mem_ctx
, ldb
,
1309 &num_objects_removed
,
1313 if (!NT_STATUS_IS_OK(status
)) {
1315 PyErr_Format(PyExc_RuntimeError
, "%s", error_string
);
1317 PyErr_SetNTSTATUS(status
);
1319 TALLOC_FREE(mem_ctx
);
1323 TALLOC_FREE(mem_ctx
);
1325 return Py_BuildValue("(II)", num_objects_removed
,
1329 static PyObject
*py_dsdb_load_udv_v2(PyObject
*self
, PyObject
*args
)
1334 PyObject
*py_ldb
= NULL
, *py_dn
= NULL
, *pylist
= NULL
;
1335 struct ldb_context
*samdb
= NULL
;
1336 struct ldb_dn
*dn
= NULL
;
1337 struct drsuapi_DsReplicaCursor2
*cursors
= NULL
;
1338 TALLOC_CTX
*tmp_ctx
= NULL
;
1340 if (!PyArg_ParseTuple(args
, "OO", &py_ldb
, &py_dn
)) {
1344 PyErr_LDB_OR_RAISE(py_ldb
, samdb
);
1346 tmp_ctx
= talloc_new(samdb
);
1347 if (tmp_ctx
== NULL
) {
1348 return PyErr_NoMemory();
1351 ok
= pyldb_Object_AsDn(tmp_ctx
, py_dn
, samdb
, &dn
);
1353 TALLOC_FREE(tmp_ctx
);
1357 ret
= dsdb_load_udv_v2(samdb
, dn
, tmp_ctx
, &cursors
, &count
);
1358 if (ret
!= LDB_SUCCESS
) {
1359 TALLOC_FREE(tmp_ctx
);
1360 PyErr_SetString(PyExc_RuntimeError
,
1361 "Failed to load udv from ldb");
1365 pylist
= PyList_New(count
);
1366 if (pylist
== NULL
) {
1367 TALLOC_FREE(tmp_ctx
);
1368 return PyErr_NoMemory();
1371 for (i
= 0; i
< count
; i
++) {
1372 PyObject
*py_cursor
;
1373 struct drsuapi_DsReplicaCursor2
*cursor
;
1374 cursor
= talloc(tmp_ctx
, struct drsuapi_DsReplicaCursor2
);
1375 if (cursor
== NULL
) {
1376 TALLOC_FREE(tmp_ctx
);
1377 return PyErr_NoMemory();
1379 *cursor
= cursors
[i
];
1381 py_cursor
= py_return_ndr_struct("samba.dcerpc.drsuapi",
1384 if (py_cursor
== NULL
) {
1385 TALLOC_FREE(tmp_ctx
);
1386 return PyErr_NoMemory();
1389 PyList_SetItem(pylist
, i
, py_cursor
);
1392 TALLOC_FREE(tmp_ctx
);
1396 static PyMethodDef py_dsdb_methods
[] = {
1397 { "_samdb_server_site_name", (PyCFunction
)py_samdb_server_site_name
,
1398 METH_VARARGS
, "Get the server site name as a string"},
1399 { "_dsdb_convert_schema_to_openldap",
1400 (PyCFunction
)py_dsdb_convert_schema_to_openldap
, METH_VARARGS
,
1401 "dsdb_convert_schema_to_openldap(ldb, target_str, mapping) -> str\n"
1402 "Create an OpenLDAP schema from a schema." },
1403 { "_samdb_set_domain_sid", (PyCFunction
)py_samdb_set_domain_sid
,
1405 "samdb_set_domain_sid(samdb, sid)\n"
1406 "Set SID of domain to use." },
1407 { "_samdb_get_domain_sid", (PyCFunction
)py_samdb_get_domain_sid
,
1409 "samdb_get_domain_sid(samdb)\n"
1410 "Get SID of domain in use." },
1411 { "_samdb_ntds_invocation_id", (PyCFunction
)py_samdb_ntds_invocation_id
,
1412 METH_VARARGS
, "get the NTDS invocation ID GUID as a string"},
1413 { "_samdb_set_ntds_settings_dn", (PyCFunction
)py_samdb_set_ntds_settings_dn
,
1415 "samdb_set_ntds_settings_dn(samdb, ntds_settings_dn)\n"
1416 "Set NTDS Settings DN for this LDB (allows it to be set before the DB fully exists)." },
1417 { "_dsdb_get_oid_from_attid", (PyCFunction
)py_dsdb_get_oid_from_attid
,
1418 METH_VARARGS
, NULL
},
1419 { "_dsdb_get_attid_from_lDAPDisplayName", (PyCFunction
)py_dsdb_get_attid_from_lDAPDisplayName
,
1420 METH_VARARGS
, NULL
},
1421 { "_dsdb_get_syntax_oid_from_lDAPDisplayName", (PyCFunction
)py_dsdb_get_syntax_oid_from_lDAPDisplayName
,
1422 METH_VARARGS
, NULL
},
1423 { "_dsdb_get_systemFlags_from_lDAPDisplayName", (PyCFunction
)py_dsdb_get_systemFlags_from_lDAPDisplayName
,
1424 METH_VARARGS
, NULL
},
1425 { "_dsdb_get_linkId_from_lDAPDisplayName", (PyCFunction
)py_dsdb_get_linkId_from_lDAPDisplayName
,
1426 METH_VARARGS
, NULL
},
1427 { "_dsdb_get_lDAPDisplayName_by_attid", (PyCFunction
)py_dsdb_get_lDAPDisplayName_by_attid
,
1428 METH_VARARGS
, NULL
},
1429 { "_dsdb_get_backlink_from_lDAPDisplayName", (PyCFunction
)py_dsdb_get_backlink_from_lDAPDisplayName
,
1430 METH_VARARGS
, NULL
},
1431 { "_dsdb_set_ntds_invocation_id",
1432 (PyCFunction
)py_dsdb_set_ntds_invocation_id
, METH_VARARGS
,
1434 { "_samdb_ntds_objectGUID", (PyCFunction
)py_samdb_ntds_objectGUID
,
1435 METH_VARARGS
, "get the NTDS objectGUID as a string"},
1436 { "_dsdb_set_global_schema", (PyCFunction
)py_dsdb_set_global_schema
,
1437 METH_VARARGS
, NULL
},
1438 { "_dsdb_load_partition_usn", (PyCFunction
)py_dsdb_load_partition_usn
,
1440 "get uSNHighest and uSNUrgent from the partition @REPLCHANGED"},
1441 { "_dsdb_set_am_rodc",
1442 (PyCFunction
)py_dsdb_set_am_rodc
, METH_VARARGS
,
1445 (PyCFunction
)py_dsdb_am_rodc
, METH_VARARGS
,
1448 (PyCFunction
)py_dsdb_am_pdc
, METH_VARARGS
,
1450 { "_dsdb_set_schema_from_ldif", (PyCFunction
)py_dsdb_set_schema_from_ldif
, METH_VARARGS
,
1452 { "_dsdb_set_schema_from_ldb", (PyCFunction
)py_dsdb_set_schema_from_ldb
, METH_VARARGS
,
1454 { "_dsdb_write_prefixes_from_schema_to_ldb", (PyCFunction
)py_dsdb_write_prefixes_from_schema_to_ldb
, METH_VARARGS
,
1456 { "_dsdb_get_partitions_dn", (PyCFunction
)py_dsdb_get_partitions_dn
, METH_VARARGS
, NULL
},
1457 { "_dsdb_get_nc_root", (PyCFunction
)py_dsdb_get_nc_root
, METH_VARARGS
, NULL
},
1458 { "_dsdb_get_wellknown_dn", (PyCFunction
)py_dsdb_get_wellknown_dn
, METH_VARARGS
, NULL
},
1459 { "_dsdb_DsReplicaAttribute", (PyCFunction
)py_dsdb_DsReplicaAttribute
, METH_VARARGS
, NULL
},
1460 { "_dsdb_normalise_attributes", (PyCFunction
)py_dsdb_normalise_attributes
, METH_VARARGS
, NULL
},
1461 { "_dsdb_garbage_collect_tombstones", (PyCFunction
)py_dsdb_garbage_collect_tombstones
, METH_VARARGS
,
1462 "_dsdb_kcc_check_deleted(samdb, [dn], current_time, tombstone_lifetime)"
1463 " -> (num_objects_expunged, num_links_expunged)" },
1464 { "_scavenge_dns_records", (PyCFunction
)py_scavenge_dns_records
,
1465 METH_VARARGS
, NULL
},
1466 { "_dns_delete_tombstones", (PyCFunction
)py_dns_delete_tombstones
,
1467 METH_VARARGS
, NULL
},
1468 { "_dsdb_create_own_rid_set", (PyCFunction
)py_dsdb_create_own_rid_set
, METH_VARARGS
,
1469 "_dsdb_create_own_rid_set(samdb)"
1471 { "_dsdb_allocate_rid", (PyCFunction
)py_dsdb_allocate_rid
, METH_VARARGS
,
1472 "_dsdb_allocate_rid(samdb)"
1474 { "_dsdb_load_udv_v2", (PyCFunction
)py_dsdb_load_udv_v2
, METH_VARARGS
, NULL
},
1478 static struct PyModuleDef moduledef
= {
1479 PyModuleDef_HEAD_INIT
,
1481 .m_doc
= "Python bindings for the directory service databases.",
1483 .m_methods
= py_dsdb_methods
,
1486 MODULE_INIT_FUNC(dsdb
)
1490 m
= PyModule_Create(&moduledef
);
1495 #define ADD_DSDB_FLAG(val) PyModule_AddObject(m, #val, PyInt_FromLong(val))
1497 /* "userAccountControl" flags */
1498 ADD_DSDB_FLAG(UF_NORMAL_ACCOUNT
);
1499 ADD_DSDB_FLAG(UF_TEMP_DUPLICATE_ACCOUNT
);
1500 ADD_DSDB_FLAG(UF_SERVER_TRUST_ACCOUNT
);
1501 ADD_DSDB_FLAG(UF_WORKSTATION_TRUST_ACCOUNT
);
1502 ADD_DSDB_FLAG(UF_INTERDOMAIN_TRUST_ACCOUNT
);
1503 ADD_DSDB_FLAG(UF_PASSWD_NOTREQD
);
1504 ADD_DSDB_FLAG(UF_ACCOUNTDISABLE
);
1506 ADD_DSDB_FLAG(UF_SCRIPT
);
1507 ADD_DSDB_FLAG(UF_ACCOUNTDISABLE
);
1508 ADD_DSDB_FLAG(UF_00000004
);
1509 ADD_DSDB_FLAG(UF_HOMEDIR_REQUIRED
);
1510 ADD_DSDB_FLAG(UF_LOCKOUT
);
1511 ADD_DSDB_FLAG(UF_PASSWD_NOTREQD
);
1512 ADD_DSDB_FLAG(UF_PASSWD_CANT_CHANGE
);
1513 ADD_DSDB_FLAG(UF_ENCRYPTED_TEXT_PASSWORD_ALLOWED
);
1514 ADD_DSDB_FLAG(UF_TEMP_DUPLICATE_ACCOUNT
);
1515 ADD_DSDB_FLAG(UF_NORMAL_ACCOUNT
);
1516 ADD_DSDB_FLAG(UF_00000400
);
1517 ADD_DSDB_FLAG(UF_INTERDOMAIN_TRUST_ACCOUNT
);
1518 ADD_DSDB_FLAG(UF_WORKSTATION_TRUST_ACCOUNT
);
1519 ADD_DSDB_FLAG(UF_SERVER_TRUST_ACCOUNT
);
1520 ADD_DSDB_FLAG(UF_00004000
);
1521 ADD_DSDB_FLAG(UF_00008000
);
1522 ADD_DSDB_FLAG(UF_DONT_EXPIRE_PASSWD
);
1523 ADD_DSDB_FLAG(UF_MNS_LOGON_ACCOUNT
);
1524 ADD_DSDB_FLAG(UF_SMARTCARD_REQUIRED
);
1525 ADD_DSDB_FLAG(UF_TRUSTED_FOR_DELEGATION
);
1526 ADD_DSDB_FLAG(UF_NOT_DELEGATED
);
1527 ADD_DSDB_FLAG(UF_USE_DES_KEY_ONLY
);
1528 ADD_DSDB_FLAG(UF_DONT_REQUIRE_PREAUTH
);
1529 ADD_DSDB_FLAG(UF_PASSWORD_EXPIRED
);
1530 ADD_DSDB_FLAG(UF_TRUSTED_TO_AUTHENTICATE_FOR_DELEGATION
);
1531 ADD_DSDB_FLAG(UF_NO_AUTH_DATA_REQUIRED
);
1532 ADD_DSDB_FLAG(UF_PARTIAL_SECRETS_ACCOUNT
);
1533 ADD_DSDB_FLAG(UF_USE_AES_KEYS
);
1535 /* groupType flags */
1536 ADD_DSDB_FLAG(GTYPE_SECURITY_BUILTIN_LOCAL_GROUP
);
1537 ADD_DSDB_FLAG(GTYPE_SECURITY_GLOBAL_GROUP
);
1538 ADD_DSDB_FLAG(GTYPE_SECURITY_DOMAIN_LOCAL_GROUP
);
1539 ADD_DSDB_FLAG(GTYPE_SECURITY_UNIVERSAL_GROUP
);
1540 ADD_DSDB_FLAG(GTYPE_DISTRIBUTION_GLOBAL_GROUP
);
1541 ADD_DSDB_FLAG(GTYPE_DISTRIBUTION_DOMAIN_LOCAL_GROUP
);
1542 ADD_DSDB_FLAG(GTYPE_DISTRIBUTION_UNIVERSAL_GROUP
);
1544 /* "sAMAccountType" flags */
1545 ADD_DSDB_FLAG(ATYPE_NORMAL_ACCOUNT
);
1546 ADD_DSDB_FLAG(ATYPE_WORKSTATION_TRUST
);
1547 ADD_DSDB_FLAG(ATYPE_INTERDOMAIN_TRUST
);
1548 ADD_DSDB_FLAG(ATYPE_SECURITY_GLOBAL_GROUP
);
1549 ADD_DSDB_FLAG(ATYPE_SECURITY_LOCAL_GROUP
);
1550 ADD_DSDB_FLAG(ATYPE_SECURITY_UNIVERSAL_GROUP
);
1551 ADD_DSDB_FLAG(ATYPE_DISTRIBUTION_GLOBAL_GROUP
);
1552 ADD_DSDB_FLAG(ATYPE_DISTRIBUTION_LOCAL_GROUP
);
1553 ADD_DSDB_FLAG(ATYPE_DISTRIBUTION_UNIVERSAL_GROUP
);
1555 /* "domainFunctionality", "forestFunctionality" flags in the rootDSE */
1556 ADD_DSDB_FLAG(DS_DOMAIN_FUNCTION_2000
);
1557 ADD_DSDB_FLAG(DS_DOMAIN_FUNCTION_2003_MIXED
);
1558 ADD_DSDB_FLAG(DS_DOMAIN_FUNCTION_2003
);
1559 ADD_DSDB_FLAG(DS_DOMAIN_FUNCTION_2008
);
1560 ADD_DSDB_FLAG(DS_DOMAIN_FUNCTION_2008_R2
);
1561 ADD_DSDB_FLAG(DS_DOMAIN_FUNCTION_2012
);
1562 ADD_DSDB_FLAG(DS_DOMAIN_FUNCTION_2012_R2
);
1563 ADD_DSDB_FLAG(DS_DOMAIN_FUNCTION_2016
);
1565 /* nc replica flags */
1566 ADD_DSDB_FLAG(INSTANCE_TYPE_IS_NC_HEAD
);
1567 ADD_DSDB_FLAG(INSTANCE_TYPE_UNINSTANT
);
1568 ADD_DSDB_FLAG(INSTANCE_TYPE_WRITE
);
1569 ADD_DSDB_FLAG(INSTANCE_TYPE_NC_ABOVE
);
1570 ADD_DSDB_FLAG(INSTANCE_TYPE_NC_COMING
);
1571 ADD_DSDB_FLAG(INSTANCE_TYPE_NC_GOING
);
1574 ADD_DSDB_FLAG(SYSTEM_FLAG_CR_NTDS_NC
);
1575 ADD_DSDB_FLAG(SYSTEM_FLAG_CR_NTDS_DOMAIN
);
1576 ADD_DSDB_FLAG(SYSTEM_FLAG_CR_NTDS_NOT_GC_REPLICATED
);
1577 ADD_DSDB_FLAG(SYSTEM_FLAG_SCHEMA_BASE_OBJECT
);
1578 ADD_DSDB_FLAG(SYSTEM_FLAG_ATTR_IS_RDN
);
1579 ADD_DSDB_FLAG(SYSTEM_FLAG_DISALLOW_MOVE_ON_DELETE
);
1580 ADD_DSDB_FLAG(SYSTEM_FLAG_DOMAIN_DISALLOW_MOVE
);
1581 ADD_DSDB_FLAG(SYSTEM_FLAG_DOMAIN_DISALLOW_RENAME
);
1582 ADD_DSDB_FLAG(SYSTEM_FLAG_CONFIG_ALLOW_LIMITED_MOVE
);
1583 ADD_DSDB_FLAG(SYSTEM_FLAG_CONFIG_ALLOW_MOVE
);
1584 ADD_DSDB_FLAG(SYSTEM_FLAG_CONFIG_ALLOW_RENAME
);
1585 ADD_DSDB_FLAG(SYSTEM_FLAG_DISALLOW_DELETE
);
1587 /* Kerberos encryption type constants */
1588 ADD_DSDB_FLAG(ENC_ALL_TYPES
);
1589 ADD_DSDB_FLAG(ENC_CRC32
);
1590 ADD_DSDB_FLAG(ENC_RSA_MD5
);
1591 ADD_DSDB_FLAG(ENC_RC4_HMAC_MD5
);
1592 ADD_DSDB_FLAG(ENC_HMAC_SHA1_96_AES128
);
1593 ADD_DSDB_FLAG(ENC_HMAC_SHA1_96_AES256
);
1595 ADD_DSDB_FLAG(SEARCH_FLAG_ATTINDEX
);
1596 ADD_DSDB_FLAG(SEARCH_FLAG_PDNTATTINDEX
);
1597 ADD_DSDB_FLAG(SEARCH_FLAG_ANR
);
1598 ADD_DSDB_FLAG(SEARCH_FLAG_PRESERVEONDELETE
);
1599 ADD_DSDB_FLAG(SEARCH_FLAG_COPY
);
1600 ADD_DSDB_FLAG(SEARCH_FLAG_TUPLEINDEX
);
1601 ADD_DSDB_FLAG(SEARCH_FLAG_SUBTREEATTRINDEX
);
1602 ADD_DSDB_FLAG(SEARCH_FLAG_CONFIDENTIAL
);
1603 ADD_DSDB_FLAG(SEARCH_FLAG_NEVERVALUEAUDIT
);
1604 ADD_DSDB_FLAG(SEARCH_FLAG_RODC_ATTRIBUTE
);
1606 ADD_DSDB_FLAG(DS_FLAG_ATTR_NOT_REPLICATED
);
1607 ADD_DSDB_FLAG(DS_FLAG_ATTR_REQ_PARTIAL_SET_MEMBER
);
1608 ADD_DSDB_FLAG(DS_FLAG_ATTR_IS_CONSTRUCTED
);
1610 ADD_DSDB_FLAG(DS_NTDSSETTINGS_OPT_IS_AUTO_TOPOLOGY_DISABLED
);
1611 ADD_DSDB_FLAG(DS_NTDSSETTINGS_OPT_IS_TOPL_CLEANUP_DISABLED
);
1612 ADD_DSDB_FLAG(DS_NTDSSETTINGS_OPT_IS_TOPL_MIN_HOPS_DISABLED
);
1613 ADD_DSDB_FLAG(DS_NTDSSETTINGS_OPT_IS_TOPL_DETECT_STALE_DISABLED
);
1614 ADD_DSDB_FLAG(DS_NTDSSETTINGS_OPT_IS_INTER_SITE_AUTO_TOPOLOGY_DISABLED
);
1615 ADD_DSDB_FLAG(DS_NTDSSETTINGS_OPT_IS_GROUP_CACHING_ENABLED
);
1616 ADD_DSDB_FLAG(DS_NTDSSETTINGS_OPT_FORCE_KCC_WHISTLER_BEHAVIOR
);
1617 ADD_DSDB_FLAG(DS_NTDSSETTINGS_OPT_IS_RAND_BH_SELECTION_DISABLED
);
1618 ADD_DSDB_FLAG(DS_NTDSSETTINGS_OPT_IS_SCHEDULE_HASHING_ENABLED
);
1619 ADD_DSDB_FLAG(DS_NTDSSETTINGS_OPT_IS_REDUNDANT_SERVER_TOPOLOGY_ENABLED
);
1621 ADD_DSDB_FLAG(DS_NTDSDSA_OPT_IS_GC
);
1622 ADD_DSDB_FLAG(DS_NTDSDSA_OPT_DISABLE_INBOUND_REPL
);
1623 ADD_DSDB_FLAG(DS_NTDSDSA_OPT_DISABLE_OUTBOUND_REPL
);
1624 ADD_DSDB_FLAG(DS_NTDSDSA_OPT_DISABLE_NTDSCONN_XLATE
);
1625 ADD_DSDB_FLAG(DS_NTDSDSA_OPT_DISABLE_SPN_REGISTRATION
);
1627 ADD_DSDB_FLAG(NTDSCONN_KCC_GC_TOPOLOGY
);
1628 ADD_DSDB_FLAG(NTDSCONN_KCC_RING_TOPOLOGY
);
1629 ADD_DSDB_FLAG(NTDSCONN_KCC_MINIMIZE_HOPS_TOPOLOGY
);
1630 ADD_DSDB_FLAG(NTDSCONN_KCC_STALE_SERVERS_TOPOLOGY
);
1631 ADD_DSDB_FLAG(NTDSCONN_KCC_OSCILLATING_CONNECTION_TOPOLOGY
);
1632 ADD_DSDB_FLAG(NTDSCONN_KCC_INTERSITE_GC_TOPOLOGY
);
1633 ADD_DSDB_FLAG(NTDSCONN_KCC_INTERSITE_TOPOLOGY
);
1634 ADD_DSDB_FLAG(NTDSCONN_KCC_SERVER_FAILOVER_TOPOLOGY
);
1635 ADD_DSDB_FLAG(NTDSCONN_KCC_SITE_FAILOVER_TOPOLOGY
);
1636 ADD_DSDB_FLAG(NTDSCONN_KCC_REDUNDANT_SERVER_TOPOLOGY
);
1638 ADD_DSDB_FLAG(NTDSCONN_OPT_IS_GENERATED
);
1639 ADD_DSDB_FLAG(NTDSCONN_OPT_TWOWAY_SYNC
);
1640 ADD_DSDB_FLAG(NTDSCONN_OPT_OVERRIDE_NOTIFY_DEFAULT
);
1641 ADD_DSDB_FLAG(NTDSCONN_OPT_USE_NOTIFY
);
1642 ADD_DSDB_FLAG(NTDSCONN_OPT_DISABLE_INTERSITE_COMPRESSION
);
1643 ADD_DSDB_FLAG(NTDSCONN_OPT_USER_OWNED_SCHEDULE
);
1644 ADD_DSDB_FLAG(NTDSCONN_OPT_RODC_TOPOLOGY
);
1646 /* Site Link Object options */
1647 ADD_DSDB_FLAG(NTDSSITELINK_OPT_USE_NOTIFY
);
1648 ADD_DSDB_FLAG(NTDSSITELINK_OPT_TWOWAY_SYNC
);
1649 ADD_DSDB_FLAG(NTDSSITELINK_OPT_DISABLE_COMPRESSION
);
1651 /* GPO policy flags */
1652 ADD_DSDB_FLAG(GPLINK_OPT_DISABLE
);
1653 ADD_DSDB_FLAG(GPLINK_OPT_ENFORCE
);
1654 ADD_DSDB_FLAG(GPO_FLAG_USER_DISABLE
);
1655 ADD_DSDB_FLAG(GPO_FLAG_MACHINE_DISABLE
);
1656 ADD_DSDB_FLAG(GPO_INHERIT
);
1657 ADD_DSDB_FLAG(GPO_BLOCK_INHERITANCE
);
1659 #define ADD_DSDB_STRING(val) PyModule_AddObject(m, #val, PyStr_FromString(val))
1661 ADD_DSDB_STRING(DSDB_SYNTAX_BINARY_DN
);
1662 ADD_DSDB_STRING(DSDB_SYNTAX_STRING_DN
);
1663 ADD_DSDB_STRING(DSDB_SYNTAX_OR_NAME
);
1664 ADD_DSDB_STRING(DSDB_CONTROL_DBCHECK
);
1665 ADD_DSDB_STRING(DSDB_CONTROL_DBCHECK_MODIFY_RO_REPLICA
);
1666 ADD_DSDB_STRING(DSDB_CONTROL_DBCHECK_FIX_DUPLICATE_LINKS
);
1667 ADD_DSDB_STRING(DSDB_CONTROL_DBCHECK_FIX_LINK_DN_NAME
);
1668 ADD_DSDB_STRING(DSDB_CONTROL_DBCHECK_FIX_LINK_DN_SID
);
1669 ADD_DSDB_STRING(DSDB_CONTROL_REPLMD_VANISH_LINKS
);
1670 ADD_DSDB_STRING(DSDB_CONTROL_PERMIT_INTERDOMAIN_TRUST_UAC_OID
);
1671 ADD_DSDB_STRING(DSDB_CONTROL_SKIP_DUPLICATES_CHECK_OID
);
1672 ADD_DSDB_STRING(DSDB_CONTROL_BYPASS_PASSWORD_HASH_OID
);
1673 ADD_DSDB_STRING(DSDB_CONTROL_INVALID_NOT_IMPLEMENTED
);
1675 ADD_DSDB_STRING(DS_GUID_COMPUTERS_CONTAINER
);
1676 ADD_DSDB_STRING(DS_GUID_DELETED_OBJECTS_CONTAINER
);
1677 ADD_DSDB_STRING(DS_GUID_DOMAIN_CONTROLLERS_CONTAINER
);
1678 ADD_DSDB_STRING(DS_GUID_FOREIGNSECURITYPRINCIPALS_CONTAINER
);
1679 ADD_DSDB_STRING(DS_GUID_INFRASTRUCTURE_CONTAINER
);
1680 ADD_DSDB_STRING(DS_GUID_LOSTANDFOUND_CONTAINER
);
1681 ADD_DSDB_STRING(DS_GUID_MICROSOFT_PROGRAM_DATA_CONTAINER
);
1682 ADD_DSDB_STRING(DS_GUID_NTDS_QUOTAS_CONTAINER
);
1683 ADD_DSDB_STRING(DS_GUID_PROGRAM_DATA_CONTAINER
);
1684 ADD_DSDB_STRING(DS_GUID_SYSTEMS_CONTAINER
);
1685 ADD_DSDB_STRING(DS_GUID_USERS_CONTAINER
);