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/>.
24 #include "dsdb/samdb/samdb.h"
25 #include "libcli/security/security.h"
26 #include "librpc/ndr/libndr.h"
27 #include "system/kerberos.h"
28 #include "auth/kerberos/kerberos.h"
29 #include "librpc/rpc/pyrpc_util.h"
30 #include "lib/policy/policy.h"
34 /* There's no Py_ssize_t in 2.4, apparently */
35 #if PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION < 5
36 typedef int Py_ssize_t;
37 typedef inquiry lenfunc;
38 typedef intargfunc ssizeargfunc;
41 /* FIXME: These should be in a header file somewhere, once we finish moving
42 * away from SWIG .. */
43 #define PyErr_LDB_OR_RAISE(py_ldb, ldb) \
44 /* if (!PyLdb_Check(py_ldb)) { \
45 PyErr_SetString(py_ldb_get_exception(), "Ldb connection object required"); \
48 ldb = PyLdb_AsLdbContext(py_ldb);
50 static PyObject *py_ldb_get_exception(void)
52 PyObject *mod = PyImport_ImportModule("ldb");
56 return PyObject_GetAttrString(mod, "LdbError");
59 static void PyErr_SetLdbError(PyObject *error, int ret, struct ldb_context *ldb_ctx)
61 if (ret == LDB_ERR_PYTHON_EXCEPTION)
62 return; /* Python exception should already be set, just keep that */
64 PyErr_SetObject(error,
65 Py_BuildValue(discard_const_p(char, "(i,s)"), ret,
66 ldb_ctx == NULL?ldb_strerror(ret):ldb_errstring(ldb_ctx)));
69 static PyObject *py_samdb_server_site_name(PyObject *self, PyObject *args)
71 PyObject *py_ldb, *result;
72 struct ldb_context *ldb;
76 if (!PyArg_ParseTuple(args, "O", &py_ldb))
79 PyErr_LDB_OR_RAISE(py_ldb, ldb);
81 mem_ctx = talloc_new(NULL);
82 if (mem_ctx == NULL) {
87 site = samdb_server_site_name(ldb, mem_ctx);
89 PyErr_SetString(PyExc_RuntimeError, "Failed to find server site");
94 result = PyString_FromString(site);
99 static PyObject *py_dsdb_convert_schema_to_openldap(PyObject *self,
102 char *target_str, *mapping;
104 struct ldb_context *ldb;
108 if (!PyArg_ParseTuple(args, "Oss", &py_ldb, &target_str, &mapping))
111 PyErr_LDB_OR_RAISE(py_ldb, ldb);
113 retstr = dsdb_convert_schema_to_openldap(ldb, target_str, mapping);
114 if (retstr == NULL) {
115 PyErr_SetString(PyExc_RuntimeError,
116 "dsdb_convert_schema_to_openldap failed");
120 ret = PyString_FromString(retstr);
125 static PyObject *py_samdb_set_domain_sid(PyLdbObject *self, PyObject *args)
127 PyObject *py_ldb, *py_sid;
128 struct ldb_context *ldb;
132 if (!PyArg_ParseTuple(args, "OO", &py_ldb, &py_sid))
135 PyErr_LDB_OR_RAISE(py_ldb, ldb);
137 sid = dom_sid_parse_talloc(NULL, PyString_AsString(py_sid));
143 ret = samdb_set_domain_sid(ldb, sid);
146 PyErr_SetString(PyExc_RuntimeError, "set_domain_sid failed");
152 static PyObject *py_samdb_set_ntds_settings_dn(PyLdbObject *self, PyObject *args)
154 PyObject *py_ldb, *py_ntds_settings_dn;
155 struct ldb_context *ldb;
156 struct ldb_dn *ntds_settings_dn;
160 if (!PyArg_ParseTuple(args, "OO", &py_ldb, &py_ntds_settings_dn))
163 PyErr_LDB_OR_RAISE(py_ldb, ldb);
165 tmp_ctx = talloc_new(NULL);
166 if (tmp_ctx == NULL) {
171 if (!PyObject_AsDn(tmp_ctx, py_ntds_settings_dn, ldb, &ntds_settings_dn)) {
172 /* exception thrown by "PyObject_AsDn" */
173 talloc_free(tmp_ctx);
177 ret = samdb_set_ntds_settings_dn(ldb, ntds_settings_dn);
178 talloc_free(tmp_ctx);
180 PyErr_SetString(PyExc_RuntimeError, "set_ntds_settings_dn failed");
186 static PyObject *py_samdb_get_domain_sid(PyLdbObject *self, PyObject *args)
189 struct ldb_context *ldb;
190 const struct dom_sid *sid;
194 if (!PyArg_ParseTuple(args, "O", &py_ldb))
197 PyErr_LDB_OR_RAISE(py_ldb, ldb);
199 sid = samdb_domain_sid(ldb);
201 PyErr_SetString(PyExc_RuntimeError, "samdb_domain_sid failed");
205 retstr = dom_sid_string(NULL, sid);
206 if (retstr == NULL) {
210 ret = PyString_FromString(retstr);
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 = PyString_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 = PyString_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_RuntimeError, "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 attribute syntax oid as a string from the attribute name
336 static PyObject *py_dsdb_get_syntax_oid_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_RuntimeError, "Failed to find attribute '%s'", ldap_display_name);
362 return PyString_FromString(attribute->syntax->ldap_oid);
366 convert a python string to a DRSUAPI drsuapi_DsReplicaAttribute attribute
368 static PyObject *py_dsdb_DsReplicaAttribute(PyObject *self, PyObject *args)
370 PyObject *py_ldb, *el_list, *ret;
371 struct ldb_context *ldb;
372 char *ldap_display_name;
373 const struct dsdb_attribute *a;
374 struct dsdb_schema *schema;
375 struct dsdb_syntax_ctx syntax_ctx;
376 struct ldb_message_element *el;
377 struct drsuapi_DsReplicaAttribute *attr;
382 if (!PyArg_ParseTuple(args, "OsO", &py_ldb, &ldap_display_name, &el_list)) {
386 PyErr_LDB_OR_RAISE(py_ldb, ldb);
388 if (!PyList_Check(el_list)) {
389 PyErr_Format(PyExc_TypeError, "ldif_elements must be a list");
393 schema = dsdb_get_schema(ldb, NULL);
395 PyErr_SetString(PyExc_RuntimeError, "Failed to find a schema from ldb");
399 a = dsdb_attribute_by_lDAPDisplayName(schema, ldap_display_name);
401 PyErr_Format(PyExc_RuntimeError, "Failed to find attribute '%s'", ldap_display_name);
405 dsdb_syntax_ctx_init(&syntax_ctx, ldb, schema);
406 syntax_ctx.is_schema_nc = false;
408 tmp_ctx = talloc_new(ldb);
409 if (tmp_ctx == NULL) {
414 el = talloc_zero(tmp_ctx, struct ldb_message_element);
417 talloc_free(tmp_ctx);
421 el->name = ldap_display_name;
422 el->num_values = PyList_Size(el_list);
424 el->values = talloc_array(el, struct ldb_val, el->num_values);
425 if (el->values == NULL) {
427 talloc_free(tmp_ctx);
431 for (i = 0; i < el->num_values; i++) {
432 PyObject *item = PyList_GetItem(el_list, i);
433 if (!PyString_Check(item)) {
434 PyErr_Format(PyExc_TypeError, "ldif_elements should be strings");
437 el->values[i].data = (uint8_t *)PyString_AsString(item);
438 el->values[i].length = PyString_Size(item);
441 attr = talloc_zero(tmp_ctx, struct drsuapi_DsReplicaAttribute);
444 talloc_free(tmp_ctx);
448 werr = a->syntax->ldb_to_drsuapi(&syntax_ctx, a, el, attr, attr);
449 PyErr_WERROR_IS_ERR_RAISE(werr);
451 ret = py_return_ndr_struct("samba.dcerpc.drsuapi", "DsReplicaAttribute", attr, attr);
453 talloc_free(tmp_ctx);
460 normalise a ldb attribute list
462 static PyObject *py_dsdb_normalise_attributes(PyObject *self, PyObject *args)
464 PyObject *py_ldb, *el_list, *ret;
465 struct ldb_context *ldb;
466 char *ldap_display_name;
467 const struct dsdb_attribute *a;
468 struct dsdb_schema *schema;
469 struct dsdb_syntax_ctx syntax_ctx;
470 struct ldb_message_element *el;
471 struct drsuapi_DsReplicaAttribute *attr;
476 if (!PyArg_ParseTuple(args, "OsO", &py_ldb, &ldap_display_name, &el_list)) {
480 PyErr_LDB_OR_RAISE(py_ldb, ldb);
482 if (!PyList_Check(el_list)) {
483 PyErr_Format(PyExc_TypeError, "ldif_elements must be a list");
487 schema = dsdb_get_schema(ldb, NULL);
489 PyErr_SetString(PyExc_RuntimeError, "Failed to find a schema from ldb");
493 a = dsdb_attribute_by_lDAPDisplayName(schema, ldap_display_name);
495 PyErr_Format(PyExc_RuntimeError, "Failed to find attribute '%s'", ldap_display_name);
499 dsdb_syntax_ctx_init(&syntax_ctx, ldb, schema);
500 syntax_ctx.is_schema_nc = false;
502 tmp_ctx = talloc_new(ldb);
503 if (tmp_ctx == NULL) {
508 el = talloc_zero(tmp_ctx, struct ldb_message_element);
511 talloc_free(tmp_ctx);
515 el->name = ldap_display_name;
516 el->num_values = PyList_Size(el_list);
518 el->values = talloc_array(el, struct ldb_val, el->num_values);
519 if (el->values == NULL) {
521 talloc_free(tmp_ctx);
525 for (i = 0; i < el->num_values; i++) {
526 PyObject *item = PyList_GetItem(el_list, i);
527 if (!PyString_Check(item)) {
528 PyErr_Format(PyExc_TypeError, "ldif_elements should be strings");
531 el->values[i].data = (uint8_t *)PyString_AsString(item);
532 el->values[i].length = PyString_Size(item);
535 /* first run ldb_to_drsuapi, then convert back again. This has
536 * the effect of normalising the attributes
539 attr = talloc_zero(tmp_ctx, struct drsuapi_DsReplicaAttribute);
542 talloc_free(tmp_ctx);
546 werr = a->syntax->ldb_to_drsuapi(&syntax_ctx, a, el, attr, attr);
547 PyErr_WERROR_IS_ERR_RAISE(werr);
549 /* now convert back again */
550 werr = a->syntax->drsuapi_to_ldb(&syntax_ctx, a, attr, el, el);
551 PyErr_WERROR_IS_ERR_RAISE(werr);
553 ret = py_return_ndr_struct("ldb", "MessageElement", el, el);
555 talloc_free(tmp_ctx);
561 static PyObject *py_dsdb_set_ntds_invocation_id(PyObject *self, PyObject *args)
563 PyObject *py_ldb, *py_guid;
566 struct ldb_context *ldb;
567 if (!PyArg_ParseTuple(args, "OO", &py_ldb, &py_guid))
570 PyErr_LDB_OR_RAISE(py_ldb, ldb);
571 GUID_from_string(PyString_AsString(py_guid), &guid);
573 ret = samdb_set_ntds_invocation_id(ldb, &guid);
575 PyErr_SetString(PyExc_RuntimeError, "set_ntds_invocation_id failed");
581 static PyObject *py_samdb_ntds_objectGUID(PyObject *self, PyObject *args)
583 PyObject *py_ldb, *result;
584 struct ldb_context *ldb;
585 const struct GUID *guid;
588 if (!PyArg_ParseTuple(args, "O", &py_ldb)) {
592 PyErr_LDB_OR_RAISE(py_ldb, ldb);
594 guid = samdb_ntds_objectGUID(ldb);
596 PyErr_SetString(PyExc_RuntimeError, "Failed to find NTDS GUID");
600 retstr = GUID_string(NULL, guid);
601 if (retstr == NULL) {
605 result = PyString_FromString(retstr);
610 static PyObject *py_dsdb_set_global_schema(PyObject *self, PyObject *args)
613 struct ldb_context *ldb;
615 if (!PyArg_ParseTuple(args, "O", &py_ldb))
618 PyErr_LDB_OR_RAISE(py_ldb, ldb);
620 ret = dsdb_set_global_schema(ldb);
621 PyErr_LDB_ERROR_IS_ERR_RAISE(py_ldb_get_exception(), ret, ldb);
626 static PyObject *py_dsdb_load_partition_usn(PyObject *self, PyObject *args)
628 PyObject *py_dn, *py_ldb, *result;
630 uint64_t highest_uSN, urgent_uSN;
631 struct ldb_context *ldb;
635 if (!PyArg_ParseTuple(args, "OO", &py_ldb, &py_dn)) {
639 PyErr_LDB_OR_RAISE(py_ldb, ldb);
641 mem_ctx = talloc_new(NULL);
642 if (mem_ctx == NULL) {
647 if (!PyObject_AsDn(mem_ctx, py_dn, ldb, &dn)) {
648 talloc_free(mem_ctx);
652 ret = dsdb_load_partition_usn(ldb, dn, &highest_uSN, &urgent_uSN);
653 if (ret != LDB_SUCCESS) {
654 PyErr_Format(PyExc_RuntimeError,
655 "Failed to load partition [%s] uSN - %s",
656 ldb_dn_get_linearized(dn),
658 talloc_free(mem_ctx);
662 talloc_free(mem_ctx);
664 result = PyDict_New();
666 PyDict_SetItemString(result, "uSNHighest", PyInt_FromLong((uint64_t)highest_uSN));
667 PyDict_SetItemString(result, "uSNUrgent", PyInt_FromLong((uint64_t)urgent_uSN));
673 static PyObject *py_dsdb_set_am_rodc(PyObject *self, PyObject *args)
677 struct ldb_context *ldb;
680 if (!PyArg_ParseTuple(args, "Oi", &py_ldb, &py_val))
683 PyErr_LDB_OR_RAISE(py_ldb, ldb);
684 ret = samdb_set_am_rodc(ldb, (bool)py_val);
686 PyErr_SetString(PyExc_RuntimeError, "set_am_rodc failed");
692 static PyObject *py_dsdb_set_schema_from_ldif(PyObject *self, PyObject *args)
697 struct ldb_context *ldb;
699 if (!PyArg_ParseTuple(args, "Oss", &py_ldb, &pf, &df))
702 PyErr_LDB_OR_RAISE(py_ldb, ldb);
704 result = dsdb_set_schema_from_ldif(ldb, pf, df);
705 PyErr_WERROR_IS_ERR_RAISE(result);
710 static PyObject *py_dsdb_set_schema_from_ldb(PyObject *self, PyObject *args)
713 struct ldb_context *ldb;
714 PyObject *py_from_ldb;
715 struct ldb_context *from_ldb;
716 struct dsdb_schema *schema;
718 if (!PyArg_ParseTuple(args, "OO", &py_ldb, &py_from_ldb))
721 PyErr_LDB_OR_RAISE(py_ldb, ldb);
723 PyErr_LDB_OR_RAISE(py_from_ldb, from_ldb);
725 schema = dsdb_get_schema(from_ldb, NULL);
727 PyErr_SetString(PyExc_RuntimeError, "Failed to set find a schema on 'from' ldb!\n");
731 ret = dsdb_reference_schema(ldb, schema, true);
732 PyErr_LDB_ERROR_IS_ERR_RAISE(py_ldb_get_exception(), ret, ldb);
737 static PyObject *py_dsdb_write_prefixes_from_schema_to_ldb(PyObject *self, PyObject *args)
740 struct ldb_context *ldb;
742 struct dsdb_schema *schema;
744 if (!PyArg_ParseTuple(args, "O", &py_ldb))
747 PyErr_LDB_OR_RAISE(py_ldb, ldb);
749 schema = dsdb_get_schema(ldb, NULL);
751 PyErr_SetString(PyExc_RuntimeError, "Failed to set find a schema on ldb!\n");
755 result = dsdb_write_prefixes_from_schema_to_ldb(NULL, ldb, schema);
756 PyErr_WERROR_IS_ERR_RAISE(result);
762 static PyObject *py_dsdb_get_partitions_dn(PyObject *self, PyObject *args)
764 struct ldb_context *ldb;
766 PyObject *py_ldb, *ret;
769 mod = PyImport_ImportModule("ldb");
771 if (!PyArg_ParseTuple(args, "O", &py_ldb))
774 PyErr_LDB_OR_RAISE(py_ldb, ldb);
776 dn = samdb_partitions_dn(ldb, NULL);
781 ret = PyLdbDn_FromDn(dn);
788 call into samdb_rodc()
790 static PyObject *py_dsdb_am_rodc(PyObject *self, PyObject *args)
793 struct ldb_context *ldb;
797 if (!PyArg_ParseTuple(args, "O", &py_ldb))
800 PyErr_LDB_OR_RAISE(py_ldb, ldb);
802 ret = samdb_rodc(ldb, &am_rodc);
803 if (ret != LDB_SUCCESS) {
804 PyErr_SetString(PyExc_RuntimeError, ldb_errstring(ldb));
808 return PyBool_FromLong(am_rodc);
812 static PyMethodDef py_dsdb_methods[] = {
813 { "_samdb_server_site_name", (PyCFunction)py_samdb_server_site_name,
814 METH_VARARGS, "Get the server site name as a string"},
815 { "_dsdb_convert_schema_to_openldap",
816 (PyCFunction)py_dsdb_convert_schema_to_openldap, METH_VARARGS,
817 "dsdb_convert_schema_to_openldap(ldb, target_str, mapping) -> str\n"
818 "Create an OpenLDAP schema from a schema." },
819 { "_samdb_set_domain_sid", (PyCFunction)py_samdb_set_domain_sid,
821 "samdb_set_domain_sid(samdb, sid)\n"
822 "Set SID of domain to use." },
823 { "_samdb_get_domain_sid", (PyCFunction)py_samdb_get_domain_sid,
825 "samdb_get_domain_sid(samdb)\n"
826 "Get SID of domain in use." },
827 { "_samdb_ntds_invocation_id", (PyCFunction)py_samdb_ntds_invocation_id,
828 METH_VARARGS, "get the NTDS invocation ID GUID as a string"},
829 { "_samdb_set_ntds_settings_dn", (PyCFunction)py_samdb_set_ntds_settings_dn,
831 "samdb_set_ntds_settings_dn(samdb, ntds_settings_dn)\n"
832 "Set NTDS Settings DN for this LDB (allows it to be set before the DB fully exists)." },
833 { "_dsdb_get_oid_from_attid", (PyCFunction)py_dsdb_get_oid_from_attid,
834 METH_VARARGS, NULL },
835 { "_dsdb_get_attid_from_lDAPDisplayName", (PyCFunction)py_dsdb_get_attid_from_lDAPDisplayName,
836 METH_VARARGS, NULL },
837 { "_dsdb_get_syntax_oid_from_lDAPDisplayName", (PyCFunction)py_dsdb_get_syntax_oid_from_lDAPDisplayName,
838 METH_VARARGS, NULL },
839 { "_dsdb_set_ntds_invocation_id",
840 (PyCFunction)py_dsdb_set_ntds_invocation_id, METH_VARARGS,
842 { "_samdb_ntds_objectGUID", (PyCFunction)py_samdb_ntds_objectGUID,
843 METH_VARARGS, "get the NTDS objectGUID as a string"},
844 { "_dsdb_set_global_schema", (PyCFunction)py_dsdb_set_global_schema,
845 METH_VARARGS, NULL },
846 { "_dsdb_load_partition_usn", (PyCFunction)py_dsdb_load_partition_usn,
848 "get uSNHighest and uSNUrgent from the partition @REPLCHANGED"},
849 { "_dsdb_set_am_rodc",
850 (PyCFunction)py_dsdb_set_am_rodc, METH_VARARGS,
853 (PyCFunction)py_dsdb_am_rodc, METH_VARARGS,
855 { "_dsdb_set_schema_from_ldif", (PyCFunction)py_dsdb_set_schema_from_ldif, METH_VARARGS,
857 { "_dsdb_set_schema_from_ldb", (PyCFunction)py_dsdb_set_schema_from_ldb, METH_VARARGS,
859 { "_dsdb_write_prefixes_from_schema_to_ldb", (PyCFunction)py_dsdb_write_prefixes_from_schema_to_ldb, METH_VARARGS,
861 { "_dsdb_get_partitions_dn", (PyCFunction)py_dsdb_get_partitions_dn, METH_VARARGS, NULL },
862 { "_dsdb_DsReplicaAttribute", (PyCFunction)py_dsdb_DsReplicaAttribute, METH_VARARGS, NULL },
863 { "_dsdb_normalise_attributes", (PyCFunction)py_dsdb_normalise_attributes, METH_VARARGS, NULL },
871 m = Py_InitModule3("dsdb", py_dsdb_methods,
872 "Python bindings for the directory service databases.");
876 #define ADD_DSDB_FLAG(val) PyModule_AddObject(m, #val, PyInt_FromLong(val))
878 /* "userAccountControl" flags */
879 ADD_DSDB_FLAG(UF_NORMAL_ACCOUNT);
880 ADD_DSDB_FLAG(UF_TEMP_DUPLICATE_ACCOUNT);
881 ADD_DSDB_FLAG(UF_SERVER_TRUST_ACCOUNT);
882 ADD_DSDB_FLAG(UF_WORKSTATION_TRUST_ACCOUNT);
883 ADD_DSDB_FLAG(UF_INTERDOMAIN_TRUST_ACCOUNT);
884 ADD_DSDB_FLAG(UF_PASSWD_NOTREQD);
885 ADD_DSDB_FLAG(UF_ACCOUNTDISABLE);
887 ADD_DSDB_FLAG(UF_SCRIPT);
888 ADD_DSDB_FLAG(UF_ACCOUNTDISABLE);
889 ADD_DSDB_FLAG(UF_00000004);
890 ADD_DSDB_FLAG(UF_HOMEDIR_REQUIRED);
891 ADD_DSDB_FLAG(UF_LOCKOUT);
892 ADD_DSDB_FLAG(UF_PASSWD_NOTREQD);
893 ADD_DSDB_FLAG(UF_PASSWD_CANT_CHANGE);
894 ADD_DSDB_FLAG(UF_ENCRYPTED_TEXT_PASSWORD_ALLOWED);
895 ADD_DSDB_FLAG(UF_TEMP_DUPLICATE_ACCOUNT);
896 ADD_DSDB_FLAG(UF_NORMAL_ACCOUNT);
897 ADD_DSDB_FLAG(UF_00000400);
898 ADD_DSDB_FLAG(UF_INTERDOMAIN_TRUST_ACCOUNT);
899 ADD_DSDB_FLAG(UF_WORKSTATION_TRUST_ACCOUNT);
900 ADD_DSDB_FLAG(UF_SERVER_TRUST_ACCOUNT);
901 ADD_DSDB_FLAG(UF_00004000);
902 ADD_DSDB_FLAG(UF_00008000);
903 ADD_DSDB_FLAG(UF_DONT_EXPIRE_PASSWD);
904 ADD_DSDB_FLAG(UF_MNS_LOGON_ACCOUNT);
905 ADD_DSDB_FLAG(UF_SMARTCARD_REQUIRED);
906 ADD_DSDB_FLAG(UF_TRUSTED_FOR_DELEGATION);
907 ADD_DSDB_FLAG(UF_NOT_DELEGATED);
908 ADD_DSDB_FLAG(UF_USE_DES_KEY_ONLY);
909 ADD_DSDB_FLAG(UF_DONT_REQUIRE_PREAUTH);
910 ADD_DSDB_FLAG(UF_PASSWORD_EXPIRED);
911 ADD_DSDB_FLAG(UF_TRUSTED_TO_AUTHENTICATE_FOR_DELEGATION);
912 ADD_DSDB_FLAG(UF_NO_AUTH_DATA_REQUIRED);
913 ADD_DSDB_FLAG(UF_PARTIAL_SECRETS_ACCOUNT);
915 /* groupType flags */
916 ADD_DSDB_FLAG(GTYPE_SECURITY_BUILTIN_LOCAL_GROUP);
917 ADD_DSDB_FLAG(GTYPE_SECURITY_GLOBAL_GROUP);
918 ADD_DSDB_FLAG(GTYPE_SECURITY_DOMAIN_LOCAL_GROUP);
919 ADD_DSDB_FLAG(GTYPE_SECURITY_UNIVERSAL_GROUP);
920 ADD_DSDB_FLAG(GTYPE_DISTRIBUTION_GLOBAL_GROUP);
921 ADD_DSDB_FLAG(GTYPE_DISTRIBUTION_DOMAIN_LOCAL_GROUP);
922 ADD_DSDB_FLAG(GTYPE_DISTRIBUTION_UNIVERSAL_GROUP);
924 /* "sAMAccountType" flags */
925 ADD_DSDB_FLAG(ATYPE_NORMAL_ACCOUNT);
926 ADD_DSDB_FLAG(ATYPE_WORKSTATION_TRUST);
927 ADD_DSDB_FLAG(ATYPE_INTERDOMAIN_TRUST);
928 ADD_DSDB_FLAG(ATYPE_SECURITY_GLOBAL_GROUP);
929 ADD_DSDB_FLAG(ATYPE_SECURITY_LOCAL_GROUP);
930 ADD_DSDB_FLAG(ATYPE_SECURITY_UNIVERSAL_GROUP);
931 ADD_DSDB_FLAG(ATYPE_DISTRIBUTION_GLOBAL_GROUP);
932 ADD_DSDB_FLAG(ATYPE_DISTRIBUTION_LOCAL_GROUP);
933 ADD_DSDB_FLAG(ATYPE_DISTRIBUTION_UNIVERSAL_GROUP);
935 /* "domainFunctionality", "forestFunctionality" flags in the rootDSE */
936 ADD_DSDB_FLAG(DS_DOMAIN_FUNCTION_2000);
937 ADD_DSDB_FLAG(DS_DOMAIN_FUNCTION_2003_MIXED);
938 ADD_DSDB_FLAG(DS_DOMAIN_FUNCTION_2003);
939 ADD_DSDB_FLAG(DS_DOMAIN_FUNCTION_2008);
940 ADD_DSDB_FLAG(DS_DOMAIN_FUNCTION_2008_R2);
943 ADD_DSDB_FLAG(SYSTEM_FLAG_CR_NTDS_NC);
944 ADD_DSDB_FLAG(SYSTEM_FLAG_CR_NTDS_DOMAIN);
945 ADD_DSDB_FLAG(SYSTEM_FLAG_CR_NTDS_NOT_GC_REPLICATED);
946 ADD_DSDB_FLAG(SYSTEM_FLAG_SCHEMA_BASE_OBJECT);
947 ADD_DSDB_FLAG(SYSTEM_FLAG_ATTR_IS_RDN);
948 ADD_DSDB_FLAG(SYSTEM_FLAG_DISALLOW_MOVE_ON_DELETE);
949 ADD_DSDB_FLAG(SYSTEM_FLAG_DOMAIN_DISALLOW_MOVE);
950 ADD_DSDB_FLAG(SYSTEM_FLAG_DOMAIN_DISALLOW_RENAME);
951 ADD_DSDB_FLAG(SYSTEM_FLAG_CONFIG_ALLOW_LIMITED_MOVE);
952 ADD_DSDB_FLAG(SYSTEM_FLAG_CONFIG_ALLOW_MOVE);
953 ADD_DSDB_FLAG(SYSTEM_FLAG_CONFIG_ALLOW_RENAME);
954 ADD_DSDB_FLAG(SYSTEM_FLAG_DISALLOW_DELETE);
956 /* Kerberos encryption type constants */
957 ADD_DSDB_FLAG(ENC_ALL_TYPES);
958 ADD_DSDB_FLAG(ENC_CRC32);
959 ADD_DSDB_FLAG(ENC_RSA_MD5);
960 ADD_DSDB_FLAG(ENC_RC4_HMAC_MD5);
961 ADD_DSDB_FLAG(ENC_HMAC_SHA1_96_AES128);
962 ADD_DSDB_FLAG(ENC_HMAC_SHA1_96_AES256);
964 ADD_DSDB_FLAG(SEARCH_FLAG_ATTINDEX);
965 ADD_DSDB_FLAG(SEARCH_FLAG_PDNTATTINDEX);
966 ADD_DSDB_FLAG(SEARCH_FLAG_ANR);
967 ADD_DSDB_FLAG(SEARCH_FLAG_PRESERVEONDELETE);
968 ADD_DSDB_FLAG(SEARCH_FLAG_COPY);
969 ADD_DSDB_FLAG(SEARCH_FLAG_TUPLEINDEX);
970 ADD_DSDB_FLAG(SEARCH_FLAG_SUBTREEATTRINDEX);
971 ADD_DSDB_FLAG(SEARCH_FLAG_CONFIDENTIAL);
972 ADD_DSDB_FLAG(SEARCH_FLAG_NEVERVALUEAUDIT);
973 ADD_DSDB_FLAG(SEARCH_FLAG_RODC_ATTRIBUTE);
975 ADD_DSDB_FLAG(DS_FLAG_ATTR_NOT_REPLICATED);
976 ADD_DSDB_FLAG(DS_FLAG_ATTR_REQ_PARTIAL_SET_MEMBER);
977 ADD_DSDB_FLAG(DS_FLAG_ATTR_IS_CONSTRUCTED);
979 ADD_DSDB_FLAG(DS_NTDSDSA_OPT_IS_GC);
980 ADD_DSDB_FLAG(DS_NTDSDSA_OPT_DISABLE_INBOUND_REPL);
981 ADD_DSDB_FLAG(DS_NTDSDSA_OPT_DISABLE_OUTBOUND_REPL);
982 ADD_DSDB_FLAG(DS_NTDSDSA_OPT_DISABLE_NTDSCONN_XLATE);
983 ADD_DSDB_FLAG(DS_NTDSDSA_OPT_DISABLE_SPN_REGISTRATION);
985 ADD_DSDB_FLAG(NTDSCONN_KCC_GC_TOPOLOGY);
986 ADD_DSDB_FLAG(NTDSCONN_KCC_RING_TOPOLOGY);
987 ADD_DSDB_FLAG(NTDSCONN_KCC_MINIMIZE_HOPS_TOPOLOGY);
988 ADD_DSDB_FLAG(NTDSCONN_KCC_STALE_SERVERS_TOPOLOGY);
989 ADD_DSDB_FLAG(NTDSCONN_KCC_OSCILLATING_CONNECTION_TOPOLOGY);
990 ADD_DSDB_FLAG(NTDSCONN_KCC_INTERSITE_GC_TOPOLOGY);
991 ADD_DSDB_FLAG(NTDSCONN_KCC_INTERSITE_TOPOLOGY);
992 ADD_DSDB_FLAG(NTDSCONN_KCC_SERVER_FAILOVER_TOPOLOGY);
993 ADD_DSDB_FLAG(NTDSCONN_KCC_SITE_FAILOVER_TOPOLOGY);
994 ADD_DSDB_FLAG(NTDSCONN_KCC_REDUNDANT_SERVER_TOPOLOGY);
996 /* GPO policy flags */
997 ADD_DSDB_FLAG(GPLINK_OPT_DISABLE);
998 ADD_DSDB_FLAG(GPLINK_OPT_ENFORCE);
999 ADD_DSDB_FLAG(GPO_FLAG_USER_DISABLE);
1000 ADD_DSDB_FLAG(GPO_FLAG_MACHINE_DISABLE);
1001 ADD_DSDB_FLAG(GPO_INHERIT);
1002 ADD_DSDB_FLAG(GPO_BLOCK_INHERITANCE);
1004 #define ADD_DSDB_STRING(val) PyModule_AddObject(m, #val, PyString_FromString(val))
1006 ADD_DSDB_STRING(DSDB_SYNTAX_BINARY_DN);
1007 ADD_DSDB_STRING(DSDB_SYNTAX_STRING_DN);
1008 ADD_DSDB_STRING(DSDB_SYNTAX_OR_NAME);