1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-12 09:18:10 +03:00

This commit was manufactured by cvs2svn to create branch 'SAMBA_3_0'.(This used to be commit 1c221b3e72)

This commit is contained in:
cvs2svn Import User 2002-04-12 03:54:14 +00:00
commit ef3197889f
22 changed files with 201 additions and 4909 deletions

View File

@ -1,231 +0,0 @@
#ifndef _RPC_CLIENT_PROTO_H_
#define _RPC_CLIENT_PROTO_H_
/* This file is automatically generated with "make proto". DO NOT EDIT */
/*The following definitions come from lib/util_list.c */
BOOL copy_policy_hnd (POLICY_HND *dest, const POLICY_HND *src);
BOOL compare_rpc_hnd_node(const RPC_HND_NODE *x,
const RPC_HND_NODE *y);
BOOL RpcHndList_set_connection(const POLICY_HND *hnd,
struct cli_connection *con);
BOOL RpcHndList_del_connection(const POLICY_HND *hnd);
struct cli_connection* RpcHndList_get_connection(const POLICY_HND *hnd);
/*The following definitions come from rpc_client/cli_connect.c */
void init_connections(void);
void free_connections(void);
void cli_connection_free(struct cli_connection *con);
void cli_connection_unlink(struct cli_connection *con);
BOOL cli_connection_init(const char *srv_name, char *pipe_name,
struct cli_connection **con);
BOOL cli_connection_init_auth(const char *srv_name, char *pipe_name,
struct cli_connection **con,
cli_auth_fns * auth, void *auth_creds);
struct _cli_auth_fns *cli_conn_get_authfns(struct cli_connection *con);
void *cli_conn_get_auth_creds(struct cli_connection *con);
BOOL rpc_hnd_pipe_req(const POLICY_HND * hnd, uint8 op_num,
prs_struct * data, prs_struct * rdata);
BOOL rpc_con_pipe_req(struct cli_connection *con, uint8 op_num,
prs_struct * data, prs_struct * rdata);
BOOL rpc_con_ok(struct cli_connection *con);
/*The following definitions come from rpc_client/cli_login.c */
BOOL cli_nt_setup_creds(struct cli_state *cli, unsigned char mach_pwd[16]);
BOOL cli_nt_srv_pwset(struct cli_state *cli, unsigned char *new_hashof_mach_pwd);
BOOL cli_nt_login_interactive(struct cli_state *cli, char *domain, char *username,
uint32 smb_userid_low, char *password,
NET_ID_INFO_CTR *ctr, NET_USER_INFO_3 *user_info3);
BOOL cli_nt_login_network(struct cli_state *cli, char *domain, char *username,
uint32 smb_userid_low, char lm_chal[8],
char *lm_chal_resp, char *nt_chal_resp,
NET_ID_INFO_CTR *ctr, NET_USER_INFO_3 *user_info3);
BOOL cli_nt_logoff(struct cli_state *cli, NET_ID_INFO_CTR *ctr);
/*The following definitions come from rpc_client/cli_lsarpc.c */
BOOL do_lsa_open_policy(struct cli_state *cli,
char *system_name, POLICY_HND *hnd,
BOOL sec_qos);
BOOL do_lsa_query_info_pol(struct cli_state *cli,
POLICY_HND *hnd, uint16 info_class,
fstring domain_name, DOM_SID *domain_sid);
BOOL do_lsa_close(struct cli_state *cli, POLICY_HND *hnd);
BOOL cli_lsa_get_domain_sid(struct cli_state *cli, char *server);
uint32 lsa_open_policy(const char *system_name, POLICY_HND *hnd,
BOOL sec_qos, uint32 des_access);
uint32 lsa_lookup_sids(POLICY_HND *hnd, int num_sids, DOM_SID *sids,
char ***names, uint32 **types, int *num_names);
uint32 lsa_lookup_names(POLICY_HND *hnd, int num_names, char **names,
DOM_SID **sids, uint32 **types, int *num_sids);
/*The following definitions come from rpc_client/cli_netlogon.c */
BOOL cli_net_logon_ctrl2(struct cli_state *cli, uint32 status_level);
BOOL cli_net_auth2(struct cli_state *cli, uint16 sec_chan,
uint32 neg_flags, DOM_CHAL *srv_chal);
BOOL cli_net_req_chal(struct cli_state *cli, DOM_CHAL *clnt_chal, DOM_CHAL *srv_chal);
BOOL cli_net_srv_pwset(struct cli_state *cli, uint8 hashed_mach_pwd[16]);
BOOL cli_net_sam_logon(struct cli_state *cli, NET_ID_INFO_CTR *ctr, NET_USER_INFO_3 *user_info3);
BOOL cli_net_sam_logoff(struct cli_state *cli, NET_ID_INFO_CTR *ctr);
BOOL change_trust_account_password( char *domain, char *remote_machine_list);
/*The following definitions come from rpc_client/cli_pipe.c */
BOOL rpc_api_pipe_req(struct cli_state *cli, uint8 op_num,
prs_struct *data, prs_struct *rdata);
BOOL rpc_pipe_bind(struct cli_state *cli, char *pipe_name, char *my_name);
void cli_nt_set_ntlmssp_flgs(struct cli_state *cli, uint32 ntlmssp_flgs);
BOOL cli_nt_session_open(struct cli_state *cli, char *pipe_name);
void cli_nt_session_close(struct cli_state *cli);
/*The following definitions come from rpc_client/cli_reg.c */
BOOL do_reg_connect(struct cli_state *cli, char *full_keyname, char *key_name,
POLICY_HND *reg_hnd);
BOOL do_reg_open_hklm(struct cli_state *cli, uint16 unknown_0, uint32 level,
POLICY_HND *hnd);
BOOL do_reg_open_hku(struct cli_state *cli, uint16 unknown_0, uint32 level,
POLICY_HND *hnd);
BOOL do_reg_flush_key(struct cli_state *cli, POLICY_HND *hnd);
BOOL do_reg_query_key(struct cli_state *cli, POLICY_HND *hnd,
char *class, uint32 *class_len,
uint32 *num_subkeys, uint32 *max_subkeylen,
uint32 *max_subkeysize, uint32 *num_values,
uint32 *max_valnamelen, uint32 *max_valbufsize,
uint32 *sec_desc, NTTIME *mod_time);
BOOL do_reg_unknown_1a(struct cli_state *cli, POLICY_HND *hnd, uint32 *unk);
BOOL do_reg_query_info(struct cli_state *cli, POLICY_HND *hnd,
char *key_value, uint32* key_type);
BOOL do_reg_set_key_sec(struct cli_state *cli, POLICY_HND *hnd, SEC_DESC_BUF *sec_desc_buf);
BOOL do_reg_get_key_sec(struct cli_state *cli, POLICY_HND *hnd, uint32 *sec_buf_size, SEC_DESC_BUF **ppsec_desc_buf);
BOOL do_reg_delete_val(struct cli_state *cli, POLICY_HND *hnd, char *val_name);
BOOL do_reg_delete_key(struct cli_state *cli, POLICY_HND *hnd, char *key_name);
BOOL do_reg_create_key(struct cli_state *cli, POLICY_HND *hnd,
char *key_name, char *key_class,
SEC_ACCESS *sam_access,
POLICY_HND *key);
BOOL do_reg_enum_key(struct cli_state *cli, POLICY_HND *hnd,
int key_index, char *key_name,
uint32 *unk_1, uint32 *unk_2,
time_t *mod_time);
BOOL do_reg_create_val(struct cli_state *cli, POLICY_HND *hnd,
char *val_name, uint32 type, BUFFER3 *data);
BOOL do_reg_enum_val(struct cli_state *cli, POLICY_HND *hnd,
int val_index, int max_valnamelen, int max_valbufsize,
fstring val_name,
uint32 *val_type, BUFFER2 *value);
BOOL do_reg_open_entry(struct cli_state *cli, POLICY_HND *hnd,
char *key_name, uint32 unk_0,
POLICY_HND *key_hnd);
BOOL do_reg_close(struct cli_state *cli, POLICY_HND *hnd);
/*The following definitions come from rpc_client/cli_samr.c */
BOOL get_samr_query_usergroups(struct cli_state *cli,
POLICY_HND *pol_open_domain, uint32 user_rid,
uint32 *num_groups, DOM_GID *gid);
BOOL get_samr_query_userinfo(struct cli_state *cli,
POLICY_HND *pol_open_domain,
uint32 info_level,
uint32 user_rid, SAM_USER_INFO_21 *usr);
BOOL do_samr_chgpasswd_user(struct cli_state *cli,
char *srv_name, char *user_name,
char nt_newpass[516], uchar nt_oldhash[16],
char lm_newpass[516], uchar lm_oldhash[16]);
BOOL do_samr_unknown_38(struct cli_state *cli, char *srv_name);
BOOL do_samr_query_dom_info(struct cli_state *cli,
POLICY_HND *domain_pol, uint16 switch_value);
BOOL do_samr_enum_dom_users(struct cli_state *cli,
POLICY_HND *pol, uint16 num_entries, uint16 unk_0,
uint16 acb_mask, uint16 unk_1, uint32 size,
struct acct_info **sam,
int *num_sam_users);
BOOL do_samr_connect(struct cli_state *cli,
char *srv_name, uint32 unknown_0,
POLICY_HND *connect_pol);
BOOL do_samr_open_user(struct cli_state *cli,
POLICY_HND *pol, uint32 unk_0, uint32 rid,
POLICY_HND *user_pol);
BOOL do_samr_open_domain(struct cli_state *cli,
POLICY_HND *connect_pol, uint32 rid, DOM_SID *sid,
POLICY_HND *domain_pol);
BOOL do_samr_query_unknown_12(struct cli_state *cli,
POLICY_HND *pol, uint32 rid, uint32 num_gids, uint32 *gids,
uint32 *num_aliases,
fstring als_names [MAX_LOOKUP_SIDS],
uint32 num_als_users[MAX_LOOKUP_SIDS]);
BOOL do_samr_query_usergroups(struct cli_state *cli,
POLICY_HND *pol, uint32 *num_groups, DOM_GID *gid);
BOOL do_samr_query_userinfo(struct cli_state *cli,
POLICY_HND *pol, uint16 switch_value, void* usr);
BOOL do_samr_close(struct cli_state *cli, POLICY_HND *hnd);
/*The following definitions come from rpc_client/cli_spoolss_notify.c */
BOOL spoolss_disconnect_from_client( struct cli_state *cli);
BOOL spoolss_connect_to_client( struct cli_state *cli, char *remote_machine);
BOOL cli_spoolss_reply_open_printer(struct cli_state *cli, char *printer, uint32 localprinter, uint32 type, uint32 *status, POLICY_HND *handle);
BOOL cli_spoolss_reply_rrpcn(struct cli_state *cli, POLICY_HND *handle,
uint32 change_low, uint32 change_high, uint32 *status);
BOOL cli_spoolss_reply_close_printer(struct cli_state *cli, POLICY_HND *handle, uint32 *status);
/*The following definitions come from rpc_client/cli_srvsvc.c */
BOOL do_srv_net_srv_conn_enum(struct cli_state *cli,
char *server_name, char *qual_name,
uint32 switch_value, SRV_CONN_INFO_CTR *ctr,
uint32 preferred_len,
ENUM_HND *hnd);
BOOL do_srv_net_srv_sess_enum(struct cli_state *cli,
char *server_name, char *qual_name,
uint32 switch_value, SRV_SESS_INFO_CTR *ctr,
uint32 preferred_len,
ENUM_HND *hnd);
BOOL do_srv_net_srv_share_enum(struct cli_state *cli,
char *server_name,
uint32 switch_value, SRV_R_NET_SHARE_ENUM *r_o,
uint32 preferred_len, ENUM_HND *hnd);
BOOL do_srv_net_srv_file_enum(struct cli_state *cli,
char *server_name, char *qual_name,
uint32 switch_value, SRV_FILE_INFO_CTR *ctr,
uint32 preferred_len,
ENUM_HND *hnd);
BOOL do_srv_net_srv_get_info(struct cli_state *cli,
char *server_name, uint32 switch_value, SRV_INFO_CTR *ctr);
/*The following definitions come from rpc_client/cli_use.c */
void init_cli_use(void);
void free_cli_use(void);
struct cli_state *cli_net_use_add(const char *srv_name,
const struct ntuser_creds *usr_creds,
BOOL reuse, BOOL *is_new);
BOOL cli_net_use_del(const char *srv_name,
const struct ntuser_creds *usr_creds,
BOOL force_close, BOOL *connection_closed);
void cli_net_use_enum(uint32 *num_cons, struct use_info ***use);
void cli_use_wait_keyboard(void);
/*The following definitions come from rpc_client/cli_wkssvc.c */
BOOL do_wks_query_info(struct cli_state *cli,
char *server_name, uint32 switch_value,
WKS_INFO_100 *wks100);
/*The following definitions come from rpc_client/ncacn_np_use.c */
BOOL ncacn_np_use_del(const char *srv_name, const char *pipe_name,
const vuser_key * key,
BOOL force_close, BOOL *connection_closed);
struct ncacn_np *ncacn_np_initialise(struct ncacn_np *msrpc,
const vuser_key * key);
struct ncacn_np *ncacn_np_use_add(const char *pipe_name,
const vuser_key * key,
const char *srv_name,
const struct ntuser_creds *ntc,
BOOL reuse, BOOL *is_new_connection);
#endif /* _PROTO_H_ */

File diff suppressed because it is too large Load Diff

View File

@ -1 +0,0 @@
setup.py

View File

