s4-dsdb: add more DS flags to the dsdb module
[metze/samba/wip.git] / source4 / dsdb / pydsdb.c
1 /* 
2    Unix SMB/CIFS implementation.
3    Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007-2010
4    Copyright (C) Matthias Dieter Wallnöfer          2009
5    
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.
10    
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.
15    
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/>.
18 */
19
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 /* FIXME: These should be in a header file somewhere, once we finish moving
30  * away from SWIG .. */
31 #define PyErr_LDB_OR_RAISE(py_ldb, ldb) \
32 /*      if (!PyLdb_Check(py_ldb)) { \
33                 PyErr_SetString(py_ldb_get_exception(), "Ldb connection object required"); \
34                 return NULL; \
35         } */\
36         ldb = PyLdb_AsLdbContext(py_ldb);
37
38 static PyObject *py_ldb_get_exception(void)
39 {
40         PyObject *mod = PyImport_ImportModule("ldb");
41         if (mod == NULL)
42                 return NULL;
43
44         return PyObject_GetAttrString(mod, "LdbError");
45 }
46
47 static void PyErr_SetLdbError(PyObject *error, int ret, struct ldb_context *ldb_ctx)
48 {
49         if (ret == LDB_ERR_PYTHON_EXCEPTION)
50                 return; /* Python exception should already be set, just keep that */
51
52         PyErr_SetObject(error, 
53                         Py_BuildValue(discard_const_p(char, "(i,s)"), ret,
54                         ldb_ctx == NULL?ldb_strerror(ret):ldb_errstring(ldb_ctx)));
55 }
56
57 static PyObject *py_samdb_server_site_name(PyObject *self, PyObject *args)
58 {
59         PyObject *py_ldb, *result;
60         struct ldb_context *ldb;
61         const char *site;
62         TALLOC_CTX *mem_ctx;
63
64         if (!PyArg_ParseTuple(args, "O", &py_ldb))
65                 return NULL;
66
67         PyErr_LDB_OR_RAISE(py_ldb, ldb);
68
69         mem_ctx = talloc_new(NULL);
70
71         site = samdb_server_site_name(ldb, mem_ctx);
72         if (site == NULL) {
73                 PyErr_SetString(PyExc_RuntimeError, "Failed to find server site");
74                 talloc_free(mem_ctx);
75                 return NULL;
76         }
77
78         result = PyString_FromString(site);
79         talloc_free(mem_ctx);
80         return result;
81 }
82
83 static PyObject *py_dsdb_convert_schema_to_openldap(PyObject *self,
84                                                                                                         PyObject *args)
85 {
86         char *target_str, *mapping;
87         PyObject *py_ldb;
88         struct ldb_context *ldb;
89         PyObject *ret;
90         char *retstr;
91
92         if (!PyArg_ParseTuple(args, "Oss", &py_ldb, &target_str, &mapping))
93                 return NULL;
94
95         PyErr_LDB_OR_RAISE(py_ldb, ldb);
96
97         retstr = dsdb_convert_schema_to_openldap(ldb, target_str, mapping);
98         if (retstr == NULL) {
99                 PyErr_SetString(PyExc_RuntimeError,
100                                                 "dsdb_convert_schema_to_openldap failed");
101                 return NULL;
102         } 
103
104         ret = PyString_FromString(retstr);
105         talloc_free(retstr);
106         return ret;
107 }
108
109 static PyObject *py_samdb_set_domain_sid(PyLdbObject *self, PyObject *args)
110
111         PyObject *py_ldb, *py_sid;
112         struct ldb_context *ldb;
113         struct dom_sid *sid;
114         bool ret;
115
116         if (!PyArg_ParseTuple(args, "OO", &py_ldb, &py_sid))
117                 return NULL;
118         
119         PyErr_LDB_OR_RAISE(py_ldb, ldb);
120
121         sid = dom_sid_parse_talloc(NULL, PyString_AsString(py_sid));
122
123         ret = samdb_set_domain_sid(ldb, sid);
124         if (!ret) {
125                 PyErr_SetString(PyExc_RuntimeError, "set_domain_sid failed");
126                 return NULL;
127         } 
128         Py_RETURN_NONE;
129 }
130
131 static PyObject *py_samdb_set_ntds_settings_dn(PyLdbObject *self, PyObject *args)
132
133         PyObject *py_ldb, *py_ntds_settings_dn;
134         struct ldb_context *ldb;
135         struct ldb_dn *ntds_settings_dn;
136         TALLOC_CTX *tmp_ctx;
137         bool ret;
138
139         if (!PyArg_ParseTuple(args, "OO", &py_ldb, &py_ntds_settings_dn))
140                 return NULL;
141         
142         PyErr_LDB_OR_RAISE(py_ldb, ldb);
143
144         tmp_ctx = talloc_new(NULL);
145         if (tmp_ctx == NULL) {
146                 PyErr_NoMemory();
147                 return NULL;
148         }
149
150         if (!PyObject_AsDn(tmp_ctx, py_ntds_settings_dn, ldb, &ntds_settings_dn)) {
151                 return NULL;
152         }
153
154         ret = samdb_set_ntds_settings_dn(ldb, ntds_settings_dn);
155         talloc_free(tmp_ctx);
156         if (!ret) {
157                 PyErr_SetString(PyExc_RuntimeError, "set_ntds_settings_dn failed");
158                 return NULL;
159         } 
160         Py_RETURN_NONE;
161 }
162
163 static PyObject *py_samdb_get_domain_sid(PyLdbObject *self, PyObject *args)
164
165         PyObject *py_ldb;
166         struct ldb_context *ldb;
167         const struct dom_sid *sid;
168         PyObject *ret;
169         char *retstr;
170
171         if (!PyArg_ParseTuple(args, "O", &py_ldb))
172                 return NULL;
173         
174         PyErr_LDB_OR_RAISE(py_ldb, ldb);
175
176         sid = samdb_domain_sid(ldb);
177         if (!sid) {
178                 PyErr_SetString(PyExc_RuntimeError, "samdb_domain_sid failed");
179                 return NULL;
180         } 
181         retstr = dom_sid_string(NULL, sid);
182         ret = PyString_FromString(retstr);
183         talloc_free(retstr);
184         return ret;
185 }
186
187 static PyObject *py_samdb_ntds_invocation_id(PyObject *self, PyObject *args)
188 {
189         PyObject *py_ldb, *result;
190         struct ldb_context *ldb;
191         TALLOC_CTX *mem_ctx;
192         const struct GUID *guid;
193
194         mem_ctx = talloc_new(NULL);
195         if (mem_ctx == NULL) {
196                 PyErr_NoMemory();
197                 return NULL;
198         }
199
200         if (!PyArg_ParseTuple(args, "O", &py_ldb)) {
201                 talloc_free(mem_ctx);
202                 return NULL;
203         }
204
205         PyErr_LDB_OR_RAISE(py_ldb, ldb);
206
207         guid = samdb_ntds_invocation_id(ldb);
208         if (guid == NULL) {
209                 PyErr_SetString(PyExc_RuntimeError,
210                                                 "Failed to find NTDS invocation ID");
211                 talloc_free(mem_ctx);
212                 return NULL;
213         }
214
215         result = PyString_FromString(GUID_string(mem_ctx, guid));
216         talloc_free(mem_ctx);
217         return result;
218 }
219
220 static PyObject *py_dsdb_get_oid_from_attid(PyObject *self, PyObject *args)
221 {
222         PyObject *py_ldb;
223         struct ldb_context *ldb;
224         uint32_t attid;
225         struct dsdb_schema *schema;
226         const char *oid;
227         PyObject *ret;
228         TALLOC_CTX *mem_ctx;
229         WERROR status;
230
231         if (!PyArg_ParseTuple(args, "Oi", &py_ldb, &attid))
232                 return NULL;
233
234         mem_ctx = talloc_new(NULL);
235         if (mem_ctx == NULL) {
236            PyErr_NoMemory();
237            return NULL;
238         }
239
240         PyErr_LDB_OR_RAISE(py_ldb, ldb);
241
242         schema = dsdb_get_schema(ldb, NULL);
243
244         if (!schema) {
245                 PyErr_SetString(PyExc_RuntimeError, "Failed to find a schema from ldb \n");
246                 talloc_free(mem_ctx);
247                 return NULL;
248         }
249         
250         status = dsdb_schema_pfm_oid_from_attid(schema->prefixmap, attid,
251                                                 mem_ctx, &oid);
252         PyErr_WERROR_IS_ERR_RAISE(status);
253
254         ret = PyString_FromString(oid);
255
256         talloc_free(mem_ctx);
257
258         return ret;
259 }
260
261
262 static PyObject *py_dsdb_get_attid_from_lDAPDisplayName(PyObject *self, PyObject *args)
263 {
264         PyObject *py_ldb, *is_schema_nc;
265         struct ldb_context *ldb;
266         struct dsdb_schema *schema;
267         const char *ldap_display_name;
268         bool schema_nc = false;
269         const struct dsdb_attribute *a;
270         uint32_t attid;
271
272         if (!PyArg_ParseTuple(args, "OsO", &py_ldb, &ldap_display_name, &is_schema_nc))
273                 return NULL;
274
275         PyErr_LDB_OR_RAISE(py_ldb, ldb);
276
277         if (is_schema_nc) {
278                 if (!PyBool_Check(is_schema_nc)) {
279                         PyErr_SetString(PyExc_TypeError, "Expected boolean is_schema_nc");
280                         return NULL;
281                 }
282                 if (is_schema_nc == Py_True) {
283                         schema_nc = true;
284                 }
285         }
286
287         schema = dsdb_get_schema(ldb, NULL);
288
289         if (!schema) {
290                 PyErr_SetString(PyExc_RuntimeError, "Failed to find a schema from ldb");
291                 return NULL;
292         }
293
294         a = dsdb_attribute_by_lDAPDisplayName(schema, ldap_display_name);
295         if (a == NULL) {
296                 PyErr_Format(PyExc_RuntimeError, "Failed to find attribute '%s'", ldap_display_name);
297                 return NULL;
298         }
299
300         attid = dsdb_attribute_get_attid(a, schema_nc);
301
302         return PyLong_FromUnsignedLong(attid);
303 }
304
305 static PyObject *py_dsdb_set_ntds_invocation_id(PyObject *self, PyObject *args)
306 {
307         PyObject *py_ldb, *py_guid;
308         bool ret;
309         struct GUID guid;
310         struct ldb_context *ldb;
311         if (!PyArg_ParseTuple(args, "OO", &py_ldb, &py_guid))
312                 return NULL;
313
314         PyErr_LDB_OR_RAISE(py_ldb, ldb);
315         GUID_from_string(PyString_AsString(py_guid), &guid);
316
317         ret = samdb_set_ntds_invocation_id(ldb, &guid);
318         if (!ret) {
319                 PyErr_SetString(PyExc_RuntimeError, "set_ntds_invocation_id failed");
320                 return NULL;
321         }
322         Py_RETURN_NONE;
323 }
324
325 static PyObject *py_samdb_ntds_objectGUID(PyObject *self, PyObject *args)
326 {
327         PyObject *py_ldb, *result;
328         struct ldb_context *ldb;
329         TALLOC_CTX *mem_ctx;
330         const struct GUID *guid;
331
332         mem_ctx = talloc_new(NULL);
333         if (mem_ctx == NULL) {
334                 PyErr_NoMemory();
335                 return NULL;
336         }
337
338         if (!PyArg_ParseTuple(args, "O", &py_ldb)) {
339                 talloc_free(mem_ctx);
340                 return NULL;
341         }
342
343         PyErr_LDB_OR_RAISE(py_ldb, ldb);
344
345         guid = samdb_ntds_objectGUID(ldb);
346         if (guid == NULL) {
347                 PyErr_SetString(PyExc_RuntimeError, "Failed to find NTDS GUID");
348                 talloc_free(mem_ctx);
349                 return NULL;
350         }
351
352         result = PyString_FromString(GUID_string(mem_ctx, guid));
353         talloc_free(mem_ctx);
354         return result;
355 }
356
357 static PyObject *py_dsdb_set_global_schema(PyObject *self, PyObject *args)
358 {
359         PyObject *py_ldb;
360         struct ldb_context *ldb;
361         int ret;
362         if (!PyArg_ParseTuple(args, "O", &py_ldb))
363                 return NULL;
364
365         PyErr_LDB_OR_RAISE(py_ldb, ldb);
366
367         ret = dsdb_set_global_schema(ldb);
368         PyErr_LDB_ERROR_IS_ERR_RAISE(py_ldb_get_exception(), ret, ldb);
369
370         Py_RETURN_NONE;
371 }
372
373 static PyObject *py_dsdb_load_partition_usn(PyObject *self, PyObject *args)
374 {
375         PyObject *py_dn, *py_ldb, *result;
376         struct ldb_dn *dn;
377         uint64_t highest_uSN, urgent_uSN;
378         struct ldb_context *ldb;
379         TALLOC_CTX *mem_ctx;
380         int ret;
381
382         mem_ctx = talloc_new(NULL);
383         if (mem_ctx == NULL) {
384            PyErr_NoMemory();
385            return NULL;
386         }
387
388         if (!PyArg_ParseTuple(args, "OO", &py_ldb, &py_dn)) {
389            talloc_free(mem_ctx);
390            return NULL;
391         }
392
393         PyErr_LDB_OR_RAISE(py_ldb, ldb);
394
395         if (!PyObject_AsDn(mem_ctx, py_dn, ldb, &dn)) {
396            talloc_free(mem_ctx);
397            return NULL;
398         }
399
400         ret = dsdb_load_partition_usn(ldb, dn, &highest_uSN, &urgent_uSN);
401         if (ret != LDB_SUCCESS) {
402            char *errstr = talloc_asprintf(mem_ctx, "Failed to load partition uSN - %s", ldb_errstring(ldb));
403            PyErr_SetString(PyExc_RuntimeError, errstr);
404            talloc_free(mem_ctx);
405            return NULL;
406         }
407
408         talloc_free(mem_ctx);
409
410         result = PyDict_New();
411
412         PyDict_SetItemString(result, "uSNHighest", PyInt_FromLong((uint64_t)highest_uSN));
413         PyDict_SetItemString(result, "uSNUrgent", PyInt_FromLong((uint64_t)urgent_uSN));
414
415
416         return result;
417 }
418
419 static PyObject *py_dsdb_set_am_rodc(PyObject *self, PyObject *args)
420 {
421         PyObject *py_ldb;
422         bool ret;
423         struct ldb_context *ldb;
424         int py_val;
425
426         if (!PyArg_ParseTuple(args, "Oi", &py_ldb, &py_val))
427                 return NULL;
428
429         PyErr_LDB_OR_RAISE(py_ldb, ldb);
430         ret = samdb_set_am_rodc(ldb, (bool)py_val);
431         if (!ret) {
432                 PyErr_SetString(PyExc_RuntimeError, "set_am_rodc failed");
433                 return NULL;
434         }
435         Py_RETURN_NONE;
436 }
437
438 static PyObject *py_dsdb_set_schema_from_ldif(PyObject *self, PyObject *args)
439 {
440         WERROR result;
441         char *pf, *df;
442         PyObject *py_ldb;
443         struct ldb_context *ldb;
444
445         if (!PyArg_ParseTuple(args, "Oss", &py_ldb, &pf, &df))
446                 return NULL;
447
448         PyErr_LDB_OR_RAISE(py_ldb, ldb);
449
450         result = dsdb_set_schema_from_ldif(ldb, pf, df);
451         PyErr_WERROR_IS_ERR_RAISE(result);
452
453         Py_RETURN_NONE;
454 }
455
456 static PyObject *py_dsdb_set_schema_from_ldb(PyObject *self, PyObject *args)
457 {
458         PyObject *py_ldb;
459         struct ldb_context *ldb;
460         PyObject *py_from_ldb;
461         struct ldb_context *from_ldb;
462         struct dsdb_schema *schema;
463         int ret;
464         if (!PyArg_ParseTuple(args, "OO", &py_ldb, &py_from_ldb))
465                 return NULL;
466
467         PyErr_LDB_OR_RAISE(py_ldb, ldb);
468
469         PyErr_LDB_OR_RAISE(py_from_ldb, from_ldb);
470
471         schema = dsdb_get_schema(from_ldb, NULL);
472         if (!schema) {
473                 PyErr_SetString(PyExc_RuntimeError, "Failed to set find a schema on 'from' ldb!\n");
474                 return NULL;
475         }
476
477         ret = dsdb_reference_schema(ldb, schema, true);
478         PyErr_LDB_ERROR_IS_ERR_RAISE(py_ldb_get_exception(), ret, ldb);
479
480         Py_RETURN_NONE;
481 }
482
483 static PyObject *py_dsdb_write_prefixes_from_schema_to_ldb(PyObject *self, PyObject *args)
484 {
485         PyObject *py_ldb;
486         struct ldb_context *ldb;
487         WERROR result;
488         struct dsdb_schema *schema;
489
490         if (!PyArg_ParseTuple(args, "O", &py_ldb))
491                 return NULL;
492
493         PyErr_LDB_OR_RAISE(py_ldb, ldb);
494
495         schema = dsdb_get_schema(ldb, NULL);
496         if (!schema) {
497                 PyErr_SetString(PyExc_RuntimeError, "Failed to set find a schema on ldb!\n");
498                 return NULL;
499         }
500
501         result = dsdb_write_prefixes_from_schema_to_ldb(NULL, ldb, schema);
502         PyErr_WERROR_IS_ERR_RAISE(result);
503
504         Py_RETURN_NONE;
505 }
506
507
508
509 static PyMethodDef py_dsdb_methods[] = {
510         { "_samdb_server_site_name", (PyCFunction)py_samdb_server_site_name,
511                 METH_VARARGS, "Get the server site name as a string"},
512         { "_dsdb_convert_schema_to_openldap",
513                 (PyCFunction)py_dsdb_convert_schema_to_openldap, METH_VARARGS, 
514                 "dsdb_convert_schema_to_openldap(ldb, target_str, mapping) -> str\n"
515                 "Create an OpenLDAP schema from a schema." },
516         { "_samdb_set_domain_sid", (PyCFunction)py_samdb_set_domain_sid,
517                 METH_VARARGS,
518                 "samdb_set_domain_sid(samdb, sid)\n"
519                 "Set SID of domain to use." },
520         { "_samdb_get_domain_sid", (PyCFunction)py_samdb_get_domain_sid,
521                 METH_VARARGS,
522                 "samdb_get_domain_sid(samdb)\n"
523                 "Get SID of domain in use." },
524         { "_samdb_ntds_invocation_id", (PyCFunction)py_samdb_ntds_invocation_id,
525                 METH_VARARGS, "get the NTDS invocation ID GUID as a string"},
526         { "_samdb_set_ntds_settings_dn", (PyCFunction)py_samdb_set_ntds_settings_dn,
527                 METH_VARARGS,
528                 "samdb_set_ntds_settings_dn(samdb, ntds_settings_dn)\n"
529                 "Set NTDS Settings DN for this LDB (allows it to be set before the DB fully exists)." },
530         { "_dsdb_get_oid_from_attid", (PyCFunction)py_dsdb_get_oid_from_attid,
531                 METH_VARARGS, NULL },
532         { "_dsdb_get_attid_from_lDAPDisplayName", (PyCFunction)py_dsdb_get_attid_from_lDAPDisplayName,
533                 METH_VARARGS, NULL },
534         { "_dsdb_set_ntds_invocation_id",
535                 (PyCFunction)py_dsdb_set_ntds_invocation_id, METH_VARARGS,
536                 NULL },
537         { "_samdb_ntds_objectGUID", (PyCFunction)py_samdb_ntds_objectGUID,
538                 METH_VARARGS, "get the NTDS objectGUID as a string"},
539         { "_dsdb_set_global_schema", (PyCFunction)py_dsdb_set_global_schema,
540                 METH_VARARGS, NULL },
541         { "_dsdb_load_partition_usn", (PyCFunction)py_dsdb_load_partition_usn,
542                 METH_VARARGS,
543                 "get uSNHighest and uSNUrgent from the partition @REPLCHANGED"},
544         { "_dsdb_set_am_rodc",
545                 (PyCFunction)py_dsdb_set_am_rodc, METH_VARARGS,
546                 NULL },
547         { "_dsdb_set_schema_from_ldif", (PyCFunction)py_dsdb_set_schema_from_ldif, METH_VARARGS,
548                 NULL },
549         { "_dsdb_set_schema_from_ldb", (PyCFunction)py_dsdb_set_schema_from_ldb, METH_VARARGS,
550                 NULL },
551         { "_dsdb_write_prefixes_from_schema_to_ldb", (PyCFunction)py_dsdb_write_prefixes_from_schema_to_ldb, METH_VARARGS,
552                 NULL },
553         { NULL }
554 };
555
556 void initdsdb(void)
557 {
558         PyObject *m;
559
560         m = Py_InitModule3("dsdb", py_dsdb_methods, 
561                            "Python bindings for the directory service databases.");
562         if (m == NULL)
563                 return;
564
565         /* "userAccountControl" flags */
566         PyModule_AddObject(m, "UF_NORMAL_ACCOUNT",
567                                            PyInt_FromLong(UF_NORMAL_ACCOUNT));
568         PyModule_AddObject(m, "UF_TEMP_DUPLICATE_ACCOUNT",
569                                            PyInt_FromLong(UF_TEMP_DUPLICATE_ACCOUNT));
570         PyModule_AddObject(m, "UF_SERVER_TRUST_ACCOUNT",
571                                            PyInt_FromLong(UF_SERVER_TRUST_ACCOUNT));
572         PyModule_AddObject(m, "UF_WORKSTATION_TRUST_ACCOUNT",
573                                            PyInt_FromLong(UF_WORKSTATION_TRUST_ACCOUNT));
574         PyModule_AddObject(m, "UF_INTERDOMAIN_TRUST_ACCOUNT",
575                                            PyInt_FromLong(UF_INTERDOMAIN_TRUST_ACCOUNT));
576         PyModule_AddObject(m, "UF_PASSWD_NOTREQD",
577                                            PyInt_FromLong(UF_PASSWD_NOTREQD));
578         PyModule_AddObject(m, "UF_ACCOUNTDISABLE",
579                                            PyInt_FromLong(UF_ACCOUNTDISABLE));
580
581         /* "groupType" flags */
582         PyModule_AddObject(m, "GTYPE_SECURITY_BUILTIN_LOCAL_GROUP",
583                                            PyInt_FromLong(GTYPE_SECURITY_BUILTIN_LOCAL_GROUP));
584         PyModule_AddObject(m, "GTYPE_SECURITY_GLOBAL_GROUP",
585                                            PyInt_FromLong(GTYPE_SECURITY_GLOBAL_GROUP));
586         PyModule_AddObject(m, "GTYPE_SECURITY_DOMAIN_LOCAL_GROUP",
587                                            PyInt_FromLong(GTYPE_SECURITY_DOMAIN_LOCAL_GROUP));
588         PyModule_AddObject(m, "GTYPE_SECURITY_UNIVERSAL_GROUP",
589                                            PyInt_FromLong(GTYPE_SECURITY_UNIVERSAL_GROUP));
590         PyModule_AddObject(m, "GTYPE_DISTRIBUTION_GLOBAL_GROUP",
591                                            PyInt_FromLong(GTYPE_DISTRIBUTION_GLOBAL_GROUP));
592         PyModule_AddObject(m, "GTYPE_DISTRIBUTION_DOMAIN_LOCAL_GROUP",
593                                            PyInt_FromLong(GTYPE_DISTRIBUTION_DOMAIN_LOCAL_GROUP));
594         PyModule_AddObject(m, "GTYPE_DISTRIBUTION_UNIVERSAL_GROUP",
595                                            PyInt_FromLong(GTYPE_DISTRIBUTION_UNIVERSAL_GROUP));
596
597         /* "sAMAccountType" flags */
598         PyModule_AddObject(m, "ATYPE_NORMAL_ACCOUNT",
599                                            PyInt_FromLong(ATYPE_NORMAL_ACCOUNT));
600         PyModule_AddObject(m, "ATYPE_WORKSTATION_TRUST",
601                                            PyInt_FromLong(ATYPE_WORKSTATION_TRUST));
602         PyModule_AddObject(m, "ATYPE_INTERDOMAIN_TRUST",
603                                            PyInt_FromLong(ATYPE_INTERDOMAIN_TRUST));
604         PyModule_AddObject(m, "ATYPE_SECURITY_GLOBAL_GROUP",
605                                            PyInt_FromLong(ATYPE_SECURITY_GLOBAL_GROUP));
606         PyModule_AddObject(m, "ATYPE_SECURITY_LOCAL_GROUP",
607                                            PyInt_FromLong(ATYPE_SECURITY_LOCAL_GROUP));
608         PyModule_AddObject(m, "ATYPE_SECURITY_UNIVERSAL_GROUP",
609                                            PyInt_FromLong(ATYPE_SECURITY_UNIVERSAL_GROUP));
610         PyModule_AddObject(m, "ATYPE_DISTRIBUTION_GLOBAL_GROUP",
611                                            PyInt_FromLong(ATYPE_DISTRIBUTION_GLOBAL_GROUP));
612         PyModule_AddObject(m, "ATYPE_DISTRIBUTION_LOCAL_GROUP",
613                                            PyInt_FromLong(ATYPE_DISTRIBUTION_LOCAL_GROUP));
614         PyModule_AddObject(m, "ATYPE_DISTRIBUTION_UNIVERSAL_GROUP",
615                                            PyInt_FromLong(ATYPE_DISTRIBUTION_UNIVERSAL_GROUP));
616
617         /* "domainFunctionality", "forestFunctionality" flags in the rootDSE */
618         PyModule_AddObject(m, "DS_DOMAIN_FUNCTION_2000",
619                                            PyInt_FromLong(DS_DOMAIN_FUNCTION_2000));
620         PyModule_AddObject(m, "DS_DOMAIN_FUNCTION_2003_MIXED",
621                                            PyInt_FromLong(DS_DOMAIN_FUNCTION_2003_MIXED));
622         PyModule_AddObject(m, "DS_DOMAIN_FUNCTION_2003",
623                                            PyInt_FromLong(DS_DOMAIN_FUNCTION_2003));
624         PyModule_AddObject(m, "DS_DOMAIN_FUNCTION_2008",
625                                            PyInt_FromLong(DS_DOMAIN_FUNCTION_2008));
626         PyModule_AddObject(m, "DS_DOMAIN_FUNCTION_2008_R2",
627                                            PyInt_FromLong(DS_DOMAIN_FUNCTION_2008_R2));
628
629         /* "systemFlags" */
630         PyModule_AddObject(m, "SYSTEM_FLAG_CR_NTDS_NC",
631                                         PyInt_FromLong(SYSTEM_FLAG_CR_NTDS_NC));
632         PyModule_AddObject(m, "SYSTEM_FLAG_CR_NTDS_DOMAIN",
633                                         PyInt_FromLong(SYSTEM_FLAG_CR_NTDS_DOMAIN));
634         PyModule_AddObject(m, "SYSTEM_FLAG_CR_NTDS_NOT_GC_REPLICATED",
635                                         PyInt_FromLong(SYSTEM_FLAG_CR_NTDS_NOT_GC_REPLICATED));
636         PyModule_AddObject(m, "SYSTEM_FLAG_SCHEMA_BASE_OBJECT",
637                                         PyInt_FromLong(SYSTEM_FLAG_SCHEMA_BASE_OBJECT));
638         PyModule_AddObject(m, "SYSTEM_FLAG_ATTR_IS_RDN",
639                                         PyInt_FromLong(SYSTEM_FLAG_ATTR_IS_RDN));
640         PyModule_AddObject(m, "SYSTEM_FLAG_DISALLOW_MOVE_ON_DELETE",
641                                         PyInt_FromLong(SYSTEM_FLAG_DISALLOW_MOVE_ON_DELETE));
642         PyModule_AddObject(m, "SYSTEM_FLAG_DOMAIN_DISALLOW_MOVE",
643                                         PyInt_FromLong(SYSTEM_FLAG_DOMAIN_DISALLOW_MOVE));
644         PyModule_AddObject(m, "SYSTEM_FLAG_DOMAIN_DISALLOW_RENAME",
645                                         PyInt_FromLong(SYSTEM_FLAG_DOMAIN_DISALLOW_RENAME));
646         PyModule_AddObject(m, "SYSTEM_FLAG_CONFIG_ALLOW_LIMITED_MOVE",
647                                         PyInt_FromLong(SYSTEM_FLAG_CONFIG_ALLOW_LIMITED_MOVE));
648         PyModule_AddObject(m, "SYSTEM_FLAG_CONFIG_ALLOW_MOVE",
649                                         PyInt_FromLong(SYSTEM_FLAG_CONFIG_ALLOW_MOVE));
650         PyModule_AddObject(m, "SYSTEM_FLAG_CONFIG_ALLOW_RENAME",
651                                         PyInt_FromLong(SYSTEM_FLAG_CONFIG_ALLOW_RENAME));
652         PyModule_AddObject(m, "SYSTEM_FLAG_DISALLOW_DELETE",
653                                         PyInt_FromLong(SYSTEM_FLAG_DISALLOW_DELETE));
654
655         /* Kerberos encryption type constants */
656         PyModule_AddObject(m, "ENC_ALL_TYPES",
657                            PyInt_FromLong(ENC_ALL_TYPES));
658         PyModule_AddObject(m, "ENC_CRC32",
659                            PyInt_FromLong(ENC_CRC32));
660         PyModule_AddObject(m, "ENC_RSA_MD5",
661                            PyInt_FromLong(ENC_RSA_MD5));
662         PyModule_AddObject(m, "ENC_RC4_HMAC_MD5",
663                            PyInt_FromLong(ENC_RC4_HMAC_MD5));
664         PyModule_AddObject(m, "ENC_HMAC_SHA1_96_AES128",
665                            PyInt_FromLong(ENC_HMAC_SHA1_96_AES128));
666         PyModule_AddObject(m, "ENC_HMAC_SHA1_96_AES256",
667                            PyInt_FromLong(ENC_HMAC_SHA1_96_AES256));
668
669         PyModule_AddObject(m, "SEARCH_FLAG_ATTINDEX", PyInt_FromLong(SEARCH_FLAG_ATTINDEX));
670         PyModule_AddObject(m, "SEARCH_FLAG_PDNTATTINDEX", PyInt_FromLong(SEARCH_FLAG_PDNTATTINDEX));
671         PyModule_AddObject(m, "SEARCH_FLAG_ANR", PyInt_FromLong(SEARCH_FLAG_ANR));
672         PyModule_AddObject(m, "SEARCH_FLAG_PRESERVEONDELETE", PyInt_FromLong(SEARCH_FLAG_PRESERVEONDELETE));
673         PyModule_AddObject(m, "SEARCH_FLAG_COPY", PyInt_FromLong(SEARCH_FLAG_COPY));
674         PyModule_AddObject(m, "SEARCH_FLAG_TUPLEINDEX", PyInt_FromLong(SEARCH_FLAG_TUPLEINDEX));
675         PyModule_AddObject(m, "SEARCH_FLAG_SUBTREEATTRINDEX", PyInt_FromLong(SEARCH_FLAG_SUBTREEATTRINDEX));
676         PyModule_AddObject(m, "SEARCH_FLAG_CONFIDENTIAL", PyInt_FromLong(SEARCH_FLAG_CONFIDENTIAL));
677         PyModule_AddObject(m, "SEARCH_FLAG_NEVERVALUEAUDIT", PyInt_FromLong(SEARCH_FLAG_NEVERVALUEAUDIT));
678         PyModule_AddObject(m, "SEARCH_FLAG_RODC_ATTRIBUTE", PyInt_FromLong(SEARCH_FLAG_RODC_ATTRIBUTE));
679
680         PyModule_AddObject(m, "DS_FLAG_ATTR_NOT_REPLICATED", PyInt_FromLong(DS_FLAG_ATTR_NOT_REPLICATED));
681         PyModule_AddObject(m, "DS_FLAG_ATTR_REQ_PARTIAL_SET_MEMBER", PyInt_FromLong(DS_FLAG_ATTR_REQ_PARTIAL_SET_MEMBER));
682         PyModule_AddObject(m, "DS_FLAG_ATTR_IS_CONSTRUCTED", PyInt_FromLong(DS_FLAG_ATTR_IS_CONSTRUCTED));
683 }