py_samr.c

来自「samba-3.0.22.tar.gz 编译smb服务器的源码」· C语言 代码 · 共 677 行 · 第 1/2 页

C
677
字号
/*    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_samr.h"/*  * Exceptions raised by this module  */PyObject *samr_error;		/* This indicates a non-RPC related error				   such as name lookup failure */PyObject *samr_ntstatus;	/* This exception is raised when a RPC call				   returns a status code other than				   NT_STATUS_OK *//* SAMR group handle object */static void py_samr_group_hnd_dealloc(PyObject* self){	PyObject_Del(self);}static PyMethodDef samr_group_methods[] = {	{ NULL }};static PyObject *py_samr_group_hnd_getattr(PyObject *self, char *attrname){	return Py_FindMethod(samr_group_methods, self, attrname);}PyTypeObject samr_group_hnd_type = {	PyObject_HEAD_INIT(NULL)	0,	"SAMR Group Handle",	sizeof(samr_group_hnd_object),	0,	py_samr_group_hnd_dealloc, /*tp_dealloc*/	0,          /*tp_print*/	py_samr_group_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 */};PyObject *new_samr_group_hnd_object(struct cli_state *cli, TALLOC_CTX *mem_ctx,				      POLICY_HND *pol){	samr_group_hnd_object *o;	o = PyObject_New(samr_group_hnd_object, &samr_group_hnd_type);	o->cli = cli;	o->mem_ctx = mem_ctx;	memcpy(&o->group_pol, pol, sizeof(POLICY_HND));	return (PyObject*)o;}/* Alias handle object */static void py_samr_alias_hnd_dealloc(PyObject* self){	PyObject_Del(self);}static PyMethodDef samr_alias_methods[] = {	{ NULL }};static PyObject *py_samr_alias_hnd_getattr(PyObject *self, char *attrname){	return Py_FindMethod(samr_alias_methods, self, attrname);}PyTypeObject samr_alias_hnd_type = {	PyObject_HEAD_INIT(NULL)	0,	"SAMR Alias Handle",	sizeof(samr_alias_hnd_object),	0,	py_samr_alias_hnd_dealloc, /*tp_dealloc*/	0,          /*tp_print*/	py_samr_alias_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 */};PyObject *new_samr_alias_hnd_object(struct cli_state *cli, TALLOC_CTX *mem_ctx,				      POLICY_HND *pol){	samr_alias_hnd_object *o;	o = PyObject_New(samr_alias_hnd_object, &samr_alias_hnd_type);	o->cli = cli;	o->mem_ctx = mem_ctx;	memcpy(&o->alias_pol, pol, sizeof(POLICY_HND));	return (PyObject*)o;}/* SAMR user handle object */static void py_samr_user_hnd_dealloc(PyObject* self){	PyObject_Del(self);}static PyObject *samr_set_user_info2(PyObject *self, PyObject *args, 				     PyObject *kw){	samr_user_hnd_object *user_hnd = (samr_user_hnd_object *)self;	static char *kwlist[] = { "dict", NULL };	PyObject *info, *result = NULL;	SAM_USERINFO_CTR ctr;	TALLOC_CTX *mem_ctx;	uchar sess_key[16];	NTSTATUS ntstatus;	int level;	union {		SAM_USER_INFO_16 id16;		SAM_USER_INFO_21 id21;	} pinfo;	if (!PyArg_ParseTupleAndKeywords(		    args, kw, "O!", kwlist, &PyDict_Type, &info))		return NULL;	if (!get_level_value(info, &level)) {		PyErr_SetString(samr_error, "invalid info level");		return NULL;	}		ZERO_STRUCT(ctr);	ctr.switch_value = level;	switch(level) {	case 16:		ctr.info.id16 = &pinfo.id16;				if (!py_to_SAM_USER_INFO_16(ctr.info.id16, info)) {			PyErr_SetString(				samr_error, "error converting user info");			goto done;		}				break;	case 21:		ctr.info.id21 = &pinfo.id21;		if (!py_to_SAM_USER_INFO_21(ctr.info.id21, info)) {			PyErr_SetString(				samr_error, "error converting user info");			goto done;		}		break;	default:		PyErr_SetString(samr_error, "unsupported info level");		goto done;	}	/* Call RPC function */	if (!(mem_ctx = talloc_init("samr_set_user_info2"))) {		PyErr_SetString(			samr_error, "unable to init talloc context\n");		goto done;	}	ntstatus = rpccli_samr_set_userinfo2(		user_hnd->cli, mem_ctx, &user_hnd->user_pol, level,		sess_key, &ctr);	talloc_destroy(mem_ctx);	if (!NT_STATUS_IS_OK(ntstatus)) {		PyErr_SetObject(samr_ntstatus, py_ntstatus_tuple(ntstatus));		goto done;	}	Py_INCREF(Py_None);	result = Py_None;	done:	return result;}static PyObject *samr_delete_dom_user(PyObject *self, PyObject *args, 				      PyObject *kw){	samr_user_hnd_object *user_hnd = (samr_user_hnd_object *)self;	static char *kwlist[] = { NULL };	NTSTATUS ntstatus;	TALLOC_CTX *mem_ctx;	PyObject *result = NULL;		if (!PyArg_ParseTupleAndKeywords(		    args, kw, "", kwlist))		return NULL;	if (!(mem_ctx = talloc_init("samr_delete_dom_user"))) {		PyErr_SetString(samr_error, "unable to init talloc context");		return NULL;	}	ntstatus = rpccli_samr_delete_dom_user(		user_hnd->cli, mem_ctx, &user_hnd->user_pol);	if (!NT_STATUS_IS_OK(ntstatus)) {		PyErr_SetObject(samr_ntstatus, py_ntstatus_tuple(ntstatus));		goto done;	}	Py_INCREF(Py_None);	result = Py_None;done:	talloc_destroy(mem_ctx);	return result;}static PyMethodDef samr_user_methods[] = {	{ "delete_domain_user", (PyCFunction)samr_delete_dom_user,	  METH_VARARGS | METH_KEYWORDS,	  "Delete domain user." },	{ "set_user_info2", (PyCFunction)samr_set_user_info2,	  METH_VARARGS | METH_KEYWORDS,	  "Set user info 2" },	{ NULL }};static PyObject *py_samr_user_hnd_getattr(PyObject *self, char *attrname){	return Py_FindMethod(samr_user_methods, self, attrname);}PyTypeObject samr_user_hnd_type = {	PyObject_HEAD_INIT(NULL)	0,	"SAMR User Handle",	sizeof(samr_user_hnd_object),	0,	py_samr_user_hnd_dealloc, /*tp_dealloc*/	0,          /*tp_print*/	py_samr_user_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 */};PyObject *new_samr_user_hnd_object(struct cli_state *cli, TALLOC_CTX *mem_ctx,				   POLICY_HND *pol){	samr_user_hnd_object *o;	o = PyObject_New(samr_user_hnd_object, &samr_user_hnd_type);	o->cli = cli;	o->mem_ctx = mem_ctx;	memcpy(&o->user_pol, pol, sizeof(POLICY_HND));	return (PyObject*)o;}/* SAMR connect handle object */static void py_samr_connect_hnd_dealloc(PyObject* self){	PyObject_Del(self);}PyObject *new_samr_domain_hnd_object(struct cli_state *cli, TALLOC_CTX *mem_ctx,				     POLICY_HND *pol){	samr_domain_hnd_object *o;	o = PyObject_New(samr_domain_hnd_object, &samr_domain_hnd_type);	o->cli = cli;	o->mem_ctx = mem_ctx;	memcpy(&o->domain_pol, pol, sizeof(POLICY_HND));	return (PyObject*)o;}static PyObject *samr_open_domain(PyObject *self, PyObject *args, PyObject *kw){	samr_connect_hnd_object *connect_hnd = (samr_connect_hnd_object *)self;	static char *kwlist[] = { "sid", "access", NULL };	uint32 desired_access = MAXIMUM_ALLOWED_ACCESS;	char *sid_str;	DOM_SID sid;	TALLOC_CTX *mem_ctx = NULL;	POLICY_HND domain_pol;	NTSTATUS ntstatus;	PyObject *result = NULL;	if (!PyArg_ParseTupleAndKeywords(		    args, kw, "s|i", kwlist, &sid_str, &desired_access))		return NULL;	if (!string_to_sid(&sid, sid_str)) {		PyErr_SetString(PyExc_TypeError, "string is not a sid");		return NULL;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?