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

s4-param: Fix more memory leaks, invalid memory context.

This commit is contained in:
Jelmer Vernooij 2010-09-22 16:44:17 -07:00
parent 5b10c82a58
commit 1c3c9a483b
7 changed files with 111 additions and 25 deletions

View File

@ -207,6 +207,7 @@ static PyObject *py_creds_guess(py_talloc_Object *self, PyObject *args)
{ {
PyObject *py_lp_ctx = Py_None; PyObject *py_lp_ctx = Py_None;
struct loadparm_context *lp_ctx; struct loadparm_context *lp_ctx;
TALLOC_CTX *mem_ctx;
struct cli_credentials *creds; struct cli_credentials *creds;
creds = PyCredentials_AsCliCredentials(self); creds = PyCredentials_AsCliCredentials(self);
@ -214,13 +215,21 @@ static PyObject *py_creds_guess(py_talloc_Object *self, PyObject *args)
if (!PyArg_ParseTuple(args, "|O", &py_lp_ctx)) if (!PyArg_ParseTuple(args, "|O", &py_lp_ctx))
return NULL; return NULL;
lp_ctx = lpcfg_from_py_object(NULL, py_lp_ctx); mem_ctx = talloc_new(NULL);
if (lp_ctx == NULL) if (mem_ctx == NULL) {
PyErr_NoMemory();
return NULL; return NULL;
}
lp_ctx = lpcfg_from_py_object(mem_ctx, py_lp_ctx);
if (lp_ctx == NULL) {
talloc_free(mem_ctx);
return NULL;
}
cli_credentials_guess(creds, lp_ctx); cli_credentials_guess(creds, lp_ctx);
talloc_free(lp_ctx); talloc_free(mem_ctx);
Py_RETURN_NONE; Py_RETURN_NONE;
} }
@ -231,18 +240,27 @@ static PyObject *py_creds_set_machine_account(py_talloc_Object *self, PyObject *
struct loadparm_context *lp_ctx; struct loadparm_context *lp_ctx;
NTSTATUS status; NTSTATUS status;
struct cli_credentials *creds; struct cli_credentials *creds;
TALLOC_CTX *mem_ctx;
creds = PyCredentials_AsCliCredentials(self); creds = PyCredentials_AsCliCredentials(self);
if (!PyArg_ParseTuple(args, "|O", &py_lp_ctx)) if (!PyArg_ParseTuple(args, "|O", &py_lp_ctx))
return NULL; return NULL;
lp_ctx = lpcfg_from_py_object(NULL, py_lp_ctx); mem_ctx = talloc_new(NULL);
if (lp_ctx == NULL) if (mem_ctx == NULL) {
PyErr_NoMemory();
return NULL; return NULL;
}
lp_ctx = lpcfg_from_py_object(mem_ctx, py_lp_ctx);
if (lp_ctx == NULL) {
talloc_free(mem_ctx);
return NULL;
}
status = cli_credentials_set_machine_account(creds, lp_ctx); status = cli_credentials_set_machine_account(creds, lp_ctx);
talloc_free(lp_ctx); talloc_free(mem_ctx);
PyErr_NTSTATUS_IS_ERR_RAISE(status); PyErr_NTSTATUS_IS_ERR_RAISE(status);
@ -278,29 +296,39 @@ static PyObject *py_creds_get_named_ccache(py_talloc_Object *self, PyObject *arg
int ret; int ret;
const char *error_string; const char *error_string;
struct cli_credentials *creds; struct cli_credentials *creds;
TALLOC_CTX *mem_ctx;
creds = PyCredentials_AsCliCredentials(self); creds = PyCredentials_AsCliCredentials(self);
if (!PyArg_ParseTuple(args, "|Os", &py_lp_ctx, &ccache_name)) if (!PyArg_ParseTuple(args, "|Os", &py_lp_ctx, &ccache_name))
return NULL; return NULL;
lp_ctx = lpcfg_from_py_object(NULL, py_lp_ctx); /* FIXME: leaky */ mem_ctx = talloc_new(NULL);
if (lp_ctx == NULL) if (mem_ctx == NULL) {
PyErr_NoMemory();
return NULL; return NULL;
}
event_ctx = tevent_context_init(NULL); lp_ctx = lpcfg_from_py_object(mem_ctx, py_lp_ctx);
if (lp_ctx == NULL) {
talloc_free(mem_ctx);
return NULL;
}
event_ctx = tevent_context_init(mem_ctx);
ret = cli_credentials_get_named_ccache(creds, event_ctx, lp_ctx, ret = cli_credentials_get_named_ccache(creds, event_ctx, lp_ctx,
ccache_name, &ccc, &error_string); ccache_name, &ccc, &error_string);
talloc_free(lp_ctx); talloc_free(lp_ctx);
if (ret == 0) { if (ret == 0) {
talloc_steal(ccc, event_ctx); talloc_steal(ccc, event_ctx);
talloc_free(mem_ctx);
return PyCredentialCacheContainer_from_ccache_container(ccc); return PyCredentialCacheContainer_from_ccache_container(ccc);
} }
PyErr_SetString(PyExc_RuntimeError, error_string?error_string:"NULL"); PyErr_SetString(PyExc_RuntimeError, error_string?error_string:"NULL");
talloc_free(event_ctx); talloc_free(mem_ctx);
return NULL; return NULL;
} }

