2002-05-13 11:27:20 +04:00
/*
Python wrappers for DCERPC / SMB client routines .
Copyright ( C ) Tim Potter , 2002
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 2 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 , write to the Free Software
Foundation , Inc . , 675 Mass Ave , Cambridge , MA 0213 9 , USA .
*/
# include "python/py_spoolss.h"
2003-02-20 01:47:49 +03:00
# include "python/py_conv.h"
2002-05-13 11:27:20 +04:00
2002-09-02 11:47:42 +04:00
static BOOL py_from_printerdata ( PyObject * * dict , char * key , char * value ,
2002-09-03 09:00:17 +04:00
uint16 data_type , uint8 * data ,
2002-05-13 11:27:20 +04:00
uint32 data_size )
{
* dict = PyDict_New ( ) ;
2002-09-02 11:47:42 +04:00
PyDict_SetItemString ( * dict , " key " , Py_BuildValue ( " s " , key ? key : " " ) ) ;
2002-05-13 11:27:20 +04:00
PyDict_SetItemString ( * dict , " value " , Py_BuildValue ( " s " , value ) ) ;
2002-09-02 11:47:42 +04:00
PyDict_SetItemString ( * dict , " type " , Py_BuildValue ( " i " , data_type ) ) ;
2002-05-13 11:27:20 +04:00
PyDict_SetItemString ( * dict , " data " ,
Py_BuildValue ( " s# " , data , data_size ) ) ;
return True ;
}
2002-09-03 09:00:17 +04:00
static BOOL py_to_printerdata ( char * * key , char * * value , uint16 * data_type ,
uint8 * * data , uint32 * data_size ,
2002-05-13 11:27:20 +04:00
PyObject * dict )
{
PyObject * obj ;
2002-09-02 11:47:42 +04:00
if ( ( obj = PyDict_GetItemString ( dict , " key " ) ) ) {
2002-05-13 11:27:20 +04:00
2002-09-02 11:47:42 +04:00
if ( ! PyString_Check ( obj ) ) {
2002-05-13 11:27:20 +04:00
PyErr_SetString ( spoolss_error ,
2002-09-02 11:47:42 +04:00
" key not a string " ) ;
2002-05-13 11:27:20 +04:00
return False ;
}
2002-09-03 09:00:17 +04:00
if ( key ) {
* key = PyString_AsString ( obj ) ;
2002-09-02 11:47:42 +04:00
2002-09-03 09:00:17 +04:00
if ( ! key [ 0 ] )
* key = NULL ;
}
2002-09-02 11:47:42 +04:00
} else
* key = NULL ;
2002-05-13 11:27:20 +04:00
if ( ( obj = PyDict_GetItemString ( dict , " value " ) ) ) {
if ( ! PyString_Check ( obj ) ) {
PyErr_SetString ( spoolss_error ,
" value not a string " ) ;
return False ;
}
* value = PyString_AsString ( obj ) ;
} else {
PyErr_SetString ( spoolss_error , " no value present " ) ;
return False ;
}
2002-09-02 11:47:42 +04:00
if ( ( obj = PyDict_GetItemString ( dict , " type " ) ) ) {
if ( ! PyInt_Check ( obj ) ) {
PyErr_SetString ( spoolss_error ,
" type not an integer " ) ;
return False ;
}
* data_type = PyInt_AsLong ( obj ) ;
} else {
PyErr_SetString ( spoolss_error , " no type present " ) ;
return False ;
}
2002-05-13 11:27:20 +04:00
if ( ( obj = PyDict_GetItemString ( dict , " data " ) ) ) {
if ( ! PyString_Check ( obj ) ) {
PyErr_SetString ( spoolss_error ,
" data not a string " ) ;
return False ;
}
* data = PyString_AsString ( obj ) ;
* data_size = PyString_Size ( obj ) ;
} else {
PyErr_SetString ( spoolss_error , " no data present " ) ;
return False ;
}
return True ;
}
2002-05-15 10:22:53 +04:00
PyObject * spoolss_hnd_getprinterdata ( PyObject * self , PyObject * args , PyObject * kw )
2002-05-13 11:27:20 +04:00
{
spoolss_policy_hnd_object * hnd = ( spoolss_policy_hnd_object * ) self ;
static char * kwlist [ ] = { " value " , NULL } ;
2002-09-03 09:00:17 +04:00
char * valuename ;
2002-05-13 11:27:20 +04:00
WERROR werror ;
PyObject * result ;
2002-09-03 09:00:17 +04:00
REGISTRY_VALUE value ;
2002-05-13 11:27:20 +04:00
/* Parse parameters */
2002-09-03 09:00:17 +04:00
if ( ! PyArg_ParseTupleAndKeywords ( args , kw , " s " , kwlist , & valuename ) )
2002-05-16 08:00:31 +04:00
return NULL ;
2002-05-13 11:27:20 +04:00
/* Call rpc function */
2005-10-07 08:54:41 +04:00
werror = rpccli_spoolss_getprinterdata (
2005-07-20 19:35:29 +04:00
hnd - > cli , hnd - > mem_ctx , & hnd - > pol , valuename ,
2002-09-03 09:00:17 +04:00
& value ) ;
2002-05-13 11:27:20 +04:00
if ( ! W_ERROR_IS_OK ( werror ) ) {
PyErr_SetObject ( spoolss_werror , py_werror_tuple ( werror ) ) ;
return NULL ;
}
2002-09-03 09:00:17 +04:00
py_from_printerdata (
& result , NULL , valuename , value . type , value . data_p ,
value . size ) ;
2002-05-13 11:27:20 +04:00
return result ;
}
2002-05-15 10:22:53 +04:00
PyObject * spoolss_hnd_setprinterdata ( PyObject * self , PyObject * args , PyObject * kw )
2002-05-13 11:27:20 +04:00
{
spoolss_policy_hnd_object * hnd = ( spoolss_policy_hnd_object * ) self ;
static char * kwlist [ ] = { " data " , NULL } ;
PyObject * py_data ;
2002-09-03 09:00:17 +04:00
char * valuename ;
2002-05-13 11:27:20 +04:00
WERROR werror ;
2002-09-03 09:00:17 +04:00
REGISTRY_VALUE value ;
2002-05-13 11:27:20 +04:00
2002-05-16 08:00:31 +04:00
if ( ! PyArg_ParseTupleAndKeywords (
args , kw , " O! " , kwlist , & PyDict_Type , & py_data ) )
2002-05-13 11:27:20 +04:00
return NULL ;
2002-09-03 09:00:17 +04:00
if ( ! py_to_printerdata (
NULL , & valuename , & value . type , & value . data_p ,
& value . size , py_data ) )
2002-05-13 11:27:20 +04:00
return NULL ;
2002-09-03 09:00:17 +04:00
fstrcpy ( value . valuename , valuename ) ;
2002-05-13 11:27:20 +04:00
/* Call rpc function */
2005-10-07 08:54:41 +04:00
werror = rpccli_spoolss_setprinterdata (
2002-09-03 09:00:17 +04:00
hnd - > cli , hnd - > mem_ctx , & hnd - > pol , & value ) ;
2002-05-13 11:27:20 +04:00
if ( ! W_ERROR_IS_OK ( werror ) ) {
PyErr_SetObject ( spoolss_werror , py_werror_tuple ( werror ) ) ;
return NULL ;
}
Py_INCREF ( Py_None ) ;
return Py_None ;
}
2002-05-15 10:22:53 +04:00
PyObject * spoolss_hnd_enumprinterdata ( PyObject * self , PyObject * args , PyObject * kw )
2002-05-13 11:27:20 +04:00
{
2002-05-14 09:01:04 +04:00
spoolss_policy_hnd_object * hnd = ( spoolss_policy_hnd_object * ) self ;
static char * kwlist [ ] = { NULL } ;
2002-09-03 09:00:17 +04:00
uint32 data_needed , value_needed , ndx = 0 ;
2002-05-14 09:01:04 +04:00
WERROR werror ;
PyObject * result ;
2002-09-03 09:00:17 +04:00
REGISTRY_VALUE value ;
2002-05-14 09:01:04 +04:00
if ( ! PyArg_ParseTupleAndKeywords ( args , kw , " " , kwlist ) )
return NULL ;
/* Get max buffer sizes for value and data */
2005-10-07 08:54:41 +04:00
werror = rpccli_spoolss_enumprinterdata (
2002-05-14 09:01:04 +04:00
hnd - > cli , hnd - > mem_ctx , & hnd - > pol , ndx , 0 , 0 ,
2002-09-03 09:00:17 +04:00
& value_needed , & data_needed , NULL ) ;
2002-05-14 09:01:04 +04:00
if ( ! W_ERROR_IS_OK ( werror ) ) {
PyErr_SetObject ( spoolss_werror , py_werror_tuple ( werror ) ) ;
return NULL ;
}
/* Iterate over all printerdata */
result = PyDict_New ( ) ;
while ( W_ERROR_IS_OK ( werror ) ) {
PyObject * obj ;
2005-10-07 08:54:41 +04:00
werror = rpccli_spoolss_enumprinterdata (
2002-05-14 09:01:04 +04:00
hnd - > cli , hnd - > mem_ctx , & hnd - > pol , ndx ,
2002-09-03 09:00:17 +04:00
value_needed , data_needed , NULL , NULL , & value ) ;
2002-05-14 09:01:04 +04:00
2002-09-02 11:47:42 +04:00
if ( py_from_printerdata (
2002-09-03 09:00:17 +04:00
& obj , NULL , value . valuename , value . type ,
value . data_p , value . size ) )
PyDict_SetItemString ( result , value . valuename , obj ) ;
2002-05-14 09:01:04 +04:00
ndx + + ;
}
return result ;
2002-05-13 11:27:20 +04:00
}
2002-05-14 11:13:25 +04:00
2002-05-15 10:22:53 +04:00
PyObject * spoolss_hnd_deleteprinterdata ( PyObject * self , PyObject * args , PyObject * kw )
2002-05-14 11:13:25 +04:00
{
spoolss_policy_hnd_object * hnd = ( spoolss_policy_hnd_object * ) self ;
static char * kwlist [ ] = { " value " , NULL } ;
char * value ;
WERROR werror ;
/* Parse parameters */
if ( ! PyArg_ParseTupleAndKeywords ( args , kw , " s " , kwlist , & value ) )
2002-05-16 08:00:31 +04:00
return NULL ;
2002-05-14 11:13:25 +04:00
/* Call rpc function */
2005-10-07 08:54:41 +04:00
werror = rpccli_spoolss_deleteprinterdata (
2002-05-14 11:13:25 +04:00
hnd - > cli , hnd - > mem_ctx , & hnd - > pol , value ) ;
if ( ! W_ERROR_IS_OK ( werror ) ) {
PyErr_SetObject ( spoolss_werror , py_werror_tuple ( werror ) ) ;
return NULL ;
}
Py_INCREF ( Py_None ) ;
return Py_None ;
}
2002-09-02 11:47:42 +04:00
PyObject * spoolss_hnd_getprinterdataex ( PyObject * self , PyObject * args , PyObject * kw )
{
spoolss_policy_hnd_object * hnd = ( spoolss_policy_hnd_object * ) self ;
static char * kwlist [ ] = { " key " , " value " , NULL } ;
2002-09-03 09:00:17 +04:00
char * key , * valuename ;
2002-09-02 11:47:42 +04:00
WERROR werror ;
PyObject * result ;
2002-09-03 09:00:17 +04:00
REGISTRY_VALUE value ;
2002-09-02 11:47:42 +04:00
/* Parse parameters */
2002-09-03 09:00:17 +04:00
if ( ! PyArg_ParseTupleAndKeywords ( args , kw , " ss " , kwlist , & key , & valuename ) )
2002-09-02 11:47:42 +04:00
return NULL ;
/* Call rpc function */
2005-10-07 08:54:41 +04:00
werror = rpccli_spoolss_getprinterdataex (
2005-07-20 19:35:29 +04:00
hnd - > cli , hnd - > mem_ctx , & hnd - > pol , key ,
2002-09-03 09:00:17 +04:00
valuename , & value ) ;
2002-09-02 11:47:42 +04:00
if ( ! W_ERROR_IS_OK ( werror ) ) {
PyErr_SetObject ( spoolss_werror , py_werror_tuple ( werror ) ) ;
return NULL ;
}
2002-09-03 09:00:17 +04:00
py_from_printerdata (
& result , key , valuename , value . type , value . data_p , value . size ) ;
2002-09-02 11:47:42 +04:00
return result ;
}
PyObject * spoolss_hnd_setprinterdataex ( PyObject * self , PyObject * args , PyObject * kw )
2002-05-14 11:13:25 +04:00
{
2002-09-02 11:47:42 +04:00
spoolss_policy_hnd_object * hnd = ( spoolss_policy_hnd_object * ) self ;
static char * kwlist [ ] = { " data " , NULL } ;
PyObject * py_data ;
2002-09-03 09:00:17 +04:00
char * keyname , * valuename ;
2002-09-02 11:47:42 +04:00
WERROR werror ;
2002-09-03 09:00:17 +04:00
REGISTRY_VALUE value ;
2002-09-02 11:47:42 +04:00
if ( ! PyArg_ParseTupleAndKeywords (
args , kw , " O! " , kwlist , & PyDict_Type , & py_data ) )
return NULL ;
2002-09-03 09:00:17 +04:00
if ( ! py_to_printerdata (
& keyname , & valuename , & value . type , & value . data_p , & value . size , py_data ) )
2002-09-02 11:47:42 +04:00
return NULL ;
2002-05-15 10:05:00 +04:00
2002-09-03 09:00:17 +04:00
fstrcpy ( value . valuename , valuename ) ;
2002-09-02 11:47:42 +04:00
/* Call rpc function */
2005-10-07 08:54:41 +04:00
werror = rpccli_spoolss_setprinterdataex (
2002-09-03 09:00:17 +04:00
hnd - > cli , hnd - > mem_ctx , & hnd - > pol , keyname , & value ) ;
2002-09-02 11:47:42 +04:00
if ( ! W_ERROR_IS_OK ( werror ) ) {
PyErr_SetObject ( spoolss_werror , py_werror_tuple ( werror ) ) ;
return NULL ;
}
Py_INCREF ( Py_None ) ;
return Py_None ;
}
PyObject * spoolss_hnd_enumprinterdataex ( PyObject * self , PyObject * args , PyObject * kw )
{
spoolss_policy_hnd_object * hnd = ( spoolss_policy_hnd_object * ) self ;
2002-09-19 09:29:14 +04:00
static char * kwlist [ ] = { " key " , NULL } ;
2005-07-20 19:35:29 +04:00
uint32 i ;
2002-09-03 04:40:06 +04:00
char * key ;
2002-09-02 11:47:42 +04:00
WERROR werror ;
PyObject * result ;
2006-04-28 00:52:04 +04:00
REGVAL_CTR * ctr ;
2002-09-02 11:47:42 +04:00
if ( ! PyArg_ParseTupleAndKeywords ( args , kw , " s " , kwlist , & key ) )
return NULL ;
2006-04-28 00:52:04 +04:00
if ( ! ( ctr = TALLOC_ZERO_P ( hnd - > mem_ctx , REGVAL_CTR ) ) ) {
2006-05-02 02:31:33 +04:00
PyErr_SetString ( spoolss_error , " talloc failed " ) ;
2006-04-28 00:52:04 +04:00
return NULL ;
}
2002-09-02 11:47:42 +04:00
/* Get max buffer sizes for value and data */
2005-10-07 08:54:41 +04:00
werror = rpccli_spoolss_enumprinterdataex (
hnd - > cli , hnd - > mem_ctx , & hnd - > pol , key , & ctr ) ;
2002-09-02 11:47:42 +04:00
if ( ! W_ERROR_IS_OK ( werror ) ) {
PyErr_SetObject ( spoolss_werror , py_werror_tuple ( werror ) ) ;
return NULL ;
}
/* Iterate over all printerdata */
result = PyDict_New ( ) ;
2002-09-03 09:00:17 +04:00
for ( i = 0 ; i < regval_ctr_numvals ( & ctr ) ; i + + ) {
REGISTRY_VALUE * value ;
2002-09-03 04:40:06 +04:00
PyObject * item ;
2002-09-02 11:47:42 +04:00
2002-09-03 04:40:06 +04:00
item = PyDict_New ( ) ;
2002-09-03 09:00:17 +04:00
value = regval_ctr_specific_value ( & ctr , i ) ;
2002-09-03 04:40:06 +04:00
2002-09-03 09:00:17 +04:00
if ( py_from_printerdata (
& item , key , value - > valuename , value - > type ,
value - > data_p , value - > size ) )
PyDict_SetItemString ( result , value - > valuename , item ) ;
2002-09-03 04:40:06 +04:00
}
2002-09-02 11:47:42 +04:00
return result ;
}
PyObject * spoolss_hnd_deleteprinterdataex ( PyObject * self , PyObject * args , PyObject * kw )
{
2002-09-03 05:10:21 +04:00
spoolss_policy_hnd_object * hnd = ( spoolss_policy_hnd_object * ) self ;
static char * kwlist [ ] = { " key " , " value " , NULL } ;
char * key , * value ;
WERROR werror ;
/* Parse parameters */
if ( ! PyArg_ParseTupleAndKeywords ( args , kw , " ss " , kwlist , & key , & value ) )
return NULL ;
/* Call rpc function */
2005-10-07 08:54:41 +04:00
werror = rpccli_spoolss_deleteprinterdataex (
2002-09-03 05:10:21 +04:00
hnd - > cli , hnd - > mem_ctx , & hnd - > pol , key , value ) ;
if ( ! W_ERROR_IS_OK ( werror ) ) {
PyErr_SetObject ( spoolss_werror , py_werror_tuple ( werror ) ) ;
return NULL ;
}
Py_INCREF ( Py_None ) ;
return Py_None ;
2002-05-14 11:13:25 +04:00
}
2002-11-07 04:12:24 +03:00
PyObject * spoolss_hnd_enumprinterkey ( PyObject * self , PyObject * args ,
PyObject * kw )
{
spoolss_policy_hnd_object * hnd = ( spoolss_policy_hnd_object * ) self ;
static char * kwlist [ ] = { " key " , NULL } ;
char * keyname ;
WERROR werror ;
2005-07-20 19:35:29 +04:00
uint32 keylist_len ;
2002-11-07 04:12:24 +03:00
uint16 * keylist ;
PyObject * result ;
/* Parse parameters */
if ( ! PyArg_ParseTupleAndKeywords ( args , kw , " s " , kwlist , & keyname ) )
return NULL ;
/* Call rpc function */
2005-10-07 08:54:41 +04:00
werror = rpccli_spoolss_enumprinterkey (
hnd - > cli , hnd - > mem_ctx , & hnd - > pol , keyname , & keylist ,
& keylist_len ) ;
2002-11-07 04:12:24 +03:00
if ( ! W_ERROR_IS_OK ( werror ) ) {
PyErr_SetObject ( spoolss_werror , py_werror_tuple ( werror ) ) ;
return NULL ;
}
result = from_unistr_list ( keylist ) ;
return result ;
}
#if 0
PyObject * spoolss_hnd_deleteprinterkey ( PyObject * self , PyObject * args ,
PyObject * kw )
{
spoolss_policy_hnd_object * hnd = ( spoolss_policy_hnd_object * ) self ;
static char * kwlist [ ] = { " key " , NULL } ;
char * keyname ;
WERROR werror ;
if ( ! PyArg_ParseTupleAndKeywords ( args , kw , " s " , kwlist , & keyname ) )
return NULL ;
Py_INCREF ( Py_None ) ;
return Py_None ;
}
# endif