@ -1,117 +0,0 @@
/*
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 02139, USA.
*/
#include "includes.h"
#include "Python.h"
/* Return a tuple of (error code, error string) from a WERROR */
PyObject *py_werror_tuple(WERROR werror)
{
return Py_BuildValue("is", W_ERROR_V(werror),
dos_errstr(werror));
}
/* Return a tuple of (error code, error string) from a WERROR */
PyObject *py_ntstatus_tuple(NTSTATUS ntstatus)
{
return Py_BuildValue("is", NT_STATUS_V(ntstatus),
nt_errstr(ntstatus));
}
/* Initialise samba client routines */
static BOOL initialised;
void py_samba_init(void)
{
if (initialised)
return;
/* Load configuration file */
if (!lp_load(dyn_CONFIGFILE, True, False, False))
fprintf(stderr, "Can't load %s\n", dyn_CONFIGFILE);
/* Misc other stuff */
load_interfaces();
initialised = True;
}
/* Debuglevel routines */
PyObject *get_debuglevel(PyObject *self, PyObject *args)
{
PyObject *debuglevel;
if (!PyArg_ParseTuple(args, ""))
return NULL;
debuglevel = PyInt_FromLong(DEBUGLEVEL);
return debuglevel;
}
PyObject *set_debuglevel(PyObject *self, PyObject *args)
{
int debuglevel;
if (!PyArg_ParseTuple(args, "i", &debuglevel))
return NULL;
DEBUGLEVEL = debuglevel;
Py_INCREF(Py_None);
return Py_None;
}
/* Initialise logging */
PyObject *py_setup_logging(PyObject *self, PyObject *args, PyObject *kw)
{
BOOL interactive = False;
char *logfilename = NULL;
static char *kwlist[] = {"interactive", "logfilename", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kw, "|is", kwlist,
&interactive, &logfilename))
return NULL;
if (interactive && logfilename) {
PyErr_SetString(PyExc_RuntimeError,
"can't be interactive and set log file name");
return NULL;
}
if (interactive)
setup_logging("spoolss", True);
if (logfilename) {
lp_set_logfile(logfilename);
setup_logging(logfilename, False);
reopen_logs();
}
Py_INCREF(Py_None);
return Py_None;
}

View File

@ -1,34 +0,0 @@
/*
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 02139, USA.
*/
#ifndef _PY_COMMON_H
#define _PY_COMMON_H
/* Function prototypes */
void py_samba_init(void);
PyObject *py_werror_tuple(WERROR werror);
PyObject *py_ntstatus_tuple(NTSTATUS ntstatus);
PyObject *py_setup_logging(PyObject *self, PyObject *args);
PyObject *get_debuglevel(PyObject *self, PyObject *args);
PyObject *set_debuglevel(PyObject *self, PyObject *args);
#endif /* _PY_COMMON_H */

View File

@ -1,126 +0,0 @@
/*
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 02139, USA.
*/
#include "includes.h"
#include "Python.h"
#include "py_conv.h"
/* Helper for rpcstr_pull() function */
static void fstr_pull(fstring str, UNISTR *uni)
{
rpcstr_pull(str, uni->buffer, sizeof(fstring), 0, STR_TERMINATE);
}
/* Convert a structure to a Python dict */
PyObject *from_struct(void *s, struct pyconv *conv)
{
PyObject *obj, *item;
int i;
obj = PyDict_New();
for (i = 0; conv[i].name; i++) {
switch (conv[i].type) {
case PY_UNISTR: {
UNISTR *u = (UNISTR *)((char *)s + conv[i].offset);
fstring s = "";
if (u->buffer)
fstr_pull(s, u);
item = PyString_FromString(s);
PyDict_SetItemString(obj, conv[i].name, item);
break;
}
case PY_UINT32: {
uint32 *u = (uint32 *)((char *)s + conv[i].offset);
item = PyInt_FromLong(*u);
PyDict_SetItemString(obj, conv[i].name, item);
break;
}
case PY_UINT16: {
uint16 *u = (uint16 *)((char *)s + conv[i].offset);
item = PyInt_FromLong(*u);
PyDict_SetItemString(obj, conv[i].name, item);
break;
}
default:
break;
}
}
return obj;
}
/* Convert a Python dict to a structure */
void to_struct(void *s, PyObject *dict, struct pyconv *conv)
{
int i;
for (i = 0; conv[i].name; i++) {
PyObject *obj;
obj = PyDict_GetItemString(dict, conv[i].name);
switch (conv[i].type) {
case PY_UNISTR: {
UNISTR *u = (UNISTR *)((char *)s + conv[i].offset);
char *s = "";
if (obj && PyString_Check(obj))
s = PyString_AsString(obj);
init_unistr(u, s);
break;
}
case PY_UINT32: {
uint32 *u = (uint32 *)((char *)s + conv[i].offset);
if (obj && PyInt_Check(obj))
*u = PyInt_AsLong(obj);
else
*u = 0;
break;
}
case PY_UINT16: {
uint16 *u = (uint16 *)((char *)s + conv[i].offset);
if (obj && PyInt_Check(obj))
*u = PyInt_AsLong(obj);
else
*u = 0;
break;
}
default:
break;
}
}
}

View File

@ -1,40 +0,0 @@
/*
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 02139, USA.
*/
#ifndef _PY_CONV_H
#define _PY_CONV_H
enum pyconv_types { PY_UNISTR, PY_UINT32, PY_UINT16 };
struct pyconv {
char *name; /* Name of member */
enum pyconv_types type; /* Type */
size_t offset; /* Offset into structure */
};
PyObject *from_struct(void *s, struct pyconv *conv);
void to_struct(void *s, PyObject *dict, struct pyconv *conv);
/* Another version of offsetof (-: */
#undef offsetof
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
#endif /* _PY_CONV_H */

View File

@ -1,141 +0,0 @@
#include "includes.h"
#include "Python.h"
#include "python/py_common.h"
static void py_policy_hnd_dealloc(PyObject* self)
{
PyObject_Del(self);
}
typedef struct {
PyObject_HEAD
struct cli_state *cli;
TALLOC_CTX *mem_ctx;
POLICY_HND pol;
} lsa_policy_hnd_object;
PyTypeObject lsa_policy_hnd_type = {
PyObject_HEAD_INIT(NULL)
0,
"LSA Policy Handle",
sizeof(lsa_policy_hnd_object),
0,
py_policy_hnd_dealloc, /*tp_dealloc*/
0, /*tp_print*/
0, /*tp_getattr*/
0, /*tp_setattr*/
0, /*tp_compare*/
0, /*tp_repr*/
0, /*tp_as_number*/
0, /*tp_as_sequence*/
0, /*tp_as_mapping*/
0, /*tp_hash */
};
/*
* Exceptions raised by this module
*/
PyObject *lsa_error; /* This indicates a non-RPC related error
such as name lookup failure */
PyObject *lsa_ntstatus; /* This exception is raised when a RPC call
returns a status code other than
NT_STATUS_OK */
/*
* Open/close lsa handles
*/
static PyObject *lsa_openpolicy(PyObject *self, PyObject *args,
PyObject *kw)
{
static char *kwlist[] = { "servername", "creds", "access", NULL };
char *server_name;
PyObject *creds = NULL;
uint32 desired_access = MAXIMUM_ALLOWED_ACCESS;
if (!PyArg_ParseTupleAndKeywords(
args, kw, "s|O!i", kwlist, &server_name, &PyDict_Type,
&creds, &desired_access)) {
goto done;
}
done:
return NULL;
}
static PyObject *lsa_close(PyObject *self, PyObject *args, PyObject *kw)
{
return NULL;
}
static PyObject *lsa_lookupnames(PyObject *self, PyObject *args,
PyObject *kw)
{
return NULL;
}
static PyObject *lsa_lookupsids(PyObject *self, PyObject *args,
PyObject *kw)
{
return NULL;
}
/*
* Method dispatch table
*/
static PyMethodDef lsa_methods[] = {
/* Open/close lsa handles */
{ "openpolicy", lsa_openpolicy, METH_VARARGS | METH_KEYWORDS,
"Open a policy handle" },
{ "close", lsa_close, METH_VARARGS,
"Close a policy handle" },
/* Name <-> SID resolution */
{ "lookupnames", lsa_lookupnames, METH_VARARGS | METH_KEYWORDS,
"Look up SIDS from a list of names" },
{ "lookupsids", lsa_lookupsids, METH_VARARGS | METH_KEYWORDS,
"Look up names from a list of SIDS" },
{ NULL }
};
/*
* Module initialisation
*/
void initlsa(void)
{
PyObject *module, *dict;
/* Initialise module */
module = Py_InitModule("lsa", lsa_methods);
dict = PyModule_GetDict(module);
lsa_error = PyErr_NewException("lsa.error", NULL, NULL);
PyDict_SetItemString(dict, "error", lsa_error);
lsa_ntstatus = PyErr_NewException("lsa.ntstatus", NULL, NULL);
PyDict_SetItemString(dict, "ntstatus", lsa_ntstatus);
/* Initialise policy handle object */
lsa_policy_hnd_type.ob_type = &PyType_Type;
/* Initialise constants */
// const_init(dict);
/* Do samba initialisation */
py_samba_init();
}

View File

