2 Python interface to passdb
4 Copyright (C) Amitay Isaacs 2011
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/>.
23 #include "lib/util/talloc_stack.h"
24 #include "libcli/security/security.h"
25 #include "librpc/gen_ndr/idmap.h"
30 /* There's no Py_ssize_t in 2.4, apparently */
31 #if PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION < 5
32 typedef int Py_ssize_t
;
33 typedef inquiry lenfunc
;
34 typedef intargfunc ssizeargfunc
;
37 #ifndef Py_TYPE /* Py_TYPE is only available on Python > 2.6 */
38 #define Py_TYPE(ob) (((PyObject*)(ob))->ob_type)
42 #define PY_CHECK_TYPE(type, var, fail) \
43 if (!PyObject_TypeCheck(var, type)) {\
44 PyErr_Format(PyExc_TypeError, __location__ ": Expected type '%s' for '%s' of type '%s'", (type)->tp_name, #var, Py_TYPE(var)->tp_name); \
50 static PyTypeObject
*dom_sid_Type
= NULL
;
51 static PyTypeObject
*security_Type
= NULL
;
52 static PyTypeObject
*guid_Type
= NULL
;
54 static PyTypeObject PySamu
;
55 static PyTypeObject PyGroupmap
;
56 static PyTypeObject PyPDB
;
58 static PyObject
*py_pdb_error
;
60 void initpassdb(void);
63 /************************** PIDL Autogeneratd ******************************/
65 static PyObject
*py_samu_get_logon_time(PyObject
*obj
, void *closure
)
67 TALLOC_CTX
*frame
= talloc_stackframe();
68 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
69 PyObject
*py_logon_time
;
71 py_logon_time
= PyInt_FromLong(pdb_get_logon_time(sam_acct
));
76 static int py_samu_set_logon_time(PyObject
*obj
, PyObject
*value
, void *closure
)
78 TALLOC_CTX
*frame
= talloc_stackframe();
79 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
81 PY_CHECK_TYPE(&PyInt_Type
, value
, return -1;);
82 if (!pdb_set_logon_time(sam_acct
, PyInt_AsLong(value
), PDB_CHANGED
)) {
90 static PyObject
*py_samu_get_logoff_time(PyObject
*obj
, void *closure
)
92 TALLOC_CTX
*frame
= talloc_stackframe();
93 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
94 PyObject
*py_logoff_time
;
96 py_logoff_time
= PyInt_FromLong(pdb_get_logoff_time(sam_acct
));
98 return py_logoff_time
;
101 static int py_samu_set_logoff_time(PyObject
*obj
, PyObject
*value
, void *closure
)
103 TALLOC_CTX
*frame
= talloc_stackframe();
104 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
106 PY_CHECK_TYPE(&PyInt_Type
, value
, return -1;);
107 if (!pdb_set_logoff_time(sam_acct
, PyInt_AsLong(value
), PDB_CHANGED
)) {
115 static PyObject
*py_samu_get_kickoff_time(PyObject
*obj
, void *closure
)
117 TALLOC_CTX
*frame
= talloc_stackframe();
118 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
119 PyObject
*py_kickoff_time
;
121 py_kickoff_time
= PyInt_FromLong(pdb_get_kickoff_time(sam_acct
));
123 return py_kickoff_time
;
126 static int py_samu_set_kickoff_time(PyObject
*obj
, PyObject
*value
, void *closure
)
128 TALLOC_CTX
*frame
= talloc_stackframe();
129 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
131 PY_CHECK_TYPE(&PyInt_Type
, value
, return -1;);
132 if (!pdb_set_kickoff_time(sam_acct
, PyInt_AsLong(value
), PDB_CHANGED
)) {
140 static PyObject
*py_samu_get_bad_password_time(PyObject
*obj
, void *closure
)
142 TALLOC_CTX
*frame
= talloc_stackframe();
143 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
144 PyObject
*py_bad_password_time
;
146 py_bad_password_time
= PyInt_FromLong(pdb_get_bad_password_time(sam_acct
));
148 return py_bad_password_time
;
151 static int py_samu_set_bad_password_time(PyObject
*obj
, PyObject
*value
, void *closure
)
153 TALLOC_CTX
*frame
= talloc_stackframe();
154 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
156 PY_CHECK_TYPE(&PyInt_Type
, value
, return -1;);
157 if (!pdb_set_bad_password_time(sam_acct
, PyInt_AsLong(value
), PDB_CHANGED
)) {
165 static PyObject
*py_samu_get_pass_last_set_time(PyObject
*obj
, void *closure
)
167 TALLOC_CTX
*frame
= talloc_stackframe();
168 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
169 PyObject
*py_pass_last_set_time
;
171 py_pass_last_set_time
= PyInt_FromLong(pdb_get_pass_last_set_time(sam_acct
));
173 return py_pass_last_set_time
;
176 static int py_samu_set_pass_last_set_time(PyObject
*obj
, PyObject
*value
, void *closure
)
178 TALLOC_CTX
*frame
= talloc_stackframe();
179 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
181 PY_CHECK_TYPE(&PyInt_Type
, value
, return -1;);
182 if (!pdb_set_pass_last_set_time(sam_acct
, PyInt_AsLong(value
), PDB_CHANGED
)) {
190 static PyObject
*py_samu_get_pass_can_change_time(PyObject
*obj
, void *closure
)
192 TALLOC_CTX
*frame
= talloc_stackframe();
193 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
194 PyObject
*py_pass_can_change_time
;
196 py_pass_can_change_time
= PyInt_FromLong(pdb_get_pass_can_change_time(sam_acct
));
198 return py_pass_can_change_time
;
201 static int py_samu_set_pass_can_change_time(PyObject
*obj
, PyObject
*value
, void *closure
)
203 TALLOC_CTX
*frame
= talloc_stackframe();
204 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
206 PY_CHECK_TYPE(&PyInt_Type
, value
, return -1;);
207 if (!pdb_set_pass_can_change_time(sam_acct
, PyInt_AsLong(value
), PDB_CHANGED
)) {
215 static PyObject
*py_samu_get_pass_must_change_time(PyObject
*obj
, void *closure
)
217 TALLOC_CTX
*frame
= talloc_stackframe();
218 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
219 PyObject
*py_pass_must_change_time
;
221 py_pass_must_change_time
= PyInt_FromLong(pdb_get_pass_must_change_time(sam_acct
));
223 return py_pass_must_change_time
;
226 static int py_samu_set_pass_must_change_time(PyObject
*obj
, PyObject
*value
, void *closure
)
228 TALLOC_CTX
*frame
= talloc_stackframe();
229 PY_CHECK_TYPE(&PyInt_Type
, value
, return -1;);
231 /* TODO: make this not a get/set or give a better exception */
236 static PyObject
*py_samu_get_username(PyObject
*obj
, void *closure
)
238 TALLOC_CTX
*frame
= talloc_stackframe();
239 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
240 PyObject
*py_username
;
241 const char *username
;
243 username
= pdb_get_username(sam_acct
);
244 if (username
== NULL
) {
248 py_username
= PyString_FromString(username
);
253 static int py_samu_set_username(PyObject
*obj
, PyObject
*value
, void *closure
)
255 TALLOC_CTX
*frame
= talloc_stackframe();
256 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
258 PY_CHECK_TYPE(&PyString_Type
, value
, return -1;);
259 if (!pdb_set_username(sam_acct
, PyString_AsString(value
), PDB_CHANGED
)) {
267 static PyObject
*py_samu_get_domain(PyObject
*obj
, void *closure
)
269 TALLOC_CTX
*frame
= talloc_stackframe();
270 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
274 domain
= pdb_get_domain(sam_acct
);
275 if (domain
== NULL
) {
279 py_domain
= PyString_FromString(domain
);
284 static int py_samu_set_domain(PyObject
*obj
, PyObject
*value
, void *closure
)
286 TALLOC_CTX
*frame
= talloc_stackframe();
287 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
289 PY_CHECK_TYPE(&PyString_Type
, value
, return -1;);
290 if (!pdb_set_domain(sam_acct
, PyString_AsString(value
), PDB_CHANGED
)) {
298 static PyObject
*py_samu_get_nt_username(PyObject
*obj
, void *closure
)
300 TALLOC_CTX
*frame
= talloc_stackframe();
301 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
302 PyObject
*py_nt_username
;
303 const char *nt_username
;
305 nt_username
= pdb_get_nt_username(sam_acct
);
306 if (nt_username
== NULL
) {
310 py_nt_username
= PyString_FromString(nt_username
);
312 return py_nt_username
;
315 static int py_samu_set_nt_username(PyObject
*obj
, PyObject
*value
, void *closure
)
317 TALLOC_CTX
*frame
= talloc_stackframe();
318 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
320 PY_CHECK_TYPE(&PyString_Type
, value
, return -1;);
321 if (!pdb_set_nt_username(sam_acct
, PyString_AsString(value
), PDB_CHANGED
)) {
329 static PyObject
*py_samu_get_full_name(PyObject
*obj
, void *closure
)
331 TALLOC_CTX
*frame
= talloc_stackframe();
332 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
333 PyObject
*py_full_name
;
334 const char *full_name
;
336 full_name
= pdb_get_fullname(sam_acct
);
337 if (full_name
== NULL
) {
341 py_full_name
= PyString_FromString(full_name
);
346 static int py_samu_set_full_name(PyObject
*obj
, PyObject
*value
, void *closure
)
348 TALLOC_CTX
*frame
= talloc_stackframe();
349 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
351 PY_CHECK_TYPE(&PyString_Type
, value
, return -1;);
352 if (!pdb_set_fullname(sam_acct
, PyString_AsString(value
), PDB_CHANGED
)) {
360 static PyObject
*py_samu_get_home_dir(PyObject
*obj
, void *closure
)
362 TALLOC_CTX
*frame
= talloc_stackframe();
363 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
364 PyObject
*py_home_dir
;
365 const char *home_dir
;
367 home_dir
= pdb_get_homedir(sam_acct
);
368 if (home_dir
== NULL
) {
372 py_home_dir
= PyString_FromString(home_dir
);
377 static int py_samu_set_home_dir(PyObject
*obj
, PyObject
*value
, void *closure
)
379 TALLOC_CTX
*frame
= talloc_stackframe();
380 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
382 PY_CHECK_TYPE(&PyString_Type
, value
, return -1;);
383 if (!pdb_set_homedir(sam_acct
, PyString_AsString(value
), PDB_CHANGED
)) {
391 static PyObject
*py_samu_get_dir_drive(PyObject
*obj
, void *closure
)
393 TALLOC_CTX
*frame
= talloc_stackframe();
394 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
395 PyObject
*py_dir_drive
;
396 const char *dir_drive
;
398 dir_drive
= pdb_get_dir_drive(sam_acct
);
399 if (dir_drive
== NULL
) {
403 py_dir_drive
= PyString_FromString(dir_drive
);
408 static int py_samu_set_dir_drive(PyObject
*obj
, PyObject
*value
, void *closure
)
410 TALLOC_CTX
*frame
= talloc_stackframe();
411 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
413 PY_CHECK_TYPE(&PyString_Type
, value
, return -1;);
414 if (!pdb_set_dir_drive(sam_acct
, PyString_AsString(value
), PDB_CHANGED
)) {
422 static PyObject
*py_samu_get_logon_script(PyObject
*obj
, void *closure
)
424 TALLOC_CTX
*frame
= talloc_stackframe();
425 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
426 PyObject
*py_logon_script
;
427 const char *logon_script
;
429 logon_script
= pdb_get_logon_script(sam_acct
);
430 if (logon_script
== NULL
) {
434 py_logon_script
= PyString_FromString(logon_script
);
436 return py_logon_script
;
439 static int py_samu_set_logon_script(PyObject
*obj
, PyObject
*value
, void *closure
)
441 TALLOC_CTX
*frame
= talloc_stackframe();
442 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
444 PY_CHECK_TYPE(&PyString_Type
, value
, return -1;);
445 if (!pdb_set_logon_script(sam_acct
, PyString_AsString(value
), PDB_CHANGED
)) {
453 static PyObject
*py_samu_get_profile_path(PyObject
*obj
, void *closure
)
455 TALLOC_CTX
*frame
= talloc_stackframe();
456 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
457 PyObject
*py_profile_path
;
458 const char *profile_path
;
460 profile_path
= pdb_get_profile_path(sam_acct
);
461 if (profile_path
== NULL
) {
465 py_profile_path
= PyString_FromString(profile_path
);
467 return py_profile_path
;
470 static int py_samu_set_profile_path(PyObject
*obj
, PyObject
*value
, void *closure
)
472 TALLOC_CTX
*frame
= talloc_stackframe();
473 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
475 PY_CHECK_TYPE(&PyString_Type
, value
, return -1;);
476 if (!pdb_set_profile_path(sam_acct
, PyString_AsString(value
), PDB_CHANGED
)) {
484 static PyObject
*py_samu_get_acct_desc(PyObject
*obj
, void *closure
)
486 TALLOC_CTX
*frame
= talloc_stackframe();
487 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
488 PyObject
*py_acct_desc
;
489 const char *acct_desc
;
491 acct_desc
= pdb_get_acct_desc(sam_acct
);
492 if (acct_desc
== NULL
) {
496 py_acct_desc
= PyString_FromString(acct_desc
);
501 static int py_samu_set_acct_desc(PyObject
*obj
, PyObject
*value
, void *closure
)
503 TALLOC_CTX
*frame
= talloc_stackframe();
504 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
506 PY_CHECK_TYPE(&PyString_Type
, value
, return -1;);
507 if (!pdb_set_acct_desc(sam_acct
, PyString_AsString(value
), PDB_CHANGED
)) {
515 static PyObject
*py_samu_get_workstations(PyObject
*obj
, void *closure
)
517 TALLOC_CTX
*frame
= talloc_stackframe();
518 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
519 PyObject
*py_workstations
;
520 const char *workstations
;
522 workstations
= pdb_get_workstations(sam_acct
);
523 if (workstations
== NULL
) {
527 py_workstations
= PyString_FromString(workstations
);
529 return py_workstations
;
532 static int py_samu_set_workstations(PyObject
*obj
, PyObject
*value
, void *closure
)
534 TALLOC_CTX
*frame
= talloc_stackframe();
535 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
537 PY_CHECK_TYPE(&PyString_Type
, value
, return -1;);
538 if (!pdb_set_workstations(sam_acct
, PyString_AsString(value
), PDB_CHANGED
)) {
546 static PyObject
*py_samu_get_comment(PyObject
*obj
, void *closure
)
548 TALLOC_CTX
*frame
= talloc_stackframe();
549 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
550 PyObject
*py_comment
;
553 comment
= pdb_get_comment(sam_acct
);
554 if (comment
== NULL
) {
558 py_comment
= PyString_FromString(comment
);
563 static int py_samu_set_comment(PyObject
*obj
, PyObject
*value
, void *closure
)
565 TALLOC_CTX
*frame
= talloc_stackframe();
566 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
568 PY_CHECK_TYPE(&PyString_Type
, value
, return -1;);
569 if (!pdb_set_comment(sam_acct
, PyString_AsString(value
), PDB_CHANGED
)) {
577 static PyObject
*py_samu_get_munged_dial(PyObject
*obj
, void *closure
)
579 TALLOC_CTX
*frame
= talloc_stackframe();
580 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
581 PyObject
*py_munged_dial
;
582 const char *munged_dial
;
584 munged_dial
= pdb_get_munged_dial(sam_acct
);
585 if (munged_dial
== NULL
) {
589 py_munged_dial
= PyString_FromString(munged_dial
);
591 return py_munged_dial
;
594 static int py_samu_set_munged_dial(PyObject
*obj
, PyObject
*value
, void *closure
)
596 TALLOC_CTX
*frame
= talloc_stackframe();
597 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
599 PY_CHECK_TYPE(&PyString_Type
, value
, return -1;);
600 if (!pdb_set_munged_dial(sam_acct
, PyString_AsString(value
), PDB_CHANGED
)) {
608 static PyObject
*py_samu_get_user_sid(PyObject
*obj
, void *closure
)
610 TALLOC_CTX
*frame
= talloc_stackframe();
611 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
612 PyObject
*py_user_sid
;
613 const struct dom_sid
*user_sid
;
614 struct dom_sid
*copy_user_sid
;
617 user_sid
= pdb_get_user_sid(sam_acct
);
618 if(user_sid
== NULL
) {
622 mem_ctx
= talloc_new(NULL
);
623 if (mem_ctx
== NULL
) {
628 copy_user_sid
= dom_sid_dup(mem_ctx
, user_sid
);
629 if (copy_user_sid
== NULL
) {
631 talloc_free(mem_ctx
);
636 py_user_sid
= pytalloc_steal(dom_sid_Type
, copy_user_sid
);
638 talloc_free(mem_ctx
);
644 static int py_samu_set_user_sid(PyObject
*obj
, PyObject
*value
, void *closure
)
646 TALLOC_CTX
*frame
= talloc_stackframe();
647 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
649 PY_CHECK_TYPE(dom_sid_Type
, value
, return -1;);
650 if (!pdb_set_user_sid(sam_acct
, (struct dom_sid
*)pytalloc_get_ptr(value
), PDB_CHANGED
)) {
658 static PyObject
*py_samu_get_group_sid(PyObject
*obj
, void *closure
)
660 TALLOC_CTX
*frame
= talloc_stackframe();
661 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
662 const struct dom_sid
*group_sid
;
663 struct dom_sid
*copy_group_sid
;
665 group_sid
= pdb_get_group_sid(sam_acct
);
666 if (group_sid
== NULL
) {
670 copy_group_sid
= dom_sid_dup(NULL
, group_sid
);
671 if (copy_group_sid
== NULL
) {
678 return pytalloc_steal(dom_sid_Type
, copy_group_sid
);
681 static int py_samu_set_group_sid(PyObject
*obj
, PyObject
*value
, void *closure
)
683 TALLOC_CTX
*frame
= talloc_stackframe();
684 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
686 PY_CHECK_TYPE(dom_sid_Type
, value
, return -1;);
687 if (!pdb_set_group_sid(sam_acct
, (struct dom_sid
*)pytalloc_get_ptr(value
), PDB_CHANGED
)) {
695 static PyObject
*py_samu_get_lanman_passwd(PyObject
*obj
, void *closure
)
697 TALLOC_CTX
*frame
= talloc_stackframe();
698 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
702 lm_pw
= (const char *)pdb_get_lanman_passwd(sam_acct
);
707 py_lm_pw
= PyString_FromStringAndSize(lm_pw
, LM_HASH_LEN
);
712 static int py_samu_set_lanman_passwd(PyObject
*obj
, PyObject
*value
, void *closure
)
714 TALLOC_CTX
*frame
= talloc_stackframe();
715 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
717 PY_CHECK_TYPE(&PyString_Type
, value
, return -1;);
718 if (!pdb_set_lanman_passwd(sam_acct
, (uint8_t *)PyString_AsString(value
), PDB_CHANGED
)) {
726 static PyObject
*py_samu_get_nt_passwd(PyObject
*obj
, void *closure
)
728 TALLOC_CTX
*frame
= talloc_stackframe();
729 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
733 nt_pw
= (const char *)pdb_get_nt_passwd(sam_acct
);
738 py_nt_pw
= PyString_FromStringAndSize(nt_pw
, NT_HASH_LEN
);
743 static int py_samu_set_nt_passwd(PyObject
*obj
, PyObject
*value
, void *closure
)
745 TALLOC_CTX
*frame
= talloc_stackframe();
746 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
748 if (!pdb_set_nt_passwd(sam_acct
, (uint8_t *)PyString_AsString(value
), PDB_CHANGED
)) {
756 static PyObject
*py_samu_get_pw_history(PyObject
*obj
, void *closure
)
758 TALLOC_CTX
*frame
= talloc_stackframe();
759 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
760 PyObject
*py_nt_pw_his
;
761 const char *nt_pw_his
;
764 nt_pw_his
= (const char *)pdb_get_pw_history(sam_acct
, &hist_len
);
765 if (nt_pw_his
== NULL
) {
769 py_nt_pw_his
= PyString_FromStringAndSize(nt_pw_his
, hist_len
*PW_HISTORY_ENTRY_LEN
);
774 static int py_samu_set_pw_history(PyObject
*obj
, PyObject
*value
, void *closure
)
776 TALLOC_CTX
*frame
= talloc_stackframe();
777 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
782 PyString_AsStringAndSize(value
, &nt_pw_his
, &len
);
783 hist_len
= len
/ PW_HISTORY_ENTRY_LEN
;
784 if (!pdb_set_pw_history(sam_acct
, (uint8_t *)nt_pw_his
, hist_len
, PDB_CHANGED
)) {
792 static PyObject
*py_samu_get_plaintext_passwd(PyObject
*obj
, void *closure
)
794 TALLOC_CTX
*frame
= talloc_stackframe();
795 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
796 PyObject
*py_plaintext_pw
;
797 const char *plaintext_pw
;
799 plaintext_pw
= pdb_get_plaintext_passwd(sam_acct
);
800 if (plaintext_pw
== NULL
) {
804 py_plaintext_pw
= PyString_FromString(plaintext_pw
);
806 return py_plaintext_pw
;
809 static int py_samu_set_plaintext_passwd(PyObject
*obj
, PyObject
*value
, void *closure
)
811 TALLOC_CTX
*frame
= talloc_stackframe();
812 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
814 if (!pdb_set_plaintext_passwd(sam_acct
, PyString_AsString(value
))) {
822 static PyObject
*py_samu_get_acct_ctrl(PyObject
*obj
, void *closure
)
824 TALLOC_CTX
*frame
= talloc_stackframe();
825 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
826 PyObject
*py_acct_ctrl
;
828 py_acct_ctrl
= PyInt_FromLong(pdb_get_acct_ctrl(sam_acct
));
833 static int py_samu_set_acct_ctrl(PyObject
*obj
, PyObject
*value
, void *closure
)
835 TALLOC_CTX
*frame
= talloc_stackframe();
836 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
838 PY_CHECK_TYPE(&PyInt_Type
, value
, return -1;);
839 if (!pdb_set_acct_ctrl(sam_acct
, PyInt_AsLong(value
), PDB_CHANGED
)) {
847 static PyObject
*py_samu_get_logon_divs(PyObject
*obj
, void *closure
)
849 TALLOC_CTX
*frame
= talloc_stackframe();
850 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
851 PyObject
*py_logon_divs
;
853 py_logon_divs
= PyInt_FromLong(pdb_get_logon_divs(sam_acct
));
855 return py_logon_divs
;
858 static int py_samu_set_logon_divs(PyObject
*obj
, PyObject
*value
, void *closure
)
860 TALLOC_CTX
*frame
= talloc_stackframe();
861 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
863 PY_CHECK_TYPE(&PyInt_Type
, value
, return -1;);
864 if (!pdb_set_logon_divs(sam_acct
, PyInt_AsLong(value
), PDB_CHANGED
)) {
872 static PyObject
*py_samu_get_hours_len(PyObject
*obj
, void *closure
)
874 TALLOC_CTX
*frame
= talloc_stackframe();
875 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
876 PyObject
*py_hours_len
;
878 py_hours_len
= PyInt_FromLong(pdb_get_hours_len(sam_acct
));
883 static int py_samu_set_hours_len(PyObject
*obj
, PyObject
*value
, void *closure
)
885 TALLOC_CTX
*frame
= talloc_stackframe();
886 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
888 PY_CHECK_TYPE(&PyInt_Type
, value
, return -1;);
889 if (!pdb_set_hours_len(sam_acct
, PyInt_AsLong(value
), PDB_CHANGED
)) {
897 static PyObject
*py_samu_get_hours(PyObject
*obj
, void *closure
)
899 TALLOC_CTX
*frame
= talloc_stackframe();
900 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
905 hours
= (const char *)pdb_get_hours(sam_acct
);
910 hours_len
= pdb_get_hours_len(sam_acct
);
911 if ((py_hours
= PyList_New(hours_len
)) == NULL
) {
917 for (i
=0; i
<hours_len
; i
++) {
918 PyList_SetItem(py_hours
, i
, PyInt_FromLong(hours
[i
]));
924 static int py_samu_set_hours(PyObject
*obj
, PyObject
*value
, void *closure
)
926 TALLOC_CTX
*frame
= talloc_stackframe();
927 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
933 PY_CHECK_TYPE(&PyList_Type
, value
, return -1;);
935 hours_len
= PyList_GET_SIZE(value
);
937 hours
= talloc_array(pytalloc_get_mem_ctx(obj
), uint8_t, hours_len
);
944 for (i
=0; i
< hours_len
; i
++) {
945 PY_CHECK_TYPE(&PyInt_Type
, PyList_GET_ITEM(value
,i
), return -1;);
946 hours
[i
] = PyInt_AsLong(PyList_GET_ITEM(value
, i
));
949 status
= pdb_set_hours(sam_acct
, hours
, hours_len
, PDB_CHANGED
);
960 static PyObject
*py_samu_get_bad_password_count(PyObject
*obj
, void *closure
)
962 TALLOC_CTX
*frame
= talloc_stackframe();
963 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
964 PyObject
*py_bad_password_count
;
966 py_bad_password_count
= PyInt_FromLong(pdb_get_bad_password_count(sam_acct
));
968 return py_bad_password_count
;
971 static int py_samu_set_bad_password_count(PyObject
*obj
, PyObject
*value
, void *closure
)
973 TALLOC_CTX
*frame
= talloc_stackframe();
974 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
976 PY_CHECK_TYPE(&PyInt_Type
, value
, return -1;);
977 if (!pdb_set_bad_password_count(sam_acct
, PyInt_AsLong(value
), PDB_CHANGED
)) {
985 static PyObject
*py_samu_get_logon_count(PyObject
*obj
, void *closure
)
987 TALLOC_CTX
*frame
= talloc_stackframe();
988 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
989 PyObject
*py_logon_count
;
991 py_logon_count
= PyInt_FromLong(pdb_get_logon_count(sam_acct
));
993 return py_logon_count
;
996 static int py_samu_set_logon_count(PyObject
*obj
, PyObject
*value
, void *closure
)
998 TALLOC_CTX
*frame
= talloc_stackframe();
999 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
1001 PY_CHECK_TYPE(&PyInt_Type
, value
, return -1;);
1002 if (!pdb_set_logon_count(sam_acct
, PyInt_AsLong(value
), PDB_CHANGED
)) {
1010 static PyObject
*py_samu_get_country_code(PyObject
*obj
, void *closure
)
1012 TALLOC_CTX
*frame
= talloc_stackframe();
1013 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
1014 PyObject
*py_country_code
;
1016 py_country_code
= PyInt_FromLong(pdb_get_country_code(sam_acct
));
1018 return py_country_code
;
1021 static int py_samu_set_country_code(PyObject
*obj
, PyObject
*value
, void *closure
)
1023 TALLOC_CTX
*frame
= talloc_stackframe();
1024 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
1026 PY_CHECK_TYPE(&PyInt_Type
, value
, return -1;);
1027 if (!pdb_set_country_code(sam_acct
, PyInt_AsLong(value
), PDB_CHANGED
)) {
1035 static PyObject
*py_samu_get_code_page(PyObject
*obj
, void *closure
)
1037 TALLOC_CTX
*frame
= talloc_stackframe();
1038 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
1039 PyObject
*py_code_page
;
1041 py_code_page
= PyInt_FromLong(pdb_get_code_page(sam_acct
));
1043 return py_code_page
;
1046 static int py_samu_set_code_page(PyObject
*obj
, PyObject
*value
, void *closure
)
1048 TALLOC_CTX
*frame
= talloc_stackframe();
1049 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
1051 PY_CHECK_TYPE(&PyInt_Type
, value
, return -1;);
1052 if (!pdb_set_code_page(sam_acct
, PyInt_AsLong(value
), PDB_CHANGED
)) {
1060 static PyGetSetDef py_samu_getsetters
[] = {
1061 { discard_const_p(char, "logon_time"), py_samu_get_logon_time
, py_samu_set_logon_time
},
1062 { discard_const_p(char, "logoff_time"), py_samu_get_logoff_time
, py_samu_set_logoff_time
},
1063 { discard_const_p(char, "kickoff_time"), py_samu_get_kickoff_time
, py_samu_set_kickoff_time
},
1064 { discard_const_p(char, "bad_password_time"), py_samu_get_bad_password_time
, py_samu_set_bad_password_time
},
1065 { discard_const_p(char, "pass_last_set_time"), py_samu_get_pass_last_set_time
, py_samu_set_pass_last_set_time
},
1066 { discard_const_p(char, "pass_can_change_time"), py_samu_get_pass_can_change_time
, py_samu_set_pass_can_change_time
},
1067 { discard_const_p(char, "pass_must_change_time"), py_samu_get_pass_must_change_time
, py_samu_set_pass_must_change_time
},
1068 { discard_const_p(char, "username"), py_samu_get_username
, py_samu_set_username
},
1069 { discard_const_p(char, "domain"), py_samu_get_domain
, py_samu_set_domain
},
1070 { discard_const_p(char, "nt_username"), py_samu_get_nt_username
, py_samu_set_nt_username
},
1071 { discard_const_p(char, "full_name"), py_samu_get_full_name
, py_samu_set_full_name
},
1072 { discard_const_p(char, "home_dir"), py_samu_get_home_dir
, py_samu_set_home_dir
},
1073 { discard_const_p(char, "dir_drive"), py_samu_get_dir_drive
, py_samu_set_dir_drive
},
1074 { discard_const_p(char, "logon_script"), py_samu_get_logon_script
, py_samu_set_logon_script
},
1075 { discard_const_p(char, "profile_path"), py_samu_get_profile_path
, py_samu_set_profile_path
},
1076 { discard_const_p(char, "acct_desc"), py_samu_get_acct_desc
, py_samu_set_acct_desc
},
1077 { discard_const_p(char, "workstations"), py_samu_get_workstations
, py_samu_set_workstations
},
1078 { discard_const_p(char, "comment"), py_samu_get_comment
, py_samu_set_comment
},
1079 { discard_const_p(char, "munged_dial"), py_samu_get_munged_dial
, py_samu_set_munged_dial
},
1080 { discard_const_p(char, "user_sid"), py_samu_get_user_sid
, py_samu_set_user_sid
},
1081 { discard_const_p(char, "group_sid"), py_samu_get_group_sid
, py_samu_set_group_sid
},
1082 { discard_const_p(char, "lanman_passwd"), py_samu_get_lanman_passwd
, py_samu_set_lanman_passwd
},
1083 { discard_const_p(char, "nt_passwd"), py_samu_get_nt_passwd
, py_samu_set_nt_passwd
},
1084 { discard_const_p(char, "pw_history"), py_samu_get_pw_history
, py_samu_set_pw_history
},
1085 { discard_const_p(char, "plaintext_passwd"), py_samu_get_plaintext_passwd
, py_samu_set_plaintext_passwd
},
1086 { discard_const_p(char, "acct_ctrl"), py_samu_get_acct_ctrl
, py_samu_set_acct_ctrl
},
1087 { discard_const_p(char, "logon_divs"), py_samu_get_logon_divs
, py_samu_set_logon_divs
},
1088 { discard_const_p(char, "hours_len"), py_samu_get_hours_len
, py_samu_set_hours_len
},
1089 { discard_const_p(char, "hours"), py_samu_get_hours
, py_samu_set_hours
},
1090 { discard_const_p(char, "bad_password_count"), py_samu_get_bad_password_count
, py_samu_set_bad_password_count
},
1091 { discard_const_p(char, "logon_count"), py_samu_get_logon_count
, py_samu_set_logon_count
},
1092 { discard_const_p(char, "country_code"), py_samu_get_country_code
, py_samu_set_country_code
},
1093 { discard_const_p(char, "code_page"), py_samu_get_code_page
, py_samu_set_code_page
},
1098 /************************** PIDL Autogeneratd ******************************/
1100 static PyObject
*py_samu_new(PyTypeObject
*type
, PyObject
*args
, PyObject
*kwargs
)
1102 TALLOC_CTX
*frame
= talloc_stackframe();
1103 struct samu
*sam_acct
;
1105 sam_acct
= samu_new(NULL
);
1113 return pytalloc_steal(type
, sam_acct
);
1116 static PyTypeObject PySamu
= {
1117 .tp_name
= "passdb.Samu",
1118 .tp_basicsize
= sizeof(pytalloc_Object
),
1119 .tp_getset
= py_samu_getsetters
,
1121 .tp_new
= py_samu_new
,
1122 .tp_flags
= Py_TPFLAGS_DEFAULT
| Py_TPFLAGS_BASETYPE
,
1123 .tp_doc
= "Samu() -> samu object\n",
1127 static PyObject
*py_groupmap_get_gid(PyObject
*obj
, void *closure
)
1129 TALLOC_CTX
*frame
= talloc_stackframe();
1130 GROUP_MAP
*group_map
= (GROUP_MAP
*)pytalloc_get_ptr(obj
);
1133 py_gid
= Py_BuildValue("i", group_map
->gid
);
1138 static int py_groupmap_set_gid(PyObject
*obj
, PyObject
*value
, void *closure
)
1140 TALLOC_CTX
*frame
= talloc_stackframe();
1141 GROUP_MAP
*group_map
= (GROUP_MAP
*)pytalloc_get_ptr(obj
);
1143 PY_CHECK_TYPE(&PyInt_Type
, value
, return -1;);
1144 group_map
->gid
= PyInt_AsLong(value
);
1149 static PyObject
*py_groupmap_get_sid(PyObject
*obj
, void *closure
)
1151 TALLOC_CTX
*frame
= talloc_stackframe();
1152 GROUP_MAP
*group_map
= (GROUP_MAP
*)pytalloc_get_ptr(obj
);
1154 struct dom_sid
*group_sid
;
1155 TALLOC_CTX
*mem_ctx
;
1157 mem_ctx
= talloc_new(NULL
);
1158 if (mem_ctx
== NULL
) {
1164 group_sid
= dom_sid_dup(mem_ctx
, &group_map
->sid
);
1165 if (group_sid
== NULL
) {
1167 talloc_free(mem_ctx
);
1172 py_sid
= pytalloc_steal(dom_sid_Type
, group_sid
);
1174 talloc_free(mem_ctx
);
1180 static int py_groupmap_set_sid(PyObject
*obj
, PyObject
*value
, void *closure
)
1182 TALLOC_CTX
*frame
= talloc_stackframe();
1183 GROUP_MAP
*group_map
= (GROUP_MAP
*)pytalloc_get_ptr(obj
);
1185 PY_CHECK_TYPE(dom_sid_Type
, value
, return -1;);
1186 group_map
->sid
= *pytalloc_get_type(value
, struct dom_sid
);
1191 static PyObject
*py_groupmap_get_sid_name_use(PyObject
*obj
, void *closure
)
1193 TALLOC_CTX
*frame
= talloc_stackframe();
1194 GROUP_MAP
*group_map
= (GROUP_MAP
*)pytalloc_get_ptr(obj
);
1195 PyObject
*py_sid_name_use
;
1197 py_sid_name_use
= PyInt_FromLong(group_map
->sid_name_use
);
1199 return py_sid_name_use
;
1202 static int py_groupmap_set_sid_name_use(PyObject
*obj
, PyObject
*value
, void *closure
)
1204 TALLOC_CTX
*frame
= talloc_stackframe();
1205 GROUP_MAP
*group_map
= (GROUP_MAP
*)pytalloc_get_ptr(obj
);
1207 PY_CHECK_TYPE(&PyInt_Type
, value
, return -1;);
1208 group_map
->sid_name_use
= PyInt_AsLong(value
);
1213 static PyObject
*py_groupmap_get_nt_name(PyObject
*obj
, void *closure
)
1215 TALLOC_CTX
*frame
= talloc_stackframe();
1216 GROUP_MAP
*group_map
= (GROUP_MAP
*)pytalloc_get_ptr(obj
);
1217 PyObject
*py_nt_name
;
1218 if (group_map
->nt_name
== NULL
) {
1219 py_nt_name
= Py_None
;
1220 Py_INCREF(py_nt_name
);
1222 py_nt_name
= PyString_FromString(group_map
->nt_name
);
1228 static int py_groupmap_set_nt_name(PyObject
*obj
, PyObject
*value
, void *closure
)
1230 TALLOC_CTX
*frame
= talloc_stackframe();
1231 GROUP_MAP
*group_map
= (GROUP_MAP
*)pytalloc_get_ptr(obj
);
1233 PY_CHECK_TYPE(&PyString_Type
, value
, return -1;);
1234 if (value
== Py_None
) {
1235 fstrcpy(group_map
->nt_name
, NULL
);
1237 fstrcpy(group_map
->nt_name
, PyString_AsString(value
));
1243 static PyObject
*py_groupmap_get_comment(PyObject
*obj
, void *closure
)
1245 TALLOC_CTX
*frame
= talloc_stackframe();
1246 GROUP_MAP
*group_map
= (GROUP_MAP
*)pytalloc_get_ptr(obj
);
1247 PyObject
*py_comment
;
1248 if (group_map
->comment
== NULL
) {
1249 py_comment
= Py_None
;
1250 Py_INCREF(py_comment
);
1252 py_comment
= PyString_FromString(group_map
->comment
);
1258 static int py_groupmap_set_comment(PyObject
*obj
, PyObject
*value
, void *closure
)
1260 TALLOC_CTX
*frame
= talloc_stackframe();
1261 GROUP_MAP
*group_map
= (GROUP_MAP
*)pytalloc_get_ptr(obj
);
1263 PY_CHECK_TYPE(&PyString_Type
, value
, return -1;);
1264 if (value
== Py_None
) {
1265 fstrcpy(group_map
->comment
, NULL
);
1267 fstrcpy(group_map
->comment
, PyString_AsString(value
));
1273 static PyGetSetDef py_groupmap_getsetters
[] = {
1274 { discard_const_p(char, "gid"), py_groupmap_get_gid
, py_groupmap_set_gid
},
1275 { discard_const_p(char, "sid"), py_groupmap_get_sid
, py_groupmap_set_sid
},
1276 { discard_const_p(char, "sid_name_use"), py_groupmap_get_sid_name_use
, py_groupmap_set_sid_name_use
},
1277 { discard_const_p(char, "nt_name"), py_groupmap_get_nt_name
, py_groupmap_set_nt_name
},
1278 { discard_const_p(char, "comment"), py_groupmap_get_comment
, py_groupmap_set_comment
},
1282 static PyObject
*py_groupmap_new(PyTypeObject
*type
, PyObject
*args
, PyObject
*kwargs
)
1284 TALLOC_CTX
*frame
= talloc_stackframe();
1285 GROUP_MAP
*group_map
;
1286 TALLOC_CTX
*mem_ctx
;
1287 PyObject
*py_group_map
;
1289 mem_ctx
= talloc_new(NULL
);
1290 if (mem_ctx
== NULL
) {
1296 group_map
= talloc_zero(mem_ctx
, GROUP_MAP
);
1297 if (group_map
== NULL
) {
1299 talloc_free(mem_ctx
);
1304 py_group_map
= pytalloc_steal(type
, group_map
);
1305 if (py_group_map
== NULL
) {
1307 talloc_free(mem_ctx
);
1312 talloc_free(mem_ctx
);
1315 return py_group_map
;
1319 static PyTypeObject PyGroupmap
= {
1320 .tp_name
= "passdb.Groupmap",
1321 .tp_basicsize
= sizeof(pytalloc_Object
),
1322 .tp_getset
= py_groupmap_getsetters
,
1324 .tp_new
= py_groupmap_new
,
1325 .tp_flags
= Py_TPFLAGS_DEFAULT
| Py_TPFLAGS_BASETYPE
,
1326 .tp_doc
= "Groupmap() -> group map object\n",
1330 static PyObject
*py_pdb_domain_info(pytalloc_Object
*self
, PyObject
*args
)
1332 TALLOC_CTX
*frame
= talloc_stackframe();
1333 struct pdb_methods
*methods
;
1334 struct pdb_domain_info
*domain_info
;
1335 PyObject
*py_domain_info
;
1336 struct dom_sid
*sid
;
1339 methods
= pytalloc_get_ptr(self
);
1341 domain_info
= methods
->get_domain_info(methods
, frame
);
1342 if (! domain_info
) {
1346 sid
= dom_sid_dup(frame
, &domain_info
->sid
);
1353 guid
= talloc(frame
, struct GUID
);
1359 *guid
= domain_info
->guid
;
1361 if ((py_domain_info
= PyDict_New()) == NULL
) {
1367 PyDict_SetItemString(py_domain_info
, "name", PyString_FromString(domain_info
->name
));
1368 PyDict_SetItemString(py_domain_info
, "dns_domain", PyString_FromString(domain_info
->dns_domain
));
1369 PyDict_SetItemString(py_domain_info
, "dns_forest", PyString_FromString(domain_info
->dns_forest
));
1370 PyDict_SetItemString(py_domain_info
, "dom_sid", pytalloc_steal(dom_sid_Type
, sid
));
1371 PyDict_SetItemString(py_domain_info
, "guid", pytalloc_steal(guid_Type
, guid
));
1374 return py_domain_info
;
1378 static PyObject
*py_pdb_getsampwnam(pytalloc_Object
*self
, PyObject
*args
)
1380 TALLOC_CTX
*frame
= talloc_stackframe();
1382 const char *username
;
1383 struct pdb_methods
*methods
;
1384 struct samu
*sam_acct
;
1385 PyObject
*py_sam_acct
;
1387 if (!PyArg_ParseTuple(args
, "s:getsampwnam", &username
)) {
1392 methods
= pytalloc_get_ptr(self
);
1394 py_sam_acct
= py_samu_new(&PySamu
, NULL
, NULL
);
1395 if (py_sam_acct
== NULL
) {
1400 sam_acct
= (struct samu
*)pytalloc_get_ptr(py_sam_acct
);
1402 status
= methods
->getsampwnam(methods
, sam_acct
, username
);
1403 if (!NT_STATUS_IS_OK(status
)) {
1404 PyErr_Format(py_pdb_error
, "Unable to get user information for '%s', (%d,%s)",
1406 NT_STATUS_V(status
),
1407 get_friendly_nt_error_msg(status
));
1408 Py_DECREF(py_sam_acct
);
1417 static PyObject
*py_pdb_getsampwsid(pytalloc_Object
*self
, PyObject
*args
)
1419 TALLOC_CTX
*frame
= talloc_stackframe();
1421 struct pdb_methods
*methods
;
1422 struct samu
*sam_acct
;
1423 PyObject
*py_sam_acct
;
1424 PyObject
*py_user_sid
;
1426 if (!PyArg_ParseTuple(args
, "O:getsampwsid", &py_user_sid
)) {
1431 methods
= pytalloc_get_ptr(self
);
1433 py_sam_acct
= py_samu_new(&PySamu
, NULL
, NULL
);
1434 if (py_sam_acct
== NULL
) {
1439 sam_acct
= (struct samu
*)pytalloc_get_ptr(py_sam_acct
);
1441 status
= methods
->getsampwsid(methods
, sam_acct
, pytalloc_get_ptr(py_user_sid
));
1442 if (!NT_STATUS_IS_OK(status
)) {
1443 PyErr_Format(py_pdb_error
, "Unable to get user information from SID, (%d,%s)",
1444 NT_STATUS_V(status
),
1445 get_friendly_nt_error_msg(status
));
1446 Py_DECREF(py_sam_acct
);
1455 static PyObject
*py_pdb_create_user(pytalloc_Object
*self
, PyObject
*args
)
1457 TALLOC_CTX
*frame
= talloc_stackframe();
1459 struct pdb_methods
*methods
;
1460 const char *username
;
1461 unsigned int acct_flags
;
1464 if (!PyArg_ParseTuple(args
, "sI:create_user", &username
, &acct_flags
)) {
1469 methods
= pytalloc_get_ptr(self
);
1471 status
= methods
->create_user(methods
, frame
, username
, acct_flags
, &rid
);
1472 if (!NT_STATUS_IS_OK(status
)) {
1473 PyErr_Format(py_pdb_error
, "Unable to create user (%s), (%d,%s)",
1475 NT_STATUS_V(status
),
1476 get_friendly_nt_error_msg(status
));
1482 return PyInt_FromLong(rid
);
1485 static PyObject
*py_pdb_delete_user(pytalloc_Object
*self
, PyObject
*args
)
1487 TALLOC_CTX
*frame
= talloc_stackframe();
1489 struct pdb_methods
*methods
;
1490 struct samu
*sam_acct
;
1491 PyObject
*py_sam_acct
;
1493 if (!PyArg_ParseTuple(args
, "O!:delete_user", &PySamu
, &py_sam_acct
)) {
1498 methods
= pytalloc_get_ptr(self
);
1500 sam_acct
= pytalloc_get_ptr(py_sam_acct
);
1502 status
= methods
->delete_user(methods
, frame
, sam_acct
);
1503 if (!NT_STATUS_IS_OK(status
)) {
1504 PyErr_Format(py_pdb_error
, "Unable to delete user, (%d,%s)",
1505 NT_STATUS_V(status
),
1506 get_friendly_nt_error_msg(status
));
1515 static PyObject
*py_pdb_add_sam_account(pytalloc_Object
*self
, PyObject
*args
)
1517 TALLOC_CTX
*frame
= talloc_stackframe();
1519 struct pdb_methods
*methods
;
1520 struct samu
*sam_acct
;
1521 PyObject
*py_sam_acct
;
1523 if (!PyArg_ParseTuple(args
, "O!:add_sam_account", &PySamu
, &py_sam_acct
)) {
1528 methods
= pytalloc_get_ptr(self
);
1530 sam_acct
= pytalloc_get_ptr(py_sam_acct
);
1532 status
= methods
->add_sam_account(methods
, sam_acct
);
1533 if (!NT_STATUS_IS_OK(status
)) {
1534 PyErr_Format(py_pdb_error
, "Unable to add sam account '%s', (%d,%s)",
1536 NT_STATUS_V(status
),
1537 get_friendly_nt_error_msg(status
));
1546 static PyObject
*py_pdb_update_sam_account(pytalloc_Object
*self
, PyObject
*args
)
1548 TALLOC_CTX
*frame
= talloc_stackframe();
1550 struct pdb_methods
*methods
;
1551 struct samu
*sam_acct
;
1552 PyObject
*py_sam_acct
;
1554 if (!PyArg_ParseTuple(args
, "O!:update_sam_account", &PySamu
, &py_sam_acct
)) {
1559 methods
= pytalloc_get_ptr(self
);
1561 sam_acct
= pytalloc_get_ptr(py_sam_acct
);
1563 status
= methods
->update_sam_account(methods
, sam_acct
);
1564 if (!NT_STATUS_IS_OK(status
)) {
1565 PyErr_Format(py_pdb_error
, "Unable to update sam account, (%d,%s)",
1566 NT_STATUS_V(status
),
1567 get_friendly_nt_error_msg(status
));
1576 static PyObject
*py_pdb_delete_sam_account(pytalloc_Object
*self
, PyObject
*args
)
1578 TALLOC_CTX
*frame
= talloc_stackframe();
1580 struct pdb_methods
*methods
;
1581 struct samu
*sam_acct
;
1582 PyObject
*py_sam_acct
;
1584 if (!PyArg_ParseTuple(args
, "O!:delete_sam_account", &PySamu
, &py_sam_acct
)) {
1589 methods
= pytalloc_get_ptr(self
);
1591 sam_acct
= pytalloc_get_ptr(py_sam_acct
);
1593 status
= methods
->delete_sam_account(methods
, sam_acct
);
1594 if (!NT_STATUS_IS_OK(status
)) {
1595 PyErr_Format(py_pdb_error
, "Unable to delete sam account, (%d,%s)",
1596 NT_STATUS_V(status
),
1597 get_friendly_nt_error_msg(status
));
1606 static PyObject
*py_pdb_rename_sam_account(pytalloc_Object
*self
, PyObject
*args
)
1608 TALLOC_CTX
*frame
= talloc_stackframe();
1610 struct pdb_methods
*methods
;
1611 struct samu
*sam_acct
;
1612 const char *new_username
;
1613 PyObject
*py_sam_acct
;
1615 if (!PyArg_ParseTuple(args
, "O!s:rename_sam_account", &PySamu
, &py_sam_acct
,
1621 methods
= pytalloc_get_ptr(self
);
1623 sam_acct
= pytalloc_get_ptr(py_sam_acct
);
1625 status
= methods
->rename_sam_account(methods
, sam_acct
, new_username
);
1626 if (!NT_STATUS_IS_OK(status
)) {
1627 PyErr_Format(py_pdb_error
, "Unable to rename sam account, (%d,%s)",
1628 NT_STATUS_V(status
),
1629 get_friendly_nt_error_msg(status
));
1639 static PyObject
*py_pdb_getgrsid(pytalloc_Object
*self
, PyObject
*args
)
1641 TALLOC_CTX
*frame
= talloc_stackframe();
1643 struct pdb_methods
*methods
;
1644 GROUP_MAP
*group_map
;
1645 struct dom_sid
*domain_sid
;
1646 PyObject
*py_domain_sid
, *py_group_map
;
1648 if (!PyArg_ParseTuple(args
, "O!:getgrsid", dom_sid_Type
, &py_domain_sid
)) {
1653 methods
= pytalloc_get_ptr(self
);
1655 domain_sid
= pytalloc_get_ptr(py_domain_sid
);
1657 py_group_map
= py_groupmap_new(&PyGroupmap
, NULL
, NULL
);
1658 if (py_group_map
== NULL
) {
1664 group_map
= pytalloc_get_ptr(py_group_map
);
1666 status
= methods
->getgrsid(methods
, group_map
, *domain_sid
);
1667 if (!NT_STATUS_IS_OK(status
)) {
1668 PyErr_Format(py_pdb_error
, "Unable to get group information by sid, (%d,%s)",
1669 NT_STATUS_V(status
),
1670 get_friendly_nt_error_msg(status
));
1676 return py_group_map
;
1680 static PyObject
*py_pdb_getgrgid(pytalloc_Object
*self
, PyObject
*args
)
1682 TALLOC_CTX
*frame
= talloc_stackframe();
1684 struct pdb_methods
*methods
;
1685 GROUP_MAP
*group_map
;
1686 PyObject
*py_group_map
;
1687 unsigned int gid_value
;
1689 if (!PyArg_ParseTuple(args
, "I:getgrgid", &gid_value
)) {
1694 methods
= pytalloc_get_ptr(self
);
1696 py_group_map
= py_groupmap_new(&PyGroupmap
, NULL
, NULL
);
1697 if (py_group_map
== NULL
) {
1703 group_map
= pytalloc_get_ptr(py_group_map
);
1705 status
= methods
->getgrgid(methods
, group_map
, gid_value
);
1706 if (!NT_STATUS_IS_OK(status
)) {
1707 PyErr_Format(py_pdb_error
, "Unable to get group information by gid, (%d,%s)",
1708 NT_STATUS_V(status
),
1709 get_friendly_nt_error_msg(status
));
1715 return py_group_map
;
1719 static PyObject
*py_pdb_getgrnam(pytalloc_Object
*self
, PyObject
*args
)
1721 TALLOC_CTX
*frame
= talloc_stackframe();
1723 struct pdb_methods
*methods
;
1724 GROUP_MAP
*group_map
;
1725 PyObject
*py_group_map
;
1726 const char *groupname
;
1728 if (!PyArg_ParseTuple(args
, "s:getgrnam", &groupname
)) {
1733 methods
= pytalloc_get_ptr(self
);
1735 py_group_map
= py_groupmap_new(&PyGroupmap
, NULL
, NULL
);
1736 if (py_group_map
== NULL
) {
1742 group_map
= pytalloc_get_ptr(py_group_map
);
1744 status
= methods
->getgrnam(methods
, group_map
, groupname
);
1745 if (!NT_STATUS_IS_OK(status
)) {
1746 PyErr_Format(py_pdb_error
, "Unable to get group information by name, (%d,%s)",
1747 NT_STATUS_V(status
),
1748 get_friendly_nt_error_msg(status
));
1754 return py_group_map
;
1758 static PyObject
*py_pdb_create_dom_group(pytalloc_Object
*self
, PyObject
*args
)
1760 TALLOC_CTX
*frame
= talloc_stackframe();
1762 struct pdb_methods
*methods
;
1763 const char *groupname
;
1766 if (!PyArg_ParseTuple(args
, "s:create_dom_group", &groupname
)) {
1771 methods
= pytalloc_get_ptr(self
);
1773 status
= methods
->create_dom_group(methods
, frame
, groupname
, &group_rid
);
1774 if (!NT_STATUS_IS_OK(status
)) {
1775 PyErr_Format(py_pdb_error
, "Unable to create domain group (%s), (%d,%s)",
1777 NT_STATUS_V(status
),
1778 get_friendly_nt_error_msg(status
));
1784 return PyInt_FromLong(group_rid
);
1788 static PyObject
*py_pdb_delete_dom_group(pytalloc_Object
*self
, PyObject
*args
)
1790 TALLOC_CTX
*frame
= talloc_stackframe();
1792 struct pdb_methods
*methods
;
1793 unsigned int group_rid
;
1795 if (!PyArg_ParseTuple(args
, "I:delete_dom_group", &group_rid
)) {
1800 methods
= pytalloc_get_ptr(self
);
1802 status
= methods
->delete_dom_group(methods
, frame
, group_rid
);
1803 if (!NT_STATUS_IS_OK(status
)) {
1804 PyErr_Format(py_pdb_error
, "Unable to delete domain group (rid=%d), (%d,%s)",
1806 NT_STATUS_V(status
),
1807 get_friendly_nt_error_msg(status
));
1817 static PyObject
*py_pdb_add_group_mapping_entry(pytalloc_Object
*self
, PyObject
*args
)
1819 TALLOC_CTX
*frame
= talloc_stackframe();
1821 struct pdb_methods
*methods
;
1822 PyObject
*py_group_map
;
1823 GROUP_MAP
*group_map
;
1825 if (!PyArg_ParseTuple(args
, "O!:add_group_mapping_entry", &PyGroupmap
, &py_group_map
)) {
1830 methods
= pytalloc_get_ptr(self
);
1832 group_map
= pytalloc_get_ptr(py_group_map
);
1834 status
= methods
->add_group_mapping_entry(methods
, group_map
);
1835 if (!NT_STATUS_IS_OK(status
)) {
1836 PyErr_Format(py_pdb_error
, "Unable to add group mapping entry, (%d,%s)",
1837 NT_STATUS_V(status
),
1838 get_friendly_nt_error_msg(status
));
1848 static PyObject
*py_pdb_update_group_mapping_entry(pytalloc_Object
*self
, PyObject
*args
)
1850 TALLOC_CTX
*frame
= talloc_stackframe();
1852 struct pdb_methods
*methods
;
1853 PyObject
*py_group_map
;
1854 GROUP_MAP
*group_map
;
1856 if (!PyArg_ParseTuple(args
, "O!:update_group_mapping_entry", &PyGroupmap
, &py_group_map
)) {
1861 methods
= pytalloc_get_ptr(self
);
1863 group_map
= pytalloc_get_ptr(py_group_map
);
1865 status
= methods
->update_group_mapping_entry(methods
, group_map
);
1866 if (!NT_STATUS_IS_OK(status
)) {
1867 PyErr_Format(py_pdb_error
, "Unable to update group mapping entry, (%d,%s)",
1868 NT_STATUS_V(status
),
1869 get_friendly_nt_error_msg(status
));
1879 static PyObject
*py_pdb_delete_group_mapping_entry(pytalloc_Object
*self
, PyObject
*args
)
1881 TALLOC_CTX
*frame
= talloc_stackframe();
1883 struct pdb_methods
*methods
;
1884 PyObject
*py_group_sid
;
1885 struct dom_sid
*group_sid
;
1887 if (!PyArg_ParseTuple(args
, "O!:delete_group_mapping_entry", dom_sid_Type
, &py_group_sid
)) {
1892 methods
= pytalloc_get_ptr(self
);
1894 group_sid
= pytalloc_get_ptr(py_group_sid
);
1896 status
= methods
->delete_group_mapping_entry(methods
, *group_sid
);
1897 if (!NT_STATUS_IS_OK(status
)) {
1898 PyErr_Format(py_pdb_error
, "Unable to delete group mapping entry, (%d,%s)",
1899 NT_STATUS_V(status
),
1900 get_friendly_nt_error_msg(status
));
1910 static PyObject
*py_pdb_enum_group_mapping(pytalloc_Object
*self
, PyObject
*args
)
1912 TALLOC_CTX
*frame
= talloc_stackframe();
1914 struct pdb_methods
*methods
;
1915 enum lsa_SidType sid_name_use
;
1916 int lsa_sidtype_value
= SID_NAME_UNKNOWN
;
1918 PyObject
*py_domain_sid
;
1919 struct dom_sid
*domain_sid
= NULL
;
1920 GROUP_MAP
**gmap
= NULL
;
1921 GROUP_MAP
*group_map
;
1923 PyObject
*py_gmap_list
, *py_group_map
;
1926 py_domain_sid
= Py_None
;
1929 if (!PyArg_ParseTuple(args
, "|O!ii:enum_group_mapping", dom_sid_Type
, &py_domain_sid
,
1930 &lsa_sidtype_value
, &unix_only
)) {
1935 methods
= pytalloc_get_ptr(self
);
1937 sid_name_use
= lsa_sidtype_value
;
1939 if (py_domain_sid
!= Py_None
) {
1940 domain_sid
= pytalloc_get_ptr(py_domain_sid
);
1943 status
= methods
->enum_group_mapping(methods
, domain_sid
, sid_name_use
,
1944 &gmap
, &num_entries
, unix_only
);
1945 if (!NT_STATUS_IS_OK(status
)) {
1946 PyErr_Format(py_pdb_error
, "Unable to enumerate group mappings, (%d,%s)",
1947 NT_STATUS_V(status
),
1948 get_friendly_nt_error_msg(status
));
1953 py_gmap_list
= PyList_New(0);
1954 if (py_gmap_list
== NULL
) {
1960 for(i
=0; i
<num_entries
; i
++) {
1961 py_group_map
= py_groupmap_new(&PyGroupmap
, NULL
, NULL
);
1963 group_map
= pytalloc_get_ptr(py_group_map
);
1964 *group_map
= *gmap
[i
];
1965 talloc_steal(group_map
, gmap
[i
]->nt_name
);
1966 talloc_steal(group_map
, gmap
[i
]->comment
);
1968 PyList_Append(py_gmap_list
, py_group_map
);
1975 return py_gmap_list
;
1979 static PyObject
*py_pdb_enum_group_members(pytalloc_Object
*self
, PyObject
*args
)
1981 TALLOC_CTX
*frame
= talloc_stackframe();
1983 struct pdb_methods
*methods
;
1984 PyObject
*py_group_sid
;
1985 struct dom_sid
*group_sid
;
1986 uint32_t *member_rids
;
1988 PyObject
*py_sid_list
;
1989 struct dom_sid
*domain_sid
, *member_sid
;
1992 if (!PyArg_ParseTuple(args
, "O!:enum_group_members", dom_sid_Type
, &py_group_sid
)) {
1997 methods
= pytalloc_get_ptr(self
);
1999 group_sid
= pytalloc_get_ptr(py_group_sid
);
2001 status
= methods
->enum_group_members(methods
, frame
, group_sid
,
2002 &member_rids
, &num_members
);
2003 if (!NT_STATUS_IS_OK(status
)) {
2004 PyErr_Format(py_pdb_error
, "Unable to enumerate group members, (%d,%s)",
2005 NT_STATUS_V(status
),
2006 get_friendly_nt_error_msg(status
));
2011 py_sid_list
= PyList_New(0);
2012 if (py_sid_list
== NULL
) {
2018 domain_sid
= get_global_sam_sid();
2020 for(i
=0; i
<num_members
; i
++) {
2021 member_sid
= dom_sid_add_rid(frame
, domain_sid
, member_rids
[i
]);
2022 PyList_Append(py_sid_list
, pytalloc_steal(dom_sid_Type
, member_sid
));
2030 static PyObject
*py_pdb_enum_group_memberships(pytalloc_Object
*self
, PyObject
*args
)
2032 TALLOC_CTX
*frame
= talloc_stackframe();
2034 struct pdb_methods
*methods
;
2037 struct samu
*sam_acct
;
2038 PyObject
*py_sam_acct
;
2039 PyObject
*py_sid_list
;
2040 struct dom_sid
*user_group_sids
= NULL
;
2041 gid_t
*user_group_ids
= NULL
;
2042 uint32_t num_groups
= 0;
2044 if (!PyArg_ParseTuple(args
, "O!:enum_group_memberships", &PySamu
, &py_sam_acct
)) {
2049 methods
= pytalloc_get_ptr(self
);
2051 sam_acct
= pytalloc_get_ptr(py_sam_acct
);
2053 status
= methods
->enum_group_memberships(methods
, frame
, sam_acct
,
2054 &user_group_sids
, &user_group_ids
, &num_groups
);
2055 if (!NT_STATUS_IS_OK(status
)) {
2056 PyErr_Format(py_pdb_error
, "Unable to enumerate group memberships, (%d,%s)",
2057 NT_STATUS_V(status
),
2058 get_friendly_nt_error_msg(status
));
2063 py_sid_list
= PyList_New(0);
2064 if (py_sid_list
== NULL
) {
2070 for(i
=0; i
<num_groups
; i
++) {
2071 PyList_Append(py_sid_list
, pytalloc_steal(dom_sid_Type
, dom_sid_dup(NULL
, &user_group_sids
[i
])));
2079 static PyObject
*py_pdb_add_groupmem(pytalloc_Object
*self
, PyObject
*args
)
2081 TALLOC_CTX
*frame
= talloc_stackframe();
2083 struct pdb_methods
*methods
;
2084 uint32_t group_rid
, member_rid
;
2086 if (!PyArg_ParseTuple(args
, "II:add_groupmem", &group_rid
, &member_rid
)) {
2091 methods
= pytalloc_get_ptr(self
);
2093 status
= methods
->add_groupmem(methods
, frame
, group_rid
, member_rid
);
2094 if (!NT_STATUS_IS_OK(status
)) {
2095 PyErr_Format(py_pdb_error
, "Unable to add group member, (%d,%s)",
2096 NT_STATUS_V(status
),
2097 get_friendly_nt_error_msg(status
));
2107 static PyObject
*py_pdb_del_groupmem(pytalloc_Object
*self
, PyObject
*args
)
2109 TALLOC_CTX
*frame
= talloc_stackframe();
2111 struct pdb_methods
*methods
;
2112 uint32_t group_rid
, member_rid
;
2114 if (!PyArg_ParseTuple(args
, "II:del_groupmem", &group_rid
, &member_rid
)) {
2119 methods
= pytalloc_get_ptr(self
);
2121 status
= methods
->del_groupmem(methods
, frame
, group_rid
, member_rid
);
2122 if (!NT_STATUS_IS_OK(status
)) {
2123 PyErr_Format(py_pdb_error
, "Unable to rename sam account, (%d,%s)",
2124 NT_STATUS_V(status
),
2125 get_friendly_nt_error_msg(status
));
2135 static PyObject
*py_pdb_create_alias(pytalloc_Object
*self
, PyObject
*args
)
2137 TALLOC_CTX
*frame
= talloc_stackframe();
2139 struct pdb_methods
*methods
;
2140 const char *alias_name
;
2143 if (!PyArg_ParseTuple(args
, "s:create_alias", &alias_name
)) {
2148 methods
= pytalloc_get_ptr(self
);
2150 status
= methods
->create_alias(methods
, alias_name
, &rid
);
2151 if (!NT_STATUS_IS_OK(status
)) {
2152 PyErr_Format(py_pdb_error
, "Unable to create alias (%s), (%d,%s)",
2154 NT_STATUS_V(status
),
2155 get_friendly_nt_error_msg(status
));
2161 return PyInt_FromLong(rid
);
2165 static PyObject
*py_pdb_delete_alias(pytalloc_Object
*self
, PyObject
*args
)
2167 TALLOC_CTX
*frame
= talloc_stackframe();
2169 struct pdb_methods
*methods
;
2170 PyObject
*py_alias_sid
;
2171 struct dom_sid
*alias_sid
;
2173 if (!PyArg_ParseTuple(args
, "O!:delete_alias", dom_sid_Type
, &py_alias_sid
)) {
2178 methods
= pytalloc_get_ptr(self
);
2180 alias_sid
= pytalloc_get_ptr(py_alias_sid
);
2182 status
= methods
->delete_alias(methods
, alias_sid
);
2183 if (!NT_STATUS_IS_OK(status
)) {
2184 PyErr_Format(py_pdb_error
, "Unable to delete alias, (%d,%s)",
2185 NT_STATUS_V(status
),
2186 get_friendly_nt_error_msg(status
));
2196 static PyObject
*py_pdb_get_aliasinfo(pytalloc_Object
*self
, PyObject
*args
)
2198 TALLOC_CTX
*frame
= talloc_stackframe();
2200 struct pdb_methods
*methods
;
2201 PyObject
*py_alias_sid
;
2202 struct dom_sid
*alias_sid
;
2203 struct acct_info
*alias_info
;
2204 PyObject
*py_alias_info
;
2206 if (!PyArg_ParseTuple(args
, "O!:get_aliasinfo", dom_sid_Type
, &py_alias_sid
)) {
2211 methods
= pytalloc_get_ptr(self
);
2213 alias_sid
= pytalloc_get_ptr(py_alias_sid
);
2215 alias_info
= talloc_zero(frame
, struct acct_info
);
2222 status
= methods
->get_aliasinfo(methods
, alias_sid
, alias_info
);
2223 if (!NT_STATUS_IS_OK(status
)) {
2224 PyErr_Format(py_pdb_error
, "Unable to get alias information, (%d,%s)",
2225 NT_STATUS_V(status
),
2226 get_friendly_nt_error_msg(status
));
2231 py_alias_info
= PyDict_New();
2232 if (py_alias_info
== NULL
) {
2238 PyDict_SetItemString(py_alias_info
, "acct_name",
2239 PyString_FromString(alias_info
->acct_name
));
2240 PyDict_SetItemString(py_alias_info
, "acct_desc",
2241 PyString_FromString(alias_info
->acct_desc
));
2242 PyDict_SetItemString(py_alias_info
, "rid",
2243 PyInt_FromLong(alias_info
->rid
));
2246 return py_alias_info
;
2250 static PyObject
*py_pdb_set_aliasinfo(pytalloc_Object
*self
, PyObject
*args
)
2252 TALLOC_CTX
*frame
= talloc_stackframe();
2254 struct pdb_methods
*methods
;
2255 PyObject
*py_alias_sid
, *py_alias_info
;
2256 struct dom_sid
*alias_sid
;
2257 struct acct_info alias_info
;
2259 if (!PyArg_ParseTuple(args
, "O!O:set_alias_info", dom_sid_Type
, &py_alias_sid
,
2265 methods
= pytalloc_get_ptr(self
);
2267 alias_sid
= pytalloc_get_ptr(py_alias_sid
);
2269 alias_info
.acct_name
= talloc_strdup(frame
, PyString_AsString(PyDict_GetItemString(py_alias_info
, "acct_name")));
2270 if (alias_info
.acct_name
== NULL
) {
2271 PyErr_Format(py_pdb_error
, "Unable to allocate memory");
2275 alias_info
.acct_desc
= talloc_strdup(frame
, PyString_AsString(PyDict_GetItemString(py_alias_info
, "acct_desc")));
2276 if (alias_info
.acct_desc
== NULL
) {
2277 PyErr_Format(py_pdb_error
, "Unable to allocate memory");
2282 status
= methods
->set_aliasinfo(methods
, alias_sid
, &alias_info
);
2283 if (!NT_STATUS_IS_OK(status
)) {
2284 PyErr_Format(py_pdb_error
, "Unable to set alias information, (%d,%s)",
2285 NT_STATUS_V(status
),
2286 get_friendly_nt_error_msg(status
));
2296 static PyObject
*py_pdb_add_aliasmem(pytalloc_Object
*self
, PyObject
*args
)
2298 TALLOC_CTX
*frame
= talloc_stackframe();
2300 struct pdb_methods
*methods
;
2301 PyObject
*py_alias_sid
, *py_member_sid
;
2302 struct dom_sid
*alias_sid
, *member_sid
;
2304 if (!PyArg_ParseTuple(args
, "O!O!:add_aliasmem", dom_sid_Type
, &py_alias_sid
,
2305 dom_sid_Type
, &py_member_sid
)) {
2310 methods
= pytalloc_get_ptr(self
);
2312 alias_sid
= pytalloc_get_ptr(py_alias_sid
);
2313 member_sid
= pytalloc_get_ptr(py_member_sid
);
2315 status
= methods
->add_aliasmem(methods
, alias_sid
, member_sid
);
2316 if (!NT_STATUS_IS_OK(status
)) {
2317 PyErr_Format(py_pdb_error
, "Unable to add member to alias, (%d,%s)",
2318 NT_STATUS_V(status
),
2319 get_friendly_nt_error_msg(status
));
2329 static PyObject
*py_pdb_del_aliasmem(pytalloc_Object
*self
, PyObject
*args
)
2331 TALLOC_CTX
*frame
= talloc_stackframe();
2333 struct pdb_methods
*methods
;
2334 PyObject
*py_alias_sid
, *py_member_sid
;
2335 const struct dom_sid
*alias_sid
, *member_sid
;
2337 if (!PyArg_ParseTuple(args
, "O!O!:del_aliasmem", dom_sid_Type
, &py_alias_sid
,
2338 dom_sid_Type
, &py_member_sid
)) {
2343 methods
= pytalloc_get_ptr(self
);
2345 alias_sid
= pytalloc_get_ptr(py_alias_sid
);
2346 member_sid
= pytalloc_get_ptr(py_member_sid
);
2348 status
= methods
->del_aliasmem(methods
, alias_sid
, member_sid
);
2349 if (!NT_STATUS_IS_OK(status
)) {
2350 PyErr_Format(py_pdb_error
, "Unable to delete member from alias, (%d,%s)",
2351 NT_STATUS_V(status
),
2352 get_friendly_nt_error_msg(status
));
2362 static PyObject
*py_pdb_enum_aliasmem(pytalloc_Object
*self
, PyObject
*args
)
2364 TALLOC_CTX
*frame
= talloc_stackframe();
2366 struct pdb_methods
*methods
;
2367 PyObject
*py_alias_sid
;
2368 struct dom_sid
*alias_sid
, *member_sid
, *tmp_sid
;
2369 PyObject
*py_member_list
, *py_member_sid
;
2373 if (!PyArg_ParseTuple(args
, "O!:enum_aliasmem", dom_sid_Type
, &py_alias_sid
)) {
2378 methods
= pytalloc_get_ptr(self
);
2380 alias_sid
= pytalloc_get_ptr(py_alias_sid
);
2382 status
= methods
->enum_aliasmem(methods
, alias_sid
, frame
, &member_sid
, &num_members
);
2383 if (!NT_STATUS_IS_OK(status
)) {
2384 PyErr_Format(py_pdb_error
, "Unable to enumerate members for alias, (%d,%s)",
2385 NT_STATUS_V(status
),
2386 get_friendly_nt_error_msg(status
));
2391 py_member_list
= PyList_New(0);
2392 if (py_member_list
== NULL
) {
2398 for(i
=0; i
<num_members
; i
++) {
2399 py_member_sid
= pytalloc_new(struct dom_sid
, dom_sid_Type
);
2400 if (py_member_sid
== NULL
) {
2405 tmp_sid
= pytalloc_get_ptr(py_member_sid
);
2406 *tmp_sid
= member_sid
[i
];
2407 PyList_Append(py_member_list
, py_member_sid
);
2411 return py_member_list
;
2415 static PyObject
*py_pdb_get_account_policy(pytalloc_Object
*self
)
2417 TALLOC_CTX
*frame
= talloc_stackframe();
2419 struct pdb_methods
*methods
;
2420 PyObject
*py_acct_policy
;
2424 enum pdb_policy_type type
;
2426 methods
= pytalloc_get_ptr(self
);
2428 py_acct_policy
= PyDict_New();
2429 if (py_acct_policy
== NULL
) {
2435 account_policy_names_list(frame
, &names
, &count
);
2436 for (i
=0; i
<count
; i
++) {
2437 type
= account_policy_name_to_typenum(names
[i
]);
2438 status
= methods
->get_account_policy(methods
, type
, &value
);
2439 if (NT_STATUS_IS_OK(status
)) {
2440 PyDict_SetItemString(py_acct_policy
, names
[i
], Py_BuildValue("i", value
));
2445 return py_acct_policy
;
2449 static PyObject
*py_pdb_set_account_policy(pytalloc_Object
*self
, PyObject
*args
)
2451 TALLOC_CTX
*frame
= talloc_stackframe();
2453 struct pdb_methods
*methods
;
2454 PyObject
*py_acct_policy
, *py_value
;
2457 enum pdb_policy_type type
;
2459 if (!PyArg_ParseTuple(args
, "O!:set_account_policy", PyDict_Type
, &py_acct_policy
)) {
2464 methods
= pytalloc_get_ptr(self
);
2466 account_policy_names_list(frame
, &names
, &count
);
2467 for (i
=0; i
<count
; i
++) {
2468 if ((py_value
= PyDict_GetItemString(py_acct_policy
, names
[i
])) != NULL
) {
2469 type
= account_policy_name_to_typenum(names
[i
]);
2470 status
= methods
->set_account_policy(methods
, type
, PyInt_AsLong(py_value
));
2471 if (!NT_STATUS_IS_OK(status
)) {
2472 PyErr_Format(py_pdb_error
, "Error setting account policy (%s), (%d,%s)",
2474 NT_STATUS_V(status
),
2475 get_friendly_nt_error_msg(status
));
2484 static PyObject
*py_pdb_search_users(pytalloc_Object
*self
, PyObject
*args
)
2486 TALLOC_CTX
*frame
= talloc_stackframe();
2487 struct pdb_methods
*methods
;
2488 unsigned int acct_flags
;
2489 struct pdb_search
*search
;
2490 struct samr_displayentry
*entry
;
2491 PyObject
*py_userlist
, *py_dict
;
2493 if (!PyArg_ParseTuple(args
, "I:search_users", &acct_flags
)) {
2498 methods
= pytalloc_get_ptr(self
);
2500 search
= talloc_zero(frame
, struct pdb_search
);
2501 if (search
== NULL
) {
2507 if (!methods
->search_users(methods
, search
, acct_flags
)) {
2508 PyErr_Format(py_pdb_error
, "Unable to search users");
2513 entry
= talloc_zero(frame
, struct samr_displayentry
);
2514 if (entry
== NULL
) {
2520 py_userlist
= PyList_New(0);
2521 if (py_userlist
== NULL
) {
2527 while (search
->next_entry(search
, entry
)) {
2528 py_dict
= PyDict_New();
2529 if (py_dict
== NULL
) {
2532 PyDict_SetItemString(py_dict
, "idx", PyInt_FromLong(entry
->idx
));
2533 PyDict_SetItemString(py_dict
, "rid", PyInt_FromLong(entry
->rid
));
2534 PyDict_SetItemString(py_dict
, "acct_flags", PyInt_FromLong(entry
->acct_flags
));
2535 PyDict_SetItemString(py_dict
, "account_name", PyString_FromString(entry
->account_name
));
2536 PyDict_SetItemString(py_dict
, "fullname", PyString_FromString(entry
->fullname
));
2537 PyDict_SetItemString(py_dict
, "description", PyString_FromString(entry
->description
));
2538 PyList_Append(py_userlist
, py_dict
);
2541 search
->search_end(search
);
2548 static PyObject
*py_pdb_search_groups(pytalloc_Object
*self
)
2550 TALLOC_CTX
*frame
= talloc_stackframe();
2551 struct pdb_methods
*methods
;
2552 struct pdb_search
*search
;
2553 struct samr_displayentry
*entry
;
2554 PyObject
*py_grouplist
, *py_dict
;
2556 methods
= pytalloc_get_ptr(self
);
2558 search
= talloc_zero(frame
, struct pdb_search
);
2559 if (search
== NULL
) {
2565 if (!methods
->search_groups(methods
, search
)) {
2566 PyErr_Format(py_pdb_error
, "Unable to search groups");
2571 entry
= talloc_zero(frame
, struct samr_displayentry
);
2572 if (entry
== NULL
) {
2578 py_grouplist
= PyList_New(0);
2579 if (py_grouplist
== NULL
) {
2585 while (search
->next_entry(search
, entry
)) {
2586 py_dict
= PyDict_New();
2587 if (py_dict
== NULL
) {
2590 PyDict_SetItemString(py_dict
, "idx", PyInt_FromLong(entry
->idx
));
2591 PyDict_SetItemString(py_dict
, "rid", PyInt_FromLong(entry
->rid
));
2592 PyDict_SetItemString(py_dict
, "acct_flags", PyInt_FromLong(entry
->acct_flags
));
2593 PyDict_SetItemString(py_dict
, "account_name", PyString_FromString(entry
->account_name
));
2594 PyDict_SetItemString(py_dict
, "fullname", PyString_FromString(entry
->fullname
));
2595 PyDict_SetItemString(py_dict
, "description", PyString_FromString(entry
->description
));
2596 PyList_Append(py_grouplist
, py_dict
);
2599 search
->search_end(search
);
2602 return py_grouplist
;
2606 static PyObject
*py_pdb_search_aliases(pytalloc_Object
*self
, PyObject
*args
)
2608 TALLOC_CTX
*frame
= talloc_stackframe();
2609 struct pdb_methods
*methods
;
2610 struct pdb_search
*search
;
2611 struct samr_displayentry
*entry
;
2612 PyObject
*py_aliaslist
, *py_dict
;
2613 PyObject
*py_domain_sid
;
2614 struct dom_sid
*domain_sid
= NULL
;
2616 py_domain_sid
= Py_None
;
2619 if (!PyArg_ParseTuple(args
, "|O!:search_aliases", dom_sid_Type
, &py_domain_sid
)) {
2624 methods
= pytalloc_get_ptr(self
);
2626 if (py_domain_sid
!= Py_None
) {
2627 domain_sid
= pytalloc_get_ptr(py_domain_sid
);
2630 search
= talloc_zero(frame
, struct pdb_search
);
2631 if (search
== NULL
) {
2637 if (!methods
->search_aliases(methods
, search
, domain_sid
)) {
2638 PyErr_Format(py_pdb_error
, "Unable to search aliases");
2643 entry
= talloc_zero(frame
, struct samr_displayentry
);
2644 if (entry
== NULL
) {
2650 py_aliaslist
= PyList_New(0);
2651 if (py_aliaslist
== NULL
) {
2657 while (search
->next_entry(search
, entry
)) {
2658 py_dict
= PyDict_New();
2659 if (py_dict
== NULL
) {
2662 PyDict_SetItemString(py_dict
, "idx", PyInt_FromLong(entry
->idx
));
2663 PyDict_SetItemString(py_dict
, "rid", PyInt_FromLong(entry
->rid
));
2664 PyDict_SetItemString(py_dict
, "acct_flags", PyInt_FromLong(entry
->acct_flags
));
2665 PyDict_SetItemString(py_dict
, "account_name", PyString_FromString(entry
->account_name
));
2666 PyDict_SetItemString(py_dict
, "fullname", PyString_FromString(entry
->fullname
));
2667 PyDict_SetItemString(py_dict
, "description", PyString_FromString(entry
->description
));
2668 PyList_Append(py_aliaslist
, py_dict
);
2671 search
->search_end(search
);
2674 return py_aliaslist
;
2678 static PyObject
*py_pdb_uid_to_sid(pytalloc_Object
*self
, PyObject
*args
)
2680 TALLOC_CTX
*frame
= talloc_stackframe();
2681 struct pdb_methods
*methods
;
2684 struct dom_sid user_sid
, *copy_user_sid
;
2685 PyObject
*py_user_sid
;
2687 if (!PyArg_ParseTuple(args
, "I:uid_to_sid", &uid
)) {
2692 methods
= pytalloc_get_ptr(self
);
2695 id
.type
= ID_TYPE_UID
;
2697 if (!methods
->id_to_sid(methods
, &id
, &user_sid
)) {
2698 PyErr_Format(py_pdb_error
, "Unable to get sid for uid=%d", uid
);
2703 copy_user_sid
= dom_sid_dup(frame
, &user_sid
);
2704 if (copy_user_sid
== NULL
) {
2710 py_user_sid
= pytalloc_steal(dom_sid_Type
, copy_user_sid
);
2717 static PyObject
*py_pdb_gid_to_sid(pytalloc_Object
*self
, PyObject
*args
)
2719 TALLOC_CTX
*frame
= talloc_stackframe();
2720 struct pdb_methods
*methods
;
2723 struct dom_sid group_sid
, *copy_group_sid
;
2724 PyObject
*py_group_sid
;
2726 if (!PyArg_ParseTuple(args
, "I:gid_to_sid", &gid
)) {
2732 id
.type
= ID_TYPE_GID
;
2734 methods
= pytalloc_get_ptr(self
);
2736 if (!methods
->id_to_sid(methods
, &id
, &group_sid
)) {
2737 PyErr_Format(py_pdb_error
, "Unable to get sid for gid=%d", gid
);
2742 copy_group_sid
= dom_sid_dup(frame
, &group_sid
);
2743 if (copy_group_sid
== NULL
) {
2749 py_group_sid
= pytalloc_steal(dom_sid_Type
, copy_group_sid
);
2752 return py_group_sid
;
2756 static PyObject
*py_pdb_sid_to_id(pytalloc_Object
*self
, PyObject
*args
)
2758 TALLOC_CTX
*frame
= talloc_stackframe();
2759 struct pdb_methods
*methods
;
2761 struct dom_sid
*sid
;
2764 if (!PyArg_ParseTuple(args
, "O!:sid_to_id", dom_sid_Type
, &py_sid
)) {
2769 methods
= pytalloc_get_ptr(self
);
2771 sid
= pytalloc_get_ptr(py_sid
);
2773 if (!methods
->sid_to_id(methods
, sid
, &id
)) {
2774 PyErr_Format(py_pdb_error
, "Unable to get id for sid");
2780 return Py_BuildValue("(II)", id
.id
, id
.type
);
2784 static PyObject
*py_pdb_new_rid(pytalloc_Object
*self
)
2786 TALLOC_CTX
*frame
= talloc_stackframe();
2787 struct pdb_methods
*methods
;
2790 methods
= pytalloc_get_ptr(self
);
2792 if (!methods
->new_rid(methods
, &rid
)) {
2793 PyErr_Format(py_pdb_error
, "Unable to get new rid");
2799 return PyInt_FromLong(rid
);
2803 static PyObject
*py_pdb_get_trusteddom_pw(pytalloc_Object
*self
, PyObject
*args
)
2805 TALLOC_CTX
*frame
= talloc_stackframe();
2806 struct pdb_methods
*methods
;
2809 struct dom_sid sid
, *copy_sid
;
2811 time_t last_set_time
;
2814 if (!PyArg_ParseTuple(args
, "s:get_trusteddom_pw", &domain
)) {
2819 methods
= pytalloc_get_ptr(self
);
2821 if (!methods
->get_trusteddom_pw(methods
, domain
, &pwd
, &sid
, &last_set_time
)) {
2822 PyErr_Format(py_pdb_error
, "Unable to get trusted domain password");
2827 copy_sid
= dom_sid_dup(frame
, &sid
);
2828 if (copy_sid
== NULL
) {
2834 py_sid
= pytalloc_steal(dom_sid_Type
, copy_sid
);
2835 if (py_sid
== NULL
) {
2841 py_value
= PyDict_New();
2842 if (py_value
== NULL
) {
2848 PyDict_SetItemString(py_value
, "pwd", PyString_FromString(pwd
));
2849 PyDict_SetItemString(py_value
, "sid", py_sid
);
2850 PyDict_SetItemString(py_value
, "last_set_tim", PyInt_FromLong(last_set_time
));
2857 static PyObject
*py_pdb_set_trusteddom_pw(pytalloc_Object
*self
, PyObject
*args
)
2859 TALLOC_CTX
*frame
= talloc_stackframe();
2860 struct pdb_methods
*methods
;
2863 const struct dom_sid
*domain_sid
;
2864 PyObject
*py_domain_sid
;
2866 if (!PyArg_ParseTuple(args
, "ssO!:set_trusteddom_pw", &domain
, &pwd
,
2867 dom_sid_Type
, &py_domain_sid
)) {
2872 methods
= pytalloc_get_ptr(self
);
2874 domain_sid
= pytalloc_get_ptr(py_domain_sid
);
2876 if (!methods
->set_trusteddom_pw(methods
, domain
, pwd
, domain_sid
)) {
2877 PyErr_Format(py_pdb_error
, "Unable to set trusted domain password");
2887 static PyObject
*py_pdb_del_trusteddom_pw(pytalloc_Object
*self
, PyObject
*args
)
2889 TALLOC_CTX
*frame
= talloc_stackframe();
2890 struct pdb_methods
*methods
;
2893 if (!PyArg_ParseTuple(args
, "s:del_trusteddom_pw", &domain
)) {
2898 methods
= pytalloc_get_ptr(self
);
2900 if (!methods
->del_trusteddom_pw(methods
, domain
)) {
2901 PyErr_Format(py_pdb_error
, "Unable to delete trusted domain password");
2911 static PyObject
*py_pdb_enum_trusteddoms(pytalloc_Object
*self
)
2913 TALLOC_CTX
*frame
= talloc_stackframe();
2915 struct pdb_methods
*methods
;
2916 uint32_t num_domains
;
2917 struct trustdom_info
**domains
;
2918 PyObject
*py_domain_list
, *py_dict
;
2921 methods
= pytalloc_get_ptr(self
);
2923 status
= methods
->enum_trusteddoms(methods
, frame
, &num_domains
, &domains
);
2924 if (!NT_STATUS_IS_OK(status
)) {
2925 PyErr_Format(py_pdb_error
, "Unable to enumerate trusted domains, (%d,%s)",
2926 NT_STATUS_V(status
),
2927 get_friendly_nt_error_msg(status
));
2932 py_domain_list
= PyList_New(0);
2933 if (py_domain_list
== NULL
) {
2939 for(i
=0; i
<num_domains
; i
++) {
2940 py_dict
= PyDict_New();
2942 PyDict_SetItemString(py_dict
, "name",
2943 PyString_FromString(domains
[i
]->name
));
2944 PyDict_SetItemString(py_dict
, "sid",
2945 pytalloc_steal(dom_sid_Type
, &domains
[i
]->sid
));
2948 PyList_Append(py_domain_list
, py_dict
);
2952 return py_domain_list
;
2956 static PyObject
*py_pdb_get_trusted_domain(pytalloc_Object
*self
, PyObject
*args
)
2958 TALLOC_CTX
*frame
= talloc_stackframe();
2960 struct pdb_methods
*methods
;
2962 struct pdb_trusted_domain
*td
;
2963 PyObject
*py_domain_info
;
2965 if (!PyArg_ParseTuple(args
, "s:get_trusted_domain", &domain
)) {
2970 methods
= pytalloc_get_ptr(self
);
2972 status
= methods
->get_trusted_domain(methods
, frame
, domain
, &td
);
2973 if (!NT_STATUS_IS_OK(status
)) {
2974 PyErr_Format(py_pdb_error
, "Unable to get trusted domain information, (%d,%s)",
2975 NT_STATUS_V(status
),
2976 get_friendly_nt_error_msg(status
));
2981 py_domain_info
= PyDict_New();
2982 if (py_domain_info
== NULL
) {
2988 PyDict_SetItemString(py_domain_info
, "domain_name",
2989 PyString_FromString(td
->domain_name
));
2990 PyDict_SetItemString(py_domain_info
, "netbios_name",
2991 PyString_FromString(td
->netbios_name
));
2992 PyDict_SetItemString(py_domain_info
, "security_identifier",
2993 pytalloc_steal(dom_sid_Type
, &td
->security_identifier
));
2994 PyDict_SetItemString(py_domain_info
, "trust_auth_incoming",
2995 PyString_FromStringAndSize((char *)td
->trust_auth_incoming
.data
,
2996 td
->trust_auth_incoming
.length
));
2997 PyDict_SetItemString(py_domain_info
, "trust_auth_outgoing",
2998 PyString_FromStringAndSize((char *)td
->trust_auth_outgoing
.data
,
2999 td
->trust_auth_outgoing
.length
));
3000 PyDict_SetItemString(py_domain_info
, "trust_direction",
3001 PyInt_FromLong(td
->trust_direction
));
3002 PyDict_SetItemString(py_domain_info
, "trust_type",
3003 PyInt_FromLong(td
->trust_type
));
3004 PyDict_SetItemString(py_domain_info
, "trust_attributes",
3005 PyInt_FromLong(td
->trust_attributes
));
3006 PyDict_SetItemString(py_domain_info
, "trust_forest_trust_info",
3007 PyString_FromStringAndSize((char *)td
->trust_forest_trust_info
.data
,
3008 td
->trust_forest_trust_info
.length
));
3011 return py_domain_info
;
3015 static PyObject
*py_pdb_get_trusted_domain_by_sid(pytalloc_Object
*self
, PyObject
*args
)
3017 TALLOC_CTX
*frame
= talloc_stackframe();
3019 struct pdb_methods
*methods
;
3020 PyObject
*py_domain_sid
;
3021 struct dom_sid
*domain_sid
;
3022 struct pdb_trusted_domain
*td
;
3023 PyObject
*py_domain_info
;
3025 if (!PyArg_ParseTuple(args
, "O!:get_trusted_domain_by_sid", dom_sid_Type
, &py_domain_sid
)) {
3030 methods
= pytalloc_get_ptr(self
);
3032 domain_sid
= pytalloc_get_ptr(py_domain_sid
);
3034 status
= methods
->get_trusted_domain_by_sid(methods
, frame
, domain_sid
, &td
);
3035 if (!NT_STATUS_IS_OK(status
)) {
3036 PyErr_Format(py_pdb_error
, "Unable to get trusted domain information, (%d,%s)",
3037 NT_STATUS_V(status
),
3038 get_friendly_nt_error_msg(status
));
3043 py_domain_info
= PyDict_New();
3044 if (py_domain_info
== NULL
) {
3050 PyDict_SetItemString(py_domain_info
, "domain_name",
3051 PyString_FromString(td
->domain_name
));
3052 PyDict_SetItemString(py_domain_info
, "netbios_name",
3053 PyString_FromString(td
->netbios_name
));
3054 PyDict_SetItemString(py_domain_info
, "security_identifier",
3055 pytalloc_steal(dom_sid_Type
, &td
->security_identifier
));
3056 PyDict_SetItemString(py_domain_info
, "trust_auth_incoming",
3057 PyString_FromStringAndSize((char *)td
->trust_auth_incoming
.data
,
3058 td
->trust_auth_incoming
.length
));
3059 PyDict_SetItemString(py_domain_info
, "trust_auth_outgoing",
3060 PyString_FromStringAndSize((char *)td
->trust_auth_outgoing
.data
,
3061 td
->trust_auth_outgoing
.length
));
3062 PyDict_SetItemString(py_domain_info
, "trust_direction",
3063 PyInt_FromLong(td
->trust_direction
));
3064 PyDict_SetItemString(py_domain_info
, "trust_type",
3065 PyInt_FromLong(td
->trust_type
));
3066 PyDict_SetItemString(py_domain_info
, "trust_attributes",
3067 PyInt_FromLong(td
->trust_attributes
));
3068 PyDict_SetItemString(py_domain_info
, "trust_forest_trust_info",
3069 PyString_FromStringAndSize((char *)td
->trust_forest_trust_info
.data
,
3070 td
->trust_forest_trust_info
.length
));
3073 return py_domain_info
;
3077 static PyObject
*py_pdb_set_trusted_domain(pytalloc_Object
*self
, PyObject
*args
)
3079 TALLOC_CTX
*frame
= talloc_stackframe();
3081 struct pdb_methods
*methods
;
3083 PyObject
*py_td_info
;
3084 struct pdb_trusted_domain td_info
;
3088 if (!PyArg_ParseTuple(args
, "sO!:set_trusted_domain", &domain
, &PyDict_Type
, &py_td_info
)) {
3093 py_tmp
= PyDict_GetItemString(py_td_info
, "domain_name");
3094 td_info
.domain_name
= PyString_AsString(py_tmp
);
3096 py_tmp
= PyDict_GetItemString(py_td_info
, "netbios_name");
3097 td_info
.netbios_name
= PyString_AsString(py_tmp
);
3099 py_tmp
= PyDict_GetItemString(py_td_info
, "security_identifier");
3100 td_info
.security_identifier
= *pytalloc_get_type(py_tmp
, struct dom_sid
);
3102 py_tmp
= PyDict_GetItemString(py_td_info
, "trust_auth_incoming");
3103 PyString_AsStringAndSize(py_tmp
, (char **)&td_info
.trust_auth_incoming
.data
, &len
);
3104 td_info
.trust_auth_incoming
.length
= len
;
3106 py_tmp
= PyDict_GetItemString(py_td_info
, "trust_auth_outgoing");
3107 PyString_AsStringAndSize(py_tmp
, (char **)&td_info
.trust_auth_outgoing
.data
, &len
);
3108 td_info
.trust_auth_outgoing
.length
= len
;
3110 py_tmp
= PyDict_GetItemString(py_td_info
, "trust_direction");
3111 td_info
.trust_direction
= PyInt_AsLong(py_tmp
);
3113 py_tmp
= PyDict_GetItemString(py_td_info
, "trust_type");
3114 td_info
.trust_type
= PyInt_AsLong(py_tmp
);
3116 py_tmp
= PyDict_GetItemString(py_td_info
, "trust_attributes");
3117 td_info
.trust_attributes
= PyInt_AsLong(py_tmp
);
3119 py_tmp
= PyDict_GetItemString(py_td_info
, "trust_forest_trust_info");
3120 PyString_AsStringAndSize(py_tmp
, (char **)&td_info
.trust_forest_trust_info
.data
, &len
);
3121 td_info
.trust_forest_trust_info
.length
= len
;
3123 methods
= pytalloc_get_ptr(self
);
3125 status
= methods
->set_trusted_domain(methods
, domain
, &td_info
);
3126 if (!NT_STATUS_IS_OK(status
)) {
3127 PyErr_Format(py_pdb_error
, "Unable to set trusted domain information, (%d,%s)",
3128 NT_STATUS_V(status
),
3129 get_friendly_nt_error_msg(status
));
3139 static PyObject
*py_pdb_del_trusted_domain(pytalloc_Object
*self
, PyObject
*args
)
3141 TALLOC_CTX
*frame
= talloc_stackframe();
3143 struct pdb_methods
*methods
;
3146 if (!PyArg_ParseTuple(args
, "s:del_trusted_domain", &domain
)) {
3151 methods
= pytalloc_get_ptr(self
);
3153 status
= methods
->del_trusted_domain(methods
, domain
);
3154 if (!NT_STATUS_IS_OK(status
)) {
3155 PyErr_Format(py_pdb_error
, "Unable to delete trusted domain, (%d,%s)",
3156 NT_STATUS_V(status
),
3157 get_friendly_nt_error_msg(status
));
3167 static PyObject
*py_pdb_enum_trusted_domains(pytalloc_Object
*self
)
3169 TALLOC_CTX
*frame
= talloc_stackframe();
3171 struct pdb_methods
*methods
;
3172 uint32_t num_domains
;
3173 struct pdb_trusted_domain
**td_info
, *td
;
3174 PyObject
*py_td_info
, *py_domain_info
;
3177 methods
= pytalloc_get_ptr(self
);
3179 status
= methods
->enum_trusted_domains(methods
, frame
, &num_domains
, &td_info
);
3180 if (!NT_STATUS_IS_OK(status
)) {
3181 PyErr_Format(py_pdb_error
, "Unable to delete trusted domain, (%d,%s)",
3182 NT_STATUS_V(status
),
3183 get_friendly_nt_error_msg(status
));
3188 py_td_info
= PyList_New(0);
3189 if (py_td_info
== NULL
) {
3195 for (i
=0; i
<num_domains
; i
++) {
3197 py_domain_info
= PyDict_New();
3198 if (py_domain_info
== NULL
) {
3200 Py_DECREF(py_td_info
);
3207 PyDict_SetItemString(py_domain_info
, "domain_name",
3208 PyString_FromString(td
->domain_name
));
3209 PyDict_SetItemString(py_domain_info
, "netbios_name",
3210 PyString_FromString(td
->netbios_name
));
3211 PyDict_SetItemString(py_domain_info
, "security_identifier",
3212 pytalloc_steal(dom_sid_Type
, &td
->security_identifier
));
3213 PyDict_SetItemString(py_domain_info
, "trust_auth_incoming",
3214 PyString_FromStringAndSize((char *)td
->trust_auth_incoming
.data
,
3215 td
->trust_auth_incoming
.length
));
3216 PyDict_SetItemString(py_domain_info
, "trust_auth_outgoing",
3217 PyString_FromStringAndSize((char *)td
->trust_auth_outgoing
.data
,
3218 td
->trust_auth_outgoing
.length
));
3219 PyDict_SetItemString(py_domain_info
, "trust_direction",
3220 PyInt_FromLong(td
->trust_direction
));
3221 PyDict_SetItemString(py_domain_info
, "trust_type",
3222 PyInt_FromLong(td
->trust_type
));
3223 PyDict_SetItemString(py_domain_info
, "trust_attributes",
3224 PyInt_FromLong(td
->trust_attributes
));
3225 PyDict_SetItemString(py_domain_info
, "trust_forest_trust_info",
3226 PyString_FromStringAndSize((char *)td
->trust_forest_trust_info
.data
,
3227 td
->trust_forest_trust_info
.length
));
3228 PyList_Append(py_td_info
, py_domain_info
);
3236 static PyObject
*py_pdb_get_secret(pytalloc_Object
*self
, PyObject
*args
)
3238 TALLOC_CTX
*frame
= talloc_stackframe();
3240 struct pdb_methods
*methods
;
3241 const char *secret_name
;
3242 DATA_BLOB secret_current
, secret_old
;
3243 NTTIME secret_current_lastchange
, secret_old_lastchange
;
3245 struct security_descriptor
*sd
;
3246 PyObject
*py_secret
;
3248 if (!PyArg_ParseTuple(args
, "s:get_secret_name", &secret_name
)) {
3253 methods
= pytalloc_get_ptr(self
);
3255 py_sd
= pytalloc_new(struct security_descriptor
, security_Type
);
3256 if (py_sd
== NULL
) {
3261 sd
= pytalloc_get_ptr(py_sd
);
3263 status
= methods
->get_secret(methods
, frame
, secret_name
,
3265 &secret_current_lastchange
,
3267 &secret_old_lastchange
,
3269 if (!NT_STATUS_IS_OK(status
)) {
3270 PyErr_Format(py_pdb_error
, "Unable to get information for secret (%s), (%d,%s)",
3272 NT_STATUS_V(status
),
3273 get_friendly_nt_error_msg(status
));
3278 py_secret
= PyDict_New();
3279 if (py_secret
== NULL
) {
3286 PyDict_SetItemString(py_secret
, "secret_current",
3287 PyString_FromStringAndSize((char *)secret_current
.data
, secret_current
.length
));
3288 PyDict_SetItemString(py_secret
, "secret_current_lastchange",
3289 PyLong_FromUnsignedLongLong(secret_current_lastchange
));
3290 PyDict_SetItemString(py_secret
, "secret_old",
3291 PyString_FromStringAndSize((char *)secret_old
.data
, secret_old
.length
));
3292 PyDict_SetItemString(py_secret
, "secret_old_lastchange",
3293 PyLong_FromUnsignedLongLong(secret_old_lastchange
));
3294 PyDict_SetItemString(py_secret
, "sd", py_sd
);
3301 static PyObject
*py_pdb_set_secret(pytalloc_Object
*self
, PyObject
*args
)
3303 TALLOC_CTX
*frame
= talloc_stackframe();
3305 struct pdb_methods
*methods
;
3306 const char *secret_name
;
3307 PyObject
*py_secret
;
3308 PyObject
*py_secret_cur
, *py_secret_old
, *py_sd
;
3309 DATA_BLOB secret_current
, secret_old
;
3310 struct security_descriptor
*sd
;
3313 if (!PyArg_ParseTuple(args
, "sO!:set_secret_name", &secret_name
, PyDict_Type
, &py_secret
)) {
3318 py_secret_cur
= PyDict_GetItemString(py_secret
, "secret_current");
3319 py_secret_old
= PyDict_GetItemString(py_secret
, "secret_old");
3320 py_sd
= PyDict_GetItemString(py_secret
, "sd");
3322 PY_CHECK_TYPE(&PyString_Type
, py_secret_cur
, return NULL
;);
3323 PY_CHECK_TYPE(&PyString_Type
, py_secret_old
, return NULL
;);
3324 PY_CHECK_TYPE(security_Type
, py_sd
, return NULL
;);
3326 methods
= pytalloc_get_ptr(self
);
3328 PyString_AsStringAndSize(py_secret_cur
, (char **)&secret_current
.data
, &len
);
3329 secret_current
.length
= len
;
3330 PyString_AsStringAndSize(py_secret_old
, (char **)&secret_old
.data
, &len
);
3331 secret_current
.length
= len
;
3332 sd
= pytalloc_get_ptr(py_sd
);
3334 status
= methods
->set_secret(methods
, secret_name
, &secret_current
, &secret_old
, sd
);
3335 if (!NT_STATUS_IS_OK(status
)) {
3336 PyErr_Format(py_pdb_error
, "Unable to set information for secret (%s), (%d,%s)",
3338 NT_STATUS_V(status
),
3339 get_friendly_nt_error_msg(status
));
3349 static PyObject
*py_pdb_delete_secret(pytalloc_Object
*self
, PyObject
*args
)
3351 TALLOC_CTX
*frame
= talloc_stackframe();
3353 struct pdb_methods
*methods
;
3354 const char *secret_name
;
3356 if (!PyArg_ParseTuple(args
, "s:delete_secret", &secret_name
)) {
3361 methods
= pytalloc_get_ptr(self
);
3363 status
= methods
->delete_secret(methods
, secret_name
);
3364 if (!NT_STATUS_IS_OK(status
)) {
3365 PyErr_Format(py_pdb_error
, "Unable to delete secret (%s), (%d,%s)",
3367 NT_STATUS_V(status
),
3368 get_friendly_nt_error_msg(status
));
3377 static PyMethodDef py_pdb_methods
[] = {
3378 { "domain_info", (PyCFunction
)py_pdb_domain_info
, METH_NOARGS
,
3379 "domain_info() -> str\n\n \
3380 Get domain information for the database." },
3381 { "getsampwnam", (PyCFunction
)py_pdb_getsampwnam
, METH_VARARGS
,
3382 "getsampwnam(username) -> samu object\n\n \
3383 Get user information by name." },
3384 { "getsampwsid", (PyCFunction
)py_pdb_getsampwsid
, METH_VARARGS
,
3385 "getsampwsid(user_sid) -> samu object\n\n \
3386 Get user information by sid (dcerpc.security.dom_sid object)." },
3387 { "create_user", (PyCFunction
)py_pdb_create_user
, METH_VARARGS
,
3388 "create_user(username, acct_flags) -> rid\n\n \
3389 Create user. acct_flags are samr account control flags." },
3390 { "delete_user", (PyCFunction
)py_pdb_delete_user
, METH_VARARGS
,
3391 "delete_user(samu object) -> None\n\n \
3393 { "add_sam_account", (PyCFunction
)py_pdb_add_sam_account
, METH_VARARGS
,
3394 "add_sam_account(samu object) -> None\n\n \
3395 Add SAM account." },
3396 { "update_sam_account", (PyCFunction
)py_pdb_update_sam_account
, METH_VARARGS
,
3397 "update_sam_account(samu object) -> None\n\n \
3398 Update SAM account." },
3399 { "delete_sam_account", (PyCFunction
)py_pdb_delete_sam_account
, METH_VARARGS
,
3400 "delete_sam_account(samu object) -> None\n\n \
3401 Delete SAM account." },
3402 { "rename_sam_account", (PyCFunction
)py_pdb_rename_sam_account
, METH_VARARGS
,
3403 "rename_sam_account(samu object1, new_username) -> None\n\n \
3404 Rename SAM account." },
3405 /* update_login_attempts */
3406 { "getgrsid", (PyCFunction
)py_pdb_getgrsid
, METH_VARARGS
,
3407 "getgrsid(group_sid) -> groupmap object\n\n \
3408 Get group information by sid (dcerpc.security.dom_sid object)." },
3409 { "getgrgid", (PyCFunction
)py_pdb_getgrgid
, METH_VARARGS
,
3410 "getgrsid(gid) -> groupmap object\n\n \
3411 Get group information by gid." },
3412 { "getgrnam", (PyCFunction
)py_pdb_getgrnam
, METH_VARARGS
,
3413 "getgrsid(groupname) -> groupmap object\n\n \
3414 Get group information by name." },
3415 { "create_dom_group", (PyCFunction
)py_pdb_create_dom_group
, METH_VARARGS
,
3416 "create_dom_group(groupname) -> group_rid\n\n \
3417 Create new domain group by name." },
3418 { "delete_dom_group", (PyCFunction
)py_pdb_delete_dom_group
, METH_VARARGS
,
3419 "delete_dom_group(group_rid) -> None\n\n \
3420 Delete domain group identified by rid" },
3421 { "add_group_mapping_entry", (PyCFunction
)py_pdb_add_group_mapping_entry
, METH_VARARGS
,
3422 "add_group_mapping_entry(groupmap) -> None\n \
3423 Add group mapping entry for groupmap object." },
3424 { "update_group_mapping_entry", (PyCFunction
)py_pdb_update_group_mapping_entry
, METH_VARARGS
,
3425 "update_group_mapping_entry(groupmap) -> None\n\n \
3426 Update group mapping entry for groupmap object." },
3427 { "delete_group_mapping_entry", (PyCFunction
)py_pdb_delete_group_mapping_entry
, METH_VARARGS
,
3428 "delete_group_mapping_entry(groupmap) -> None\n\n \
3429 Delete group mapping entry for groupmap object." },
3430 { "enum_group_mapping", (PyCFunction
)py_pdb_enum_group_mapping
, METH_VARARGS
,
3431 "enum_group_mapping([domain_sid, [type, [unix_only]]]) -> List\n\n \
3432 Return list of group mappings as groupmap objects. Optional arguments are domain_sid object, type of group, unix only flag." },
3433 { "enum_group_members", (PyCFunction
)py_pdb_enum_group_members
, METH_VARARGS
,
3434 "enum_group_members(group_sid) -> List\n\n \
3435 Return list of users (dom_sid object) in group." },
3436 { "enum_group_memberships", (PyCFunction
)py_pdb_enum_group_memberships
, METH_VARARGS
,
3437 "enum_group_memberships(samu object) -> List\n\n \
3438 Return list of groups (dom_sid object) this user is part of." },
3439 /* set_unix_primary_group */
3440 { "add_groupmem", (PyCFunction
)py_pdb_add_groupmem
, METH_VARARGS
,
3441 "add_groupmem(group_rid, member_rid) -> None\n\n \
3442 Add user to group." },
3443 { "del_groupmem", (PyCFunction
)py_pdb_del_groupmem
, METH_VARARGS
,
3444 "del_groupmem(group_rid, member_rid) -> None\n\n \
3445 Remove user from from group." },
3446 { "create_alias", (PyCFunction
)py_pdb_create_alias
, METH_VARARGS
,
3447 "create_alias(alias_name) -> alias_rid\n\n \
3448 Create alias entry." },
3449 { "delete_alias", (PyCFunction
)py_pdb_delete_alias
, METH_VARARGS
,
3450 "delete_alias(alias_sid) -> None\n\n \
3451 Delete alias entry." },
3452 { "get_aliasinfo", (PyCFunction
)py_pdb_get_aliasinfo
, METH_VARARGS
,
3453 "get_aliasinfo(alias_sid) -> Mapping\n\n \
3454 Get alias information as a dictionary with keys - acct_name, acct_desc, rid." },
3455 { "set_aliasinfo", (PyCFunction
)py_pdb_set_aliasinfo
, METH_VARARGS
,
3456 "set_alias_info(alias_sid, Mapping) -> None\n\n \
3457 Set alias information from a dictionary with keys - acct_name, acct_desc." },
3458 { "add_aliasmem", (PyCFunction
)py_pdb_add_aliasmem
, METH_VARARGS
,
3459 "add_aliasmem(alias_sid, member_sid) -> None\n\n \
3460 Add user to alias entry." },
3461 { "del_aliasmem", (PyCFunction
)py_pdb_del_aliasmem
, METH_VARARGS
,
3462 "del_aliasmem(alias_sid, member_sid) -> None\n\n \
3463 Remove a user from alias entry." },
3464 { "enum_aliasmem", (PyCFunction
)py_pdb_enum_aliasmem
, METH_VARARGS
,
3465 "enum_aliasmem(alias_sid) -> List\n\n \
3466 Return a list of members (dom_sid object) for alias entry." },
3467 /* enum_alias_memberships */
3470 { "get_account_policy", (PyCFunction
)py_pdb_get_account_policy
, METH_NOARGS
,
3471 "get_account_policy() -> Mapping\n\n \
3472 Get account policy information as a dictionary." },
3473 { "set_account_policy", (PyCFunction
)py_pdb_set_account_policy
, METH_VARARGS
,
3474 "get_account_policy(Mapping) -> None\n\n \
3475 Set account policy settings from a dicionary." },
3477 { "search_users", (PyCFunction
)py_pdb_search_users
, METH_VARARGS
,
3478 "search_users(acct_flags) -> List\n\n \
3479 Search users. acct_flags are samr account control flags.\n \
3480 Each list entry is dictionary with keys - idx, rid, acct_flags, account_name, fullname, description." },
3481 { "search_groups", (PyCFunction
)py_pdb_search_groups
, METH_NOARGS
,
3482 "search_groups() -> List\n\n \
3483 Search unix only groups. \n \
3484 Each list entry is dictionary with keys - idx, rid, acct_flags, account_name, fullname, description." },
3485 { "search_aliases", (PyCFunction
)py_pdb_search_aliases
, METH_VARARGS
,
3486 "search_aliases([domain_sid]) -> List\n\n \
3487 Search aliases. domain_sid is dcerpc.security.dom_sid object.\n \
3488 Each list entry is dictionary with keys - idx, rid, acct_flags, account_name, fullname, description." },
3489 { "uid_to_sid", (PyCFunction
)py_pdb_uid_to_sid
, METH_VARARGS
,
3490 "uid_to_sid(uid) -> sid\n\n \
3491 Return sid for given user id." },
3492 { "gid_to_sid", (PyCFunction
)py_pdb_gid_to_sid
, METH_VARARGS
,
3493 "gid_to_sid(gid) -> sid\n\n \
3494 Return sid for given group id." },
3495 { "sid_to_id", (PyCFunction
)py_pdb_sid_to_id
, METH_VARARGS
,
3496 "sid_to_id(sid) -> Tuple\n\n \
3497 Return id and type for given sid." },
3499 { "new_rid", (PyCFunction
)py_pdb_new_rid
, METH_NOARGS
,
3500 "new_rid() -> rid\n\n \
3502 { "get_trusteddom_pw", (PyCFunction
)py_pdb_get_trusteddom_pw
, METH_VARARGS
,
3503 "get_trusteddom_pw(domain) -> Mapping\n\n \
3504 Get trusted domain password, sid and last set time in a dictionary." },
3505 { "set_trusteddom_pw", (PyCFunction
)py_pdb_set_trusteddom_pw
, METH_VARARGS
,
3506 "set_trusteddom_pw(domain, pwd, sid) -> None\n\n \
3507 Set trusted domain password." },
3508 { "del_trusteddom_pw", (PyCFunction
)py_pdb_del_trusteddom_pw
, METH_VARARGS
,
3509 "del_trusteddom_pw(domain) -> None\n\n \
3510 Delete trusted domain password." },
3511 { "enum_trusteddoms", (PyCFunction
)py_pdb_enum_trusteddoms
, METH_NOARGS
,
3512 "enum_trusteddoms() -> List\n\n \
3513 Get list of trusted domains. Each item is a dictionary with name and sid keys" },
3514 { "get_trusted_domain", (PyCFunction
)py_pdb_get_trusted_domain
, METH_VARARGS
,
3515 "get_trusted_domain(domain) -> Mapping\n\n \
3516 Get trusted domain information by name. Information is a dictionary with keys - domain_name, netbios_name, security_identifier, trust_auth_incoming, trust_auth_outgoing, trust_direction, trust_type, trust_attributes, trust_forest_trust_info." },
3517 { "get_trusted_domain_by_sid", (PyCFunction
)py_pdb_get_trusted_domain_by_sid
, METH_VARARGS
,
3518 "get_trusted_domain_by_sid(domain_sid) -> Mapping\n\n \
3519 Get trusted domain information by sid. Information is a dictionary with keys - domain_name, netbios_name, security_identifier, trust_auth_incoming, trust_auth_outgoing, trust_direction, trust_type, trust_attributes, trust_forest_trust_info" },
3520 { "set_trusted_domain", (PyCFunction
)py_pdb_set_trusted_domain
, METH_VARARGS
,
3521 "set_trusted_domain(domain, Mapping) -> None\n\n \
3522 Set trusted domain information for domain. Mapping is a dictionary with keys - domain_name, netbios_name, security_identifier, trust_auth_incoming, trust_auth_outgoing, trust_direction, trust_type, trust_attributes, trust_forest_trust_info." },
3523 { "del_trusted_domain", (PyCFunction
)py_pdb_del_trusted_domain
, METH_VARARGS
,
3524 "del_trusted_domain(domain) -> None\n\n \
3525 Delete trusted domain." },
3526 { "enum_trusted_domains", (PyCFunction
)py_pdb_enum_trusted_domains
, METH_VARARGS
,
3527 "enum_trusted_domains() -> List\n\n \
3528 Get list of trusted domains. Each entry is a dictionary with keys - domain_name, netbios_name, security_identifier, trust_auth_incoming, trust_auth_outgoing, trust_direction, trust_type, trust_attributes, trust_forest_trust_info." },
3529 { "get_secret", (PyCFunction
)py_pdb_get_secret
, METH_VARARGS
,
3530 "get_secret(secret_name) -> Mapping\n\n \
3531 Get secret information for secret_name. Information is a dictionary with keys - secret_current, secret_current_lastchange, secret_old, secret_old_lastchange, sd." },
3532 { "set_secret", (PyCFunction
)py_pdb_set_secret
, METH_VARARGS
,
3533 "set_secret(secret_name, Mapping) -> None\n\n \
3534 Set secret information for secret_name using dictionary with keys - secret_current, sd." },
3535 { "delete_secret", (PyCFunction
)py_pdb_delete_secret
, METH_VARARGS
,
3536 "delete_secret(secret_name) -> None\n\n \
3537 Delete secret information for secret_name." },
3542 static PyObject
*py_pdb_new(PyTypeObject
*type
, PyObject
*args
, PyObject
*kwargs
)
3544 TALLOC_CTX
*frame
= talloc_stackframe();
3545 const char *url
= NULL
;
3548 struct pdb_methods
*methods
;
3550 if (!PyArg_ParseTuple(args
, "s", &url
)) {
3555 /* Initalize list of methods */
3556 status
= make_pdb_method_name(&methods
, url
);
3557 if (!NT_STATUS_IS_OK(status
)) {
3558 PyErr_Format(py_pdb_error
, "Cannot load backend methods for '%s' backend (%d,%s)",
3560 NT_STATUS_V(status
),
3561 get_friendly_nt_error_msg(status
));
3566 if ((pypdb
= pytalloc_steal(type
, methods
)) == NULL
) {
3577 static PyTypeObject PyPDB
= {
3578 .tp_name
= "passdb.PDB",
3579 .tp_basicsize
= sizeof(pytalloc_Object
),
3580 .tp_new
= py_pdb_new
,
3581 .tp_flags
= Py_TPFLAGS_DEFAULT
,
3582 .tp_methods
= py_pdb_methods
,
3583 .tp_doc
= "PDB(url[, read_write_flags]) -> Password DB object\n",
3588 * Return a list of passdb backends
3590 static PyObject
*py_passdb_backends(PyObject
*self
)
3592 TALLOC_CTX
*frame
= talloc_stackframe();
3594 const struct pdb_init_function_entry
*entry
;
3596 entry
= pdb_get_backends();
3601 if((py_blist
= PyList_New(0)) == NULL
) {
3608 PyList_Append(py_blist
, PyString_FromString(entry
->name
));
3609 entry
= entry
->next
;
3617 static PyObject
*py_set_smb_config(PyObject
*self
, PyObject
*args
)
3619 TALLOC_CTX
*frame
= talloc_stackframe();
3620 const char *smb_config
;
3622 if (!PyArg_ParseTuple(args
, "s", &smb_config
)) {
3627 /* Load smbconf parameters */
3628 if (!lp_load_global(smb_config
)) {
3629 PyErr_Format(py_pdb_error
, "Cannot open '%s'", smb_config
);
3639 static PyObject
*py_set_secrets_dir(PyObject
*self
, PyObject
*args
)
3641 TALLOC_CTX
*frame
= talloc_stackframe();
3642 const char *private_dir
;
3644 if (!PyArg_ParseTuple(args
, "s", &private_dir
)) {
3649 /* Initialize secrets database */
3650 if (!secrets_init_path(private_dir
)) {
3651 PyErr_Format(py_pdb_error
, "Cannot open secrets file database in '%s'",
3661 static PyObject
*py_reload_static_pdb(PyObject
*self
, PyObject
*args
)
3663 TALLOC_CTX
*frame
= talloc_stackframe();
3665 /* Initialize secrets database */
3666 if (!initialize_password_db(true, NULL
)) {
3667 PyErr_Format(py_pdb_error
, "Cannot re-open passdb backend %s", lp_passdb_backend());
3676 static PyObject
*py_get_global_sam_sid(PyObject
*self
)
3678 TALLOC_CTX
*frame
= talloc_stackframe();
3679 struct dom_sid
*domain_sid
, *domain_sid_copy
;
3680 PyObject
*py_dom_sid
;
3682 domain_sid
= get_global_sam_sid();
3684 domain_sid_copy
= dom_sid_dup(frame
, domain_sid
);
3685 if (domain_sid_copy
== NULL
) {
3691 py_dom_sid
= pytalloc_steal(dom_sid_Type
, domain_sid_copy
);
3698 static PyMethodDef py_passdb_methods
[] = {
3699 { "get_backends", (PyCFunction
)py_passdb_backends
, METH_NOARGS
,
3700 "get_backends() -> list\n\n \
3701 Get a list of password database backends supported." },
3702 { "set_smb_config", (PyCFunction
)py_set_smb_config
, METH_VARARGS
,
3703 "set_smb_config(path) -> None\n\n \
3704 Set path to smb.conf file to load configuration parameters." },
3705 { "set_secrets_dir", (PyCFunction
)py_set_secrets_dir
, METH_VARARGS
,
3706 "set_secrets_dir(private_dir) -> None\n\n \
3707 Set path to private directory to load secrets database from non-default location." },
3708 { "get_global_sam_sid", (PyCFunction
)py_get_global_sam_sid
, METH_NOARGS
,
3709 "get_global_sam_sid() -> dom_sid\n\n \
3710 Return domain SID." },
3711 { "reload_static_pdb", (PyCFunction
)py_reload_static_pdb
, METH_NOARGS
,
3712 "reload_static_pdb() -> None\n\n \
3713 Re-initalise the static pdb used internally. Needed if 'passdb backend' is changed." },
3717 void initpassdb(void)
3719 TALLOC_CTX
*frame
= talloc_stackframe();
3721 char exception_name
[] = "passdb.error";
3723 PyTypeObject
*talloc_type
= pytalloc_GetObjectType();
3724 if (talloc_type
== NULL
) {
3729 PyPDB
.tp_base
= talloc_type
;
3730 if (PyType_Ready(&PyPDB
) < 0) {
3735 PySamu
.tp_base
= talloc_type
;
3736 if (PyType_Ready(&PySamu
) < 0) {
3741 PyGroupmap
.tp_base
= talloc_type
;
3742 if (PyType_Ready(&PyGroupmap
) < 0) {
3747 m
= Py_InitModule3("passdb", py_passdb_methods
, "SAMBA Password Database");
3753 /* Create new exception for passdb module */
3754 py_pdb_error
= PyErr_NewException(exception_name
, NULL
, NULL
);
3755 Py_INCREF(py_pdb_error
);
3756 PyModule_AddObject(m
, "error", py_pdb_error
);
3759 PyModule_AddObject(m
, "PDB", (PyObject
*)&PyPDB
);
3762 PyModule_AddObject(m
, "Samu", (PyObject
*)&PySamu
);
3764 Py_INCREF(&PyGroupmap
);
3765 PyModule_AddObject(m
, "Groupmap", (PyObject
*)&PyGroupmap
);
3767 /* Import dom_sid type from dcerpc.security */
3768 mod
= PyImport_ImportModule("samba.dcerpc.security");
3774 dom_sid_Type
= (PyTypeObject
*)PyObject_GetAttrString(mod
, "dom_sid");
3775 if (dom_sid_Type
== NULL
) {
3780 /* Import security_descriptor type from dcerpc.security */
3781 security_Type
= (PyTypeObject
*)PyObject_GetAttrString(mod
, "descriptor");
3783 if (security_Type
== NULL
) {
3788 /* Import GUID type from dcerpc.misc */
3789 mod
= PyImport_ImportModule("samba.dcerpc.misc");
3795 guid_Type
= (PyTypeObject
*)PyObject_GetAttrString(mod
, "GUID");
3797 if (guid_Type
== NULL
) {