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"
29 /* There's no Py_ssize_t in 2.4, apparently */
30 #if PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION < 5
31 typedef int Py_ssize_t
;
32 typedef inquiry lenfunc
;
33 typedef intargfunc ssizeargfunc
;
36 #ifndef Py_TYPE /* Py_TYPE is only available on Python > 2.6 */
37 #define Py_TYPE(ob) (((PyObject*)(ob))->ob_type)
41 #define PY_CHECK_TYPE(type, var, fail) \
42 if (!PyObject_TypeCheck(var, type)) {\
43 PyErr_Format(PyExc_TypeError, __location__ ": Expected type '%s' for '%s' of type '%s'", (type)->tp_name, #var, Py_TYPE(var)->tp_name); \
49 static PyTypeObject
*dom_sid_Type
= NULL
;
50 static PyTypeObject
*security_Type
= NULL
;
51 static PyTypeObject
*guid_Type
= NULL
;
53 staticforward PyTypeObject PySamu
;
54 staticforward PyTypeObject PyGroupmap
;
55 staticforward PyTypeObject PyPDB
;
57 static PyObject
*py_pdb_error
;
59 void initpassdb(void);
62 /************************** PIDL Autogeneratd ******************************/
64 static PyObject
*py_samu_get_logon_time(PyObject
*obj
, void *closure
)
66 TALLOC_CTX
*frame
= talloc_stackframe();
67 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
68 PyObject
*py_logon_time
;
70 py_logon_time
= PyInt_FromLong(pdb_get_logon_time(sam_acct
));
75 static int py_samu_set_logon_time(PyObject
*obj
, PyObject
*value
, void *closure
)
77 TALLOC_CTX
*frame
= talloc_stackframe();
78 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
80 PY_CHECK_TYPE(&PyInt_Type
, value
, return -1;);
81 if (!pdb_set_logon_time(sam_acct
, PyInt_AsLong(value
), PDB_CHANGED
)) {
89 static PyObject
*py_samu_get_logoff_time(PyObject
*obj
, void *closure
)
91 TALLOC_CTX
*frame
= talloc_stackframe();
92 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
93 PyObject
*py_logoff_time
;
95 py_logoff_time
= PyInt_FromLong(pdb_get_logoff_time(sam_acct
));
97 return py_logoff_time
;
100 static int py_samu_set_logoff_time(PyObject
*obj
, PyObject
*value
, void *closure
)
102 TALLOC_CTX
*frame
= talloc_stackframe();
103 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
105 PY_CHECK_TYPE(&PyInt_Type
, value
, return -1;);
106 if (!pdb_set_logoff_time(sam_acct
, PyInt_AsLong(value
), PDB_CHANGED
)) {
114 static PyObject
*py_samu_get_kickoff_time(PyObject
*obj
, void *closure
)
116 TALLOC_CTX
*frame
= talloc_stackframe();
117 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
118 PyObject
*py_kickoff_time
;
120 py_kickoff_time
= PyInt_FromLong(pdb_get_kickoff_time(sam_acct
));
122 return py_kickoff_time
;
125 static int py_samu_set_kickoff_time(PyObject
*obj
, PyObject
*value
, void *closure
)
127 TALLOC_CTX
*frame
= talloc_stackframe();
128 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
130 PY_CHECK_TYPE(&PyInt_Type
, value
, return -1;);
131 if (!pdb_set_kickoff_time(sam_acct
, PyInt_AsLong(value
), PDB_CHANGED
)) {
139 static PyObject
*py_samu_get_bad_password_time(PyObject
*obj
, void *closure
)
141 TALLOC_CTX
*frame
= talloc_stackframe();
142 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
143 PyObject
*py_bad_password_time
;
145 py_bad_password_time
= PyInt_FromLong(pdb_get_bad_password_time(sam_acct
));
147 return py_bad_password_time
;
150 static int py_samu_set_bad_password_time(PyObject
*obj
, PyObject
*value
, void *closure
)
152 TALLOC_CTX
*frame
= talloc_stackframe();
153 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
155 PY_CHECK_TYPE(&PyInt_Type
, value
, return -1;);
156 if (!pdb_set_bad_password_time(sam_acct
, PyInt_AsLong(value
), PDB_CHANGED
)) {
164 static PyObject
*py_samu_get_pass_last_set_time(PyObject
*obj
, void *closure
)
166 TALLOC_CTX
*frame
= talloc_stackframe();
167 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
168 PyObject
*py_pass_last_set_time
;
170 py_pass_last_set_time
= PyInt_FromLong(pdb_get_pass_last_set_time(sam_acct
));
172 return py_pass_last_set_time
;
175 static int py_samu_set_pass_last_set_time(PyObject
*obj
, PyObject
*value
, void *closure
)
177 TALLOC_CTX
*frame
= talloc_stackframe();
178 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
180 PY_CHECK_TYPE(&PyInt_Type
, value
, return -1;);
181 if (!pdb_set_pass_last_set_time(sam_acct
, PyInt_AsLong(value
), PDB_CHANGED
)) {
189 static PyObject
*py_samu_get_pass_can_change_time(PyObject
*obj
, void *closure
)
191 TALLOC_CTX
*frame
= talloc_stackframe();
192 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
193 PyObject
*py_pass_can_change_time
;
195 py_pass_can_change_time
= PyInt_FromLong(pdb_get_pass_can_change_time(sam_acct
));
197 return py_pass_can_change_time
;
200 static int py_samu_set_pass_can_change_time(PyObject
*obj
, PyObject
*value
, void *closure
)
202 TALLOC_CTX
*frame
= talloc_stackframe();
203 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
205 PY_CHECK_TYPE(&PyInt_Type
, value
, return -1;);
206 if (!pdb_set_pass_can_change_time(sam_acct
, PyInt_AsLong(value
), PDB_CHANGED
)) {
214 static PyObject
*py_samu_get_pass_must_change_time(PyObject
*obj
, void *closure
)
216 TALLOC_CTX
*frame
= talloc_stackframe();
217 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
218 PyObject
*py_pass_must_change_time
;
220 py_pass_must_change_time
= PyInt_FromLong(pdb_get_pass_must_change_time(sam_acct
));
222 return py_pass_must_change_time
;
225 static int py_samu_set_pass_must_change_time(PyObject
*obj
, PyObject
*value
, void *closure
)
227 TALLOC_CTX
*frame
= talloc_stackframe();
228 PY_CHECK_TYPE(&PyInt_Type
, value
, return -1;);
230 /* TODO: make this not a get/set or give a better exception */
235 static PyObject
*py_samu_get_username(PyObject
*obj
, void *closure
)
237 TALLOC_CTX
*frame
= talloc_stackframe();
238 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
239 PyObject
*py_username
;
240 const char *username
;
242 username
= pdb_get_username(sam_acct
);
243 if (username
== NULL
) {
247 py_username
= PyString_FromString(username
);
252 static int py_samu_set_username(PyObject
*obj
, PyObject
*value
, void *closure
)
254 TALLOC_CTX
*frame
= talloc_stackframe();
255 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
257 PY_CHECK_TYPE(&PyString_Type
, value
, return -1;);
258 if (!pdb_set_username(sam_acct
, PyString_AsString(value
), PDB_CHANGED
)) {
266 static PyObject
*py_samu_get_domain(PyObject
*obj
, void *closure
)
268 TALLOC_CTX
*frame
= talloc_stackframe();
269 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
273 domain
= pdb_get_domain(sam_acct
);
274 if (domain
== NULL
) {
278 py_domain
= PyString_FromString(domain
);
283 static int py_samu_set_domain(PyObject
*obj
, PyObject
*value
, void *closure
)
285 TALLOC_CTX
*frame
= talloc_stackframe();
286 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
288 PY_CHECK_TYPE(&PyString_Type
, value
, return -1;);
289 if (!pdb_set_domain(sam_acct
, PyString_AsString(value
), PDB_CHANGED
)) {
297 static PyObject
*py_samu_get_nt_username(PyObject
*obj
, void *closure
)
299 TALLOC_CTX
*frame
= talloc_stackframe();
300 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
301 PyObject
*py_nt_username
;
302 const char *nt_username
;
304 nt_username
= pdb_get_nt_username(sam_acct
);
305 if (nt_username
== NULL
) {
309 py_nt_username
= PyString_FromString(nt_username
);
311 return py_nt_username
;
314 static int py_samu_set_nt_username(PyObject
*obj
, PyObject
*value
, void *closure
)
316 TALLOC_CTX
*frame
= talloc_stackframe();
317 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
319 PY_CHECK_TYPE(&PyString_Type
, value
, return -1;);
320 if (!pdb_set_nt_username(sam_acct
, PyString_AsString(value
), PDB_CHANGED
)) {
328 static PyObject
*py_samu_get_full_name(PyObject
*obj
, void *closure
)
330 TALLOC_CTX
*frame
= talloc_stackframe();
331 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
332 PyObject
*py_full_name
;
333 const char *full_name
;
335 full_name
= pdb_get_fullname(sam_acct
);
336 if (full_name
== NULL
) {
340 py_full_name
= PyString_FromString(full_name
);
345 static int py_samu_set_full_name(PyObject
*obj
, PyObject
*value
, void *closure
)
347 TALLOC_CTX
*frame
= talloc_stackframe();
348 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
350 PY_CHECK_TYPE(&PyString_Type
, value
, return -1;);
351 if (!pdb_set_fullname(sam_acct
, PyString_AsString(value
), PDB_CHANGED
)) {
359 static PyObject
*py_samu_get_home_dir(PyObject
*obj
, void *closure
)
361 TALLOC_CTX
*frame
= talloc_stackframe();
362 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
363 PyObject
*py_home_dir
;
364 const char *home_dir
;
366 home_dir
= pdb_get_homedir(sam_acct
);
367 if (home_dir
== NULL
) {
371 py_home_dir
= PyString_FromString(home_dir
);
376 static int py_samu_set_home_dir(PyObject
*obj
, PyObject
*value
, void *closure
)
378 TALLOC_CTX
*frame
= talloc_stackframe();
379 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
381 PY_CHECK_TYPE(&PyString_Type
, value
, return -1;);
382 if (!pdb_set_homedir(sam_acct
, PyString_AsString(value
), PDB_CHANGED
)) {
390 static PyObject
*py_samu_get_dir_drive(PyObject
*obj
, void *closure
)
392 TALLOC_CTX
*frame
= talloc_stackframe();
393 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
394 PyObject
*py_dir_drive
;
395 const char *dir_drive
;
397 dir_drive
= pdb_get_dir_drive(sam_acct
);
398 if (dir_drive
== NULL
) {
402 py_dir_drive
= PyString_FromString(dir_drive
);
407 static int py_samu_set_dir_drive(PyObject
*obj
, PyObject
*value
, void *closure
)
409 TALLOC_CTX
*frame
= talloc_stackframe();
410 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
412 PY_CHECK_TYPE(&PyString_Type
, value
, return -1;);
413 if (!pdb_set_dir_drive(sam_acct
, PyString_AsString(value
), PDB_CHANGED
)) {
421 static PyObject
*py_samu_get_logon_script(PyObject
*obj
, void *closure
)
423 TALLOC_CTX
*frame
= talloc_stackframe();
424 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
425 PyObject
*py_logon_script
;
426 const char *logon_script
;
428 logon_script
= pdb_get_logon_script(sam_acct
);
429 if (logon_script
== NULL
) {
433 py_logon_script
= PyString_FromString(logon_script
);
435 return py_logon_script
;
438 static int py_samu_set_logon_script(PyObject
*obj
, PyObject
*value
, void *closure
)
440 TALLOC_CTX
*frame
= talloc_stackframe();
441 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
443 PY_CHECK_TYPE(&PyString_Type
, value
, return -1;);
444 if (!pdb_set_logon_script(sam_acct
, PyString_AsString(value
), PDB_CHANGED
)) {
452 static PyObject
*py_samu_get_profile_path(PyObject
*obj
, void *closure
)
454 TALLOC_CTX
*frame
= talloc_stackframe();
455 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
456 PyObject
*py_profile_path
;
457 const char *profile_path
;
459 profile_path
= pdb_get_profile_path(sam_acct
);
460 if (profile_path
== NULL
) {
464 py_profile_path
= PyString_FromString(profile_path
);
466 return py_profile_path
;
469 static int py_samu_set_profile_path(PyObject
*obj
, PyObject
*value
, void *closure
)
471 TALLOC_CTX
*frame
= talloc_stackframe();
472 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
474 PY_CHECK_TYPE(&PyString_Type
, value
, return -1;);
475 if (!pdb_set_profile_path(sam_acct
, PyString_AsString(value
), PDB_CHANGED
)) {
483 static PyObject
*py_samu_get_acct_desc(PyObject
*obj
, void *closure
)
485 TALLOC_CTX
*frame
= talloc_stackframe();
486 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
487 PyObject
*py_acct_desc
;
488 const char *acct_desc
;
490 acct_desc
= pdb_get_acct_desc(sam_acct
);
491 if (acct_desc
== NULL
) {
495 py_acct_desc
= PyString_FromString(acct_desc
);
500 static int py_samu_set_acct_desc(PyObject
*obj
, PyObject
*value
, void *closure
)
502 TALLOC_CTX
*frame
= talloc_stackframe();
503 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
505 PY_CHECK_TYPE(&PyString_Type
, value
, return -1;);
506 if (!pdb_set_acct_desc(sam_acct
, PyString_AsString(value
), PDB_CHANGED
)) {
514 static PyObject
*py_samu_get_workstations(PyObject
*obj
, void *closure
)
516 TALLOC_CTX
*frame
= talloc_stackframe();
517 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
518 PyObject
*py_workstations
;
519 const char *workstations
;
521 workstations
= pdb_get_workstations(sam_acct
);
522 if (workstations
== NULL
) {
526 py_workstations
= PyString_FromString(workstations
);
528 return py_workstations
;
531 static int py_samu_set_workstations(PyObject
*obj
, PyObject
*value
, void *closure
)
533 TALLOC_CTX
*frame
= talloc_stackframe();
534 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
536 PY_CHECK_TYPE(&PyString_Type
, value
, return -1;);
537 if (!pdb_set_workstations(sam_acct
, PyString_AsString(value
), PDB_CHANGED
)) {
545 static PyObject
*py_samu_get_comment(PyObject
*obj
, void *closure
)
547 TALLOC_CTX
*frame
= talloc_stackframe();
548 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
549 PyObject
*py_comment
;
552 comment
= pdb_get_comment(sam_acct
);
553 if (comment
== NULL
) {
557 py_comment
= PyString_FromString(comment
);
562 static int py_samu_set_comment(PyObject
*obj
, PyObject
*value
, void *closure
)
564 TALLOC_CTX
*frame
= talloc_stackframe();
565 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
567 PY_CHECK_TYPE(&PyString_Type
, value
, return -1;);
568 if (!pdb_set_comment(sam_acct
, PyString_AsString(value
), PDB_CHANGED
)) {
576 static PyObject
*py_samu_get_munged_dial(PyObject
*obj
, void *closure
)
578 TALLOC_CTX
*frame
= talloc_stackframe();
579 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
580 PyObject
*py_munged_dial
;
581 const char *munged_dial
;
583 munged_dial
= pdb_get_munged_dial(sam_acct
);
584 if (munged_dial
== NULL
) {
588 py_munged_dial
= PyString_FromString(munged_dial
);
590 return py_munged_dial
;
593 static int py_samu_set_munged_dial(PyObject
*obj
, PyObject
*value
, void *closure
)
595 TALLOC_CTX
*frame
= talloc_stackframe();
596 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
598 PY_CHECK_TYPE(&PyString_Type
, value
, return -1;);
599 if (!pdb_set_munged_dial(sam_acct
, PyString_AsString(value
), PDB_CHANGED
)) {
607 static PyObject
*py_samu_get_user_sid(PyObject
*obj
, void *closure
)
609 TALLOC_CTX
*frame
= talloc_stackframe();
610 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
611 PyObject
*py_user_sid
;
612 const struct dom_sid
*user_sid
;
613 struct dom_sid
*copy_user_sid
;
616 user_sid
= pdb_get_user_sid(sam_acct
);
617 if(user_sid
== NULL
) {
621 mem_ctx
= talloc_new(NULL
);
622 if (mem_ctx
== NULL
) {
627 copy_user_sid
= dom_sid_dup(mem_ctx
, user_sid
);
628 if (copy_user_sid
== NULL
) {
630 talloc_free(mem_ctx
);
635 py_user_sid
= pytalloc_steal(dom_sid_Type
, copy_user_sid
);
637 talloc_free(mem_ctx
);
643 static int py_samu_set_user_sid(PyObject
*obj
, PyObject
*value
, void *closure
)
645 TALLOC_CTX
*frame
= talloc_stackframe();
646 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
648 PY_CHECK_TYPE(dom_sid_Type
, value
, return -1;);
649 if (!pdb_set_user_sid(sam_acct
, (struct dom_sid
*)pytalloc_get_ptr(value
), PDB_CHANGED
)) {
657 static PyObject
*py_samu_get_group_sid(PyObject
*obj
, void *closure
)
659 TALLOC_CTX
*frame
= talloc_stackframe();
660 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
661 const struct dom_sid
*group_sid
;
662 struct dom_sid
*copy_group_sid
;
664 group_sid
= pdb_get_group_sid(sam_acct
);
665 if (group_sid
== NULL
) {
669 copy_group_sid
= dom_sid_dup(NULL
, group_sid
);
670 if (copy_group_sid
== NULL
) {
677 return pytalloc_steal(dom_sid_Type
, copy_group_sid
);
680 static int py_samu_set_group_sid(PyObject
*obj
, PyObject
*value
, void *closure
)
682 TALLOC_CTX
*frame
= talloc_stackframe();
683 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
685 PY_CHECK_TYPE(dom_sid_Type
, value
, return -1;);
686 if (!pdb_set_group_sid(sam_acct
, (struct dom_sid
*)pytalloc_get_ptr(value
), PDB_CHANGED
)) {
694 static PyObject
*py_samu_get_lanman_passwd(PyObject
*obj
, void *closure
)
696 TALLOC_CTX
*frame
= talloc_stackframe();
697 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
701 lm_pw
= (const char *)pdb_get_lanman_passwd(sam_acct
);
706 py_lm_pw
= PyString_FromStringAndSize(lm_pw
, LM_HASH_LEN
);
711 static int py_samu_set_lanman_passwd(PyObject
*obj
, PyObject
*value
, void *closure
)
713 TALLOC_CTX
*frame
= talloc_stackframe();
714 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
716 PY_CHECK_TYPE(&PyString_Type
, value
, return -1;);
717 if (!pdb_set_lanman_passwd(sam_acct
, (uint8_t *)PyString_AsString(value
), PDB_CHANGED
)) {
725 static PyObject
*py_samu_get_nt_passwd(PyObject
*obj
, void *closure
)
727 TALLOC_CTX
*frame
= talloc_stackframe();
728 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
732 nt_pw
= (const char *)pdb_get_nt_passwd(sam_acct
);
737 py_nt_pw
= PyString_FromStringAndSize(nt_pw
, NT_HASH_LEN
);
742 static int py_samu_set_nt_passwd(PyObject
*obj
, PyObject
*value
, void *closure
)
744 TALLOC_CTX
*frame
= talloc_stackframe();
745 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
747 if (!pdb_set_nt_passwd(sam_acct
, (uint8_t *)PyString_AsString(value
), PDB_CHANGED
)) {
755 static PyObject
*py_samu_get_pw_history(PyObject
*obj
, void *closure
)
757 TALLOC_CTX
*frame
= talloc_stackframe();
758 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
759 PyObject
*py_nt_pw_his
;
760 const char *nt_pw_his
;
763 nt_pw_his
= (const char *)pdb_get_pw_history(sam_acct
, &hist_len
);
764 if (nt_pw_his
== NULL
) {
768 py_nt_pw_his
= PyString_FromStringAndSize(nt_pw_his
, hist_len
*PW_HISTORY_ENTRY_LEN
);
773 static int py_samu_set_pw_history(PyObject
*obj
, PyObject
*value
, void *closure
)
775 TALLOC_CTX
*frame
= talloc_stackframe();
776 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
781 PyString_AsStringAndSize(value
, &nt_pw_his
, &len
);
782 hist_len
= len
/ PW_HISTORY_ENTRY_LEN
;
783 if (!pdb_set_pw_history(sam_acct
, (uint8_t *)nt_pw_his
, hist_len
, PDB_CHANGED
)) {
791 static PyObject
*py_samu_get_plaintext_passwd(PyObject
*obj
, void *closure
)
793 TALLOC_CTX
*frame
= talloc_stackframe();
794 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
795 PyObject
*py_plaintext_pw
;
796 const char *plaintext_pw
;
798 plaintext_pw
= pdb_get_plaintext_passwd(sam_acct
);
799 if (plaintext_pw
== NULL
) {
803 py_plaintext_pw
= PyString_FromString(plaintext_pw
);
805 return py_plaintext_pw
;
808 static int py_samu_set_plaintext_passwd(PyObject
*obj
, PyObject
*value
, void *closure
)
810 TALLOC_CTX
*frame
= talloc_stackframe();
811 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
813 if (!pdb_set_plaintext_passwd(sam_acct
, PyString_AsString(value
))) {
821 static PyObject
*py_samu_get_acct_ctrl(PyObject
*obj
, void *closure
)
823 TALLOC_CTX
*frame
= talloc_stackframe();
824 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
825 PyObject
*py_acct_ctrl
;
827 py_acct_ctrl
= PyInt_FromLong(pdb_get_acct_ctrl(sam_acct
));
832 static int py_samu_set_acct_ctrl(PyObject
*obj
, PyObject
*value
, void *closure
)
834 TALLOC_CTX
*frame
= talloc_stackframe();
835 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
837 PY_CHECK_TYPE(&PyInt_Type
, value
, return -1;);
838 if (!pdb_set_acct_ctrl(sam_acct
, PyInt_AsLong(value
), PDB_CHANGED
)) {
846 static PyObject
*py_samu_get_logon_divs(PyObject
*obj
, void *closure
)
848 TALLOC_CTX
*frame
= talloc_stackframe();
849 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
850 PyObject
*py_logon_divs
;
852 py_logon_divs
= PyInt_FromLong(pdb_get_logon_divs(sam_acct
));
854 return py_logon_divs
;
857 static int py_samu_set_logon_divs(PyObject
*obj
, PyObject
*value
, void *closure
)
859 TALLOC_CTX
*frame
= talloc_stackframe();
860 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
862 PY_CHECK_TYPE(&PyInt_Type
, value
, return -1;);
863 if (!pdb_set_logon_divs(sam_acct
, PyInt_AsLong(value
), PDB_CHANGED
)) {
871 static PyObject
*py_samu_get_hours_len(PyObject
*obj
, void *closure
)
873 TALLOC_CTX
*frame
= talloc_stackframe();
874 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
875 PyObject
*py_hours_len
;
877 py_hours_len
= PyInt_FromLong(pdb_get_hours_len(sam_acct
));
882 static int py_samu_set_hours_len(PyObject
*obj
, PyObject
*value
, void *closure
)
884 TALLOC_CTX
*frame
= talloc_stackframe();
885 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
887 PY_CHECK_TYPE(&PyInt_Type
, value
, return -1;);
888 if (!pdb_set_hours_len(sam_acct
, PyInt_AsLong(value
), PDB_CHANGED
)) {
896 static PyObject
*py_samu_get_hours(PyObject
*obj
, void *closure
)
898 TALLOC_CTX
*frame
= talloc_stackframe();
899 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
904 hours
= (const char *)pdb_get_hours(sam_acct
);
909 hours_len
= pdb_get_hours_len(sam_acct
);
910 if ((py_hours
= PyList_New(hours_len
)) == NULL
) {
916 for (i
=0; i
<hours_len
; i
++) {
917 PyList_SetItem(py_hours
, i
, PyInt_FromLong(hours
[i
]));
923 static int py_samu_set_hours(PyObject
*obj
, PyObject
*value
, void *closure
)
925 TALLOC_CTX
*frame
= talloc_stackframe();
926 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
932 PY_CHECK_TYPE(&PyList_Type
, value
, return -1;);
934 hours_len
= PyList_GET_SIZE(value
);
936 hours
= talloc_array(pytalloc_get_mem_ctx(obj
), uint8_t, hours_len
);
943 for (i
=0; i
< hours_len
; i
++) {
944 PY_CHECK_TYPE(&PyInt_Type
, PyList_GET_ITEM(value
,i
), return -1;);
945 hours
[i
] = PyInt_AsLong(PyList_GET_ITEM(value
, i
));
948 status
= pdb_set_hours(sam_acct
, hours
, hours_len
, PDB_CHANGED
);
959 static PyObject
*py_samu_get_bad_password_count(PyObject
*obj
, void *closure
)
961 TALLOC_CTX
*frame
= talloc_stackframe();
962 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
963 PyObject
*py_bad_password_count
;
965 py_bad_password_count
= PyInt_FromLong(pdb_get_bad_password_count(sam_acct
));
967 return py_bad_password_count
;
970 static int py_samu_set_bad_password_count(PyObject
*obj
, PyObject
*value
, void *closure
)
972 TALLOC_CTX
*frame
= talloc_stackframe();
973 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
975 PY_CHECK_TYPE(&PyInt_Type
, value
, return -1;);
976 if (!pdb_set_bad_password_count(sam_acct
, PyInt_AsLong(value
), PDB_CHANGED
)) {
984 static PyObject
*py_samu_get_logon_count(PyObject
*obj
, void *closure
)
986 TALLOC_CTX
*frame
= talloc_stackframe();
987 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
988 PyObject
*py_logon_count
;
990 py_logon_count
= PyInt_FromLong(pdb_get_logon_count(sam_acct
));
992 return py_logon_count
;
995 static int py_samu_set_logon_count(PyObject
*obj
, PyObject
*value
, void *closure
)
997 TALLOC_CTX
*frame
= talloc_stackframe();
998 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
1000 PY_CHECK_TYPE(&PyInt_Type
, value
, return -1;);
1001 if (!pdb_set_logon_count(sam_acct
, PyInt_AsLong(value
), PDB_CHANGED
)) {
1009 static PyObject
*py_samu_get_country_code(PyObject
*obj
, void *closure
)
1011 TALLOC_CTX
*frame
= talloc_stackframe();
1012 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
1013 PyObject
*py_country_code
;
1015 py_country_code
= PyInt_FromLong(pdb_get_country_code(sam_acct
));
1017 return py_country_code
;
1020 static int py_samu_set_country_code(PyObject
*obj
, PyObject
*value
, void *closure
)
1022 TALLOC_CTX
*frame
= talloc_stackframe();
1023 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
1025 PY_CHECK_TYPE(&PyInt_Type
, value
, return -1;);
1026 if (!pdb_set_country_code(sam_acct
, PyInt_AsLong(value
), PDB_CHANGED
)) {
1034 static PyObject
*py_samu_get_code_page(PyObject
*obj
, void *closure
)
1036 TALLOC_CTX
*frame
= talloc_stackframe();
1037 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
1038 PyObject
*py_code_page
;
1040 py_code_page
= PyInt_FromLong(pdb_get_code_page(sam_acct
));
1042 return py_code_page
;
1045 static int py_samu_set_code_page(PyObject
*obj
, PyObject
*value
, void *closure
)
1047 TALLOC_CTX
*frame
= talloc_stackframe();
1048 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
1050 PY_CHECK_TYPE(&PyInt_Type
, value
, return -1;);
1051 if (!pdb_set_code_page(sam_acct
, PyInt_AsLong(value
), PDB_CHANGED
)) {
1059 static PyGetSetDef py_samu_getsetters
[] = {
1060 { discard_const_p(char, "logon_time"), py_samu_get_logon_time
, py_samu_set_logon_time
},
1061 { discard_const_p(char, "logoff_time"), py_samu_get_logoff_time
, py_samu_set_logoff_time
},
1062 { discard_const_p(char, "kickoff_time"), py_samu_get_kickoff_time
, py_samu_set_kickoff_time
},
1063 { discard_const_p(char, "bad_password_time"), py_samu_get_bad_password_time
, py_samu_set_bad_password_time
},
1064 { discard_const_p(char, "pass_last_set_time"), py_samu_get_pass_last_set_time
, py_samu_set_pass_last_set_time
},
1065 { discard_const_p(char, "pass_can_change_time"), py_samu_get_pass_can_change_time
, py_samu_set_pass_can_change_time
},
1066 { discard_const_p(char, "pass_must_change_time"), py_samu_get_pass_must_change_time
, py_samu_set_pass_must_change_time
},
1067 { discard_const_p(char, "username"), py_samu_get_username
, py_samu_set_username
},
1068 { discard_const_p(char, "domain"), py_samu_get_domain
, py_samu_set_domain
},
1069 { discard_const_p(char, "nt_username"), py_samu_get_nt_username
, py_samu_set_nt_username
},
1070 { discard_const_p(char, "full_name"), py_samu_get_full_name
, py_samu_set_full_name
},
1071 { discard_const_p(char, "home_dir"), py_samu_get_home_dir
, py_samu_set_home_dir
},
1072 { discard_const_p(char, "dir_drive"), py_samu_get_dir_drive
, py_samu_set_dir_drive
},
1073 { discard_const_p(char, "logon_script"), py_samu_get_logon_script
, py_samu_set_logon_script
},
1074 { discard_const_p(char, "profile_path"), py_samu_get_profile_path
, py_samu_set_profile_path
},
1075 { discard_const_p(char, "acct_desc"), py_samu_get_acct_desc
, py_samu_set_acct_desc
},
1076 { discard_const_p(char, "workstations"), py_samu_get_workstations
, py_samu_set_workstations
},
1077 { discard_const_p(char, "comment"), py_samu_get_comment
, py_samu_set_comment
},
1078 { discard_const_p(char, "munged_dial"), py_samu_get_munged_dial
, py_samu_set_munged_dial
},
1079 { discard_const_p(char, "user_sid"), py_samu_get_user_sid
, py_samu_set_user_sid
},
1080 { discard_const_p(char, "group_sid"), py_samu_get_group_sid
, py_samu_set_group_sid
},
1081 { discard_const_p(char, "lanman_passwd"), py_samu_get_lanman_passwd
, py_samu_set_lanman_passwd
},
1082 { discard_const_p(char, "nt_passwd"), py_samu_get_nt_passwd
, py_samu_set_nt_passwd
},
1083 { discard_const_p(char, "pw_history"), py_samu_get_pw_history
, py_samu_set_pw_history
},
1084 { discard_const_p(char, "plaintext_passwd"), py_samu_get_plaintext_passwd
, py_samu_set_plaintext_passwd
},
1085 { discard_const_p(char, "acct_ctrl"), py_samu_get_acct_ctrl
, py_samu_set_acct_ctrl
},
1086 { discard_const_p(char, "logon_divs"), py_samu_get_logon_divs
, py_samu_set_logon_divs
},
1087 { discard_const_p(char, "hours_len"), py_samu_get_hours_len
, py_samu_set_hours_len
},
1088 { discard_const_p(char, "hours"), py_samu_get_hours
, py_samu_set_hours
},
1089 { discard_const_p(char, "bad_password_count"), py_samu_get_bad_password_count
, py_samu_set_bad_password_count
},
1090 { discard_const_p(char, "logon_count"), py_samu_get_logon_count
, py_samu_set_logon_count
},
1091 { discard_const_p(char, "country_code"), py_samu_get_country_code
, py_samu_set_country_code
},
1092 { discard_const_p(char, "code_page"), py_samu_get_code_page
, py_samu_set_code_page
},
1097 /************************** PIDL Autogeneratd ******************************/
1099 static PyObject
*py_samu_new(PyTypeObject
*type
, PyObject
*args
, PyObject
*kwargs
)
1101 TALLOC_CTX
*frame
= talloc_stackframe();
1102 struct samu
*sam_acct
;
1104 sam_acct
= samu_new(NULL
);
1112 return pytalloc_steal(type
, sam_acct
);
1115 static PyTypeObject PySamu
= {
1116 .tp_name
= "passdb.Samu",
1117 .tp_basicsize
= sizeof(pytalloc_Object
),
1118 .tp_getset
= py_samu_getsetters
,
1120 .tp_new
= py_samu_new
,
1121 .tp_flags
= Py_TPFLAGS_DEFAULT
| Py_TPFLAGS_BASETYPE
,
1122 .tp_doc
= "Samu() -> samu object\n",
1126 static PyObject
*py_groupmap_get_gid(PyObject
*obj
, void *closure
)
1128 TALLOC_CTX
*frame
= talloc_stackframe();
1129 GROUP_MAP
*group_map
= (GROUP_MAP
*)pytalloc_get_ptr(obj
);
1132 py_gid
= Py_BuildValue("i", group_map
->gid
);
1137 static int py_groupmap_set_gid(PyObject
*obj
, PyObject
*value
, void *closure
)
1139 TALLOC_CTX
*frame
= talloc_stackframe();
1140 GROUP_MAP
*group_map
= (GROUP_MAP
*)pytalloc_get_ptr(obj
);
1142 PY_CHECK_TYPE(&PyInt_Type
, value
, return -1;);
1143 group_map
->gid
= PyInt_AsLong(value
);
1148 static PyObject
*py_groupmap_get_sid(PyObject
*obj
, void *closure
)
1150 TALLOC_CTX
*frame
= talloc_stackframe();
1151 GROUP_MAP
*group_map
= (GROUP_MAP
*)pytalloc_get_ptr(obj
);
1153 struct dom_sid
*group_sid
;
1154 TALLOC_CTX
*mem_ctx
;
1156 mem_ctx
= talloc_new(NULL
);
1157 if (mem_ctx
== NULL
) {
1163 group_sid
= dom_sid_dup(mem_ctx
, &group_map
->sid
);
1164 if (group_sid
== NULL
) {
1166 talloc_free(mem_ctx
);
1171 py_sid
= pytalloc_steal(dom_sid_Type
, group_sid
);
1173 talloc_free(mem_ctx
);
1179 static int py_groupmap_set_sid(PyObject
*obj
, PyObject
*value
, void *closure
)
1181 TALLOC_CTX
*frame
= talloc_stackframe();
1182 GROUP_MAP
*group_map
= (GROUP_MAP
*)pytalloc_get_ptr(obj
);
1184 PY_CHECK_TYPE(dom_sid_Type
, value
, return -1;);
1185 group_map
->sid
= *pytalloc_get_type(value
, struct dom_sid
);
1190 static PyObject
*py_groupmap_get_sid_name_use(PyObject
*obj
, void *closure
)
1192 TALLOC_CTX
*frame
= talloc_stackframe();
1193 GROUP_MAP
*group_map
= (GROUP_MAP
*)pytalloc_get_ptr(obj
);
1194 PyObject
*py_sid_name_use
;
1196 py_sid_name_use
= PyInt_FromLong(group_map
->sid_name_use
);
1198 return py_sid_name_use
;
1201 static int py_groupmap_set_sid_name_use(PyObject
*obj
, PyObject
*value
, void *closure
)
1203 TALLOC_CTX
*frame
= talloc_stackframe();
1204 GROUP_MAP
*group_map
= (GROUP_MAP
*)pytalloc_get_ptr(obj
);
1206 PY_CHECK_TYPE(&PyInt_Type
, value
, return -1;);
1207 group_map
->sid_name_use
= PyInt_AsLong(value
);
1212 static PyObject
*py_groupmap_get_nt_name(PyObject
*obj
, void *closure
)
1214 TALLOC_CTX
*frame
= talloc_stackframe();
1215 GROUP_MAP
*group_map
= (GROUP_MAP
*)pytalloc_get_ptr(obj
);
1216 PyObject
*py_nt_name
;
1217 if (group_map
->nt_name
== NULL
) {
1218 py_nt_name
= Py_None
;
1219 Py_INCREF(py_nt_name
);
1221 py_nt_name
= PyString_FromString(group_map
->nt_name
);
1227 static int py_groupmap_set_nt_name(PyObject
*obj
, PyObject
*value
, void *closure
)
1229 TALLOC_CTX
*frame
= talloc_stackframe();
1230 GROUP_MAP
*group_map
= (GROUP_MAP
*)pytalloc_get_ptr(obj
);
1232 PY_CHECK_TYPE(&PyString_Type
, value
, return -1;);
1233 if (value
== Py_None
) {
1234 fstrcpy(group_map
->nt_name
, NULL
);
1236 fstrcpy(group_map
->nt_name
, PyString_AsString(value
));
1242 static PyObject
*py_groupmap_get_comment(PyObject
*obj
, void *closure
)
1244 TALLOC_CTX
*frame
= talloc_stackframe();
1245 GROUP_MAP
*group_map
= (GROUP_MAP
*)pytalloc_get_ptr(obj
);
1246 PyObject
*py_comment
;
1247 if (group_map
->comment
== NULL
) {
1248 py_comment
= Py_None
;
1249 Py_INCREF(py_comment
);
1251 py_comment
= PyString_FromString(group_map
->comment
);
1257 static int py_groupmap_set_comment(PyObject
*obj
, PyObject
*value
, void *closure
)
1259 TALLOC_CTX
*frame
= talloc_stackframe();
1260 GROUP_MAP
*group_map
= (GROUP_MAP
*)pytalloc_get_ptr(obj
);
1262 PY_CHECK_TYPE(&PyString_Type
, value
, return -1;);
1263 if (value
== Py_None
) {
1264 fstrcpy(group_map
->comment
, NULL
);
1266 fstrcpy(group_map
->comment
, PyString_AsString(value
));
1272 static PyGetSetDef py_groupmap_getsetters
[] = {
1273 { discard_const_p(char, "gid"), py_groupmap_get_gid
, py_groupmap_set_gid
},
1274 { discard_const_p(char, "sid"), py_groupmap_get_sid
, py_groupmap_set_sid
},
1275 { discard_const_p(char, "sid_name_use"), py_groupmap_get_sid_name_use
, py_groupmap_set_sid_name_use
},
1276 { discard_const_p(char, "nt_name"), py_groupmap_get_nt_name
, py_groupmap_set_nt_name
},
1277 { discard_const_p(char, "comment"), py_groupmap_get_comment
, py_groupmap_set_comment
},
1281 static PyObject
*py_groupmap_new(PyTypeObject
*type
, PyObject
*args
, PyObject
*kwargs
)
1283 TALLOC_CTX
*frame
= talloc_stackframe();
1284 GROUP_MAP
*group_map
;
1285 TALLOC_CTX
*mem_ctx
;
1286 PyObject
*py_group_map
;
1288 mem_ctx
= talloc_new(NULL
);
1289 if (mem_ctx
== NULL
) {
1295 group_map
= talloc_zero(mem_ctx
, GROUP_MAP
);
1296 if (group_map
== NULL
) {
1298 talloc_free(mem_ctx
);
1303 py_group_map
= pytalloc_steal(type
, group_map
);
1304 if (py_group_map
== NULL
) {
1306 talloc_free(mem_ctx
);
1311 talloc_free(mem_ctx
);
1314 return py_group_map
;
1318 static PyTypeObject PyGroupmap
= {
1319 .tp_name
= "passdb.Groupmap",
1320 .tp_basicsize
= sizeof(pytalloc_Object
),
1321 .tp_getset
= py_groupmap_getsetters
,
1323 .tp_new
= py_groupmap_new
,
1324 .tp_flags
= Py_TPFLAGS_DEFAULT
| Py_TPFLAGS_BASETYPE
,
1325 .tp_doc
= "Groupmap() -> group map object\n",
1329 static PyObject
*py_pdb_domain_info(pytalloc_Object
*self
, PyObject
*args
)
1331 TALLOC_CTX
*frame
= talloc_stackframe();
1332 struct pdb_methods
*methods
;
1333 struct pdb_domain_info
*domain_info
;
1334 PyObject
*py_domain_info
;
1335 struct dom_sid
*sid
;
1338 methods
= pytalloc_get_ptr(self
);
1340 domain_info
= methods
->get_domain_info(methods
, frame
);
1341 if (! domain_info
) {
1345 sid
= dom_sid_dup(frame
, &domain_info
->sid
);
1352 guid
= talloc(frame
, struct GUID
);
1358 *guid
= domain_info
->guid
;
1360 if ((py_domain_info
= PyDict_New()) == NULL
) {
1366 PyDict_SetItemString(py_domain_info
, "name", PyString_FromString(domain_info
->name
));
1367 PyDict_SetItemString(py_domain_info
, "dns_domain", PyString_FromString(domain_info
->dns_domain
));
1368 PyDict_SetItemString(py_domain_info
, "dns_forest", PyString_FromString(domain_info
->dns_forest
));
1369 PyDict_SetItemString(py_domain_info
, "dom_sid", pytalloc_steal(dom_sid_Type
, sid
));
1370 PyDict_SetItemString(py_domain_info
, "guid", pytalloc_steal(guid_Type
, guid
));
1373 return py_domain_info
;
1377 static PyObject
*py_pdb_getsampwnam(pytalloc_Object
*self
, PyObject
*args
)
1379 TALLOC_CTX
*frame
= talloc_stackframe();
1381 const char *username
;
1382 struct pdb_methods
*methods
;
1383 struct samu
*sam_acct
;
1384 PyObject
*py_sam_acct
;
1386 if (!PyArg_ParseTuple(args
, "s:getsampwnam", &username
)) {
1391 methods
= pytalloc_get_ptr(self
);
1393 py_sam_acct
= py_samu_new(&PySamu
, NULL
, NULL
);
1394 if (py_sam_acct
== NULL
) {
1399 sam_acct
= (struct samu
*)pytalloc_get_ptr(py_sam_acct
);
1401 status
= methods
->getsampwnam(methods
, sam_acct
, username
);
1402 if (!NT_STATUS_IS_OK(status
)) {
1403 PyErr_Format(py_pdb_error
, "Unable to get user information for '%s', (%d,%s)",
1405 NT_STATUS_V(status
),
1406 get_friendly_nt_error_msg(status
));
1407 Py_DECREF(py_sam_acct
);
1416 static PyObject
*py_pdb_getsampwsid(pytalloc_Object
*self
, PyObject
*args
)
1418 TALLOC_CTX
*frame
= talloc_stackframe();
1420 struct pdb_methods
*methods
;
1421 struct samu
*sam_acct
;
1422 PyObject
*py_sam_acct
;
1423 PyObject
*py_user_sid
;
1425 if (!PyArg_ParseTuple(args
, "O:getsampwsid", &py_user_sid
)) {
1430 methods
= pytalloc_get_ptr(self
);
1432 py_sam_acct
= py_samu_new(&PySamu
, NULL
, NULL
);
1433 if (py_sam_acct
== NULL
) {
1438 sam_acct
= (struct samu
*)pytalloc_get_ptr(py_sam_acct
);
1440 status
= methods
->getsampwsid(methods
, sam_acct
, pytalloc_get_ptr(py_user_sid
));
1441 if (!NT_STATUS_IS_OK(status
)) {
1442 PyErr_Format(py_pdb_error
, "Unable to get user information from SID, (%d,%s)",
1443 NT_STATUS_V(status
),
1444 get_friendly_nt_error_msg(status
));
1445 Py_DECREF(py_sam_acct
);
1454 static PyObject
*py_pdb_create_user(pytalloc_Object
*self
, PyObject
*args
)
1456 TALLOC_CTX
*frame
= talloc_stackframe();
1458 struct pdb_methods
*methods
;
1459 const char *username
;
1460 unsigned int acct_flags
;
1463 if (!PyArg_ParseTuple(args
, "sI:create_user", &username
, &acct_flags
)) {
1468 methods
= pytalloc_get_ptr(self
);
1470 status
= methods
->create_user(methods
, frame
, username
, acct_flags
, &rid
);
1471 if (!NT_STATUS_IS_OK(status
)) {
1472 PyErr_Format(py_pdb_error
, "Unable to create user (%s), (%d,%s)",
1474 NT_STATUS_V(status
),
1475 get_friendly_nt_error_msg(status
));
1481 return PyInt_FromLong(rid
);
1484 static PyObject
*py_pdb_delete_user(pytalloc_Object
*self
, PyObject
*args
)
1486 TALLOC_CTX
*frame
= talloc_stackframe();
1488 struct pdb_methods
*methods
;
1489 struct samu
*sam_acct
;
1490 PyObject
*py_sam_acct
;
1492 if (!PyArg_ParseTuple(args
, "O!:delete_user", &PySamu
, &py_sam_acct
)) {
1497 methods
= pytalloc_get_ptr(self
);
1499 sam_acct
= pytalloc_get_ptr(py_sam_acct
);
1501 status
= methods
->delete_user(methods
, frame
, sam_acct
);
1502 if (!NT_STATUS_IS_OK(status
)) {
1503 PyErr_Format(py_pdb_error
, "Unable to delete user, (%d,%s)",
1504 NT_STATUS_V(status
),
1505 get_friendly_nt_error_msg(status
));
1514 static PyObject
*py_pdb_add_sam_account(pytalloc_Object
*self
, PyObject
*args
)
1516 TALLOC_CTX
*frame
= talloc_stackframe();
1518 struct pdb_methods
*methods
;
1519 struct samu
*sam_acct
;
1520 PyObject
*py_sam_acct
;
1522 if (!PyArg_ParseTuple(args
, "O!:add_sam_account", &PySamu
, &py_sam_acct
)) {
1527 methods
= pytalloc_get_ptr(self
);
1529 sam_acct
= pytalloc_get_ptr(py_sam_acct
);
1531 status
= methods
->add_sam_account(methods
, sam_acct
);
1532 if (!NT_STATUS_IS_OK(status
)) {
1533 PyErr_Format(py_pdb_error
, "Unable to add sam account '%s', (%d,%s)",
1535 NT_STATUS_V(status
),
1536 get_friendly_nt_error_msg(status
));
1545 static PyObject
*py_pdb_update_sam_account(pytalloc_Object
*self
, PyObject
*args
)
1547 TALLOC_CTX
*frame
= talloc_stackframe();
1549 struct pdb_methods
*methods
;
1550 struct samu
*sam_acct
;
1551 PyObject
*py_sam_acct
;
1553 if (!PyArg_ParseTuple(args
, "O!:update_sam_account", &PySamu
, &py_sam_acct
)) {
1558 methods
= pytalloc_get_ptr(self
);
1560 sam_acct
= pytalloc_get_ptr(py_sam_acct
);
1562 status
= methods
->update_sam_account(methods
, sam_acct
);
1563 if (!NT_STATUS_IS_OK(status
)) {
1564 PyErr_Format(py_pdb_error
, "Unable to update sam account, (%d,%s)",
1565 NT_STATUS_V(status
),
1566 get_friendly_nt_error_msg(status
));
1575 static PyObject
*py_pdb_delete_sam_account(pytalloc_Object
*self
, PyObject
*args
)
1577 TALLOC_CTX
*frame
= talloc_stackframe();
1579 struct pdb_methods
*methods
;
1580 struct samu
*sam_acct
;
1581 PyObject
*py_sam_acct
;
1583 if (!PyArg_ParseTuple(args
, "O!:delete_sam_account", &PySamu
, &py_sam_acct
)) {
1588 methods
= pytalloc_get_ptr(self
);
1590 sam_acct
= pytalloc_get_ptr(py_sam_acct
);
1592 status
= methods
->delete_sam_account(methods
, sam_acct
);
1593 if (!NT_STATUS_IS_OK(status
)) {
1594 PyErr_Format(py_pdb_error
, "Unable to delete sam account, (%d,%s)",
1595 NT_STATUS_V(status
),
1596 get_friendly_nt_error_msg(status
));
1605 static PyObject
*py_pdb_rename_sam_account(pytalloc_Object
*self
, PyObject
*args
)
1607 TALLOC_CTX
*frame
= talloc_stackframe();
1609 struct pdb_methods
*methods
;
1610 struct samu
*sam_acct
;
1611 const char *new_username
;
1612 PyObject
*py_sam_acct
;
1614 if (!PyArg_ParseTuple(args
, "O!s:rename_sam_account", &PySamu
, &py_sam_acct
,
1620 methods
= pytalloc_get_ptr(self
);
1622 sam_acct
= pytalloc_get_ptr(py_sam_acct
);
1624 status
= methods
->rename_sam_account(methods
, sam_acct
, new_username
);
1625 if (!NT_STATUS_IS_OK(status
)) {
1626 PyErr_Format(py_pdb_error
, "Unable to rename sam account, (%d,%s)",
1627 NT_STATUS_V(status
),
1628 get_friendly_nt_error_msg(status
));
1638 static PyObject
*py_pdb_getgrsid(pytalloc_Object
*self
, PyObject
*args
)
1640 TALLOC_CTX
*frame
= talloc_stackframe();
1642 struct pdb_methods
*methods
;
1643 GROUP_MAP
*group_map
;
1644 struct dom_sid
*domain_sid
;
1645 PyObject
*py_domain_sid
, *py_group_map
;
1647 if (!PyArg_ParseTuple(args
, "O!:getgrsid", dom_sid_Type
, &py_domain_sid
)) {
1652 methods
= pytalloc_get_ptr(self
);
1654 domain_sid
= pytalloc_get_ptr(py_domain_sid
);
1656 py_group_map
= py_groupmap_new(&PyGroupmap
, NULL
, NULL
);
1657 if (py_group_map
== NULL
) {
1663 group_map
= pytalloc_get_ptr(py_group_map
);
1665 status
= methods
->getgrsid(methods
, group_map
, *domain_sid
);
1666 if (!NT_STATUS_IS_OK(status
)) {
1667 PyErr_Format(py_pdb_error
, "Unable to get group information by sid, (%d,%s)",
1668 NT_STATUS_V(status
),
1669 get_friendly_nt_error_msg(status
));
1675 return py_group_map
;
1679 static PyObject
*py_pdb_getgrgid(pytalloc_Object
*self
, PyObject
*args
)
1681 TALLOC_CTX
*frame
= talloc_stackframe();
1683 struct pdb_methods
*methods
;
1684 GROUP_MAP
*group_map
;
1685 PyObject
*py_group_map
;
1686 unsigned int gid_value
;
1688 if (!PyArg_ParseTuple(args
, "I:getgrgid", &gid_value
)) {
1693 methods
= pytalloc_get_ptr(self
);
1695 py_group_map
= py_groupmap_new(&PyGroupmap
, NULL
, NULL
);
1696 if (py_group_map
== NULL
) {
1702 group_map
= pytalloc_get_ptr(py_group_map
);
1704 status
= methods
->getgrgid(methods
, group_map
, gid_value
);
1705 if (!NT_STATUS_IS_OK(status
)) {
1706 PyErr_Format(py_pdb_error
, "Unable to get group information by gid, (%d,%s)",
1707 NT_STATUS_V(status
),
1708 get_friendly_nt_error_msg(status
));
1714 return py_group_map
;
1718 static PyObject
*py_pdb_getgrnam(pytalloc_Object
*self
, PyObject
*args
)
1720 TALLOC_CTX
*frame
= talloc_stackframe();
1722 struct pdb_methods
*methods
;
1723 GROUP_MAP
*group_map
;
1724 PyObject
*py_group_map
;
1725 const char *groupname
;
1727 if (!PyArg_ParseTuple(args
, "s:getgrnam", &groupname
)) {
1732 methods
= pytalloc_get_ptr(self
);
1734 py_group_map
= py_groupmap_new(&PyGroupmap
, NULL
, NULL
);
1735 if (py_group_map
== NULL
) {
1741 group_map
= pytalloc_get_ptr(py_group_map
);
1743 status
= methods
->getgrnam(methods
, group_map
, groupname
);
1744 if (!NT_STATUS_IS_OK(status
)) {
1745 PyErr_Format(py_pdb_error
, "Unable to get group information by name, (%d,%s)",
1746 NT_STATUS_V(status
),
1747 get_friendly_nt_error_msg(status
));
1753 return py_group_map
;
1757 static PyObject
*py_pdb_create_dom_group(pytalloc_Object
*self
, PyObject
*args
)
1759 TALLOC_CTX
*frame
= talloc_stackframe();
1761 struct pdb_methods
*methods
;
1762 const char *groupname
;
1765 if (!PyArg_ParseTuple(args
, "s:create_dom_group", &groupname
)) {
1770 methods
= pytalloc_get_ptr(self
);
1772 status
= methods
->create_dom_group(methods
, frame
, groupname
, &group_rid
);
1773 if (!NT_STATUS_IS_OK(status
)) {
1774 PyErr_Format(py_pdb_error
, "Unable to create domain group (%s), (%d,%s)",
1776 NT_STATUS_V(status
),
1777 get_friendly_nt_error_msg(status
));
1783 return PyInt_FromLong(group_rid
);
1787 static PyObject
*py_pdb_delete_dom_group(pytalloc_Object
*self
, PyObject
*args
)
1789 TALLOC_CTX
*frame
= talloc_stackframe();
1791 struct pdb_methods
*methods
;
1792 unsigned int group_rid
;
1794 if (!PyArg_ParseTuple(args
, "I:delete_dom_group", &group_rid
)) {
1799 methods
= pytalloc_get_ptr(self
);
1801 status
= methods
->delete_dom_group(methods
, frame
, group_rid
);
1802 if (!NT_STATUS_IS_OK(status
)) {
1803 PyErr_Format(py_pdb_error
, "Unable to delete domain group (rid=%d), (%d,%s)",
1805 NT_STATUS_V(status
),
1806 get_friendly_nt_error_msg(status
));
1816 static PyObject
*py_pdb_add_group_mapping_entry(pytalloc_Object
*self
, PyObject
*args
)
1818 TALLOC_CTX
*frame
= talloc_stackframe();
1820 struct pdb_methods
*methods
;
1821 PyObject
*py_group_map
;
1822 GROUP_MAP
*group_map
;
1824 if (!PyArg_ParseTuple(args
, "O!:add_group_mapping_entry", &PyGroupmap
, &py_group_map
)) {
1829 methods
= pytalloc_get_ptr(self
);
1831 group_map
= pytalloc_get_ptr(py_group_map
);
1833 status
= methods
->add_group_mapping_entry(methods
, group_map
);
1834 if (!NT_STATUS_IS_OK(status
)) {
1835 PyErr_Format(py_pdb_error
, "Unable to add group mapping entry, (%d,%s)",
1836 NT_STATUS_V(status
),
1837 get_friendly_nt_error_msg(status
));
1847 static PyObject
*py_pdb_update_group_mapping_entry(pytalloc_Object
*self
, PyObject
*args
)
1849 TALLOC_CTX
*frame
= talloc_stackframe();
1851 struct pdb_methods
*methods
;
1852 PyObject
*py_group_map
;
1853 GROUP_MAP
*group_map
;
1855 if (!PyArg_ParseTuple(args
, "O!:update_group_mapping_entry", &PyGroupmap
, &py_group_map
)) {
1860 methods
= pytalloc_get_ptr(self
);
1862 group_map
= pytalloc_get_ptr(py_group_map
);
1864 status
= methods
->update_group_mapping_entry(methods
, group_map
);
1865 if (!NT_STATUS_IS_OK(status
)) {
1866 PyErr_Format(py_pdb_error
, "Unable to update group mapping entry, (%d,%s)",
1867 NT_STATUS_V(status
),
1868 get_friendly_nt_error_msg(status
));
1878 static PyObject
*py_pdb_delete_group_mapping_entry(pytalloc_Object
*self
, PyObject
*args
)
1880 TALLOC_CTX
*frame
= talloc_stackframe();
1882 struct pdb_methods
*methods
;
1883 PyObject
*py_group_sid
;
1884 struct dom_sid
*group_sid
;
1886 if (!PyArg_ParseTuple(args
, "O!:delete_group_mapping_entry", dom_sid_Type
, &py_group_sid
)) {
1891 methods
= pytalloc_get_ptr(self
);
1893 group_sid
= pytalloc_get_ptr(py_group_sid
);
1895 status
= methods
->delete_group_mapping_entry(methods
, *group_sid
);
1896 if (!NT_STATUS_IS_OK(status
)) {
1897 PyErr_Format(py_pdb_error
, "Unable to delete group mapping entry, (%d,%s)",
1898 NT_STATUS_V(status
),
1899 get_friendly_nt_error_msg(status
));
1909 static PyObject
*py_pdb_enum_group_mapping(pytalloc_Object
*self
, PyObject
*args
)
1911 TALLOC_CTX
*frame
= talloc_stackframe();
1913 struct pdb_methods
*methods
;
1914 enum lsa_SidType sid_name_use
;
1915 int lsa_sidtype_value
= SID_NAME_UNKNOWN
;
1917 PyObject
*py_domain_sid
;
1918 struct dom_sid
*domain_sid
= NULL
;
1919 GROUP_MAP
**gmap
= NULL
;
1920 GROUP_MAP
*group_map
;
1922 PyObject
*py_gmap_list
, *py_group_map
;
1925 py_domain_sid
= Py_None
;
1928 if (!PyArg_ParseTuple(args
, "|O!ii:enum_group_mapping", dom_sid_Type
, &py_domain_sid
,
1929 &lsa_sidtype_value
, &unix_only
)) {
1934 methods
= pytalloc_get_ptr(self
);
1936 sid_name_use
= lsa_sidtype_value
;
1938 if (py_domain_sid
!= Py_None
) {
1939 domain_sid
= pytalloc_get_ptr(py_domain_sid
);
1942 status
= methods
->enum_group_mapping(methods
, domain_sid
, sid_name_use
,
1943 &gmap
, &num_entries
, unix_only
);
1944 if (!NT_STATUS_IS_OK(status
)) {
1945 PyErr_Format(py_pdb_error
, "Unable to enumerate group mappings, (%d,%s)",
1946 NT_STATUS_V(status
),
1947 get_friendly_nt_error_msg(status
));
1952 py_gmap_list
= PyList_New(0);
1953 if (py_gmap_list
== NULL
) {
1959 for(i
=0; i
<num_entries
; i
++) {
1960 py_group_map
= py_groupmap_new(&PyGroupmap
, NULL
, NULL
);
1962 group_map
= pytalloc_get_ptr(py_group_map
);
1963 *group_map
= *gmap
[i
];
1964 talloc_steal(group_map
, gmap
[i
]->nt_name
);
1965 talloc_steal(group_map
, gmap
[i
]->comment
);
1967 PyList_Append(py_gmap_list
, py_group_map
);
1974 return py_gmap_list
;
1978 static PyObject
*py_pdb_enum_group_members(pytalloc_Object
*self
, PyObject
*args
)
1980 TALLOC_CTX
*frame
= talloc_stackframe();
1982 struct pdb_methods
*methods
;
1983 PyObject
*py_group_sid
;
1984 struct dom_sid
*group_sid
;
1985 uint32_t *member_rids
;
1987 PyObject
*py_sid_list
;
1988 struct dom_sid
*domain_sid
, *member_sid
;
1991 if (!PyArg_ParseTuple(args
, "O!:enum_group_members", dom_sid_Type
, &py_group_sid
)) {
1996 methods
= pytalloc_get_ptr(self
);
1998 group_sid
= pytalloc_get_ptr(py_group_sid
);
2000 status
= methods
->enum_group_members(methods
, frame
, group_sid
,
2001 &member_rids
, &num_members
);
2002 if (!NT_STATUS_IS_OK(status
)) {
2003 PyErr_Format(py_pdb_error
, "Unable to enumerate group members, (%d,%s)",
2004 NT_STATUS_V(status
),
2005 get_friendly_nt_error_msg(status
));
2010 py_sid_list
= PyList_New(0);
2011 if (py_sid_list
== NULL
) {
2017 domain_sid
= get_global_sam_sid();
2019 for(i
=0; i
<num_members
; i
++) {
2020 member_sid
= dom_sid_add_rid(frame
, domain_sid
, member_rids
[i
]);
2021 PyList_Append(py_sid_list
, pytalloc_steal(dom_sid_Type
, member_sid
));
2029 static PyObject
*py_pdb_enum_group_memberships(pytalloc_Object
*self
, PyObject
*args
)
2031 TALLOC_CTX
*frame
= talloc_stackframe();
2033 struct pdb_methods
*methods
;
2036 struct samu
*sam_acct
;
2037 PyObject
*py_sam_acct
;
2038 PyObject
*py_sid_list
;
2039 struct dom_sid
*user_group_sids
= NULL
;
2040 gid_t
*user_group_ids
= NULL
;
2041 uint32_t num_groups
= 0;
2043 if (!PyArg_ParseTuple(args
, "O!:enum_group_memberships", &PySamu
, &py_sam_acct
)) {
2048 methods
= pytalloc_get_ptr(self
);
2050 sam_acct
= pytalloc_get_ptr(py_sam_acct
);
2052 status
= methods
->enum_group_memberships(methods
, frame
, sam_acct
,
2053 &user_group_sids
, &user_group_ids
, &num_groups
);
2054 if (!NT_STATUS_IS_OK(status
)) {
2055 PyErr_Format(py_pdb_error
, "Unable to enumerate group memberships, (%d,%s)",
2056 NT_STATUS_V(status
),
2057 get_friendly_nt_error_msg(status
));
2062 py_sid_list
= PyList_New(0);
2063 if (py_sid_list
== NULL
) {
2069 for(i
=0; i
<num_groups
; i
++) {
2070 PyList_Append(py_sid_list
, pytalloc_steal(dom_sid_Type
, dom_sid_dup(NULL
, &user_group_sids
[i
])));
2078 static PyObject
*py_pdb_add_groupmem(pytalloc_Object
*self
, PyObject
*args
)
2080 TALLOC_CTX
*frame
= talloc_stackframe();
2082 struct pdb_methods
*methods
;
2083 uint32_t group_rid
, member_rid
;
2085 if (!PyArg_ParseTuple(args
, "II:add_groupmem", &group_rid
, &member_rid
)) {
2090 methods
= pytalloc_get_ptr(self
);
2092 status
= methods
->add_groupmem(methods
, frame
, group_rid
, member_rid
);
2093 if (!NT_STATUS_IS_OK(status
)) {
2094 PyErr_Format(py_pdb_error
, "Unable to add group member, (%d,%s)",
2095 NT_STATUS_V(status
),
2096 get_friendly_nt_error_msg(status
));
2106 static PyObject
*py_pdb_del_groupmem(pytalloc_Object
*self
, PyObject
*args
)
2108 TALLOC_CTX
*frame
= talloc_stackframe();
2110 struct pdb_methods
*methods
;
2111 uint32_t group_rid
, member_rid
;
2113 if (!PyArg_ParseTuple(args
, "II:del_groupmem", &group_rid
, &member_rid
)) {
2118 methods
= pytalloc_get_ptr(self
);
2120 status
= methods
->del_groupmem(methods
, frame
, group_rid
, member_rid
);
2121 if (!NT_STATUS_IS_OK(status
)) {
2122 PyErr_Format(py_pdb_error
, "Unable to rename sam account, (%d,%s)",
2123 NT_STATUS_V(status
),
2124 get_friendly_nt_error_msg(status
));
2134 static PyObject
*py_pdb_create_alias(pytalloc_Object
*self
, PyObject
*args
)
2136 TALLOC_CTX
*frame
= talloc_stackframe();
2138 struct pdb_methods
*methods
;
2139 const char *alias_name
;
2142 if (!PyArg_ParseTuple(args
, "s:create_alias", &alias_name
)) {
2147 methods
= pytalloc_get_ptr(self
);
2149 status
= methods
->create_alias(methods
, alias_name
, &rid
);
2150 if (!NT_STATUS_IS_OK(status
)) {
2151 PyErr_Format(py_pdb_error
, "Unable to create alias (%s), (%d,%s)",
2153 NT_STATUS_V(status
),
2154 get_friendly_nt_error_msg(status
));
2160 return PyInt_FromLong(rid
);
2164 static PyObject
*py_pdb_delete_alias(pytalloc_Object
*self
, PyObject
*args
)
2166 TALLOC_CTX
*frame
= talloc_stackframe();
2168 struct pdb_methods
*methods
;
2169 PyObject
*py_alias_sid
;
2170 struct dom_sid
*alias_sid
;
2172 if (!PyArg_ParseTuple(args
, "O!:delete_alias", dom_sid_Type
, &py_alias_sid
)) {
2177 methods
= pytalloc_get_ptr(self
);
2179 alias_sid
= pytalloc_get_ptr(py_alias_sid
);
2181 status
= methods
->delete_alias(methods
, alias_sid
);
2182 if (!NT_STATUS_IS_OK(status
)) {
2183 PyErr_Format(py_pdb_error
, "Unable to delete alias, (%d,%s)",
2184 NT_STATUS_V(status
),
2185 get_friendly_nt_error_msg(status
));
2195 static PyObject
*py_pdb_get_aliasinfo(pytalloc_Object
*self
, PyObject
*args
)
2197 TALLOC_CTX
*frame
= talloc_stackframe();
2199 struct pdb_methods
*methods
;
2200 PyObject
*py_alias_sid
;
2201 struct dom_sid
*alias_sid
;
2202 struct acct_info
*alias_info
;
2203 PyObject
*py_alias_info
;
2205 if (!PyArg_ParseTuple(args
, "O!:get_aliasinfo", dom_sid_Type
, &py_alias_sid
)) {
2210 methods
= pytalloc_get_ptr(self
);
2212 alias_sid
= pytalloc_get_ptr(py_alias_sid
);
2214 alias_info
= talloc_zero(frame
, struct acct_info
);
2221 status
= methods
->get_aliasinfo(methods
, alias_sid
, alias_info
);
2222 if (!NT_STATUS_IS_OK(status
)) {
2223 PyErr_Format(py_pdb_error
, "Unable to get alias information, (%d,%s)",
2224 NT_STATUS_V(status
),
2225 get_friendly_nt_error_msg(status
));
2230 py_alias_info
= PyDict_New();
2231 if (py_alias_info
== NULL
) {
2237 PyDict_SetItemString(py_alias_info
, "acct_name",
2238 PyString_FromString(alias_info
->acct_name
));
2239 PyDict_SetItemString(py_alias_info
, "acct_desc",
2240 PyString_FromString(alias_info
->acct_desc
));
2241 PyDict_SetItemString(py_alias_info
, "rid",
2242 PyInt_FromLong(alias_info
->rid
));
2245 return py_alias_info
;
2249 static PyObject
*py_pdb_set_aliasinfo(pytalloc_Object
*self
, PyObject
*args
)
2251 TALLOC_CTX
*frame
= talloc_stackframe();
2253 struct pdb_methods
*methods
;
2254 PyObject
*py_alias_sid
, *py_alias_info
;
2255 struct dom_sid
*alias_sid
;
2256 struct acct_info alias_info
;
2258 if (!PyArg_ParseTuple(args
, "O!O:set_alias_info", dom_sid_Type
, &py_alias_sid
,
2264 methods
= pytalloc_get_ptr(self
);
2266 alias_sid
= pytalloc_get_ptr(py_alias_sid
);
2268 alias_info
.acct_name
= talloc_strdup(frame
, PyString_AsString(PyDict_GetItemString(py_alias_info
, "acct_name")));
2269 if (alias_info
.acct_name
== NULL
) {
2270 PyErr_Format(py_pdb_error
, "Unable to allocate memory");
2274 alias_info
.acct_desc
= talloc_strdup(frame
, PyString_AsString(PyDict_GetItemString(py_alias_info
, "acct_desc")));
2275 if (alias_info
.acct_desc
== NULL
) {
2276 PyErr_Format(py_pdb_error
, "Unable to allocate memory");
2281 status
= methods
->set_aliasinfo(methods
, alias_sid
, &alias_info
);
2282 if (!NT_STATUS_IS_OK(status
)) {
2283 PyErr_Format(py_pdb_error
, "Unable to set alias information, (%d,%s)",
2284 NT_STATUS_V(status
),
2285 get_friendly_nt_error_msg(status
));
2295 static PyObject
*py_pdb_add_aliasmem(pytalloc_Object
*self
, PyObject
*args
)
2297 TALLOC_CTX
*frame
= talloc_stackframe();
2299 struct pdb_methods
*methods
;
2300 PyObject
*py_alias_sid
, *py_member_sid
;
2301 struct dom_sid
*alias_sid
, *member_sid
;
2303 if (!PyArg_ParseTuple(args
, "O!O!:add_aliasmem", dom_sid_Type
, &py_alias_sid
,
2304 dom_sid_Type
, &py_member_sid
)) {
2309 methods
= pytalloc_get_ptr(self
);
2311 alias_sid
= pytalloc_get_ptr(py_alias_sid
);
2312 member_sid
= pytalloc_get_ptr(py_member_sid
);
2314 status
= methods
->add_aliasmem(methods
, alias_sid
, member_sid
);
2315 if (!NT_STATUS_IS_OK(status
)) {
2316 PyErr_Format(py_pdb_error
, "Unable to add member to alias, (%d,%s)",
2317 NT_STATUS_V(status
),
2318 get_friendly_nt_error_msg(status
));
2328 static PyObject
*py_pdb_del_aliasmem(pytalloc_Object
*self
, PyObject
*args
)
2330 TALLOC_CTX
*frame
= talloc_stackframe();
2332 struct pdb_methods
*methods
;
2333 PyObject
*py_alias_sid
, *py_member_sid
;
2334 const struct dom_sid
*alias_sid
, *member_sid
;
2336 if (!PyArg_ParseTuple(args
, "O!O!:del_aliasmem", dom_sid_Type
, &py_alias_sid
,
2337 dom_sid_Type
, &py_member_sid
)) {
2342 methods
= pytalloc_get_ptr(self
);
2344 alias_sid
= pytalloc_get_ptr(py_alias_sid
);
2345 member_sid
= pytalloc_get_ptr(py_member_sid
);
2347 status
= methods
->del_aliasmem(methods
, alias_sid
, member_sid
);
2348 if (!NT_STATUS_IS_OK(status
)) {
2349 PyErr_Format(py_pdb_error
, "Unable to delete member from alias, (%d,%s)",
2350 NT_STATUS_V(status
),
2351 get_friendly_nt_error_msg(status
));
2361 static PyObject
*py_pdb_enum_aliasmem(pytalloc_Object
*self
, PyObject
*args
)
2363 TALLOC_CTX
*frame
= talloc_stackframe();
2365 struct pdb_methods
*methods
;
2366 PyObject
*py_alias_sid
;
2367 struct dom_sid
*alias_sid
, *member_sid
, *tmp_sid
;
2368 PyObject
*py_member_list
, *py_member_sid
;
2372 if (!PyArg_ParseTuple(args
, "O!:enum_aliasmem", dom_sid_Type
, &py_alias_sid
)) {
2377 methods
= pytalloc_get_ptr(self
);
2379 alias_sid
= pytalloc_get_ptr(py_alias_sid
);
2381 status
= methods
->enum_aliasmem(methods
, alias_sid
, frame
, &member_sid
, &num_members
);
2382 if (!NT_STATUS_IS_OK(status
)) {
2383 PyErr_Format(py_pdb_error
, "Unable to enumerate members for alias, (%d,%s)",
2384 NT_STATUS_V(status
),
2385 get_friendly_nt_error_msg(status
));
2390 py_member_list
= PyList_New(0);
2391 if (py_member_list
== NULL
) {
2397 for(i
=0; i
<num_members
; i
++) {
2398 py_member_sid
= pytalloc_new(struct dom_sid
, dom_sid_Type
);
2399 if (py_member_sid
== NULL
) {
2404 tmp_sid
= pytalloc_get_ptr(py_member_sid
);
2405 *tmp_sid
= member_sid
[i
];
2406 PyList_Append(py_member_list
, py_member_sid
);
2410 return py_member_list
;
2414 static PyObject
*py_pdb_get_account_policy(pytalloc_Object
*self
)
2416 TALLOC_CTX
*frame
= talloc_stackframe();
2418 struct pdb_methods
*methods
;
2419 PyObject
*py_acct_policy
;
2423 enum pdb_policy_type type
;
2425 methods
= pytalloc_get_ptr(self
);
2427 py_acct_policy
= PyDict_New();
2428 if (py_acct_policy
== NULL
) {
2434 account_policy_names_list(frame
, &names
, &count
);
2435 for (i
=0; i
<count
; i
++) {
2436 type
= account_policy_name_to_typenum(names
[i
]);
2437 status
= methods
->get_account_policy(methods
, type
, &value
);
2438 if (NT_STATUS_IS_OK(status
)) {
2439 PyDict_SetItemString(py_acct_policy
, names
[i
], Py_BuildValue("i", value
));
2444 return py_acct_policy
;
2448 static PyObject
*py_pdb_set_account_policy(pytalloc_Object
*self
, PyObject
*args
)
2450 TALLOC_CTX
*frame
= talloc_stackframe();
2452 struct pdb_methods
*methods
;
2453 PyObject
*py_acct_policy
, *py_value
;
2456 enum pdb_policy_type type
;
2458 if (!PyArg_ParseTuple(args
, "O!:set_account_policy", PyDict_Type
, &py_acct_policy
)) {
2463 methods
= pytalloc_get_ptr(self
);
2465 account_policy_names_list(frame
, &names
, &count
);
2466 for (i
=0; i
<count
; i
++) {
2467 if ((py_value
= PyDict_GetItemString(py_acct_policy
, names
[i
])) != NULL
) {
2468 type
= account_policy_name_to_typenum(names
[i
]);
2469 status
= methods
->set_account_policy(methods
, type
, PyInt_AsLong(py_value
));
2470 if (!NT_STATUS_IS_OK(status
)) {
2471 PyErr_Format(py_pdb_error
, "Error setting account policy (%s), (%d,%s)",
2473 NT_STATUS_V(status
),
2474 get_friendly_nt_error_msg(status
));
2483 static PyObject
*py_pdb_search_users(pytalloc_Object
*self
, PyObject
*args
)
2485 TALLOC_CTX
*frame
= talloc_stackframe();
2486 struct pdb_methods
*methods
;
2487 unsigned int acct_flags
;
2488 struct pdb_search
*search
;
2489 struct samr_displayentry
*entry
;
2490 PyObject
*py_userlist
, *py_dict
;
2492 if (!PyArg_ParseTuple(args
, "I:search_users", &acct_flags
)) {
2497 methods
= pytalloc_get_ptr(self
);
2499 search
= talloc_zero(frame
, struct pdb_search
);
2500 if (search
== NULL
) {
2506 if (!methods
->search_users(methods
, search
, acct_flags
)) {
2507 PyErr_Format(py_pdb_error
, "Unable to search users");
2512 entry
= talloc_zero(frame
, struct samr_displayentry
);
2513 if (entry
== NULL
) {
2519 py_userlist
= PyList_New(0);
2520 if (py_userlist
== NULL
) {
2526 while (search
->next_entry(search
, entry
)) {
2527 py_dict
= PyDict_New();
2528 if (py_dict
== NULL
) {
2531 PyDict_SetItemString(py_dict
, "idx", PyInt_FromLong(entry
->idx
));
2532 PyDict_SetItemString(py_dict
, "rid", PyInt_FromLong(entry
->rid
));
2533 PyDict_SetItemString(py_dict
, "acct_flags", PyInt_FromLong(entry
->acct_flags
));
2534 PyDict_SetItemString(py_dict
, "account_name", PyString_FromString(entry
->account_name
));
2535 PyDict_SetItemString(py_dict
, "fullname", PyString_FromString(entry
->fullname
));
2536 PyDict_SetItemString(py_dict
, "description", PyString_FromString(entry
->description
));
2537 PyList_Append(py_userlist
, py_dict
);
2540 search
->search_end(search
);
2547 static PyObject
*py_pdb_search_groups(pytalloc_Object
*self
)
2549 TALLOC_CTX
*frame
= talloc_stackframe();
2550 struct pdb_methods
*methods
;
2551 struct pdb_search
*search
;
2552 struct samr_displayentry
*entry
;
2553 PyObject
*py_grouplist
, *py_dict
;
2555 methods
= pytalloc_get_ptr(self
);
2557 search
= talloc_zero(frame
, struct pdb_search
);
2558 if (search
== NULL
) {
2564 if (!methods
->search_groups(methods
, search
)) {
2565 PyErr_Format(py_pdb_error
, "Unable to search groups");
2570 entry
= talloc_zero(frame
, struct samr_displayentry
);
2571 if (entry
== NULL
) {
2577 py_grouplist
= PyList_New(0);
2578 if (py_grouplist
== NULL
) {
2584 while (search
->next_entry(search
, entry
)) {
2585 py_dict
= PyDict_New();
2586 if (py_dict
== NULL
) {
2589 PyDict_SetItemString(py_dict
, "idx", PyInt_FromLong(entry
->idx
));
2590 PyDict_SetItemString(py_dict
, "rid", PyInt_FromLong(entry
->rid
));
2591 PyDict_SetItemString(py_dict
, "acct_flags", PyInt_FromLong(entry
->acct_flags
));
2592 PyDict_SetItemString(py_dict
, "account_name", PyString_FromString(entry
->account_name
));
2593 PyDict_SetItemString(py_dict
, "fullname", PyString_FromString(entry
->fullname
));
2594 PyDict_SetItemString(py_dict
, "description", PyString_FromString(entry
->description
));
2595 PyList_Append(py_grouplist
, py_dict
);
2598 search
->search_end(search
);
2601 return py_grouplist
;
2605 static PyObject
*py_pdb_search_aliases(pytalloc_Object
*self
, PyObject
*args
)
2607 TALLOC_CTX
*frame
= talloc_stackframe();
2608 struct pdb_methods
*methods
;
2609 struct pdb_search
*search
;
2610 struct samr_displayentry
*entry
;
2611 PyObject
*py_aliaslist
, *py_dict
;
2612 PyObject
*py_domain_sid
;
2613 struct dom_sid
*domain_sid
= NULL
;
2615 py_domain_sid
= Py_None
;
2618 if (!PyArg_ParseTuple(args
, "|O!:search_aliases", dom_sid_Type
, &py_domain_sid
)) {
2623 methods
= pytalloc_get_ptr(self
);
2625 if (py_domain_sid
!= Py_None
) {
2626 domain_sid
= pytalloc_get_ptr(py_domain_sid
);
2629 search
= talloc_zero(frame
, struct pdb_search
);
2630 if (search
== NULL
) {
2636 if (!methods
->search_aliases(methods
, search
, domain_sid
)) {
2637 PyErr_Format(py_pdb_error
, "Unable to search aliases");
2642 entry
= talloc_zero(frame
, struct samr_displayentry
);
2643 if (entry
== NULL
) {
2649 py_aliaslist
= PyList_New(0);
2650 if (py_aliaslist
== NULL
) {
2656 while (search
->next_entry(search
, entry
)) {
2657 py_dict
= PyDict_New();
2658 if (py_dict
== NULL
) {
2661 PyDict_SetItemString(py_dict
, "idx", PyInt_FromLong(entry
->idx
));
2662 PyDict_SetItemString(py_dict
, "rid", PyInt_FromLong(entry
->rid
));
2663 PyDict_SetItemString(py_dict
, "acct_flags", PyInt_FromLong(entry
->acct_flags
));
2664 PyDict_SetItemString(py_dict
, "account_name", PyString_FromString(entry
->account_name
));
2665 PyDict_SetItemString(py_dict
, "fullname", PyString_FromString(entry
->fullname
));
2666 PyDict_SetItemString(py_dict
, "description", PyString_FromString(entry
->description
));
2667 PyList_Append(py_aliaslist
, py_dict
);
2670 search
->search_end(search
);
2673 return py_aliaslist
;
2677 static PyObject
*py_pdb_uid_to_sid(pytalloc_Object
*self
, PyObject
*args
)
2679 TALLOC_CTX
*frame
= talloc_stackframe();
2680 struct pdb_methods
*methods
;
2682 struct dom_sid user_sid
, *copy_user_sid
;
2683 PyObject
*py_user_sid
;
2685 if (!PyArg_ParseTuple(args
, "I:uid_to_sid", &uid
)) {
2690 methods
= pytalloc_get_ptr(self
);
2692 if (!methods
->uid_to_sid(methods
, uid
, &user_sid
)) {
2693 PyErr_Format(py_pdb_error
, "Unable to get sid for uid=%d", uid
);
2698 copy_user_sid
= dom_sid_dup(frame
, &user_sid
);
2699 if (copy_user_sid
== NULL
) {
2705 py_user_sid
= pytalloc_steal(dom_sid_Type
, copy_user_sid
);
2712 static PyObject
*py_pdb_gid_to_sid(pytalloc_Object
*self
, PyObject
*args
)
2714 TALLOC_CTX
*frame
= talloc_stackframe();
2715 struct pdb_methods
*methods
;
2717 struct dom_sid group_sid
, *copy_group_sid
;
2718 PyObject
*py_group_sid
;
2720 if (!PyArg_ParseTuple(args
, "I:gid_to_sid", &gid
)) {
2725 methods
= pytalloc_get_ptr(self
);
2727 if (!methods
->gid_to_sid(methods
, gid
, &group_sid
)) {
2728 PyErr_Format(py_pdb_error
, "Unable to get sid for gid=%d", gid
);
2733 copy_group_sid
= dom_sid_dup(frame
, &group_sid
);
2734 if (copy_group_sid
== NULL
) {
2740 py_group_sid
= pytalloc_steal(dom_sid_Type
, copy_group_sid
);
2743 return py_group_sid
;
2747 static PyObject
*py_pdb_sid_to_id(pytalloc_Object
*self
, PyObject
*args
)
2749 TALLOC_CTX
*frame
= talloc_stackframe();
2750 struct pdb_methods
*methods
;
2752 struct dom_sid
*sid
;
2755 if (!PyArg_ParseTuple(args
, "O!:sid_to_id", dom_sid_Type
, &py_sid
)) {
2760 methods
= pytalloc_get_ptr(self
);
2762 sid
= pytalloc_get_ptr(py_sid
);
2764 if (!methods
->sid_to_id(methods
, sid
, &id
)) {
2765 PyErr_Format(py_pdb_error
, "Unable to get id for sid");
2771 return Py_BuildValue("(II)", id
.id
, id
.type
);
2775 static PyObject
*py_pdb_new_rid(pytalloc_Object
*self
)
2777 TALLOC_CTX
*frame
= talloc_stackframe();
2778 struct pdb_methods
*methods
;
2781 methods
= pytalloc_get_ptr(self
);
2783 if (!methods
->new_rid(methods
, &rid
)) {
2784 PyErr_Format(py_pdb_error
, "Unable to get new rid");
2790 return PyInt_FromLong(rid
);
2794 static PyObject
*py_pdb_get_trusteddom_pw(pytalloc_Object
*self
, PyObject
*args
)
2796 TALLOC_CTX
*frame
= talloc_stackframe();
2797 struct pdb_methods
*methods
;
2800 struct dom_sid sid
, *copy_sid
;
2802 time_t last_set_time
;
2805 if (!PyArg_ParseTuple(args
, "s:get_trusteddom_pw", &domain
)) {
2810 methods
= pytalloc_get_ptr(self
);
2812 if (!methods
->get_trusteddom_pw(methods
, domain
, &pwd
, &sid
, &last_set_time
)) {
2813 PyErr_Format(py_pdb_error
, "Unable to get trusted domain password");
2818 copy_sid
= dom_sid_dup(frame
, &sid
);
2819 if (copy_sid
== NULL
) {
2825 py_sid
= pytalloc_steal(dom_sid_Type
, copy_sid
);
2826 if (py_sid
== NULL
) {
2832 py_value
= PyDict_New();
2833 if (py_value
== NULL
) {
2839 PyDict_SetItemString(py_value
, "pwd", PyString_FromString(pwd
));
2840 PyDict_SetItemString(py_value
, "sid", py_sid
);
2841 PyDict_SetItemString(py_value
, "last_set_tim", PyInt_FromLong(last_set_time
));
2848 static PyObject
*py_pdb_set_trusteddom_pw(pytalloc_Object
*self
, PyObject
*args
)
2850 TALLOC_CTX
*frame
= talloc_stackframe();
2851 struct pdb_methods
*methods
;
2854 const struct dom_sid
*domain_sid
;
2855 PyObject
*py_domain_sid
;
2857 if (!PyArg_ParseTuple(args
, "ssO!:set_trusteddom_pw", &domain
, &pwd
,
2858 dom_sid_Type
, &py_domain_sid
)) {
2863 methods
= pytalloc_get_ptr(self
);
2865 domain_sid
= pytalloc_get_ptr(py_domain_sid
);
2867 if (!methods
->set_trusteddom_pw(methods
, domain
, pwd
, domain_sid
)) {
2868 PyErr_Format(py_pdb_error
, "Unable to set trusted domain password");
2878 static PyObject
*py_pdb_del_trusteddom_pw(pytalloc_Object
*self
, PyObject
*args
)
2880 TALLOC_CTX
*frame
= talloc_stackframe();
2881 struct pdb_methods
*methods
;
2884 if (!PyArg_ParseTuple(args
, "s:del_trusteddom_pw", &domain
)) {
2889 methods
= pytalloc_get_ptr(self
);
2891 if (!methods
->del_trusteddom_pw(methods
, domain
)) {
2892 PyErr_Format(py_pdb_error
, "Unable to delete trusted domain password");
2902 static PyObject
*py_pdb_enum_trusteddoms(pytalloc_Object
*self
)
2904 TALLOC_CTX
*frame
= talloc_stackframe();
2906 struct pdb_methods
*methods
;
2907 uint32_t num_domains
;
2908 struct trustdom_info
**domains
;
2909 PyObject
*py_domain_list
, *py_dict
;
2912 methods
= pytalloc_get_ptr(self
);
2914 status
= methods
->enum_trusteddoms(methods
, frame
, &num_domains
, &domains
);
2915 if (!NT_STATUS_IS_OK(status
)) {
2916 PyErr_Format(py_pdb_error
, "Unable to enumerate trusted domains, (%d,%s)",
2917 NT_STATUS_V(status
),
2918 get_friendly_nt_error_msg(status
));
2923 py_domain_list
= PyList_New(0);
2924 if (py_domain_list
== NULL
) {
2930 for(i
=0; i
<num_domains
; i
++) {
2931 py_dict
= PyDict_New();
2933 PyDict_SetItemString(py_dict
, "name",
2934 PyString_FromString(domains
[i
]->name
));
2935 PyDict_SetItemString(py_dict
, "sid",
2936 pytalloc_steal(dom_sid_Type
, &domains
[i
]->sid
));
2939 PyList_Append(py_domain_list
, py_dict
);
2943 return py_domain_list
;
2947 static PyObject
*py_pdb_get_trusted_domain(pytalloc_Object
*self
, PyObject
*args
)
2949 TALLOC_CTX
*frame
= talloc_stackframe();
2951 struct pdb_methods
*methods
;
2953 struct pdb_trusted_domain
*td
;
2954 PyObject
*py_domain_info
;
2956 if (!PyArg_ParseTuple(args
, "s:get_trusted_domain", &domain
)) {
2961 methods
= pytalloc_get_ptr(self
);
2963 status
= methods
->get_trusted_domain(methods
, frame
, domain
, &td
);
2964 if (!NT_STATUS_IS_OK(status
)) {
2965 PyErr_Format(py_pdb_error
, "Unable to get trusted domain information, (%d,%s)",
2966 NT_STATUS_V(status
),
2967 get_friendly_nt_error_msg(status
));
2972 py_domain_info
= PyDict_New();
2973 if (py_domain_info
== NULL
) {
2979 PyDict_SetItemString(py_domain_info
, "domain_name",
2980 PyString_FromString(td
->domain_name
));
2981 PyDict_SetItemString(py_domain_info
, "netbios_name",
2982 PyString_FromString(td
->netbios_name
));
2983 PyDict_SetItemString(py_domain_info
, "security_identifier",
2984 pytalloc_steal(dom_sid_Type
, &td
->security_identifier
));
2985 PyDict_SetItemString(py_domain_info
, "trust_auth_incoming",
2986 PyString_FromStringAndSize((char *)td
->trust_auth_incoming
.data
,
2987 td
->trust_auth_incoming
.length
));
2988 PyDict_SetItemString(py_domain_info
, "trust_auth_outgoing",
2989 PyString_FromStringAndSize((char *)td
->trust_auth_outgoing
.data
,
2990 td
->trust_auth_outgoing
.length
));
2991 PyDict_SetItemString(py_domain_info
, "trust_direction",
2992 PyInt_FromLong(td
->trust_direction
));
2993 PyDict_SetItemString(py_domain_info
, "trust_type",
2994 PyInt_FromLong(td
->trust_type
));
2995 PyDict_SetItemString(py_domain_info
, "trust_attributes",
2996 PyInt_FromLong(td
->trust_attributes
));
2997 PyDict_SetItemString(py_domain_info
, "trust_forest_trust_info",
2998 PyString_FromStringAndSize((char *)td
->trust_forest_trust_info
.data
,
2999 td
->trust_forest_trust_info
.length
));
3002 return py_domain_info
;
3006 static PyObject
*py_pdb_get_trusted_domain_by_sid(pytalloc_Object
*self
, PyObject
*args
)
3008 TALLOC_CTX
*frame
= talloc_stackframe();
3010 struct pdb_methods
*methods
;
3011 PyObject
*py_domain_sid
;
3012 struct dom_sid
*domain_sid
;
3013 struct pdb_trusted_domain
*td
;
3014 PyObject
*py_domain_info
;
3016 if (!PyArg_ParseTuple(args
, "O!:get_trusted_domain_by_sid", dom_sid_Type
, &py_domain_sid
)) {
3021 methods
= pytalloc_get_ptr(self
);
3023 domain_sid
= pytalloc_get_ptr(py_domain_sid
);
3025 status
= methods
->get_trusted_domain_by_sid(methods
, frame
, domain_sid
, &td
);
3026 if (!NT_STATUS_IS_OK(status
)) {
3027 PyErr_Format(py_pdb_error
, "Unable to get trusted domain information, (%d,%s)",
3028 NT_STATUS_V(status
),
3029 get_friendly_nt_error_msg(status
));
3034 py_domain_info
= PyDict_New();
3035 if (py_domain_info
== NULL
) {
3041 PyDict_SetItemString(py_domain_info
, "domain_name",
3042 PyString_FromString(td
->domain_name
));
3043 PyDict_SetItemString(py_domain_info
, "netbios_name",
3044 PyString_FromString(td
->netbios_name
));
3045 PyDict_SetItemString(py_domain_info
, "security_identifier",
3046 pytalloc_steal(dom_sid_Type
, &td
->security_identifier
));
3047 PyDict_SetItemString(py_domain_info
, "trust_auth_incoming",
3048 PyString_FromStringAndSize((char *)td
->trust_auth_incoming
.data
,
3049 td
->trust_auth_incoming
.length
));
3050 PyDict_SetItemString(py_domain_info
, "trust_auth_outgoing",
3051 PyString_FromStringAndSize((char *)td
->trust_auth_outgoing
.data
,
3052 td
->trust_auth_outgoing
.length
));
3053 PyDict_SetItemString(py_domain_info
, "trust_direction",
3054 PyInt_FromLong(td
->trust_direction
));
3055 PyDict_SetItemString(py_domain_info
, "trust_type",
3056 PyInt_FromLong(td
->trust_type
));
3057 PyDict_SetItemString(py_domain_info
, "trust_attributes",
3058 PyInt_FromLong(td
->trust_attributes
));
3059 PyDict_SetItemString(py_domain_info
, "trust_forest_trust_info",
3060 PyString_FromStringAndSize((char *)td
->trust_forest_trust_info
.data
,
3061 td
->trust_forest_trust_info
.length
));
3064 return py_domain_info
;
3068 static PyObject
*py_pdb_set_trusted_domain(pytalloc_Object
*self
, PyObject
*args
)
3070 TALLOC_CTX
*frame
= talloc_stackframe();
3072 struct pdb_methods
*methods
;
3074 PyObject
*py_td_info
;
3075 struct pdb_trusted_domain td_info
;
3079 if (!PyArg_ParseTuple(args
, "sO!:set_trusted_domain", &domain
, &PyDict_Type
, &py_td_info
)) {
3084 py_tmp
= PyDict_GetItemString(py_td_info
, "domain_name");
3085 td_info
.domain_name
= PyString_AsString(py_tmp
);
3087 py_tmp
= PyDict_GetItemString(py_td_info
, "netbios_name");
3088 td_info
.netbios_name
= PyString_AsString(py_tmp
);
3090 py_tmp
= PyDict_GetItemString(py_td_info
, "security_identifier");
3091 td_info
.security_identifier
= *pytalloc_get_type(py_tmp
, struct dom_sid
);
3093 py_tmp
= PyDict_GetItemString(py_td_info
, "trust_auth_incoming");
3094 PyString_AsStringAndSize(py_tmp
, (char **)&td_info
.trust_auth_incoming
.data
, &len
);
3095 td_info
.trust_auth_incoming
.length
= len
;
3097 py_tmp
= PyDict_GetItemString(py_td_info
, "trust_auth_outgoing");
3098 PyString_AsStringAndSize(py_tmp
, (char **)&td_info
.trust_auth_outgoing
.data
, &len
);
3099 td_info
.trust_auth_outgoing
.length
= len
;
3101 py_tmp
= PyDict_GetItemString(py_td_info
, "trust_direction");
3102 td_info
.trust_direction
= PyInt_AsLong(py_tmp
);
3104 py_tmp
= PyDict_GetItemString(py_td_info
, "trust_type");
3105 td_info
.trust_type
= PyInt_AsLong(py_tmp
);
3107 py_tmp
= PyDict_GetItemString(py_td_info
, "trust_attributes");
3108 td_info
.trust_attributes
= PyInt_AsLong(py_tmp
);
3110 py_tmp
= PyDict_GetItemString(py_td_info
, "trust_forest_trust_info");
3111 PyString_AsStringAndSize(py_tmp
, (char **)&td_info
.trust_forest_trust_info
.data
, &len
);
3112 td_info
.trust_forest_trust_info
.length
= len
;
3114 methods
= pytalloc_get_ptr(self
);
3116 status
= methods
->set_trusted_domain(methods
, domain
, &td_info
);
3117 if (!NT_STATUS_IS_OK(status
)) {
3118 PyErr_Format(py_pdb_error
, "Unable to set trusted domain information, (%d,%s)",
3119 NT_STATUS_V(status
),
3120 get_friendly_nt_error_msg(status
));
3130 static PyObject
*py_pdb_del_trusted_domain(pytalloc_Object
*self
, PyObject
*args
)
3132 TALLOC_CTX
*frame
= talloc_stackframe();
3134 struct pdb_methods
*methods
;
3137 if (!PyArg_ParseTuple(args
, "s:del_trusted_domain", &domain
)) {
3142 methods
= pytalloc_get_ptr(self
);
3144 status
= methods
->del_trusted_domain(methods
, domain
);
3145 if (!NT_STATUS_IS_OK(status
)) {
3146 PyErr_Format(py_pdb_error
, "Unable to delete trusted domain, (%d,%s)",
3147 NT_STATUS_V(status
),
3148 get_friendly_nt_error_msg(status
));
3158 static PyObject
*py_pdb_enum_trusted_domains(pytalloc_Object
*self
)
3160 TALLOC_CTX
*frame
= talloc_stackframe();
3162 struct pdb_methods
*methods
;
3163 uint32_t num_domains
;
3164 struct pdb_trusted_domain
**td_info
, *td
;
3165 PyObject
*py_td_info
, *py_domain_info
;
3168 methods
= pytalloc_get_ptr(self
);
3170 status
= methods
->enum_trusted_domains(methods
, frame
, &num_domains
, &td_info
);
3171 if (!NT_STATUS_IS_OK(status
)) {
3172 PyErr_Format(py_pdb_error
, "Unable to delete trusted domain, (%d,%s)",
3173 NT_STATUS_V(status
),
3174 get_friendly_nt_error_msg(status
));
3179 py_td_info
= PyList_New(0);
3180 if (py_td_info
== NULL
) {
3186 for (i
=0; i
<num_domains
; i
++) {
3188 py_domain_info
= PyDict_New();
3189 if (py_domain_info
== NULL
) {
3191 Py_DECREF(py_td_info
);
3198 PyDict_SetItemString(py_domain_info
, "domain_name",
3199 PyString_FromString(td
->domain_name
));
3200 PyDict_SetItemString(py_domain_info
, "netbios_name",
3201 PyString_FromString(td
->netbios_name
));
3202 PyDict_SetItemString(py_domain_info
, "security_identifier",
3203 pytalloc_steal(dom_sid_Type
, &td
->security_identifier
));
3204 PyDict_SetItemString(py_domain_info
, "trust_auth_incoming",
3205 PyString_FromStringAndSize((char *)td
->trust_auth_incoming
.data
,
3206 td
->trust_auth_incoming
.length
));
3207 PyDict_SetItemString(py_domain_info
, "trust_auth_outgoing",
3208 PyString_FromStringAndSize((char *)td
->trust_auth_outgoing
.data
,
3209 td
->trust_auth_outgoing
.length
));
3210 PyDict_SetItemString(py_domain_info
, "trust_direction",
3211 PyInt_FromLong(td
->trust_direction
));
3212 PyDict_SetItemString(py_domain_info
, "trust_type",
3213 PyInt_FromLong(td
->trust_type
));
3214 PyDict_SetItemString(py_domain_info
, "trust_attributes",
3215 PyInt_FromLong(td
->trust_attributes
));
3216 PyDict_SetItemString(py_domain_info
, "trust_forest_trust_info",
3217 PyString_FromStringAndSize((char *)td
->trust_forest_trust_info
.data
,
3218 td
->trust_forest_trust_info
.length
));
3219 PyList_Append(py_td_info
, py_domain_info
);
3227 static PyObject
*py_pdb_get_secret(pytalloc_Object
*self
, PyObject
*args
)
3229 TALLOC_CTX
*frame
= talloc_stackframe();
3231 struct pdb_methods
*methods
;
3232 const char *secret_name
;
3233 DATA_BLOB secret_current
, secret_old
;
3234 NTTIME secret_current_lastchange
, secret_old_lastchange
;
3236 struct security_descriptor
*sd
;
3237 PyObject
*py_secret
;
3239 if (!PyArg_ParseTuple(args
, "s:get_secret_name", &secret_name
)) {
3244 methods
= pytalloc_get_ptr(self
);
3246 py_sd
= pytalloc_new(struct security_descriptor
, security_Type
);
3247 if (py_sd
== NULL
) {
3252 sd
= pytalloc_get_ptr(py_sd
);
3254 status
= methods
->get_secret(methods
, frame
, secret_name
,
3256 &secret_current_lastchange
,
3258 &secret_old_lastchange
,
3260 if (!NT_STATUS_IS_OK(status
)) {
3261 PyErr_Format(py_pdb_error
, "Unable to get information for secret (%s), (%d,%s)",
3263 NT_STATUS_V(status
),
3264 get_friendly_nt_error_msg(status
));
3269 py_secret
= PyDict_New();
3270 if (py_secret
== NULL
) {
3277 PyDict_SetItemString(py_secret
, "secret_current",
3278 PyString_FromStringAndSize((char *)secret_current
.data
, secret_current
.length
));
3279 PyDict_SetItemString(py_secret
, "secret_current_lastchange",
3280 PyLong_FromUnsignedLongLong(secret_current_lastchange
));
3281 PyDict_SetItemString(py_secret
, "secret_old",
3282 PyString_FromStringAndSize((char *)secret_old
.data
, secret_old
.length
));
3283 PyDict_SetItemString(py_secret
, "secret_old_lastchange",
3284 PyLong_FromUnsignedLongLong(secret_old_lastchange
));
3285 PyDict_SetItemString(py_secret
, "sd", py_sd
);
3292 static PyObject
*py_pdb_set_secret(pytalloc_Object
*self
, PyObject
*args
)
3294 TALLOC_CTX
*frame
= talloc_stackframe();
3296 struct pdb_methods
*methods
;
3297 const char *secret_name
;
3298 PyObject
*py_secret
;
3299 PyObject
*py_secret_cur
, *py_secret_old
, *py_sd
;
3300 DATA_BLOB secret_current
, secret_old
;
3301 struct security_descriptor
*sd
;
3304 if (!PyArg_ParseTuple(args
, "sO!:set_secret_name", &secret_name
, PyDict_Type
, &py_secret
)) {
3309 py_secret_cur
= PyDict_GetItemString(py_secret
, "secret_current");
3310 py_secret_old
= PyDict_GetItemString(py_secret
, "secret_old");
3311 py_sd
= PyDict_GetItemString(py_secret
, "sd");
3313 PY_CHECK_TYPE(&PyString_Type
, py_secret_cur
, return NULL
;);
3314 PY_CHECK_TYPE(&PyString_Type
, py_secret_old
, return NULL
;);
3315 PY_CHECK_TYPE(security_Type
, py_sd
, return NULL
;);
3317 methods
= pytalloc_get_ptr(self
);
3319 PyString_AsStringAndSize(py_secret_cur
, (char **)&secret_current
.data
, &len
);
3320 secret_current
.length
= len
;
3321 PyString_AsStringAndSize(py_secret_old
, (char **)&secret_old
.data
, &len
);
3322 secret_current
.length
= len
;
3323 sd
= pytalloc_get_ptr(py_sd
);
3325 status
= methods
->set_secret(methods
, secret_name
, &secret_current
, &secret_old
, sd
);
3326 if (!NT_STATUS_IS_OK(status
)) {
3327 PyErr_Format(py_pdb_error
, "Unable to set information for secret (%s), (%d,%s)",
3329 NT_STATUS_V(status
),
3330 get_friendly_nt_error_msg(status
));
3340 static PyObject
*py_pdb_delete_secret(pytalloc_Object
*self
, PyObject
*args
)
3342 TALLOC_CTX
*frame
= talloc_stackframe();
3344 struct pdb_methods
*methods
;
3345 const char *secret_name
;
3347 if (!PyArg_ParseTuple(args
, "s:delete_secret", &secret_name
)) {
3352 methods
= pytalloc_get_ptr(self
);
3354 status
= methods
->delete_secret(methods
, secret_name
);
3355 if (!NT_STATUS_IS_OK(status
)) {
3356 PyErr_Format(py_pdb_error
, "Unable to delete secret (%s), (%d,%s)",
3358 NT_STATUS_V(status
),
3359 get_friendly_nt_error_msg(status
));
3368 static PyMethodDef py_pdb_methods
[] = {
3369 { "domain_info", (PyCFunction
)py_pdb_domain_info
, METH_NOARGS
,
3370 "domain_info() -> str\n\n \
3371 Get domain information for the database." },
3372 { "getsampwnam", (PyCFunction
)py_pdb_getsampwnam
, METH_VARARGS
,
3373 "getsampwnam(username) -> samu object\n\n \
3374 Get user information by name." },
3375 { "getsampwsid", (PyCFunction
)py_pdb_getsampwsid
, METH_VARARGS
,
3376 "getsampwsid(user_sid) -> samu object\n\n \
3377 Get user information by sid (dcerpc.security.dom_sid object)." },
3378 { "create_user", (PyCFunction
)py_pdb_create_user
, METH_VARARGS
,
3379 "create_user(username, acct_flags) -> rid\n\n \
3380 Create user. acct_flags are samr account control flags." },
3381 { "delete_user", (PyCFunction
)py_pdb_delete_user
, METH_VARARGS
,
3382 "delete_user(samu object) -> None\n\n \
3384 { "add_sam_account", (PyCFunction
)py_pdb_add_sam_account
, METH_VARARGS
,
3385 "add_sam_account(samu object) -> None\n\n \
3386 Add SAM account." },
3387 { "update_sam_account", (PyCFunction
)py_pdb_update_sam_account
, METH_VARARGS
,
3388 "update_sam_account(samu object) -> None\n\n \
3389 Update SAM account." },
3390 { "delete_sam_account", (PyCFunction
)py_pdb_delete_sam_account
, METH_VARARGS
,
3391 "delete_sam_account(samu object) -> None\n\n \
3392 Delete SAM account." },
3393 { "rename_sam_account", (PyCFunction
)py_pdb_rename_sam_account
, METH_VARARGS
,
3394 "rename_sam_account(samu object1, new_username) -> None\n\n \
3395 Rename SAM account." },
3396 /* update_login_attempts */
3397 { "getgrsid", (PyCFunction
)py_pdb_getgrsid
, METH_VARARGS
,
3398 "getgrsid(group_sid) -> groupmap object\n\n \
3399 Get group information by sid (dcerpc.security.dom_sid object)." },
3400 { "getgrgid", (PyCFunction
)py_pdb_getgrgid
, METH_VARARGS
,
3401 "getgrsid(gid) -> groupmap object\n\n \
3402 Get group information by gid." },
3403 { "getgrnam", (PyCFunction
)py_pdb_getgrnam
, METH_VARARGS
,
3404 "getgrsid(groupname) -> groupmap object\n\n \
3405 Get group information by name." },
3406 { "create_dom_group", (PyCFunction
)py_pdb_create_dom_group
, METH_VARARGS
,
3407 "create_dom_group(groupname) -> group_rid\n\n \
3408 Create new domain group by name." },
3409 { "delete_dom_group", (PyCFunction
)py_pdb_delete_dom_group
, METH_VARARGS
,
3410 "delete_dom_group(group_rid) -> None\n\n \
3411 Delete domain group identified by rid" },
3412 { "add_group_mapping_entry", (PyCFunction
)py_pdb_add_group_mapping_entry
, METH_VARARGS
,
3413 "add_group_mapping_entry(groupmap) -> None\n \
3414 Add group mapping entry for groupmap object." },
3415 { "update_group_mapping_entry", (PyCFunction
)py_pdb_update_group_mapping_entry
, METH_VARARGS
,
3416 "update_group_mapping_entry(groupmap) -> None\n\n \
3417 Update group mapping entry for groupmap object." },
3418 { "delete_group_mapping_entry", (PyCFunction
)py_pdb_delete_group_mapping_entry
, METH_VARARGS
,
3419 "delete_group_mapping_entry(groupmap) -> None\n\n \
3420 Delete group mapping entry for groupmap object." },
3421 { "enum_group_mapping", (PyCFunction
)py_pdb_enum_group_mapping
, METH_VARARGS
,
3422 "enum_group_mapping([domain_sid, [type, [unix_only]]]) -> List\n\n \
3423 Return list of group mappings as groupmap objects. Optional arguments are domain_sid object, type of group, unix only flag." },
3424 { "enum_group_members", (PyCFunction
)py_pdb_enum_group_members
, METH_VARARGS
,
3425 "enum_group_members(group_sid) -> List\n\n \
3426 Return list of users (dom_sid object) in group." },
3427 { "enum_group_memberships", (PyCFunction
)py_pdb_enum_group_memberships
, METH_VARARGS
,
3428 "enum_group_memberships(samu object) -> List\n\n \
3429 Return list of groups (dom_sid object) this user is part of." },
3430 /* set_unix_primary_group */
3431 { "add_groupmem", (PyCFunction
)py_pdb_add_groupmem
, METH_VARARGS
,
3432 "add_groupmem(group_rid, member_rid) -> None\n\n \
3433 Add user to group." },
3434 { "del_groupmem", (PyCFunction
)py_pdb_del_groupmem
, METH_VARARGS
,
3435 "del_groupmem(group_rid, member_rid) -> None\n\n \
3436 Remove user from from group." },
3437 { "create_alias", (PyCFunction
)py_pdb_create_alias
, METH_VARARGS
,
3438 "create_alias(alias_name) -> alias_rid\n\n \
3439 Create alias entry." },
3440 { "delete_alias", (PyCFunction
)py_pdb_delete_alias
, METH_VARARGS
,
3441 "delete_alias(alias_sid) -> None\n\n \
3442 Delete alias entry." },
3443 { "get_aliasinfo", (PyCFunction
)py_pdb_get_aliasinfo
, METH_VARARGS
,
3444 "get_aliasinfo(alias_sid) -> Mapping\n\n \
3445 Get alias information as a dictionary with keys - acct_name, acct_desc, rid." },
3446 { "set_aliasinfo", (PyCFunction
)py_pdb_set_aliasinfo
, METH_VARARGS
,
3447 "set_alias_info(alias_sid, Mapping) -> None\n\n \
3448 Set alias information from a dictionary with keys - acct_name, acct_desc." },
3449 { "add_aliasmem", (PyCFunction
)py_pdb_add_aliasmem
, METH_VARARGS
,
3450 "add_aliasmem(alias_sid, member_sid) -> None\n\n \
3451 Add user to alias entry." },
3452 { "del_aliasmem", (PyCFunction
)py_pdb_del_aliasmem
, METH_VARARGS
,
3453 "del_aliasmem(alias_sid, member_sid) -> None\n\n \
3454 Remove a user from alias entry." },
3455 { "enum_aliasmem", (PyCFunction
)py_pdb_enum_aliasmem
, METH_VARARGS
,
3456 "enum_aliasmem(alias_sid) -> List\n\n \
3457 Return a list of members (dom_sid object) for alias entry." },
3458 /* enum_alias_memberships */
3461 { "get_account_policy", (PyCFunction
)py_pdb_get_account_policy
, METH_NOARGS
,
3462 "get_account_policy() -> Mapping\n\n \
3463 Get account policy information as a dictionary." },
3464 { "set_account_policy", (PyCFunction
)py_pdb_set_account_policy
, METH_VARARGS
,
3465 "get_account_policy(Mapping) -> None\n\n \
3466 Set account policy settings from a dicionary." },
3468 { "search_users", (PyCFunction
)py_pdb_search_users
, METH_VARARGS
,
3469 "search_users(acct_flags) -> List\n\n \
3470 Search users. acct_flags are samr account control flags.\n \
3471 Each list entry is dictionary with keys - idx, rid, acct_flags, account_name, fullname, description." },
3472 { "search_groups", (PyCFunction
)py_pdb_search_groups
, METH_NOARGS
,
3473 "search_groups() -> List\n\n \
3474 Search unix only groups. \n \
3475 Each list entry is dictionary with keys - idx, rid, acct_flags, account_name, fullname, description." },
3476 { "search_aliases", (PyCFunction
)py_pdb_search_aliases
, METH_VARARGS
,
3477 "search_aliases([domain_sid]) -> List\n\n \
3478 Search aliases. domain_sid is dcerpc.security.dom_sid object.\n \
3479 Each list entry is dictionary with keys - idx, rid, acct_flags, account_name, fullname, description." },
3480 { "uid_to_sid", (PyCFunction
)py_pdb_uid_to_sid
, METH_VARARGS
,
3481 "uid_to_sid(uid) -> sid\n\n \
3482 Return sid for given user id." },
3483 { "gid_to_sid", (PyCFunction
)py_pdb_gid_to_sid
, METH_VARARGS
,
3484 "gid_to_sid(gid) -> sid\n\n \
3485 Return sid for given group id." },
3486 { "sid_to_id", (PyCFunction
)py_pdb_sid_to_id
, METH_VARARGS
,
3487 "sid_to_id(sid) -> Tuple\n\n \
3488 Return id and type for given sid." },
3490 { "new_rid", (PyCFunction
)py_pdb_new_rid
, METH_NOARGS
,
3491 "new_rid() -> rid\n\n \
3493 { "get_trusteddom_pw", (PyCFunction
)py_pdb_get_trusteddom_pw
, METH_VARARGS
,
3494 "get_trusteddom_pw(domain) -> Mapping\n\n \
3495 Get trusted domain password, sid and last set time in a dictionary." },
3496 { "set_trusteddom_pw", (PyCFunction
)py_pdb_set_trusteddom_pw
, METH_VARARGS
,
3497 "set_trusteddom_pw(domain, pwd, sid) -> None\n\n \
3498 Set trusted domain password." },
3499 { "del_trusteddom_pw", (PyCFunction
)py_pdb_del_trusteddom_pw
, METH_VARARGS
,
3500 "del_trusteddom_pw(domain) -> None\n\n \
3501 Delete trusted domain password." },
3502 { "enum_trusteddoms", (PyCFunction
)py_pdb_enum_trusteddoms
, METH_NOARGS
,
3503 "enum_trusteddoms() -> List\n\n \
3504 Get list of trusted domains. Each item is a dictionary with name and sid keys" },
3505 { "get_trusted_domain", (PyCFunction
)py_pdb_get_trusted_domain
, METH_VARARGS
,
3506 "get_trusted_domain(domain) -> Mapping\n\n \
3507 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." },
3508 { "get_trusted_domain_by_sid", (PyCFunction
)py_pdb_get_trusted_domain_by_sid
, METH_VARARGS
,
3509 "get_trusted_domain_by_sid(domain_sid) -> Mapping\n\n \
3510 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" },
3511 { "set_trusted_domain", (PyCFunction
)py_pdb_set_trusted_domain
, METH_VARARGS
,
3512 "set_trusted_domain(domain, Mapping) -> None\n\n \
3513 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." },
3514 { "del_trusted_domain", (PyCFunction
)py_pdb_del_trusted_domain
, METH_VARARGS
,
3515 "del_trusted_domain(domain) -> None\n\n \
3516 Delete trusted domain." },
3517 { "enum_trusted_domains", (PyCFunction
)py_pdb_enum_trusted_domains
, METH_VARARGS
,
3518 "enum_trusted_domains() -> List\n\n \
3519 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." },
3520 { "get_secret", (PyCFunction
)py_pdb_get_secret
, METH_VARARGS
,
3521 "get_secret(secret_name) -> Mapping\n\n \
3522 Get secret information for secret_name. Information is a dictionary with keys - secret_current, secret_current_lastchange, secret_old, secret_old_lastchange, sd." },
3523 { "set_secret", (PyCFunction
)py_pdb_set_secret
, METH_VARARGS
,
3524 "set_secret(secret_name, Mapping) -> None\n\n \
3525 Set secret information for secret_name using dictionary with keys - secret_current, sd." },
3526 { "delete_secret", (PyCFunction
)py_pdb_delete_secret
, METH_VARARGS
,
3527 "delete_secret(secret_name) -> None\n\n \
3528 Delete secret information for secret_name." },
3533 static PyObject
*py_pdb_new(PyTypeObject
*type
, PyObject
*args
, PyObject
*kwargs
)
3535 TALLOC_CTX
*frame
= talloc_stackframe();
3536 const char *url
= NULL
;
3539 struct pdb_methods
*methods
;
3541 if (!PyArg_ParseTuple(args
, "s", &url
)) {
3546 /* Initalize list of methods */
3547 status
= make_pdb_method_name(&methods
, url
);
3548 if (!NT_STATUS_IS_OK(status
)) {
3549 PyErr_Format(py_pdb_error
, "Cannot load backend methods for '%s' backend (%d,%s)",
3551 NT_STATUS_V(status
),
3552 get_friendly_nt_error_msg(status
));
3557 if ((pypdb
= pytalloc_steal(type
, methods
)) == NULL
) {
3568 static PyTypeObject PyPDB
= {
3569 .tp_name
= "passdb.PDB",
3570 .tp_basicsize
= sizeof(pytalloc_Object
),
3571 .tp_new
= py_pdb_new
,
3572 .tp_flags
= Py_TPFLAGS_DEFAULT
,
3573 .tp_methods
= py_pdb_methods
,
3574 .tp_doc
= "PDB(url[, read_write_flags]) -> Password DB object\n",
3579 * Return a list of passdb backends
3581 static PyObject
*py_passdb_backends(PyObject
*self
)
3583 TALLOC_CTX
*frame
= talloc_stackframe();
3585 const struct pdb_init_function_entry
*entry
;
3587 entry
= pdb_get_backends();
3592 if((py_blist
= PyList_New(0)) == NULL
) {
3599 PyList_Append(py_blist
, PyString_FromString(entry
->name
));
3600 entry
= entry
->next
;
3608 static PyObject
*py_set_smb_config(PyObject
*self
, PyObject
*args
)
3610 TALLOC_CTX
*frame
= talloc_stackframe();
3611 const char *smb_config
;
3613 if (!PyArg_ParseTuple(args
, "s", &smb_config
)) {
3618 /* Load smbconf parameters */
3619 if (!lp_load_global(smb_config
)) {
3620 PyErr_Format(py_pdb_error
, "Cannot open '%s'", smb_config
);
3630 static PyObject
*py_set_secrets_dir(PyObject
*self
, PyObject
*args
)
3632 TALLOC_CTX
*frame
= talloc_stackframe();
3633 const char *private_dir
;
3635 if (!PyArg_ParseTuple(args
, "s", &private_dir
)) {
3640 /* Initialize secrets database */
3641 if (!secrets_init_path(private_dir
, lp_use_ntdb())) {
3642 PyErr_Format(py_pdb_error
, "Cannot open secrets file database in '%s'",
3652 static PyObject
*py_reload_static_pdb(PyObject
*self
, PyObject
*args
)
3654 TALLOC_CTX
*frame
= talloc_stackframe();
3656 /* Initialize secrets database */
3657 if (!initialize_password_db(true, NULL
)) {
3658 PyErr_Format(py_pdb_error
, "Cannot re-open passdb backend %s", lp_passdb_backend());
3667 static PyObject
*py_get_global_sam_sid(PyObject
*self
)
3669 TALLOC_CTX
*frame
= talloc_stackframe();
3670 struct dom_sid
*domain_sid
, *domain_sid_copy
;
3671 PyObject
*py_dom_sid
;
3673 domain_sid
= get_global_sam_sid();
3675 domain_sid_copy
= dom_sid_dup(frame
, domain_sid
);
3676 if (domain_sid_copy
== NULL
) {
3682 py_dom_sid
= pytalloc_steal(dom_sid_Type
, domain_sid_copy
);
3689 static PyMethodDef py_passdb_methods
[] = {
3690 { "get_backends", (PyCFunction
)py_passdb_backends
, METH_NOARGS
,
3691 "get_backends() -> list\n\n \
3692 Get a list of password database backends supported." },
3693 { "set_smb_config", (PyCFunction
)py_set_smb_config
, METH_VARARGS
,
3694 "set_smb_config(path) -> None\n\n \
3695 Set path to smb.conf file to load configuration parameters." },
3696 { "set_secrets_dir", (PyCFunction
)py_set_secrets_dir
, METH_VARARGS
,
3697 "set_secrets_dir(private_dir) -> None\n\n \
3698 Set path to private directory to load secrets database from non-default location." },
3699 { "get_global_sam_sid", (PyCFunction
)py_get_global_sam_sid
, METH_NOARGS
,
3700 "get_global_sam_sid() -> dom_sid\n\n \
3701 Return domain SID." },
3702 { "reload_static_pdb", (PyCFunction
)py_reload_static_pdb
, METH_NOARGS
,
3703 "reload_static_pdb() -> None\n\n \
3704 Re-initalise the static pdb used internally. Needed if 'passdb backend' is changed." },
3708 void initpassdb(void)
3710 TALLOC_CTX
*frame
= talloc_stackframe();
3712 char exception_name
[] = "passdb.error";
3714 PyTypeObject
*talloc_type
= pytalloc_GetObjectType();
3715 if (talloc_type
== NULL
) {
3720 PyPDB
.tp_base
= talloc_type
;
3721 if (PyType_Ready(&PyPDB
) < 0) {
3726 PySamu
.tp_base
= talloc_type
;
3727 if (PyType_Ready(&PySamu
) < 0) {
3732 PyGroupmap
.tp_base
= talloc_type
;
3733 if (PyType_Ready(&PyGroupmap
) < 0) {
3738 m
= Py_InitModule3("passdb", py_passdb_methods
, "SAMBA Password Database");
3744 /* Create new exception for passdb module */
3745 py_pdb_error
= PyErr_NewException(exception_name
, NULL
, NULL
);
3746 Py_INCREF(py_pdb_error
);
3747 PyModule_AddObject(m
, "error", py_pdb_error
);
3750 PyModule_AddObject(m
, "PDB", (PyObject
*)&PyPDB
);
3753 PyModule_AddObject(m
, "Samu", (PyObject
*)&PySamu
);
3755 Py_INCREF(&PyGroupmap
);
3756 PyModule_AddObject(m
, "Groupmap", (PyObject
*)&PyGroupmap
);
3758 /* Import dom_sid type from dcerpc.security */
3759 mod
= PyImport_ImportModule("samba.dcerpc.security");
3765 dom_sid_Type
= (PyTypeObject
*)PyObject_GetAttrString(mod
, "dom_sid");
3766 if (dom_sid_Type
== NULL
) {
3771 /* Import security_descriptor type from dcerpc.security */
3772 security_Type
= (PyTypeObject
*)PyObject_GetAttrString(mod
, "descriptor");
3774 if (security_Type
== NULL
) {
3779 /* Import GUID type from dcerpc.misc */
3780 mod
= PyImport_ImportModule("samba.dcerpc.misc");
3786 guid_Type
= (PyTypeObject
*)PyObject_GetAttrString(mod
, "GUID");
3788 if (guid_Type
== NULL
) {