@ -1,433 +0,0 @@
/*
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 02139, USA.
*/
#include "python/py_spoolss.h"
/* Exceptions this module can raise */
PyObject *spoolss_error, *spoolss_werror;
/*
* Routines to convert from python hashes to Samba structures
*/
struct cli_state *open_pipe_creds(char *system_name, PyObject *creds,
cli_pipe_fn *connect_fn,
struct cli_state *cli)
{
struct ntuser_creds nt_creds;
if (!cli) {
cli = (struct cli_state *)malloc(sizeof(struct cli_state));
if (!cli)
return NULL;
}
ZERO_STRUCTP(cli);
/* Extract credentials from the python dictionary and initialise
the ntuser_creds struct from them. */
ZERO_STRUCT(nt_creds);
nt_creds.pwd.null_pwd = True;
if (creds && PyDict_Size(creds) > 0) {
char *username, *password, *domain;
PyObject *username_obj, *password_obj, *domain_obj;
/* Check credentials passed are valid. This means the
username, domain and password keys must exist and be
string objects. */
username_obj = PyDict_GetItemString(creds, "username");
domain_obj = PyDict_GetItemString(creds, "domain");
password_obj = PyDict_GetItemString(creds, "password");
if (!username_obj || !domain_obj || !password_obj) {
error:
PyErr_SetString(spoolss_error, "invalid credentials");
return NULL;
}
if (!PyString_Check(username_obj) ||
!PyString_Check(domain_obj) ||
!PyString_Check(password_obj))
goto error;
username = PyString_AsString(username_obj);
domain = PyString_AsString(domain_obj);
password = PyString_AsString(password_obj);
if (!username || !domain || !password)
goto error;
/* Initialise nt_creds structure with passed creds */
fstrcpy(nt_creds.user_name, username);
fstrcpy(nt_creds.domain, domain);
if (lp_encrypted_passwords())
pwd_make_lm_nt_16(&nt_creds.pwd, password);
else
pwd_set_cleartext(&nt_creds.pwd, password);
nt_creds.pwd.null_pwd = False;
}
/* Now try to connect */
connect_fn(cli, system_name, &nt_creds);
return cli;
}
PyObject *new_policy_hnd_object(struct cli_state *cli, TALLOC_CTX *mem_ctx,
POLICY_HND *pol)
{
spoolss_policy_hnd_object *o;
o = PyObject_New(spoolss_policy_hnd_object, &spoolss_policy_hnd_type);
o->cli = cli;
o->mem_ctx = mem_ctx;
memcpy(&o->pol, pol, sizeof(POLICY_HND));
return (PyObject*)o;
}
/*
* Method dispatch table
*/
static PyMethodDef spoolss_methods[] = {
/* Open/close printer handles */
{ "openprinter", spoolss_openprinter, METH_VARARGS | METH_KEYWORDS,
"openprinter(printername, [creds, access]) -> <spoolss hnd object>
Open a printer given by printername in UNC format. Optionally a
dictionary of (username, password) may be given in which case they are
used when opening the RPC pipe. An access mask may also be given which
defaults to MAXIMUM_ALLOWED_ACCESS.
Example:
>>> hnd = spoolss.openprinter(\"\\\\\\\\NPSD-PDC2\\\\meanie\")
"},
{ "closeprinter", spoolss_closeprinter, METH_VARARGS,
"closeprinter()
Close a printer handle opened with openprinter or addprinter.
Example:
>>> spoolss.closeprinter(hnd)
"},
/* Server enumeratation functions */
{ "enumprinters", spoolss_enumprinters, METH_VARARGS | METH_KEYWORDS,
"enumprinters(server, [creds, level, flags]) -> list
Return a list of printers on a print server. The credentials, info level
and flags may be specified as keyword arguments.
Example:
>>> print spoolss.enumprinters(\"\\\\\\\\npsd-pdc2\")
[{'comment': 'i am a comment', 'printer_name': 'meanie', 'flags': 8388608,
'description': 'meanie,Generic / Text Only,i am a location'},
{'comment': '', 'printer_name': 'fileprint', 'flags': 8388608,
'description': 'fileprint,Generic / Text Only,'}]
"},
{ "enumports", spoolss_enumports, METH_VARARGS | METH_KEYWORDS,
"enumports(server, [creds, level]) -> list
Return a list of ports on a print server.
Example:
>>> print spoolss.enumports(\"\\\\\\\\npsd-pdc2\")
[{'name': 'LPT1:'}, {'name': 'LPT2:'}, {'name': 'COM1:'}, {'name': 'COM2:'},
{'name': 'FILE:'}, {'name': '\\\\nautilus1\\zpekt3r'}]
"},
{ "enumprinterdrivers", spoolss_enumprinterdrivers, METH_VARARGS |
METH_KEYWORDS,
"enumprinterdrivers(server, [level, arch, creds]) -> list
Return a list of printer drivers.
"},
/* Miscellaneous other commands */
{ "getprinterdriverdir", spoolss_getprinterdriverdir, METH_VARARGS |
METH_KEYWORDS, "getprinterdriverdir(server, [creds]) -> string
Return the printer driver directory for a given architecture. The
architecture defaults to \"Windows NT x86\".
"},
/* Other stuff - this should really go into a samba config module
but for the moment let's leave it here. */
{ "setup_logging", py_setup_logging, METH_VARARGS | METH_KEYWORDS,
"" },
{ "get_debuglevel", get_debuglevel, METH_VARARGS, "" },
{ "set_debuglevel", set_debuglevel, METH_VARARGS, "" },
{ NULL }
};
/* Methods attached to a spoolss handle object */
static PyMethodDef spoolss_hnd_methods[] = {
/* Printer info */
{ "getprinter", spoolss_getprinter, METH_VARARGS | METH_KEYWORDS,
"getprinter([level]) -> dict
Return a dictionary of print information. The info level defaults to 1.
Example:
>>> hnd.getprinter()
{'comment': 'i am a comment', 'printer_name': '\\\\NPSD-PDC2\\meanie',
'description': '\\\\NPSD-PDC2\\meanie,Generic / Text Only,i am a location',
'flags': 8388608}
"},
{ "setprinter", spoolss_setprinter, METH_VARARGS | METH_KEYWORDS,
"setprinter(dict) -> None
Set printer information.
"},
/* Printer drivers */
{ "getprinterdriver", spoolss_getprinterdriver,
METH_VARARGS | METH_KEYWORDS,
"getprinterdriver([level = 1, arch = \"Windows NT x86\"] -> dict
Return a dictionary of printer driver information.
"},
/* Forms */
{ "enumforms", spoolss_enumforms, METH_VARARGS | METH_KEYWORDS,
"enumforms([level = 1]) -> list
Return a list of forms supported by a printer.
"},
{ "setform", spoolss_setform, METH_VARARGS | METH_KEYWORDS,
"setform(dict) -> None
Set the form given by the dictionary argument.
"},
{ "addform", spoolss_addform, METH_VARARGS | METH_KEYWORDS,
"Insert a form" },
{ "getform", spoolss_getform, METH_VARARGS | METH_KEYWORDS,
"Fetch form properties" },
{ "deleteform", spoolss_deleteform, METH_VARARGS | METH_KEYWORDS,
"Delete a form" },
{ NULL }
};
static void py_policy_hnd_dealloc(PyObject* self)
{
PyObject_Del(self);
}
static PyObject *py_policy_hnd_getattr(PyObject *self, char *attrname)
{
return Py_FindMethod(spoolss_hnd_methods, self, attrname);
}
static char spoolss_type_doc[] =
"Python wrapper for Windows NT SPOOLSS rpc pipe.";
PyTypeObject spoolss_policy_hnd_type = {
PyObject_HEAD_INIT(NULL)
0,
"spoolss.hnd",
sizeof(spoolss_policy_hnd_object),
0,
py_policy_hnd_dealloc, /* tp_dealloc*/
0, /* tp_print*/
py_policy_hnd_getattr, /* tp_getattr*/
0, /* tp_setattr*/
0, /* tp_compare*/
0, /* tp_repr*/
0, /* tp_as_number*/
0, /* tp_as_sequence*/
0, /* tp_as_mapping*/
0, /* tp_hash */
0, /* tp_call */
0, /* tp_str */
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer*/
Py_TPFLAGS_DEFAULT, /* tp_flags */
spoolss_type_doc, /* tp_doc */
};
/* Initialise constants */
struct spoolss_const {
char *name;
uint32 value;
} spoolss_const_vals[] = {
/* Access permissions */
{ "MAXIMUM_ALLOWED_ACCESS", MAXIMUM_ALLOWED_ACCESS },
{ "SERVER_ALL_ACCESS", SERVER_ALL_ACCESS },
{ "SERVER_READ", SERVER_READ },
{ "SERVER_WRITE", SERVER_WRITE },
{ "SERVER_EXECUTE", SERVER_EXECUTE },
{ "SERVER_ACCESS_ADMINISTER", SERVER_ACCESS_ADMINISTER },
{ "SERVER_ACCESS_ENUMERATE", SERVER_ACCESS_ENUMERATE },
{ "PRINTER_ALL_ACCESS", PRINTER_ALL_ACCESS },
{ "PRINTER_READ", PRINTER_READ },
{ "PRINTER_WRITE", PRINTER_WRITE },
{ "PRINTER_EXECUTE", PRINTER_EXECUTE },
{ "PRINTER_ACCESS_ADMINISTER", PRINTER_ACCESS_ADMINISTER },
{ "PRINTER_ACCESS_USE", PRINTER_ACCESS_USE },
{ "JOB_ACCESS_ADMINISTER", JOB_ACCESS_ADMINISTER },
{ "JOB_ALL_ACCESS", JOB_ALL_ACCESS },
{ "JOB_READ", JOB_READ },
{ "JOB_WRITE", JOB_WRITE },
{ "JOB_EXECUTE", JOB_EXECUTE },
{ "STANDARD_RIGHTS_ALL_ACCESS", STANDARD_RIGHTS_ALL_ACCESS },
{ "STANDARD_RIGHTS_EXECUTE_ACCESS", STANDARD_RIGHTS_EXECUTE_ACCESS },
{ "STANDARD_RIGHTS_READ_ACCESS", STANDARD_RIGHTS_READ_ACCESS },
{ "STANDARD_RIGHTS_REQUIRED_ACCESS", STANDARD_RIGHTS_REQUIRED_ACCESS },
{ "STANDARD_RIGHTS_WRITE_ACCESS", STANDARD_RIGHTS_WRITE_ACCESS },
/* Printer enumeration flags */
{ "PRINTER_ENUM_DEFAULT", PRINTER_ENUM_DEFAULT },
{ "PRINTER_ENUM_LOCAL", PRINTER_ENUM_LOCAL },
{ "PRINTER_ENUM_CONNECTIONS", PRINTER_ENUM_CONNECTIONS },
{ "PRINTER_ENUM_FAVORITE", PRINTER_ENUM_FAVORITE },
{ "PRINTER_ENUM_NAME", PRINTER_ENUM_NAME },
{ "PRINTER_ENUM_REMOTE", PRINTER_ENUM_REMOTE },
{ "PRINTER_ENUM_SHARED", PRINTER_ENUM_SHARED },
{ "PRINTER_ENUM_NETWORK", PRINTER_ENUM_NETWORK },
/* Form types */
{ "FORM_USER", FORM_USER },
{ "FORM_BUILTIN", FORM_BUILTIN },
{ "FORM_PRINTER", FORM_PRINTER },
/* WERRORs */
{ "WERR_OK", 0 },
{ "WERR_BADFILE", 2 },
{ "WERR_ACCESS_DENIED", 5 },
{ "WERR_BADFID", 6 },
{ "WERR_BADFUNC", 1 },
{ "WERR_INSUFFICIENT_BUFFER", 122 },
{ "WERR_NO_SUCH_SHARE", 67 },
{ "WERR_ALREADY_EXISTS", 80 },
{ "WERR_INVALID_PARAM", 87 },
{ "WERR_NOT_SUPPORTED", 50 },
{ "WERR_BAD_PASSWORD", 86 },
{ "WERR_NOMEM", 8 },
{ "WERR_INVALID_NAME", 123 },
{ "WERR_UNKNOWN_LEVEL", 124 },
{ "WERR_OBJECT_PATH_INVALID", 161 },
{ "WERR_NO_MORE_ITEMS", 259 },
{ "WERR_MORE_DATA", 234 },
{ "WERR_UNKNOWN_PRINTER_DRIVER", 1797 },
{ "WERR_INVALID_PRINTER_NAME", 1801 },
{ "WERR_PRINTER_ALREADY_EXISTS", 1802 },
{ "WERR_INVALID_DATATYPE", 1804 },
{ "WERR_INVALID_ENVIRONMENT", 1805 },
{ "WERR_INVALID_FORM_NAME", 1902 },
{ "WERR_INVALID_FORM_SIZE", 1903 },
{ "WERR_BUF_TOO_SMALL", 2123 },
{ "WERR_JOB_NOT_FOUND", 2151 },
{ "WERR_DEST_NOT_FOUND", 2152 },
{ "WERR_NOT_LOCAL_DOMAIN", 2320 },
{ "WERR_PRINTER_DRIVER_IN_USE", 3001 },
{ "WERR_STATUS_MORE_ENTRIES ", 0x0105 },
{ NULL },
};
static void const_init(PyObject *dict)
{
struct spoolss_const *tmp;
PyObject *obj;
for (tmp = spoolss_const_vals; tmp->name; tmp++) {
obj = PyInt_FromLong(tmp->value);
PyDict_SetItemString(dict, tmp->name, obj);
Py_DECREF(obj);
}
}
/* Module initialisation */
void initspoolss(void)
{
PyObject *module, *dict;
/* Initialise module */
module = Py_InitModule("spoolss", spoolss_methods);
dict = PyModule_GetDict(module);
/* Make spools_error global an exception we can raise when an error
occurs. */
spoolss_error = PyErr_NewException("spoolss.error", NULL, NULL);
PyDict_SetItemString(dict, "error", spoolss_error);
spoolss_werror = PyErr_NewException("spoolss.werror", NULL, NULL);
PyDict_SetItemString(dict, "werror", spoolss_werror);
/* Initialise policy handle object */
spoolss_policy_hnd_type.ob_type = &PyType_Type;
PyDict_SetItemString(dict, "spoolss.hnd",
(PyObject *)&spoolss_policy_hnd_type);
/* Initialise constants */
const_init(dict);
/* Do samba initialisation */
py_samba_init();
}

View File

@ -1,53 +0,0 @@
/*
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 02139, USA.
*/
#ifndef _PY_SPOOLSS_H
#define _PY_SPOOLSS_H
#include "includes.h"
#include "Python.h"
#include "python/py_common.h"
/* Spoolss policy handle object */
typedef struct {
PyObject_HEAD
struct cli_state *cli;
TALLOC_CTX *mem_ctx;
POLICY_HND pol;
} spoolss_policy_hnd_object;
/* Exceptions raised by this module */
extern PyTypeObject spoolss_policy_hnd_type;
extern PyObject *spoolss_error, *spoolss_werror;
/* Return a cli_state struct opened on the SPOOLSS pipe. If credentials
are passed use them. */
typedef struct cli_state *(cli_pipe_fn)(
struct cli_state *cli, char *system_name,
struct ntuser_creds *creds);
#include "python/py_spoolss_proto.h"
#endif /* _PY_SPOOLSS_H */

View File

@ -1,243 +0,0 @@
/*
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 02139, USA.
*/
#include "python/py_spoolss.h"
/* Enumerate printer drivers */
PyObject *spoolss_enumprinterdrivers(PyObject *self, PyObject *args,
PyObject *kw)
{
WERROR werror;
PyObject *result = Py_None, *creds = NULL;
PRINTER_DRIVER_CTR ctr;
int level = 1, i;
uint32 needed, num_drivers;
char *arch = "Windows NT x86", *server_name;
static char *kwlist[] = {"server", "level", "arch", "creds", NULL};
struct cli_state *cli = NULL;
TALLOC_CTX *mem_ctx = NULL;
/* Parse parameters */
if (!PyArg_ParseTupleAndKeywords(args, kw, "s|isO!", kwlist,
&server_name, &level, &arch,
&PyDict_Type, &creds))
return NULL;
/* Call rpc function */
if (!(cli = open_pipe_creds(server_name, creds,
cli_spoolss_initialise, NULL))) {
fprintf(stderr, "could not initialise cli state\n");
goto done;
}
if (!(mem_ctx = talloc_init())) {
fprintf(stderr, "unable to initialise talloc context\n");
goto done;
}
werror = cli_spoolss_enumprinterdrivers(
cli, mem_ctx, 0, &needed, level, arch,
&num_drivers, &ctr);
if (W_ERROR_V(werror) == ERRinsufficientbuffer)
werror = cli_spoolss_enumprinterdrivers(
cli, mem_ctx, needed, NULL, level, arch,
&num_drivers, &ctr);
if (!W_ERROR_IS_OK(werror)) {
PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
return NULL;
}
/* Return value */
switch (level) {
case 1:
result = PyList_New(num_drivers);
for (i = 0; i < num_drivers; i++) {
PyObject *value;
py_from_DRIVER_INFO_1(&value, ctr.info1);
PyList_SetItem(result, i, value);
}
break;
case 2:
result = PyList_New(num_drivers);
for(i = 0; i < num_drivers; i++) {
PyObject *value;
py_from_DRIVER_INFO_2(&value, ctr.info2);
PyList_SetItem(result, i, value);
}
break;
case 6:
result = PyList_New(num_drivers);
for(i = 0; i < num_drivers; i++) {
PyObject *value;
py_from_DRIVER_INFO_6(&value, ctr.info6);
PyList_SetItem(result, i, value);
}
break;
default:
result = Py_None;
break;
}
done:
if (cli)
cli_shutdown(cli);
if (mem_ctx)
talloc_destroy(mem_ctx);
Py_INCREF(result);
return result;
}
/* Fetch printer driver */
PyObject *spoolss_getprinterdriver(PyObject *self, PyObject *args,
PyObject *kw)
{
spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
WERROR werror;
PyObject *result = Py_None;
PRINTER_DRIVER_CTR ctr;
int level = 1;
uint32 needed;
char *arch = "Windows NT x86";
static char *kwlist[] = {"level", "arch", NULL};
/* Parse parameters */
if (!PyArg_ParseTupleAndKeywords(args, kw, "|is", kwlist,
&level, &arch))
return NULL;
/* Call rpc function */
werror = cli_spoolss_getprinterdriver(
hnd->cli, hnd->mem_ctx, 0, &needed, &hnd->pol, level,
arch, &ctr);
if (W_ERROR_V(werror) == ERRinsufficientbuffer)
werror = cli_spoolss_getprinterdriver(
hnd->cli, hnd->mem_ctx, needed, NULL, &hnd->pol,
level, arch, &ctr);
if (!W_ERROR_IS_OK(werror)) {
PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
return NULL;
}
/* Return value */
switch (level) {
case 1:
py_from_DRIVER_INFO_1(&result, ctr.info1);
break;
case 2:
py_from_DRIVER_INFO_2(&result, ctr.info2);
break;
case 6:
py_from_DRIVER_INFO_6(&result, ctr.info6);
break;
default:
break;
}
Py_INCREF(result);
return result;
}
/* Fetch printer driver directory */
PyObject *spoolss_getprinterdriverdir(PyObject *self, PyObject *args,
PyObject *kw)
{
WERROR werror;
PyObject *result = Py_None, *creds = NULL;
DRIVER_DIRECTORY_CTR ctr;
uint32 needed, level;
char *arch = "Windows NT x86", *server_name;
static char *kwlist[] = {"server", "level", "arch", "creds", NULL};
struct cli_state *cli = NULL;
TALLOC_CTX *mem_ctx = NULL;
/* Parse parameters */
if (!PyArg_ParseTupleAndKeywords(args, kw, "s|isO!", kwlist,
&server_name, &level, &arch,
&PyDict_Type, &creds))
return NULL;
/* Call rpc function */
if (!(cli = open_pipe_creds(server_name, creds,
cli_spoolss_initialise, NULL))) {
fprintf(stderr, "could not initialise cli state\n");
goto done;
}
if (!(mem_ctx = talloc_init())) {
fprintf(stderr, "unable to initialise talloc context\n");
goto done;
}
werror = cli_spoolss_getprinterdriverdir(
cli, mem_ctx, 0, &needed, level, arch, &ctr);
if (W_ERROR_V(werror) == ERRinsufficientbuffer)
werror = cli_spoolss_getprinterdriverdir(
cli, mem_ctx, needed, NULL, level, arch, &ctr);
if (!W_ERROR_IS_OK(werror)) {
PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
return NULL;
}
/* Return value */
switch (level) {
case 1:
py_from_DRIVER_DIRECTORY_1(&result, ctr.info1);
break;
}
done:
if (cli)
cli_shutdown(cli);
if (mem_ctx)
talloc_destroy(mem_ctx);
Py_INCREF(result);
return result;
}

View File

@ -1,137 +0,0 @@
/*
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 02139, USA.
*/
#include "python/py_spoolss.h"
#include "python/py_conv.h"
/* Structure/hash conversions */
struct pyconv py_DRIVER_INFO_1[] = {
{ "name", PY_UNISTR, offsetof(DRIVER_INFO_1, name) },
{ NULL }
};
struct pyconv py_DRIVER_INFO_2[] = {
{ "version", PY_UINT32, offsetof(DRIVER_INFO_2, version) },
{ "name", PY_UNISTR, offsetof(DRIVER_INFO_2, name) },
{ "architecture", PY_UNISTR, offsetof(DRIVER_INFO_2, architecture) },
{ "driver_path", PY_UNISTR, offsetof(DRIVER_INFO_2, driverpath) },
{ "data_file", PY_UNISTR, offsetof(DRIVER_INFO_2, datafile) },
{ "config_file", PY_UNISTR, offsetof(DRIVER_INFO_2, configfile) },
{ NULL }
};
struct pyconv py_DRIVER_INFO_3[] = {
{ "version", PY_UINT32, offsetof(DRIVER_INFO_3, version) },
{ "name", PY_UNISTR, offsetof(DRIVER_INFO_3, name) },
{ "architecture", PY_UNISTR, offsetof(DRIVER_INFO_3, architecture) },
{ "driver_path", PY_UNISTR, offsetof(DRIVER_INFO_3, driverpath) },
{ "data_file", PY_UNISTR, offsetof(DRIVER_INFO_3, datafile) },
{ "config_file", PY_UNISTR, offsetof(DRIVER_INFO_3, configfile) },
{ "help_file", PY_UNISTR, offsetof(DRIVER_INFO_3, helpfile) },
/* dependentfiles */
{ "monitor_name", PY_UNISTR, offsetof(DRIVER_INFO_3, monitorname) },
{ "default_datatype", PY_UNISTR, offsetof(DRIVER_INFO_3, defaultdatatype) },
{ NULL }
};
struct pyconv py_DRIVER_INFO_6[] = {
{ "version", PY_UINT32, offsetof(DRIVER_INFO_6, version) },
{ "name", PY_UNISTR, offsetof(DRIVER_INFO_6, name) },
{ "architecture", PY_UNISTR, offsetof(DRIVER_INFO_6, architecture) },
{ "driver_path", PY_UNISTR, offsetof(DRIVER_INFO_6, driverpath) },
{ "data_file", PY_UNISTR, offsetof(DRIVER_INFO_6, datafile) },
{ "config_file", PY_UNISTR, offsetof(DRIVER_INFO_6, configfile) },
{ "help_file", PY_UNISTR, offsetof(DRIVER_INFO_6, helpfile) },
/* dependentfiles */
{ "monitor_name", PY_UNISTR, offsetof(DRIVER_INFO_6, monitorname) },
{ "default_datatype", PY_UNISTR, offsetof(DRIVER_INFO_6, defaultdatatype) },
/* driver_date */
{ "padding", PY_UINT32, offsetof(DRIVER_INFO_6, padding) },
{ "driver_version_low", PY_UINT32, offsetof(DRIVER_INFO_6, driver_version_low) },
{ "driver_version_high", PY_UINT32, offsetof(DRIVER_INFO_6, driver_version_high) },
{ "mfg_name", PY_UNISTR, offsetof(DRIVER_INFO_6, mfgname) },
{ "oem_url", PY_UNISTR, offsetof(DRIVER_INFO_6, oem_url) },
{ "hardware_id", PY_UNISTR, offsetof(DRIVER_INFO_6, hardware_id) },
{ "provider", PY_UNISTR, offsetof(DRIVER_INFO_6, provider) },
{ NULL }
};
struct pyconv py_DRIVER_DIRECTORY_1[] = {
{ "name", PY_UNISTR, offsetof(DRIVER_DIRECTORY_1, name) },
{ NULL }
};
BOOL py_from_DRIVER_INFO_1(PyObject **dict, DRIVER_INFO_1 *info)
{
*dict = from_struct(info, py_DRIVER_INFO_1);
return True;
}
BOOL py_to_DRIVER_INFO_1(DRIVER_INFO_1 *info, PyObject *dict)
{
return False;
}
BOOL py_from_DRIVER_INFO_2(PyObject **dict, DRIVER_INFO_2 *info)
{
*dict = from_struct(info, py_DRIVER_INFO_2);
return True;
}
BOOL py_to_DRIVER_INFO_2(DRIVER_INFO_2 *info, PyObject *dict)
{
return False;
}
BOOL py_from_DRIVER_INFO_3(PyObject **dict, DRIVER_INFO_3 *info)
{
*dict = from_struct(info, py_DRIVER_INFO_3);
return True;
}
BOOL py_to_DRIVER_INFO_3(DRIVER_INFO_3 *info, PyObject *dict)
{
return False;
}
BOOL py_from_DRIVER_INFO_6(PyObject **dict, DRIVER_INFO_6 *info)
{
*dict = from_struct(info, py_DRIVER_INFO_6);
return True;
}
BOOL py_to_DRIVER_INFO_6(DRIVER_INFO_6 *info, PyObject *dict)
{
return False;
}
BOOL py_from_DRIVER_DIRECTORY_1(PyObject **dict, DRIVER_DIRECTORY_1 *info)
{
*dict = from_struct(info, py_DRIVER_DIRECTORY_1);
return True;
}
BOOL py_to_DRIVER_DIRECTORY_1(DRIVER_DIRECTORY_1 *info, PyObject *dict)
{
return False;
}

View File

@ -1,237 +0,0 @@
/*
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 02139, USA.
*/
#include "python/py_spoolss.h"
/* Add a form */
PyObject *spoolss_addform(PyObject *self, PyObject *args, PyObject *kw)
{
spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
WERROR werror;
PyObject *py_form, *py_form_name;
char *form_name;
FORM form;
int level = 1;
static char *kwlist[] = {"form", "level", NULL};
/* Parse parameters */
if (!PyArg_ParseTupleAndKeywords(
args, kw, "O!|i", kwlist, &PyDict_Type, &py_form, &level))
return NULL;
/* Call rpc function */
if (!py_to_FORM(&form, py_form) ||
!(py_form_name = PyDict_GetItemString(py_form, "name")) ||
!(form_name = PyString_AsString(py_form_name))) {
PyErr_SetString(spoolss_error, "invalid form");
return NULL;
}
switch (level) {
case 1:
init_unistr2(&form.name, form_name, strlen(form_name) + 1);
break;
default:
PyErr_SetString(spoolss_error, "unsupported info level");
return NULL;
}
werror = cli_spoolss_addform(hnd->cli, hnd->mem_ctx, &hnd->pol,
level, &form);
if (!W_ERROR_IS_OK(werror)) {
PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
return NULL;
}
Py_INCREF(Py_None);
return Py_None;
}
/* Get form properties */
PyObject *spoolss_getform(PyObject *self, PyObject *args, PyObject *kw)
{
spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
WERROR werror;
PyObject *result;
char *form_name;
int level = 1;
static char *kwlist[] = {"form_name", "level", NULL};
uint32 needed;
FORM_1 form;
/* Parse parameters */
if (!PyArg_ParseTupleAndKeywords(args, kw, "s|i", kwlist,
&form_name, &level))
return NULL;
/* Call rpc function */
werror = cli_spoolss_getform(hnd->cli, hnd->mem_ctx, 0, &needed,
&hnd->pol, form_name, 1, &form);
if (W_ERROR_V(werror) == ERRinsufficientbuffer)
werror = cli_spoolss_getform(
hnd->cli, hnd->mem_ctx, needed, NULL, &hnd->pol,
form_name, 1, &form);
if (!W_ERROR_IS_OK(werror)) {
PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
return NULL;
}
result = Py_None;
switch(level) {
case 1:
py_from_FORM_1(&result, &form);
break;
}
Py_INCREF(result);
return result;
}
/* Set form properties */
PyObject *spoolss_setform(PyObject *self, PyObject *args, PyObject *kw)
{
spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
WERROR werror;
PyObject *py_form, *py_form_name;
int level = 1;
static char *kwlist[] = {"form", "level", NULL};
char *form_name;
FORM form;
/* Parse parameters */
if (!PyArg_ParseTupleAndKeywords(args, kw, "O!|i", kwlist,
&PyDict_Type, &py_form, &level))
return NULL;
/* Call rpc function */
if (!py_to_FORM(&form, py_form) ||
!(py_form_name = PyDict_GetItemString(py_form, "name")) ||
!(form_name = PyString_AsString(py_form_name))) {
PyErr_SetString(spoolss_error, "invalid form");
return NULL;
}
init_unistr2(&form.name, form_name, strlen(form_name) + 1);
werror = cli_spoolss_setform(hnd->cli, hnd->mem_ctx, &hnd->pol,
level, form_name, &form);
if (!W_ERROR_IS_OK(werror)) {
PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
return NULL;
}
Py_INCREF(Py_None);
return Py_None;
}
/* Delete a form */
PyObject *spoolss_deleteform(PyObject *self, PyObject *args, PyObject *kw)
{
spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
WERROR werror;
int level = 1;
static char *kwlist[] = {"form_name", "level", NULL};
char *form_name;
/* Parse parameters */
if (!PyArg_ParseTupleAndKeywords(
args, kw, "s|i", kwlist, &form_name, &level))
return NULL;
/* Call rpc function */
werror = cli_spoolss_deleteform(
hnd->cli, hnd->mem_ctx, &hnd->pol, form_name);
if (!W_ERROR_IS_OK(werror)) {
PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
return NULL;
}
Py_INCREF(Py_None);
return Py_None;
}
/* Enumerate forms */
PyObject *spoolss_enumforms(PyObject *self, PyObject *args, PyObject *kw)
{
PyObject *result;
spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
WERROR werror;
uint32 level = 1, num_forms, needed, i;
static char *kwlist[] = {"level", NULL};
FORM_1 *forms;
/* Parse parameters */
if (!PyArg_ParseTupleAndKeywords(
args, kw, "|i", kwlist, &level))
return NULL;
/* Call rpc function */
werror = cli_spoolss_enumforms(
hnd->cli, hnd->mem_ctx, 0, &needed, &hnd->pol, level,
&num_forms, &forms);
if (W_ERROR_V(werror) == ERRinsufficientbuffer)
werror = cli_spoolss_enumforms(
hnd->cli, hnd->mem_ctx, needed, NULL, &hnd->pol, level,
&num_forms, &forms);
if (!W_ERROR_IS_OK(werror)) {
PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
return NULL;
}
result = PyList_New(num_forms);
for (i = 0; i < num_forms; i++) {
PyObject *obj = NULL;
switch(level) {
case 1:
py_from_FORM_1(&obj, &forms[i]);
break;
}
PyList_SetItem(result, i, obj);
}
return result;
}

View File

@ -1,57 +0,0 @@
/*
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 02139, USA.
*/
#include "python/py_spoolss.h"
#include "python/py_conv.h"
struct pyconv py_FORM[] = {
{ "flags", PY_UINT32, offsetof(FORM, flags) },
{ "width", PY_UINT32, offsetof(FORM, size_x) },
{ "length", PY_UINT32, offsetof(FORM, size_y) },
{ "top", PY_UINT32, offsetof(FORM, top) },
{ "left", PY_UINT32, offsetof(FORM, left) },
{ "right", PY_UINT32, offsetof(FORM, right) },
{ "bottom", PY_UINT32, offsetof(FORM, bottom) },
{ NULL }
};
struct pyconv py_FORM_1[] = {
{ "flags", PY_UINT32, offsetof(FORM_1, flag) },
{ "width", PY_UINT32, offsetof(FORM_1, width) },
{ "length", PY_UINT32, offsetof(FORM_1, length) },
{ "top", PY_UINT32, offsetof(FORM_1, top) },
{ "left", PY_UINT32, offsetof(FORM_1, left) },
{ "right", PY_UINT32, offsetof(FORM_1, right) },
{ "bottom", PY_UINT32, offsetof(FORM_1, bottom) },
{ "name", PY_UNISTR, offsetof(FORM_1, name) },
{ NULL }
};
BOOL py_from_FORM_1(PyObject **dict, FORM_1 *form)
{
*dict = from_struct(form, py_FORM_1);
return True;
}
BOOL py_to_FORM(FORM *form, PyObject *dict)
{
to_struct(form, dict, py_FORM);
return True;
}

View File

@ -1,95 +0,0 @@
/*
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 02139, USA.
*/
#include "python/py_spoolss.h"
/* Enumerate ports */
PyObject *spoolss_enumports(PyObject *self, PyObject *args, PyObject *kw)
{
WERROR werror;
PyObject *result, *creds = NULL;
int level = 1;
uint32 i, needed, num_ports;
static char *kwlist[] = {"server", "level", "creds", NULL};
TALLOC_CTX *mem_ctx = NULL;
struct cli_state *cli = NULL;
char *server;
PORT_INFO_CTR ctr;
/* Parse parameters */
if (!PyArg_ParseTupleAndKeywords(args, kw, "s|iO!", kwlist,
&server, &creds, &level,
&PyDict_Type))
return NULL;
if (server[0] == '\\' && server[1] == '\\')
server += 2;
mem_ctx = talloc_init();
cli = open_pipe_creds(server, creds, cli_spoolss_initialise, NULL);
/* Call rpc function */
werror = cli_spoolss_enum_ports(
cli, mem_ctx, 0, &needed, level, &num_ports, &ctr);
if (W_ERROR_V(werror) == ERRinsufficientbuffer)
werror = cli_spoolss_enum_ports(
cli, mem_ctx, needed, NULL, level,
&num_ports, &ctr);
/* Return value */
result = Py_None;
if (!W_ERROR_IS_OK(werror))
goto done;
result = PyList_New(num_ports);
switch (level) {
case 1:
for (i = 0; i < num_ports; i++) {
PyObject *value;
py_from_PORT_INFO_1(&value, &ctr.port.info_1[i]);
PyList_SetItem(result, i, value);
}
break;
case 2:
for(i = 0; i < num_ports; i++) {
PyObject *value;
py_from_PORT_INFO_2(&value, &ctr.port.info_2[i]);
PyList_SetItem(result, i, value);
}
break;
}
done:
Py_INCREF(result);
return result;
}

View File

@ -1,363 +0,0 @@
/*
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 02139, USA.
*/
#include "python/py_spoolss.h"
/* Open a printer */
PyObject *spoolss_openprinter(PyObject *self, PyObject *args, PyObject *kw)
{
char *full_name, *computer_name = NULL;
TALLOC_CTX *mem_ctx;
POLICY_HND hnd;
WERROR werror;
PyObject *result = NULL, *creds = NULL;
static char *kwlist[] = { "printername", "creds", "access", NULL };
uint32 desired_access = MAXIMUM_ALLOWED_ACCESS;
struct cli_state *cli;
if (!PyArg_ParseTupleAndKeywords(
args, kw, "s|O!i", kwlist, &full_name, &PyDict_Type, &creds,
&desired_access)) {
goto done;
}
/* FIXME: Return name format exception for names without a UNC
prefix */
computer_name = strdup(full_name + 2);
if (strchr(computer_name, '\\')) {
char *c = strchr(computer_name, '\\');
*c = 0;
}
if (!(cli = open_pipe_creds(computer_name, creds,
cli_spoolss_initialise, NULL))) {
fprintf(stderr, "could not initialise cli state\n");
goto done;
}
if (!(mem_ctx = talloc_init())) {
fprintf(stderr, "unable to initialise talloc context\n");
goto done;
}
werror = cli_spoolss_open_printer_ex(
cli, mem_ctx, full_name, "", desired_access, computer_name,
"", &hnd);
if (!W_ERROR_IS_OK(werror)) {
cli_shutdown(cli);
SAFE_FREE(cli);
PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
goto done;
}
result = new_policy_hnd_object(cli, mem_ctx, &hnd);
done:
SAFE_FREE(computer_name);
return result;
}
/* Close a printer */
PyObject *spoolss_closeprinter(PyObject *self, PyObject *args)
{
PyObject *po;
spoolss_policy_hnd_object *hnd;
WERROR result;
/* Parse parameters */
if (!PyArg_ParseTuple(args, "O!", &spoolss_policy_hnd_type, &po))
return NULL;
hnd = (spoolss_policy_hnd_object *)po;
/* Call rpc function */
result = cli_spoolss_close_printer(hnd->cli, hnd->mem_ctx, &hnd->pol);
/* Cleanup samba stuf */
cli_shutdown(hnd->cli);
talloc_destroy(hnd->mem_ctx);
/* Return value */
Py_INCREF(Py_None);
return Py_None;
}
/* Fetch printer information */
PyObject *spoolss_getprinter(PyObject *self, PyObject *args, PyObject *kw)
{
spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
WERROR werror;
PyObject *result = NULL;
PRINTER_INFO_CTR ctr;
int level = 1;
uint32 needed;
static char *kwlist[] = {"level", NULL};
/* Parse parameters */
if (!PyArg_ParseTupleAndKeywords(args, kw, "|i", kwlist, &level))
return NULL;
/* Call rpc function */
werror = cli_spoolss_getprinter(
hnd->cli, hnd->mem_ctx, 0, &needed, &hnd->pol, level, &ctr);
if (W_ERROR_V(werror) == ERRinsufficientbuffer)
werror = cli_spoolss_getprinter(
hnd->cli, hnd->mem_ctx, needed, NULL, &hnd->pol,
level, &ctr);
/* Return value */
if (!W_ERROR_IS_OK(werror)) {
PyErr_SetObject(spoolss_werror,
PyInt_FromLong(W_ERROR_V(werror)));
return NULL;
}
result = Py_None;
switch (level) {
case 0:
py_from_PRINTER_INFO_0(&result, ctr.printers_0);
break;
case 1:
py_from_PRINTER_INFO_1(&result, ctr.printers_1);
break;
case 2:
py_from_PRINTER_INFO_2(&result, ctr.printers_2);
break;
case 3:
py_from_PRINTER_INFO_3(&result, ctr.printers_3);
break;
}
PyDict_SetItemString(result, "level", PyInt_FromLong(level));
Py_INCREF(result);
return result;
}
/* Set printer information */
PyObject *spoolss_setprinter(PyObject *self, PyObject *args, PyObject *kw)
{
spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
WERROR werror;
PyObject *info, *level_obj;
PRINTER_INFO_CTR ctr;
uint32 level;
static char *kwlist[] = {"dict", NULL};
union {
PRINTER_INFO_0 printers_0;
PRINTER_INFO_1 printers_1;
PRINTER_INFO_2 printers_2;
PRINTER_INFO_3 printers_3;
PRINTER_INFO_4 printers_4;
PRINTER_INFO_5 printers_5;
} pinfo;
/* Parse parameters */
if (!PyArg_ParseTupleAndKeywords(args, kw, "O!", kwlist,
&PyDict_Type, &info))
return NULL;
/* Check dictionary contains a level */
if ((level_obj = PyDict_GetItemString(info, "level"))) {
if (!PyInt_Check(level_obj))
goto error;
level = PyInt_AsLong(level_obj);
} else {
error:
PyErr_SetString(spoolss_error, "invalid info");
return NULL;
}
/* Fill in printer info */
ZERO_STRUCT(ctr);
switch (level) {
case 2: {
PyObject *devmode_obj;
ctr.printers_2 = &pinfo.printers_2;
if (!py_to_PRINTER_INFO_2(&pinfo.printers_2, info))
goto error;
#if 0
devmode_obj = PyDict_GetItemString(info, "device_mode");
pinfo.printers_2.devmode = talloc(
hnd->mem_ctx, sizeof(DEVICEMODE));
PyDEVICEMODE_AsDEVICEMODE(pinfo.printers_2.devmode,
devmode_obj);
#else
/* FIXME: can we actually set the security descriptor using
a setprinter level 2? */
pinfo.printers_2.secdesc = NULL;
pinfo.printers_2.secdesc = NULL;
#endif
break;
}
default:
PyErr_SetString(spoolss_error, "unsupported info level");
return NULL;
}
/* Call rpc function */
werror = cli_spoolss_setprinter(hnd->cli, hnd->mem_ctx, &hnd->pol,
level, &ctr, 0);
/* Return value */
if (!W_ERROR_IS_OK(werror)) {
PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));
return NULL;
}
Py_INCREF(Py_None);
return Py_None;
}
/* Enumerate printers */
PyObject *spoolss_enumprinters(PyObject *self, PyObject *args, PyObject *kw)
{
WERROR werror;
PyObject *result, *creds = NULL;
PRINTER_INFO_CTR ctr;
int level = 1, flags = PRINTER_ENUM_LOCAL, i;
uint32 needed, num_printers;
static char *kwlist[] = {"server", "name", "level", "flags",
"creds", NULL};
TALLOC_CTX *mem_ctx = NULL;
struct cli_state *cli = NULL;
char *server, *name = NULL;
/* Parse parameters */
if (!PyArg_ParseTupleAndKeywords(args, kw, "s|siiO!", kwlist,
&server, &name, &level, &flags,
&PyDict_Type, &creds))
return NULL;
if (server[0] == '\\' && server[1] == '\\')
server += 2;
mem_ctx = talloc_init();
cli = open_pipe_creds(server, creds, cli_spoolss_initialise, NULL);
/* Call rpc function */
werror = cli_spoolss_enum_printers(
cli, mem_ctx, 0, &needed, flags, level,
&num_printers, &ctr);
if (W_ERROR_V(werror) == ERRinsufficientbuffer)
werror = cli_spoolss_enum_printers(
cli, mem_ctx, needed, NULL, flags, level,
&num_printers, &ctr);
/* Return value */
if (!W_ERROR_IS_OK(werror)) {
PyErr_SetObject(spoolss_werror,
PyInt_FromLong(W_ERROR_V(werror)));
return NULL;
}
result = PyList_New(num_printers);
switch (level) {
case 0:
for (i = 0; i < num_printers; i++) {
PyObject *value;
py_from_PRINTER_INFO_0(&value, &ctr.printers_0[i]);
PyList_SetItem(result, i, value);
}
break;
case 1:
for(i = 0; i < num_printers; i++) {
PyObject *value;
py_from_PRINTER_INFO_1(&value, &ctr.printers_1[i]);
PyList_SetItem(result, i, value);
}
break;
case 2:
for(i = 0; i < num_printers; i++) {
PyObject *value;
py_from_PRINTER_INFO_2(&value, &ctr.printers_2[i]);
PyList_SetItem(result, i, value);
}
break;
case 3:
for(i = 0; i < num_printers; i++) {
PyObject *value;
py_from_PRINTER_INFO_3(&value, &ctr.printers_3[i]);
PyList_SetItem(result, i, value);
}
break;
}
Py_INCREF(result);
return result;
}

View File

@ -1,367 +0,0 @@
/*
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 02139, USA.
*/
#include "python/py_spoolss.h"
#include "python/py_conv.h"
struct pyconv py_PRINTER_INFO_0[] = {
{ "printer_name", PY_UNISTR, offsetof(PRINTER_INFO_0, printername) },
{ "server_name", PY_UNISTR, offsetof(PRINTER_INFO_0, servername) },
{ "cjobs", PY_UINT32, offsetof(PRINTER_INFO_0, cjobs) },
{ "total_jobs", PY_UINT32, offsetof(PRINTER_INFO_0, total_jobs) },
{ "total_bytes", PY_UINT32, offsetof(PRINTER_INFO_0, total_bytes) },
{ "year", PY_UINT16, offsetof(PRINTER_INFO_0, year) },
{ "month", PY_UINT16, offsetof(PRINTER_INFO_0, month) },
{ "day_of_week", PY_UINT16, offsetof(PRINTER_INFO_0, dayofweek) },
{ "day", PY_UINT16, offsetof(PRINTER_INFO_0, day) },
{ "hour", PY_UINT16, offsetof(PRINTER_INFO_0, hour) },
{ "minute", PY_UINT16, offsetof(PRINTER_INFO_0, minute) },
{ "second", PY_UINT16, offsetof(PRINTER_INFO_0, second) },
{ "milliseconds", PY_UINT16, offsetof(PRINTER_INFO_0, milliseconds) },
{ "global_counter", PY_UINT32, offsetof(PRINTER_INFO_0, global_counter) },
{ "total_pages", PY_UINT32, offsetof(PRINTER_INFO_0, total_pages) },
{ "major_version", PY_UINT16, offsetof(PRINTER_INFO_0, major_version) },
{ "build_version", PY_UINT16, offsetof(PRINTER_INFO_0, build_version) },
{ "unknown7", PY_UINT32, offsetof(PRINTER_INFO_0, unknown7) },
{ "unknown8", PY_UINT32, offsetof(PRINTER_INFO_0, unknown8) },
{ "unknown9", PY_UINT32, offsetof(PRINTER_INFO_0, unknown9) },
{ "session_counter", PY_UINT32, offsetof(PRINTER_INFO_0, session_counter)},
{ "unknown11", PY_UINT32, offsetof(PRINTER_INFO_0, unknown11) },
{ "printer_errors", PY_UINT32, offsetof(PRINTER_INFO_0, printer_errors) },
{ "unknown13", PY_UINT32, offsetof(PRINTER_INFO_0, unknown13) },
{ "unknown14", PY_UINT32, offsetof(PRINTER_INFO_0, unknown14) },
{ "unknown15", PY_UINT32, offsetof(PRINTER_INFO_0, unknown15) },
{ "unknown16", PY_UINT32, offsetof(PRINTER_INFO_0, unknown16) },
{ "change_id", PY_UINT32, offsetof(PRINTER_INFO_0, change_id) },
{ "unknown18", PY_UINT32, offsetof(PRINTER_INFO_0, unknown18) },
{ "status", PY_UINT32, offsetof(PRINTER_INFO_0, status) },
{ "unknown20", PY_UINT32, offsetof(PRINTER_INFO_0, unknown20) },
{ "c_setprinter", PY_UINT32, offsetof(PRINTER_INFO_0, c_setprinter) },
{ "unknown22", PY_UINT32, offsetof(PRINTER_INFO_0, unknown22) },
{ "unknown23", PY_UINT32, offsetof(PRINTER_INFO_0, unknown23) },
{ "unknown24", PY_UINT32, offsetof(PRINTER_INFO_0, unknown24) },
{ "unknown25", PY_UINT32, offsetof(PRINTER_INFO_0, unknown25) },
{ "unknown26", PY_UINT32, offsetof(PRINTER_INFO_0, unknown26) },
{ "unknown27", PY_UINT32, offsetof(PRINTER_INFO_0, unknown27) },
{ "unknown28", PY_UINT32, offsetof(PRINTER_INFO_0, unknown28) },
{ "unknown29", PY_UINT32, offsetof(PRINTER_INFO_0, unknown29) },
{ NULL }
};
struct pyconv py_PRINTER_INFO_1[] = {
{ "printer_name", PY_UNISTR, offsetof(PRINTER_INFO_1, name) },
{ "description", PY_UNISTR, offsetof(PRINTER_INFO_1, description) },
{ "comment", PY_UNISTR, offsetof(PRINTER_INFO_1, comment) },
{ "flags", PY_UINT32, offsetof(PRINTER_INFO_1, flags) },
{ NULL }
};
struct pyconv py_PRINTER_INFO_2[] = {
{ "server_name", PY_UNISTR, offsetof(PRINTER_INFO_2, servername) },
{ "printer_name", PY_UNISTR, offsetof(PRINTER_INFO_2, printername) },
{ "share_name", PY_UNISTR, offsetof(PRINTER_INFO_2, sharename) },
{ "port_name", PY_UNISTR, offsetof(PRINTER_INFO_2, portname) },
{ "driver_name", PY_UNISTR, offsetof(PRINTER_INFO_2, drivername) },
{ "comment", PY_UNISTR, offsetof(PRINTER_INFO_2, comment) },
{ "location", PY_UNISTR, offsetof(PRINTER_INFO_2, location) },
{ "datatype", PY_UNISTR, offsetof(PRINTER_INFO_2, datatype) },
{ "sepfile", PY_UNISTR, offsetof(PRINTER_INFO_2, sepfile) },
{ "print_processor", PY_UNISTR, offsetof(PRINTER_INFO_2, printprocessor) },
{ "parameters", PY_UNISTR, offsetof(PRINTER_INFO_2, parameters) },
{ "attributes", PY_UINT32, offsetof(PRINTER_INFO_2, attributes) },
{ "default_priority", PY_UINT32, offsetof(PRINTER_INFO_2, defaultpriority) },
{ "priority", PY_UINT32, offsetof(PRINTER_INFO_2, priority) },
{ "start_time", PY_UINT32, offsetof(PRINTER_INFO_2, starttime) },
{ "until_time", PY_UINT32, offsetof(PRINTER_INFO_2, untiltime) },
{ "status", PY_UINT32, offsetof(PRINTER_INFO_2, status) },
{ "cjobs", PY_UINT32, offsetof(PRINTER_INFO_2, cjobs) },
{ "average_ppm", PY_UINT32, offsetof(PRINTER_INFO_2, averageppm) },
{ NULL }
};
struct pyconv py_PRINTER_INFO_3[] = {
{ "flags", PY_UINT32, offsetof(PRINTER_INFO_3, flags) },
{ NULL }
};
struct pyconv py_DEVICEMODE[] = {
{ "device_name", PY_UNISTR, offsetof(DEVICEMODE, devicename) },
{ "spec_version", PY_UINT16, offsetof(DEVICEMODE, specversion) },
{ "driver_version", PY_UINT16, offsetof(DEVICEMODE, driverversion) },
{ "size", PY_UINT16, offsetof(DEVICEMODE, size) },
{ "fields", PY_UINT16, offsetof(DEVICEMODE, fields) },
{ "orientation", PY_UINT16, offsetof(DEVICEMODE, orientation) },
{ "paper_size", PY_UINT16, offsetof(DEVICEMODE, papersize) },
{ "paper_width", PY_UINT16, offsetof(DEVICEMODE, paperwidth) },
{ "paper_length", PY_UINT16, offsetof(DEVICEMODE, paperlength) },
{ "scale", PY_UINT16, offsetof(DEVICEMODE, scale) },
{ "copies", PY_UINT16, offsetof(DEVICEMODE, copies) },
{ "default_source", PY_UINT16, offsetof(DEVICEMODE, defaultsource) },
{ "print_quality", PY_UINT16, offsetof(DEVICEMODE, printquality) },
{ "color", PY_UINT16, offsetof(DEVICEMODE, color) },
{ "duplex", PY_UINT16, offsetof(DEVICEMODE, duplex) },
{ "y_resolution", PY_UINT16, offsetof(DEVICEMODE, yresolution) },
{ "tt_option", PY_UINT16, offsetof(DEVICEMODE, ttoption) },
{ "collate", PY_UINT16, offsetof(DEVICEMODE, collate) },
{ "form_name", PY_UNISTR, offsetof(DEVICEMODE, formname) },
{ "log_pixels", PY_UINT16, offsetof(DEVICEMODE, logpixels) },
{ "bits_per_pel", PY_UINT32, offsetof(DEVICEMODE, bitsperpel) },
{ "pels_width", PY_UINT32, offsetof(DEVICEMODE, pelswidth) },
{ "pels_height", PY_UINT32, offsetof(DEVICEMODE, pelsheight) },
{ "display_flags", PY_UINT32, offsetof(DEVICEMODE, displayflags) },
{ "display_frequency", PY_UINT32, offsetof(DEVICEMODE, displayfrequency) },
{ "icm_method", PY_UINT32, offsetof(DEVICEMODE, icmmethod) },
{ "icm_intent", PY_UINT32, offsetof(DEVICEMODE, icmintent) },
{ "media_type", PY_UINT32, offsetof(DEVICEMODE, mediatype) },
{ "dither_type", PY_UINT32, offsetof(DEVICEMODE, dithertype) },
{ "reserved1", PY_UINT32, offsetof(DEVICEMODE, reserved1) },
{ "reserved2", PY_UINT32, offsetof(DEVICEMODE, reserved2) },
{ "panning_width", PY_UINT32, offsetof(DEVICEMODE, panningwidth) },
{ "panning_height", PY_UINT32, offsetof(DEVICEMODE, panningheight) },
{ NULL }
};
/* Convert a security descriptor to a Python dict */
BOOL py_from_SID(PyObject **obj, DOM_SID *sid)
{
fstring sidstr;
if (!sid) {
Py_INCREF(Py_None);
*obj = Py_None;
return True;
}
if (!sid_to_string(sidstr, sid))
return False;
*obj = PyString_FromString(sidstr);
return True;
}
BOOL py_to_SID(DOM_SID *sid, PyObject *dict)
{
return False;
}
BOOL py_from_ACE(PyObject **dict, SEC_ACE *ace)
{
PyObject *obj;
if (!ace) {
Py_INCREF(Py_None);
*dict = Py_None;
return True;
}
*dict = PyDict_New();
PyDict_SetItemString(*dict, "type", PyInt_FromLong(ace->type));
PyDict_SetItemString(*dict, "flags", PyInt_FromLong(ace->flags));
PyDict_SetItemString(*dict, "mask", PyInt_FromLong(ace->info.mask));
if (py_from_SID(&obj, &ace->trustee))
PyDict_SetItemString(*dict, "trustee", obj);
return True;
}
BOOL py_to_ACE(SEC_ACE *ace, PyObject *dict)
{
return False;
}
BOOL py_from_ACL(PyObject **dict, SEC_ACL *acl)
{
PyObject *ace_list;
int i;
if (!acl) {
Py_INCREF(Py_None);
*dict = Py_None;
return True;
}
*dict = PyDict_New();
PyDict_SetItemString(*dict, "revision", PyInt_FromLong(acl->revision));
ace_list = PyList_New(acl->num_aces);
for (i = 0; i < acl->num_aces; i++) {
PyObject *obj;
if (py_from_ACE(&obj, &acl->ace[i]))
PyList_SetItem(ace_list, i, obj);
}
PyDict_SetItemString(*dict, "ace_list", ace_list);
return True;
}
BOOL py_to_ACL(SEC_ACL *acl, PyObject *dict)
{
return False;
}
BOOL py_from_SECDESC(PyObject **dict, SEC_DESC *sd)
{
PyObject *obj;
*dict = PyDict_New();
PyDict_SetItemString(*dict, "revision", PyInt_FromLong(sd->revision));
PyDict_SetItemString(*dict, "type", PyInt_FromLong(sd->type));
if (py_from_SID(&obj, sd->owner_sid))
PyDict_SetItemString(*dict, "owner_sid", obj);
if (py_from_SID(&obj, sd->grp_sid))
PyDict_SetItemString(*dict, "group_sid", obj);
if (py_from_ACL(&obj, sd->dacl))
PyDict_SetItemString(*dict, "dacl", obj);
if (py_from_ACL(&obj, sd->sacl))
PyDict_SetItemString(*dict, "sacl", obj);
return True;
}
BOOL py_to_SECDESC(SEC_DESC *sd, PyObject *dict)
{
return False;
}
/*
* Convert between DEVICEMODE and Python
*/
BOOL py_from_DEVICEMODE(PyObject **dict, DEVICEMODE *devmode)
{
*dict = from_struct(devmode, py_DEVICEMODE);
PyDict_SetItemString(*dict, "private",
PyString_FromStringAndSize(
devmode->private, devmode->driverextra));
return True;
}
BOOL py_to_DEVICEMODE(DEVICEMODE *devmode, PyObject *dict)
{
PyObject *obj;
to_struct(devmode, dict, py_DEVICEMODE);
obj = PyDict_GetItemString(dict, "private");
if (!obj)
return False;
devmode->private = PyString_AsString(obj);
devmode->driverextra = PyString_Size(obj);
return True;
}
/*
* Convert between PRINTER_INFO_0 and Python
*/
BOOL py_from_PRINTER_INFO_0(PyObject **dict, PRINTER_INFO_0 *info)
{
*dict = from_struct(info, py_PRINTER_INFO_0);
return True;
}
BOOL py_to_PRINTER_INFO_0(PRINTER_INFO_0 *info, PyObject *dict)
{
return False;
}
/*
* Convert between PRINTER_INFO_1 and Python
*/
BOOL py_from_PRINTER_INFO_1(PyObject **dict, PRINTER_INFO_1 *info)
{
*dict = from_struct(info, py_PRINTER_INFO_1);
return True;
}
BOOL py_to_PRINTER_INFO_1(PRINTER_INFO_1 *info, PyObject *dict)
{
return False;
}
/*
* Convert between PRINTER_INFO_2 and Python
*/
BOOL py_from_PRINTER_INFO_2(PyObject **dict, PRINTER_INFO_2 *info)
{
PyObject *obj;
*dict = from_struct(info, py_PRINTER_INFO_2);
if (py_from_SECDESC(&obj, info->secdesc))
PyDict_SetItemString(*dict, "security_descriptor", obj);
if (py_from_DEVICEMODE(&obj, info->devmode))
PyDict_SetItemString(*dict, "device_mode", obj);
return True;
}
BOOL py_to_PRINTER_INFO_2(PRINTER_INFO_2 *info, PyObject *dict)
{
return False;
}
/*
* Convert between PRINTER_INFO_1 and Python
*/
BOOL py_from_PRINTER_INFO_3(PyObject **dict, PRINTER_INFO_3 *info)
{
PyObject *obj;
*dict = from_struct(info, py_PRINTER_INFO_3);
if (py_from_SECDESC(&obj, info->secdesc))
PyDict_SetItemString(*dict, "security_descriptor", obj);
return True;
}
BOOL py_to_PRINTER_INFO_3(PRINTER_INFO_3 *info, PyObject *dict)
{
return False;
}

View File

@ -1,91 +0,0 @@
#ifndef _PY_SPOOLSS_PROTO_H
#define _PY_SPOOLSS_PROTO_H
/* This file is automatically generated with "make proto". DO NOT EDIT */
/* The following definitions come from python/py_spoolss.c */
struct cli_state *open_pipe_creds(char *system_name, PyObject *creds,
cli_pipe_fn *connect_fn,
struct cli_state *cli);
PyObject *new_policy_hnd_object(struct cli_state *cli, TALLOC_CTX *mem_ctx,
POLICY_HND *pol);
void initspoolss(void);
/* The following definitions come from python/py_spoolss_drivers.c */
PyObject *spoolss_enumprinterdrivers(PyObject *self, PyObject *args,
PyObject *kw);
PyObject *spoolss_getprinterdriver(PyObject *self, PyObject *args,
PyObject *kw);
PyObject *spoolss_getprinterdriverdir(PyObject *self, PyObject *args,
PyObject *kw);
/* The following definitions come from python/py_spoolss_drivers_conv.c */
BOOL py_from_DRIVER_INFO_1(PyObject **dict, DRIVER_INFO_1 *info);
BOOL py_to_DRIVER_INFO_1(DRIVER_INFO_1 *info, PyObject *dict);
BOOL py_from_DRIVER_INFO_2(PyObject **dict, DRIVER_INFO_2 *info);
BOOL py_to_DRIVER_INFO_2(DRIVER_INFO_2 *info, PyObject *dict);
BOOL py_from_DRIVER_INFO_3(PyObject **dict, DRIVER_INFO_3 *info);
BOOL py_to_DRIVER_INFO_3(DRIVER_INFO_3 *info, PyObject *dict);
BOOL py_from_DRIVER_INFO_6(PyObject **dict, DRIVER_INFO_6 *info);
BOOL py_to_DRIVER_INFO_6(DRIVER_INFO_6 *info, PyObject *dict);
BOOL py_from_DRIVER_DIRECTORY_1(PyObject **dict, DRIVER_DIRECTORY_1 *info);
BOOL py_to_DRIVER_DIRECTORY_1(DRIVER_DIRECTORY_1 *info, PyObject *dict);
/* The following definitions come from python/py_spoolss_forms.c */
PyObject *spoolss_addform(PyObject *self, PyObject *args, PyObject *kw);
PyObject *spoolss_getform(PyObject *self, PyObject *args, PyObject *kw);
PyObject *spoolss_setform(PyObject *self, PyObject *args, PyObject *kw);
PyObject *spoolss_deleteform(PyObject *self, PyObject *args, PyObject *kw);
PyObject *spoolss_enumforms(PyObject *self, PyObject *args, PyObject *kw);
/* The following definitions come from python/py_spoolss_forms_conv.c */
BOOL py_from_FORM_1(PyObject **dict, FORM_1 *form);
BOOL py_to_FORM(FORM *form, PyObject *dict);
/* The following definitions come from python/py_spoolss_ports.c */
PyObject *spoolss_enumports(PyObject *self, PyObject *args, PyObject *kw);
/* The following definitions come from python/py_spoolss_ports_conv.c */
BOOL py_from_PORT_INFO_1(PyObject **dict, PORT_INFO_1 *info);
BOOL py_to_PORT_INFO_1(PORT_INFO_1 *info, PyObject *dict);
BOOL py_from_PORT_INFO_2(PyObject **dict, PORT_INFO_2 *info);
BOOL py_to_PORT_INFO_2(PORT_INFO_2 *info, PyObject *dict);
/* The following definitions come from python/py_spoolss_printers.c */
PyObject *spoolss_openprinter(PyObject *self, PyObject *args, PyObject *kw);
PyObject *spoolss_closeprinter(PyObject *self, PyObject *args);
PyObject *spoolss_getprinter(PyObject *self, PyObject *args, PyObject *kw);
PyObject *spoolss_setprinter(PyObject *self, PyObject *args, PyObject *kw);
PyObject *spoolss_enumprinters(PyObject *self, PyObject *args, PyObject *kw);
/* The following definitions come from python/py_spoolss_printers_conv.c */
BOOL py_from_SID(PyObject **obj, DOM_SID *sid);
BOOL py_to_SID(DOM_SID *sid, PyObject *dict);
BOOL py_from_ACE(PyObject **dict, SEC_ACE *ace);
BOOL py_to_ACE(SEC_ACE *ace, PyObject *dict);
BOOL py_from_ACL(PyObject **dict, SEC_ACL *acl);
BOOL py_to_ACL(SEC_ACL *acl, PyObject *dict);
BOOL py_from_SECDESC(PyObject **dict, SEC_DESC *sd);
BOOL py_to_SECDESC(SEC_DESC *sd, PyObject *dict);
BOOL py_from_DEVICEMODE(PyObject **dict, DEVICEMODE *devmode);
BOOL py_to_DEVICEMODE(DEVICEMODE *devmode, PyObject *dict);
BOOL py_from_PRINTER_INFO_0(PyObject **dict, PRINTER_INFO_0 *info);
BOOL py_to_PRINTER_INFO_0(PRINTER_INFO_0 *info, PyObject *dict);
BOOL py_from_PRINTER_INFO_1(PyObject **dict, PRINTER_INFO_1 *info);
BOOL py_to_PRINTER_INFO_1(PRINTER_INFO_1 *info, PyObject *dict);
BOOL py_from_PRINTER_INFO_2(PyObject **dict, PRINTER_INFO_2 *info);
BOOL py_to_PRINTER_INFO_2(PRINTER_INFO_2 *info, PyObject *dict);
BOOL py_from_PRINTER_INFO_3(PyObject **dict, PRINTER_INFO_3 *info);
BOOL py_to_PRINTER_INFO_3(PRINTER_INFO_3 *info, PyObject *dict);
#endif /* _PY_SPOOLSS_PROTO_H */

View File

@ -1,651 +0,0 @@
/*
Unix SMB/CIFS implementation.
Python wrapper for winbind client functions.
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 02139, USA.
*/
#include "includes.h"
#include "Python.h"
#include "py_common.h"
/*
* Exceptions raised by this module
*/
PyObject *winbind_error; /* A winbind call returned WINBINDD_ERROR */
/* Prototypes from common.h */
NSS_STATUS winbindd_request(int req_type,
struct winbindd_request *request,
struct winbindd_response *response);
/*
* Name <-> SID conversion
*/
/* Convert a name to a sid */
static PyObject *py_name_to_sid(PyObject *self, PyObject *args)
{
struct winbindd_request request;
struct winbindd_response response;
PyObject *result;
char *name, *p, *sep;
if (!PyArg_ParseTuple(args, "s", &name))
return NULL;
ZERO_STRUCT(request);
ZERO_STRUCT(response);
sep = lp_winbind_separator();
if ((p = strchr(name, sep[0]))) {
*p = 0;
fstrcpy(request.data.name.dom_name, name);
fstrcpy(request.data.name.name, p + 1);
} else {
fstrcpy(request.data.name.dom_name, lp_workgroup());
fstrcpy(request.data.name.name, name);
}
if (winbindd_request(WINBINDD_LOOKUPNAME, &request, &response)
!= NSS_STATUS_SUCCESS) {
PyErr_SetString(winbind_error, "lookup failed");
return NULL;
}
result = PyString_FromString(response.data.sid.sid);
return result;
}
/* Convert a sid to a name */
static PyObject *py_sid_to_name(PyObject *self, PyObject *args)
{
struct winbindd_request request;
struct winbindd_response response;
PyObject *result;
char *sid, *name;
if (!PyArg_ParseTuple(args, "s", &sid))
return NULL;
ZERO_STRUCT(request);
ZERO_STRUCT(response);
fstrcpy(request.data.sid, sid);
if (winbindd_request(WINBINDD_LOOKUPSID, &request, &response)
!= NSS_STATUS_SUCCESS) {
PyErr_SetString(winbind_error, "lookup failed");
return NULL;
}
asprintf(&name, "%s%s%s", response.data.name.dom_name,
lp_winbind_separator(), response.data.name.name);
result = PyString_FromString(name);
free(name);
return result;
}
/*
* Enumerate users/groups
*/
/* Enumerate domain users */
static PyObject *py_enum_domain_users(PyObject *self, PyObject *args)
{
struct winbindd_response response;
PyObject *result;
if (!PyArg_ParseTuple(args, ""))
return NULL;
ZERO_STRUCT(response);
if (winbindd_request(WINBINDD_LIST_USERS, NULL, &response)
!= NSS_STATUS_SUCCESS) {
PyErr_SetString(winbind_error, "lookup failed");
return NULL;
}
result = PyList_New(0);
if (response.extra_data) {
char *extra_data = response.extra_data;
fstring name;
while (next_token(&extra_data, name, ",", sizeof(fstring)))
PyList_Append(result, PyString_FromString(name));
}
return result;
}
/* Enumerate domain groups */
static PyObject *py_enum_domain_groups(PyObject *self, PyObject *args)
{
struct winbindd_response response;
PyObject *result = NULL;
if (!PyArg_ParseTuple(args, ""))
return NULL;
ZERO_STRUCT(response);
if (winbindd_request(WINBINDD_LIST_GROUPS, NULL, &response)
!= NSS_STATUS_SUCCESS) {
PyErr_SetString(winbind_error, "lookup failed");
return NULL;
}
result = PyList_New(0);
if (response.extra_data) {
char *extra_data = response.extra_data;
fstring name;
while (next_token(&extra_data, name, ",", sizeof(fstring)))
PyList_Append(result, PyString_FromString(name));
}
return result;
}
/*
* Miscellaneous domain related
*/
/* Enumerate domain groups */
static PyObject *py_enum_trust_dom(PyObject *self, PyObject *args)
{
struct winbindd_response response;
PyObject *result = NULL;
if (!PyArg_ParseTuple(args, ""))
return NULL;
ZERO_STRUCT(response);
if (winbindd_request(WINBINDD_LIST_TRUSTDOM, NULL, &response)
!= NSS_STATUS_SUCCESS) {
PyErr_SetString(winbind_error, "lookup failed");
return NULL;
}
result = PyList_New(0);
if (response.extra_data) {
char *extra_data = response.extra_data;
fstring name;
while (next_token(&extra_data, name, ",", sizeof(fstring)))
PyList_Append(result, PyString_FromString(name));
}
return result;
}
/* Check machine account password */
static PyObject *py_check_secret(PyObject *self, PyObject *args)
{
struct winbindd_response response;
if (!PyArg_ParseTuple(args, ""))
return NULL;
ZERO_STRUCT(response);
if (winbindd_request(WINBINDD_CHECK_MACHACC, NULL, &response)
!= NSS_STATUS_SUCCESS) {
PyErr_SetString(winbind_error, "lookup failed");
return NULL;
}
return PyInt_FromLong(response.data.num_entries);
}
/*
* Return a dictionary consisting of all the winbind related smb.conf
* parameters. This is stored in the module object.
*/
static PyObject *py_config_dict(void)
{
PyObject *result;
uid_t ulow, uhi;
gid_t glow, ghi;
if (!(result = PyDict_New()))
return NULL;
/* Various string parameters */
PyDict_SetItemString(result, "workgroup",
PyString_FromString(lp_workgroup()));
PyDict_SetItemString(result, "separator",
PyString_FromString(lp_winbind_separator()));
PyDict_SetItemString(result, "template_homedir",
PyString_FromString(lp_template_homedir()));
PyDict_SetItemString(result, "template_shell",
PyString_FromString(lp_template_shell()));
/* Winbind uid/gid range */
if (lp_winbind_uid(&ulow, &uhi)) {
PyDict_SetItemString(result, "uid_low", PyInt_FromLong(ulow));
PyDict_SetItemString(result, "uid_high", PyInt_FromLong(uhi));
}
if (lp_winbind_gid(&glow, &ghi)) {
PyDict_SetItemString(result, "gid_low", PyInt_FromLong(glow));
PyDict_SetItemString(result, "gid_high", PyInt_FromLong(ghi));
}
return result;
}
/*
* ID mapping
*/
/* Convert a uid to a SID */
static PyObject *py_uid_to_sid(PyObject *self, PyObject *args)
{
struct winbindd_request request;
struct winbindd_response response;
int id;
if (!PyArg_ParseTuple(args, "i", &id))
return NULL;
ZERO_STRUCT(request);
ZERO_STRUCT(response);
request.data.uid = id;
if (winbindd_request(WINBINDD_UID_TO_SID, &request, &response)
!= NSS_STATUS_SUCCESS) {
PyErr_SetString(winbind_error, "lookup failed");
return NULL;
}
return PyString_FromString(response.data.sid.sid);
}
/* Convert a gid to a SID */
static PyObject *py_gid_to_sid(PyObject *self, PyObject *args)
{
struct winbindd_request request;
struct winbindd_response response;
int id;
if (!PyArg_ParseTuple(args, "i", &id))
return NULL;
ZERO_STRUCT(request);
ZERO_STRUCT(response);
request.data.gid = id;
if (winbindd_request(WINBINDD_GID_TO_SID, &request, &response)
!= NSS_STATUS_SUCCESS) {
PyErr_SetString(winbind_error, "lookup failed");
return NULL;
}
return PyString_FromString(response.data.sid.sid);
}
/* Convert a sid to a uid */
static PyObject *py_sid_to_uid(PyObject *self, PyObject *args)
{
struct winbindd_request request;
struct winbindd_response response;
char *sid;
if (!PyArg_ParseTuple(args, "s", &sid))
return NULL;
ZERO_STRUCT(request);
ZERO_STRUCT(response);
fstrcpy(request.data.sid, sid);
if (winbindd_request(WINBINDD_SID_TO_UID, &request, &response)
!= NSS_STATUS_SUCCESS) {
PyErr_SetString(winbind_error, "lookup failed");
return NULL;
}
return PyInt_FromLong(response.data.uid);
}
/* Convert a sid to a gid */
static PyObject *py_sid_to_gid(PyObject *self, PyObject *args)
{
struct winbindd_request request;
struct winbindd_response response;
char *sid;
if (!PyArg_ParseTuple(args, "s", &sid))
return NULL;
ZERO_STRUCT(request);
ZERO_STRUCT(response);
fstrcpy(request.data.sid, sid);
if (winbindd_request(WINBINDD_SID_TO_GID, &request, &response)
!= NSS_STATUS_SUCCESS) {
PyErr_SetString(winbind_error, "lookup failed");
return NULL;
}
return PyInt_FromLong(response.data.gid);
}
/*
* PAM authentication functions
*/
/* Plaintext authentication */
static PyObject *py_auth_plaintext(PyObject *self, PyObject *args)
{
struct winbindd_request request;
struct winbindd_response response;
char *username, *password;
if (!PyArg_ParseTuple(args, "ss", &username, &password))
return NULL;
ZERO_STRUCT(request);
ZERO_STRUCT(response);
fstrcpy(request.data.auth.user, username);
fstrcpy(request.data.auth.pass, password);
if (winbindd_request(WINBINDD_PAM_AUTH, &request, &response)
!= NSS_STATUS_SUCCESS) {
PyErr_SetString(winbind_error, "lookup failed");
return NULL;
}
return PyInt_FromLong(response.data.auth.nt_status);
}
/* Challenge/response authentication */
static PyObject *py_auth_crap(PyObject *self, PyObject *args)
{
struct winbindd_request request;
struct winbindd_response response;
char *username, *password;
if (!PyArg_ParseTuple(args, "ss", &username, &password))
return NULL;
ZERO_STRUCT(request);
ZERO_STRUCT(response);
fstrcpy(request.data.auth_crap.user, username);
generate_random_buffer(request.data.auth_crap.chal, 8, False);
SMBencrypt((uchar *)password, request.data.auth_crap.chal,
(uchar *)request.data.auth_crap.lm_resp);
SMBNTencrypt((uchar *)password, request.data.auth_crap.chal,
(uchar *)request.data.auth_crap.nt_resp);
request.data.auth_crap.lm_resp_len = 24;
request.data.auth_crap.nt_resp_len = 24;
if (winbindd_request(WINBINDD_PAM_AUTH_CRAP, &request, &response)
!= NSS_STATUS_SUCCESS) {
PyErr_SetString(winbind_error, "lookup failed");
return NULL;
}
return PyInt_FromLong(response.data.auth.nt_status);
}
/*
* Method dispatch table
*/
static PyMethodDef winbind_methods[] = {
/* Name <-> SID conversion */
{ "name_to_sid", py_name_to_sid, METH_VARARGS,
"name_to_sid(s) -> string
Return the SID for a name.
Example:
>>> winbind.name_to_sid('FOO/Administrator')
'S-1-5-21-406022937-1377575209-526660263-500' " },
{ "sid_to_name", py_sid_to_name, METH_VARARGS,
"sid_to_name(s) -> string
Return the name for a SID.
Example:
>>> import winbind
>>> winbind.sid_to_name('S-1-5-21-406022937-1377575209-526660263-500')
'FOO/Administrator' " },
/* Enumerate users/groups */
{ "enum_domain_users", py_enum_domain_users, METH_VARARGS,
"enum_domain_users() -> list of strings
Return a list of domain users.
Example:
>>> winbind.enum_domain_users()
['FOO/Administrator', 'FOO/anna', 'FOO/Anne Elk', 'FOO/build',
'FOO/foo', 'FOO/foo2', 'FOO/foo3', 'FOO/Guest', 'FOO/user1',
'FOO/whoops-ptang'] " },
{ "enum_domain_groups", py_enum_domain_groups, METH_VARARGS,
"enum_domain_groups() -> list of strings
Return a list of domain groups.
Example:
>>> winbind.enum_domain_groups()
['FOO/cows', 'FOO/Domain Admins', 'FOO/Domain Guests',
'FOO/Domain Users'] " },
/* ID mapping */
{ "uid_to_sid", py_uid_to_sid, METH_VARARGS,
"uid_to_sid(int) -> string
Return the SID for a UNIX uid.
Example:
>>> winbind.uid_to_sid(10000)
'S-1-5-21-406022937-1377575209-526660263-500' " },
{ "gid_to_sid", py_gid_to_sid, METH_VARARGS,
"gid_to_sid(int) -> string
Return the UNIX gid for a SID.
Example:
>>> winbind.gid_to_sid(10001)
'S-1-5-21-406022937-1377575209-526660263-512' " },
{ "sid_to_uid", py_sid_to_uid, METH_VARARGS,
"sid_to_uid(string) -> int
Return the UNIX uid for a SID.
Example:
>>> winbind.sid_to_uid('S-1-5-21-406022937-1377575209-526660263-500')
10000 " },
{ "sid_to_gid", py_sid_to_gid, METH_VARARGS,
"sid_to_gid(string) -> int
Return the UNIX gid corresponding to a SID.
Example:
>>> winbind.sid_to_gid('S-1-5-21-406022937-1377575209-526660263-512')
10001 " },
/* Miscellaneous */
{ "check_secret", py_check_secret, METH_VARARGS,
"check_secret() -> int
Check the machine trust account password. The NT status is returned
with zero indicating success. " },
{ "enum_trust_dom", py_enum_trust_dom, METH_VARARGS,
"enum_trust_dom() -> list of strings
Return a list of trusted domains. The domain the server is a member
of is not included.
Example:
>>> winbind.enum_trust_dom()
['NPSD-TEST2', 'SP2NDOM'] " },
/* PAM authorisation functions */
{ "auth_plaintext", py_auth_plaintext, METH_VARARGS,
"auth_plaintext(s, s) -> int
Authenticate a username and password using plaintext authentication.
The NT status code is returned with zero indicating success." },
{ "auth_crap", py_auth_crap, METH_VARARGS,
"auth_crap(s, s) -> int
Authenticate a username and password using the challenge/response
protocol. The NT status code is returned with zero indicating
success." },
{ NULL }
};
static struct winbind_const {
char *name;
uint32 value;
char *docstring;
} winbind_const_vals[] = {
/* Well known RIDs */
{ "DOMAIN_USER_RID_ADMIN", DOMAIN_USER_RID_ADMIN,
"Well-known RID for Administrator user" },
{ "DOMAIN_USER_RID_GUEST", DOMAIN_USER_RID_GUEST,
"Well-known RID for Guest user" },
{ "DOMAIN_GROUP_RID_ADMINS", DOMAIN_GROUP_RID_ADMINS,
"Well-known RID for Domain Admins group" },
{ "DOMAIN_GROUP_RID_USERS", DOMAIN_GROUP_RID_USERS,
"Well-known RID for Domain Users group" },
{ "DOMAIN_GROUP_RID_GUESTS", DOMAIN_GROUP_RID_GUESTS,
"Well-known RID for Domain Guests group" },
{ NULL }
};
static void const_init(PyObject *dict)
{
struct winbind_const *tmp;
PyObject *obj;
for (tmp = winbind_const_vals; tmp->name; tmp++) {
obj = PyInt_FromLong(tmp->value);
PyDict_SetItemString(dict, tmp->name, obj);
Py_DECREF(obj);
}
}
/*
* Module initialisation
*/
static char winbind_module__doc__[] =
"A python extension to winbind client functions.";
void initwinbind(void)
{
PyObject *module, *dict;
/* Initialise module */
module = Py_InitModule3("winbind", winbind_methods,
winbind_module__doc__);
dict = PyModule_GetDict(module);
winbind_error = PyErr_NewException("winbind.error", NULL, NULL);
PyDict_SetItemString(dict, "error", winbind_error);
/* Do samba initialisation */
py_samba_init();
/* Initialise constants */
const_init(dict);
/* Insert configuration dictionary */
PyDict_SetItemString(dict, "config", py_config_dict());
}

View File

@ -1,53 +0,0 @@
Index: Makefile.in
===================================================================
RCS file: /data/cvs/samba/source/Makefile.in,v
retrieving revision 1.465
diff -u -r1.465 Makefile.in
--- Makefile.in 2002/04/04 22:58:56 1.465
+++ Makefile.in 2002/04/05 05:48:51
@@ -785,6 +785,29 @@
-$(INSTALLCMD) -d ${prefix}/include
-$(INSTALLCMD) include/libsmbclient.h ${prefix}/include
+# Python extensions
+
+PYTHON_OBJS = $(LIB_OBJ) $(LIBSMB_OBJ) $(RPC_PARSE_OBJ) $(UBIQX_OBJ) \
+ $(PARAM_OBJ) $(LIBMSRPC_OBJ) $(PASSDB_OBJ) $(GROUPDB_OBJ)
+
+PY_SPOOLSS_PROTO_OBJ = python/py_spoolss.o \
+ python/py_spoolss_printers.o python/py_spoolss_printers_conv.o\
+ python/py_spoolss_forms.o python/py_spoolss_forms_conv.o \
+ python/py_spoolss_ports.o python/py_spoolss_ports_conv.o \
+ python/py_spoolss_drivers.o python/py_spoolss_drivers_conv.o \
+
+python_proto: python_spoolss_proto
+
+python_spoolss_proto:
+ @cd $(srcdir) && $(SHELL) script/mkproto.sh $(AWK) \
+ -h _PY_SPOOLSS_PROTO_H python/py_spoolss_proto.h \
+ $(PY_SPOOLSS_PROTO_OBJ)
+
+python_ext: $(PYTHON_OBJS)
+ @echo python python/setup.py build
+ @PYTHON_OBJS="$(PYTHON_OBJS)" PYTHON_CFLAGS="$(CFLAGS) $(CPPFLAGS)" \
+ python python/setup.py build
+
# revert to the previously installed version
revert:
@$(SHELL) $(srcdir)/script/revert.sh $(SBINDIR) $(SPROGS)
Index: configure.in
===================================================================
RCS file: /data/cvs/samba/source/configure.in,v
retrieving revision 1.298
diff -u -r1.298 configure.in
--- configure.in 2002/04/04 05:47:41 1.298
+++ configure.in 2002/04/05 05:48:52
@@ -2695,7 +2695,7 @@
builddir=`pwd`
AC_SUBST(builddir)
-AC_OUTPUT(include/stamp-h Makefile)
+AC_OUTPUT(include/stamp-h Makefile python/setup.py)
#################################################
# Print very concise instructions on building/use

View File

@ -1,122 +0,0 @@
# -*- mode: python -*-
#
# Unix SMB/CIFS implementation.
# Module packaging setup for Samba python extensions
#
# 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 02139, USA.
#
from distutils.core import setup
from distutils.extension import Extension
import sys, string, os
# The Makefile passes in environment variable $PYTHON_OBJ as being the
# list of Samba objects. This kind of goes against the distutils.cmd
# method of adding setup commands and will also confuse people who are
# familiar with the python Distutils module.
samba_objs = ""
if os.environ.has_key("PYTHON_OBJS"):
samba_objs = os.environ.get("PYTHON_OBJS")
samba_cflags = ""
if os.environ.has_key("PYTHON_CFLAGS"):
samba_cflags = os.environ.get("PYTHON_CFLAGS")
samba_srcdir = ""
if os.environ.has_key("SRCDIR"):
samba_srcdir = os.environ.get("SRCDIR")
# These variables are filled in by configure
samba_libs = "@LIBS@"
# Convert libs and objs from space separated strings to lists of strings
# for distutils to digest. Split "-l" prefix off library list.
obj_list = string.split(samba_objs)
lib_list = []
for lib in string.split(samba_libs):
lib_list.append(string.replace(lib, "-l", ""))
flags_list = string.split(samba_cflags)
# Invoke distutils.setup
setup(
# Overview information
name = "Samba Python Extensions",
version = "0.1",
author = "Tim Potter",
author_email = "tpot@samba.org",
license = "GPL",
# Build info
include_dirs = [samba_srcdir + '.', samba_srcdir + "include",
samba_srcdir + "ubiqx", samba_srcdir + "smbwrapper",
samba_srcdir + "popt", "/usr/kerberos/include",
"/usr/local/include"],
# Module list
ext_modules = [
# SPOOLSS pipe module
Extension(name = "spoolss",
sources = [samba_srcdir + "python/py_spoolss.c",
samba_srcdir + "python/py_common.c",
samba_srcdir + "python/py_conv.c",
samba_srcdir + "python/py_spoolss_forms.c",
samba_srcdir + "python/py_spoolss_forms_conv.c",
samba_srcdir + "python/py_spoolss_drivers.c",
samba_srcdir + "python/py_spoolss_drivers_conv.c",
samba_srcdir + "python/py_spoolss_printers.c",
samba_srcdir + "python/py_spoolss_printers_conv.c",
samba_srcdir + "python/py_spoolss_ports.c",
samba_srcdir + "python/py_spoolss_ports_conv.c",
],
libraries = lib_list,
library_dirs = ["/usr/kerberos/lib"],
extra_objects = obj_list),
# LSA pipe module
Extension(name = "lsa",
sources = [samba_srcdir + "python/py_lsa.c",
samba_srcdir + "python/py_common.c"],
libraries = lib_list,
library_dirs = ["/usr/kerberos/lib"],
extra_objects = obj_list),
# winbind client module
Extension(name = "winbind",
sources = [samba_srcdir + "python/py_winbind.c",
samba_srcdir + "python/py_common.c"],
libraries = lib_list,
library_dirs = ["/usr/kerberos/lib"],
extra_objects = obj_list,
extra_compile_args = flags_list),
]
)

View File

@ -0,0 +1,201 @@
/*
Unix SMB/CIFS implementation.
SMB torture tester - mangling test
Copyright (C) Andrew Tridgell 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 02139, USA.
*/
#include "includes.h"
static TDB_CONTEXT *tdb;
#define NAME_LENGTH 20
static unsigned total, collisions, failures;
static BOOL test_one(struct cli_state *cli, const char *name)
{
int fnum;
fstring shortname;
fstring name2;
NTSTATUS status;
TDB_DATA data;
total++;
fnum = cli_open(cli, name, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
if (fnum == -1) {
printf("open of %s failed (%s)\n", name, cli_errstr(cli));
return False;
}
if (!cli_close(cli, fnum)) {
printf("close of %s failed (%s)\n", name, cli_errstr(cli));
return False;
}
/* get the short name */
status = cli_qpathinfo_alt_name(cli, name, shortname);
if (!NT_STATUS_IS_OK(status)) {
printf("query altname of %s failed (%s)\n", name, cli_errstr(cli));
return False;
}
snprintf(name2, sizeof(name2), "\\mangle_test\\%s", shortname);
if (!cli_unlink(cli, name2)) {
printf("unlink of %s (%s) failed (%s)\n",
name2, name, cli_errstr(cli));
return False;
}
/* recreate by short name */
fnum = cli_open(cli, name2, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
if (fnum == -1) {
printf("open2 of %s failed (%s)\n", name2, cli_errstr(cli));
return False;
}
if (!cli_close(cli, fnum)) {
printf("close of %s failed (%s)\n", name, cli_errstr(cli));
return False;
}
/* and unlink by long name */
if (!cli_unlink(cli, name)) {
printf("unlink2 of %s (%s) failed (%s)\n",
name, name2, cli_errstr(cli));
failures++;
cli_unlink(cli, name2);
return True;
}
/* see if the short name is already in the tdb */
data = tdb_fetch_by_string(tdb, shortname);
if (data.dptr) {
/* maybe its a duplicate long name? */
if (strcasecmp(name, data.dptr) != 0) {
/* we have a collision */
collisions++;
printf("Collision between %s and %s -> %s\n",
name, data.dptr, shortname);
}
free(data.dptr);
} else {
/* store it for later */
tdb_store_by_string(tdb, shortname, name, strlen(name)+1);
}
return True;
}
static void gen_name(char *name)
{
const char *chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz._-$~...";
unsigned max_idx = strlen(chars);
unsigned len;
int i;
char *p;
fstrcpy(name, "\\mangle_test\\");
p = name + strlen(name);
len = 1 + random() % NAME_LENGTH;
for (i=0;i<len;i++) {
p[i] = chars[random() % max_idx];
}
p[i] = 0;
if (strcmp(p, ".") == 0 || strcmp(p, "..") == 0) {
p[0] = '_';
}
/* have a high probability of a common lead char */
if (random() % 2 == 0) {
p[0] = 'A';
}
/* and a medium probability of a common lead string */
if (random() % 10 == 0) {
strncpy(p, "ABCDE", 5);
}
/* and a high probability of a good extension length */
if (random() % 2 == 0) {
char *s = strrchr(p, '.');
if (s) {
s[4] = 0;
}
}
}
BOOL torture_mangle(int dummy)
{
extern int torture_numops;
static struct cli_state cli;
int i;
printf("starting mangle test\n");
if (!torture_open_connection(&cli)) {
return False;
}
/* we will use an internal tdb to store the names we have used */
tdb = tdb_open(NULL, 100000, TDB_INTERNAL, 0, 0);
if (!tdb) {
printf("ERROR: Failed to open tdb\n");
return False;
}
cli_unlink(&cli, "\\mangle_test\\*");
cli_rmdir(&cli, "\\mangle_test");
if (!cli_mkdir(&cli, "\\mangle_test")) {
printf("ERROR: Failed to make directory\n");
return False;
}
for (i=0;i<torture_numops;i++) {
fstring name;
gen_name(name);
if (!test_one(&cli, name)) {
break;
}
if (total && total % 100 == 0) {
printf("collisions %u/%u - %.2f%% (%u failures)\r",
collisions, total, (100.0*collisions) / total, failures);
}
}
cli_unlink(&cli, "\\mangle_test\\*");
if (!cli_rmdir(&cli, "\\mangle_test")) {
printf("ERROR: Failed to remove directory\n");
return False;
}
printf("\nTotal collisions %u/%u - %.2f%% (%u failures)\n",
collisions, total, (100.0*collisions) / total, failures);
torture_close_connection(&cli);
printf("mangle test finished\n");
return (failures == 0);
}