2 Unix SMB/CIFS implementation.
3 Set NT and POSIX ACLs and other VFS operations from Python
5 Copyrigyt (C) Andrew Bartlett 2012
6 Copyright (C) Jeremy Allison 1994-2009.
7 Copyright (C) Andreas Gruenbacher 2002.
8 Copyright (C) Simo Sorce <idra@samba.org> 2009.
9 Copyright (C) Simo Sorce 2002
10 Copyright (C) Eric Lorimer 2002
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 3 of the License, or
15 (at your option) any later version.
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with this program. If not, see <http://www.gnu.org/licenses/>.
26 #include "lib/replace/system/python.h"
28 #include "python/py3compat.h"
29 #include "python/modules.h"
30 #include "smbd/smbd.h"
31 #include "libcli/util/pyerrors.h"
32 #include "librpc/rpc/pyrpc_util.h"
34 #include "system/filesys.h"
39 extern const struct generic_mapping file_generic_mapping
;
42 #define DBGC_CLASS DBGC_ACLS
45 #define DIRECTORY_FLAGS O_RDONLY|O_DIRECTORY
47 /* POSIX allows us to open a directory with O_RDONLY. */
48 #define DIRECTORY_FLAGS O_RDONLY
52 static connection_struct
*get_conn_tos(
54 const struct auth_session_info
*session_info
)
56 struct conn_struct_tos
*c
= NULL
;
60 struct smb_filename cwd_fname
= {0};
63 if (!posix_locking_init(false)) {
69 snum
= lp_servicenumber(service
);
71 PyErr_SetString(PyExc_RuntimeError
, "unknown service");
77 * Make sure that session unix info is filled,
78 * which is required by vfs operations.
80 if (session_info
->unix_info
== NULL
) {
81 PyErr_SetString(PyExc_RuntimeError
,
82 "Session unix info not initialized");
85 if (session_info
->unix_info
->unix_name
== NULL
) {
86 PyErr_SetString(PyExc_RuntimeError
,
87 "Session unix info not available");
91 status
= create_conn_struct_tos(NULL
,
96 PyErr_NTSTATUS_IS_ERR_RAISE(status
);
98 /* Ignore read-only and share restrictions */
99 c
->conn
->read_only
= false;
100 c
->conn
->share_access
= SEC_RIGHTS_FILE_ALL
;
102 /* Provided by libreplace if not present. Always mallocs. */
103 cwd
= get_current_dir_name();
109 cwd_fname
.base_name
= cwd
;
111 * We need to call vfs_ChDir() to initialize
112 * conn->cwd_fsp correctly. Change directory
113 * to current directory (so no change for process).
115 ret
= vfs_ChDir(c
->conn
, &cwd_fname
);
117 status
= map_nt_error_from_unix(errno
);
119 PyErr_NTSTATUS_IS_ERR_RAISE(status
);
127 static int set_sys_acl_conn(const char *fname
,
128 SMB_ACL_TYPE_T acltype
,
129 SMB_ACL_T theacl
, connection_struct
*conn
)
132 struct smb_filename
*smb_fname
= NULL
;
133 TALLOC_CTX
*frame
= talloc_stackframe();
136 smb_fname
= synthetic_smb_fname_split(frame
,
138 lp_posix_pathnames());
139 if (smb_fname
== NULL
) {
144 status
= openat_pathref_fsp(conn
->cwd_fsp
, smb_fname
);
145 if (!NT_STATUS_IS_OK(status
)) {
147 errno
= map_errno_from_nt_status(status
);
151 ret
= SMB_VFS_SYS_ACL_SET_FD(smb_fname
->fsp
, acltype
, theacl
);
153 status
= fd_close(smb_fname
->fsp
);
154 if (!NT_STATUS_IS_OK(status
)) {
156 errno
= map_errno_from_nt_status(status
);
165 static NTSTATUS
init_files_struct(TALLOC_CTX
*mem_ctx
,
167 struct connection_struct
*conn
,
169 struct files_struct
**_fsp
)
171 struct vfs_open_how how
= { .flags
= flags
, .mode
= 0644 };
172 struct smb_filename
*smb_fname
= NULL
;
175 struct files_struct
*fsp
;
176 struct files_struct
*fspcwd
= NULL
;
179 fsp
= talloc_zero(mem_ctx
, struct files_struct
);
181 return NT_STATUS_NO_MEMORY
;
183 fsp
->fh
= fd_handle_create(fsp
);
184 if (fsp
->fh
== NULL
) {
185 return NT_STATUS_NO_MEMORY
;
189 smb_fname
= synthetic_smb_fname_split(fsp
,
191 lp_posix_pathnames());
192 if (smb_fname
== NULL
) {
193 return NT_STATUS_NO_MEMORY
;
196 fsp
->fsp_name
= smb_fname
;
198 status
= vfs_at_fspcwd(fsp
, conn
, &fspcwd
);
199 if (!NT_STATUS_IS_OK(status
)) {
204 * we want total control over the permissions on created files,
205 * so set our umask to 0 (this matters if flags contains O_CREAT)
207 saved_umask
= umask(0);
209 fd
= SMB_VFS_OPENAT(conn
,
220 return NT_STATUS_OBJECT_NAME_NOT_FOUND
;
222 return NT_STATUS_INVALID_PARAMETER
;
226 status
= vfs_stat_fsp(fsp
);
227 if (!NT_STATUS_IS_OK(status
)) {
228 /* If we have an fd, this stat should succeed. */
229 DEBUG(0,("Error doing fstat on open file %s (%s)\n",
230 smb_fname_str_dbg(smb_fname
),
231 nt_errstr(status
) ));
235 fsp
->file_id
= vfs_file_id_from_sbuf(conn
, &smb_fname
->st
);
236 fsp
->vuid
= UID_FIELD_INVALID
;
238 fsp
->fsp_flags
.can_lock
= true;
239 fsp
->fsp_flags
.can_read
= true;
240 fsp
->fsp_flags
.can_write
= true;
241 fsp
->print_file
= NULL
;
242 fsp
->fsp_flags
.modified
= false;
243 fsp
->sent_oplock_break
= NO_BREAK_SENT
;
244 fsp
->fsp_flags
.is_directory
= S_ISDIR(smb_fname
->st
.st_ex_mode
);
251 static NTSTATUS
set_nt_acl_conn(const char *fname
,
252 uint32_t security_info_sent
, const struct security_descriptor
*sd
,
253 connection_struct
*conn
)
255 TALLOC_CTX
*frame
= talloc_stackframe();
256 struct files_struct
*fsp
= NULL
;
257 NTSTATUS status
= NT_STATUS_OK
;
259 /* first, try to open it as a file with flag O_RDWR */
260 status
= init_files_struct(frame
,
265 if (!NT_STATUS_IS_OK(status
) && errno
== EISDIR
) {
266 /* if fail, try to open as dir */
267 status
= init_files_struct(frame
,
274 if (!NT_STATUS_IS_OK(status
)) {
275 DBG_ERR("init_files_struct failed: %s\n",
284 status
= SMB_VFS_FSET_NT_ACL(metadata_fsp(fsp
), security_info_sent
, sd
);
285 if (!NT_STATUS_IS_OK(status
)) {
286 DEBUG(0,("set_nt_acl_conn: fset_nt_acl returned %s.\n", nt_errstr(status
)));
295 static NTSTATUS
get_nt_acl_conn(TALLOC_CTX
*mem_ctx
,
297 connection_struct
*conn
,
298 uint32_t security_info_wanted
,
299 struct security_descriptor
**sd
)
301 TALLOC_CTX
*frame
= talloc_stackframe();
303 struct smb_filename
*smb_fname
= NULL
;
305 smb_fname
= synthetic_smb_fname_split(frame
,
307 lp_posix_pathnames());
309 if (smb_fname
== NULL
) {
311 return NT_STATUS_NO_MEMORY
;
314 status
= openat_pathref_fsp(conn
->cwd_fsp
, smb_fname
);
315 if (!NT_STATUS_IS_OK(status
)) {
320 status
= SMB_VFS_FGET_NT_ACL(metadata_fsp(smb_fname
->fsp
),
321 security_info_wanted
,
324 if (!NT_STATUS_IS_OK(status
)) {
325 DBG_ERR("fget_nt_acl_at returned %s.\n",
329 status
= fd_close(smb_fname
->fsp
);
330 if (!NT_STATUS_IS_OK(status
)) {
340 static int set_acl_entry_perms(SMB_ACL_ENTRY_T entry
, mode_t perm_mask
)
342 SMB_ACL_PERMSET_T perms
= NULL
;
344 if (sys_acl_get_permset(entry
, &perms
) != 0) {
348 if (sys_acl_clear_perms(perms
) != 0) {
352 if ((perm_mask
& SMB_ACL_READ
) != 0 &&
353 sys_acl_add_perm(perms
, SMB_ACL_READ
) != 0) {
357 if ((perm_mask
& SMB_ACL_WRITE
) != 0 &&
358 sys_acl_add_perm(perms
, SMB_ACL_WRITE
) != 0) {
362 if ((perm_mask
& SMB_ACL_EXECUTE
) != 0 &&
363 sys_acl_add_perm(perms
, SMB_ACL_EXECUTE
) != 0) {
367 if (sys_acl_set_permset(entry
, perms
) != 0) {
374 static SMB_ACL_T
make_simple_acl(TALLOC_CTX
*mem_ctx
,
378 mode_t mode
= SMB_ACL_READ
|SMB_ACL_WRITE
|SMB_ACL_EXECUTE
;
380 mode_t mode_user
= (chmod_mode
& 0700) >> 6;
381 mode_t mode_group
= (chmod_mode
& 070) >> 3;
382 mode_t mode_other
= chmod_mode
& 07;
383 SMB_ACL_ENTRY_T entry
;
384 SMB_ACL_T acl
= sys_acl_init(mem_ctx
);
390 if (sys_acl_create_entry(&acl
, &entry
) != 0) {
395 if (sys_acl_set_tag_type(entry
, SMB_ACL_USER_OBJ
) != 0) {
400 if (set_acl_entry_perms(entry
, mode_user
) != 0) {
405 if (sys_acl_create_entry(&acl
, &entry
) != 0) {
410 if (sys_acl_set_tag_type(entry
, SMB_ACL_GROUP_OBJ
) != 0) {
415 if (set_acl_entry_perms(entry
, mode_group
) != 0) {
420 if (sys_acl_create_entry(&acl
, &entry
) != 0) {
425 if (sys_acl_set_tag_type(entry
, SMB_ACL_OTHER
) != 0) {
430 if (set_acl_entry_perms(entry
, mode_other
) != 0) {
436 if (sys_acl_create_entry(&acl
, &entry
) != 0) {
441 if (sys_acl_set_tag_type(entry
, SMB_ACL_GROUP
) != 0) {
446 if (sys_acl_set_qualifier(entry
, &gid
) != 0) {
451 if (set_acl_entry_perms(entry
, mode_group
) != 0) {
457 if (sys_acl_create_entry(&acl
, &entry
) != 0) {
462 if (sys_acl_set_tag_type(entry
, SMB_ACL_MASK
) != 0) {
467 if (set_acl_entry_perms(entry
, mode
) != 0) {
476 set a simple ACL on a file, as a test
478 static PyObject
*py_smbd_set_simple_acl(PyObject
*self
, PyObject
*args
, PyObject
*kwargs
)
480 const char * const kwnames
[] = {
488 char *fname
, *service
= NULL
;
489 PyObject
*py_session
= Py_None
;
490 struct auth_session_info
*session_info
= NULL
;
495 connection_struct
*conn
;
497 if (!PyArg_ParseTupleAndKeywords(args
, kwargs
, "siO|iz",
498 discard_const_p(char *, kwnames
),
506 if (!py_check_dcerpc_type(py_session
,
511 session_info
= pytalloc_get_type(py_session
,
512 struct auth_session_info
);
513 if (session_info
== NULL
) {
514 PyErr_Format(PyExc_TypeError
,
515 "Expected auth_session_info for session_info argument got %s",
516 pytalloc_get_name(py_session
));
520 frame
= talloc_stackframe();
522 acl
= make_simple_acl(frame
, gid
, mode
);
528 conn
= get_conn_tos(service
, session_info
);
534 ret
= set_sys_acl_conn(fname
, SMB_ACL_TYPE_ACCESS
, acl
, conn
);
539 return PyErr_SetFromErrno(PyExc_OSError
);
550 static PyObject
*py_smbd_chown(PyObject
*self
, PyObject
*args
, PyObject
*kwargs
)
552 const char * const kwnames
[] = {
560 connection_struct
*conn
;
563 char *fname
, *service
= NULL
;
564 PyObject
*py_session
= Py_None
;
565 struct auth_session_info
*session_info
= NULL
;
568 struct files_struct
*fsp
= NULL
;
570 if (!PyArg_ParseTupleAndKeywords(args
, kwargs
, "siiO|z",
571 discard_const_p(char *, kwnames
),
579 if (!py_check_dcerpc_type(py_session
,
584 session_info
= pytalloc_get_type(py_session
,
585 struct auth_session_info
);
586 if (session_info
== NULL
) {
587 PyErr_Format(PyExc_TypeError
,
588 "Expected auth_session_info for session_info argument got %s",
589 pytalloc_get_name(py_session
));
593 frame
= talloc_stackframe();
595 conn
= get_conn_tos(service
, session_info
);
601 /* first, try to open it as a file with flag O_RDWR */
602 status
= init_files_struct(frame
,
607 if (!NT_STATUS_IS_OK(status
) && errno
== EISDIR
) {
608 /* if fail, try to open as dir */
609 status
= init_files_struct(frame
,
616 if (!NT_STATUS_IS_OK(status
)) {
617 DBG_ERR("init_files_struct failed: %s\n",
624 * The following macro raises a python
625 * error then returns NULL.
627 PyErr_NTSTATUS_IS_ERR_RAISE(status
);
630 ret
= SMB_VFS_FCHOWN(fsp
, uid
, gid
);
632 int saved_errno
= errno
;
636 return PyErr_SetFromErrno(PyExc_OSError
);
648 static PyObject
*py_smbd_unlink(PyObject
*self
, PyObject
*args
, PyObject
*kwargs
)
650 const char * const kwnames
[] = {
656 connection_struct
*conn
;
658 struct smb_filename
*smb_fname
= NULL
;
659 struct smb_filename
*parent_fname
= NULL
;
660 struct smb_filename
*at_fname
= NULL
;
661 PyObject
*py_session
= Py_None
;
662 struct auth_session_info
*session_info
= NULL
;
663 char *fname
, *service
= NULL
;
667 frame
= talloc_stackframe();
669 if (!PyArg_ParseTupleAndKeywords(args
, kwargs
, "sO|z",
670 discard_const_p(char *, kwnames
),
678 if (!py_check_dcerpc_type(py_session
,
684 session_info
= pytalloc_get_type(py_session
,
685 struct auth_session_info
);
686 if (session_info
== NULL
) {
687 PyErr_Format(PyExc_TypeError
,
688 "Expected auth_session_info for session_info argument got %s",
689 pytalloc_get_name(py_session
));
694 conn
= get_conn_tos(service
, session_info
);
700 smb_fname
= synthetic_smb_fname_split(frame
,
702 lp_posix_pathnames());
703 if (smb_fname
== NULL
) {
705 return PyErr_NoMemory();
708 status
= parent_pathref(frame
,
713 if (!NT_STATUS_IS_OK(status
)) {
715 return PyErr_NoMemory();
718 ret
= SMB_VFS_UNLINKAT(conn
,
725 return PyErr_SetFromErrno(PyExc_OSError
);
734 check if we have ACL support
736 static PyObject
*py_smbd_have_posix_acls(PyObject
*self
,
737 PyObject
*Py_UNUSED(ignored
))
739 #ifdef HAVE_POSIX_ACLS
740 return PyBool_FromLong(true);
742 return PyBool_FromLong(false);
747 set the NT ACL on a file
749 static PyObject
*py_smbd_set_nt_acl(PyObject
*self
, PyObject
*args
, PyObject
*kwargs
)
751 const char * const kwnames
[] = {
753 "security_info_sent",
761 char *fname
, *service
= NULL
;
762 int security_info_sent
;
764 struct security_descriptor
*sd
;
765 PyObject
*py_session
= Py_None
;
766 struct auth_session_info
*session_info
= NULL
;
767 connection_struct
*conn
;
770 frame
= talloc_stackframe();
772 if (!PyArg_ParseTupleAndKeywords(args
, kwargs
, "siOO|z",
773 discard_const_p(char *, kwnames
),
783 if (!py_check_dcerpc_type(py_sd
, "samba.dcerpc.security", "descriptor")) {
788 if (!py_check_dcerpc_type(py_session
,
794 session_info
= pytalloc_get_type(py_session
,
795 struct auth_session_info
);
796 if (session_info
== NULL
) {
797 PyErr_Format(PyExc_TypeError
,
798 "Expected auth_session_info for session_info argument got %s",
799 pytalloc_get_name(py_session
));
803 conn
= get_conn_tos(service
, session_info
);
809 sd
= pytalloc_get_type(py_sd
, struct security_descriptor
);
811 status
= set_nt_acl_conn(fname
, security_info_sent
, sd
, conn
);
813 if (NT_STATUS_IS_ERR(status
)) {
814 if (NT_STATUS_EQUAL(status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
)) {
816 * This will show up as a FileNotFoundError in python.
818 PyErr_SetFromErrnoWithFilename(PyExc_OSError
, fname
);
820 PyErr_SetNTSTATUS(status
);
829 Return the NT ACL on a file
831 static PyObject
*py_smbd_get_nt_acl(PyObject
*self
, PyObject
*args
, PyObject
*kwargs
)
833 const char * const kwnames
[] = {
835 "security_info_wanted",
840 char *fname
, *service
= NULL
;
841 int security_info_wanted
;
843 struct security_descriptor
*sd
;
844 TALLOC_CTX
*frame
= talloc_stackframe();
845 PyObject
*py_session
= Py_None
;
846 struct auth_session_info
*session_info
= NULL
;
847 connection_struct
*conn
;
851 ret
= PyArg_ParseTupleAndKeywords(args
,
854 discard_const_p(char *, kwnames
),
856 &security_info_wanted
,
864 if (!py_check_dcerpc_type(py_session
,
870 session_info
= pytalloc_get_type(py_session
,
871 struct auth_session_info
);
872 if (session_info
== NULL
) {
875 "Expected auth_session_info for "
876 "session_info argument got %s",
877 pytalloc_get_name(py_session
));
882 conn
= get_conn_tos(service
, session_info
);
888 status
= get_nt_acl_conn(frame
, fname
, conn
, security_info_wanted
, &sd
);
889 if (NT_STATUS_IS_ERR(status
)) {
890 if (NT_STATUS_EQUAL(status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
)) {
892 * This will show up as a FileNotFoundError in python,
893 * from which samba-tool can at least produce a short
894 * message containing the problematic filename.
896 PyErr_SetFromErrnoWithFilename(PyExc_OSError
, fname
);
898 PyErr_SetNTSTATUS(status
);
904 py_sd
= py_return_ndr_struct("samba.dcerpc.security", "descriptor", sd
, sd
);
912 set the posix (or similar) ACL on a file
914 static PyObject
*py_smbd_set_sys_acl(PyObject
*self
, PyObject
*args
, PyObject
*kwargs
)
916 const char * const kwnames
[] = {
924 TALLOC_CTX
*frame
= talloc_stackframe();
926 char *fname
, *service
= NULL
;
928 PyObject
*py_session
= Py_None
;
929 struct auth_session_info
*session_info
= NULL
;
930 struct smb_acl_t
*acl
;
932 connection_struct
*conn
;
934 if (!PyArg_ParseTupleAndKeywords(args
, kwargs
, "siOO|z",
935 discard_const_p(char *, kwnames
),
945 if (!py_check_dcerpc_type(py_acl
, "samba.dcerpc.smb_acl", "t")) {
950 if (!py_check_dcerpc_type(py_session
,
956 session_info
= pytalloc_get_type(py_session
,
957 struct auth_session_info
);
958 if (session_info
== NULL
) {
959 PyErr_Format(PyExc_TypeError
,
960 "Expected auth_session_info for session_info argument got %s",
961 pytalloc_get_name(py_session
));
966 conn
= get_conn_tos(service
, session_info
);
972 acl
= pytalloc_get_type(py_acl
, struct smb_acl_t
);
974 ret
= set_sys_acl_conn(fname
, acl_type
, acl
, conn
);
978 return PyErr_SetFromErrno(PyExc_OSError
);
986 Return the posix (or similar) ACL on a file
988 static PyObject
*py_smbd_get_sys_acl(PyObject
*self
, PyObject
*args
, PyObject
*kwargs
)
990 const char * const kwnames
[] = {
999 PyObject
*py_session
= Py_None
;
1000 struct auth_session_info
*session_info
= NULL
;
1001 struct smb_acl_t
*acl
;
1003 TALLOC_CTX
*frame
= talloc_stackframe();
1004 connection_struct
*conn
;
1005 char *service
= NULL
;
1006 struct smb_filename
*smb_fname
= NULL
;
1009 if (!PyArg_ParseTupleAndKeywords(args
, kwargs
, "siO|z",
1010 discard_const_p(char *, kwnames
),
1019 if (!py_check_dcerpc_type(py_session
,
1020 "samba.dcerpc.auth",
1025 session_info
= pytalloc_get_type(py_session
,
1026 struct auth_session_info
);
1027 if (session_info
== NULL
) {
1028 PyErr_Format(PyExc_TypeError
,
1029 "Expected auth_session_info for session_info argument got %s",
1030 pytalloc_get_name(py_session
));
1035 conn
= get_conn_tos(service
, session_info
);
1041 smb_fname
= synthetic_smb_fname_split(frame
,
1043 lp_posix_pathnames());
1044 if (smb_fname
== NULL
) {
1049 status
= openat_pathref_fsp(conn
->cwd_fsp
, smb_fname
);
1050 if (!NT_STATUS_IS_OK(status
)) {
1052 PyErr_SetNTSTATUS(status
);
1056 acl
= SMB_VFS_SYS_ACL_GET_FD(smb_fname
->fsp
, acl_type
, frame
);
1059 return PyErr_SetFromErrno(PyExc_OSError
);
1062 status
= fd_close(smb_fname
->fsp
);
1063 if (!NT_STATUS_IS_OK(status
)) {
1065 PyErr_SetNTSTATUS(status
);
1069 py_acl
= py_return_ndr_struct("samba.dcerpc.smb_acl", "t", acl
, acl
);
1076 static PyObject
*py_smbd_mkdir(PyObject
*self
, PyObject
*args
, PyObject
*kwargs
)
1078 const char * const kwnames
[] = {
1084 char *fname
, *service
= NULL
;
1085 PyObject
*py_session
= Py_None
;
1086 struct auth_session_info
*session_info
= NULL
;
1087 TALLOC_CTX
*frame
= talloc_stackframe();
1088 struct connection_struct
*conn
= NULL
;
1089 struct smb_filename
*smb_fname
= NULL
;
1090 struct smb_filename
*parent_fname
= NULL
;
1091 struct smb_filename
*base_name
= NULL
;
1096 if (!PyArg_ParseTupleAndKeywords(args
,
1099 discard_const_p(char *,
1108 if (!py_check_dcerpc_type(py_session
,
1109 "samba.dcerpc.auth",
1114 session_info
= pytalloc_get_type(py_session
,
1115 struct auth_session_info
);
1116 if (session_info
== NULL
) {
1117 PyErr_Format(PyExc_TypeError
,
1118 "Expected auth_session_info for session_info argument got %s",
1119 pytalloc_get_name(py_session
));
1124 conn
= get_conn_tos(service
, session_info
);
1130 smb_fname
= synthetic_smb_fname(talloc_tos(),
1135 lp_posix_pathnames() ?
1136 SMB_FILENAME_POSIX_PATH
: 0);
1138 if (smb_fname
== NULL
) {
1143 status
= parent_pathref(talloc_tos(),
1148 if (!NT_STATUS_IS_OK(status
)) {
1153 /* we want total control over the permissions on created files,
1154 so set our umask to 0 */
1155 saved_umask
= umask(0);
1157 ret
= SMB_VFS_MKDIRAT(conn
,
1165 DBG_ERR("mkdirat error=%d (%s)\n", errno
, strerror(errno
));
1176 Create an empty file
1178 static PyObject
*py_smbd_create_file(PyObject
*self
, PyObject
*args
, PyObject
*kwargs
)
1180 const char * const kwnames
[] = {
1186 char *fname
, *service
= NULL
;
1187 PyObject
*py_session
= Py_None
;
1188 struct auth_session_info
*session_info
= NULL
;
1189 TALLOC_CTX
*frame
= talloc_stackframe();
1190 struct connection_struct
*conn
= NULL
;
1191 struct files_struct
*fsp
= NULL
;
1194 if (!PyArg_ParseTupleAndKeywords(args
,
1197 discard_const_p(char *,
1206 if (!py_check_dcerpc_type(py_session
,
1207 "samba.dcerpc.auth",
1212 session_info
= pytalloc_get_type(py_session
,
1213 struct auth_session_info
);
1214 if (session_info
== NULL
) {
1215 PyErr_Format(PyExc_TypeError
,
1216 "Expected auth_session_info for session_info argument got %s",
1217 pytalloc_get_name(py_session
));
1222 conn
= get_conn_tos(service
, session_info
);
1228 status
= init_files_struct(frame
,
1231 O_CREAT
|O_EXCL
|O_RDWR
,
1233 if (!NT_STATUS_IS_OK(status
)) {
1234 DBG_ERR("init_files_struct failed: %s\n",
1236 } else if (fsp
!= NULL
) {
1241 PyErr_NTSTATUS_NOT_OK_RAISE(status
);
1246 static PyMethodDef py_smbd_methods
[] = {
1247 { "have_posix_acls",
1248 (PyCFunction
)py_smbd_have_posix_acls
, METH_NOARGS
,
1251 PY_DISCARD_FUNC_SIG(PyCFunction
, py_smbd_set_simple_acl
),
1252 METH_VARARGS
|METH_KEYWORDS
,
1255 PY_DISCARD_FUNC_SIG(PyCFunction
, py_smbd_set_nt_acl
),
1256 METH_VARARGS
|METH_KEYWORDS
,
1259 PY_DISCARD_FUNC_SIG(PyCFunction
, py_smbd_get_nt_acl
),
1260 METH_VARARGS
|METH_KEYWORDS
,
1263 PY_DISCARD_FUNC_SIG(PyCFunction
, py_smbd_get_sys_acl
),
1264 METH_VARARGS
|METH_KEYWORDS
,
1267 PY_DISCARD_FUNC_SIG(PyCFunction
, py_smbd_set_sys_acl
),
1268 METH_VARARGS
|METH_KEYWORDS
,
1271 PY_DISCARD_FUNC_SIG(PyCFunction
, py_smbd_chown
),
1272 METH_VARARGS
|METH_KEYWORDS
,
1275 PY_DISCARD_FUNC_SIG(PyCFunction
, py_smbd_unlink
),
1276 METH_VARARGS
|METH_KEYWORDS
,
1279 PY_DISCARD_FUNC_SIG(PyCFunction
, py_smbd_mkdir
),
1280 METH_VARARGS
|METH_KEYWORDS
,
1283 PY_DISCARD_FUNC_SIG(PyCFunction
, py_smbd_create_file
),
1284 METH_VARARGS
|METH_KEYWORDS
,
1289 void initsmbd(void);
1291 static struct PyModuleDef moduledef
= {
1292 PyModuleDef_HEAD_INIT
,
1294 .m_doc
= "Python bindings for the smbd file server.",
1296 .m_methods
= py_smbd_methods
,
1299 MODULE_INIT_FUNC(smbd
)
1303 m
= PyModule_Create(&moduledef
);