View File

@ -43,16 +43,25 @@ static PyObject *py_system_session(PyObject *module, PyObject *args)
PyObject *py_lp_ctx = Py_None; PyObject *py_lp_ctx = Py_None;
struct loadparm_context *lp_ctx = NULL; struct loadparm_context *lp_ctx = NULL;
struct auth_session_info *session; struct auth_session_info *session;
TALLOC_CTX *mem_ctx;
if (!PyArg_ParseTuple(args, "|O", &py_lp_ctx)) if (!PyArg_ParseTuple(args, "|O", &py_lp_ctx))
return NULL; return NULL;
lp_ctx = lpcfg_from_py_object(NULL, py_lp_ctx); mem_ctx = talloc_new(NULL);
if (lp_ctx == NULL) if (mem_ctx == NULL) {
PyErr_NoMemory();
return NULL; return NULL;
}
lp_ctx = lpcfg_from_py_object(mem_ctx, py_lp_ctx);
if (lp_ctx == NULL) {
talloc_free(mem_ctx);
return NULL;
}
session = system_session(lp_ctx); session = system_session(lp_ctx);
talloc_free(lp_ctx); talloc_free(mem_ctx);
return PyAuthSession_FromSession(session); return PyAuthSession_FromSession(session);
} }
@ -65,17 +74,32 @@ static PyObject *py_admin_session(PyObject *module, PyObject *args)
struct loadparm_context *lp_ctx = NULL; struct loadparm_context *lp_ctx = NULL;
struct auth_session_info *session; struct auth_session_info *session;
struct dom_sid *domain_sid = NULL; struct dom_sid *domain_sid = NULL;
TALLOC_CTX *mem_ctx;
if (!PyArg_ParseTuple(args, "OO", &py_lp_ctx, &py_sid)) if (!PyArg_ParseTuple(args, "OO", &py_lp_ctx, &py_sid))
return NULL; return NULL;
lp_ctx = lpcfg_from_py_object(NULL, py_lp_ctx); mem_ctx = talloc_new(NULL);
if (lp_ctx == NULL) if (mem_ctx == NULL) {
PyErr_NoMemory();
return NULL; return NULL;
}
domain_sid = dom_sid_parse_talloc(NULL, PyString_AsString(py_sid)); lp_ctx = lpcfg_from_py_object(mem_ctx, py_lp_ctx);
if (lp_ctx == NULL) {
talloc_free(mem_ctx);
return NULL;
}
domain_sid = dom_sid_parse_talloc(mem_ctx, PyString_AsString(py_sid));
if (domain_sid == NULL) {
PyErr_Format(PyExc_RuntimeError, "Unable to parse sid %s",
PyString_AsString(py_sid));
talloc_free(mem_ctx);
return NULL;
}
session = admin_session(NULL, lp_ctx, domain_sid); session = admin_session(NULL, lp_ctx, domain_sid);
talloc_free(mem_ctx);
talloc_free(lp_ctx);
return PyAuthSession_FromSession(session); return PyAuthSession_FromSession(session);
} }

View File

