2 Unix SMB/CIFS implementation.
3 Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #include "lib/replace/system/python.h"
20 #include "python/py3compat.h"
22 #include "python/modules.h"
23 #include "pycredentials.h"
24 #include "param/param.h"
25 #include "auth/credentials/credentials_internal.h"
26 #include "auth/credentials/credentials_krb5.h"
27 #include "librpc/gen_ndr/samr.h" /* for struct samr_Password */
28 #include "librpc/gen_ndr/netlogon.h"
29 #include "libcli/util/pyerrors.h"
30 #include "libcli/auth/libcli_auth.h"
31 #include "param/pyparam.h"
33 #include "libcli/auth/libcli_auth.h"
34 #include "system/kerberos.h"
35 #include "auth/kerberos/kerberos.h"
36 #include "libcli/smb/smb_constants.h"
38 static PyObject
*py_creds_new(PyTypeObject
*type
, PyObject
*args
, PyObject
*kwargs
)
40 return pytalloc_steal(type
, cli_credentials_init(NULL
));
43 static PyObject
*PyCredentials_from_cli_credentials(struct cli_credentials
*creds
)
45 return pytalloc_reference(&PyCredentials
, creds
);
48 static PyObject
*py_creds_get_username(PyObject
*self
, PyObject
*unused
)
50 struct cli_credentials
*creds
= PyCredentials_AsCliCredentials(self
);
52 PyErr_Format(PyExc_TypeError
, "Credentials expected");
55 return PyString_FromStringOrNULL(cli_credentials_get_username(creds
));
58 static PyObject
*py_creds_set_username(PyObject
*self
, PyObject
*args
)
61 enum credentials_obtained obt
= CRED_SPECIFIED
;
63 struct cli_credentials
*creds
= PyCredentials_AsCliCredentials(self
);
65 PyErr_Format(PyExc_TypeError
, "Credentials expected");
69 if (!PyArg_ParseTuple(args
, "s|i", &newval
, &_obt
)) {
74 return PyBool_FromLong(cli_credentials_set_username(creds
, newval
, obt
));
77 static PyObject
*py_creds_get_ntlm_username_domain(PyObject
*self
, PyObject
*unused
)
79 TALLOC_CTX
*frame
= talloc_stackframe();
80 const char *user
= NULL
;
81 const char *domain
= NULL
;
83 struct cli_credentials
*creds
= PyCredentials_AsCliCredentials(self
);
85 PyErr_Format(PyExc_TypeError
, "Credentials expected");
88 cli_credentials_get_ntlm_username_domain(creds
,
89 frame
, &user
, &domain
);
90 ret
= Py_BuildValue("(ss)",
98 static PyObject
*py_creds_get_ntlm_response(PyObject
*self
, PyObject
*args
, PyObject
*kwargs
)
100 TALLOC_CTX
*frame
= talloc_stackframe();
101 PyObject
*ret
= NULL
;
103 struct timeval tv_now
;
104 NTTIME server_timestamp
;
105 DATA_BLOB challenge
= data_blob_null
;
106 DATA_BLOB target_info
= data_blob_null
;
108 DATA_BLOB lm_response
= data_blob_null
;
109 DATA_BLOB nt_response
= data_blob_null
;
110 DATA_BLOB lm_session_key
= data_blob_null
;
111 DATA_BLOB nt_session_key
= data_blob_null
;
112 const char *kwnames
[] = { "flags", "challenge",
115 struct cli_credentials
*creds
= PyCredentials_AsCliCredentials(self
);
117 PyErr_Format(PyExc_TypeError
, "Credentials expected");
121 tv_now
= timeval_current();
122 server_timestamp
= timeval_to_nttime(&tv_now
);
124 if (!PyArg_ParseTupleAndKeywords(args
, kwargs
, "is#|s#",
125 discard_const_p(char *, kwnames
),
130 &target_info
.length
)) {
134 status
= cli_credentials_get_ntlm_response(creds
,
139 &lm_response
, &nt_response
,
140 &lm_session_key
, &nt_session_key
);
142 if (!NT_STATUS_IS_OK(status
)) {
143 PyErr_SetNTSTATUS(status
);
148 ret
= Py_BuildValue("{sis" PYARG_BYTES_LEN
"s" PYARG_BYTES_LEN
149 "s" PYARG_BYTES_LEN
"s" PYARG_BYTES_LEN
"}",
152 (const char *)lm_response
.data
, lm_response
.length
,
154 (const char *)nt_response
.data
, nt_response
.length
,
156 (const char *)lm_session_key
.data
, lm_session_key
.length
,
158 (const char *)nt_session_key
.data
, nt_session_key
.length
);
163 static PyObject
*py_creds_get_principal(PyObject
*self
, PyObject
*unused
)
165 TALLOC_CTX
*frame
= talloc_stackframe();
166 PyObject
*ret
= NULL
;
167 struct cli_credentials
*creds
= PyCredentials_AsCliCredentials(self
);
169 PyErr_Format(PyExc_TypeError
, "Credentials expected");
172 ret
= PyString_FromStringOrNULL(cli_credentials_get_principal(creds
, frame
));
177 static PyObject
*py_creds_set_principal(PyObject
*self
, PyObject
*args
)
180 enum credentials_obtained obt
= CRED_SPECIFIED
;
182 struct cli_credentials
*creds
= PyCredentials_AsCliCredentials(self
);
184 PyErr_Format(PyExc_TypeError
, "Credentials expected");
188 if (!PyArg_ParseTuple(args
, "s|i", &newval
, &_obt
)) {
193 return PyBool_FromLong(cli_credentials_set_principal(creds
, newval
, obt
));
196 static PyObject
*py_creds_get_password(PyObject
*self
, PyObject
*unused
)
198 struct cli_credentials
*creds
= PyCredentials_AsCliCredentials(self
);
200 PyErr_Format(PyExc_TypeError
, "Credentials expected");
203 return PyString_FromStringOrNULL(cli_credentials_get_password(creds
));
206 static PyObject
*py_creds_set_password(PyObject
*self
, PyObject
*args
)
208 const char *newval
= NULL
;
209 enum credentials_obtained obt
= CRED_SPECIFIED
;
211 PyObject
*result
= NULL
;
212 struct cli_credentials
*creds
= PyCredentials_AsCliCredentials(self
);
214 PyErr_Format(PyExc_TypeError
, "Credentials expected");
218 if (!PyArg_ParseTuple(args
, PYARG_STR_UNI
"|i", "utf8", &newval
, &_obt
)) {
223 result
= PyBool_FromLong(cli_credentials_set_password(creds
, newval
, obt
));
224 PyMem_Free(discard_const_p(void*, newval
));
228 static PyObject
*py_creds_set_utf16_password(PyObject
*self
, PyObject
*args
)
230 enum credentials_obtained obt
= CRED_SPECIFIED
;
232 PyObject
*newval
= NULL
;
233 DATA_BLOB blob
= data_blob_null
;
237 struct cli_credentials
*creds
= PyCredentials_AsCliCredentials(self
);
239 PyErr_Format(PyExc_TypeError
, "Credentials expected");
243 if (!PyArg_ParseTuple(args
, "O|i", &newval
, &_obt
)) {
248 result
= PyBytes_AsStringAndSize(newval
, (char **)&blob
.data
, &size
);
250 PyErr_SetString(PyExc_RuntimeError
, "Failed to convert passed value to Bytes");
255 ok
= cli_credentials_set_utf16_password(creds
,
258 return PyBool_FromLong(ok
);
261 static PyObject
*py_creds_get_old_password(PyObject
*self
, PyObject
*unused
)
263 struct cli_credentials
*creds
= PyCredentials_AsCliCredentials(self
);
265 PyErr_Format(PyExc_TypeError
, "Credentials expected");
268 return PyString_FromStringOrNULL(cli_credentials_get_old_password(creds
));
271 static PyObject
*py_creds_set_old_password(PyObject
*self
, PyObject
*args
)
274 enum credentials_obtained obt
= CRED_SPECIFIED
;
276 struct cli_credentials
*creds
= PyCredentials_AsCliCredentials(self
);
278 PyErr_Format(PyExc_TypeError
, "Credentials expected");
282 if (!PyArg_ParseTuple(args
, "s|i", &oldval
, &_obt
)) {
287 return PyBool_FromLong(cli_credentials_set_old_password(creds
, oldval
, obt
));
290 static PyObject
*py_creds_set_old_utf16_password(PyObject
*self
, PyObject
*args
)
292 PyObject
*oldval
= NULL
;
293 DATA_BLOB blob
= data_blob_null
;
297 struct cli_credentials
*creds
= PyCredentials_AsCliCredentials(self
);
299 PyErr_Format(PyExc_TypeError
, "Credentials expected");
303 if (!PyArg_ParseTuple(args
, "O", &oldval
)) {
307 result
= PyBytes_AsStringAndSize(oldval
, (char **)&blob
.data
, &size
);
309 PyErr_SetString(PyExc_RuntimeError
, "Failed to convert passed value to Bytes");
314 ok
= cli_credentials_set_old_utf16_password(creds
,
317 return PyBool_FromLong(ok
);
320 static PyObject
*py_creds_get_domain(PyObject
*self
, PyObject
*unused
)
322 struct cli_credentials
*creds
= PyCredentials_AsCliCredentials(self
);
324 PyErr_Format(PyExc_TypeError
, "Credentials expected");
327 return PyString_FromStringOrNULL(cli_credentials_get_domain(creds
));
330 static PyObject
*py_creds_set_domain(PyObject
*self
, PyObject
*args
)
333 enum credentials_obtained obt
= CRED_SPECIFIED
;
335 struct cli_credentials
*creds
= PyCredentials_AsCliCredentials(self
);
337 PyErr_Format(PyExc_TypeError
, "Credentials expected");
341 if (!PyArg_ParseTuple(args
, "s|i", &newval
, &_obt
)) {
346 return PyBool_FromLong(cli_credentials_set_domain(creds
, newval
, obt
));
349 static PyObject
*py_creds_get_realm(PyObject
*self
, PyObject
*unused
)
351 struct cli_credentials
*creds
= PyCredentials_AsCliCredentials(self
);
353 PyErr_Format(PyExc_TypeError
, "Credentials expected");
356 return PyString_FromStringOrNULL(cli_credentials_get_realm(creds
));
359 static PyObject
*py_creds_set_realm(PyObject
*self
, PyObject
*args
)
362 enum credentials_obtained obt
= CRED_SPECIFIED
;
364 struct cli_credentials
*creds
= PyCredentials_AsCliCredentials(self
);
366 PyErr_Format(PyExc_TypeError
, "Credentials expected");
370 if (!PyArg_ParseTuple(args
, "s|i", &newval
, &_obt
)) {
375 return PyBool_FromLong(cli_credentials_set_realm(creds
, newval
, obt
));
378 static PyObject
*py_creds_get_bind_dn(PyObject
*self
, PyObject
*unused
)
380 struct cli_credentials
*creds
= PyCredentials_AsCliCredentials(self
);
382 PyErr_Format(PyExc_TypeError
, "Credentials expected");
385 return PyString_FromStringOrNULL(cli_credentials_get_bind_dn(creds
));
388 static PyObject
*py_creds_set_bind_dn(PyObject
*self
, PyObject
*args
)
391 struct cli_credentials
*creds
= PyCredentials_AsCliCredentials(self
);
393 PyErr_Format(PyExc_TypeError
, "Credentials expected");
396 if (!PyArg_ParseTuple(args
, "z", &newval
))
399 return PyBool_FromLong(cli_credentials_set_bind_dn(creds
, newval
));
402 static PyObject
*py_creds_get_workstation(PyObject
*self
, PyObject
*unused
)
404 struct cli_credentials
*creds
= PyCredentials_AsCliCredentials(self
);
406 PyErr_Format(PyExc_TypeError
, "Credentials expected");
409 return PyString_FromStringOrNULL(cli_credentials_get_workstation(creds
));
412 static PyObject
*py_creds_set_workstation(PyObject
*self
, PyObject
*args
)
415 enum credentials_obtained obt
= CRED_SPECIFIED
;
417 struct cli_credentials
*creds
= PyCredentials_AsCliCredentials(self
);
419 PyErr_Format(PyExc_TypeError
, "Credentials expected");
423 if (!PyArg_ParseTuple(args
, "s|i", &newval
, &_obt
)) {
428 return PyBool_FromLong(cli_credentials_set_workstation(creds
, newval
, obt
));
431 static PyObject
*py_creds_is_anonymous(PyObject
*self
, PyObject
*unused
)
433 struct cli_credentials
*creds
= PyCredentials_AsCliCredentials(self
);
435 PyErr_Format(PyExc_TypeError
, "Credentials expected");
438 return PyBool_FromLong(cli_credentials_is_anonymous(creds
));
441 static PyObject
*py_creds_set_anonymous(PyObject
*self
, PyObject
*unused
)
443 struct cli_credentials
*creds
= PyCredentials_AsCliCredentials(self
);
445 PyErr_Format(PyExc_TypeError
, "Credentials expected");
448 cli_credentials_set_anonymous(creds
);
452 static PyObject
*py_creds_authentication_requested(PyObject
*self
, PyObject
*unused
)
454 struct cli_credentials
*creds
= PyCredentials_AsCliCredentials(self
);
456 PyErr_Format(PyExc_TypeError
, "Credentials expected");
459 return PyBool_FromLong(cli_credentials_authentication_requested(creds
));
462 static PyObject
*py_creds_wrong_password(PyObject
*self
, PyObject
*unused
)
464 struct cli_credentials
*creds
= PyCredentials_AsCliCredentials(self
);
466 PyErr_Format(PyExc_TypeError
, "Credentials expected");
469 return PyBool_FromLong(cli_credentials_wrong_password(creds
));
472 static PyObject
*py_creds_set_cmdline_callbacks(PyObject
*self
, PyObject
*unused
)
474 struct cli_credentials
*creds
= PyCredentials_AsCliCredentials(self
);
476 PyErr_Format(PyExc_TypeError
, "Credentials expected");
479 return PyBool_FromLong(cli_credentials_set_cmdline_callbacks(creds
));
482 static PyObject
*py_creds_parse_string(PyObject
*self
, PyObject
*args
)
485 enum credentials_obtained obt
= CRED_SPECIFIED
;
487 struct cli_credentials
*creds
= PyCredentials_AsCliCredentials(self
);
489 PyErr_Format(PyExc_TypeError
, "Credentials expected");
493 if (!PyArg_ParseTuple(args
, "s|i", &newval
, &_obt
)) {
498 cli_credentials_parse_string(creds
, newval
, obt
);
502 static PyObject
*py_creds_parse_file(PyObject
*self
, PyObject
*args
)
505 enum credentials_obtained obt
= CRED_SPECIFIED
;
507 struct cli_credentials
*creds
= PyCredentials_AsCliCredentials(self
);
509 PyErr_Format(PyExc_TypeError
, "Credentials expected");
513 if (!PyArg_ParseTuple(args
, "s|i", &newval
, &_obt
)) {
518 cli_credentials_parse_file(creds
, newval
, obt
);
522 static PyObject
*py_cli_credentials_set_password_will_be_nt_hash(PyObject
*self
, PyObject
*args
)
524 struct cli_credentials
*creds
= PyCredentials_AsCliCredentials(self
);
525 PyObject
*py_val
= NULL
;
528 if (!PyArg_ParseTuple(args
, "O!", &PyBool_Type
, &py_val
)) {
531 val
= PyObject_IsTrue(py_val
);
533 cli_credentials_set_password_will_be_nt_hash(creds
, val
);
537 static PyObject
*py_creds_get_nt_hash(PyObject
*self
, PyObject
*unused
)
540 struct samr_Password
*ntpw
= NULL
;
541 struct cli_credentials
*creds
= PyCredentials_AsCliCredentials(self
);
543 PyErr_Format(PyExc_TypeError
, "Credentials expected");
546 ntpw
= cli_credentials_get_nt_hash(creds
, creds
);
551 ret
= PyBytes_FromStringAndSize(discard_const_p(char, ntpw
->hash
), 16);
556 static PyObject
*py_creds_set_nt_hash(PyObject
*self
, PyObject
*args
)
558 PyObject
*py_cp
= Py_None
;
559 const struct samr_Password
*pwd
= NULL
;
560 enum credentials_obtained obt
= CRED_SPECIFIED
;
562 struct cli_credentials
*creds
= PyCredentials_AsCliCredentials(self
);
564 PyErr_Format(PyExc_TypeError
, "Credentials expected");
568 if (!PyArg_ParseTuple(args
, "O|i", &py_cp
, &_obt
)) {
573 if (!py_check_dcerpc_type(py_cp
, "samba.dcerpc.samr", "Password")) {
574 /* py_check_dcerpc_type sets TypeError */
578 pwd
= pytalloc_get_ptr(py_cp
);
580 return PyBool_FromLong(cli_credentials_set_nt_hash(creds
, pwd
, obt
));
583 static PyObject
*py_creds_get_kerberos_state(PyObject
*self
, PyObject
*unused
)
586 struct cli_credentials
*creds
= PyCredentials_AsCliCredentials(self
);
588 PyErr_Format(PyExc_TypeError
, "Credentials expected");
591 state
= cli_credentials_get_kerberos_state(creds
);
592 return PyLong_FromLong(state
);
595 static PyObject
*py_creds_set_kerberos_state(PyObject
*self
, PyObject
*args
)
598 struct cli_credentials
*creds
= PyCredentials_AsCliCredentials(self
);
600 PyErr_Format(PyExc_TypeError
, "Credentials expected");
603 if (!PyArg_ParseTuple(args
, "i", &state
))
606 cli_credentials_set_kerberos_state(creds
, state
, CRED_SPECIFIED
);
610 static PyObject
*py_creds_set_krb_forwardable(PyObject
*self
, PyObject
*args
)
613 struct cli_credentials
*creds
= PyCredentials_AsCliCredentials(self
);
615 PyErr_Format(PyExc_TypeError
, "Credentials expected");
618 if (!PyArg_ParseTuple(args
, "i", &state
))
621 cli_credentials_set_krb_forwardable(creds
, state
);
626 static PyObject
*py_creds_get_forced_sasl_mech(PyObject
*self
, PyObject
*unused
)
628 struct cli_credentials
*creds
= PyCredentials_AsCliCredentials(self
);
630 PyErr_Format(PyExc_TypeError
, "Credentials expected");
633 return PyString_FromStringOrNULL(cli_credentials_get_forced_sasl_mech(creds
));
636 static PyObject
*py_creds_set_forced_sasl_mech(PyObject
*self
, PyObject
*args
)
639 struct cli_credentials
*creds
= PyCredentials_AsCliCredentials(self
);
641 PyErr_Format(PyExc_TypeError
, "Credentials expected");
645 if (!PyArg_ParseTuple(args
, "s", &newval
)) {
649 cli_credentials_set_forced_sasl_mech(creds
, newval
);
653 static PyObject
*py_creds_set_conf(PyObject
*self
, PyObject
*args
)
655 PyObject
*py_lp_ctx
= Py_None
;
656 struct loadparm_context
*lp_ctx
;
658 struct cli_credentials
*creds
;
661 creds
= PyCredentials_AsCliCredentials(self
);
663 PyErr_Format(PyExc_TypeError
, "Credentials expected");
667 if (!PyArg_ParseTuple(args
, "|O", &py_lp_ctx
)) {
671 mem_ctx
= talloc_new(NULL
);
672 if (mem_ctx
== NULL
) {
677 lp_ctx
= lpcfg_from_py_object(mem_ctx
, py_lp_ctx
);
678 if (lp_ctx
== NULL
) {
679 talloc_free(mem_ctx
);
683 ok
= cli_credentials_set_conf(creds
, lp_ctx
);
684 talloc_free(mem_ctx
);
692 static PyObject
*py_creds_guess(PyObject
*self
, PyObject
*args
)
694 PyObject
*py_lp_ctx
= Py_None
;
695 struct loadparm_context
*lp_ctx
;
697 struct cli_credentials
*creds
;
700 creds
= PyCredentials_AsCliCredentials(self
);
702 PyErr_Format(PyExc_TypeError
, "Credentials expected");
706 if (!PyArg_ParseTuple(args
, "|O", &py_lp_ctx
))
709 mem_ctx
= talloc_new(NULL
);
710 if (mem_ctx
== NULL
) {
715 lp_ctx
= lpcfg_from_py_object(mem_ctx
, py_lp_ctx
);
716 if (lp_ctx
== NULL
) {
717 talloc_free(mem_ctx
);
721 ok
= cli_credentials_guess(creds
, lp_ctx
);
722 talloc_free(mem_ctx
);
730 static PyObject
*py_creds_set_machine_account(PyObject
*self
, PyObject
*args
)
732 PyObject
*py_lp_ctx
= Py_None
;
733 struct loadparm_context
*lp_ctx
;
735 struct cli_credentials
*creds
;
738 creds
= PyCredentials_AsCliCredentials(self
);
740 PyErr_Format(PyExc_TypeError
, "Credentials expected");
744 if (!PyArg_ParseTuple(args
, "|O", &py_lp_ctx
))
747 mem_ctx
= talloc_new(NULL
);
748 if (mem_ctx
== NULL
) {
753 lp_ctx
= lpcfg_from_py_object(mem_ctx
, py_lp_ctx
);
754 if (lp_ctx
== NULL
) {
755 talloc_free(mem_ctx
);
759 status
= cli_credentials_set_machine_account(creds
, lp_ctx
);
760 talloc_free(mem_ctx
);
762 PyErr_NTSTATUS_IS_ERR_RAISE(status
);
767 static PyObject
*PyCredentialCacheContainer_from_ccache_container(struct ccache_container
*ccc
)
769 return pytalloc_reference(&PyCredentialCacheContainer
, ccc
);
773 static PyObject
*py_creds_get_named_ccache(PyObject
*self
, PyObject
*args
)
775 PyObject
*py_lp_ctx
= Py_None
;
776 char *ccache_name
= NULL
;
777 struct loadparm_context
*lp_ctx
;
778 struct ccache_container
*ccc
;
779 struct tevent_context
*event_ctx
;
781 const char *error_string
;
782 struct cli_credentials
*creds
;
785 creds
= PyCredentials_AsCliCredentials(self
);
787 PyErr_Format(PyExc_TypeError
, "Credentials expected");
791 if (!PyArg_ParseTuple(args
, "|Os", &py_lp_ctx
, &ccache_name
))
794 mem_ctx
= talloc_new(NULL
);
795 if (mem_ctx
== NULL
) {
800 lp_ctx
= lpcfg_from_py_object(mem_ctx
, py_lp_ctx
);
801 if (lp_ctx
== NULL
) {
802 talloc_free(mem_ctx
);
806 event_ctx
= samba_tevent_context_init(mem_ctx
);
808 ret
= cli_credentials_get_named_ccache(creds
, event_ctx
, lp_ctx
,
809 ccache_name
, &ccc
, &error_string
);
810 talloc_unlink(mem_ctx
, lp_ctx
);
812 talloc_steal(ccc
, event_ctx
);
813 talloc_free(mem_ctx
);
814 return PyCredentialCacheContainer_from_ccache_container(ccc
);
817 PyErr_SetString(PyExc_RuntimeError
, error_string
?error_string
:"NULL");
819 talloc_free(mem_ctx
);
823 static PyObject
*py_creds_set_named_ccache(PyObject
*self
, PyObject
*args
)
825 struct loadparm_context
*lp_ctx
= NULL
;
826 enum credentials_obtained obt
= CRED_SPECIFIED
;
827 const char *error_string
= NULL
;
828 TALLOC_CTX
*mem_ctx
= NULL
;
830 PyObject
*py_lp_ctx
= Py_None
;
833 struct cli_credentials
*creds
= PyCredentials_AsCliCredentials(self
);
835 PyErr_Format(PyExc_TypeError
, "Credentials expected");
839 if (!PyArg_ParseTuple(args
, "s|iO", &newval
, &_obt
, &py_lp_ctx
))
843 mem_ctx
= talloc_new(NULL
);
844 if (mem_ctx
== NULL
) {
849 lp_ctx
= lpcfg_from_py_object(mem_ctx
, py_lp_ctx
);
850 if (lp_ctx
== NULL
) {
851 talloc_free(mem_ctx
);
855 ret
= cli_credentials_set_ccache(creds
,
861 PyErr_SetString(PyExc_RuntimeError
,
862 error_string
!= NULL
? error_string
: "NULL");
863 talloc_free(mem_ctx
);
867 talloc_free(mem_ctx
);
871 static PyObject
*py_creds_set_gensec_features(PyObject
*self
, PyObject
*args
)
873 unsigned int gensec_features
;
874 struct cli_credentials
*creds
= PyCredentials_AsCliCredentials(self
);
876 PyErr_Format(PyExc_TypeError
, "Credentials expected");
880 if (!PyArg_ParseTuple(args
, "I", &gensec_features
))
883 cli_credentials_set_gensec_features(creds
,
890 static PyObject
*py_creds_get_gensec_features(PyObject
*self
, PyObject
*args
)
892 unsigned int gensec_features
;
893 struct cli_credentials
*creds
= PyCredentials_AsCliCredentials(self
);
895 PyErr_Format(PyExc_TypeError
, "Credentials expected");
899 gensec_features
= cli_credentials_get_gensec_features(creds
);
900 return PyLong_FromLong(gensec_features
);
903 static PyObject
*py_creds_new_client_authenticator(PyObject
*self
,
906 struct netr_Authenticator auth
;
907 struct cli_credentials
*creds
= NULL
;
908 struct netlogon_creds_CredentialState
*nc
= NULL
;
909 PyObject
*ret
= NULL
;
912 creds
= PyCredentials_AsCliCredentials(self
);
914 PyErr_SetString(PyExc_RuntimeError
,
915 "Failed to get credentials from python");
919 nc
= creds
->netlogon_creds
;
921 PyErr_SetString(PyExc_ValueError
,
922 "No netlogon credentials cannot make "
923 "client authenticator");
927 status
= netlogon_creds_client_authenticator(nc
, &auth
);
928 if (!NT_STATUS_IS_OK(status
)) {
929 PyErr_SetString(PyExc_ValueError
,
930 "Failed to create client authenticator");
934 ret
= Py_BuildValue("{s"PYARG_BYTES_LEN
"si}",
936 (const char *) &auth
.cred
, sizeof(auth
.cred
),
937 "timestamp", auth
.timestamp
);
941 static PyObject
*py_creds_set_secure_channel_type(PyObject
*self
, PyObject
*args
)
943 unsigned int channel_type
;
944 struct cli_credentials
*creds
= PyCredentials_AsCliCredentials(self
);
946 PyErr_Format(PyExc_TypeError
, "Credentials expected");
950 if (!PyArg_ParseTuple(args
, "I", &channel_type
))
953 cli_credentials_set_secure_channel_type(
960 static PyObject
*py_creds_get_secure_channel_type(PyObject
*self
, PyObject
*args
)
962 enum netr_SchannelType channel_type
= SEC_CHAN_NULL
;
963 struct cli_credentials
*creds
= PyCredentials_AsCliCredentials(self
);
965 PyErr_Format(PyExc_TypeError
, "Credentials expected");
969 channel_type
= cli_credentials_get_secure_channel_type(creds
);
971 return PyLong_FromLong(channel_type
);
974 static PyObject
*py_creds_set_kerberos_salt_principal(PyObject
*self
, PyObject
*args
)
976 char *salt_principal
= NULL
;
977 struct cli_credentials
*creds
= PyCredentials_AsCliCredentials(self
);
979 PyErr_Format(PyExc_TypeError
, "Credentials expected");
983 if (!PyArg_ParseTuple(args
, "s", &salt_principal
))
986 cli_credentials_set_salt_principal(
993 static PyObject
*py_creds_get_kerberos_salt_principal(PyObject
*self
, PyObject
*unused
)
996 PyObject
*ret
= NULL
;
997 struct cli_credentials
*creds
= PyCredentials_AsCliCredentials(self
);
999 PyErr_Format(PyExc_TypeError
, "Credentials expected");
1002 mem_ctx
= talloc_new(NULL
);
1003 if (mem_ctx
== NULL
) {
1008 ret
= PyString_FromStringOrNULL(cli_credentials_get_salt_principal(creds
, mem_ctx
));
1010 TALLOC_FREE(mem_ctx
);
1015 static PyObject
*py_creds_get_kerberos_key_current_or_old(PyObject
*self
, PyObject
*args
, bool old
)
1017 struct loadparm_context
*lp_ctx
= NULL
;
1018 TALLOC_CTX
*mem_ctx
= NULL
;
1019 PyObject
*py_lp_ctx
= Py_None
;
1023 PyObject
*ret
= NULL
;
1024 struct cli_credentials
*creds
= PyCredentials_AsCliCredentials(self
);
1025 if (creds
== NULL
) {
1026 PyErr_Format(PyExc_TypeError
, "Credentials expected");
1030 if (!PyArg_ParseTuple(args
, "i|O", &enctype
, &py_lp_ctx
))
1033 mem_ctx
= talloc_new(NULL
);
1034 if (mem_ctx
== NULL
) {
1039 lp_ctx
= lpcfg_from_py_object(mem_ctx
, py_lp_ctx
);
1040 if (lp_ctx
== NULL
) {
1041 talloc_free(mem_ctx
);
1045 code
= cli_credentials_get_kerberos_key(creds
,
1052 PyErr_SetString(PyExc_RuntimeError
,
1053 "Failed to generate Kerberos key");
1054 talloc_free(mem_ctx
);
1058 ret
= PyBytes_FromStringAndSize((const char *)key
.data
,
1060 talloc_free(mem_ctx
);
1064 static PyObject
*py_creds_get_kerberos_key(PyObject
*self
, PyObject
*args
)
1066 return py_creds_get_kerberos_key_current_or_old(self
, args
, false);
1069 static PyObject
*py_creds_get_old_kerberos_key(PyObject
*self
, PyObject
*args
)
1071 return py_creds_get_kerberos_key_current_or_old(self
, args
, true);
1074 static PyObject
*py_creds_encrypt_netr_crypt_password(PyObject
*self
,
1077 DATA_BLOB data
= data_blob_null
;
1078 struct cli_credentials
*creds
= NULL
;
1079 struct netr_CryptPassword
*pwd
= NULL
;
1081 PyObject
*py_cp
= Py_None
;
1083 creds
= PyCredentials_AsCliCredentials(self
);
1084 if (creds
== NULL
) {
1085 PyErr_Format(PyExc_TypeError
, "Credentials expected");
1089 if (!PyArg_ParseTuple(args
, "O", &py_cp
)) {
1093 if (!py_check_dcerpc_type(py_cp
, "samba.dcerpc.netlogon", "netr_CryptPassword")) {
1094 /* py_check_dcerpc_type sets TypeError */
1098 pwd
= pytalloc_get_ptr(py_cp
);
1100 /* pytalloc_get_type sets TypeError */
1103 data
.length
= sizeof(struct netr_CryptPassword
);
1104 data
.data
= (uint8_t *)pwd
;
1105 status
= netlogon_creds_session_encrypt(creds
->netlogon_creds
, data
);
1107 PyErr_NTSTATUS_IS_ERR_RAISE(status
);
1112 static PyObject
*py_creds_encrypt_samr_password(PyObject
*self
,
1115 DATA_BLOB data
= data_blob_null
;
1116 struct cli_credentials
*creds
= NULL
;
1117 struct samr_Password
*pwd
= NULL
;
1119 PyObject
*py_cp
= Py_None
;
1121 creds
= PyCredentials_AsCliCredentials(self
);
1122 if (creds
== NULL
) {
1123 PyErr_Format(PyExc_TypeError
, "Credentials expected");
1127 if (creds
->netlogon_creds
== NULL
) {
1128 PyErr_Format(PyExc_ValueError
, "NetLogon credentials not set");
1132 if (!PyArg_ParseTuple(args
, "O", &py_cp
)) {
1136 if (!py_check_dcerpc_type(py_cp
, "samba.dcerpc.samr", "Password")) {
1137 /* py_check_dcerpc_type sets TypeError */
1141 pwd
= pytalloc_get_type(py_cp
, struct samr_Password
);
1143 /* pytalloc_get_type sets TypeError */
1146 data
= data_blob_const(pwd
->hash
, sizeof(pwd
->hash
));
1147 status
= netlogon_creds_session_encrypt(creds
->netlogon_creds
, data
);
1149 PyErr_NTSTATUS_IS_ERR_RAISE(status
);
1154 static PyObject
*py_creds_get_smb_signing(PyObject
*self
, PyObject
*unused
)
1156 enum smb_signing_setting signing_state
;
1157 struct cli_credentials
*creds
= NULL
;
1159 creds
= PyCredentials_AsCliCredentials(self
);
1160 if (creds
== NULL
) {
1161 PyErr_Format(PyExc_TypeError
, "Credentials expected");
1165 signing_state
= cli_credentials_get_smb_signing(creds
);
1166 return PyLong_FromLong(signing_state
);
1169 static PyObject
*py_creds_set_smb_signing(PyObject
*self
, PyObject
*args
)
1171 enum smb_signing_setting signing_state
;
1172 struct cli_credentials
*creds
= NULL
;
1173 enum credentials_obtained obt
= CRED_SPECIFIED
;
1175 creds
= PyCredentials_AsCliCredentials(self
);
1176 if (creds
== NULL
) {
1177 PyErr_Format(PyExc_TypeError
, "Credentials expected");
1180 if (!PyArg_ParseTuple(args
, "i|i", &signing_state
, &obt
)) {
1184 switch (signing_state
) {
1185 case SMB_SIGNING_DEFAULT
:
1186 case SMB_SIGNING_OFF
:
1187 case SMB_SIGNING_IF_REQUIRED
:
1188 case SMB_SIGNING_DESIRED
:
1189 case SMB_SIGNING_REQUIRED
:
1192 PyErr_Format(PyExc_TypeError
, "Invalid signing state value");
1196 cli_credentials_set_smb_signing(creds
, signing_state
, obt
);
1200 static PyObject
*py_creds_get_smb_ipc_signing(PyObject
*self
, PyObject
*unused
)
1202 enum smb_signing_setting signing_state
;
1203 struct cli_credentials
*creds
= NULL
;
1205 creds
= PyCredentials_AsCliCredentials(self
);
1206 if (creds
== NULL
) {
1207 PyErr_Format(PyExc_TypeError
, "Credentials expected");
1211 signing_state
= cli_credentials_get_smb_ipc_signing(creds
);
1212 return PyLong_FromLong(signing_state
);
1215 static PyObject
*py_creds_set_smb_ipc_signing(PyObject
*self
, PyObject
*args
)
1217 enum smb_signing_setting signing_state
;
1218 struct cli_credentials
*creds
= NULL
;
1219 enum credentials_obtained obt
= CRED_SPECIFIED
;
1221 creds
= PyCredentials_AsCliCredentials(self
);
1222 if (creds
== NULL
) {
1223 PyErr_Format(PyExc_TypeError
, "Credentials expected");
1226 if (!PyArg_ParseTuple(args
, "i|i", &signing_state
, &obt
)) {
1230 switch (signing_state
) {
1231 case SMB_SIGNING_DEFAULT
:
1232 case SMB_SIGNING_OFF
:
1233 case SMB_SIGNING_IF_REQUIRED
:
1234 case SMB_SIGNING_DESIRED
:
1235 case SMB_SIGNING_REQUIRED
:
1238 PyErr_Format(PyExc_TypeError
, "Invalid signing state value");
1242 cli_credentials_set_smb_ipc_signing(creds
, signing_state
, obt
);
1246 static PyObject
*py_creds_get_smb_encryption(PyObject
*self
, PyObject
*unused
)
1248 enum smb_encryption_setting encryption_state
;
1249 struct cli_credentials
*creds
= NULL
;
1251 creds
= PyCredentials_AsCliCredentials(self
);
1252 if (creds
== NULL
) {
1253 PyErr_Format(PyExc_TypeError
, "Credentials expected");
1257 encryption_state
= cli_credentials_get_smb_encryption(creds
);
1258 return PyLong_FromLong(encryption_state
);
1261 static PyObject
*py_creds_set_smb_encryption(PyObject
*self
, PyObject
*args
)
1263 enum smb_encryption_setting encryption_state
;
1264 struct cli_credentials
*creds
= NULL
;
1265 enum credentials_obtained obt
= CRED_SPECIFIED
;
1267 creds
= PyCredentials_AsCliCredentials(self
);
1268 if (creds
== NULL
) {
1269 PyErr_Format(PyExc_TypeError
, "Credentials expected");
1272 if (!PyArg_ParseTuple(args
, "i|i", &encryption_state
, &obt
)) {
1276 switch (encryption_state
) {
1277 case SMB_ENCRYPTION_DEFAULT
:
1278 case SMB_ENCRYPTION_OFF
:
1279 case SMB_ENCRYPTION_IF_REQUIRED
:
1280 case SMB_ENCRYPTION_DESIRED
:
1281 case SMB_ENCRYPTION_REQUIRED
:
1284 PyErr_Format(PyExc_TypeError
, "Invalid encryption state value");
1288 (void)cli_credentials_set_smb_encryption(creds
, encryption_state
, obt
);
1292 static PyObject
*py_creds_get_krb5_fast_armor_credentials(PyObject
*self
, PyObject
*unused
)
1294 struct cli_credentials
*creds
= NULL
;
1295 struct cli_credentials
*fast_creds
= NULL
;
1297 creds
= PyCredentials_AsCliCredentials(self
);
1298 if (creds
== NULL
) {
1299 PyErr_Format(PyExc_TypeError
, "Credentials expected");
1303 fast_creds
= cli_credentials_get_krb5_fast_armor_credentials(creds
);
1304 if (fast_creds
== NULL
) {
1308 return PyCredentials_from_cli_credentials(fast_creds
);
1311 static PyObject
*py_creds_set_krb5_fast_armor_credentials(PyObject
*self
, PyObject
*args
)
1313 struct cli_credentials
*creds
= NULL
;
1314 PyObject
*pyfast_creds
;
1315 struct cli_credentials
*fast_creds
= NULL
;
1316 int fast_armor_required
= 0;
1319 creds
= PyCredentials_AsCliCredentials(self
);
1320 if (creds
== NULL
) {
1321 PyErr_Format(PyExc_TypeError
, "Credentials expected");
1324 if (!PyArg_ParseTuple(args
, "Op", &pyfast_creds
, &fast_armor_required
)) {
1327 if (pyfast_creds
== Py_None
) {
1330 fast_creds
= PyCredentials_AsCliCredentials(pyfast_creds
);
1331 if (fast_creds
== NULL
) {
1332 PyErr_Format(PyExc_TypeError
, "Credentials expected");
1337 status
= cli_credentials_set_krb5_fast_armor_credentials(creds
,
1339 fast_armor_required
);
1341 PyErr_NTSTATUS_IS_ERR_RAISE(status
);
1345 static PyObject
*py_creds_get_krb5_require_fast_armor(PyObject
*self
, PyObject
*unused
)
1347 bool krb5_fast_armor_required
;
1348 struct cli_credentials
*creds
= NULL
;
1350 creds
= PyCredentials_AsCliCredentials(self
);
1351 if (creds
== NULL
) {
1352 PyErr_Format(PyExc_TypeError
, "Credentials expected");
1356 krb5_fast_armor_required
= cli_credentials_get_krb5_require_fast_armor(creds
);
1357 return PyBool_FromLong(krb5_fast_armor_required
);
1360 static PyMethodDef py_creds_methods
[] = {
1362 .ml_name
= "get_username",
1363 .ml_meth
= py_creds_get_username
,
1364 .ml_flags
= METH_NOARGS
,
1365 .ml_doc
= "S.get_username() -> username\nObtain username.",
1368 .ml_name
= "set_username",
1369 .ml_meth
= py_creds_set_username
,
1370 .ml_flags
= METH_VARARGS
,
1371 .ml_doc
= "S.set_username(name[, credentials.SPECIFIED]) -> None\n"
1375 .ml_name
= "get_principal",
1376 .ml_meth
= py_creds_get_principal
,
1377 .ml_flags
= METH_NOARGS
,
1378 .ml_doc
= "S.get_principal() -> user@realm\nObtain user principal.",
1381 .ml_name
= "set_principal",
1382 .ml_meth
= py_creds_set_principal
,
1383 .ml_flags
= METH_VARARGS
,
1384 .ml_doc
= "S.set_principal(name[, credentials.SPECIFIED]) -> None\n"
1385 "Change principal.",
1388 .ml_name
= "get_password",
1389 .ml_meth
= py_creds_get_password
,
1390 .ml_flags
= METH_NOARGS
,
1391 .ml_doc
= "S.get_password() -> password\n"
1395 .ml_name
= "get_ntlm_username_domain",
1396 .ml_meth
= py_creds_get_ntlm_username_domain
,
1397 .ml_flags
= METH_NOARGS
,
1398 .ml_doc
= "S.get_ntlm_username_domain() -> (domain, username)\n"
1399 "Obtain NTLM username and domain, split up either as (DOMAIN, user) or (\"\", \"user@realm\").",
1402 .ml_name
= "get_ntlm_response",
1403 .ml_meth
= PY_DISCARD_FUNC_SIG(PyCFunction
,
1404 py_creds_get_ntlm_response
),
1405 .ml_flags
= METH_VARARGS
| METH_KEYWORDS
,
1406 .ml_doc
= "S.get_ntlm_response"
1407 "(flags, challenge[, target_info]) -> "
1408 "(flags, lm_response, nt_response, lm_session_key, nt_session_key)\n"
1409 "Obtain LM or NTLM response.",
1412 .ml_name
= "set_password",
1413 .ml_meth
= py_creds_set_password
,
1414 .ml_flags
= METH_VARARGS
,
1415 .ml_doc
= "S.set_password(password[, credentials.SPECIFIED]) -> None\n"
1419 .ml_name
= "set_utf16_password",
1420 .ml_meth
= py_creds_set_utf16_password
,
1421 .ml_flags
= METH_VARARGS
,
1422 .ml_doc
= "S.set_utf16_password(password[, credentials.SPECIFIED]) -> None\n"
1426 .ml_name
= "get_old_password",
1427 .ml_meth
= py_creds_get_old_password
,
1428 .ml_flags
= METH_NOARGS
,
1429 .ml_doc
= "S.get_old_password() -> password\n"
1430 "Obtain old password.",
1433 .ml_name
= "set_old_password",
1434 .ml_meth
= py_creds_set_old_password
,
1435 .ml_flags
= METH_VARARGS
,
1436 .ml_doc
= "S.set_old_password(password[, credentials.SPECIFIED]) -> None\n"
1437 "Change old password.",
1440 .ml_name
= "set_old_utf16_password",
1441 .ml_meth
= py_creds_set_old_utf16_password
,
1442 .ml_flags
= METH_VARARGS
,
1443 .ml_doc
= "S.set_old_utf16_password(password[, credentials.SPECIFIED]) -> None\n"
1444 "Change old password.",
1447 .ml_name
= "get_domain",
1448 .ml_meth
= py_creds_get_domain
,
1449 .ml_flags
= METH_NOARGS
,
1450 .ml_doc
= "S.get_domain() -> domain\n"
1451 "Obtain domain name.",
1454 .ml_name
= "set_domain",
1455 .ml_meth
= py_creds_set_domain
,
1456 .ml_flags
= METH_VARARGS
,
1457 .ml_doc
= "S.set_domain(domain[, credentials.SPECIFIED]) -> None\n"
1458 "Change domain name.",
1461 .ml_name
= "get_realm",
1462 .ml_meth
= py_creds_get_realm
,
1463 .ml_flags
= METH_NOARGS
,
1464 .ml_doc
= "S.get_realm() -> realm\n"
1465 "Obtain realm name.",
1468 .ml_name
= "set_realm",
1469 .ml_meth
= py_creds_set_realm
,
1470 .ml_flags
= METH_VARARGS
,
1471 .ml_doc
= "S.set_realm(realm[, credentials.SPECIFIED]) -> None\n"
1472 "Change realm name.",
1475 .ml_name
= "get_bind_dn",
1476 .ml_meth
= py_creds_get_bind_dn
,
1477 .ml_flags
= METH_NOARGS
,
1478 .ml_doc
= "S.get_bind_dn() -> bind dn\n"
1482 .ml_name
= "set_bind_dn",
1483 .ml_meth
= py_creds_set_bind_dn
,
1484 .ml_flags
= METH_VARARGS
,
1485 .ml_doc
= "S.set_bind_dn(bind_dn) -> None\n"
1489 .ml_name
= "is_anonymous",
1490 .ml_meth
= py_creds_is_anonymous
,
1491 .ml_flags
= METH_NOARGS
,
1494 .ml_name
= "set_anonymous",
1495 .ml_meth
= py_creds_set_anonymous
,
1496 .ml_flags
= METH_NOARGS
,
1497 .ml_doc
= "S.set_anonymous() -> None\n"
1498 "Use anonymous credentials.",
1501 .ml_name
= "get_workstation",
1502 .ml_meth
= py_creds_get_workstation
,
1503 .ml_flags
= METH_NOARGS
,
1506 .ml_name
= "set_workstation",
1507 .ml_meth
= py_creds_set_workstation
,
1508 .ml_flags
= METH_VARARGS
,
1511 .ml_name
= "authentication_requested",
1512 .ml_meth
= py_creds_authentication_requested
,
1513 .ml_flags
= METH_NOARGS
,
1516 .ml_name
= "wrong_password",
1517 .ml_meth
= py_creds_wrong_password
,
1518 .ml_flags
= METH_NOARGS
,
1519 .ml_doc
= "S.wrong_password() -> bool\n"
1520 "Indicate the returned password was incorrect.",
1523 .ml_name
= "set_cmdline_callbacks",
1524 .ml_meth
= py_creds_set_cmdline_callbacks
,
1525 .ml_flags
= METH_NOARGS
,
1526 .ml_doc
= "S.set_cmdline_callbacks() -> bool\n"
1527 "Use command-line to obtain credentials not explicitly set.",
1530 .ml_name
= "parse_string",
1531 .ml_meth
= py_creds_parse_string
,
1532 .ml_flags
= METH_VARARGS
,
1533 .ml_doc
= "S.parse_string(text[, credentials.SPECIFIED]) -> None\n"
1534 "Parse credentials string.",
1537 .ml_name
= "parse_file",
1538 .ml_meth
= py_creds_parse_file
,
1539 .ml_flags
= METH_VARARGS
,
1540 .ml_doc
= "S.parse_file(filename[, credentials.SPECIFIED]) -> None\n"
1541 "Parse credentials file.",
1544 .ml_name
= "set_password_will_be_nt_hash",
1545 .ml_meth
= py_cli_credentials_set_password_will_be_nt_hash
,
1546 .ml_flags
= METH_VARARGS
,
1547 .ml_doc
= "S.set_password_will_be_nt_hash(bool) -> None\n"
1548 "Alters the behaviour of S.set_password() "
1549 "to expect the NTHASH as hexstring.",
1552 .ml_name
= "get_nt_hash",
1553 .ml_meth
= py_creds_get_nt_hash
,
1554 .ml_flags
= METH_NOARGS
,
1557 .ml_name
= "set_nt_hash",
1558 .ml_meth
= py_creds_set_nt_hash
,
1559 .ml_flags
= METH_VARARGS
,
1560 .ml_doc
= "S.set_net_sh(samr_Password[, credentials.SPECIFIED]) -> bool\n"
1564 .ml_name
= "get_kerberos_state",
1565 .ml_meth
= py_creds_get_kerberos_state
,
1566 .ml_flags
= METH_NOARGS
,
1569 .ml_name
= "set_kerberos_state",
1570 .ml_meth
= py_creds_set_kerberos_state
,
1571 .ml_flags
= METH_VARARGS
,
1574 .ml_name
= "set_krb_forwardable",
1575 .ml_meth
= py_creds_set_krb_forwardable
,
1576 .ml_flags
= METH_VARARGS
,
1579 .ml_name
= "set_conf",
1580 .ml_meth
= py_creds_set_conf
,
1581 .ml_flags
= METH_VARARGS
,
1585 .ml_meth
= py_creds_guess
,
1586 .ml_flags
= METH_VARARGS
,
1589 .ml_name
= "set_machine_account",
1590 .ml_meth
= py_creds_set_machine_account
,
1591 .ml_flags
= METH_VARARGS
,
1594 .ml_name
= "get_named_ccache",
1595 .ml_meth
= py_creds_get_named_ccache
,
1596 .ml_flags
= METH_VARARGS
,
1599 .ml_name
= "set_named_ccache",
1600 .ml_meth
= py_creds_set_named_ccache
,
1601 .ml_flags
= METH_VARARGS
,
1602 .ml_doc
= "S.set_named_ccache(krb5_ccache_name, obtained, lp) -> None\n"
1603 "Set credentials to KRB5 Credentials Cache (by name).",
1606 .ml_name
= "set_gensec_features",
1607 .ml_meth
= py_creds_set_gensec_features
,
1608 .ml_flags
= METH_VARARGS
,
1611 .ml_name
= "get_gensec_features",
1612 .ml_meth
= py_creds_get_gensec_features
,
1613 .ml_flags
= METH_NOARGS
,
1616 .ml_name
= "get_forced_sasl_mech",
1617 .ml_meth
= py_creds_get_forced_sasl_mech
,
1618 .ml_flags
= METH_NOARGS
,
1619 .ml_doc
= "S.get_forced_sasl_mech() -> SASL mechanism\nObtain forced SASL mechanism.",
1622 .ml_name
= "set_forced_sasl_mech",
1623 .ml_meth
= py_creds_set_forced_sasl_mech
,
1624 .ml_flags
= METH_VARARGS
,
1625 .ml_doc
= "S.set_forced_sasl_mech(name) -> None\n"
1626 "Set forced SASL mechanism.",
1629 .ml_name
= "new_client_authenticator",
1630 .ml_meth
= py_creds_new_client_authenticator
,
1631 .ml_flags
= METH_NOARGS
,
1632 .ml_doc
= "S.new_client_authenticator() -> Authenticator\n"
1633 "Get a new client NETLOGON_AUTHENTICATOR"},
1635 .ml_name
= "set_secure_channel_type",
1636 .ml_meth
= py_creds_set_secure_channel_type
,
1637 .ml_flags
= METH_VARARGS
,
1640 .ml_name
= "get_secure_channel_type",
1641 .ml_meth
= py_creds_get_secure_channel_type
,
1642 .ml_flags
= METH_VARARGS
,
1645 .ml_name
= "set_kerberos_salt_principal",
1646 .ml_meth
= py_creds_set_kerberos_salt_principal
,
1647 .ml_flags
= METH_VARARGS
,
1650 .ml_name
= "get_kerberos_salt_principal",
1651 .ml_meth
= py_creds_get_kerberos_salt_principal
,
1652 .ml_flags
= METH_VARARGS
,
1655 .ml_name
= "get_kerberos_key",
1656 .ml_meth
= py_creds_get_kerberos_key
,
1657 .ml_flags
= METH_VARARGS
,
1658 .ml_doc
= "S.get_kerberos_key(enctype, [lp]) -> bytes\n"
1659 "Generate a Kerberos key using the current password and\n"
1660 "the salt on this credentials object",
1663 .ml_name
= "get_old_kerberos_key",
1664 .ml_meth
= py_creds_get_old_kerberos_key
,
1665 .ml_flags
= METH_VARARGS
,
1666 .ml_doc
= "S.get_old_kerberos_key(enctype, [lp]) -> bytes\n"
1667 "Generate a Kerberos key using the old (previous) password and\n"
1668 "the salt on this credentials object",
1671 .ml_name
= "encrypt_netr_crypt_password",
1672 .ml_meth
= py_creds_encrypt_netr_crypt_password
,
1673 .ml_flags
= METH_VARARGS
,
1674 .ml_doc
= "S.encrypt_netr_crypt_password(password) -> None\n"
1675 "Encrypt the supplied password using the session key and\n"
1676 "the negotiated encryption algorithm in place\n"
1677 "i.e. it overwrites the original data"},
1679 .ml_name
= "encrypt_samr_password",
1680 .ml_meth
= py_creds_encrypt_samr_password
,
1681 .ml_flags
= METH_VARARGS
,
1682 .ml_doc
= "S.encrypt_samr_password(password) -> None\n"
1683 "Encrypt the supplied password using the session key and\n"
1684 "the negotiated encryption algorithm in place\n"
1685 "i.e. it overwrites the original data"
1688 .ml_name
= "get_smb_signing",
1689 .ml_meth
= py_creds_get_smb_signing
,
1690 .ml_flags
= METH_NOARGS
,
1693 .ml_name
= "set_smb_signing",
1694 .ml_meth
= py_creds_set_smb_signing
,
1695 .ml_flags
= METH_VARARGS
,
1698 .ml_name
= "get_smb_ipc_signing",
1699 .ml_meth
= py_creds_get_smb_ipc_signing
,
1700 .ml_flags
= METH_NOARGS
,
1703 .ml_name
= "set_smb_ipc_signing",
1704 .ml_meth
= py_creds_set_smb_ipc_signing
,
1705 .ml_flags
= METH_VARARGS
,
1708 .ml_name
= "get_smb_encryption",
1709 .ml_meth
= py_creds_get_smb_encryption
,
1710 .ml_flags
= METH_NOARGS
,
1713 .ml_name
= "set_smb_encryption",
1714 .ml_meth
= py_creds_set_smb_encryption
,
1715 .ml_flags
= METH_VARARGS
,
1718 .ml_name
= "get_krb5_fast_armor_credentials",
1719 .ml_meth
= py_creds_get_krb5_fast_armor_credentials
,
1720 .ml_flags
= METH_NOARGS
,
1721 .ml_doc
= "S.get_krb5_fast_armor_credentials() -> Credentials\n"
1722 "Get the Kerberos FAST credentials set on this credentials object"
1725 .ml_name
= "set_krb5_fast_armor_credentials",
1726 .ml_meth
= py_creds_set_krb5_fast_armor_credentials
,
1727 .ml_flags
= METH_VARARGS
,
1728 .ml_doc
= "S.set_krb5_fast_armor_credentials(credentials, required) -> None\n"
1729 "Set Kerberos FAST credentials for this credentials object, and if FAST armoring must be used."
1732 .ml_name
= "get_krb5_require_fast_armor",
1733 .ml_meth
= py_creds_get_krb5_require_fast_armor
,
1734 .ml_flags
= METH_NOARGS
,
1735 .ml_doc
= "S.get_krb5_fast_armor() -> bool\n"
1736 "Indicate if Kerberos FAST armor is required"
1741 static struct PyModuleDef moduledef
= {
1742 PyModuleDef_HEAD_INIT
,
1743 .m_name
= "credentials",
1744 .m_doc
= "Credentials management.",
1746 .m_methods
= py_creds_methods
,
1749 PyTypeObject PyCredentials
= {
1750 .tp_name
= "credentials.Credentials",
1751 .tp_new
= py_creds_new
,
1752 .tp_flags
= Py_TPFLAGS_DEFAULT
| Py_TPFLAGS_BASETYPE
,
1753 .tp_methods
= py_creds_methods
,
1756 static PyObject
*py_ccache_name(PyObject
*self
, PyObject
*unused
)
1758 struct ccache_container
*ccc
= NULL
;
1760 PyObject
*py_name
= NULL
;
1763 ccc
= pytalloc_get_type(self
, struct ccache_container
);
1765 ret
= krb5_cc_get_full_name(ccc
->smb_krb5_context
->krb5_context
,
1766 ccc
->ccache
, &name
);
1768 py_name
= PyString_FromStringOrNULL(name
);
1769 krb5_free_string(ccc
->smb_krb5_context
->krb5_context
, name
);
1771 PyErr_SetString(PyExc_RuntimeError
,
1772 "Failed to get ccache name");
1778 static PyMethodDef py_ccache_container_methods
[] = {
1779 { "get_name", py_ccache_name
, METH_NOARGS
,
1780 "S.get_name() -> name\nObtain KRB5 credentials cache name." },
1784 PyTypeObject PyCredentialCacheContainer
= {
1785 .tp_name
= "credentials.CredentialCacheContainer",
1786 .tp_flags
= Py_TPFLAGS_DEFAULT
,
1787 .tp_methods
= py_ccache_container_methods
,
1790 MODULE_INIT_FUNC(credentials
)
1793 if (pytalloc_BaseObject_PyType_Ready(&PyCredentials
) < 0)
1796 if (pytalloc_BaseObject_PyType_Ready(&PyCredentialCacheContainer
) < 0)
1799 m
= PyModule_Create(&moduledef
);
1803 PyModule_AddObject(m
, "UNINITIALISED", PyLong_FromLong(CRED_UNINITIALISED
));
1804 PyModule_AddObject(m
, "SMB_CONF", PyLong_FromLong(CRED_SMB_CONF
));
1805 PyModule_AddObject(m
, "CALLBACK", PyLong_FromLong(CRED_CALLBACK
));
1806 PyModule_AddObject(m
, "GUESS_ENV", PyLong_FromLong(CRED_GUESS_ENV
));
1807 PyModule_AddObject(m
, "GUESS_FILE", PyLong_FromLong(CRED_GUESS_FILE
));
1808 PyModule_AddObject(m
, "CALLBACK_RESULT", PyLong_FromLong(CRED_CALLBACK_RESULT
));
1809 PyModule_AddObject(m
, "SPECIFIED", PyLong_FromLong(CRED_SPECIFIED
));
1811 PyModule_AddObject(m
, "AUTO_USE_KERBEROS", PyLong_FromLong(CRED_USE_KERBEROS_DESIRED
));
1812 PyModule_AddObject(m
, "DONT_USE_KERBEROS", PyLong_FromLong(CRED_USE_KERBEROS_DISABLED
));
1813 PyModule_AddObject(m
, "MUST_USE_KERBEROS", PyLong_FromLong(CRED_USE_KERBEROS_REQUIRED
));
1815 PyModule_AddObject(m
, "AUTO_KRB_FORWARDABLE", PyLong_FromLong(CRED_AUTO_KRB_FORWARDABLE
));
1816 PyModule_AddObject(m
, "NO_KRB_FORWARDABLE", PyLong_FromLong(CRED_NO_KRB_FORWARDABLE
));
1817 PyModule_AddObject(m
, "FORCE_KRB_FORWARDABLE", PyLong_FromLong(CRED_FORCE_KRB_FORWARDABLE
));
1818 PyModule_AddObject(m
, "CLI_CRED_NTLM2", PyLong_FromLong(CLI_CRED_NTLM2
));
1819 PyModule_AddObject(m
, "CLI_CRED_NTLMv2_AUTH", PyLong_FromLong(CLI_CRED_NTLMv2_AUTH
));
1820 PyModule_AddObject(m
, "CLI_CRED_LANMAN_AUTH", PyLong_FromLong(CLI_CRED_LANMAN_AUTH
));
1821 PyModule_AddObject(m
, "CLI_CRED_NTLM_AUTH", PyLong_FromLong(CLI_CRED_NTLM_AUTH
));
1822 PyModule_AddObject(m
, "CLI_CRED_CLEAR_AUTH", PyLong_FromLong(CLI_CRED_CLEAR_AUTH
));
1824 PyModule_AddObject(m
, "SMB_SIGNING_DEFAULT", PyLong_FromLong(SMB_SIGNING_DEFAULT
));
1825 PyModule_AddObject(m
, "SMB_SIGNING_OFF", PyLong_FromLong(SMB_SIGNING_OFF
));
1826 PyModule_AddObject(m
, "SMB_SIGNING_IF_REQUIRED", PyLong_FromLong(SMB_SIGNING_IF_REQUIRED
));
1827 PyModule_AddObject(m
, "SMB_SIGNING_DESIRED", PyLong_FromLong(SMB_SIGNING_DESIRED
));
1828 PyModule_AddObject(m
, "SMB_SIGNING_REQUIRED", PyLong_FromLong(SMB_SIGNING_REQUIRED
));
1830 PyModule_AddObject(m
, "SMB_ENCRYPTION_DEFAULT", PyLong_FromLong(SMB_ENCRYPTION_DEFAULT
));
1831 PyModule_AddObject(m
, "SMB_ENCRYPTION_OFF", PyLong_FromLong(SMB_ENCRYPTION_OFF
));
1832 PyModule_AddObject(m
, "SMB_ENCRYPTION_IF_REQUIRED", PyLong_FromLong(SMB_ENCRYPTION_IF_REQUIRED
));
1833 PyModule_AddObject(m
, "SMB_ENCRYPTION_DESIRED", PyLong_FromLong(SMB_ENCRYPTION_DESIRED
));
1834 PyModule_AddObject(m
, "SMB_ENCRYPTION_REQUIRED", PyLong_FromLong(SMB_ENCRYPTION_REQUIRED
));
1836 PyModule_AddObject(m
, "ENCTYPE_ARCFOUR_HMAC", PyLong_FromLong(ENCTYPE_ARCFOUR_HMAC
));
1837 PyModule_AddObject(m
, "ENCTYPE_AES128_CTS_HMAC_SHA1_96", PyLong_FromLong(ENCTYPE_AES128_CTS_HMAC_SHA1_96
));
1838 PyModule_AddObject(m
, "ENCTYPE_AES256_CTS_HMAC_SHA1_96", PyLong_FromLong(ENCTYPE_AES256_CTS_HMAC_SHA1_96
));
1840 Py_INCREF(&PyCredentials
);
1841 PyModule_AddObject(m
, "Credentials", (PyObject
*)&PyCredentials
);
1842 Py_INCREF(&PyCredentialCacheContainer
);
1843 PyModule_AddObject(m
, "CredentialCacheContainer", (PyObject
*)&PyCredentialCacheContainer
);