-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcommands.c
More file actions
185 lines (165 loc) · 4.95 KB
/
commands.c
File metadata and controls
185 lines (165 loc) · 4.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#include "commands.h"
int python_connect(vfs_handle_struct *handle,
const char *service,
const char *user)
{
int success = 1;
PyObject *py_func = get_func(handle, "connect");
if (py_func != NULL)
{
PyObject *py_ret = PyObject_CallFunction(py_func, "ss", service, user);
success = PyObject_IsTrue(py_ret);
Py_DECREF(py_ret);
Py_DECREF(py_func);
}
if (success == 1)
{
return SMB_VFS_NEXT_CONNECT(handle, service, user);
}
else
{
return -1;
}
}
void python_disconnect(vfs_handle_struct *handle)
{
SMB_VFS_NEXT_DISCONNECT(handle);
}
int python_mkdir(vfs_handle_struct *handle,
const char *path,
mode_t mode)
{
int success = 1;
PyObject *py_func = get_func(handle, "mkdir");
if (py_func != NULL)
{
PyObject *py_ret = PyObject_CallFunction(py_func, "s", path);
success = PyObject_IsTrue(py_ret);
Py_DECREF(py_ret);
Py_DECREF(py_func);
}
if (success == 1)
{
return SMB_VFS_NEXT_MKDIR(handle, path, mode);
}
else
{
return -1;
}
}
int python_rmdir(vfs_handle_struct *handle, const char *path)
{
int success = 1;
PyObject *py_func = get_func(handle, "rmdir");
if (py_func != NULL)
{
PyObject *py_ret = PyObject_CallFunction(py_func, "s", path);
success = PyObject_IsTrue(py_ret);
Py_DECREF(py_ret);
Py_DECREF(py_func);
}
if (success == 1)
{
return SMB_VFS_NEXT_RMDIR(handle, path);
}
else
{
return -1;
}
}
NTSTATUS python_create_file(struct vfs_handle_struct *handle,
struct smb_request *req,
uint16_t root_dir_fid,
struct smb_filename *smb_fname,
uint32_t access_mask,
uint32_t share_access,
uint32_t create_disposition,
uint32_t create_options,
uint32_t file_attributes,
uint32_t oplock_request,
uint64_t allocation_size,
uint32_t private_flags,
struct security_descriptor *sd,
struct ea_list *ea_list,
files_struct **result,
int *pinfo)
{
int success = 1;
PyObject *py_func = get_func(handle, "create_file");
if (py_func != NULL)
{
PyObject *py_ret = PyObject_CallFunction(py_func, "s", smb_fname->base_name);
success = PyObject_IsTrue(py_ret);
Py_DECREF(py_ret);
Py_DECREF(py_func);
}
if (success == 1)
{
return SMB_VFS_NEXT_CREATE_FILE(handle,
req,
root_dir_fid,
smb_fname,
access_mask,
share_access,
create_disposition,
create_options,
file_attributes,
oplock_request,
allocation_size,
private_flags,
sd,
ea_list,
result,
pinfo);
}
else
{
return NT_STATUS_UNSUCCESSFUL;
}
}
int python_rename(vfs_handle_struct *handle,
const struct smb_filename *smb_fname_src,
const struct smb_filename *smb_fname_dst)
{
int success = 1;
PyObject *py_func = get_func(handle, "rename");
if (py_func != NULL)
{
PyObject *py_ret = PyObject_CallFunction(py_func,
"ss",
smb_fname_src->base_name,
smb_fname_dst->base_name);
success = PyObject_IsTrue(py_ret);
Py_DECREF(py_ret);
Py_DECREF(py_func);
}
if (success == 1)
{
return SMB_VFS_NEXT_RENAME(handle, smb_fname_src, smb_fname_dst);
}
else
{
return -1;
}
}
int python_unlink(vfs_handle_struct *handle,
const struct smb_filename *smb_fname)
{
int success = 1;
PyObject *py_func = get_func(handle, "unlink");
if (py_func != NULL)
{
PyObject *py_ret = PyObject_CallFunction(py_func, "s", smb_fname->base_name);
success = PyObject_IsTrue(py_ret);
Py_DECREF(py_ret);
Py_DECREF(py_func);
}
if (success == 1)
{
return SMB_VFS_NEXT_UNLINK(handle, smb_fname);
}
else
{
return -1;
}
}