s3-printing: clean up get_correct_cversion error paths
[Samba.git] / source4 / dsdb / pydsdb.c
blobf5832d1d3972ad0cc164338b13b583736c59f903
1 /*
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/>.
20 #include <Python.h>
21 #include "includes.h"
22 #include "libcli/util/pyerrors.h"
23 #include "dsdb/samdb/samdb.h"
24 #include "lib/ldb/pyldb.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"
32 /* There's no Py_ssize_t in 2.4, apparently */
33 #if PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION < 5
34 typedef int Py_ssize_t;
35 typedef inquiry lenfunc;
36 typedef intargfunc ssizeargfunc;
37 #endif
39 #ifndef Py_RETURN_NONE
40 #define Py_RETURN_NONE return Py_INCREF(Py_None), Py_None
41 #endif
43 /* FIXME: These should be in a header file somewhere, once we finish moving
44 * away from SWIG .. */
45 #define PyErr_LDB_OR_RAISE(py_ldb, ldb) \
46 /* if (!PyLdb_Check(py_ldb)) { \
47 PyErr_SetString(py_ldb_get_exception(), "Ldb connection object required"); \
48 return NULL; \
49 } */\
50 ldb = PyLdb_AsLdbContext(py_ldb);
52 static PyObject *py_ldb_get_exception(void)
54 PyObject *mod = PyImport_ImportModule("ldb");
55 if (mod == NULL)
56 return NULL;
58 return PyObject_GetAttrString(mod, "LdbError");
61 static void PyErr_SetLdbError(PyObject *error, int ret, struct ldb_context *ldb_ctx)
63 if (ret == LDB_ERR_PYTHON_EXCEPTION)
64 return; /* Python exception should already be set, just keep that */
66 PyErr_SetObject(error,
67 Py_BuildValue(discard_const_p(char, "(i,s)"), ret,
68 ldb_ctx == NULL?ldb_strerror(ret):ldb_errstring(ldb_ctx)));
71 static PyObject *py_samdb_server_site_name(PyObject *self, PyObject *args)
73 PyObject *py_ldb, *result;
74 struct ldb_context *ldb;
75 const char *site;
76 TALLOC_CTX *mem_ctx;
78 if (!PyArg_ParseTuple(args, "O", &py_ldb))
79 return NULL;
81 PyErr_LDB_OR_RAISE(py_ldb, ldb);
83 mem_ctx = talloc_new(NULL);
85 site = samdb_server_site_name(ldb, mem_ctx);
86 if (site == NULL) {
87 PyErr_SetString(PyExc_RuntimeError, "Failed to find server site");
88 talloc_free(mem_ctx);
89 return NULL;
92 result = PyString_FromString(site);
93 talloc_free(mem_ctx);
94 return result;
97 static PyObject *py_dsdb_convert_schema_to_openldap(PyObject *self,
98 PyObject *args)
100 char *target_str, *mapping;
101 PyObject *py_ldb;
102 struct ldb_context *ldb;
103 PyObject *ret;
104 char *retstr;
106 if (!PyArg_ParseTuple(args, "Oss", &py_ldb, &target_str, &mapping))
107 return NULL;
109 PyErr_LDB_OR_RAISE(py_ldb, ldb);
111 retstr = dsdb_convert_schema_to_openldap(ldb, target_str, mapping);
112 if (retstr == NULL) {
113 PyErr_SetString(PyExc_RuntimeError,
114 "dsdb_convert_schema_to_openldap failed");
115 return NULL;
118 ret = PyString_FromString(retstr);
119 talloc_free(retstr);
120 return ret;
123 static PyObject *py_samdb_set_domain_sid(PyLdbObject *self, PyObject *args)
125 PyObject *py_ldb, *py_sid;
126 struct ldb_context *ldb;
127 struct dom_sid *sid;
128 bool ret;
130 if (!PyArg_ParseTuple(args, "OO", &py_ldb, &py_sid))
131 return NULL;
133 PyErr_LDB_OR_RAISE(py_ldb, ldb);
135 sid = dom_sid_parse_talloc(NULL, PyString_AsString(py_sid));
137 ret = samdb_set_domain_sid(ldb, sid);
138 talloc_free(sid);
139 if (!ret) {
140 PyErr_SetString(PyExc_RuntimeError, "set_domain_sid failed");
141 return NULL;
143 Py_RETURN_NONE;
146 static PyObject *py_samdb_set_ntds_settings_dn(PyLdbObject *self, PyObject *args)
148 PyObject *py_ldb, *py_ntds_settings_dn;
149 struct ldb_context *ldb;
150 struct ldb_dn *ntds_settings_dn;
151 TALLOC_CTX *tmp_ctx;
152 bool ret;
154 if (!PyArg_ParseTuple(args, "OO", &py_ldb, &py_ntds_settings_dn))
155 return NULL;
157 PyErr_LDB_OR_RAISE(py_ldb, ldb);
159 tmp_ctx = talloc_new(NULL);
160 if (tmp_ctx == NULL) {
161 PyErr_NoMemory();
162 return NULL;
165 if (!PyObject_AsDn(tmp_ctx, py_ntds_settings_dn, ldb, &ntds_settings_dn)) {
166 return NULL;
169 ret = samdb_set_ntds_settings_dn(ldb, ntds_settings_dn);
170 talloc_free(tmp_ctx);
171 if (!ret) {
172 PyErr_SetString(PyExc_RuntimeError, "set_ntds_settings_dn failed");
173 return NULL;
175 Py_RETURN_NONE;
178 static PyObject *py_samdb_get_domain_sid(PyLdbObject *self, PyObject *args)
180 PyObject *py_ldb;
181 struct ldb_context *ldb;
182 const struct dom_sid *sid;
183 PyObject *ret;
184 char *retstr;
186 if (!PyArg_ParseTuple(args, "O", &py_ldb))
187 return NULL;
189 PyErr_LDB_OR_RAISE(py_ldb, ldb);
191 sid = samdb_domain_sid(ldb);
192 if (!sid) {
193 PyErr_SetString(PyExc_RuntimeError, "samdb_domain_sid failed");
194 return NULL;
196 retstr = dom_sid_string(NULL, sid);
197 ret = PyString_FromString(retstr);
198 talloc_free(retstr);
199 return ret;
202 static PyObject *py_samdb_ntds_invocation_id(PyObject *self, PyObject *args)
204 PyObject *py_ldb, *result;
205 struct ldb_context *ldb;
206 TALLOC_CTX *mem_ctx;
207 const struct GUID *guid;
209 mem_ctx = talloc_new(NULL);
210 if (mem_ctx == NULL) {
211 PyErr_NoMemory();
212 return NULL;
215 if (!PyArg_ParseTuple(args, "O", &py_ldb)) {
216 talloc_free(mem_ctx);
217 return NULL;
220 PyErr_LDB_OR_RAISE(py_ldb, ldb);
222 guid = samdb_ntds_invocation_id(ldb);
223 if (guid == NULL) {
224 PyErr_SetString(PyExc_RuntimeError,
225 "Failed to find NTDS invocation ID");
226 talloc_free(mem_ctx);
227 return NULL;
230 result = PyString_FromString(GUID_string(mem_ctx, guid));
231 talloc_free(mem_ctx);
232 return result;
235 static PyObject *py_dsdb_get_oid_from_attid(PyObject *self, PyObject *args)
237 PyObject *py_ldb;
238 struct ldb_context *ldb;
239 uint32_t attid;
240 struct dsdb_schema *schema;
241 const char *oid;
242 PyObject *ret;
243 TALLOC_CTX *mem_ctx;
244 WERROR status;
246 if (!PyArg_ParseTuple(args, "Oi", &py_ldb, &attid))
247 return NULL;
249 PyErr_LDB_OR_RAISE(py_ldb, ldb);
251 mem_ctx = talloc_new(NULL);
252 if (mem_ctx == NULL) {
253 PyErr_NoMemory();
254 return NULL;
257 schema = dsdb_get_schema(ldb, NULL);
259 if (!schema) {
260 PyErr_SetString(PyExc_RuntimeError, "Failed to find a schema from ldb \n");
261 talloc_free(mem_ctx);
262 return NULL;
265 status = dsdb_schema_pfm_oid_from_attid(schema->prefixmap, attid,
266 mem_ctx, &oid);
267 PyErr_WERROR_IS_ERR_RAISE(status);
269 ret = PyString_FromString(oid);
271 talloc_free(mem_ctx);
273 return ret;
277 static PyObject *py_dsdb_get_attid_from_lDAPDisplayName(PyObject *self, PyObject *args)
279 PyObject *py_ldb, *is_schema_nc;
280 struct ldb_context *ldb;
281 struct dsdb_schema *schema;
282 const char *ldap_display_name;
283 bool schema_nc = false;
284 const struct dsdb_attribute *a;
285 uint32_t attid;
287 if (!PyArg_ParseTuple(args, "OsO", &py_ldb, &ldap_display_name, &is_schema_nc))
288 return NULL;
290 PyErr_LDB_OR_RAISE(py_ldb, ldb);
292 if (is_schema_nc) {
293 if (!PyBool_Check(is_schema_nc)) {
294 PyErr_SetString(PyExc_TypeError, "Expected boolean is_schema_nc");
295 return NULL;
297 if (is_schema_nc == Py_True) {
298 schema_nc = true;
302 schema = dsdb_get_schema(ldb, NULL);
304 if (!schema) {
305 PyErr_SetString(PyExc_RuntimeError, "Failed to find a schema from ldb");
306 return NULL;
309 a = dsdb_attribute_by_lDAPDisplayName(schema, ldap_display_name);
310 if (a == NULL) {
311 PyErr_Format(PyExc_RuntimeError, "Failed to find attribute '%s'", ldap_display_name);
312 return NULL;
315 attid = dsdb_attribute_get_attid(a, schema_nc);
317 return PyLong_FromUnsignedLong(attid);
321 convert a python string to a DRSUAPI drsuapi_DsReplicaAttribute attribute
323 static PyObject *py_dsdb_DsReplicaAttribute(PyObject *self, PyObject *args)
325 PyObject *py_ldb, *el_list, *ret;
326 struct ldb_context *ldb;
327 char *ldap_display_name;
328 const struct dsdb_attribute *a;
329 struct dsdb_schema *schema;
330 struct dsdb_syntax_ctx syntax_ctx;
331 struct ldb_message_element *el;
332 struct drsuapi_DsReplicaAttribute *attr;
333 TALLOC_CTX *tmp_ctx;
334 WERROR werr;
335 Py_ssize_t i;
337 if (!PyArg_ParseTuple(args, "OsO", &py_ldb, &ldap_display_name, &el_list)) {
338 return NULL;
341 PyErr_LDB_OR_RAISE(py_ldb, ldb);
343 if (!PyList_Check(el_list)) {
344 PyErr_Format(PyExc_TypeError, "ldif_elements must be a list");
345 return NULL;
348 schema = dsdb_get_schema(ldb, NULL);
349 if (!schema) {
350 PyErr_SetString(PyExc_RuntimeError, "Failed to find a schema from ldb");
351 return NULL;
354 a = dsdb_attribute_by_lDAPDisplayName(schema, ldap_display_name);
355 if (a == NULL) {
356 PyErr_Format(PyExc_RuntimeError, "Failed to find attribute '%s'", ldap_display_name);
357 return NULL;
360 dsdb_syntax_ctx_init(&syntax_ctx, ldb, schema);
361 syntax_ctx.is_schema_nc = false;
363 tmp_ctx = talloc_new(ldb);
365 el = talloc_zero(tmp_ctx, struct ldb_message_element);
366 el->name = ldap_display_name;
367 el->num_values = PyList_Size(el_list);
368 el->values = talloc_array(el, struct ldb_val, el->num_values);
369 for (i = 0; i < el->num_values; i++) {
370 PyObject *item = PyList_GetItem(el_list, i);
371 if (!PyString_Check(item)) {
372 PyErr_Format(PyExc_TypeError, "ldif_elements should be strings");
373 return NULL;
375 el->values[i].data = (uint8_t *)PyString_AsString(item);
376 el->values[i].length = PyString_Size(item);
379 attr = talloc_zero(tmp_ctx, struct drsuapi_DsReplicaAttribute);
381 werr = a->syntax->ldb_to_drsuapi(&syntax_ctx, a, el, attr, attr);
382 PyErr_WERROR_IS_ERR_RAISE(werr);
384 ret = py_return_ndr_struct("samba.dcerpc.drsuapi", "DsReplicaAttribute", attr, attr);
386 talloc_unlink(ldb, tmp_ctx);
388 return ret;
391 static PyObject *py_dsdb_set_ntds_invocation_id(PyObject *self, PyObject *args)
393 PyObject *py_ldb, *py_guid;
394 bool ret;
395 struct GUID guid;
396 struct ldb_context *ldb;
397 if (!PyArg_ParseTuple(args, "OO", &py_ldb, &py_guid))
398 return NULL;
400 PyErr_LDB_OR_RAISE(py_ldb, ldb);
401 GUID_from_string(PyString_AsString(py_guid), &guid);
403 ret = samdb_set_ntds_invocation_id(ldb, &guid);
404 if (!ret) {
405 PyErr_SetString(PyExc_RuntimeError, "set_ntds_invocation_id failed");
406 return NULL;
408 Py_RETURN_NONE;
411 static PyObject *py_samdb_ntds_objectGUID(PyObject *self, PyObject *args)
413 PyObject *py_ldb, *result;
414 struct ldb_context *ldb;
415 TALLOC_CTX *mem_ctx;
416 const struct GUID *guid;
418 if (!PyArg_ParseTuple(args, "O", &py_ldb)) {
419 return NULL;
422 PyErr_LDB_OR_RAISE(py_ldb, ldb);
424 mem_ctx = talloc_new(NULL);
425 if (mem_ctx == NULL) {
426 PyErr_NoMemory();
427 return NULL;
430 guid = samdb_ntds_objectGUID(ldb);
431 if (guid == NULL) {
432 PyErr_SetString(PyExc_RuntimeError, "Failed to find NTDS GUID");
433 talloc_free(mem_ctx);
434 return NULL;
437 result = PyString_FromString(GUID_string(mem_ctx, guid));
438 talloc_free(mem_ctx);
439 return result;
442 static PyObject *py_dsdb_set_global_schema(PyObject *self, PyObject *args)
444 PyObject *py_ldb;
445 struct ldb_context *ldb;
446 int ret;
447 if (!PyArg_ParseTuple(args, "O", &py_ldb))
448 return NULL;
450 PyErr_LDB_OR_RAISE(py_ldb, ldb);
452 ret = dsdb_set_global_schema(ldb);
453 PyErr_LDB_ERROR_IS_ERR_RAISE(py_ldb_get_exception(), ret, ldb);
455 Py_RETURN_NONE;
458 static PyObject *py_dsdb_load_partition_usn(PyObject *self, PyObject *args)
460 PyObject *py_dn, *py_ldb, *result;
461 struct ldb_dn *dn;
462 uint64_t highest_uSN, urgent_uSN;
463 struct ldb_context *ldb;
464 TALLOC_CTX *mem_ctx;
465 int ret;
467 mem_ctx = talloc_new(NULL);
468 if (mem_ctx == NULL) {
469 PyErr_NoMemory();
470 return NULL;
473 if (!PyArg_ParseTuple(args, "OO", &py_ldb, &py_dn)) {
474 talloc_free(mem_ctx);
475 return NULL;
478 PyErr_LDB_OR_RAISE(py_ldb, ldb);
480 if (!PyObject_AsDn(mem_ctx, py_dn, ldb, &dn)) {
481 talloc_free(mem_ctx);
482 return NULL;
485 ret = dsdb_load_partition_usn(ldb, dn, &highest_uSN, &urgent_uSN);
486 if (ret != LDB_SUCCESS) {
487 PyErr_Format(PyExc_RuntimeError,
488 "Failed to load partition [%s] uSN - %s",
489 ldb_dn_get_linearized(dn),
490 ldb_errstring(ldb));
491 talloc_free(mem_ctx);
492 return NULL;
495 talloc_free(mem_ctx);
497 result = PyDict_New();
499 PyDict_SetItemString(result, "uSNHighest", PyInt_FromLong((uint64_t)highest_uSN));
500 PyDict_SetItemString(result, "uSNUrgent", PyInt_FromLong((uint64_t)urgent_uSN));
503 return result;
506 static PyObject *py_dsdb_set_am_rodc(PyObject *self, PyObject *args)
508 PyObject *py_ldb;
509 bool ret;
510 struct ldb_context *ldb;
511 int py_val;
513 if (!PyArg_ParseTuple(args, "Oi", &py_ldb, &py_val))
514 return NULL;
516 PyErr_LDB_OR_RAISE(py_ldb, ldb);
517 ret = samdb_set_am_rodc(ldb, (bool)py_val);
518 if (!ret) {
519 PyErr_SetString(PyExc_RuntimeError, "set_am_rodc failed");
520 return NULL;
522 Py_RETURN_NONE;
525 static PyObject *py_dsdb_set_schema_from_ldif(PyObject *self, PyObject *args)
527 WERROR result;
528 char *pf, *df;
529 PyObject *py_ldb;
530 struct ldb_context *ldb;
532 if (!PyArg_ParseTuple(args, "Oss", &py_ldb, &pf, &df))
533 return NULL;
535 PyErr_LDB_OR_RAISE(py_ldb, ldb);
537 result = dsdb_set_schema_from_ldif(ldb, pf, df);
538 PyErr_WERROR_IS_ERR_RAISE(result);
540 Py_RETURN_NONE;
543 static PyObject *py_dsdb_set_schema_from_ldb(PyObject *self, PyObject *args)
545 PyObject *py_ldb;
546 struct ldb_context *ldb;
547 PyObject *py_from_ldb;
548 struct ldb_context *from_ldb;
549 struct dsdb_schema *schema;
550 int ret;
551 if (!PyArg_ParseTuple(args, "OO", &py_ldb, &py_from_ldb))
552 return NULL;
554 PyErr_LDB_OR_RAISE(py_ldb, ldb);
556 PyErr_LDB_OR_RAISE(py_from_ldb, from_ldb);
558 schema = dsdb_get_schema(from_ldb, NULL);
559 if (!schema) {
560 PyErr_SetString(PyExc_RuntimeError, "Failed to set find a schema on 'from' ldb!\n");
561 return NULL;
564 ret = dsdb_reference_schema(ldb, schema, true);
565 PyErr_LDB_ERROR_IS_ERR_RAISE(py_ldb_get_exception(), ret, ldb);
567 Py_RETURN_NONE;
570 static PyObject *py_dsdb_write_prefixes_from_schema_to_ldb(PyObject *self, PyObject *args)
572 PyObject *py_ldb;
573 struct ldb_context *ldb;
574 WERROR result;
575 struct dsdb_schema *schema;
577 if (!PyArg_ParseTuple(args, "O", &py_ldb))
578 return NULL;
580 PyErr_LDB_OR_RAISE(py_ldb, ldb);
582 schema = dsdb_get_schema(ldb, NULL);
583 if (!schema) {
584 PyErr_SetString(PyExc_RuntimeError, "Failed to set find a schema on ldb!\n");
585 return NULL;
588 result = dsdb_write_prefixes_from_schema_to_ldb(NULL, ldb, schema);
589 PyErr_WERROR_IS_ERR_RAISE(result);
591 Py_RETURN_NONE;
595 static PyObject *py_dsdb_get_partitions_dn(PyObject *self, PyObject *args)
597 struct ldb_context *ldb;
598 struct ldb_dn *dn;
599 PyObject *py_ldb, *ret;
600 TALLOC_CTX *tmp_ctx;
601 PyObject *mod;
603 mod = PyImport_ImportModule("ldb");
605 if (!PyArg_ParseTuple(args, "O", &py_ldb))
606 return NULL;
608 PyErr_LDB_OR_RAISE(py_ldb, ldb);
610 tmp_ctx = talloc_new(NULL);
612 dn = samdb_partitions_dn(ldb, tmp_ctx);
614 if (dn == NULL) {
615 talloc_free(tmp_ctx);
616 Py_RETURN_NONE;
618 ret = PyLdbDn_FromDn(dn);
619 talloc_free(tmp_ctx);
620 return ret;
625 call into samdb_rodc()
627 static PyObject *py_dsdb_am_rodc(PyObject *self, PyObject *args)
629 PyObject *py_ldb;
630 struct ldb_context *ldb;
631 int ret;
632 bool am_rodc;
634 if (!PyArg_ParseTuple(args, "O", &py_ldb))
635 return NULL;
637 PyErr_LDB_OR_RAISE(py_ldb, ldb);
639 ret = samdb_rodc(ldb, &am_rodc);
640 if (ret != LDB_SUCCESS) {
641 PyErr_SetString(PyExc_RuntimeError, ldb_errstring(ldb));
642 return NULL;
645 return PyBool_FromLong(am_rodc);
649 static PyMethodDef py_dsdb_methods[] = {
650 { "_samdb_server_site_name", (PyCFunction)py_samdb_server_site_name,
651 METH_VARARGS, "Get the server site name as a string"},
652 { "_dsdb_convert_schema_to_openldap",
653 (PyCFunction)py_dsdb_convert_schema_to_openldap, METH_VARARGS,
654 "dsdb_convert_schema_to_openldap(ldb, target_str, mapping) -> str\n"
655 "Create an OpenLDAP schema from a schema." },
656 { "_samdb_set_domain_sid", (PyCFunction)py_samdb_set_domain_sid,
657 METH_VARARGS,
658 "samdb_set_domain_sid(samdb, sid)\n"
659 "Set SID of domain to use." },
660 { "_samdb_get_domain_sid", (PyCFunction)py_samdb_get_domain_sid,
661 METH_VARARGS,
662 "samdb_get_domain_sid(samdb)\n"
663 "Get SID of domain in use." },
664 { "_samdb_ntds_invocation_id", (PyCFunction)py_samdb_ntds_invocation_id,
665 METH_VARARGS, "get the NTDS invocation ID GUID as a string"},
666 { "_samdb_set_ntds_settings_dn", (PyCFunction)py_samdb_set_ntds_settings_dn,
667 METH_VARARGS,
668 "samdb_set_ntds_settings_dn(samdb, ntds_settings_dn)\n"
669 "Set NTDS Settings DN for this LDB (allows it to be set before the DB fully exists)." },
670 { "_dsdb_get_oid_from_attid", (PyCFunction)py_dsdb_get_oid_from_attid,
671 METH_VARARGS, NULL },
672 { "_dsdb_get_attid_from_lDAPDisplayName", (PyCFunction)py_dsdb_get_attid_from_lDAPDisplayName,
673 METH_VARARGS, NULL },
674 { "_dsdb_set_ntds_invocation_id",
675 (PyCFunction)py_dsdb_set_ntds_invocation_id, METH_VARARGS,
676 NULL },
677 { "_samdb_ntds_objectGUID", (PyCFunction)py_samdb_ntds_objectGUID,
678 METH_VARARGS, "get the NTDS objectGUID as a string"},
679 { "_dsdb_set_global_schema", (PyCFunction)py_dsdb_set_global_schema,
680 METH_VARARGS, NULL },
681 { "_dsdb_load_partition_usn", (PyCFunction)py_dsdb_load_partition_usn,
682 METH_VARARGS,
683 "get uSNHighest and uSNUrgent from the partition @REPLCHANGED"},
684 { "_dsdb_set_am_rodc",
685 (PyCFunction)py_dsdb_set_am_rodc, METH_VARARGS,
686 NULL },
687 { "_am_rodc",
688 (PyCFunction)py_dsdb_am_rodc, METH_VARARGS,
689 NULL },
690 { "_dsdb_set_schema_from_ldif", (PyCFunction)py_dsdb_set_schema_from_ldif, METH_VARARGS,
691 NULL },
692 { "_dsdb_set_schema_from_ldb", (PyCFunction)py_dsdb_set_schema_from_ldb, METH_VARARGS,
693 NULL },
694 { "_dsdb_write_prefixes_from_schema_to_ldb", (PyCFunction)py_dsdb_write_prefixes_from_schema_to_ldb, METH_VARARGS,
695 NULL },
696 { "_dsdb_get_partitions_dn", (PyCFunction)py_dsdb_get_partitions_dn, METH_VARARGS, NULL },
697 { "_dsdb_DsReplicaAttribute", (PyCFunction)py_dsdb_DsReplicaAttribute, METH_VARARGS, NULL },
698 { NULL }
701 void initdsdb(void)
703 PyObject *m;
705 m = Py_InitModule3("dsdb", py_dsdb_methods,
706 "Python bindings for the directory service databases.");
707 if (m == NULL)
708 return;
710 #define ADD_DSDB_FLAG(val) PyModule_AddObject(m, #val, PyInt_FromLong(val))
712 /* "userAccountControl" flags */
713 ADD_DSDB_FLAG(UF_NORMAL_ACCOUNT);
714 ADD_DSDB_FLAG(UF_TEMP_DUPLICATE_ACCOUNT);
715 ADD_DSDB_FLAG(UF_SERVER_TRUST_ACCOUNT);
716 ADD_DSDB_FLAG(UF_WORKSTATION_TRUST_ACCOUNT);
717 ADD_DSDB_FLAG(UF_INTERDOMAIN_TRUST_ACCOUNT);
718 ADD_DSDB_FLAG(UF_PASSWD_NOTREQD);
719 ADD_DSDB_FLAG(UF_ACCOUNTDISABLE);
721 ADD_DSDB_FLAG(UF_SCRIPT);
722 ADD_DSDB_FLAG(UF_ACCOUNTDISABLE);
723 ADD_DSDB_FLAG(UF_00000004);
724 ADD_DSDB_FLAG(UF_HOMEDIR_REQUIRED);
725 ADD_DSDB_FLAG(UF_LOCKOUT);
726 ADD_DSDB_FLAG(UF_PASSWD_NOTREQD);
727 ADD_DSDB_FLAG(UF_PASSWD_CANT_CHANGE);
728 ADD_DSDB_FLAG(UF_ENCRYPTED_TEXT_PASSWORD_ALLOWED);
729 ADD_DSDB_FLAG(UF_TEMP_DUPLICATE_ACCOUNT);
730 ADD_DSDB_FLAG(UF_NORMAL_ACCOUNT);
731 ADD_DSDB_FLAG(UF_00000400);
732 ADD_DSDB_FLAG(UF_INTERDOMAIN_TRUST_ACCOUNT);
733 ADD_DSDB_FLAG(UF_WORKSTATION_TRUST_ACCOUNT);
734 ADD_DSDB_FLAG(UF_SERVER_TRUST_ACCOUNT);
735 ADD_DSDB_FLAG(UF_00004000);
736 ADD_DSDB_FLAG(UF_00008000);
737 ADD_DSDB_FLAG(UF_DONT_EXPIRE_PASSWD);
738 ADD_DSDB_FLAG(UF_MNS_LOGON_ACCOUNT);
739 ADD_DSDB_FLAG(UF_SMARTCARD_REQUIRED);
740 ADD_DSDB_FLAG(UF_TRUSTED_FOR_DELEGATION);
741 ADD_DSDB_FLAG(UF_NOT_DELEGATED);
742 ADD_DSDB_FLAG(UF_USE_DES_KEY_ONLY);
743 ADD_DSDB_FLAG(UF_DONT_REQUIRE_PREAUTH);
744 ADD_DSDB_FLAG(UF_PASSWORD_EXPIRED);
745 ADD_DSDB_FLAG(UF_TRUSTED_TO_AUTHENTICATE_FOR_DELEGATION);
746 ADD_DSDB_FLAG(UF_NO_AUTH_DATA_REQUIRED);
747 ADD_DSDB_FLAG(UF_PARTIAL_SECRETS_ACCOUNT);
749 /* groupType flags */
750 ADD_DSDB_FLAG(GTYPE_SECURITY_BUILTIN_LOCAL_GROUP);
751 ADD_DSDB_FLAG(GTYPE_SECURITY_GLOBAL_GROUP);
752 ADD_DSDB_FLAG(GTYPE_SECURITY_DOMAIN_LOCAL_GROUP);
753 ADD_DSDB_FLAG(GTYPE_SECURITY_UNIVERSAL_GROUP);
754 ADD_DSDB_FLAG(GTYPE_DISTRIBUTION_GLOBAL_GROUP);
755 ADD_DSDB_FLAG(GTYPE_DISTRIBUTION_DOMAIN_LOCAL_GROUP);
756 ADD_DSDB_FLAG(GTYPE_DISTRIBUTION_UNIVERSAL_GROUP);
758 /* "sAMAccountType" flags */
759 ADD_DSDB_FLAG(ATYPE_NORMAL_ACCOUNT);
760 ADD_DSDB_FLAG(ATYPE_WORKSTATION_TRUST);
761 ADD_DSDB_FLAG(ATYPE_INTERDOMAIN_TRUST);
762 ADD_DSDB_FLAG(ATYPE_SECURITY_GLOBAL_GROUP);
763 ADD_DSDB_FLAG(ATYPE_SECURITY_LOCAL_GROUP);
764 ADD_DSDB_FLAG(ATYPE_SECURITY_UNIVERSAL_GROUP);
765 ADD_DSDB_FLAG(ATYPE_DISTRIBUTION_GLOBAL_GROUP);
766 ADD_DSDB_FLAG(ATYPE_DISTRIBUTION_LOCAL_GROUP);
767 ADD_DSDB_FLAG(ATYPE_DISTRIBUTION_UNIVERSAL_GROUP);
769 /* "domainFunctionality", "forestFunctionality" flags in the rootDSE */
770 ADD_DSDB_FLAG(DS_DOMAIN_FUNCTION_2000);
771 ADD_DSDB_FLAG(DS_DOMAIN_FUNCTION_2003_MIXED);
772 ADD_DSDB_FLAG(DS_DOMAIN_FUNCTION_2003);
773 ADD_DSDB_FLAG(DS_DOMAIN_FUNCTION_2008);
774 ADD_DSDB_FLAG(DS_DOMAIN_FUNCTION_2008_R2);
776 /* "systemFlags" */
777 ADD_DSDB_FLAG(SYSTEM_FLAG_CR_NTDS_NC);
778 ADD_DSDB_FLAG(SYSTEM_FLAG_CR_NTDS_DOMAIN);
779 ADD_DSDB_FLAG(SYSTEM_FLAG_CR_NTDS_NOT_GC_REPLICATED);
780 ADD_DSDB_FLAG(SYSTEM_FLAG_SCHEMA_BASE_OBJECT);
781 ADD_DSDB_FLAG(SYSTEM_FLAG_ATTR_IS_RDN);
782 ADD_DSDB_FLAG(SYSTEM_FLAG_DISALLOW_MOVE_ON_DELETE);
783 ADD_DSDB_FLAG(SYSTEM_FLAG_DOMAIN_DISALLOW_MOVE);
784 ADD_DSDB_FLAG(SYSTEM_FLAG_DOMAIN_DISALLOW_RENAME);
785 ADD_DSDB_FLAG(SYSTEM_FLAG_CONFIG_ALLOW_LIMITED_MOVE);
786 ADD_DSDB_FLAG(SYSTEM_FLAG_CONFIG_ALLOW_MOVE);
787 ADD_DSDB_FLAG(SYSTEM_FLAG_CONFIG_ALLOW_RENAME);
788 ADD_DSDB_FLAG(SYSTEM_FLAG_DISALLOW_DELETE);
790 /* Kerberos encryption type constants */
791 ADD_DSDB_FLAG(ENC_ALL_TYPES);
792 ADD_DSDB_FLAG(ENC_CRC32);
793 ADD_DSDB_FLAG(ENC_RSA_MD5);
794 ADD_DSDB_FLAG(ENC_RC4_HMAC_MD5);
795 ADD_DSDB_FLAG(ENC_HMAC_SHA1_96_AES128);
796 ADD_DSDB_FLAG(ENC_HMAC_SHA1_96_AES256);
798 ADD_DSDB_FLAG(SEARCH_FLAG_ATTINDEX);
799 ADD_DSDB_FLAG(SEARCH_FLAG_PDNTATTINDEX);
800 ADD_DSDB_FLAG(SEARCH_FLAG_ANR);
801 ADD_DSDB_FLAG(SEARCH_FLAG_PRESERVEONDELETE);
802 ADD_DSDB_FLAG(SEARCH_FLAG_COPY);
803 ADD_DSDB_FLAG(SEARCH_FLAG_TUPLEINDEX);
804 ADD_DSDB_FLAG(SEARCH_FLAG_SUBTREEATTRINDEX);
805 ADD_DSDB_FLAG(SEARCH_FLAG_CONFIDENTIAL);
806 ADD_DSDB_FLAG(SEARCH_FLAG_NEVERVALUEAUDIT);
807 ADD_DSDB_FLAG(SEARCH_FLAG_RODC_ATTRIBUTE);
809 ADD_DSDB_FLAG(DS_FLAG_ATTR_NOT_REPLICATED);
810 ADD_DSDB_FLAG(DS_FLAG_ATTR_REQ_PARTIAL_SET_MEMBER);
811 ADD_DSDB_FLAG(DS_FLAG_ATTR_IS_CONSTRUCTED);
813 ADD_DSDB_FLAG(DS_NTDSDSA_OPT_IS_GC);
814 ADD_DSDB_FLAG(DS_NTDSDSA_OPT_DISABLE_INBOUND_REPL);
815 ADD_DSDB_FLAG(DS_NTDSDSA_OPT_DISABLE_OUTBOUND_REPL);
816 ADD_DSDB_FLAG(DS_NTDSDSA_OPT_DISABLE_NTDSCONN_XLATE);
817 ADD_DSDB_FLAG(DS_NTDSDSA_OPT_DISABLE_SPN_REGISTRATION);
819 ADD_DSDB_FLAG(NTDSCONN_KCC_GC_TOPOLOGY);
820 ADD_DSDB_FLAG(NTDSCONN_KCC_RING_TOPOLOGY);
821 ADD_DSDB_FLAG(NTDSCONN_KCC_MINIMIZE_HOPS_TOPOLOGY);
822 ADD_DSDB_FLAG(NTDSCONN_KCC_STALE_SERVERS_TOPOLOGY);
823 ADD_DSDB_FLAG(NTDSCONN_KCC_OSCILLATING_CONNECTION_TOPOLOGY);
824 ADD_DSDB_FLAG(NTDSCONN_KCC_INTERSITE_GC_TOPOLOGY);
825 ADD_DSDB_FLAG(NTDSCONN_KCC_INTERSITE_TOPOLOGY);
826 ADD_DSDB_FLAG(NTDSCONN_KCC_SERVER_FAILOVER_TOPOLOGY);
827 ADD_DSDB_FLAG(NTDSCONN_KCC_SITE_FAILOVER_TOPOLOGY);
828 ADD_DSDB_FLAG(NTDSCONN_KCC_REDUNDANT_SERVER_TOPOLOGY);
830 /* GPO policy flags */
831 ADD_DSDB_FLAG(GPLINK_OPT_DISABLE);
832 ADD_DSDB_FLAG(GPLINK_OPT_ENFORCE);
833 ADD_DSDB_FLAG(GPO_FLAG_USER_DISABLE);
834 ADD_DSDB_FLAG(GPO_FLAG_MACHINE_DISABLE);
835 ADD_DSDB_FLAG(GPO_INHERIT);
836 ADD_DSDB_FLAG(GPO_BLOCK_INHERITANCE);