Skip to content

Commit fabe938

Browse files
committed
add missing decrefs, implement rmdir()
1 parent cecb803 commit fabe938

File tree

4 files changed

+35
-0
lines changed

4 files changed

+35
-0
lines changed

commands.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ int python_connect(vfs_handle_struct *handle,
1212
PyObject *py_ret = PyObject_CallFunction(py_func, "ss", service, user);
1313
success = PyObject_IsTrue(py_ret);
1414
Py_DECREF(py_ret);
15+
Py_DECREF(py_func);
1516
}
1617

1718
if (success == 1)
@@ -42,6 +43,7 @@ int python_mkdir(vfs_handle_struct *handle,
4243
PyObject *py_ret = PyObject_CallFunction(py_func, "s", path);
4344
success = PyObject_IsTrue(py_ret);
4445
Py_DECREF(py_ret);
46+
Py_DECREF(py_func);
4547
}
4648

4749
if (success == 1)
@@ -54,6 +56,29 @@ int python_mkdir(vfs_handle_struct *handle,
5456
}
5557
}
5658

59+
int python_rmdir(vfs_handle_struct *handle, const char *path)
60+
{
61+
int success = 1;
62+
63+
PyObject *py_func = get_func(handle, "rmdir");
64+
if (py_func != NULL)
65+
{
66+
PyObject *py_ret = PyObject_CallFunction(py_func, "s", path);
67+
success = PyObject_IsTrue(py_ret);
68+
Py_DECREF(py_ret);
69+
Py_DECREF(py_func);
70+
}
71+
72+
if (success == 1)
73+
{
74+
return SMB_VFS_NEXT_RMDIR(handle, path);
75+
}
76+
else
77+
{
78+
return -1;
79+
}
80+
}
81+
5782
NTSTATUS python_create_file(struct vfs_handle_struct *handle,
5883
struct smb_request *req,
5984
uint16_t root_dir_fid,
@@ -79,6 +104,7 @@ NTSTATUS python_create_file(struct vfs_handle_struct *handle,
79104
PyObject *py_ret = PyObject_CallFunction(py_func, "s", smb_fname->base_name);
80105
success = PyObject_IsTrue(py_ret);
81106
Py_DECREF(py_ret);
107+
Py_DECREF(py_func);
82108
}
83109

84110
if (success == 1)
@@ -121,6 +147,7 @@ int python_rename(vfs_handle_struct *handle,
121147
smb_fname_dst->base_name);
122148
success = PyObject_IsTrue(py_ret);
123149
Py_DECREF(py_ret);
150+
Py_DECREF(py_func);
124151
}
125152

126153
if (success == 1)

commands.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ void python_disconnect(vfs_handle_struct *handle);
88
int python_mkdir(vfs_handle_struct *handle,
99
const char *path,
1010
mode_t mode);
11+
int python_rmdir(vfs_handle_struct *handle, const char *path);
1112

1213
NTSTATUS python_create_file(struct vfs_handle_struct *handle,
1314
struct smb_request *req,

handler.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ def mkdir(path):
1010
debug('Create dir: {}'.format(path))
1111
return True
1212

13+
def rmdir(path):
14+
debug('Remove dir: {}'.format(path))
15+
if path == 'dont_touch_this':
16+
return False
17+
return True
18+
1319
def create_file(path):
1420
debug('Create file: {}'.format(path))
1521
if path == 'bad_file':

vfs_python.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ static struct vfs_fn_pointers vfs_python_fns = {
55
.connect_fn = python_connect,
66
.disconnect_fn = python_disconnect,
77
.mkdir_fn = python_mkdir,
8+
.rmdir_fn = python_rmdir,
89
.create_file_fn = python_create_file,
910
.rename_fn = python_rename
1011
};

0 commit comments

Comments
 (0)