1 # Copyright (C) Volker Lendecke <vl@samba.org> 2020
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 from samba
.samba3
.libsmb_samba_cwrapper
import *
17 from samba
.dcerpc
import security
19 class Conn(LibsmbCConn
):
20 def deltree(self
, path
):
21 if self
.chkpath(path
):
22 for entry
in self
.list(path
):
23 self
.deltree(path
+ "\\" + entry
['name'])
28 SECINFO_DEFAULT_FLAGS
= \
29 security
.SECINFO_OWNER | \
30 security
.SECINFO_GROUP | \
31 security
.SECINFO_DACL | \
34 def required_access_for_get_secinfo(self
, secinfo
):
38 # This is based on MS-FSA
39 # 2.1.5.13 Server Requests a Query of Security Information
41 # Note that MS-SMB2 3.3.5.20.3 Handling SMB2_0_INFO_SECURITY
42 # doesn't specify any extra checks
45 if secinfo
& security
.SECINFO_OWNER
:
46 access |
= security
.SEC_STD_READ_CONTROL
47 if secinfo
& security
.SECINFO_GROUP
:
48 access |
= security
.SEC_STD_READ_CONTROL
49 if secinfo
& security
.SECINFO_DACL
:
50 access |
= security
.SEC_STD_READ_CONTROL
51 if secinfo
& security
.SECINFO_SACL
:
52 access |
= security
.SEC_FLAG_SYSTEM_SECURITY
54 if secinfo
& security
.SECINFO_LABEL
:
55 access |
= security
.SEC_STD_READ_CONTROL
59 def required_access_for_set_secinfo(self
, secinfo
):
63 # This is based on MS-FSA
64 # 2.1.5.16 Server Requests Setting of Security Information
65 # and additional constraints from
66 # MS-SMB2 3.3.5.21.3 Handling SMB2_0_INFO_SECURITY
69 if secinfo
& security
.SECINFO_OWNER
:
70 access |
= security
.SEC_STD_WRITE_OWNER
71 if secinfo
& security
.SECINFO_GROUP
:
72 access |
= security
.SEC_STD_WRITE_OWNER
73 if secinfo
& security
.SECINFO_DACL
:
74 access |
= security
.SEC_STD_WRITE_DAC
75 if secinfo
& security
.SECINFO_SACL
:
76 access |
= security
.SEC_FLAG_SYSTEM_SECURITY
78 if secinfo
& security
.SECINFO_LABEL
:
79 access |
= security
.SEC_STD_WRITE_OWNER
81 if secinfo
& security
.SECINFO_ATTRIBUTE
:
82 access |
= security
.SEC_STD_WRITE_DAC
84 if secinfo
& security
.SECINFO_SCOPE
:
85 access |
= security
.SEC_FLAG_SYSTEM_SECURITY
87 if secinfo
& security
.SECINFO_BACKUP
:
88 access |
= security
.SEC_STD_WRITE_OWNER
89 access |
= security
.SEC_STD_WRITE_DAC
90 access |
= security
.SEC_FLAG_SYSTEM_SECURITY
98 """Get security descriptor for file."""
100 sinfo
= self
.SECINFO_DEFAULT_FLAGS
101 if access_mask
is None:
102 access_mask
= self
.required_access_for_get_secinfo(sinfo
)
105 DesiredAccess
=access_mask
,
106 ShareAccess
=(FILE_SHARE_READ|FILE_SHARE_WRITE
))
108 sd
= self
.get_sd(fnum
, sinfo
)
118 """Set security descriptor for file."""
120 sinfo
= self
.SECINFO_DEFAULT_FLAGS
121 if access_mask
is None:
122 access_mask
= self
.required_access_for_set_secinfo(sinfo
)
125 DesiredAccess
=access_mask
,
126 ShareAccess
=(FILE_SHARE_READ|FILE_SHARE_WRITE
))
128 self
.set_sd(fnum
, sd
, sinfo
)