@ -253,6 +253,7 @@ static PyObject *py_open_hive(PyTypeObject *type, PyObject *args, PyObject *kwar
struct cli_credentials *credentials; struct cli_credentials *credentials;
char *location; char *location;
struct hive_key *hive_key; struct hive_key *hive_key;
TALLOC_CTX *mem_ctx;
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|OOO", if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|OOO",
discard_const_p(char *, kwnames), discard_const_p(char *, kwnames),
@ -261,15 +262,23 @@ static PyObject *py_open_hive(PyTypeObject *type, PyObject *args, PyObject *kwar
&py_credentials)) &py_credentials))
return NULL; return NULL;
lp_ctx = lpcfg_from_py_object(NULL, py_lp_ctx); /* FIXME: leaky */ mem_ctx = talloc_new(NULL);
if (mem_ctx == NULL) {
PyErr_NoMemory();
return NULL;
}
lp_ctx = lpcfg_from_py_object(mem_ctx, py_lp_ctx);
if (lp_ctx == NULL) { if (lp_ctx == NULL) {
PyErr_SetString(PyExc_TypeError, "Expected loadparm context"); PyErr_SetString(PyExc_TypeError, "Expected loadparm context");
talloc_free(mem_ctx);
return NULL; return NULL;
} }
credentials = cli_credentials_from_py_object(py_credentials); credentials = cli_credentials_from_py_object(py_credentials);
if (credentials == NULL) { if (credentials == NULL) {
PyErr_SetString(PyExc_TypeError, "Expected credentials"); PyErr_SetString(PyExc_TypeError, "Expected credentials");
talloc_free(mem_ctx);
return NULL; return NULL;
} }
session_info = NULL; session_info = NULL;
@ -277,6 +286,7 @@ static PyObject *py_open_hive(PyTypeObject *type, PyObject *args, PyObject *kwar
result = reg_open_hive(NULL, location, session_info, credentials, result = reg_open_hive(NULL, location, session_info, credentials,
tevent_context_init(NULL), tevent_context_init(NULL),
lp_ctx, &hive_key); lp_ctx, &hive_key);
talloc_free(mem_ctx);
PyErr_WERROR_IS_ERR_RAISE(result); PyErr_WERROR_IS_ERR_RAISE(result);
return py_talloc_steal(&PyHiveKey, hive_key); return py_talloc_steal(&PyHiveKey, hive_key);
@ -307,21 +317,31 @@ static PyObject *py_open_samba(PyObject *self, PyObject *args, PyObject *kwargs)
PyObject *py_lp_ctx, *py_session_info, *py_credentials; PyObject *py_lp_ctx, *py_session_info, *py_credentials;
struct auth_session_info *session_info; struct auth_session_info *session_info;
struct cli_credentials *credentials; struct cli_credentials *credentials;
TALLOC_CTX *mem_ctx;
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|OOO", if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|OOO",
discard_const_p(char *, kwnames), discard_const_p(char *, kwnames),
&py_lp_ctx, &py_session_info, &py_lp_ctx, &py_session_info,
&py_credentials)) &py_credentials))
return NULL; return NULL;
lp_ctx = lpcfg_from_py_object(NULL, py_lp_ctx); /* FIXME: leaky */ mem_ctx = talloc_new(NULL);
if (mem_ctx == NULL) {
PyErr_NoMemory();
return NULL;
}
lp_ctx = lpcfg_from_py_object(mem_ctx, py_lp_ctx);
if (lp_ctx == NULL) { if (lp_ctx == NULL) {
PyErr_SetString(PyExc_TypeError, "Expected loadparm context"); PyErr_SetString(PyExc_TypeError, "Expected loadparm context");
talloc_free(mem_ctx);
return NULL; return NULL;
} }
credentials = cli_credentials_from_py_object(py_credentials); credentials = cli_credentials_from_py_object(py_credentials);
if (credentials == NULL) { if (credentials == NULL) {
PyErr_SetString(PyExc_TypeError, "Expected credentials"); PyErr_SetString(PyExc_TypeError, "Expected credentials");
talloc_free(mem_ctx);
return NULL; return NULL;
} }
@ -329,6 +349,7 @@ static PyObject *py_open_samba(PyObject *self, PyObject *args, PyObject *kwargs)
result = reg_open_samba(NULL, &reg_ctx, NULL, result = reg_open_samba(NULL, &reg_ctx, NULL,
lp_ctx, session_info, credentials); lp_ctx, session_info, credentials);
talloc_free(mem_ctx);
if (!W_ERROR_IS_OK(result)) { if (!W_ERROR_IS_OK(result)) {
PyErr_SetWERROR(result); PyErr_SetWERROR(result);
return NULL; return NULL;
@ -377,6 +398,7 @@ static PyObject *py_open_ldb_file(PyObject *self, PyObject *args, PyObject *kwar
struct cli_credentials *credentials; struct cli_credentials *credentials;
struct hive_key *key; struct hive_key *key;
struct auth_session_info *session_info; struct auth_session_info *session_info;
TALLOC_CTX *mem_ctx;
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|OOO", if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|OOO",
discard_const_p(char *, kwnames), discard_const_p(char *, kwnames),
@ -384,15 +406,23 @@ static PyObject *py_open_ldb_file(PyObject *self, PyObject *args, PyObject *kwar
&py_credentials, &py_lp_ctx)) &py_credentials, &py_lp_ctx))
return NULL; return NULL;
lp_ctx = lpcfg_from_py_object(NULL, py_lp_ctx); /* FIXME: leaky */ mem_ctx = talloc_new(NULL);
if (mem_ctx == NULL) {
PyErr_NoMemory();
return NULL;
}
lp_ctx = lpcfg_from_py_object(mem_ctx, py_lp_ctx);
if (lp_ctx == NULL) { if (lp_ctx == NULL) {
PyErr_SetString(PyExc_TypeError, "Expected loadparm context"); PyErr_SetString(PyExc_TypeError, "Expected loadparm context");
talloc_free(mem_ctx);
return NULL; return NULL;
} }
credentials = cli_credentials_from_py_object(py_credentials); credentials = cli_credentials_from_py_object(py_credentials);
if (credentials == NULL) { if (credentials == NULL) {
PyErr_SetString(PyExc_TypeError, "Expected credentials"); PyErr_SetString(PyExc_TypeError, "Expected credentials");
talloc_free(mem_ctx);
return NULL; return NULL;
} }
@ -400,6 +430,7 @@ static PyObject *py_open_ldb_file(PyObject *self, PyObject *args, PyObject *kwar
result = reg_open_ldb_file(NULL, location, session_info, credentials, result = reg_open_ldb_file(NULL, location, session_info, credentials,
s4_event_context_init(NULL), lp_ctx, &key); s4_event_context_init(NULL), lp_ctx, &key);
talloc_free(mem_ctx);
PyErr_WERROR_IS_ERR_RAISE(result); PyErr_WERROR_IS_ERR_RAISE(result);
return py_talloc_steal(&PyHiveKey, key); return py_talloc_steal(&PyHiveKey, key);

View File

@ -198,7 +198,7 @@ NTSTATUS provision_bare(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx,
DEBUG(0, ("Missing 'lp' attribute")); DEBUG(0, ("Missing 'lp' attribute"));
return NT_STATUS_UNSUCCESSFUL; return NT_STATUS_UNSUCCESSFUL;
} }
result->lp_ctx = lpcfg_from_py_object(result, py_lp_ctx); result->lp_ctx = lpcfg_from_py_object(mem_ctx, py_lp_ctx);
result->samdb = PyLdb_AsLdbContext(PyObject_GetAttrString(py_result, "samdb")); result->samdb = PyLdb_AsLdbContext(PyObject_GetAttrString(py_result, "samdb"));
return NT_STATUS_OK; return NT_STATUS_OK;

View File

@ -131,6 +131,10 @@ static PyObject *py_interface_ips(PyObject *self, PyObject *args)
return NULL; return NULL;
tmp_ctx = talloc_new(NULL); tmp_ctx = talloc_new(NULL);
if (tmp_ctx == NULL) {
PyErr_NoMemory();
return NULL;
}
lp_ctx = lpcfg_from_py_object(tmp_ctx, py_lp_ctx); lp_ctx = lpcfg_from_py_object(tmp_ctx, py_lp_ctx);
if (lp_ctx == NULL) { if (lp_ctx == NULL) {

View File

@ -1491,7 +1491,6 @@ def provision(setup_dir, logger, session_info,
lp=lp) lp=lp)
share_ldb.load_ldif_file_add(setup_path("share.ldif")) share_ldb.load_ldif_file_add(setup_path("share.ldif"))
logger.info("Setting up secrets.ldb") logger.info("Setting up secrets.ldb")
secrets_ldb = setup_secretsdb(paths.secrets, setup_path, secrets_ldb = setup_secretsdb(paths.secrets, setup_path,
session_info=session_info, session_info=session_info,