1 # Samba common group policy functions
3 # Copyright Andrew Tridgell 2010
4 # Copyright Amitay Isaacs 2011-2012 <amitay@gmail.com>
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 from samba
.credentials
import SMB_SIGNING_REQUIRED
21 from samba
.samba3
import param
as s3param
22 from samba
.samba3
import libsmb_samba_internal
as libsmb
23 from samba
.netcmd
import CommandError
25 def get_gpo_dn(samdb
, gpo
):
26 """Construct the DN for gpo"""
28 dn
= samdb
.get_default_basedn()
29 dn
.add_child(ldb
.Dn(samdb
, "CN=Policies,CN=System"))
30 dn
.add_child(ldb
.Dn(samdb
, "CN=%s" % gpo
))
33 def create_directory_hier(conn
, remotedir
):
34 elems
= remotedir
.replace('/', '\\').split('\\')
37 path
= path
+ '\\' + e
38 if not conn
.chkpath(path
):
41 def smb_connection(dc_hostname
, service
, lp
, creds
):
43 # Force signing for the smb connection
44 saved_signing_state
= creds
.get_smb_signing()
45 creds
.set_smb_signing(SMB_SIGNING_REQUIRED
)
47 # the SMB bindings rely on having a s3 loadparm
48 s3_lp
= s3param
.get_context()
49 s3_lp
.load(lp
.configfile
)
50 conn
= libsmb
.Conn(dc_hostname
, service
, lp
=s3_lp
, creds
=creds
)
52 raise CommandError("Error connecting to '%s' using SMB" % dc_hostname
)
54 creds
.set_smb_signing(saved_signing_state
)