gstate = PyGILState_Ensure();
while (!t->do_shutdown) {
+ TALLOC_CTX *frame = talloc_stackframe();
int ret;
ret = tevent_loop_once(self->ev);
assert(ret == 0);
+ TALLOC_FREE(frame);
}
PyGILState_Release(gstate);
return NULL;
if (py_negotiate_contexts != NULL) {
negotiate_contexts = py_cli_get_negotiate_contexts(
- talloc_tos(), py_negotiate_contexts);
+ frame, py_negotiate_contexts);
if (negotiate_contexts == NULL) {
TALLOC_FREE(frame);
return -1;
static void py_cli_got_oplock_break(struct tevent_req *req)
{
+ TALLOC_CTX *frame = talloc_stackframe();
struct py_cli_state *self = (struct py_cli_state *)
tevent_req_callback_data_void(req);
struct py_cli_oplock_break b;
self->oplock_waiter = NULL;
if (!NT_STATUS_IS_OK(status)) {
+ TALLOC_FREE(frame);
return;
}
tmp = talloc_realloc(self->ev, self->oplock_breaks,
struct py_cli_oplock_break, num_breaks+1);
if (tmp == NULL) {
+ TALLOC_FREE(frame);
return;
}
self->oplock_breaks = tmp;
self->oplock_waiter = cli_smb_oplock_break_waiter_send(
self->ev, self->ev, self->cli);
if (self->oplock_waiter == NULL) {
+ TALLOC_FREE(frame);
return;
}
tevent_req_set_callback(self->oplock_waiter, py_cli_got_oplock_break,
static PyObject *py_cli_get_oplock_break(struct py_cli_state *self,
PyObject *args)
{
+ TALLOC_CTX *frame = talloc_stackframe();
size_t num_oplock_breaks;
if (!PyArg_ParseTuple(args, "")) {
+ TALLOC_FREE(frame);
return NULL;
}
PyErr_SetString(PyExc_RuntimeError,
"get_oplock_break() only possible on "
"a multi_threaded connection");
+ TALLOC_FREE(frame);
return NULL;
}
if (self->oplock_cond != NULL) {
+ TALLOC_FREE(frame);
errno = EBUSY;
PyErr_SetFromErrno(PyExc_RuntimeError);
return NULL;
self->oplock_cond = NULL;
if (ret != 0) {
+ TALLOC_FREE(frame);
errno = ret;
PyErr_SetFromErrno(PyExc_RuntimeError);
return NULL;
NULL, self->oplock_breaks, struct py_cli_oplock_break,
num_oplock_breaks - 1);
+ TALLOC_FREE(frame);
return result;
}
+
+ TALLOC_FREE(frame);
Py_RETURN_NONE;
}
static void py_cli_state_dealloc(struct py_cli_state *self)
{
+ TALLOC_CTX *frame = talloc_stackframe();
+
TALLOC_FREE(self->thread_state);
TALLOC_FREE(self->oplock_waiter);
TALLOC_FREE(self->ev);
self->cli = NULL;
}
Py_TYPE(self)->tp_free((PyObject *)self);
+ TALLOC_FREE(frame);
}
static PyObject *py_cli_settimeout(struct py_cli_state *self, PyObject *args)
{
+ TALLOC_CTX *frame = talloc_stackframe();
unsigned int nmsecs = 0;
unsigned int omsecs = 0;
if (!PyArg_ParseTuple(args, "I", &nmsecs)) {
+ TALLOC_FREE(frame);
return NULL;
}
omsecs = cli_set_timeout(self->cli, nmsecs);
+ TALLOC_FREE(frame);
return PyLong_FromLong(omsecs);
}
static PyObject *py_cli_echo(struct py_cli_state *self,
PyObject *Py_UNUSED(ignored))
{
+ TALLOC_CTX *frame = talloc_stackframe();
DATA_BLOB data = data_blob_string_const("keepalive");
struct tevent_req *req = NULL;
NTSTATUS status;
- req = cli_echo_send(NULL, self->ev, self->cli, 1, data);
+ req = cli_echo_send(frame, self->ev, self->cli, 1, data);
if (!py_tevent_req_wait_exc(self, req)) {
+ TALLOC_FREE(frame);
return NULL;
}
status = cli_echo_recv(req);
TALLOC_FREE(req);
if (!NT_STATUS_IS_OK(status)) {
PyErr_SetNTSTATUS(status);
+ TALLOC_FREE(frame);
return NULL;
}
+ TALLOC_FREE(frame);
Py_RETURN_NONE;
}
static PyObject *py_cli_create(struct py_cli_state *self, PyObject *args,
PyObject *kwds)
{
+ TALLOC_CTX *frame = talloc_stackframe();
char *fname;
unsigned CreateFlags = 0;
unsigned DesiredAccess = FILE_GENERIC_READ;
&fname, &CreateFlags, &DesiredAccess, &FileAttributes,
&ShareAccess, &CreateDisposition, &CreateOptions,
&ImpersonationLevel, &SecurityFlags)) {
+ TALLOC_FREE(frame);
return NULL;
}
- req = cli_ntcreate_send(NULL, self->ev, self->cli, fname, CreateFlags,
+ req = cli_ntcreate_send(frame, self->ev, self->cli, fname, CreateFlags,
DesiredAccess, FileAttributes, ShareAccess,
CreateDisposition, CreateOptions,
ImpersonationLevel, SecurityFlags);
if (!py_tevent_req_wait_exc(self, req)) {
+ TALLOC_FREE(frame);
return NULL;
}
status = cli_ntcreate_recv(req, &fnum, NULL);
if (!NT_STATUS_IS_OK(status)) {
PyErr_SetNTSTATUS(status);
+ TALLOC_FREE(frame);
return NULL;
}
+
+ TALLOC_FREE(frame);
return Py_BuildValue("I", (unsigned)fnum);
}
static PyObject *py_cli_symlink_error(const struct symlink_reparse_struct *s)
{
+ TALLOC_CTX *frame = talloc_stackframe();
char *subst_utf8 = NULL, *print_utf8 = NULL;
size_t subst_utf8_len, print_utf8_len;
PyObject *v = NULL;
*/
ok = convert_string_talloc(
- talloc_tos(),
+ frame,
CH_UNIX,
CH_UTF8,
s->substitute_name,
}
ok = convert_string_talloc(
- talloc_tos(),
+ frame,
CH_UNIX,
CH_UTF8,
s->print_name,
(unsigned long long)s->flags);
fail:
- TALLOC_FREE(subst_utf8);
- TALLOC_FREE(print_utf8);
+ TALLOC_FREE(frame);
return v;
}
static PyObject *py_cli_get_posix_fs_info(
struct py_cli_state *self, PyObject *args, PyObject *kwds)
{
+ TALLOC_CTX *frame = talloc_stackframe();
NTSTATUS status;
struct tevent_req *req = NULL;
uint32_t optimal_transfer_size = 0;
uint64_t free_file_nodes = 0;
uint64_t fs_identifier = 0;
- req = cli_get_posix_fs_info_send(NULL, self->ev, self->cli);
+ req = cli_get_posix_fs_info_send(frame, self->ev, self->cli);
if (!py_tevent_req_wait_exc(self, req)) {
+ TALLOC_FREE(frame);
return NULL;
}
TALLOC_FREE(req);
if (!NT_STATUS_IS_OK(status)) {
PyErr_SetNTSTATUS(status);
+ TALLOC_FREE(frame);
return NULL;
}
+ TALLOC_FREE(frame);
return Py_BuildValue("{s:I,s:I,s:I,s:I,s:I,s:I,s:I,s:I}",
"optimal_transfer_size", optimal_transfer_size,
"block_size", block_size,
static PyObject *py_cli_create_ex(
struct py_cli_state *self, PyObject *args, PyObject *kwds)
{
+ TALLOC_CTX *frame = talloc_stackframe();
char *fname = NULL;
unsigned CreateFlags = 0;
unsigned DesiredAccess = FILE_GENERIC_READ;
&SecurityFlags,
&py_create_contexts_in);
if (!ret) {
+ TALLOC_FREE(frame);
return NULL;
}
if (py_create_contexts_in != NULL) {
create_contexts_in = py_cli_get_create_contexts(
- NULL, py_create_contexts_in);
+ frame, py_create_contexts_in);
if (create_contexts_in == NULL) {
+ TALLOC_FREE(frame);
errno = EINVAL;
PyErr_SetFromErrno(PyExc_RuntimeError);
return NULL;
};
req = cli_smb2_create_fnum_send(
- NULL,
+ frame,
self->ev,
self->cli,
fname,
create_contexts_in);
} else {
req = cli_ntcreate_send(
- NULL,
+ frame,
self->ev,
self->cli,
fname,
ok = py_tevent_req_wait_exc(self, req);
if (!ok) {
+ TALLOC_FREE(frame);
return NULL;
}
req,
&fnum,
&cr,
- NULL,
+ frame,
&create_contexts_out,
&symlink);
} else {
(unsigned)fnum,
py_cr,
py_create_contexts_out);
+ TALLOC_FREE(frame);
return v;
nomem:
status = NT_STATUS_NO_MEMORY;
} else {
PyErr_SetNTSTATUS(status);
}
+
+ TALLOC_FREE(frame);
return NULL;
}
static PyObject *py_cli_close(struct py_cli_state *self, PyObject *args)
{
+ TALLOC_CTX *frame = talloc_stackframe();
struct tevent_req *req;
int fnum;
int flags = 0;
NTSTATUS status;
if (!PyArg_ParseTuple(args, "i|i", &fnum, &flags)) {
+ TALLOC_FREE(frame);
return NULL;
}
- req = cli_close_send(NULL, self->ev, self->cli, fnum, flags);
+ req = cli_close_send(frame, self->ev, self->cli, fnum, flags);
if (!py_tevent_req_wait_exc(self, req)) {
+ TALLOC_FREE(frame);
return NULL;
}
status = cli_close_recv(req);
if (!NT_STATUS_IS_OK(status)) {
PyErr_SetNTSTATUS(status);
+ TALLOC_FREE(frame);
return NULL;
}
+
+ TALLOC_FREE(frame);
Py_RETURN_NONE;
}
static PyObject *py_cli_qfileinfo(struct py_cli_state *self, PyObject *args)
{
+ TALLOC_CTX *frame = talloc_stackframe();
struct tevent_req *req = NULL;
int fnum, level;
uint16_t recv_flags2;
NTSTATUS status;
if (!PyArg_ParseTuple(args, "ii", &fnum, &level)) {
+ TALLOC_FREE(frame);
return NULL;
}
req = cli_qfileinfo_send(
- NULL, self->ev, self->cli, fnum, level, 0, UINT32_MAX);
+ frame, self->ev, self->cli, fnum, level, 0, UINT32_MAX);
if (!py_tevent_req_wait_exc(self, req)) {
+ TALLOC_FREE(frame);
return NULL;
}
status = cli_qfileinfo_recv(
- req, NULL, &recv_flags2, &rdata, &num_rdata);
+ req, frame, &recv_flags2, &rdata, &num_rdata);
TALLOC_FREE(req);
if (!NT_STATUS_IS_OK(status)) {
PyErr_SetNTSTATUS(status);
+ TALLOC_FREE(frame);
return NULL;
}
if (num_rdata != 8) {
PyErr_SetNTSTATUS(NT_STATUS_INVALID_NETWORK_RESPONSE);
+ TALLOC_FREE(frame);
return NULL;
}
if (num_rdata < 80) {
PyErr_SetNTSTATUS(NT_STATUS_INVALID_NETWORK_RESPONSE);
+ TALLOC_FREE(frame);
return NULL;
}
&sid_size);
if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
PyErr_SetNTSTATUS(NT_STATUS_INVALID_NETWORK_RESPONSE);
+ TALLOC_FREE(frame);
return NULL;
}
if (data_off + sid_size < data_off ||
data_off + sid_size > num_rdata)
{
PyErr_SetNTSTATUS(NT_STATUS_INVALID_NETWORK_RESPONSE);
+ TALLOC_FREE(frame);
return NULL;
}
data_off += sid_size;
&sid_size);
if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
PyErr_SetNTSTATUS(NT_STATUS_INVALID_NETWORK_RESPONSE);
+ TALLOC_FREE(frame);
return NULL;
}
break;
}
- TALLOC_FREE(rdata);
+ TALLOC_FREE(frame);
return result;
}
static PyObject *py_cli_rename(
struct py_cli_state *self, PyObject *args, PyObject *kwds)
{
+ TALLOC_CTX *frame = talloc_stackframe();
char *fname_src = NULL, *fname_dst = NULL;
int replace = false;
struct tevent_req *req = NULL;
ok = ParseTupleAndKeywords(
args, kwds, "ss|p", kwlist, &fname_src, &fname_dst, &replace);
if (!ok) {
+ TALLOC_FREE(frame);
return NULL;
}
req = cli_rename_send(
- NULL, self->ev, self->cli, fname_src, fname_dst, replace);
+ frame, self->ev, self->cli, fname_src, fname_dst, replace);
if (!py_tevent_req_wait_exc(self, req)) {
+ TALLOC_FREE(frame);
return NULL;
}
status = cli_rename_recv(req);
if (!NT_STATUS_IS_OK(status)) {
PyErr_SetNTSTATUS(status);
+ TALLOC_FREE(frame);
return NULL;
}
+
+ TALLOC_FREE(frame);
Py_RETURN_NONE;
}
*/
static PyObject *py_smb_savefile(struct py_cli_state *self, PyObject *args)
{
+ TALLOC_CTX *frame = talloc_stackframe();
uint16_t fnum;
const char *filename = NULL;
char *data = NULL;
if (!PyArg_ParseTuple(args, "s"PYARG_BYTES_LEN":savefile", &filename,
&data, &size)) {
+ TALLOC_FREE(frame);
return NULL;
}
/* create a new file handle for writing to */
- req = cli_ntcreate_send(NULL, self->ev, self->cli, filename, 0,
+ req = cli_ntcreate_send(frame, self->ev, self->cli, filename, 0,
FILE_WRITE_DATA, FILE_ATTRIBUTE_NORMAL,
FILE_SHARE_READ|FILE_SHARE_WRITE,
FILE_OVERWRITE_IF, FILE_NON_DIRECTORY_FILE,
SMB2_IMPERSONATION_IMPERSONATION, 0);
if (!py_tevent_req_wait_exc(self, req)) {
+ TALLOC_FREE(frame);
return NULL;
}
status = cli_ntcreate_recv(req, &fnum, NULL);
TALLOC_FREE(req);
if (!NT_STATUS_IS_OK(status)) {
PyErr_SetNTSTATUS(status);
+ TALLOC_FREE(frame);
return NULL;
}
state.nread = 0;
state.total_data = size;
- req = cli_push_send(NULL, self->ev, self->cli, fnum, 0, 0, 0,
+ req = cli_push_send(frame, self->ev, self->cli, fnum, 0, 0, 0,
push_data, &state);
if (!py_tevent_req_wait_exc(self, req)) {
+ TALLOC_FREE(frame);
return NULL;
}
status = cli_push_recv(req);
TALLOC_FREE(req);
if (!NT_STATUS_IS_OK(status)) {
PyErr_SetNTSTATUS(status);
+ TALLOC_FREE(frame);
return NULL;
}
/* close the file handle */
- req = cli_close_send(NULL, self->ev, self->cli, fnum, 0);
+ req = cli_close_send(frame, self->ev, self->cli, fnum, 0);
if (!py_tevent_req_wait_exc(self, req)) {
+ TALLOC_FREE(frame);
return NULL;
}
status = cli_close_recv(req);
TALLOC_FREE(req);
if (!NT_STATUS_IS_OK(status)) {
PyErr_SetNTSTATUS(status);
+ TALLOC_FREE(frame);
return NULL;
}
+ TALLOC_FREE(frame);
Py_RETURN_NONE;
}
static PyObject *py_cli_write(struct py_cli_state *self, PyObject *args,
PyObject *kwds)
{
+ TALLOC_CTX *frame = talloc_stackframe();
int fnum;
unsigned mode = 0;
char *buf;
if (!ParseTupleAndKeywords(
args, kwds, "i" PYARG_BYTES_LEN "K|I", kwlist,
&fnum, &buf, &buflen, &offset, &mode)) {
+ TALLOC_FREE(frame);
return NULL;
}
req = cli_write_send(NULL, self->ev, self->cli, fnum, mode,
(uint8_t *)buf, offset, buflen);
if (!py_tevent_req_wait_exc(self, req)) {
+ TALLOC_FREE(frame);
return NULL;
}
status = cli_write_recv(req, &written);
if (!NT_STATUS_IS_OK(status)) {
PyErr_SetNTSTATUS(status);
+ TALLOC_FREE(frame);
return NULL;
}
+ TALLOC_FREE(frame);
return Py_BuildValue("K", (unsigned long long)written);
}
static NTSTATUS py_smb_filesize(struct py_cli_state *self, uint16_t fnum,
off_t *size)
{
+ TALLOC_CTX *frame = talloc_stackframe();
NTSTATUS status;
struct tevent_req *req = NULL;
- req = cli_qfileinfo_basic_send(NULL, self->ev, self->cli, fnum);
+ req = cli_qfileinfo_basic_send(frame, self->ev, self->cli, fnum);
if (!py_tevent_req_wait_exc(self, req)) {
+ TALLOC_FREE(frame);
return NT_STATUS_INTERNAL_ERROR;
}
status = cli_qfileinfo_basic_recv(
req, NULL, size, NULL, NULL, NULL, NULL, NULL);
- TALLOC_FREE(req);
+ TALLOC_FREE(frame);
return status;
}
*/
static PyObject *py_smb_loadfile(struct py_cli_state *self, PyObject *args)
{
+ TALLOC_CTX *frame = talloc_stackframe();
NTSTATUS status;
const char *filename = NULL;
struct tevent_req *req = NULL;
PyObject *result = NULL;
if (!PyArg_ParseTuple(args, "s:loadfile", &filename)) {
+ TALLOC_FREE(frame);
return NULL;
}
FILE_SHARE_READ, FILE_OPEN, 0,
SMB2_IMPERSONATION_IMPERSONATION, 0);
if (!py_tevent_req_wait_exc(self, req)) {
+ TALLOC_FREE(frame);
return NULL;
}
status = cli_ntcreate_recv(req, &fnum, NULL);
TALLOC_FREE(req);
if (!NT_STATUS_IS_OK(status)) {
PyErr_SetNTSTATUS(status);
+ TALLOC_FREE(frame);
return NULL;
}
status = py_smb_filesize(self, fnum, &size);
if (!NT_STATUS_IS_OK(status)) {
PyErr_SetNTSTATUS(status);
+ TALLOC_FREE(frame);
return NULL;
}
result = PyBytes_FromStringAndSize(NULL, size);
if (result == NULL) {
+ TALLOC_FREE(frame);
return NULL;
}
size, cli_read_sink, &buf);
if (!py_tevent_req_wait_exc(self, req)) {
Py_XDECREF(result);
+ TALLOC_FREE(frame);
return NULL;
}
status = cli_pull_recv(req, &nread);
if (!NT_STATUS_IS_OK(status)) {
Py_XDECREF(result);
PyErr_SetNTSTATUS(status);
+ TALLOC_FREE(frame);
return NULL;
}
req = cli_close_send(NULL, self->ev, self->cli, fnum, 0);
if (!py_tevent_req_wait_exc(self, req)) {
Py_XDECREF(result);
+ TALLOC_FREE(frame);
return NULL;
}
status = cli_close_recv(req);
if (!NT_STATUS_IS_OK(status)) {
Py_XDECREF(result);
PyErr_SetNTSTATUS(status);
+ TALLOC_FREE(frame);
return NULL;
}
PyErr_Format(PyExc_IOError,
"read invalid - got %zu requested %zu",
nread, size);
+ TALLOC_FREE(frame);
return NULL;
}
if (nread < size) {
if (_PyBytes_Resize(&result, nread) < 0) {
+ TALLOC_FREE(frame);
return NULL;
}
}
+ TALLOC_FREE(frame);
return result;
}
static PyObject *py_cli_read(struct py_cli_state *self, PyObject *args,
PyObject *kwds)
{
+ TALLOC_CTX *frame = talloc_stackframe();
int fnum;
unsigned long long offset;
unsigned size;
if (!ParseTupleAndKeywords(
args, kwds, "iKI", kwlist, &fnum, &offset,
&size)) {
+ TALLOC_FREE(frame);
return NULL;
}
result = PyBytes_FromStringAndSize(NULL, size);
if (result == NULL) {
+ TALLOC_FREE(frame);
return NULL;
}
buf = PyBytes_AS_STRING(result);
buf, offset, size);
if (!py_tevent_req_wait_exc(self, req)) {
Py_XDECREF(result);
+ TALLOC_FREE(frame);
return NULL;
}
status = cli_read_recv(req, &received);
if (!NT_STATUS_IS_OK(status)) {
Py_XDECREF(result);
PyErr_SetNTSTATUS(status);
+ TALLOC_FREE(frame);
return NULL;
}
PyErr_Format(PyExc_IOError,
"read invalid - got %zu requested %u",
received, size);
+ TALLOC_FREE(frame);
return NULL;
}
if (received < size) {
if (_PyBytes_Resize(&result, received) < 0) {
+ TALLOC_FREE(frame);
return NULL;
}
}
+ TALLOC_FREE(frame);
return result;
}
static PyObject *py_cli_ftruncate(struct py_cli_state *self, PyObject *args,
PyObject *kwds)
{
+ TALLOC_CTX *frame = talloc_stackframe();
int fnum;
unsigned long long size;
struct tevent_req *req;
if (!ParseTupleAndKeywords(
args, kwds, "IK", kwlist, &fnum, &size)) {
+ TALLOC_FREE(frame);
return NULL;
}
- req = cli_ftruncate_send(NULL, self->ev, self->cli, fnum, size);
+ req = cli_ftruncate_send(frame, self->ev, self->cli, fnum, size);
if (!py_tevent_req_wait_exc(self, req)) {
+ TALLOC_FREE(frame);
return NULL;
}
status = cli_ftruncate_recv(req);
if (!NT_STATUS_IS_OK(status)) {
PyErr_SetNTSTATUS(status);
+ TALLOC_FREE(frame);
return NULL;
}
+
+ TALLOC_FREE(frame);
Py_RETURN_NONE;
}
PyObject *args,
PyObject *kwds)
{
+ TALLOC_CTX *frame = talloc_stackframe();
unsigned fnum, flag;
struct tevent_req *req;
NTSTATUS status;
if (!ParseTupleAndKeywords(
args, kwds, "II", kwlist, &fnum, &flag)) {
+ TALLOC_FREE(frame);
return NULL;
}
- req = cli_nt_delete_on_close_send(NULL, self->ev, self->cli, fnum,
+ req = cli_nt_delete_on_close_send(frame, self->ev, self->cli, fnum,
flag);
if (!py_tevent_req_wait_exc(self, req)) {
+ TALLOC_FREE(frame);
return NULL;
}
status = cli_nt_delete_on_close_recv(req);
if (!NT_STATUS_IS_OK(status)) {
PyErr_SetNTSTATUS(status);
+ TALLOC_FREE(frame);
return NULL;
}
+
+ TALLOC_FREE(frame);
Py_RETURN_NONE;
}
static void py_cli_notify_state_dealloc(struct py_cli_notify_state *self)
{
+ TALLOC_CTX *frame = talloc_stackframe();
+
TALLOC_FREE(self->req);
Py_CLEAR(self->py_cli_state);
Py_TYPE(self)->tp_free(self);
+
+ TALLOC_FREE(frame);
}
static PyTypeObject py_cli_notify_state_type;
PyObject *args,
PyObject *kwds)
{
+ TALLOC_CTX *frame = talloc_stackframe();
static const char *kwlist[] = {
"fnum",
"buffer_size",
&completion_filter,
&py_recursive);
if (!ok) {
+ TALLOC_FREE(frame);
return NULL;
}
completion_filter,
recursive);
if (req == NULL) {
+ TALLOC_FREE(frame);
PyErr_NoMemory();
return NULL;
}
+ /*
+ * only reparent to frame,
+ * if we would pass frame to
+ * cli_query_security_descriptor_recv()
+ * we'd leak a potential talloc_stackframe_pool
+ * via py_return_ndr_struct().
+ */
+ talloc_reparent(NULL, frame, req);
/*
* Just wait for the request being submitted to
self->ev,
send_queue);
if (flush_req == NULL) {
- TALLOC_FREE(req);
+ TALLOC_FREE(frame);
PyErr_NoMemory();
return NULL;
}
self->ev,
endtime);
if (!ok) {
- TALLOC_FREE(req);
+ TALLOC_FREE(frame);
PyErr_NoMemory();
return NULL;
}
ok = py_tevent_req_wait_exc(self, flush_req);
if (!ok) {
- TALLOC_FREE(req);
+ TALLOC_FREE(frame);
return NULL;
}
TALLOC_FREE(flush_req);
py_notify_state = (struct py_cli_notify_state *)
py_cli_notify_state_type.tp_alloc(&py_cli_notify_state_type, 0);
if (py_notify_state == NULL) {
- TALLOC_FREE(req);
+ TALLOC_FREE(frame);
PyErr_NoMemory();
return NULL;
}
Py_INCREF(self);
py_notify_state->py_cli_state = self;
- py_notify_state->req = req;
+ py_notify_state->req = talloc_move(NULL, &req);
+ TALLOC_FREE(frame);
return (PyObject *)py_notify_state;
}
PyObject *args,
PyObject *kwds)
{
+ TALLOC_CTX *frame = talloc_stackframe();
struct py_cli_state *py_cli_state = self->py_cli_state;
- struct tevent_req *req = self->req;
+ struct tevent_req *req = NULL;
uint32_t i;
uint32_t num_changes = 0;
struct notify_change *changes = NULL;
kwlist,
&py_wait);
if (!ok) {
+ TALLOC_FREE(frame);
return NULL;
}
wait = PyObject_IsTrue(py_wait);
- if (req == NULL) {
+ if (self->req == NULL) {
PyErr_SetString(PyExc_RuntimeError,
"TODO req == NULL "
"- missing change notify request?");
+ TALLOC_FREE(frame);
return NULL;
}
- pending = tevent_req_is_in_progress(req);
+ pending = tevent_req_is_in_progress(self->req);
if (pending && !wait) {
+ TALLOC_FREE(frame);
Py_RETURN_NONE;
}
+ /*
+ * Now we really return success or an exception
+ * so we move self->req to frame and set
+ * self->req to NULL.
+ *
+ * Below we also call Py_CLEAR(self->py_cli_state)
+ * as soon as possible.
+ */
+ req = talloc_move(frame, &self->req);
+
if (pending) {
struct timeval endtime;
py_cli_state->ev,
endtime);
if (!ok) {
- TALLOC_FREE(req);
+ TALLOC_FREE(frame);
+ Py_CLEAR(self->py_cli_state);
PyErr_NoMemory();
return NULL;
}
}
ok = py_tevent_req_wait_exc(py_cli_state, req);
- self->req = NULL;
Py_CLEAR(self->py_cli_state);
if (!ok) {
+ TALLOC_FREE(frame);
return NULL;
}
status = cli_notify_recv(req, req, &num_changes, &changes);
+ TALLOC_FREE(req);
if (!NT_STATUS_IS_OK(status)) {
- TALLOC_FREE(req);
+ TALLOC_FREE(frame);
PyErr_SetNTSTATUS(status);
return NULL;
}
result = Py_BuildValue("[]");
if (result == NULL) {
- TALLOC_FREE(req);
+ TALLOC_FREE(frame);
return NULL;
}
"action", changes[i].action);
if (change == NULL) {
Py_XDECREF(result);
- TALLOC_FREE(req);
+ TALLOC_FREE(frame);
return NULL;
}
Py_DECREF(change);
if (ret == -1) {
Py_XDECREF(result);
- TALLOC_FREE(req);
+ TALLOC_FREE(frame);
return NULL;
}
}
- TALLOC_FREE(req);
+ TALLOC_FREE(frame);
return result;
}
static void do_listing_cb(struct tevent_req *subreq)
{
+ TALLOC_CTX *frame = talloc_stackframe();
struct do_listing_state *state = tevent_req_callback_data_void(subreq);
struct file_info *finfo = NULL;
- state->status = cli_list_recv(subreq, NULL, &finfo);
+ state->status = cli_list_recv(subreq, frame, &finfo);
if (!NT_STATUS_IS_OK(state->status)) {
+ TALLOC_FREE(frame);
return;
}
state->callback_fn(finfo, state->mask, state->private_data);
- TALLOC_FREE(finfo);
+ TALLOC_FREE(frame);
}
static NTSTATUS do_listing(struct py_cli_state *self,
const char *, void *),
void *priv)
{
+ TALLOC_CTX *frame = talloc_stackframe();
char *mask = NULL;
struct do_listing_state state = {
.mask = mask,
NTSTATUS status;
if (user_mask == NULL) {
- mask = talloc_asprintf(NULL, "%s\\*", base_dir);
+ mask = talloc_asprintf(frame, "%s\\*", base_dir);
} else {
- mask = talloc_asprintf(NULL, "%s\\%s", base_dir, user_mask);
+ mask = talloc_asprintf(frame, "%s\\%s", base_dir, user_mask);
}
if (mask == NULL) {
+ TALLOC_FREE(frame);
return NT_STATUS_NO_MEMORY;
}
dos_format(mask);
- req = cli_list_send(NULL, self->ev, self->cli, mask, attribute,
+ req = cli_list_send(frame, self->ev, self->cli, mask, attribute,
info_level);
if (req == NULL) {
status = NT_STATUS_NO_MEMORY;
}
done:
- TALLOC_FREE(mask);
- TALLOC_FREE(req);
+ TALLOC_FREE(frame);
return status;
}
PyObject *args,
PyObject *kwds)
{
+ TALLOC_CTX *frame = talloc_stackframe();
char *base_dir;
char *user_mask = NULL;
unsigned int attribute = LIST_ATTRIBUTE_MASK;
if (!ParseTupleAndKeywords(args, kwds, "z|sII:list", kwlist,
&base_dir, &user_mask, &attribute,
&info_level)) {
+ TALLOC_FREE(frame);
return NULL;
}
result = Py_BuildValue("[]");
if (result == NULL) {
+ TALLOC_FREE(frame);
return NULL;
}
if (!NT_STATUS_IS_OK(status)) {
Py_XDECREF(result);
PyErr_SetNTSTATUS(status);
+ TALLOC_FREE(frame);
return NULL;
}
+ TALLOC_FREE(frame);
return result;
}
static PyObject *py_smb_unlink(struct py_cli_state *self, PyObject *args)
{
+ TALLOC_CTX *frame = talloc_stackframe();
NTSTATUS status;
const char *filename = NULL;
struct tevent_req *req = NULL;
const uint32_t attrs = (FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
if (!PyArg_ParseTuple(args, "s:unlink", &filename)) {
+ TALLOC_FREE(frame);
return NULL;
}
- req = cli_unlink_send(NULL, self->ev, self->cli, filename, attrs);
+ req = cli_unlink_send(frame, self->ev, self->cli, filename, attrs);
if (!py_tevent_req_wait_exc(self, req)) {
+ TALLOC_FREE(frame);
return NULL;
}
status = cli_unlink_recv(req);
TALLOC_FREE(req);
if (!NT_STATUS_IS_OK(status)) {
PyErr_SetNTSTATUS(status);
+ TALLOC_FREE(frame);
return NULL;
}
+ TALLOC_FREE(frame);
Py_RETURN_NONE;
}
static PyObject *py_smb_rmdir(struct py_cli_state *self, PyObject *args)
{
+ TALLOC_CTX *frame = talloc_stackframe();
NTSTATUS status;
struct tevent_req *req = NULL;
const char *dirname = NULL;
if (!PyArg_ParseTuple(args, "s:rmdir", &dirname)) {
+ TALLOC_FREE(frame);
return NULL;
}
- req = cli_rmdir_send(NULL, self->ev, self->cli, dirname);
+ req = cli_rmdir_send(frame, self->ev, self->cli, dirname);
if (!py_tevent_req_wait_exc(self, req)) {
+ TALLOC_FREE(frame);
return NULL;
}
status = cli_rmdir_recv(req);
TALLOC_FREE(req);
if (!NT_STATUS_IS_OK(status)) {
PyErr_SetNTSTATUS(status);
+ TALLOC_FREE(frame);
return NULL;
}
+ TALLOC_FREE(frame);
Py_RETURN_NONE;
}
*/
static PyObject *py_smb_mkdir(struct py_cli_state *self, PyObject *args)
{
+ TALLOC_CTX *frame = talloc_stackframe();
NTSTATUS status;
const char *dirname = NULL;
struct tevent_req *req = NULL;
if (!PyArg_ParseTuple(args, "s:mkdir", &dirname)) {
+ TALLOC_FREE(frame);
return NULL;
}
- req = cli_mkdir_send(NULL, self->ev, self->cli, dirname);
+ req = cli_mkdir_send(frame, self->ev, self->cli, dirname);
if (!py_tevent_req_wait_exc(self, req)) {
+ TALLOC_FREE(frame);
return NULL;
}
status = cli_mkdir_recv(req);
TALLOC_FREE(req);
if (!NT_STATUS_IS_OK(status)) {
PyErr_SetNTSTATUS(status);
+ TALLOC_FREE(frame);
return NULL;
}
+ TALLOC_FREE(frame);
Py_RETURN_NONE;
}
*/
static bool check_dir_path(struct py_cli_state *self, const char *path)
{
+ TALLOC_CTX *frame = talloc_stackframe();
NTSTATUS status;
struct tevent_req *req = NULL;
- req = cli_chkpath_send(NULL, self->ev, self->cli, path);
+ req = cli_chkpath_send(frame, self->ev, self->cli, path);
if (!py_tevent_req_wait_exc(self, req)) {
+ TALLOC_FREE(frame);
return false;
}
status = cli_chkpath_recv(req);
TALLOC_FREE(req);
+ TALLOC_FREE(frame);
return NT_STATUS_IS_OK(status);
}
static PyObject *py_smb_chkpath(struct py_cli_state *self, PyObject *args)
{
+ TALLOC_CTX *frame = talloc_stackframe();
const char *path = NULL;
bool dir_exists;
if (!PyArg_ParseTuple(args, "s:chkpath", &path)) {
+ TALLOC_FREE(frame);
return NULL;
}
dir_exists = check_dir_path(self, path);
+ TALLOC_FREE(frame);
return PyBool_FromLong(dir_exists);
}
static PyObject *py_smb_get_sd(struct py_cli_state *self, PyObject *args)
{
+ TALLOC_CTX *frame = talloc_stackframe();
int fnum;
unsigned sinfo;
struct tevent_req *req = NULL;
struct security_descriptor *sd = NULL;
+ PyObject *py_sd = NULL;
NTSTATUS status;
if (!PyArg_ParseTuple(args, "iI:get_acl", &fnum, &sinfo)) {
+ TALLOC_FREE(frame);
return NULL;
}
req = cli_query_security_descriptor_send(
- NULL, self->ev, self->cli, fnum, sinfo);
+ frame, self->ev, self->cli, fnum, sinfo);
if (!py_tevent_req_wait_exc(self, req)) {
+ TALLOC_FREE(frame);
return NULL;
}
status = cli_query_security_descriptor_recv(req, NULL, &sd);
TALLOC_FREE(req);
if (!NT_STATUS_IS_OK(status)) {
PyErr_SetNTSTATUS(status);
+ TALLOC_FREE(frame);
return NULL;
}
+ /*
+ * only reparent to frame,
+ * if we would pass frame to
+ * cli_query_security_descriptor_recv()
+ * we'd leak a potential talloc_stackframe_pool
+ * via py_return_ndr_struct().
+ */
+ talloc_reparent(NULL, frame, sd);
- return py_return_ndr_struct(
- "samba.dcerpc.security", "descriptor", sd, sd);
+ py_sd = py_return_ndr_struct("samba.dcerpc.security", "descriptor",
+ sd, sd);
+ TALLOC_FREE(frame);
+ return py_sd;
}
static PyObject *py_smb_set_sd(struct py_cli_state *self, PyObject *args)
{
+ TALLOC_CTX *frame = talloc_stackframe();
PyObject *py_sd = NULL;
struct tevent_req *req = NULL;
struct security_descriptor *sd = NULL;
NTSTATUS status;
if (!PyArg_ParseTuple(args, "iOI:set_sd", &fnum, &py_sd, &sinfo)) {
+ TALLOC_FREE(frame);
return NULL;
}
PyErr_Format(PyExc_TypeError,
"Expected dcerpc.security.descriptor as argument, got %s",
pytalloc_get_name(py_sd));
+ TALLOC_FREE(frame);
return NULL;
}
req = cli_set_security_descriptor_send(
- NULL, self->ev, self->cli, fnum, sinfo, sd);
+ frame, self->ev, self->cli, fnum, sinfo, sd);
if (!py_tevent_req_wait_exc(self, req)) {
+ TALLOC_FREE(frame);
return NULL;
}
TALLOC_FREE(req);
if (!NT_STATUS_IS_OK(status)) {
PyErr_SetNTSTATUS(status);
+ TALLOC_FREE(frame);
return NULL;
}
+ TALLOC_FREE(frame);
Py_RETURN_NONE;
}
static PyObject *py_smb_smb1_posix(
struct py_cli_state *self, PyObject *Py_UNUSED(ignored))
{
+ TALLOC_CTX *frame = talloc_stackframe();
NTSTATUS status;
struct tevent_req *req = NULL;
uint16_t major, minor;
uint32_t caplow, caphigh;
PyObject *result = NULL;
- req = cli_unix_extensions_version_send(NULL, self->ev, self->cli);
+ req = cli_unix_extensions_version_send(frame, self->ev, self->cli);
if (!py_tevent_req_wait_exc(self, req)) {
+ TALLOC_FREE(frame);
return NULL;
}
status = cli_unix_extensions_version_recv(
TALLOC_FREE(req);
if (!NT_STATUS_IS_OK(status)) {
PyErr_SetNTSTATUS(status);
+ TALLOC_FREE(frame);
return NULL;
}
req = cli_set_unix_extensions_capabilities_send(
- NULL, self->ev, self->cli, major, minor, caplow, caphigh);
+ frame, self->ev, self->cli, major, minor, caplow, caphigh);
if (!py_tevent_req_wait_exc(self, req)) {
+ TALLOC_FREE(frame);
return NULL;
}
status = cli_set_unix_extensions_capabilities_recv(req);
TALLOC_FREE(req);
if (!NT_STATUS_IS_OK(status)) {
PyErr_SetNTSTATUS(status);
+ TALLOC_FREE(frame);
return NULL;
}
(unsigned)major,
(unsigned)caplow,
(unsigned)caphigh);
+ TALLOC_FREE(frame);
return result;
}
static PyObject *py_smb_smb1_readlink(
struct py_cli_state *self, PyObject *args)
{
+ TALLOC_CTX *frame = talloc_stackframe();
NTSTATUS status;
const char *filename = NULL;
struct tevent_req *req = NULL;
PyObject *result = NULL;
if (!PyArg_ParseTuple(args, "s:smb1_readlink", &filename)) {
+ TALLOC_FREE(frame);
return NULL;
}
- req = cli_posix_readlink_send(NULL, self->ev, self->cli, filename);
+ req = cli_posix_readlink_send(frame, self->ev, self->cli, filename);
if (!py_tevent_req_wait_exc(self, req)) {
+ TALLOC_FREE(frame);
return NULL;
}
- status = cli_posix_readlink_recv(req, NULL, &target);
+ status = cli_posix_readlink_recv(req, frame, &target);
TALLOC_FREE(req);
if (!NT_STATUS_IS_OK(status)) {
PyErr_SetNTSTATUS(status);
+ TALLOC_FREE(frame);
return NULL;
}
result = PyBytes_FromString(target);
- TALLOC_FREE(target);
+ TALLOC_FREE(frame);
return result;
}
static PyObject *py_smb_smb1_symlink(
struct py_cli_state *self, PyObject *args)
{
+ TALLOC_CTX *frame = talloc_stackframe();
NTSTATUS status;
const char *target = NULL, *newname = NULL;
struct tevent_req *req = NULL;
if (!PyArg_ParseTuple(args, "ss:smb1_symlink", &target, &newname)) {
+ TALLOC_FREE(frame);
return NULL;
}
req = cli_posix_symlink_send(
- NULL, self->ev, self->cli, target, newname);
+ frame, self->ev, self->cli, target, newname);
if (!py_tevent_req_wait_exc(self, req)) {
+ TALLOC_FREE(frame);
return NULL;
}
status = cli_posix_symlink_recv(req);
TALLOC_FREE(req);
if (!NT_STATUS_IS_OK(status)) {
PyErr_SetNTSTATUS(status);
+ TALLOC_FREE(frame);
return NULL;
}
+ TALLOC_FREE(frame);
Py_RETURN_NONE;
}
static PyObject *py_smb_smb1_stat(
struct py_cli_state *self, PyObject *args)
{
+ TALLOC_CTX *frame = talloc_stackframe();
NTSTATUS status;
const char *fname = NULL;
struct tevent_req *req = NULL;
struct stat_ex sbuf = { .st_ex_nlink = 0, };
if (!PyArg_ParseTuple(args, "s:smb1_stat", &fname)) {
+ TALLOC_FREE(frame);
return NULL;
}
- req = cli_posix_stat_send(NULL, self->ev, self->cli, fname);
+ req = cli_posix_stat_send(frame, self->ev, self->cli, fname);
if (!py_tevent_req_wait_exc(self, req)) {
+ TALLOC_FREE(frame);
return NULL;
}
status = cli_posix_stat_recv(req, &sbuf);
TALLOC_FREE(req);
if (!NT_STATUS_IS_OK(status)) {
PyErr_SetNTSTATUS(status);
+ TALLOC_FREE(frame);
return NULL;
}
+ TALLOC_FREE(frame);
return Py_BuildValue(
"{sLsLsLsLsLsLsLsLsLsLsLsLsLsLsLsLsLsLsLsL}",
"dev",
static PyObject *py_cli_mknod(
struct py_cli_state *self, PyObject *args, PyObject *kwds)
{
+ TALLOC_CTX *frame = talloc_stackframe();
char *fname = NULL;
int mode = 0, major = 0, minor = 0, dev = 0;
struct tevent_req *req = NULL;
&major,
&minor);
if (!ok) {
+ TALLOC_FREE(frame);
return NULL;
}
#endif
req = cli_mknod_send(
- NULL, self->ev, self->cli, fname, mode, dev);
+ frame, self->ev, self->cli, fname, mode, dev);
if (!py_tevent_req_wait_exc(self, req)) {
+ TALLOC_FREE(frame);
return NULL;
}
status = cli_mknod_recv(req);
TALLOC_FREE(req);
if (!NT_STATUS_IS_OK(status)) {
PyErr_SetNTSTATUS(status);
+ TALLOC_FREE(frame);
return NULL;
}
+
+ TALLOC_FREE(frame);
Py_RETURN_NONE;
}
static PyObject *py_cli_fsctl(
struct py_cli_state *self, PyObject *args, PyObject *kwds)
{
+ TALLOC_CTX *frame = talloc_stackframe();
int fnum, ctl_code;
int max_out = 0;
char *buf = NULL;
&buflen,
&max_out);
if (!ok) {
+ TALLOC_FREE(frame);
return NULL;
}
in = (DATA_BLOB) { .data = (uint8_t *)buf, .length = buflen, };
req = cli_fsctl_send(
- NULL, self->ev, self->cli, fnum, ctl_code, &in, max_out);
+ frame, self->ev, self->cli, fnum, ctl_code, &in, max_out);
if (!py_tevent_req_wait_exc(self, req)) {
+ TALLOC_FREE(frame);
return NULL;
}
- status = cli_fsctl_recv(req, NULL, &out);
+ status = cli_fsctl_recv(req, frame, &out);
if (!NT_STATUS_IS_OK(status)) {
PyErr_SetNTSTATUS(status);
+ TALLOC_FREE(frame);
return NULL;
}
result = PyBytes_FromStringAndSize((char *)out.data, out.length);
- data_blob_free(&out);
+ TALLOC_FREE(frame);
return result;
}