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"
30 #include "lib/util/string_wrappers.h"
32 #ifndef Py_TYPE /* Py_TYPE is only available on Python > 2.6 */
33 #define Py_TYPE(ob) (((PyObject*)(ob))->ob_type)
37 #define PY_CHECK_TYPE(type, var, fail) \
38 if (!PyObject_TypeCheck(var, type)) {\
39 PyErr_Format(PyExc_TypeError, __location__ ": Expected type '%s' for '%s' of type '%s'", (type)->tp_name, #var, Py_TYPE(var)->tp_name); \
45 static PyTypeObject
*dom_sid_Type
= NULL
;
46 static PyTypeObject
*security_Type
= NULL
;
47 static PyTypeObject
*guid_Type
= NULL
;
49 static PyTypeObject PySamu
;
50 static PyTypeObject PyGroupmap
;
51 static PyTypeObject PyPDB
;
53 static PyObject
*py_pdb_error
;
55 void initpassdb(void);
58 /************************** PIDL Autogeneratd ******************************/
60 static PyObject
*py_samu_get_logon_time(PyObject
*obj
, void *closure
)
62 TALLOC_CTX
*frame
= talloc_stackframe();
63 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
64 PyObject
*py_logon_time
;
66 py_logon_time
= PyLong_FromLong(pdb_get_logon_time(sam_acct
));
71 static int py_samu_set_logon_time(PyObject
*obj
, PyObject
*value
, void *closure
)
73 TALLOC_CTX
*frame
= talloc_stackframe();
74 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
76 PY_CHECK_TYPE(&PyLong_Type
, value
, return -1;);
77 if (!pdb_set_logon_time(sam_acct
, PyLong_AsLong(value
), PDB_CHANGED
)) {
85 static PyObject
*py_samu_get_logoff_time(PyObject
*obj
, void *closure
)
87 TALLOC_CTX
*frame
= talloc_stackframe();
88 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
89 PyObject
*py_logoff_time
;
91 py_logoff_time
= PyLong_FromLong(pdb_get_logoff_time(sam_acct
));
93 return py_logoff_time
;
96 static int py_samu_set_logoff_time(PyObject
*obj
, PyObject
*value
, void *closure
)
98 TALLOC_CTX
*frame
= talloc_stackframe();
99 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
101 PY_CHECK_TYPE(&PyLong_Type
, value
, return -1;);
102 if (!pdb_set_logoff_time(sam_acct
, PyLong_AsLong(value
), PDB_CHANGED
)) {
110 static PyObject
*py_samu_get_kickoff_time(PyObject
*obj
, void *closure
)
112 TALLOC_CTX
*frame
= talloc_stackframe();
113 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
114 PyObject
*py_kickoff_time
;
116 py_kickoff_time
= PyLong_FromLong(pdb_get_kickoff_time(sam_acct
));
118 return py_kickoff_time
;
121 static int py_samu_set_kickoff_time(PyObject
*obj
, PyObject
*value
, void *closure
)
123 TALLOC_CTX
*frame
= talloc_stackframe();
124 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
126 PY_CHECK_TYPE(&PyLong_Type
, value
, return -1;);
127 if (!pdb_set_kickoff_time(sam_acct
, PyLong_AsLong(value
), PDB_CHANGED
)) {
135 static PyObject
*py_samu_get_bad_password_time(PyObject
*obj
, void *closure
)
137 TALLOC_CTX
*frame
= talloc_stackframe();
138 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
139 PyObject
*py_bad_password_time
;
141 py_bad_password_time
= PyLong_FromLong(pdb_get_bad_password_time(sam_acct
));
143 return py_bad_password_time
;
146 static int py_samu_set_bad_password_time(PyObject
*obj
, PyObject
*value
, void *closure
)
148 TALLOC_CTX
*frame
= talloc_stackframe();
149 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
151 PY_CHECK_TYPE(&PyLong_Type
, value
, return -1;);
152 if (!pdb_set_bad_password_time(sam_acct
, PyLong_AsLong(value
), PDB_CHANGED
)) {
160 static PyObject
*py_samu_get_pass_last_set_time(PyObject
*obj
, void *closure
)
162 TALLOC_CTX
*frame
= talloc_stackframe();
163 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
164 PyObject
*py_pass_last_set_time
;
166 py_pass_last_set_time
= PyLong_FromLong(pdb_get_pass_last_set_time(sam_acct
));
168 return py_pass_last_set_time
;
171 static int py_samu_set_pass_last_set_time(PyObject
*obj
, PyObject
*value
, void *closure
)
173 TALLOC_CTX
*frame
= talloc_stackframe();
174 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
176 PY_CHECK_TYPE(&PyLong_Type
, value
, return -1;);
177 if (!pdb_set_pass_last_set_time(sam_acct
, PyLong_AsLong(value
), PDB_CHANGED
)) {
185 static PyObject
*py_samu_get_pass_can_change_time(PyObject
*obj
, void *closure
)
187 TALLOC_CTX
*frame
= talloc_stackframe();
188 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
189 PyObject
*py_pass_can_change_time
;
191 py_pass_can_change_time
= PyLong_FromLong(pdb_get_pass_can_change_time(sam_acct
));
193 return py_pass_can_change_time
;
196 static int py_samu_set_pass_can_change_time(PyObject
*obj
, PyObject
*value
, void *closure
)
198 TALLOC_CTX
*frame
= talloc_stackframe();
199 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
201 PY_CHECK_TYPE(&PyLong_Type
, value
, return -1;);
202 if (!pdb_set_pass_can_change_time(sam_acct
, PyLong_AsLong(value
), PDB_CHANGED
)) {
210 static PyObject
*py_samu_get_pass_must_change_time(PyObject
*obj
, void *closure
)
212 TALLOC_CTX
*frame
= talloc_stackframe();
213 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
214 PyObject
*py_pass_must_change_time
;
216 py_pass_must_change_time
= PyLong_FromLong(pdb_get_pass_must_change_time(sam_acct
));
218 return py_pass_must_change_time
;
221 static int py_samu_set_pass_must_change_time(PyObject
*obj
, PyObject
*value
, void *closure
)
223 TALLOC_CTX
*frame
= talloc_stackframe();
224 PY_CHECK_TYPE(&PyLong_Type
, value
, return -1;);
226 /* TODO: make this not a get/set or give a better exception */
231 static PyObject
*py_samu_get_username(PyObject
*obj
, void *closure
)
233 TALLOC_CTX
*frame
= talloc_stackframe();
234 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
235 PyObject
*py_username
;
236 const char *username
;
238 username
= pdb_get_username(sam_acct
);
239 if (username
== NULL
) {
243 py_username
= PyUnicode_FromString(username
);
248 static int py_samu_set_username(PyObject
*obj
, PyObject
*value
, void *closure
)
250 TALLOC_CTX
*frame
= talloc_stackframe();
251 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
253 PY_CHECK_TYPE(&PyUnicode_Type
, value
, return -1;);
254 if (!pdb_set_username(sam_acct
, PyUnicode_AsUTF8(value
), PDB_CHANGED
)) {
262 static PyObject
*py_samu_get_domain(PyObject
*obj
, void *closure
)
264 TALLOC_CTX
*frame
= talloc_stackframe();
265 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
269 domain
= pdb_get_domain(sam_acct
);
270 if (domain
== NULL
) {
274 py_domain
= PyUnicode_FromString(domain
);
279 static int py_samu_set_domain(PyObject
*obj
, PyObject
*value
, void *closure
)
281 TALLOC_CTX
*frame
= talloc_stackframe();
282 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
284 PY_CHECK_TYPE(&PyUnicode_Type
, value
, return -1;);
285 if (!pdb_set_domain(sam_acct
, PyUnicode_AsUTF8(value
), PDB_CHANGED
)) {
293 static PyObject
*py_samu_get_nt_username(PyObject
*obj
, void *closure
)
295 TALLOC_CTX
*frame
= talloc_stackframe();
296 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
297 PyObject
*py_nt_username
;
298 const char *nt_username
;
300 nt_username
= pdb_get_nt_username(sam_acct
);
301 if (nt_username
== NULL
) {
305 py_nt_username
= PyUnicode_FromString(nt_username
);
307 return py_nt_username
;
310 static int py_samu_set_nt_username(PyObject
*obj
, PyObject
*value
, void *closure
)
312 TALLOC_CTX
*frame
= talloc_stackframe();
313 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
315 PY_CHECK_TYPE(&PyUnicode_Type
, value
, return -1;);
316 if (!pdb_set_nt_username(sam_acct
, PyUnicode_AsUTF8(value
), PDB_CHANGED
)) {
324 static PyObject
*py_samu_get_full_name(PyObject
*obj
, void *closure
)
326 TALLOC_CTX
*frame
= talloc_stackframe();
327 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
328 PyObject
*py_full_name
;
329 const char *full_name
;
331 full_name
= pdb_get_fullname(sam_acct
);
332 if (full_name
== NULL
) {
336 py_full_name
= PyUnicode_FromString(full_name
);
341 static int py_samu_set_full_name(PyObject
*obj
, PyObject
*value
, void *closure
)
343 TALLOC_CTX
*frame
= talloc_stackframe();
344 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
346 PY_CHECK_TYPE(&PyUnicode_Type
, value
, return -1;);
347 if (!pdb_set_fullname(sam_acct
, PyUnicode_AsUTF8(value
), PDB_CHANGED
)) {
355 static PyObject
*py_samu_get_home_dir(PyObject
*obj
, void *closure
)
357 TALLOC_CTX
*frame
= talloc_stackframe();
358 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
359 PyObject
*py_home_dir
;
360 const char *home_dir
;
362 home_dir
= pdb_get_homedir(sam_acct
);
363 if (home_dir
== NULL
) {
367 py_home_dir
= PyUnicode_FromString(home_dir
);
372 static int py_samu_set_home_dir(PyObject
*obj
, PyObject
*value
, void *closure
)
374 TALLOC_CTX
*frame
= talloc_stackframe();
375 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
377 PY_CHECK_TYPE(&PyUnicode_Type
, value
, return -1;);
378 if (!pdb_set_homedir(sam_acct
, PyUnicode_AsUTF8(value
), PDB_CHANGED
)) {
386 static PyObject
*py_samu_get_dir_drive(PyObject
*obj
, void *closure
)
388 TALLOC_CTX
*frame
= talloc_stackframe();
389 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
390 PyObject
*py_dir_drive
;
391 const char *dir_drive
;
393 dir_drive
= pdb_get_dir_drive(sam_acct
);
394 if (dir_drive
== NULL
) {
398 py_dir_drive
= PyUnicode_FromString(dir_drive
);
403 static int py_samu_set_dir_drive(PyObject
*obj
, PyObject
*value
, void *closure
)
405 TALLOC_CTX
*frame
= talloc_stackframe();
406 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
408 PY_CHECK_TYPE(&PyUnicode_Type
, value
, return -1;);
409 if (!pdb_set_dir_drive(sam_acct
, PyUnicode_AsUTF8(value
), PDB_CHANGED
)) {
417 static PyObject
*py_samu_get_logon_script(PyObject
*obj
, void *closure
)
419 TALLOC_CTX
*frame
= talloc_stackframe();
420 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
421 PyObject
*py_logon_script
;
422 const char *logon_script
;
424 logon_script
= pdb_get_logon_script(sam_acct
);
425 if (logon_script
== NULL
) {
429 py_logon_script
= PyUnicode_FromString(logon_script
);
431 return py_logon_script
;
434 static int py_samu_set_logon_script(PyObject
*obj
, PyObject
*value
, void *closure
)
436 TALLOC_CTX
*frame
= talloc_stackframe();
437 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
439 PY_CHECK_TYPE(&PyUnicode_Type
, value
, return -1;);
440 if (!pdb_set_logon_script(sam_acct
, PyUnicode_AsUTF8(value
), PDB_CHANGED
)) {
448 static PyObject
*py_samu_get_profile_path(PyObject
*obj
, void *closure
)
450 TALLOC_CTX
*frame
= talloc_stackframe();
451 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
452 PyObject
*py_profile_path
;
453 const char *profile_path
;
455 profile_path
= pdb_get_profile_path(sam_acct
);
456 if (profile_path
== NULL
) {
460 py_profile_path
= PyUnicode_FromString(profile_path
);
462 return py_profile_path
;
465 static int py_samu_set_profile_path(PyObject
*obj
, PyObject
*value
, void *closure
)
467 TALLOC_CTX
*frame
= talloc_stackframe();
468 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
470 PY_CHECK_TYPE(&PyUnicode_Type
, value
, return -1;);
471 if (!pdb_set_profile_path(sam_acct
, PyUnicode_AsUTF8(value
), PDB_CHANGED
)) {
479 static PyObject
*py_samu_get_acct_desc(PyObject
*obj
, void *closure
)
481 TALLOC_CTX
*frame
= talloc_stackframe();
482 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
483 PyObject
*py_acct_desc
;
484 const char *acct_desc
;
486 acct_desc
= pdb_get_acct_desc(sam_acct
);
487 if (acct_desc
== NULL
) {
491 py_acct_desc
= PyUnicode_FromString(acct_desc
);
496 static int py_samu_set_acct_desc(PyObject
*obj
, PyObject
*value
, void *closure
)
498 TALLOC_CTX
*frame
= talloc_stackframe();
499 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
501 PY_CHECK_TYPE(&PyUnicode_Type
, value
, return -1;);
502 if (!pdb_set_acct_desc(sam_acct
, PyUnicode_AsUTF8(value
), PDB_CHANGED
)) {
510 static PyObject
*py_samu_get_workstations(PyObject
*obj
, void *closure
)
512 TALLOC_CTX
*frame
= talloc_stackframe();
513 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
514 PyObject
*py_workstations
;
515 const char *workstations
;
517 workstations
= pdb_get_workstations(sam_acct
);
518 if (workstations
== NULL
) {
522 py_workstations
= PyUnicode_FromString(workstations
);
524 return py_workstations
;
527 static int py_samu_set_workstations(PyObject
*obj
, PyObject
*value
, void *closure
)
529 TALLOC_CTX
*frame
= talloc_stackframe();
530 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
532 PY_CHECK_TYPE(&PyUnicode_Type
, value
, return -1;);
533 if (!pdb_set_workstations(sam_acct
, PyUnicode_AsUTF8(value
), PDB_CHANGED
)) {
541 static PyObject
*py_samu_get_comment(PyObject
*obj
, void *closure
)
543 TALLOC_CTX
*frame
= talloc_stackframe();
544 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
545 PyObject
*py_comment
;
548 comment
= pdb_get_comment(sam_acct
);
549 if (comment
== NULL
) {
553 py_comment
= PyUnicode_FromString(comment
);
558 static int py_samu_set_comment(PyObject
*obj
, PyObject
*value
, void *closure
)
560 TALLOC_CTX
*frame
= talloc_stackframe();
561 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
563 PY_CHECK_TYPE(&PyUnicode_Type
, value
, return -1;);
564 if (!pdb_set_comment(sam_acct
, PyUnicode_AsUTF8(value
), PDB_CHANGED
)) {
572 static PyObject
*py_samu_get_munged_dial(PyObject
*obj
, void *closure
)
574 TALLOC_CTX
*frame
= talloc_stackframe();
575 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
576 PyObject
*py_munged_dial
;
577 const char *munged_dial
;
579 munged_dial
= pdb_get_munged_dial(sam_acct
);
580 if (munged_dial
== NULL
) {
584 py_munged_dial
= PyUnicode_FromString(munged_dial
);
586 return py_munged_dial
;
589 static int py_samu_set_munged_dial(PyObject
*obj
, PyObject
*value
, void *closure
)
591 TALLOC_CTX
*frame
= talloc_stackframe();
592 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
594 PY_CHECK_TYPE(&PyUnicode_Type
, value
, return -1;);
595 if (!pdb_set_munged_dial(sam_acct
, PyUnicode_AsUTF8(value
), PDB_CHANGED
)) {
603 static PyObject
*py_samu_get_user_sid(PyObject
*obj
, void *closure
)
605 TALLOC_CTX
*frame
= talloc_stackframe();
606 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
607 PyObject
*py_user_sid
;
608 const struct dom_sid
*user_sid
;
609 struct dom_sid
*copy_user_sid
;
612 user_sid
= pdb_get_user_sid(sam_acct
);
613 if(user_sid
== NULL
) {
617 mem_ctx
= talloc_new(NULL
);
618 if (mem_ctx
== NULL
) {
623 copy_user_sid
= dom_sid_dup(mem_ctx
, user_sid
);
624 if (copy_user_sid
== NULL
) {
626 talloc_free(mem_ctx
);
631 py_user_sid
= pytalloc_steal(dom_sid_Type
, copy_user_sid
);
633 talloc_free(mem_ctx
);
639 static int py_samu_set_user_sid(PyObject
*obj
, PyObject
*value
, void *closure
)
641 TALLOC_CTX
*frame
= talloc_stackframe();
642 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
644 PY_CHECK_TYPE(dom_sid_Type
, value
, return -1;);
645 if (!pdb_set_user_sid(sam_acct
, (struct dom_sid
*)pytalloc_get_ptr(value
), PDB_CHANGED
)) {
653 static PyObject
*py_samu_get_group_sid(PyObject
*obj
, void *closure
)
655 TALLOC_CTX
*frame
= talloc_stackframe();
656 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
657 const struct dom_sid
*group_sid
;
658 struct dom_sid
*copy_group_sid
;
660 group_sid
= pdb_get_group_sid(sam_acct
);
661 if (group_sid
== NULL
) {
665 copy_group_sid
= dom_sid_dup(NULL
, group_sid
);
666 if (copy_group_sid
== NULL
) {
673 return pytalloc_steal(dom_sid_Type
, copy_group_sid
);
676 static int py_samu_set_group_sid(PyObject
*obj
, PyObject
*value
, void *closure
)
678 TALLOC_CTX
*frame
= talloc_stackframe();
679 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
681 PY_CHECK_TYPE(dom_sid_Type
, value
, return -1;);
682 if (!pdb_set_group_sid(sam_acct
, (struct dom_sid
*)pytalloc_get_ptr(value
), PDB_CHANGED
)) {
690 static PyObject
*py_samu_get_lanman_passwd(PyObject
*obj
, void *closure
)
692 TALLOC_CTX
*frame
= talloc_stackframe();
693 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
697 lm_pw
= (const char *)pdb_get_lanman_passwd(sam_acct
);
702 py_lm_pw
= PyBytes_FromStringAndSize(lm_pw
, LM_HASH_LEN
);
707 static int py_samu_set_lanman_passwd(PyObject
*obj
, PyObject
*value
, void *closure
)
709 TALLOC_CTX
*frame
= talloc_stackframe();
710 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
712 PY_CHECK_TYPE(&PyBytes_Type
, value
, return -1;);
713 if (!pdb_set_lanman_passwd(sam_acct
, (uint8_t *)PyBytes_AsString(value
), PDB_CHANGED
)) {
721 static PyObject
*py_samu_get_nt_passwd(PyObject
*obj
, void *closure
)
723 TALLOC_CTX
*frame
= talloc_stackframe();
724 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
728 nt_pw
= (const char *)pdb_get_nt_passwd(sam_acct
);
733 py_nt_pw
= PyBytes_FromStringAndSize(nt_pw
, NT_HASH_LEN
);
738 static int py_samu_set_nt_passwd(PyObject
*obj
, PyObject
*value
, void *closure
)
740 TALLOC_CTX
*frame
= talloc_stackframe();
741 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
743 if (!pdb_set_nt_passwd(sam_acct
, (uint8_t *)PyBytes_AsString(value
), PDB_CHANGED
)) {
751 static PyObject
*py_samu_get_pw_history(PyObject
*obj
, void *closure
)
753 TALLOC_CTX
*frame
= talloc_stackframe();
754 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
755 PyObject
*py_nt_pw_his
;
756 const char *nt_pw_his
;
759 nt_pw_his
= (const char *)pdb_get_pw_history(sam_acct
, &hist_len
);
760 if (nt_pw_his
== NULL
) {
764 py_nt_pw_his
= PyBytes_FromStringAndSize(nt_pw_his
, hist_len
*PW_HISTORY_ENTRY_LEN
);
769 static int py_samu_set_pw_history(PyObject
*obj
, PyObject
*value
, void *closure
)
771 TALLOC_CTX
*frame
= talloc_stackframe();
772 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
777 PyBytes_AsStringAndSize(value
, &nt_pw_his
, &len
);
778 hist_len
= len
/ PW_HISTORY_ENTRY_LEN
;
779 if (!pdb_set_pw_history(sam_acct
, (uint8_t *)nt_pw_his
, hist_len
, PDB_CHANGED
)) {
787 static PyObject
*py_samu_get_plaintext_passwd(PyObject
*obj
, void *closure
)
789 TALLOC_CTX
*frame
= talloc_stackframe();
790 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
791 PyObject
*py_plaintext_pw
;
792 const char *plaintext_pw
;
794 plaintext_pw
= pdb_get_plaintext_passwd(sam_acct
);
795 if (plaintext_pw
== NULL
) {
799 py_plaintext_pw
= PyUnicode_FromString(plaintext_pw
);
801 return py_plaintext_pw
;
804 static int py_samu_set_plaintext_passwd(PyObject
*obj
, PyObject
*value
, void *closure
)
806 TALLOC_CTX
*frame
= talloc_stackframe();
807 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
809 if (!pdb_set_plaintext_passwd(sam_acct
, PyUnicode_AsUTF8(value
))) {
817 static PyObject
*py_samu_get_acct_ctrl(PyObject
*obj
, void *closure
)
819 TALLOC_CTX
*frame
= talloc_stackframe();
820 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
821 PyObject
*py_acct_ctrl
;
823 py_acct_ctrl
= PyLong_FromLong(pdb_get_acct_ctrl(sam_acct
));
828 static int py_samu_set_acct_ctrl(PyObject
*obj
, PyObject
*value
, void *closure
)
830 TALLOC_CTX
*frame
= talloc_stackframe();
831 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
833 PY_CHECK_TYPE(&PyLong_Type
, value
, return -1;);
834 if (!pdb_set_acct_ctrl(sam_acct
, PyLong_AsLong(value
), PDB_CHANGED
)) {
842 static PyObject
*py_samu_get_logon_divs(PyObject
*obj
, void *closure
)
844 TALLOC_CTX
*frame
= talloc_stackframe();
845 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
846 PyObject
*py_logon_divs
;
848 py_logon_divs
= PyLong_FromLong(pdb_get_logon_divs(sam_acct
));
850 return py_logon_divs
;
853 static int py_samu_set_logon_divs(PyObject
*obj
, PyObject
*value
, void *closure
)
855 TALLOC_CTX
*frame
= talloc_stackframe();
856 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
858 PY_CHECK_TYPE(&PyLong_Type
, value
, return -1;);
859 if (!pdb_set_logon_divs(sam_acct
, PyLong_AsLong(value
), PDB_CHANGED
)) {
867 static PyObject
*py_samu_get_hours_len(PyObject
*obj
, void *closure
)
869 TALLOC_CTX
*frame
= talloc_stackframe();
870 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
871 PyObject
*py_hours_len
;
873 py_hours_len
= PyLong_FromLong(pdb_get_hours_len(sam_acct
));
878 static int py_samu_set_hours_len(PyObject
*obj
, PyObject
*value
, void *closure
)
880 TALLOC_CTX
*frame
= talloc_stackframe();
881 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
883 PY_CHECK_TYPE(&PyLong_Type
, value
, return -1;);
884 if (!pdb_set_hours_len(sam_acct
, PyLong_AsLong(value
), PDB_CHANGED
)) {
892 static PyObject
*py_samu_get_hours(PyObject
*obj
, void *closure
)
894 TALLOC_CTX
*frame
= talloc_stackframe();
895 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
900 hours
= (const char *)pdb_get_hours(sam_acct
);
905 hours_len
= pdb_get_hours_len(sam_acct
);
906 if ((py_hours
= PyList_New(hours_len
)) == NULL
) {
912 for (i
=0; i
<hours_len
; i
++) {
913 PyList_SetItem(py_hours
, i
, PyLong_FromLong(hours
[i
]));
919 static int py_samu_set_hours(PyObject
*obj
, PyObject
*value
, void *closure
)
921 TALLOC_CTX
*frame
= talloc_stackframe();
922 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
928 PY_CHECK_TYPE(&PyList_Type
, value
, return -1;);
930 hours_len
= PyList_GET_SIZE(value
);
932 hours
= talloc_array(pytalloc_get_mem_ctx(obj
), uint8_t, hours_len
);
939 for (i
=0; i
< hours_len
; i
++) {
940 PY_CHECK_TYPE(&PyLong_Type
, PyList_GET_ITEM(value
,i
), return -1;);
941 hours
[i
] = PyLong_AsLong(PyList_GET_ITEM(value
, i
));
944 status
= pdb_set_hours(sam_acct
, hours
, hours_len
, PDB_CHANGED
);
955 static PyObject
*py_samu_get_bad_password_count(PyObject
*obj
, void *closure
)
957 TALLOC_CTX
*frame
= talloc_stackframe();
958 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
959 PyObject
*py_bad_password_count
;
961 py_bad_password_count
= PyLong_FromLong(pdb_get_bad_password_count(sam_acct
));
963 return py_bad_password_count
;
966 static int py_samu_set_bad_password_count(PyObject
*obj
, PyObject
*value
, void *closure
)
968 TALLOC_CTX
*frame
= talloc_stackframe();
969 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
971 PY_CHECK_TYPE(&PyLong_Type
, value
, return -1;);
972 if (!pdb_set_bad_password_count(sam_acct
, PyLong_AsLong(value
), PDB_CHANGED
)) {
980 static PyObject
*py_samu_get_logon_count(PyObject
*obj
, void *closure
)
982 TALLOC_CTX
*frame
= talloc_stackframe();
983 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
984 PyObject
*py_logon_count
;
986 py_logon_count
= PyLong_FromLong(pdb_get_logon_count(sam_acct
));
988 return py_logon_count
;
991 static int py_samu_set_logon_count(PyObject
*obj
, PyObject
*value
, void *closure
)
993 TALLOC_CTX
*frame
= talloc_stackframe();
994 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
996 PY_CHECK_TYPE(&PyLong_Type
, value
, return -1;);
997 if (!pdb_set_logon_count(sam_acct
, PyLong_AsLong(value
), PDB_CHANGED
)) {
1005 static PyObject
*py_samu_get_country_code(PyObject
*obj
, void *closure
)
1007 TALLOC_CTX
*frame
= talloc_stackframe();
1008 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
1009 PyObject
*py_country_code
;
1011 py_country_code
= PyLong_FromLong(pdb_get_country_code(sam_acct
));
1013 return py_country_code
;
1016 static int py_samu_set_country_code(PyObject
*obj
, PyObject
*value
, void *closure
)
1018 TALLOC_CTX
*frame
= talloc_stackframe();
1019 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
1021 PY_CHECK_TYPE(&PyLong_Type
, value
, return -1;);
1022 if (!pdb_set_country_code(sam_acct
, PyLong_AsLong(value
), PDB_CHANGED
)) {
1030 static PyObject
*py_samu_get_code_page(PyObject
*obj
, void *closure
)
1032 TALLOC_CTX
*frame
= talloc_stackframe();
1033 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
1034 PyObject
*py_code_page
;
1036 py_code_page
= PyLong_FromLong(pdb_get_code_page(sam_acct
));
1038 return py_code_page
;
1041 static int py_samu_set_code_page(PyObject
*obj
, PyObject
*value
, void *closure
)
1043 TALLOC_CTX
*frame
= talloc_stackframe();
1044 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
1046 PY_CHECK_TYPE(&PyLong_Type
, value
, return -1;);
1047 if (!pdb_set_code_page(sam_acct
, PyLong_AsLong(value
), PDB_CHANGED
)) {
1055 static PyGetSetDef py_samu_getsetters
[] = {
1057 .name
= discard_const_p(char, "logon_time"),
1058 .get
= py_samu_get_logon_time
,
1059 .set
= py_samu_set_logon_time
,
1062 .name
= discard_const_p(char, "logoff_time"),
1063 .get
= py_samu_get_logoff_time
,
1064 .set
= py_samu_set_logoff_time
,
1067 .name
= discard_const_p(char, "kickoff_time"),
1068 .get
= py_samu_get_kickoff_time
,
1069 .set
= py_samu_set_kickoff_time
,
1072 .name
= discard_const_p(char, "bad_password_time"),
1073 .get
= py_samu_get_bad_password_time
,
1074 .set
= py_samu_set_bad_password_time
,
1077 .name
= discard_const_p(char, "pass_last_set_time"),
1078 .get
= py_samu_get_pass_last_set_time
,
1079 .set
= py_samu_set_pass_last_set_time
,
1082 .name
= discard_const_p(char, "pass_can_change_time"),
1083 .get
= py_samu_get_pass_can_change_time
,
1084 .set
= py_samu_set_pass_can_change_time
,
1087 .name
= discard_const_p(char, "pass_must_change_time"),
1088 .get
= py_samu_get_pass_must_change_time
,
1089 .set
= py_samu_set_pass_must_change_time
,
1092 .name
= discard_const_p(char, "username"),
1093 .get
= py_samu_get_username
,
1094 .set
= py_samu_set_username
,
1097 .name
= discard_const_p(char, "domain"),
1098 .get
= py_samu_get_domain
,
1099 .set
= py_samu_set_domain
,
1102 .name
= discard_const_p(char, "nt_username"),
1103 .get
= py_samu_get_nt_username
,
1104 .set
= py_samu_set_nt_username
,
1107 .name
= discard_const_p(char, "full_name"),
1108 .get
= py_samu_get_full_name
,
1109 .set
= py_samu_set_full_name
,
1112 .name
= discard_const_p(char, "home_dir"),
1113 .get
= py_samu_get_home_dir
,
1114 .set
= py_samu_set_home_dir
,
1117 .name
= discard_const_p(char, "dir_drive"),
1118 .get
= py_samu_get_dir_drive
,
1119 .set
= py_samu_set_dir_drive
,
1122 .name
= discard_const_p(char, "logon_script"),
1123 .get
= py_samu_get_logon_script
,
1124 .set
= py_samu_set_logon_script
,
1127 .name
= discard_const_p(char, "profile_path"),
1128 .get
= py_samu_get_profile_path
,
1129 .set
= py_samu_set_profile_path
,
1132 .name
= discard_const_p(char, "acct_desc"),
1133 .get
= py_samu_get_acct_desc
,
1134 .set
= py_samu_set_acct_desc
,
1137 .name
= discard_const_p(char, "workstations"),
1138 .get
= py_samu_get_workstations
,
1139 .set
= py_samu_set_workstations
,
1142 .name
= discard_const_p(char, "comment"),
1143 .get
= py_samu_get_comment
,
1144 .set
= py_samu_set_comment
,
1147 .name
= discard_const_p(char, "munged_dial"),
1148 .get
= py_samu_get_munged_dial
,
1149 .set
= py_samu_set_munged_dial
,
1152 .name
= discard_const_p(char, "user_sid"),
1153 .get
= py_samu_get_user_sid
,
1154 .set
= py_samu_set_user_sid
,
1157 .name
= discard_const_p(char, "group_sid"),
1158 .get
= py_samu_get_group_sid
,
1159 .set
= py_samu_set_group_sid
,
1162 .name
= discard_const_p(char, "lanman_passwd"),
1163 .get
= py_samu_get_lanman_passwd
,
1164 .set
= py_samu_set_lanman_passwd
,
1167 .name
= discard_const_p(char, "nt_passwd"),
1168 .get
= py_samu_get_nt_passwd
,
1169 .set
= py_samu_set_nt_passwd
,
1172 .name
= discard_const_p(char, "pw_history"),
1173 .get
= py_samu_get_pw_history
,
1174 .set
= py_samu_set_pw_history
,
1177 .name
= discard_const_p(char, "plaintext_passwd"),
1178 .get
= py_samu_get_plaintext_passwd
,
1179 .set
= py_samu_set_plaintext_passwd
,
1182 .name
= discard_const_p(char, "acct_ctrl"),
1183 .get
= py_samu_get_acct_ctrl
,
1184 .set
= py_samu_set_acct_ctrl
,
1187 .name
= discard_const_p(char, "logon_divs"),
1188 .get
= py_samu_get_logon_divs
,
1189 .set
= py_samu_set_logon_divs
,
1192 .name
= discard_const_p(char, "hours_len"),
1193 .get
= py_samu_get_hours_len
,
1194 .set
= py_samu_set_hours_len
,
1197 .name
= discard_const_p(char, "hours"),
1198 .get
= py_samu_get_hours
,
1199 .set
= py_samu_set_hours
,
1202 .name
= discard_const_p(char, "bad_password_count"),
1203 .get
= py_samu_get_bad_password_count
,
1204 .set
= py_samu_set_bad_password_count
,
1207 .name
= discard_const_p(char, "logon_count"),
1208 .get
= py_samu_get_logon_count
,
1209 .set
= py_samu_set_logon_count
,
1212 .name
= discard_const_p(char, "country_code"),
1213 .get
= py_samu_get_country_code
,
1214 .set
= py_samu_set_country_code
,
1217 .name
= discard_const_p(char, "code_page"),
1218 .get
= py_samu_get_code_page
,
1219 .set
= py_samu_set_code_page
,
1227 /************************** PIDL Autogeneratd ******************************/
1229 static PyObject
*py_samu_new(PyTypeObject
*type
, PyObject
*args
, PyObject
*kwargs
)
1231 TALLOC_CTX
*frame
= talloc_stackframe();
1232 struct samu
*sam_acct
;
1234 sam_acct
= samu_new(NULL
);
1242 return pytalloc_steal(type
, sam_acct
);
1245 static PyTypeObject PySamu
= {
1246 .tp_name
= "passdb.Samu",
1247 .tp_getset
= py_samu_getsetters
,
1249 .tp_new
= py_samu_new
,
1250 .tp_flags
= Py_TPFLAGS_DEFAULT
| Py_TPFLAGS_BASETYPE
,
1251 .tp_doc
= "Samu() -> samu object\n",
1255 static PyObject
*py_groupmap_get_gid(PyObject
*obj
, void *closure
)
1257 TALLOC_CTX
*frame
= talloc_stackframe();
1258 GROUP_MAP
*group_map
= (GROUP_MAP
*)pytalloc_get_ptr(obj
);
1261 py_gid
= Py_BuildValue("i", group_map
->gid
);
1266 static int py_groupmap_set_gid(PyObject
*obj
, PyObject
*value
, void *closure
)
1268 TALLOC_CTX
*frame
= talloc_stackframe();
1269 GROUP_MAP
*group_map
= (GROUP_MAP
*)pytalloc_get_ptr(obj
);
1271 PY_CHECK_TYPE(&PyLong_Type
, value
, return -1;);
1272 group_map
->gid
= PyLong_AsLong(value
);
1277 static PyObject
*py_groupmap_get_sid(PyObject
*obj
, void *closure
)
1279 TALLOC_CTX
*frame
= talloc_stackframe();
1280 GROUP_MAP
*group_map
= (GROUP_MAP
*)pytalloc_get_ptr(obj
);
1282 struct dom_sid
*group_sid
;
1283 TALLOC_CTX
*mem_ctx
;
1285 mem_ctx
= talloc_new(NULL
);
1286 if (mem_ctx
== NULL
) {
1292 group_sid
= dom_sid_dup(mem_ctx
, &group_map
->sid
);
1293 if (group_sid
== NULL
) {
1295 talloc_free(mem_ctx
);
1300 py_sid
= pytalloc_steal(dom_sid_Type
, group_sid
);
1302 talloc_free(mem_ctx
);
1308 static int py_groupmap_set_sid(PyObject
*obj
, PyObject
*value
, void *closure
)
1310 TALLOC_CTX
*frame
= talloc_stackframe();
1311 GROUP_MAP
*group_map
= (GROUP_MAP
*)pytalloc_get_ptr(obj
);
1313 PY_CHECK_TYPE(dom_sid_Type
, value
, return -1;);
1314 group_map
->sid
= *pytalloc_get_type(value
, struct dom_sid
);
1319 static PyObject
*py_groupmap_get_sid_name_use(PyObject
*obj
, void *closure
)
1321 TALLOC_CTX
*frame
= talloc_stackframe();
1322 GROUP_MAP
*group_map
= (GROUP_MAP
*)pytalloc_get_ptr(obj
);
1323 PyObject
*py_sid_name_use
;
1325 py_sid_name_use
= PyLong_FromLong(group_map
->sid_name_use
);
1327 return py_sid_name_use
;
1330 static int py_groupmap_set_sid_name_use(PyObject
*obj
, PyObject
*value
, void *closure
)
1332 TALLOC_CTX
*frame
= talloc_stackframe();
1333 GROUP_MAP
*group_map
= (GROUP_MAP
*)pytalloc_get_ptr(obj
);
1335 PY_CHECK_TYPE(&PyLong_Type
, value
, return -1;);
1336 group_map
->sid_name_use
= PyLong_AsLong(value
);
1341 static PyObject
*py_groupmap_get_nt_name(PyObject
*obj
, void *closure
)
1343 TALLOC_CTX
*frame
= talloc_stackframe();
1344 GROUP_MAP
*group_map
= (GROUP_MAP
*)pytalloc_get_ptr(obj
);
1345 PyObject
*py_nt_name
;
1346 if (group_map
->nt_name
== NULL
) {
1347 py_nt_name
= Py_None
;
1348 Py_INCREF(py_nt_name
);
1350 py_nt_name
= PyUnicode_FromString(group_map
->nt_name
);
1356 static int py_groupmap_set_nt_name(PyObject
*obj
, PyObject
*value
, void *closure
)
1358 TALLOC_CTX
*frame
= talloc_stackframe();
1359 GROUP_MAP
*group_map
= (GROUP_MAP
*)pytalloc_get_ptr(obj
);
1361 PY_CHECK_TYPE(&PyUnicode_Type
, value
, return -1;);
1362 if (value
== Py_None
) {
1363 fstrcpy(group_map
->nt_name
, NULL
);
1365 fstrcpy(group_map
->nt_name
, PyUnicode_AsUTF8(value
));
1371 static PyObject
*py_groupmap_get_comment(PyObject
*obj
, void *closure
)
1373 TALLOC_CTX
*frame
= talloc_stackframe();
1374 GROUP_MAP
*group_map
= (GROUP_MAP
*)pytalloc_get_ptr(obj
);
1375 PyObject
*py_comment
;
1376 if (group_map
->comment
== NULL
) {
1377 py_comment
= Py_None
;
1378 Py_INCREF(py_comment
);
1380 py_comment
= PyUnicode_FromString(group_map
->comment
);
1386 static int py_groupmap_set_comment(PyObject
*obj
, PyObject
*value
, void *closure
)
1388 TALLOC_CTX
*frame
= talloc_stackframe();
1389 GROUP_MAP
*group_map
= (GROUP_MAP
*)pytalloc_get_ptr(obj
);
1391 PY_CHECK_TYPE(&PyUnicode_Type
, value
, return -1;);
1392 if (value
== Py_None
) {
1393 fstrcpy(group_map
->comment
, NULL
);
1395 fstrcpy(group_map
->comment
, PyUnicode_AsUTF8(value
));
1401 static PyGetSetDef py_groupmap_getsetters
[] = {
1403 .name
= discard_const_p(char, "gid"),
1404 .get
= py_groupmap_get_gid
,
1405 .set
= py_groupmap_set_gid
,
1408 .name
= discard_const_p(char, "sid"),
1409 .get
= py_groupmap_get_sid
,
1410 .set
= py_groupmap_set_sid
,
1413 .name
= discard_const_p(char, "sid_name_use"),
1414 .get
= py_groupmap_get_sid_name_use
,
1415 .set
= py_groupmap_set_sid_name_use
,
1418 .name
= discard_const_p(char, "nt_name"),
1419 .get
= py_groupmap_get_nt_name
,
1420 .set
= py_groupmap_set_nt_name
,
1423 .name
= discard_const_p(char, "comment"),
1424 .get
= py_groupmap_get_comment
,
1425 .set
= py_groupmap_set_comment
,
1432 static PyObject
*py_groupmap_new(PyTypeObject
*type
, PyObject
*args
, PyObject
*kwargs
)
1434 TALLOC_CTX
*frame
= talloc_stackframe();
1435 GROUP_MAP
*group_map
;
1436 TALLOC_CTX
*mem_ctx
;
1437 PyObject
*py_group_map
;
1439 mem_ctx
= talloc_new(NULL
);
1440 if (mem_ctx
== NULL
) {
1446 group_map
= talloc_zero(mem_ctx
, GROUP_MAP
);
1447 if (group_map
== NULL
) {
1449 talloc_free(mem_ctx
);
1454 py_group_map
= pytalloc_steal(type
, group_map
);
1455 if (py_group_map
== NULL
) {
1457 talloc_free(mem_ctx
);
1462 talloc_free(mem_ctx
);
1465 return py_group_map
;
1469 static PyTypeObject PyGroupmap
= {
1470 .tp_name
= "passdb.Groupmap",
1471 .tp_getset
= py_groupmap_getsetters
,
1473 .tp_new
= py_groupmap_new
,
1474 .tp_flags
= Py_TPFLAGS_DEFAULT
| Py_TPFLAGS_BASETYPE
,
1475 .tp_doc
= "Groupmap() -> group map object\n",
1479 static PyObject
*py_pdb_domain_info(PyObject
*self
, PyObject
*args
)
1481 TALLOC_CTX
*frame
= talloc_stackframe();
1482 struct pdb_methods
*methods
;
1483 struct pdb_domain_info
*domain_info
;
1484 PyObject
*py_domain_info
;
1485 struct dom_sid
*sid
;
1487 PyObject
*py_dom_sid
= NULL
;
1488 PyObject
*py_guid
= NULL
;
1490 methods
= pytalloc_get_ptr(self
);
1492 domain_info
= methods
->get_domain_info(methods
, frame
);
1493 if (! domain_info
) {
1497 sid
= dom_sid_dup(frame
, &domain_info
->sid
);
1504 guid
= talloc(frame
, struct GUID
);
1510 *guid
= domain_info
->guid
;
1512 py_dom_sid
= pytalloc_steal(dom_sid_Type
, sid
);
1513 py_guid
= pytalloc_steal(guid_Type
, guid
);
1515 py_domain_info
= Py_BuildValue(
1516 "{s:s, s:s, s:s, s:O, s:O}",
1517 "name", domain_info
->name
,
1518 "dns_domain", domain_info
->dns_domain
,
1519 "dns_forest", domain_info
->dns_forest
,
1520 "dom_sid", py_dom_sid
,
1524 Py_CLEAR(py_dom_sid
);
1527 return py_domain_info
;
1531 static PyObject
*py_pdb_getsampwnam(PyObject
*self
, PyObject
*args
)
1533 TALLOC_CTX
*frame
= talloc_stackframe();
1535 const char *username
;
1536 struct pdb_methods
*methods
;
1537 struct samu
*sam_acct
;
1538 PyObject
*py_sam_acct
;
1540 if (!PyArg_ParseTuple(args
, "s:getsampwnam", &username
)) {
1545 methods
= pytalloc_get_ptr(self
);
1547 py_sam_acct
= py_samu_new(&PySamu
, NULL
, NULL
);
1548 if (py_sam_acct
== NULL
) {
1553 sam_acct
= (struct samu
*)pytalloc_get_ptr(py_sam_acct
);
1555 status
= methods
->getsampwnam(methods
, sam_acct
, username
);
1556 if (!NT_STATUS_IS_OK(status
)) {
1557 PyErr_Format(py_pdb_error
, "Unable to get user information for '%s', (%d,%s)",
1559 NT_STATUS_V(status
),
1560 get_friendly_nt_error_msg(status
));
1561 Py_DECREF(py_sam_acct
);
1570 static PyObject
*py_pdb_getsampwsid(PyObject
*self
, PyObject
*args
)
1572 TALLOC_CTX
*frame
= talloc_stackframe();
1574 struct pdb_methods
*methods
;
1575 struct samu
*sam_acct
;
1576 PyObject
*py_sam_acct
;
1577 PyObject
*py_user_sid
;
1579 if (!PyArg_ParseTuple(args
, "O:getsampwsid", &py_user_sid
)) {
1584 methods
= pytalloc_get_ptr(self
);
1586 py_sam_acct
= py_samu_new(&PySamu
, NULL
, NULL
);
1587 if (py_sam_acct
== NULL
) {
1592 sam_acct
= (struct samu
*)pytalloc_get_ptr(py_sam_acct
);
1594 status
= methods
->getsampwsid(methods
, sam_acct
, pytalloc_get_ptr(py_user_sid
));
1595 if (!NT_STATUS_IS_OK(status
)) {
1596 PyErr_Format(py_pdb_error
, "Unable to get user information from SID, (%d,%s)",
1597 NT_STATUS_V(status
),
1598 get_friendly_nt_error_msg(status
));
1599 Py_DECREF(py_sam_acct
);
1608 static PyObject
*py_pdb_create_user(PyObject
*self
, PyObject
*args
)
1610 TALLOC_CTX
*frame
= talloc_stackframe();
1612 struct pdb_methods
*methods
;
1613 const char *username
;
1614 unsigned int acct_flags
;
1617 if (!PyArg_ParseTuple(args
, "sI:create_user", &username
, &acct_flags
)) {
1622 methods
= pytalloc_get_ptr(self
);
1624 status
= methods
->create_user(methods
, frame
, username
, acct_flags
, &rid
);
1625 if (!NT_STATUS_IS_OK(status
)) {
1626 PyErr_Format(py_pdb_error
, "Unable to create user (%s), (%d,%s)",
1628 NT_STATUS_V(status
),
1629 get_friendly_nt_error_msg(status
));
1635 return PyLong_FromLong(rid
);
1638 static PyObject
*py_pdb_delete_user(PyObject
*self
, PyObject
*args
)
1640 TALLOC_CTX
*frame
= talloc_stackframe();
1642 struct pdb_methods
*methods
;
1643 struct samu
*sam_acct
;
1644 PyObject
*py_sam_acct
;
1646 if (!PyArg_ParseTuple(args
, "O!:delete_user", &PySamu
, &py_sam_acct
)) {
1651 methods
= pytalloc_get_ptr(self
);
1653 sam_acct
= pytalloc_get_ptr(py_sam_acct
);
1655 status
= methods
->delete_user(methods
, frame
, sam_acct
);
1656 if (!NT_STATUS_IS_OK(status
)) {
1657 PyErr_Format(py_pdb_error
, "Unable to delete user, (%d,%s)",
1658 NT_STATUS_V(status
),
1659 get_friendly_nt_error_msg(status
));
1668 static PyObject
*py_pdb_add_sam_account(PyObject
*self
, PyObject
*args
)
1670 TALLOC_CTX
*frame
= talloc_stackframe();
1672 struct pdb_methods
*methods
;
1673 struct samu
*sam_acct
;
1674 PyObject
*py_sam_acct
;
1676 if (!PyArg_ParseTuple(args
, "O!:add_sam_account", &PySamu
, &py_sam_acct
)) {
1681 methods
= pytalloc_get_ptr(self
);
1683 sam_acct
= pytalloc_get_ptr(py_sam_acct
);
1685 status
= methods
->add_sam_account(methods
, sam_acct
);
1686 if (!NT_STATUS_IS_OK(status
)) {
1687 PyErr_Format(py_pdb_error
, "Unable to add sam account '%s', (%d,%s)",
1689 NT_STATUS_V(status
),
1690 get_friendly_nt_error_msg(status
));
1699 static PyObject
*py_pdb_update_sam_account(PyObject
*self
, PyObject
*args
)
1701 TALLOC_CTX
*frame
= talloc_stackframe();
1703 struct pdb_methods
*methods
;
1704 struct samu
*sam_acct
;
1705 PyObject
*py_sam_acct
;
1707 if (!PyArg_ParseTuple(args
, "O!:update_sam_account", &PySamu
, &py_sam_acct
)) {
1712 methods
= pytalloc_get_ptr(self
);
1714 sam_acct
= pytalloc_get_ptr(py_sam_acct
);
1716 status
= methods
->update_sam_account(methods
, sam_acct
);
1717 if (!NT_STATUS_IS_OK(status
)) {
1718 PyErr_Format(py_pdb_error
, "Unable to update sam account, (%d,%s)",
1719 NT_STATUS_V(status
),
1720 get_friendly_nt_error_msg(status
));
1729 static PyObject
*py_pdb_delete_sam_account(PyObject
*self
, PyObject
*args
)
1731 TALLOC_CTX
*frame
= talloc_stackframe();
1733 struct pdb_methods
*methods
;
1734 struct samu
*sam_acct
;
1735 PyObject
*py_sam_acct
;
1737 if (!PyArg_ParseTuple(args
, "O!:delete_sam_account", &PySamu
, &py_sam_acct
)) {
1742 methods
= pytalloc_get_ptr(self
);
1744 sam_acct
= pytalloc_get_ptr(py_sam_acct
);
1746 status
= methods
->delete_sam_account(methods
, sam_acct
);
1747 if (!NT_STATUS_IS_OK(status
)) {
1748 PyErr_Format(py_pdb_error
, "Unable to delete sam account, (%d,%s)",
1749 NT_STATUS_V(status
),
1750 get_friendly_nt_error_msg(status
));
1759 static PyObject
*py_pdb_rename_sam_account(PyObject
*self
, PyObject
*args
)
1761 TALLOC_CTX
*frame
= talloc_stackframe();
1763 struct pdb_methods
*methods
;
1764 struct samu
*sam_acct
;
1765 const char *new_username
;
1766 PyObject
*py_sam_acct
;
1768 if (!PyArg_ParseTuple(args
, "O!s:rename_sam_account", &PySamu
, &py_sam_acct
,
1774 methods
= pytalloc_get_ptr(self
);
1776 sam_acct
= pytalloc_get_ptr(py_sam_acct
);
1778 status
= methods
->rename_sam_account(methods
, sam_acct
, new_username
);
1779 if (!NT_STATUS_IS_OK(status
)) {
1780 PyErr_Format(py_pdb_error
, "Unable to rename sam account, (%d,%s)",
1781 NT_STATUS_V(status
),
1782 get_friendly_nt_error_msg(status
));
1792 static PyObject
*py_pdb_getgrsid(PyObject
*self
, PyObject
*args
)
1794 TALLOC_CTX
*frame
= talloc_stackframe();
1796 struct pdb_methods
*methods
;
1797 GROUP_MAP
*group_map
;
1798 struct dom_sid
*domain_sid
;
1799 PyObject
*py_domain_sid
, *py_group_map
;
1801 if (!PyArg_ParseTuple(args
, "O!:getgrsid", dom_sid_Type
, &py_domain_sid
)) {
1806 methods
= pytalloc_get_ptr(self
);
1808 domain_sid
= pytalloc_get_ptr(py_domain_sid
);
1810 py_group_map
= py_groupmap_new(&PyGroupmap
, NULL
, NULL
);
1811 if (py_group_map
== NULL
) {
1817 group_map
= pytalloc_get_ptr(py_group_map
);
1819 status
= methods
->getgrsid(methods
, group_map
, *domain_sid
);
1820 if (!NT_STATUS_IS_OK(status
)) {
1821 PyErr_Format(py_pdb_error
, "Unable to get group information by sid, (%d,%s)",
1822 NT_STATUS_V(status
),
1823 get_friendly_nt_error_msg(status
));
1829 return py_group_map
;
1833 static PyObject
*py_pdb_getgrgid(PyObject
*self
, PyObject
*args
)
1835 TALLOC_CTX
*frame
= talloc_stackframe();
1837 struct pdb_methods
*methods
;
1838 GROUP_MAP
*group_map
;
1839 PyObject
*py_group_map
;
1840 unsigned int gid_value
;
1842 if (!PyArg_ParseTuple(args
, "I:getgrgid", &gid_value
)) {
1847 methods
= pytalloc_get_ptr(self
);
1849 py_group_map
= py_groupmap_new(&PyGroupmap
, NULL
, NULL
);
1850 if (py_group_map
== NULL
) {
1856 group_map
= pytalloc_get_ptr(py_group_map
);
1858 status
= methods
->getgrgid(methods
, group_map
, gid_value
);
1859 if (!NT_STATUS_IS_OK(status
)) {
1860 PyErr_Format(py_pdb_error
, "Unable to get group information by gid, (%d,%s)",
1861 NT_STATUS_V(status
),
1862 get_friendly_nt_error_msg(status
));
1868 return py_group_map
;
1872 static PyObject
*py_pdb_getgrnam(PyObject
*self
, PyObject
*args
)
1874 TALLOC_CTX
*frame
= talloc_stackframe();
1876 struct pdb_methods
*methods
;
1877 GROUP_MAP
*group_map
;
1878 PyObject
*py_group_map
;
1879 const char *groupname
;
1881 if (!PyArg_ParseTuple(args
, "s:getgrnam", &groupname
)) {
1886 methods
= pytalloc_get_ptr(self
);
1888 py_group_map
= py_groupmap_new(&PyGroupmap
, NULL
, NULL
);
1889 if (py_group_map
== NULL
) {
1895 group_map
= pytalloc_get_ptr(py_group_map
);
1897 status
= methods
->getgrnam(methods
, group_map
, groupname
);
1898 if (!NT_STATUS_IS_OK(status
)) {
1899 PyErr_Format(py_pdb_error
, "Unable to get group information by name, (%d,%s)",
1900 NT_STATUS_V(status
),
1901 get_friendly_nt_error_msg(status
));
1907 return py_group_map
;
1911 static PyObject
*py_pdb_create_dom_group(PyObject
*self
, PyObject
*args
)
1913 TALLOC_CTX
*frame
= talloc_stackframe();
1915 struct pdb_methods
*methods
;
1916 const char *groupname
;
1919 if (!PyArg_ParseTuple(args
, "s:create_dom_group", &groupname
)) {
1924 methods
= pytalloc_get_ptr(self
);
1926 status
= methods
->create_dom_group(methods
, frame
, groupname
, &group_rid
);
1927 if (!NT_STATUS_IS_OK(status
)) {
1928 PyErr_Format(py_pdb_error
, "Unable to create domain group (%s), (%d,%s)",
1930 NT_STATUS_V(status
),
1931 get_friendly_nt_error_msg(status
));
1937 return PyLong_FromLong(group_rid
);
1941 static PyObject
*py_pdb_delete_dom_group(PyObject
*self
, PyObject
*args
)
1943 TALLOC_CTX
*frame
= talloc_stackframe();
1945 struct pdb_methods
*methods
;
1946 unsigned int group_rid
;
1948 if (!PyArg_ParseTuple(args
, "I:delete_dom_group", &group_rid
)) {
1953 methods
= pytalloc_get_ptr(self
);
1955 status
= methods
->delete_dom_group(methods
, frame
, group_rid
);
1956 if (!NT_STATUS_IS_OK(status
)) {
1957 PyErr_Format(py_pdb_error
, "Unable to delete domain group (rid=%d), (%d,%s)",
1959 NT_STATUS_V(status
),
1960 get_friendly_nt_error_msg(status
));
1970 static PyObject
*py_pdb_add_group_mapping_entry(PyObject
*self
, PyObject
*args
)
1972 TALLOC_CTX
*frame
= talloc_stackframe();
1974 struct pdb_methods
*methods
;
1975 PyObject
*py_group_map
;
1976 GROUP_MAP
*group_map
;
1978 if (!PyArg_ParseTuple(args
, "O!:add_group_mapping_entry", &PyGroupmap
, &py_group_map
)) {
1983 methods
= pytalloc_get_ptr(self
);
1985 group_map
= pytalloc_get_ptr(py_group_map
);
1987 status
= methods
->add_group_mapping_entry(methods
, group_map
);
1988 if (!NT_STATUS_IS_OK(status
)) {
1989 PyErr_Format(py_pdb_error
, "Unable to add group mapping entry, (%d,%s)",
1990 NT_STATUS_V(status
),
1991 get_friendly_nt_error_msg(status
));
2001 static PyObject
*py_pdb_update_group_mapping_entry(PyObject
*self
, PyObject
*args
)
2003 TALLOC_CTX
*frame
= talloc_stackframe();
2005 struct pdb_methods
*methods
;
2006 PyObject
*py_group_map
;
2007 GROUP_MAP
*group_map
;
2009 if (!PyArg_ParseTuple(args
, "O!:update_group_mapping_entry", &PyGroupmap
, &py_group_map
)) {
2014 methods
= pytalloc_get_ptr(self
);
2016 group_map
= pytalloc_get_ptr(py_group_map
);
2018 status
= methods
->update_group_mapping_entry(methods
, group_map
);
2019 if (!NT_STATUS_IS_OK(status
)) {
2020 PyErr_Format(py_pdb_error
, "Unable to update group mapping entry, (%d,%s)",
2021 NT_STATUS_V(status
),
2022 get_friendly_nt_error_msg(status
));
2032 static PyObject
*py_pdb_delete_group_mapping_entry(PyObject
*self
, PyObject
*args
)
2034 TALLOC_CTX
*frame
= talloc_stackframe();
2036 struct pdb_methods
*methods
;
2037 PyObject
*py_group_sid
;
2038 struct dom_sid
*group_sid
;
2040 if (!PyArg_ParseTuple(args
, "O!:delete_group_mapping_entry", dom_sid_Type
, &py_group_sid
)) {
2045 methods
= pytalloc_get_ptr(self
);
2047 group_sid
= pytalloc_get_ptr(py_group_sid
);
2049 status
= methods
->delete_group_mapping_entry(methods
, *group_sid
);
2050 if (!NT_STATUS_IS_OK(status
)) {
2051 PyErr_Format(py_pdb_error
, "Unable to delete group mapping entry, (%d,%s)",
2052 NT_STATUS_V(status
),
2053 get_friendly_nt_error_msg(status
));
2063 static PyObject
*py_pdb_enum_group_mapping(PyObject
*self
, PyObject
*args
)
2065 TALLOC_CTX
*frame
= talloc_stackframe();
2067 struct pdb_methods
*methods
;
2068 enum lsa_SidType sid_name_use
;
2069 int lsa_sidtype_value
= SID_NAME_UNKNOWN
;
2071 PyObject
*py_domain_sid
= Py_None
;
2072 struct dom_sid
*domain_sid
= NULL
;
2073 GROUP_MAP
**gmap
= NULL
;
2074 GROUP_MAP
*group_map
;
2075 size_t i
, num_entries
;
2076 PyObject
*py_gmap_list
, *py_group_map
;
2080 if (!PyArg_ParseTuple(args
, "|O!ii:enum_group_mapping", dom_sid_Type
, &py_domain_sid
,
2081 &lsa_sidtype_value
, &unix_only
)) {
2086 methods
= pytalloc_get_ptr(self
);
2088 sid_name_use
= lsa_sidtype_value
;
2090 if (py_domain_sid
!= Py_None
) {
2091 domain_sid
= pytalloc_get_ptr(py_domain_sid
);
2094 status
= methods
->enum_group_mapping(methods
, domain_sid
, sid_name_use
,
2095 &gmap
, &num_entries
, unix_only
);
2096 if (!NT_STATUS_IS_OK(status
)) {
2097 PyErr_Format(py_pdb_error
, "Unable to enumerate group mappings, (%d,%s)",
2098 NT_STATUS_V(status
),
2099 get_friendly_nt_error_msg(status
));
2104 py_gmap_list
= PyList_New(0);
2105 if (py_gmap_list
== NULL
) {
2111 for(i
=0; i
<num_entries
; i
++) {
2112 py_group_map
= py_groupmap_new(&PyGroupmap
, NULL
, NULL
);
2115 group_map
= pytalloc_get_ptr(py_group_map
);
2116 *group_map
= *gmap
[i
];
2117 talloc_steal(group_map
, gmap
[i
]->nt_name
);
2118 talloc_steal(group_map
, gmap
[i
]->comment
);
2120 res
= PyList_Append(py_gmap_list
, py_group_map
);
2121 Py_CLEAR(py_group_map
);
2123 Py_CLEAR(py_gmap_list
);
2133 return py_gmap_list
;
2137 static PyObject
*py_pdb_enum_group_members(PyObject
*self
, PyObject
*args
)
2139 TALLOC_CTX
*frame
= talloc_stackframe();
2141 struct pdb_methods
*methods
;
2142 PyObject
*py_group_sid
;
2143 struct dom_sid
*group_sid
;
2144 uint32_t *member_rids
;
2145 size_t i
, num_members
;
2146 PyObject
*py_sid_list
;
2147 struct dom_sid
*domain_sid
, *member_sid
;
2149 if (!PyArg_ParseTuple(args
, "O!:enum_group_members", dom_sid_Type
, &py_group_sid
)) {
2154 methods
= pytalloc_get_ptr(self
);
2156 group_sid
= pytalloc_get_ptr(py_group_sid
);
2158 status
= methods
->enum_group_members(methods
, frame
, group_sid
,
2159 &member_rids
, &num_members
);
2160 if (!NT_STATUS_IS_OK(status
)) {
2161 PyErr_Format(py_pdb_error
, "Unable to enumerate group members, (%d,%s)",
2162 NT_STATUS_V(status
),
2163 get_friendly_nt_error_msg(status
));
2168 py_sid_list
= PyList_New(0);
2169 if (py_sid_list
== NULL
) {
2175 domain_sid
= get_global_sam_sid();
2177 for(i
=0; i
<num_members
; i
++) {
2179 PyObject
*py_member_sid
= NULL
;
2180 member_sid
= dom_sid_add_rid(frame
, domain_sid
, member_rids
[i
]);
2181 py_member_sid
= pytalloc_steal(dom_sid_Type
, member_sid
);
2182 res
= PyList_Append(py_sid_list
,
2184 Py_CLEAR(py_member_sid
);
2187 Py_CLEAR(py_sid_list
);
2197 static PyObject
*py_pdb_enum_group_memberships(PyObject
*self
, PyObject
*args
)
2199 TALLOC_CTX
*frame
= talloc_stackframe();
2201 struct pdb_methods
*methods
;
2204 struct samu
*sam_acct
;
2205 PyObject
*py_sam_acct
;
2206 PyObject
*py_sid_list
;
2207 struct dom_sid
*user_group_sids
= NULL
;
2208 gid_t
*user_group_ids
= NULL
;
2209 uint32_t num_groups
= 0;
2211 if (!PyArg_ParseTuple(args
, "O!:enum_group_memberships", &PySamu
, &py_sam_acct
)) {
2216 methods
= pytalloc_get_ptr(self
);
2218 sam_acct
= pytalloc_get_ptr(py_sam_acct
);
2220 status
= methods
->enum_group_memberships(methods
, frame
, sam_acct
,
2221 &user_group_sids
, &user_group_ids
, &num_groups
);
2222 if (!NT_STATUS_IS_OK(status
)) {
2223 PyErr_Format(py_pdb_error
, "Unable to enumerate group memberships, (%d,%s)",
2224 NT_STATUS_V(status
),
2225 get_friendly_nt_error_msg(status
));
2230 py_sid_list
= PyList_New(0);
2231 if (py_sid_list
== NULL
) {
2237 for(i
=0; i
<num_groups
; i
++) {
2239 pytalloc_steal(dom_sid_Type
,
2240 dom_sid_dup(NULL
, &user_group_sids
[i
]));
2241 PyList_Append(py_sid_list
, py_sid
);
2250 static PyObject
*py_pdb_add_groupmem(PyObject
*self
, PyObject
*args
)
2252 TALLOC_CTX
*frame
= talloc_stackframe();
2254 struct pdb_methods
*methods
;
2255 uint32_t group_rid
, member_rid
;
2257 if (!PyArg_ParseTuple(args
, "II:add_groupmem", &group_rid
, &member_rid
)) {
2262 methods
= pytalloc_get_ptr(self
);
2264 status
= methods
->add_groupmem(methods
, frame
, group_rid
, member_rid
);
2265 if (!NT_STATUS_IS_OK(status
)) {
2266 PyErr_Format(py_pdb_error
, "Unable to add group member, (%d,%s)",
2267 NT_STATUS_V(status
),
2268 get_friendly_nt_error_msg(status
));
2278 static PyObject
*py_pdb_del_groupmem(PyObject
*self
, PyObject
*args
)
2280 TALLOC_CTX
*frame
= talloc_stackframe();
2282 struct pdb_methods
*methods
;
2283 uint32_t group_rid
, member_rid
;
2285 if (!PyArg_ParseTuple(args
, "II:del_groupmem", &group_rid
, &member_rid
)) {
2290 methods
= pytalloc_get_ptr(self
);
2292 status
= methods
->del_groupmem(methods
, frame
, group_rid
, member_rid
);
2293 if (!NT_STATUS_IS_OK(status
)) {
2294 PyErr_Format(py_pdb_error
, "Unable to rename sam account, (%d,%s)",
2295 NT_STATUS_V(status
),
2296 get_friendly_nt_error_msg(status
));
2306 static PyObject
*py_pdb_create_alias(PyObject
*self
, PyObject
*args
)
2308 TALLOC_CTX
*frame
= talloc_stackframe();
2310 struct pdb_methods
*methods
;
2311 const char *alias_name
;
2314 if (!PyArg_ParseTuple(args
, "s:create_alias", &alias_name
)) {
2319 methods
= pytalloc_get_ptr(self
);
2321 status
= methods
->create_alias(methods
, alias_name
, &rid
);
2322 if (!NT_STATUS_IS_OK(status
)) {
2323 PyErr_Format(py_pdb_error
, "Unable to create alias (%s), (%d,%s)",
2325 NT_STATUS_V(status
),
2326 get_friendly_nt_error_msg(status
));
2332 return PyLong_FromLong(rid
);
2336 static PyObject
*py_pdb_delete_alias(PyObject
*self
, PyObject
*args
)
2338 TALLOC_CTX
*frame
= talloc_stackframe();
2340 struct pdb_methods
*methods
;
2341 PyObject
*py_alias_sid
;
2342 struct dom_sid
*alias_sid
;
2344 if (!PyArg_ParseTuple(args
, "O!:delete_alias", dom_sid_Type
, &py_alias_sid
)) {
2349 methods
= pytalloc_get_ptr(self
);
2351 alias_sid
= pytalloc_get_ptr(py_alias_sid
);
2353 status
= methods
->delete_alias(methods
, alias_sid
);
2354 if (!NT_STATUS_IS_OK(status
)) {
2355 PyErr_Format(py_pdb_error
, "Unable to delete alias, (%d,%s)",
2356 NT_STATUS_V(status
),
2357 get_friendly_nt_error_msg(status
));
2367 static PyObject
*py_pdb_get_aliasinfo(PyObject
*self
, PyObject
*args
)
2369 TALLOC_CTX
*frame
= talloc_stackframe();
2371 struct pdb_methods
*methods
;
2372 PyObject
*py_alias_sid
;
2373 struct dom_sid
*alias_sid
;
2374 struct acct_info
*alias_info
;
2375 PyObject
*py_alias_info
;
2377 if (!PyArg_ParseTuple(args
, "O!:get_aliasinfo", dom_sid_Type
, &py_alias_sid
)) {
2382 methods
= pytalloc_get_ptr(self
);
2384 alias_sid
= pytalloc_get_ptr(py_alias_sid
);
2386 alias_info
= talloc_zero(frame
, struct acct_info
);
2393 status
= methods
->get_aliasinfo(methods
, alias_sid
, alias_info
);
2394 if (!NT_STATUS_IS_OK(status
)) {
2395 PyErr_Format(py_pdb_error
, "Unable to get alias information, (%d,%s)",
2396 NT_STATUS_V(status
),
2397 get_friendly_nt_error_msg(status
));
2402 py_alias_info
= Py_BuildValue(
2404 "acct_name", alias_info
->acct_name
,
2405 "acct_desc", alias_info
->acct_desc
,
2406 "rid", alias_info
->rid
);
2409 return py_alias_info
;
2413 static PyObject
*py_pdb_set_aliasinfo(PyObject
*self
, PyObject
*args
)
2415 TALLOC_CTX
*frame
= talloc_stackframe();
2417 struct pdb_methods
*methods
;
2418 PyObject
*py_alias_sid
, *py_alias_info
;
2419 struct dom_sid
*alias_sid
;
2420 struct acct_info alias_info
;
2422 if (!PyArg_ParseTuple(args
, "O!O:set_alias_info", dom_sid_Type
, &py_alias_sid
,
2428 methods
= pytalloc_get_ptr(self
);
2430 alias_sid
= pytalloc_get_ptr(py_alias_sid
);
2432 alias_info
.acct_name
= talloc_strdup(frame
, PyUnicode_AsUTF8(PyDict_GetItemString(py_alias_info
, "acct_name")));
2433 if (alias_info
.acct_name
== NULL
) {
2434 PyErr_Format(py_pdb_error
, "Unable to allocate memory");
2438 alias_info
.acct_desc
= talloc_strdup(frame
, PyUnicode_AsUTF8(PyDict_GetItemString(py_alias_info
, "acct_desc")));
2439 if (alias_info
.acct_desc
== NULL
) {
2440 PyErr_Format(py_pdb_error
, "Unable to allocate memory");
2445 status
= methods
->set_aliasinfo(methods
, alias_sid
, &alias_info
);
2446 if (!NT_STATUS_IS_OK(status
)) {
2447 PyErr_Format(py_pdb_error
, "Unable to set alias information, (%d,%s)",
2448 NT_STATUS_V(status
),
2449 get_friendly_nt_error_msg(status
));
2459 static PyObject
*py_pdb_add_aliasmem(PyObject
*self
, PyObject
*args
)
2461 TALLOC_CTX
*frame
= talloc_stackframe();
2463 struct pdb_methods
*methods
;
2464 PyObject
*py_alias_sid
, *py_member_sid
;
2465 struct dom_sid
*alias_sid
, *member_sid
;
2467 if (!PyArg_ParseTuple(args
, "O!O!:add_aliasmem", dom_sid_Type
, &py_alias_sid
,
2468 dom_sid_Type
, &py_member_sid
)) {
2473 methods
= pytalloc_get_ptr(self
);
2475 alias_sid
= pytalloc_get_ptr(py_alias_sid
);
2476 member_sid
= pytalloc_get_ptr(py_member_sid
);
2478 status
= methods
->add_aliasmem(methods
, alias_sid
, member_sid
);
2479 if (!NT_STATUS_IS_OK(status
)) {
2480 PyErr_Format(py_pdb_error
, "Unable to add member to alias, (%d,%s)",
2481 NT_STATUS_V(status
),
2482 get_friendly_nt_error_msg(status
));
2492 static PyObject
*py_pdb_del_aliasmem(PyObject
*self
, PyObject
*args
)
2494 TALLOC_CTX
*frame
= talloc_stackframe();
2496 struct pdb_methods
*methods
;
2497 PyObject
*py_alias_sid
, *py_member_sid
;
2498 const struct dom_sid
*alias_sid
, *member_sid
;
2500 if (!PyArg_ParseTuple(args
, "O!O!:del_aliasmem", dom_sid_Type
, &py_alias_sid
,
2501 dom_sid_Type
, &py_member_sid
)) {
2506 methods
= pytalloc_get_ptr(self
);
2508 alias_sid
= pytalloc_get_ptr(py_alias_sid
);
2509 member_sid
= pytalloc_get_ptr(py_member_sid
);
2511 status
= methods
->del_aliasmem(methods
, alias_sid
, member_sid
);
2512 if (!NT_STATUS_IS_OK(status
)) {
2513 PyErr_Format(py_pdb_error
, "Unable to delete member from alias, (%d,%s)",
2514 NT_STATUS_V(status
),
2515 get_friendly_nt_error_msg(status
));
2525 static PyObject
*py_pdb_enum_aliasmem(PyObject
*self
, PyObject
*args
)
2527 TALLOC_CTX
*frame
= talloc_stackframe();
2529 struct pdb_methods
*methods
;
2530 PyObject
*py_alias_sid
;
2531 struct dom_sid
*alias_sid
, *member_sid
, *tmp_sid
;
2532 PyObject
*py_member_list
, *py_member_sid
;
2533 size_t i
, num_members
;
2535 if (!PyArg_ParseTuple(args
, "O!:enum_aliasmem", dom_sid_Type
, &py_alias_sid
)) {
2540 methods
= pytalloc_get_ptr(self
);
2542 alias_sid
= pytalloc_get_ptr(py_alias_sid
);
2544 status
= methods
->enum_aliasmem(methods
, alias_sid
, frame
, &member_sid
, &num_members
);
2545 if (!NT_STATUS_IS_OK(status
)) {
2546 PyErr_Format(py_pdb_error
, "Unable to enumerate members for alias, (%d,%s)",
2547 NT_STATUS_V(status
),
2548 get_friendly_nt_error_msg(status
));
2553 py_member_list
= PyList_New(0);
2554 if (py_member_list
== NULL
) {
2560 for(i
=0; i
<num_members
; i
++) {
2562 py_member_sid
= pytalloc_new(struct dom_sid
, dom_sid_Type
);
2563 if (py_member_sid
== NULL
) {
2565 Py_CLEAR(py_member_list
);
2569 tmp_sid
= pytalloc_get_ptr(py_member_sid
);
2570 *tmp_sid
= member_sid
[i
];
2571 res
= PyList_Append(py_member_list
, py_member_sid
);
2572 Py_CLEAR(py_member_sid
);
2574 Py_CLEAR(py_member_list
);
2581 return py_member_list
;
2585 static PyObject
*py_pdb_get_account_policy(PyObject
*self
, PyObject
*unused
)
2587 TALLOC_CTX
*frame
= talloc_stackframe();
2589 struct pdb_methods
*methods
;
2590 PyObject
*py_acct_policy
;
2594 enum pdb_policy_type type
;
2596 methods
= pytalloc_get_ptr(self
);
2598 py_acct_policy
= PyDict_New();
2599 if (py_acct_policy
== NULL
) {
2605 account_policy_names_list(frame
, &names
, &count
);
2606 for (i
=0; i
<count
; i
++) {
2607 type
= account_policy_name_to_typenum(names
[i
]);
2608 status
= methods
->get_account_policy(methods
, type
, &value
);
2609 if (NT_STATUS_IS_OK(status
)) {
2611 PyObject
*py_value
= Py_BuildValue("i", value
);
2612 if (py_value
== NULL
) {
2613 Py_CLEAR(py_acct_policy
);
2616 res
= PyDict_SetItemString(py_acct_policy
,
2621 Py_CLEAR(py_acct_policy
);
2628 return py_acct_policy
;
2632 static PyObject
*py_pdb_set_account_policy(PyObject
*self
, PyObject
*args
)
2634 TALLOC_CTX
*frame
= talloc_stackframe();
2636 struct pdb_methods
*methods
;
2637 PyObject
*py_acct_policy
, *py_value
;
2640 enum pdb_policy_type type
;
2642 if (!PyArg_ParseTuple(args
, "O!:set_account_policy", PyDict_Type
, &py_acct_policy
)) {
2647 methods
= pytalloc_get_ptr(self
);
2649 account_policy_names_list(frame
, &names
, &count
);
2650 for (i
=0; i
<count
; i
++) {
2651 if ((py_value
= PyDict_GetItemString(py_acct_policy
, names
[i
])) != NULL
) {
2652 type
= account_policy_name_to_typenum(names
[i
]);
2653 status
= methods
->set_account_policy(methods
, type
, PyLong_AsLong(py_value
));
2654 if (!NT_STATUS_IS_OK(status
)) {
2655 PyErr_Format(py_pdb_error
, "Error setting account policy (%s), (%d,%s)",
2657 NT_STATUS_V(status
),
2658 get_friendly_nt_error_msg(status
));
2667 static PyObject
*py_pdb_search_users(PyObject
*self
, PyObject
*args
)
2669 TALLOC_CTX
*frame
= talloc_stackframe();
2670 struct pdb_methods
*methods
;
2671 unsigned int acct_flags
;
2672 struct pdb_search
*search
;
2673 struct samr_displayentry
*entry
;
2674 PyObject
*py_userlist
, *py_dict
;
2676 if (!PyArg_ParseTuple(args
, "I:search_users", &acct_flags
)) {
2681 methods
= pytalloc_get_ptr(self
);
2683 search
= talloc_zero(frame
, struct pdb_search
);
2684 if (search
== NULL
) {
2690 if (!methods
->search_users(methods
, search
, acct_flags
)) {
2691 PyErr_Format(py_pdb_error
, "Unable to search users");
2696 entry
= talloc_zero(frame
, struct samr_displayentry
);
2697 if (entry
== NULL
) {
2703 py_userlist
= PyList_New(0);
2704 if (py_userlist
== NULL
) {
2710 while (search
->next_entry(search
, entry
)) {
2712 py_dict
= Py_BuildValue(
2713 "{s:l, s:l, s:l, s:s, s:s, s:s}",
2716 "acct_flags", entry
->acct_flags
,
2717 "account_name", entry
->account_name
,
2718 "fullname", entry
->fullname
,
2719 "description", entry
->description
);
2720 if (py_dict
== NULL
) {
2721 Py_CLEAR(py_userlist
);
2725 res
= PyList_Append(py_userlist
, py_dict
);
2728 Py_CLEAR(py_userlist
);
2732 search
->search_end(search
);
2740 static PyObject
*py_pdb_search_groups(PyObject
*self
, PyObject
*unused
)
2742 TALLOC_CTX
*frame
= talloc_stackframe();
2743 struct pdb_methods
*methods
;
2744 struct pdb_search
*search
;
2745 struct samr_displayentry
*entry
;
2746 PyObject
*py_grouplist
, *py_dict
;
2748 methods
= pytalloc_get_ptr(self
);
2750 search
= talloc_zero(frame
, struct pdb_search
);
2751 if (search
== NULL
) {
2757 if (!methods
->search_groups(methods
, search
)) {
2758 PyErr_Format(py_pdb_error
, "Unable to search groups");
2763 entry
= talloc_zero(frame
, struct samr_displayentry
);
2764 if (entry
== NULL
) {
2770 py_grouplist
= PyList_New(0);
2771 if (py_grouplist
== NULL
) {
2777 while (search
->next_entry(search
, entry
)) {
2779 py_dict
= Py_BuildValue(
2780 "{s:l, s:l, s:l, s:s, s:s, s:s}",
2783 "acct_flags", entry
->acct_flags
,
2784 "account_name", entry
->account_name
,
2785 "fullname", entry
->fullname
,
2786 "description", entry
->description
);
2788 if (py_dict
== NULL
) {
2789 Py_CLEAR(py_grouplist
);
2793 res
= PyList_Append(py_grouplist
, py_dict
);
2796 Py_CLEAR(py_grouplist
);
2800 search
->search_end(search
);
2803 return py_grouplist
;
2807 static PyObject
*py_pdb_search_aliases(PyObject
*self
, PyObject
*args
)
2809 TALLOC_CTX
*frame
= talloc_stackframe();
2810 struct pdb_methods
*methods
;
2811 struct pdb_search
*search
;
2812 struct samr_displayentry
*entry
;
2813 PyObject
*py_aliaslist
, *py_dict
;
2814 PyObject
*py_domain_sid
= Py_None
;
2815 struct dom_sid
*domain_sid
= NULL
;
2819 if (!PyArg_ParseTuple(args
, "|O!:search_aliases", dom_sid_Type
, &py_domain_sid
)) {
2824 methods
= pytalloc_get_ptr(self
);
2826 if (py_domain_sid
!= Py_None
) {
2827 domain_sid
= pytalloc_get_ptr(py_domain_sid
);
2830 search
= talloc_zero(frame
, struct pdb_search
);
2831 if (search
== NULL
) {
2837 if (!methods
->search_aliases(methods
, search
, domain_sid
)) {
2838 PyErr_Format(py_pdb_error
, "Unable to search aliases");
2843 entry
= talloc_zero(frame
, struct samr_displayentry
);
2844 if (entry
== NULL
) {
2850 py_aliaslist
= PyList_New(0);
2851 if (py_aliaslist
== NULL
) {
2857 while (search
->next_entry(search
, entry
)) {
2860 py_dict
= Py_BuildValue(
2861 "{s:l, s:l, s:l, s:s, s:s, s:s}",
2864 "acct_flags", entry
->acct_flags
,
2865 "account_name", entry
->account_name
,
2866 "fullname", entry
->fullname
,
2867 "description", entry
->description
);
2869 if (py_dict
== NULL
) {
2870 Py_CLEAR(py_aliaslist
);
2873 res
= PyList_Append(py_aliaslist
, py_dict
);
2876 Py_CLEAR(py_aliaslist
);
2880 search
->search_end(search
);
2883 return py_aliaslist
;
2887 static PyObject
*py_pdb_uid_to_sid(PyObject
*self
, PyObject
*args
)
2889 TALLOC_CTX
*frame
= talloc_stackframe();
2890 struct pdb_methods
*methods
;
2893 struct dom_sid user_sid
, *copy_user_sid
;
2894 PyObject
*py_user_sid
;
2896 if (!PyArg_ParseTuple(args
, "I:uid_to_sid", &uid
)) {
2901 methods
= pytalloc_get_ptr(self
);
2904 id
.type
= ID_TYPE_UID
;
2906 if (!methods
->id_to_sid(methods
, &id
, &user_sid
)) {
2907 PyErr_Format(py_pdb_error
, "Unable to get sid for uid=%d", uid
);
2912 copy_user_sid
= dom_sid_dup(frame
, &user_sid
);
2913 if (copy_user_sid
== NULL
) {
2919 py_user_sid
= pytalloc_steal(dom_sid_Type
, copy_user_sid
);
2926 static PyObject
*py_pdb_gid_to_sid(PyObject
*self
, PyObject
*args
)
2928 TALLOC_CTX
*frame
= talloc_stackframe();
2929 struct pdb_methods
*methods
;
2932 struct dom_sid group_sid
, *copy_group_sid
;
2933 PyObject
*py_group_sid
;
2935 if (!PyArg_ParseTuple(args
, "I:gid_to_sid", &gid
)) {
2941 id
.type
= ID_TYPE_GID
;
2943 methods
= pytalloc_get_ptr(self
);
2945 if (!methods
->id_to_sid(methods
, &id
, &group_sid
)) {
2946 PyErr_Format(py_pdb_error
, "Unable to get sid for gid=%d", gid
);
2951 copy_group_sid
= dom_sid_dup(frame
, &group_sid
);
2952 if (copy_group_sid
== NULL
) {
2958 py_group_sid
= pytalloc_steal(dom_sid_Type
, copy_group_sid
);
2961 return py_group_sid
;
2965 static PyObject
*py_pdb_sid_to_id(PyObject
*self
, PyObject
*args
)
2967 TALLOC_CTX
*frame
= talloc_stackframe();
2968 struct pdb_methods
*methods
;
2970 struct dom_sid
*sid
;
2973 if (!PyArg_ParseTuple(args
, "O!:sid_to_id", dom_sid_Type
, &py_sid
)) {
2978 methods
= pytalloc_get_ptr(self
);
2980 sid
= pytalloc_get_ptr(py_sid
);
2982 if (!methods
->sid_to_id(methods
, sid
, &id
)) {
2983 PyErr_Format(py_pdb_error
, "Unable to get id for sid");
2989 return Py_BuildValue("(II)", id
.id
, id
.type
);
2993 static PyObject
*py_pdb_new_rid(PyObject
*self
, PyObject
*unused
)
2995 TALLOC_CTX
*frame
= talloc_stackframe();
2996 struct pdb_methods
*methods
;
2999 methods
= pytalloc_get_ptr(self
);
3001 if (!methods
->new_rid(methods
, &rid
)) {
3002 PyErr_Format(py_pdb_error
, "Unable to get new rid");
3008 return PyLong_FromLong(rid
);
3012 static PyObject
*py_pdb_get_trusteddom_pw(PyObject
*self
, PyObject
*args
)
3014 TALLOC_CTX
*frame
= talloc_stackframe();
3015 struct pdb_methods
*methods
;
3018 struct dom_sid sid
, *copy_sid
;
3020 time_t last_set_time
;
3023 if (!PyArg_ParseTuple(args
, "s:get_trusteddom_pw", &domain
)) {
3028 methods
= pytalloc_get_ptr(self
);
3030 if (!methods
->get_trusteddom_pw(methods
, domain
, &pwd
, &sid
, &last_set_time
)) {
3031 PyErr_Format(py_pdb_error
, "Unable to get trusted domain password");
3036 copy_sid
= dom_sid_dup(frame
, &sid
);
3037 if (copy_sid
== NULL
) {
3043 py_sid
= pytalloc_steal(dom_sid_Type
, copy_sid
);
3044 if (py_sid
== NULL
) {
3050 py_value
= Py_BuildValue(
3054 "last_set_tim", last_set_time
);
3062 static PyObject
*py_pdb_set_trusteddom_pw(PyObject
*self
, PyObject
*args
)
3064 TALLOC_CTX
*frame
= talloc_stackframe();
3065 struct pdb_methods
*methods
;
3068 const struct dom_sid
*domain_sid
;
3069 PyObject
*py_domain_sid
;
3071 if (!PyArg_ParseTuple(args
, "ssO!:set_trusteddom_pw", &domain
, &pwd
,
3072 dom_sid_Type
, &py_domain_sid
)) {
3077 methods
= pytalloc_get_ptr(self
);
3079 domain_sid
= pytalloc_get_ptr(py_domain_sid
);
3081 if (!methods
->set_trusteddom_pw(methods
, domain
, pwd
, domain_sid
)) {
3082 PyErr_Format(py_pdb_error
, "Unable to set trusted domain password");
3092 static PyObject
*py_pdb_del_trusteddom_pw(PyObject
*self
, PyObject
*args
)
3094 TALLOC_CTX
*frame
= talloc_stackframe();
3095 struct pdb_methods
*methods
;
3098 if (!PyArg_ParseTuple(args
, "s:del_trusteddom_pw", &domain
)) {
3103 methods
= pytalloc_get_ptr(self
);
3105 if (!methods
->del_trusteddom_pw(methods
, domain
)) {
3106 PyErr_Format(py_pdb_error
, "Unable to delete trusted domain password");
3116 static PyObject
*py_pdb_enum_trusteddoms(PyObject
*self
, PyObject
*unused
)
3118 TALLOC_CTX
*frame
= talloc_stackframe();
3120 struct pdb_methods
*methods
;
3121 uint32_t i
, num_domains
;
3122 struct trustdom_info
**domains
;
3123 PyObject
*py_domain_list
, *py_dict
;
3125 methods
= pytalloc_get_ptr(self
);
3127 status
= methods
->enum_trusteddoms(methods
, frame
, &num_domains
, &domains
);
3128 if (!NT_STATUS_IS_OK(status
)) {
3129 PyErr_Format(py_pdb_error
, "Unable to enumerate trusted domains, (%d,%s)",
3130 NT_STATUS_V(status
),
3131 get_friendly_nt_error_msg(status
));
3136 py_domain_list
= PyList_New(0);
3137 if (py_domain_list
== NULL
) {
3143 for(i
=0; i
<num_domains
; i
++) {
3146 pytalloc_steal(dom_sid_Type
, &domains
[i
]->sid
);
3147 py_dict
= Py_BuildValue(
3149 "name", domains
[i
]->name
,
3152 if (py_dict
== NULL
) {
3153 DBG_ERR("Failed to insert entry to dict\n");
3154 Py_CLEAR(py_domain_list
);
3158 res
= PyList_Append(py_domain_list
, py_dict
);
3161 Py_CLEAR(py_domain_list
);
3167 return py_domain_list
;
3171 static PyObject
*py_pdb_get_trusted_domain(PyObject
*self
, PyObject
*args
)
3173 TALLOC_CTX
*frame
= talloc_stackframe();
3175 struct pdb_methods
*methods
;
3177 struct pdb_trusted_domain
*td
;
3178 PyObject
*py_domain_info
;
3179 PyObject
*py_sid
= NULL
;
3181 if (!PyArg_ParseTuple(args
, "s:get_trusted_domain", &domain
)) {
3186 methods
= pytalloc_get_ptr(self
);
3188 status
= methods
->get_trusted_domain(methods
, frame
, domain
, &td
);
3189 if (!NT_STATUS_IS_OK(status
)) {
3190 PyErr_Format(py_pdb_error
, "Unable to get trusted domain information, (%d,%s)",
3191 NT_STATUS_V(status
),
3192 get_friendly_nt_error_msg(status
));
3197 py_sid
= pytalloc_steal(dom_sid_Type
, &td
->security_identifier
);
3199 py_domain_info
= Py_BuildValue(
3201 " s:"PYARG_BYTES_LEN
","
3202 " s:"PYARG_BYTES_LEN
","
3204 " s:"PYARG_BYTES_LEN
"}",
3205 "domain_name", td
->domain_name
,
3206 "netbios_name", td
->netbios_name
,
3207 "security_identifier", py_sid
,
3208 "trust_auth_incoming",
3209 (const char *)td
->trust_auth_incoming
.data
,
3210 td
->trust_auth_incoming
.length
,
3211 "trust_auth_outgoing",
3212 (const char *)td
->trust_auth_outgoing
.data
,
3213 td
->trust_auth_outgoing
.length
,
3214 "trust_direction", td
->trust_direction
,
3215 "trust_type", td
->trust_type
,
3216 "trust_attributes", td
->trust_attributes
,
3217 "trust_forest_trust_info",
3218 (const char *)td
->trust_forest_trust_info
.data
,
3219 td
->trust_forest_trust_info
.length
);
3223 return py_domain_info
;
3227 static PyObject
*py_pdb_get_trusted_domain_by_sid(PyObject
*self
, PyObject
*args
)
3229 TALLOC_CTX
*frame
= talloc_stackframe();
3231 struct pdb_methods
*methods
;
3232 PyObject
*py_domain_sid
;
3233 struct dom_sid
*domain_sid
;
3234 struct pdb_trusted_domain
*td
;
3235 PyObject
*py_domain_info
;
3236 PyObject
*py_sid
= NULL
;
3238 if (!PyArg_ParseTuple(args
, "O!:get_trusted_domain_by_sid", dom_sid_Type
, &py_domain_sid
)) {
3243 methods
= pytalloc_get_ptr(self
);
3245 domain_sid
= pytalloc_get_ptr(py_domain_sid
);
3247 status
= methods
->get_trusted_domain_by_sid(methods
, frame
, domain_sid
, &td
);
3248 if (!NT_STATUS_IS_OK(status
)) {
3249 PyErr_Format(py_pdb_error
, "Unable to get trusted domain information, (%d,%s)",
3250 NT_STATUS_V(status
),
3251 get_friendly_nt_error_msg(status
));
3256 py_sid
= pytalloc_steal(dom_sid_Type
, &td
->security_identifier
);
3258 py_domain_info
= Py_BuildValue(
3260 " s:"PYARG_BYTES_LEN
","
3261 " s:"PYARG_BYTES_LEN
","
3263 " s:"PYARG_BYTES_LEN
"}",
3264 "domain_name", td
->domain_name
,
3265 "netbios_name", td
->netbios_name
,
3266 "security_identifier", py_sid
,
3267 "trust_auth_incoming",
3268 (const char *)td
->trust_auth_incoming
.data
,
3269 td
->trust_auth_incoming
.length
,
3270 "trust_auth_outgoing",
3271 (const char *)td
->trust_auth_outgoing
.data
,
3272 td
->trust_auth_outgoing
.length
,
3273 "trust_direction", td
->trust_direction
,
3274 "trust_type", td
->trust_type
,
3275 "trust_attributes", td
->trust_attributes
,
3276 "trust_forest_trust_info",
3277 (const char *)td
->trust_forest_trust_info
.data
,
3278 td
->trust_forest_trust_info
.length
);
3282 return py_domain_info
;
3286 static PyObject
*py_pdb_set_trusted_domain(PyObject
*self
, PyObject
*args
)
3288 TALLOC_CTX
*frame
= talloc_stackframe();
3290 struct pdb_methods
*methods
;
3292 PyObject
*py_td_info
;
3293 struct pdb_trusted_domain td_info
;
3297 if (!PyArg_ParseTuple(args
, "sO!:set_trusted_domain", &domain
, &PyDict_Type
, &py_td_info
)) {
3302 py_tmp
= PyDict_GetItemString(py_td_info
, "domain_name");
3303 td_info
.domain_name
= discard_const_p(char, PyUnicode_AsUTF8(py_tmp
));
3305 py_tmp
= PyDict_GetItemString(py_td_info
, "netbios_name");
3306 td_info
.netbios_name
= discard_const_p(char, PyUnicode_AsUTF8(py_tmp
));
3308 py_tmp
= PyDict_GetItemString(py_td_info
, "security_identifier");
3309 td_info
.security_identifier
= *pytalloc_get_type(py_tmp
, struct dom_sid
);
3311 py_tmp
= PyDict_GetItemString(py_td_info
, "trust_auth_incoming");
3312 PyBytes_AsStringAndSize(py_tmp
, (char **)&td_info
.trust_auth_incoming
.data
, &len
);
3313 td_info
.trust_auth_incoming
.length
= len
;
3315 py_tmp
= PyDict_GetItemString(py_td_info
, "trust_auth_outgoing");
3316 PyBytes_AsStringAndSize(py_tmp
, (char **)&td_info
.trust_auth_outgoing
.data
, &len
);
3317 td_info
.trust_auth_outgoing
.length
= len
;
3319 py_tmp
= PyDict_GetItemString(py_td_info
, "trust_direction");
3320 td_info
.trust_direction
= PyLong_AsLong(py_tmp
);
3322 py_tmp
= PyDict_GetItemString(py_td_info
, "trust_type");
3323 td_info
.trust_type
= PyLong_AsLong(py_tmp
);
3325 py_tmp
= PyDict_GetItemString(py_td_info
, "trust_attributes");
3326 td_info
.trust_attributes
= PyLong_AsLong(py_tmp
);
3328 py_tmp
= PyDict_GetItemString(py_td_info
, "trust_forest_trust_info");
3329 PyBytes_AsStringAndSize(py_tmp
, (char **)&td_info
.trust_forest_trust_info
.data
, &len
);
3330 td_info
.trust_forest_trust_info
.length
= len
;
3332 methods
= pytalloc_get_ptr(self
);
3334 status
= methods
->set_trusted_domain(methods
, domain
, &td_info
);
3335 if (!NT_STATUS_IS_OK(status
)) {
3336 PyErr_Format(py_pdb_error
, "Unable to set trusted domain information, (%d,%s)",
3337 NT_STATUS_V(status
),
3338 get_friendly_nt_error_msg(status
));
3348 static PyObject
*py_pdb_del_trusted_domain(PyObject
*self
, PyObject
*args
)
3350 TALLOC_CTX
*frame
= talloc_stackframe();
3352 struct pdb_methods
*methods
;
3355 if (!PyArg_ParseTuple(args
, "s:del_trusted_domain", &domain
)) {
3360 methods
= pytalloc_get_ptr(self
);
3362 status
= methods
->del_trusted_domain(methods
, domain
);
3363 if (!NT_STATUS_IS_OK(status
)) {
3364 PyErr_Format(py_pdb_error
, "Unable to delete trusted domain, (%d,%s)",
3365 NT_STATUS_V(status
),
3366 get_friendly_nt_error_msg(status
));
3376 static PyObject
*py_pdb_enum_trusted_domains(PyObject
*self
, PyObject
*args
)
3378 TALLOC_CTX
*frame
= talloc_stackframe();
3380 struct pdb_methods
*methods
;
3381 uint32_t i
, num_domains
;
3382 struct pdb_trusted_domain
**td_info
;
3383 PyObject
*py_td_info
, *py_domain_info
;
3385 methods
= pytalloc_get_ptr(self
);
3387 status
= methods
->enum_trusted_domains(methods
, frame
, &num_domains
, &td_info
);
3388 if (!NT_STATUS_IS_OK(status
)) {
3389 PyErr_Format(py_pdb_error
, "Unable to delete trusted domain, (%d,%s)",
3390 NT_STATUS_V(status
),
3391 get_friendly_nt_error_msg(status
));
3396 py_td_info
= PyList_New(0);
3397 if (py_td_info
== NULL
) {
3403 for (i
=0; i
<num_domains
; i
++) {
3405 struct pdb_trusted_domain
*td
= td_info
[i
];
3407 pytalloc_steal(dom_sid_Type
, &td
->security_identifier
);
3409 py_domain_info
= Py_BuildValue(
3411 " s:"PYARG_BYTES_LEN
","
3412 " s:"PYARG_BYTES_LEN
","
3414 " s:"PYARG_BYTES_LEN
"}",
3415 "domain_name", td
->domain_name
,
3416 "netbios_name", td
->netbios_name
,
3417 "security_identifier", py_sid
,
3418 "trust_auth_incoming",
3419 (const char *)td
->trust_auth_incoming
.data
,
3420 td
->trust_auth_incoming
.length
,
3421 "trust_auth_outgoing",
3422 (const char *)td
->trust_auth_outgoing
.data
,
3423 td
->trust_auth_outgoing
.length
,
3424 "trust_direction", td
->trust_direction
,
3425 "trust_type", td
->trust_type
,
3426 "trust_attributes", td
->trust_attributes
,
3427 "trust_forest_trust_info",
3428 (const char *)td
->trust_forest_trust_info
.data
,
3429 td
->trust_forest_trust_info
.length
);
3432 if (py_domain_info
== NULL
) {
3433 Py_CLEAR(py_td_info
);
3436 res
= PyList_Append(py_td_info
, py_domain_info
);
3437 Py_CLEAR(py_domain_info
);
3439 Py_CLEAR(py_td_info
);
3449 static PyObject
*py_pdb_get_secret(PyObject
*self
, PyObject
*args
)
3451 TALLOC_CTX
*frame
= talloc_stackframe();
3453 struct pdb_methods
*methods
;
3454 const char *secret_name
;
3455 DATA_BLOB secret_current
, secret_old
;
3456 NTTIME secret_current_lastchange
, secret_old_lastchange
;
3458 struct security_descriptor
*sd
;
3459 PyObject
*py_secret
;
3461 if (!PyArg_ParseTuple(args
, "s:get_secret_name", &secret_name
)) {
3466 methods
= pytalloc_get_ptr(self
);
3468 py_sd
= pytalloc_new(struct security_descriptor
, security_Type
);
3469 if (py_sd
== NULL
) {
3474 sd
= pytalloc_get_ptr(py_sd
);
3476 status
= methods
->get_secret(methods
, frame
, secret_name
,
3478 &secret_current_lastchange
,
3480 &secret_old_lastchange
,
3482 if (!NT_STATUS_IS_OK(status
)) {
3483 PyErr_Format(py_pdb_error
, "Unable to get information for secret (%s), (%d,%s)",
3485 NT_STATUS_V(status
),
3486 get_friendly_nt_error_msg(status
));
3491 py_secret
= Py_BuildValue(
3492 "{s:"PYARG_BYTES_LEN
","
3494 " s:"PYARG_BYTES_LEN
","
3496 "secret_current", (const char*)secret_current
.data
,
3497 secret_current
.length
,
3498 "secret_current_lastchange", secret_current_lastchange
,
3499 "secret_old", (const char*)secret_old
.data
,
3501 "secret_old_lastchange", secret_old_lastchange
,
3505 if (py_secret
== NULL
) {
3515 static PyObject
*py_pdb_set_secret(PyObject
*self
, PyObject
*args
)
3517 TALLOC_CTX
*frame
= talloc_stackframe();
3519 struct pdb_methods
*methods
;
3520 const char *secret_name
;
3521 PyObject
*py_secret
;
3522 PyObject
*py_secret_cur
, *py_secret_old
, *py_sd
;
3523 DATA_BLOB secret_current
, secret_old
;
3524 struct security_descriptor
*sd
;
3527 if (!PyArg_ParseTuple(args
, "sO!:set_secret_name", &secret_name
, PyDict_Type
, &py_secret
)) {
3532 py_secret_cur
= PyDict_GetItemString(py_secret
, "secret_current");
3533 py_secret_old
= PyDict_GetItemString(py_secret
, "secret_old");
3534 py_sd
= PyDict_GetItemString(py_secret
, "sd");
3536 PY_CHECK_TYPE(&PyBytes_Type
, py_secret_cur
, return NULL
;);
3537 PY_CHECK_TYPE(&PyBytes_Type
, py_secret_old
, return NULL
;);
3538 PY_CHECK_TYPE(security_Type
, py_sd
, return NULL
;);
3540 methods
= pytalloc_get_ptr(self
);
3542 PyBytes_AsStringAndSize(py_secret_cur
, (char **)&secret_current
.data
, &len
);
3543 secret_current
.length
= len
;
3544 PyBytes_AsStringAndSize(py_secret_old
, (char **)&secret_old
.data
, &len
);
3545 secret_current
.length
= len
;
3546 sd
= pytalloc_get_ptr(py_sd
);
3548 status
= methods
->set_secret(methods
, secret_name
, &secret_current
, &secret_old
, sd
);
3549 if (!NT_STATUS_IS_OK(status
)) {
3550 PyErr_Format(py_pdb_error
, "Unable to set information for secret (%s), (%d,%s)",
3552 NT_STATUS_V(status
),
3553 get_friendly_nt_error_msg(status
));
3563 static PyObject
*py_pdb_delete_secret(PyObject
*self
, PyObject
*args
)
3565 TALLOC_CTX
*frame
= talloc_stackframe();
3567 struct pdb_methods
*methods
;
3568 const char *secret_name
;
3570 if (!PyArg_ParseTuple(args
, "s:delete_secret", &secret_name
)) {
3575 methods
= pytalloc_get_ptr(self
);
3577 status
= methods
->delete_secret(methods
, secret_name
);
3578 if (!NT_STATUS_IS_OK(status
)) {
3579 PyErr_Format(py_pdb_error
, "Unable to delete secret (%s), (%d,%s)",
3581 NT_STATUS_V(status
),
3582 get_friendly_nt_error_msg(status
));
3591 static PyMethodDef py_pdb_methods
[] = {
3592 { "domain_info", py_pdb_domain_info
, METH_NOARGS
,
3593 "domain_info() -> str\n\n \
3594 Get domain information for the database." },
3595 { "getsampwnam", py_pdb_getsampwnam
, METH_VARARGS
,
3596 "getsampwnam(username) -> samu object\n\n \
3597 Get user information by name." },
3598 { "getsampwsid", py_pdb_getsampwsid
, METH_VARARGS
,
3599 "getsampwsid(user_sid) -> samu object\n\n \
3600 Get user information by sid (dcerpc.security.dom_sid object)." },
3601 { "create_user", py_pdb_create_user
, METH_VARARGS
,
3602 "create_user(username, acct_flags) -> rid\n\n \
3603 Create user. acct_flags are samr account control flags." },
3604 { "delete_user", py_pdb_delete_user
, METH_VARARGS
,
3605 "delete_user(samu object) -> None\n\n \
3607 { "add_sam_account", py_pdb_add_sam_account
, METH_VARARGS
,
3608 "add_sam_account(samu object) -> None\n\n \
3609 Add SAM account." },
3610 { "update_sam_account", py_pdb_update_sam_account
, METH_VARARGS
,
3611 "update_sam_account(samu object) -> None\n\n \
3612 Update SAM account." },
3613 { "delete_sam_account", py_pdb_delete_sam_account
, METH_VARARGS
,
3614 "delete_sam_account(samu object) -> None\n\n \
3615 Delete SAM account." },
3616 { "rename_sam_account", py_pdb_rename_sam_account
, METH_VARARGS
,
3617 "rename_sam_account(samu object1, new_username) -> None\n\n \
3618 Rename SAM account." },
3619 /* update_login_attempts */
3620 { "getgrsid", py_pdb_getgrsid
, METH_VARARGS
,
3621 "getgrsid(group_sid) -> groupmap object\n\n \
3622 Get group information by sid (dcerpc.security.dom_sid object)." },
3623 { "getgrgid", py_pdb_getgrgid
, METH_VARARGS
,
3624 "getgrsid(gid) -> groupmap object\n\n \
3625 Get group information by gid." },
3626 { "getgrnam", py_pdb_getgrnam
, METH_VARARGS
,
3627 "getgrsid(groupname) -> groupmap object\n\n \
3628 Get group information by name." },
3629 { "create_dom_group", py_pdb_create_dom_group
, METH_VARARGS
,
3630 "create_dom_group(groupname) -> group_rid\n\n \
3631 Create new domain group by name." },
3632 { "delete_dom_group", py_pdb_delete_dom_group
, METH_VARARGS
,
3633 "delete_dom_group(group_rid) -> None\n\n \
3634 Delete domain group identified by rid" },
3635 { "add_group_mapping_entry", py_pdb_add_group_mapping_entry
, METH_VARARGS
,
3636 "add_group_mapping_entry(groupmap) -> None\n \
3637 Add group mapping entry for groupmap object." },
3638 { "update_group_mapping_entry", py_pdb_update_group_mapping_entry
, METH_VARARGS
,
3639 "update_group_mapping_entry(groupmap) -> None\n\n \
3640 Update group mapping entry for groupmap object." },
3641 { "delete_group_mapping_entry", py_pdb_delete_group_mapping_entry
, METH_VARARGS
,
3642 "delete_group_mapping_entry(groupmap) -> None\n\n \
3643 Delete group mapping entry for groupmap object." },
3644 { "enum_group_mapping", py_pdb_enum_group_mapping
, METH_VARARGS
,
3645 "enum_group_mapping([domain_sid, [type, [unix_only]]]) -> List\n\n \
3646 Return list of group mappings as groupmap objects. Optional arguments are domain_sid object, type of group, unix only flag." },
3647 { "enum_group_members", py_pdb_enum_group_members
, METH_VARARGS
,
3648 "enum_group_members(group_sid) -> List\n\n \
3649 Return list of users (dom_sid object) in group." },
3650 { "enum_group_memberships", py_pdb_enum_group_memberships
, METH_VARARGS
,
3651 "enum_group_memberships(samu object) -> List\n\n \
3652 Return list of groups (dom_sid object) this user is part of." },
3653 /* set_unix_primary_group */
3654 { "add_groupmem", py_pdb_add_groupmem
, METH_VARARGS
,
3655 "add_groupmem(group_rid, member_rid) -> None\n\n \
3656 Add user to group." },
3657 { "del_groupmem", py_pdb_del_groupmem
, METH_VARARGS
,
3658 "del_groupmem(group_rid, member_rid) -> None\n\n \
3659 Remove user from from group." },
3660 { "create_alias", py_pdb_create_alias
, METH_VARARGS
,
3661 "create_alias(alias_name) -> alias_rid\n\n \
3662 Create alias entry." },
3663 { "delete_alias", py_pdb_delete_alias
, METH_VARARGS
,
3664 "delete_alias(alias_sid) -> None\n\n \
3665 Delete alias entry." },
3666 { "get_aliasinfo", py_pdb_get_aliasinfo
, METH_VARARGS
,
3667 "get_aliasinfo(alias_sid) -> Mapping\n\n \
3668 Get alias information as a dictionary with keys - acct_name, acct_desc, rid." },
3669 { "set_aliasinfo", py_pdb_set_aliasinfo
, METH_VARARGS
,
3670 "set_alias_info(alias_sid, Mapping) -> None\n\n \
3671 Set alias information from a dictionary with keys - acct_name, acct_desc." },
3672 { "add_aliasmem", py_pdb_add_aliasmem
, METH_VARARGS
,
3673 "add_aliasmem(alias_sid, member_sid) -> None\n\n \
3674 Add user to alias entry." },
3675 { "del_aliasmem", py_pdb_del_aliasmem
, METH_VARARGS
,
3676 "del_aliasmem(alias_sid, member_sid) -> None\n\n \
3677 Remove a user from alias entry." },
3678 { "enum_aliasmem", py_pdb_enum_aliasmem
, METH_VARARGS
,
3679 "enum_aliasmem(alias_sid) -> List\n\n \
3680 Return a list of members (dom_sid object) for alias entry." },
3681 /* enum_alias_memberships */
3684 { "get_account_policy", py_pdb_get_account_policy
, METH_NOARGS
,
3685 "get_account_policy() -> Mapping\n\n \
3686 Get account policy information as a dictionary." },
3687 { "set_account_policy", py_pdb_set_account_policy
, METH_VARARGS
,
3688 "get_account_policy(Mapping) -> None\n\n \
3689 Set account policy settings from a dicionary." },
3691 { "search_users", py_pdb_search_users
, METH_VARARGS
,
3692 "search_users(acct_flags) -> List\n\n \
3693 Search users. acct_flags are samr account control flags.\n \
3694 Each list entry is dictionary with keys - idx, rid, acct_flags, account_name, fullname, description." },
3695 { "search_groups", py_pdb_search_groups
, METH_NOARGS
,
3696 "search_groups() -> List\n\n \
3697 Search unix only groups. \n \
3698 Each list entry is dictionary with keys - idx, rid, acct_flags, account_name, fullname, description." },
3699 { "search_aliases", py_pdb_search_aliases
, METH_VARARGS
,
3700 "search_aliases([domain_sid]) -> List\n\n \
3701 Search aliases. domain_sid is dcerpc.security.dom_sid object.\n \
3702 Each list entry is dictionary with keys - idx, rid, acct_flags, account_name, fullname, description." },
3703 { "uid_to_sid", py_pdb_uid_to_sid
, METH_VARARGS
,
3704 "uid_to_sid(uid) -> sid\n\n \
3705 Return sid for given user id." },
3706 { "gid_to_sid", py_pdb_gid_to_sid
, METH_VARARGS
,
3707 "gid_to_sid(gid) -> sid\n\n \
3708 Return sid for given group id." },
3709 { "sid_to_id", py_pdb_sid_to_id
, METH_VARARGS
,
3710 "sid_to_id(sid) -> Tuple\n\n \
3711 Return id and type for given sid." },
3713 { "new_rid", py_pdb_new_rid
, METH_NOARGS
,
3714 "new_rid() -> rid\n\n \
3716 { "get_trusteddom_pw", py_pdb_get_trusteddom_pw
, METH_VARARGS
,
3717 "get_trusteddom_pw(domain) -> Mapping\n\n \
3718 Get trusted domain password, sid and last set time in a dictionary." },
3719 { "set_trusteddom_pw", py_pdb_set_trusteddom_pw
, METH_VARARGS
,
3720 "set_trusteddom_pw(domain, pwd, sid) -> None\n\n \
3721 Set trusted domain password." },
3722 { "del_trusteddom_pw", py_pdb_del_trusteddom_pw
, METH_VARARGS
,
3723 "del_trusteddom_pw(domain) -> None\n\n \
3724 Delete trusted domain password." },
3725 { "enum_trusteddoms", py_pdb_enum_trusteddoms
, METH_NOARGS
,
3726 "enum_trusteddoms() -> List\n\n \
3727 Get list of trusted domains. Each item is a dictionary with name and sid keys" },
3728 { "get_trusted_domain", py_pdb_get_trusted_domain
, METH_VARARGS
,
3729 "get_trusted_domain(domain) -> Mapping\n\n \
3730 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." },
3731 { "get_trusted_domain_by_sid", py_pdb_get_trusted_domain_by_sid
, METH_VARARGS
,
3732 "get_trusted_domain_by_sid(domain_sid) -> Mapping\n\n \
3733 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" },
3734 { "set_trusted_domain", py_pdb_set_trusted_domain
, METH_VARARGS
,
3735 "set_trusted_domain(domain, Mapping) -> None\n\n \
3736 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." },
3737 { "del_trusted_domain", py_pdb_del_trusted_domain
, METH_VARARGS
,
3738 "del_trusted_domain(domain) -> None\n\n \
3739 Delete trusted domain." },
3740 { "enum_trusted_domains", py_pdb_enum_trusted_domains
, METH_VARARGS
,
3741 "enum_trusted_domains() -> List\n\n \
3742 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." },
3743 { "get_secret", py_pdb_get_secret
, METH_VARARGS
,
3744 "get_secret(secret_name) -> Mapping\n\n \
3745 Get secret information for secret_name. Information is a dictionary with keys - secret_current, secret_current_lastchange, secret_old, secret_old_lastchange, sd." },
3746 { "set_secret", py_pdb_set_secret
, METH_VARARGS
,
3747 "set_secret(secret_name, Mapping) -> None\n\n \
3748 Set secret information for secret_name using dictionary with keys - secret_current, sd." },
3749 { "delete_secret", py_pdb_delete_secret
, METH_VARARGS
,
3750 "delete_secret(secret_name) -> None\n\n \
3751 Delete secret information for secret_name." },
3756 static PyObject
*py_pdb_new(PyTypeObject
*type
, PyObject
*args
, PyObject
*kwargs
)
3758 TALLOC_CTX
*frame
= talloc_stackframe();
3759 const char *url
= NULL
;
3762 struct pdb_methods
*methods
;
3764 if (!PyArg_ParseTuple(args
, "s", &url
)) {
3769 /* Initialize list of methods */
3770 status
= make_pdb_method_name(&methods
, url
);
3771 if (!NT_STATUS_IS_OK(status
)) {
3772 PyErr_Format(py_pdb_error
, "Cannot load backend methods for '%s' backend (%d,%s)",
3774 NT_STATUS_V(status
),
3775 get_friendly_nt_error_msg(status
));
3780 if ((pypdb
= pytalloc_steal(type
, methods
)) == NULL
) {
3791 static PyTypeObject PyPDB
= {
3792 .tp_name
= "passdb.PDB",
3793 .tp_new
= py_pdb_new
,
3794 .tp_flags
= Py_TPFLAGS_DEFAULT
,
3795 .tp_methods
= py_pdb_methods
,
3796 .tp_doc
= "PDB(url[, read_write_flags]) -> Password DB object\n",
3801 * Return a list of passdb backends
3803 static PyObject
*py_passdb_backends(PyObject
*self
, PyObject
*unused
)
3805 TALLOC_CTX
*frame
= talloc_stackframe();
3807 const struct pdb_init_function_entry
*entry
;
3809 entry
= pdb_get_backends();
3814 if((py_blist
= PyList_New(0)) == NULL
) {
3822 PyObject
*entry_name
= PyUnicode_FromString(entry
->name
);
3824 res
= PyList_Append(py_blist
, entry_name
);
3826 Py_CLEAR(entry_name
);
3830 Py_CLEAR(entry_name
);
3835 entry
= entry
->next
;
3843 static PyObject
*py_set_smb_config(PyObject
*self
, PyObject
*args
)
3845 TALLOC_CTX
*frame
= talloc_stackframe();
3846 const char *smb_config
;
3848 if (!PyArg_ParseTuple(args
, "s", &smb_config
)) {
3853 /* Load smbconf parameters */
3854 if (!lp_load_global(smb_config
)) {
3855 PyErr_Format(py_pdb_error
, "Cannot open '%s'", smb_config
);
3865 static PyObject
*py_set_secrets_dir(PyObject
*self
, PyObject
*args
)
3867 TALLOC_CTX
*frame
= talloc_stackframe();
3868 const char *private_dir
;
3870 if (!PyArg_ParseTuple(args
, "s", &private_dir
)) {
3875 /* Initialize secrets database */
3876 if (!secrets_init_path(private_dir
)) {
3877 PyErr_Format(py_pdb_error
, "Cannot open secrets file database in '%s'",
3887 static PyObject
*py_reload_static_pdb(PyObject
*self
, PyObject
*args
)
3889 TALLOC_CTX
*frame
= talloc_stackframe();
3891 /* Initialize secrets database */
3892 if (!initialize_password_db(true, NULL
)) {
3893 PyErr_Format(py_pdb_error
, "Cannot re-open passdb backend %s", lp_passdb_backend());
3902 static PyObject
*py_get_domain_sid(PyObject
*self
, PyObject
*unused
)
3904 TALLOC_CTX
*frame
= talloc_stackframe();
3905 struct dom_sid domain_sid
, *domain_sid_copy
;
3906 PyObject
*py_dom_sid
= Py_None
;
3909 ret
= secrets_fetch_domain_sid(lp_workgroup(), &domain_sid
);
3912 return PyErr_NoMemory();
3915 domain_sid_copy
= dom_sid_dup(frame
, &domain_sid
);
3916 if (domain_sid_copy
== NULL
) {
3918 return PyErr_NoMemory();
3921 py_dom_sid
= pytalloc_steal(dom_sid_Type
, domain_sid_copy
);
3927 static PyObject
*py_get_global_sam_sid(PyObject
*self
, PyObject
*unused
)
3929 TALLOC_CTX
*frame
= talloc_stackframe();
3930 struct dom_sid
*domain_sid
, *domain_sid_copy
;
3931 PyObject
*py_dom_sid
;
3933 domain_sid
= get_global_sam_sid();
3935 domain_sid_copy
= dom_sid_dup(frame
, domain_sid
);
3936 if (domain_sid_copy
== NULL
) {
3942 py_dom_sid
= pytalloc_steal(dom_sid_Type
, domain_sid_copy
);
3949 static PyMethodDef py_passdb_methods
[] = {
3950 { "get_backends", py_passdb_backends
, METH_NOARGS
,
3951 "get_backends() -> list\n\n \
3952 Get a list of password database backends supported." },
3953 { "set_smb_config", py_set_smb_config
, METH_VARARGS
,
3954 "set_smb_config(path) -> None\n\n \
3955 Set path to smb.conf file to load configuration parameters." },
3956 { "set_secrets_dir", py_set_secrets_dir
, METH_VARARGS
,
3957 "set_secrets_dir(private_dir) -> None\n\n \
3958 Set path to private directory to load secrets database from non-default location." },
3959 { "get_global_sam_sid", py_get_global_sam_sid
, METH_NOARGS
,
3960 "get_global_sam_sid() -> dom_sid\n\n \
3961 Return domain SID." },
3962 { "get_domain_sid", py_get_domain_sid
, METH_NOARGS
,
3963 "get_domain_sid() -> dom_sid\n\n \
3964 Return domain SID from secrets database." },
3965 { "reload_static_pdb", py_reload_static_pdb
, METH_NOARGS
,
3966 "reload_static_pdb() -> None\n\n \
3967 Re-initialise the static pdb used internally. Needed if 'passdb backend' is changed." },
3971 static struct PyModuleDef moduledef
= {
3972 PyModuleDef_HEAD_INIT
,
3974 .m_doc
= "SAMBA Password Database",
3976 .m_methods
= py_passdb_methods
,
3979 MODULE_INIT_FUNC(passdb
)
3981 TALLOC_CTX
*frame
= talloc_stackframe();
3982 PyObject
*m
= NULL
, *mod
= NULL
;
3983 char exception_name
[] = "passdb.error";
3985 if (pytalloc_BaseObject_PyType_Ready(&PyPDB
) < 0) {
3990 if (pytalloc_BaseObject_PyType_Ready(&PySamu
) < 0) {
3995 if (pytalloc_BaseObject_PyType_Ready(&PyGroupmap
) < 0) {
4000 m
= PyModule_Create(&moduledef
);
4006 /* Create new exception for passdb module */
4007 py_pdb_error
= PyErr_NewException(exception_name
, NULL
, NULL
);
4008 Py_INCREF(py_pdb_error
);
4009 PyModule_AddObject(m
, "error", py_pdb_error
);
4012 PyModule_AddObject(m
, "PDB", (PyObject
*)&PyPDB
);
4015 PyModule_AddObject(m
, "Samu", (PyObject
*)&PySamu
);
4017 Py_INCREF(&PyGroupmap
);
4018 PyModule_AddObject(m
, "Groupmap", (PyObject
*)&PyGroupmap
);
4020 /* Import dom_sid type from dcerpc.security */
4021 mod
= PyImport_ImportModule("samba.dcerpc.security");
4027 dom_sid_Type
= (PyTypeObject
*)PyObject_GetAttrString(mod
, "dom_sid");
4028 if (dom_sid_Type
== NULL
) {
4034 /* Import security_descriptor type from dcerpc.security */
4035 security_Type
= (PyTypeObject
*)PyObject_GetAttrString(mod
, "descriptor");
4037 if (security_Type
== NULL
) {
4038 Py_DECREF(dom_sid_Type
);
4043 /* Import GUID type from dcerpc.misc */
4044 mod
= PyImport_ImportModule("samba.dcerpc.misc");
4046 Py_DECREF(security_Type
);
4047 Py_DECREF(dom_sid_Type
);
4052 guid_Type
= (PyTypeObject
*)PyObject_GetAttrString(mod
, "GUID");
4054 if (guid_Type
== NULL
) {
4055 Py_DECREF(security_Type
);
4056 Py_DECREF(dom_sid_Type
);