2008-05-24 21:02:56 +02:00
/*
Unix SMB / CIFS implementation .
Samba utility functions
Copyright ( C ) Jelmer Vernooij < jelmer @ samba . org > 2008
2010-09-03 02:39:38 +02:00
2008-05-24 21:02:56 +02:00
This program is free software ; you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation ; either version 3 of the License , or
( at your option ) any later version .
2010-09-03 02:39:38 +02:00
2008-05-24 21:02:56 +02:00
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
2010-09-03 02:39:38 +02:00
2008-05-24 21:02:56 +02:00
You should have received a copy of the GNU General Public License
along with this program . If not , see < http : //www.gnu.org/licenses/>.
*/
2024-09-18 23:35:20 +02:00
# define SOURCE4_LIBRPC_INTERNALS 1
2023-11-09 11:35:56 +01:00
# include "lib/replace/system/python.h"
2017-02-15 09:19:33 +01:00
# include "python/py3compat.h"
2009-10-23 16:23:01 +11:00
# include "includes.h"
2019-05-02 19:35:56 +01:00
# include "python/modules.h"
2008-05-25 04:38:57 +02:00
# include <structmember.h>
2008-05-24 21:02:56 +02:00
# include "librpc/rpc/pyrpc.h"
# include "lib/events/events.h"
2008-12-22 04:38:57 +01:00
# include "param/pyparam.h"
2010-09-03 02:39:38 +02:00
# include "librpc/rpc/dcerpc.h"
# include "librpc/rpc/pyrpc_util.h"
2009-04-23 01:21:47 +02:00
# include "auth/credentials/pycredentials.h"
2011-12-16 10:55:46 +01:00
# include "auth/gensec/gensec.h"
2008-05-24 21:02:56 +02:00
2010-12-17 22:17:33 +01:00
void initbase ( void ) ;
2014-12-03 13:59:58 +01:00
static PyTypeObject dcerpc_InterfaceType ;
2008-05-25 23:14:48 +02:00
2018-11-29 12:41:34 +01:00
static PyTypeObject * BaseObject_Type ;
2014-03-27 14:57:29 +01:00
static PyTypeObject * ndr_syntax_id_Type ;
2008-05-24 23:02:09 +02:00
static bool PyString_AsGUID ( PyObject * object , struct GUID * uuid )
{
NTSTATUS status ;
2019-06-07 11:16:25 +02:00
status = GUID_from_string ( PyUnicode_AsUTF8 ( object ) , uuid ) ;
2008-05-24 23:02:09 +02:00
if ( NT_STATUS_IS_ERR ( status ) ) {
PyErr_SetNTSTATUS ( status ) ;
return false ;
}
return true ;
}
2008-05-25 04:23:03 +02:00
static bool ndr_syntax_from_py_object ( PyObject * object , struct ndr_syntax_id * syntax_id )
{
ZERO_STRUCTP ( syntax_id ) ;
2019-06-15 23:14:49 +12:00
if ( PyUnicode_Check ( object ) ) {
2008-05-25 04:23:03 +02:00
return PyString_AsGUID ( object , & syntax_id - > uuid ) ;
2022-03-17 17:14:40 +01:00
}
if ( PyTuple_Check ( object ) ) {
2018-04-13 17:34:19 +01:00
PyObject * item = NULL ;
2008-05-25 04:23:03 +02:00
if ( PyTuple_Size ( object ) < 1 | | PyTuple_Size ( object ) > 2 ) {
PyErr_SetString ( PyExc_ValueError , " Syntax ID tuple has invalid size " ) ;
return false ;
}
2018-04-13 17:34:19 +01:00
item = PyTuple_GetItem ( object , 0 ) ;
2019-06-15 23:14:49 +12:00
if ( ! PyUnicode_Check ( item ) ) {
2008-05-25 04:23:03 +02:00
PyErr_SetString ( PyExc_ValueError , " Expected GUID as first element in tuple " ) ;
return false ;
}
2018-04-13 17:34:19 +01:00
if ( ! PyString_AsGUID ( item , & syntax_id - > uuid ) ) {
2008-05-25 04:23:03 +02:00
return false ;
2018-04-13 17:34:19 +01:00
}
2008-05-25 04:23:03 +02:00
2018-04-13 17:34:19 +01:00
item = PyTuple_GetItem ( object , 1 ) ;
2020-03-15 10:04:52 +13:00
if ( ! PyLong_Check ( item ) ) {
2008-05-25 04:23:03 +02:00
PyErr_SetString ( PyExc_ValueError , " Expected version as second element in tuple " ) ;
return false ;
}
2020-03-15 10:32:11 +13:00
syntax_id - > if_version = PyLong_AsLong ( item ) ;
2008-05-25 04:23:03 +02:00
return true ;
}
PyErr_SetString ( PyExc_TypeError , " Expected UUID or syntax id tuple " ) ;
return false ;
2010-09-03 02:39:38 +02:00
}
2008-05-25 04:23:03 +02:00
2008-05-24 21:02:56 +02:00
static PyObject * py_iface_server_name ( PyObject * obj , void * closure )
{
2008-05-24 21:20:45 +02:00
const char * server_name ;
2008-05-24 21:02:56 +02:00
dcerpc_InterfaceObject * iface = ( dcerpc_InterfaceObject * ) obj ;
2010-09-03 02:39:38 +02:00
2008-05-24 21:20:45 +02:00
server_name = dcerpc_server_name ( iface - > pipe ) ;
if ( server_name = = NULL )
2009-01-06 04:13:57 +01:00
Py_RETURN_NONE ;
2008-05-24 21:02:56 +02:00
2019-06-07 10:45:52 +02:00
return PyUnicode_FromString ( server_name ) ;
2008-05-24 21:02:56 +02:00
}
2008-05-25 04:54:38 +02:00
static PyObject * py_ndr_syntax_id ( struct ndr_syntax_id * syntax_id )
{
PyObject * ret ;
2022-03-17 17:18:21 +01:00
struct GUID_txt_buf buf ;
2008-05-25 04:54:38 +02:00
2022-03-17 17:18:21 +01:00
ret = Py_BuildValue (
" (s,i) " ,
GUID_buf_string ( & syntax_id - > uuid , & buf ) ,
syntax_id - > if_version ) ;
2008-05-25 04:54:38 +02:00
return ret ;
}
static PyObject * py_iface_abstract_syntax ( PyObject * obj , void * closure )
{
dcerpc_InterfaceObject * iface = ( dcerpc_InterfaceObject * ) obj ;
return py_ndr_syntax_id ( & iface - > pipe - > syntax ) ;
}
static PyObject * py_iface_transfer_syntax ( PyObject * obj , void * closure )
{
dcerpc_InterfaceObject * iface = ( dcerpc_InterfaceObject * ) obj ;
return py_ndr_syntax_id ( & iface - > pipe - > transfer_syntax ) ;
}
2011-08-26 13:23:41 +10:00
static PyObject * py_iface_session_key ( PyObject * obj , void * closure )
{
dcerpc_InterfaceObject * iface = ( dcerpc_InterfaceObject * ) obj ;
2024-09-14 14:20:46 +02:00
TALLOC_CTX * frame = talloc_stackframe ( ) ;
DATA_BLOB session_key = { . length = 0 , } ;
static PyObject * session_key_obj = NULL ;
NTSTATUS status ;
2011-08-26 13:23:41 +10:00
2024-09-14 14:20:46 +02:00
if ( iface - > binding_handle = = NULL ) {
PyErr_SetNTSTATUS ( NT_STATUS_NO_USER_SESSION_KEY ) ;
TALLOC_FREE ( frame ) ;
return NULL ;
}
status = dcerpc_binding_handle_transport_session_key ( iface - > binding_handle ,
frame ,
& session_key ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
PyErr_SetNTSTATUS ( status ) ;
TALLOC_FREE ( frame ) ;
return NULL ;
}
2011-08-26 13:23:41 +10:00
2024-09-14 14:20:46 +02:00
session_key_obj = PyBytes_FromStringAndSize ( ( const char * ) session_key . data ,
session_key . length ) ;
TALLOC_FREE ( frame ) ;
return session_key_obj ;
2011-08-26 13:23:41 +10:00
}
2011-12-16 10:55:46 +01:00
static PyObject * py_iface_user_session_key ( PyObject * obj , void * closure )
{
dcerpc_InterfaceObject * iface = ( dcerpc_InterfaceObject * ) obj ;
TALLOC_CTX * mem_ctx ;
NTSTATUS status ;
DATA_BLOB session_key = data_blob_null ;
static PyObject * session_key_obj = NULL ;
2024-09-14 14:20:46 +02:00
if ( iface - > binding_handle = = NULL ) {
2011-12-16 10:55:46 +01:00
PyErr_SetNTSTATUS ( NT_STATUS_NO_USER_SESSION_KEY ) ;
return NULL ;
}
mem_ctx = talloc_new ( NULL ) ;
2024-09-14 14:20:46 +02:00
status = dcerpc_binding_handle_auth_session_key ( iface - > binding_handle ,
mem_ctx ,
& session_key ) ;
2011-12-16 10:55:46 +01:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
talloc_free ( mem_ctx ) ;
PyErr_SetNTSTATUS ( status ) ;
return NULL ;
}
2017-02-15 09:19:33 +01:00
session_key_obj = PyBytes_FromStringAndSize ( ( const char * ) session_key . data ,
2011-12-16 10:55:46 +01:00
session_key . length ) ;
talloc_free ( mem_ctx ) ;
return session_key_obj ;
}
2016-07-28 06:36:05 +02:00
static PyObject * py_iface_get_timeout ( PyObject * obj , void * closure )
{
dcerpc_InterfaceObject * iface = ( dcerpc_InterfaceObject * ) obj ;
uint32_t timeout ;
timeout = dcerpc_binding_handle_set_timeout ( iface - > binding_handle , 0 ) ;
dcerpc_binding_handle_set_timeout ( iface - > binding_handle , timeout ) ;
return PyLong_FromUnsignedLong ( timeout ) ;
}
static int py_iface_set_timeout ( PyObject * obj , PyObject * value , void * closure )
{
dcerpc_InterfaceObject * iface = ( dcerpc_InterfaceObject * ) obj ;
uint32_t timeout ;
timeout = PyLong_AsUnsignedLong ( value ) ;
if ( PyErr_Occurred ( ) ! = NULL ) {
return - 1 ;
}
dcerpc_binding_handle_set_timeout ( iface - > binding_handle , timeout ) ;
return 0 ;
}
2008-05-24 21:02:56 +02:00
static PyGetSetDef dcerpc_interface_getsetters [ ] = {
2018-12-13 11:38:43 +01:00
{
. name = discard_const_p ( char , " server_name " ) ,
. get = py_iface_server_name ,
. doc = discard_const_p ( char , " name of the server, if connected over SMB " ) ,
} ,
{
. name = discard_const_p ( char , " abstract_syntax " ) ,
. get = py_iface_abstract_syntax ,
. doc = discard_const_p ( char , " syntax id of the abstract syntax " ) ,
} ,
{
. name = discard_const_p ( char , " transfer_syntax " ) ,
. get = py_iface_transfer_syntax ,
2019-01-18 10:57:51 +13:00
. doc = discard_const_p ( char , " syntax id of the transfer syntax " ) ,
2018-12-13 11:38:43 +01:00
} ,
{
. name = discard_const_p ( char , " session_key " ) ,
. get = py_iface_session_key ,
. doc = discard_const_p ( char , " session key (as used for blob encryption on LSA and SAMR) " ) ,
} ,
{
. name = discard_const_p ( char , " user_session_key " ) ,
. get = py_iface_user_session_key ,
. doc = discard_const_p ( char , " user_session key (as used for blob encryption on DRSUAPI) " ) ,
} ,
{
. name = discard_const_p ( char , " request_timeout " ) ,
. get = py_iface_get_timeout ,
. set = py_iface_set_timeout ,
. doc = discard_const_p ( char , " request timeout, in seconds " ) ,
} ,
{ . name = NULL }
2008-05-25 04:38:57 +02:00
} ;
2008-05-24 21:02:56 +02:00
static PyObject * py_iface_request ( PyObject * self , PyObject * args , PyObject * kwargs )
{
dcerpc_InterfaceObject * iface = ( dcerpc_InterfaceObject * ) self ;
int opnum ;
DATA_BLOB data_in , data_out ;
NTSTATUS status ;
2008-05-24 21:20:45 +02:00
char * in_data ;
2016-01-04 13:07:08 +13:00
Py_ssize_t in_length ;
2008-05-24 21:20:45 +02:00
PyObject * ret ;
2008-05-24 23:02:09 +02:00
PyObject * object = NULL ;
struct GUID object_guid ;
2008-05-24 21:20:45 +02:00
TALLOC_CTX * mem_ctx = talloc_new ( NULL ) ;
2011-03-13 14:44:53 +01:00
uint32_t out_flags = 0 ;
2008-05-24 21:02:56 +02:00
const char * kwnames [ ] = { " opnum " , " data " , " object " , NULL } ;
2008-05-24 23:02:09 +02:00
if ( ! PyArg_ParseTupleAndKeywords ( args , kwargs , " is#|O:request " ,
2008-05-24 21:20:45 +02:00
discard_const_p ( char * , kwnames ) , & opnum , & in_data , & in_length , & object ) ) {
2011-03-13 14:44:28 +01:00
talloc_free ( mem_ctx ) ;
2008-05-24 21:02:56 +02:00
return NULL ;
}
2008-05-24 23:07:16 +02:00
data_in . data = ( uint8_t * ) talloc_memdup ( mem_ctx , in_data , in_length ) ;
2008-05-24 21:20:45 +02:00
data_in . length = in_length ;
2008-05-24 22:56:49 +02:00
ZERO_STRUCT ( data_out ) ;
2008-05-24 23:02:09 +02:00
if ( object ! = NULL & & ! PyString_AsGUID ( object , & object_guid ) ) {
2011-03-13 14:44:28 +01:00
talloc_free ( mem_ctx ) ;
2008-05-24 23:02:09 +02:00
return NULL ;
}
2011-03-13 14:44:53 +01:00
status = dcerpc_binding_handle_raw_call ( iface - > binding_handle ,
object ? & object_guid : NULL ,
opnum ,
0 , /* in_flags */
data_in . data ,
data_in . length ,
mem_ctx ,
& data_out . data ,
& data_out . length ,
& out_flags ) ;
2010-04-13 09:07:21 +02:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2008-05-24 23:39:38 +02:00
PyErr_SetDCERPCStatus ( iface - > pipe , status ) ;
2008-05-24 21:20:45 +02:00
talloc_free ( mem_ctx ) ;
2008-05-24 21:02:56 +02:00
return NULL ;
}
2017-02-15 09:19:33 +01:00
ret = PyBytes_FromStringAndSize ( ( char * ) data_out . data , data_out . length ) ;
2008-05-24 21:20:45 +02:00
talloc_free ( mem_ctx ) ;
return ret ;
2008-05-24 21:02:56 +02:00
}
2020-08-20 12:35:01 +02:00
static PyObject * py_iface_transport_encrypted ( PyObject * self )
{
dcerpc_InterfaceObject * iface = ( dcerpc_InterfaceObject * ) self ;
2024-09-14 13:35:47 +02:00
if ( dcerpc_binding_handle_transport_encrypted ( iface - > binding_handle ) ) {
2020-08-20 12:35:01 +02:00
Py_RETURN_TRUE ;
}
Py_RETURN_FALSE ;
}
2008-05-24 21:02:56 +02:00
static PyMethodDef dcerpc_interface_methods [ ] = {
2019-05-02 19:35:56 +01:00
{ " request " , PY_DISCARD_FUNC_SIG ( PyCFunction , py_iface_request ) ,
METH_VARARGS | METH_KEYWORDS ,
" S.request(opnum, data, object=None) -> data \n "
" Make a raw request " } ,
2020-08-20 12:35:01 +02:00
{ " transport_encrypted " , PY_DISCARD_FUNC_SIG ( PyCFunction , py_iface_transport_encrypted ) ,
METH_NOARGS ,
" Check if the DCE transport is encrypted " } ,
2008-05-24 21:02:56 +02:00
{ NULL , NULL , 0 , NULL } ,
} ;
static void dcerpc_interface_dealloc ( PyObject * self )
{
dcerpc_InterfaceObject * interface = ( dcerpc_InterfaceObject * ) self ;
2019-05-08 11:30:20 +12:00
struct tevent_context * ev_save = talloc_reparent (
2019-05-22 11:43:54 +12:00
interface - > mem_ctx , NULL , interface - > ev ) ;
SMB_ASSERT ( ev_save ! = NULL ) ;
2019-05-08 11:30:20 +12:00
2014-01-05 18:37:41 +01:00
interface - > binding_handle = NULL ;
interface - > pipe = NULL ;
2019-05-08 11:30:20 +12:00
/*
* Free everything * except * the event context , which must go
* away last
*/
2014-01-05 18:37:41 +01:00
TALLOC_FREE ( interface - > mem_ctx ) ;
2019-05-08 11:30:20 +12:00
/*
* Now wish a fond goodbye to the event context itself
*/
talloc_unlink ( NULL , ev_save ) ;
2010-12-29 18:56:13 +01:00
self - > ob_type - > tp_free ( self ) ;
2008-05-24 21:02:56 +02:00
}
2010-06-19 18:57:13 +02:00
static PyObject * dcerpc_interface_new ( PyTypeObject * type , PyObject * args , PyObject * kwargs )
2008-05-24 21:02:56 +02:00
{
2014-02-15 10:19:29 +01:00
PyObject * ret ;
2014-01-05 18:37:41 +01:00
const char * binding_string = NULL ;
PyObject * py_lp_ctx = Py_None ;
PyObject * py_credentials = Py_None ;
PyObject * syntax = Py_None ;
PyObject * py_basis = Py_None ;
2008-05-24 21:02:56 +02:00
const char * kwnames [ ] = {
2008-05-25 04:23:03 +02:00
" binding " , " syntax " , " lp_ctx " , " credentials " , " basis_connection " , NULL
2008-05-24 21:02:56 +02:00
} ;
2014-02-15 10:19:29 +01:00
static struct ndr_interface_table dummy_table ;
2017-04-19 16:13:20 +12:00
static struct ndr_interface_string_array dummy_endpoints ;
2014-02-15 10:19:29 +01:00
PyObject * args2 = Py_None ;
PyObject * kwargs2 = Py_None ;
2008-05-24 21:02:56 +02:00
2008-05-25 04:23:03 +02:00
if ( ! PyArg_ParseTupleAndKeywords ( args , kwargs , " sO|OOO:connect " , discard_const_p ( char * , kwnames ) , & binding_string , & syntax , & py_lp_ctx , & py_credentials , & py_basis ) ) {
2008-05-24 21:02:56 +02:00
return NULL ;
}
2014-02-15 10:19:29 +01:00
if ( strncmp ( binding_string , " irpc: " , 5 ) = = 0 ) {
PyErr_SetString ( PyExc_ValueError , " irpc: transport not supported " ) ;
2010-06-19 18:57:13 +02:00
return NULL ;
}
2014-02-15 10:19:29 +01:00
/*
* Fill a dummy interface table struct . TODO : In the future , we should
2010-06-19 18:57:13 +02:00
* rather just allow connecting without requiring an interface table .
2014-02-15 10:19:29 +01:00
*
* We just fill the syntax during the connect , but keep the memory valid
* the whole time .
2008-05-24 22:56:49 +02:00
*/
2014-02-15 10:19:29 +01:00
if ( ! ndr_syntax_from_py_object ( syntax , & dummy_table . syntax_id ) ) {
2008-05-24 22:56:49 +02:00
return NULL ;
}
2017-04-19 16:13:20 +12:00
/*
* Initialise the endpoints list in dummy_table if required
*/
if ( dummy_table . endpoints = = NULL ) {
dummy_table . endpoints = & dummy_endpoints ;
}
2014-02-15 10:19:29 +01:00
args2 = Py_BuildValue ( " (s) " , binding_string ) ;
if ( args2 = = NULL ) {
2008-05-24 22:56:49 +02:00
return NULL ;
}
2014-02-15 10:19:29 +01:00
kwargs2 = Py_BuildValue ( " {s:O,s:O,s:O} " ,
" lp_ctx " , py_lp_ctx ,
" credentials " , py_credentials ,
" basis_connection " , py_basis ) ;
if ( kwargs2 = = NULL ) {
Py_DECREF ( args2 ) ;
2008-05-24 21:02:56 +02:00
return NULL ;
}
2014-02-15 10:19:29 +01:00
ret = py_dcerpc_interface_init_helper ( type , args2 , kwargs2 , & dummy_table ) ;
ZERO_STRUCT ( dummy_table . syntax_id ) ;
Py_DECREF ( args2 ) ;
Py_DECREF ( kwargs2 ) ;
return ret ;
2008-05-24 21:02:56 +02:00
}
2010-09-03 02:39:38 +02:00
static PyTypeObject dcerpc_InterfaceType = {
2017-02-15 09:19:33 +01:00
PyVarObject_HEAD_INIT ( NULL , 0 )
2008-05-24 21:02:56 +02:00
. tp_name = " dcerpc.ClientConnection " ,
. tp_basicsize = sizeof ( dcerpc_InterfaceObject ) ,
. tp_dealloc = dcerpc_interface_dealloc ,
. tp_getset = dcerpc_interface_getsetters ,
. tp_methods = dcerpc_interface_methods ,
. tp_doc = " ClientConnection(binding, syntax, lp_ctx=None, credentials=None) -> connection \n "
" \n "
" binding should be a DCE/RPC binding string (for example: ncacn_ip_tcp:127.0.0.1) \n "
" syntax should be a tuple with a GUID and version number of an interface \n "
" lp_ctx should be a path to a smb.conf file or a param.LoadParm object \n "
" credentials should be a credentials.Credentials object. \n \n " ,
. tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE ,
. tp_new = dcerpc_interface_new ,
} ;
2014-03-27 14:57:29 +01:00
static PyObject * py_transfer_syntax_ndr_new ( PyTypeObject * type , PyObject * args , PyObject * kwargs )
{
return py_dcerpc_syntax_init_helper ( type , args , kwargs , & ndr_transfer_syntax_ndr ) ;
}
static PyTypeObject py_transfer_syntax_ndr_SyntaxType = {
2017-02-15 09:19:33 +01:00
PyVarObject_HEAD_INIT ( NULL , 0 )
2014-03-27 14:57:29 +01:00
. tp_name = " base.transfer_syntax_ndr " ,
. tp_doc = " transfer_syntax_ndr() \n " ,
. tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE ,
. tp_new = py_transfer_syntax_ndr_new ,
} ;
static PyObject * py_transfer_syntax_ndr64_new ( PyTypeObject * type , PyObject * args , PyObject * kwargs )
{
return py_dcerpc_syntax_init_helper ( type , args , kwargs , & ndr_transfer_syntax_ndr64 ) ;
}
static PyTypeObject py_transfer_syntax_ndr64_SyntaxType = {
2017-02-15 09:19:33 +01:00
PyVarObject_HEAD_INIT ( NULL , 0 )
2014-03-27 14:57:29 +01:00
. tp_name = " base.transfer_syntax_ndr64 " ,
. tp_doc = " transfer_syntax_ndr64() \n " ,
. tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE ,
. tp_new = py_transfer_syntax_ndr64_new ,
} ;
2014-04-02 19:53:18 +02:00
static PyObject * py_bind_time_features_syntax_new ( PyTypeObject * type , PyObject * args , PyObject * kwargs )
{
const char * kwnames [ ] = {
" features " , NULL
} ;
unsigned long long features = 0 ;
struct ndr_syntax_id syntax ;
PyObject * args2 = Py_None ;
PyObject * kwargs2 = Py_None ;
if ( ! PyArg_ParseTupleAndKeywords ( args , kwargs , " K:features " , discard_const_p ( char * , kwnames ) , & features ) ) {
return NULL ;
}
args2 = Py_BuildValue ( " () " ) ;
if ( args2 = = NULL ) {
return NULL ;
}
kwargs2 = Py_BuildValue ( " {} " ) ;
if ( kwargs2 = = NULL ) {
Py_DECREF ( args2 ) ;
return NULL ;
}
syntax = dcerpc_construct_bind_time_features ( features ) ;
return py_dcerpc_syntax_init_helper ( type , args2 , kwargs2 , & syntax ) ;
}
static PyTypeObject py_bind_time_features_syntax_SyntaxType = {
2017-02-15 09:19:33 +01:00
PyVarObject_HEAD_INIT ( NULL , 0 )
2014-04-02 19:53:18 +02:00
. tp_name = " base.bind_time_features_syntax " ,
. tp_doc = " bind_time_features_syntax(features) \n " ,
. tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE ,
. tp_new = py_bind_time_features_syntax_new ,
} ;
2018-11-29 12:41:34 +01:00
struct py_dcerpc_ndr_pointer {
PyObject * value ;
} ;
static void py_dcerpc_ndr_pointer_dealloc ( PyObject * self )
{
struct py_dcerpc_ndr_pointer * obj =
pytalloc_get_type ( self , struct py_dcerpc_ndr_pointer ) ;
2023-04-24 10:42:39 +12:00
Py_CLEAR ( obj - > value ) ;
2018-11-29 12:41:34 +01:00
self - > ob_type - > tp_free ( self ) ;
}
static PyObject * py_dcerpc_ndr_pointer_get_value ( PyObject * self , void * closure )
{
struct py_dcerpc_ndr_pointer * obj =
pytalloc_get_type ( self , struct py_dcerpc_ndr_pointer ) ;
Py_INCREF ( obj - > value ) ;
return obj - > value ;
}
static int py_dcerpc_ndr_pointer_set_value ( PyObject * self , PyObject * value , void * closure )
{
struct py_dcerpc_ndr_pointer * obj =
pytalloc_get_type ( self , struct py_dcerpc_ndr_pointer ) ;
2023-04-24 10:42:39 +12:00
Py_CLEAR ( obj - > value ) ;
2018-11-29 12:41:34 +01:00
obj - > value = value ;
Py_INCREF ( obj - > value ) ;
return 0 ;
}
static PyGetSetDef py_dcerpc_ndr_pointer_getsetters [ ] = {
2018-12-13 11:38:43 +01:00
{
. name = discard_const_p ( char , " value " ) ,
. get = py_dcerpc_ndr_pointer_get_value ,
. set = py_dcerpc_ndr_pointer_set_value ,
. doc = discard_const_p ( char , " the value store by the pointer " ) ,
} ,
{
. name = NULL ,
} ,
2018-11-29 12:41:34 +01:00
} ;
static PyObject * py_dcerpc_ndr_pointer_new ( PyTypeObject * type , PyObject * args , PyObject * kwargs )
{
PyObject * ret = NULL ;
struct py_dcerpc_ndr_pointer * obj = NULL ;
const char * kwnames [ ] = { " value " , NULL } ;
PyObject * value = NULL ;
bool ok ;
ok = PyArg_ParseTupleAndKeywords ( args , kwargs , " O:value " ,
discard_const_p ( char * , kwnames ) ,
& value ) ;
if ( ! ok ) {
return NULL ;
}
ret = pytalloc_new ( struct py_dcerpc_ndr_pointer , type ) ;
if ( ret = = NULL ) {
return NULL ;
}
obj = pytalloc_get_type ( ret , struct py_dcerpc_ndr_pointer ) ;
* obj = ( struct py_dcerpc_ndr_pointer ) {
. value = value ,
} ;
Py_INCREF ( obj - > value ) ;
return ret ;
}
static PyTypeObject py_dcerpc_ndr_pointer_type = {
PyVarObject_HEAD_INIT ( NULL , 0 )
. tp_name = " base.ndr_pointer " ,
. tp_dealloc = py_dcerpc_ndr_pointer_dealloc ,
. tp_getset = py_dcerpc_ndr_pointer_getsetters ,
. tp_doc = " ndr_pointer(value) \n " ,
. tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE ,
. tp_new = py_dcerpc_ndr_pointer_new ,
} ;
2017-02-15 09:19:33 +01:00
static struct PyModuleDef moduledef = {
PyModuleDef_HEAD_INIT ,
. m_name = " base " ,
. m_doc = " DCE/RPC protocol implementation " ,
. m_size = - 1 ,
} ;
MODULE_INIT_FUNC ( base )
2008-05-24 21:02:56 +02:00
{
PyObject * m ;
2018-11-29 12:41:34 +01:00
PyObject * dep_talloc ;
2014-03-27 14:57:29 +01:00
PyObject * dep_samba_dcerpc_misc ;
2018-11-29 12:41:34 +01:00
dep_talloc = PyImport_ImportModule ( " talloc " ) ;
if ( dep_talloc = = NULL )
return NULL ;
BaseObject_Type = ( PyTypeObject * ) PyObject_GetAttrString ( dep_talloc , " BaseObject " ) ;
2019-01-23 15:15:07 +00:00
if ( BaseObject_Type = = NULL ) {
Py_CLEAR ( dep_talloc ) ;
2018-11-29 12:41:34 +01:00
return NULL ;
2019-01-23 15:15:07 +00:00
}
2018-11-29 12:41:34 +01:00
2019-01-23 15:15:07 +00:00
Py_CLEAR ( dep_talloc ) ;
2014-03-27 14:57:29 +01:00
dep_samba_dcerpc_misc = PyImport_ImportModule ( " samba.dcerpc.misc " ) ;
2019-01-23 15:15:07 +00:00
if ( dep_samba_dcerpc_misc = = NULL ) {
2017-02-15 09:19:33 +01:00
return NULL ;
2019-01-23 15:15:07 +00:00
}
2014-03-27 14:57:29 +01:00
ndr_syntax_id_Type = ( PyTypeObject * ) PyObject_GetAttrString ( dep_samba_dcerpc_misc , " ndr_syntax_id " ) ;
2019-01-23 15:15:07 +00:00
Py_CLEAR ( dep_samba_dcerpc_misc ) ;
if ( ndr_syntax_id_Type = = NULL ) {
2017-02-15 09:19:33 +01:00
return NULL ;
2019-01-23 15:15:07 +00:00
}
2014-03-27 14:57:29 +01:00
py_transfer_syntax_ndr_SyntaxType . tp_base = ndr_syntax_id_Type ;
2016-02-16 14:06:28 +13:00
py_transfer_syntax_ndr_SyntaxType . tp_basicsize = pytalloc_BaseObject_size ( ) ;
2014-03-27 14:57:29 +01:00
py_transfer_syntax_ndr64_SyntaxType . tp_base = ndr_syntax_id_Type ;
2016-02-16 14:06:28 +13:00
py_transfer_syntax_ndr64_SyntaxType . tp_basicsize = pytalloc_BaseObject_size ( ) ;
2014-04-02 19:53:18 +02:00
py_bind_time_features_syntax_SyntaxType . tp_base = ndr_syntax_id_Type ;
2016-02-16 14:06:28 +13:00
py_bind_time_features_syntax_SyntaxType . tp_basicsize = pytalloc_BaseObject_size ( ) ;
2008-05-24 21:02:56 +02:00
2018-11-29 12:41:34 +01:00
py_dcerpc_ndr_pointer_type . tp_base = BaseObject_Type ;
py_dcerpc_ndr_pointer_type . tp_basicsize = pytalloc_BaseObject_size ( ) ;
2019-01-23 15:15:07 +00:00
if ( PyType_Ready ( & dcerpc_InterfaceType ) < 0 ) {
2017-02-15 09:19:33 +01:00
return NULL ;
2019-01-23 15:15:07 +00:00
}
2008-05-24 21:02:56 +02:00
2019-01-23 15:15:07 +00:00
if ( PyType_Ready ( & py_transfer_syntax_ndr_SyntaxType ) < 0 ) {
2017-02-15 09:19:33 +01:00
return NULL ;
2019-01-23 15:15:07 +00:00
}
if ( PyType_Ready ( & py_transfer_syntax_ndr64_SyntaxType ) < 0 ) {
2017-02-15 09:19:33 +01:00
return NULL ;
2019-01-23 15:15:07 +00:00
}
if ( PyType_Ready ( & py_bind_time_features_syntax_SyntaxType ) < 0 ) {
2017-02-15 09:19:33 +01:00
return NULL ;
2019-01-23 15:15:07 +00:00
}
2014-03-27 14:57:29 +01:00
2019-01-23 15:15:07 +00:00
if ( PyType_Ready ( & py_dcerpc_ndr_pointer_type ) < 0 ) {
2018-11-29 12:41:34 +01:00
return NULL ;
2019-01-23 15:15:07 +00:00
}
2018-11-29 12:41:34 +01:00
2017-02-15 09:19:33 +01:00
m = PyModule_Create ( & moduledef ) ;
2019-01-23 15:15:07 +00:00
if ( m = = NULL ) {
2017-02-15 09:19:33 +01:00
return NULL ;
2019-01-23 15:15:07 +00:00
}
2008-05-24 21:02:56 +02:00
Py_INCREF ( ( PyObject * ) & dcerpc_InterfaceType ) ;
PyModule_AddObject ( m , " ClientConnection " , ( PyObject * ) & dcerpc_InterfaceType ) ;
2014-03-27 14:57:29 +01:00
Py_INCREF ( ( PyObject * ) ( void * ) & py_transfer_syntax_ndr_SyntaxType ) ;
PyModule_AddObject ( m , " transfer_syntax_ndr " , ( PyObject * ) ( void * ) & py_transfer_syntax_ndr_SyntaxType ) ;
Py_INCREF ( ( PyObject * ) ( void * ) & py_transfer_syntax_ndr64_SyntaxType ) ;
PyModule_AddObject ( m , " transfer_syntax_ndr64 " , ( PyObject * ) ( void * ) & py_transfer_syntax_ndr64_SyntaxType ) ;
2014-04-02 19:53:18 +02:00
Py_INCREF ( ( PyObject * ) ( void * ) & py_bind_time_features_syntax_SyntaxType ) ;
PyModule_AddObject ( m , " bind_time_features_syntax " , ( PyObject * ) ( void * ) & py_bind_time_features_syntax_SyntaxType ) ;
2018-11-29 12:41:34 +01:00
Py_INCREF ( ( PyObject * ) ( void * ) & py_dcerpc_ndr_pointer_type ) ;
PyModule_AddObject ( m , " ndr_pointer " , ( PyObject * ) ( void * ) & py_dcerpc_ndr_pointer_type ) ;
2017-02-15 09:19:33 +01:00
return m ;
2008-05-24 21:02:56 +02:00
}