2014-01-31 04:27:05 +04:00
/*
Unix SMB / CIFS implementation .
Copyright ( C ) Luke Morrison < luc785 @ hotmail . com > 2013
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/>.
*/
# include <Python.h>
# include "includes.h"
# include "version.h"
# include "param/pyparam.h"
# include "gpo.h"
# include "ads.h"
2017-05-10 22:30:17 +03:00
# include "secrets.h"
# include "../libds/common/flags.h"
2017-10-24 06:40:02 +03:00
# include "librpc/rpc/pyrpc_util.h"
2017-05-10 22:30:17 +03:00
# include "auth/credentials/pycredentials.h"
2017-10-24 05:58:45 +03:00
# include "libcli/util/pyerrors.h"
2018-01-30 22:31:42 +03:00
# include "python/py3compat.h"
2019-05-02 21:47:29 +03:00
# include "python/modules.h"
2014-01-31 04:27:05 +04:00
/* A Python C API module to use LIBGPO */
2017-05-10 22:30:17 +03:00
# define GPO_getter(ATTR) \
2017-10-24 06:48:13 +03:00
static PyObject * GPO_get_ # # ATTR ( PyObject * self , void * closure ) \
2017-05-10 22:30:17 +03:00
{ \
2017-10-24 06:48:13 +03:00
struct GROUP_POLICY_OBJECT * gpo_ptr \
= pytalloc_get_ptr ( self ) ; \
\
if ( gpo_ptr - > ATTR ) \
2019-06-07 11:45:52 +03:00
return PyUnicode_FromString ( gpo_ptr - > ATTR ) ; \
2017-05-10 22:30:17 +03:00
else \
return Py_None ; \
}
GPO_getter ( ds_path )
GPO_getter ( file_sys_path )
GPO_getter ( display_name )
GPO_getter ( name )
GPO_getter ( link )
GPO_getter ( user_extensions )
GPO_getter ( machine_extensions )
static PyGetSetDef GPO_setters [ ] = {
2017-11-20 00:28:33 +03:00
{ discard_const_p ( char , " ds_path " ) , ( getter ) GPO_get_ds_path , NULL , NULL ,
NULL } ,
{ discard_const_p ( char , " file_sys_path " ) , ( getter ) GPO_get_file_sys_path ,
NULL , NULL , NULL } ,
2017-11-22 01:00:56 +03:00
{ discard_const_p ( char , " display_name " ) , ( getter ) GPO_get_display_name ,
NULL , NULL , NULL } ,
{ discard_const_p ( char , " name " ) , ( getter ) GPO_get_name , NULL , NULL ,
NULL } ,
{ discard_const_p ( char , " link " ) , ( getter ) GPO_get_link , NULL , NULL ,
NULL } ,
{ discard_const_p ( char , " user_extensions " ) ,
( getter ) GPO_get_user_extensions ,
2017-11-20 00:28:33 +03:00
NULL , NULL , NULL } ,
{ discard_const_p ( char , " machine_extensions " ) ,
( getter ) GPO_get_machine_extensions , NULL , NULL , NULL } ,
2017-05-10 22:30:17 +03:00
{ NULL }
} ;
2017-10-24 06:48:13 +03:00
static PyObject * py_gpo_get_unix_path ( PyObject * self , PyObject * args ,
PyObject * kwds )
2017-05-10 22:30:17 +03:00
{
NTSTATUS status ;
const char * cache_dir = NULL ;
2019-02-27 19:03:16 +03:00
PyObject * ret = NULL ;
2017-05-10 22:30:17 +03:00
char * unix_path = NULL ;
2017-10-24 07:24:38 +03:00
TALLOC_CTX * frame = NULL ;
2017-05-10 22:30:17 +03:00
static const char * kwlist [ ] = { " cache_dir " , NULL } ;
2017-10-24 06:48:13 +03:00
struct GROUP_POLICY_OBJECT * gpo_ptr \
= ( struct GROUP_POLICY_OBJECT * ) pytalloc_get_ptr ( self ) ;
2018-08-17 11:11:03 +03:00
frame = talloc_stackframe ( ) ;
2017-11-20 00:28:33 +03:00
if ( ! PyArg_ParseTupleAndKeywords ( args , kwds , " |s " ,
discard_const_p ( char * , kwlist ) ,
& cache_dir ) ) {
2017-05-10 22:30:17 +03:00
goto out ;
}
if ( ! cache_dir ) {
2018-08-16 11:51:44 +03:00
cache_dir = cache_path ( talloc_tos ( ) , GPO_CACHE_DIR ) ;
2017-05-10 22:30:17 +03:00
if ( ! cache_dir ) {
2017-11-20 00:28:33 +03:00
PyErr_SetString ( PyExc_MemoryError ,
" Failed to determine gpo cache dir " ) ;
2017-05-10 22:30:17 +03:00
goto out ;
}
}
2017-10-24 06:48:13 +03:00
status = gpo_get_unix_path ( frame , cache_dir , gpo_ptr , & unix_path ) ;
2017-10-24 07:24:38 +03:00
2017-05-10 22:30:17 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2019-02-27 19:03:16 +03:00
PyErr_Format ( PyExc_RuntimeError ,
" Failed to determine gpo unix path: %s " ,
get_friendly_nt_error_msg ( status ) ) ;
2017-05-10 22:30:17 +03:00
goto out ;
}
2019-06-07 11:45:52 +03:00
ret = PyUnicode_FromString ( unix_path ) ;
2017-05-10 22:30:17 +03:00
out :
2018-08-17 11:11:03 +03:00
TALLOC_FREE ( frame ) ;
2017-05-10 22:30:17 +03:00
return ret ;
}
static PyMethodDef GPO_methods [ ] = {
2019-05-02 21:47:29 +03:00
{ " get_unix_path " , PY_DISCARD_FUNC_SIG ( PyCFunction ,
py_gpo_get_unix_path ) ,
METH_KEYWORDS ,
2017-11-22 01:00:56 +03:00
NULL } ,
2017-05-10 22:30:17 +03:00
{ NULL }
} ;
static PyTypeObject GPOType = {
2017-10-24 06:48:13 +03:00
PyVarObject_HEAD_INIT ( NULL , 0 )
2017-05-10 22:30:17 +03:00
. tp_name = " gpo.GROUP_POLICY_OBJECT " ,
. tp_doc = " GROUP_POLICY_OBJECT " ,
. tp_getset = GPO_setters ,
. tp_methods = GPO_methods ,
2017-10-24 06:48:13 +03:00
. tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE ,
2017-05-10 22:30:17 +03:00
} ;
typedef struct {
PyObject_HEAD
ADS_STRUCT * ads_ptr ;
2019-02-27 19:36:32 +03:00
PyObject * py_creds ;
2017-05-10 22:30:17 +03:00
struct cli_credentials * cli_creds ;
} ADS ;
static void py_ads_dealloc ( ADS * self )
{
ads_destroy ( & ( self - > ads_ptr ) ) ;
2019-02-27 19:36:32 +03:00
Py_CLEAR ( self - > py_creds ) ;
2017-05-10 22:30:17 +03:00
Py_TYPE ( self ) - > tp_free ( ( PyObject * ) self ) ;
}
2019-05-02 21:47:29 +03:00
static PyObject * py_ads_connect ( ADS * self , PyObject * Py_UNUSED ( ignored ) ) ;
2017-05-10 22:30:17 +03:00
static int py_ads_init ( ADS * self , PyObject * args , PyObject * kwds )
{
const char * realm = NULL ;
const char * workgroup = NULL ;
const char * ldap_server = NULL ;
PyObject * lp_obj = NULL ;
2019-02-28 14:34:47 +03:00
PyObject * py_creds = NULL ;
2017-05-10 22:30:17 +03:00
struct loadparm_context * lp_ctx = NULL ;
2019-02-27 19:32:14 +03:00
bool ok = false ;
2017-05-10 22:30:17 +03:00
2017-11-22 01:00:56 +03:00
static const char * kwlist [ ] = {
" ldap_server " , " loadparm_context " , " credentials " , NULL
} ;
2017-11-20 00:28:33 +03:00
if ( ! PyArg_ParseTupleAndKeywords ( args , kwds , " sO|O " ,
discard_const_p ( char * , kwlist ) ,
2019-02-28 14:34:47 +03:00
& ldap_server , & lp_obj , & py_creds ) ) {
2017-05-10 22:30:17 +03:00
return - 1 ;
2017-11-22 01:00:35 +03:00
}
2019-02-28 14:34:47 +03:00
/* keep reference to the credentials. Clear any earlier ones */
Py_CLEAR ( self - > py_creds ) ;
self - > cli_creds = NULL ;
self - > py_creds = py_creds ;
2019-02-27 19:36:32 +03:00
Py_XINCREF ( self - > py_creds ) ;
2017-05-10 22:30:17 +03:00
2019-02-27 19:36:32 +03:00
if ( self - > py_creds ) {
ok = py_check_dcerpc_type ( self - > py_creds , " samba.credentials " ,
2019-02-27 19:32:14 +03:00
" Credentials " ) ;
if ( ! ok ) {
2017-10-24 06:40:02 +03:00
return - 1 ;
}
self - > cli_creds
2019-02-27 19:36:32 +03:00
= PyCredentials_AsCliCredentials ( self - > py_creds ) ;
2017-10-24 06:40:02 +03:00
}
2017-05-10 22:30:17 +03:00
2019-02-27 19:32:14 +03:00
ok = py_check_dcerpc_type ( lp_obj , " samba.param " , " LoadParm " ) ;
if ( ! ok ) {
return - 1 ;
}
lp_ctx = pytalloc_get_type ( lp_obj , struct loadparm_context ) ;
if ( lp_ctx = = NULL ) {
return - 1 ;
}
ok = lp_load_initial_only ( lp_ctx - > szConfigFile ) ;
if ( ! ok ) {
PyErr_Format ( PyExc_RuntimeError , " Could not load config file '%s' " ,
lp_ctx - > szConfigFile ) ;
return - 1 ;
2017-05-10 22:30:17 +03:00
}
if ( self - > cli_creds ) {
realm = cli_credentials_get_realm ( self - > cli_creds ) ;
workgroup = cli_credentials_get_domain ( self - > cli_creds ) ;
} else {
realm = lp_realm ( ) ;
workgroup = lp_workgroup ( ) ;
}
2019-02-28 14:34:47 +03:00
/* in case __init__ is called more than once */
if ( self - > ads_ptr ) {
ads_destroy ( & self - > ads_ptr ) ;
self - > ads_ptr = NULL ;
}
2019-02-27 19:32:14 +03:00
/* always succeeds or crashes */
2019-08-13 18:41:40 +03:00
self - > ads_ptr = ads_init ( realm , workgroup , ldap_server , ADS_SASL_PLAIN ) ;
2019-02-27 19:32:14 +03:00
2017-05-10 22:30:17 +03:00
return 0 ;
}
2019-02-27 17:12:43 +03:00
/* connect. Failure to connect results in an Exception */
2019-05-02 21:47:29 +03:00
static PyObject * py_ads_connect ( ADS * self ,
PyObject * Py_UNUSED ( ignored ) )
2017-05-10 22:30:17 +03:00
{
ADS_STATUS status ;
2017-11-07 20:41:05 +03:00
TALLOC_CTX * frame = talloc_stackframe ( ) ;
2019-02-28 14:34:47 +03:00
if ( ! self - > ads_ptr ) {
PyErr_SetString ( PyExc_RuntimeError , " Uninitialized " ) ;
return NULL ;
}
SAFE_FREE ( self - > ads_ptr - > auth . user_name ) ;
SAFE_FREE ( self - > ads_ptr - > auth . password ) ;
SAFE_FREE ( self - > ads_ptr - > auth . realm ) ;
2017-05-10 22:30:17 +03:00
if ( self - > cli_creds ) {
2017-11-20 00:28:33 +03:00
self - > ads_ptr - > auth . user_name =
SMB_STRDUP ( cli_credentials_get_username ( self - > cli_creds ) ) ;
self - > ads_ptr - > auth . password =
SMB_STRDUP ( cli_credentials_get_password ( self - > cli_creds ) ) ;
self - > ads_ptr - > auth . realm =
SMB_STRDUP ( cli_credentials_get_realm ( self - > cli_creds ) ) ;
2019-02-28 14:34:47 +03:00
self - > ads_ptr - > auth . flags | = ADS_AUTH_USER_CREDS ;
2017-05-10 22:30:17 +03:00
status = ads_connect_user_creds ( self - > ads_ptr ) ;
} else {
2017-11-22 01:00:35 +03:00
char * passwd = NULL ;
2019-02-28 14:34:47 +03:00
int ret ;
2017-05-10 22:30:17 +03:00
if ( ! secrets_init ( ) ) {
2019-02-27 16:36:03 +03:00
PyErr_SetString ( PyExc_RuntimeError ,
2017-11-22 01:00:35 +03:00
" secrets_init() failed " ) ;
2019-02-27 17:12:43 +03:00
goto err ;
2017-05-10 22:30:17 +03:00
}
2017-11-22 01:00:35 +03:00
passwd = secrets_fetch_machine_password ( self - > ads_ptr - > server . workgroup ,
NULL , NULL ) ;
if ( passwd = = NULL ) {
2019-02-27 16:36:03 +03:00
PyErr_SetString ( PyExc_RuntimeError ,
2017-11-22 01:00:56 +03:00
" Failed to fetch the machine account "
" password " ) ;
2019-02-27 17:12:43 +03:00
goto err ;
2017-05-10 22:30:17 +03:00
}
2019-02-28 14:34:47 +03:00
ret = asprintf ( & ( self - > ads_ptr - > auth . user_name ) , " %s$ " ,
lp_netbios_name ( ) ) ;
if ( ret = = - 1 ) {
2019-02-28 18:15:14 +03:00
SAFE_FREE ( passwd ) ;
2019-02-28 14:34:47 +03:00
PyErr_NoMemory ( ) ;
goto err ;
}
2019-02-28 18:15:14 +03:00
self - > ads_ptr - > auth . password = passwd ; /* take ownership of this data */
2017-11-22 01:00:56 +03:00
self - > ads_ptr - > auth . realm =
2019-02-28 18:15:14 +03:00
SMB_STRDUP ( self - > ads_ptr - > server . realm ) ;
2017-05-10 22:30:17 +03:00
if ( ! strupper_m ( self - > ads_ptr - > auth . realm ) ) {
2019-02-27 17:12:43 +03:00
PyErr_SetString ( PyExc_RuntimeError , " Failed to strupper " ) ;
goto err ;
2017-05-10 22:30:17 +03:00
}
2019-02-28 14:34:47 +03:00
self - > ads_ptr - > auth . flags | = ADS_AUTH_USER_CREDS ;
2017-05-10 22:30:17 +03:00
status = ads_connect ( self - > ads_ptr ) ;
2019-02-28 14:34:47 +03:00
}
if ( ! ADS_ERR_OK ( status ) ) {
PyErr_Format ( PyExc_RuntimeError ,
" ads_connect() failed: %s " ,
ads_errstr ( status ) ) ;
goto err ;
2017-05-10 22:30:17 +03:00
}
2017-11-07 20:41:05 +03:00
TALLOC_FREE ( frame ) ;
2017-05-10 22:30:17 +03:00
Py_RETURN_TRUE ;
2019-02-27 17:12:43 +03:00
err :
TALLOC_FREE ( frame ) ;
return NULL ;
2017-05-10 22:30:17 +03:00
}
2014-01-31 04:27:05 +04:00
/* Parameter mapping and functions for the GP_EXT struct */
void initgpo ( void ) ;
/* Global methods aka do not need a special pyobject type */
2017-11-20 00:28:33 +03:00
static PyObject * py_gpo_get_sysvol_gpt_version ( PyObject * self ,
PyObject * args )
2014-01-31 04:27:05 +04:00
{
TALLOC_CTX * tmp_ctx = NULL ;
char * unix_path ;
char * display_name = NULL ;
uint32_t sysvol_version = 0 ;
PyObject * result ;
2017-10-24 05:58:45 +03:00
NTSTATUS status ;
2014-01-31 04:27:05 +04:00
if ( ! PyArg_ParseTuple ( args , " s " , & unix_path ) ) {
return NULL ;
}
2019-02-27 19:32:14 +03:00
tmp_ctx = talloc_new ( NULL ) ;
if ( ! tmp_ctx ) {
return PyErr_NoMemory ( ) ;
}
2017-10-24 05:58:45 +03:00
status = gpo_get_sysvol_gpt_version ( tmp_ctx , unix_path ,
& sysvol_version ,
& display_name ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
PyErr_SetNTSTATUS ( status ) ;
TALLOC_FREE ( tmp_ctx ) ;
return NULL ;
}
2014-01-31 04:27:05 +04:00
result = Py_BuildValue ( " [s,i] " , display_name , sysvol_version ) ;
2019-02-27 19:32:14 +03:00
talloc_free ( tmp_ctx ) ;
2014-01-31 04:27:05 +04:00
return result ;
}
2018-02-03 09:07:55 +03:00
# ifdef HAVE_ADS
2017-11-20 00:28:33 +03:00
static ADS_STATUS find_samaccount ( ADS_STRUCT * ads , TALLOC_CTX * mem_ctx ,
const char * samaccountname ,
uint32_t * uac_ret , const char * * dn_ret )
2017-05-10 22:30:17 +03:00
{
ADS_STATUS status ;
const char * attrs [ ] = { " userAccountControl " , NULL } ;
const char * filter ;
LDAPMessage * res = NULL ;
char * dn = NULL ;
uint32_t uac = 0 ;
2017-11-22 01:00:56 +03:00
filter = talloc_asprintf ( mem_ctx , " (sAMAccountName=%s) " ,
samaccountname ) ;
2017-05-10 22:30:17 +03:00
if ( filter = = NULL ) {
status = ADS_ERROR_NT ( NT_STATUS_NO_MEMORY ) ;
goto out ;
}
2017-11-22 01:00:56 +03:00
status = ads_do_search_all ( ads , ads - > config . bind_path ,
LDAP_SCOPE_SUBTREE , filter , attrs , & res ) ;
2017-05-10 22:30:17 +03:00
if ( ! ADS_ERR_OK ( status ) ) {
goto out ;
}
if ( ads_count_replies ( ads , res ) ! = 1 ) {
status = ADS_ERROR ( LDAP_NO_RESULTS_RETURNED ) ;
goto out ;
}
dn = ads_get_dn ( ads , talloc_tos ( ) , res ) ;
if ( dn = = NULL ) {
status = ADS_ERROR ( LDAP_NO_MEMORY ) ;
goto out ;
}
if ( ! ads_pull_uint32 ( ads , res , " userAccountControl " , & uac ) ) {
status = ADS_ERROR ( LDAP_NO_SUCH_ATTRIBUTE ) ;
goto out ;
}
if ( uac_ret ) {
* uac_ret = uac ;
}
if ( dn_ret ) {
* dn_ret = talloc_strdup ( mem_ctx , dn ) ;
2017-11-22 01:00:35 +03:00
if ( * dn_ret = = NULL ) {
2017-05-10 22:30:17 +03:00
status = ADS_ERROR ( LDAP_NO_MEMORY ) ;
goto out ;
}
}
out :
TALLOC_FREE ( dn ) ;
ads_msgfree ( ads , res ) ;
return status ;
}
static PyObject * py_ads_get_gpo_list ( ADS * self , PyObject * args , PyObject * kwds )
{
2017-10-24 07:24:38 +03:00
TALLOC_CTX * frame = NULL ;
2017-10-24 06:48:13 +03:00
struct GROUP_POLICY_OBJECT * gpo = NULL , * gpo_list = NULL ;
2017-05-10 22:30:17 +03:00
ADS_STATUS status ;
const char * samaccountname = NULL ;
const char * dn = NULL ;
uint32_t uac = 0 ;
uint32_t flags = 0 ;
struct security_token * token = NULL ;
2019-02-27 19:32:14 +03:00
PyObject * ret = NULL ;
TALLOC_CTX * gpo_ctx = NULL ;
2017-10-24 06:48:13 +03:00
size_t list_size ;
size_t i ;
2017-05-10 22:30:17 +03:00
static const char * kwlist [ ] = { " samaccountname " , NULL } ;
2017-11-20 00:28:33 +03:00
if ( ! PyArg_ParseTupleAndKeywords ( args , kwds , " s " ,
discard_const_p ( char * , kwlist ) ,
& samaccountname ) ) {
2019-02-27 19:32:14 +03:00
return NULL ;
2017-05-10 22:30:17 +03:00
}
2019-02-28 14:34:47 +03:00
if ( ! self - > ads_ptr ) {
PyErr_SetString ( PyExc_RuntimeError , " Uninitialized " ) ;
return NULL ;
}
2017-05-10 22:30:17 +03:00
2017-10-24 07:24:38 +03:00
frame = talloc_stackframe ( ) ;
2017-05-10 22:30:17 +03:00
2017-11-22 01:00:56 +03:00
status = find_samaccount ( self - > ads_ptr , frame ,
samaccountname , & uac , & dn ) ;
2017-05-10 22:30:17 +03:00
if ( ! ADS_ERR_OK ( status ) ) {
2019-02-27 19:32:14 +03:00
PyErr_Format ( PyExc_RuntimeError ,
" Failed to find samAccountName '%s': %s " ,
samaccountname , ads_errstr ( status ) ) ;
2017-05-10 22:30:17 +03:00
goto out ;
}
2017-11-22 01:00:56 +03:00
if ( uac & UF_WORKSTATION_TRUST_ACCOUNT | |
uac & UF_SERVER_TRUST_ACCOUNT ) {
2017-05-10 22:30:17 +03:00
flags | = GPO_LIST_FLAG_MACHINE ;
2017-11-22 01:00:56 +03:00
status = gp_get_machine_token ( self - > ads_ptr , frame , dn ,
& token ) ;
2019-02-27 19:32:14 +03:00
if ( ! ADS_ERR_OK ( status ) ) {
PyErr_Format ( PyExc_RuntimeError ,
" Failed to get machine token for '%s'(%s): %s " ,
samaccountname , dn , ads_errstr ( status ) ) ;
goto out ;
}
2017-05-10 22:30:17 +03:00
} else {
2017-10-24 07:24:38 +03:00
status = ads_get_sid_token ( self - > ads_ptr , frame , dn , & token ) ;
2019-02-27 19:32:14 +03:00
if ( ! ADS_ERR_OK ( status ) ) {
PyErr_Format ( PyExc_RuntimeError ,
" Failed to get sid token for '%s'(%s): %s " ,
samaccountname , dn , ads_errstr ( status ) ) ;
goto out ;
}
2017-05-10 22:30:17 +03:00
}
2017-10-24 06:48:13 +03:00
gpo_ctx = talloc_new ( frame ) ;
2019-02-27 19:32:14 +03:00
if ( ! gpo_ctx ) {
PyErr_NoMemory ( ) ;
goto out ;
}
2017-11-20 00:28:33 +03:00
status = ads_get_gpo_list ( self - > ads_ptr , gpo_ctx , dn , flags , token ,
& gpo_list ) ;
2017-05-10 22:30:17 +03:00
if ( ! ADS_ERR_OK ( status ) ) {
2019-02-27 19:32:14 +03:00
PyErr_Format ( PyExc_RuntimeError ,
" Failed to fetch GPO list: %s " ,
ads_errstr ( status ) ) ;
2017-05-10 22:30:17 +03:00
goto out ;
}
2017-10-24 06:48:13 +03:00
/* Convert the C linked list into a python list */
list_size = 0 ;
for ( gpo = gpo_list ; gpo ! = NULL ; gpo = gpo - > next ) {
list_size + + ;
}
i = 0 ;
ret = PyList_New ( list_size ) ;
if ( ret = = NULL ) {
goto out ;
}
for ( gpo = gpo_list ; gpo ! = NULL ; gpo = gpo - > next ) {
PyObject * obj = pytalloc_reference_ex ( & GPOType ,
gpo_ctx , gpo ) ;
if ( obj = = NULL ) {
2019-02-27 19:32:14 +03:00
Py_CLEAR ( ret ) ;
2017-10-24 06:48:13 +03:00
goto out ;
}
PyList_SetItem ( ret , i , obj ) ;
i + + ;
}
2017-05-10 22:30:17 +03:00
out :
2019-02-27 19:32:14 +03:00
TALLOC_FREE ( gpo_ctx ) ;
2017-10-24 07:24:38 +03:00
TALLOC_FREE ( frame ) ;
2017-05-10 22:30:17 +03:00
return ret ;
}
2018-02-03 09:07:55 +03:00
# endif
2017-05-10 22:30:17 +03:00
static PyMethodDef ADS_methods [ ] = {
2017-11-20 00:28:33 +03:00
{ " connect " , ( PyCFunction ) py_ads_connect , METH_NOARGS ,
" Connect to the LDAP server " } ,
2018-02-03 09:07:55 +03:00
# ifdef HAVE_ADS
2019-05-02 21:47:29 +03:00
{ " get_gpo_list " , PY_DISCARD_FUNC_SIG ( PyCFunction , py_ads_get_gpo_list ) ,
METH_VARARGS | METH_KEYWORDS ,
2017-11-22 01:00:56 +03:00
NULL } ,
2018-02-03 09:07:55 +03:00
# endif
2017-05-10 22:30:17 +03:00
{ NULL }
} ;
static PyTypeObject ads_ADSType = {
. tp_name = " gpo.ADS_STRUCT " ,
. tp_basicsize = sizeof ( ADS ) ,
. tp_dealloc = ( destructor ) py_ads_dealloc ,
. tp_flags = Py_TPFLAGS_DEFAULT ,
. tp_doc = " ADS struct " ,
. tp_methods = ADS_methods ,
. tp_init = ( initproc ) py_ads_init ,
} ;
2014-01-31 04:27:05 +04:00
static PyMethodDef py_gpo_methods [ ] = {
2017-11-22 01:00:56 +03:00
{ " gpo_get_sysvol_gpt_version " ,
( PyCFunction ) py_gpo_get_sysvol_gpt_version ,
2017-11-20 00:28:33 +03:00
METH_VARARGS , NULL } ,
2014-01-31 04:27:05 +04:00
{ NULL }
} ;
2018-01-30 22:31:42 +03:00
static struct PyModuleDef moduledef = {
PyModuleDef_HEAD_INIT ,
. m_name = " gpo " ,
. m_doc = " libgpo python bindings " ,
. m_size = - 1 ,
. m_methods = py_gpo_methods ,
} ;
2014-01-31 04:27:05 +04:00
/* Will be called by python when loading this module */
2018-01-30 22:31:42 +03:00
void initgpo ( void ) ;
MODULE_INIT_FUNC ( gpo )
2014-01-31 04:27:05 +04:00
{
PyObject * m ;
debug_setup_talloc_log ( ) ;
2017-11-22 01:00:35 +03:00
2014-01-31 04:27:05 +04:00
/* Instantiate the types */
2018-01-30 22:31:42 +03:00
m = PyModule_Create ( & moduledef ) ;
2017-11-22 01:00:35 +03:00
if ( m = = NULL ) {
2019-02-27 19:48:39 +03:00
goto err ;
2017-11-22 01:00:35 +03:00
}
2019-02-27 19:48:39 +03:00
if ( PyModule_AddObject ( m , " version " ,
2019-06-07 11:45:52 +03:00
PyUnicode_FromString ( SAMBA_VERSION_STRING ) ) ) {
2019-02-27 19:48:39 +03:00
goto err ;
}
2017-10-24 06:48:13 +03:00
2019-02-27 19:48:39 +03:00
ads_ADSType . tp_new = PyType_GenericNew ;
2017-11-22 01:00:35 +03:00
if ( PyType_Ready ( & ads_ADSType ) < 0 ) {
2019-02-27 19:48:39 +03:00
goto err ;
2017-11-22 01:00:35 +03:00
}
2019-02-27 19:48:39 +03:00
Py_INCREF ( & ads_ADSType ) ;
if ( PyModule_AddObject ( m , " ADS_STRUCT " , ( PyObject * ) & ads_ADSType ) ) {
goto err ;
}
2017-10-24 06:48:13 +03:00
2017-11-22 01:00:35 +03:00
if ( pytalloc_BaseObject_PyType_Ready ( & GPOType ) < 0 ) {
2019-02-27 19:48:39 +03:00
goto err ;
2017-11-22 01:00:35 +03:00
}
2017-10-24 06:48:13 +03:00
Py_INCREF ( ( PyObject * ) ( void * ) & GPOType ) ;
2019-02-27 19:48:39 +03:00
if ( PyModule_AddObject ( m , " GROUP_POLICY_OBJECT " ,
( PyObject * ) & GPOType ) ) {
goto err ;
}
2018-01-30 22:31:42 +03:00
return m ;
2017-10-24 06:48:13 +03:00
2019-02-27 19:48:39 +03:00
err :
Py_CLEAR ( m ) ;
return NULL ;
2014-01-31 04:27:05 +04:00
}