2 Python interface to passdb
4 Copyright (C) Amitay Isaacs 2011
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "lib/util/talloc_stack.h"
24 #include "libcli/security/security.h"
25 #include "librpc/gen_ndr/idmap.h"
29 /* There's no Py_ssize_t in 2.4, apparently */
30 #if PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION < 5
31 typedef int Py_ssize_t
;
32 typedef inquiry lenfunc
;
33 typedef intargfunc ssizeargfunc
;
36 #ifndef Py_RETURN_NONE
37 #define Py_RETURN_NONE return Py_INCREF(Py_None), Py_None
40 #ifndef Py_TYPE /* Py_TYPE is only available on Python > 2.6 */
41 #define Py_TYPE(ob) (((PyObject*)(ob))->ob_type)
45 #define PY_CHECK_TYPE(type, var, fail) \
46 if (!PyObject_TypeCheck(var, type)) {\
47 PyErr_Format(PyExc_TypeError, __location__ ": Expected type '%s' for '%s' of type '%s'", (type)->tp_name, #var, Py_TYPE(var)->tp_name); \
53 static PyTypeObject
*dom_sid_Type
= NULL
;
54 static PyTypeObject
*security_Type
= NULL
;
55 static PyTypeObject
*guid_Type
= NULL
;
57 staticforward PyTypeObject PySamu
;
58 staticforward PyTypeObject PyGroupmap
;
59 staticforward PyTypeObject PyPDB
;
61 static PyObject
*py_pdb_error
;
63 void initpassdb(void);
66 /************************** PIDL Autogeneratd ******************************/
68 static PyObject
*py_samu_get_logon_time(PyObject
*obj
, void *closure
)
70 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
71 PyObject
*py_logon_time
;
73 py_logon_time
= PyInt_FromLong(pdb_get_logon_time(sam_acct
));
77 static int py_samu_set_logon_time(PyObject
*obj
, PyObject
*value
, void *closure
)
79 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
81 PY_CHECK_TYPE(&PyInt_Type
, value
, return -1;);
82 if (!pdb_set_logon_time(sam_acct
, PyInt_AsLong(value
), PDB_CHANGED
)) {
88 static PyObject
*py_samu_get_logoff_time(PyObject
*obj
, void *closure
)
90 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
91 PyObject
*py_logoff_time
;
93 py_logoff_time
= PyInt_FromLong(pdb_get_logoff_time(sam_acct
));
94 return py_logoff_time
;
97 static int py_samu_set_logoff_time(PyObject
*obj
, PyObject
*value
, void *closure
)
99 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
101 PY_CHECK_TYPE(&PyInt_Type
, value
, return -1;);
102 if (!pdb_set_logoff_time(sam_acct
, PyInt_AsLong(value
), PDB_CHANGED
)) {
108 static PyObject
*py_samu_get_kickoff_time(PyObject
*obj
, void *closure
)
110 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
111 PyObject
*py_kickoff_time
;
113 py_kickoff_time
= PyInt_FromLong(pdb_get_kickoff_time(sam_acct
));
114 return py_kickoff_time
;
117 static int py_samu_set_kickoff_time(PyObject
*obj
, PyObject
*value
, void *closure
)
119 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
121 PY_CHECK_TYPE(&PyInt_Type
, value
, return -1;);
122 if (!pdb_set_kickoff_time(sam_acct
, PyInt_AsLong(value
), PDB_CHANGED
)) {
128 static PyObject
*py_samu_get_bad_password_time(PyObject
*obj
, void *closure
)
130 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
131 PyObject
*py_bad_password_time
;
133 py_bad_password_time
= PyInt_FromLong(pdb_get_bad_password_time(sam_acct
));
134 return py_bad_password_time
;
137 static int py_samu_set_bad_password_time(PyObject
*obj
, PyObject
*value
, void *closure
)
139 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
141 PY_CHECK_TYPE(&PyInt_Type
, value
, return -1;);
142 if (!pdb_set_bad_password_time(sam_acct
, PyInt_AsLong(value
), PDB_CHANGED
)) {
148 static PyObject
*py_samu_get_pass_last_set_time(PyObject
*obj
, void *closure
)
150 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
151 PyObject
*py_pass_last_set_time
;
153 py_pass_last_set_time
= PyInt_FromLong(pdb_get_pass_last_set_time(sam_acct
));
154 return py_pass_last_set_time
;
157 static int py_samu_set_pass_last_set_time(PyObject
*obj
, PyObject
*value
, void *closure
)
159 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
161 PY_CHECK_TYPE(&PyInt_Type
, value
, return -1;);
162 if (!pdb_set_pass_last_set_time(sam_acct
, PyInt_AsLong(value
), PDB_CHANGED
)) {
168 static PyObject
*py_samu_get_pass_can_change_time(PyObject
*obj
, void *closure
)
170 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
171 PyObject
*py_pass_can_change_time
;
173 py_pass_can_change_time
= PyInt_FromLong(pdb_get_pass_can_change_time(sam_acct
));
174 return py_pass_can_change_time
;
177 static int py_samu_set_pass_can_change_time(PyObject
*obj
, PyObject
*value
, void *closure
)
179 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
181 PY_CHECK_TYPE(&PyInt_Type
, value
, return -1;);
182 if (!pdb_set_pass_can_change_time(sam_acct
, PyInt_AsLong(value
), PDB_CHANGED
)) {
188 static PyObject
*py_samu_get_pass_must_change_time(PyObject
*obj
, void *closure
)
190 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
191 PyObject
*py_pass_must_change_time
;
193 py_pass_must_change_time
= PyInt_FromLong(pdb_get_pass_must_change_time(sam_acct
));
194 return py_pass_must_change_time
;
197 static int py_samu_set_pass_must_change_time(PyObject
*obj
, PyObject
*value
, void *closure
)
199 PY_CHECK_TYPE(&PyInt_Type
, value
, return -1;);
201 /* TODO: make this not a get/set or give a better exception */
205 static PyObject
*py_samu_get_username(PyObject
*obj
, void *closure
)
207 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
208 PyObject
*py_username
;
209 const char *username
;
211 username
= pdb_get_username(sam_acct
);
212 if (username
== NULL
) {
216 py_username
= PyString_FromString(username
);
220 static int py_samu_set_username(PyObject
*obj
, PyObject
*value
, void *closure
)
222 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
224 PY_CHECK_TYPE(&PyString_Type
, value
, return -1;);
225 if (!pdb_set_username(sam_acct
, PyString_AsString(value
), PDB_CHANGED
)) {
231 static PyObject
*py_samu_get_domain(PyObject
*obj
, void *closure
)
233 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
237 domain
= pdb_get_domain(sam_acct
);
238 if (domain
== NULL
) {
242 py_domain
= PyString_FromString(domain
);
246 static int py_samu_set_domain(PyObject
*obj
, PyObject
*value
, void *closure
)
248 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
250 PY_CHECK_TYPE(&PyString_Type
, value
, return -1;);
251 if (!pdb_set_domain(sam_acct
, PyString_AsString(value
), PDB_CHANGED
)) {
257 static PyObject
*py_samu_get_nt_username(PyObject
*obj
, void *closure
)
259 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
260 PyObject
*py_nt_username
;
261 const char *nt_username
;
263 nt_username
= pdb_get_nt_username(sam_acct
);
264 if (nt_username
== NULL
) {
268 py_nt_username
= PyString_FromString(nt_username
);
269 return py_nt_username
;
272 static int py_samu_set_nt_username(PyObject
*obj
, PyObject
*value
, void *closure
)
274 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
276 PY_CHECK_TYPE(&PyString_Type
, value
, return -1;);
277 if (!pdb_set_nt_username(sam_acct
, PyString_AsString(value
), PDB_CHANGED
)) {
283 static PyObject
*py_samu_get_full_name(PyObject
*obj
, void *closure
)
285 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
286 PyObject
*py_full_name
;
287 const char *full_name
;
289 full_name
= pdb_get_fullname(sam_acct
);
290 if (full_name
== NULL
) {
294 py_full_name
= PyString_FromString(full_name
);
298 static int py_samu_set_full_name(PyObject
*obj
, PyObject
*value
, void *closure
)
300 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
302 PY_CHECK_TYPE(&PyString_Type
, value
, return -1;);
303 if (!pdb_set_fullname(sam_acct
, PyString_AsString(value
), PDB_CHANGED
)) {
309 static PyObject
*py_samu_get_home_dir(PyObject
*obj
, void *closure
)
311 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
312 PyObject
*py_home_dir
;
313 const char *home_dir
;
315 home_dir
= pdb_get_homedir(sam_acct
);
316 if (home_dir
== NULL
) {
320 py_home_dir
= PyString_FromString(home_dir
);
324 static int py_samu_set_home_dir(PyObject
*obj
, PyObject
*value
, void *closure
)
326 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
328 PY_CHECK_TYPE(&PyString_Type
, value
, return -1;);
329 if (!pdb_set_homedir(sam_acct
, PyString_AsString(value
), PDB_CHANGED
)) {
335 static PyObject
*py_samu_get_dir_drive(PyObject
*obj
, void *closure
)
337 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
338 PyObject
*py_dir_drive
;
339 const char *dir_drive
;
341 dir_drive
= pdb_get_dir_drive(sam_acct
);
342 if (dir_drive
== NULL
) {
346 py_dir_drive
= PyString_FromString(dir_drive
);
350 static int py_samu_set_dir_drive(PyObject
*obj
, PyObject
*value
, void *closure
)
352 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
354 PY_CHECK_TYPE(&PyString_Type
, value
, return -1;);
355 if (!pdb_set_dir_drive(sam_acct
, PyString_AsString(value
), PDB_CHANGED
)) {
361 static PyObject
*py_samu_get_logon_script(PyObject
*obj
, void *closure
)
363 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
364 PyObject
*py_logon_script
;
365 const char *logon_script
;
367 logon_script
= pdb_get_logon_script(sam_acct
);
368 if (logon_script
== NULL
) {
372 py_logon_script
= PyString_FromString(logon_script
);
373 return py_logon_script
;
376 static int py_samu_set_logon_script(PyObject
*obj
, PyObject
*value
, void *closure
)
378 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
380 PY_CHECK_TYPE(&PyString_Type
, value
, return -1;);
381 if (!pdb_set_logon_script(sam_acct
, PyString_AsString(value
), PDB_CHANGED
)) {
387 static PyObject
*py_samu_get_profile_path(PyObject
*obj
, void *closure
)
389 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
390 PyObject
*py_profile_path
;
391 const char *profile_path
;
393 profile_path
= pdb_get_profile_path(sam_acct
);
394 if (profile_path
== NULL
) {
398 py_profile_path
= PyString_FromString(profile_path
);
399 return py_profile_path
;
402 static int py_samu_set_profile_path(PyObject
*obj
, PyObject
*value
, void *closure
)
404 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
406 PY_CHECK_TYPE(&PyString_Type
, value
, return -1;);
407 if (!pdb_set_profile_path(sam_acct
, PyString_AsString(value
), PDB_CHANGED
)) {
413 static PyObject
*py_samu_get_acct_desc(PyObject
*obj
, void *closure
)
415 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
416 PyObject
*py_acct_desc
;
417 const char *acct_desc
;
419 acct_desc
= pdb_get_acct_desc(sam_acct
);
420 if (acct_desc
== NULL
) {
424 py_acct_desc
= PyString_FromString(acct_desc
);
428 static int py_samu_set_acct_desc(PyObject
*obj
, PyObject
*value
, void *closure
)
430 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
432 PY_CHECK_TYPE(&PyString_Type
, value
, return -1;);
433 if (!pdb_set_acct_desc(sam_acct
, PyString_AsString(value
), PDB_CHANGED
)) {
439 static PyObject
*py_samu_get_workstations(PyObject
*obj
, void *closure
)
441 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
442 PyObject
*py_workstations
;
443 const char *workstations
;
445 workstations
= pdb_get_workstations(sam_acct
);
446 if (workstations
== NULL
) {
450 py_workstations
= PyString_FromString(workstations
);
451 return py_workstations
;
454 static int py_samu_set_workstations(PyObject
*obj
, PyObject
*value
, void *closure
)
456 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
458 PY_CHECK_TYPE(&PyString_Type
, value
, return -1;);
459 if (!pdb_set_workstations(sam_acct
, PyString_AsString(value
), PDB_CHANGED
)) {
465 static PyObject
*py_samu_get_comment(PyObject
*obj
, void *closure
)
467 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
468 PyObject
*py_comment
;
471 comment
= pdb_get_comment(sam_acct
);
472 if (comment
== NULL
) {
476 py_comment
= PyString_FromString(comment
);
480 static int py_samu_set_comment(PyObject
*obj
, PyObject
*value
, void *closure
)
482 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
484 PY_CHECK_TYPE(&PyString_Type
, value
, return -1;);
485 if (!pdb_set_comment(sam_acct
, PyString_AsString(value
), PDB_CHANGED
)) {
491 static PyObject
*py_samu_get_munged_dial(PyObject
*obj
, void *closure
)
493 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
494 PyObject
*py_munged_dial
;
495 const char *munged_dial
;
497 munged_dial
= pdb_get_munged_dial(sam_acct
);
498 if (munged_dial
== NULL
) {
502 py_munged_dial
= PyString_FromString(munged_dial
);
503 return py_munged_dial
;
506 static int py_samu_set_munged_dial(PyObject
*obj
, PyObject
*value
, void *closure
)
508 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
510 PY_CHECK_TYPE(&PyString_Type
, value
, return -1;);
511 if (!pdb_set_munged_dial(sam_acct
, PyString_AsString(value
), PDB_CHANGED
)) {
517 static PyObject
*py_samu_get_user_sid(PyObject
*obj
, void *closure
)
519 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
520 PyObject
*py_user_sid
;
521 const struct dom_sid
*user_sid
;
522 struct dom_sid
*copy_user_sid
;
525 user_sid
= pdb_get_user_sid(sam_acct
);
526 if(user_sid
== NULL
) {
530 mem_ctx
= talloc_new(NULL
);
531 if (mem_ctx
== NULL
) {
535 copy_user_sid
= dom_sid_dup(mem_ctx
, user_sid
);
536 if (copy_user_sid
== NULL
) {
538 talloc_free(mem_ctx
);
542 py_user_sid
= pytalloc_steal(dom_sid_Type
, copy_user_sid
);
544 talloc_free(mem_ctx
);
549 static int py_samu_set_user_sid(PyObject
*obj
, PyObject
*value
, void *closure
)
551 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
553 PY_CHECK_TYPE(dom_sid_Type
, value
, return -1;);
554 if (!pdb_set_user_sid(sam_acct
, (struct dom_sid
*)pytalloc_get_ptr(value
), PDB_CHANGED
)) {
560 static PyObject
*py_samu_get_group_sid(PyObject
*obj
, void *closure
)
562 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
563 PyObject
*py_group_sid
;
564 const struct dom_sid
*group_sid
;
565 struct dom_sid
*copy_group_sid
;
568 mem_ctx
= talloc_stackframe();
569 if (mem_ctx
== NULL
) {
574 group_sid
= pdb_get_group_sid(sam_acct
);
575 if (group_sid
== NULL
) {
579 copy_group_sid
= dom_sid_dup(mem_ctx
, group_sid
);
580 if (copy_group_sid
== NULL
) {
582 talloc_free(mem_ctx
);
586 py_group_sid
= pytalloc_steal(dom_sid_Type
, copy_group_sid
);
588 talloc_free(mem_ctx
);
593 static int py_samu_set_group_sid(PyObject
*obj
, PyObject
*value
, void *closure
)
595 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
597 PY_CHECK_TYPE(dom_sid_Type
, value
, return -1;);
598 if (!pdb_set_group_sid(sam_acct
, (struct dom_sid
*)pytalloc_get_ptr(value
), PDB_CHANGED
)) {
604 static PyObject
*py_samu_get_lanman_passwd(PyObject
*obj
, void *closure
)
606 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
610 lm_pw
= (const char *)pdb_get_lanman_passwd(sam_acct
);
615 py_lm_pw
= PyString_FromStringAndSize(lm_pw
, LM_HASH_LEN
);
619 static int py_samu_set_lanman_passwd(PyObject
*obj
, PyObject
*value
, void *closure
)
621 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
623 PY_CHECK_TYPE(&PyString_Type
, value
, return -1;);
624 if (!pdb_set_lanman_passwd(sam_acct
, (uint8_t *)PyString_AsString(value
), PDB_CHANGED
)) {
630 static PyObject
*py_samu_get_nt_passwd(PyObject
*obj
, void *closure
)
632 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
636 nt_pw
= (const char *)pdb_get_nt_passwd(sam_acct
);
641 py_nt_pw
= PyString_FromStringAndSize(nt_pw
, NT_HASH_LEN
);
645 static int py_samu_set_nt_passwd(PyObject
*obj
, PyObject
*value
, void *closure
)
647 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
649 if (!pdb_set_nt_passwd(sam_acct
, (uint8_t *)PyString_AsString(value
), PDB_CHANGED
)) {
655 static PyObject
*py_samu_get_pw_history(PyObject
*obj
, void *closure
)
657 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
658 PyObject
*py_nt_pw_his
;
659 const char *nt_pw_his
;
662 nt_pw_his
= (const char *)pdb_get_pw_history(sam_acct
, &hist_len
);
663 if (nt_pw_his
== NULL
) {
667 py_nt_pw_his
= PyString_FromStringAndSize(nt_pw_his
, hist_len
*PW_HISTORY_ENTRY_LEN
);
671 static int py_samu_set_pw_history(PyObject
*obj
, PyObject
*value
, void *closure
)
673 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
678 PyString_AsStringAndSize(value
, &nt_pw_his
, &len
);
679 hist_len
= len
/ PW_HISTORY_ENTRY_LEN
;
680 if (!pdb_set_pw_history(sam_acct
, (uint8_t *)nt_pw_his
, hist_len
, PDB_CHANGED
)) {
686 static PyObject
*py_samu_get_plaintext_passwd(PyObject
*obj
, void *closure
)
688 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
689 PyObject
*py_plaintext_pw
;
690 const char *plaintext_pw
;
692 plaintext_pw
= pdb_get_plaintext_passwd(sam_acct
);
693 if (plaintext_pw
== NULL
) {
697 py_plaintext_pw
= PyString_FromString(plaintext_pw
);
698 return py_plaintext_pw
;
701 static int py_samu_set_plaintext_passwd(PyObject
*obj
, PyObject
*value
, void *closure
)
703 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
705 if (!pdb_set_plaintext_passwd(sam_acct
, PyString_AsString(value
))) {
711 static PyObject
*py_samu_get_acct_ctrl(PyObject
*obj
, void *closure
)
713 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
714 PyObject
*py_acct_ctrl
;
716 py_acct_ctrl
= PyInt_FromLong(pdb_get_acct_ctrl(sam_acct
));
720 static int py_samu_set_acct_ctrl(PyObject
*obj
, PyObject
*value
, void *closure
)
722 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
724 PY_CHECK_TYPE(&PyInt_Type
, value
, return -1;);
725 if (!pdb_set_acct_ctrl(sam_acct
, PyInt_AsLong(value
), PDB_CHANGED
)) {
731 static PyObject
*py_samu_get_logon_divs(PyObject
*obj
, void *closure
)
733 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
734 PyObject
*py_logon_divs
;
736 py_logon_divs
= PyInt_FromLong(pdb_get_logon_divs(sam_acct
));
737 return py_logon_divs
;
740 static int py_samu_set_logon_divs(PyObject
*obj
, PyObject
*value
, void *closure
)
742 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
744 PY_CHECK_TYPE(&PyInt_Type
, value
, return -1;);
745 if (!pdb_set_logon_divs(sam_acct
, PyInt_AsLong(value
), PDB_CHANGED
)) {
751 static PyObject
*py_samu_get_hours_len(PyObject
*obj
, void *closure
)
753 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
754 PyObject
*py_hours_len
;
756 py_hours_len
= PyInt_FromLong(pdb_get_hours_len(sam_acct
));
760 static int py_samu_set_hours_len(PyObject
*obj
, PyObject
*value
, void *closure
)
762 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
764 PY_CHECK_TYPE(&PyInt_Type
, value
, return -1;);
765 if (!pdb_set_hours_len(sam_acct
, PyInt_AsLong(value
), PDB_CHANGED
)) {
771 static PyObject
*py_samu_get_hours(PyObject
*obj
, void *closure
)
773 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
778 hours
= (const char *)pdb_get_hours(sam_acct
);
783 hours_len
= pdb_get_hours_len(sam_acct
);
784 if ((py_hours
= PyList_New(hours_len
)) == NULL
) {
789 for (i
=0; i
<hours_len
; i
++) {
790 PyList_SetItem(py_hours
, i
, PyInt_FromLong(hours
[i
]));
795 static int py_samu_set_hours(PyObject
*obj
, PyObject
*value
, void *closure
)
797 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
803 PY_CHECK_TYPE(&PyList_Type
, value
, return -1;);
805 hours_len
= PyList_GET_SIZE(value
);
807 hours
= talloc_array(pytalloc_get_mem_ctx(obj
), uint8_t, hours_len
);
813 for (i
=0; i
< hours_len
; i
++) {
814 PY_CHECK_TYPE(&PyInt_Type
, PyList_GET_ITEM(value
,i
), return -1;);
815 hours
[i
] = PyInt_AsLong(PyList_GET_ITEM(value
, i
));
818 status
= pdb_set_hours(sam_acct
, hours
, hours_len
, PDB_CHANGED
);
827 static PyObject
*py_samu_get_bad_password_count(PyObject
*obj
, void *closure
)
829 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
830 PyObject
*py_bad_password_count
;
832 py_bad_password_count
= PyInt_FromLong(pdb_get_bad_password_count(sam_acct
));
833 return py_bad_password_count
;
836 static int py_samu_set_bad_password_count(PyObject
*obj
, PyObject
*value
, void *closure
)
838 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
840 PY_CHECK_TYPE(&PyInt_Type
, value
, return -1;);
841 if (!pdb_set_bad_password_count(sam_acct
, PyInt_AsLong(value
), PDB_CHANGED
)) {
847 static PyObject
*py_samu_get_logon_count(PyObject
*obj
, void *closure
)
849 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
850 PyObject
*py_logon_count
;
852 py_logon_count
= PyInt_FromLong(pdb_get_logon_count(sam_acct
));
853 return py_logon_count
;
856 static int py_samu_set_logon_count(PyObject
*obj
, PyObject
*value
, void *closure
)
858 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
860 PY_CHECK_TYPE(&PyInt_Type
, value
, return -1;);
861 if (!pdb_set_logon_count(sam_acct
, PyInt_AsLong(value
), PDB_CHANGED
)) {
867 static PyObject
*py_samu_get_country_code(PyObject
*obj
, void *closure
)
869 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
870 PyObject
*py_country_code
;
872 py_country_code
= PyInt_FromLong(pdb_get_country_code(sam_acct
));
873 return py_country_code
;
876 static int py_samu_set_country_code(PyObject
*obj
, PyObject
*value
, void *closure
)
878 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
880 PY_CHECK_TYPE(&PyInt_Type
, value
, return -1;);
881 if (!pdb_set_country_code(sam_acct
, PyInt_AsLong(value
), PDB_CHANGED
)) {
887 static PyObject
*py_samu_get_code_page(PyObject
*obj
, void *closure
)
889 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
890 PyObject
*py_code_page
;
892 py_code_page
= PyInt_FromLong(pdb_get_code_page(sam_acct
));
896 static int py_samu_set_code_page(PyObject
*obj
, PyObject
*value
, void *closure
)
898 struct samu
*sam_acct
= (struct samu
*)pytalloc_get_ptr(obj
);
900 PY_CHECK_TYPE(&PyInt_Type
, value
, return -1;);
901 if (!pdb_set_code_page(sam_acct
, PyInt_AsLong(value
), PDB_CHANGED
)) {
907 static PyGetSetDef py_samu_getsetters
[] = {
908 { discard_const_p(char, "logon_time"), py_samu_get_logon_time
, py_samu_set_logon_time
},
909 { discard_const_p(char, "logoff_time"), py_samu_get_logoff_time
, py_samu_set_logoff_time
},
910 { discard_const_p(char, "kickoff_time"), py_samu_get_kickoff_time
, py_samu_set_kickoff_time
},
911 { discard_const_p(char, "bad_password_time"), py_samu_get_bad_password_time
, py_samu_set_bad_password_time
},
912 { discard_const_p(char, "pass_last_set_time"), py_samu_get_pass_last_set_time
, py_samu_set_pass_last_set_time
},
913 { discard_const_p(char, "pass_can_change_time"), py_samu_get_pass_can_change_time
, py_samu_set_pass_can_change_time
},
914 { discard_const_p(char, "pass_must_change_time"), py_samu_get_pass_must_change_time
, py_samu_set_pass_must_change_time
},
915 { discard_const_p(char, "username"), py_samu_get_username
, py_samu_set_username
},
916 { discard_const_p(char, "domain"), py_samu_get_domain
, py_samu_set_domain
},
917 { discard_const_p(char, "nt_username"), py_samu_get_nt_username
, py_samu_set_nt_username
},
918 { discard_const_p(char, "full_name"), py_samu_get_full_name
, py_samu_set_full_name
},
919 { discard_const_p(char, "home_dir"), py_samu_get_home_dir
, py_samu_set_home_dir
},
920 { discard_const_p(char, "dir_drive"), py_samu_get_dir_drive
, py_samu_set_dir_drive
},
921 { discard_const_p(char, "logon_script"), py_samu_get_logon_script
, py_samu_set_logon_script
},
922 { discard_const_p(char, "profile_path"), py_samu_get_profile_path
, py_samu_set_profile_path
},
923 { discard_const_p(char, "acct_desc"), py_samu_get_acct_desc
, py_samu_set_acct_desc
},
924 { discard_const_p(char, "workstations"), py_samu_get_workstations
, py_samu_set_workstations
},
925 { discard_const_p(char, "comment"), py_samu_get_comment
, py_samu_set_comment
},
926 { discard_const_p(char, "munged_dial"), py_samu_get_munged_dial
, py_samu_set_munged_dial
},
927 { discard_const_p(char, "user_sid"), py_samu_get_user_sid
, py_samu_set_user_sid
},
928 { discard_const_p(char, "group_sid"), py_samu_get_group_sid
, py_samu_set_group_sid
},
929 { discard_const_p(char, "lanman_passwd"), py_samu_get_lanman_passwd
, py_samu_set_lanman_passwd
},
930 { discard_const_p(char, "nt_passwd"), py_samu_get_nt_passwd
, py_samu_set_nt_passwd
},
931 { discard_const_p(char, "pw_history"), py_samu_get_pw_history
, py_samu_set_pw_history
},
932 { discard_const_p(char, "plaintext_passwd"), py_samu_get_plaintext_passwd
, py_samu_set_plaintext_passwd
},
933 { discard_const_p(char, "acct_ctrl"), py_samu_get_acct_ctrl
, py_samu_set_acct_ctrl
},
934 { discard_const_p(char, "logon_divs"), py_samu_get_logon_divs
, py_samu_set_logon_divs
},
935 { discard_const_p(char, "hours_len"), py_samu_get_hours_len
, py_samu_set_hours_len
},
936 { discard_const_p(char, "hours"), py_samu_get_hours
, py_samu_set_hours
},
937 { discard_const_p(char, "bad_password_count"), py_samu_get_bad_password_count
, py_samu_set_bad_password_count
},
938 { discard_const_p(char, "logon_count"), py_samu_get_logon_count
, py_samu_set_logon_count
},
939 { discard_const_p(char, "country_code"), py_samu_get_country_code
, py_samu_set_country_code
},
940 { discard_const_p(char, "code_page"), py_samu_get_code_page
, py_samu_set_code_page
},
945 /************************** PIDL Autogeneratd ******************************/
947 static PyObject
*py_samu_new(PyTypeObject
*type
, PyObject
*args
, PyObject
*kwargs
)
949 struct samu
*sam_acct
;
951 sam_acct
= samu_new(NULL
);
957 return pytalloc_steal(type
, sam_acct
);
960 static PyTypeObject PySamu
= {
961 .tp_name
= "passdb.Samu",
962 .tp_basicsize
= sizeof(pytalloc_Object
),
963 .tp_getset
= py_samu_getsetters
,
965 .tp_new
= py_samu_new
,
966 .tp_flags
= Py_TPFLAGS_DEFAULT
| Py_TPFLAGS_BASETYPE
,
967 .tp_doc
= "Samu() -> samu object\n",
971 static PyObject
*py_groupmap_get_gid(PyObject
*obj
, void *closure
)
973 GROUP_MAP
*group_map
= (GROUP_MAP
*)pytalloc_get_ptr(obj
);
976 py_gid
= Py_BuildValue("i", group_map
->gid
);
980 static int py_groupmap_set_gid(PyObject
*obj
, PyObject
*value
, void *closure
)
982 GROUP_MAP
*group_map
= (GROUP_MAP
*)pytalloc_get_ptr(obj
);
984 PY_CHECK_TYPE(&PyInt_Type
, value
, return -1;);
985 group_map
->gid
= PyInt_AsLong(value
);
989 static PyObject
*py_groupmap_get_sid(PyObject
*obj
, void *closure
)
991 GROUP_MAP
*group_map
= (GROUP_MAP
*)pytalloc_get_ptr(obj
);
993 struct dom_sid
*group_sid
;
996 mem_ctx
= talloc_new(NULL
);
997 if (mem_ctx
== NULL
) {
1002 group_sid
= dom_sid_dup(mem_ctx
, &group_map
->sid
);
1003 if (group_sid
== NULL
) {
1005 talloc_free(mem_ctx
);
1009 py_sid
= pytalloc_steal(dom_sid_Type
, group_sid
);
1011 talloc_free(mem_ctx
);
1016 static int py_groupmap_set_sid(PyObject
*obj
, PyObject
*value
, void *closure
)
1018 GROUP_MAP
*group_map
= (GROUP_MAP
*)pytalloc_get_ptr(obj
);
1020 PY_CHECK_TYPE(dom_sid_Type
, value
, return -1;);
1021 group_map
->sid
= *pytalloc_get_type(value
, struct dom_sid
);
1025 static PyObject
*py_groupmap_get_sid_name_use(PyObject
*obj
, void *closure
)
1027 GROUP_MAP
*group_map
= (GROUP_MAP
*)pytalloc_get_ptr(obj
);
1028 PyObject
*py_sid_name_use
;
1030 py_sid_name_use
= PyInt_FromLong(group_map
->sid_name_use
);
1031 return py_sid_name_use
;
1034 static int py_groupmap_set_sid_name_use(PyObject
*obj
, PyObject
*value
, void *closure
)
1036 GROUP_MAP
*group_map
= (GROUP_MAP
*)pytalloc_get_ptr(obj
);
1038 PY_CHECK_TYPE(&PyInt_Type
, value
, return -1;);
1039 group_map
->sid_name_use
= PyInt_AsLong(value
);
1043 static PyObject
*py_groupmap_get_nt_name(PyObject
*obj
, void *closure
)
1045 GROUP_MAP
*group_map
= (GROUP_MAP
*)pytalloc_get_ptr(obj
);
1046 PyObject
*py_nt_name
;
1047 if (group_map
->nt_name
== NULL
) {
1048 py_nt_name
= Py_None
;
1049 Py_INCREF(py_nt_name
);
1051 py_nt_name
= PyString_FromString(group_map
->nt_name
);
1056 static int py_groupmap_set_nt_name(PyObject
*obj
, PyObject
*value
, void *closure
)
1058 GROUP_MAP
*group_map
= (GROUP_MAP
*)pytalloc_get_ptr(obj
);
1060 PY_CHECK_TYPE(&PyString_Type
, value
, return -1;);
1061 if (value
== Py_None
) {
1062 fstrcpy(group_map
->nt_name
, NULL
);
1064 fstrcpy(group_map
->nt_name
, PyString_AsString(value
));
1069 static PyObject
*py_groupmap_get_comment(PyObject
*obj
, void *closure
)
1071 GROUP_MAP
*group_map
= (GROUP_MAP
*)pytalloc_get_ptr(obj
);
1072 PyObject
*py_comment
;
1073 if (group_map
->comment
== NULL
) {
1074 py_comment
= Py_None
;
1075 Py_INCREF(py_comment
);
1077 py_comment
= PyString_FromString(group_map
->comment
);
1082 static int py_groupmap_set_comment(PyObject
*obj
, PyObject
*value
, void *closure
)
1084 GROUP_MAP
*group_map
= (GROUP_MAP
*)pytalloc_get_ptr(obj
);
1086 PY_CHECK_TYPE(&PyString_Type
, value
, return -1;);
1087 if (value
== Py_None
) {
1088 fstrcpy(group_map
->comment
, NULL
);
1090 fstrcpy(group_map
->comment
, PyString_AsString(value
));
1095 static PyGetSetDef py_groupmap_getsetters
[] = {
1096 { discard_const_p(char, "gid"), py_groupmap_get_gid
, py_groupmap_set_gid
},
1097 { discard_const_p(char, "sid"), py_groupmap_get_sid
, py_groupmap_set_sid
},
1098 { discard_const_p(char, "sid_name_use"), py_groupmap_get_sid_name_use
, py_groupmap_set_sid_name_use
},
1099 { discard_const_p(char, "nt_name"), py_groupmap_get_nt_name
, py_groupmap_set_nt_name
},
1100 { discard_const_p(char, "comment"), py_groupmap_get_comment
, py_groupmap_set_comment
},
1104 static PyObject
*py_groupmap_new(PyTypeObject
*type
, PyObject
*args
, PyObject
*kwargs
)
1106 GROUP_MAP
*group_map
;
1107 TALLOC_CTX
*mem_ctx
;
1108 PyObject
*py_group_map
;
1110 mem_ctx
= talloc_new(NULL
);
1111 if (mem_ctx
== NULL
) {
1116 group_map
= talloc_zero(mem_ctx
, GROUP_MAP
);
1117 if (group_map
== NULL
) {
1119 talloc_free(mem_ctx
);
1123 py_group_map
= pytalloc_steal(type
, group_map
);
1124 if (py_group_map
== NULL
) {
1126 talloc_free(mem_ctx
);
1130 talloc_free(mem_ctx
);
1132 return py_group_map
;
1136 static PyTypeObject PyGroupmap
= {
1137 .tp_name
= "passdb.Groupmap",
1138 .tp_basicsize
= sizeof(pytalloc_Object
),
1139 .tp_getset
= py_groupmap_getsetters
,
1141 .tp_new
= py_groupmap_new
,
1142 .tp_flags
= Py_TPFLAGS_DEFAULT
| Py_TPFLAGS_BASETYPE
,
1143 .tp_doc
= "Groupmap() -> group map object\n",
1147 static PyObject
*py_pdb_domain_info(pytalloc_Object
*self
, PyObject
*args
)
1149 struct pdb_methods
*methods
;
1150 struct pdb_domain_info
*domain_info
;
1151 PyObject
*py_domain_info
;
1153 struct dom_sid
*sid
;
1156 methods
= pytalloc_get_ptr(self
);
1158 if ((tframe
= talloc_stackframe()) == NULL
) {
1163 domain_info
= methods
->get_domain_info(methods
, tframe
);
1164 if (! domain_info
) {
1168 sid
= dom_sid_dup(tframe
, &domain_info
->sid
);
1171 talloc_free(tframe
);
1175 guid
= talloc(tframe
, struct GUID
);
1178 talloc_free(tframe
);
1181 *guid
= domain_info
->guid
;
1183 if ((py_domain_info
= PyDict_New()) == NULL
) {
1188 PyDict_SetItemString(py_domain_info
, "name", PyString_FromString(domain_info
->name
));
1189 PyDict_SetItemString(py_domain_info
, "dns_domain", PyString_FromString(domain_info
->name
));
1190 PyDict_SetItemString(py_domain_info
, "dns_forest", PyString_FromString(domain_info
->name
));
1191 PyDict_SetItemString(py_domain_info
, "dom_sid", pytalloc_steal(dom_sid_Type
, sid
));
1192 PyDict_SetItemString(py_domain_info
, "guid", pytalloc_steal(guid_Type
, guid
));
1194 talloc_free(tframe
);
1196 return py_domain_info
;
1200 static PyObject
*py_pdb_getsampwnam(pytalloc_Object
*self
, PyObject
*args
)
1203 const char *username
;
1204 struct pdb_methods
*methods
;
1205 struct samu
*sam_acct
;
1206 PyObject
*py_sam_acct
;
1209 if (!PyArg_ParseTuple(args
, "s:getsampwnam", &username
)) {
1213 methods
= pytalloc_get_ptr(self
);
1215 if ((tframe
= talloc_stackframe()) == NULL
) {
1220 py_sam_acct
= py_samu_new(&PySamu
, NULL
, NULL
);
1221 if (py_sam_acct
== NULL
) {
1223 talloc_free(tframe
);
1226 sam_acct
= (struct samu
*)pytalloc_get_ptr(py_sam_acct
);
1228 status
= methods
->getsampwnam(methods
, sam_acct
, username
);
1229 if (!NT_STATUS_IS_OK(status
)) {
1230 PyErr_Format(py_pdb_error
, "Unable to get user information for '%s', (%d,%s)",
1232 NT_STATUS_V(status
),
1233 get_friendly_nt_error_msg(status
));
1234 Py_DECREF(py_sam_acct
);
1235 talloc_free(tframe
);
1239 talloc_free(tframe
);
1243 static PyObject
*py_pdb_getsampwsid(pytalloc_Object
*self
, PyObject
*args
)
1246 struct pdb_methods
*methods
;
1247 struct samu
*sam_acct
;
1248 PyObject
*py_sam_acct
;
1250 PyObject
*py_user_sid
;
1252 if (!PyArg_ParseTuple(args
, "O:getsampwsid", &py_user_sid
)) {
1256 methods
= pytalloc_get_ptr(self
);
1258 if ((tframe
= talloc_stackframe()) == NULL
) {
1263 py_sam_acct
= py_samu_new(&PySamu
, NULL
, NULL
);
1264 if (py_sam_acct
== NULL
) {
1266 talloc_free(tframe
);
1269 sam_acct
= (struct samu
*)pytalloc_get_ptr(py_sam_acct
);
1271 status
= methods
->getsampwsid(methods
, sam_acct
, pytalloc_get_ptr(py_user_sid
));
1272 if (!NT_STATUS_IS_OK(status
)) {
1273 PyErr_Format(py_pdb_error
, "Unable to get user information from SID, (%d,%s)",
1274 NT_STATUS_V(status
),
1275 get_friendly_nt_error_msg(status
));
1276 Py_DECREF(py_sam_acct
);
1277 talloc_free(tframe
);
1281 talloc_free(tframe
);
1285 static PyObject
*py_pdb_create_user(pytalloc_Object
*self
, PyObject
*args
)
1288 struct pdb_methods
*methods
;
1289 const char *username
;
1290 unsigned int acct_flags
;
1294 if (!PyArg_ParseTuple(args
, "sI:create_user", &username
, &acct_flags
)) {
1298 methods
= pytalloc_get_ptr(self
);
1300 if ((tframe
= talloc_stackframe()) == NULL
) {
1305 status
= methods
->create_user(methods
, tframe
, username
, acct_flags
, &rid
);
1306 if (!NT_STATUS_IS_OK(status
)) {
1307 PyErr_Format(py_pdb_error
, "Unable to create user (%s), (%d,%s)",
1309 NT_STATUS_V(status
),
1310 get_friendly_nt_error_msg(status
));
1311 talloc_free(tframe
);
1315 talloc_free(tframe
);
1316 return PyInt_FromLong(rid
);
1319 static PyObject
*py_pdb_delete_user(pytalloc_Object
*self
, PyObject
*args
)
1322 struct pdb_methods
*methods
;
1324 struct samu
*sam_acct
;
1325 PyObject
*py_sam_acct
;
1327 if (!PyArg_ParseTuple(args
, "O!:delete_user", &PySamu
, &py_sam_acct
)) {
1331 methods
= pytalloc_get_ptr(self
);
1333 if ((tframe
= talloc_stackframe()) == NULL
) {
1338 sam_acct
= pytalloc_get_ptr(py_sam_acct
);
1340 status
= methods
->delete_user(methods
, tframe
, sam_acct
);
1341 if (!NT_STATUS_IS_OK(status
)) {
1342 PyErr_Format(py_pdb_error
, "Unable to delete user, (%d,%s)",
1343 NT_STATUS_V(status
),
1344 get_friendly_nt_error_msg(status
));
1345 talloc_free(tframe
);
1349 talloc_free(tframe
);
1353 static PyObject
*py_pdb_add_sam_account(pytalloc_Object
*self
, PyObject
*args
)
1356 struct pdb_methods
*methods
;
1358 struct samu
*sam_acct
;
1359 PyObject
*py_sam_acct
;
1361 if (!PyArg_ParseTuple(args
, "O!:add_sam_account", &PySamu
, &py_sam_acct
)) {
1365 methods
= pytalloc_get_ptr(self
);
1367 if ((tframe
= talloc_stackframe()) == NULL
) {
1372 sam_acct
= pytalloc_get_ptr(py_sam_acct
);
1374 status
= methods
->add_sam_account(methods
, sam_acct
);
1375 if (!NT_STATUS_IS_OK(status
)) {
1376 PyErr_Format(py_pdb_error
, "Unable to add sam account '%s', (%d,%s)",
1378 NT_STATUS_V(status
),
1379 get_friendly_nt_error_msg(status
));
1380 talloc_free(tframe
);
1384 talloc_free(tframe
);
1388 static PyObject
*py_pdb_update_sam_account(pytalloc_Object
*self
, PyObject
*args
)
1391 struct pdb_methods
*methods
;
1393 struct samu
*sam_acct
;
1394 PyObject
*py_sam_acct
;
1396 if (!PyArg_ParseTuple(args
, "O!:update_sam_account", &PySamu
, &py_sam_acct
)) {
1400 methods
= pytalloc_get_ptr(self
);
1402 if ((tframe
= talloc_stackframe()) == NULL
) {
1407 sam_acct
= pytalloc_get_ptr(py_sam_acct
);
1409 status
= methods
->update_sam_account(methods
, sam_acct
);
1410 if (!NT_STATUS_IS_OK(status
)) {
1411 PyErr_Format(py_pdb_error
, "Unable to update sam account, (%d,%s)",
1412 NT_STATUS_V(status
),
1413 get_friendly_nt_error_msg(status
));
1414 talloc_free(tframe
);
1418 talloc_free(tframe
);
1422 static PyObject
*py_pdb_delete_sam_account(pytalloc_Object
*self
, PyObject
*args
)
1425 struct pdb_methods
*methods
;
1427 struct samu
*sam_acct
;
1428 PyObject
*py_sam_acct
;
1430 if (!PyArg_ParseTuple(args
, "O!:delete_sam_account", &PySamu
, &py_sam_acct
)) {
1434 methods
= pytalloc_get_ptr(self
);
1436 if ((tframe
= talloc_stackframe()) == NULL
) {
1441 sam_acct
= pytalloc_get_ptr(py_sam_acct
);
1443 status
= methods
->delete_sam_account(methods
, sam_acct
);
1444 if (!NT_STATUS_IS_OK(status
)) {
1445 PyErr_Format(py_pdb_error
, "Unable to delete sam account, (%d,%s)",
1446 NT_STATUS_V(status
),
1447 get_friendly_nt_error_msg(status
));
1448 talloc_free(tframe
);
1452 talloc_free(tframe
);
1456 static PyObject
*py_pdb_rename_sam_account(pytalloc_Object
*self
, PyObject
*args
)
1459 struct pdb_methods
*methods
;
1461 struct samu
*sam_acct
;
1462 const char *new_username
;
1463 PyObject
*py_sam_acct
;
1465 if (!PyArg_ParseTuple(args
, "O!s:rename_sam_account", &PySamu
, &py_sam_acct
,
1470 methods
= pytalloc_get_ptr(self
);
1472 if ((tframe
= talloc_stackframe()) == NULL
) {
1477 sam_acct
= pytalloc_get_ptr(py_sam_acct
);
1479 status
= methods
->rename_sam_account(methods
, sam_acct
, new_username
);
1480 if (!NT_STATUS_IS_OK(status
)) {
1481 PyErr_Format(py_pdb_error
, "Unable to rename sam account, (%d,%s)",
1482 NT_STATUS_V(status
),
1483 get_friendly_nt_error_msg(status
));
1484 talloc_free(tframe
);
1488 talloc_free(tframe
);
1493 static PyObject
*py_pdb_getgrsid(pytalloc_Object
*self
, PyObject
*args
)
1496 struct pdb_methods
*methods
;
1498 GROUP_MAP
*group_map
;
1499 struct dom_sid
*domain_sid
;
1500 PyObject
*py_domain_sid
, *py_group_map
;
1502 if (!PyArg_ParseTuple(args
, "O!:getgrsid", dom_sid_Type
, &py_domain_sid
)) {
1506 methods
= pytalloc_get_ptr(self
);
1508 if ((tframe
= talloc_stackframe()) == NULL
) {
1513 domain_sid
= pytalloc_get_ptr(py_domain_sid
);
1515 py_group_map
= py_groupmap_new(&PyGroupmap
, NULL
, NULL
);
1516 if (py_group_map
== NULL
) {
1518 talloc_free(tframe
);
1522 group_map
= pytalloc_get_ptr(py_group_map
);
1524 status
= methods
->getgrsid(methods
, group_map
, *domain_sid
);
1525 if (!NT_STATUS_IS_OK(status
)) {
1526 PyErr_Format(py_pdb_error
, "Unable to get group information by sid, (%d,%s)",
1527 NT_STATUS_V(status
),
1528 get_friendly_nt_error_msg(status
));
1529 talloc_free(tframe
);
1533 talloc_free(tframe
);
1534 return py_group_map
;
1538 static PyObject
*py_pdb_getgrgid(pytalloc_Object
*self
, PyObject
*args
)
1541 struct pdb_methods
*methods
;
1543 GROUP_MAP
*group_map
;
1544 PyObject
*py_group_map
;
1545 unsigned int gid_value
;
1547 if (!PyArg_ParseTuple(args
, "I:getgrgid", &gid_value
)) {
1551 methods
= pytalloc_get_ptr(self
);
1553 if ((tframe
= talloc_stackframe()) == NULL
) {
1558 py_group_map
= py_groupmap_new(&PyGroupmap
, NULL
, NULL
);
1559 if (py_group_map
== NULL
) {
1561 talloc_free(tframe
);
1565 group_map
= pytalloc_get_ptr(py_group_map
);
1567 status
= methods
->getgrgid(methods
, group_map
, gid_value
);
1568 if (!NT_STATUS_IS_OK(status
)) {
1569 PyErr_Format(py_pdb_error
, "Unable to get group information by gid, (%d,%s)",
1570 NT_STATUS_V(status
),
1571 get_friendly_nt_error_msg(status
));
1572 talloc_free(tframe
);
1576 talloc_free(tframe
);
1577 return py_group_map
;
1581 static PyObject
*py_pdb_getgrnam(pytalloc_Object
*self
, PyObject
*args
)
1584 struct pdb_methods
*methods
;
1586 GROUP_MAP
*group_map
;
1587 PyObject
*py_group_map
;
1588 const char *groupname
;
1590 if (!PyArg_ParseTuple(args
, "s:getgrnam", &groupname
)) {
1594 methods
= pytalloc_get_ptr(self
);
1596 if ((tframe
= talloc_stackframe()) == NULL
) {
1601 py_group_map
= py_groupmap_new(&PyGroupmap
, NULL
, NULL
);
1602 if (py_group_map
== NULL
) {
1604 talloc_free(tframe
);
1608 group_map
= pytalloc_get_ptr(py_group_map
);
1610 status
= methods
->getgrnam(methods
, group_map
, groupname
);
1611 if (!NT_STATUS_IS_OK(status
)) {
1612 PyErr_Format(py_pdb_error
, "Unable to get group information by name, (%d,%s)",
1613 NT_STATUS_V(status
),
1614 get_friendly_nt_error_msg(status
));
1615 talloc_free(tframe
);
1619 talloc_free(tframe
);
1620 return py_group_map
;
1624 static PyObject
*py_pdb_create_dom_group(pytalloc_Object
*self
, PyObject
*args
)
1627 struct pdb_methods
*methods
;
1629 const char *groupname
;
1632 if (!PyArg_ParseTuple(args
, "s:create_dom_group", &groupname
)) {
1636 methods
= pytalloc_get_ptr(self
);
1638 if ((tframe
= talloc_stackframe()) == NULL
) {
1643 status
= methods
->create_dom_group(methods
, tframe
, groupname
, &group_rid
);
1644 if (!NT_STATUS_IS_OK(status
)) {
1645 PyErr_Format(py_pdb_error
, "Unable to create domain group (%s), (%d,%s)",
1647 NT_STATUS_V(status
),
1648 get_friendly_nt_error_msg(status
));
1649 talloc_free(tframe
);
1653 talloc_free(tframe
);
1654 return PyInt_FromLong(group_rid
);
1658 static PyObject
*py_pdb_delete_dom_group(pytalloc_Object
*self
, PyObject
*args
)
1661 struct pdb_methods
*methods
;
1663 unsigned int group_rid
;
1665 if (!PyArg_ParseTuple(args
, "I:delete_dom_group", &group_rid
)) {
1669 methods
= pytalloc_get_ptr(self
);
1671 if ((tframe
= talloc_stackframe()) == NULL
) {
1676 status
= methods
->delete_dom_group(methods
, tframe
, group_rid
);
1677 if (!NT_STATUS_IS_OK(status
)) {
1678 PyErr_Format(py_pdb_error
, "Unable to delete domain group (rid=%d), (%d,%s)",
1680 NT_STATUS_V(status
),
1681 get_friendly_nt_error_msg(status
));
1682 talloc_free(tframe
);
1686 talloc_free(tframe
);
1691 static PyObject
*py_pdb_add_group_mapping_entry(pytalloc_Object
*self
, PyObject
*args
)
1694 struct pdb_methods
*methods
;
1696 PyObject
*py_group_map
;
1697 GROUP_MAP
*group_map
;
1699 if (!PyArg_ParseTuple(args
, "O!:add_group_mapping_entry", &PyGroupmap
, &py_group_map
)) {
1703 methods
= pytalloc_get_ptr(self
);
1705 if ((tframe
= talloc_stackframe()) == NULL
) {
1710 group_map
= pytalloc_get_ptr(py_group_map
);
1712 status
= methods
->add_group_mapping_entry(methods
, group_map
);
1713 if (!NT_STATUS_IS_OK(status
)) {
1714 PyErr_Format(py_pdb_error
, "Unable to add group mapping entry, (%d,%s)",
1715 NT_STATUS_V(status
),
1716 get_friendly_nt_error_msg(status
));
1717 talloc_free(tframe
);
1721 talloc_free(tframe
);
1726 static PyObject
*py_pdb_update_group_mapping_entry(pytalloc_Object
*self
, PyObject
*args
)
1729 struct pdb_methods
*methods
;
1731 PyObject
*py_group_map
;
1732 GROUP_MAP
*group_map
;
1734 if (!PyArg_ParseTuple(args
, "O!:update_group_mapping_entry", &PyGroupmap
, &py_group_map
)) {
1738 methods
= pytalloc_get_ptr(self
);
1740 if ((tframe
= talloc_stackframe()) == NULL
) {
1745 group_map
= pytalloc_get_ptr(py_group_map
);
1747 status
= methods
->update_group_mapping_entry(methods
, group_map
);
1748 if (!NT_STATUS_IS_OK(status
)) {
1749 PyErr_Format(py_pdb_error
, "Unable to update group mapping entry, (%d,%s)",
1750 NT_STATUS_V(status
),
1751 get_friendly_nt_error_msg(status
));
1752 talloc_free(tframe
);
1756 talloc_free(tframe
);
1761 static PyObject
*py_pdb_delete_group_mapping_entry(pytalloc_Object
*self
, PyObject
*args
)
1764 struct pdb_methods
*methods
;
1766 PyObject
*py_group_sid
;
1767 struct dom_sid
*group_sid
;
1769 if (!PyArg_ParseTuple(args
, "O!:delete_group_mapping_entry", dom_sid_Type
, &py_group_sid
)) {
1773 methods
= pytalloc_get_ptr(self
);
1775 if ((tframe
= talloc_stackframe()) == NULL
) {
1780 group_sid
= pytalloc_get_ptr(py_group_sid
);
1782 status
= methods
->delete_group_mapping_entry(methods
, *group_sid
);
1783 if (!NT_STATUS_IS_OK(status
)) {
1784 PyErr_Format(py_pdb_error
, "Unable to delete group mapping entry, (%d,%s)",
1785 NT_STATUS_V(status
),
1786 get_friendly_nt_error_msg(status
));
1787 talloc_free(tframe
);
1791 talloc_free(tframe
);
1796 static PyObject
*py_pdb_enum_group_mapping(pytalloc_Object
*self
, PyObject
*args
)
1799 struct pdb_methods
*methods
;
1801 enum lsa_SidType sid_name_use
;
1802 int lsa_sidtype_value
= SID_NAME_UNKNOWN
;
1804 PyObject
*py_domain_sid
;
1805 struct dom_sid
*domain_sid
= NULL
;
1806 GROUP_MAP
**gmap
= NULL
;
1807 GROUP_MAP
*group_map
;
1809 PyObject
*py_gmap_list
, *py_group_map
;
1812 py_domain_sid
= Py_None
;
1815 if (!PyArg_ParseTuple(args
, "|O!ii:enum_group_mapping", dom_sid_Type
, &py_domain_sid
,
1816 &lsa_sidtype_value
, &unix_only
)) {
1820 methods
= pytalloc_get_ptr(self
);
1822 if ((tframe
= talloc_stackframe()) == NULL
) {
1827 sid_name_use
= lsa_sidtype_value
;
1829 if (py_domain_sid
!= Py_None
) {
1830 domain_sid
= pytalloc_get_ptr(py_domain_sid
);
1833 status
= methods
->enum_group_mapping(methods
, domain_sid
, sid_name_use
,
1834 &gmap
, &num_entries
, unix_only
);
1835 if (!NT_STATUS_IS_OK(status
)) {
1836 PyErr_Format(py_pdb_error
, "Unable to enumerate group mappings, (%d,%s)",
1837 NT_STATUS_V(status
),
1838 get_friendly_nt_error_msg(status
));
1839 talloc_free(tframe
);
1843 py_gmap_list
= PyList_New(0);
1844 if (py_gmap_list
== NULL
) {
1846 talloc_free(tframe
);
1850 for(i
=0; i
<num_entries
; i
++) {
1851 py_group_map
= py_groupmap_new(&PyGroupmap
, NULL
, NULL
);
1853 group_map
= pytalloc_get_ptr(py_group_map
);
1854 *group_map
= *gmap
[i
];
1855 talloc_steal(group_map
, gmap
[i
]->nt_name
);
1856 talloc_steal(group_map
, gmap
[i
]->comment
);
1858 PyList_Append(py_gmap_list
, py_group_map
);
1863 talloc_free(tframe
);
1865 return py_gmap_list
;
1869 static PyObject
*py_pdb_enum_group_members(pytalloc_Object
*self
, PyObject
*args
)
1872 struct pdb_methods
*methods
;
1874 PyObject
*py_group_sid
;
1875 struct dom_sid
*group_sid
;
1876 uint32_t *member_rids
;
1878 PyObject
*py_sid_list
;
1879 struct dom_sid
*domain_sid
, *member_sid
;
1882 if (!PyArg_ParseTuple(args
, "O!:enum_group_members", dom_sid_Type
, &py_group_sid
)) {
1886 methods
= pytalloc_get_ptr(self
);
1888 if ((tframe
= talloc_stackframe()) == NULL
) {
1893 group_sid
= pytalloc_get_ptr(py_group_sid
);
1895 status
= methods
->enum_group_members(methods
, tframe
, group_sid
,
1896 &member_rids
, &num_members
);
1897 if (!NT_STATUS_IS_OK(status
)) {
1898 PyErr_Format(py_pdb_error
, "Unable to enumerate group members, (%d,%s)",
1899 NT_STATUS_V(status
),
1900 get_friendly_nt_error_msg(status
));
1901 talloc_free(tframe
);
1905 py_sid_list
= PyList_New(0);
1906 if (py_sid_list
== NULL
) {
1908 talloc_free(tframe
);
1912 domain_sid
= get_global_sam_sid();
1914 for(i
=0; i
<num_members
; i
++) {
1915 member_sid
= dom_sid_add_rid(tframe
, domain_sid
, member_rids
[i
]);
1916 PyList_Append(py_sid_list
, pytalloc_steal(dom_sid_Type
, member_sid
));
1919 talloc_free(tframe
);
1925 static PyObject
*py_pdb_enum_group_memberships(pytalloc_Object
*self
, PyObject
*args
)
1928 struct pdb_methods
*methods
;
1932 struct samu
*sam_acct
;
1933 PyObject
*py_sam_acct
;
1934 PyObject
*py_sid_list
;
1935 struct dom_sid
*user_group_sids
= NULL
;
1936 gid_t
*user_group_ids
= NULL
;
1937 uint32_t num_groups
= 0;
1939 if (!PyArg_ParseTuple(args
, "O!:enum_group_memberships", &PySamu
, &py_sam_acct
)) {
1943 methods
= pytalloc_get_ptr(self
);
1945 if ((tframe
= talloc_stackframe()) == NULL
) {
1950 sam_acct
= pytalloc_get_ptr(py_sam_acct
);
1952 status
= methods
->enum_group_memberships(methods
, tframe
, sam_acct
,
1953 &user_group_sids
, &user_group_ids
, &num_groups
);
1954 if (!NT_STATUS_IS_OK(status
)) {
1955 PyErr_Format(py_pdb_error
, "Unable to enumerate group memberships, (%d,%s)",
1956 NT_STATUS_V(status
),
1957 get_friendly_nt_error_msg(status
));
1958 talloc_free(tframe
);
1962 py_sid_list
= PyList_New(0);
1963 if (py_sid_list
== NULL
) {
1965 talloc_free(tframe
);
1969 for(i
=0; i
<num_groups
; i
++) {
1970 PyList_Append(py_sid_list
, pytalloc_steal(dom_sid_Type
, dom_sid_dup(NULL
, &user_group_sids
[i
])));
1973 talloc_free(tframe
);
1979 static PyObject
*py_pdb_add_groupmem(pytalloc_Object
*self
, PyObject
*args
)
1982 struct pdb_methods
*methods
;
1984 uint32_t group_rid
, member_rid
;
1986 if (!PyArg_ParseTuple(args
, "II:add_groupmem", &group_rid
, &member_rid
)) {
1990 methods
= pytalloc_get_ptr(self
);
1992 if ((tframe
= talloc_stackframe()) == NULL
) {
1997 status
= methods
->add_groupmem(methods
, tframe
, group_rid
, member_rid
);
1998 if (!NT_STATUS_IS_OK(status
)) {
1999 PyErr_Format(py_pdb_error
, "Unable to add group member, (%d,%s)",
2000 NT_STATUS_V(status
),
2001 get_friendly_nt_error_msg(status
));
2002 talloc_free(tframe
);
2006 talloc_free(tframe
);
2011 static PyObject
*py_pdb_del_groupmem(pytalloc_Object
*self
, PyObject
*args
)
2014 struct pdb_methods
*methods
;
2016 uint32_t group_rid
, member_rid
;
2018 if (!PyArg_ParseTuple(args
, "II:del_groupmem", &group_rid
, &member_rid
)) {
2022 methods
= pytalloc_get_ptr(self
);
2024 if ((tframe
= talloc_stackframe()) == NULL
) {
2029 status
= methods
->del_groupmem(methods
, tframe
, group_rid
, member_rid
);
2030 if (!NT_STATUS_IS_OK(status
)) {
2031 PyErr_Format(py_pdb_error
, "Unable to rename sam account, (%d,%s)",
2032 NT_STATUS_V(status
),
2033 get_friendly_nt_error_msg(status
));
2034 talloc_free(tframe
);
2038 talloc_free(tframe
);
2043 static PyObject
*py_pdb_create_alias(pytalloc_Object
*self
, PyObject
*args
)
2046 struct pdb_methods
*methods
;
2048 const char *alias_name
;
2051 if (!PyArg_ParseTuple(args
, "s:create_alias", &alias_name
)) {
2055 methods
= pytalloc_get_ptr(self
);
2057 if ((tframe
= talloc_stackframe()) == NULL
) {
2062 status
= methods
->create_alias(methods
, alias_name
, &rid
);
2063 if (!NT_STATUS_IS_OK(status
)) {
2064 PyErr_Format(py_pdb_error
, "Unable to create alias (%s), (%d,%s)",
2066 NT_STATUS_V(status
),
2067 get_friendly_nt_error_msg(status
));
2068 talloc_free(tframe
);
2072 talloc_free(tframe
);
2074 return PyInt_FromLong(rid
);
2078 static PyObject
*py_pdb_delete_alias(pytalloc_Object
*self
, PyObject
*args
)
2081 struct pdb_methods
*methods
;
2083 PyObject
*py_alias_sid
;
2084 struct dom_sid
*alias_sid
;
2086 if (!PyArg_ParseTuple(args
, "O!:delete_alias", dom_sid_Type
, &py_alias_sid
)) {
2090 methods
= pytalloc_get_ptr(self
);
2092 if ((tframe
= talloc_stackframe()) == NULL
) {
2097 alias_sid
= pytalloc_get_ptr(py_alias_sid
);
2099 status
= methods
->delete_alias(methods
, alias_sid
);
2100 if (!NT_STATUS_IS_OK(status
)) {
2101 PyErr_Format(py_pdb_error
, "Unable to delete alias, (%d,%s)",
2102 NT_STATUS_V(status
),
2103 get_friendly_nt_error_msg(status
));
2104 talloc_free(tframe
);
2108 talloc_free(tframe
);
2113 static PyObject
*py_pdb_get_aliasinfo(pytalloc_Object
*self
, PyObject
*args
)
2116 struct pdb_methods
*methods
;
2118 PyObject
*py_alias_sid
;
2119 struct dom_sid
*alias_sid
;
2120 struct acct_info
*alias_info
;
2121 PyObject
*py_alias_info
;
2123 if (!PyArg_ParseTuple(args
, "O!:get_aliasinfo", dom_sid_Type
, &py_alias_sid
)) {
2127 methods
= pytalloc_get_ptr(self
);
2129 if ((tframe
= talloc_stackframe()) == NULL
) {
2134 alias_sid
= pytalloc_get_ptr(py_alias_sid
);
2136 alias_info
= talloc_zero(tframe
, struct acct_info
);
2142 status
= methods
->get_aliasinfo(methods
, alias_sid
, alias_info
);
2143 if (!NT_STATUS_IS_OK(status
)) {
2144 PyErr_Format(py_pdb_error
, "Unable to get alias information, (%d,%s)",
2145 NT_STATUS_V(status
),
2146 get_friendly_nt_error_msg(status
));
2147 talloc_free(tframe
);
2151 py_alias_info
= PyDict_New();
2152 if (py_alias_info
== NULL
) {
2154 talloc_free(tframe
);
2158 PyDict_SetItemString(py_alias_info
, "acct_name",
2159 PyString_FromString(alias_info
->acct_name
));
2160 PyDict_SetItemString(py_alias_info
, "acct_desc",
2161 PyString_FromString(alias_info
->acct_desc
));
2162 PyDict_SetItemString(py_alias_info
, "rid",
2163 PyInt_FromLong(alias_info
->rid
));
2165 talloc_free(tframe
);
2167 return py_alias_info
;
2171 static PyObject
*py_pdb_set_aliasinfo(pytalloc_Object
*self
, PyObject
*args
)
2174 struct pdb_methods
*methods
;
2176 PyObject
*py_alias_sid
, *py_alias_info
;
2177 struct dom_sid
*alias_sid
;
2178 struct acct_info alias_info
;
2180 if (!PyArg_ParseTuple(args
, "O!O:set_alias_info", dom_sid_Type
, &py_alias_sid
,
2185 methods
= pytalloc_get_ptr(self
);
2187 if ((tframe
= talloc_stackframe()) == NULL
) {
2192 alias_sid
= pytalloc_get_ptr(py_alias_sid
);
2194 fstrcpy(alias_info
.acct_name
, PyString_AsString(PyDict_GetItemString(py_alias_info
, "acct_name")));
2195 fstrcpy(alias_info
.acct_desc
, PyString_AsString(PyDict_GetItemString(py_alias_info
, "acct_desc")));
2197 status
= methods
->set_aliasinfo(methods
, alias_sid
, &alias_info
);
2198 if (!NT_STATUS_IS_OK(status
)) {
2199 PyErr_Format(py_pdb_error
, "Unable to set alias information, (%d,%s)",
2200 NT_STATUS_V(status
),
2201 get_friendly_nt_error_msg(status
));
2202 talloc_free(tframe
);
2206 talloc_free(tframe
);
2211 static PyObject
*py_pdb_add_aliasmem(pytalloc_Object
*self
, PyObject
*args
)
2214 struct pdb_methods
*methods
;
2216 PyObject
*py_alias_sid
, *py_member_sid
;
2217 struct dom_sid
*alias_sid
, *member_sid
;
2219 if (!PyArg_ParseTuple(args
, "O!O!:add_aliasmem", dom_sid_Type
, &py_alias_sid
,
2220 dom_sid_Type
, &py_member_sid
)) {
2224 methods
= pytalloc_get_ptr(self
);
2226 if ((tframe
= talloc_stackframe()) == NULL
) {
2231 alias_sid
= pytalloc_get_ptr(py_alias_sid
);
2232 member_sid
= pytalloc_get_ptr(py_member_sid
);
2234 status
= methods
->add_aliasmem(methods
, alias_sid
, member_sid
);
2235 if (!NT_STATUS_IS_OK(status
)) {
2236 PyErr_Format(py_pdb_error
, "Unable to add member to alias, (%d,%s)",
2237 NT_STATUS_V(status
),
2238 get_friendly_nt_error_msg(status
));
2239 talloc_free(tframe
);
2243 talloc_free(tframe
);
2248 static PyObject
*py_pdb_del_aliasmem(pytalloc_Object
*self
, PyObject
*args
)
2251 struct pdb_methods
*methods
;
2253 PyObject
*py_alias_sid
, *py_member_sid
;
2254 const struct dom_sid
*alias_sid
, *member_sid
;
2256 if (!PyArg_ParseTuple(args
, "O!O!:del_aliasmem", dom_sid_Type
, &py_alias_sid
,
2257 dom_sid_Type
, &py_member_sid
)) {
2261 methods
= pytalloc_get_ptr(self
);
2263 if ((tframe
= talloc_stackframe()) == NULL
) {
2268 alias_sid
= pytalloc_get_ptr(py_alias_sid
);
2269 member_sid
= pytalloc_get_ptr(py_member_sid
);
2271 status
= methods
->del_aliasmem(methods
, alias_sid
, member_sid
);
2272 if (!NT_STATUS_IS_OK(status
)) {
2273 PyErr_Format(py_pdb_error
, "Unable to delete member from alias, (%d,%s)",
2274 NT_STATUS_V(status
),
2275 get_friendly_nt_error_msg(status
));
2276 talloc_free(tframe
);
2280 talloc_free(tframe
);
2285 static PyObject
*py_pdb_enum_aliasmem(pytalloc_Object
*self
, PyObject
*args
)
2288 struct pdb_methods
*methods
;
2290 PyObject
*py_alias_sid
;
2291 struct dom_sid
*alias_sid
, *member_sid
, *tmp_sid
;
2292 PyObject
*py_member_list
, *py_member_sid
;
2296 if (!PyArg_ParseTuple(args
, "O!:enum_aliasmem", dom_sid_Type
, &py_alias_sid
)) {
2300 methods
= pytalloc_get_ptr(self
);
2302 if ((tframe
= talloc_stackframe()) == NULL
) {
2307 alias_sid
= pytalloc_get_ptr(py_alias_sid
);
2309 status
= methods
->enum_aliasmem(methods
, alias_sid
, tframe
, &member_sid
, &num_members
);
2310 if (!NT_STATUS_IS_OK(status
)) {
2311 PyErr_Format(py_pdb_error
, "Unable to enumerate members for alias, (%d,%s)",
2312 NT_STATUS_V(status
),
2313 get_friendly_nt_error_msg(status
));
2314 talloc_free(tframe
);
2318 py_member_list
= PyList_New(0);
2319 if (py_member_list
== NULL
) {
2321 talloc_free(tframe
);
2325 for(i
=0; i
<num_members
; i
++) {
2326 py_member_sid
= pytalloc_new(struct dom_sid
, dom_sid_Type
);
2327 if (py_member_sid
== NULL
) {
2329 talloc_free(tframe
);
2332 tmp_sid
= pytalloc_get_ptr(py_member_sid
);
2333 *tmp_sid
= member_sid
[i
];
2334 PyList_Append(py_member_list
, py_member_sid
);
2337 talloc_free(tframe
);
2339 return py_member_list
;
2343 static PyObject
*py_pdb_get_account_policy(pytalloc_Object
*self
)
2346 struct pdb_methods
*methods
;
2348 PyObject
*py_acct_policy
;
2352 enum pdb_policy_type type
;
2354 methods
= pytalloc_get_ptr(self
);
2356 if ((tframe
= talloc_stackframe()) == NULL
) {
2361 py_acct_policy
= PyDict_New();
2362 if (py_acct_policy
== NULL
) {
2367 account_policy_names_list(tframe
, &names
, &count
);
2368 for (i
=0; i
<count
; i
++) {
2369 type
= account_policy_name_to_typenum(names
[i
]);
2370 status
= methods
->get_account_policy(methods
, type
, &value
);
2371 if (NT_STATUS_IS_OK(status
)) {
2372 PyDict_SetItemString(py_acct_policy
, names
[i
], Py_BuildValue("i", value
));
2376 talloc_free(tframe
);
2378 return py_acct_policy
;
2382 static PyObject
*py_pdb_set_account_policy(pytalloc_Object
*self
, PyObject
*args
)
2385 struct pdb_methods
*methods
;
2387 PyObject
*py_acct_policy
, *py_value
;
2390 enum pdb_policy_type type
;
2392 if (!PyArg_ParseTuple(args
, "O!:set_account_policy", PyDict_Type
, &py_acct_policy
)) {
2396 methods
= pytalloc_get_ptr(self
);
2398 if ((tframe
= talloc_stackframe()) == NULL
) {
2403 account_policy_names_list(tframe
, &names
, &count
);
2404 for (i
=0; i
<count
; i
++) {
2405 if ((py_value
= PyDict_GetItemString(py_acct_policy
, names
[i
])) != NULL
) {
2406 type
= account_policy_name_to_typenum(names
[i
]);
2407 status
= methods
->set_account_policy(methods
, type
, PyInt_AsLong(py_value
));
2408 if (!NT_STATUS_IS_OK(status
)) {
2409 PyErr_Format(py_pdb_error
, "Error setting account policy (%s), (%d,%s)",
2411 NT_STATUS_V(status
),
2412 get_friendly_nt_error_msg(status
));
2418 talloc_free(tframe
);
2423 static PyObject
*py_pdb_search_users(pytalloc_Object
*self
, PyObject
*args
)
2426 struct pdb_methods
*methods
;
2428 unsigned int acct_flags
;
2429 struct pdb_search
*search
;
2430 struct samr_displayentry
*entry
;
2431 PyObject
*py_userlist
, *py_dict
;
2433 if (!PyArg_ParseTuple(args
, "I:search_users", &acct_flags
)) {
2437 methods
= pytalloc_get_ptr(self
);
2439 if ((tframe
= talloc_stackframe()) == NULL
) {
2444 search
= talloc_zero(tframe
, struct pdb_search
);
2445 if (search
== NULL
) {
2447 talloc_free(tframe
);
2451 if (!methods
->search_users(methods
, search
, acct_flags
)) {
2452 PyErr_Format(py_pdb_error
, "Unable to search users, (%d,%s)",
2453 NT_STATUS_V(status
),
2454 get_friendly_nt_error_msg(status
));
2455 talloc_free(tframe
);
2459 entry
= talloc_zero(tframe
, struct samr_displayentry
);
2460 if (entry
== NULL
) {
2462 talloc_free(tframe
);
2466 py_userlist
= PyList_New(0);
2467 if (py_userlist
== NULL
) {
2469 talloc_free(tframe
);
2473 while (search
->next_entry(search
, entry
)) {
2474 py_dict
= PyDict_New();
2475 if (py_dict
== NULL
) {
2478 PyDict_SetItemString(py_dict
, "idx", PyInt_FromLong(entry
->idx
));
2479 PyDict_SetItemString(py_dict
, "rid", PyInt_FromLong(entry
->rid
));
2480 PyDict_SetItemString(py_dict
, "acct_flags", PyInt_FromLong(entry
->acct_flags
));
2481 PyDict_SetItemString(py_dict
, "account_name", PyString_FromString(entry
->account_name
));
2482 PyDict_SetItemString(py_dict
, "fullname", PyString_FromString(entry
->fullname
));
2483 PyDict_SetItemString(py_dict
, "description", PyString_FromString(entry
->description
));
2484 PyList_Append(py_userlist
, py_dict
);
2487 search
->search_end(search
);
2489 talloc_free(tframe
);
2495 static PyObject
*py_pdb_search_groups(pytalloc_Object
*self
)
2498 struct pdb_methods
*methods
;
2500 struct pdb_search
*search
;
2501 struct samr_displayentry
*entry
;
2502 PyObject
*py_grouplist
, *py_dict
;
2504 methods
= pytalloc_get_ptr(self
);
2506 if ((tframe
= talloc_stackframe()) == NULL
) {
2511 search
= talloc_zero(tframe
, struct pdb_search
);
2512 if (search
== NULL
) {
2514 talloc_free(tframe
);
2518 if (!methods
->search_groups(methods
, search
)) {
2519 PyErr_Format(py_pdb_error
, "Unable to search groups, (%d,%s)",
2520 NT_STATUS_V(status
),
2521 get_friendly_nt_error_msg(status
));
2522 talloc_free(tframe
);
2526 entry
= talloc_zero(tframe
, struct samr_displayentry
);
2527 if (entry
== NULL
) {
2529 talloc_free(tframe
);
2533 py_grouplist
= PyList_New(0);
2534 if (py_grouplist
== NULL
) {
2536 talloc_free(tframe
);
2540 while (search
->next_entry(search
, entry
)) {
2541 py_dict
= PyDict_New();
2542 if (py_dict
== NULL
) {
2545 PyDict_SetItemString(py_dict
, "idx", PyInt_FromLong(entry
->idx
));
2546 PyDict_SetItemString(py_dict
, "rid", PyInt_FromLong(entry
->rid
));
2547 PyDict_SetItemString(py_dict
, "acct_flags", PyInt_FromLong(entry
->acct_flags
));
2548 PyDict_SetItemString(py_dict
, "account_name", PyString_FromString(entry
->account_name
));
2549 PyDict_SetItemString(py_dict
, "fullname", PyString_FromString(entry
->fullname
));
2550 PyDict_SetItemString(py_dict
, "description", PyString_FromString(entry
->description
));
2551 PyList_Append(py_grouplist
, py_dict
);
2554 search
->search_end(search
);
2556 talloc_free(tframe
);
2558 return py_grouplist
;
2562 static PyObject
*py_pdb_search_aliases(pytalloc_Object
*self
, PyObject
*args
)
2564 struct pdb_methods
*methods
;
2566 struct pdb_search
*search
;
2567 struct samr_displayentry
*entry
;
2568 PyObject
*py_aliaslist
, *py_dict
;
2569 PyObject
*py_domain_sid
;
2570 struct dom_sid
*domain_sid
= NULL
;
2572 py_domain_sid
= Py_None
;
2575 if (!PyArg_ParseTuple(args
, "|O!:search_aliases", dom_sid_Type
, &py_domain_sid
)) {
2579 methods
= pytalloc_get_ptr(self
);
2581 if ((tframe
= talloc_stackframe()) == NULL
) {
2586 if (py_domain_sid
!= Py_None
) {
2587 domain_sid
= pytalloc_get_ptr(py_domain_sid
);
2590 search
= talloc_zero(tframe
, struct pdb_search
);
2591 if (search
== NULL
) {
2593 talloc_free(tframe
);
2597 if (!methods
->search_aliases(methods
, search
, domain_sid
)) {
2598 PyErr_Format(py_pdb_error
, "Unable to search aliases");
2599 talloc_free(tframe
);
2603 entry
= talloc_zero(tframe
, struct samr_displayentry
);
2604 if (entry
== NULL
) {
2606 talloc_free(tframe
);
2610 py_aliaslist
= PyList_New(0);
2611 if (py_aliaslist
== NULL
) {
2613 talloc_free(tframe
);
2617 while (search
->next_entry(search
, entry
)) {
2618 py_dict
= PyDict_New();
2619 if (py_dict
== NULL
) {
2622 PyDict_SetItemString(py_dict
, "idx", PyInt_FromLong(entry
->idx
));
2623 PyDict_SetItemString(py_dict
, "rid", PyInt_FromLong(entry
->rid
));
2624 PyDict_SetItemString(py_dict
, "acct_flags", PyInt_FromLong(entry
->acct_flags
));
2625 PyDict_SetItemString(py_dict
, "account_name", PyString_FromString(entry
->account_name
));
2626 PyDict_SetItemString(py_dict
, "fullname", PyString_FromString(entry
->fullname
));
2627 PyDict_SetItemString(py_dict
, "description", PyString_FromString(entry
->description
));
2628 PyList_Append(py_aliaslist
, py_dict
);
2631 search
->search_end(search
);
2633 talloc_free(tframe
);
2635 return py_aliaslist
;
2639 static PyObject
*py_pdb_uid_to_sid(pytalloc_Object
*self
, PyObject
*args
)
2641 struct pdb_methods
*methods
;
2644 struct dom_sid user_sid
, *copy_user_sid
;
2645 PyObject
*py_user_sid
;
2647 if (!PyArg_ParseTuple(args
, "I:uid_to_sid", &uid
)) {
2651 methods
= pytalloc_get_ptr(self
);
2653 if ((tframe
= talloc_stackframe()) == NULL
) {
2658 if (!methods
->uid_to_sid(methods
, uid
, &user_sid
)) {
2659 PyErr_Format(py_pdb_error
, "Unable to get sid for uid=%d", uid
);
2660 talloc_free(tframe
);
2664 copy_user_sid
= dom_sid_dup(tframe
, &user_sid
);
2665 if (copy_user_sid
== NULL
) {
2667 talloc_free(tframe
);
2671 py_user_sid
= pytalloc_steal(dom_sid_Type
, copy_user_sid
);
2673 talloc_free(tframe
);
2679 static PyObject
*py_pdb_gid_to_sid(pytalloc_Object
*self
, PyObject
*args
)
2681 struct pdb_methods
*methods
;
2684 struct dom_sid group_sid
, *copy_group_sid
;
2685 PyObject
*py_group_sid
;
2687 if (!PyArg_ParseTuple(args
, "I:gid_to_sid", &gid
)) {
2691 methods
= pytalloc_get_ptr(self
);
2693 if ((tframe
= talloc_stackframe()) == NULL
) {
2698 if (!methods
->gid_to_sid(methods
, gid
, &group_sid
)) {
2699 PyErr_Format(py_pdb_error
, "Unable to get sid for gid=%d", gid
);
2700 talloc_free(tframe
);
2704 copy_group_sid
= dom_sid_dup(tframe
, &group_sid
);
2705 if (copy_group_sid
== NULL
) {
2707 talloc_free(tframe
);
2711 py_group_sid
= pytalloc_steal(dom_sid_Type
, copy_group_sid
);
2713 talloc_free(tframe
);
2715 return py_group_sid
;
2719 static PyObject
*py_pdb_sid_to_id(pytalloc_Object
*self
, PyObject
*args
)
2721 struct pdb_methods
*methods
;
2724 struct dom_sid
*sid
;
2727 if (!PyArg_ParseTuple(args
, "O!:sid_to_id", dom_sid_Type
, &py_sid
)) {
2731 methods
= pytalloc_get_ptr(self
);
2733 if ((tframe
= talloc_stackframe()) == NULL
) {
2738 sid
= pytalloc_get_ptr(py_sid
);
2740 if (!methods
->sid_to_id(methods
, sid
, &id
)) {
2741 PyErr_Format(py_pdb_error
, "Unable to get id for sid");
2742 talloc_free(tframe
);
2746 talloc_free(tframe
);
2748 return Py_BuildValue("(II)", id
.id
, id
.type
);
2752 static PyObject
*py_pdb_new_rid(pytalloc_Object
*self
)
2754 struct pdb_methods
*methods
;
2758 methods
= pytalloc_get_ptr(self
);
2760 if ((tframe
= talloc_stackframe()) == NULL
) {
2765 if (!methods
->new_rid(methods
, &rid
)) {
2766 PyErr_Format(py_pdb_error
, "Unable to get new rid");
2767 talloc_free(tframe
);
2771 talloc_free(tframe
);
2773 return PyInt_FromLong(rid
);
2777 static PyObject
*py_pdb_get_trusteddom_pw(pytalloc_Object
*self
, PyObject
*args
)
2779 struct pdb_methods
*methods
;
2783 struct dom_sid sid
, *copy_sid
;
2785 time_t last_set_time
;
2788 if (!PyArg_ParseTuple(args
, "s:get_trusteddom_pw", &domain
)) {
2792 methods
= pytalloc_get_ptr(self
);
2794 if ((tframe
= talloc_stackframe()) == NULL
) {
2799 if (!methods
->get_trusteddom_pw(methods
, domain
, &pwd
, &sid
, &last_set_time
)) {
2800 PyErr_Format(py_pdb_error
, "Unable to get trusted domain password");
2801 talloc_free(tframe
);
2805 copy_sid
= dom_sid_dup(tframe
, &sid
);
2806 if (copy_sid
== NULL
) {
2808 talloc_free(tframe
);
2812 py_sid
= pytalloc_steal(dom_sid_Type
, copy_sid
);
2813 if (py_sid
== NULL
) {
2815 talloc_free(tframe
);
2819 talloc_free(tframe
);
2821 py_value
= PyDict_New();
2822 if (py_value
== NULL
) {
2827 PyDict_SetItemString(py_value
, "pwd", PyString_FromString(pwd
));
2828 PyDict_SetItemString(py_value
, "sid", py_sid
);
2829 PyDict_SetItemString(py_value
, "last_set_tim", PyInt_FromLong(last_set_time
));
2835 static PyObject
*py_pdb_set_trusteddom_pw(pytalloc_Object
*self
, PyObject
*args
)
2837 struct pdb_methods
*methods
;
2841 const struct dom_sid
*domain_sid
;
2842 PyObject
*py_domain_sid
;
2844 if (!PyArg_ParseTuple(args
, "ssO!:set_trusteddom_pw", &domain
, &pwd
,
2845 dom_sid_Type
, &py_domain_sid
)) {
2849 methods
= pytalloc_get_ptr(self
);
2851 if ((tframe
= talloc_stackframe()) == NULL
) {
2856 domain_sid
= pytalloc_get_ptr(py_domain_sid
);
2858 if (!methods
->set_trusteddom_pw(methods
, domain
, pwd
, domain_sid
)) {
2859 PyErr_Format(py_pdb_error
, "Unable to set trusted domain password");
2860 talloc_free(tframe
);
2868 static PyObject
*py_pdb_del_trusteddom_pw(pytalloc_Object
*self
, PyObject
*args
)
2870 struct pdb_methods
*methods
;
2874 if (!PyArg_ParseTuple(args
, "s:del_trusteddom_pw", &domain
)) {
2878 methods
= pytalloc_get_ptr(self
);
2880 if ((tframe
= talloc_stackframe()) == NULL
) {
2885 if (!methods
->del_trusteddom_pw(methods
, domain
)) {
2886 PyErr_Format(py_pdb_error
, "Unable to delete trusted domain password");
2887 talloc_free(tframe
);
2895 static PyObject
*py_pdb_enum_trusteddoms(pytalloc_Object
*self
)
2898 struct pdb_methods
*methods
;
2900 uint32_t num_domains
;
2901 struct trustdom_info
**domains
;
2902 PyObject
*py_domain_list
, *py_dict
;
2905 methods
= pytalloc_get_ptr(self
);
2907 if ((tframe
= talloc_stackframe()) == NULL
) {
2912 status
= methods
->enum_trusteddoms(methods
, tframe
, &num_domains
, &domains
);
2913 if (!NT_STATUS_IS_OK(status
)) {
2914 PyErr_Format(py_pdb_error
, "Unable to enumerate trusted domains, (%d,%s)",
2915 NT_STATUS_V(status
),
2916 get_friendly_nt_error_msg(status
));
2917 talloc_free(tframe
);
2921 py_domain_list
= PyList_New(0);
2922 if (py_domain_list
== NULL
) {
2924 talloc_free(tframe
);
2928 for(i
=0; i
<num_domains
; i
++) {
2929 py_dict
= PyDict_New();
2931 PyDict_SetItemString(py_dict
, "name",
2932 PyString_FromString(domains
[i
]->name
));
2933 PyDict_SetItemString(py_dict
, "sid",
2934 pytalloc_steal(dom_sid_Type
, &domains
[i
]->sid
));
2937 PyList_Append(py_domain_list
, py_dict
);
2940 talloc_free(tframe
);
2942 return py_domain_list
;
2946 static PyObject
*py_pdb_get_trusted_domain(pytalloc_Object
*self
, PyObject
*args
)
2949 struct pdb_methods
*methods
;
2952 struct pdb_trusted_domain
*td
;
2953 PyObject
*py_domain_info
;
2955 if (!PyArg_ParseTuple(args
, "s:get_trusted_domain", &domain
)) {
2959 methods
= pytalloc_get_ptr(self
);
2961 if ((tframe
= talloc_stackframe()) == NULL
) {
2966 status
= methods
->get_trusted_domain(methods
, tframe
, domain
, &td
);
2967 if (!NT_STATUS_IS_OK(status
)) {
2968 PyErr_Format(py_pdb_error
, "Unable to get trusted domain information, (%d,%s)",
2969 NT_STATUS_V(status
),
2970 get_friendly_nt_error_msg(status
));
2971 talloc_free(tframe
);
2975 py_domain_info
= PyDict_New();
2976 if (py_domain_info
== NULL
) {
2978 talloc_free(tframe
);
2982 PyDict_SetItemString(py_domain_info
, "domain_name",
2983 PyString_FromString(td
->domain_name
));
2984 PyDict_SetItemString(py_domain_info
, "netbios_name",
2985 PyString_FromString(td
->netbios_name
));
2986 PyDict_SetItemString(py_domain_info
, "security_identifier",
2987 pytalloc_steal(dom_sid_Type
, &td
->security_identifier
));
2988 PyDict_SetItemString(py_domain_info
, "trust_auth_incoming",
2989 PyString_FromStringAndSize((char *)td
->trust_auth_incoming
.data
,
2990 td
->trust_auth_incoming
.length
));
2991 PyDict_SetItemString(py_domain_info
, "trust_auth_outgoing",
2992 PyString_FromStringAndSize((char *)td
->trust_auth_outgoing
.data
,
2993 td
->trust_auth_outgoing
.length
));
2994 PyDict_SetItemString(py_domain_info
, "trust_direction",
2995 PyInt_FromLong(td
->trust_direction
));
2996 PyDict_SetItemString(py_domain_info
, "trust_type",
2997 PyInt_FromLong(td
->trust_type
));
2998 PyDict_SetItemString(py_domain_info
, "trust_attributes",
2999 PyInt_FromLong(td
->trust_attributes
));
3000 PyDict_SetItemString(py_domain_info
, "trust_forest_trust_info",
3001 PyString_FromStringAndSize((char *)td
->trust_forest_trust_info
.data
,
3002 td
->trust_forest_trust_info
.length
));
3004 talloc_free(tframe
);
3006 return py_domain_info
;
3010 static PyObject
*py_pdb_get_trusted_domain_by_sid(pytalloc_Object
*self
, PyObject
*args
)
3013 struct pdb_methods
*methods
;
3015 PyObject
*py_domain_sid
;
3016 struct dom_sid
*domain_sid
;
3017 struct pdb_trusted_domain
*td
;
3018 PyObject
*py_domain_info
;
3020 if (!PyArg_ParseTuple(args
, "O!:get_trusted_domain_by_sid", dom_sid_Type
, &py_domain_sid
)) {
3024 methods
= pytalloc_get_ptr(self
);
3026 if ((tframe
= talloc_stackframe()) == NULL
) {
3031 domain_sid
= pytalloc_get_ptr(py_domain_sid
);
3033 status
= methods
->get_trusted_domain_by_sid(methods
, tframe
, domain_sid
, &td
);
3034 if (!NT_STATUS_IS_OK(status
)) {
3035 PyErr_Format(py_pdb_error
, "Unable to get trusted domain information, (%d,%s)",
3036 NT_STATUS_V(status
),
3037 get_friendly_nt_error_msg(status
));
3038 talloc_free(tframe
);
3042 py_domain_info
= PyDict_New();
3043 if (py_domain_info
== NULL
) {
3045 talloc_free(tframe
);
3049 PyDict_SetItemString(py_domain_info
, "domain_name",
3050 PyString_FromString(td
->domain_name
));
3051 PyDict_SetItemString(py_domain_info
, "netbios_name",
3052 PyString_FromString(td
->netbios_name
));
3053 PyDict_SetItemString(py_domain_info
, "security_identifier",
3054 pytalloc_steal(dom_sid_Type
, &td
->security_identifier
));
3055 PyDict_SetItemString(py_domain_info
, "trust_auth_incoming",
3056 PyString_FromStringAndSize((char *)td
->trust_auth_incoming
.data
,
3057 td
->trust_auth_incoming
.length
));
3058 PyDict_SetItemString(py_domain_info
, "trust_auth_outgoing",
3059 PyString_FromStringAndSize((char *)td
->trust_auth_outgoing
.data
,
3060 td
->trust_auth_outgoing
.length
));
3061 PyDict_SetItemString(py_domain_info
, "trust_direction",
3062 PyInt_FromLong(td
->trust_direction
));
3063 PyDict_SetItemString(py_domain_info
, "trust_type",
3064 PyInt_FromLong(td
->trust_type
));
3065 PyDict_SetItemString(py_domain_info
, "trust_attributes",
3066 PyInt_FromLong(td
->trust_attributes
));
3067 PyDict_SetItemString(py_domain_info
, "trust_forest_trust_info",
3068 PyString_FromStringAndSize((char *)td
->trust_forest_trust_info
.data
,
3069 td
->trust_forest_trust_info
.length
));
3071 talloc_free(tframe
);
3073 return py_domain_info
;
3077 static PyObject
*py_pdb_set_trusted_domain(pytalloc_Object
*self
, PyObject
*args
)
3080 struct pdb_methods
*methods
;
3083 PyObject
*py_td_info
;
3084 struct pdb_trusted_domain td_info
;
3088 if (!PyArg_ParseTuple(args
, "sO!:set_trusted_domain", &domain
, &PyDict_Type
, &py_td_info
)) {
3092 py_tmp
= PyDict_GetItemString(py_td_info
, "domain_name");
3093 td_info
.domain_name
= PyString_AsString(py_tmp
);
3095 py_tmp
= PyDict_GetItemString(py_td_info
, "netbios_name");
3096 td_info
.netbios_name
= PyString_AsString(py_tmp
);
3098 py_tmp
= PyDict_GetItemString(py_td_info
, "security_identifier");
3099 td_info
.security_identifier
= *pytalloc_get_type(py_tmp
, struct dom_sid
);
3101 py_tmp
= PyDict_GetItemString(py_td_info
, "trust_auth_incoming");
3102 PyString_AsStringAndSize(py_tmp
, (char **)&td_info
.trust_auth_incoming
.data
, &len
);
3103 td_info
.trust_auth_incoming
.length
= len
;
3105 py_tmp
= PyDict_GetItemString(py_td_info
, "trust_auth_outgoing");
3106 PyString_AsStringAndSize(py_tmp
, (char **)&td_info
.trust_auth_outgoing
.data
, &len
);
3107 td_info
.trust_auth_outgoing
.length
= len
;
3109 py_tmp
= PyDict_GetItemString(py_td_info
, "trust_direction");
3110 td_info
.trust_direction
= PyInt_AsLong(py_tmp
);
3112 py_tmp
= PyDict_GetItemString(py_td_info
, "trust_type");
3113 td_info
.trust_type
= PyInt_AsLong(py_tmp
);
3115 py_tmp
= PyDict_GetItemString(py_td_info
, "trust_attributes");
3116 td_info
.trust_attributes
= PyInt_AsLong(py_tmp
);
3118 py_tmp
= PyDict_GetItemString(py_td_info
, "trust_forest_trust_info");
3119 PyString_AsStringAndSize(py_tmp
, (char **)&td_info
.trust_forest_trust_info
.data
, &len
);
3120 td_info
.trust_forest_trust_info
.length
= len
;
3122 methods
= pytalloc_get_ptr(self
);
3124 if ((tframe
= talloc_stackframe()) == NULL
) {
3129 status
= methods
->set_trusted_domain(methods
, domain
, &td_info
);
3130 if (!NT_STATUS_IS_OK(status
)) {
3131 PyErr_Format(py_pdb_error
, "Unable to set trusted domain information, (%d,%s)",
3132 NT_STATUS_V(status
),
3133 get_friendly_nt_error_msg(status
));
3134 talloc_free(tframe
);
3138 talloc_free(tframe
);
3144 static PyObject
*py_pdb_del_trusted_domain(pytalloc_Object
*self
, PyObject
*args
)
3147 struct pdb_methods
*methods
;
3151 if (!PyArg_ParseTuple(args
, "s:del_trusted_domain", &domain
)) {
3155 methods
= pytalloc_get_ptr(self
);
3157 if ((tframe
= talloc_stackframe()) == NULL
) {
3162 status
= methods
->del_trusted_domain(methods
, domain
);
3163 if (!NT_STATUS_IS_OK(status
)) {
3164 PyErr_Format(py_pdb_error
, "Unable to delete trusted domain, (%d,%s)",
3165 NT_STATUS_V(status
),
3166 get_friendly_nt_error_msg(status
));
3167 talloc_free(tframe
);
3171 talloc_free(tframe
);
3177 static PyObject
*py_pdb_enum_trusted_domains(pytalloc_Object
*self
)
3180 struct pdb_methods
*methods
;
3182 uint32_t num_domains
;
3183 struct pdb_trusted_domain
**td_info
, *td
;
3184 PyObject
*py_td_info
, *py_domain_info
;
3187 methods
= pytalloc_get_ptr(self
);
3189 if ((tframe
= talloc_stackframe()) == NULL
) {
3194 status
= methods
->enum_trusted_domains(methods
, tframe
, &num_domains
, &td_info
);
3195 if (!NT_STATUS_IS_OK(status
)) {
3196 PyErr_Format(py_pdb_error
, "Unable to delete trusted domain, (%d,%s)",
3197 NT_STATUS_V(status
),
3198 get_friendly_nt_error_msg(status
));
3199 talloc_free(tframe
);
3203 py_td_info
= PyList_New(0);
3204 if (py_td_info
== NULL
) {
3206 talloc_free(tframe
);
3210 for (i
=0; i
<num_domains
; i
++) {
3212 py_domain_info
= PyDict_New();
3213 if (py_domain_info
== NULL
) {
3215 Py_DECREF(py_td_info
);
3216 talloc_free(tframe
);
3222 PyDict_SetItemString(py_domain_info
, "domain_name",
3223 PyString_FromString(td
->domain_name
));
3224 PyDict_SetItemString(py_domain_info
, "netbios_name",
3225 PyString_FromString(td
->netbios_name
));
3226 PyDict_SetItemString(py_domain_info
, "security_identifier",
3227 pytalloc_steal(dom_sid_Type
, &td
->security_identifier
));
3228 PyDict_SetItemString(py_domain_info
, "trust_auth_incoming",
3229 PyString_FromStringAndSize((char *)td
->trust_auth_incoming
.data
,
3230 td
->trust_auth_incoming
.length
));
3231 PyDict_SetItemString(py_domain_info
, "trust_auth_outgoing",
3232 PyString_FromStringAndSize((char *)td
->trust_auth_outgoing
.data
,
3233 td
->trust_auth_outgoing
.length
));
3234 PyDict_SetItemString(py_domain_info
, "trust_direction",
3235 PyInt_FromLong(td
->trust_direction
));
3236 PyDict_SetItemString(py_domain_info
, "trust_type",
3237 PyInt_FromLong(td
->trust_type
));
3238 PyDict_SetItemString(py_domain_info
, "trust_attributes",
3239 PyInt_FromLong(td
->trust_attributes
));
3240 PyDict_SetItemString(py_domain_info
, "trust_forest_trust_info",
3241 PyString_FromStringAndSize((char *)td
->trust_forest_trust_info
.data
,
3242 td
->trust_forest_trust_info
.length
));
3243 PyList_Append(py_td_info
, py_domain_info
);
3246 talloc_free(tframe
);
3252 static PyObject
*py_pdb_get_secret(pytalloc_Object
*self
, PyObject
*args
)
3255 struct pdb_methods
*methods
;
3257 const char *secret_name
;
3258 DATA_BLOB secret_current
, secret_old
;
3259 NTTIME secret_current_lastchange
, secret_old_lastchange
;
3261 struct security_descriptor
*sd
;
3262 PyObject
*py_secret
;
3264 if (!PyArg_ParseTuple(args
, "s:get_secret_name", &secret_name
)) {
3268 methods
= pytalloc_get_ptr(self
);
3270 if ((tframe
= talloc_stackframe()) == NULL
) {
3275 py_sd
= pytalloc_new(struct security_descriptor
, security_Type
);
3276 if (py_sd
== NULL
) {
3278 talloc_free(tframe
);
3281 sd
= pytalloc_get_ptr(py_sd
);
3283 status
= methods
->get_secret(methods
, tframe
, secret_name
,
3285 &secret_current_lastchange
,
3287 &secret_old_lastchange
,
3289 if (!NT_STATUS_IS_OK(status
)) {
3290 PyErr_Format(py_pdb_error
, "Unable to get information for secret (%s), (%d,%s)",
3292 NT_STATUS_V(status
),
3293 get_friendly_nt_error_msg(status
));
3294 talloc_free(tframe
);
3298 py_secret
= PyDict_New();
3299 if (py_secret
== NULL
) {
3302 talloc_free(tframe
);
3306 PyDict_SetItemString(py_secret
, "secret_current",
3307 PyString_FromStringAndSize((char *)secret_current
.data
, secret_current
.length
));
3308 PyDict_SetItemString(py_secret
, "secret_current_lastchange",
3309 PyLong_FromUnsignedLongLong(secret_current_lastchange
));
3310 PyDict_SetItemString(py_secret
, "secret_old",
3311 PyString_FromStringAndSize((char *)secret_old
.data
, secret_old
.length
));
3312 PyDict_SetItemString(py_secret
, "secret_old_lastchange",
3313 PyLong_FromUnsignedLongLong(secret_old_lastchange
));
3314 PyDict_SetItemString(py_secret
, "sd", py_sd
);
3316 talloc_free(tframe
);
3322 static PyObject
*py_pdb_set_secret(pytalloc_Object
*self
, PyObject
*args
)
3325 struct pdb_methods
*methods
;
3327 const char *secret_name
;
3328 PyObject
*py_secret
;
3329 PyObject
*py_secret_cur
, *py_secret_old
, *py_sd
;
3330 DATA_BLOB secret_current
, secret_old
;
3331 struct security_descriptor
*sd
;
3334 if (!PyArg_ParseTuple(args
, "sO!:set_secret_name", &secret_name
, PyDict_Type
, &py_secret
)) {
3338 py_secret_cur
= PyDict_GetItemString(py_secret
, "secret_current");
3339 py_secret_old
= PyDict_GetItemString(py_secret
, "secret_old");
3340 py_sd
= PyDict_GetItemString(py_secret
, "sd");
3342 PY_CHECK_TYPE(&PyString_Type
, py_secret_cur
, return NULL
;);
3343 PY_CHECK_TYPE(&PyString_Type
, py_secret_old
, return NULL
;);
3344 PY_CHECK_TYPE(security_Type
, py_sd
, return NULL
;);
3346 methods
= pytalloc_get_ptr(self
);
3348 if ((tframe
= talloc_stackframe()) == NULL
) {
3353 PyString_AsStringAndSize(py_secret_cur
, (char **)&secret_current
.data
, &len
);
3354 secret_current
.length
= len
;
3355 PyString_AsStringAndSize(py_secret_old
, (char **)&secret_old
.data
, &len
);
3356 secret_current
.length
= len
;
3357 sd
= pytalloc_get_ptr(py_sd
);
3359 status
= methods
->set_secret(methods
, secret_name
, &secret_current
, &secret_old
, sd
);
3360 if (!NT_STATUS_IS_OK(status
)) {
3361 PyErr_Format(py_pdb_error
, "Unable to set information for secret (%s), (%d,%s)",
3363 NT_STATUS_V(status
),
3364 get_friendly_nt_error_msg(status
));
3365 talloc_free(tframe
);
3369 talloc_free(tframe
);
3375 static PyObject
*py_pdb_delete_secret(pytalloc_Object
*self
, PyObject
*args
)
3378 struct pdb_methods
*methods
;
3380 const char *secret_name
;
3382 if (!PyArg_ParseTuple(args
, "s:delete_secret", &secret_name
)) {
3386 methods
= pytalloc_get_ptr(self
);
3388 if ((tframe
= talloc_stackframe()) == NULL
) {
3393 status
= methods
->delete_secret(methods
, secret_name
);
3394 if (!NT_STATUS_IS_OK(status
)) {
3395 PyErr_Format(py_pdb_error
, "Unable to delete secret (%s), (%d,%s)",
3397 NT_STATUS_V(status
),
3398 get_friendly_nt_error_msg(status
));
3399 talloc_free(tframe
);
3403 talloc_free(tframe
);
3408 static PyMethodDef py_pdb_methods
[] = {
3409 { "domain_info", (PyCFunction
)py_pdb_domain_info
, METH_NOARGS
,
3410 "domain_info() -> str\n\n \
3411 Get domain information for the database." },
3412 { "getsampwnam", (PyCFunction
)py_pdb_getsampwnam
, METH_VARARGS
,
3413 "getsampwnam(username) -> samu object\n\n \
3414 Get user information by name." },
3415 { "getsampwsid", (PyCFunction
)py_pdb_getsampwsid
, METH_VARARGS
,
3416 "getsampwsid(user_sid) -> samu object\n\n \
3417 Get user information by sid (dcerpc.security.dom_sid object)." },
3418 { "create_user", (PyCFunction
)py_pdb_create_user
, METH_VARARGS
,
3419 "create_user(username, acct_flags) -> rid\n\n \
3420 Create user. acct_flags are samr account control flags." },
3421 { "delete_user", (PyCFunction
)py_pdb_delete_user
, METH_VARARGS
,
3422 "delete_user(samu object) -> None\n\n \
3424 { "add_sam_account", (PyCFunction
)py_pdb_add_sam_account
, METH_VARARGS
,
3425 "add_sam_account(samu object) -> None\n\n \
3426 Add SAM account." },
3427 { "update_sam_account", (PyCFunction
)py_pdb_update_sam_account
, METH_VARARGS
,
3428 "update_sam_account(samu object) -> None\n\n \
3429 Update SAM account." },
3430 { "delete_sam_account", (PyCFunction
)py_pdb_delete_sam_account
, METH_VARARGS
,
3431 "delete_sam_account(samu object) -> None\n\n \
3432 Delete SAM account." },
3433 { "rename_sam_account", (PyCFunction
)py_pdb_rename_sam_account
, METH_VARARGS
,
3434 "rename_sam_account(samu object1, new_username) -> None\n\n \
3435 Rename SAM account." },
3436 /* update_login_attempts */
3437 { "getgrsid", (PyCFunction
)py_pdb_getgrsid
, METH_VARARGS
,
3438 "getgrsid(group_sid) -> groupmap object\n\n \
3439 Get group information by sid (dcerpc.security.dom_sid object)." },
3440 { "getgrgid", (PyCFunction
)py_pdb_getgrgid
, METH_VARARGS
,
3441 "getgrsid(gid) -> groupmap object\n\n \
3442 Get group information by gid." },
3443 { "getgrnam", (PyCFunction
)py_pdb_getgrnam
, METH_VARARGS
,
3444 "getgrsid(groupname) -> groupmap object\n\n \
3445 Get group information by name." },
3446 { "create_dom_group", (PyCFunction
)py_pdb_create_dom_group
, METH_VARARGS
,
3447 "create_dom_group(groupname) -> group_rid\n\n \
3448 Create new domain group by name." },
3449 { "delete_dom_group", (PyCFunction
)py_pdb_delete_dom_group
, METH_VARARGS
,
3450 "delete_dom_group(group_rid) -> None\n\n \
3451 Delete domain group identified by rid" },
3452 { "add_group_mapping_entry", (PyCFunction
)py_pdb_add_group_mapping_entry
, METH_VARARGS
,
3453 "add_group_mapping_entry(groupmap) -> None\n \
3454 Add group mapping entry for groupmap object." },
3455 { "update_group_mapping_entry", (PyCFunction
)py_pdb_update_group_mapping_entry
, METH_VARARGS
,
3456 "update_group_mapping_entry(groupmap) -> None\n\n \
3457 Update group mapping entry for groupmap object." },
3458 { "delete_group_mapping_entry", (PyCFunction
)py_pdb_delete_group_mapping_entry
, METH_VARARGS
,
3459 "delete_group_mapping_entry(groupmap) -> None\n\n \
3460 Delete group mapping entry for groupmap object." },
3461 { "enum_group_mapping", (PyCFunction
)py_pdb_enum_group_mapping
, METH_VARARGS
,
3462 "enum_group_mapping([domain_sid, [type, [unix_only]]]) -> List\n\n \
3463 Return list of group mappings as groupmap objects. Optional arguments are domain_sid object, type of group, unix only flag." },
3464 { "enum_group_members", (PyCFunction
)py_pdb_enum_group_members
, METH_VARARGS
,
3465 "enum_group_members(group_sid) -> List\n\n \
3466 Return list of users (dom_sid object) in group." },
3467 { "enum_group_memberships", (PyCFunction
)py_pdb_enum_group_memberships
, METH_VARARGS
,
3468 "enum_group_memberships(samu object) -> List\n\n \
3469 Return list of groups (dom_sid object) this user is part of." },
3470 /* set_unix_primary_group */
3471 { "add_groupmem", (PyCFunction
)py_pdb_add_groupmem
, METH_VARARGS
,
3472 "add_groupmem(group_rid, member_rid) -> None\n\n \
3473 Add user to group." },
3474 { "del_groupmem", (PyCFunction
)py_pdb_del_groupmem
, METH_VARARGS
,
3475 "del_groupmem(group_rid, member_rid) -> None\n\n \
3476 Remove user from from group." },
3477 { "create_alias", (PyCFunction
)py_pdb_create_alias
, METH_VARARGS
,
3478 "create_alias(alias_name) -> alias_rid\n\n \
3479 Create alias entry." },
3480 { "delete_alias", (PyCFunction
)py_pdb_delete_alias
, METH_VARARGS
,
3481 "delete_alias(alias_sid) -> None\n\n \
3482 Delete alias entry." },
3483 { "get_aliasinfo", (PyCFunction
)py_pdb_get_aliasinfo
, METH_VARARGS
,
3484 "get_aliasinfo(alias_sid) -> Mapping\n\n \
3485 Get alias information as a dictionary with keys - acct_name, acct_desc, rid." },
3486 { "set_aliasinfo", (PyCFunction
)py_pdb_set_aliasinfo
, METH_VARARGS
,
3487 "set_alias_info(alias_sid, Mapping) -> None\n\n \
3488 Set alias information from a dictionary with keys - acct_name, acct_desc." },
3489 { "add_aliasmem", (PyCFunction
)py_pdb_add_aliasmem
, METH_VARARGS
,
3490 "add_aliasmem(alias_sid, member_sid) -> None\n\n \
3491 Add user to alias entry." },
3492 { "del_aliasmem", (PyCFunction
)py_pdb_del_aliasmem
, METH_VARARGS
,
3493 "del_aliasmem(alias_sid, member_sid) -> None\n\n \
3494 Remove a user from alias entry." },
3495 { "enum_aliasmem", (PyCFunction
)py_pdb_enum_aliasmem
, METH_VARARGS
,
3496 "enum_aliasmem(alias_sid) -> List\n\n \
3497 Return a list of members (dom_sid object) for alias entry." },
3498 /* enum_alias_memberships */
3501 { "get_account_policy", (PyCFunction
)py_pdb_get_account_policy
, METH_NOARGS
,
3502 "get_account_policy() -> Mapping\n\n \
3503 Get account policy information as a dictionary." },
3504 { "set_account_policy", (PyCFunction
)py_pdb_set_account_policy
, METH_VARARGS
,
3505 "get_account_policy(Mapping) -> None\n\n \
3506 Set account policy settings from a dicionary." },
3508 { "search_users", (PyCFunction
)py_pdb_search_users
, METH_VARARGS
,
3509 "search_users(acct_flags) -> List\n\n \
3510 Search users. acct_flags are samr account control flags.\n \
3511 Each list entry is dictionary with keys - idx, rid, acct_flags, account_name, fullname, description." },
3512 { "search_groups", (PyCFunction
)py_pdb_search_groups
, METH_NOARGS
,
3513 "search_groups() -> List\n\n \
3514 Search unix only groups. \n \
3515 Each list entry is dictionary with keys - idx, rid, acct_flags, account_name, fullname, description." },
3516 { "search_aliases", (PyCFunction
)py_pdb_search_aliases
, METH_VARARGS
,
3517 "search_aliases([domain_sid]) -> List\n\n \
3518 Search aliases. domain_sid is dcerpc.security.dom_sid object.\n \
3519 Each list entry is dictionary with keys - idx, rid, acct_flags, account_name, fullname, description." },
3520 { "uid_to_sid", (PyCFunction
)py_pdb_uid_to_sid
, METH_VARARGS
,
3521 "uid_to_sid(uid) -> sid\n\n \
3522 Return sid for given user id." },
3523 { "gid_to_sid", (PyCFunction
)py_pdb_gid_to_sid
, METH_VARARGS
,
3524 "gid_to_sid(gid) -> sid\n\n \
3525 Return sid for given group id." },
3526 { "sid_to_id", (PyCFunction
)py_pdb_sid_to_id
, METH_VARARGS
,
3527 "sid_to_id(sid) -> Tuple\n\n \
3528 Return id and type for given sid." },
3530 { "new_rid", (PyCFunction
)py_pdb_new_rid
, METH_NOARGS
,
3531 "new_rid() -> rid\n\n \
3533 { "get_trusteddom_pw", (PyCFunction
)py_pdb_get_trusteddom_pw
, METH_VARARGS
,
3534 "get_trusteddom_pw(domain) -> Mapping\n\n \
3535 Get trusted domain password, sid and last set time in a dictionary." },
3536 { "set_trusteddom_pw", (PyCFunction
)py_pdb_set_trusteddom_pw
, METH_VARARGS
,
3537 "set_trusteddom_pw(domain, pwd, sid) -> None\n\n \
3538 Set trusted domain password." },
3539 { "del_trusteddom_pw", (PyCFunction
)py_pdb_del_trusteddom_pw
, METH_VARARGS
,
3540 "del_trusteddom_pw(domain) -> None\n\n \
3541 Delete trusted domain password." },
3542 { "enum_trusteddoms", (PyCFunction
)py_pdb_enum_trusteddoms
, METH_NOARGS
,
3543 "enum_trusteddoms() -> List\n\n \
3544 Get list of trusted domains. Each item is a dictionary with name and sid keys" },
3545 { "get_trusted_domain", (PyCFunction
)py_pdb_get_trusted_domain
, METH_VARARGS
,
3546 "get_trusted_domain(domain) -> Mapping\n\n \
3547 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." },
3548 { "get_trusted_domain_by_sid", (PyCFunction
)py_pdb_get_trusted_domain_by_sid
, METH_VARARGS
,
3549 "get_trusted_domain_by_sid(domain_sid) -> Mapping\n\n \
3550 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" },
3551 { "set_trusted_domain", (PyCFunction
)py_pdb_set_trusted_domain
, METH_VARARGS
,
3552 "set_trusted_domain(domain, Mapping) -> None\n\n \
3553 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." },
3554 { "del_trusted_domain", (PyCFunction
)py_pdb_del_trusted_domain
, METH_VARARGS
,
3555 "del_trusted_domain(domain) -> None\n\n \
3556 Delete trusted domain." },
3557 { "enum_trusted_domains", (PyCFunction
)py_pdb_enum_trusted_domains
, METH_VARARGS
,
3558 "enum_trusted_domains() -> List\n\n \
3559 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." },
3560 { "get_secret", (PyCFunction
)py_pdb_get_secret
, METH_VARARGS
,
3561 "get_secret(secret_name) -> Mapping\n\n \
3562 Get secret information for secret_name. Information is a dictionary with keys - secret_current, secret_current_lastchange, secret_old, secret_old_lastchange, sd." },
3563 { "set_secret", (PyCFunction
)py_pdb_set_secret
, METH_VARARGS
,
3564 "set_secret(secret_name, Mapping) -> None\n\n \
3565 Set secret information for secret_name using dictionary with keys - secret_current, sd." },
3566 { "delete_secret", (PyCFunction
)py_pdb_delete_secret
, METH_VARARGS
,
3567 "delete_secret(secret_name) -> None\n\n \
3568 Delete secret information for secret_name." },
3573 static PyObject
*py_pdb_new(PyTypeObject
*type
, PyObject
*args
, PyObject
*kwargs
)
3575 const char *url
= NULL
;
3578 struct pdb_methods
*methods
;
3580 if (!PyArg_ParseTuple(args
, "s", &url
)) {
3584 /* Initalize list of methods */
3585 status
= make_pdb_method_name(&methods
, url
);
3586 if (!NT_STATUS_IS_OK(status
)) {
3587 PyErr_Format(py_pdb_error
, "Cannot load backend methods for '%s' backend (%d,%s)",
3589 NT_STATUS_V(status
),
3590 get_friendly_nt_error_msg(status
));
3594 if ((pypdb
= pytalloc_steal(type
, methods
)) == NULL
) {
3603 static PyTypeObject PyPDB
= {
3604 .tp_name
= "passdb.PDB",
3605 .tp_basicsize
= sizeof(pytalloc_Object
),
3606 .tp_new
= py_pdb_new
,
3607 .tp_flags
= Py_TPFLAGS_DEFAULT
,
3608 .tp_methods
= py_pdb_methods
,
3609 .tp_doc
= "PDB(url[, read_write_flags]) -> Password DB object\n",
3614 * Return a list of passdb backends
3616 static PyObject
*py_passdb_backends(PyObject
*self
)
3619 const struct pdb_init_function_entry
*entry
;
3622 if ((tframe
= talloc_stackframe()) == NULL
) {
3627 entry
= pdb_get_backends();
3632 if((py_blist
= PyList_New(0)) == NULL
) {
3638 PyList_Append(py_blist
, PyString_FromString(entry
->name
));
3639 entry
= entry
->next
;
3642 talloc_free(tframe
);
3648 static PyObject
*py_set_smb_config(PyObject
*self
, PyObject
*args
)
3650 const char *smb_config
;
3653 if (!PyArg_ParseTuple(args
, "s", &smb_config
)) {
3657 if ((tframe
= talloc_stackframe()) == NULL
) {
3662 /* Load smbconf parameters */
3663 if (!lp_load_global(smb_config
)) {
3664 PyErr_Format(py_pdb_error
, "Cannot open '%s'", smb_config
);
3668 talloc_free(tframe
);
3674 static PyObject
*py_set_secrets_dir(PyObject
*self
, PyObject
*args
)
3676 const char *private_dir
;
3679 if (!PyArg_ParseTuple(args
, "s", &private_dir
)) {
3683 if ((tframe
= talloc_stackframe()) == NULL
) {
3688 /* Initialize secrets database */
3689 if (!secrets_init_path(private_dir
)) {
3690 PyErr_Format(py_pdb_error
, "Cannot open secrets file database in '%s'",
3695 talloc_free(tframe
);
3700 static PyObject
*py_get_global_sam_sid(PyObject
*self
)
3702 struct dom_sid
*domain_sid
, *domain_sid_copy
;
3704 PyObject
*py_dom_sid
;
3706 tframe
= talloc_stackframe();
3707 if (tframe
== NULL
) {
3712 domain_sid
= get_global_sam_sid();
3714 domain_sid_copy
= dom_sid_dup(tframe
, domain_sid
);
3715 if (domain_sid_copy
== NULL
) {
3717 talloc_free(tframe
);
3721 py_dom_sid
= pytalloc_steal(dom_sid_Type
, domain_sid_copy
);
3723 talloc_free(tframe
);
3729 static PyMethodDef py_passdb_methods
[] = {
3730 { "get_backends", (PyCFunction
)py_passdb_backends
, METH_NOARGS
,
3731 "get_backends() -> list\n\n \
3732 Get a list of password database backends supported." },
3733 { "set_smb_config", (PyCFunction
)py_set_smb_config
, METH_VARARGS
,
3734 "set_smb_config(path) -> None\n\n \
3735 Set path to smb.conf file to load configuration parameters." },
3736 { "set_secrets_dir", (PyCFunction
)py_set_secrets_dir
, METH_VARARGS
,
3737 "set_secrets_dir(private_dir) -> None\n\n \
3738 Set path to private directory to load secrets database from non-default location." },
3739 { "get_global_sam_sid", (PyCFunction
)py_get_global_sam_sid
, METH_NOARGS
,
3740 "get_global_sam_sid() -> dom_sid\n\n \
3741 Return domain SID." },
3745 void initpassdb(void)
3748 char exception_name
[] = "passdb.error";
3750 PyTypeObject
*talloc_type
= pytalloc_GetObjectType();
3751 if (talloc_type
== NULL
) {
3755 PyPDB
.tp_base
= talloc_type
;
3756 if (PyType_Ready(&PyPDB
) < 0) {
3760 PySamu
.tp_base
= talloc_type
;
3761 if (PyType_Ready(&PySamu
) < 0) {
3765 PyGroupmap
.tp_base
= talloc_type
;
3766 if (PyType_Ready(&PyGroupmap
) < 0) {
3770 m
= Py_InitModule3("passdb", py_passdb_methods
, "SAMBA Password Database");
3775 /* Create new exception for passdb module */
3776 py_pdb_error
= PyErr_NewException(exception_name
, NULL
, NULL
);
3777 Py_INCREF(py_pdb_error
);
3778 PyModule_AddObject(m
, "error", py_pdb_error
);
3781 PyModule_AddObject(m
, "PDB", (PyObject
*)&PyPDB
);
3784 PyModule_AddObject(m
, "Samu", (PyObject
*)&PySamu
);
3786 Py_INCREF(&PyGroupmap
);
3787 PyModule_AddObject(m
, "Groupmap", (PyObject
*)&PyGroupmap
);
3789 /* Import dom_sid type from dcerpc.security */
3790 mod
= PyImport_ImportModule("samba.dcerpc.security");
3795 dom_sid_Type
= (PyTypeObject
*)PyObject_GetAttrString(mod
, "dom_sid");
3796 if (dom_sid_Type
== NULL
) {
3800 /* Import security_descriptor type from dcerpc.security */
3801 security_Type
= (PyTypeObject
*)PyObject_GetAttrString(mod
, "descriptor");
3803 if (security_Type
== NULL
) {
3807 /* Import GUID type from dcerpc.misc */
3808 mod
= PyImport_ImportModule("samba.dcerpc.misc");
3813 guid_Type
= (PyTypeObject
*)PyObject_GetAttrString(mod
, "GUID");
3815 if (guid_Type
== NULL
) {