Line data Source code
1 : /*
2 : Python interface to passdb
3 :
4 : Copyright (C) Amitay Isaacs 2011
5 :
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.
10 :
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.
15 :
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/>.
18 : */
19 :
20 : #include "lib/replace/system/python.h"
21 : #include <pytalloc.h>
22 : #include "includes.h"
23 : #include "python/py3compat.h"
24 : #include "lib/util/talloc_stack.h"
25 : #include "libcli/security/security.h"
26 : #include "librpc/gen_ndr/idmap.h"
27 : #include "passdb.h"
28 : #include "secrets.h"
29 : #include "idmap.h"
30 : #include "lib/util/string_wrappers.h"
31 :
32 : #ifndef Py_TYPE /* Py_TYPE is only available on Python > 2.6 */
33 : #define Py_TYPE(ob) (((PyObject*)(ob))->ob_type)
34 : #endif
35 :
36 : #ifndef PY_CHECK_TYPE
37 : #define PY_CHECK_TYPE(type, var, fail) \
38 : if (!PyObject_TypeCheck(var, type)) {\
39 : PyErr_Format(PyExc_TypeError, __location__ ": Expected type '%s' for '%s' of type '%s'", (type)->tp_name, #var, Py_TYPE(var)->tp_name); \
40 : fail; \
41 : }
42 : #endif
43 :
44 :
45 : static PyTypeObject *dom_sid_Type = NULL;
46 : static PyTypeObject *security_Type = NULL;
47 : static PyTypeObject *guid_Type = NULL;
48 :
49 : static PyTypeObject PySamu;
50 : static PyTypeObject PyGroupmap;
51 : static PyTypeObject PyPDB;
52 :
53 : static PyObject *py_pdb_error;
54 :
55 : void initpassdb(void);
56 :
57 :
58 : /************************** PIDL Autogeneratd ******************************/
59 :
60 1 : static PyObject *py_samu_get_logon_time(PyObject *obj, void *closure)
61 : {
62 1 : TALLOC_CTX *frame = talloc_stackframe();
63 1 : struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj);
64 1 : PyObject *py_logon_time;
65 :
66 1 : py_logon_time = PyLong_FromLong(pdb_get_logon_time(sam_acct));
67 1 : talloc_free(frame);
68 1 : return py_logon_time;
69 : }
70 :
71 0 : static int py_samu_set_logon_time(PyObject *obj, PyObject *value, void *closure)
72 : {
73 0 : TALLOC_CTX *frame = talloc_stackframe();
74 0 : struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj);
75 :
76 0 : PY_CHECK_TYPE(&PyLong_Type, value, return -1;);
77 0 : if (!pdb_set_logon_time(sam_acct, PyLong_AsLong(value), PDB_CHANGED)) {
78 0 : talloc_free(frame);
79 0 : return -1;
80 : }
81 0 : talloc_free(frame);
82 0 : return 0;
83 : }
84 :
85 1 : static PyObject *py_samu_get_logoff_time(PyObject *obj, void *closure)
86 : {
87 1 : TALLOC_CTX *frame = talloc_stackframe();
88 1 : struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj);
89 1 : PyObject *py_logoff_time;
90 :
91 1 : py_logoff_time = PyLong_FromLong(pdb_get_logoff_time(sam_acct));
92 1 : talloc_free(frame);
93 1 : return py_logoff_time;
94 : }
95 :
96 0 : static int py_samu_set_logoff_time(PyObject *obj, PyObject *value, void *closure)
97 : {
98 0 : TALLOC_CTX *frame = talloc_stackframe();
99 0 : struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj);
100 :
101 0 : PY_CHECK_TYPE(&PyLong_Type, value, return -1;);
102 0 : if (!pdb_set_logoff_time(sam_acct, PyLong_AsLong(value), PDB_CHANGED)) {
103 0 : talloc_free(frame);
104 0 : return -1;
105 : }
106 0 : talloc_free(frame);
107 0 : return 0;
108 : }
109 :
110 1 : static PyObject *py_samu_get_kickoff_time(PyObject *obj, void *closure)
111 : {
112 1 : TALLOC_CTX *frame = talloc_stackframe();
113 1 : struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj);
114 1 : PyObject *py_kickoff_time;
115 :
116 1 : py_kickoff_time = PyLong_FromLong(pdb_get_kickoff_time(sam_acct));
117 1 : talloc_free(frame);
118 1 : return py_kickoff_time;
119 : }
120 :
121 0 : static int py_samu_set_kickoff_time(PyObject *obj, PyObject *value, void *closure)
122 : {
123 0 : TALLOC_CTX *frame = talloc_stackframe();
124 0 : struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj);
125 :
126 0 : PY_CHECK_TYPE(&PyLong_Type, value, return -1;);
127 0 : if (!pdb_set_kickoff_time(sam_acct, PyLong_AsLong(value), PDB_CHANGED)) {
128 0 : talloc_free(frame);
129 0 : return -1;
130 : }
131 0 : talloc_free(frame);
132 0 : return 0;
133 : }
134 :
135 1 : static PyObject *py_samu_get_bad_password_time(PyObject *obj, void *closure)
136 : {
137 1 : TALLOC_CTX *frame = talloc_stackframe();
138 1 : struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj);
139 1 : PyObject *py_bad_password_time;
140 :
141 1 : py_bad_password_time = PyLong_FromLong(pdb_get_bad_password_time(sam_acct));
142 1 : talloc_free(frame);
143 1 : return py_bad_password_time;
144 : }
145 :
146 0 : static int py_samu_set_bad_password_time(PyObject *obj, PyObject *value, void *closure)
147 : {
148 0 : TALLOC_CTX *frame = talloc_stackframe();
149 0 : struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj);
150 :
151 0 : PY_CHECK_TYPE(&PyLong_Type, value, return -1;);
152 0 : if (!pdb_set_bad_password_time(sam_acct, PyLong_AsLong(value), PDB_CHANGED)) {
153 0 : talloc_free(frame);
154 0 : return -1;
155 : }
156 0 : talloc_free(frame);
157 0 : return 0;
158 : }
159 :
160 4 : static PyObject *py_samu_get_pass_last_set_time(PyObject *obj, void *closure)
161 : {
162 4 : TALLOC_CTX *frame = talloc_stackframe();
163 4 : struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj);
164 4 : PyObject *py_pass_last_set_time;
165 :
166 4 : py_pass_last_set_time = PyLong_FromLong(pdb_get_pass_last_set_time(sam_acct));
167 4 : talloc_free(frame);
168 4 : return py_pass_last_set_time;
169 : }
170 :
171 3 : static int py_samu_set_pass_last_set_time(PyObject *obj, PyObject *value, void *closure)
172 : {
173 3 : TALLOC_CTX *frame = talloc_stackframe();
174 3 : struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj);
175 :
176 3 : PY_CHECK_TYPE(&PyLong_Type, value, return -1;);
177 3 : if (!pdb_set_pass_last_set_time(sam_acct, PyLong_AsLong(value), PDB_CHANGED)) {
178 0 : talloc_free(frame);
179 0 : return -1;
180 : }
181 3 : talloc_free(frame);
182 3 : return 0;
183 : }
184 :
185 1 : static PyObject *py_samu_get_pass_can_change_time(PyObject *obj, void *closure)
186 : {
187 1 : TALLOC_CTX *frame = talloc_stackframe();
188 1 : struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj);
189 1 : PyObject *py_pass_can_change_time;
190 :
191 1 : py_pass_can_change_time = PyLong_FromLong(pdb_get_pass_can_change_time(sam_acct));
192 1 : talloc_free(frame);
193 1 : return py_pass_can_change_time;
194 : }
195 :
196 0 : static int py_samu_set_pass_can_change_time(PyObject *obj, PyObject *value, void *closure)
197 : {
198 0 : TALLOC_CTX *frame = talloc_stackframe();
199 0 : struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj);
200 :
201 0 : PY_CHECK_TYPE(&PyLong_Type, value, return -1;);
202 0 : if (!pdb_set_pass_can_change_time(sam_acct, PyLong_AsLong(value), PDB_CHANGED)) {
203 0 : talloc_free(frame);
204 0 : return -1;
205 : }
206 0 : talloc_free(frame);
207 0 : return 0;
208 : }
209 :
210 1 : static PyObject *py_samu_get_pass_must_change_time(PyObject *obj, void *closure)
211 : {
212 1 : TALLOC_CTX *frame = talloc_stackframe();
213 1 : struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj);
214 1 : PyObject *py_pass_must_change_time;
215 :
216 1 : py_pass_must_change_time = PyLong_FromLong(pdb_get_pass_must_change_time(sam_acct));
217 1 : talloc_free(frame);
218 1 : return py_pass_must_change_time;
219 : }
220 :
221 0 : static int py_samu_set_pass_must_change_time(PyObject *obj, PyObject *value, void *closure)
222 : {
223 0 : TALLOC_CTX *frame = talloc_stackframe();
224 0 : PY_CHECK_TYPE(&PyLong_Type, value, return -1;);
225 :
226 : /* TODO: make this not a get/set or give a better exception */
227 0 : talloc_free(frame);
228 0 : return -1;
229 : }
230 :
231 1 : static PyObject *py_samu_get_username(PyObject *obj, void *closure)
232 : {
233 1 : TALLOC_CTX *frame = talloc_stackframe();
234 1 : struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj);
235 1 : PyObject *py_username;
236 1 : const char *username;
237 :
238 1 : username = pdb_get_username(sam_acct);
239 1 : if (username == NULL) {
240 0 : Py_RETURN_NONE;
241 : }
242 :
243 1 : py_username = PyUnicode_FromString(username);
244 1 : talloc_free(frame);
245 1 : return py_username;
246 : }
247 :
248 0 : static int py_samu_set_username(PyObject *obj, PyObject *value, void *closure)
249 : {
250 0 : TALLOC_CTX *frame = talloc_stackframe();
251 0 : struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj);
252 :
253 0 : PY_CHECK_TYPE(&PyUnicode_Type, value, return -1;);
254 0 : if (!pdb_set_username(sam_acct, PyUnicode_AsUTF8(value), PDB_CHANGED)) {
255 0 : talloc_free(frame);
256 0 : return -1;
257 : }
258 0 : talloc_free(frame);
259 0 : return 0;
260 : }
261 :
262 1 : static PyObject *py_samu_get_domain(PyObject *obj, void *closure)
263 : {
264 1 : TALLOC_CTX *frame = talloc_stackframe();
265 1 : struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj);
266 1 : PyObject *py_domain;
267 1 : const char *domain;
268 :
269 1 : domain = pdb_get_domain(sam_acct);
270 1 : if (domain == NULL) {
271 0 : Py_RETURN_NONE;
272 : }
273 :
274 1 : py_domain = PyUnicode_FromString(domain);
275 1 : talloc_free(frame);
276 1 : return py_domain;
277 : }
278 :
279 0 : static int py_samu_set_domain(PyObject *obj, PyObject *value, void *closure)
280 : {
281 0 : TALLOC_CTX *frame = talloc_stackframe();
282 0 : struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj);
283 :
284 0 : PY_CHECK_TYPE(&PyUnicode_Type, value, return -1;);
285 0 : if (!pdb_set_domain(sam_acct, PyUnicode_AsUTF8(value), PDB_CHANGED)) {
286 0 : talloc_free(frame);
287 0 : return -1;
288 : }
289 0 : talloc_free(frame);
290 0 : return 0;
291 : }
292 :
293 1 : static PyObject *py_samu_get_nt_username(PyObject *obj, void *closure)
294 : {
295 1 : TALLOC_CTX *frame = talloc_stackframe();
296 1 : struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj);
297 1 : PyObject *py_nt_username;
298 1 : const char *nt_username;
299 :
300 1 : nt_username = pdb_get_nt_username(sam_acct);
301 1 : if (nt_username == NULL) {
302 0 : Py_RETURN_NONE;
303 : }
304 :
305 1 : py_nt_username = PyUnicode_FromString(nt_username);
306 1 : talloc_free(frame);
307 1 : return py_nt_username;
308 : }
309 :
310 0 : static int py_samu_set_nt_username(PyObject *obj, PyObject *value, void *closure)
311 : {
312 0 : TALLOC_CTX *frame = talloc_stackframe();
313 0 : struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj);
314 :
315 0 : PY_CHECK_TYPE(&PyUnicode_Type, value, return -1;);
316 0 : if (!pdb_set_nt_username(sam_acct, PyUnicode_AsUTF8(value), PDB_CHANGED)) {
317 0 : talloc_free(frame);
318 0 : return -1;
319 : }
320 0 : talloc_free(frame);
321 0 : return 0;
322 : }
323 :
324 1 : static PyObject *py_samu_get_full_name(PyObject *obj, void *closure)
325 : {
326 1 : TALLOC_CTX *frame = talloc_stackframe();
327 1 : struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj);
328 1 : PyObject *py_full_name;
329 1 : const char *full_name;
330 :
331 1 : full_name = pdb_get_fullname(sam_acct);
332 1 : if (full_name == NULL) {
333 0 : Py_RETURN_NONE;
334 : }
335 :
336 1 : py_full_name = PyUnicode_FromString(full_name);
337 1 : talloc_free(frame);
338 1 : return py_full_name;
339 : }
340 :
341 0 : static int py_samu_set_full_name(PyObject *obj, PyObject *value, void *closure)
342 : {
343 0 : TALLOC_CTX *frame = talloc_stackframe();
344 0 : struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj);
345 :
346 0 : PY_CHECK_TYPE(&PyUnicode_Type, value, return -1;);
347 0 : if (!pdb_set_fullname(sam_acct, PyUnicode_AsUTF8(value), PDB_CHANGED)) {
348 0 : talloc_free(frame);
349 0 : return -1;
350 : }
351 0 : talloc_free(frame);
352 0 : return 0;
353 : }
354 :
355 1 : static PyObject *py_samu_get_home_dir(PyObject *obj, void *closure)
356 : {
357 1 : TALLOC_CTX *frame = talloc_stackframe();
358 1 : struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj);
359 1 : PyObject *py_home_dir;
360 1 : const char *home_dir;
361 :
362 1 : home_dir = pdb_get_homedir(sam_acct);
363 1 : if (home_dir == NULL) {
364 0 : Py_RETURN_NONE;
365 : }
366 :
367 1 : py_home_dir = PyUnicode_FromString(home_dir);
368 1 : talloc_free(frame);
369 1 : return py_home_dir;
370 : }
371 :
372 0 : static int py_samu_set_home_dir(PyObject *obj, PyObject *value, void *closure)
373 : {
374 0 : TALLOC_CTX *frame = talloc_stackframe();
375 0 : struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj);
376 :
377 0 : PY_CHECK_TYPE(&PyUnicode_Type, value, return -1;);
378 0 : if (!pdb_set_homedir(sam_acct, PyUnicode_AsUTF8(value), PDB_CHANGED)) {
379 0 : talloc_free(frame);
380 0 : return -1;
381 : }
382 0 : talloc_free(frame);
383 0 : return 0;
384 : }
385 :
386 1 : static PyObject *py_samu_get_dir_drive(PyObject *obj, void *closure)
387 : {
388 1 : TALLOC_CTX *frame = talloc_stackframe();
389 1 : struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj);
390 1 : PyObject *py_dir_drive;
391 1 : const char *dir_drive;
392 :
393 1 : dir_drive = pdb_get_dir_drive(sam_acct);
394 1 : if (dir_drive == NULL) {
395 0 : Py_RETURN_NONE;
396 : }
397 :
398 1 : py_dir_drive = PyUnicode_FromString(dir_drive);
399 1 : talloc_free(frame);
400 1 : return py_dir_drive;
401 : }
402 :
403 0 : static int py_samu_set_dir_drive(PyObject *obj, PyObject *value, void *closure)
404 : {
405 0 : TALLOC_CTX *frame = talloc_stackframe();
406 0 : struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj);
407 :
408 0 : PY_CHECK_TYPE(&PyUnicode_Type, value, return -1;);
409 0 : if (!pdb_set_dir_drive(sam_acct, PyUnicode_AsUTF8(value), PDB_CHANGED)) {
410 0 : talloc_free(frame);
411 0 : return -1;
412 : }
413 0 : talloc_free(frame);
414 0 : return 0;
415 : }
416 :
417 1 : static PyObject *py_samu_get_logon_script(PyObject *obj, void *closure)
418 : {
419 1 : TALLOC_CTX *frame = talloc_stackframe();
420 1 : struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj);
421 1 : PyObject *py_logon_script;
422 1 : const char *logon_script;
423 :
424 1 : logon_script = pdb_get_logon_script(sam_acct);
425 1 : if (logon_script == NULL) {
426 0 : Py_RETURN_NONE;
427 : }
428 :
429 1 : py_logon_script = PyUnicode_FromString(logon_script);
430 1 : talloc_free(frame);
431 1 : return py_logon_script;
432 : }
433 :
434 0 : static int py_samu_set_logon_script(PyObject *obj, PyObject *value, void *closure)
435 : {
436 0 : TALLOC_CTX *frame = talloc_stackframe();
437 0 : struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj);
438 :
439 0 : PY_CHECK_TYPE(&PyUnicode_Type, value, return -1;);
440 0 : if (!pdb_set_logon_script(sam_acct, PyUnicode_AsUTF8(value), PDB_CHANGED)) {
441 0 : talloc_free(frame);
442 0 : return -1;
443 : }
444 0 : talloc_free(frame);
445 0 : return 0;
446 : }
447 :
448 1 : static PyObject *py_samu_get_profile_path(PyObject *obj, void *closure)
449 : {
450 1 : TALLOC_CTX *frame = talloc_stackframe();
451 1 : struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj);
452 1 : PyObject *py_profile_path;
453 1 : const char *profile_path;
454 :
455 1 : profile_path = pdb_get_profile_path(sam_acct);
456 1 : if (profile_path == NULL) {
457 0 : Py_RETURN_NONE;
458 : }
459 :
460 1 : py_profile_path = PyUnicode_FromString(profile_path);
461 1 : talloc_free(frame);
462 1 : return py_profile_path;
463 : }
464 :
465 0 : static int py_samu_set_profile_path(PyObject *obj, PyObject *value, void *closure)
466 : {
467 0 : TALLOC_CTX *frame = talloc_stackframe();
468 0 : struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj);
469 :
470 0 : PY_CHECK_TYPE(&PyUnicode_Type, value, return -1;);
471 0 : if (!pdb_set_profile_path(sam_acct, PyUnicode_AsUTF8(value), PDB_CHANGED)) {
472 0 : talloc_free(frame);
473 0 : return -1;
474 : }
475 0 : talloc_free(frame);
476 0 : return 0;
477 : }
478 :
479 1 : static PyObject *py_samu_get_acct_desc(PyObject *obj, void *closure)
480 : {
481 1 : TALLOC_CTX *frame = talloc_stackframe();
482 1 : struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj);
483 1 : PyObject *py_acct_desc;
484 1 : const char *acct_desc;
485 :
486 1 : acct_desc = pdb_get_acct_desc(sam_acct);
487 1 : if (acct_desc == NULL) {
488 0 : Py_RETURN_NONE;
489 : }
490 :
491 1 : py_acct_desc = PyUnicode_FromString(acct_desc);
492 1 : talloc_free(frame);
493 1 : return py_acct_desc;
494 : }
495 :
496 0 : static int py_samu_set_acct_desc(PyObject *obj, PyObject *value, void *closure)
497 : {
498 0 : TALLOC_CTX *frame = talloc_stackframe();
499 0 : struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj);
500 :
501 0 : PY_CHECK_TYPE(&PyUnicode_Type, value, return -1;);
502 0 : if (!pdb_set_acct_desc(sam_acct, PyUnicode_AsUTF8(value), PDB_CHANGED)) {
503 0 : talloc_free(frame);
504 0 : return -1;
505 : }
506 0 : talloc_free(frame);
507 0 : return 0;
508 : }
509 :
510 1 : static PyObject *py_samu_get_workstations(PyObject *obj, void *closure)
511 : {
512 1 : TALLOC_CTX *frame = talloc_stackframe();
513 1 : struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj);
514 1 : PyObject *py_workstations;
515 1 : const char *workstations;
516 :
517 1 : workstations = pdb_get_workstations(sam_acct);
518 1 : if (workstations == NULL) {
519 0 : Py_RETURN_NONE;
520 : }
521 :
522 1 : py_workstations = PyUnicode_FromString(workstations);
523 1 : talloc_free(frame);
524 1 : return py_workstations;
525 : }
526 :
527 0 : static int py_samu_set_workstations(PyObject *obj, PyObject *value, void *closure)
528 : {
529 0 : TALLOC_CTX *frame = talloc_stackframe();
530 0 : struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj);
531 :
532 0 : PY_CHECK_TYPE(&PyUnicode_Type, value, return -1;);
533 0 : if (!pdb_set_workstations(sam_acct, PyUnicode_AsUTF8(value), PDB_CHANGED)) {
534 0 : talloc_free(frame);
535 0 : return -1;
536 : }
537 0 : talloc_free(frame);
538 0 : return 0;
539 : }
540 :
541 0 : static PyObject *py_samu_get_comment(PyObject *obj, void *closure)
542 : {
543 0 : TALLOC_CTX *frame = talloc_stackframe();
544 0 : struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj);
545 0 : PyObject *py_comment;
546 0 : const char *comment;
547 :
548 0 : comment = pdb_get_comment(sam_acct);
549 0 : if (comment == NULL) {
550 0 : Py_RETURN_NONE;
551 : }
552 :
553 0 : py_comment = PyUnicode_FromString(comment);
554 0 : talloc_free(frame);
555 0 : return py_comment;
556 : }
557 :
558 0 : static int py_samu_set_comment(PyObject *obj, PyObject *value, void *closure)
559 : {
560 0 : TALLOC_CTX *frame = talloc_stackframe();
561 0 : struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj);
562 :
563 0 : PY_CHECK_TYPE(&PyUnicode_Type, value, return -1;);
564 0 : if (!pdb_set_comment(sam_acct, PyUnicode_AsUTF8(value), PDB_CHANGED)) {
565 0 : talloc_free(frame);
566 0 : return -1;
567 : }
568 0 : talloc_free(frame);
569 0 : return 0;
570 : }
571 :
572 1 : static PyObject *py_samu_get_munged_dial(PyObject *obj, void *closure)
573 : {
574 1 : TALLOC_CTX *frame = talloc_stackframe();
575 1 : struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj);
576 1 : PyObject *py_munged_dial;
577 1 : const char *munged_dial;
578 :
579 1 : munged_dial = pdb_get_munged_dial(sam_acct);
580 1 : if (munged_dial == NULL) {
581 0 : Py_RETURN_NONE;
582 : }
583 :
584 1 : py_munged_dial = PyUnicode_FromString(munged_dial);
585 1 : talloc_free(frame);
586 1 : return py_munged_dial;
587 : }
588 :
589 0 : static int py_samu_set_munged_dial(PyObject *obj, PyObject *value, void *closure)
590 : {
591 0 : TALLOC_CTX *frame = talloc_stackframe();
592 0 : struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj);
593 :
594 0 : PY_CHECK_TYPE(&PyUnicode_Type, value, return -1;);
595 0 : if (!pdb_set_munged_dial(sam_acct, PyUnicode_AsUTF8(value), PDB_CHANGED)) {
596 0 : talloc_free(frame);
597 0 : return -1;
598 : }
599 0 : talloc_free(frame);
600 0 : return 0;
601 : }
602 :
603 22 : static PyObject *py_samu_get_user_sid(PyObject *obj, void *closure)
604 : {
605 22 : TALLOC_CTX *frame = talloc_stackframe();
606 22 : struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj);
607 22 : PyObject *py_user_sid;
608 22 : const struct dom_sid *user_sid;
609 22 : struct dom_sid *copy_user_sid;
610 22 : TALLOC_CTX *mem_ctx;
611 :
612 22 : user_sid = pdb_get_user_sid(sam_acct);
613 22 : if(user_sid == NULL) {
614 0 : Py_RETURN_NONE;
615 : }
616 :
617 22 : mem_ctx = talloc_new(NULL);
618 22 : if (mem_ctx == NULL) {
619 0 : PyErr_NoMemory();
620 0 : talloc_free(frame);
621 0 : return NULL;
622 : }
623 22 : copy_user_sid = dom_sid_dup(mem_ctx, user_sid);
624 22 : if (copy_user_sid == NULL) {
625 0 : PyErr_NoMemory();
626 0 : talloc_free(mem_ctx);
627 0 : talloc_free(frame);
628 0 : return NULL;
629 : }
630 :
631 22 : py_user_sid = pytalloc_steal(dom_sid_Type, copy_user_sid);
632 :
633 22 : talloc_free(mem_ctx);
634 :
635 22 : talloc_free(frame);
636 22 : return py_user_sid;
637 : }
638 :
639 0 : static int py_samu_set_user_sid(PyObject *obj, PyObject *value, void *closure)
640 : {
641 0 : TALLOC_CTX *frame = talloc_stackframe();
642 0 : struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj);
643 :
644 0 : PY_CHECK_TYPE(dom_sid_Type, value, return -1;);
645 0 : if (!pdb_set_user_sid(sam_acct, (struct dom_sid *)pytalloc_get_ptr(value), PDB_CHANGED)) {
646 0 : talloc_free(frame);
647 0 : return -1;
648 : }
649 0 : talloc_free(frame);
650 0 : return 0;
651 : }
652 :
653 1 : static PyObject *py_samu_get_group_sid(PyObject *obj, void *closure)
654 : {
655 1 : TALLOC_CTX *frame = talloc_stackframe();
656 1 : struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj);
657 1 : const struct dom_sid *group_sid;
658 1 : struct dom_sid *copy_group_sid;
659 :
660 1 : group_sid = pdb_get_group_sid(sam_acct);
661 1 : if (group_sid == NULL) {
662 0 : Py_RETURN_NONE;
663 : }
664 :
665 1 : copy_group_sid = dom_sid_dup(NULL, group_sid);
666 1 : if (copy_group_sid == NULL) {
667 0 : PyErr_NoMemory();
668 0 : talloc_free(frame);
669 0 : return NULL;
670 : }
671 :
672 1 : talloc_free(frame);
673 1 : return pytalloc_steal(dom_sid_Type, copy_group_sid);
674 : }
675 :
676 0 : static int py_samu_set_group_sid(PyObject *obj, PyObject *value, void *closure)
677 : {
678 0 : TALLOC_CTX *frame = talloc_stackframe();
679 0 : struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj);
680 :
681 0 : PY_CHECK_TYPE(dom_sid_Type, value, return -1;);
682 0 : if (!pdb_set_group_sid(sam_acct, (struct dom_sid *)pytalloc_get_ptr(value), PDB_CHANGED)) {
683 0 : talloc_free(frame);
684 0 : return -1;
685 : }
686 0 : talloc_free(frame);
687 0 : return 0;
688 : }
689 :
690 4 : static PyObject *py_samu_get_lanman_passwd(PyObject *obj, void *closure)
691 : {
692 4 : TALLOC_CTX *frame = talloc_stackframe();
693 4 : struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj);
694 4 : PyObject *py_lm_pw;
695 4 : const char *lm_pw;
696 :
697 4 : lm_pw = (const char *)pdb_get_lanman_passwd(sam_acct);
698 4 : if (lm_pw == NULL) {
699 4 : Py_RETURN_NONE;
700 : }
701 :
702 0 : py_lm_pw = PyBytes_FromStringAndSize(lm_pw, LM_HASH_LEN);
703 0 : talloc_free(frame);
704 0 : return py_lm_pw;
705 : }
706 :
707 0 : static int py_samu_set_lanman_passwd(PyObject *obj, PyObject *value, void *closure)
708 : {
709 0 : TALLOC_CTX *frame = talloc_stackframe();
710 0 : struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj);
711 :
712 0 : PY_CHECK_TYPE(&PyBytes_Type, value, return -1;);
713 0 : if (!pdb_set_lanman_passwd(sam_acct, (uint8_t *)PyBytes_AsString(value), PDB_CHANGED)) {
714 0 : talloc_free(frame);
715 0 : return -1;
716 : }
717 0 : talloc_free(frame);
718 0 : return 0;
719 : }
720 :
721 4 : static PyObject *py_samu_get_nt_passwd(PyObject *obj, void *closure)
722 : {
723 4 : TALLOC_CTX *frame = talloc_stackframe();
724 4 : struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj);
725 4 : PyObject *py_nt_pw;
726 4 : const char *nt_pw;
727 :
728 4 : nt_pw = (const char *)pdb_get_nt_passwd(sam_acct);
729 4 : if (nt_pw == NULL) {
730 0 : Py_RETURN_NONE;
731 : }
732 :
733 4 : py_nt_pw = PyBytes_FromStringAndSize(nt_pw, NT_HASH_LEN);
734 4 : talloc_free(frame);
735 4 : return py_nt_pw;
736 : }
737 :
738 3 : static int py_samu_set_nt_passwd(PyObject *obj, PyObject *value, void *closure)
739 : {
740 3 : TALLOC_CTX *frame = talloc_stackframe();
741 3 : struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj);
742 :
743 3 : if (!pdb_set_nt_passwd(sam_acct, (uint8_t *)PyBytes_AsString(value), PDB_CHANGED)) {
744 0 : talloc_free(frame);
745 0 : return -1;
746 : }
747 3 : talloc_free(frame);
748 3 : return 0;
749 : }
750 :
751 4 : static PyObject *py_samu_get_pw_history(PyObject *obj, void *closure)
752 : {
753 4 : TALLOC_CTX *frame = talloc_stackframe();
754 4 : struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj);
755 4 : PyObject *py_nt_pw_his;
756 4 : const char *nt_pw_his;
757 4 : uint32_t hist_len;
758 :
759 4 : nt_pw_his = (const char *)pdb_get_pw_history(sam_acct, &hist_len);
760 4 : if (nt_pw_his == NULL) {
761 4 : Py_RETURN_NONE;
762 : }
763 :
764 0 : py_nt_pw_his = PyBytes_FromStringAndSize(nt_pw_his, hist_len*PW_HISTORY_ENTRY_LEN);
765 0 : talloc_free(frame);
766 0 : return py_nt_pw_his;
767 : }
768 :
769 0 : static int py_samu_set_pw_history(PyObject *obj, PyObject *value, void *closure)
770 : {
771 0 : TALLOC_CTX *frame = talloc_stackframe();
772 0 : struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj);
773 0 : char *nt_pw_his;
774 0 : Py_ssize_t len;
775 0 : uint32_t hist_len;
776 :
777 0 : PyBytes_AsStringAndSize(value, &nt_pw_his, &len);
778 0 : hist_len = len / PW_HISTORY_ENTRY_LEN;
779 0 : if (!pdb_set_pw_history(sam_acct, (uint8_t *)nt_pw_his, hist_len, PDB_CHANGED)) {
780 0 : talloc_free(frame);
781 0 : return -1;
782 : }
783 0 : talloc_free(frame);
784 0 : return 0;
785 : }
786 :
787 1 : static PyObject *py_samu_get_plaintext_passwd(PyObject *obj, void *closure)
788 : {
789 1 : TALLOC_CTX *frame = talloc_stackframe();
790 1 : struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj);
791 1 : PyObject *py_plaintext_pw;
792 1 : const char *plaintext_pw;
793 :
794 1 : plaintext_pw = pdb_get_plaintext_passwd(sam_acct);
795 1 : if (plaintext_pw == NULL) {
796 1 : Py_RETURN_NONE;
797 : }
798 :
799 0 : py_plaintext_pw = PyUnicode_FromString(plaintext_pw);
800 :
801 0 : BURN_STR(discard_const_p(char, plaintext_pw));
802 0 : talloc_free(frame);
803 0 : return py_plaintext_pw;
804 : }
805 :
806 0 : static int py_samu_set_plaintext_passwd(PyObject *obj, PyObject *value, void *closure)
807 : {
808 0 : TALLOC_CTX *frame = talloc_stackframe();
809 0 : struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj);
810 :
811 0 : if (!pdb_set_plaintext_passwd(sam_acct, PyUnicode_AsUTF8(value))) {
812 0 : talloc_free(frame);
813 0 : return -1;
814 : }
815 0 : talloc_free(frame);
816 0 : return 0;
817 : }
818 :
819 7 : static PyObject *py_samu_get_acct_ctrl(PyObject *obj, void *closure)
820 : {
821 7 : TALLOC_CTX *frame = talloc_stackframe();
822 7 : struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj);
823 7 : PyObject *py_acct_ctrl;
824 :
825 7 : py_acct_ctrl = PyLong_FromLong(pdb_get_acct_ctrl(sam_acct));
826 7 : talloc_free(frame);
827 7 : return py_acct_ctrl;
828 : }
829 :
830 0 : static int py_samu_set_acct_ctrl(PyObject *obj, PyObject *value, void *closure)
831 : {
832 0 : TALLOC_CTX *frame = talloc_stackframe();
833 0 : struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj);
834 :
835 0 : PY_CHECK_TYPE(&PyLong_Type, value, return -1;);
836 0 : if (!pdb_set_acct_ctrl(sam_acct, PyLong_AsLong(value), PDB_CHANGED)) {
837 0 : talloc_free(frame);
838 0 : return -1;
839 : }
840 0 : talloc_free(frame);
841 0 : return 0;
842 : }
843 :
844 1 : static PyObject *py_samu_get_logon_divs(PyObject *obj, void *closure)
845 : {
846 1 : TALLOC_CTX *frame = talloc_stackframe();
847 1 : struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj);
848 1 : PyObject *py_logon_divs;
849 :
850 1 : py_logon_divs = PyLong_FromLong(pdb_get_logon_divs(sam_acct));
851 1 : talloc_free(frame);
852 1 : return py_logon_divs;
853 : }
854 :
855 0 : static int py_samu_set_logon_divs(PyObject *obj, PyObject *value, void *closure)
856 : {
857 0 : TALLOC_CTX *frame = talloc_stackframe();
858 0 : struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj);
859 :
860 0 : PY_CHECK_TYPE(&PyLong_Type, value, return -1;);
861 0 : if (!pdb_set_logon_divs(sam_acct, PyLong_AsLong(value), PDB_CHANGED)) {
862 0 : talloc_free(frame);
863 0 : return -1;
864 : }
865 0 : talloc_free(frame);
866 0 : return 0;
867 : }
868 :
869 1 : static PyObject *py_samu_get_hours_len(PyObject *obj, void *closure)
870 : {
871 1 : TALLOC_CTX *frame = talloc_stackframe();
872 1 : struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj);
873 1 : PyObject *py_hours_len;
874 :
875 1 : py_hours_len = PyLong_FromLong(pdb_get_hours_len(sam_acct));
876 1 : talloc_free(frame);
877 1 : return py_hours_len;
878 : }
879 :
880 0 : static int py_samu_set_hours_len(PyObject *obj, PyObject *value, void *closure)
881 : {
882 0 : TALLOC_CTX *frame = talloc_stackframe();
883 0 : struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj);
884 :
885 0 : PY_CHECK_TYPE(&PyLong_Type, value, return -1;);
886 0 : if (!pdb_set_hours_len(sam_acct, PyLong_AsLong(value), PDB_CHANGED)) {
887 0 : talloc_free(frame);
888 0 : return -1;
889 : }
890 0 : talloc_free(frame);
891 0 : return 0;
892 : }
893 :
894 1 : static PyObject *py_samu_get_hours(PyObject *obj, void *closure)
895 : {
896 1 : TALLOC_CTX *frame = talloc_stackframe();
897 1 : struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj);
898 1 : PyObject *py_hours;
899 1 : const char *hours;
900 1 : int hours_len, i;
901 :
902 1 : hours = (const char *)pdb_get_hours(sam_acct);
903 1 : if(! hours) {
904 0 : Py_RETURN_NONE;
905 : }
906 :
907 1 : hours_len = pdb_get_hours_len(sam_acct);
908 1 : if ((py_hours = PyList_New(hours_len)) == NULL) {
909 0 : PyErr_NoMemory();
910 0 : talloc_free(frame);
911 0 : return NULL;
912 : }
913 :
914 22 : for (i=0; i<hours_len; i++) {
915 21 : PyList_SetItem(py_hours, i, PyLong_FromLong(hours[i]));
916 : }
917 1 : talloc_free(frame);
918 1 : return py_hours;
919 : }
920 :
921 0 : static int py_samu_set_hours(PyObject *obj, PyObject *value, void *closure)
922 : {
923 0 : TALLOC_CTX *frame = talloc_stackframe();
924 0 : struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj);
925 0 : int i;
926 0 : uint8_t *hours;
927 0 : int hours_len;
928 0 : bool status;
929 :
930 0 : PY_CHECK_TYPE(&PyList_Type, value, return -1;);
931 :
932 0 : hours_len = PyList_GET_SIZE(value);
933 :
934 0 : hours = talloc_array(pytalloc_get_mem_ctx(obj), uint8_t, hours_len);
935 0 : if (!hours) {
936 0 : PyErr_NoMemory();
937 0 : talloc_free(frame);
938 0 : return -1;
939 : }
940 :
941 0 : for (i=0; i < hours_len; i++) {
942 0 : PY_CHECK_TYPE(&PyLong_Type, PyList_GET_ITEM(value,i), return -1;);
943 0 : hours[i] = PyLong_AsLong(PyList_GET_ITEM(value, i));
944 : }
945 :
946 0 : status = pdb_set_hours(sam_acct, hours, hours_len, PDB_CHANGED);
947 0 : talloc_free(hours);
948 :
949 0 : if(! status) {
950 0 : talloc_free(frame);
951 0 : return -1;
952 : }
953 0 : talloc_free(frame);
954 0 : return 0;
955 : }
956 :
957 1 : static PyObject *py_samu_get_bad_password_count(PyObject *obj, void *closure)
958 : {
959 1 : TALLOC_CTX *frame = talloc_stackframe();
960 1 : struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj);
961 1 : PyObject *py_bad_password_count;
962 :
963 1 : py_bad_password_count = PyLong_FromLong(pdb_get_bad_password_count(sam_acct));
964 1 : talloc_free(frame);
965 1 : return py_bad_password_count;
966 : }
967 :
968 0 : static int py_samu_set_bad_password_count(PyObject *obj, PyObject *value, void *closure)
969 : {
970 0 : TALLOC_CTX *frame = talloc_stackframe();
971 0 : struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj);
972 :
973 0 : PY_CHECK_TYPE(&PyLong_Type, value, return -1;);
974 0 : if (!pdb_set_bad_password_count(sam_acct, PyLong_AsLong(value), PDB_CHANGED)) {
975 0 : talloc_free(frame);
976 0 : return -1;
977 : }
978 0 : talloc_free(frame);
979 0 : return 0;
980 : }
981 :
982 1 : static PyObject *py_samu_get_logon_count(PyObject *obj, void *closure)
983 : {
984 1 : TALLOC_CTX *frame = talloc_stackframe();
985 1 : struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj);
986 1 : PyObject *py_logon_count;
987 :
988 1 : py_logon_count = PyLong_FromLong(pdb_get_logon_count(sam_acct));
989 1 : talloc_free(frame);
990 1 : return py_logon_count;
991 : }
992 :
993 0 : static int py_samu_set_logon_count(PyObject *obj, PyObject *value, void *closure)
994 : {
995 0 : TALLOC_CTX *frame = talloc_stackframe();
996 0 : struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj);
997 :
998 0 : PY_CHECK_TYPE(&PyLong_Type, value, return -1;);
999 0 : if (!pdb_set_logon_count(sam_acct, PyLong_AsLong(value), PDB_CHANGED)) {
1000 0 : talloc_free(frame);
1001 0 : return -1;
1002 : }
1003 0 : talloc_free(frame);
1004 0 : return 0;
1005 : }
1006 :
1007 1 : static PyObject *py_samu_get_country_code(PyObject *obj, void *closure)
1008 : {
1009 1 : TALLOC_CTX *frame = talloc_stackframe();
1010 1 : struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj);
1011 1 : PyObject *py_country_code;
1012 :
1013 1 : py_country_code = PyLong_FromLong(pdb_get_country_code(sam_acct));
1014 1 : talloc_free(frame);
1015 1 : return py_country_code;
1016 : }
1017 :
1018 0 : static int py_samu_set_country_code(PyObject *obj, PyObject *value, void *closure)
1019 : {
1020 0 : TALLOC_CTX *frame = talloc_stackframe();
1021 0 : struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj);
1022 :
1023 0 : PY_CHECK_TYPE(&PyLong_Type, value, return -1;);
1024 0 : if (!pdb_set_country_code(sam_acct, PyLong_AsLong(value), PDB_CHANGED)) {
1025 0 : talloc_free(frame);
1026 0 : return -1;
1027 : }
1028 0 : talloc_free(frame);
1029 0 : return 0;
1030 : }
1031 :
1032 1 : static PyObject *py_samu_get_code_page(PyObject *obj, void *closure)
1033 : {
1034 1 : TALLOC_CTX *frame = talloc_stackframe();
1035 1 : struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj);
1036 1 : PyObject *py_code_page;
1037 :
1038 1 : py_code_page = PyLong_FromLong(pdb_get_code_page(sam_acct));
1039 1 : talloc_free(frame);
1040 1 : return py_code_page;
1041 : }
1042 :
1043 0 : static int py_samu_set_code_page(PyObject *obj, PyObject *value, void *closure)
1044 : {
1045 0 : TALLOC_CTX *frame = talloc_stackframe();
1046 0 : struct samu *sam_acct = (struct samu *)pytalloc_get_ptr(obj);
1047 :
1048 0 : PY_CHECK_TYPE(&PyLong_Type, value, return -1;);
1049 0 : if (!pdb_set_code_page(sam_acct, PyLong_AsLong(value), PDB_CHANGED)) {
1050 0 : talloc_free(frame);
1051 0 : return -1;
1052 : }
1053 0 : talloc_free(frame);
1054 0 : return 0;
1055 : }
1056 :
1057 : static PyGetSetDef py_samu_getsetters[] = {
1058 : {
1059 : .name = discard_const_p(char, "logon_time"),
1060 : .get = py_samu_get_logon_time,
1061 : .set = py_samu_set_logon_time,
1062 : },
1063 : {
1064 : .name = discard_const_p(char, "logoff_time"),
1065 : .get = py_samu_get_logoff_time,
1066 : .set = py_samu_set_logoff_time,
1067 : },
1068 : {
1069 : .name = discard_const_p(char, "kickoff_time"),
1070 : .get = py_samu_get_kickoff_time,
1071 : .set = py_samu_set_kickoff_time,
1072 : },
1073 : {
1074 : .name = discard_const_p(char, "bad_password_time"),
1075 : .get = py_samu_get_bad_password_time,
1076 : .set = py_samu_set_bad_password_time,
1077 : },
1078 : {
1079 : .name = discard_const_p(char, "pass_last_set_time"),
1080 : .get = py_samu_get_pass_last_set_time,
1081 : .set = py_samu_set_pass_last_set_time,
1082 : },
1083 : {
1084 : .name = discard_const_p(char, "pass_can_change_time"),
1085 : .get = py_samu_get_pass_can_change_time,
1086 : .set = py_samu_set_pass_can_change_time,
1087 : },
1088 : {
1089 : .name = discard_const_p(char, "pass_must_change_time"),
1090 : .get = py_samu_get_pass_must_change_time,
1091 : .set = py_samu_set_pass_must_change_time,
1092 : },
1093 : {
1094 : .name = discard_const_p(char, "username"),
1095 : .get = py_samu_get_username,
1096 : .set = py_samu_set_username,
1097 : },
1098 : {
1099 : .name = discard_const_p(char, "domain"),
1100 : .get = py_samu_get_domain,
1101 : .set = py_samu_set_domain,
1102 : },
1103 : {
1104 : .name = discard_const_p(char, "nt_username"),
1105 : .get = py_samu_get_nt_username,
1106 : .set = py_samu_set_nt_username,
1107 : },
1108 : {
1109 : .name = discard_const_p(char, "full_name"),
1110 : .get = py_samu_get_full_name,
1111 : .set = py_samu_set_full_name,
1112 : },
1113 : {
1114 : .name = discard_const_p(char, "home_dir"),
1115 : .get = py_samu_get_home_dir,
1116 : .set = py_samu_set_home_dir,
1117 : },
1118 : {
1119 : .name = discard_const_p(char, "dir_drive"),
1120 : .get = py_samu_get_dir_drive,
1121 : .set = py_samu_set_dir_drive,
1122 : },
1123 : {
1124 : .name = discard_const_p(char, "logon_script"),
1125 : .get = py_samu_get_logon_script,
1126 : .set = py_samu_set_logon_script,
1127 : },
1128 : {
1129 : .name = discard_const_p(char, "profile_path"),
1130 : .get = py_samu_get_profile_path,
1131 : .set = py_samu_set_profile_path,
1132 : },
1133 : {
1134 : .name = discard_const_p(char, "acct_desc"),
1135 : .get = py_samu_get_acct_desc,
1136 : .set = py_samu_set_acct_desc,
1137 : },
1138 : {
1139 : .name = discard_const_p(char, "workstations"),
1140 : .get = py_samu_get_workstations,
1141 : .set = py_samu_set_workstations,
1142 : },
1143 : {
1144 : .name = discard_const_p(char, "comment"),
1145 : .get = py_samu_get_comment,
1146 : .set = py_samu_set_comment,
1147 : },
1148 : {
1149 : .name = discard_const_p(char, "munged_dial"),
1150 : .get = py_samu_get_munged_dial,
1151 : .set = py_samu_set_munged_dial,
1152 : },
1153 : {
1154 : .name = discard_const_p(char, "user_sid"),
1155 : .get = py_samu_get_user_sid,
1156 : .set = py_samu_set_user_sid,
1157 : },
1158 : {
1159 : .name = discard_const_p(char, "group_sid"),
1160 : .get = py_samu_get_group_sid,
1161 : .set = py_samu_set_group_sid,
1162 : },
1163 : {
1164 : .name = discard_const_p(char, "lanman_passwd"),
1165 : .get = py_samu_get_lanman_passwd,
1166 : .set = py_samu_set_lanman_passwd,
1167 : },
1168 : {
1169 : .name = discard_const_p(char, "nt_passwd"),
1170 : .get = py_samu_get_nt_passwd,
1171 : .set = py_samu_set_nt_passwd,
1172 : },
1173 : {
1174 : .name = discard_const_p(char, "pw_history"),
1175 : .get = py_samu_get_pw_history,
1176 : .set = py_samu_set_pw_history,
1177 : },
1178 : {
1179 : .name = discard_const_p(char, "plaintext_passwd"),
1180 : .get = py_samu_get_plaintext_passwd,
1181 : .set = py_samu_set_plaintext_passwd,
1182 : },
1183 : {
1184 : .name = discard_const_p(char, "acct_ctrl"),
1185 : .get = py_samu_get_acct_ctrl,
1186 : .set = py_samu_set_acct_ctrl,
1187 : },
1188 : {
1189 : .name = discard_const_p(char, "logon_divs"),
1190 : .get = py_samu_get_logon_divs,
1191 : .set = py_samu_set_logon_divs,
1192 : },
1193 : {
1194 : .name = discard_const_p(char, "hours_len"),
1195 : .get = py_samu_get_hours_len,
1196 : .set = py_samu_set_hours_len,
1197 : },
1198 : {
1199 : .name = discard_const_p(char, "hours"),
1200 : .get = py_samu_get_hours,
1201 : .set = py_samu_set_hours,
1202 : },
1203 : {
1204 : .name = discard_const_p(char, "bad_password_count"),
1205 : .get = py_samu_get_bad_password_count,
1206 : .set = py_samu_set_bad_password_count,
1207 : },
1208 : {
1209 : .name = discard_const_p(char, "logon_count"),
1210 : .get = py_samu_get_logon_count,
1211 : .set = py_samu_set_logon_count,
1212 : },
1213 : {
1214 : .name = discard_const_p(char, "country_code"),
1215 : .get = py_samu_get_country_code,
1216 : .set = py_samu_set_country_code,
1217 : },
1218 : {
1219 : .name = discard_const_p(char, "code_page"),
1220 : .get = py_samu_get_code_page,
1221 : .set = py_samu_set_code_page,
1222 : },
1223 : {
1224 : .name = NULL,
1225 : }
1226 : };
1227 :
1228 :
1229 : /************************** PIDL Autogeneratd ******************************/
1230 :
1231 13 : static PyObject *py_samu_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
1232 : {
1233 13 : TALLOC_CTX *frame = talloc_stackframe();
1234 13 : struct samu *sam_acct;
1235 :
1236 13 : sam_acct = samu_new(NULL);
1237 13 : if (!sam_acct) {
1238 0 : PyErr_NoMemory();
1239 0 : talloc_free(frame);
1240 0 : return NULL;
1241 : }
1242 :
1243 13 : talloc_free(frame);
1244 13 : return pytalloc_steal(type, sam_acct);
1245 : }
1246 :
1247 : static PyTypeObject PySamu = {
1248 : .tp_name = "passdb.Samu",
1249 : .tp_getset = py_samu_getsetters,
1250 : .tp_methods = NULL,
1251 : .tp_new = py_samu_new,
1252 : .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
1253 : .tp_doc = "Samu() -> samu object\n",
1254 : };
1255 :
1256 :
1257 43 : static PyObject *py_groupmap_get_gid(PyObject *obj, void *closure)
1258 : {
1259 43 : TALLOC_CTX *frame = talloc_stackframe();
1260 43 : GROUP_MAP *group_map = (GROUP_MAP *)pytalloc_get_ptr(obj);
1261 43 : PyObject *py_gid;
1262 :
1263 43 : py_gid = Py_BuildValue("i", group_map->gid);
1264 43 : talloc_free(frame);
1265 43 : return py_gid;
1266 : }
1267 :
1268 0 : static int py_groupmap_set_gid(PyObject *obj, PyObject *value, void *closure)
1269 : {
1270 0 : TALLOC_CTX *frame = talloc_stackframe();
1271 0 : GROUP_MAP *group_map = (GROUP_MAP *)pytalloc_get_ptr(obj);
1272 :
1273 0 : PY_CHECK_TYPE(&PyLong_Type, value, return -1;);
1274 0 : group_map->gid = PyLong_AsLong(value);
1275 0 : talloc_free(frame);
1276 0 : return 0;
1277 : }
1278 :
1279 277 : static PyObject *py_groupmap_get_sid(PyObject *obj, void *closure)
1280 : {
1281 277 : TALLOC_CTX *frame = talloc_stackframe();
1282 277 : GROUP_MAP *group_map = (GROUP_MAP *)pytalloc_get_ptr(obj);
1283 277 : PyObject *py_sid;
1284 277 : struct dom_sid *group_sid;
1285 277 : TALLOC_CTX *mem_ctx;
1286 :
1287 277 : mem_ctx = talloc_new(NULL);
1288 277 : if (mem_ctx == NULL) {
1289 0 : PyErr_NoMemory();
1290 0 : talloc_free(frame);
1291 0 : return NULL;
1292 : }
1293 :
1294 277 : group_sid = dom_sid_dup(mem_ctx, &group_map->sid);
1295 277 : if (group_sid == NULL) {
1296 0 : PyErr_NoMemory();
1297 0 : talloc_free(mem_ctx);
1298 0 : talloc_free(frame);
1299 0 : return NULL;
1300 : }
1301 :
1302 277 : py_sid = pytalloc_steal(dom_sid_Type, group_sid);
1303 :
1304 277 : talloc_free(mem_ctx);
1305 :
1306 277 : talloc_free(frame);
1307 277 : return py_sid;
1308 : }
1309 :
1310 0 : static int py_groupmap_set_sid(PyObject *obj, PyObject *value, void *closure)
1311 : {
1312 0 : TALLOC_CTX *frame = talloc_stackframe();
1313 0 : GROUP_MAP *group_map = (GROUP_MAP *)pytalloc_get_ptr(obj);
1314 :
1315 0 : PY_CHECK_TYPE(dom_sid_Type, value, return -1;);
1316 0 : group_map->sid = *pytalloc_get_type(value, struct dom_sid);
1317 0 : talloc_free(frame);
1318 0 : return 0;
1319 : }
1320 :
1321 109 : static PyObject *py_groupmap_get_sid_name_use(PyObject *obj, void *closure)
1322 : {
1323 109 : TALLOC_CTX *frame = talloc_stackframe();
1324 109 : GROUP_MAP *group_map = (GROUP_MAP *)pytalloc_get_ptr(obj);
1325 109 : PyObject *py_sid_name_use;
1326 :
1327 109 : py_sid_name_use = PyLong_FromLong(group_map->sid_name_use);
1328 109 : talloc_free(frame);
1329 109 : return py_sid_name_use;
1330 : }
1331 :
1332 0 : static int py_groupmap_set_sid_name_use(PyObject *obj, PyObject *value, void *closure)
1333 : {
1334 0 : TALLOC_CTX *frame = talloc_stackframe();
1335 0 : GROUP_MAP *group_map = (GROUP_MAP *)pytalloc_get_ptr(obj);
1336 :
1337 0 : PY_CHECK_TYPE(&PyLong_Type, value, return -1;);
1338 0 : group_map->sid_name_use = PyLong_AsLong(value);
1339 0 : talloc_free(frame);
1340 0 : return 0;
1341 : }
1342 :
1343 55 : static PyObject *py_groupmap_get_nt_name(PyObject *obj, void *closure)
1344 : {
1345 55 : TALLOC_CTX *frame = talloc_stackframe();
1346 55 : GROUP_MAP *group_map = (GROUP_MAP *)pytalloc_get_ptr(obj);
1347 55 : PyObject *py_nt_name;
1348 55 : if (group_map->nt_name == NULL) {
1349 0 : py_nt_name = Py_None;
1350 0 : Py_INCREF(py_nt_name);
1351 : } else {
1352 55 : py_nt_name = PyUnicode_FromString(group_map->nt_name);
1353 : }
1354 55 : talloc_free(frame);
1355 55 : return py_nt_name;
1356 : }
1357 :
1358 0 : static int py_groupmap_set_nt_name(PyObject *obj, PyObject *value, void *closure)
1359 : {
1360 0 : TALLOC_CTX *frame = talloc_stackframe();
1361 0 : GROUP_MAP *group_map = (GROUP_MAP *)pytalloc_get_ptr(obj);
1362 :
1363 0 : PY_CHECK_TYPE(&PyUnicode_Type, value, return -1;);
1364 0 : if (group_map->nt_name != NULL) {
1365 0 : TALLOC_FREE(group_map->nt_name);
1366 : }
1367 0 : if (value == Py_None) {
1368 0 : group_map->nt_name = talloc_strdup(group_map, "");
1369 : } else {
1370 0 : group_map->nt_name = talloc_strdup(group_map,
1371 : PyUnicode_AsUTF8(value));
1372 : }
1373 0 : TALLOC_FREE(frame);
1374 0 : if (group_map->nt_name == NULL) {
1375 0 : return -1;
1376 : }
1377 0 : return 0;
1378 : }
1379 :
1380 6 : static PyObject *py_groupmap_get_comment(PyObject *obj, void *closure)
1381 : {
1382 6 : TALLOC_CTX *frame = talloc_stackframe();
1383 6 : GROUP_MAP *group_map = (GROUP_MAP *)pytalloc_get_ptr(obj);
1384 6 : PyObject *py_comment;
1385 6 : if (group_map->comment == NULL) {
1386 0 : py_comment = Py_None;
1387 0 : Py_INCREF(py_comment);
1388 : } else {
1389 6 : py_comment = PyUnicode_FromString(group_map->comment);
1390 : }
1391 6 : talloc_free(frame);
1392 6 : return py_comment;
1393 : }
1394 :
1395 0 : static int py_groupmap_set_comment(PyObject *obj, PyObject *value, void *closure)
1396 : {
1397 0 : TALLOC_CTX *frame = talloc_stackframe();
1398 0 : GROUP_MAP *group_map = (GROUP_MAP *)pytalloc_get_ptr(obj);
1399 :
1400 0 : PY_CHECK_TYPE(&PyUnicode_Type, value, return -1;);
1401 0 : if (group_map->comment != NULL) {
1402 0 : TALLOC_FREE(group_map->comment);
1403 : }
1404 0 : if (value == Py_None) {
1405 0 : group_map->comment = talloc_strdup(group_map, "");
1406 : } else {
1407 0 : group_map->comment = talloc_strdup(group_map,
1408 : PyUnicode_AsUTF8(value));
1409 : }
1410 0 : TALLOC_FREE(frame);
1411 0 : if (group_map->comment == NULL) {
1412 0 : return -1;
1413 : }
1414 0 : return 0;
1415 : }
1416 :
1417 : static PyGetSetDef py_groupmap_getsetters[] = {
1418 : {
1419 : .name = discard_const_p(char, "gid"),
1420 : .get = py_groupmap_get_gid,
1421 : .set = py_groupmap_set_gid,
1422 : },
1423 : {
1424 : .name = discard_const_p(char, "sid"),
1425 : .get = py_groupmap_get_sid,
1426 : .set = py_groupmap_set_sid,
1427 : },
1428 : {
1429 : .name = discard_const_p(char, "sid_name_use"),
1430 : .get = py_groupmap_get_sid_name_use,
1431 : .set = py_groupmap_set_sid_name_use,
1432 : },
1433 : {
1434 : .name = discard_const_p(char, "nt_name"),
1435 : .get = py_groupmap_get_nt_name,
1436 : .set = py_groupmap_set_nt_name,
1437 : },
1438 : {
1439 : .name = discard_const_p(char, "comment"),
1440 : .get = py_groupmap_get_comment,
1441 : .set = py_groupmap_set_comment,
1442 : },
1443 : {
1444 : .name = NULL,
1445 : },
1446 : };
1447 :
1448 79 : static PyObject *py_groupmap_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
1449 : {
1450 79 : TALLOC_CTX *frame = talloc_stackframe();
1451 79 : GROUP_MAP *group_map;
1452 79 : TALLOC_CTX *mem_ctx;
1453 79 : PyObject *py_group_map;
1454 :
1455 79 : mem_ctx = talloc_new(NULL);
1456 79 : if (mem_ctx == NULL) {
1457 0 : PyErr_NoMemory();
1458 0 : talloc_free(frame);
1459 0 : return NULL;
1460 : }
1461 :
1462 79 : group_map = talloc_zero(mem_ctx, GROUP_MAP);
1463 79 : if (group_map == NULL) {
1464 0 : PyErr_NoMemory();
1465 0 : talloc_free(mem_ctx);
1466 0 : talloc_free(frame);
1467 0 : return NULL;
1468 : }
1469 :
1470 79 : py_group_map = pytalloc_steal(type, group_map);
1471 79 : if (py_group_map == NULL) {
1472 0 : PyErr_NoMemory();
1473 0 : talloc_free(mem_ctx);
1474 0 : talloc_free(frame);
1475 0 : return NULL;
1476 : }
1477 :
1478 79 : talloc_free(mem_ctx);
1479 :
1480 79 : talloc_free(frame);
1481 79 : return py_group_map;
1482 : }
1483 :
1484 :
1485 : static PyTypeObject PyGroupmap = {
1486 : .tp_name = "passdb.Groupmap",
1487 : .tp_getset = py_groupmap_getsetters,
1488 : .tp_methods = NULL,
1489 : .tp_new = py_groupmap_new,
1490 : .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
1491 : .tp_doc = "Groupmap() -> group map object\n",
1492 : };
1493 :
1494 :
1495 72 : static PyObject *py_pdb_domain_info(PyObject *self, PyObject *args)
1496 : {
1497 72 : TALLOC_CTX *frame = talloc_stackframe();
1498 5 : struct pdb_methods *methods;
1499 5 : struct pdb_domain_info *domain_info;
1500 5 : PyObject *py_domain_info;
1501 5 : struct dom_sid *sid;
1502 5 : struct GUID *guid;
1503 72 : PyObject *py_dom_sid = NULL;
1504 72 : PyObject *py_guid = NULL;
1505 :
1506 72 : methods = pytalloc_get_ptr(self);
1507 :
1508 72 : domain_info = methods->get_domain_info(methods, frame);
1509 72 : if (! domain_info) {
1510 0 : Py_RETURN_NONE;
1511 : }
1512 :
1513 72 : sid = dom_sid_dup(frame, &domain_info->sid);
1514 72 : if (sid == NULL) {
1515 0 : PyErr_NoMemory();
1516 0 : talloc_free(frame);
1517 0 : return NULL;
1518 : }
1519 :
1520 72 : guid = talloc(frame, struct GUID);
1521 72 : if (guid == NULL) {
1522 0 : PyErr_NoMemory();
1523 0 : talloc_free(frame);
1524 0 : return NULL;
1525 : }
1526 72 : *guid = domain_info->guid;
1527 :
1528 72 : py_dom_sid = pytalloc_steal(dom_sid_Type, sid);
1529 72 : py_guid = pytalloc_steal(guid_Type, guid);
1530 :
1531 72 : py_domain_info = Py_BuildValue(
1532 : "{s:s, s:s, s:s, s:O, s:O}",
1533 : "name", domain_info->name,
1534 : "dns_domain", domain_info->dns_domain,
1535 : "dns_forest", domain_info->dns_forest,
1536 : "dom_sid", py_dom_sid,
1537 : "guid", py_guid);
1538 :
1539 :
1540 72 : Py_CLEAR(py_dom_sid);
1541 72 : Py_CLEAR(py_guid);
1542 72 : talloc_free(frame);
1543 72 : return py_domain_info;
1544 : }
1545 :
1546 :
1547 13 : static PyObject *py_pdb_getsampwnam(PyObject *self, PyObject *args)
1548 : {
1549 13 : TALLOC_CTX *frame = talloc_stackframe();
1550 13 : NTSTATUS status;
1551 13 : const char *username;
1552 13 : struct pdb_methods *methods;
1553 13 : struct samu *sam_acct;
1554 13 : PyObject *py_sam_acct;
1555 :
1556 13 : if (!PyArg_ParseTuple(args, "s:getsampwnam", &username)) {
1557 0 : talloc_free(frame);
1558 0 : return NULL;
1559 : }
1560 :
1561 13 : methods = pytalloc_get_ptr(self);
1562 :
1563 13 : py_sam_acct = py_samu_new(&PySamu, NULL, NULL);
1564 13 : if (py_sam_acct == NULL) {
1565 0 : PyErr_NoMemory();
1566 0 : talloc_free(frame);
1567 0 : return NULL;
1568 : }
1569 13 : sam_acct = (struct samu *)pytalloc_get_ptr(py_sam_acct);
1570 :
1571 13 : status = methods->getsampwnam(methods, sam_acct, username);
1572 13 : if (!NT_STATUS_IS_OK(status)) {
1573 3 : PyErr_Format(py_pdb_error, "Unable to get user information for '%s', (%d,%s)",
1574 : username,
1575 : NT_STATUS_V(status),
1576 : get_friendly_nt_error_msg(status));
1577 3 : Py_DECREF(py_sam_acct);
1578 3 : talloc_free(frame);
1579 3 : return NULL;
1580 : }
1581 :
1582 10 : talloc_free(frame);
1583 10 : return py_sam_acct;
1584 : }
1585 :
1586 0 : static PyObject *py_pdb_getsampwsid(PyObject *self, PyObject *args)
1587 : {
1588 0 : TALLOC_CTX *frame = talloc_stackframe();
1589 0 : NTSTATUS status;
1590 0 : struct pdb_methods *methods;
1591 0 : struct samu *sam_acct;
1592 0 : PyObject *py_sam_acct;
1593 0 : PyObject *py_user_sid;
1594 :
1595 0 : if (!PyArg_ParseTuple(args, "O:getsampwsid", &py_user_sid)) {
1596 0 : talloc_free(frame);
1597 0 : return NULL;
1598 : }
1599 :
1600 0 : methods = pytalloc_get_ptr(self);
1601 :
1602 0 : py_sam_acct = py_samu_new(&PySamu, NULL, NULL);
1603 0 : if (py_sam_acct == NULL) {
1604 0 : PyErr_NoMemory();
1605 0 : talloc_free(frame);
1606 0 : return NULL;
1607 : }
1608 0 : sam_acct = (struct samu *)pytalloc_get_ptr(py_sam_acct);
1609 :
1610 0 : status = methods->getsampwsid(methods, sam_acct, pytalloc_get_ptr(py_user_sid));
1611 0 : if (!NT_STATUS_IS_OK(status)) {
1612 0 : PyErr_Format(py_pdb_error, "Unable to get user information from SID, (%d,%s)",
1613 : NT_STATUS_V(status),
1614 : get_friendly_nt_error_msg(status));
1615 0 : Py_DECREF(py_sam_acct);
1616 0 : talloc_free(frame);
1617 0 : return NULL;
1618 : }
1619 :
1620 0 : talloc_free(frame);
1621 0 : return py_sam_acct;
1622 : }
1623 :
1624 0 : static PyObject *py_pdb_create_user(PyObject *self, PyObject *args)
1625 : {
1626 0 : TALLOC_CTX *frame = talloc_stackframe();
1627 0 : NTSTATUS status;
1628 0 : struct pdb_methods *methods;
1629 0 : const char *username;
1630 0 : unsigned int acct_flags;
1631 0 : unsigned int rid;
1632 :
1633 0 : if (!PyArg_ParseTuple(args, "sI:create_user", &username, &acct_flags)) {
1634 0 : talloc_free(frame);
1635 0 : return NULL;
1636 : }
1637 :
1638 0 : methods = pytalloc_get_ptr(self);
1639 :
1640 0 : status = methods->create_user(methods, frame, username, acct_flags, &rid);
1641 0 : if (!NT_STATUS_IS_OK(status)) {
1642 0 : PyErr_Format(py_pdb_error, "Unable to create user (%s), (%d,%s)",
1643 : username,
1644 : NT_STATUS_V(status),
1645 : get_friendly_nt_error_msg(status));
1646 0 : talloc_free(frame);
1647 0 : return NULL;
1648 : }
1649 :
1650 0 : talloc_free(frame);
1651 0 : return PyLong_FromLong(rid);
1652 : }
1653 :
1654 0 : static PyObject *py_pdb_delete_user(PyObject *self, PyObject *args)
1655 : {
1656 0 : TALLOC_CTX *frame = talloc_stackframe();
1657 0 : NTSTATUS status;
1658 0 : struct pdb_methods *methods;
1659 0 : struct samu *sam_acct;
1660 0 : PyObject *py_sam_acct;
1661 :
1662 0 : if (!PyArg_ParseTuple(args, "O!:delete_user", &PySamu, &py_sam_acct)) {
1663 0 : talloc_free(frame);
1664 0 : return NULL;
1665 : }
1666 :
1667 0 : methods = pytalloc_get_ptr(self);
1668 :
1669 0 : sam_acct = pytalloc_get_ptr(py_sam_acct);
1670 :
1671 0 : status = methods->delete_user(methods, frame, sam_acct);
1672 0 : if (!NT_STATUS_IS_OK(status)) {
1673 0 : PyErr_Format(py_pdb_error, "Unable to delete user, (%d,%s)",
1674 : NT_STATUS_V(status),
1675 : get_friendly_nt_error_msg(status));
1676 0 : talloc_free(frame);
1677 0 : return NULL;
1678 : }
1679 :
1680 0 : talloc_free(frame);
1681 0 : Py_RETURN_NONE;
1682 : }
1683 :
1684 6 : static PyObject *py_pdb_add_sam_account(PyObject *self, PyObject *args)
1685 : {
1686 6 : TALLOC_CTX *frame = talloc_stackframe();
1687 6 : NTSTATUS status;
1688 6 : struct pdb_methods *methods;
1689 6 : struct samu *sam_acct;
1690 6 : PyObject *py_sam_acct;
1691 :
1692 6 : if (!PyArg_ParseTuple(args, "O!:add_sam_account", &PySamu, &py_sam_acct)) {
1693 0 : talloc_free(frame);
1694 0 : return NULL;
1695 : }
1696 :
1697 6 : methods = pytalloc_get_ptr(self);
1698 :
1699 6 : sam_acct = pytalloc_get_ptr(py_sam_acct);
1700 :
1701 6 : status = methods->add_sam_account(methods, sam_acct);
1702 6 : if (!NT_STATUS_IS_OK(status)) {
1703 0 : PyErr_Format(py_pdb_error, "Unable to add sam account '%s', (%d,%s)",
1704 : sam_acct->username,
1705 : NT_STATUS_V(status),
1706 : get_friendly_nt_error_msg(status));
1707 0 : talloc_free(frame);
1708 0 : return NULL;
1709 : }
1710 :
1711 6 : talloc_free(frame);
1712 6 : Py_RETURN_NONE;
1713 : }
1714 :
1715 3 : static PyObject *py_pdb_update_sam_account(PyObject *self, PyObject *args)
1716 : {
1717 3 : TALLOC_CTX *frame = talloc_stackframe();
1718 3 : NTSTATUS status;
1719 3 : struct pdb_methods *methods;
1720 3 : struct samu *sam_acct;
1721 3 : PyObject *py_sam_acct;
1722 :
1723 3 : if (!PyArg_ParseTuple(args, "O!:update_sam_account", &PySamu, &py_sam_acct)) {
1724 0 : talloc_free(frame);
1725 0 : return NULL;
1726 : }
1727 :
1728 3 : methods = pytalloc_get_ptr(self);
1729 :
1730 3 : sam_acct = pytalloc_get_ptr(py_sam_acct);
1731 :
1732 3 : status = methods->update_sam_account(methods, sam_acct);
1733 3 : if (!NT_STATUS_IS_OK(status)) {
1734 0 : PyErr_Format(py_pdb_error, "Unable to update sam account, (%d,%s)",
1735 : NT_STATUS_V(status),
1736 : get_friendly_nt_error_msg(status));
1737 0 : talloc_free(frame);
1738 0 : return NULL;
1739 : }
1740 :
1741 3 : talloc_free(frame);
1742 3 : Py_RETURN_NONE;
1743 : }
1744 :
1745 0 : static PyObject *py_pdb_delete_sam_account(PyObject *self, PyObject *args)
1746 : {
1747 0 : TALLOC_CTX *frame = talloc_stackframe();
1748 0 : NTSTATUS status;
1749 0 : struct pdb_methods *methods;
1750 0 : struct samu *sam_acct;
1751 0 : PyObject *py_sam_acct;
1752 :
1753 0 : if (!PyArg_ParseTuple(args, "O!:delete_sam_account", &PySamu, &py_sam_acct)) {
1754 0 : talloc_free(frame);
1755 0 : return NULL;
1756 : }
1757 :
1758 0 : methods = pytalloc_get_ptr(self);
1759 :
1760 0 : sam_acct = pytalloc_get_ptr(py_sam_acct);
1761 :
1762 0 : status = methods->delete_sam_account(methods, sam_acct);
1763 0 : if (!NT_STATUS_IS_OK(status)) {
1764 0 : PyErr_Format(py_pdb_error, "Unable to delete sam account, (%d,%s)",
1765 : NT_STATUS_V(status),
1766 : get_friendly_nt_error_msg(status));
1767 0 : talloc_free(frame);
1768 0 : return NULL;
1769 : }
1770 :
1771 0 : talloc_free(frame);
1772 0 : Py_RETURN_NONE;
1773 : }
1774 :
1775 0 : static PyObject *py_pdb_rename_sam_account(PyObject *self, PyObject *args)
1776 : {
1777 0 : TALLOC_CTX *frame = talloc_stackframe();
1778 0 : NTSTATUS status;
1779 0 : struct pdb_methods *methods;
1780 0 : struct samu *sam_acct;
1781 0 : const char *new_username;
1782 0 : PyObject *py_sam_acct;
1783 :
1784 0 : if (!PyArg_ParseTuple(args, "O!s:rename_sam_account", &PySamu, &py_sam_acct,
1785 : &new_username)) {
1786 0 : talloc_free(frame);
1787 0 : return NULL;
1788 : }
1789 :
1790 0 : methods = pytalloc_get_ptr(self);
1791 :
1792 0 : sam_acct = pytalloc_get_ptr(py_sam_acct);
1793 :
1794 0 : status = methods->rename_sam_account(methods, sam_acct, new_username);
1795 0 : if (!NT_STATUS_IS_OK(status)) {
1796 0 : PyErr_Format(py_pdb_error, "Unable to rename sam account, (%d,%s)",
1797 : NT_STATUS_V(status),
1798 : get_friendly_nt_error_msg(status));
1799 0 : talloc_free(frame);
1800 0 : return NULL;
1801 : }
1802 :
1803 0 : talloc_free(frame);
1804 0 : Py_RETURN_NONE;
1805 : }
1806 :
1807 :
1808 1 : static PyObject *py_pdb_getgrsid(PyObject *self, PyObject *args)
1809 : {
1810 1 : TALLOC_CTX *frame = talloc_stackframe();
1811 1 : NTSTATUS status;
1812 1 : struct pdb_methods *methods;
1813 1 : GROUP_MAP *group_map;
1814 1 : struct dom_sid *domain_sid;
1815 1 : PyObject *py_domain_sid, *py_group_map;
1816 :
1817 1 : if (!PyArg_ParseTuple(args, "O!:getgrsid", dom_sid_Type, &py_domain_sid)) {
1818 0 : talloc_free(frame);
1819 0 : return NULL;
1820 : }
1821 :
1822 1 : methods = pytalloc_get_ptr(self);
1823 :
1824 1 : domain_sid = pytalloc_get_ptr(py_domain_sid);
1825 :
1826 1 : py_group_map = py_groupmap_new(&PyGroupmap, NULL, NULL);
1827 1 : if (py_group_map == NULL) {
1828 0 : PyErr_NoMemory();
1829 0 : talloc_free(frame);
1830 0 : return NULL;
1831 : }
1832 :
1833 1 : group_map = pytalloc_get_ptr(py_group_map);
1834 :
1835 1 : status = methods->getgrsid(methods, group_map, *domain_sid);
1836 1 : if (!NT_STATUS_IS_OK(status)) {
1837 0 : PyErr_Format(py_pdb_error, "Unable to get group information by sid, (%d,%s)",
1838 : NT_STATUS_V(status),
1839 : get_friendly_nt_error_msg(status));
1840 0 : talloc_free(frame);
1841 0 : return NULL;
1842 : }
1843 :
1844 1 : talloc_free(frame);
1845 1 : return py_group_map;
1846 : }
1847 :
1848 :
1849 0 : static PyObject *py_pdb_getgrgid(PyObject *self, PyObject *args)
1850 : {
1851 0 : TALLOC_CTX *frame = talloc_stackframe();
1852 0 : NTSTATUS status;
1853 0 : struct pdb_methods *methods;
1854 0 : GROUP_MAP *group_map;
1855 0 : PyObject *py_group_map;
1856 0 : unsigned int gid_value;
1857 :
1858 0 : if (!PyArg_ParseTuple(args, "I:getgrgid", &gid_value)) {
1859 0 : talloc_free(frame);
1860 0 : return NULL;
1861 : }
1862 :
1863 0 : methods = pytalloc_get_ptr(self);
1864 :
1865 0 : py_group_map = py_groupmap_new(&PyGroupmap, NULL, NULL);
1866 0 : if (py_group_map == NULL) {
1867 0 : PyErr_NoMemory();
1868 0 : talloc_free(frame);
1869 0 : return NULL;
1870 : }
1871 :
1872 0 : group_map = pytalloc_get_ptr(py_group_map);
1873 :
1874 0 : status = methods->getgrgid(methods, group_map, gid_value);
1875 0 : if (!NT_STATUS_IS_OK(status)) {
1876 0 : PyErr_Format(py_pdb_error, "Unable to get group information by gid, (%d,%s)",
1877 : NT_STATUS_V(status),
1878 : get_friendly_nt_error_msg(status));
1879 0 : talloc_free(frame);
1880 0 : return NULL;
1881 : }
1882 :
1883 0 : talloc_free(frame);
1884 0 : return py_group_map;
1885 : }
1886 :
1887 :
1888 0 : static PyObject *py_pdb_getgrnam(PyObject *self, PyObject *args)
1889 : {
1890 0 : TALLOC_CTX *frame = talloc_stackframe();
1891 0 : NTSTATUS status;
1892 0 : struct pdb_methods *methods;
1893 0 : GROUP_MAP *group_map;
1894 0 : PyObject *py_group_map;
1895 0 : const char *groupname;
1896 :
1897 0 : if (!PyArg_ParseTuple(args, "s:getgrnam", &groupname)) {
1898 0 : talloc_free(frame);
1899 0 : return NULL;
1900 : }
1901 :
1902 0 : methods = pytalloc_get_ptr(self);
1903 :
1904 0 : py_group_map = py_groupmap_new(&PyGroupmap, NULL, NULL);
1905 0 : if (py_group_map == NULL) {
1906 0 : PyErr_NoMemory();
1907 0 : talloc_free(frame);
1908 0 : return NULL;
1909 : }
1910 :
1911 0 : group_map = pytalloc_get_ptr(py_group_map);
1912 :
1913 0 : status = methods->getgrnam(methods, group_map, groupname);
1914 0 : if (!NT_STATUS_IS_OK(status)) {
1915 0 : PyErr_Format(py_pdb_error, "Unable to get group information by name, (%d,%s)",
1916 : NT_STATUS_V(status),
1917 : get_friendly_nt_error_msg(status));
1918 0 : talloc_free(frame);
1919 0 : return NULL;
1920 : }
1921 :
1922 0 : talloc_free(frame);
1923 0 : return py_group_map;
1924 : }
1925 :
1926 :
1927 0 : static PyObject *py_pdb_create_dom_group(PyObject *self, PyObject *args)
1928 : {
1929 0 : TALLOC_CTX *frame = talloc_stackframe();
1930 0 : NTSTATUS status;
1931 0 : struct pdb_methods *methods;
1932 0 : const char *groupname;
1933 0 : uint32_t group_rid;
1934 :
1935 0 : if (!PyArg_ParseTuple(args, "s:create_dom_group", &groupname)) {
1936 0 : talloc_free(frame);
1937 0 : return NULL;
1938 : }
1939 :
1940 0 : methods = pytalloc_get_ptr(self);
1941 :
1942 0 : status = methods->create_dom_group(methods, frame, groupname, &group_rid);
1943 0 : if (!NT_STATUS_IS_OK(status)) {
1944 0 : PyErr_Format(py_pdb_error, "Unable to create domain group (%s), (%d,%s)",
1945 : groupname,
1946 : NT_STATUS_V(status),
1947 : get_friendly_nt_error_msg(status));
1948 0 : talloc_free(frame);
1949 0 : return NULL;
1950 : }
1951 :
1952 0 : talloc_free(frame);
1953 0 : return PyLong_FromLong(group_rid);
1954 : }
1955 :
1956 :
1957 0 : static PyObject *py_pdb_delete_dom_group(PyObject *self, PyObject *args)
1958 : {
1959 0 : TALLOC_CTX *frame = talloc_stackframe();
1960 0 : NTSTATUS status;
1961 0 : struct pdb_methods *methods;
1962 0 : unsigned int group_rid;
1963 :
1964 0 : if (!PyArg_ParseTuple(args, "I:delete_dom_group", &group_rid)) {
1965 0 : talloc_free(frame);
1966 0 : return NULL;
1967 : }
1968 :
1969 0 : methods = pytalloc_get_ptr(self);
1970 :
1971 0 : status = methods->delete_dom_group(methods, frame, group_rid);
1972 0 : if (!NT_STATUS_IS_OK(status)) {
1973 0 : PyErr_Format(py_pdb_error, "Unable to delete domain group (rid=%d), (%d,%s)",
1974 : group_rid,
1975 : NT_STATUS_V(status),
1976 : get_friendly_nt_error_msg(status));
1977 0 : talloc_free(frame);
1978 0 : return NULL;
1979 : }
1980 :
1981 0 : talloc_free(frame);
1982 0 : Py_RETURN_NONE;
1983 : }
1984 :
1985 :
1986 0 : static PyObject *py_pdb_add_group_mapping_entry(PyObject *self, PyObject *args)
1987 : {
1988 0 : TALLOC_CTX *frame = talloc_stackframe();
1989 0 : NTSTATUS status;
1990 0 : struct pdb_methods *methods;
1991 0 : PyObject *py_group_map;
1992 0 : GROUP_MAP *group_map;
1993 :
1994 0 : if (!PyArg_ParseTuple(args, "O!:add_group_mapping_entry", &PyGroupmap, &py_group_map)) {
1995 0 : talloc_free(frame);
1996 0 : return NULL;
1997 : }
1998 :
1999 0 : methods = pytalloc_get_ptr(self);
2000 :
2001 0 : group_map = pytalloc_get_ptr(py_group_map);
2002 :
2003 0 : status = methods->add_group_mapping_entry(methods, group_map);
2004 0 : if (!NT_STATUS_IS_OK(status)) {
2005 0 : PyErr_Format(py_pdb_error, "Unable to add group mapping entry, (%d,%s)",
2006 : NT_STATUS_V(status),
2007 : get_friendly_nt_error_msg(status));
2008 0 : talloc_free(frame);
2009 0 : return NULL;
2010 : }
2011 :
2012 0 : talloc_free(frame);
2013 0 : Py_RETURN_NONE;
2014 : }
2015 :
2016 :
2017 0 : static PyObject *py_pdb_update_group_mapping_entry(PyObject *self, PyObject *args)
2018 : {
2019 0 : TALLOC_CTX *frame = talloc_stackframe();
2020 0 : NTSTATUS status;
2021 0 : struct pdb_methods *methods;
2022 0 : PyObject *py_group_map;
2023 0 : GROUP_MAP *group_map;
2024 :
2025 0 : if (!PyArg_ParseTuple(args, "O!:update_group_mapping_entry", &PyGroupmap, &py_group_map)) {
2026 0 : talloc_free(frame);
2027 0 : return NULL;
2028 : }
2029 :
2030 0 : methods = pytalloc_get_ptr(self);
2031 :
2032 0 : group_map = pytalloc_get_ptr(py_group_map);
2033 :
2034 0 : status = methods->update_group_mapping_entry(methods, group_map);
2035 0 : if (!NT_STATUS_IS_OK(status)) {
2036 0 : PyErr_Format(py_pdb_error, "Unable to update group mapping entry, (%d,%s)",
2037 : NT_STATUS_V(status),
2038 : get_friendly_nt_error_msg(status));
2039 0 : talloc_free(frame);
2040 0 : return NULL;
2041 : }
2042 :
2043 0 : talloc_free(frame);
2044 0 : Py_RETURN_NONE;
2045 : }
2046 :
2047 :
2048 0 : static PyObject *py_pdb_delete_group_mapping_entry(PyObject *self, PyObject *args)
2049 : {
2050 0 : TALLOC_CTX *frame = talloc_stackframe();
2051 0 : NTSTATUS status;
2052 0 : struct pdb_methods *methods;
2053 0 : PyObject *py_group_sid;
2054 0 : struct dom_sid *group_sid;
2055 :
2056 0 : if (!PyArg_ParseTuple(args, "O!:delete_group_mapping_entry", dom_sid_Type, &py_group_sid)) {
2057 0 : talloc_free(frame);
2058 0 : return NULL;
2059 : }
2060 :
2061 0 : methods = pytalloc_get_ptr(self);
2062 :
2063 0 : group_sid = pytalloc_get_ptr(py_group_sid);
2064 :
2065 0 : status = methods->delete_group_mapping_entry(methods, *group_sid);
2066 0 : if (!NT_STATUS_IS_OK(status)) {
2067 0 : PyErr_Format(py_pdb_error, "Unable to delete group mapping entry, (%d,%s)",
2068 : NT_STATUS_V(status),
2069 : get_friendly_nt_error_msg(status));
2070 0 : talloc_free(frame);
2071 0 : return NULL;
2072 : }
2073 :
2074 0 : talloc_free(frame);
2075 0 : Py_RETURN_NONE;
2076 : }
2077 :
2078 :
2079 6 : static PyObject *py_pdb_enum_group_mapping(PyObject *self, PyObject *args)
2080 : {
2081 6 : TALLOC_CTX *frame = talloc_stackframe();
2082 6 : NTSTATUS status;
2083 6 : struct pdb_methods *methods;
2084 6 : enum lsa_SidType sid_name_use;
2085 6 : int lsa_sidtype_value = SID_NAME_UNKNOWN;
2086 6 : int unix_only = 0;
2087 6 : PyObject *py_domain_sid = Py_None;
2088 6 : struct dom_sid *domain_sid = NULL;
2089 6 : GROUP_MAP **gmap = NULL;
2090 6 : GROUP_MAP *group_map;
2091 6 : size_t i, num_entries;
2092 6 : PyObject *py_gmap_list, *py_group_map;
2093 :
2094 6 : if (!PyArg_ParseTuple(args, "|O!ii:enum_group_mapping", dom_sid_Type, &py_domain_sid,
2095 : &lsa_sidtype_value, &unix_only)) {
2096 0 : talloc_free(frame);
2097 0 : return NULL;
2098 : }
2099 :
2100 6 : methods = pytalloc_get_ptr(self);
2101 :
2102 6 : sid_name_use = lsa_sidtype_value;
2103 :
2104 6 : if (py_domain_sid != Py_None) {
2105 0 : domain_sid = pytalloc_get_ptr(py_domain_sid);
2106 : }
2107 :
2108 6 : status = methods->enum_group_mapping(methods, domain_sid, sid_name_use,
2109 : &gmap, &num_entries, unix_only);
2110 6 : if (!NT_STATUS_IS_OK(status)) {
2111 0 : PyErr_Format(py_pdb_error, "Unable to enumerate group mappings, (%d,%s)",
2112 : NT_STATUS_V(status),
2113 : get_friendly_nt_error_msg(status));
2114 0 : talloc_free(frame);
2115 0 : return NULL;
2116 : }
2117 :
2118 6 : py_gmap_list = PyList_New(0);
2119 6 : if (py_gmap_list == NULL) {
2120 0 : PyErr_NoMemory();
2121 0 : talloc_free(frame);
2122 0 : return NULL;
2123 : }
2124 :
2125 84 : for(i=0; i<num_entries; i++) {
2126 78 : py_group_map = py_groupmap_new(&PyGroupmap, NULL, NULL);
2127 78 : if (py_group_map) {
2128 78 : int res = 0;
2129 78 : group_map = pytalloc_get_ptr(py_group_map);
2130 78 : *group_map = *gmap[i];
2131 78 : talloc_steal(group_map, gmap[i]->nt_name);
2132 78 : talloc_steal(group_map, gmap[i]->comment);
2133 :
2134 78 : res = PyList_Append(py_gmap_list, py_group_map);
2135 78 : Py_CLEAR(py_group_map);
2136 78 : if (res == -1) {
2137 0 : Py_CLEAR(py_gmap_list);
2138 0 : talloc_free(frame);
2139 0 : return NULL;
2140 : }
2141 : }
2142 : }
2143 :
2144 6 : talloc_free(gmap);
2145 :
2146 6 : talloc_free(frame);
2147 6 : return py_gmap_list;
2148 : }
2149 :
2150 :
2151 9 : static PyObject *py_pdb_enum_group_members(PyObject *self, PyObject *args)
2152 : {
2153 9 : TALLOC_CTX *frame = talloc_stackframe();
2154 9 : NTSTATUS status;
2155 9 : struct pdb_methods *methods;
2156 9 : PyObject *py_group_sid;
2157 9 : struct dom_sid *group_sid;
2158 9 : uint32_t *member_rids;
2159 9 : size_t i, num_members;
2160 9 : PyObject *py_sid_list;
2161 9 : struct dom_sid *domain_sid, *member_sid;
2162 :
2163 9 : if (!PyArg_ParseTuple(args, "O!:enum_group_members", dom_sid_Type, &py_group_sid)) {
2164 0 : talloc_free(frame);
2165 0 : return NULL;
2166 : }
2167 :
2168 9 : methods = pytalloc_get_ptr(self);
2169 :
2170 9 : group_sid = pytalloc_get_ptr(py_group_sid);
2171 :
2172 9 : status = methods->enum_group_members(methods, frame, group_sid,
2173 : &member_rids, &num_members);
2174 9 : if (!NT_STATUS_IS_OK(status)) {
2175 9 : PyErr_Format(py_pdb_error, "Unable to enumerate group members, (%d,%s)",
2176 : NT_STATUS_V(status),
2177 : get_friendly_nt_error_msg(status));
2178 9 : talloc_free(frame);
2179 9 : return NULL;
2180 : }
2181 :
2182 0 : py_sid_list = PyList_New(0);
2183 0 : if (py_sid_list == NULL) {
2184 0 : PyErr_NoMemory();
2185 0 : talloc_free(frame);
2186 0 : return NULL;
2187 : }
2188 :
2189 0 : domain_sid = get_global_sam_sid();
2190 :
2191 0 : for(i=0; i<num_members; i++) {
2192 0 : int res = 0;
2193 0 : PyObject *py_member_sid = NULL;
2194 0 : member_sid = dom_sid_add_rid(frame, domain_sid, member_rids[i]);
2195 0 : py_member_sid = pytalloc_steal(dom_sid_Type, member_sid);
2196 0 : res = PyList_Append(py_sid_list,
2197 : py_member_sid);
2198 0 : Py_CLEAR(py_member_sid);
2199 0 : if (res == -1) {
2200 0 : talloc_free(frame);
2201 0 : Py_CLEAR(py_sid_list);
2202 0 : return NULL;
2203 : }
2204 : }
2205 :
2206 0 : talloc_free(frame);
2207 0 : return py_sid_list;
2208 : }
2209 :
2210 :
2211 6 : static PyObject *py_pdb_enum_group_memberships(PyObject *self, PyObject *args)
2212 : {
2213 6 : TALLOC_CTX *frame = talloc_stackframe();
2214 6 : NTSTATUS status;
2215 6 : struct pdb_methods *methods;
2216 6 : uint32_t i;
2217 :
2218 6 : struct samu *sam_acct;
2219 6 : PyObject *py_sam_acct;
2220 6 : PyObject *py_sid_list;
2221 6 : struct dom_sid *user_group_sids = NULL;
2222 6 : gid_t *user_group_ids = NULL;
2223 6 : uint32_t num_groups = 0;
2224 :
2225 6 : if (!PyArg_ParseTuple(args, "O!:enum_group_memberships", &PySamu, &py_sam_acct)) {
2226 0 : talloc_free(frame);
2227 0 : return NULL;
2228 : }
2229 :
2230 6 : methods = pytalloc_get_ptr(self);
2231 :
2232 6 : sam_acct = pytalloc_get_ptr(py_sam_acct);
2233 :
2234 6 : status = methods->enum_group_memberships(methods, frame, sam_acct,
2235 : &user_group_sids, &user_group_ids, &num_groups);
2236 6 : if (!NT_STATUS_IS_OK(status)) {
2237 3 : PyErr_Format(py_pdb_error, "Unable to enumerate group memberships, (%d,%s)",
2238 : NT_STATUS_V(status),
2239 : get_friendly_nt_error_msg(status));
2240 3 : talloc_free(frame);
2241 3 : return NULL;
2242 : }
2243 :
2244 3 : py_sid_list = PyList_New(0);
2245 3 : if (py_sid_list == NULL) {
2246 0 : PyErr_NoMemory();
2247 0 : talloc_free(frame);
2248 0 : return NULL;
2249 : }
2250 :
2251 6 : for(i=0; i<num_groups; i++) {
2252 3 : PyObject *py_sid =
2253 3 : pytalloc_steal(dom_sid_Type,
2254 3 : dom_sid_dup(NULL, &user_group_sids[i]));
2255 3 : PyList_Append(py_sid_list, py_sid);
2256 3 : Py_CLEAR(py_sid);
2257 : }
2258 :
2259 3 : talloc_free(frame);
2260 3 : return py_sid_list;
2261 : }
2262 :
2263 :
2264 0 : static PyObject *py_pdb_add_groupmem(PyObject *self, PyObject *args)
2265 : {
2266 0 : TALLOC_CTX *frame = talloc_stackframe();
2267 0 : NTSTATUS status;
2268 0 : struct pdb_methods *methods;
2269 0 : uint32_t group_rid, member_rid;
2270 :
2271 0 : if (!PyArg_ParseTuple(args, "II:add_groupmem", &group_rid, &member_rid)) {
2272 0 : talloc_free(frame);
2273 0 : return NULL;
2274 : }
2275 :
2276 0 : methods = pytalloc_get_ptr(self);
2277 :
2278 0 : status = methods->add_groupmem(methods, frame, group_rid, member_rid);
2279 0 : if (!NT_STATUS_IS_OK(status)) {
2280 0 : PyErr_Format(py_pdb_error, "Unable to add group member, (%d,%s)",
2281 : NT_STATUS_V(status),
2282 : get_friendly_nt_error_msg(status));
2283 0 : talloc_free(frame);
2284 0 : return NULL;
2285 : }
2286 :
2287 0 : talloc_free(frame);
2288 0 : Py_RETURN_NONE;
2289 : }
2290 :
2291 :
2292 0 : static PyObject *py_pdb_del_groupmem(PyObject *self, PyObject *args)
2293 : {
2294 0 : TALLOC_CTX *frame = talloc_stackframe();
2295 0 : NTSTATUS status;
2296 0 : struct pdb_methods *methods;
2297 0 : uint32_t group_rid, member_rid;
2298 :
2299 0 : if (!PyArg_ParseTuple(args, "II:del_groupmem", &group_rid, &member_rid)) {
2300 0 : talloc_free(frame);
2301 0 : return NULL;
2302 : }
2303 :
2304 0 : methods = pytalloc_get_ptr(self);
2305 :
2306 0 : status = methods->del_groupmem(methods, frame, group_rid, member_rid);
2307 0 : if (!NT_STATUS_IS_OK(status)) {
2308 0 : PyErr_Format(py_pdb_error, "Unable to rename sam account, (%d,%s)",
2309 : NT_STATUS_V(status),
2310 : get_friendly_nt_error_msg(status));
2311 0 : talloc_free(frame);
2312 0 : return NULL;
2313 : }
2314 :
2315 0 : talloc_free(frame);
2316 0 : Py_RETURN_NONE;
2317 : }
2318 :
2319 :
2320 0 : static PyObject *py_pdb_create_alias(PyObject *self, PyObject *args)
2321 : {
2322 0 : TALLOC_CTX *frame = talloc_stackframe();
2323 0 : NTSTATUS status;
2324 0 : struct pdb_methods *methods;
2325 0 : const char *alias_name;
2326 0 : uint32_t rid;
2327 :
2328 0 : if (!PyArg_ParseTuple(args, "s:create_alias", &alias_name)) {
2329 0 : talloc_free(frame);
2330 0 : return NULL;
2331 : }
2332 :
2333 0 : methods = pytalloc_get_ptr(self);
2334 :
2335 0 : status = methods->create_alias(methods, alias_name, &rid);
2336 0 : if (!NT_STATUS_IS_OK(status)) {
2337 0 : PyErr_Format(py_pdb_error, "Unable to create alias (%s), (%d,%s)",
2338 : alias_name,
2339 : NT_STATUS_V(status),
2340 : get_friendly_nt_error_msg(status));
2341 0 : talloc_free(frame);
2342 0 : return NULL;
2343 : }
2344 :
2345 0 : talloc_free(frame);
2346 0 : return PyLong_FromLong(rid);
2347 : }
2348 :
2349 :
2350 0 : static PyObject *py_pdb_delete_alias(PyObject *self, PyObject *args)
2351 : {
2352 0 : TALLOC_CTX *frame = talloc_stackframe();
2353 0 : NTSTATUS status;
2354 0 : struct pdb_methods *methods;
2355 0 : PyObject *py_alias_sid;
2356 0 : struct dom_sid *alias_sid;
2357 :
2358 0 : if (!PyArg_ParseTuple(args, "O!:delete_alias", dom_sid_Type, &py_alias_sid)) {
2359 0 : talloc_free(frame);
2360 0 : return NULL;
2361 : }
2362 :
2363 0 : methods = pytalloc_get_ptr(self);
2364 :
2365 0 : alias_sid = pytalloc_get_ptr(py_alias_sid);
2366 :
2367 0 : status = methods->delete_alias(methods, alias_sid);
2368 0 : if (!NT_STATUS_IS_OK(status)) {
2369 0 : PyErr_Format(py_pdb_error, "Unable to delete alias, (%d,%s)",
2370 : NT_STATUS_V(status),
2371 : get_friendly_nt_error_msg(status));
2372 0 : talloc_free(frame);
2373 0 : return NULL;
2374 : }
2375 :
2376 0 : talloc_free(frame);
2377 0 : Py_RETURN_NONE;
2378 : }
2379 :
2380 :
2381 0 : static PyObject *py_pdb_get_aliasinfo(PyObject *self, PyObject *args)
2382 : {
2383 0 : TALLOC_CTX *frame = talloc_stackframe();
2384 0 : NTSTATUS status;
2385 0 : struct pdb_methods *methods;
2386 0 : PyObject *py_alias_sid;
2387 0 : struct dom_sid *alias_sid;
2388 0 : struct acct_info *alias_info;
2389 0 : PyObject *py_alias_info;
2390 :
2391 0 : if (!PyArg_ParseTuple(args, "O!:get_aliasinfo", dom_sid_Type, &py_alias_sid)) {
2392 0 : talloc_free(frame);
2393 0 : return NULL;
2394 : }
2395 :
2396 0 : methods = pytalloc_get_ptr(self);
2397 :
2398 0 : alias_sid = pytalloc_get_ptr(py_alias_sid);
2399 :
2400 0 : alias_info = talloc_zero(frame, struct acct_info);
2401 0 : if (!alias_info) {
2402 0 : PyErr_NoMemory();
2403 0 : talloc_free(frame);
2404 0 : return NULL;
2405 : }
2406 :
2407 0 : status = methods->get_aliasinfo(methods, alias_sid, alias_info);
2408 0 : if (!NT_STATUS_IS_OK(status)) {
2409 0 : PyErr_Format(py_pdb_error, "Unable to get alias information, (%d,%s)",
2410 : NT_STATUS_V(status),
2411 : get_friendly_nt_error_msg(status));
2412 0 : talloc_free(frame);
2413 0 : return NULL;
2414 : }
2415 :
2416 0 : py_alias_info = Py_BuildValue(
2417 : "{s:s, s:s, s:l}",
2418 : "acct_name", alias_info->acct_name,
2419 : "acct_desc", alias_info->acct_desc,
2420 : "rid", alias_info->rid);
2421 :
2422 0 : talloc_free(frame);
2423 0 : return py_alias_info;
2424 : }
2425 :
2426 :
2427 0 : static PyObject *py_pdb_set_aliasinfo(PyObject *self, PyObject *args)
2428 : {
2429 0 : TALLOC_CTX *frame = talloc_stackframe();
2430 0 : NTSTATUS status;
2431 0 : struct pdb_methods *methods;
2432 0 : PyObject *py_alias_sid, *py_alias_info;
2433 0 : struct dom_sid *alias_sid;
2434 0 : struct acct_info alias_info;
2435 :
2436 0 : if (!PyArg_ParseTuple(args, "O!O:set_alias_info", dom_sid_Type, &py_alias_sid,
2437 : &py_alias_info)) {
2438 0 : talloc_free(frame);
2439 0 : return NULL;
2440 : }
2441 :
2442 0 : methods = pytalloc_get_ptr(self);
2443 :
2444 0 : alias_sid = pytalloc_get_ptr(py_alias_sid);
2445 :
2446 0 : alias_info.acct_name = talloc_strdup(frame, PyUnicode_AsUTF8(PyDict_GetItemString(py_alias_info, "acct_name")));
2447 0 : if (alias_info.acct_name == NULL) {
2448 0 : PyErr_Format(py_pdb_error, "Unable to allocate memory");
2449 0 : talloc_free(frame);
2450 0 : return NULL;
2451 : }
2452 0 : alias_info.acct_desc = talloc_strdup(frame, PyUnicode_AsUTF8(PyDict_GetItemString(py_alias_info, "acct_desc")));
2453 0 : if (alias_info.acct_desc == NULL) {
2454 0 : PyErr_Format(py_pdb_error, "Unable to allocate memory");
2455 0 : talloc_free(frame);
2456 0 : return NULL;
2457 : }
2458 :
2459 0 : status = methods->set_aliasinfo(methods, alias_sid, &alias_info);
2460 0 : if (!NT_STATUS_IS_OK(status)) {
2461 0 : PyErr_Format(py_pdb_error, "Unable to set alias information, (%d,%s)",
2462 : NT_STATUS_V(status),
2463 : get_friendly_nt_error_msg(status));
2464 0 : talloc_free(frame);
2465 0 : return NULL;
2466 : }
2467 :
2468 0 : talloc_free(frame);
2469 0 : Py_RETURN_NONE;
2470 : }
2471 :
2472 :
2473 0 : static PyObject *py_pdb_add_aliasmem(PyObject *self, PyObject *args)
2474 : {
2475 0 : TALLOC_CTX *frame = talloc_stackframe();
2476 0 : NTSTATUS status;
2477 0 : struct pdb_methods *methods;
2478 0 : PyObject *py_alias_sid, *py_member_sid;
2479 0 : struct dom_sid *alias_sid, *member_sid;
2480 :
2481 0 : if (!PyArg_ParseTuple(args, "O!O!:add_aliasmem", dom_sid_Type, &py_alias_sid,
2482 : dom_sid_Type, &py_member_sid)) {
2483 0 : talloc_free(frame);
2484 0 : return NULL;
2485 : }
2486 :
2487 0 : methods = pytalloc_get_ptr(self);
2488 :
2489 0 : alias_sid = pytalloc_get_ptr(py_alias_sid);
2490 0 : member_sid = pytalloc_get_ptr(py_member_sid);
2491 :
2492 0 : status = methods->add_aliasmem(methods, alias_sid, member_sid);
2493 0 : if (!NT_STATUS_IS_OK(status)) {
2494 0 : PyErr_Format(py_pdb_error, "Unable to add member to alias, (%d,%s)",
2495 : NT_STATUS_V(status),
2496 : get_friendly_nt_error_msg(status));
2497 0 : talloc_free(frame);
2498 0 : return NULL;
2499 : }
2500 :
2501 0 : talloc_free(frame);
2502 0 : Py_RETURN_NONE;
2503 : }
2504 :
2505 :
2506 0 : static PyObject *py_pdb_del_aliasmem(PyObject *self, PyObject *args)
2507 : {
2508 0 : TALLOC_CTX *frame = talloc_stackframe();
2509 0 : NTSTATUS status;
2510 0 : struct pdb_methods *methods;
2511 0 : PyObject *py_alias_sid, *py_member_sid;
2512 0 : const struct dom_sid *alias_sid, *member_sid;
2513 :
2514 0 : if (!PyArg_ParseTuple(args, "O!O!:del_aliasmem", dom_sid_Type, &py_alias_sid,
2515 : dom_sid_Type, &py_member_sid)) {
2516 0 : talloc_free(frame);
2517 0 : return NULL;
2518 : }
2519 :
2520 0 : methods = pytalloc_get_ptr(self);
2521 :
2522 0 : alias_sid = pytalloc_get_ptr(py_alias_sid);
2523 0 : member_sid = pytalloc_get_ptr(py_member_sid);
2524 :
2525 0 : status = methods->del_aliasmem(methods, alias_sid, member_sid);
2526 0 : if (!NT_STATUS_IS_OK(status)) {
2527 0 : PyErr_Format(py_pdb_error, "Unable to delete member from alias, (%d,%s)",
2528 : NT_STATUS_V(status),
2529 : get_friendly_nt_error_msg(status));
2530 0 : talloc_free(frame);
2531 0 : return NULL;
2532 : }
2533 :
2534 0 : talloc_free(frame);
2535 0 : Py_RETURN_NONE;
2536 : }
2537 :
2538 :
2539 30 : static PyObject *py_pdb_enum_aliasmem(PyObject *self, PyObject *args)
2540 : {
2541 30 : TALLOC_CTX *frame = talloc_stackframe();
2542 30 : NTSTATUS status;
2543 30 : struct pdb_methods *methods;
2544 30 : PyObject *py_alias_sid;
2545 30 : struct dom_sid *alias_sid, *member_sid, *tmp_sid;
2546 30 : PyObject *py_member_list, *py_member_sid;
2547 30 : size_t i, num_members;
2548 :
2549 30 : if (!PyArg_ParseTuple(args, "O!:enum_aliasmem", dom_sid_Type, &py_alias_sid)) {
2550 0 : talloc_free(frame);
2551 0 : return NULL;
2552 : }
2553 :
2554 30 : methods = pytalloc_get_ptr(self);
2555 :
2556 30 : alias_sid = pytalloc_get_ptr(py_alias_sid);
2557 :
2558 30 : status = methods->enum_aliasmem(methods, alias_sid, frame, &member_sid, &num_members);
2559 30 : if (!NT_STATUS_IS_OK(status)) {
2560 0 : PyErr_Format(py_pdb_error, "Unable to enumerate members for alias, (%d,%s)",
2561 : NT_STATUS_V(status),
2562 : get_friendly_nt_error_msg(status));
2563 0 : talloc_free(frame);
2564 0 : return NULL;
2565 : }
2566 :
2567 30 : py_member_list = PyList_New(0);
2568 30 : if (py_member_list == NULL) {
2569 0 : PyErr_NoMemory();
2570 0 : talloc_free(frame);
2571 0 : return NULL;
2572 : }
2573 :
2574 30 : for(i=0; i<num_members; i++) {
2575 0 : int res = 0;
2576 0 : py_member_sid = pytalloc_new(struct dom_sid, dom_sid_Type);
2577 0 : if (py_member_sid == NULL) {
2578 0 : PyErr_NoMemory();
2579 0 : Py_CLEAR(py_member_list);
2580 0 : talloc_free(frame);
2581 0 : return NULL;
2582 : }
2583 0 : tmp_sid = pytalloc_get_ptr(py_member_sid);
2584 0 : *tmp_sid = member_sid[i];
2585 0 : res = PyList_Append(py_member_list, py_member_sid);
2586 0 : Py_CLEAR(py_member_sid);
2587 0 : if (res == -1) {
2588 0 : Py_CLEAR(py_member_list);
2589 0 : talloc_free(frame);
2590 0 : return NULL;
2591 : }
2592 : }
2593 :
2594 30 : talloc_free(frame);
2595 30 : return py_member_list;
2596 : }
2597 :
2598 :
2599 4 : static PyObject *py_pdb_get_account_policy(PyObject *self, PyObject *unused)
2600 : {
2601 4 : TALLOC_CTX *frame = talloc_stackframe();
2602 4 : NTSTATUS status;
2603 4 : struct pdb_methods *methods;
2604 4 : PyObject *py_acct_policy;
2605 4 : uint32_t value;
2606 4 : const char **names;
2607 4 : int count, i;
2608 4 : enum pdb_policy_type type;
2609 :
2610 4 : methods = pytalloc_get_ptr(self);
2611 :
2612 4 : py_acct_policy = PyDict_New();
2613 4 : if (py_acct_policy == NULL) {
2614 0 : PyErr_NoMemory();
2615 0 : talloc_free(frame);
2616 0 : return NULL;
2617 : }
2618 :
2619 4 : account_policy_names_list(frame, &names, &count);
2620 48 : for (i=0; i<count; i++) {
2621 40 : type = account_policy_name_to_typenum(names[i]);
2622 40 : status = methods->get_account_policy(methods, type, &value);
2623 40 : if (NT_STATUS_IS_OK(status)) {
2624 40 : int res = 0;
2625 40 : PyObject *py_value = Py_BuildValue("i", value);
2626 40 : if (py_value == NULL) {
2627 0 : Py_CLEAR(py_acct_policy);
2628 0 : break;
2629 : }
2630 80 : res = PyDict_SetItemString(py_acct_policy,
2631 40 : names[i],
2632 : py_value);
2633 40 : Py_CLEAR(py_value);
2634 40 : if (res == -1) {
2635 0 : Py_CLEAR(py_acct_policy);
2636 0 : break;
2637 : }
2638 : }
2639 : }
2640 :
2641 4 : talloc_free(frame);
2642 4 : return py_acct_policy;
2643 : }
2644 :
2645 :
2646 0 : static PyObject *py_pdb_set_account_policy(PyObject *self, PyObject *args)
2647 : {
2648 0 : TALLOC_CTX *frame = talloc_stackframe();
2649 0 : NTSTATUS status;
2650 0 : struct pdb_methods *methods;
2651 0 : PyObject *py_acct_policy, *py_value;
2652 0 : const char **names;
2653 0 : int count, i;
2654 0 : enum pdb_policy_type type;
2655 :
2656 0 : if (!PyArg_ParseTuple(args, "O!:set_account_policy", PyDict_Type, &py_acct_policy)) {
2657 0 : talloc_free(frame);
2658 0 : return NULL;
2659 : }
2660 :
2661 0 : methods = pytalloc_get_ptr(self);
2662 :
2663 0 : account_policy_names_list(frame, &names, &count);
2664 0 : for (i=0; i<count; i++) {
2665 0 : if ((py_value = PyDict_GetItemString(py_acct_policy, names[i])) != NULL) {
2666 0 : type = account_policy_name_to_typenum(names[i]);
2667 0 : status = methods->set_account_policy(methods, type, PyLong_AsLong(py_value));
2668 0 : if (!NT_STATUS_IS_OK(status)) {
2669 0 : PyErr_Format(py_pdb_error, "Error setting account policy (%s), (%d,%s)",
2670 0 : names[i],
2671 : NT_STATUS_V(status),
2672 : get_friendly_nt_error_msg(status));
2673 : }
2674 : }
2675 : }
2676 :
2677 0 : talloc_free(frame);
2678 0 : Py_RETURN_NONE;
2679 : }
2680 :
2681 7 : static PyObject *py_pdb_search_users(PyObject *self, PyObject *args)
2682 : {
2683 7 : TALLOC_CTX *frame = talloc_stackframe();
2684 7 : struct pdb_methods *methods;
2685 7 : unsigned int acct_flags;
2686 7 : struct pdb_search *search;
2687 7 : struct samr_displayentry *entry;
2688 7 : PyObject *py_userlist, *py_dict;
2689 :
2690 7 : if (!PyArg_ParseTuple(args, "I:search_users", &acct_flags)) {
2691 0 : talloc_free(frame);
2692 0 : return NULL;
2693 : }
2694 :
2695 7 : methods = pytalloc_get_ptr(self);
2696 :
2697 7 : search = talloc_zero(frame, struct pdb_search);
2698 7 : if (search == NULL) {
2699 0 : PyErr_NoMemory();
2700 0 : talloc_free(frame);
2701 0 : return NULL;
2702 : }
2703 :
2704 7 : if (!methods->search_users(methods, search, acct_flags)) {
2705 0 : PyErr_Format(py_pdb_error, "Unable to search users");
2706 0 : talloc_free(frame);
2707 0 : return NULL;
2708 : }
2709 :
2710 7 : entry = talloc_zero(frame, struct samr_displayentry);
2711 7 : if (entry == NULL) {
2712 0 : PyErr_NoMemory();
2713 0 : talloc_free(frame);
2714 0 : return NULL;
2715 : }
2716 :
2717 7 : py_userlist = PyList_New(0);
2718 7 : if (py_userlist == NULL) {
2719 0 : PyErr_NoMemory();
2720 0 : talloc_free(frame);
2721 0 : return NULL;
2722 : }
2723 :
2724 28 : while (search->next_entry(search, entry)) {
2725 21 : int res = 1;
2726 21 : py_dict = Py_BuildValue(
2727 : "{s:l, s:l, s:l, s:s, s:s, s:s}",
2728 : "idx", entry->idx,
2729 : "rid", entry->rid,
2730 : "acct_flags", entry->acct_flags,
2731 : "account_name", entry->account_name,
2732 : "fullname", entry->fullname,
2733 : "description", entry->description);
2734 21 : if (py_dict == NULL) {
2735 0 : Py_CLEAR(py_userlist);
2736 0 : goto out;
2737 : }
2738 :
2739 21 : res = PyList_Append(py_userlist, py_dict);
2740 21 : Py_CLEAR(py_dict);
2741 21 : if (res == -1) {
2742 0 : Py_CLEAR(py_userlist);
2743 0 : goto out;
2744 : }
2745 : }
2746 7 : search->search_end(search);
2747 :
2748 7 : out:
2749 7 : talloc_free(frame);
2750 7 : return py_userlist;
2751 : }
2752 :
2753 :
2754 0 : static PyObject *py_pdb_search_groups(PyObject *self, PyObject *unused)
2755 : {
2756 0 : TALLOC_CTX *frame = talloc_stackframe();
2757 0 : struct pdb_methods *methods;
2758 0 : struct pdb_search *search;
2759 0 : struct samr_displayentry *entry;
2760 0 : PyObject *py_grouplist, *py_dict;
2761 :
2762 0 : methods = pytalloc_get_ptr(self);
2763 :
2764 0 : search = talloc_zero(frame, struct pdb_search);
2765 0 : if (search == NULL) {
2766 0 : PyErr_NoMemory();
2767 0 : talloc_free(frame);
2768 0 : return NULL;
2769 : }
2770 :
2771 0 : if (!methods->search_groups(methods, search)) {
2772 0 : PyErr_Format(py_pdb_error, "Unable to search groups");
2773 0 : talloc_free(frame);
2774 0 : return NULL;
2775 : }
2776 :
2777 0 : entry = talloc_zero(frame, struct samr_displayentry);
2778 0 : if (entry == NULL) {
2779 0 : PyErr_NoMemory();
2780 0 : talloc_free(frame);
2781 0 : return NULL;
2782 : }
2783 :
2784 0 : py_grouplist = PyList_New(0);
2785 0 : if (py_grouplist == NULL) {
2786 0 : PyErr_NoMemory();
2787 0 : talloc_free(frame);
2788 0 : return NULL;
2789 : }
2790 :
2791 0 : while (search->next_entry(search, entry)) {
2792 0 : int res = 0;
2793 0 : py_dict = Py_BuildValue(
2794 : "{s:l, s:l, s:l, s:s, s:s, s:s}",
2795 : "idx", entry->idx,
2796 : "rid", entry->rid,
2797 : "acct_flags", entry->acct_flags,
2798 : "account_name", entry->account_name,
2799 : "fullname", entry->fullname,
2800 : "description", entry->description);
2801 :
2802 0 : if (py_dict == NULL) {
2803 0 : Py_CLEAR(py_grouplist);
2804 0 : goto out;
2805 : }
2806 :
2807 0 : res = PyList_Append(py_grouplist, py_dict);
2808 0 : Py_CLEAR(py_dict);
2809 0 : if (res == -1) {
2810 0 : Py_CLEAR(py_grouplist);
2811 0 : goto out;
2812 : }
2813 : }
2814 0 : search->search_end(search);
2815 0 : out:
2816 0 : talloc_free(frame);
2817 0 : return py_grouplist;
2818 : }
2819 :
2820 :
2821 2 : static PyObject *py_pdb_search_aliases(PyObject *self, PyObject *args)
2822 : {
2823 2 : TALLOC_CTX *frame = talloc_stackframe();
2824 2 : struct pdb_methods *methods;
2825 2 : struct pdb_search *search;
2826 2 : struct samr_displayentry *entry;
2827 2 : PyObject *py_aliaslist, *py_dict;
2828 2 : PyObject *py_domain_sid = Py_None;
2829 2 : struct dom_sid *domain_sid = NULL;
2830 :
2831 2 : if (!PyArg_ParseTuple(args, "|O!:search_aliases", dom_sid_Type, &py_domain_sid)) {
2832 0 : talloc_free(frame);
2833 0 : return NULL;
2834 : }
2835 :
2836 2 : methods = pytalloc_get_ptr(self);
2837 :
2838 2 : if (py_domain_sid != Py_None) {
2839 0 : domain_sid = pytalloc_get_ptr(py_domain_sid);
2840 : }
2841 :
2842 2 : search = talloc_zero(frame, struct pdb_search);
2843 2 : if (search == NULL) {
2844 0 : PyErr_NoMemory();
2845 0 : talloc_free(frame);
2846 0 : return NULL;
2847 : }
2848 :
2849 2 : if (!methods->search_aliases(methods, search, domain_sid)) {
2850 0 : PyErr_Format(py_pdb_error, "Unable to search aliases");
2851 0 : talloc_free(frame);
2852 0 : return NULL;
2853 : }
2854 :
2855 2 : entry = talloc_zero(frame, struct samr_displayentry);
2856 2 : if (entry == NULL) {
2857 0 : PyErr_NoMemory();
2858 0 : talloc_free(frame);
2859 0 : return NULL;
2860 : }
2861 :
2862 2 : py_aliaslist = PyList_New(0);
2863 2 : if (py_aliaslist == NULL) {
2864 0 : PyErr_NoMemory();
2865 0 : talloc_free(frame);
2866 0 : return NULL;
2867 : }
2868 :
2869 4 : while (search->next_entry(search, entry)) {
2870 2 : int res = 0;
2871 :
2872 2 : py_dict = Py_BuildValue(
2873 : "{s:l, s:l, s:l, s:s, s:s, s:s}",
2874 : "idx", entry->idx,
2875 : "rid", entry->rid,
2876 : "acct_flags", entry->acct_flags,
2877 : "account_name", entry->account_name,
2878 : "fullname", entry->fullname,
2879 : "description", entry->description);
2880 :
2881 2 : if (py_dict == NULL) {
2882 0 : Py_CLEAR(py_aliaslist);
2883 0 : goto out;
2884 : }
2885 2 : res = PyList_Append(py_aliaslist, py_dict);
2886 2 : Py_CLEAR(py_dict);
2887 2 : if (res == -1) {
2888 0 : Py_CLEAR(py_aliaslist);
2889 0 : goto out;
2890 : }
2891 : }
2892 2 : search->search_end(search);
2893 2 : out:
2894 2 : talloc_free(frame);
2895 2 : return py_aliaslist;
2896 : }
2897 :
2898 :
2899 36 : static PyObject *py_pdb_uid_to_sid(PyObject *self, PyObject *args)
2900 : {
2901 36 : TALLOC_CTX *frame = talloc_stackframe();
2902 0 : struct pdb_methods *methods;
2903 0 : struct unixid id;
2904 0 : unsigned int uid;
2905 0 : struct dom_sid user_sid, *copy_user_sid;
2906 0 : PyObject *py_user_sid;
2907 :
2908 36 : if (!PyArg_ParseTuple(args, "I:uid_to_sid", &uid)) {
2909 0 : talloc_free(frame);
2910 0 : return NULL;
2911 : }
2912 :
2913 36 : methods = pytalloc_get_ptr(self);
2914 :
2915 36 : id.id = uid;
2916 36 : id.type = ID_TYPE_UID;
2917 :
2918 36 : if (!methods->id_to_sid(methods, &id, &user_sid)) {
2919 0 : PyErr_Format(py_pdb_error, "Unable to get sid for uid=%d", uid);
2920 0 : talloc_free(frame);
2921 0 : return NULL;
2922 : }
2923 :
2924 36 : copy_user_sid = dom_sid_dup(frame, &user_sid);
2925 36 : if (copy_user_sid == NULL) {
2926 0 : PyErr_NoMemory();
2927 0 : talloc_free(frame);
2928 0 : return NULL;
2929 : }
2930 :
2931 36 : py_user_sid = pytalloc_steal(dom_sid_Type, copy_user_sid);
2932 :
2933 36 : talloc_free(frame);
2934 36 : return py_user_sid;
2935 : }
2936 :
2937 :
2938 24 : static PyObject *py_pdb_gid_to_sid(PyObject *self, PyObject *args)
2939 : {
2940 24 : TALLOC_CTX *frame = talloc_stackframe();
2941 0 : struct pdb_methods *methods;
2942 0 : struct unixid id;
2943 0 : unsigned int gid;
2944 0 : struct dom_sid group_sid, *copy_group_sid;
2945 0 : PyObject *py_group_sid;
2946 :
2947 24 : if (!PyArg_ParseTuple(args, "I:gid_to_sid", &gid)) {
2948 0 : talloc_free(frame);
2949 0 : return NULL;
2950 : }
2951 :
2952 24 : id.id = gid;
2953 24 : id.type = ID_TYPE_GID;
2954 :
2955 24 : methods = pytalloc_get_ptr(self);
2956 :
2957 24 : if (!methods->id_to_sid(methods, &id, &group_sid)) {
2958 0 : PyErr_Format(py_pdb_error, "Unable to get sid for gid=%d", gid);
2959 0 : talloc_free(frame);
2960 0 : return NULL;
2961 : }
2962 :
2963 24 : copy_group_sid = dom_sid_dup(frame, &group_sid);
2964 24 : if (copy_group_sid == NULL) {
2965 0 : PyErr_NoMemory();
2966 0 : talloc_free(frame);
2967 0 : return NULL;
2968 : }
2969 :
2970 24 : py_group_sid = pytalloc_steal(dom_sid_Type, copy_group_sid);
2971 :
2972 24 : talloc_free(frame);
2973 24 : return py_group_sid;
2974 : }
2975 :
2976 :
2977 1760 : static PyObject *py_pdb_sid_to_id(PyObject *self, PyObject *args)
2978 : {
2979 1760 : TALLOC_CTX *frame = talloc_stackframe();
2980 111 : struct pdb_methods *methods;
2981 111 : PyObject *py_sid;
2982 111 : struct dom_sid *sid;
2983 111 : struct unixid id;
2984 :
2985 1760 : if (!PyArg_ParseTuple(args, "O!:sid_to_id", dom_sid_Type, &py_sid)) {
2986 0 : talloc_free(frame);
2987 0 : return NULL;
2988 : }
2989 :
2990 1760 : methods = pytalloc_get_ptr(self);
2991 :
2992 1760 : sid = pytalloc_get_ptr(py_sid);
2993 :
2994 1760 : if (!methods->sid_to_id(methods, sid, &id)) {
2995 3 : PyErr_Format(py_pdb_error, "Unable to get id for sid");
2996 3 : talloc_free(frame);
2997 3 : return NULL;
2998 : }
2999 :
3000 1757 : talloc_free(frame);
3001 1757 : return Py_BuildValue("(II)", id.id, id.type);
3002 : }
3003 :
3004 :
3005 0 : static PyObject *py_pdb_new_rid(PyObject *self, PyObject *unused)
3006 : {
3007 0 : TALLOC_CTX *frame = talloc_stackframe();
3008 0 : struct pdb_methods *methods;
3009 0 : uint32_t rid;
3010 :
3011 0 : methods = pytalloc_get_ptr(self);
3012 :
3013 0 : if (!methods->new_rid(methods, &rid)) {
3014 0 : PyErr_Format(py_pdb_error, "Unable to get new rid");
3015 0 : talloc_free(frame);
3016 0 : return NULL;
3017 : }
3018 :
3019 0 : talloc_free(frame);
3020 0 : return PyLong_FromLong(rid);
3021 : }
3022 :
3023 :
3024 0 : static PyObject *py_pdb_get_trusteddom_pw(PyObject *self, PyObject *args)
3025 : {
3026 0 : TALLOC_CTX *frame = talloc_stackframe();
3027 0 : struct pdb_methods *methods;
3028 0 : const char *domain;
3029 0 : char *pwd;
3030 0 : struct dom_sid sid, *copy_sid;
3031 0 : PyObject *py_sid;
3032 0 : time_t last_set_time;
3033 0 : PyObject *py_value;
3034 :
3035 0 : if (!PyArg_ParseTuple(args, "s:get_trusteddom_pw", &domain)) {
3036 0 : talloc_free(frame);
3037 0 : return NULL;
3038 : }
3039 :
3040 0 : methods = pytalloc_get_ptr(self);
3041 :
3042 0 : if (!methods->get_trusteddom_pw(methods, domain, &pwd, &sid, &last_set_time)) {
3043 0 : PyErr_Format(py_pdb_error, "Unable to get trusted domain password");
3044 0 : talloc_free(frame);
3045 0 : return NULL;
3046 : }
3047 :
3048 0 : copy_sid = dom_sid_dup(frame, &sid);
3049 0 : if (copy_sid == NULL) {
3050 0 : PyErr_NoMemory();
3051 0 : talloc_free(frame);
3052 0 : return NULL;
3053 : }
3054 :
3055 0 : py_sid = pytalloc_steal(dom_sid_Type, copy_sid);
3056 0 : if (py_sid == NULL) {
3057 0 : PyErr_NoMemory();
3058 0 : talloc_free(frame);
3059 0 : return NULL;
3060 : }
3061 :
3062 0 : py_value = Py_BuildValue(
3063 : "{s:s, s:O, s:l}",
3064 : "pwd", pwd,
3065 : "sid", py_sid,
3066 : "last_set_tim", last_set_time);
3067 :
3068 0 : Py_CLEAR(py_sid);
3069 0 : talloc_free(frame);
3070 0 : return py_value;
3071 : }
3072 :
3073 :
3074 0 : static PyObject *py_pdb_set_trusteddom_pw(PyObject *self, PyObject *args)
3075 : {
3076 0 : TALLOC_CTX *frame = talloc_stackframe();
3077 0 : struct pdb_methods *methods;
3078 0 : const char *domain;
3079 0 : const char *pwd;
3080 0 : const struct dom_sid *domain_sid;
3081 0 : PyObject *py_domain_sid;
3082 :
3083 0 : if (!PyArg_ParseTuple(args, "ssO!:set_trusteddom_pw", &domain, &pwd,
3084 : dom_sid_Type, &py_domain_sid)) {
3085 0 : talloc_free(frame);
3086 0 : return NULL;
3087 : }
3088 :
3089 0 : methods = pytalloc_get_ptr(self);
3090 :
3091 0 : domain_sid = pytalloc_get_ptr(py_domain_sid);
3092 :
3093 0 : if (!methods->set_trusteddom_pw(methods, domain, pwd, domain_sid)) {
3094 0 : PyErr_Format(py_pdb_error, "Unable to set trusted domain password");
3095 0 : talloc_free(frame);
3096 0 : return NULL;
3097 : }
3098 :
3099 0 : talloc_free(frame);
3100 0 : Py_RETURN_NONE;
3101 : }
3102 :
3103 :
3104 0 : static PyObject *py_pdb_del_trusteddom_pw(PyObject *self, PyObject *args)
3105 : {
3106 0 : TALLOC_CTX *frame = talloc_stackframe();
3107 0 : struct pdb_methods *methods;
3108 0 : const char *domain;
3109 :
3110 0 : if (!PyArg_ParseTuple(args, "s:del_trusteddom_pw", &domain)) {
3111 0 : talloc_free(frame);
3112 0 : return NULL;
3113 : }
3114 :
3115 0 : methods = pytalloc_get_ptr(self);
3116 :
3117 0 : if (!methods->del_trusteddom_pw(methods, domain)) {
3118 0 : PyErr_Format(py_pdb_error, "Unable to delete trusted domain password");
3119 0 : talloc_free(frame);
3120 0 : return NULL;
3121 : }
3122 :
3123 0 : talloc_free(frame);
3124 0 : Py_RETURN_NONE;
3125 : }
3126 :
3127 :
3128 0 : static PyObject *py_pdb_enum_trusteddoms(PyObject *self, PyObject *unused)
3129 : {
3130 0 : TALLOC_CTX *frame = talloc_stackframe();
3131 0 : NTSTATUS status;
3132 0 : struct pdb_methods *methods;
3133 0 : uint32_t i, num_domains;
3134 0 : struct trustdom_info **domains;
3135 0 : PyObject *py_domain_list, *py_dict;
3136 :
3137 0 : methods = pytalloc_get_ptr(self);
3138 :
3139 0 : status = methods->enum_trusteddoms(methods, frame, &num_domains, &domains);
3140 0 : if (!NT_STATUS_IS_OK(status)) {
3141 0 : PyErr_Format(py_pdb_error, "Unable to enumerate trusted domains, (%d,%s)",
3142 : NT_STATUS_V(status),
3143 : get_friendly_nt_error_msg(status));
3144 0 : talloc_free(frame);
3145 0 : return NULL;
3146 : }
3147 :
3148 0 : py_domain_list = PyList_New(0);
3149 0 : if (py_domain_list == NULL) {
3150 0 : PyErr_NoMemory();
3151 0 : talloc_free(frame);
3152 0 : return NULL;
3153 : }
3154 :
3155 0 : for(i=0; i<num_domains; i++) {
3156 0 : int res = 0;
3157 0 : PyObject *py_sid =
3158 0 : pytalloc_steal(dom_sid_Type, &domains[i]->sid);
3159 0 : py_dict = Py_BuildValue(
3160 : "{s:s, s:O}",
3161 0 : "name", domains[i]->name,
3162 : "sid", py_sid);
3163 0 : Py_CLEAR(py_sid);
3164 0 : if (py_dict == NULL) {
3165 0 : DBG_ERR("Failed to insert entry to dict\n");
3166 0 : Py_CLEAR(py_domain_list);
3167 0 : break;
3168 : }
3169 :
3170 0 : res = PyList_Append(py_domain_list, py_dict);
3171 0 : Py_CLEAR(py_dict);
3172 0 : if (res == -1) {
3173 0 : Py_CLEAR(py_domain_list);
3174 0 : break;
3175 : }
3176 : }
3177 :
3178 0 : talloc_free(frame);
3179 0 : return py_domain_list;
3180 : }
3181 :
3182 :
3183 0 : static PyObject *py_pdb_get_trusted_domain(PyObject *self, PyObject *args)
3184 : {
3185 0 : TALLOC_CTX *frame = talloc_stackframe();
3186 0 : NTSTATUS status;
3187 0 : struct pdb_methods *methods;
3188 0 : const char *domain;
3189 0 : struct pdb_trusted_domain *td;
3190 0 : PyObject *py_domain_info;
3191 0 : PyObject *py_sid = NULL;
3192 :
3193 0 : if (!PyArg_ParseTuple(args, "s:get_trusted_domain", &domain)) {
3194 0 : talloc_free(frame);
3195 0 : return NULL;
3196 : }
3197 :
3198 0 : methods = pytalloc_get_ptr(self);
3199 :
3200 0 : status = methods->get_trusted_domain(methods, frame, domain, &td);
3201 0 : if (!NT_STATUS_IS_OK(status)) {
3202 0 : PyErr_Format(py_pdb_error, "Unable to get trusted domain information, (%d,%s)",
3203 : NT_STATUS_V(status),
3204 : get_friendly_nt_error_msg(status));
3205 0 : talloc_free(frame);
3206 0 : return NULL;
3207 : }
3208 :
3209 0 : py_sid = pytalloc_steal(dom_sid_Type, &td->security_identifier);
3210 :
3211 0 : py_domain_info = Py_BuildValue(
3212 : "{s:s, s:s, s:O,"
3213 : " s:"PYARG_BYTES_LEN","
3214 : " s:"PYARG_BYTES_LEN","
3215 : " s:l, s:l, s:l,"
3216 : " s:"PYARG_BYTES_LEN"}",
3217 0 : "domain_name", td->domain_name,
3218 0 : "netbios_name", td->netbios_name,
3219 : "security_identifier", py_sid,
3220 : "trust_auth_incoming",
3221 0 : (const char *)td->trust_auth_incoming.data,
3222 0 : td->trust_auth_incoming.length,
3223 : "trust_auth_outgoing",
3224 0 : (const char *)td->trust_auth_outgoing.data,
3225 0 : td->trust_auth_outgoing.length,
3226 0 : "trust_direction", td->trust_direction,
3227 0 : "trust_type", td->trust_type,
3228 0 : "trust_attributes", td->trust_attributes,
3229 : "trust_forest_trust_info",
3230 0 : (const char *)td->trust_forest_trust_info.data,
3231 0 : td->trust_forest_trust_info.length);
3232 0 : Py_CLEAR(py_sid);
3233 :
3234 0 : talloc_free(frame);
3235 0 : return py_domain_info;
3236 : }
3237 :
3238 :
3239 0 : static PyObject *py_pdb_get_trusted_domain_by_sid(PyObject *self, PyObject *args)
3240 : {
3241 0 : TALLOC_CTX *frame = talloc_stackframe();
3242 0 : NTSTATUS status;
3243 0 : struct pdb_methods *methods;
3244 0 : PyObject *py_domain_sid;
3245 0 : struct dom_sid *domain_sid;
3246 0 : struct pdb_trusted_domain *td;
3247 0 : PyObject *py_domain_info;
3248 0 : PyObject *py_sid = NULL;
3249 :
3250 0 : if (!PyArg_ParseTuple(args, "O!:get_trusted_domain_by_sid", dom_sid_Type, &py_domain_sid)) {
3251 0 : talloc_free(frame);
3252 0 : return NULL;
3253 : }
3254 :
3255 0 : methods = pytalloc_get_ptr(self);
3256 :
3257 0 : domain_sid = pytalloc_get_ptr(py_domain_sid);
3258 :
3259 0 : status = methods->get_trusted_domain_by_sid(methods, frame, domain_sid, &td);
3260 0 : if (!NT_STATUS_IS_OK(status)) {
3261 0 : PyErr_Format(py_pdb_error, "Unable to get trusted domain information, (%d,%s)",
3262 : NT_STATUS_V(status),
3263 : get_friendly_nt_error_msg(status));
3264 0 : talloc_free(frame);
3265 0 : return NULL;
3266 : }
3267 :
3268 0 : py_sid = pytalloc_steal(dom_sid_Type, &td->security_identifier);
3269 :
3270 0 : py_domain_info = Py_BuildValue(
3271 : "{s:s, s:s, s:O,"
3272 : " s:"PYARG_BYTES_LEN","
3273 : " s:"PYARG_BYTES_LEN","
3274 : " s:l, s:l, s:l,"
3275 : " s:"PYARG_BYTES_LEN"}",
3276 0 : "domain_name", td->domain_name,
3277 0 : "netbios_name", td->netbios_name,
3278 : "security_identifier", py_sid,
3279 : "trust_auth_incoming",
3280 0 : (const char *)td->trust_auth_incoming.data,
3281 0 : td->trust_auth_incoming.length,
3282 : "trust_auth_outgoing",
3283 0 : (const char *)td->trust_auth_outgoing.data,
3284 0 : td->trust_auth_outgoing.length,
3285 0 : "trust_direction", td->trust_direction,
3286 0 : "trust_type", td->trust_type,
3287 0 : "trust_attributes", td->trust_attributes,
3288 : "trust_forest_trust_info",
3289 0 : (const char *)td->trust_forest_trust_info.data,
3290 0 : td->trust_forest_trust_info.length);
3291 0 : Py_CLEAR(py_sid);
3292 :
3293 0 : talloc_free(frame);
3294 0 : return py_domain_info;
3295 : }
3296 :
3297 :
3298 0 : static PyObject *py_pdb_set_trusted_domain(PyObject *self, PyObject *args)
3299 : {
3300 0 : TALLOC_CTX *frame = talloc_stackframe();
3301 0 : NTSTATUS status;
3302 0 : struct pdb_methods *methods;
3303 0 : const char *domain;
3304 0 : PyObject *py_td_info;
3305 0 : struct pdb_trusted_domain td_info;
3306 0 : PyObject *py_tmp;
3307 0 : Py_ssize_t len;
3308 :
3309 0 : if (!PyArg_ParseTuple(args, "sO!:set_trusted_domain", &domain, &PyDict_Type, &py_td_info)) {
3310 0 : talloc_free(frame);
3311 0 : return NULL;
3312 : }
3313 :
3314 0 : py_tmp = PyDict_GetItemString(py_td_info, "domain_name");
3315 0 : td_info.domain_name = discard_const_p(char, PyUnicode_AsUTF8(py_tmp));
3316 :
3317 0 : py_tmp = PyDict_GetItemString(py_td_info, "netbios_name");
3318 0 : td_info.netbios_name = discard_const_p(char, PyUnicode_AsUTF8(py_tmp));
3319 :
3320 0 : py_tmp = PyDict_GetItemString(py_td_info, "security_identifier");
3321 0 : td_info.security_identifier = *pytalloc_get_type(py_tmp, struct dom_sid);
3322 :
3323 0 : py_tmp = PyDict_GetItemString(py_td_info, "trust_auth_incoming");
3324 0 : PyBytes_AsStringAndSize(py_tmp, (char **)&td_info.trust_auth_incoming.data, &len);
3325 0 : td_info.trust_auth_incoming.length = len;
3326 :
3327 0 : py_tmp = PyDict_GetItemString(py_td_info, "trust_auth_outgoing");
3328 0 : PyBytes_AsStringAndSize(py_tmp, (char **)&td_info.trust_auth_outgoing.data, &len);
3329 0 : td_info.trust_auth_outgoing.length = len;
3330 :
3331 0 : py_tmp = PyDict_GetItemString(py_td_info, "trust_direction");
3332 0 : td_info.trust_direction = PyLong_AsLong(py_tmp);
3333 :
3334 0 : py_tmp = PyDict_GetItemString(py_td_info, "trust_type");
3335 0 : td_info.trust_type = PyLong_AsLong(py_tmp);
3336 :
3337 0 : py_tmp = PyDict_GetItemString(py_td_info, "trust_attributes");
3338 0 : td_info.trust_attributes = PyLong_AsLong(py_tmp);
3339 :
3340 0 : py_tmp = PyDict_GetItemString(py_td_info, "trust_forest_trust_info");
3341 0 : PyBytes_AsStringAndSize(py_tmp, (char **)&td_info.trust_forest_trust_info.data, &len);
3342 0 : td_info.trust_forest_trust_info.length = len;
3343 :
3344 0 : methods = pytalloc_get_ptr(self);
3345 :
3346 0 : status = methods->set_trusted_domain(methods, domain, &td_info);
3347 0 : if (!NT_STATUS_IS_OK(status)) {
3348 0 : PyErr_Format(py_pdb_error, "Unable to set trusted domain information, (%d,%s)",
3349 : NT_STATUS_V(status),
3350 : get_friendly_nt_error_msg(status));
3351 0 : talloc_free(frame);
3352 0 : return NULL;
3353 : }
3354 :
3355 0 : talloc_free(frame);
3356 0 : Py_RETURN_NONE;
3357 : }
3358 :
3359 :
3360 0 : static PyObject *py_pdb_del_trusted_domain(PyObject *self, PyObject *args)
3361 : {
3362 0 : TALLOC_CTX *frame = talloc_stackframe();
3363 0 : NTSTATUS status;
3364 0 : struct pdb_methods *methods;
3365 0 : const char *domain;
3366 :
3367 0 : if (!PyArg_ParseTuple(args, "s:del_trusted_domain", &domain)) {
3368 0 : talloc_free(frame);
3369 0 : return NULL;
3370 : }
3371 :
3372 0 : methods = pytalloc_get_ptr(self);
3373 :
3374 0 : status = methods->del_trusted_domain(methods, domain);
3375 0 : if (!NT_STATUS_IS_OK(status)) {
3376 0 : PyErr_Format(py_pdb_error, "Unable to delete trusted domain, (%d,%s)",
3377 : NT_STATUS_V(status),
3378 : get_friendly_nt_error_msg(status));
3379 0 : talloc_free(frame);
3380 0 : return NULL;
3381 : }
3382 :
3383 0 : talloc_free(frame);
3384 0 : Py_RETURN_NONE;
3385 : }
3386 :
3387 :
3388 0 : static PyObject *py_pdb_enum_trusted_domains(PyObject *self, PyObject *args)
3389 : {
3390 0 : TALLOC_CTX *frame = talloc_stackframe();
3391 0 : NTSTATUS status;
3392 0 : struct pdb_methods *methods;
3393 0 : uint32_t i, num_domains;
3394 0 : struct pdb_trusted_domain **td_info;
3395 0 : PyObject *py_td_info, *py_domain_info;
3396 :
3397 0 : methods = pytalloc_get_ptr(self);
3398 :
3399 0 : status = methods->enum_trusted_domains(methods, frame, &num_domains, &td_info);
3400 0 : if (!NT_STATUS_IS_OK(status)) {
3401 0 : PyErr_Format(py_pdb_error, "Unable to delete trusted domain, (%d,%s)",
3402 : NT_STATUS_V(status),
3403 : get_friendly_nt_error_msg(status));
3404 0 : talloc_free(frame);
3405 0 : return NULL;
3406 : }
3407 :
3408 0 : py_td_info = PyList_New(0);
3409 0 : if (py_td_info == NULL) {
3410 0 : PyErr_NoMemory();
3411 0 : talloc_free(frame);
3412 0 : return NULL;
3413 : }
3414 :
3415 0 : for (i=0; i<num_domains; i++) {
3416 0 : int res = 0;
3417 0 : struct pdb_trusted_domain *td = td_info[i];
3418 0 : PyObject *py_sid =
3419 0 : pytalloc_steal(dom_sid_Type, &td->security_identifier);
3420 :
3421 0 : py_domain_info = Py_BuildValue(
3422 : "{s:s, s:s, s:O,"
3423 : " s:"PYARG_BYTES_LEN","
3424 : " s:"PYARG_BYTES_LEN","
3425 : " s:l, s:l, s:l,"
3426 : " s:"PYARG_BYTES_LEN"}",
3427 : "domain_name", td->domain_name,
3428 : "netbios_name", td->netbios_name,
3429 : "security_identifier", py_sid,
3430 : "trust_auth_incoming",
3431 0 : (const char *)td->trust_auth_incoming.data,
3432 : td->trust_auth_incoming.length,
3433 : "trust_auth_outgoing",
3434 0 : (const char *)td->trust_auth_outgoing.data,
3435 : td->trust_auth_outgoing.length,
3436 : "trust_direction", td->trust_direction,
3437 : "trust_type", td->trust_type,
3438 : "trust_attributes", td->trust_attributes,
3439 : "trust_forest_trust_info",
3440 0 : (const char *)td->trust_forest_trust_info.data,
3441 : td->trust_forest_trust_info.length);
3442 0 : Py_CLEAR(py_sid);
3443 :
3444 0 : if (py_domain_info == NULL) {
3445 0 : Py_CLEAR(py_td_info);
3446 0 : break;
3447 : }
3448 0 : res = PyList_Append(py_td_info, py_domain_info);
3449 0 : Py_CLEAR(py_domain_info);
3450 0 : if (res == -1) {
3451 0 : Py_CLEAR(py_td_info);
3452 0 : break;
3453 : }
3454 : }
3455 :
3456 0 : talloc_free(frame);
3457 0 : return py_td_info;
3458 : }
3459 :
3460 :
3461 0 : static PyObject *py_pdb_get_secret(PyObject *self, PyObject *args)
3462 : {
3463 0 : TALLOC_CTX *frame = talloc_stackframe();
3464 0 : NTSTATUS status;
3465 0 : struct pdb_methods *methods;
3466 0 : const char *secret_name;
3467 0 : DATA_BLOB secret_current, secret_old;
3468 0 : NTTIME secret_current_lastchange, secret_old_lastchange;
3469 0 : PyObject *py_sd;
3470 0 : struct security_descriptor *sd;
3471 0 : PyObject *py_secret;
3472 :
3473 0 : if (!PyArg_ParseTuple(args, "s:get_secret_name", &secret_name)) {
3474 0 : talloc_free(frame);
3475 0 : return NULL;
3476 : }
3477 :
3478 0 : methods = pytalloc_get_ptr(self);
3479 :
3480 0 : py_sd = pytalloc_new(struct security_descriptor, security_Type);
3481 0 : if (py_sd == NULL) {
3482 0 : PyErr_NoMemory();
3483 0 : talloc_free(frame);
3484 0 : return NULL;
3485 : }
3486 0 : sd = pytalloc_get_ptr(py_sd);
3487 :
3488 0 : status = methods->get_secret(methods, frame, secret_name,
3489 : &secret_current,
3490 : &secret_current_lastchange,
3491 : &secret_old,
3492 : &secret_old_lastchange,
3493 : &sd);
3494 0 : if (!NT_STATUS_IS_OK(status)) {
3495 0 : PyErr_Format(py_pdb_error, "Unable to get information for secret (%s), (%d,%s)",
3496 : secret_name,
3497 : NT_STATUS_V(status),
3498 : get_friendly_nt_error_msg(status));
3499 0 : talloc_free(frame);
3500 0 : return NULL;
3501 : }
3502 :
3503 0 : py_secret = Py_BuildValue(
3504 : "{s:"PYARG_BYTES_LEN","
3505 : " s:K"
3506 : " s:"PYARG_BYTES_LEN","
3507 : " s:K, s:O}",
3508 0 : "secret_current", (const char*)secret_current.data,
3509 : secret_current.length,
3510 : "secret_current_lastchange", secret_current_lastchange,
3511 0 : "secret_old", (const char*)secret_old.data,
3512 : secret_old.length,
3513 : "secret_old_lastchange", secret_old_lastchange,
3514 : "sd", py_sd);
3515 :
3516 0 : Py_CLEAR(py_sd);
3517 0 : if (py_secret == NULL) {
3518 0 : talloc_free(frame);
3519 0 : return NULL;
3520 : }
3521 :
3522 0 : talloc_free(frame);
3523 0 : return py_secret;
3524 : }
3525 :
3526 :
3527 0 : static PyObject *py_pdb_set_secret(PyObject *self, PyObject *args)
3528 : {
3529 0 : TALLOC_CTX *frame = talloc_stackframe();
3530 0 : NTSTATUS status;
3531 0 : struct pdb_methods *methods;
3532 0 : const char *secret_name;
3533 0 : PyObject *py_secret;
3534 0 : PyObject *py_secret_cur, *py_secret_old, *py_sd;
3535 0 : DATA_BLOB secret_current, secret_old;
3536 0 : struct security_descriptor *sd;
3537 0 : Py_ssize_t len;
3538 :
3539 0 : if (!PyArg_ParseTuple(args, "sO!:set_secret_name", &secret_name, PyDict_Type, &py_secret)) {
3540 0 : talloc_free(frame);
3541 0 : return NULL;
3542 : }
3543 :
3544 0 : py_secret_cur = PyDict_GetItemString(py_secret, "secret_current");
3545 0 : py_secret_old = PyDict_GetItemString(py_secret, "secret_old");
3546 0 : py_sd = PyDict_GetItemString(py_secret, "sd");
3547 :
3548 0 : PY_CHECK_TYPE(&PyBytes_Type, py_secret_cur, return NULL;);
3549 0 : PY_CHECK_TYPE(&PyBytes_Type, py_secret_old, return NULL;);
3550 0 : PY_CHECK_TYPE(security_Type, py_sd, return NULL;);
3551 :
3552 0 : methods = pytalloc_get_ptr(self);
3553 :
3554 0 : PyBytes_AsStringAndSize(py_secret_cur, (char **)&secret_current.data, &len);
3555 0 : secret_current.length = len;
3556 0 : PyBytes_AsStringAndSize(py_secret_old, (char **)&secret_old.data, &len);
3557 0 : secret_current.length = len;
3558 0 : sd = pytalloc_get_ptr(py_sd);
3559 :
3560 0 : status = methods->set_secret(methods, secret_name, &secret_current, &secret_old, sd);
3561 0 : if (!NT_STATUS_IS_OK(status)) {
3562 0 : PyErr_Format(py_pdb_error, "Unable to set information for secret (%s), (%d,%s)",
3563 : secret_name,
3564 : NT_STATUS_V(status),
3565 : get_friendly_nt_error_msg(status));
3566 0 : talloc_free(frame);
3567 0 : return NULL;
3568 : }
3569 :
3570 0 : talloc_free(frame);
3571 0 : Py_RETURN_NONE;
3572 : }
3573 :
3574 :
3575 0 : static PyObject *py_pdb_delete_secret(PyObject *self, PyObject *args)
3576 : {
3577 0 : TALLOC_CTX *frame = talloc_stackframe();
3578 0 : NTSTATUS status;
3579 0 : struct pdb_methods *methods;
3580 0 : const char *secret_name;
3581 :
3582 0 : if (!PyArg_ParseTuple(args, "s:delete_secret", &secret_name)) {
3583 0 : talloc_free(frame);
3584 0 : return NULL;
3585 : }
3586 :
3587 0 : methods = pytalloc_get_ptr(self);
3588 :
3589 0 : status = methods->delete_secret(methods, secret_name);
3590 0 : if (!NT_STATUS_IS_OK(status)) {
3591 0 : PyErr_Format(py_pdb_error, "Unable to delete secret (%s), (%d,%s)",
3592 : secret_name,
3593 : NT_STATUS_V(status),
3594 : get_friendly_nt_error_msg(status));
3595 0 : talloc_free(frame);
3596 0 : return NULL;
3597 : }
3598 :
3599 0 : talloc_free(frame);
3600 0 : Py_RETURN_NONE;
3601 : }
3602 :
3603 : static PyMethodDef py_pdb_methods[] = {
3604 : { "domain_info", py_pdb_domain_info, METH_NOARGS,
3605 : "domain_info() -> str\n\n \
3606 : Get domain information for the database." },
3607 : { "getsampwnam", py_pdb_getsampwnam, METH_VARARGS,
3608 : "getsampwnam(username) -> samu object\n\n \
3609 : Get user information by name." },
3610 : { "getsampwsid", py_pdb_getsampwsid, METH_VARARGS,
3611 : "getsampwsid(user_sid) -> samu object\n\n \
3612 : Get user information by sid (dcerpc.security.dom_sid object)." },
3613 : { "create_user", py_pdb_create_user, METH_VARARGS,
3614 : "create_user(username, acct_flags) -> rid\n\n \
3615 : Create user. acct_flags are samr account control flags." },
3616 : { "delete_user", py_pdb_delete_user, METH_VARARGS,
3617 : "delete_user(samu object) -> None\n\n \
3618 : Delete user." },
3619 : { "add_sam_account", py_pdb_add_sam_account, METH_VARARGS,
3620 : "add_sam_account(samu object) -> None\n\n \
3621 : Add SAM account." },
3622 : { "update_sam_account", py_pdb_update_sam_account, METH_VARARGS,
3623 : "update_sam_account(samu object) -> None\n\n \
3624 : Update SAM account." },
3625 : { "delete_sam_account", py_pdb_delete_sam_account, METH_VARARGS,
3626 : "delete_sam_account(samu object) -> None\n\n \
3627 : Delete SAM account." },
3628 : { "rename_sam_account", py_pdb_rename_sam_account, METH_VARARGS,
3629 : "rename_sam_account(samu object1, new_username) -> None\n\n \
3630 : Rename SAM account." },
3631 : /* update_login_attempts */
3632 : { "getgrsid", py_pdb_getgrsid, METH_VARARGS,
3633 : "getgrsid(group_sid) -> groupmap object\n\n \
3634 : Get group information by sid (dcerpc.security.dom_sid object)." },
3635 : { "getgrgid", py_pdb_getgrgid, METH_VARARGS,
3636 : "getgrsid(gid) -> groupmap object\n\n \
3637 : Get group information by gid." },
3638 : { "getgrnam", py_pdb_getgrnam, METH_VARARGS,
3639 : "getgrsid(groupname) -> groupmap object\n\n \
3640 : Get group information by name." },
3641 : { "create_dom_group", py_pdb_create_dom_group, METH_VARARGS,
3642 : "create_dom_group(groupname) -> group_rid\n\n \
3643 : Create new domain group by name." },
3644 : { "delete_dom_group", py_pdb_delete_dom_group, METH_VARARGS,
3645 : "delete_dom_group(group_rid) -> None\n\n \
3646 : Delete domain group identified by rid" },
3647 : { "add_group_mapping_entry", py_pdb_add_group_mapping_entry, METH_VARARGS,
3648 : "add_group_mapping_entry(groupmap) -> None\n \
3649 : Add group mapping entry for groupmap object." },
3650 : { "update_group_mapping_entry", py_pdb_update_group_mapping_entry, METH_VARARGS,
3651 : "update_group_mapping_entry(groupmap) -> None\n\n \
3652 : Update group mapping entry for groupmap object." },
3653 : { "delete_group_mapping_entry", py_pdb_delete_group_mapping_entry, METH_VARARGS,
3654 : "delete_group_mapping_entry(groupmap) -> None\n\n \
3655 : Delete group mapping entry for groupmap object." },
3656 : { "enum_group_mapping", py_pdb_enum_group_mapping, METH_VARARGS,
3657 : "enum_group_mapping([domain_sid, [type, [unix_only]]]) -> List\n\n \
3658 : Return list of group mappings as groupmap objects. Optional arguments are domain_sid object, type of group, unix only flag." },
3659 : { "enum_group_members", py_pdb_enum_group_members, METH_VARARGS,
3660 : "enum_group_members(group_sid) -> List\n\n \
3661 : Return list of users (dom_sid object) in group." },
3662 : { "enum_group_memberships", py_pdb_enum_group_memberships, METH_VARARGS,
3663 : "enum_group_memberships(samu object) -> List\n\n \
3664 : Return list of groups (dom_sid object) this user is part of." },
3665 : /* set_unix_primary_group */
3666 : { "add_groupmem", py_pdb_add_groupmem, METH_VARARGS,
3667 : "add_groupmem(group_rid, member_rid) -> None\n\n \
3668 : Add user to group." },
3669 : { "del_groupmem", py_pdb_del_groupmem, METH_VARARGS,
3670 : "del_groupmem(group_rid, member_rid) -> None\n\n \
3671 : Remove user from group." },
3672 : { "create_alias", py_pdb_create_alias, METH_VARARGS,
3673 : "create_alias(alias_name) -> alias_rid\n\n \
3674 : Create alias entry." },
3675 : { "delete_alias", py_pdb_delete_alias, METH_VARARGS,
3676 : "delete_alias(alias_sid) -> None\n\n \
3677 : Delete alias entry." },
3678 : { "get_aliasinfo", py_pdb_get_aliasinfo, METH_VARARGS,
3679 : "get_aliasinfo(alias_sid) -> Mapping\n\n \
3680 : Get alias information as a dictionary with keys - acct_name, acct_desc, rid." },
3681 : { "set_aliasinfo", py_pdb_set_aliasinfo, METH_VARARGS,
3682 : "set_alias_info(alias_sid, Mapping) -> None\n\n \
3683 : Set alias information from a dictionary with keys - acct_name, acct_desc." },
3684 : { "add_aliasmem", py_pdb_add_aliasmem, METH_VARARGS,
3685 : "add_aliasmem(alias_sid, member_sid) -> None\n\n \
3686 : Add user to alias entry." },
3687 : { "del_aliasmem", py_pdb_del_aliasmem, METH_VARARGS,
3688 : "del_aliasmem(alias_sid, member_sid) -> None\n\n \
3689 : Remove a user from alias entry." },
3690 : { "enum_aliasmem", py_pdb_enum_aliasmem, METH_VARARGS,
3691 : "enum_aliasmem(alias_sid) -> List\n\n \
3692 : Return a list of members (dom_sid object) for alias entry." },
3693 : /* enum_alias_memberships */
3694 : /* lookup_rids */
3695 : /* lookup_names */
3696 : { "get_account_policy", py_pdb_get_account_policy, METH_NOARGS,
3697 : "get_account_policy() -> Mapping\n\n \
3698 : Get account policy information as a dictionary." },
3699 : { "set_account_policy", py_pdb_set_account_policy, METH_VARARGS,
3700 : "get_account_policy(Mapping) -> None\n\n \
3701 : Set account policy settings from a dictionary." },
3702 : /* get_seq_num */
3703 : { "search_users", py_pdb_search_users, METH_VARARGS,
3704 : "search_users(acct_flags) -> List\n\n \
3705 : Search users. acct_flags are samr account control flags.\n \
3706 : Each list entry is dictionary with keys - idx, rid, acct_flags, account_name, fullname, description." },
3707 : { "search_groups", py_pdb_search_groups, METH_NOARGS,
3708 : "search_groups() -> List\n\n \
3709 : Search unix only groups. \n \
3710 : Each list entry is dictionary with keys - idx, rid, acct_flags, account_name, fullname, description." },
3711 : { "search_aliases", py_pdb_search_aliases, METH_VARARGS,
3712 : "search_aliases([domain_sid]) -> List\n\n \
3713 : Search aliases. domain_sid is dcerpc.security.dom_sid object.\n \
3714 : Each list entry is dictionary with keys - idx, rid, acct_flags, account_name, fullname, description." },
3715 : { "uid_to_sid", py_pdb_uid_to_sid, METH_VARARGS,
3716 : "uid_to_sid(uid) -> sid\n\n \
3717 : Return sid for given user id." },
3718 : { "gid_to_sid", py_pdb_gid_to_sid, METH_VARARGS,
3719 : "gid_to_sid(gid) -> sid\n\n \
3720 : Return sid for given group id." },
3721 : { "sid_to_id", py_pdb_sid_to_id, METH_VARARGS,
3722 : "sid_to_id(sid) -> Tuple\n\n \
3723 : Return id and type for given sid." },
3724 : /* capabilities */
3725 : { "new_rid", py_pdb_new_rid, METH_NOARGS,
3726 : "new_rid() -> rid\n\n \
3727 : Get a new rid." },
3728 : { "get_trusteddom_pw", py_pdb_get_trusteddom_pw, METH_VARARGS,
3729 : "get_trusteddom_pw(domain) -> Mapping\n\n \
3730 : Get trusted domain password, sid and last set time in a dictionary." },
3731 : { "set_trusteddom_pw", py_pdb_set_trusteddom_pw, METH_VARARGS,
3732 : "set_trusteddom_pw(domain, pwd, sid) -> None\n\n \
3733 : Set trusted domain password." },
3734 : { "del_trusteddom_pw", py_pdb_del_trusteddom_pw, METH_VARARGS,
3735 : "del_trusteddom_pw(domain) -> None\n\n \
3736 : Delete trusted domain password." },
3737 : { "enum_trusteddoms", py_pdb_enum_trusteddoms, METH_NOARGS,
3738 : "enum_trusteddoms() -> List\n\n \
3739 : Get list of trusted domains. Each item is a dictionary with name and sid keys" },
3740 : { "get_trusted_domain", py_pdb_get_trusted_domain, METH_VARARGS,
3741 : "get_trusted_domain(domain) -> Mapping\n\n \
3742 : 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." },
3743 : { "get_trusted_domain_by_sid", py_pdb_get_trusted_domain_by_sid, METH_VARARGS,
3744 : "get_trusted_domain_by_sid(domain_sid) -> Mapping\n\n \
3745 : 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" },
3746 : { "set_trusted_domain", py_pdb_set_trusted_domain, METH_VARARGS,
3747 : "set_trusted_domain(domain, Mapping) -> None\n\n \
3748 : 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." },
3749 : { "del_trusted_domain", py_pdb_del_trusted_domain, METH_VARARGS,
3750 : "del_trusted_domain(domain) -> None\n\n \
3751 : Delete trusted domain." },
3752 : { "enum_trusted_domains", py_pdb_enum_trusted_domains, METH_VARARGS,
3753 : "enum_trusted_domains() -> List\n\n \
3754 : 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." },
3755 : { "get_secret", py_pdb_get_secret, METH_VARARGS,
3756 : "get_secret(secret_name) -> Mapping\n\n \
3757 : Get secret information for secret_name. Information is a dictionary with keys - secret_current, secret_current_lastchange, secret_old, secret_old_lastchange, sd." },
3758 : { "set_secret", py_pdb_set_secret, METH_VARARGS,
3759 : "set_secret(secret_name, Mapping) -> None\n\n \
3760 : Set secret information for secret_name using dictionary with keys - secret_current, sd." },
3761 : { "delete_secret", py_pdb_delete_secret, METH_VARARGS,
3762 : "delete_secret(secret_name) -> None\n\n \
3763 : Delete secret information for secret_name." },
3764 : {0},
3765 : };
3766 :
3767 :
3768 221 : static PyObject *py_pdb_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
3769 : {
3770 221 : TALLOC_CTX *frame = talloc_stackframe();
3771 221 : const char *url = NULL;
3772 20 : PyObject *pypdb;
3773 20 : NTSTATUS status;
3774 20 : struct pdb_methods *methods;
3775 :
3776 221 : if (!PyArg_ParseTuple(args, "s", &url)) {
3777 0 : talloc_free(frame);
3778 0 : return NULL;
3779 : }
3780 :
3781 : /* Initialize list of methods */
3782 221 : status = make_pdb_method_name(&methods, url);
3783 221 : if (!NT_STATUS_IS_OK(status)) {
3784 0 : PyErr_Format(py_pdb_error, "Cannot load backend methods for '%s' backend (%d,%s)",
3785 : url,
3786 : NT_STATUS_V(status),
3787 : get_friendly_nt_error_msg(status));
3788 0 : talloc_free(frame);
3789 0 : return NULL;
3790 : }
3791 :
3792 221 : if ((pypdb = pytalloc_steal(type, methods)) == NULL) {
3793 0 : PyErr_NoMemory();
3794 0 : talloc_free(frame);
3795 0 : return NULL;
3796 : }
3797 :
3798 221 : talloc_free(frame);
3799 221 : return pypdb;
3800 : }
3801 :
3802 :
3803 : static PyTypeObject PyPDB = {
3804 : .tp_name = "passdb.PDB",
3805 : .tp_new = py_pdb_new,
3806 : .tp_flags = Py_TPFLAGS_DEFAULT,
3807 : .tp_methods = py_pdb_methods,
3808 : .tp_doc = "PDB(url[, read_write_flags]) -> Password DB object\n",
3809 : };
3810 :
3811 :
3812 : /*
3813 : * Return a list of passdb backends
3814 : */
3815 0 : static PyObject *py_passdb_backends(PyObject *self, PyObject *unused)
3816 : {
3817 0 : TALLOC_CTX *frame = talloc_stackframe();
3818 0 : PyObject *py_blist;
3819 0 : const struct pdb_init_function_entry *entry;
3820 :
3821 0 : entry = pdb_get_backends();
3822 0 : if(! entry) {
3823 0 : Py_RETURN_NONE;
3824 : }
3825 :
3826 0 : if((py_blist = PyList_New(0)) == NULL) {
3827 0 : PyErr_NoMemory();
3828 0 : talloc_free(frame);
3829 0 : return NULL;
3830 : }
3831 :
3832 0 : while(entry) {
3833 0 : int res = 0;
3834 0 : PyObject *entry_name = PyUnicode_FromString(entry->name);
3835 0 : if (entry_name) {
3836 0 : res = PyList_Append(py_blist, entry_name);
3837 : } else {
3838 0 : Py_CLEAR(entry_name);
3839 0 : Py_CLEAR(py_blist);
3840 0 : break;
3841 : }
3842 0 : Py_CLEAR(entry_name);
3843 0 : if (res == -1) {
3844 0 : Py_CLEAR(py_blist);
3845 0 : break;
3846 : }
3847 0 : entry = entry->next;
3848 : }
3849 :
3850 0 : talloc_free(frame);
3851 0 : return py_blist;
3852 : }
3853 :
3854 :
3855 0 : static PyObject *py_set_smb_config(PyObject *self, PyObject *args)
3856 : {
3857 0 : TALLOC_CTX *frame = talloc_stackframe();
3858 0 : const char *smb_config;
3859 :
3860 0 : if (!PyArg_ParseTuple(args, "s", &smb_config)) {
3861 0 : talloc_free(frame);
3862 0 : return NULL;
3863 : }
3864 :
3865 : /* Load smbconf parameters */
3866 0 : if (!lp_load_global(smb_config)) {
3867 0 : PyErr_Format(py_pdb_error, "Cannot open '%s'", smb_config);
3868 0 : talloc_free(frame);
3869 0 : return NULL;
3870 : }
3871 :
3872 0 : talloc_free(frame);
3873 0 : Py_RETURN_NONE;
3874 : }
3875 :
3876 :
3877 11 : static PyObject *py_set_secrets_dir(PyObject *self, PyObject *args)
3878 : {
3879 11 : TALLOC_CTX *frame = talloc_stackframe();
3880 11 : const char *private_dir;
3881 :
3882 11 : if (!PyArg_ParseTuple(args, "s", &private_dir)) {
3883 0 : talloc_free(frame);
3884 0 : return NULL;
3885 : }
3886 :
3887 : /* Initialize secrets database */
3888 11 : if (!secrets_init_path(private_dir)) {
3889 0 : PyErr_Format(py_pdb_error, "Cannot open secrets file database in '%s'",
3890 : private_dir);
3891 0 : talloc_free(frame);
3892 0 : return NULL;
3893 : }
3894 :
3895 11 : talloc_free(frame);
3896 11 : Py_RETURN_NONE;
3897 : }
3898 :
3899 66 : static PyObject *py_reload_static_pdb(PyObject *self, PyObject *args)
3900 : {
3901 66 : TALLOC_CTX *frame = talloc_stackframe();
3902 :
3903 : /* Initialize secrets database */
3904 66 : if (!initialize_password_db(true, NULL)) {
3905 0 : PyErr_Format(py_pdb_error, "Cannot re-open passdb backend %s", lp_passdb_backend());
3906 0 : talloc_free(frame);
3907 0 : return NULL;
3908 : }
3909 :
3910 66 : talloc_free(frame);
3911 66 : Py_RETURN_NONE;
3912 : }
3913 :
3914 66 : static PyObject *py_get_domain_sid(PyObject *self, PyObject *unused)
3915 : {
3916 66 : TALLOC_CTX *frame = talloc_stackframe();
3917 0 : struct dom_sid domain_sid, *domain_sid_copy;
3918 66 : PyObject *py_dom_sid = Py_None;
3919 66 : bool ret = false;
3920 :
3921 66 : ret = secrets_fetch_domain_sid(lp_workgroup(), &domain_sid);
3922 66 : if (!ret) {
3923 0 : talloc_free(frame);
3924 0 : return PyErr_NoMemory();
3925 : }
3926 :
3927 66 : domain_sid_copy = dom_sid_dup(frame, &domain_sid);
3928 66 : if (domain_sid_copy == NULL) {
3929 0 : talloc_free(frame);
3930 0 : return PyErr_NoMemory();
3931 : }
3932 :
3933 66 : py_dom_sid = pytalloc_steal(dom_sid_Type, domain_sid_copy);
3934 :
3935 66 : talloc_free(frame);
3936 66 : return py_dom_sid;
3937 : }
3938 :
3939 136 : static PyObject *py_get_global_sam_sid(PyObject *self, PyObject *unused)
3940 : {
3941 136 : TALLOC_CTX *frame = talloc_stackframe();
3942 9 : struct dom_sid *domain_sid, *domain_sid_copy;
3943 9 : PyObject *py_dom_sid;
3944 :
3945 136 : domain_sid = get_global_sam_sid();
3946 :
3947 136 : domain_sid_copy = dom_sid_dup(frame, domain_sid);
3948 136 : if (domain_sid_copy == NULL) {
3949 0 : PyErr_NoMemory();
3950 0 : talloc_free(frame);
3951 0 : return NULL;
3952 : }
3953 :
3954 136 : py_dom_sid = pytalloc_steal(dom_sid_Type, domain_sid_copy);
3955 :
3956 136 : talloc_free(frame);
3957 136 : return py_dom_sid;
3958 : }
3959 :
3960 :
3961 : static PyMethodDef py_passdb_methods[] = {
3962 : { "get_backends", py_passdb_backends, METH_NOARGS,
3963 : "get_backends() -> list\n\n \
3964 : Get a list of password database backends supported." },
3965 : { "set_smb_config", py_set_smb_config, METH_VARARGS,
3966 : "set_smb_config(path) -> None\n\n \
3967 : Set path to smb.conf file to load configuration parameters." },
3968 : { "set_secrets_dir", py_set_secrets_dir, METH_VARARGS,
3969 : "set_secrets_dir(private_dir) -> None\n\n \
3970 : Set path to private directory to load secrets database from non-default location." },
3971 : { "get_global_sam_sid", py_get_global_sam_sid, METH_NOARGS,
3972 : "get_global_sam_sid() -> dom_sid\n\n \
3973 : Return domain SID." },
3974 : { "get_domain_sid", py_get_domain_sid, METH_NOARGS,
3975 : "get_domain_sid() -> dom_sid\n\n \
3976 : Return domain SID from secrets database." },
3977 : { "reload_static_pdb", py_reload_static_pdb, METH_NOARGS,
3978 : "reload_static_pdb() -> None\n\n \
3979 : Re-initialise the static pdb used internally. Needed if 'passdb backend' is changed." },
3980 : {0},
3981 : };
3982 :
3983 : static struct PyModuleDef moduledef = {
3984 : PyModuleDef_HEAD_INIT,
3985 : .m_name = "passdb",
3986 : .m_doc = "SAMBA Password Database",
3987 : .m_size = -1,
3988 : .m_methods = py_passdb_methods,
3989 : };
3990 :
3991 1887 : MODULE_INIT_FUNC(passdb)
3992 : {
3993 1887 : TALLOC_CTX *frame = talloc_stackframe();
3994 1887 : PyObject *m = NULL, *mod = NULL;
3995 1887 : char exception_name[] = "passdb.error";
3996 :
3997 1887 : if (pytalloc_BaseObject_PyType_Ready(&PyPDB) < 0) {
3998 0 : talloc_free(frame);
3999 0 : return NULL;
4000 : }
4001 :
4002 1887 : if (pytalloc_BaseObject_PyType_Ready(&PySamu) < 0) {
4003 0 : talloc_free(frame);
4004 0 : return NULL;
4005 : }
4006 :
4007 1887 : if (pytalloc_BaseObject_PyType_Ready(&PyGroupmap) < 0) {
4008 0 : talloc_free(frame);
4009 0 : return NULL;
4010 : }
4011 :
4012 1887 : m = PyModule_Create(&moduledef);
4013 1887 : if (m == NULL) {
4014 0 : talloc_free(frame);
4015 0 : return NULL;
4016 : }
4017 :
4018 : /* Create new exception for passdb module */
4019 1887 : py_pdb_error = PyErr_NewException(exception_name, NULL, NULL);
4020 1887 : Py_INCREF(py_pdb_error);
4021 1887 : PyModule_AddObject(m, "error", py_pdb_error);
4022 :
4023 1549 : Py_INCREF(&PyPDB);
4024 1887 : PyModule_AddObject(m, "PDB", (PyObject *)&PyPDB);
4025 :
4026 1549 : Py_INCREF(&PySamu);
4027 1887 : PyModule_AddObject(m, "Samu", (PyObject *)&PySamu);
4028 :
4029 1549 : Py_INCREF(&PyGroupmap);
4030 1887 : PyModule_AddObject(m, "Groupmap", (PyObject *)&PyGroupmap);
4031 :
4032 : /* Import dom_sid type from dcerpc.security */
4033 1887 : mod = PyImport_ImportModule("samba.dcerpc.security");
4034 1887 : if (mod == NULL) {
4035 0 : talloc_free(frame);
4036 0 : return NULL;
4037 : }
4038 :
4039 1887 : dom_sid_Type = (PyTypeObject *)PyObject_GetAttrString(mod, "dom_sid");
4040 1887 : if (dom_sid_Type == NULL) {
4041 0 : Py_DECREF(mod);
4042 0 : talloc_free(frame);
4043 0 : return NULL;
4044 : }
4045 :
4046 : /* Import security_descriptor type from dcerpc.security */
4047 1887 : security_Type = (PyTypeObject *)PyObject_GetAttrString(mod, "descriptor");
4048 1549 : Py_DECREF(mod);
4049 1887 : if (security_Type == NULL) {
4050 0 : Py_DECREF(dom_sid_Type);
4051 0 : talloc_free(frame);
4052 0 : return NULL;
4053 : }
4054 :
4055 : /* Import GUID type from dcerpc.misc */
4056 1887 : mod = PyImport_ImportModule("samba.dcerpc.misc");
4057 1887 : if (mod == NULL) {
4058 0 : Py_DECREF(security_Type);
4059 0 : Py_DECREF(dom_sid_Type);
4060 0 : talloc_free(frame);
4061 0 : return NULL;
4062 : }
4063 :
4064 1887 : guid_Type = (PyTypeObject *)PyObject_GetAttrString(mod, "GUID");
4065 1549 : Py_DECREF(mod);
4066 1887 : if (guid_Type == NULL) {
4067 0 : Py_DECREF(security_Type);
4068 0 : Py_DECREF(dom_sid_Type);
4069 0 : talloc_free(frame);
4070 0 : return NULL;
4071 : }
4072 1887 : talloc_free(frame);
4073 1887 : return m;
4074 : }
|