2008-12-16 21:51:01 +01:00
/*
Unix SMB / CIFS implementation .
Samba utility functions
Copyright ( C ) Jelmer Vernooij < jelmer @ samba . org > 2008
2010-07-26 12:32:32 +02:00
Copyright ( C ) Wilco Baan Hofman < wilco @ baanhofman . nl > 2010
2008-12-16 21:51:01 +01: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 .
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 .
You should have received a copy of the GNU General Public License
along with this program . If not , see < http : //www.gnu.org/licenses/>.
*/
2023-11-09 11:35:56 +01:00
# include "lib/replace/system/python.h"
2017-10-11 12:46:11 +02:00
# include "python/py3compat.h"
2008-12-16 21:51:01 +01:00
# include "includes.h"
2019-05-02 19:45:14 +01:00
# include "python/modules.h"
2008-12-18 16:49:33 +00:00
# include "libcli/util/pyerrors.h"
# include "lib/registry/registry.h"
2011-08-14 15:34:08 +02:00
# include <pytalloc.h>
2010-08-23 12:07:19 +10:00
# include "lib/events/events.h"
2009-02-05 15:58:40 +01:00
# include "auth/credentials/pycredentials.h"
2008-12-22 04:38:57 +01:00
# include "param/pyparam.h"
2008-12-18 16:49:33 +00:00
2010-11-22 00:07:21 +01:00
extern PyTypeObject PyRegistryKey ;
extern PyTypeObject PyRegistry ;
extern PyTypeObject PyHiveKey ;
2008-12-16 21:51:01 +01:00
2011-08-10 15:15:18 +02:00
/*#define PyRegistryKey_AsRegistryKey(obj) pytalloc_get_type(obj, struct registry_key)*/
# define PyRegistry_AsRegistryContext(obj) ((struct registry_context *)pytalloc_get_ptr(obj))
# define PyHiveKey_AsHiveKey(obj) ((struct hive_key*)pytalloc_get_ptr(obj))
2009-02-06 12:10:23 +01:00
2009-02-05 15:58:40 +01:00
2008-12-16 21:51:01 +01:00
static PyObject * py_get_predefined_key_by_name ( PyObject * self , PyObject * args )
{
2008-12-18 16:49:33 +00:00
char * name ;
WERROR result ;
2009-02-05 15:58:40 +01:00
struct registry_context * ctx = PyRegistry_AsRegistryContext ( self ) ;
2008-12-18 16:49:33 +00:00
struct registry_key * key ;
if ( ! PyArg_ParseTuple ( args , " s " , & name ) )
return NULL ;
result = reg_get_predefined_key_by_name ( ctx , name , & key ) ;
2012-08-06 10:39:19 +02:00
PyErr_WERROR_NOT_OK_RAISE ( result ) ;
2008-12-18 16:49:33 +00:00
2011-08-10 15:15:18 +02:00
return pytalloc_steal ( & PyRegistryKey , key ) ;
2008-12-16 21:51:01 +01:00
}
static PyObject * py_key_del_abs ( PyObject * self , PyObject * args )
{
2008-12-18 16:49:33 +00:00
char * path ;
WERROR result ;
2009-02-05 15:58:40 +01:00
struct registry_context * ctx = PyRegistry_AsRegistryContext ( self ) ;
2008-12-18 16:49:33 +00:00
if ( ! PyArg_ParseTuple ( args , " s " , & path ) )
return NULL ;
2010-03-29 18:43:38 +02:00
result = reg_key_del_abs ( ctx , path ) ;
2012-08-06 10:39:19 +02:00
PyErr_WERROR_NOT_OK_RAISE ( result ) ;
2008-12-18 16:49:33 +00:00
2009-01-06 04:13:57 +01:00
Py_RETURN_NONE ;
2008-12-18 16:49:33 +00:00
}
static PyObject * py_get_predefined_key ( PyObject * self , PyObject * args )
{
uint32_t hkey ;
2009-02-05 15:58:40 +01:00
struct registry_context * ctx = PyRegistry_AsRegistryContext ( self ) ;
2008-12-18 16:49:33 +00:00
WERROR result ;
struct registry_key * key ;
if ( ! PyArg_ParseTuple ( args , " I " , & hkey ) )
return NULL ;
result = reg_get_predefined_key ( ctx , hkey , & key ) ;
2012-08-06 10:39:19 +02:00
PyErr_WERROR_NOT_OK_RAISE ( result ) ;
2008-12-18 16:49:33 +00:00
2011-08-10 15:15:18 +02:00
return pytalloc_steal ( & PyRegistryKey , key ) ;
2008-12-18 16:49:33 +00:00
}
static PyObject * py_diff_apply ( PyObject * self , PyObject * args )
{
char * filename ;
WERROR result ;
2009-02-05 15:58:40 +01:00
struct registry_context * ctx = PyRegistry_AsRegistryContext ( self ) ;
2008-12-18 16:49:33 +00:00
if ( ! PyArg_ParseTuple ( args , " s " , & filename ) )
return NULL ;
2010-05-09 17:20:01 +02:00
result = reg_diff_apply ( ctx , filename ) ;
2012-08-06 10:39:19 +02:00
PyErr_WERROR_NOT_OK_RAISE ( result ) ;
2008-12-18 16:49:33 +00:00
2009-01-06 04:13:57 +01:00
Py_RETURN_NONE ;
2008-12-18 16:49:33 +00:00
}
static PyObject * py_mount_hive ( PyObject * self , PyObject * args )
{
2009-02-05 15:58:40 +01:00
struct registry_context * ctx = PyRegistry_AsRegistryContext ( self ) ;
2008-12-18 16:49:33 +00:00
uint32_t hkey ;
PyObject * py_hivekey , * py_elements = Py_None ;
const char * * elements ;
WERROR result ;
if ( ! PyArg_ParseTuple ( args , " OI|O " , & py_hivekey , & hkey , & py_elements ) )
return NULL ;
if ( ! PyList_Check ( py_elements ) & & py_elements ! = Py_None ) {
PyErr_SetString ( PyExc_TypeError , " Expected list of elements " ) ;
return NULL ;
}
if ( py_elements = = Py_None ) {
elements = NULL ;
} else {
int i ;
elements = talloc_array ( NULL , const char * , PyList_Size ( py_elements ) ) ;
for ( i = 0 ; i < PyList_Size ( py_elements ) ; i + + )
2019-06-07 11:16:25 +02:00
elements [ i ] = PyUnicode_AsUTF8 ( PyList_GetItem ( py_elements , i ) ) ;
2008-12-18 16:49:33 +00:00
}
SMB_ASSERT ( ctx ! = NULL ) ;
2009-02-05 15:58:40 +01:00
result = reg_mount_hive ( ctx , PyHiveKey_AsHiveKey ( py_hivekey ) , hkey , elements ) ;
2012-08-06 10:39:19 +02:00
PyErr_WERROR_NOT_OK_RAISE ( result ) ;
2008-12-18 16:49:33 +00:00
2009-01-06 04:13:57 +01:00
Py_RETURN_NONE ;
2008-12-18 16:49:33 +00:00
}
static PyObject * registry_new ( PyTypeObject * type , PyObject * args , PyObject * kwargs )
{
WERROR result ;
struct registry_context * ctx ;
result = reg_open_local ( NULL , & ctx ) ;
2012-08-06 10:39:19 +02:00
PyErr_WERROR_NOT_OK_RAISE ( result ) ;
2011-08-10 15:15:18 +02:00
return pytalloc_steal ( & PyRegistry , ctx ) ;
2008-12-16 21:51:01 +01:00
}
static PyMethodDef registry_methods [ ] = {
{ " get_predefined_key_by_name " , py_get_predefined_key_by_name , METH_VARARGS ,
" S.get_predefined_key_by_name(name) -> key \n "
" Find a predefined key by name " } ,
{ " key_del_abs " , py_key_del_abs , METH_VARARGS , " S.key_del_abs(name) -> None \n "
" Delete a key by absolute path. " } ,
{ " get_predefined_key " , py_get_predefined_key , METH_VARARGS , " S.get_predefined_key(hkey_id) -> key \n "
" Find a predefined key by id " } ,
{ " diff_apply " , py_diff_apply , METH_VARARGS , " S.diff_apply(filename) -> None \n "
" Apply the diff from the specified file " } ,
{ " mount_hive " , py_mount_hive , METH_VARARGS , " S.mount_hive(key, key_id, elements=None) -> None \n "
" Mount the specified key at the specified path. " } ,
2020-05-05 13:47:39 +12:00
{ 0 }
2008-12-16 21:51:01 +01:00
} ;
PyTypeObject PyRegistry = {
. tp_name = " Registry " ,
. tp_methods = registry_methods ,
. tp_new = registry_new ,
2008-12-21 03:08:14 +01:00
. tp_flags = Py_TPFLAGS_DEFAULT ,
2008-12-16 21:51:01 +01:00
} ;
2008-12-18 16:49:33 +00:00
static PyObject * py_hive_key_del ( PyObject * self , PyObject * args )
{
char * name ;
2009-02-05 15:58:40 +01:00
struct hive_key * key = PyHiveKey_AsHiveKey ( self ) ;
2008-12-18 16:49:33 +00:00
WERROR result ;
if ( ! PyArg_ParseTuple ( args , " s " , & name ) )
return NULL ;
2010-03-22 19:18:56 +01:00
result = hive_key_del ( NULL , key , name ) ;
2008-12-18 16:49:33 +00:00
2012-08-06 10:39:19 +02:00
PyErr_WERROR_NOT_OK_RAISE ( result ) ;
2008-12-18 16:49:33 +00:00
2009-01-06 04:13:57 +01:00
Py_RETURN_NONE ;
2008-12-18 16:49:33 +00:00
}
2019-05-02 19:45:14 +01:00
static PyObject * py_hive_key_flush ( PyObject * self ,
PyObject * Py_UNUSED ( ignored ) )
2008-12-18 16:49:33 +00:00
{
WERROR result ;
2009-02-05 15:58:40 +01:00
struct hive_key * key = PyHiveKey_AsHiveKey ( self ) ;
2008-12-18 16:49:33 +00:00
result = hive_key_flush ( key ) ;
2012-08-06 10:39:19 +02:00
PyErr_WERROR_NOT_OK_RAISE ( result ) ;
2008-12-18 16:49:33 +00:00
2009-01-06 04:13:57 +01:00
Py_RETURN_NONE ;
2008-12-18 16:49:33 +00:00
}
static PyObject * py_hive_key_del_value ( PyObject * self , PyObject * args )
{
char * name ;
WERROR result ;
2009-02-05 15:58:40 +01:00
struct hive_key * key = PyHiveKey_AsHiveKey ( self ) ;
2008-12-18 16:49:33 +00:00
if ( ! PyArg_ParseTuple ( args , " s " , & name ) )
return NULL ;
2010-03-22 19:18:56 +01:00
result = hive_key_del_value ( NULL , key , name ) ;
2008-12-18 16:49:33 +00:00
2012-08-06 10:39:19 +02:00
PyErr_WERROR_NOT_OK_RAISE ( result ) ;
2008-12-18 16:49:33 +00:00
2009-01-06 04:13:57 +01:00
Py_RETURN_NONE ;
2008-12-18 16:49:33 +00:00
}
static PyObject * py_hive_key_set_value ( PyObject * self , PyObject * args )
{
char * name ;
uint32_t type ;
DATA_BLOB value ;
2016-01-04 13:06:31 +13:00
Py_ssize_t value_length = 0 ;
2008-12-18 16:49:33 +00:00
WERROR result ;
2009-02-05 15:58:40 +01:00
struct hive_key * key = PyHiveKey_AsHiveKey ( self ) ;
2008-12-18 16:49:33 +00:00
2019-02-07 17:36:02 +13:00
if ( ! PyArg_ParseTuple ( args , " sIz# " , & name , & type , & value . data , & value_length ) ) {
2008-12-18 16:49:33 +00:00
return NULL ;
2011-08-08 14:30:00 +02:00
}
value . length = value_length ;
2008-12-18 16:49:33 +00:00
if ( value . data ! = NULL )
result = hive_key_set_value ( key , name , type , value ) ;
else
2010-03-22 19:18:56 +01:00
result = hive_key_del_value ( NULL , key , name ) ;
2008-12-18 16:49:33 +00:00
2012-08-06 10:39:19 +02:00
PyErr_WERROR_NOT_OK_RAISE ( result ) ;
2008-12-18 16:49:33 +00:00
2009-01-06 04:13:57 +01:00
Py_RETURN_NONE ;
2008-12-18 16:49:33 +00:00
}
2008-12-16 21:51:01 +01:00
static PyMethodDef hive_key_methods [ ] = {
2008-12-18 16:49:33 +00:00
{ " del " , py_hive_key_del , METH_VARARGS , " S.del(name) -> None \n "
2008-12-16 21:51:01 +01:00
" Delete a subkey " } ,
2008-12-18 16:49:33 +00:00
{ " flush " , ( PyCFunction ) py_hive_key_flush , METH_NOARGS , " S.flush() -> None \n "
2008-12-16 21:51:01 +01:00
" Flush this key to disk " } ,
2008-12-18 16:49:33 +00:00
{ " del_value " , py_hive_key_del_value , METH_VARARGS , " S.del_value(name) -> None \n "
2008-12-16 21:51:01 +01:00
" Delete a value " } ,
2008-12-18 16:49:33 +00:00
{ " set_value " , py_hive_key_set_value , METH_VARARGS , " S.set_value(name, type, data) -> None \n "
2008-12-16 21:51:01 +01:00
" Set a value " } ,
2020-05-05 13:47:39 +12:00
{ 0 }
2008-12-16 21:51:01 +01:00
} ;
2010-07-26 12:32:32 +02:00
static PyObject * hive_new ( PyTypeObject * type , PyObject * args , PyObject * kwargs ) {
2009-01-06 04:13:57 +01:00
Py_RETURN_NONE ;
2008-12-16 21:51:01 +01:00
}
2010-07-26 12:32:32 +02:00
static PyObject * py_open_hive ( PyTypeObject * type , PyObject * args , PyObject * kwargs )
{
const char * kwnames [ ] = { " location " , " lp_ctx " , " session_info " , " credentials " , NULL } ;
WERROR result ;
struct loadparm_context * lp_ctx ;
2018-04-12 17:15:19 +12:00
PyObject * py_lp_ctx = Py_None ;
PyObject * py_session_info = Py_None ;
PyObject * py_credentials = Py_None ;
2010-07-26 12:32:32 +02:00
struct auth_session_info * session_info ;
struct cli_credentials * credentials ;
char * location ;
struct hive_key * hive_key ;
2010-09-22 16:44:17 -07:00
TALLOC_CTX * mem_ctx ;
2010-07-26 12:32:32 +02:00
if ( ! PyArg_ParseTupleAndKeywords ( args , kwargs , " s|OOO " ,
discard_const_p ( char * , kwnames ) ,
& location ,
& py_lp_ctx , & py_session_info ,
& py_credentials ) )
return NULL ;
2010-09-22 16:44:17 -07:00
mem_ctx = talloc_new ( NULL ) ;
if ( mem_ctx = = NULL ) {
PyErr_NoMemory ( ) ;
return NULL ;
}
lp_ctx = lpcfg_from_py_object ( mem_ctx , py_lp_ctx ) ;
2010-07-26 12:32:32 +02:00
if ( lp_ctx = = NULL ) {
PyErr_SetString ( PyExc_TypeError , " Expected loadparm context " ) ;
2010-09-22 16:44:17 -07:00
talloc_free ( mem_ctx ) ;
2010-07-26 12:32:32 +02:00
return NULL ;
}
credentials = cli_credentials_from_py_object ( py_credentials ) ;
if ( credentials = = NULL ) {
PyErr_SetString ( PyExc_TypeError , " Expected credentials " ) ;
2010-09-22 16:44:17 -07:00
talloc_free ( mem_ctx ) ;
2010-07-26 12:32:32 +02:00
return NULL ;
}
session_info = NULL ;
result = reg_open_hive ( NULL , location , session_info , credentials ,
2013-02-21 08:31:41 +01:00
samba_tevent_context_init ( NULL ) ,
2010-07-26 12:32:32 +02:00
lp_ctx , & hive_key ) ;
2010-09-22 16:44:17 -07:00
talloc_free ( mem_ctx ) ;
2012-08-06 10:39:19 +02:00
PyErr_WERROR_NOT_OK_RAISE ( result ) ;
2010-07-26 12:32:32 +02:00
2011-08-10 15:15:18 +02:00
return pytalloc_steal ( & PyHiveKey , hive_key ) ;
2010-07-26 12:32:32 +02:00
}
2008-12-16 21:51:01 +01:00
PyTypeObject PyHiveKey = {
. tp_name = " HiveKey " ,
. tp_methods = hive_key_methods ,
2010-07-26 12:32:32 +02:00
. tp_new = hive_new ,
2008-12-21 03:08:14 +01:00
. tp_flags = Py_TPFLAGS_DEFAULT ,
2008-12-18 16:49:33 +00:00
} ;
PyTypeObject PyRegistryKey = {
. tp_name = " RegistryKey " ,
2008-12-21 03:08:14 +01:00
. tp_flags = Py_TPFLAGS_DEFAULT ,
2008-12-16 21:51:01 +01:00
} ;
static PyObject * py_open_samba ( PyObject * self , PyObject * args , PyObject * kwargs )
{
2008-12-18 16:49:33 +00:00
const char * kwnames [ ] = { " lp_ctx " , " session_info " , NULL } ;
2008-12-16 21:51:01 +01:00
struct registry_context * reg_ctx ;
2008-12-18 16:49:33 +00:00
WERROR result ;
2010-04-07 14:33:09 +02:00
struct loadparm_context * lp_ctx ;
2018-04-12 17:15:19 +12:00
PyObject * py_lp_ctx = Py_None ;
PyObject * py_session_info = Py_None ;
PyObject * py_credentials = Py_None ;
2008-12-18 16:49:33 +00:00
struct auth_session_info * session_info ;
2010-04-07 14:33:09 +02:00
struct cli_credentials * credentials ;
2010-09-22 16:44:17 -07:00
TALLOC_CTX * mem_ctx ;
2010-04-07 14:33:09 +02:00
if ( ! PyArg_ParseTupleAndKeywords ( args , kwargs , " |OOO " ,
discard_const_p ( char * , kwnames ) ,
& py_lp_ctx , & py_session_info ,
& py_credentials ) )
2008-12-16 21:51:01 +01:00
return NULL ;
2010-09-22 16:44:17 -07:00
mem_ctx = talloc_new ( NULL ) ;
if ( mem_ctx = = NULL ) {
PyErr_NoMemory ( ) ;
return NULL ;
}
lp_ctx = lpcfg_from_py_object ( mem_ctx , py_lp_ctx ) ;
2010-04-07 14:33:09 +02:00
if ( lp_ctx = = NULL ) {
2008-12-18 16:49:33 +00:00
PyErr_SetString ( PyExc_TypeError , " Expected loadparm context " ) ;
2010-09-22 16:44:17 -07:00
talloc_free ( mem_ctx ) ;
2008-12-18 16:49:33 +00:00
return NULL ;
2010-04-07 14:33:09 +02:00
}
2008-12-18 16:49:33 +00:00
credentials = cli_credentials_from_py_object ( py_credentials ) ;
if ( credentials = = NULL ) {
PyErr_SetString ( PyExc_TypeError , " Expected credentials " ) ;
2010-09-22 16:44:17 -07:00
talloc_free ( mem_ctx ) ;
2008-12-18 16:49:33 +00:00
return NULL ;
}
2008-12-16 21:51:01 +01:00
2008-12-18 16:49:33 +00:00
session_info = NULL ; /* FIXME */
result = reg_open_samba ( NULL , & reg_ctx , NULL ,
2008-12-16 21:51:01 +01:00
lp_ctx , session_info , credentials ) ;
2010-09-22 16:44:17 -07:00
talloc_free ( mem_ctx ) ;
2008-12-16 21:51:01 +01:00
if ( ! W_ERROR_IS_OK ( result ) ) {
PyErr_SetWERROR ( result ) ;
return NULL ;
}
2010-12-01 00:03:08 +01:00
2011-08-10 15:15:18 +02:00
return pytalloc_steal ( & PyRegistry , reg_ctx ) ;
2008-12-18 16:49:33 +00:00
}
2008-12-16 21:51:01 +01:00
2008-12-18 16:49:33 +00:00
static PyObject * py_open_ldb_file ( PyObject * self , PyObject * args , PyObject * kwargs )
{
const char * kwnames [ ] = { " location " , " session_info " , " credentials " , " lp_ctx " , NULL } ;
PyObject * py_session_info = Py_None , * py_credentials = Py_None , * py_lp_ctx = Py_None ;
WERROR result ;
char * location ;
2010-04-07 14:33:09 +02:00
struct loadparm_context * lp_ctx ;
struct cli_credentials * credentials ;
2008-12-18 16:49:33 +00:00
struct hive_key * key ;
struct auth_session_info * session_info ;
2010-09-22 16:44:17 -07:00
TALLOC_CTX * mem_ctx ;
2008-12-18 16:49:33 +00:00
if ( ! PyArg_ParseTupleAndKeywords ( args , kwargs , " s|OOO " ,
2010-04-07 14:33:09 +02:00
discard_const_p ( char * , kwnames ) ,
& location , & py_session_info ,
& py_credentials , & py_lp_ctx ) )
2008-12-18 16:49:33 +00:00
return NULL ;
2010-09-22 16:44:17 -07:00
mem_ctx = talloc_new ( NULL ) ;
if ( mem_ctx = = NULL ) {
PyErr_NoMemory ( ) ;
return NULL ;
}
lp_ctx = lpcfg_from_py_object ( mem_ctx , py_lp_ctx ) ;
2010-04-07 14:33:09 +02:00
if ( lp_ctx = = NULL ) {
2008-12-18 16:49:33 +00:00
PyErr_SetString ( PyExc_TypeError , " Expected loadparm context " ) ;
2010-09-22 16:44:17 -07:00
talloc_free ( mem_ctx ) ;
2008-12-18 16:49:33 +00:00
return NULL ;
2010-04-07 14:33:09 +02:00
}
2008-12-18 16:49:33 +00:00
credentials = cli_credentials_from_py_object ( py_credentials ) ;
if ( credentials = = NULL ) {
PyErr_SetString ( PyExc_TypeError , " Expected credentials " ) ;
2010-09-22 16:44:17 -07:00
talloc_free ( mem_ctx ) ;
2008-12-18 16:49:33 +00:00
return NULL ;
}
session_info = NULL ; /* FIXME */
result = reg_open_ldb_file ( NULL , location , session_info , credentials ,
2010-08-23 12:07:19 +10:00
s4_event_context_init ( NULL ) , lp_ctx , & key ) ;
2010-09-22 16:44:17 -07:00
talloc_free ( mem_ctx ) ;
2012-08-06 10:39:19 +02:00
PyErr_WERROR_NOT_OK_RAISE ( result ) ;
2008-12-18 16:49:33 +00:00
2011-08-10 15:15:18 +02:00
return pytalloc_steal ( & PyHiveKey , key ) ;
2008-12-18 16:49:33 +00:00
}
static PyObject * py_str_regtype ( PyObject * self , PyObject * args )
{
int regtype ;
if ( ! PyArg_ParseTuple ( args , " i " , & regtype ) )
return NULL ;
2019-06-07 10:45:52 +02:00
return PyUnicode_FromString ( str_regtype ( regtype ) ) ;
2008-12-18 16:49:33 +00:00
}
static PyObject * py_get_predef_name ( PyObject * self , PyObject * args )
{
uint32_t hkey ;
const char * str ;
if ( ! PyArg_ParseTuple ( args , " I " , & hkey ) )
return NULL ;
str = reg_get_predef_name ( hkey ) ;
if ( str = = NULL )
2009-01-06 04:13:57 +01:00
Py_RETURN_NONE ;
2019-06-07 10:45:52 +02:00
return PyUnicode_FromString ( str ) ;
2008-12-16 21:51:01 +01:00
}
static PyMethodDef py_registry_methods [ ] = {
2019-05-02 19:45:14 +01:00
{ " open_samba " , PY_DISCARD_FUNC_SIG ( PyCFunction , py_open_samba ) ,
METH_VARARGS | METH_KEYWORDS , " open_samba() -> reg " } ,
{ " open_ldb " , PY_DISCARD_FUNC_SIG ( PyCFunction , py_open_ldb_file ) ,
METH_VARARGS | METH_KEYWORDS , " open_ldb(location, session_info=None, credentials=None, loadparm_context=None) -> key " } ,
{ " open_hive " , PY_DISCARD_FUNC_SIG ( PyCFunction , py_open_hive ) ,
METH_VARARGS | METH_KEYWORDS , " open_hive(location, session_info=None, credentials=None, loadparm_context=None) -> key " } ,
2008-12-16 21:51:01 +01:00
{ " str_regtype " , py_str_regtype , METH_VARARGS , " str_regtype(int) -> str " } ,
{ " get_predef_name " , py_get_predef_name , METH_VARARGS , " get_predef_name(hkey) -> str " } ,
2020-05-05 13:47:39 +12:00
{ 0 }
2008-12-16 21:51:01 +01:00
} ;
2017-10-11 12:46:11 +02:00
static struct PyModuleDef moduledef = {
PyModuleDef_HEAD_INIT ,
. m_name = " registry " ,
. m_doc = " Registry " ,
. m_size = - 1 ,
. m_methods = py_registry_methods ,
} ;
MODULE_INIT_FUNC ( registry )
2008-12-16 21:51:01 +01:00
{
2008-12-18 16:49:33 +00:00
PyObject * m ;
2010-12-01 00:03:08 +01:00
2016-03-01 09:33:48 +13:00
if ( pytalloc_BaseObject_PyType_Ready ( & PyHiveKey ) < 0 )
2017-10-11 12:46:11 +02:00
return NULL ;
2010-12-01 00:03:08 +01:00
2016-03-01 09:33:48 +13:00
if ( pytalloc_BaseObject_PyType_Ready ( & PyRegistry ) < 0 )
2017-10-11 12:46:11 +02:00
return NULL ;
2008-12-18 16:49:33 +00:00
2016-03-01 09:33:48 +13:00
if ( pytalloc_BaseObject_PyType_Ready ( & PyRegistryKey ) < 0 )
2017-10-11 12:46:11 +02:00
return NULL ;
2008-12-18 16:49:33 +00:00
2017-10-11 12:46:11 +02:00
m = PyModule_Create ( & moduledef ) ;
2008-12-16 21:51:01 +01:00
if ( m = = NULL )
2017-10-11 12:46:11 +02:00
return NULL ;
2008-12-16 21:51:01 +01:00
2020-03-15 10:36:59 +13:00
PyModule_AddObject ( m , " HKEY_CLASSES_ROOT " , PyLong_FromLong ( HKEY_CLASSES_ROOT ) ) ;
PyModule_AddObject ( m , " HKEY_CURRENT_USER " , PyLong_FromLong ( HKEY_CURRENT_USER ) ) ;
PyModule_AddObject ( m , " HKEY_LOCAL_MACHINE " , PyLong_FromLong ( HKEY_LOCAL_MACHINE ) ) ;
PyModule_AddObject ( m , " HKEY_USERS " , PyLong_FromLong ( HKEY_USERS ) ) ;
PyModule_AddObject ( m , " HKEY_PERFORMANCE_DATA " , PyLong_FromLong ( HKEY_PERFORMANCE_DATA ) ) ;
PyModule_AddObject ( m , " HKEY_CURRENT_CONFIG " , PyLong_FromLong ( HKEY_CURRENT_CONFIG ) ) ;
PyModule_AddObject ( m , " HKEY_DYN_DATA " , PyLong_FromLong ( HKEY_DYN_DATA ) ) ;
PyModule_AddObject ( m , " HKEY_PERFORMANCE_TEXT " , PyLong_FromLong ( HKEY_PERFORMANCE_TEXT ) ) ;
PyModule_AddObject ( m , " HKEY_PERFORMANCE_NLSTEXT " , PyLong_FromLong ( HKEY_PERFORMANCE_NLSTEXT ) ) ;
2008-12-18 16:49:33 +00:00
Py_INCREF ( & PyRegistry ) ;
PyModule_AddObject ( m , " Registry " , ( PyObject * ) & PyRegistry ) ;
Py_INCREF ( & PyHiveKey ) ;
PyModule_AddObject ( m , " HiveKey " , ( PyObject * ) & PyHiveKey ) ;
Py_INCREF ( & PyRegistryKey ) ;
PyModule_AddObject ( m , " RegistryKey " , ( PyObject * ) & PyRegistryKey ) ;
2017-10-11 12:46:11 +02:00
return m ;
2008-12-16 21:51:01 +01:00
}