forked from vortec/vfs_python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommands.c
More file actions
181 lines (163 loc) · 5.36 KB
/
commands.c
File metadata and controls
181 lines (163 loc) · 5.36 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
#include "includes.h"
#include "commands.h"
#include "vfs.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_XDECREF(py_ret);
Py_XDECREF(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_mkdirat(vfs_handle_struct *handle,
struct files_struct *dirfsp,
const struct smb_filename *smb_fname,
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", smb_fname->base_name);
success = PyObject_IsTrue(py_ret);
Py_XDECREF(py_ret);
Py_XDECREF(py_func);
}
if (success == 1)
{
return SMB_VFS_NEXT_MKDIRAT(handle, dirfsp, smb_fname, mode);
}
else
{
return -1;
}
}
int python_unlinkat(vfs_handle_struct *handle,
struct files_struct *dirfsp,
const struct smb_filename *smb_fname,
int flags)
{
int success = 1;
PyObject *py_func = NULL;
if (flags & AT_REMOVEDIR) {
py_func = get_func(handle, "rmdir");
} else {
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_XDECREF(py_ret);
Py_XDECREF(py_func);
}
if (success == 1)
{
return SMB_VFS_NEXT_UNLINKAT(handle, dirfsp, smb_fname, flags);
}
else
{
return -1;
}
}
NTSTATUS python_create_file(struct vfs_handle_struct *handle,
struct smb_request *req,
struct files_struct *dirfsp,
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,
const struct smb2_lease *lease,
uint64_t allocation_size,
uint32_t private_flags,
struct security_descriptor *sd,
struct ea_list *ea_list,
files_struct **result,
int *pinfo,
const struct smb2_create_blobs *in_context_blobs,
struct smb2_create_blobs *out_context_blobs)
{
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_XDECREF(py_ret);
Py_XDECREF(py_func);
}
if (success == 1)
{
return SMB_VFS_NEXT_CREATE_FILE(handle,
req,
dirfsp,
smb_fname,
access_mask,
share_access,
create_disposition,
create_options,
file_attributes,
oplock_request,
lease,
allocation_size,
private_flags,
sd,
ea_list,
result,
pinfo,
in_context_blobs,
out_context_blobs);
}
else
{
return NT_STATUS_UNSUCCESSFUL;
}
}
int python_renameat(struct vfs_handle_struct *handle,
struct files_struct *oldfsp,
const struct smb_filename *smb_fname_src,
struct files_struct *newfsp,
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_XDECREF(py_ret);
Py_XDECREF(py_func);
}
if (success == 1)
{
return SMB_VFS_NEXT_RENAMEAT(handle, oldfsp, smb_fname_src, newfsp, smb_fname_dst);
}
else
{
return -1;
}
}