1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-23 17:34:34 +03:00

Convert credentials Python module to "manual" C - no SWIG used to generate

the C code.
This commit is contained in:
Jelmer Vernooij 2008-12-21 05:29:23 +01:00
parent 33ebc95591
commit 263c6670fc
6 changed files with 350 additions and 4719 deletions

View File

@ -14,11 +14,9 @@ $(eval $(call proto_header_template,$(authsrcdir)/credentials/credentials_proto.
PUBLIC_HEADERS += $(authsrcdir)/credentials/credentials.h
[PYTHON::swig_credentials]
LIBRARY_REALNAME = samba/_credentials.$(SHLIBEXT)
PUBLIC_DEPENDENCIES = CREDENTIALS LIBCMDLINE_CREDENTIALS
LIBRARY_REALNAME = samba/credentials.$(SHLIBEXT)
PUBLIC_DEPENDENCIES = CREDENTIALS LIBCMDLINE_CREDENTIALS PYTALLOC param
$(eval $(call python_py_module_template,samba/credentials.py,$(authsrcdir)/credentials/credentials.py))
swig_credentials_OBJ_FILES = $(authsrcdir)/credentials/pycredentials.o
swig_credentials_OBJ_FILES = $(authsrcdir)/credentials/credentials_wrap.o
$(swig_credentials_OBJ_FILES): CFLAGS+=$(CFLAG_NO_UNUSED_MACROS) $(CFLAG_NO_CAST_QUAL)
$(swig_credentials_OBJ_FILES): CFLAGS+=$(CFLAG_NO_CAST_QUAL)

View File

@ -1,147 +0,0 @@
/*
Unix SMB/CIFS implementation.
Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
%module(docstring="Credentials management.",package="samba.credentials") credentials
%{
/* Include headers */
#include <stdint.h>
#include <stdbool.h>
#include "includes.h"
#include "auth/credentials/credentials.h"
#include "param/param.h"
#include "lib/cmdline/credentials.h"
typedef struct cli_credentials cli_credentials;
%}
%import "carrays.i"
%import "typemaps.i"
%import "param/param.i"
%typemap(default,noblock=1) struct cli_credentials * {
$1 = NULL;
}
%constant int AUTO_USE_KERBEROS = CRED_AUTO_USE_KERBEROS;
%constant int DONT_USE_KERBEROS = CRED_DONT_USE_KERBEROS;
%constant int MUST_USE_KERBEROS = CRED_MUST_USE_KERBEROS;
%{
#include "librpc/gen_ndr/samr.h" /* for struct samr_Password */
%}
%typemap(out,noblock=1) struct samr_Password * {
$result = PyString_FromStringAndSize((char *)$1->hash, 16);
}
%talloctype(cli_credentials);
%rename(Credentials) cli_credentials;
typedef struct cli_credentials {
%extend {
cli_credentials(void) {
return cli_credentials_init(NULL);
}
/* username */
%feature("docstring") get_username "S.get_username() -> username\nObtain username.";
const char *get_username(void);
%feature("docstring") set_username "S.set_username(name, obtained=CRED_SPECIFIED) -> None\nChange username.";
bool set_username(const char *value,
enum credentials_obtained obtained=CRED_SPECIFIED);
/* password */
%feature("docstring") get_password "S.get_password() -> password\n" \
"Obtain password.";
const char *get_password(void);
%feature("docstring") set_password "S.set_password(password, obtained=CRED_SPECIFIED) -> None\n" \
"Change password.";
bool set_password(const char *val,
enum credentials_obtained obtained=CRED_SPECIFIED);
/* domain */
%feature("docstring") get_password "S.get_domain() -> domain\nObtain domain name.";
const char *get_domain(void);
%feature("docstring") set_domain "S.set_domain(domain, obtained=CRED_SPECIFIED) -> None\n" \
"Change domain name.";
bool set_domain(const char *val,
enum credentials_obtained obtained=CRED_SPECIFIED);
/* realm */
%feature("docstring") get_realm "S.get_realm() -> realm\nObtain realm name.";
const char *get_realm(void);
%feature("docstring") set_realm "S.set_realm(realm, obtained=CRED_SPECIFIED) -> None\n" \
"Change realm name.";
bool set_realm(const char *val,
enum credentials_obtained obtained=CRED_SPECIFIED);
/* Kerberos */
void set_kerberos_state(enum credentials_use_kerberos use_kerberos);
%feature("docstring") parse_string "S.parse_string(text, obtained=CRED_SPECIFIED) -> None\n" \
"Parse credentials string.";
void parse_string(const char *text,
enum credentials_obtained obtained=CRED_SPECIFIED);
/* bind dn */
%feature("docstring") get_bind_dn "S.get_bind_dn() -> bind dn\nObtain bind DN.";
const char *get_bind_dn(void);
%feature("docstring") set_bind_dn "S.set_bind_dn(bind_dn) -> None\nChange bind DN.";
bool set_bind_dn(const char *bind_dn);
%feature("docstring") set_anonymous "S.set_anonymous() -> None\nUse anonymous credentials.";
void set_anonymous();
/* workstation name */
const char *get_workstation(void);
bool set_workstation(const char *workstation,
enum credentials_obtained obtained=CRED_SPECIFIED);
NTSTATUS set_machine_account(struct loadparm_context *lp_ctx);
void guess(struct loadparm_context *lp_ctx);
bool is_anonymous(void);
const struct samr_Password *get_nt_hash(TALLOC_CTX *mem_ctx);
bool authentication_requested(void);
%feature("docstring") wrong_password "S.wrong_password() -> bool\nIndicate the returned password was incorrect.";
bool wrong_password(void);
%feature("docstring") set_cmdline_callbacks "S.set_cmdline_callbacks() -> bool\nUse command-line to obtain credentials not explicitly set.";
bool set_cmdline_callbacks();
}
} cli_credentials;
%{
struct cli_credentials *cli_credentials_from_py_object(PyObject *py_obj)
{
struct cli_credentials *ret;
if (py_obj == Py_None) {
return cli_credentials_init_anon(NULL);
}
if (SWIG_ConvertPtr(py_obj, (void *)&ret, SWIGTYPE_p_cli_credentials, 0 | 0 ) < 0) {
return NULL;
}
return ret;
}
%}

View File

@ -1,191 +0,0 @@
# This file was automatically generated by SWIG (http://www.swig.org).
# Version 1.3.36
#
# Don't modify this file, modify the SWIG interface instead.
"""
Credentials management.
"""
import _credentials
import new
new_instancemethod = new.instancemethod
try:
_swig_property = property
except NameError:
pass # Python < 2.2 doesn't have 'property'.
def _swig_setattr_nondynamic(self,class_type,name,value,static=1):
if (name == "thisown"): return self.this.own(value)
if (name == "this"):
if type(value).__name__ == 'PySwigObject':
self.__dict__[name] = value
return
method = class_type.__swig_setmethods__.get(name,None)
if method: return method(self,value)
if (not static) or hasattr(self,name):
self.__dict__[name] = value
else:
raise AttributeError("You cannot add attributes to %s" % self)
def _swig_setattr(self,class_type,name,value):
return _swig_setattr_nondynamic(self,class_type,name,value,0)
def _swig_getattr(self,class_type,name):
if (name == "thisown"): return self.this.own()
method = class_type.__swig_getmethods__.get(name,None)
if method: return method(self)
raise AttributeError,name
def _swig_repr(self):
try: strthis = "proxy of " + self.this.__repr__()
except: strthis = ""
return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,)
import types
try:
_object = types.ObjectType
_newclass = 1
except AttributeError:
class _object : pass
_newclass = 0
del types
def _swig_setattr_nondynamic_method(set):
def set_attr(self,name,value):
if (name == "thisown"): return self.this.own(value)
if hasattr(self,name) or (name == "this"):
set(self,name,value)
else:
raise AttributeError("You cannot add attributes to %s" % self)
return set_attr
import param
AUTO_USE_KERBEROS = _credentials.AUTO_USE_KERBEROS
DONT_USE_KERBEROS = _credentials.DONT_USE_KERBEROS
MUST_USE_KERBEROS = _credentials.MUST_USE_KERBEROS
class Credentials(object):
thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag')
__repr__ = _swig_repr
def __init__(self, *args, **kwargs):
_credentials.Credentials_swiginit(self,_credentials.new_Credentials(*args, **kwargs))
def get_username(*args, **kwargs):
"""
S.get_username() -> username
Obtain username.
"""
return _credentials.Credentials_get_username(*args, **kwargs)
def set_username(*args, **kwargs):
"""
S.set_username(name, obtained=CRED_SPECIFIED) -> None
Change username.
"""
return _credentials.Credentials_set_username(*args, **kwargs)
def get_password(*args, **kwargs):
"""
S.get_password() -> password
Obtain password.
"""
return _credentials.Credentials_get_password(*args, **kwargs)
def set_password(*args, **kwargs):
"""
S.set_password(password, obtained=CRED_SPECIFIED) -> None
Change password.
"""
return _credentials.Credentials_set_password(*args, **kwargs)
def set_domain(*args, **kwargs):
"""
S.set_domain(domain, obtained=CRED_SPECIFIED) -> None
Change domain name.
"""
return _credentials.Credentials_set_domain(*args, **kwargs)
def get_realm(*args, **kwargs):
"""
S.get_realm() -> realm
Obtain realm name.
"""
return _credentials.Credentials_get_realm(*args, **kwargs)
def set_realm(*args, **kwargs):
"""
S.set_realm(realm, obtained=CRED_SPECIFIED) -> None
Change realm name.
"""
return _credentials.Credentials_set_realm(*args, **kwargs)
def parse_string(*args, **kwargs):
"""
S.parse_string(text, obtained=CRED_SPECIFIED) -> None
Parse credentials string.
"""
return _credentials.Credentials_parse_string(*args, **kwargs)
def get_bind_dn(*args, **kwargs):
"""
S.get_bind_dn() -> bind dn
Obtain bind DN.
"""
return _credentials.Credentials_get_bind_dn(*args, **kwargs)
def set_bind_dn(*args, **kwargs):
"""
S.set_bind_dn(bind_dn) -> None
Change bind DN.
"""
return _credentials.Credentials_set_bind_dn(*args, **kwargs)
def set_anonymous(*args, **kwargs):
"""
S.set_anonymous() -> None
Use anonymous credentials.
"""
return _credentials.Credentials_set_anonymous(*args, **kwargs)
def wrong_password(*args, **kwargs):
"""
S.wrong_password() -> bool
Indicate the returned password was incorrect.
"""
return _credentials.Credentials_wrong_password(*args, **kwargs)
def set_cmdline_callbacks(*args, **kwargs):
"""
S.set_cmdline_callbacks() -> bool
Use command-line to obtain credentials not explicitly set.
"""
return _credentials.Credentials_set_cmdline_callbacks(*args, **kwargs)
__swig_destroy__ = _credentials.delete_Credentials
Credentials.get_username = new_instancemethod(_credentials.Credentials_get_username,None,Credentials)
Credentials.set_username = new_instancemethod(_credentials.Credentials_set_username,None,Credentials)
Credentials.get_password = new_instancemethod(_credentials.Credentials_get_password,None,Credentials)
Credentials.set_password = new_instancemethod(_credentials.Credentials_set_password,None,Credentials)
Credentials.get_domain = new_instancemethod(_credentials.Credentials_get_domain,None,Credentials)
Credentials.set_domain = new_instancemethod(_credentials.Credentials_set_domain,None,Credentials)
Credentials.get_realm = new_instancemethod(_credentials.Credentials_get_realm,None,Credentials)
Credentials.set_realm = new_instancemethod(_credentials.Credentials_set_realm,None,Credentials)
Credentials.set_kerberos_state = new_instancemethod(_credentials.Credentials_set_kerberos_state,None,Credentials)
Credentials.parse_string = new_instancemethod(_credentials.Credentials_parse_string,None,Credentials)
Credentials.get_bind_dn = new_instancemethod(_credentials.Credentials_get_bind_dn,None,Credentials)
Credentials.set_bind_dn = new_instancemethod(_credentials.Credentials_set_bind_dn,None,Credentials)
Credentials.set_anonymous = new_instancemethod(_credentials.Credentials_set_anonymous,None,Credentials)
Credentials.get_workstation = new_instancemethod(_credentials.Credentials_get_workstation,None,Credentials)
Credentials.set_workstation = new_instancemethod(_credentials.Credentials_set_workstation,None,Credentials)
Credentials.set_machine_account = new_instancemethod(_credentials.Credentials_set_machine_account,None,Credentials)
Credentials.guess = new_instancemethod(_credentials.Credentials_guess,None,Credentials)
Credentials.is_anonymous = new_instancemethod(_credentials.Credentials_is_anonymous,None,Credentials)
Credentials.get_nt_hash = new_instancemethod(_credentials.Credentials_get_nt_hash,None,Credentials)
Credentials.authentication_requested = new_instancemethod(_credentials.Credentials_authentication_requested,None,Credentials)
Credentials.wrong_password = new_instancemethod(_credentials.Credentials_wrong_password,None,Credentials)
Credentials.set_cmdline_callbacks = new_instancemethod(_credentials.Credentials_set_cmdline_callbacks,None,Credentials)
Credentials_swigregister = _credentials.Credentials_swigregister
Credentials_swigregister(Credentials)

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,316 @@
/*
Unix SMB/CIFS implementation.
Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "includes.h"
#include "pycredentials.h"
#include "param/param.h"
#include "lib/cmdline/credentials.h"
#include "librpc/gen_ndr/samr.h" /* for struct samr_Password */
#include "libcli/util/pyerrors.h"
/* Here until param/param.i gets rewritten in "manual" C */
extern struct loadparm_context *lp_from_py_object(PyObject *py_obj);
struct cli_credentials *cli_credentials_from_py_object(PyObject *py_obj)
{
if (py_obj == Py_None) {
return cli_credentials_init_anon(NULL);
}
if (PyCredentials_Check(py_obj))
return PyCredentials_AsCliCredentials(py_obj);
return NULL;
}
static PyObject *PyString_FromStringOrNULL(const char *str)
{
if (str == NULL)
return Py_None;
return PyString_FromString(str);
}
static PyObject *py_creds_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
{
return py_talloc_import(type, cli_credentials_init(NULL));
}
static PyObject *py_creds_get_username(py_talloc_Object *self)
{
return PyString_FromStringOrNULL(cli_credentials_get_username(self->ptr));
}
static PyObject *py_creds_set_username(py_talloc_Object *self, PyObject *args)
{
char *newval;
enum credentials_obtained obt = CRED_SPECIFIED;
if (!PyArg_ParseTuple(args, "s|i", &newval, &obt))
return NULL;
return PyBool_FromLong(cli_credentials_set_username(self->ptr, newval, obt));
}
static PyObject *py_creds_get_password(py_talloc_Object *self)
{
return PyString_FromStringOrNULL(cli_credentials_get_password(self->ptr));
}
static PyObject *py_creds_set_password(py_talloc_Object *self, PyObject *args)
{
char *newval;
enum credentials_obtained obt = CRED_SPECIFIED;
if (!PyArg_ParseTuple(args, "s|i", &newval, &obt))
return NULL;
return PyBool_FromLong(cli_credentials_set_password(self->ptr, newval, obt));
}
static PyObject *py_creds_get_domain(py_talloc_Object *self)
{
return PyString_FromStringOrNULL(cli_credentials_get_domain(self->ptr));
}
static PyObject *py_creds_set_domain(py_talloc_Object *self, PyObject *args)
{
char *newval;
enum credentials_obtained obt = CRED_SPECIFIED;
if (!PyArg_ParseTuple(args, "s|i", &newval, &obt))
return NULL;
return PyBool_FromLong(cli_credentials_set_domain(self->ptr, newval, obt));
}
static PyObject *py_creds_get_realm(py_talloc_Object *self)
{
return PyString_FromStringOrNULL(cli_credentials_get_realm(self->ptr));
}
static PyObject *py_creds_set_realm(py_talloc_Object *self, PyObject *args)
{
char *newval;
enum credentials_obtained obt = CRED_SPECIFIED;
if (!PyArg_ParseTuple(args, "s|i", &newval, &obt))
return NULL;
return PyBool_FromLong(cli_credentials_set_realm(self->ptr, newval, obt));
}
static PyObject *py_creds_get_bind_dn(py_talloc_Object *self)
{
return PyString_FromStringOrNULL(cli_credentials_get_bind_dn(self->ptr));
}
static PyObject *py_creds_set_bind_dn(py_talloc_Object *self, PyObject *args)
{
char *newval;
if (!PyArg_ParseTuple(args, "s", &newval))
return NULL;
return PyBool_FromLong(cli_credentials_set_bind_dn(self->ptr, newval));
}
static PyObject *py_creds_get_workstation(py_talloc_Object *self)
{
return PyString_FromStringOrNULL(cli_credentials_get_workstation(self->ptr));
}
static PyObject *py_creds_set_workstation(py_talloc_Object *self, PyObject *args)
{
char *newval;
enum credentials_obtained obt = CRED_SPECIFIED;
if (!PyArg_ParseTuple(args, "s|i", &newval, &obt))
return NULL;
return PyBool_FromLong(cli_credentials_set_workstation(self->ptr, newval, obt));
}
static PyObject *py_creds_is_anonymous(py_talloc_Object *self)
{
return PyBool_FromLong(cli_credentials_is_anonymous(self->ptr));
}
static PyObject *py_creds_set_anonymous(py_talloc_Object *self)
{
cli_credentials_set_anonymous(self->ptr);
return Py_None;
}
static PyObject *py_creds_authentication_requested(py_talloc_Object *self)
{
return PyBool_FromLong(cli_credentials_authentication_requested(self->ptr));
}
static PyObject *py_creds_wrong_password(py_talloc_Object *self)
{
return PyBool_FromLong(cli_credentials_wrong_password(self->ptr));
}
static PyObject *py_creds_set_cmdline_callbacks(py_talloc_Object *self)
{
return PyBool_FromLong(cli_credentials_set_cmdline_callbacks(self->ptr));
}
static PyObject *py_creds_parse_string(py_talloc_Object *self, PyObject *args)
{
char *newval;
enum credentials_obtained obt = CRED_SPECIFIED;
if (!PyArg_ParseTuple(args, "s|i", &newval, &obt))
return NULL;
cli_credentials_parse_string(self->ptr, newval, obt);
return Py_None;
}
static PyObject *py_creds_get_nt_hash(py_talloc_Object *self)
{
const struct samr_Password *ntpw = cli_credentials_get_nt_hash(self->ptr, self->ptr);
return PyString_FromStringAndSize((char *)ntpw->hash, 16);
}
static PyObject *py_creds_set_kerberos_state(py_talloc_Object *self, PyObject *args)
{
int state;
if (!PyArg_ParseTuple(args, "i", &state))
return NULL;
cli_credentials_set_kerberos_state(self->ptr, state);
return Py_None;
}
static PyObject *py_creds_guess(py_talloc_Object *self, PyObject *args)
{
PyObject *py_lp_ctx = Py_None;
struct loadparm_context *lp_ctx;
if (!PyArg_ParseTuple(args, "|O", &py_lp_ctx))
return NULL;
lp_ctx = lp_from_py_object(py_lp_ctx);
if (lp_ctx == NULL)
return NULL;
cli_credentials_guess(self->ptr, lp_ctx);
return Py_None;
}
static PyObject *py_creds_set_machine_account(py_talloc_Object *self, PyObject *args)
{
PyObject *py_lp_ctx = Py_None;
struct loadparm_context *lp_ctx;
NTSTATUS status;
if (!PyArg_ParseTuple(args, "|O", &py_lp_ctx))
return NULL;
lp_ctx = lp_from_py_object(py_lp_ctx);
if (lp_ctx == NULL)
return NULL;
status = cli_credentials_set_machine_account(self->ptr, lp_ctx);
PyErr_NTSTATUS_IS_ERR_RAISE(status);
return Py_None;
}
static PyMethodDef py_creds_methods[] = {
{ "get_username", (PyCFunction)py_creds_get_username, METH_NOARGS,
"S.get_username() -> username\nObtain username." },
{ "set_username", (PyCFunction)py_creds_set_username, METH_VARARGS,
"S.set_username(name, obtained=CRED_SPECIFIED) -> None\n"
"Change username." },
{ "get_password", (PyCFunction)py_creds_get_password, METH_NOARGS,
"S.get_password() -> password\n"
"Obtain password." },
{ "set_password", (PyCFunction)py_creds_set_password, METH_VARARGS,
"S.set_password(password, obtained=CRED_SPECIFIED) -> None\n"
"Change password." },
{ "get_domain", (PyCFunction)py_creds_get_domain, METH_NOARGS,
"S.get_domain() -> domain\n"
"Obtain domain name." },
{ "set_domain", (PyCFunction)py_creds_set_domain, METH_VARARGS,
"S.set_domain(domain, obtained=CRED_SPECIFIED) -> None\n"
"Change domain name." },
{ "get_realm", (PyCFunction)py_creds_get_realm, METH_NOARGS,
"S.get_realm() -> realm\n"
"Obtain realm name." },
{ "set_realm", (PyCFunction)py_creds_set_realm, METH_VARARGS,
"S.set_realm(realm, obtained=CRED_SPECIFIED) -> None\n"
"Change realm name." },
{ "get_bind_dn", (PyCFunction)py_creds_get_bind_dn, METH_NOARGS,
"S.get_bind_dn() -> bind dn\n"
"Obtain bind DN." },
{ "set_bind_dn", (PyCFunction)py_creds_set_bind_dn, METH_VARARGS,
"S.set_bind_dn(bind_dn) -> None\n"
"Change bind DN." },
{ "is_anonymous", (PyCFunction)py_creds_is_anonymous, METH_NOARGS,
NULL },
{ "set_anonymous", (PyCFunction)py_creds_set_anonymous, METH_NOARGS,
"S.set_anonymous() -> None\n"
"Use anonymous credentials." },
{ "get_workstation", (PyCFunction)py_creds_get_workstation, METH_NOARGS,
NULL },
{ "set_workstation", (PyCFunction)py_creds_set_workstation, METH_VARARGS,
NULL },
{ "authentication_requested", (PyCFunction)py_creds_authentication_requested, METH_NOARGS,
NULL },
{ "wrong_password", (PyCFunction)py_creds_wrong_password, METH_NOARGS,
"S.wrong_password() -> bool\n"
"Indicate the returned password was incorrect." },
{ "set_cmdline_callbacks", (PyCFunction)py_creds_set_cmdline_callbacks, METH_NOARGS,
"S.set_cmdline_callbacks() -> bool\n"
"Use command-line to obtain credentials not explicitly set." },
{ "parse_string", (PyCFunction)py_creds_parse_string, METH_VARARGS,
"S.parse_string(text, obtained=CRED_SPECIFIED) -> None\n"
"Parse credentials string." },
{ "get_nt_hash", (PyCFunction)py_creds_get_nt_hash, METH_NOARGS,
NULL },
{ "set_kerberos_state", (PyCFunction)py_creds_set_kerberos_state, METH_VARARGS,
NULL },
{ "guess", (PyCFunction)py_creds_guess, METH_VARARGS, NULL },
{ "set_machine_account", (PyCFunction)py_creds_set_machine_account, METH_VARARGS, NULL },
{ NULL }
};
PyTypeObject PyCredentials = {
.tp_name = "Credentials",
.tp_basicsize = sizeof(py_talloc_Object),
.tp_dealloc = py_talloc_dealloc,
.tp_new = py_creds_new,
.tp_flags = Py_TPFLAGS_DEFAULT,
.tp_methods = py_creds_methods,
};
void initcredentials(void)
{
PyObject *m;
if (PyType_Ready(&PyCredentials) < 0)
return;
m = Py_InitModule3("credentials", NULL, "Credentials management.");
if (m == NULL)
return;
PyModule_AddObject(m, "AUTO_USE_KERBEROS", PyInt_FromLong(CRED_AUTO_USE_KERBEROS));
PyModule_AddObject(m, "DONT_USE_KERBEROS", PyInt_FromLong(CRED_DONT_USE_KERBEROS));
PyModule_AddObject(m, "MUST_USE_KERBEROS", PyInt_FromLong(CRED_MUST_USE_KERBEROS));
Py_INCREF(&PyCredentials);
PyModule_AddObject(m, "Credentials", (PyObject *)&PyCredentials);
}

View File

@ -0,0 +1,30 @@
/*
Unix SMB/CIFS implementation.
Samba utility functions
Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2008
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _PYCREDENTIALS_H_
#define _PYCREDENTIALS_H_
#include "auth/credentials/credentials.h"
#include "pytalloc.h"
PyAPI_DATA(PyTypeObject) PyCredentials;
struct cli_credentials *cli_credentials_from_py_object(PyObject *py_obj);
#define PyCredentials_Check(py_obj) PyObject_TypeCheck(py_obj, &PyCredentials)
#define PyCredentials_AsCliCredentials(py_obj) py_talloc_get_ptr(py_obj)
#endif /* _PYCREDENTIALS_H_ */