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_RETURN_NONE
37 #define Py_RETURN_NONE return Py_INCREF(Py_None), Py_None
40 #ifndef Py_TYPE /* Py_TYPE is only available on Python > 2.6 */
41 #define Py_TYPE(ob) (((PyObject*)(ob))->ob_type)
45 #define PY_CHECK_TYPE(type, var, fail) \
46 if (!PyObject_TypeCheck(var, type)) {\
47 PyErr_Format(PyExc_TypeError, __location__ ": Expected type '%s' for '%s' of type '%s'", (type)->tp_name, #var, Py_TYPE(var)->tp_name); \
53 static PyTypeObject
*dom_sid_Type
= NULL
;
54 static PyTypeObject
*security_Type
= NULL
;
55 static PyTypeObject
*guid_Type
= NULL
;
57 staticforward PyTypeObject PySamu
;
58 staticforward PyTypeObject PyGroupmap
;
59 staticforward PyTypeObject PyPDB
;
61 static PyObject
*py_pdb_error
;
63 void initpassdb(void);
66 /************************** PIDL Autogeneratd ******************************/
68 static PyObject
*py_samu_get_logon_time(PyObject
*obj
, void *closure
)
70 TALLOC_CTX
*frame
= talloc_stackframe();
71 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
72 PyObject
*py_logon_time
;
74 py_logon_time
= PyInt_FromLong(pdb_get_logon_time(sam_acct
));
79 static int py_samu_set_logon_time(PyObject
*obj
, PyObject
*value
, void *closure
)
81 TALLOC_CTX
*frame
= talloc_stackframe();
82 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
84 PY_CHECK_TYPE(&PyInt_Type
, value
, return -1;);
85 if (!pdb_set_logon_time(sam_acct
, PyInt_AsLong(value
), PDB_CHANGED
)) {
93 static PyObject
*py_samu_get_logoff_time(PyObject
*obj
, void *closure
)
95 TALLOC_CTX
*frame
= talloc_stackframe();
96 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
97 PyObject
*py_logoff_time
;
99 py_logoff_time
= PyInt_FromLong(pdb_get_logoff_time(sam_acct
));
101 return py_logoff_time
;
104 static int py_samu_set_logoff_time(PyObject
*obj
, PyObject
*value
, void *closure
)
106 TALLOC_CTX
*frame
= talloc_stackframe();
107 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
109 PY_CHECK_TYPE(&PyInt_Type
, value
, return -1;);
110 if (!pdb_set_logoff_time(sam_acct
, PyInt_AsLong(value
), PDB_CHANGED
)) {
118 static PyObject
*py_samu_get_kickoff_time(PyObject
*obj
, void *closure
)
120 TALLOC_CTX
*frame
= talloc_stackframe();
121 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
122 PyObject
*py_kickoff_time
;
124 py_kickoff_time
= PyInt_FromLong(pdb_get_kickoff_time(sam_acct
));
126 return py_kickoff_time
;
129 static int py_samu_set_kickoff_time(PyObject
*obj
, PyObject
*value
, void *closure
)
131 TALLOC_CTX
*frame
= talloc_stackframe();
132 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
134 PY_CHECK_TYPE(&PyInt_Type
, value
, return -1;);
135 if (!pdb_set_kickoff_time(sam_acct
, PyInt_AsLong(value
), PDB_CHANGED
)) {
143 static PyObject
*py_samu_get_bad_password_time(PyObject
*obj
, void *closure
)
145 TALLOC_CTX
*frame
= talloc_stackframe();
146 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
147 PyObject
*py_bad_password_time
;
149 py_bad_password_time
= PyInt_FromLong(pdb_get_bad_password_time(sam_acct
));
151 return py_bad_password_time
;
154 static int py_samu_set_bad_password_time(PyObject
*obj
, PyObject
*value
, void *closure
)
156 TALLOC_CTX
*frame
= talloc_stackframe();
157 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
159 PY_CHECK_TYPE(&PyInt_Type
, value
, return -1;);
160 if (!pdb_set_bad_password_time(sam_acct
, PyInt_AsLong(value
), PDB_CHANGED
)) {
168 static PyObject
*py_samu_get_pass_last_set_time(PyObject
*obj
, void *closure
)
170 TALLOC_CTX
*frame
= talloc_stackframe();
171 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
172 PyObject
*py_pass_last_set_time
;
174 py_pass_last_set_time
= PyInt_FromLong(pdb_get_pass_last_set_time(sam_acct
));
176 return py_pass_last_set_time
;
179 static int py_samu_set_pass_last_set_time(PyObject
*obj
, PyObject
*value
, void *closure
)
181 TALLOC_CTX
*frame
= talloc_stackframe();
182 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
184 PY_CHECK_TYPE(&PyInt_Type
, value
, return -1;);
185 if (!pdb_set_pass_last_set_time(sam_acct
, PyInt_AsLong(value
), PDB_CHANGED
)) {
193 static PyObject
*py_samu_get_pass_can_change_time(PyObject
*obj
, void *closure
)
195 TALLOC_CTX
*frame
= talloc_stackframe();
196 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
197 PyObject
*py_pass_can_change_time
;
199 py_pass_can_change_time
= PyInt_FromLong(pdb_get_pass_can_change_time(sam_acct
));
201 return py_pass_can_change_time
;
204 static int py_samu_set_pass_can_change_time(PyObject
*obj
, PyObject
*value
, void *closure
)
206 TALLOC_CTX
*frame
= talloc_stackframe();
207 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
209 PY_CHECK_TYPE(&PyInt_Type
, value
, return -1;);
210 if (!pdb_set_pass_can_change_time(sam_acct
, PyInt_AsLong(value
), PDB_CHANGED
)) {
218 static PyObject
*py_samu_get_pass_must_change_time(PyObject
*obj
, void *closure
)
220 TALLOC_CTX
*frame
= talloc_stackframe();
221 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
222 PyObject
*py_pass_must_change_time
;
224 py_pass_must_change_time
= PyInt_FromLong(pdb_get_pass_must_change_time(sam_acct
));
226 return py_pass_must_change_time
;
229 static int py_samu_set_pass_must_change_time(PyObject
*obj
, PyObject
*value
, void *closure
)
231 TALLOC_CTX
*frame
= talloc_stackframe();
232 PY_CHECK_TYPE(&PyInt_Type
, value
, return -1;);
234 /* TODO: make this not a get/set or give a better exception */
239 static PyObject
*py_samu_get_username(PyObject
*obj
, void *closure
)
241 TALLOC_CTX
*frame
= talloc_stackframe();
242 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
243 PyObject
*py_username
;
244 const char *username
;
246 username
= pdb_get_username(sam_acct
);
247 if (username
== NULL
) {
251 py_username
= PyString_FromString(username
);
256 static int py_samu_set_username(PyObject
*obj
, PyObject
*value
, void *closure
)
258 TALLOC_CTX
*frame
= talloc_stackframe();
259 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
261 PY_CHECK_TYPE(&PyString_Type
, value
, return -1;);
262 if (!pdb_set_username(sam_acct
, PyString_AsString(value
), PDB_CHANGED
)) {
270 static PyObject
*py_samu_get_domain(PyObject
*obj
, void *closure
)
272 TALLOC_CTX
*frame
= talloc_stackframe();
273 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
277 domain
= pdb_get_domain(sam_acct
);
278 if (domain
== NULL
) {
282 py_domain
= PyString_FromString(domain
);
287 static int py_samu_set_domain(PyObject
*obj
, PyObject
*value
, void *closure
)
289 TALLOC_CTX
*frame
= talloc_stackframe();
290 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
292 PY_CHECK_TYPE(&PyString_Type
, value
, return -1;);
293 if (!pdb_set_domain(sam_acct
, PyString_AsString(value
), PDB_CHANGED
)) {
301 static PyObject
*py_samu_get_nt_username(PyObject
*obj
, void *closure
)
303 TALLOC_CTX
*frame
= talloc_stackframe();
304 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
305 PyObject
*py_nt_username
;
306 const char *nt_username
;
308 nt_username
= pdb_get_nt_username(sam_acct
);
309 if (nt_username
== NULL
) {
313 py_nt_username
= PyString_FromString(nt_username
);
315 return py_nt_username
;
318 static int py_samu_set_nt_username(PyObject
*obj
, PyObject
*value
, void *closure
)
320 TALLOC_CTX
*frame
= talloc_stackframe();
321 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
323 PY_CHECK_TYPE(&PyString_Type
, value
, return -1;);
324 if (!pdb_set_nt_username(sam_acct
, PyString_AsString(value
), PDB_CHANGED
)) {
332 static PyObject
*py_samu_get_full_name(PyObject
*obj
, void *closure
)
334 TALLOC_CTX
*frame
= talloc_stackframe();
335 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
336 PyObject
*py_full_name
;
337 const char *full_name
;
339 full_name
= pdb_get_fullname(sam_acct
);
340 if (full_name
== NULL
) {
344 py_full_name
= PyString_FromString(full_name
);
349 static int py_samu_set_full_name(PyObject
*obj
, PyObject
*value
, void *closure
)
351 TALLOC_CTX
*frame
= talloc_stackframe();
352 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
354 PY_CHECK_TYPE(&PyString_Type
, value
, return -1;);
355 if (!pdb_set_fullname(sam_acct
, PyString_AsString(value
), PDB_CHANGED
)) {
363 static PyObject
*py_samu_get_home_dir(PyObject
*obj
, void *closure
)
365 TALLOC_CTX
*frame
= talloc_stackframe();
366 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
367 PyObject
*py_home_dir
;
368 const char *home_dir
;
370 home_dir
= pdb_get_homedir(sam_acct
);
371 if (home_dir
== NULL
) {
375 py_home_dir
= PyString_FromString(home_dir
);
380 static int py_samu_set_home_dir(PyObject
*obj
, PyObject
*value
, void *closure
)
382 TALLOC_CTX
*frame
= talloc_stackframe();
383 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
385 PY_CHECK_TYPE(&PyString_Type
, value
, return -1;);
386 if (!pdb_set_homedir(sam_acct
, PyString_AsString(value
), PDB_CHANGED
)) {
394 static PyObject
*py_samu_get_dir_drive(PyObject
*obj
, void *closure
)
396 TALLOC_CTX
*frame
= talloc_stackframe();
397 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
398 PyObject
*py_dir_drive
;
399 const char *dir_drive
;
401 dir_drive
= pdb_get_dir_drive(sam_acct
);
402 if (dir_drive
== NULL
) {
406 py_dir_drive
= PyString_FromString(dir_drive
);
411 static int py_samu_set_dir_drive(PyObject
*obj
, PyObject
*value
, void *closure
)
413 TALLOC_CTX
*frame
= talloc_stackframe();
414 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
416 PY_CHECK_TYPE(&PyString_Type
, value
, return -1;);
417 if (!pdb_set_dir_drive(sam_acct
, PyString_AsString(value
), PDB_CHANGED
)) {
425 static PyObject
*py_samu_get_logon_script(PyObject
*obj
, void *closure
)
427 TALLOC_CTX
*frame
= talloc_stackframe();
428 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
429 PyObject
*py_logon_script
;
430 const char *logon_script
;
432 logon_script
= pdb_get_logon_script(sam_acct
);
433 if (logon_script
== NULL
) {
437 py_logon_script
= PyString_FromString(logon_script
);
439 return py_logon_script
;
442 static int py_samu_set_logon_script(PyObject
*obj
, PyObject
*value
, void *closure
)
444 TALLOC_CTX
*frame
= talloc_stackframe();
445 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
447 PY_CHECK_TYPE(&PyString_Type
, value
, return -1;);
448 if (!pdb_set_logon_script(sam_acct
, PyString_AsString(value
), PDB_CHANGED
)) {
456 static PyObject
*py_samu_get_profile_path(PyObject
*obj
, void *closure
)
458 TALLOC_CTX
*frame
= talloc_stackframe();
459 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
460 PyObject
*py_profile_path
;
461 const char *profile_path
;
463 profile_path
= pdb_get_profile_path(sam_acct
);
464 if (profile_path
== NULL
) {
468 py_profile_path
= PyString_FromString(profile_path
);
470 return py_profile_path
;
473 static int py_samu_set_profile_path(PyObject
*obj
, PyObject
*value
, void *closure
)
475 TALLOC_CTX
*frame
= talloc_stackframe();
476 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
478 PY_CHECK_TYPE(&PyString_Type
, value
, return -1;);
479 if (!pdb_set_profile_path(sam_acct
, PyString_AsString(value
), PDB_CHANGED
)) {
487 static PyObject
*py_samu_get_acct_desc(PyObject
*obj
, void *closure
)
489 TALLOC_CTX
*frame
= talloc_stackframe();
490 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
491 PyObject
*py_acct_desc
;
492 const char *acct_desc
;
494 acct_desc
= pdb_get_acct_desc(sam_acct
);
495 if (acct_desc
== NULL
) {
499 py_acct_desc
= PyString_FromString(acct_desc
);
504 static int py_samu_set_acct_desc(PyObject
*obj
, PyObject
*value
, void *closure
)
506 TALLOC_CTX
*frame
= talloc_stackframe();
507 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
509 PY_CHECK_TYPE(&PyString_Type
, value
, return -1;);
510 if (!pdb_set_acct_desc(sam_acct
, PyString_AsString(value
), PDB_CHANGED
)) {
518 static PyObject
*py_samu_get_workstations(PyObject
*obj
, void *closure
)
520 TALLOC_CTX
*frame
= talloc_stackframe();
521 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
522 PyObject
*py_workstations
;
523 const char *workstations
;
525 workstations
= pdb_get_workstations(sam_acct
);
526 if (workstations
== NULL
) {
530 py_workstations
= PyString_FromString(workstations
);
532 return py_workstations
;
535 static int py_samu_set_workstations(PyObject
*obj
, PyObject
*value
, void *closure
)
537 TALLOC_CTX
*frame
= talloc_stackframe();
538 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
540 PY_CHECK_TYPE(&PyString_Type
, value
, return -1;);
541 if (!pdb_set_workstations(sam_acct
, PyString_AsString(value
), PDB_CHANGED
)) {
549 static PyObject
*py_samu_get_comment(PyObject
*obj
, void *closure
)
551 TALLOC_CTX
*frame
= talloc_stackframe();
552 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
553 PyObject
*py_comment
;
556 comment
= pdb_get_comment(sam_acct
);
557 if (comment
== NULL
) {
561 py_comment
= PyString_FromString(comment
);
566 static int py_samu_set_comment(PyObject
*obj
, PyObject
*value
, void *closure
)
568 TALLOC_CTX
*frame
= talloc_stackframe();
569 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
571 PY_CHECK_TYPE(&PyString_Type
, value
, return -1;);
572 if (!pdb_set_comment(sam_acct
, PyString_AsString(value
), PDB_CHANGED
)) {
580 static PyObject
*py_samu_get_munged_dial(PyObject
*obj
, void *closure
)
582 TALLOC_CTX
*frame
= talloc_stackframe();
583 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
584 PyObject
*py_munged_dial
;
585 const char *munged_dial
;
587 munged_dial
= pdb_get_munged_dial(sam_acct
);
588 if (munged_dial
== NULL
) {
592 py_munged_dial
= PyString_FromString(munged_dial
);
594 return py_munged_dial
;
597 static int py_samu_set_munged_dial(PyObject
*obj
, PyObject
*value
, void *closure
)
599 TALLOC_CTX
*frame
= talloc_stackframe();
600 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
602 PY_CHECK_TYPE(&PyString_Type
, value
, return -1;);
603 if (!pdb_set_munged_dial(sam_acct
, PyString_AsString(value
), PDB_CHANGED
)) {
611 static PyObject
*py_samu_get_user_sid(PyObject
*obj
, void *closure
)
613 TALLOC_CTX
*frame
= talloc_stackframe();
614 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
615 PyObject
*py_user_sid
;
616 const struct dom_sid
*user_sid
;
617 struct dom_sid
*copy_user_sid
;
620 user_sid
= pdb_get_user_sid(sam_acct
);
621 if(user_sid
== NULL
) {
625 mem_ctx
= talloc_new(NULL
);
626 if (mem_ctx
== NULL
) {
631 copy_user_sid
= dom_sid_dup(mem_ctx
, user_sid
);
632 if (copy_user_sid
== NULL
) {
634 talloc_free(mem_ctx
);
639 py_user_sid
= pytalloc_steal(dom_sid_Type
, copy_user_sid
);
641 talloc_free(mem_ctx
);
647 static int py_samu_set_user_sid(PyObject
*obj
, PyObject
*value
, void *closure
)
649 TALLOC_CTX
*frame
= talloc_stackframe();
650 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
652 PY_CHECK_TYPE(dom_sid_Type
, value
, return -1;);
653 if (!pdb_set_user_sid(sam_acct
, (struct dom_sid
*)pytalloc_get_ptr(value
), PDB_CHANGED
)) {
661 static PyObject
*py_samu_get_group_sid(PyObject
*obj
, void *closure
)
663 TALLOC_CTX
*frame
= talloc_stackframe();
664 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
665 const struct dom_sid
*group_sid
;
666 struct dom_sid
*copy_group_sid
;
668 group_sid
= pdb_get_group_sid(sam_acct
);
669 if (group_sid
== NULL
) {
673 copy_group_sid
= dom_sid_dup(NULL
, group_sid
);
674 if (copy_group_sid
== NULL
) {
681 return pytalloc_steal(dom_sid_Type
, copy_group_sid
);
684 static int py_samu_set_group_sid(PyObject
*obj
, PyObject
*value
, void *closure
)
686 TALLOC_CTX
*frame
= talloc_stackframe();
687 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
689 PY_CHECK_TYPE(dom_sid_Type
, value
, return -1;);
690 if (!pdb_set_group_sid(sam_acct
, (struct dom_sid
*)pytalloc_get_ptr(value
), PDB_CHANGED
)) {
698 static PyObject
*py_samu_get_lanman_passwd(PyObject
*obj
, void *closure
)
700 TALLOC_CTX
*frame
= talloc_stackframe();
701 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
705 lm_pw
= (const char *)pdb_get_lanman_passwd(sam_acct
);
710 py_lm_pw
= PyString_FromStringAndSize(lm_pw
, LM_HASH_LEN
);
715 static int py_samu_set_lanman_passwd(PyObject
*obj
, PyObject
*value
, void *closure
)
717 TALLOC_CTX
*frame
= talloc_stackframe();
718 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
720 PY_CHECK_TYPE(&PyString_Type
, value
, return -1;);
721 if (!pdb_set_lanman_passwd(sam_acct
, (uint8_t *)PyString_AsString(value
), PDB_CHANGED
)) {
729 static PyObject
*py_samu_get_nt_passwd(PyObject
*obj
, void *closure
)
731 TALLOC_CTX
*frame
= talloc_stackframe();
732 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
736 nt_pw
= (const char *)pdb_get_nt_passwd(sam_acct
);
741 py_nt_pw
= PyString_FromStringAndSize(nt_pw
, NT_HASH_LEN
);
746 static int py_samu_set_nt_passwd(PyObject
*obj
, PyObject
*value
, void *closure
)
748 TALLOC_CTX
*frame
= talloc_stackframe();
749 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
751 if (!pdb_set_nt_passwd(sam_acct
, (uint8_t *)PyString_AsString(value
), PDB_CHANGED
)) {
759 static PyObject
*py_samu_get_pw_history(PyObject
*obj
, void *closure
)
761 TALLOC_CTX
*frame
= talloc_stackframe();
762 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
763 PyObject
*py_nt_pw_his
;
764 const char *nt_pw_his
;
767 nt_pw_his
= (const char *)pdb_get_pw_history(sam_acct
, &hist_len
);
768 if (nt_pw_his
== NULL
) {
772 py_nt_pw_his
= PyString_FromStringAndSize(nt_pw_his
, hist_len
*PW_HISTORY_ENTRY_LEN
);
777 static int py_samu_set_pw_history(PyObject
*obj
, PyObject
*value
, void *closure
)
779 TALLOC_CTX
*frame
= talloc_stackframe();
780 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
785 PyString_AsStringAndSize(value
, &nt_pw_his
, &len
);
786 hist_len
= len
/ PW_HISTORY_ENTRY_LEN
;
787 if (!pdb_set_pw_history(sam_acct
, (uint8_t *)nt_pw_his
, hist_len
, PDB_CHANGED
)) {
795 static PyObject
*py_samu_get_plaintext_passwd(PyObject
*obj
, void *closure
)
797 TALLOC_CTX
*frame
= talloc_stackframe();
798 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
799 PyObject
*py_plaintext_pw
;
800 const char *plaintext_pw
;
802 plaintext_pw
= pdb_get_plaintext_passwd(sam_acct
);
803 if (plaintext_pw
== NULL
) {
807 py_plaintext_pw
= PyString_FromString(plaintext_pw
);
809 return py_plaintext_pw
;
812 static int py_samu_set_plaintext_passwd(PyObject
*obj
, PyObject
*value
, void *closure
)
814 TALLOC_CTX
*frame
= talloc_stackframe();
815 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
817 if (!pdb_set_plaintext_passwd(sam_acct
, PyString_AsString(value
))) {
825 static PyObject
*py_samu_get_acct_ctrl(PyObject
*obj
, void *closure
)
827 TALLOC_CTX
*frame
= talloc_stackframe();
828 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
829 PyObject
*py_acct_ctrl
;
831 py_acct_ctrl
= PyInt_FromLong(pdb_get_acct_ctrl(sam_acct
));
836 static int py_samu_set_acct_ctrl(PyObject
*obj
, PyObject
*value
, void *closure
)
838 TALLOC_CTX
*frame
= talloc_stackframe();
839 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
841 PY_CHECK_TYPE(&PyInt_Type
, value
, return -1;);
842 if (!pdb_set_acct_ctrl(sam_acct
, PyInt_AsLong(value
), PDB_CHANGED
)) {
850 static PyObject
*py_samu_get_logon_divs(PyObject
*obj
, void *closure
)
852 TALLOC_CTX
*frame
= talloc_stackframe();
853 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
854 PyObject
*py_logon_divs
;
856 py_logon_divs
= PyInt_FromLong(pdb_get_logon_divs(sam_acct
));
858 return py_logon_divs
;
861 static int py_samu_set_logon_divs(PyObject
*obj
, PyObject
*value
, void *closure
)
863 TALLOC_CTX
*frame
= talloc_stackframe();
864 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
866 PY_CHECK_TYPE(&PyInt_Type
, value
, return -1;);
867 if (!pdb_set_logon_divs(sam_acct
, PyInt_AsLong(value
), PDB_CHANGED
)) {
875 static PyObject
*py_samu_get_hours_len(PyObject
*obj
, void *closure
)
877 TALLOC_CTX
*frame
= talloc_stackframe();
878 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
879 PyObject
*py_hours_len
;
881 py_hours_len
= PyInt_FromLong(pdb_get_hours_len(sam_acct
));
886 static int py_samu_set_hours_len(PyObject
*obj
, PyObject
*value
, void *closure
)
888 TALLOC_CTX
*frame
= talloc_stackframe();
889 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
891 PY_CHECK_TYPE(&PyInt_Type
, value
, return -1;);
892 if (!pdb_set_hours_len(sam_acct
, PyInt_AsLong(value
), PDB_CHANGED
)) {
900 static PyObject
*py_samu_get_hours(PyObject
*obj
, void *closure
)
902 TALLOC_CTX
*frame
= talloc_stackframe();
903 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
908 hours
= (const char *)pdb_get_hours(sam_acct
);
913 hours_len
= pdb_get_hours_len(sam_acct
);
914 if ((py_hours
= PyList_New(hours_len
)) == NULL
) {
920 for (i
=0; i
<hours_len
; i
++) {
921 PyList_SetItem(py_hours
, i
, PyInt_FromLong(hours
[i
]));
927 static int py_samu_set_hours(PyObject
*obj
, PyObject
*value
, void *closure
)
929 TALLOC_CTX
*frame
= talloc_stackframe();
930 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
936 PY_CHECK_TYPE(&PyList_Type
, value
, return -1;);
938 hours_len
= PyList_GET_SIZE(value
);
940 hours
= talloc_array(pytalloc_get_mem_ctx(obj
), uint8_t, hours_len
);
947 for (i
=0; i
< hours_len
; i
++) {
948 PY_CHECK_TYPE(&PyInt_Type
, PyList_GET_ITEM(value
,i
), return -1;);
949 hours
[i
] = PyInt_AsLong(PyList_GET_ITEM(value
, i
));
952 status
= pdb_set_hours(sam_acct
, hours
, hours_len
, PDB_CHANGED
);
963 static PyObject
*py_samu_get_bad_password_count(PyObject
*obj
, void *closure
)
965 TALLOC_CTX
*frame
= talloc_stackframe();
966 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
967 PyObject
*py_bad_password_count
;
969 py_bad_password_count
= PyInt_FromLong(pdb_get_bad_password_count(sam_acct
));
971 return py_bad_password_count
;
974 static int py_samu_set_bad_password_count(PyObject
*obj
, PyObject
*value
, void *closure
)
976 TALLOC_CTX
*frame
= talloc_stackframe();
977 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
979 PY_CHECK_TYPE(&PyInt_Type
, value
, return -1;);
980 if (!pdb_set_bad_password_count(sam_acct
, PyInt_AsLong(value
), PDB_CHANGED
)) {
988 static PyObject
*py_samu_get_logon_count(PyObject
*obj
, void *closure
)
990 TALLOC_CTX
*frame
= talloc_stackframe();
991 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
992 PyObject
*py_logon_count
;
994 py_logon_count
= PyInt_FromLong(pdb_get_logon_count(sam_acct
));
996 return py_logon_count
;
999 static int py_samu_set_logon_count(PyObject
*obj
, PyObject
*value
, void *closure
)
1001 TALLOC_CTX
*frame
= talloc_stackframe();
1002 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
1004 PY_CHECK_TYPE(&PyInt_Type
, value
, return -1;);
1005 if (!pdb_set_logon_count(sam_acct
, PyInt_AsLong(value
), PDB_CHANGED
)) {
1013 static PyObject
*py_samu_get_country_code(PyObject
*obj
, void *closure
)
1015 TALLOC_CTX
*frame
= talloc_stackframe();
1016 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
1017 PyObject
*py_country_code
;
1019 py_country_code
= PyInt_FromLong(pdb_get_country_code(sam_acct
));
1021 return py_country_code
;
1024 static int py_samu_set_country_code(PyObject
*obj
, PyObject
*value
, void *closure
)
1026 TALLOC_CTX
*frame
= talloc_stackframe();
1027 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
1029 PY_CHECK_TYPE(&PyInt_Type
, value
, return -1;);
1030 if (!pdb_set_country_code(sam_acct
, PyInt_AsLong(value
), PDB_CHANGED
)) {
1038 static PyObject
*py_samu_get_code_page(PyObject
*obj
, void *closure
)
1040 TALLOC_CTX
*frame
= talloc_stackframe();
1041 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
1042 PyObject
*py_code_page
;
1044 py_code_page
= PyInt_FromLong(pdb_get_code_page(sam_acct
));
1046 return py_code_page
;
1049 static int py_samu_set_code_page(PyObject
*obj
, PyObject
*value
, void *closure
)
1051 TALLOC_CTX
*frame
= talloc_stackframe();
1052 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
1054 PY_CHECK_TYPE(&PyInt_Type
, value
, return -1;);
1055 if (!pdb_set_code_page(sam_acct
, PyInt_AsLong(value
), PDB_CHANGED
)) {
1063 static PyGetSetDef py_samu_getsetters
[] = {
1064 { discard_const_p(char, "logon_time"), py_samu_get_logon_time
, py_samu_set_logon_time
},
1065 { discard_const_p(char, "logoff_time"), py_samu_get_logoff_time
, py_samu_set_logoff_time
},
1066 { discard_const_p(char, "kickoff_time"), py_samu_get_kickoff_time
, py_samu_set_kickoff_time
},
1067 { discard_const_p(char, "bad_password_time"), py_samu_get_bad_password_time
, py_samu_set_bad_password_time
},
1068 { discard_const_p(char, "pass_last_set_time"), py_samu_get_pass_last_set_time
, py_samu_set_pass_last_set_time
},
1069 { discard_const_p(char, "pass_can_change_time"), py_samu_get_pass_can_change_time
, py_samu_set_pass_can_change_time
},
1070 { discard_const_p(char, "pass_must_change_time"), py_samu_get_pass_must_change_time
, py_samu_set_pass_must_change_time
},
1071 { discard_const_p(char, "username"), py_samu_get_username
, py_samu_set_username
},
1072 { discard_const_p(char, "domain"), py_samu_get_domain
, py_samu_set_domain
},
1073 { discard_const_p(char, "nt_username"), py_samu_get_nt_username
, py_samu_set_nt_username
},
1074 { discard_const_p(char, "full_name"), py_samu_get_full_name
, py_samu_set_full_name
},
1075 { discard_const_p(char, "home_dir"), py_samu_get_home_dir
, py_samu_set_home_dir
},
1076 { discard_const_p(char, "dir_drive"), py_samu_get_dir_drive
, py_samu_set_dir_drive
},
1077 { discard_const_p(char, "logon_script"), py_samu_get_logon_script
, py_samu_set_logon_script
},
1078 { discard_const_p(char, "profile_path"), py_samu_get_profile_path
, py_samu_set_profile_path
},
1079 { discard_const_p(char, "acct_desc"), py_samu_get_acct_desc
, py_samu_set_acct_desc
},
1080 { discard_const_p(char, "workstations"), py_samu_get_workstations
, py_samu_set_workstations
},
1081 { discard_const_p(char, "comment"), py_samu_get_comment
, py_samu_set_comment
},
1082 { discard_const_p(char, "munged_dial"), py_samu_get_munged_dial
, py_samu_set_munged_dial
},
1083 { discard_const_p(char, "user_sid"), py_samu_get_user_sid
, py_samu_set_user_sid
},
1084 { discard_const_p(char, "group_sid"), py_samu_get_group_sid
, py_samu_set_group_sid
},
1085 { discard_const_p(char, "lanman_passwd"), py_samu_get_lanman_passwd
, py_samu_set_lanman_passwd
},
1086 { discard_const_p(char, "nt_passwd"), py_samu_get_nt_passwd
, py_samu_set_nt_passwd
},
1087 { discard_const_p(char, "pw_history"), py_samu_get_pw_history
, py_samu_set_pw_history
},
1088 { discard_const_p(char, "plaintext_passwd"), py_samu_get_plaintext_passwd
, py_samu_set_plaintext_passwd
},
1089 { discard_const_p(char, "acct_ctrl"), py_samu_get_acct_ctrl
, py_samu_set_acct_ctrl
},
1090 { discard_const_p(char, "logon_divs"), py_samu_get_logon_divs
, py_samu_set_logon_divs
},
1091 { discard_const_p(char, "hours_len"), py_samu_get_hours_len
, py_samu_set_hours_len
},
1092 { discard_const_p(char, "hours"), py_samu_get_hours
, py_samu_set_hours
},
1093 { discard_const_p(char, "bad_password_count"), py_samu_get_bad_password_count
, py_samu_set_bad_password_count
},
1094 { discard_const_p(char, "logon_count"), py_samu_get_logon_count
, py_samu_set_logon_count
},
1095 { discard_const_p(char, "country_code"), py_samu_get_country_code
, py_samu_set_country_code
},
1096 { discard_const_p(char, "code_page"), py_samu_get_code_page
, py_samu_set_code_page
},
1101 /************************** PIDL Autogeneratd ******************************/
1103 static PyObject
*py_samu_new(PyTypeObject
*type
, PyObject
*args
, PyObject
*kwargs
)
1105 TALLOC_CTX
*frame
= talloc_stackframe();
1106 struct samu
*sam_acct
;
1108 sam_acct
= samu_new(NULL
);
1116 return pytalloc_steal(type
, sam_acct
);
1119 static PyTypeObject PySamu
= {
1120 .tp_name
= "passdb.Samu",
1121 .tp_basicsize
= sizeof(pytalloc_Object
),
1122 .tp_getset
= py_samu_getsetters
,
1124 .tp_new
= py_samu_new
,
1125 .tp_flags
= Py_TPFLAGS_DEFAULT
| Py_TPFLAGS_BASETYPE
,
1126 .tp_doc
= "Samu() -> samu object\n",
1130 static PyObject
*py_groupmap_get_gid(PyObject
*obj
, void *closure
)
1132 TALLOC_CTX
*frame
= talloc_stackframe();
1133 GROUP_MAP
*group_map
= (GROUP_MAP
*)pytalloc_get_ptr(obj
);
1136 py_gid
= Py_BuildValue("i", group_map
->gid
);
1141 static int py_groupmap_set_gid(PyObject
*obj
, PyObject
*value
, void *closure
)
1143 TALLOC_CTX
*frame
= talloc_stackframe();
1144 GROUP_MAP
*group_map
= (GROUP_MAP
*)pytalloc_get_ptr(obj
);
1146 PY_CHECK_TYPE(&PyInt_Type
, value
, return -1;);
1147 group_map
->gid
= PyInt_AsLong(value
);
1152 static PyObject
*py_groupmap_get_sid(PyObject
*obj
, void *closure
)
1154 TALLOC_CTX
*frame
= talloc_stackframe();
1155 GROUP_MAP
*group_map
= (GROUP_MAP
*)pytalloc_get_ptr(obj
);
1157 struct dom_sid
*group_sid
;
1158 TALLOC_CTX
*mem_ctx
;
1160 mem_ctx
= talloc_new(NULL
);
1161 if (mem_ctx
== NULL
) {
1167 group_sid
= dom_sid_dup(mem_ctx
, &group_map
->sid
);
1168 if (group_sid
== NULL
) {
1170 talloc_free(mem_ctx
);
1175 py_sid
= pytalloc_steal(dom_sid_Type
, group_sid
);
1177 talloc_free(mem_ctx
);
1183 static int py_groupmap_set_sid(PyObject
*obj
, PyObject
*value
, void *closure
)
1185 TALLOC_CTX
*frame
= talloc_stackframe();
1186 GROUP_MAP
*group_map
= (GROUP_MAP
*)pytalloc_get_ptr(obj
);
1188 PY_CHECK_TYPE(dom_sid_Type
, value
, return -1;);
1189 group_map
->sid
= *pytalloc_get_type(value
, struct dom_sid
);
1194 static PyObject
*py_groupmap_get_sid_name_use(PyObject
*obj
, void *closure
)
1196 TALLOC_CTX
*frame
= talloc_stackframe();
1197 GROUP_MAP
*group_map
= (GROUP_MAP
*)pytalloc_get_ptr(obj
);
1198 PyObject
*py_sid_name_use
;
1200 py_sid_name_use
= PyInt_FromLong(group_map
->sid_name_use
);
1202 return py_sid_name_use
;
1205 static int py_groupmap_set_sid_name_use(PyObject
*obj
, PyObject
*value
, void *closure
)
1207 TALLOC_CTX
*frame
= talloc_stackframe();
1208 GROUP_MAP
*group_map
= (GROUP_MAP
*)pytalloc_get_ptr(obj
);
1210 PY_CHECK_TYPE(&PyInt_Type
, value
, return -1;);
1211 group_map
->sid_name_use
= PyInt_AsLong(value
);
1216 static PyObject
*py_groupmap_get_nt_name(PyObject
*obj
, void *closure
)
1218 TALLOC_CTX
*frame
= talloc_stackframe();
1219 GROUP_MAP
*group_map
= (GROUP_MAP
*)pytalloc_get_ptr(obj
);
1220 PyObject
*py_nt_name
;
1221 if (group_map
->nt_name
== NULL
) {
1222 py_nt_name
= Py_None
;
1223 Py_INCREF(py_nt_name
);
1225 py_nt_name
= PyString_FromString(group_map
->nt_name
);
1231 static int py_groupmap_set_nt_name(PyObject
*obj
, PyObject
*value
, void *closure
)
1233 TALLOC_CTX
*frame
= talloc_stackframe();
1234 GROUP_MAP
*group_map
= (GROUP_MAP
*)pytalloc_get_ptr(obj
);
1236 PY_CHECK_TYPE(&PyString_Type
, value
, return -1;);
1237 if (value
== Py_None
) {
1238 fstrcpy(group_map
->nt_name
, NULL
);
1240 fstrcpy(group_map
->nt_name
, PyString_AsString(value
));
1246 static PyObject
*py_groupmap_get_comment(PyObject
*obj
, void *closure
)
1248 TALLOC_CTX
*frame
= talloc_stackframe();
1249 GROUP_MAP
*group_map
= (GROUP_MAP
*)pytalloc_get_ptr(obj
);
1250 PyObject
*py_comment
;
1251 if (group_map
->comment
== NULL
) {
1252 py_comment
= Py_None
;
1253 Py_INCREF(py_comment
);
1255 py_comment
= PyString_FromString(group_map
->comment
);
1261 static int py_groupmap_set_comment(PyObject
*obj
, PyObject
*value
, void *closure
)
1263 TALLOC_CTX
*frame
= talloc_stackframe();
1264 GROUP_MAP
*group_map
= (GROUP_MAP
*)pytalloc_get_ptr(obj
);
1266 PY_CHECK_TYPE(&PyString_Type
, value
, return -1;);
1267 if (value
== Py_None
) {
1268 fstrcpy(group_map
->comment
, NULL
);
1270 fstrcpy(group_map
->comment
, PyString_AsString(value
));
1276 static PyGetSetDef py_groupmap_getsetters
[] = {
1277 { discard_const_p(char, "gid"), py_groupmap_get_gid
, py_groupmap_set_gid
},
1278 { discard_const_p(char, "sid"), py_groupmap_get_sid
, py_groupmap_set_sid
},
1279 { discard_const_p(char, "sid_name_use"), py_groupmap_get_sid_name_use
, py_groupmap_set_sid_name_use
},
1280 { discard_const_p(char, "nt_name"), py_groupmap_get_nt_name
, py_groupmap_set_nt_name
},
1281 { discard_const_p(char, "comment"), py_groupmap_get_comment
, py_groupmap_set_comment
},
1285 static PyObject
*py_groupmap_new(PyTypeObject
*type
, PyObject
*args
, PyObject
*kwargs
)
1287 TALLOC_CTX
*frame
= talloc_stackframe();
1288 GROUP_MAP
*group_map
;
1289 TALLOC_CTX
*mem_ctx
;
1290 PyObject
*py_group_map
;
1292 mem_ctx
= talloc_new(NULL
);
1293 if (mem_ctx
== NULL
) {
1299 group_map
= talloc_zero(mem_ctx
, GROUP_MAP
);
1300 if (group_map
== NULL
) {
1302 talloc_free(mem_ctx
);
1307 py_group_map
= pytalloc_steal(type
, group_map
);
1308 if (py_group_map
== NULL
) {
1310 talloc_free(mem_ctx
);
1315 talloc_free(mem_ctx
);
1318 return py_group_map
;
1322 static PyTypeObject PyGroupmap
= {
1323 .tp_name
= "passdb.Groupmap",
1324 .tp_basicsize
= sizeof(pytalloc_Object
),
1325 .tp_getset
= py_groupmap_getsetters
,
1327 .tp_new
= py_groupmap_new
,
1328 .tp_flags
= Py_TPFLAGS_DEFAULT
| Py_TPFLAGS_BASETYPE
,
1329 .tp_doc
= "Groupmap() -> group map object\n",
1333 static PyObject
*py_pdb_domain_info(pytalloc_Object
*self
, PyObject
*args
)
1335 TALLOC_CTX
*frame
= talloc_stackframe();
1336 struct pdb_methods
*methods
;
1337 struct pdb_domain_info
*domain_info
;
1338 PyObject
*py_domain_info
;
1339 struct dom_sid
*sid
;
1342 methods
= pytalloc_get_ptr(self
);
1344 domain_info
= methods
->get_domain_info(methods
, frame
);
1345 if (! domain_info
) {
1349 sid
= dom_sid_dup(frame
, &domain_info
->sid
);
1356 guid
= talloc(frame
, struct GUID
);
1362 *guid
= domain_info
->guid
;
1364 if ((py_domain_info
= PyDict_New()) == NULL
) {
1370 PyDict_SetItemString(py_domain_info
, "name", PyString_FromString(domain_info
->name
));
1371 PyDict_SetItemString(py_domain_info
, "dns_domain", PyString_FromString(domain_info
->dns_domain
));
1372 PyDict_SetItemString(py_domain_info
, "dns_forest", PyString_FromString(domain_info
->dns_forest
));
1373 PyDict_SetItemString(py_domain_info
, "dom_sid", pytalloc_steal(dom_sid_Type
, sid
));
1374 PyDict_SetItemString(py_domain_info
, "guid", pytalloc_steal(guid_Type
, guid
));
1377 return py_domain_info
;
1381 static PyObject
*py_pdb_getsampwnam(pytalloc_Object
*self
, PyObject
*args
)
1383 TALLOC_CTX
*frame
= talloc_stackframe();
1385 const char *username
;
1386 struct pdb_methods
*methods
;
1387 struct samu
*sam_acct
;
1388 PyObject
*py_sam_acct
;
1390 if (!PyArg_ParseTuple(args
, "s:getsampwnam", &username
)) {
1395 methods
= pytalloc_get_ptr(self
);
1397 py_sam_acct
= py_samu_new(&PySamu
, NULL
, NULL
);
1398 if (py_sam_acct
== NULL
) {
1403 sam_acct
= (struct samu
*)pytalloc_get_ptr(py_sam_acct
);
1405 status
= methods
->getsampwnam(methods
, sam_acct
, username
);
1406 if (!NT_STATUS_IS_OK(status
)) {
1407 PyErr_Format(py_pdb_error
, "Unable to get user information for '%s', (%d,%s)",
1409 NT_STATUS_V(status
),
1410 get_friendly_nt_error_msg(status
));
1411 Py_DECREF(py_sam_acct
);
1420 static PyObject
*py_pdb_getsampwsid(pytalloc_Object
*self
, PyObject
*args
)
1422 TALLOC_CTX
*frame
= talloc_stackframe();
1424 struct pdb_methods
*methods
;
1425 struct samu
*sam_acct
;
1426 PyObject
*py_sam_acct
;
1427 PyObject
*py_user_sid
;
1429 if (!PyArg_ParseTuple(args
, "O:getsampwsid", &py_user_sid
)) {
1434 methods
= pytalloc_get_ptr(self
);
1436 py_sam_acct
= py_samu_new(&PySamu
, NULL
, NULL
);
1437 if (py_sam_acct
== NULL
) {
1442 sam_acct
= (struct samu
*)pytalloc_get_ptr(py_sam_acct
);
1444 status
= methods
->getsampwsid(methods
, sam_acct
, pytalloc_get_ptr(py_user_sid
));
1445 if (!NT_STATUS_IS_OK(status
)) {
1446 PyErr_Format(py_pdb_error
, "Unable to get user information from SID, (%d,%s)",
1447 NT_STATUS_V(status
),
1448 get_friendly_nt_error_msg(status
));
1449 Py_DECREF(py_sam_acct
);
1458 static PyObject
*py_pdb_create_user(pytalloc_Object
*self
, PyObject
*args
)
1460 TALLOC_CTX
*frame
= talloc_stackframe();
1462 struct pdb_methods
*methods
;
1463 const char *username
;
1464 unsigned int acct_flags
;
1467 if (!PyArg_ParseTuple(args
, "sI:create_user", &username
, &acct_flags
)) {
1472 methods
= pytalloc_get_ptr(self
);
1474 status
= methods
->create_user(methods
, frame
, username
, acct_flags
, &rid
);
1475 if (!NT_STATUS_IS_OK(status
)) {
1476 PyErr_Format(py_pdb_error
, "Unable to create user (%s), (%d,%s)",
1478 NT_STATUS_V(status
),
1479 get_friendly_nt_error_msg(status
));
1485 return PyInt_FromLong(rid
);
1488 static PyObject
*py_pdb_delete_user(pytalloc_Object
*self
, PyObject
*args
)
1490 TALLOC_CTX
*frame
= talloc_stackframe();
1492 struct pdb_methods
*methods
;
1493 struct samu
*sam_acct
;
1494 PyObject
*py_sam_acct
;
1496 if (!PyArg_ParseTuple(args
, "O!:delete_user", &PySamu
, &py_sam_acct
)) {
1501 methods
= pytalloc_get_ptr(self
);
1503 sam_acct
= pytalloc_get_ptr(py_sam_acct
);
1505 status
= methods
->delete_user(methods
, frame
, sam_acct
);
1506 if (!NT_STATUS_IS_OK(status
)) {
1507 PyErr_Format(py_pdb_error
, "Unable to delete user, (%d,%s)",
1508 NT_STATUS_V(status
),
1509 get_friendly_nt_error_msg(status
));
1518 static PyObject
*py_pdb_add_sam_account(pytalloc_Object
*self
, PyObject
*args
)
1520 TALLOC_CTX
*frame
= talloc_stackframe();
1522 struct pdb_methods
*methods
;
1523 struct samu
*sam_acct
;
1524 PyObject
*py_sam_acct
;
1526 if (!PyArg_ParseTuple(args
, "O!:add_sam_account", &PySamu
, &py_sam_acct
)) {
1531 methods
= pytalloc_get_ptr(self
);
1533 sam_acct
= pytalloc_get_ptr(py_sam_acct
);
1535 status
= methods
->add_sam_account(methods
, sam_acct
);
1536 if (!NT_STATUS_IS_OK(status
)) {
1537 PyErr_Format(py_pdb_error
, "Unable to add sam account '%s', (%d,%s)",
1539 NT_STATUS_V(status
),
1540 get_friendly_nt_error_msg(status
));
1549 static PyObject
*py_pdb_update_sam_account(pytalloc_Object
*self
, PyObject
*args
)
1551 TALLOC_CTX
*frame
= talloc_stackframe();
1553 struct pdb_methods
*methods
;
1554 struct samu
*sam_acct
;
1555 PyObject
*py_sam_acct
;
1557 if (!PyArg_ParseTuple(args
, "O!:update_sam_account", &PySamu
, &py_sam_acct
)) {
1562 methods
= pytalloc_get_ptr(self
);
1564 sam_acct
= pytalloc_get_ptr(py_sam_acct
);
1566 status
= methods
->update_sam_account(methods
, sam_acct
);
1567 if (!NT_STATUS_IS_OK(status
)) {
1568 PyErr_Format(py_pdb_error
, "Unable to update sam account, (%d,%s)",
1569 NT_STATUS_V(status
),
1570 get_friendly_nt_error_msg(status
));
1579 static PyObject
*py_pdb_delete_sam_account(pytalloc_Object
*self
, PyObject
*args
)
1581 TALLOC_CTX
*frame
= talloc_stackframe();
1583 struct pdb_methods
*methods
;
1584 struct samu
*sam_acct
;
1585 PyObject
*py_sam_acct
;
1587 if (!PyArg_ParseTuple(args
, "O!:delete_sam_account", &PySamu
, &py_sam_acct
)) {
1592 methods
= pytalloc_get_ptr(self
);
1594 sam_acct
= pytalloc_get_ptr(py_sam_acct
);
1596 status
= methods
->delete_sam_account(methods
, sam_acct
);
1597 if (!NT_STATUS_IS_OK(status
)) {
1598 PyErr_Format(py_pdb_error
, "Unable to delete sam account, (%d,%s)",
1599 NT_STATUS_V(status
),
1600 get_friendly_nt_error_msg(status
));
1609 static PyObject
*py_pdb_rename_sam_account(pytalloc_Object
*self
, PyObject
*args
)
1611 TALLOC_CTX
*frame
= talloc_stackframe();
1613 struct pdb_methods
*methods
;
1614 struct samu
*sam_acct
;
1615 const char *new_username
;
1616 PyObject
*py_sam_acct
;
1618 if (!PyArg_ParseTuple(args
, "O!s:rename_sam_account", &PySamu
, &py_sam_acct
,
1624 methods
= pytalloc_get_ptr(self
);
1626 sam_acct
= pytalloc_get_ptr(py_sam_acct
);
1628 status
= methods
->rename_sam_account(methods
, sam_acct
, new_username
);
1629 if (!NT_STATUS_IS_OK(status
)) {
1630 PyErr_Format(py_pdb_error
, "Unable to rename sam account, (%d,%s)",
1631 NT_STATUS_V(status
),
1632 get_friendly_nt_error_msg(status
));
1642 static PyObject
*py_pdb_getgrsid(pytalloc_Object
*self
, PyObject
*args
)
1644 TALLOC_CTX
*frame
= talloc_stackframe();
1646 struct pdb_methods
*methods
;
1647 GROUP_MAP
*group_map
;
1648 struct dom_sid
*domain_sid
;
1649 PyObject
*py_domain_sid
, *py_group_map
;
1651 if (!PyArg_ParseTuple(args
, "O!:getgrsid", dom_sid_Type
, &py_domain_sid
)) {
1656 methods
= pytalloc_get_ptr(self
);
1658 domain_sid
= pytalloc_get_ptr(py_domain_sid
);
1660 py_group_map
= py_groupmap_new(&PyGroupmap
, NULL
, NULL
);
1661 if (py_group_map
== NULL
) {
1667 group_map
= pytalloc_get_ptr(py_group_map
);
1669 status
= methods
->getgrsid(methods
, group_map
, *domain_sid
);
1670 if (!NT_STATUS_IS_OK(status
)) {
1671 PyErr_Format(py_pdb_error
, "Unable to get group information by sid, (%d,%s)",
1672 NT_STATUS_V(status
),
1673 get_friendly_nt_error_msg(status
));
1679 return py_group_map
;
1683 static PyObject
*py_pdb_getgrgid(pytalloc_Object
*self
, PyObject
*args
)
1685 TALLOC_CTX
*frame
= talloc_stackframe();
1687 struct pdb_methods
*methods
;
1688 GROUP_MAP
*group_map
;
1689 PyObject
*py_group_map
;
1690 unsigned int gid_value
;
1692 if (!PyArg_ParseTuple(args
, "I:getgrgid", &gid_value
)) {
1697 methods
= pytalloc_get_ptr(self
);
1699 py_group_map
= py_groupmap_new(&PyGroupmap
, NULL
, NULL
);
1700 if (py_group_map
== NULL
) {
1706 group_map
= pytalloc_get_ptr(py_group_map
);
1708 status
= methods
->getgrgid(methods
, group_map
, gid_value
);
1709 if (!NT_STATUS_IS_OK(status
)) {
1710 PyErr_Format(py_pdb_error
, "Unable to get group information by gid, (%d,%s)",
1711 NT_STATUS_V(status
),
1712 get_friendly_nt_error_msg(status
));
1718 return py_group_map
;
1722 static PyObject
*py_pdb_getgrnam(pytalloc_Object
*self
, PyObject
*args
)
1724 TALLOC_CTX
*frame
= talloc_stackframe();
1726 struct pdb_methods
*methods
;
1727 GROUP_MAP
*group_map
;
1728 PyObject
*py_group_map
;
1729 const char *groupname
;
1731 if (!PyArg_ParseTuple(args
, "s:getgrnam", &groupname
)) {
1736 methods
= pytalloc_get_ptr(self
);
1738 py_group_map
= py_groupmap_new(&PyGroupmap
, NULL
, NULL
);
1739 if (py_group_map
== NULL
) {
1745 group_map
= pytalloc_get_ptr(py_group_map
);
1747 status
= methods
->getgrnam(methods
, group_map
, groupname
);
1748 if (!NT_STATUS_IS_OK(status
)) {
1749 PyErr_Format(py_pdb_error
, "Unable to get group information by name, (%d,%s)",
1750 NT_STATUS_V(status
),
1751 get_friendly_nt_error_msg(status
));
1757 return py_group_map
;
1761 static PyObject
*py_pdb_create_dom_group(pytalloc_Object
*self
, PyObject
*args
)
1763 TALLOC_CTX
*frame
= talloc_stackframe();
1765 struct pdb_methods
*methods
;
1766 const char *groupname
;
1769 if (!PyArg_ParseTuple(args
, "s:create_dom_group", &groupname
)) {
1774 methods
= pytalloc_get_ptr(self
);
1776 status
= methods
->create_dom_group(methods
, frame
, groupname
, &group_rid
);
1777 if (!NT_STATUS_IS_OK(status
)) {
1778 PyErr_Format(py_pdb_error
, "Unable to create domain group (%s), (%d,%s)",
1780 NT_STATUS_V(status
),
1781 get_friendly_nt_error_msg(status
));
1787 return PyInt_FromLong(group_rid
);
1791 static PyObject
*py_pdb_delete_dom_group(pytalloc_Object
*self
, PyObject
*args
)
1793 TALLOC_CTX
*frame
= talloc_stackframe();
1795 struct pdb_methods
*methods
;
1796 unsigned int group_rid
;
1798 if (!PyArg_ParseTuple(args
, "I:delete_dom_group", &group_rid
)) {
1803 methods
= pytalloc_get_ptr(self
);
1805 status
= methods
->delete_dom_group(methods
, frame
, group_rid
);
1806 if (!NT_STATUS_IS_OK(status
)) {
1807 PyErr_Format(py_pdb_error
, "Unable to delete domain group (rid=%d), (%d,%s)",
1809 NT_STATUS_V(status
),
1810 get_friendly_nt_error_msg(status
));
1820 static PyObject
*py_pdb_add_group_mapping_entry(pytalloc_Object
*self
, PyObject
*args
)
1822 TALLOC_CTX
*frame
= talloc_stackframe();
1824 struct pdb_methods
*methods
;
1825 PyObject
*py_group_map
;
1826 GROUP_MAP
*group_map
;
1828 if (!PyArg_ParseTuple(args
, "O!:add_group_mapping_entry", &PyGroupmap
, &py_group_map
)) {
1833 methods
= pytalloc_get_ptr(self
);
1835 group_map
= pytalloc_get_ptr(py_group_map
);
1837 status
= methods
->add_group_mapping_entry(methods
, group_map
);
1838 if (!NT_STATUS_IS_OK(status
)) {
1839 PyErr_Format(py_pdb_error
, "Unable to add group mapping entry, (%d,%s)",
1840 NT_STATUS_V(status
),
1841 get_friendly_nt_error_msg(status
));
1851 static PyObject
*py_pdb_update_group_mapping_entry(pytalloc_Object
*self
, PyObject
*args
)
1853 TALLOC_CTX
*frame
= talloc_stackframe();
1855 struct pdb_methods
*methods
;
1856 PyObject
*py_group_map
;
1857 GROUP_MAP
*group_map
;
1859 if (!PyArg_ParseTuple(args
, "O!:update_group_mapping_entry", &PyGroupmap
, &py_group_map
)) {
1864 methods
= pytalloc_get_ptr(self
);
1866 group_map
= pytalloc_get_ptr(py_group_map
);
1868 status
= methods
->update_group_mapping_entry(methods
, group_map
);
1869 if (!NT_STATUS_IS_OK(status
)) {
1870 PyErr_Format(py_pdb_error
, "Unable to update group mapping entry, (%d,%s)",
1871 NT_STATUS_V(status
),
1872 get_friendly_nt_error_msg(status
));
1882 static PyObject
*py_pdb_delete_group_mapping_entry(pytalloc_Object
*self
, PyObject
*args
)
1884 TALLOC_CTX
*frame
= talloc_stackframe();
1886 struct pdb_methods
*methods
;
1887 PyObject
*py_group_sid
;
1888 struct dom_sid
*group_sid
;
1890 if (!PyArg_ParseTuple(args
, "O!:delete_group_mapping_entry", dom_sid_Type
, &py_group_sid
)) {
1895 methods
= pytalloc_get_ptr(self
);
1897 group_sid
= pytalloc_get_ptr(py_group_sid
);
1899 status
= methods
->delete_group_mapping_entry(methods
, *group_sid
);
1900 if (!NT_STATUS_IS_OK(status
)) {
1901 PyErr_Format(py_pdb_error
, "Unable to delete group mapping entry, (%d,%s)",
1902 NT_STATUS_V(status
),
1903 get_friendly_nt_error_msg(status
));
1913 static PyObject
*py_pdb_enum_group_mapping(pytalloc_Object
*self
, PyObject
*args
)
1915 TALLOC_CTX
*frame
= talloc_stackframe();
1917 struct pdb_methods
*methods
;
1918 enum lsa_SidType sid_name_use
;
1919 int lsa_sidtype_value
= SID_NAME_UNKNOWN
;
1921 PyObject
*py_domain_sid
;
1922 struct dom_sid
*domain_sid
= NULL
;
1923 GROUP_MAP
**gmap
= NULL
;
1924 GROUP_MAP
*group_map
;
1926 PyObject
*py_gmap_list
, *py_group_map
;
1929 py_domain_sid
= Py_None
;
1932 if (!PyArg_ParseTuple(args
, "|O!ii:enum_group_mapping", dom_sid_Type
, &py_domain_sid
,
1933 &lsa_sidtype_value
, &unix_only
)) {
1938 methods
= pytalloc_get_ptr(self
);
1940 sid_name_use
= lsa_sidtype_value
;
1942 if (py_domain_sid
!= Py_None
) {
1943 domain_sid
= pytalloc_get_ptr(py_domain_sid
);
1946 status
= methods
->enum_group_mapping(methods
, domain_sid
, sid_name_use
,
1947 &gmap
, &num_entries
, unix_only
);
1948 if (!NT_STATUS_IS_OK(status
)) {
1949 PyErr_Format(py_pdb_error
, "Unable to enumerate group mappings, (%d,%s)",
1950 NT_STATUS_V(status
),
1951 get_friendly_nt_error_msg(status
));
1956 py_gmap_list
= PyList_New(0);
1957 if (py_gmap_list
== NULL
) {
1963 for(i
=0; i
<num_entries
; i
++) {
1964 py_group_map
= py_groupmap_new(&PyGroupmap
, NULL
, NULL
);
1966 group_map
= pytalloc_get_ptr(py_group_map
);
1967 *group_map
= *gmap
[i
];
1968 talloc_steal(group_map
, gmap
[i
]->nt_name
);
1969 talloc_steal(group_map
, gmap
[i
]->comment
);
1971 PyList_Append(py_gmap_list
, py_group_map
);
1978 return py_gmap_list
;
1982 static PyObject
*py_pdb_enum_group_members(pytalloc_Object
*self
, PyObject
*args
)
1984 TALLOC_CTX
*frame
= talloc_stackframe();
1986 struct pdb_methods
*methods
;
1987 PyObject
*py_group_sid
;
1988 struct dom_sid
*group_sid
;
1989 uint32_t *member_rids
;
1991 PyObject
*py_sid_list
;
1992 struct dom_sid
*domain_sid
, *member_sid
;
1995 if (!PyArg_ParseTuple(args
, "O!:enum_group_members", dom_sid_Type
, &py_group_sid
)) {
2000 methods
= pytalloc_get_ptr(self
);
2002 group_sid
= pytalloc_get_ptr(py_group_sid
);
2004 status
= methods
->enum_group_members(methods
, frame
, group_sid
,
2005 &member_rids
, &num_members
);
2006 if (!NT_STATUS_IS_OK(status
)) {
2007 PyErr_Format(py_pdb_error
, "Unable to enumerate group members, (%d,%s)",
2008 NT_STATUS_V(status
),
2009 get_friendly_nt_error_msg(status
));
2014 py_sid_list
= PyList_New(0);
2015 if (py_sid_list
== NULL
) {
2021 domain_sid
= get_global_sam_sid();
2023 for(i
=0; i
<num_members
; i
++) {
2024 member_sid
= dom_sid_add_rid(frame
, domain_sid
, member_rids
[i
]);
2025 PyList_Append(py_sid_list
, pytalloc_steal(dom_sid_Type
, member_sid
));
2033 static PyObject
*py_pdb_enum_group_memberships(pytalloc_Object
*self
, PyObject
*args
)
2035 TALLOC_CTX
*frame
= talloc_stackframe();
2037 struct pdb_methods
*methods
;
2040 struct samu
*sam_acct
;
2041 PyObject
*py_sam_acct
;
2042 PyObject
*py_sid_list
;
2043 struct dom_sid
*user_group_sids
= NULL
;
2044 gid_t
*user_group_ids
= NULL
;
2045 uint32_t num_groups
= 0;
2047 if (!PyArg_ParseTuple(args
, "O!:enum_group_memberships", &PySamu
, &py_sam_acct
)) {
2052 methods
= pytalloc_get_ptr(self
);
2054 sam_acct
= pytalloc_get_ptr(py_sam_acct
);
2056 status
= methods
->enum_group_memberships(methods
, frame
, sam_acct
,
2057 &user_group_sids
, &user_group_ids
, &num_groups
);
2058 if (!NT_STATUS_IS_OK(status
)) {
2059 PyErr_Format(py_pdb_error
, "Unable to enumerate group memberships, (%d,%s)",
2060 NT_STATUS_V(status
),
2061 get_friendly_nt_error_msg(status
));
2066 py_sid_list
= PyList_New(0);
2067 if (py_sid_list
== NULL
) {
2073 for(i
=0; i
<num_groups
; i
++) {
2074 PyList_Append(py_sid_list
, pytalloc_steal(dom_sid_Type
, dom_sid_dup(NULL
, &user_group_sids
[i
])));
2082 static PyObject
*py_pdb_add_groupmem(pytalloc_Object
*self
, PyObject
*args
)
2084 TALLOC_CTX
*frame
= talloc_stackframe();
2086 struct pdb_methods
*methods
;
2087 uint32_t group_rid
, member_rid
;
2089 if (!PyArg_ParseTuple(args
, "II:add_groupmem", &group_rid
, &member_rid
)) {
2094 methods
= pytalloc_get_ptr(self
);
2096 status
= methods
->add_groupmem(methods
, frame
, group_rid
, member_rid
);
2097 if (!NT_STATUS_IS_OK(status
)) {
2098 PyErr_Format(py_pdb_error
, "Unable to add group member, (%d,%s)",
2099 NT_STATUS_V(status
),
2100 get_friendly_nt_error_msg(status
));
2110 static PyObject
*py_pdb_del_groupmem(pytalloc_Object
*self
, PyObject
*args
)
2112 TALLOC_CTX
*frame
= talloc_stackframe();
2114 struct pdb_methods
*methods
;
2115 uint32_t group_rid
, member_rid
;
2117 if (!PyArg_ParseTuple(args
, "II:del_groupmem", &group_rid
, &member_rid
)) {
2122 methods
= pytalloc_get_ptr(self
);
2124 status
= methods
->del_groupmem(methods
, frame
, group_rid
, member_rid
);
2125 if (!NT_STATUS_IS_OK(status
)) {
2126 PyErr_Format(py_pdb_error
, "Unable to rename sam account, (%d,%s)",
2127 NT_STATUS_V(status
),
2128 get_friendly_nt_error_msg(status
));
2138 static PyObject
*py_pdb_create_alias(pytalloc_Object
*self
, PyObject
*args
)
2140 TALLOC_CTX
*frame
= talloc_stackframe();
2142 struct pdb_methods
*methods
;
2143 const char *alias_name
;
2146 if (!PyArg_ParseTuple(args
, "s:create_alias", &alias_name
)) {
2151 methods
= pytalloc_get_ptr(self
);
2153 status
= methods
->create_alias(methods
, alias_name
, &rid
);
2154 if (!NT_STATUS_IS_OK(status
)) {
2155 PyErr_Format(py_pdb_error
, "Unable to create alias (%s), (%d,%s)",
2157 NT_STATUS_V(status
),
2158 get_friendly_nt_error_msg(status
));
2164 return PyInt_FromLong(rid
);
2168 static PyObject
*py_pdb_delete_alias(pytalloc_Object
*self
, PyObject
*args
)
2170 TALLOC_CTX
*frame
= talloc_stackframe();
2172 struct pdb_methods
*methods
;
2173 PyObject
*py_alias_sid
;
2174 struct dom_sid
*alias_sid
;
2176 if (!PyArg_ParseTuple(args
, "O!:delete_alias", dom_sid_Type
, &py_alias_sid
)) {
2181 methods
= pytalloc_get_ptr(self
);
2183 alias_sid
= pytalloc_get_ptr(py_alias_sid
);
2185 status
= methods
->delete_alias(methods
, alias_sid
);
2186 if (!NT_STATUS_IS_OK(status
)) {
2187 PyErr_Format(py_pdb_error
, "Unable to delete alias, (%d,%s)",
2188 NT_STATUS_V(status
),
2189 get_friendly_nt_error_msg(status
));
2199 static PyObject
*py_pdb_get_aliasinfo(pytalloc_Object
*self
, PyObject
*args
)
2201 TALLOC_CTX
*frame
= talloc_stackframe();
2203 struct pdb_methods
*methods
;
2204 PyObject
*py_alias_sid
;
2205 struct dom_sid
*alias_sid
;
2206 struct acct_info
*alias_info
;
2207 PyObject
*py_alias_info
;
2209 if (!PyArg_ParseTuple(args
, "O!:get_aliasinfo", dom_sid_Type
, &py_alias_sid
)) {
2214 methods
= pytalloc_get_ptr(self
);
2216 alias_sid
= pytalloc_get_ptr(py_alias_sid
);
2218 alias_info
= talloc_zero(frame
, struct acct_info
);
2225 status
= methods
->get_aliasinfo(methods
, alias_sid
, alias_info
);
2226 if (!NT_STATUS_IS_OK(status
)) {
2227 PyErr_Format(py_pdb_error
, "Unable to get alias information, (%d,%s)",
2228 NT_STATUS_V(status
),
2229 get_friendly_nt_error_msg(status
));
2234 py_alias_info
= PyDict_New();
2235 if (py_alias_info
== NULL
) {
2241 PyDict_SetItemString(py_alias_info
, "acct_name",
2242 PyString_FromString(alias_info
->acct_name
));
2243 PyDict_SetItemString(py_alias_info
, "acct_desc",
2244 PyString_FromString(alias_info
->acct_desc
));
2245 PyDict_SetItemString(py_alias_info
, "rid",
2246 PyInt_FromLong(alias_info
->rid
));
2249 return py_alias_info
;
2253 static PyObject
*py_pdb_set_aliasinfo(pytalloc_Object
*self
, PyObject
*args
)
2255 TALLOC_CTX
*frame
= talloc_stackframe();
2257 struct pdb_methods
*methods
;
2258 PyObject
*py_alias_sid
, *py_alias_info
;
2259 struct dom_sid
*alias_sid
;
2260 struct acct_info alias_info
;
2262 if (!PyArg_ParseTuple(args
, "O!O:set_alias_info", dom_sid_Type
, &py_alias_sid
,
2268 methods
= pytalloc_get_ptr(self
);
2270 alias_sid
= pytalloc_get_ptr(py_alias_sid
);
2272 fstrcpy(alias_info
.acct_name
, PyString_AsString(PyDict_GetItemString(py_alias_info
, "acct_name")));
2273 fstrcpy(alias_info
.acct_desc
, PyString_AsString(PyDict_GetItemString(py_alias_info
, "acct_desc")));
2275 status
= methods
->set_aliasinfo(methods
, alias_sid
, &alias_info
);
2276 if (!NT_STATUS_IS_OK(status
)) {
2277 PyErr_Format(py_pdb_error
, "Unable to set alias information, (%d,%s)",
2278 NT_STATUS_V(status
),
2279 get_friendly_nt_error_msg(status
));
2289 static PyObject
*py_pdb_add_aliasmem(pytalloc_Object
*self
, PyObject
*args
)
2291 TALLOC_CTX
*frame
= talloc_stackframe();
2293 struct pdb_methods
*methods
;
2294 PyObject
*py_alias_sid
, *py_member_sid
;
2295 struct dom_sid
*alias_sid
, *member_sid
;
2297 if (!PyArg_ParseTuple(args
, "O!O!:add_aliasmem", dom_sid_Type
, &py_alias_sid
,
2298 dom_sid_Type
, &py_member_sid
)) {
2303 methods
= pytalloc_get_ptr(self
);
2305 alias_sid
= pytalloc_get_ptr(py_alias_sid
);
2306 member_sid
= pytalloc_get_ptr(py_member_sid
);
2308 status
= methods
->add_aliasmem(methods
, alias_sid
, member_sid
);
2309 if (!NT_STATUS_IS_OK(status
)) {
2310 PyErr_Format(py_pdb_error
, "Unable to add member to alias, (%d,%s)",
2311 NT_STATUS_V(status
),
2312 get_friendly_nt_error_msg(status
));
2322 static PyObject
*py_pdb_del_aliasmem(pytalloc_Object
*self
, PyObject
*args
)
2324 TALLOC_CTX
*frame
= talloc_stackframe();
2326 struct pdb_methods
*methods
;
2327 PyObject
*py_alias_sid
, *py_member_sid
;
2328 const struct dom_sid
*alias_sid
, *member_sid
;
2330 if (!PyArg_ParseTuple(args
, "O!O!:del_aliasmem", dom_sid_Type
, &py_alias_sid
,
2331 dom_sid_Type
, &py_member_sid
)) {
2336 methods
= pytalloc_get_ptr(self
);
2338 alias_sid
= pytalloc_get_ptr(py_alias_sid
);
2339 member_sid
= pytalloc_get_ptr(py_member_sid
);
2341 status
= methods
->del_aliasmem(methods
, alias_sid
, member_sid
);
2342 if (!NT_STATUS_IS_OK(status
)) {
2343 PyErr_Format(py_pdb_error
, "Unable to delete member from alias, (%d,%s)",
2344 NT_STATUS_V(status
),
2345 get_friendly_nt_error_msg(status
));
2355 static PyObject
*py_pdb_enum_aliasmem(pytalloc_Object
*self
, PyObject
*args
)
2357 TALLOC_CTX
*frame
= talloc_stackframe();
2359 struct pdb_methods
*methods
;
2360 PyObject
*py_alias_sid
;
2361 struct dom_sid
*alias_sid
, *member_sid
, *tmp_sid
;
2362 PyObject
*py_member_list
, *py_member_sid
;
2366 if (!PyArg_ParseTuple(args
, "O!:enum_aliasmem", dom_sid_Type
, &py_alias_sid
)) {
2371 methods
= pytalloc_get_ptr(self
);
2373 alias_sid
= pytalloc_get_ptr(py_alias_sid
);
2375 status
= methods
->enum_aliasmem(methods
, alias_sid
, frame
, &member_sid
, &num_members
);
2376 if (!NT_STATUS_IS_OK(status
)) {
2377 PyErr_Format(py_pdb_error
, "Unable to enumerate members for alias, (%d,%s)",
2378 NT_STATUS_V(status
),
2379 get_friendly_nt_error_msg(status
));
2384 py_member_list
= PyList_New(0);
2385 if (py_member_list
== NULL
) {
2391 for(i
=0; i
<num_members
; i
++) {
2392 py_member_sid
= pytalloc_new(struct dom_sid
, dom_sid_Type
);
2393 if (py_member_sid
== NULL
) {
2398 tmp_sid
= pytalloc_get_ptr(py_member_sid
);
2399 *tmp_sid
= member_sid
[i
];
2400 PyList_Append(py_member_list
, py_member_sid
);
2404 return py_member_list
;
2408 static PyObject
*py_pdb_get_account_policy(pytalloc_Object
*self
)
2410 TALLOC_CTX
*frame
= talloc_stackframe();
2412 struct pdb_methods
*methods
;
2413 PyObject
*py_acct_policy
;
2417 enum pdb_policy_type type
;
2419 methods
= pytalloc_get_ptr(self
);
2421 py_acct_policy
= PyDict_New();
2422 if (py_acct_policy
== NULL
) {
2428 account_policy_names_list(frame
, &names
, &count
);
2429 for (i
=0; i
<count
; i
++) {
2430 type
= account_policy_name_to_typenum(names
[i
]);
2431 status
= methods
->get_account_policy(methods
, type
, &value
);
2432 if (NT_STATUS_IS_OK(status
)) {
2433 PyDict_SetItemString(py_acct_policy
, names
[i
], Py_BuildValue("i", value
));
2438 return py_acct_policy
;
2442 static PyObject
*py_pdb_set_account_policy(pytalloc_Object
*self
, PyObject
*args
)
2444 TALLOC_CTX
*frame
= talloc_stackframe();
2446 struct pdb_methods
*methods
;
2447 PyObject
*py_acct_policy
, *py_value
;
2450 enum pdb_policy_type type
;
2452 if (!PyArg_ParseTuple(args
, "O!:set_account_policy", PyDict_Type
, &py_acct_policy
)) {
2457 methods
= pytalloc_get_ptr(self
);
2459 account_policy_names_list(frame
, &names
, &count
);
2460 for (i
=0; i
<count
; i
++) {
2461 if ((py_value
= PyDict_GetItemString(py_acct_policy
, names
[i
])) != NULL
) {
2462 type
= account_policy_name_to_typenum(names
[i
]);
2463 status
= methods
->set_account_policy(methods
, type
, PyInt_AsLong(py_value
));
2464 if (!NT_STATUS_IS_OK(status
)) {
2465 PyErr_Format(py_pdb_error
, "Error setting account policy (%s), (%d,%s)",
2467 NT_STATUS_V(status
),
2468 get_friendly_nt_error_msg(status
));
2477 static PyObject
*py_pdb_search_users(pytalloc_Object
*self
, PyObject
*args
)
2479 TALLOC_CTX
*frame
= talloc_stackframe();
2481 struct pdb_methods
*methods
;
2482 unsigned int acct_flags
;
2483 struct pdb_search
*search
;
2484 struct samr_displayentry
*entry
;
2485 PyObject
*py_userlist
, *py_dict
;
2487 if (!PyArg_ParseTuple(args
, "I:search_users", &acct_flags
)) {
2492 methods
= pytalloc_get_ptr(self
);
2494 search
= talloc_zero(frame
, struct pdb_search
);
2495 if (search
== NULL
) {
2501 if (!methods
->search_users(methods
, search
, acct_flags
)) {
2502 PyErr_Format(py_pdb_error
, "Unable to search users, (%d,%s)",
2503 NT_STATUS_V(status
),
2504 get_friendly_nt_error_msg(status
));
2509 entry
= talloc_zero(frame
, struct samr_displayentry
);
2510 if (entry
== NULL
) {
2516 py_userlist
= PyList_New(0);
2517 if (py_userlist
== NULL
) {
2523 while (search
->next_entry(search
, entry
)) {
2524 py_dict
= PyDict_New();
2525 if (py_dict
== NULL
) {
2528 PyDict_SetItemString(py_dict
, "idx", PyInt_FromLong(entry
->idx
));
2529 PyDict_SetItemString(py_dict
, "rid", PyInt_FromLong(entry
->rid
));
2530 PyDict_SetItemString(py_dict
, "acct_flags", PyInt_FromLong(entry
->acct_flags
));
2531 PyDict_SetItemString(py_dict
, "account_name", PyString_FromString(entry
->account_name
));
2532 PyDict_SetItemString(py_dict
, "fullname", PyString_FromString(entry
->fullname
));
2533 PyDict_SetItemString(py_dict
, "description", PyString_FromString(entry
->description
));
2534 PyList_Append(py_userlist
, py_dict
);
2537 search
->search_end(search
);
2544 static PyObject
*py_pdb_search_groups(pytalloc_Object
*self
)
2546 TALLOC_CTX
*frame
= talloc_stackframe();
2548 struct pdb_methods
*methods
;
2549 struct pdb_search
*search
;
2550 struct samr_displayentry
*entry
;
2551 PyObject
*py_grouplist
, *py_dict
;
2553 methods
= pytalloc_get_ptr(self
);
2555 search
= talloc_zero(frame
, struct pdb_search
);
2556 if (search
== NULL
) {
2562 if (!methods
->search_groups(methods
, search
)) {
2563 PyErr_Format(py_pdb_error
, "Unable to search groups, (%d,%s)",
2564 NT_STATUS_V(status
),
2565 get_friendly_nt_error_msg(status
));
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
)) {
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
) {