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 "python/py3compat.h"
24 #include "lib/util/talloc_stack.h"
25 #include "libcli/security/security.h"
26 #include "librpc/gen_ndr/idmap.h"
31 #ifndef Py_TYPE /* Py_TYPE is only available on Python > 2.6 */
32 #define Py_TYPE(ob) (((PyObject*)(ob))->ob_type)
36 #define PY_CHECK_TYPE(type, var, fail) \
37 if (!PyObject_TypeCheck(var, type)) {\
38 PyErr_Format(PyExc_TypeError, __location__ ": Expected type '%s' for '%s' of type '%s'", (type)->tp_name, #var, Py_TYPE(var)->tp_name); \
44 static PyTypeObject
*dom_sid_Type
= NULL
;
45 static PyTypeObject
*security_Type
= NULL
;
46 static PyTypeObject
*guid_Type
= NULL
;
48 static PyTypeObject PySamu
;
49 static PyTypeObject PyGroupmap
;
50 static PyTypeObject PyPDB
;
52 static PyObject
*py_pdb_error
;
54 void initpassdb(void);
57 /************************** PIDL Autogeneratd ******************************/
59 static PyObject
*py_samu_get_logon_time(PyObject
*obj
, void *closure
)
61 TALLOC_CTX
*frame
= talloc_stackframe();
62 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
63 PyObject
*py_logon_time
;
65 py_logon_time
= PyInt_FromLong(pdb_get_logon_time(sam_acct
));
70 static int py_samu_set_logon_time(PyObject
*obj
, PyObject
*value
, void *closure
)
72 TALLOC_CTX
*frame
= talloc_stackframe();
73 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
75 PY_CHECK_TYPE(&PyInt_Type
, value
, return -1;);
76 if (!pdb_set_logon_time(sam_acct
, PyInt_AsLong(value
), PDB_CHANGED
)) {
84 static PyObject
*py_samu_get_logoff_time(PyObject
*obj
, void *closure
)
86 TALLOC_CTX
*frame
= talloc_stackframe();
87 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
88 PyObject
*py_logoff_time
;
90 py_logoff_time
= PyInt_FromLong(pdb_get_logoff_time(sam_acct
));
92 return py_logoff_time
;
95 static int py_samu_set_logoff_time(PyObject
*obj
, PyObject
*value
, void *closure
)
97 TALLOC_CTX
*frame
= talloc_stackframe();
98 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
100 PY_CHECK_TYPE(&PyInt_Type
, value
, return -1;);
101 if (!pdb_set_logoff_time(sam_acct
, PyInt_AsLong(value
), PDB_CHANGED
)) {
109 static PyObject
*py_samu_get_kickoff_time(PyObject
*obj
, void *closure
)
111 TALLOC_CTX
*frame
= talloc_stackframe();
112 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
113 PyObject
*py_kickoff_time
;
115 py_kickoff_time
= PyInt_FromLong(pdb_get_kickoff_time(sam_acct
));
117 return py_kickoff_time
;
120 static int py_samu_set_kickoff_time(PyObject
*obj
, PyObject
*value
, void *closure
)
122 TALLOC_CTX
*frame
= talloc_stackframe();
123 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
125 PY_CHECK_TYPE(&PyInt_Type
, value
, return -1;);
126 if (!pdb_set_kickoff_time(sam_acct
, PyInt_AsLong(value
), PDB_CHANGED
)) {
134 static PyObject
*py_samu_get_bad_password_time(PyObject
*obj
, void *closure
)
136 TALLOC_CTX
*frame
= talloc_stackframe();
137 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
138 PyObject
*py_bad_password_time
;
140 py_bad_password_time
= PyInt_FromLong(pdb_get_bad_password_time(sam_acct
));
142 return py_bad_password_time
;
145 static int py_samu_set_bad_password_time(PyObject
*obj
, PyObject
*value
, void *closure
)
147 TALLOC_CTX
*frame
= talloc_stackframe();
148 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
150 PY_CHECK_TYPE(&PyInt_Type
, value
, return -1;);
151 if (!pdb_set_bad_password_time(sam_acct
, PyInt_AsLong(value
), PDB_CHANGED
)) {
159 static PyObject
*py_samu_get_pass_last_set_time(PyObject
*obj
, void *closure
)
161 TALLOC_CTX
*frame
= talloc_stackframe();
162 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
163 PyObject
*py_pass_last_set_time
;
165 py_pass_last_set_time
= PyInt_FromLong(pdb_get_pass_last_set_time(sam_acct
));
167 return py_pass_last_set_time
;
170 static int py_samu_set_pass_last_set_time(PyObject
*obj
, PyObject
*value
, void *closure
)
172 TALLOC_CTX
*frame
= talloc_stackframe();
173 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
175 PY_CHECK_TYPE(&PyInt_Type
, value
, return -1;);
176 if (!pdb_set_pass_last_set_time(sam_acct
, PyInt_AsLong(value
), PDB_CHANGED
)) {
184 static PyObject
*py_samu_get_pass_can_change_time(PyObject
*obj
, void *closure
)
186 TALLOC_CTX
*frame
= talloc_stackframe();
187 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
188 PyObject
*py_pass_can_change_time
;
190 py_pass_can_change_time
= PyInt_FromLong(pdb_get_pass_can_change_time(sam_acct
));
192 return py_pass_can_change_time
;
195 static int py_samu_set_pass_can_change_time(PyObject
*obj
, PyObject
*value
, void *closure
)
197 TALLOC_CTX
*frame
= talloc_stackframe();
198 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
200 PY_CHECK_TYPE(&PyInt_Type
, value
, return -1;);
201 if (!pdb_set_pass_can_change_time(sam_acct
, PyInt_AsLong(value
), PDB_CHANGED
)) {
209 static PyObject
*py_samu_get_pass_must_change_time(PyObject
*obj
, void *closure
)
211 TALLOC_CTX
*frame
= talloc_stackframe();
212 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
213 PyObject
*py_pass_must_change_time
;
215 py_pass_must_change_time
= PyInt_FromLong(pdb_get_pass_must_change_time(sam_acct
));
217 return py_pass_must_change_time
;
220 static int py_samu_set_pass_must_change_time(PyObject
*obj
, PyObject
*value
, void *closure
)
222 TALLOC_CTX
*frame
= talloc_stackframe();
223 PY_CHECK_TYPE(&PyInt_Type
, value
, return -1;);
225 /* TODO: make this not a get/set or give a better exception */
230 static PyObject
*py_samu_get_username(PyObject
*obj
, void *closure
)
232 TALLOC_CTX
*frame
= talloc_stackframe();
233 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
234 PyObject
*py_username
;
235 const char *username
;
237 username
= pdb_get_username(sam_acct
);
238 if (username
== NULL
) {
242 py_username
= PyStr_FromString(username
);
247 static int py_samu_set_username(PyObject
*obj
, PyObject
*value
, void *closure
)
249 TALLOC_CTX
*frame
= talloc_stackframe();
250 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
252 PY_CHECK_TYPE(&PyStr_Type
, value
, return -1;);
253 if (!pdb_set_username(sam_acct
, PyStr_AsString(value
), PDB_CHANGED
)) {
261 static PyObject
*py_samu_get_domain(PyObject
*obj
, void *closure
)
263 TALLOC_CTX
*frame
= talloc_stackframe();
264 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
268 domain
= pdb_get_domain(sam_acct
);
269 if (domain
== NULL
) {
273 py_domain
= PyStr_FromString(domain
);
278 static int py_samu_set_domain(PyObject
*obj
, PyObject
*value
, void *closure
)
280 TALLOC_CTX
*frame
= talloc_stackframe();
281 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
283 PY_CHECK_TYPE(&PyStr_Type
, value
, return -1;);
284 if (!pdb_set_domain(sam_acct
, PyStr_AsString(value
), PDB_CHANGED
)) {
292 static PyObject
*py_samu_get_nt_username(PyObject
*obj
, void *closure
)
294 TALLOC_CTX
*frame
= talloc_stackframe();
295 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
296 PyObject
*py_nt_username
;
297 const char *nt_username
;
299 nt_username
= pdb_get_nt_username(sam_acct
);
300 if (nt_username
== NULL
) {
304 py_nt_username
= PyStr_FromString(nt_username
);
306 return py_nt_username
;
309 static int py_samu_set_nt_username(PyObject
*obj
, PyObject
*value
, void *closure
)
311 TALLOC_CTX
*frame
= talloc_stackframe();
312 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
314 PY_CHECK_TYPE(&PyStr_Type
, value
, return -1;);
315 if (!pdb_set_nt_username(sam_acct
, PyStr_AsString(value
), PDB_CHANGED
)) {
323 static PyObject
*py_samu_get_full_name(PyObject
*obj
, void *closure
)
325 TALLOC_CTX
*frame
= talloc_stackframe();
326 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
327 PyObject
*py_full_name
;
328 const char *full_name
;
330 full_name
= pdb_get_fullname(sam_acct
);
331 if (full_name
== NULL
) {
335 py_full_name
= PyStr_FromString(full_name
);
340 static int py_samu_set_full_name(PyObject
*obj
, PyObject
*value
, void *closure
)
342 TALLOC_CTX
*frame
= talloc_stackframe();
343 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
345 PY_CHECK_TYPE(&PyStr_Type
, value
, return -1;);
346 if (!pdb_set_fullname(sam_acct
, PyStr_AsString(value
), PDB_CHANGED
)) {
354 static PyObject
*py_samu_get_home_dir(PyObject
*obj
, void *closure
)
356 TALLOC_CTX
*frame
= talloc_stackframe();
357 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
358 PyObject
*py_home_dir
;
359 const char *home_dir
;
361 home_dir
= pdb_get_homedir(sam_acct
);
362 if (home_dir
== NULL
) {
366 py_home_dir
= PyStr_FromString(home_dir
);
371 static int py_samu_set_home_dir(PyObject
*obj
, PyObject
*value
, void *closure
)
373 TALLOC_CTX
*frame
= talloc_stackframe();
374 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
376 PY_CHECK_TYPE(&PyStr_Type
, value
, return -1;);
377 if (!pdb_set_homedir(sam_acct
, PyStr_AsString(value
), PDB_CHANGED
)) {
385 static PyObject
*py_samu_get_dir_drive(PyObject
*obj
, void *closure
)
387 TALLOC_CTX
*frame
= talloc_stackframe();
388 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
389 PyObject
*py_dir_drive
;
390 const char *dir_drive
;
392 dir_drive
= pdb_get_dir_drive(sam_acct
);
393 if (dir_drive
== NULL
) {
397 py_dir_drive
= PyStr_FromString(dir_drive
);
402 static int py_samu_set_dir_drive(PyObject
*obj
, PyObject
*value
, void *closure
)
404 TALLOC_CTX
*frame
= talloc_stackframe();
405 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
407 PY_CHECK_TYPE(&PyStr_Type
, value
, return -1;);
408 if (!pdb_set_dir_drive(sam_acct
, PyStr_AsString(value
), PDB_CHANGED
)) {
416 static PyObject
*py_samu_get_logon_script(PyObject
*obj
, void *closure
)
418 TALLOC_CTX
*frame
= talloc_stackframe();
419 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
420 PyObject
*py_logon_script
;
421 const char *logon_script
;
423 logon_script
= pdb_get_logon_script(sam_acct
);
424 if (logon_script
== NULL
) {
428 py_logon_script
= PyStr_FromString(logon_script
);
430 return py_logon_script
;
433 static int py_samu_set_logon_script(PyObject
*obj
, PyObject
*value
, void *closure
)
435 TALLOC_CTX
*frame
= talloc_stackframe();
436 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
438 PY_CHECK_TYPE(&PyStr_Type
, value
, return -1;);
439 if (!pdb_set_logon_script(sam_acct
, PyStr_AsString(value
), PDB_CHANGED
)) {
447 static PyObject
*py_samu_get_profile_path(PyObject
*obj
, void *closure
)
449 TALLOC_CTX
*frame
= talloc_stackframe();
450 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
451 PyObject
*py_profile_path
;
452 const char *profile_path
;
454 profile_path
= pdb_get_profile_path(sam_acct
);
455 if (profile_path
== NULL
) {
459 py_profile_path
= PyStr_FromString(profile_path
);
461 return py_profile_path
;
464 static int py_samu_set_profile_path(PyObject
*obj
, PyObject
*value
, void *closure
)
466 TALLOC_CTX
*frame
= talloc_stackframe();
467 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
469 PY_CHECK_TYPE(&PyStr_Type
, value
, return -1;);
470 if (!pdb_set_profile_path(sam_acct
, PyStr_AsString(value
), PDB_CHANGED
)) {
478 static PyObject
*py_samu_get_acct_desc(PyObject
*obj
, void *closure
)
480 TALLOC_CTX
*frame
= talloc_stackframe();
481 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
482 PyObject
*py_acct_desc
;
483 const char *acct_desc
;
485 acct_desc
= pdb_get_acct_desc(sam_acct
);
486 if (acct_desc
== NULL
) {
490 py_acct_desc
= PyStr_FromString(acct_desc
);
495 static int py_samu_set_acct_desc(PyObject
*obj
, PyObject
*value
, void *closure
)
497 TALLOC_CTX
*frame
= talloc_stackframe();
498 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
500 PY_CHECK_TYPE(&PyStr_Type
, value
, return -1;);
501 if (!pdb_set_acct_desc(sam_acct
, PyStr_AsString(value
), PDB_CHANGED
)) {
509 static PyObject
*py_samu_get_workstations(PyObject
*obj
, void *closure
)
511 TALLOC_CTX
*frame
= talloc_stackframe();
512 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
513 PyObject
*py_workstations
;
514 const char *workstations
;
516 workstations
= pdb_get_workstations(sam_acct
);
517 if (workstations
== NULL
) {
521 py_workstations
= PyStr_FromString(workstations
);
523 return py_workstations
;
526 static int py_samu_set_workstations(PyObject
*obj
, PyObject
*value
, void *closure
)
528 TALLOC_CTX
*frame
= talloc_stackframe();
529 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
531 PY_CHECK_TYPE(&PyStr_Type
, value
, return -1;);
532 if (!pdb_set_workstations(sam_acct
, PyStr_AsString(value
), PDB_CHANGED
)) {
540 static PyObject
*py_samu_get_comment(PyObject
*obj
, void *closure
)
542 TALLOC_CTX
*frame
= talloc_stackframe();
543 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
544 PyObject
*py_comment
;
547 comment
= pdb_get_comment(sam_acct
);
548 if (comment
== NULL
) {
552 py_comment
= PyStr_FromString(comment
);
557 static int py_samu_set_comment(PyObject
*obj
, PyObject
*value
, void *closure
)
559 TALLOC_CTX
*frame
= talloc_stackframe();
560 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
562 PY_CHECK_TYPE(&PyStr_Type
, value
, return -1;);
563 if (!pdb_set_comment(sam_acct
, PyStr_AsString(value
), PDB_CHANGED
)) {
571 static PyObject
*py_samu_get_munged_dial(PyObject
*obj
, void *closure
)
573 TALLOC_CTX
*frame
= talloc_stackframe();
574 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
575 PyObject
*py_munged_dial
;
576 const char *munged_dial
;
578 munged_dial
= pdb_get_munged_dial(sam_acct
);
579 if (munged_dial
== NULL
) {
583 py_munged_dial
= PyStr_FromString(munged_dial
);
585 return py_munged_dial
;
588 static int py_samu_set_munged_dial(PyObject
*obj
, PyObject
*value
, void *closure
)
590 TALLOC_CTX
*frame
= talloc_stackframe();
591 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
593 PY_CHECK_TYPE(&PyStr_Type
, value
, return -1;);
594 if (!pdb_set_munged_dial(sam_acct
, PyStr_AsString(value
), PDB_CHANGED
)) {
602 static PyObject
*py_samu_get_user_sid(PyObject
*obj
, void *closure
)
604 TALLOC_CTX
*frame
= talloc_stackframe();
605 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
606 PyObject
*py_user_sid
;
607 const struct dom_sid
*user_sid
;
608 struct dom_sid
*copy_user_sid
;
611 user_sid
= pdb_get_user_sid(sam_acct
);
612 if(user_sid
== NULL
) {
616 mem_ctx
= talloc_new(NULL
);
617 if (mem_ctx
== NULL
) {
622 copy_user_sid
= dom_sid_dup(mem_ctx
, user_sid
);
623 if (copy_user_sid
== NULL
) {
625 talloc_free(mem_ctx
);
630 py_user_sid
= pytalloc_steal(dom_sid_Type
, copy_user_sid
);
632 talloc_free(mem_ctx
);
638 static int py_samu_set_user_sid(PyObject
*obj
, PyObject
*value
, void *closure
)
640 TALLOC_CTX
*frame
= talloc_stackframe();
641 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
643 PY_CHECK_TYPE(dom_sid_Type
, value
, return -1;);
644 if (!pdb_set_user_sid(sam_acct
, (struct dom_sid
*)pytalloc_get_ptr(value
), PDB_CHANGED
)) {
652 static PyObject
*py_samu_get_group_sid(PyObject
*obj
, void *closure
)
654 TALLOC_CTX
*frame
= talloc_stackframe();
655 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
656 const struct dom_sid
*group_sid
;
657 struct dom_sid
*copy_group_sid
;
659 group_sid
= pdb_get_group_sid(sam_acct
);
660 if (group_sid
== NULL
) {
664 copy_group_sid
= dom_sid_dup(NULL
, group_sid
);
665 if (copy_group_sid
== NULL
) {
672 return pytalloc_steal(dom_sid_Type
, copy_group_sid
);
675 static int py_samu_set_group_sid(PyObject
*obj
, PyObject
*value
, void *closure
)
677 TALLOC_CTX
*frame
= talloc_stackframe();
678 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
680 PY_CHECK_TYPE(dom_sid_Type
, value
, return -1;);
681 if (!pdb_set_group_sid(sam_acct
, (struct dom_sid
*)pytalloc_get_ptr(value
), PDB_CHANGED
)) {
689 static PyObject
*py_samu_get_lanman_passwd(PyObject
*obj
, void *closure
)
691 TALLOC_CTX
*frame
= talloc_stackframe();
692 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
696 lm_pw
= (const char *)pdb_get_lanman_passwd(sam_acct
);
701 py_lm_pw
= PyBytes_FromStringAndSize(lm_pw
, LM_HASH_LEN
);
706 static int py_samu_set_lanman_passwd(PyObject
*obj
, PyObject
*value
, void *closure
)
708 TALLOC_CTX
*frame
= talloc_stackframe();
709 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
711 PY_CHECK_TYPE(&PyBytes_Type
, value
, return -1;);
712 if (!pdb_set_lanman_passwd(sam_acct
, (uint8_t *)PyBytes_AsString(value
), PDB_CHANGED
)) {
720 static PyObject
*py_samu_get_nt_passwd(PyObject
*obj
, void *closure
)
722 TALLOC_CTX
*frame
= talloc_stackframe();
723 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
727 nt_pw
= (const char *)pdb_get_nt_passwd(sam_acct
);
732 py_nt_pw
= PyBytes_FromStringAndSize(nt_pw
, NT_HASH_LEN
);
737 static int py_samu_set_nt_passwd(PyObject
*obj
, PyObject
*value
, void *closure
)
739 TALLOC_CTX
*frame
= talloc_stackframe();
740 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
742 if (!pdb_set_nt_passwd(sam_acct
, (uint8_t *)PyBytes_AsString(value
), PDB_CHANGED
)) {
750 static PyObject
*py_samu_get_pw_history(PyObject
*obj
, void *closure
)
752 TALLOC_CTX
*frame
= talloc_stackframe();
753 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
754 PyObject
*py_nt_pw_his
;
755 const char *nt_pw_his
;
758 nt_pw_his
= (const char *)pdb_get_pw_history(sam_acct
, &hist_len
);
759 if (nt_pw_his
== NULL
) {
763 py_nt_pw_his
= PyBytes_FromStringAndSize(nt_pw_his
, hist_len
*PW_HISTORY_ENTRY_LEN
);
768 static int py_samu_set_pw_history(PyObject
*obj
, PyObject
*value
, void *closure
)
770 TALLOC_CTX
*frame
= talloc_stackframe();
771 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
776 PyBytes_AsStringAndSize(value
, &nt_pw_his
, &len
);
777 hist_len
= len
/ PW_HISTORY_ENTRY_LEN
;
778 if (!pdb_set_pw_history(sam_acct
, (uint8_t *)nt_pw_his
, hist_len
, PDB_CHANGED
)) {
786 static PyObject
*py_samu_get_plaintext_passwd(PyObject
*obj
, void *closure
)
788 TALLOC_CTX
*frame
= talloc_stackframe();
789 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
790 PyObject
*py_plaintext_pw
;
791 const char *plaintext_pw
;
793 plaintext_pw
= pdb_get_plaintext_passwd(sam_acct
);
794 if (plaintext_pw
== NULL
) {
798 py_plaintext_pw
= PyStr_FromString(plaintext_pw
);
800 return py_plaintext_pw
;
803 static int py_samu_set_plaintext_passwd(PyObject
*obj
, PyObject
*value
, void *closure
)
805 TALLOC_CTX
*frame
= talloc_stackframe();
806 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
808 if (!pdb_set_plaintext_passwd(sam_acct
, PyStr_AsString(value
))) {
816 static PyObject
*py_samu_get_acct_ctrl(PyObject
*obj
, void *closure
)
818 TALLOC_CTX
*frame
= talloc_stackframe();
819 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
820 PyObject
*py_acct_ctrl
;
822 py_acct_ctrl
= PyInt_FromLong(pdb_get_acct_ctrl(sam_acct
));
827 static int py_samu_set_acct_ctrl(PyObject
*obj
, PyObject
*value
, void *closure
)
829 TALLOC_CTX
*frame
= talloc_stackframe();
830 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
832 PY_CHECK_TYPE(&PyInt_Type
, value
, return -1;);
833 if (!pdb_set_acct_ctrl(sam_acct
, PyInt_AsLong(value
), PDB_CHANGED
)) {
841 static PyObject
*py_samu_get_logon_divs(PyObject
*obj
, void *closure
)
843 TALLOC_CTX
*frame
= talloc_stackframe();
844 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
845 PyObject
*py_logon_divs
;
847 py_logon_divs
= PyInt_FromLong(pdb_get_logon_divs(sam_acct
));
849 return py_logon_divs
;
852 static int py_samu_set_logon_divs(PyObject
*obj
, PyObject
*value
, void *closure
)
854 TALLOC_CTX
*frame
= talloc_stackframe();
855 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
857 PY_CHECK_TYPE(&PyInt_Type
, value
, return -1;);
858 if (!pdb_set_logon_divs(sam_acct
, PyInt_AsLong(value
), PDB_CHANGED
)) {
866 static PyObject
*py_samu_get_hours_len(PyObject
*obj
, void *closure
)
868 TALLOC_CTX
*frame
= talloc_stackframe();
869 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
870 PyObject
*py_hours_len
;
872 py_hours_len
= PyInt_FromLong(pdb_get_hours_len(sam_acct
));
877 static int py_samu_set_hours_len(PyObject
*obj
, PyObject
*value
, void *closure
)
879 TALLOC_CTX
*frame
= talloc_stackframe();
880 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
882 PY_CHECK_TYPE(&PyInt_Type
, value
, return -1;);
883 if (!pdb_set_hours_len(sam_acct
, PyInt_AsLong(value
), PDB_CHANGED
)) {
891 static PyObject
*py_samu_get_hours(PyObject
*obj
, void *closure
)
893 TALLOC_CTX
*frame
= talloc_stackframe();
894 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
899 hours
= (const char *)pdb_get_hours(sam_acct
);
904 hours_len
= pdb_get_hours_len(sam_acct
);
905 if ((py_hours
= PyList_New(hours_len
)) == NULL
) {
911 for (i
=0; i
<hours_len
; i
++) {
912 PyList_SetItem(py_hours
, i
, PyInt_FromLong(hours
[i
]));
918 static int py_samu_set_hours(PyObject
*obj
, PyObject
*value
, void *closure
)
920 TALLOC_CTX
*frame
= talloc_stackframe();
921 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
927 PY_CHECK_TYPE(&PyList_Type
, value
, return -1;);
929 hours_len
= PyList_GET_SIZE(value
);
931 hours
= talloc_array(pytalloc_get_mem_ctx(obj
), uint8_t, hours_len
);
938 for (i
=0; i
< hours_len
; i
++) {
939 PY_CHECK_TYPE(&PyInt_Type
, PyList_GET_ITEM(value
,i
), return -1;);
940 hours
[i
] = PyInt_AsLong(PyList_GET_ITEM(value
, i
));
943 status
= pdb_set_hours(sam_acct
, hours
, hours_len
, PDB_CHANGED
);
954 static PyObject
*py_samu_get_bad_password_count(PyObject
*obj
, void *closure
)
956 TALLOC_CTX
*frame
= talloc_stackframe();
957 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
958 PyObject
*py_bad_password_count
;
960 py_bad_password_count
= PyInt_FromLong(pdb_get_bad_password_count(sam_acct
));
962 return py_bad_password_count
;
965 static int py_samu_set_bad_password_count(PyObject
*obj
, PyObject
*value
, void *closure
)
967 TALLOC_CTX
*frame
= talloc_stackframe();
968 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
970 PY_CHECK_TYPE(&PyInt_Type
, value
, return -1;);
971 if (!pdb_set_bad_password_count(sam_acct
, PyInt_AsLong(value
), PDB_CHANGED
)) {
979 static PyObject
*py_samu_get_logon_count(PyObject
*obj
, void *closure
)
981 TALLOC_CTX
*frame
= talloc_stackframe();
982 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
983 PyObject
*py_logon_count
;
985 py_logon_count
= PyInt_FromLong(pdb_get_logon_count(sam_acct
));
987 return py_logon_count
;
990 static int py_samu_set_logon_count(PyObject
*obj
, PyObject
*value
, void *closure
)
992 TALLOC_CTX
*frame
= talloc_stackframe();
993 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
995 PY_CHECK_TYPE(&PyInt_Type
, value
, return -1;);
996 if (!pdb_set_logon_count(sam_acct
, PyInt_AsLong(value
), PDB_CHANGED
)) {
1004 static PyObject
*py_samu_get_country_code(PyObject
*obj
, void *closure
)
1006 TALLOC_CTX
*frame
= talloc_stackframe();
1007 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
1008 PyObject
*py_country_code
;
1010 py_country_code
= PyInt_FromLong(pdb_get_country_code(sam_acct
));
1012 return py_country_code
;
1015 static int py_samu_set_country_code(PyObject
*obj
, PyObject
*value
, void *closure
)
1017 TALLOC_CTX
*frame
= talloc_stackframe();
1018 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
1020 PY_CHECK_TYPE(&PyInt_Type
, value
, return -1;);
1021 if (!pdb_set_country_code(sam_acct
, PyInt_AsLong(value
), PDB_CHANGED
)) {
1029 static PyObject
*py_samu_get_code_page(PyObject
*obj
, void *closure
)
1031 TALLOC_CTX
*frame
= talloc_stackframe();
1032 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
1033 PyObject
*py_code_page
;
1035 py_code_page
= PyInt_FromLong(pdb_get_code_page(sam_acct
));
1037 return py_code_page
;
1040 static int py_samu_set_code_page(PyObject
*obj
, PyObject
*value
, void *closure
)
1042 TALLOC_CTX
*frame
= talloc_stackframe();
1043 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
1045 PY_CHECK_TYPE(&PyInt_Type
, value
, return -1;);
1046 if (!pdb_set_code_page(sam_acct
, PyInt_AsLong(value
), PDB_CHANGED
)) {
1054 static PyGetSetDef py_samu_getsetters
[] = {
1056 .name
= discard_const_p(char, "logon_time"),
1057 .get
= py_samu_get_logon_time
,
1058 .set
= py_samu_set_logon_time
,
1061 .name
= discard_const_p(char, "logoff_time"),
1062 .get
= py_samu_get_logoff_time
,
1063 .set
= py_samu_set_logoff_time
,
1066 .name
= discard_const_p(char, "kickoff_time"),
1067 .get
= py_samu_get_kickoff_time
,
1068 .set
= py_samu_set_kickoff_time
,
1071 .name
= discard_const_p(char, "bad_password_time"),
1072 .get
= py_samu_get_bad_password_time
,
1073 .set
= py_samu_set_bad_password_time
,
1076 .name
= discard_const_p(char, "pass_last_set_time"),
1077 .get
= py_samu_get_pass_last_set_time
,
1078 .set
= py_samu_set_pass_last_set_time
,
1081 .name
= discard_const_p(char, "pass_can_change_time"),
1082 .get
= py_samu_get_pass_can_change_time
,
1083 .set
= py_samu_set_pass_can_change_time
,
1086 .name
= discard_const_p(char, "pass_must_change_time"),
1087 .get
= py_samu_get_pass_must_change_time
,
1088 .set
= py_samu_set_pass_must_change_time
,
1091 .name
= discard_const_p(char, "username"),
1092 .get
= py_samu_get_username
,
1093 .set
= py_samu_set_username
,
1096 .name
= discard_const_p(char, "domain"),
1097 .get
= py_samu_get_domain
,
1098 .set
= py_samu_set_domain
,
1101 .name
= discard_const_p(char, "nt_username"),
1102 .get
= py_samu_get_nt_username
,
1103 .set
= py_samu_set_nt_username
,
1106 .name
= discard_const_p(char, "full_name"),
1107 .get
= py_samu_get_full_name
,
1108 .set
= py_samu_set_full_name
,
1111 .name
= discard_const_p(char, "home_dir"),
1112 .get
= py_samu_get_home_dir
,
1113 .set
= py_samu_set_home_dir
,
1116 .name
= discard_const_p(char, "dir_drive"),
1117 .get
= py_samu_get_dir_drive
,
1118 .set
= py_samu_set_dir_drive
,
1121 .name
= discard_const_p(char, "logon_script"),
1122 .get
= py_samu_get_logon_script
,
1123 .set
= py_samu_set_logon_script
,
1126 .name
= discard_const_p(char, "profile_path"),
1127 .get
= py_samu_get_profile_path
,
1128 .set
= py_samu_set_profile_path
,
1131 .name
= discard_const_p(char, "acct_desc"),
1132 .get
= py_samu_get_acct_desc
,
1133 .set
= py_samu_set_acct_desc
,
1136 .name
= discard_const_p(char, "workstations"),
1137 .get
= py_samu_get_workstations
,
1138 .set
= py_samu_set_workstations
,
1141 .name
= discard_const_p(char, "comment"),
1142 .get
= py_samu_get_comment
,
1143 .set
= py_samu_set_comment
,
1146 .name
= discard_const_p(char, "munged_dial"),
1147 .get
= py_samu_get_munged_dial
,
1148 .set
= py_samu_set_munged_dial
,
1151 .name
= discard_const_p(char, "user_sid"),
1152 .get
= py_samu_get_user_sid
,
1153 .set
= py_samu_set_user_sid
,
1156 .name
= discard_const_p(char, "group_sid"),
1157 .get
= py_samu_get_group_sid
,
1158 .set
= py_samu_set_group_sid
,
1161 .name
= discard_const_p(char, "lanman_passwd"),
1162 .get
= py_samu_get_lanman_passwd
,
1163 .set
= py_samu_set_lanman_passwd
,
1166 .name
= discard_const_p(char, "nt_passwd"),
1167 .get
= py_samu_get_nt_passwd
,
1168 .set
= py_samu_set_nt_passwd
,
1171 .name
= discard_const_p(char, "pw_history"),
1172 .get
= py_samu_get_pw_history
,
1173 .set
= py_samu_set_pw_history
,
1176 .name
= discard_const_p(char, "plaintext_passwd"),
1177 .get
= py_samu_get_plaintext_passwd
,
1178 .set
= py_samu_set_plaintext_passwd
,
1181 .name
= discard_const_p(char, "acct_ctrl"),
1182 .get
= py_samu_get_acct_ctrl
,
1183 .set
= py_samu_set_acct_ctrl
,
1186 .name
= discard_const_p(char, "logon_divs"),
1187 .get
= py_samu_get_logon_divs
,
1188 .set
= py_samu_set_logon_divs
,
1191 .name
= discard_const_p(char, "hours_len"),
1192 .get
= py_samu_get_hours_len
,
1193 .set
= py_samu_set_hours_len
,
1196 .name
= discard_const_p(char, "hours"),
1197 .get
= py_samu_get_hours
,
1198 .set
= py_samu_set_hours
,
1201 .name
= discard_const_p(char, "bad_password_count"),
1202 .get
= py_samu_get_bad_password_count
,
1203 .set
= py_samu_set_bad_password_count
,
1206 .name
= discard_const_p(char, "logon_count"),
1207 .get
= py_samu_get_logon_count
,
1208 .set
= py_samu_set_logon_count
,
1211 .name
= discard_const_p(char, "country_code"),
1212 .get
= py_samu_get_country_code
,
1213 .set
= py_samu_set_country_code
,
1216 .name
= discard_const_p(char, "code_page"),
1217 .get
= py_samu_get_code_page
,
1218 .set
= py_samu_set_code_page
,
1226 /************************** PIDL Autogeneratd ******************************/
1228 static PyObject
*py_samu_new(PyTypeObject
*type
, PyObject
*args
, PyObject
*kwargs
)
1230 TALLOC_CTX
*frame
= talloc_stackframe();
1231 struct samu
*sam_acct
;
1233 sam_acct
= samu_new(NULL
);
1241 return pytalloc_steal(type
, sam_acct
);
1244 static PyTypeObject PySamu
= {
1245 .tp_name
= "passdb.Samu",
1246 .tp_getset
= py_samu_getsetters
,
1248 .tp_new
= py_samu_new
,
1249 .tp_flags
= Py_TPFLAGS_DEFAULT
| Py_TPFLAGS_BASETYPE
,
1250 .tp_doc
= "Samu() -> samu object\n",
1254 static PyObject
*py_groupmap_get_gid(PyObject
*obj
, void *closure
)
1256 TALLOC_CTX
*frame
= talloc_stackframe();
1257 GROUP_MAP
*group_map
= (GROUP_MAP
*)pytalloc_get_ptr(obj
);
1260 py_gid
= Py_BuildValue("i", group_map
->gid
);
1265 static int py_groupmap_set_gid(PyObject
*obj
, PyObject
*value
, void *closure
)
1267 TALLOC_CTX
*frame
= talloc_stackframe();
1268 GROUP_MAP
*group_map
= (GROUP_MAP
*)pytalloc_get_ptr(obj
);
1270 PY_CHECK_TYPE(&PyInt_Type
, value
, return -1;);
1271 group_map
->gid
= PyInt_AsLong(value
);
1276 static PyObject
*py_groupmap_get_sid(PyObject
*obj
, void *closure
)
1278 TALLOC_CTX
*frame
= talloc_stackframe();
1279 GROUP_MAP
*group_map
= (GROUP_MAP
*)pytalloc_get_ptr(obj
);
1281 struct dom_sid
*group_sid
;
1282 TALLOC_CTX
*mem_ctx
;
1284 mem_ctx
= talloc_new(NULL
);
1285 if (mem_ctx
== NULL
) {
1291 group_sid
= dom_sid_dup(mem_ctx
, &group_map
->sid
);
1292 if (group_sid
== NULL
) {
1294 talloc_free(mem_ctx
);
1299 py_sid
= pytalloc_steal(dom_sid_Type
, group_sid
);
1301 talloc_free(mem_ctx
);
1307 static int py_groupmap_set_sid(PyObject
*obj
, PyObject
*value
, void *closure
)
1309 TALLOC_CTX
*frame
= talloc_stackframe();
1310 GROUP_MAP
*group_map
= (GROUP_MAP
*)pytalloc_get_ptr(obj
);
1312 PY_CHECK_TYPE(dom_sid_Type
, value
, return -1;);
1313 group_map
->sid
= *pytalloc_get_type(value
, struct dom_sid
);
1318 static PyObject
*py_groupmap_get_sid_name_use(PyObject
*obj
, void *closure
)
1320 TALLOC_CTX
*frame
= talloc_stackframe();
1321 GROUP_MAP
*group_map
= (GROUP_MAP
*)pytalloc_get_ptr(obj
);
1322 PyObject
*py_sid_name_use
;
1324 py_sid_name_use
= PyInt_FromLong(group_map
->sid_name_use
);
1326 return py_sid_name_use
;
1329 static int py_groupmap_set_sid_name_use(PyObject
*obj
, PyObject
*value
, void *closure
)
1331 TALLOC_CTX
*frame
= talloc_stackframe();
1332 GROUP_MAP
*group_map
= (GROUP_MAP
*)pytalloc_get_ptr(obj
);
1334 PY_CHECK_TYPE(&PyInt_Type
, value
, return -1;);
1335 group_map
->sid_name_use
= PyInt_AsLong(value
);
1340 static PyObject
*py_groupmap_get_nt_name(PyObject
*obj
, void *closure
)
1342 TALLOC_CTX
*frame
= talloc_stackframe();
1343 GROUP_MAP
*group_map
= (GROUP_MAP
*)pytalloc_get_ptr(obj
);
1344 PyObject
*py_nt_name
;
1345 if (group_map
->nt_name
== NULL
) {
1346 py_nt_name
= Py_None
;
1347 Py_INCREF(py_nt_name
);
1349 py_nt_name
= PyStr_FromString(group_map
->nt_name
);
1355 static int py_groupmap_set_nt_name(PyObject
*obj
, PyObject
*value
, void *closure
)
1357 TALLOC_CTX
*frame
= talloc_stackframe();
1358 GROUP_MAP
*group_map
= (GROUP_MAP
*)pytalloc_get_ptr(obj
);
1360 PY_CHECK_TYPE(&PyStr_Type
, value
, return -1;);
1361 if (value
== Py_None
) {
1362 fstrcpy(group_map
->nt_name
, NULL
);
1364 fstrcpy(group_map
->nt_name
, PyStr_AsString(value
));
1370 static PyObject
*py_groupmap_get_comment(PyObject
*obj
, void *closure
)
1372 TALLOC_CTX
*frame
= talloc_stackframe();
1373 GROUP_MAP
*group_map
= (GROUP_MAP
*)pytalloc_get_ptr(obj
);
1374 PyObject
*py_comment
;
1375 if (group_map
->comment
== NULL
) {
1376 py_comment
= Py_None
;
1377 Py_INCREF(py_comment
);
1379 py_comment
= PyStr_FromString(group_map
->comment
);
1385 static int py_groupmap_set_comment(PyObject
*obj
, PyObject
*value
, void *closure
)
1387 TALLOC_CTX
*frame
= talloc_stackframe();
1388 GROUP_MAP
*group_map
= (GROUP_MAP
*)pytalloc_get_ptr(obj
);
1390 PY_CHECK_TYPE(&PyStr_Type
, value
, return -1;);
1391 if (value
== Py_None
) {
1392 fstrcpy(group_map
->comment
, NULL
);
1394 fstrcpy(group_map
->comment
, PyStr_AsString(value
));
1400 static PyGetSetDef py_groupmap_getsetters
[] = {
1402 .name
= discard_const_p(char, "gid"),
1403 .get
= py_groupmap_get_gid
,
1404 .set
= py_groupmap_set_gid
,
1407 .name
= discard_const_p(char, "sid"),
1408 .get
= py_groupmap_get_sid
,
1409 .set
= py_groupmap_set_sid
,
1412 .name
= discard_const_p(char, "sid_name_use"),
1413 .get
= py_groupmap_get_sid_name_use
,
1414 .set
= py_groupmap_set_sid_name_use
,
1417 .name
= discard_const_p(char, "nt_name"),
1418 .get
= py_groupmap_get_nt_name
,
1419 .set
= py_groupmap_set_nt_name
,
1422 .name
= discard_const_p(char, "comment"),
1423 .get
= py_groupmap_get_comment
,
1424 .set
= py_groupmap_set_comment
,
1431 static PyObject
*py_groupmap_new(PyTypeObject
*type
, PyObject
*args
, PyObject
*kwargs
)
1433 TALLOC_CTX
*frame
= talloc_stackframe();
1434 GROUP_MAP
*group_map
;
1435 TALLOC_CTX
*mem_ctx
;
1436 PyObject
*py_group_map
;
1438 mem_ctx
= talloc_new(NULL
);
1439 if (mem_ctx
== NULL
) {
1445 group_map
= talloc_zero(mem_ctx
, GROUP_MAP
);
1446 if (group_map
== NULL
) {
1448 talloc_free(mem_ctx
);
1453 py_group_map
= pytalloc_steal(type
, group_map
);
1454 if (py_group_map
== NULL
) {
1456 talloc_free(mem_ctx
);
1461 talloc_free(mem_ctx
);
1464 return py_group_map
;
1468 static PyTypeObject PyGroupmap
= {
1469 .tp_name
= "passdb.Groupmap",
1470 .tp_getset
= py_groupmap_getsetters
,
1472 .tp_new
= py_groupmap_new
,
1473 .tp_flags
= Py_TPFLAGS_DEFAULT
| Py_TPFLAGS_BASETYPE
,
1474 .tp_doc
= "Groupmap() -> group map object\n",
1478 static PyObject
*py_pdb_domain_info(PyObject
*self
, PyObject
*args
)
1480 TALLOC_CTX
*frame
= talloc_stackframe();
1481 struct pdb_methods
*methods
;
1482 struct pdb_domain_info
*domain_info
;
1483 PyObject
*py_domain_info
;
1484 struct dom_sid
*sid
;
1487 methods
= pytalloc_get_ptr(self
);
1489 domain_info
= methods
->get_domain_info(methods
, frame
);
1490 if (! domain_info
) {
1494 sid
= dom_sid_dup(frame
, &domain_info
->sid
);
1501 guid
= talloc(frame
, struct GUID
);
1507 *guid
= domain_info
->guid
;
1509 if ((py_domain_info
= PyDict_New()) == NULL
) {
1515 PyDict_SetItemString(py_domain_info
, "name", PyStr_FromString(domain_info
->name
));
1516 PyDict_SetItemString(py_domain_info
, "dns_domain", PyStr_FromString(domain_info
->dns_domain
));
1517 PyDict_SetItemString(py_domain_info
, "dns_forest", PyStr_FromString(domain_info
->dns_forest
));
1518 PyDict_SetItemString(py_domain_info
, "dom_sid", pytalloc_steal(dom_sid_Type
, sid
));
1519 PyDict_SetItemString(py_domain_info
, "guid", pytalloc_steal(guid_Type
, guid
));
1522 return py_domain_info
;
1526 static PyObject
*py_pdb_getsampwnam(PyObject
*self
, PyObject
*args
)
1528 TALLOC_CTX
*frame
= talloc_stackframe();
1530 const char *username
;
1531 struct pdb_methods
*methods
;
1532 struct samu
*sam_acct
;
1533 PyObject
*py_sam_acct
;
1535 if (!PyArg_ParseTuple(args
, "s:getsampwnam", &username
)) {
1540 methods
= pytalloc_get_ptr(self
);
1542 py_sam_acct
= py_samu_new(&PySamu
, NULL
, NULL
);
1543 if (py_sam_acct
== NULL
) {
1548 sam_acct
= (struct samu
*)pytalloc_get_ptr(py_sam_acct
);
1550 status
= methods
->getsampwnam(methods
, sam_acct
, username
);
1551 if (!NT_STATUS_IS_OK(status
)) {
1552 PyErr_Format(py_pdb_error
, "Unable to get user information for '%s', (%d,%s)",
1554 NT_STATUS_V(status
),
1555 get_friendly_nt_error_msg(status
));
1556 Py_DECREF(py_sam_acct
);
1565 static PyObject
*py_pdb_getsampwsid(PyObject
*self
, PyObject
*args
)
1567 TALLOC_CTX
*frame
= talloc_stackframe();
1569 struct pdb_methods
*methods
;
1570 struct samu
*sam_acct
;
1571 PyObject
*py_sam_acct
;
1572 PyObject
*py_user_sid
;
1574 if (!PyArg_ParseTuple(args
, "O:getsampwsid", &py_user_sid
)) {
1579 methods
= pytalloc_get_ptr(self
);
1581 py_sam_acct
= py_samu_new(&PySamu
, NULL
, NULL
);
1582 if (py_sam_acct
== NULL
) {
1587 sam_acct
= (struct samu
*)pytalloc_get_ptr(py_sam_acct
);
1589 status
= methods
->getsampwsid(methods
, sam_acct
, pytalloc_get_ptr(py_user_sid
));
1590 if (!NT_STATUS_IS_OK(status
)) {
1591 PyErr_Format(py_pdb_error
, "Unable to get user information from SID, (%d,%s)",
1592 NT_STATUS_V(status
),
1593 get_friendly_nt_error_msg(status
));
1594 Py_DECREF(py_sam_acct
);
1603 static PyObject
*py_pdb_create_user(PyObject
*self
, PyObject
*args
)
1605 TALLOC_CTX
*frame
= talloc_stackframe();
1607 struct pdb_methods
*methods
;
1608 const char *username
;
1609 unsigned int acct_flags
;
1612 if (!PyArg_ParseTuple(args
, "sI:create_user", &username
, &acct_flags
)) {
1617 methods
= pytalloc_get_ptr(self
);
1619 status
= methods
->create_user(methods
, frame
, username
, acct_flags
, &rid
);
1620 if (!NT_STATUS_IS_OK(status
)) {
1621 PyErr_Format(py_pdb_error
, "Unable to create user (%s), (%d,%s)",
1623 NT_STATUS_V(status
),
1624 get_friendly_nt_error_msg(status
));
1630 return PyInt_FromLong(rid
);
1633 static PyObject
*py_pdb_delete_user(PyObject
*self
, PyObject
*args
)
1635 TALLOC_CTX
*frame
= talloc_stackframe();
1637 struct pdb_methods
*methods
;
1638 struct samu
*sam_acct
;
1639 PyObject
*py_sam_acct
;
1641 if (!PyArg_ParseTuple(args
, "O!:delete_user", &PySamu
, &py_sam_acct
)) {
1646 methods
= pytalloc_get_ptr(self
);
1648 sam_acct
= pytalloc_get_ptr(py_sam_acct
);
1650 status
= methods
->delete_user(methods
, frame
, sam_acct
);
1651 if (!NT_STATUS_IS_OK(status
)) {
1652 PyErr_Format(py_pdb_error
, "Unable to delete user, (%d,%s)",
1653 NT_STATUS_V(status
),
1654 get_friendly_nt_error_msg(status
));
1663 static PyObject
*py_pdb_add_sam_account(PyObject
*self
, PyObject
*args
)
1665 TALLOC_CTX
*frame
= talloc_stackframe();
1667 struct pdb_methods
*methods
;
1668 struct samu
*sam_acct
;
1669 PyObject
*py_sam_acct
;
1671 if (!PyArg_ParseTuple(args
, "O!:add_sam_account", &PySamu
, &py_sam_acct
)) {
1676 methods
= pytalloc_get_ptr(self
);
1678 sam_acct
= pytalloc_get_ptr(py_sam_acct
);
1680 status
= methods
->add_sam_account(methods
, sam_acct
);
1681 if (!NT_STATUS_IS_OK(status
)) {
1682 PyErr_Format(py_pdb_error
, "Unable to add sam account '%s', (%d,%s)",
1684 NT_STATUS_V(status
),
1685 get_friendly_nt_error_msg(status
));
1694 static PyObject
*py_pdb_update_sam_account(PyObject
*self
, PyObject
*args
)
1696 TALLOC_CTX
*frame
= talloc_stackframe();
1698 struct pdb_methods
*methods
;
1699 struct samu
*sam_acct
;
1700 PyObject
*py_sam_acct
;
1702 if (!PyArg_ParseTuple(args
, "O!:update_sam_account", &PySamu
, &py_sam_acct
)) {
1707 methods
= pytalloc_get_ptr(self
);
1709 sam_acct
= pytalloc_get_ptr(py_sam_acct
);
1711 status
= methods
->update_sam_account(methods
, sam_acct
);
1712 if (!NT_STATUS_IS_OK(status
)) {
1713 PyErr_Format(py_pdb_error
, "Unable to update sam account, (%d,%s)",
1714 NT_STATUS_V(status
),
1715 get_friendly_nt_error_msg(status
));
1724 static PyObject
*py_pdb_delete_sam_account(PyObject
*self
, PyObject
*args
)
1726 TALLOC_CTX
*frame
= talloc_stackframe();
1728 struct pdb_methods
*methods
;
1729 struct samu
*sam_acct
;
1730 PyObject
*py_sam_acct
;
1732 if (!PyArg_ParseTuple(args
, "O!:delete_sam_account", &PySamu
, &py_sam_acct
)) {
1737 methods
= pytalloc_get_ptr(self
);
1739 sam_acct
= pytalloc_get_ptr(py_sam_acct
);
1741 status
= methods
->delete_sam_account(methods
, sam_acct
);
1742 if (!NT_STATUS_IS_OK(status
)) {
1743 PyErr_Format(py_pdb_error
, "Unable to delete sam account, (%d,%s)",
1744 NT_STATUS_V(status
),
1745 get_friendly_nt_error_msg(status
));
1754 static PyObject
*py_pdb_rename_sam_account(PyObject
*self
, PyObject
*args
)
1756 TALLOC_CTX
*frame
= talloc_stackframe();
1758 struct pdb_methods
*methods
;
1759 struct samu
*sam_acct
;
1760 const char *new_username
;
1761 PyObject
*py_sam_acct
;
1763 if (!PyArg_ParseTuple(args
, "O!s:rename_sam_account", &PySamu
, &py_sam_acct
,
1769 methods
= pytalloc_get_ptr(self
);
1771 sam_acct
= pytalloc_get_ptr(py_sam_acct
);
1773 status
= methods
->rename_sam_account(methods
, sam_acct
, new_username
);
1774 if (!NT_STATUS_IS_OK(status
)) {
1775 PyErr_Format(py_pdb_error
, "Unable to rename sam account, (%d,%s)",
1776 NT_STATUS_V(status
),
1777 get_friendly_nt_error_msg(status
));
1787 static PyObject
*py_pdb_getgrsid(PyObject
*self
, PyObject
*args
)
1789 TALLOC_CTX
*frame
= talloc_stackframe();
1791 struct pdb_methods
*methods
;
1792 GROUP_MAP
*group_map
;
1793 struct dom_sid
*domain_sid
;
1794 PyObject
*py_domain_sid
, *py_group_map
;
1796 if (!PyArg_ParseTuple(args
, "O!:getgrsid", dom_sid_Type
, &py_domain_sid
)) {
1801 methods
= pytalloc_get_ptr(self
);
1803 domain_sid
= pytalloc_get_ptr(py_domain_sid
);
1805 py_group_map
= py_groupmap_new(&PyGroupmap
, NULL
, NULL
);
1806 if (py_group_map
== NULL
) {
1812 group_map
= pytalloc_get_ptr(py_group_map
);
1814 status
= methods
->getgrsid(methods
, group_map
, *domain_sid
);
1815 if (!NT_STATUS_IS_OK(status
)) {
1816 PyErr_Format(py_pdb_error
, "Unable to get group information by sid, (%d,%s)",
1817 NT_STATUS_V(status
),
1818 get_friendly_nt_error_msg(status
));
1824 return py_group_map
;
1828 static PyObject
*py_pdb_getgrgid(PyObject
*self
, PyObject
*args
)
1830 TALLOC_CTX
*frame
= talloc_stackframe();
1832 struct pdb_methods
*methods
;
1833 GROUP_MAP
*group_map
;
1834 PyObject
*py_group_map
;
1835 unsigned int gid_value
;
1837 if (!PyArg_ParseTuple(args
, "I:getgrgid", &gid_value
)) {
1842 methods
= pytalloc_get_ptr(self
);
1844 py_group_map
= py_groupmap_new(&PyGroupmap
, NULL
, NULL
);
1845 if (py_group_map
== NULL
) {
1851 group_map
= pytalloc_get_ptr(py_group_map
);
1853 status
= methods
->getgrgid(methods
, group_map
, gid_value
);
1854 if (!NT_STATUS_IS_OK(status
)) {
1855 PyErr_Format(py_pdb_error
, "Unable to get group information by gid, (%d,%s)",
1856 NT_STATUS_V(status
),
1857 get_friendly_nt_error_msg(status
));
1863 return py_group_map
;
1867 static PyObject
*py_pdb_getgrnam(PyObject
*self
, PyObject
*args
)
1869 TALLOC_CTX
*frame
= talloc_stackframe();
1871 struct pdb_methods
*methods
;
1872 GROUP_MAP
*group_map
;
1873 PyObject
*py_group_map
;
1874 const char *groupname
;
1876 if (!PyArg_ParseTuple(args
, "s:getgrnam", &groupname
)) {
1881 methods
= pytalloc_get_ptr(self
);
1883 py_group_map
= py_groupmap_new(&PyGroupmap
, NULL
, NULL
);
1884 if (py_group_map
== NULL
) {
1890 group_map
= pytalloc_get_ptr(py_group_map
);
1892 status
= methods
->getgrnam(methods
, group_map
, groupname
);
1893 if (!NT_STATUS_IS_OK(status
)) {
1894 PyErr_Format(py_pdb_error
, "Unable to get group information by name, (%d,%s)",
1895 NT_STATUS_V(status
),
1896 get_friendly_nt_error_msg(status
));
1902 return py_group_map
;
1906 static PyObject
*py_pdb_create_dom_group(PyObject
*self
, PyObject
*args
)
1908 TALLOC_CTX
*frame
= talloc_stackframe();
1910 struct pdb_methods
*methods
;
1911 const char *groupname
;
1914 if (!PyArg_ParseTuple(args
, "s:create_dom_group", &groupname
)) {
1919 methods
= pytalloc_get_ptr(self
);
1921 status
= methods
->create_dom_group(methods
, frame
, groupname
, &group_rid
);
1922 if (!NT_STATUS_IS_OK(status
)) {
1923 PyErr_Format(py_pdb_error
, "Unable to create domain group (%s), (%d,%s)",
1925 NT_STATUS_V(status
),
1926 get_friendly_nt_error_msg(status
));
1932 return PyInt_FromLong(group_rid
);
1936 static PyObject
*py_pdb_delete_dom_group(PyObject
*self
, PyObject
*args
)
1938 TALLOC_CTX
*frame
= talloc_stackframe();
1940 struct pdb_methods
*methods
;
1941 unsigned int group_rid
;
1943 if (!PyArg_ParseTuple(args
, "I:delete_dom_group", &group_rid
)) {
1948 methods
= pytalloc_get_ptr(self
);
1950 status
= methods
->delete_dom_group(methods
, frame
, group_rid
);
1951 if (!NT_STATUS_IS_OK(status
)) {
1952 PyErr_Format(py_pdb_error
, "Unable to delete domain group (rid=%d), (%d,%s)",
1954 NT_STATUS_V(status
),
1955 get_friendly_nt_error_msg(status
));
1965 static PyObject
*py_pdb_add_group_mapping_entry(PyObject
*self
, PyObject
*args
)
1967 TALLOC_CTX
*frame
= talloc_stackframe();
1969 struct pdb_methods
*methods
;
1970 PyObject
*py_group_map
;
1971 GROUP_MAP
*group_map
;
1973 if (!PyArg_ParseTuple(args
, "O!:add_group_mapping_entry", &PyGroupmap
, &py_group_map
)) {
1978 methods
= pytalloc_get_ptr(self
);
1980 group_map
= pytalloc_get_ptr(py_group_map
);
1982 status
= methods
->add_group_mapping_entry(methods
, group_map
);
1983 if (!NT_STATUS_IS_OK(status
)) {
1984 PyErr_Format(py_pdb_error
, "Unable to add group mapping entry, (%d,%s)",
1985 NT_STATUS_V(status
),
1986 get_friendly_nt_error_msg(status
));
1996 static PyObject
*py_pdb_update_group_mapping_entry(PyObject
*self
, PyObject
*args
)
1998 TALLOC_CTX
*frame
= talloc_stackframe();
2000 struct pdb_methods
*methods
;
2001 PyObject
*py_group_map
;
2002 GROUP_MAP
*group_map
;
2004 if (!PyArg_ParseTuple(args
, "O!:update_group_mapping_entry", &PyGroupmap
, &py_group_map
)) {
2009 methods
= pytalloc_get_ptr(self
);
2011 group_map
= pytalloc_get_ptr(py_group_map
);
2013 status
= methods
->update_group_mapping_entry(methods
, group_map
);
2014 if (!NT_STATUS_IS_OK(status
)) {
2015 PyErr_Format(py_pdb_error
, "Unable to update group mapping entry, (%d,%s)",
2016 NT_STATUS_V(status
),
2017 get_friendly_nt_error_msg(status
));
2027 static PyObject
*py_pdb_delete_group_mapping_entry(PyObject
*self
, PyObject
*args
)
2029 TALLOC_CTX
*frame
= talloc_stackframe();
2031 struct pdb_methods
*methods
;
2032 PyObject
*py_group_sid
;
2033 struct dom_sid
*group_sid
;
2035 if (!PyArg_ParseTuple(args
, "O!:delete_group_mapping_entry", dom_sid_Type
, &py_group_sid
)) {
2040 methods
= pytalloc_get_ptr(self
);
2042 group_sid
= pytalloc_get_ptr(py_group_sid
);
2044 status
= methods
->delete_group_mapping_entry(methods
, *group_sid
);
2045 if (!NT_STATUS_IS_OK(status
)) {
2046 PyErr_Format(py_pdb_error
, "Unable to delete group mapping entry, (%d,%s)",
2047 NT_STATUS_V(status
),
2048 get_friendly_nt_error_msg(status
));
2058 static PyObject
*py_pdb_enum_group_mapping(PyObject
*self
, PyObject
*args
)
2060 TALLOC_CTX
*frame
= talloc_stackframe();
2062 struct pdb_methods
*methods
;
2063 enum lsa_SidType sid_name_use
;
2064 int lsa_sidtype_value
= SID_NAME_UNKNOWN
;
2066 PyObject
*py_domain_sid
= Py_None
;
2067 struct dom_sid
*domain_sid
= NULL
;
2068 GROUP_MAP
**gmap
= NULL
;
2069 GROUP_MAP
*group_map
;
2071 PyObject
*py_gmap_list
, *py_group_map
;
2076 if (!PyArg_ParseTuple(args
, "|O!ii:enum_group_mapping", dom_sid_Type
, &py_domain_sid
,
2077 &lsa_sidtype_value
, &unix_only
)) {
2082 methods
= pytalloc_get_ptr(self
);
2084 sid_name_use
= lsa_sidtype_value
;
2086 if (py_domain_sid
!= Py_None
) {
2087 domain_sid
= pytalloc_get_ptr(py_domain_sid
);
2090 status
= methods
->enum_group_mapping(methods
, domain_sid
, sid_name_use
,
2091 &gmap
, &num_entries
, unix_only
);
2092 if (!NT_STATUS_IS_OK(status
)) {
2093 PyErr_Format(py_pdb_error
, "Unable to enumerate group mappings, (%d,%s)",
2094 NT_STATUS_V(status
),
2095 get_friendly_nt_error_msg(status
));
2100 py_gmap_list
= PyList_New(0);
2101 if (py_gmap_list
== NULL
) {
2107 for(i
=0; i
<num_entries
; i
++) {
2108 py_group_map
= py_groupmap_new(&PyGroupmap
, NULL
, NULL
);
2110 group_map
= pytalloc_get_ptr(py_group_map
);
2111 *group_map
= *gmap
[i
];
2112 talloc_steal(group_map
, gmap
[i
]->nt_name
);
2113 talloc_steal(group_map
, gmap
[i
]->comment
);
2115 PyList_Append(py_gmap_list
, py_group_map
);
2122 return py_gmap_list
;
2126 static PyObject
*py_pdb_enum_group_members(PyObject
*self
, PyObject
*args
)
2128 TALLOC_CTX
*frame
= talloc_stackframe();
2130 struct pdb_methods
*methods
;
2131 PyObject
*py_group_sid
;
2132 struct dom_sid
*group_sid
;
2133 uint32_t *member_rids
;
2135 PyObject
*py_sid_list
;
2136 struct dom_sid
*domain_sid
, *member_sid
;
2139 if (!PyArg_ParseTuple(args
, "O!:enum_group_members", dom_sid_Type
, &py_group_sid
)) {
2144 methods
= pytalloc_get_ptr(self
);
2146 group_sid
= pytalloc_get_ptr(py_group_sid
);
2148 status
= methods
->enum_group_members(methods
, frame
, group_sid
,
2149 &member_rids
, &num_members
);
2150 if (!NT_STATUS_IS_OK(status
)) {
2151 PyErr_Format(py_pdb_error
, "Unable to enumerate group members, (%d,%s)",
2152 NT_STATUS_V(status
),
2153 get_friendly_nt_error_msg(status
));
2158 py_sid_list
= PyList_New(0);
2159 if (py_sid_list
== NULL
) {
2165 domain_sid
= get_global_sam_sid();
2167 for(i
=0; i
<num_members
; i
++) {
2168 member_sid
= dom_sid_add_rid(frame
, domain_sid
, member_rids
[i
]);
2169 PyList_Append(py_sid_list
, pytalloc_steal(dom_sid_Type
, member_sid
));
2177 static PyObject
*py_pdb_enum_group_memberships(PyObject
*self
, PyObject
*args
)
2179 TALLOC_CTX
*frame
= talloc_stackframe();
2181 struct pdb_methods
*methods
;
2184 struct samu
*sam_acct
;
2185 PyObject
*py_sam_acct
;
2186 PyObject
*py_sid_list
;
2187 struct dom_sid
*user_group_sids
= NULL
;
2188 gid_t
*user_group_ids
= NULL
;
2189 uint32_t num_groups
= 0;
2191 if (!PyArg_ParseTuple(args
, "O!:enum_group_memberships", &PySamu
, &py_sam_acct
)) {
2196 methods
= pytalloc_get_ptr(self
);
2198 sam_acct
= pytalloc_get_ptr(py_sam_acct
);
2200 status
= methods
->enum_group_memberships(methods
, frame
, sam_acct
,
2201 &user_group_sids
, &user_group_ids
, &num_groups
);
2202 if (!NT_STATUS_IS_OK(status
)) {
2203 PyErr_Format(py_pdb_error
, "Unable to enumerate group memberships, (%d,%s)",
2204 NT_STATUS_V(status
),
2205 get_friendly_nt_error_msg(status
));
2210 py_sid_list
= PyList_New(0);
2211 if (py_sid_list
== NULL
) {
2217 for(i
=0; i
<num_groups
; i
++) {
2218 PyList_Append(py_sid_list
, pytalloc_steal(dom_sid_Type
, dom_sid_dup(NULL
, &user_group_sids
[i
])));
2226 static PyObject
*py_pdb_add_groupmem(PyObject
*self
, PyObject
*args
)
2228 TALLOC_CTX
*frame
= talloc_stackframe();
2230 struct pdb_methods
*methods
;
2231 uint32_t group_rid
, member_rid
;
2233 if (!PyArg_ParseTuple(args
, "II:add_groupmem", &group_rid
, &member_rid
)) {
2238 methods
= pytalloc_get_ptr(self
);
2240 status
= methods
->add_groupmem(methods
, frame
, group_rid
, member_rid
);
2241 if (!NT_STATUS_IS_OK(status
)) {
2242 PyErr_Format(py_pdb_error
, "Unable to add group member, (%d,%s)",
2243 NT_STATUS_V(status
),
2244 get_friendly_nt_error_msg(status
));
2254 static PyObject
*py_pdb_del_groupmem(PyObject
*self
, PyObject
*args
)
2256 TALLOC_CTX
*frame
= talloc_stackframe();
2258 struct pdb_methods
*methods
;
2259 uint32_t group_rid
, member_rid
;
2261 if (!PyArg_ParseTuple(args
, "II:del_groupmem", &group_rid
, &member_rid
)) {
2266 methods
= pytalloc_get_ptr(self
);
2268 status
= methods
->del_groupmem(methods
, frame
, group_rid
, member_rid
);
2269 if (!NT_STATUS_IS_OK(status
)) {
2270 PyErr_Format(py_pdb_error
, "Unable to rename sam account, (%d,%s)",
2271 NT_STATUS_V(status
),
2272 get_friendly_nt_error_msg(status
));
2282 static PyObject
*py_pdb_create_alias(PyObject
*self
, PyObject
*args
)
2284 TALLOC_CTX
*frame
= talloc_stackframe();
2286 struct pdb_methods
*methods
;
2287 const char *alias_name
;
2290 if (!PyArg_ParseTuple(args
, "s:create_alias", &alias_name
)) {
2295 methods
= pytalloc_get_ptr(self
);
2297 status
= methods
->create_alias(methods
, alias_name
, &rid
);
2298 if (!NT_STATUS_IS_OK(status
)) {
2299 PyErr_Format(py_pdb_error
, "Unable to create alias (%s), (%d,%s)",
2301 NT_STATUS_V(status
),
2302 get_friendly_nt_error_msg(status
));
2308 return PyInt_FromLong(rid
);
2312 static PyObject
*py_pdb_delete_alias(PyObject
*self
, PyObject
*args
)
2314 TALLOC_CTX
*frame
= talloc_stackframe();
2316 struct pdb_methods
*methods
;
2317 PyObject
*py_alias_sid
;
2318 struct dom_sid
*alias_sid
;
2320 if (!PyArg_ParseTuple(args
, "O!:delete_alias", dom_sid_Type
, &py_alias_sid
)) {
2325 methods
= pytalloc_get_ptr(self
);
2327 alias_sid
= pytalloc_get_ptr(py_alias_sid
);
2329 status
= methods
->delete_alias(methods
, alias_sid
);
2330 if (!NT_STATUS_IS_OK(status
)) {
2331 PyErr_Format(py_pdb_error
, "Unable to delete alias, (%d,%s)",
2332 NT_STATUS_V(status
),
2333 get_friendly_nt_error_msg(status
));
2343 static PyObject
*py_pdb_get_aliasinfo(PyObject
*self
, PyObject
*args
)
2345 TALLOC_CTX
*frame
= talloc_stackframe();
2347 struct pdb_methods
*methods
;
2348 PyObject
*py_alias_sid
;
2349 struct dom_sid
*alias_sid
;
2350 struct acct_info
*alias_info
;
2351 PyObject
*py_alias_info
;
2353 if (!PyArg_ParseTuple(args
, "O!:get_aliasinfo", dom_sid_Type
, &py_alias_sid
)) {
2358 methods
= pytalloc_get_ptr(self
);
2360 alias_sid
= pytalloc_get_ptr(py_alias_sid
);
2362 alias_info
= talloc_zero(frame
, struct acct_info
);
2369 status
= methods
->get_aliasinfo(methods
, alias_sid
, alias_info
);
2370 if (!NT_STATUS_IS_OK(status
)) {
2371 PyErr_Format(py_pdb_error
, "Unable to get alias information, (%d,%s)",
2372 NT_STATUS_V(status
),
2373 get_friendly_nt_error_msg(status
));
2378 py_alias_info
= PyDict_New();
2379 if (py_alias_info
== NULL
) {
2385 PyDict_SetItemString(py_alias_info
, "acct_name",
2386 PyStr_FromString(alias_info
->acct_name
));
2387 PyDict_SetItemString(py_alias_info
, "acct_desc",
2388 PyStr_FromString(alias_info
->acct_desc
));
2389 PyDict_SetItemString(py_alias_info
, "rid",
2390 PyInt_FromLong(alias_info
->rid
));
2393 return py_alias_info
;
2397 static PyObject
*py_pdb_set_aliasinfo(PyObject
*self
, PyObject
*args
)
2399 TALLOC_CTX
*frame
= talloc_stackframe();
2401 struct pdb_methods
*methods
;
2402 PyObject
*py_alias_sid
, *py_alias_info
;
2403 struct dom_sid
*alias_sid
;
2404 struct acct_info alias_info
;
2406 if (!PyArg_ParseTuple(args
, "O!O:set_alias_info", dom_sid_Type
, &py_alias_sid
,
2412 methods
= pytalloc_get_ptr(self
);
2414 alias_sid
= pytalloc_get_ptr(py_alias_sid
);
2416 alias_info
.acct_name
= talloc_strdup(frame
, PyStr_AsString(PyDict_GetItemString(py_alias_info
, "acct_name")));
2417 if (alias_info
.acct_name
== NULL
) {
2418 PyErr_Format(py_pdb_error
, "Unable to allocate memory");
2422 alias_info
.acct_desc
= talloc_strdup(frame
, PyStr_AsString(PyDict_GetItemString(py_alias_info
, "acct_desc")));
2423 if (alias_info
.acct_desc
== NULL
) {
2424 PyErr_Format(py_pdb_error
, "Unable to allocate memory");
2429 status
= methods
->set_aliasinfo(methods
, alias_sid
, &alias_info
);
2430 if (!NT_STATUS_IS_OK(status
)) {
2431 PyErr_Format(py_pdb_error
, "Unable to set alias information, (%d,%s)",
2432 NT_STATUS_V(status
),
2433 get_friendly_nt_error_msg(status
));
2443 static PyObject
*py_pdb_add_aliasmem(PyObject
*self
, PyObject
*args
)
2445 TALLOC_CTX
*frame
= talloc_stackframe();
2447 struct pdb_methods
*methods
;
2448 PyObject
*py_alias_sid
, *py_member_sid
;
2449 struct dom_sid
*alias_sid
, *member_sid
;
2451 if (!PyArg_ParseTuple(args
, "O!O!:add_aliasmem", dom_sid_Type
, &py_alias_sid
,
2452 dom_sid_Type
, &py_member_sid
)) {
2457 methods
= pytalloc_get_ptr(self
);
2459 alias_sid
= pytalloc_get_ptr(py_alias_sid
);
2460 member_sid
= pytalloc_get_ptr(py_member_sid
);
2462 status
= methods
->add_aliasmem(methods
, alias_sid
, member_sid
);
2463 if (!NT_STATUS_IS_OK(status
)) {
2464 PyErr_Format(py_pdb_error
, "Unable to add member to alias, (%d,%s)",
2465 NT_STATUS_V(status
),
2466 get_friendly_nt_error_msg(status
));
2476 static PyObject
*py_pdb_del_aliasmem(PyObject
*self
, PyObject
*args
)
2478 TALLOC_CTX
*frame
= talloc_stackframe();
2480 struct pdb_methods
*methods
;
2481 PyObject
*py_alias_sid
, *py_member_sid
;
2482 const struct dom_sid
*alias_sid
, *member_sid
;
2484 if (!PyArg_ParseTuple(args
, "O!O!:del_aliasmem", dom_sid_Type
, &py_alias_sid
,
2485 dom_sid_Type
, &py_member_sid
)) {
2490 methods
= pytalloc_get_ptr(self
);
2492 alias_sid
= pytalloc_get_ptr(py_alias_sid
);
2493 member_sid
= pytalloc_get_ptr(py_member_sid
);
2495 status
= methods
->del_aliasmem(methods
, alias_sid
, member_sid
);
2496 if (!NT_STATUS_IS_OK(status
)) {
2497 PyErr_Format(py_pdb_error
, "Unable to delete member from alias, (%d,%s)",
2498 NT_STATUS_V(status
),
2499 get_friendly_nt_error_msg(status
));
2509 static PyObject
*py_pdb_enum_aliasmem(PyObject
*self
, PyObject
*args
)
2511 TALLOC_CTX
*frame
= talloc_stackframe();
2513 struct pdb_methods
*methods
;
2514 PyObject
*py_alias_sid
;
2515 struct dom_sid
*alias_sid
, *member_sid
, *tmp_sid
;
2516 PyObject
*py_member_list
, *py_member_sid
;
2520 if (!PyArg_ParseTuple(args
, "O!:enum_aliasmem", dom_sid_Type
, &py_alias_sid
)) {
2525 methods
= pytalloc_get_ptr(self
);
2527 alias_sid
= pytalloc_get_ptr(py_alias_sid
);
2529 status
= methods
->enum_aliasmem(methods
, alias_sid
, frame
, &member_sid
, &num_members
);
2530 if (!NT_STATUS_IS_OK(status
)) {
2531 PyErr_Format(py_pdb_error
, "Unable to enumerate members for alias, (%d,%s)",
2532 NT_STATUS_V(status
),
2533 get_friendly_nt_error_msg(status
));
2538 py_member_list
= PyList_New(0);
2539 if (py_member_list
== NULL
) {
2545 for(i
=0; i
<num_members
; i
++) {
2546 py_member_sid
= pytalloc_new(struct dom_sid
, dom_sid_Type
);
2547 if (py_member_sid
== NULL
) {
2552 tmp_sid
= pytalloc_get_ptr(py_member_sid
);
2553 *tmp_sid
= member_sid
[i
];
2554 PyList_Append(py_member_list
, py_member_sid
);
2558 return py_member_list
;
2562 static PyObject
*py_pdb_get_account_policy(PyObject
*self
, PyObject
*unused
)
2564 TALLOC_CTX
*frame
= talloc_stackframe();
2566 struct pdb_methods
*methods
;
2567 PyObject
*py_acct_policy
;
2571 enum pdb_policy_type type
;
2573 methods
= pytalloc_get_ptr(self
);
2575 py_acct_policy
= PyDict_New();
2576 if (py_acct_policy
== NULL
) {
2582 account_policy_names_list(frame
, &names
, &count
);
2583 for (i
=0; i
<count
; i
++) {
2584 type
= account_policy_name_to_typenum(names
[i
]);
2585 status
= methods
->get_account_policy(methods
, type
, &value
);
2586 if (NT_STATUS_IS_OK(status
)) {
2587 PyDict_SetItemString(py_acct_policy
, names
[i
], Py_BuildValue("i", value
));
2592 return py_acct_policy
;
2596 static PyObject
*py_pdb_set_account_policy(PyObject
*self
, PyObject
*args
)
2598 TALLOC_CTX
*frame
= talloc_stackframe();
2600 struct pdb_methods
*methods
;
2601 PyObject
*py_acct_policy
, *py_value
;
2604 enum pdb_policy_type type
;
2606 if (!PyArg_ParseTuple(args
, "O!:set_account_policy", PyDict_Type
, &py_acct_policy
)) {
2611 methods
= pytalloc_get_ptr(self
);
2613 account_policy_names_list(frame
, &names
, &count
);
2614 for (i
=0; i
<count
; i
++) {
2615 if ((py_value
= PyDict_GetItemString(py_acct_policy
, names
[i
])) != NULL
) {
2616 type
= account_policy_name_to_typenum(names
[i
]);
2617 status
= methods
->set_account_policy(methods
, type
, PyInt_AsLong(py_value
));
2618 if (!NT_STATUS_IS_OK(status
)) {
2619 PyErr_Format(py_pdb_error
, "Error setting account policy (%s), (%d,%s)",
2621 NT_STATUS_V(status
),
2622 get_friendly_nt_error_msg(status
));
2631 static PyObject
*py_pdb_search_users(PyObject
*self
, PyObject
*args
)
2633 TALLOC_CTX
*frame
= talloc_stackframe();
2634 struct pdb_methods
*methods
;
2635 unsigned int acct_flags
;
2636 struct pdb_search
*search
;
2637 struct samr_displayentry
*entry
;
2638 PyObject
*py_userlist
, *py_dict
;
2640 if (!PyArg_ParseTuple(args
, "I:search_users", &acct_flags
)) {
2645 methods
= pytalloc_get_ptr(self
);
2647 search
= talloc_zero(frame
, struct pdb_search
);
2648 if (search
== NULL
) {
2654 if (!methods
->search_users(methods
, search
, acct_flags
)) {
2655 PyErr_Format(py_pdb_error
, "Unable to search users");
2660 entry
= talloc_zero(frame
, struct samr_displayentry
);
2661 if (entry
== NULL
) {
2667 py_userlist
= PyList_New(0);
2668 if (py_userlist
== NULL
) {
2674 while (search
->next_entry(search
, entry
)) {
2675 py_dict
= PyDict_New();
2676 if (py_dict
== NULL
) {
2679 PyDict_SetItemString(py_dict
, "idx", PyInt_FromLong(entry
->idx
));
2680 PyDict_SetItemString(py_dict
, "rid", PyInt_FromLong(entry
->rid
));
2681 PyDict_SetItemString(py_dict
, "acct_flags", PyInt_FromLong(entry
->acct_flags
));
2682 PyDict_SetItemString(py_dict
, "account_name", PyStr_FromString(entry
->account_name
));
2683 PyDict_SetItemString(py_dict
, "fullname", PyStr_FromString(entry
->fullname
));
2684 PyDict_SetItemString(py_dict
, "description", PyStr_FromString(entry
->description
));
2685 PyList_Append(py_userlist
, py_dict
);
2688 search
->search_end(search
);
2695 static PyObject
*py_pdb_search_groups(PyObject
*self
, PyObject
*unused
)
2697 TALLOC_CTX
*frame
= talloc_stackframe();
2698 struct pdb_methods
*methods
;
2699 struct pdb_search
*search
;
2700 struct samr_displayentry
*entry
;
2701 PyObject
*py_grouplist
, *py_dict
;
2703 methods
= pytalloc_get_ptr(self
);
2705 search
= talloc_zero(frame
, struct pdb_search
);
2706 if (search
== NULL
) {
2712 if (!methods
->search_groups(methods
, search
)) {
2713 PyErr_Format(py_pdb_error
, "Unable to search groups");
2718 entry
= talloc_zero(frame
, struct samr_displayentry
);
2719 if (entry
== NULL
) {
2725 py_grouplist
= PyList_New(0);
2726 if (py_grouplist
== NULL
) {
2732 while (search
->next_entry(search
, entry
)) {
2733 py_dict
= PyDict_New();
2734 if (py_dict
== NULL
) {
2737 PyDict_SetItemString(py_dict
, "idx", PyInt_FromLong(entry
->idx
));
2738 PyDict_SetItemString(py_dict
, "rid", PyInt_FromLong(entry
->rid
));
2739 PyDict_SetItemString(py_dict
, "acct_flags", PyInt_FromLong(entry
->acct_flags
));
2740 PyDict_SetItemString(py_dict
, "account_name", PyStr_FromString(entry
->account_name
));
2741 PyDict_SetItemString(py_dict
, "fullname", PyStr_FromString(entry
->fullname
));
2742 PyDict_SetItemString(py_dict
, "description", PyStr_FromString(entry
->description
));
2743 PyList_Append(py_grouplist
, py_dict
);
2746 search
->search_end(search
);
2749 return py_grouplist
;
2753 static PyObject
*py_pdb_search_aliases(PyObject
*self
, PyObject
*args
)
2755 TALLOC_CTX
*frame
= talloc_stackframe();
2756 struct pdb_methods
*methods
;
2757 struct pdb_search
*search
;
2758 struct samr_displayentry
*entry
;
2759 PyObject
*py_aliaslist
, *py_dict
;
2760 PyObject
*py_domain_sid
= Py_None
;
2761 struct dom_sid
*domain_sid
= NULL
;
2765 if (!PyArg_ParseTuple(args
, "|O!:search_aliases", dom_sid_Type
, &py_domain_sid
)) {
2770 methods
= pytalloc_get_ptr(self
);
2772 if (py_domain_sid
!= Py_None
) {
2773 domain_sid
= pytalloc_get_ptr(py_domain_sid
);
2776 search
= talloc_zero(frame
, struct pdb_search
);
2777 if (search
== NULL
) {
2783 if (!methods
->search_aliases(methods
, search
, domain_sid
)) {
2784 PyErr_Format(py_pdb_error
, "Unable to search aliases");
2789 entry
= talloc_zero(frame
, struct samr_displayentry
);
2790 if (entry
== NULL
) {
2796 py_aliaslist
= PyList_New(0);
2797 if (py_aliaslist
== NULL
) {
2803 while (search
->next_entry(search
, entry
)) {
2804 py_dict
= PyDict_New();
2805 if (py_dict
== NULL
) {
2808 PyDict_SetItemString(py_dict
, "idx", PyInt_FromLong(entry
->idx
));
2809 PyDict_SetItemString(py_dict
, "rid", PyInt_FromLong(entry
->rid
));
2810 PyDict_SetItemString(py_dict
, "acct_flags", PyInt_FromLong(entry
->acct_flags
));
2811 PyDict_SetItemString(py_dict
, "account_name", PyStr_FromString(entry
->account_name
));
2812 PyDict_SetItemString(py_dict
, "fullname", PyStr_FromString(entry
->fullname
));
2813 PyDict_SetItemString(py_dict
, "description", PyStr_FromString(entry
->description
));
2814 PyList_Append(py_aliaslist
, py_dict
);
2817 search
->search_end(search
);
2820 return py_aliaslist
;
2824 static PyObject
*py_pdb_uid_to_sid(PyObject
*self
, PyObject
*args
)
2826 TALLOC_CTX
*frame
= talloc_stackframe();
2827 struct pdb_methods
*methods
;
2830 struct dom_sid user_sid
, *copy_user_sid
;
2831 PyObject
*py_user_sid
;
2833 if (!PyArg_ParseTuple(args
, "I:uid_to_sid", &uid
)) {
2838 methods
= pytalloc_get_ptr(self
);
2841 id
.type
= ID_TYPE_UID
;
2843 if (!methods
->id_to_sid(methods
, &id
, &user_sid
)) {
2844 PyErr_Format(py_pdb_error
, "Unable to get sid for uid=%d", uid
);
2849 copy_user_sid
= dom_sid_dup(frame
, &user_sid
);
2850 if (copy_user_sid
== NULL
) {
2856 py_user_sid
= pytalloc_steal(dom_sid_Type
, copy_user_sid
);
2863 static PyObject
*py_pdb_gid_to_sid(PyObject
*self
, PyObject
*args
)
2865 TALLOC_CTX
*frame
= talloc_stackframe();
2866 struct pdb_methods
*methods
;
2869 struct dom_sid group_sid
, *copy_group_sid
;
2870 PyObject
*py_group_sid
;
2872 if (!PyArg_ParseTuple(args
, "I:gid_to_sid", &gid
)) {
2878 id
.type
= ID_TYPE_GID
;
2880 methods
= pytalloc_get_ptr(self
);
2882 if (!methods
->id_to_sid(methods
, &id
, &group_sid
)) {
2883 PyErr_Format(py_pdb_error
, "Unable to get sid for gid=%d", gid
);
2888 copy_group_sid
= dom_sid_dup(frame
, &group_sid
);
2889 if (copy_group_sid
== NULL
) {
2895 py_group_sid
= pytalloc_steal(dom_sid_Type
, copy_group_sid
);
2898 return py_group_sid
;
2902 static PyObject
*py_pdb_sid_to_id(PyObject
*self
, PyObject
*args
)
2904 TALLOC_CTX
*frame
= talloc_stackframe();
2905 struct pdb_methods
*methods
;
2907 struct dom_sid
*sid
;
2910 if (!PyArg_ParseTuple(args
, "O!:sid_to_id", dom_sid_Type
, &py_sid
)) {
2915 methods
= pytalloc_get_ptr(self
);
2917 sid
= pytalloc_get_ptr(py_sid
);
2919 if (!methods
->sid_to_id(methods
, sid
, &id
)) {
2920 PyErr_Format(py_pdb_error
, "Unable to get id for sid");
2926 return Py_BuildValue("(II)", id
.id
, id
.type
);
2930 static PyObject
*py_pdb_new_rid(PyObject
*self
, PyObject
*unused
)
2932 TALLOC_CTX
*frame
= talloc_stackframe();
2933 struct pdb_methods
*methods
;
2936 methods
= pytalloc_get_ptr(self
);
2938 if (!methods
->new_rid(methods
, &rid
)) {
2939 PyErr_Format(py_pdb_error
, "Unable to get new rid");
2945 return PyInt_FromLong(rid
);
2949 static PyObject
*py_pdb_get_trusteddom_pw(PyObject
*self
, PyObject
*args
)
2951 TALLOC_CTX
*frame
= talloc_stackframe();
2952 struct pdb_methods
*methods
;
2955 struct dom_sid sid
, *copy_sid
;
2957 time_t last_set_time
;
2960 if (!PyArg_ParseTuple(args
, "s:get_trusteddom_pw", &domain
)) {
2965 methods
= pytalloc_get_ptr(self
);
2967 if (!methods
->get_trusteddom_pw(methods
, domain
, &pwd
, &sid
, &last_set_time
)) {
2968 PyErr_Format(py_pdb_error
, "Unable to get trusted domain password");
2973 copy_sid
= dom_sid_dup(frame
, &sid
);
2974 if (copy_sid
== NULL
) {
2980 py_sid
= pytalloc_steal(dom_sid_Type
, copy_sid
);
2981 if (py_sid
== NULL
) {
2987 py_value
= PyDict_New();
2988 if (py_value
== NULL
) {
2994 PyDict_SetItemString(py_value
, "pwd", PyStr_FromString(pwd
));
2995 PyDict_SetItemString(py_value
, "sid", py_sid
);
2996 PyDict_SetItemString(py_value
, "last_set_tim", PyInt_FromLong(last_set_time
));
3003 static PyObject
*py_pdb_set_trusteddom_pw(PyObject
*self
, PyObject
*args
)
3005 TALLOC_CTX
*frame
= talloc_stackframe();
3006 struct pdb_methods
*methods
;
3009 const struct dom_sid
*domain_sid
;
3010 PyObject
*py_domain_sid
;
3012 if (!PyArg_ParseTuple(args
, "ssO!:set_trusteddom_pw", &domain
, &pwd
,
3013 dom_sid_Type
, &py_domain_sid
)) {
3018 methods
= pytalloc_get_ptr(self
);
3020 domain_sid
= pytalloc_get_ptr(py_domain_sid
);
3022 if (!methods
->set_trusteddom_pw(methods
, domain
, pwd
, domain_sid
)) {
3023 PyErr_Format(py_pdb_error
, "Unable to set trusted domain password");
3033 static PyObject
*py_pdb_del_trusteddom_pw(PyObject
*self
, PyObject
*args
)
3035 TALLOC_CTX
*frame
= talloc_stackframe();
3036 struct pdb_methods
*methods
;
3039 if (!PyArg_ParseTuple(args
, "s:del_trusteddom_pw", &domain
)) {
3044 methods
= pytalloc_get_ptr(self
);
3046 if (!methods
->del_trusteddom_pw(methods
, domain
)) {
3047 PyErr_Format(py_pdb_error
, "Unable to delete trusted domain password");
3057 static PyObject
*py_pdb_enum_trusteddoms(PyObject
*self
, PyObject
*unused
)
3059 TALLOC_CTX
*frame
= talloc_stackframe();
3061 struct pdb_methods
*methods
;
3062 uint32_t num_domains
;
3063 struct trustdom_info
**domains
;
3064 PyObject
*py_domain_list
, *py_dict
;
3067 methods
= pytalloc_get_ptr(self
);
3069 status
= methods
->enum_trusteddoms(methods
, frame
, &num_domains
, &domains
);
3070 if (!NT_STATUS_IS_OK(status
)) {
3071 PyErr_Format(py_pdb_error
, "Unable to enumerate trusted domains, (%d,%s)",
3072 NT_STATUS_V(status
),
3073 get_friendly_nt_error_msg(status
));
3078 py_domain_list
= PyList_New(0);
3079 if (py_domain_list
== NULL
) {
3085 for(i
=0; i
<num_domains
; i
++) {
3086 py_dict
= PyDict_New();
3088 PyDict_SetItemString(py_dict
, "name",
3089 PyStr_FromString(domains
[i
]->name
));
3090 PyDict_SetItemString(py_dict
, "sid",
3091 pytalloc_steal(dom_sid_Type
, &domains
[i
]->sid
));
3094 PyList_Append(py_domain_list
, py_dict
);
3098 return py_domain_list
;
3102 static PyObject
*py_pdb_get_trusted_domain(PyObject
*self
, PyObject
*args
)
3104 TALLOC_CTX
*frame
= talloc_stackframe();
3106 struct pdb_methods
*methods
;
3108 struct pdb_trusted_domain
*td
;
3109 PyObject
*py_domain_info
;
3111 if (!PyArg_ParseTuple(args
, "s:get_trusted_domain", &domain
)) {
3116 methods
= pytalloc_get_ptr(self
);
3118 status
= methods
->get_trusted_domain(methods
, frame
, domain
, &td
);
3119 if (!NT_STATUS_IS_OK(status
)) {
3120 PyErr_Format(py_pdb_error
, "Unable to get trusted domain information, (%d,%s)",
3121 NT_STATUS_V(status
),
3122 get_friendly_nt_error_msg(status
));
3127 py_domain_info
= PyDict_New();
3128 if (py_domain_info
== NULL
) {
3134 PyDict_SetItemString(py_domain_info
, "domain_name",
3135 PyStr_FromString(td
->domain_name
));
3136 PyDict_SetItemString(py_domain_info
, "netbios_name",
3137 PyStr_FromString(td
->netbios_name
));
3138 PyDict_SetItemString(py_domain_info
, "security_identifier",
3139 pytalloc_steal(dom_sid_Type
, &td
->security_identifier
));
3140 PyDict_SetItemString(py_domain_info
, "trust_auth_incoming",
3141 PyBytes_FromStringAndSize((const char *)td
->trust_auth_incoming
.data
,
3142 td
->trust_auth_incoming
.length
));
3143 PyDict_SetItemString(py_domain_info
, "trust_auth_outgoing",
3144 PyBytes_FromStringAndSize((const char *)td
->trust_auth_outgoing
.data
,
3145 td
->trust_auth_outgoing
.length
));
3146 PyDict_SetItemString(py_domain_info
, "trust_direction",
3147 PyInt_FromLong(td
->trust_direction
));
3148 PyDict_SetItemString(py_domain_info
, "trust_type",
3149 PyInt_FromLong(td
->trust_type
));
3150 PyDict_SetItemString(py_domain_info
, "trust_attributes",
3151 PyInt_FromLong(td
->trust_attributes
));
3152 PyDict_SetItemString(py_domain_info
, "trust_forest_trust_info",
3153 PyBytes_FromStringAndSize((const char *)td
->trust_forest_trust_info
.data
,
3154 td
->trust_forest_trust_info
.length
));
3157 return py_domain_info
;
3161 static PyObject
*py_pdb_get_trusted_domain_by_sid(PyObject
*self
, PyObject
*args
)
3163 TALLOC_CTX
*frame
= talloc_stackframe();
3165 struct pdb_methods
*methods
;
3166 PyObject
*py_domain_sid
;
3167 struct dom_sid
*domain_sid
;
3168 struct pdb_trusted_domain
*td
;
3169 PyObject
*py_domain_info
;
3171 if (!PyArg_ParseTuple(args
, "O!:get_trusted_domain_by_sid", dom_sid_Type
, &py_domain_sid
)) {
3176 methods
= pytalloc_get_ptr(self
);
3178 domain_sid
= pytalloc_get_ptr(py_domain_sid
);
3180 status
= methods
->get_trusted_domain_by_sid(methods
, frame
, domain_sid
, &td
);
3181 if (!NT_STATUS_IS_OK(status
)) {
3182 PyErr_Format(py_pdb_error
, "Unable to get trusted domain information, (%d,%s)",
3183 NT_STATUS_V(status
),
3184 get_friendly_nt_error_msg(status
));
3189 py_domain_info
= PyDict_New();
3190 if (py_domain_info
== NULL
) {
3196 PyDict_SetItemString(py_domain_info
, "domain_name",
3197 PyStr_FromString(td
->domain_name
));
3198 PyDict_SetItemString(py_domain_info
, "netbios_name",
3199 PyStr_FromString(td
->netbios_name
));
3200 PyDict_SetItemString(py_domain_info
, "security_identifier",
3201 pytalloc_steal(dom_sid_Type
, &td
->security_identifier
));
3202 PyDict_SetItemString(py_domain_info
, "trust_auth_incoming",
3203 PyBytes_FromStringAndSize((char *)td
->trust_auth_incoming
.data
,
3204 td
->trust_auth_incoming
.length
));
3205 PyDict_SetItemString(py_domain_info
, "trust_auth_outgoing",
3206 PyBytes_FromStringAndSize((char *)td
->trust_auth_outgoing
.data
,
3207 td
->trust_auth_outgoing
.length
));
3208 PyDict_SetItemString(py_domain_info
, "trust_direction",
3209 PyInt_FromLong(td
->trust_direction
));
3210 PyDict_SetItemString(py_domain_info
, "trust_type",
3211 PyInt_FromLong(td
->trust_type
));
3212 PyDict_SetItemString(py_domain_info
, "trust_attributes",
3213 PyInt_FromLong(td
->trust_attributes
));
3214 PyDict_SetItemString(py_domain_info
, "trust_forest_trust_info",
3215 PyBytes_FromStringAndSize((char *)td
->trust_forest_trust_info
.data
,
3216 td
->trust_forest_trust_info
.length
));
3219 return py_domain_info
;
3223 static PyObject
*py_pdb_set_trusted_domain(PyObject
*self
, PyObject
*args
)
3225 TALLOC_CTX
*frame
= talloc_stackframe();
3227 struct pdb_methods
*methods
;
3229 PyObject
*py_td_info
;
3230 struct pdb_trusted_domain td_info
;
3234 if (!PyArg_ParseTuple(args
, "sO!:set_trusted_domain", &domain
, &PyDict_Type
, &py_td_info
)) {
3239 py_tmp
= PyDict_GetItemString(py_td_info
, "domain_name");
3240 td_info
.domain_name
= discard_const_p(char, PyStr_AsString(py_tmp
));
3242 py_tmp
= PyDict_GetItemString(py_td_info
, "netbios_name");
3243 td_info
.netbios_name
= discard_const_p(char, PyStr_AsString(py_tmp
));
3245 py_tmp
= PyDict_GetItemString(py_td_info
, "security_identifier");
3246 td_info
.security_identifier
= *pytalloc_get_type(py_tmp
, struct dom_sid
);
3248 py_tmp
= PyDict_GetItemString(py_td_info
, "trust_auth_incoming");
3249 PyBytes_AsStringAndSize(py_tmp
, (char **)&td_info
.trust_auth_incoming
.data
, &len
);
3250 td_info
.trust_auth_incoming
.length
= len
;
3252 py_tmp
= PyDict_GetItemString(py_td_info
, "trust_auth_outgoing");
3253 PyBytes_AsStringAndSize(py_tmp
, (char **)&td_info
.trust_auth_outgoing
.data
, &len
);
3254 td_info
.trust_auth_outgoing
.length
= len
;
3256 py_tmp
= PyDict_GetItemString(py_td_info
, "trust_direction");
3257 td_info
.trust_direction
= PyInt_AsLong(py_tmp
);
3259 py_tmp
= PyDict_GetItemString(py_td_info
, "trust_type");
3260 td_info
.trust_type
= PyInt_AsLong(py_tmp
);
3262 py_tmp
= PyDict_GetItemString(py_td_info
, "trust_attributes");
3263 td_info
.trust_attributes
= PyInt_AsLong(py_tmp
);
3265 py_tmp
= PyDict_GetItemString(py_td_info
, "trust_forest_trust_info");
3266 PyBytes_AsStringAndSize(py_tmp
, (char **)&td_info
.trust_forest_trust_info
.data
, &len
);
3267 td_info
.trust_forest_trust_info
.length
= len
;
3269 methods
= pytalloc_get_ptr(self
);
3271 status
= methods
->set_trusted_domain(methods
, domain
, &td_info
);
3272 if (!NT_STATUS_IS_OK(status
)) {
3273 PyErr_Format(py_pdb_error
, "Unable to set trusted domain information, (%d,%s)",
3274 NT_STATUS_V(status
),
3275 get_friendly_nt_error_msg(status
));
3285 static PyObject
*py_pdb_del_trusted_domain(PyObject
*self
, PyObject
*args
)
3287 TALLOC_CTX
*frame
= talloc_stackframe();
3289 struct pdb_methods
*methods
;
3292 if (!PyArg_ParseTuple(args
, "s:del_trusted_domain", &domain
)) {
3297 methods
= pytalloc_get_ptr(self
);
3299 status
= methods
->del_trusted_domain(methods
, domain
);
3300 if (!NT_STATUS_IS_OK(status
)) {
3301 PyErr_Format(py_pdb_error
, "Unable to delete trusted domain, (%d,%s)",
3302 NT_STATUS_V(status
),
3303 get_friendly_nt_error_msg(status
));
3313 static PyObject
*py_pdb_enum_trusted_domains(PyObject
*self
, PyObject
*args
)
3315 TALLOC_CTX
*frame
= talloc_stackframe();
3317 struct pdb_methods
*methods
;
3318 uint32_t num_domains
;
3319 struct pdb_trusted_domain
**td_info
, *td
;
3320 PyObject
*py_td_info
, *py_domain_info
;
3323 methods
= pytalloc_get_ptr(self
);
3325 status
= methods
->enum_trusted_domains(methods
, frame
, &num_domains
, &td_info
);
3326 if (!NT_STATUS_IS_OK(status
)) {
3327 PyErr_Format(py_pdb_error
, "Unable to delete trusted domain, (%d,%s)",
3328 NT_STATUS_V(status
),
3329 get_friendly_nt_error_msg(status
));
3334 py_td_info
= PyList_New(0);
3335 if (py_td_info
== NULL
) {
3341 for (i
=0; i
<num_domains
; i
++) {
3343 py_domain_info
= PyDict_New();
3344 if (py_domain_info
== NULL
) {
3346 Py_DECREF(py_td_info
);
3353 PyDict_SetItemString(py_domain_info
, "domain_name",
3354 PyStr_FromString(td
->domain_name
));
3355 PyDict_SetItemString(py_domain_info
, "netbios_name",
3356 PyStr_FromString(td
->netbios_name
));
3357 PyDict_SetItemString(py_domain_info
, "security_identifier",
3358 pytalloc_steal(dom_sid_Type
, &td
->security_identifier
));
3359 PyDict_SetItemString(py_domain_info
, "trust_auth_incoming",
3360 PyBytes_FromStringAndSize((const char *)td
->trust_auth_incoming
.data
,
3361 td
->trust_auth_incoming
.length
));
3362 PyDict_SetItemString(py_domain_info
, "trust_auth_outgoing",
3363 PyBytes_FromStringAndSize((const char *)td
->trust_auth_outgoing
.data
,
3364 td
->trust_auth_outgoing
.length
));
3365 PyDict_SetItemString(py_domain_info
, "trust_direction",
3366 PyInt_FromLong(td
->trust_direction
));
3367 PyDict_SetItemString(py_domain_info
, "trust_type",
3368 PyInt_FromLong(td
->trust_type
));
3369 PyDict_SetItemString(py_domain_info
, "trust_attributes",
3370 PyInt_FromLong(td
->trust_attributes
));
3371 PyDict_SetItemString(py_domain_info
, "trust_forest_trust_info",
3372 PyBytes_FromStringAndSize((const char *)td
->trust_forest_trust_info
.data
,
3373 td
->trust_forest_trust_info
.length
));
3374 PyList_Append(py_td_info
, py_domain_info
);
3382 static PyObject
*py_pdb_get_secret(PyObject
*self
, PyObject
*args
)
3384 TALLOC_CTX
*frame
= talloc_stackframe();
3386 struct pdb_methods
*methods
;
3387 const char *secret_name
;
3388 DATA_BLOB secret_current
, secret_old
;
3389 NTTIME secret_current_lastchange
, secret_old_lastchange
;
3391 struct security_descriptor
*sd
;
3392 PyObject
*py_secret
;
3394 if (!PyArg_ParseTuple(args
, "s:get_secret_name", &secret_name
)) {
3399 methods
= pytalloc_get_ptr(self
);
3401 py_sd
= pytalloc_new(struct security_descriptor
, security_Type
);
3402 if (py_sd
== NULL
) {
3407 sd
= pytalloc_get_ptr(py_sd
);
3409 status
= methods
->get_secret(methods
, frame
, secret_name
,
3411 &secret_current_lastchange
,
3413 &secret_old_lastchange
,
3415 if (!NT_STATUS_IS_OK(status
)) {
3416 PyErr_Format(py_pdb_error
, "Unable to get information for secret (%s), (%d,%s)",
3418 NT_STATUS_V(status
),
3419 get_friendly_nt_error_msg(status
));
3424 py_secret
= PyDict_New();
3425 if (py_secret
== NULL
) {
3432 PyDict_SetItemString(py_secret
, "secret_current",
3433 PyBytes_FromStringAndSize((const char*)secret_current
.data
, secret_current
.length
));
3434 PyDict_SetItemString(py_secret
, "secret_current_lastchange",
3435 PyLong_FromUnsignedLongLong(secret_current_lastchange
));
3436 PyDict_SetItemString(py_secret
, "secret_old",
3437 PyBytes_FromStringAndSize((const char*)secret_old
.data
, secret_old
.length
));
3438 PyDict_SetItemString(py_secret
, "secret_old_lastchange",
3439 PyLong_FromUnsignedLongLong(secret_old_lastchange
));
3440 PyDict_SetItemString(py_secret
, "sd", py_sd
);
3447 static PyObject
*py_pdb_set_secret(PyObject
*self
, PyObject
*args
)
3449 TALLOC_CTX
*frame
= talloc_stackframe();
3451 struct pdb_methods
*methods
;
3452 const char *secret_name
;
3453 PyObject
*py_secret
;
3454 PyObject
*py_secret_cur
, *py_secret_old
, *py_sd
;
3455 DATA_BLOB secret_current
, secret_old
;
3456 struct security_descriptor
*sd
;
3459 if (!PyArg_ParseTuple(args
, "sO!:set_secret_name", &secret_name
, PyDict_Type
, &py_secret
)) {
3464 py_secret_cur
= PyDict_GetItemString(py_secret
, "secret_current");
3465 py_secret_old
= PyDict_GetItemString(py_secret
, "secret_old");
3466 py_sd
= PyDict_GetItemString(py_secret
, "sd");
3468 PY_CHECK_TYPE(&PyBytes_Type
, py_secret_cur
, return NULL
;);
3469 PY_CHECK_TYPE(&PyBytes_Type
, py_secret_old
, return NULL
;);
3470 PY_CHECK_TYPE(security_Type
, py_sd
, return NULL
;);
3472 methods
= pytalloc_get_ptr(self
);
3474 PyBytes_AsStringAndSize(py_secret_cur
, (char **)&secret_current
.data
, &len
);
3475 secret_current
.length
= len
;
3476 PyBytes_AsStringAndSize(py_secret_old
, (char **)&secret_old
.data
, &len
);
3477 secret_current
.length
= len
;
3478 sd
= pytalloc_get_ptr(py_sd
);
3480 status
= methods
->set_secret(methods
, secret_name
, &secret_current
, &secret_old
, sd
);
3481 if (!NT_STATUS_IS_OK(status
)) {
3482 PyErr_Format(py_pdb_error
, "Unable to set information for secret (%s), (%d,%s)",
3484 NT_STATUS_V(status
),
3485 get_friendly_nt_error_msg(status
));
3495 static PyObject
*py_pdb_delete_secret(PyObject
*self
, PyObject
*args
)
3497 TALLOC_CTX
*frame
= talloc_stackframe();
3499 struct pdb_methods
*methods
;
3500 const char *secret_name
;
3502 if (!PyArg_ParseTuple(args
, "s:delete_secret", &secret_name
)) {
3507 methods
= pytalloc_get_ptr(self
);
3509 status
= methods
->delete_secret(methods
, secret_name
);
3510 if (!NT_STATUS_IS_OK(status
)) {
3511 PyErr_Format(py_pdb_error
, "Unable to delete secret (%s), (%d,%s)",
3513 NT_STATUS_V(status
),
3514 get_friendly_nt_error_msg(status
));
3523 static PyMethodDef py_pdb_methods
[] = {
3524 { "domain_info", py_pdb_domain_info
, METH_NOARGS
,
3525 "domain_info() -> str\n\n \
3526 Get domain information for the database." },
3527 { "getsampwnam", py_pdb_getsampwnam
, METH_VARARGS
,
3528 "getsampwnam(username) -> samu object\n\n \
3529 Get user information by name." },
3530 { "getsampwsid", py_pdb_getsampwsid
, METH_VARARGS
,
3531 "getsampwsid(user_sid) -> samu object\n\n \
3532 Get user information by sid (dcerpc.security.dom_sid object)." },
3533 { "create_user", py_pdb_create_user
, METH_VARARGS
,
3534 "create_user(username, acct_flags) -> rid\n\n \
3535 Create user. acct_flags are samr account control flags." },
3536 { "delete_user", py_pdb_delete_user
, METH_VARARGS
,
3537 "delete_user(samu object) -> None\n\n \
3539 { "add_sam_account", py_pdb_add_sam_account
, METH_VARARGS
,
3540 "add_sam_account(samu object) -> None\n\n \
3541 Add SAM account." },
3542 { "update_sam_account", py_pdb_update_sam_account
, METH_VARARGS
,
3543 "update_sam_account(samu object) -> None\n\n \
3544 Update SAM account." },
3545 { "delete_sam_account", py_pdb_delete_sam_account
, METH_VARARGS
,
3546 "delete_sam_account(samu object) -> None\n\n \
3547 Delete SAM account." },
3548 { "rename_sam_account", py_pdb_rename_sam_account
, METH_VARARGS
,
3549 "rename_sam_account(samu object1, new_username) -> None\n\n \
3550 Rename SAM account." },
3551 /* update_login_attempts */
3552 { "getgrsid", py_pdb_getgrsid
, METH_VARARGS
,
3553 "getgrsid(group_sid) -> groupmap object\n\n \
3554 Get group information by sid (dcerpc.security.dom_sid object)." },
3555 { "getgrgid", py_pdb_getgrgid
, METH_VARARGS
,
3556 "getgrsid(gid) -> groupmap object\n\n \
3557 Get group information by gid." },
3558 { "getgrnam", py_pdb_getgrnam
, METH_VARARGS
,
3559 "getgrsid(groupname) -> groupmap object\n\n \
3560 Get group information by name." },
3561 { "create_dom_group", py_pdb_create_dom_group
, METH_VARARGS
,
3562 "create_dom_group(groupname) -> group_rid\n\n \
3563 Create new domain group by name." },
3564 { "delete_dom_group", py_pdb_delete_dom_group
, METH_VARARGS
,
3565 "delete_dom_group(group_rid) -> None\n\n \
3566 Delete domain group identified by rid" },
3567 { "add_group_mapping_entry", py_pdb_add_group_mapping_entry
, METH_VARARGS
,
3568 "add_group_mapping_entry(groupmap) -> None\n \
3569 Add group mapping entry for groupmap object." },
3570 { "update_group_mapping_entry", py_pdb_update_group_mapping_entry
, METH_VARARGS
,
3571 "update_group_mapping_entry(groupmap) -> None\n\n \
3572 Update group mapping entry for groupmap object." },
3573 { "delete_group_mapping_entry", py_pdb_delete_group_mapping_entry
, METH_VARARGS
,
3574 "delete_group_mapping_entry(groupmap) -> None\n\n \
3575 Delete group mapping entry for groupmap object." },
3576 { "enum_group_mapping", py_pdb_enum_group_mapping
, METH_VARARGS
,
3577 "enum_group_mapping([domain_sid, [type, [unix_only]]]) -> List\n\n \
3578 Return list of group mappings as groupmap objects. Optional arguments are domain_sid object, type of group, unix only flag." },
3579 { "enum_group_members", py_pdb_enum_group_members
, METH_VARARGS
,
3580 "enum_group_members(group_sid) -> List\n\n \
3581 Return list of users (dom_sid object) in group." },
3582 { "enum_group_memberships", py_pdb_enum_group_memberships
, METH_VARARGS
,
3583 "enum_group_memberships(samu object) -> List\n\n \
3584 Return list of groups (dom_sid object) this user is part of." },
3585 /* set_unix_primary_group */
3586 { "add_groupmem", py_pdb_add_groupmem
, METH_VARARGS
,
3587 "add_groupmem(group_rid, member_rid) -> None\n\n \
3588 Add user to group." },
3589 { "del_groupmem", py_pdb_del_groupmem
, METH_VARARGS
,
3590 "del_groupmem(group_rid, member_rid) -> None\n\n \
3591 Remove user from from group." },
3592 { "create_alias", py_pdb_create_alias
, METH_VARARGS
,
3593 "create_alias(alias_name) -> alias_rid\n\n \
3594 Create alias entry." },
3595 { "delete_alias", py_pdb_delete_alias
, METH_VARARGS
,
3596 "delete_alias(alias_sid) -> None\n\n \
3597 Delete alias entry." },
3598 { "get_aliasinfo", py_pdb_get_aliasinfo
, METH_VARARGS
,
3599 "get_aliasinfo(alias_sid) -> Mapping\n\n \
3600 Get alias information as a dictionary with keys - acct_name, acct_desc, rid." },
3601 { "set_aliasinfo", py_pdb_set_aliasinfo
, METH_VARARGS
,
3602 "set_alias_info(alias_sid, Mapping) -> None\n\n \
3603 Set alias information from a dictionary with keys - acct_name, acct_desc." },
3604 { "add_aliasmem", py_pdb_add_aliasmem
, METH_VARARGS
,
3605 "add_aliasmem(alias_sid, member_sid) -> None\n\n \
3606 Add user to alias entry." },
3607 { "del_aliasmem", py_pdb_del_aliasmem
, METH_VARARGS
,
3608 "del_aliasmem(alias_sid, member_sid) -> None\n\n \
3609 Remove a user from alias entry." },
3610 { "enum_aliasmem", py_pdb_enum_aliasmem
, METH_VARARGS
,
3611 "enum_aliasmem(alias_sid) -> List\n\n \
3612 Return a list of members (dom_sid object) for alias entry." },
3613 /* enum_alias_memberships */
3616 { "get_account_policy", py_pdb_get_account_policy
, METH_NOARGS
,
3617 "get_account_policy() -> Mapping\n\n \
3618 Get account policy information as a dictionary." },
3619 { "set_account_policy", py_pdb_set_account_policy
, METH_VARARGS
,
3620 "get_account_policy(Mapping) -> None\n\n \
3621 Set account policy settings from a dicionary." },
3623 { "search_users", py_pdb_search_users
, METH_VARARGS
,
3624 "search_users(acct_flags) -> List\n\n \
3625 Search users. acct_flags are samr account control flags.\n \
3626 Each list entry is dictionary with keys - idx, rid, acct_flags, account_name, fullname, description." },
3627 { "search_groups", py_pdb_search_groups
, METH_NOARGS
,
3628 "search_groups() -> List\n\n \
3629 Search unix only groups. \n \
3630 Each list entry is dictionary with keys - idx, rid, acct_flags, account_name, fullname, description." },
3631 { "search_aliases", py_pdb_search_aliases
, METH_VARARGS
,
3632 "search_aliases([domain_sid]) -> List\n\n \
3633 Search aliases. domain_sid is dcerpc.security.dom_sid object.\n \
3634 Each list entry is dictionary with keys - idx, rid, acct_flags, account_name, fullname, description." },
3635 { "uid_to_sid", py_pdb_uid_to_sid
, METH_VARARGS
,
3636 "uid_to_sid(uid) -> sid\n\n \
3637 Return sid for given user id." },
3638 { "gid_to_sid", py_pdb_gid_to_sid
, METH_VARARGS
,
3639 "gid_to_sid(gid) -> sid\n\n \
3640 Return sid for given group id." },
3641 { "sid_to_id", py_pdb_sid_to_id
, METH_VARARGS
,
3642 "sid_to_id(sid) -> Tuple\n\n \
3643 Return id and type for given sid." },
3645 { "new_rid", py_pdb_new_rid
, METH_NOARGS
,
3646 "new_rid() -> rid\n\n \
3648 { "get_trusteddom_pw", py_pdb_get_trusteddom_pw
, METH_VARARGS
,
3649 "get_trusteddom_pw(domain) -> Mapping\n\n \
3650 Get trusted domain password, sid and last set time in a dictionary." },
3651 { "set_trusteddom_pw", py_pdb_set_trusteddom_pw
, METH_VARARGS
,
3652 "set_trusteddom_pw(domain, pwd, sid) -> None\n\n \
3653 Set trusted domain password." },
3654 { "del_trusteddom_pw", py_pdb_del_trusteddom_pw
, METH_VARARGS
,
3655 "del_trusteddom_pw(domain) -> None\n\n \
3656 Delete trusted domain password." },
3657 { "enum_trusteddoms", py_pdb_enum_trusteddoms
, METH_NOARGS
,
3658 "enum_trusteddoms() -> List\n\n \
3659 Get list of trusted domains. Each item is a dictionary with name and sid keys" },
3660 { "get_trusted_domain", py_pdb_get_trusted_domain
, METH_VARARGS
,
3661 "get_trusted_domain(domain) -> Mapping\n\n \
3662 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." },
3663 { "get_trusted_domain_by_sid", py_pdb_get_trusted_domain_by_sid
, METH_VARARGS
,
3664 "get_trusted_domain_by_sid(domain_sid) -> Mapping\n\n \
3665 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" },
3666 { "set_trusted_domain", py_pdb_set_trusted_domain
, METH_VARARGS
,
3667 "set_trusted_domain(domain, Mapping) -> None\n\n \
3668 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." },
3669 { "del_trusted_domain", py_pdb_del_trusted_domain
, METH_VARARGS
,
3670 "del_trusted_domain(domain) -> None\n\n \
3671 Delete trusted domain." },
3672 { "enum_trusted_domains", py_pdb_enum_trusted_domains
, METH_VARARGS
,
3673 "enum_trusted_domains() -> List\n\n \
3674 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." },
3675 { "get_secret", py_pdb_get_secret
, METH_VARARGS
,
3676 "get_secret(secret_name) -> Mapping\n\n \
3677 Get secret information for secret_name. Information is a dictionary with keys - secret_current, secret_current_lastchange, secret_old, secret_old_lastchange, sd." },
3678 { "set_secret", py_pdb_set_secret
, METH_VARARGS
,
3679 "set_secret(secret_name, Mapping) -> None\n\n \
3680 Set secret information for secret_name using dictionary with keys - secret_current, sd." },
3681 { "delete_secret", py_pdb_delete_secret
, METH_VARARGS
,
3682 "delete_secret(secret_name) -> None\n\n \
3683 Delete secret information for secret_name." },
3688 static PyObject
*py_pdb_new(PyTypeObject
*type
, PyObject
*args
, PyObject
*kwargs
)
3690 TALLOC_CTX
*frame
= talloc_stackframe();
3691 const char *url
= NULL
;
3694 struct pdb_methods
*methods
;
3696 if (!PyArg_ParseTuple(args
, "s", &url
)) {
3701 /* Initialize list of methods */
3702 status
= make_pdb_method_name(&methods
, url
);
3703 if (!NT_STATUS_IS_OK(status
)) {
3704 PyErr_Format(py_pdb_error
, "Cannot load backend methods for '%s' backend (%d,%s)",
3706 NT_STATUS_V(status
),
3707 get_friendly_nt_error_msg(status
));
3712 if ((pypdb
= pytalloc_steal(type
, methods
)) == NULL
) {
3723 static PyTypeObject PyPDB
= {
3724 .tp_name
= "passdb.PDB",
3725 .tp_new
= py_pdb_new
,
3726 .tp_flags
= Py_TPFLAGS_DEFAULT
,
3727 .tp_methods
= py_pdb_methods
,
3728 .tp_doc
= "PDB(url[, read_write_flags]) -> Password DB object\n",
3733 * Return a list of passdb backends
3735 static PyObject
*py_passdb_backends(PyObject
*self
, PyObject
*unused
)
3737 TALLOC_CTX
*frame
= talloc_stackframe();
3739 const struct pdb_init_function_entry
*entry
;
3741 entry
= pdb_get_backends();
3746 if((py_blist
= PyList_New(0)) == NULL
) {
3753 PyList_Append(py_blist
, PyStr_FromString(entry
->name
));
3754 entry
= entry
->next
;
3762 static PyObject
*py_set_smb_config(PyObject
*self
, PyObject
*args
)
3764 TALLOC_CTX
*frame
= talloc_stackframe();
3765 const char *smb_config
;
3767 if (!PyArg_ParseTuple(args
, "s", &smb_config
)) {
3772 /* Load smbconf parameters */
3773 if (!lp_load_global(smb_config
)) {
3774 PyErr_Format(py_pdb_error
, "Cannot open '%s'", smb_config
);
3784 static PyObject
*py_set_secrets_dir(PyObject
*self
, PyObject
*args
)
3786 TALLOC_CTX
*frame
= talloc_stackframe();
3787 const char *private_dir
;
3789 if (!PyArg_ParseTuple(args
, "s", &private_dir
)) {
3794 /* Initialize secrets database */
3795 if (!secrets_init_path(private_dir
)) {
3796 PyErr_Format(py_pdb_error
, "Cannot open secrets file database in '%s'",
3806 static PyObject
*py_reload_static_pdb(PyObject
*self
, PyObject
*args
)
3808 TALLOC_CTX
*frame
= talloc_stackframe();
3810 /* Initialize secrets database */
3811 if (!initialize_password_db(true, NULL
)) {
3812 PyErr_Format(py_pdb_error
, "Cannot re-open passdb backend %s", lp_passdb_backend());
3821 static PyObject
*py_get_domain_sid(PyObject
*self
, PyObject
*unused
)
3823 TALLOC_CTX
*frame
= talloc_stackframe();
3824 struct dom_sid domain_sid
, *domain_sid_copy
;
3825 PyObject
*py_dom_sid
= Py_None
;
3828 ret
= secrets_fetch_domain_sid(lp_workgroup(), &domain_sid
);
3831 return PyErr_NoMemory();
3834 domain_sid_copy
= dom_sid_dup(frame
, &domain_sid
);
3835 if (domain_sid_copy
== NULL
) {
3837 return PyErr_NoMemory();
3840 py_dom_sid
= pytalloc_steal(dom_sid_Type
, domain_sid_copy
);
3846 static PyObject
*py_get_global_sam_sid(PyObject
*self
, PyObject
*unused
)
3848 TALLOC_CTX
*frame
= talloc_stackframe();
3849 struct dom_sid
*domain_sid
, *domain_sid_copy
;
3850 PyObject
*py_dom_sid
;
3852 domain_sid
= get_global_sam_sid();
3854 domain_sid_copy
= dom_sid_dup(frame
, domain_sid
);
3855 if (domain_sid_copy
== NULL
) {
3861 py_dom_sid
= pytalloc_steal(dom_sid_Type
, domain_sid_copy
);
3868 static PyMethodDef py_passdb_methods
[] = {
3869 { "get_backends", py_passdb_backends
, METH_NOARGS
,
3870 "get_backends() -> list\n\n \
3871 Get a list of password database backends supported." },
3872 { "set_smb_config", py_set_smb_config
, METH_VARARGS
,
3873 "set_smb_config(path) -> None\n\n \
3874 Set path to smb.conf file to load configuration parameters." },
3875 { "set_secrets_dir", py_set_secrets_dir
, METH_VARARGS
,
3876 "set_secrets_dir(private_dir) -> None\n\n \
3877 Set path to private directory to load secrets database from non-default location." },
3878 { "get_global_sam_sid", py_get_global_sam_sid
, METH_NOARGS
,
3879 "get_global_sam_sid() -> dom_sid\n\n \
3880 Return domain SID." },
3881 { "get_domain_sid", py_get_domain_sid
, METH_NOARGS
,
3882 "get_domain_sid() -> dom_sid\n\n \
3883 Return domain SID from secrets database." },
3884 { "reload_static_pdb", py_reload_static_pdb
, METH_NOARGS
,
3885 "reload_static_pdb() -> None\n\n \
3886 Re-initialise the static pdb used internally. Needed if 'passdb backend' is changed." },
3890 static struct PyModuleDef moduledef
= {
3891 PyModuleDef_HEAD_INIT
,
3893 .m_doc
= "SAMBA Password Database",
3895 .m_methods
= py_passdb_methods
,
3898 MODULE_INIT_FUNC(passdb
)
3900 TALLOC_CTX
*frame
= talloc_stackframe();
3901 PyObject
*m
= NULL
, *mod
= NULL
;
3902 char exception_name
[] = "passdb.error";
3904 if (pytalloc_BaseObject_PyType_Ready(&PyPDB
) < 0) {
3909 if (pytalloc_BaseObject_PyType_Ready(&PySamu
) < 0) {
3914 if (pytalloc_BaseObject_PyType_Ready(&PyGroupmap
) < 0) {
3919 m
= PyModule_Create(&moduledef
);
3925 /* Create new exception for passdb module */
3926 py_pdb_error
= PyErr_NewException(exception_name
, NULL
, NULL
);
3927 Py_INCREF(py_pdb_error
);
3928 PyModule_AddObject(m
, "error", py_pdb_error
);
3931 PyModule_AddObject(m
, "PDB", (PyObject
*)&PyPDB
);
3934 PyModule_AddObject(m
, "Samu", (PyObject
*)&PySamu
);
3936 Py_INCREF(&PyGroupmap
);
3937 PyModule_AddObject(m
, "Groupmap", (PyObject
*)&PyGroupmap
);
3939 /* Import dom_sid type from dcerpc.security */
3940 mod
= PyImport_ImportModule("samba.dcerpc.security");
3946 dom_sid_Type
= (PyTypeObject
*)PyObject_GetAttrString(mod
, "dom_sid");
3947 if (dom_sid_Type
== NULL
) {
3953 /* Import security_descriptor type from dcerpc.security */
3954 security_Type
= (PyTypeObject
*)PyObject_GetAttrString(mod
, "descriptor");
3956 if (security_Type
== NULL
) {
3957 Py_DECREF(dom_sid_Type
);
3962 /* Import GUID type from dcerpc.misc */
3963 mod
= PyImport_ImportModule("samba.dcerpc.misc");
3965 Py_DECREF(security_Type
);
3966 Py_DECREF(dom_sid_Type
);
3971 guid_Type
= (PyTypeObject
*)PyObject_GetAttrString(mod
, "GUID");
3973 if (guid_Type
== NULL
) {
3974 Py_DECREF(security_Type
);
3975 Py_DECREF(dom_sid_Type
);