mirror of
https://github.com/samba-team/samba.git
synced 2025-03-09 08:58:35 +03:00
pydsdb: Fix memory leak on invalid parameters, formatting, trivial
typos.
This commit is contained in:
parent
ce28f854c0
commit
13bbfa3fca
@ -191,31 +191,38 @@ static PyObject *py_dsdb_get_oid_from_attid(PyObject *self, PyObject *args)
|
|||||||
uint32_t attid;
|
uint32_t attid;
|
||||||
struct dsdb_schema *schema;
|
struct dsdb_schema *schema;
|
||||||
const char *oid;
|
const char *oid;
|
||||||
|
PyObject *ret;
|
||||||
TALLOC_CTX *mem_ctx;
|
TALLOC_CTX *mem_ctx;
|
||||||
WERROR status;
|
WERROR status;
|
||||||
|
|
||||||
|
if (!PyArg_ParseTuple(args, "Oi", &py_ldb, &attid))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
mem_ctx = talloc_new(NULL);
|
mem_ctx = talloc_new(NULL);
|
||||||
if (mem_ctx == NULL) {
|
if (mem_ctx == NULL) {
|
||||||
PyErr_NoMemory();
|
PyErr_NoMemory();
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "Oi", &py_ldb, &attid))
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
PyErr_LDB_OR_RAISE(py_ldb, ldb);
|
PyErr_LDB_OR_RAISE(py_ldb, ldb);
|
||||||
|
|
||||||
schema = dsdb_get_schema(ldb, NULL);
|
schema = dsdb_get_schema(ldb, NULL);
|
||||||
|
|
||||||
if (!schema) {
|
if (!schema) {
|
||||||
PyErr_SetString(PyExc_RuntimeError, "Failed to find a schema from ldb \n");
|
PyErr_SetString(PyExc_RuntimeError, "Failed to find a schema from ldb \n");
|
||||||
|
talloc_free(mem_ctx);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
status = dsdb_schema_pfm_oid_from_attid(schema->prefixmap, attid,
|
|
||||||
mem_ctx, &oid);
|
status = dsdb_schema_pfm_oid_from_attid(schema->prefixmap, attid,
|
||||||
|
mem_ctx, &oid);
|
||||||
PyErr_WERROR_IS_ERR_RAISE(status);
|
PyErr_WERROR_IS_ERR_RAISE(status);
|
||||||
|
|
||||||
return PyString_FromString(oid);
|
ret = PyString_FromString(oid);
|
||||||
|
|
||||||
|
talloc_free(mem_ctx);
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *py_dsdb_set_ntds_invocation_id(PyObject *self, PyObject *args)
|
static PyObject *py_dsdb_set_ntds_invocation_id(PyObject *self, PyObject *args)
|
||||||
@ -349,8 +356,8 @@ static PyMethodDef py_dsdb_methods[] = {
|
|||||||
"Get SID of domain in use." },
|
"Get SID of domain in use." },
|
||||||
{ "samdb_ntds_invocation_id", (PyCFunction)py_samdb_ntds_invocation_id,
|
{ "samdb_ntds_invocation_id", (PyCFunction)py_samdb_ntds_invocation_id,
|
||||||
METH_VARARGS, "get the NTDS invocation ID GUID as a string"},
|
METH_VARARGS, "get the NTDS invocation ID GUID as a string"},
|
||||||
{ "dsdb_get_oid_from_attid", (PyCFunction)py_dsdb_get_oid_from_attid, METH_VARARGS,
|
{ "dsdb_get_oid_from_attid", (PyCFunction)py_dsdb_get_oid_from_attid,
|
||||||
NULL },
|
METH_VARARGS, NULL },
|
||||||
{ "dsdb_set_ntds_invocation_id",
|
{ "dsdb_set_ntds_invocation_id",
|
||||||
(PyCFunction)py_dsdb_set_ntds_invocation_id, METH_VARARGS,
|
(PyCFunction)py_dsdb_set_ntds_invocation_id, METH_VARARGS,
|
||||||
NULL },
|
NULL },
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
|
|
||||||
# Unix SMB/CIFS implementation. Tests for glue helper
|
# Unix SMB/CIFS implementation. Tests for dsdb
|
||||||
# Copyright (C) Matthieu Patou <mat@matws.net> 2010
|
# Copyright (C) Matthieu Patou <mat@matws.net> 2010
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or modify
|
# This program is free software; you can redistribute it and/or modify
|
||||||
@ -18,27 +18,25 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
import samba.dsdb
|
import samba.dsdb
|
||||||
import samba.param
|
|
||||||
from samba.credentials import Credentials
|
from samba.credentials import Credentials
|
||||||
from samba import Ldb
|
from samba import Ldb
|
||||||
from samba.auth import system_session
|
from samba.auth import system_session
|
||||||
from testtools.testcase import TestCase, TestSkipped
|
from testtools.testcase import TestCase
|
||||||
import random
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
class GlueTests(TestCase):
|
|
||||||
|
|
||||||
|
class DsdbTests(TestCase):
|
||||||
|
|
||||||
def _baseprovpath(self):
|
def _baseprovpath(self):
|
||||||
return os.path.join(os.environ['SELFTEST_PREFIX'], "dc")
|
return os.path.join(os.environ['SELFTEST_PREFIX'], "dc")
|
||||||
|
|
||||||
def test_get_oid_from_attrid(self):
|
def test_get_oid_from_attrid(self):
|
||||||
lp = samba.param.LoadParm()
|
lp = samba.param.LoadParm()
|
||||||
lp.load(os.path.join(os.path.join(self._baseprovpath(),"etc"),"smb.conf"))
|
lp.load(os.path.join(os.path.join(self._baseprovpath(), "etc"), "smb.conf"))
|
||||||
creds = Credentials()
|
creds = Credentials()
|
||||||
creds.guess(lp)
|
creds.guess(lp)
|
||||||
session = system_session()
|
session = system_session()
|
||||||
test_ldb = Ldb(os.path.join(os.path.join(self._baseprovpath(),"private"),"sam.ldb"), session_info=session, credentials=creds,lp=lp)
|
test_ldb = Ldb(os.path.join(self._baseprovpath(), "private", "sam.ldb"),
|
||||||
oid = samba.dsdb.dsdb_get_oid_from_attid(test_ldb,591614)
|
session_info=session, credentials=creds,lp=lp)
|
||||||
|
oid = samba.dsdb.dsdb_get_oid_from_attid(test_ldb, 591614)
|
||||||
self.assertEquals(oid, "1.2.840.113556.1.4.1790")
|
self.assertEquals(oid, "1.2.840.113556.1.4.1790")
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user