<s> import os <EOL> import samba . getopt as options <EOL> import ldb <EOL> from samba . auth import system_session <EOL> from samba . netcmd import ( <EOL> Command , <EOL> CommandError , <EOL> Option , <EOL> SuperCommand , <EOL> ) <EOL> from samba . samdb import SamDB <EOL> from samba import dsdb <EOL> from samba . dcerpc import security <EOL> from samba . ndr import ndr_unpack <EOL> import samba . security <EOL> import samba . auth <EOL> from samba . auth import AUTH_SESSION_INFO_DEFAULT_GROUPS , AUTH_SESSION_INFO_AUTHENTICATED , AUTH_SESSION_INFO_SIMPLE_PRIVILEGES <EOL> from samba . netcmd . common import netcmd_finddc <EOL> from samba import policy <EOL> from samba import smb <EOL> import uuid <EOL> from samba . ntacls import dsacl2fsacl <EOL> from samba . dcerpc import nbt <EOL> from samba . net import Net <EOL> def samdb_connect ( ctx ) : <EOL> '''<STR_LIT>''' <EOL> try : <EOL> ctx . samdb = SamDB ( url = ctx . url , <EOL> session_info = system_session ( ) , <EOL> credentials = ctx . creds , lp = ctx . lp ) <EOL> except Exception , e : <EOL> raise CommandError ( "<STR_LIT>" % ctx . url , e ) <EOL> def attr_default ( msg , attrname , default ) : <EOL> '''<STR_LIT>''' <EOL> if attrname in msg : <EOL> return msg [ attrname ] [ <NUM_LIT:0> ] <EOL> return default <EOL> def gpo_flags_string ( value ) : <EOL> '''<STR_LIT>''' <EOL> flags = policy . get_gpo_flags ( value ) <EOL> if not flags : <EOL> ret = '<STR_LIT>' <EOL> else : <EOL> ret = '<STR_LIT:U+0020>' . join ( flags ) <EOL> return ret <EOL> def gplink_options_string ( value ) : <EOL> '''<STR_LIT>''' <EOL> options = policy . get_gplink_options ( value ) <EOL> if not options : <EOL> ret = '<STR_LIT>' <EOL> else : <EOL> ret = '<STR_LIT:U+0020>' . join ( options ) <EOL> return ret <EOL> def parse_gplink ( gplink ) : <EOL> '''<STR_LIT>''' <EOL> ret = [ ] <EOL> a = gplink . split ( '<STR_LIT:]>' ) <EOL> for g in a : <EOL> if not g : <EOL> continue <EOL> d = g . split ( '<STR_LIT:;>' ) <EOL> if len ( d ) != <NUM_LIT:2> or not d [ <NUM_LIT:0> ] . startswith ( "<STR_LIT>" ) : <EOL> raise RuntimeError ( "<STR_LIT>" % g ) <EOL> ret . append ( { '<STR_LIT>' : d [ <NUM_LIT:0> ] [ <NUM_LIT:8> : ] , '<STR_LIT>' : int ( d [ <NUM_LIT:1> ] ) } ) <EOL> return ret <EOL> def encode_gplink ( gplist ) : <EOL> '''<STR_LIT>''' <EOL> ret = '<STR_LIT>' <EOL> for g in gplist : <EOL> ret += "<STR_LIT>" % ( g [ '<STR_LIT>' ] , g [ '<STR_LIT>' ] ) <EOL> return ret <EOL> def dc_url ( lp , creds , url = None , dc = None ) : <EOL> '''<STR_LIT>''' <EOL> if url is None : <EOL> if dc is None : <EOL> try : <EOL> dc = netcmd_finddc ( lp , creds ) <EOL> except Exception , e : <EOL> raise RuntimeError ( "<STR_LIT>" , e ) <EOL> url = '<STR_LIT>' + dc <EOL> return url <EOL> def get_gpo_dn ( samdb , gpo ) : <EOL> '''<STR_LIT>''' <EOL> dn = samdb . get_default_basedn ( ) <EOL> dn . add_child ( ldb . Dn ( samdb , "<STR_LIT>" ) ) <EOL> dn . add_child ( ldb . Dn ( samdb , "<STR_LIT>" % gpo ) ) <EOL> return dn <EOL> def get_gpo_info ( samdb , gpo = None , displayname = None , dn = None , <EOL> sd_flags = security . SECINFO_OWNER | security . SECINFO_GROUP | security . SECINFO_DACL | security . SECINFO_SACL ) : <EOL> '''<STR_LIT>''' <EOL> policies_dn = samdb . get_default_basedn ( ) <EOL> policies_dn . add_child ( ldb . Dn ( samdb , "<STR_LIT>" ) ) <EOL> base_dn = policies_dn <EOL> search_expr = "<STR_LIT>" <EOL> search_scope = ldb . SCOPE_ONELEVEL <EOL> if gpo is not None : <EOL> search_expr = "<STR_LIT>" % ldb . binary_encode ( gpo ) <EOL> if displayname is not None : <EOL> search_expr = "<STR_LIT>" % ldb . binary_encode ( displayname ) <EOL> if dn is not None : <EOL> base_dn = dn <EOL> search_scope = ldb . SCOPE_BASE <EOL> try : <EOL> msg = samdb . search ( base = base_dn , scope = search_scope , <EOL> expression = search_expr , <EOL> attrs = [ '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:name>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ] , <EOL> controls = [ '<STR_LIT>' % sd_flags ] ) <EOL> except Exception , e : <EOL> if gpo is not None : <EOL> mesg = "<STR_LIT>" % gpo <EOL> else : <EOL> mesg = "<STR_LIT>" <EOL> raise CommandError ( mesg , e ) <EOL> return msg <EOL> def get_gpo_containers ( samdb , gpo ) : <EOL> '''<STR_LIT>''' <EOL> search_expr = "<STR_LIT>" % gpo <EOL> try : <EOL> msg = samdb . search ( expression = search_expr , attrs = [ '<STR_LIT>' ] ) <EOL> except Exception , e : <EOL> raise CommandError ( "<STR_LIT>" % gpo , e ) <EOL> return msg <EOL> def del_gpo_link ( samdb , container_dn , gpo ) : <EOL> '''<STR_LIT>''' <EOL> try : <EOL> msg = samdb . search ( base = container_dn , scope = ldb . SCOPE_BASE , <EOL> expression = "<STR_LIT>" , <EOL> attrs = [ '<STR_LIT>' ] ) [ <NUM_LIT:0> ] <EOL> except Exception , e : <EOL> raise CommandError ( "<STR_LIT>" % container_dn , e ) <EOL> found = False <EOL> gpo_dn = str ( get_gpo_dn ( samdb , gpo ) ) <EOL> if '<STR_LIT>' in msg : <EOL> gplist = parse_gplink ( msg [ '<STR_LIT>' ] [ <NUM_LIT:0> ] ) <EOL> for g in gplist : <EOL> if g [ '<STR_LIT>' ] . lower ( ) == gpo_dn . lower ( ) : <EOL> gplist . remove ( g ) <EOL> found = True <EOL> break <EOL> else : <EOL> raise CommandError ( "<STR_LIT>" ) <EOL> if not found : <EOL> raise CommandError ( "<STR_LIT>" % gpo ) <EOL> m = ldb . Message ( ) <EOL> m . dn = container_dn <EOL> if gplist : <EOL> gplink_str = encode_gplink ( gplist ) <EOL> m [ '<STR_LIT>' ] = ldb . MessageElement ( gplink_str , ldb . FLAG_MOD_REPLACE , '<STR_LIT>' ) <EOL> else : <EOL> m [ '<STR_LIT>' ] = ldb . MessageElement ( msg [ '<STR_LIT>' ] [ <NUM_LIT:0> ] , ldb . FLAG_MOD_DELETE , '<STR_LIT>' ) <EOL> try : <EOL> samdb . modify ( m ) <EOL> except Exception , e : <EOL> raise CommandError ( "<STR_LIT>" , e ) <EOL> def parse_unc ( unc ) : <EOL> '''<STR_LIT>''' <EOL> if unc . startswith ( '<STR_LIT>' ) and unc . startswith ( '<STR_LIT>' ) : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> tmp = unc [ <NUM_LIT:2> : ] . split ( '<STR_LIT:/>' , <NUM_LIT:2> ) <EOL> if len ( tmp ) == <NUM_LIT:3> : <EOL> return tmp <EOL> tmp = unc [ <NUM_LIT:2> : ] . split ( '<STR_LIT:\\>' , <NUM_LIT:2> ) <EOL> if len ( tmp ) == <NUM_LIT:3> : <EOL> return tmp <EOL> raise ValueError ( "<STR_LIT>" % unc ) <EOL> def copy_directory_remote_to_local ( conn , remotedir , localdir ) : <EOL> if not os . path . isdir ( localdir ) : <EOL> os . mkdir ( localdir ) <EOL> r_dirs = [ remotedir ] <EOL> l_dirs = [ localdir ] <EOL> while r_dirs : <EOL> r_dir = r_dirs . pop ( ) <EOL> l_dir = l_dirs . pop ( ) <EOL> dirlist = conn . list ( r_dir ) <EOL> for e in dirlist : <EOL> r_name = r_dir + '<STR_LIT:\\>' + e [ '<STR_LIT:name>' ] <EOL> l_name = os . path . join ( l_dir , e [ '<STR_LIT:name>' ] ) <EOL> if e [ '<STR_LIT>' ] & smb . FILE_ATTRIBUTE_DIRECTORY : <EOL> r_dirs . append ( r_name ) <EOL> l_dirs . append ( l_name ) <EOL> os . mkdir ( l_name ) <EOL> else : <EOL> data = conn . loadfile ( r_name ) <EOL> file ( l_name , '<STR_LIT:w>' ) . write ( data ) <EOL> def copy_directory_local_to_remote ( conn , localdir , remotedir ) : <EOL> if not conn . chkpath ( remotedir ) : <EOL> conn . mkdir ( remotedir ) <EOL> l_dirs = [ localdir ] <EOL> r_dirs = [ remotedir ] <EOL> while l_dirs : <EOL> l_dir = l_dirs . pop ( ) <EOL> r_dir = r_dirs . pop ( ) <EOL> dirlist = os . listdir ( l_dir ) <EOL> for e in dirlist : <EOL> l_name = os . path . join ( l_dir , e ) <EOL> r_name = r_dir + '<STR_LIT:\\>' + e <EOL> if os . path . isdir ( l_name ) : <EOL> l_dirs . append ( l_name ) <EOL> r_dirs . append ( r_name ) <EOL> conn . mkdir ( r_name ) <EOL> else : <EOL> data = file ( l_name , '<STR_LIT:r>' ) . read ( ) <EOL> conn . savefile ( r_name , data ) <EOL> def create_directory_hier ( conn , remotedir ) : <EOL> elems = remotedir . replace ( '<STR_LIT:/>' , '<STR_LIT:\\>' ) . split ( '<STR_LIT:\\>' ) <EOL> path = "<STR_LIT>" <EOL> for e in elems : <EOL> path = path + '<STR_LIT:\\>' + e <EOL> if not conn . chkpath ( path ) : <EOL> conn . mkdir ( path ) <EOL> class cmd_listall ( Command ) : <EOL> """<STR_LIT>""" <EOL> synopsis = "<STR_LIT>" <EOL> takes_optiongroups = { <EOL> "<STR_LIT>" : options . SambaOptions , <EOL> "<STR_LIT>" : options . VersionOptions , <EOL> "<STR_LIT>" : options . CredentialsOptions , <EOL> } <EOL> takes_options = [ <EOL> Option ( "<STR_LIT>" , "<STR_LIT>" , help = "<STR_LIT>" , type = str , <EOL> metavar = "<STR_LIT>" , dest = "<STR_LIT:H>" ) <EOL> ] <EOL> def run ( self , H = None , sambaopts = None , credopts = None , versionopts = None ) : <EOL> self . lp = sambaopts . get_loadparm ( ) <EOL> self . creds = credopts . get_credentials ( self . lp , fallback_machine = True ) <EOL> self . url = dc_url ( self . lp , self . creds , H ) <EOL> samdb_connect ( self ) <EOL> msg = get_gpo_info ( self . samdb , None ) <EOL> for m in msg : <EOL> self . outf . write ( "<STR_LIT>" % m [ '<STR_LIT:name>' ] [ <NUM_LIT:0> ] ) <EOL> self . outf . write ( "<STR_LIT>" % m [ '<STR_LIT>' ] [ <NUM_LIT:0> ] ) <EOL> self . outf . write ( "<STR_LIT>" % m [ '<STR_LIT>' ] [ <NUM_LIT:0> ] ) <EOL> self . outf . write ( "<STR_LIT>" % m . dn ) <EOL> self . outf . write ( "<STR_LIT>" % attr_default ( m , '<STR_LIT>' , '<STR_LIT:0>' ) ) <EOL> self . outf . write ( "<STR_LIT>" % gpo_flags_string ( int ( attr_default ( m , '<STR_LIT>' , <NUM_LIT:0> ) ) ) ) <EOL> self . outf . write ( "<STR_LIT:\n>" ) <EOL> class cmd_list ( Command ) : <EOL> """<STR_LIT>""" <EOL> synopsis = "<STR_LIT>" <EOL> takes_args = [ '<STR_LIT:username>' ] <EOL> takes_optiongroups = { <EOL> "<STR_LIT>" : options . SambaOptions , <EOL> "<STR_LIT>" : options . VersionOptions , <EOL> "<STR_LIT>" : options . CredentialsOptions , <EOL> } <EOL> takes_options = [ <EOL> Option ( "<STR_LIT>" , "<STR_LIT>" , help = "<STR_LIT>" , <EOL> type = str , metavar = "<STR_LIT>" , dest = "<STR_LIT:H>" ) <EOL> ] <EOL> def run ( self , username , H = None , sambaopts = None , credopts = None , versionopts = None ) : <EOL> self . lp = sambaopts . get_loadparm ( ) <EOL> self . creds = credopts . get_credentials ( self . lp , fallback_machine = True ) <EOL> self . url = dc_url ( self . lp , self . creds , H ) <EOL> samdb_connect ( self ) <EOL> try : <EOL> msg = self . samdb . search ( expression = '<STR_LIT>' % <EOL> ( ldb . binary_encode ( username ) , ldb . binary_encode ( username ) ) ) <EOL> user_dn = msg [ <NUM_LIT:0> ] . dn <EOL> except Exception : <EOL> raise CommandError ( "<STR_LIT>" % username ) <EOL> try : <EOL> msg = self . samdb . search ( base = user_dn , scope = ldb . SCOPE_BASE , attrs = [ '<STR_LIT>' ] ) [ <NUM_LIT:0> ] <EOL> is_computer = '<STR_LIT>' in msg [ '<STR_LIT>' ] <EOL> except Exception : <EOL> raise CommandError ( "<STR_LIT>" % username ) <EOL> session_info_flags = ( AUTH_SESSION_INFO_DEFAULT_GROUPS | <EOL> AUTH_SESSION_INFO_AUTHENTICATED ) <EOL> if self . url is not None and self . url . startswith ( '<STR_LIT>' ) : <EOL> session_info_flags |= AUTH_SESSION_INFO_SIMPLE_PRIVILEGES <EOL> session = samba . auth . user_session ( self . samdb , lp_ctx = self . lp , dn = user_dn , <EOL> session_info_flags = session_info_flags ) <EOL> token = session . security_token <EOL> gpos = [ ] <EOL> inherit = True <EOL> dn = ldb . Dn ( self . samdb , str ( user_dn ) ) . parent ( ) <EOL> while True : <EOL> msg = self . samdb . search ( base = dn , scope = ldb . SCOPE_BASE , attrs = [ '<STR_LIT>' , '<STR_LIT>' ] ) [ <NUM_LIT:0> ] <EOL> if '<STR_LIT>' in msg : <EOL> glist = parse_gplink ( msg [ '<STR_LIT>' ] [ <NUM_LIT:0> ] ) <EOL> for g in glist : <EOL> if not inherit and not ( g [ '<STR_LIT>' ] & dsdb . GPLINK_OPT_ENFORCE ) : <EOL> continue <EOL> if g [ '<STR_LIT>' ] & dsdb . GPLINK_OPT_DISABLE : <EOL> continue <EOL> try : <EOL> sd_flags = security . SECINFO_OWNER | security . SECINFO_GROUP | security . SECINFO_DACL <EOL> gmsg = self . samdb . search ( base = g [ '<STR_LIT>' ] , scope = ldb . SCOPE_BASE , <EOL> attrs = [ '<STR_LIT:name>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ] , <EOL> controls = [ '<STR_LIT>' % sd_flags ] ) <EOL> secdesc_ndr = gmsg [ <NUM_LIT:0> ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] <EOL> secdesc = ndr_unpack ( security . descriptor , secdesc_ndr ) <EOL> except Exception : <EOL> self . outf . write ( "<STR_LIT>" % <EOL> g [ '<STR_LIT>' ] ) <EOL> continue <EOL> try : <EOL> samba . security . access_check ( secdesc , token , <EOL> security . SEC_STD_READ_CONTROL | <EOL> security . SEC_ADS_LIST | <EOL> security . SEC_ADS_READ_PROP ) <EOL> except RuntimeError : <EOL> self . outf . write ( "<STR_LIT>" % msg . dn ) <EOL> continue <EOL> flags = int ( attr_default ( gmsg [ <NUM_LIT:0> ] , '<STR_LIT>' , <NUM_LIT:0> ) ) <EOL> if is_computer and ( flags & dsdb . GPO_FLAG_MACHINE_DISABLE ) : <EOL> continue <EOL> if not is_computer and ( flags & dsdb . GPO_FLAG_USER_DISABLE ) : <EOL> continue <EOL> gpos . append ( ( gmsg [ <NUM_LIT:0> ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] , gmsg [ <NUM_LIT:0> ] [ '<STR_LIT:name>' ] [ <NUM_LIT:0> ] ) ) <EOL> gpoptions = int ( attr_default ( msg , '<STR_LIT>' , <NUM_LIT:0> ) ) <EOL> if gpoptions & dsdb . GPO_BLOCK_INHERITANCE : <EOL> inherit = False <EOL> if dn == self . samdb . get_default_basedn ( ) : <EOL> break <EOL> dn = dn . parent ( ) <EOL> if is_computer : <EOL> msg_str = '<STR_LIT>' <EOL> else : <EOL> msg_str = '<STR_LIT:user>' <EOL> self . outf . write ( "<STR_LIT>" % ( msg_str , username ) ) <EOL> for g in gpos : <EOL> self . outf . write ( "<STR_LIT>" % ( g [ <NUM_LIT:0> ] , g [ <NUM_LIT:1> ] ) ) <EOL> class cmd_show ( Command ) : <EOL> """<STR_LIT>""" <EOL> synopsis = "<STR_LIT>" <EOL> takes_optiongroups = { <EOL> "<STR_LIT>" : options . SambaOptions , <EOL> "<STR_LIT>" : options . VersionOptions , <EOL> "<STR_LIT>" : options . CredentialsOptions , <EOL> } <EOL> takes_args = [ '<STR_LIT>' ] <EOL> takes_options = [ <EOL> Option ( "<STR_LIT>" , help = "<STR_LIT>" , type = str ) <EOL> ] <EOL> def run ( self , gpo , H = None , sambaopts = None , credopts = None , versionopts = None ) : <EOL> self . lp = sambaopts . get_loadparm ( ) <EOL> self . creds = credopts . get_credentials ( self . lp , fallback_machine = True ) <EOL> self . url = dc_url ( self . lp , self . creds , H ) <EOL> samdb_connect ( self ) <EOL> try : <EOL> msg = get_gpo_info ( self . samdb , gpo ) [ <NUM_LIT:0> ] <EOL> except Exception : <EOL> raise CommandError ( "<STR_LIT>" % gpo ) <EOL> try : <EOL> secdesc_ndr = msg [ '<STR_LIT>' ] [ <NUM_LIT:0> ] <EOL> secdesc = ndr_unpack ( security . descriptor , secdesc_ndr ) <EOL> secdesc_sddl = secdesc . as_sddl ( ) <EOL> except Exception : <EOL> secdesc_sddl = "<STR_LIT>" <EOL> self . outf . write ( "<STR_LIT>" % msg [ '<STR_LIT:name>' ] [ <NUM_LIT:0> ] ) <EOL> self . outf . write ( "<STR_LIT>" % msg [ '<STR_LIT>' ] [ <NUM_LIT:0> ] ) <EOL> self . outf . write ( "<STR_LIT>" % msg [ '<STR_LIT>' ] [ <NUM_LIT:0> ] ) <EOL> self . outf . write ( "<STR_LIT>" % msg . dn ) <EOL> self . outf . write ( "<STR_LIT>" % attr_default ( msg , '<STR_LIT>' , '<STR_LIT:0>' ) ) <EOL> self . outf . write ( "<STR_LIT>" % gpo_flags_string ( int ( attr_default ( msg , '<STR_LIT>' , <NUM_LIT:0> ) ) ) ) <EOL> self . outf . write ( "<STR_LIT>" % secdesc_sddl ) <EOL> self . outf . write ( "<STR_LIT:\n>" ) <EOL> class cmd_getlink ( Command ) : <EOL> """<STR_LIT>""" <EOL> synopsis = "<STR_LIT>" <EOL> takes_optiongroups = { <EOL> "<STR_LIT>" : options . SambaOptions , <EOL> "<STR_LIT>" : options . VersionOptions , <EOL> "<STR_LIT>" : options . CredentialsOptions , <EOL> } <EOL> takes_args = [ '<STR_LIT>' ] <EOL> takes_options = [ <EOL> Option ( "<STR_LIT>" , help = "<STR_LIT>" , type = str ) <EOL> ] <EOL> def run ( self , container_dn , H = None , sambaopts = None , credopts = None , <EOL> versionopts = None ) : <EOL> self . lp = sambaopts . get_loadparm ( ) <EOL> self . creds = credopts . get_credentials ( self . lp , fallback_machine = True ) <EOL> self . url = dc_url ( self . lp , self . creds , H ) <EOL> samdb_connect ( self ) <EOL> try : <EOL> msg = self . samdb . search ( base = container_dn , scope = ldb . SCOPE_BASE , <EOL> expression = "<STR_LIT>" , <EOL> attrs = [ '<STR_LIT>' ] ) [ <NUM_LIT:0> ] <EOL> except Exception : <EOL> raise CommandError ( "<STR_LIT>" % container_dn ) <EOL> if msg [ '<STR_LIT>' ] : <EOL> self . outf . write ( "<STR_LIT>" % container_dn ) <EOL> gplist = parse_gplink ( msg [ '<STR_LIT>' ] [ <NUM_LIT:0> ] ) <EOL> for g in gplist : <EOL> msg = get_gpo_info ( self . samdb , dn = g [ '<STR_LIT>' ] ) <EOL> self . outf . write ( "<STR_LIT>" % msg [ <NUM_LIT:0> ] [ '<STR_LIT:name>' ] [ <NUM_LIT:0> ] ) <EOL> self . outf . write ( "<STR_LIT>" % msg [ <NUM_LIT:0> ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] ) <EOL> self . outf . write ( "<STR_LIT>" % gplink_options_string ( g [ '<STR_LIT>' ] ) ) <EOL> self . outf . write ( "<STR_LIT:\n>" ) <EOL> else : <EOL> self . outf . write ( "<STR_LIT>" % container_dn ) <EOL> class cmd_setlink ( Command ) : <EOL> """<STR_LIT>""" <EOL> synopsis = "<STR_LIT>" <EOL> takes_optiongroups = { <EOL> "<STR_LIT>" : options . SambaOptions , <EOL> "<STR_LIT>" : options . VersionOptions , <EOL> "<STR_LIT>" : options . CredentialsOptions , <EOL> } <EOL> takes_args = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> takes_options = [ <EOL> Option ( "<STR_LIT>" , help = "<STR_LIT>" , type = str ) , <EOL> Option ( "<STR_LIT>" , dest = "<STR_LIT>" , default = False , action = '<STR_LIT:store_true>' , <EOL> help = "<STR_LIT>" ) , <EOL> Option ( "<STR_LIT>" , dest = "<STR_LIT>" , default = False , action = '<STR_LIT:store_true>' , <EOL> help = "<STR_LIT>" ) <EOL> ] <EOL> def run ( self , container_dn , gpo , H = None , disabled = False , enforced = False , <EOL> sambaopts = None , credopts = None , versionopts = None ) : <EOL> self . lp = sambaopts . get_loadparm ( ) <EOL> self . creds = credopts . get_credentials ( self . lp , fallback_machine = True ) <EOL> self . url = dc_url ( self . lp , self . creds , H ) <EOL> samdb_connect ( self ) <EOL> gplink_options = <NUM_LIT:0> <EOL> if disabled : <EOL> gplink_options |= dsdb . GPLINK_OPT_DISABLE <EOL> if enforced : <EOL> gplink_options |= dsdb . GPLINK_OPT_ENFORCE <EOL> try : <EOL> msg = get_gpo_info ( self . samdb , gpo = gpo ) [ <NUM_LIT:0> ] <EOL> except Exception : <EOL> raise CommandError ( "<STR_LIT>" % gpo ) <EOL> gpo_dn = str ( get_gpo_dn ( self . samdb , gpo ) ) <EOL> try : <EOL> msg = self . samdb . search ( base = container_dn , scope = ldb . SCOPE_BASE , <EOL> expression = "<STR_LIT>" , <EOL> attrs = [ '<STR_LIT>' ] ) [ <NUM_LIT:0> ] <EOL> except Exception : <EOL> raise CommandError ( "<STR_LIT>" % container_dn ) <EOL> existing_gplink = False <EOL> if '<STR_LIT>' in msg : <EOL> gplist = parse_gplink ( msg [ '<STR_LIT>' ] [ <NUM_LIT:0> ] ) <EOL> existing_gplink = True <EOL> found = False <EOL> for g in gplist : <EOL> if g [ '<STR_LIT>' ] . lower ( ) == gpo_dn . lower ( ) : <EOL> g [ '<STR_LIT>' ] = gplink_options <EOL> found = True <EOL> break <EOL> if found : <EOL> raise CommandError ( "<STR_LIT>" % gpo ) <EOL> else : <EOL> gplist . insert ( <NUM_LIT:0> , { '<STR_LIT>' : gpo_dn , '<STR_LIT>' : gplink_options } ) <EOL> else : <EOL> gplist = [ ] <EOL> gplist . append ( { '<STR_LIT>' : gpo_dn , '<STR_LIT>' : gplink_options } ) <EOL> gplink_str = encode_gplink ( gplist ) <EOL> m = ldb . Message ( ) <EOL> m . dn = ldb . Dn ( self . samdb , container_dn ) <EOL> if existing_gplink : <EOL> m [ '<STR_LIT>' ] = ldb . MessageElement ( gplink_str , ldb . FLAG_MOD_REPLACE , '<STR_LIT>' ) <EOL> else : <EOL> m [ '<STR_LIT>' ] = ldb . MessageElement ( gplink_str , ldb . FLAG_MOD_ADD , '<STR_LIT>' ) <EOL> try : <EOL> self . samdb . modify ( m ) <EOL> except Exception , e : <EOL> raise CommandError ( "<STR_LIT>" , e ) <EOL> self . outf . write ( "<STR_LIT>" ) <EOL> cmd_getlink ( ) . run ( container_dn , H , sambaopts , credopts , versionopts ) <EOL> class cmd_dellink ( Command ) : <EOL> """<STR_LIT>""" <EOL> synopsis = "<STR_LIT>" <EOL> takes_optiongroups = { <EOL> "<STR_LIT>" : options . SambaOptions , <EOL> "<STR_LIT>" : options . VersionOptions , <EOL> "<STR_LIT>" : options . CredentialsOptions , <EOL> } <EOL> takes_args = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> takes_options = [ <EOL> Option ( "<STR_LIT>" , help = "<STR_LIT>" , type = str ) , <EOL> ] <EOL> def run ( self , container , gpo , H = None , sambaopts = None , credopts = None , <EOL> versionopts = None ) : <EOL> self . lp = sambaopts . get_loadparm ( ) <EOL> self . creds = credopts . get_credentials ( self . lp , fallback_machine = True ) <EOL> self . url = dc_url ( self . lp , self . creds , H ) <EOL> samdb_connect ( self ) <EOL> try : <EOL> get_gpo_info ( self . samdb , gpo = gpo ) [ <NUM_LIT:0> ] <EOL> except Exception : <EOL> raise CommandError ( "<STR_LIT>" % gpo ) <EOL> container_dn = ldb . Dn ( self . samdb , container ) <EOL> del_gpo_link ( self . samdb , container_dn , gpo ) <EOL> self . outf . write ( "<STR_LIT>" ) <EOL> cmd_getlink ( ) . run ( container_dn , H , sambaopts , credopts , versionopts ) <EOL> class cmd_listcontainers ( Command ) : <EOL> """<STR_LIT>""" <EOL> synopsis = "<STR_LIT>" <EOL> takes_optiongroups = { <EOL> "<STR_LIT>" : options . SambaOptions , <EOL> "<STR_LIT>" : options . VersionOptions , <EOL> "<STR_LIT>" : options . CredentialsOptions , <EOL> } <EOL> takes_args = [ '<STR_LIT>' ] <EOL> takes_options = [ <EOL> Option ( "<STR_LIT>" , help = "<STR_LIT>" , type = str ) <EOL> ] <EOL> def run ( self , gpo , H = None , sambaopts = None , credopts = None , <EOL> versionopts = None ) : <EOL> self . lp = sambaopts . get_loadparm ( ) <EOL> self . creds = credopts . get_credentials ( self . lp , fallback_machine = True ) <EOL> self . url = dc_url ( self . lp , self . creds , H ) <EOL> samdb_connect ( self ) <EOL> msg = get_gpo_containers ( self . samdb , gpo ) <EOL> if len ( msg ) : <EOL> self . outf . write ( "<STR_LIT>" % gpo ) <EOL> for m in msg : <EOL> self . outf . write ( "<STR_LIT>" % m [ '<STR_LIT>' ] ) <EOL> else : <EOL> self . outf . write ( "<STR_LIT>" % gpo ) <EOL> class cmd_getinheritance ( Command ) : <EOL> """<STR_LIT>""" <EOL> synopsis = "<STR_LIT>" <EOL> takes_optiongroups = { <EOL> "<STR_LIT>" : options . SambaOptions , <EOL> "<STR_LIT>" : options . VersionOptions , <EOL> "<STR_LIT>" : options . CredentialsOptions , <EOL> } <EOL> takes_args = [ '<STR_LIT>' ] <EOL> takes_options = [ <EOL> Option ( "<STR_LIT>" , help = "<STR_LIT>" , type = str ) <EOL> ] <EOL> def run ( self , container_dn , H = None , sambaopts = None , credopts = None , <EOL> versionopts = None ) : <EOL> self . lp = sambaopts . get_loadparm ( ) <EOL> self . creds = credopts . get_credentials ( self . lp , fallback_machine = True ) <EOL> self . url = dc_url ( self . lp , self . creds , H ) <EOL> samdb_connect ( self ) <EOL> try : <EOL> msg = self . samdb . search ( base = container_dn , scope = ldb . SCOPE_BASE , <EOL> expression = "<STR_LIT>" , <EOL> attrs = [ '<STR_LIT>' ] ) [ <NUM_LIT:0> ] <EOL> except Exception : <EOL> raise CommandError ( "<STR_LIT>" % container_dn ) <EOL> inheritance = <NUM_LIT:0> <EOL> if '<STR_LIT>' in msg : <EOL> inheritance = int ( msg [ '<STR_LIT>' ] [ <NUM_LIT:0> ] ) <EOL> if inheritance == dsdb . GPO_BLOCK_INHERITANCE : <EOL> self . outf . write ( "<STR_LIT>" ) <EOL> else : <EOL> self . outf . write ( "<STR_LIT>" ) <EOL> class cmd_setinheritance ( Command ) : <EOL> """<STR_LIT>""" <EOL> synopsis = "<STR_LIT>" <EOL> takes_optiongroups = { <EOL> "<STR_LIT>" : options . SambaOptions , <EOL> "<STR_LIT>" : options . VersionOptions , <EOL> "<STR_LIT>" : options . CredentialsOptions , <EOL> } <EOL> takes_args = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> takes_options = [ <EOL> Option ( "<STR_LIT>" , help = "<STR_LIT>" , type = str ) <EOL> ] <EOL> def run ( self , container_dn , inherit_state , H = None , sambaopts = None , credopts = None , <EOL> versionopts = None ) : <EOL> if inherit_state . lower ( ) == '<STR_LIT>' : <EOL> inheritance = dsdb . GPO_BLOCK_INHERITANCE <EOL> elif inherit_state . lower ( ) == '<STR_LIT>' : <EOL> inheritance = dsdb . GPO_INHERIT <EOL> else : <EOL> raise CommandError ( "<STR_LIT>" % inherit_state ) <EOL> self . lp = sambaopts . get_loadparm ( ) <EOL> self . creds = credopts . get_credentials ( self . lp , fallback_machine = True ) <EOL> self . url = dc_url ( self . lp , self . creds , H ) <EOL> samdb_connect ( self ) <EOL> try : <EOL> msg = self . samdb . search ( base = container_dn , scope = ldb . SCOPE_BASE , <EOL> expression = "<STR_LIT>" , <EOL> attrs = [ '<STR_LIT>' ] ) [ <NUM_LIT:0> ] <EOL> except Exception : <EOL> raise CommandError ( "<STR_LIT>" % container_dn ) <EOL> m = ldb . Message ( ) <EOL> m . dn = ldb . Dn ( self . samdb , container_dn ) <EOL> if '<STR_LIT>' in msg : <EOL> m [ '<STR_LIT>' ] = ldb . MessageElement ( str ( inheritance ) , ldb . FLAG_MOD_REPLACE , '<STR_LIT>' ) <EOL> else : <EOL> m [ '<STR_LIT>' ] = ldb . MessageElement ( str ( inheritance ) , ldb . FLAG_MOD_ADD , '<STR_LIT>' ) <EOL> try : <EOL> self . samdb . modify ( m ) <EOL> except Exception , e : <EOL> raise CommandError ( "<STR_LIT>" % inherit_state , e ) <EOL> class cmd_fetch ( Command ) : <EOL> """<STR_LIT>""" <EOL> synopsis = "<STR_LIT>" <EOL> takes_optiongroups = { <EOL> "<STR_LIT>" : options . SambaOptions , <EOL> "<STR_LIT>" : options . VersionOptions , <EOL> "<STR_LIT>" : options . CredentialsOptions , <EOL> } <EOL> takes_args = [ '<STR_LIT>' ] <EOL> takes_options = [ <EOL> Option ( "<STR_LIT>" , help = "<STR_LIT>" , type = str ) , <EOL> Option ( "<STR_LIT>" , help = "<STR_LIT>" , type = str ) <EOL> ] <EOL> def run ( self , gpo , H = None , tmpdir = None , sambaopts = None , credopts = None , versionopts = None ) : <EOL> self . lp = sambaopts . get_loadparm ( ) <EOL> self . creds = credopts . get_credentials ( self . lp , fallback_machine = True ) <EOL> if H and H . startswith ( '<STR_LIT>' ) : <EOL> dc_hostname = H [ <NUM_LIT:7> : ] <EOL> self . url = H <EOL> else : <EOL> dc_hostname = netcmd_finddc ( self . lp , self . creds ) <EOL> self . url = dc_url ( self . lp , self . creds , dc = dc_hostname ) <EOL> samdb_connect ( self ) <EOL> try : <EOL> msg = get_gpo_info ( self . samdb , gpo ) [ <NUM_LIT:0> ] <EOL> except Exception : <EOL> raise CommandError ( "<STR_LIT>" % gpo ) <EOL> unc = msg [ '<STR_LIT>' ] [ <NUM_LIT:0> ] <EOL> try : <EOL> [ dom_name , service , sharepath ] = parse_unc ( unc ) <EOL> except ValueError : <EOL> raise CommandError ( "<STR_LIT>" % unc ) <EOL> try : <EOL> conn = smb . SMB ( dc_hostname , service , lp = self . lp , creds = self . creds ) <EOL> except Exception : <EOL> raise CommandError ( "<STR_LIT>" % dc_hostname ) <EOL> if tmpdir is None : <EOL> tmpdir = "<STR_LIT>" <EOL> if not os . path . isdir ( tmpdir ) : <EOL> raise CommandError ( "<STR_LIT>" % tmpdir ) <EOL> localdir = os . path . join ( tmpdir , "<STR_LIT>" ) <EOL> if not os . path . isdir ( localdir ) : <EOL> os . mkdir ( localdir ) <EOL> gpodir = os . path . join ( localdir , gpo ) <EOL> if os . path . isdir ( gpodir ) : <EOL> raise CommandError ( "<STR_LIT>" % gpodir ) <EOL> try : <EOL> os . mkdir ( gpodir ) <EOL> copy_directory_remote_to_local ( conn , sharepath , gpodir ) <EOL> except Exception , e : <EOL> raise CommandError ( "<STR_LIT>" , e ) <EOL> self . outf . write ( '<STR_LIT>' % gpodir ) <EOL> class cmd_create ( Command ) : <EOL> """<STR_LIT>""" <EOL> synopsis = "<STR_LIT>" <EOL> takes_optiongroups = { <EOL> "<STR_LIT>" : options . SambaOptions , <EOL> "<STR_LIT>" : options . VersionOptions , <EOL> "<STR_LIT>" : options . CredentialsOptions , <EOL> } <EOL> takes_args = [ '<STR_LIT>' ] <EOL> takes_options = [ <EOL> Option ( "<STR_LIT>" , help = "<STR_LIT>" , type = str ) , <EOL> Option ( "<STR_LIT>" , help = "<STR_LIT>" , type = str ) <EOL> ] <EOL> def run ( self , displayname , H = None , tmpdir = None , sambaopts = None , credopts = None , <EOL> versionopts = None ) : <EOL> self . lp = sambaopts . get_loadparm ( ) <EOL> self . creds = credopts . get_credentials ( self . lp , fallback_machine = True ) <EOL> net = Net ( creds = self . creds , lp = self . lp ) <EOL> if H and H . startswith ( '<STR_LIT>' ) : <EOL> dc_hostname = H [ <NUM_LIT:7> : ] <EOL> self . url = H <EOL> flags = ( nbt . NBT_SERVER_LDAP | <EOL> nbt . NBT_SERVER_DS | <EOL> nbt . NBT_SERVER_WRITABLE ) <EOL> cldap_ret = net . finddc ( address = dc_hostname , flags = flags ) <EOL> else : <EOL> flags = ( nbt . NBT_SERVER_LDAP | <EOL> nbt . NBT_SERVER_DS | <EOL> nbt . NBT_SERVER_WRITABLE ) <EOL> cldap_ret = net . finddc ( domain = self . lp . get ( '<STR_LIT>' ) , flags = flags ) <EOL> dc_hostname = cldap_ret . pdc_dns_name <EOL> self . url = dc_url ( self . lp , self . creds , dc = dc_hostname ) <EOL> samdb_connect ( self ) <EOL> msg = get_gpo_info ( self . samdb , displayname = displayname ) <EOL> if msg . count > <NUM_LIT:0> : <EOL> raise CommandError ( "<STR_LIT>" % displayname ) <EOL> guid = str ( uuid . uuid4 ( ) ) <EOL> gpo = "<STR_LIT>" % guid . upper ( ) <EOL> realm = cldap_ret . dns_domain <EOL> unc_path = "<STR_LIT>" % ( realm , realm , gpo ) <EOL> if tmpdir is None : <EOL> tmpdir = "<STR_LIT>" <EOL> if not os . path . isdir ( tmpdir ) : <EOL> raise CommandError ( "<STR_LIT>" % tmpdir ) <EOL> localdir = os . path . join ( tmpdir , "<STR_LIT>" ) <EOL> if not os . path . isdir ( localdir ) : <EOL> os . mkdir ( localdir ) <EOL> gpodir = os . path . join ( localdir , gpo ) <EOL> if os . path . isdir ( gpodir ) : <EOL> raise CommandError ( "<STR_LIT>" % gpodir ) <EOL> try : <EOL> os . mkdir ( gpodir ) <EOL> os . mkdir ( os . path . join ( gpodir , "<STR_LIT>" ) ) <EOL> os . mkdir ( os . path . join ( gpodir , "<STR_LIT>" ) ) <EOL> gpt_contents = "<STR_LIT>" <EOL> file ( os . path . join ( gpodir , "<STR_LIT>" ) , "<STR_LIT:w>" ) . write ( gpt_contents ) <EOL> except Exception , e : <EOL> raise CommandError ( "<STR_LIT>" , e ) <EOL> [ dom_name , service , sharepath ] = parse_unc ( unc_path ) <EOL> try : <EOL> conn = smb . SMB ( dc_hostname , service , lp = self . lp , creds = self . creds ) <EOL> except Exception , e : <EOL> raise CommandError ( "<STR_LIT>" % dc_hostname , e ) <EOL> self . samdb . transaction_start ( ) <EOL> try : <EOL> gpo_dn = get_gpo_dn ( self . samdb , gpo ) <EOL> m = ldb . Message ( ) <EOL> m . dn = gpo_dn <EOL> m [ '<STR_LIT>' ] = ldb . MessageElement ( "<STR_LIT>" , ldb . FLAG_MOD_ADD , "<STR_LIT>" ) <EOL> self . samdb . add ( m ) <EOL> m = ldb . Message ( ) <EOL> m . dn = ldb . Dn ( self . samdb , "<STR_LIT>" % str ( gpo_dn ) ) <EOL> m [ '<STR_LIT>' ] = ldb . MessageElement ( "<STR_LIT>" , ldb . FLAG_MOD_ADD , "<STR_LIT>" ) <EOL> self . samdb . add ( m ) <EOL> m = ldb . Message ( ) <EOL> m . dn = ldb . Dn ( self . samdb , "<STR_LIT>" % str ( gpo_dn ) ) <EOL> m [ '<STR_LIT>' ] = ldb . MessageElement ( "<STR_LIT>" , ldb . FLAG_MOD_ADD , "<STR_LIT>" ) <EOL> self . samdb . add ( m ) <EOL> ds_sd_flags = ( security . SECINFO_OWNER | <EOL> security . SECINFO_GROUP | <EOL> security . SECINFO_DACL ) <EOL> msg = get_gpo_info ( self . samdb , gpo = gpo , sd_flags = ds_sd_flags ) [ <NUM_LIT:0> ] <EOL> ds_sd_ndr = msg [ '<STR_LIT>' ] [ <NUM_LIT:0> ] <EOL> ds_sd = ndr_unpack ( security . descriptor , ds_sd_ndr ) . as_sddl ( ) <EOL> domain_sid = security . dom_sid ( self . samdb . get_domain_sid ( ) ) <EOL> sddl = dsacl2fsacl ( ds_sd , domain_sid ) <EOL> fs_sd = security . descriptor . from_sddl ( sddl , domain_sid ) <EOL> create_directory_hier ( conn , sharepath ) <EOL> sio = ( security . SECINFO_OWNER | <EOL> security . SECINFO_GROUP | <EOL> security . SECINFO_DACL | <EOL> security . SECINFO_PROTECTED_DACL ) <EOL> conn . set_acl ( sharepath , fs_sd , sio ) <EOL> copy_directory_local_to_remote ( conn , gpodir , sharepath ) <EOL> m = ldb . Message ( ) <EOL> m . dn = gpo_dn <EOL> m [ '<STR_LIT>' ] = ldb . MessageElement ( displayname , ldb . FLAG_MOD_REPLACE , "<STR_LIT>" ) <EOL> m [ '<STR_LIT>' ] = ldb . MessageElement ( unc_path , ldb . FLAG_MOD_REPLACE , "<STR_LIT>" ) <EOL> m [ '<STR_LIT>' ] = ldb . MessageElement ( "<STR_LIT:0>" , ldb . FLAG_MOD_REPLACE , "<STR_LIT>" ) <EOL> m [ '<STR_LIT>' ] = ldb . MessageElement ( "<STR_LIT:2>" , ldb . FLAG_MOD_REPLACE , "<STR_LIT>" ) <EOL> m [ '<STR_LIT>' ] = ldb . MessageElement ( "<STR_LIT:0>" , ldb . FLAG_MOD_REPLACE , "<STR_LIT>" ) <EOL> controls = [ "<STR_LIT>" ] <EOL> self . samdb . modify ( m , controls = controls ) <EOL> except Exception : <EOL> self . samdb . transaction_cancel ( ) <EOL> raise <EOL> else : <EOL> self . samdb . transaction_commit ( ) <EOL> self . outf . write ( "<STR_LIT>" % ( displayname , gpo ) ) <EOL> class cmd_del ( Command ) : <EOL> """<STR_LIT>""" <EOL> synopsis = "<STR_LIT>" <EOL> takes_optiongroups = { <EOL> "<STR_LIT>" : options . SambaOptions , <EOL> "<STR_LIT>" : options . VersionOptions , <EOL> "<STR_LIT>" : options . CredentialsOptions , <EOL> } <EOL> takes_args = [ '<STR_LIT>' ] <EOL> takes_options = [ <EOL> Option ( "<STR_LIT>" , help = "<STR_LIT>" , type = str ) , <EOL> ] <EOL> def run ( self , gpo , H = None , sambaopts = None , credopts = None , <EOL> versionopts = None ) : <EOL> self . lp = sambaopts . get_loadparm ( ) <EOL> self . creds = credopts . get_credentials ( self . lp , fallback_machine = True ) <EOL> if H and H . startswith ( '<STR_LIT>' ) : <EOL> dc_hostname = H [ <NUM_LIT:7> : ] <EOL> self . url = H <EOL> else : <EOL> dc_hostname = netcmd_finddc ( self . lp , self . creds ) <EOL> self . url = dc_url ( self . lp , self . creds , dc = dc_hostname ) <EOL> samdb_connect ( self ) <EOL> try : <EOL> msg = get_gpo_info ( self . samdb , gpo = gpo ) [ <NUM_LIT:0> ] <EOL> unc_path = msg [ '<STR_LIT>' ] [ <NUM_LIT:0> ] <EOL> except Exception : <EOL> raise CommandError ( "<STR_LIT>" % gpo ) <EOL> [ dom_name , service , sharepath ] = parse_unc ( unc_path ) <EOL> try : <EOL> conn = smb . SMB ( dc_hostname , service , lp = self . lp , creds = self . creds ) <EOL> except Exception , e : <EOL> raise CommandError ( "<STR_LIT>" % dc_hostname , e ) <EOL> self . samdb . transaction_start ( ) <EOL> try : <EOL> msg = get_gpo_containers ( self . samdb , gpo ) <EOL> if len ( msg ) : <EOL> self . outf . write ( "<STR_LIT>" % gpo ) <EOL> for m in msg : <EOL> del_gpo_link ( self . samdb , m [ '<STR_LIT>' ] , gpo ) <EOL> self . outf . write ( "<STR_LIT>" % m [ '<STR_LIT>' ] ) <EOL> gpo_dn = get_gpo_dn ( self . samdb , gpo ) <EOL> self . samdb . delete ( ldb . Dn ( self . samdb , "<STR_LIT>" % str ( gpo_dn ) ) ) <EOL> self . samdb . delete ( ldb . Dn ( self . samdb , "<STR_LIT>" % str ( gpo_dn ) ) ) <EOL> self . samdb . delete ( gpo_dn ) <EOL> conn . deltree ( sharepath ) <EOL> except Exception : <EOL> self . samdb . transaction_cancel ( ) <EOL> raise <EOL> else : <EOL> self . samdb . transaction_commit ( ) <EOL> self . outf . write ( "<STR_LIT>" % gpo ) <EOL> class cmd_aclcheck ( Command ) : <EOL> """<STR_LIT>""" <EOL> synopsis = "<STR_LIT>" <EOL> takes_optiongroups = { <EOL> "<STR_LIT>" : options . SambaOptions , <EOL> "<STR_LIT>" : options . VersionOptions , <EOL> "<STR_LIT>" : options . CredentialsOptions , <EOL> } <EOL> takes_options = [ <EOL> Option ( "<STR_LIT>" , "<STR_LIT>" , help = "<STR_LIT>" , type = str , <EOL> metavar = "<STR_LIT>" , dest = "<STR_LIT:H>" ) <EOL> ] <EOL> def run ( self , H = None , sambaopts = None , credopts = None , versionopts = None ) : <EOL> self . lp = sambaopts . get_loadparm ( ) <EOL> self . creds = credopts . get_credentials ( self . lp , fallback_machine = True ) <EOL> self . url = dc_url ( self . lp , self . creds , H ) <EOL> if H and H . startswith ( '<STR_LIT>' ) : <EOL> dc_hostname = H [ <NUM_LIT:7> : ] <EOL> self . url = H <EOL> else : <EOL> dc_hostname = netcmd_finddc ( self . lp , self . creds ) <EOL> self . url = dc_url ( self . lp , self . creds , dc = dc_hostname ) <EOL> samdb_connect ( self ) <EOL> msg = get_gpo_info ( self . samdb , None ) <EOL> for m in msg : <EOL> unc = m [ '<STR_LIT>' ] [ <NUM_LIT:0> ] <EOL> try : <EOL> [ dom_name , service , sharepath ] = parse_unc ( unc ) <EOL> except ValueError : <EOL> raise CommandError ( "<STR_LIT>" % unc ) <EOL> try : <EOL> conn = smb . SMB ( dc_hostname , service , lp = self . lp , creds = self . creds ) <EOL> except Exception : <EOL> raise CommandError ( "<STR_LIT>" % dc_hostname ) <EOL> fs_sd = conn . get_acl ( sharepath , security . SECINFO_OWNER | security . SECINFO_GROUP | security . SECINFO_DACL , security . SEC_FLAG_MAXIMUM_ALLOWED ) <EOL> ds_sd_ndr = m [ '<STR_LIT>' ] [ <NUM_LIT:0> ] <EOL> ds_sd = ndr_unpack ( security . descriptor , ds_sd_ndr ) . as_sddl ( ) <EOL> domain_sid = security . dom_sid ( self . samdb . get_domain_sid ( ) ) <EOL> expected_fs_sddl = dsacl2fsacl ( ds_sd , domain_sid ) <EOL> if ( fs_sd . as_sddl ( domain_sid ) != expected_fs_sddl ) : <EOL> raise CommandError ( "<STR_LIT>" % ( fs_sd . as_sddl ( domain_sid ) , sharepath , expected_fs_sddl ) ) <EOL> class cmd_gpo ( SuperCommand ) : <EOL> """<STR_LIT>""" <EOL> subcommands = { } <EOL> subcommands [ "<STR_LIT>" ] = cmd_listall ( ) <EOL> subcommands [ "<STR_LIT:list>" ] = cmd_list ( ) <EOL> subcommands [ "<STR_LIT>" ] = cmd_show ( ) <EOL> subcommands [ "<STR_LIT>" ] = cmd_getlink ( ) <EOL> subcommands [ "<STR_LIT>" ] = cmd_setlink ( ) <EOL> subcommands [ "<STR_LIT>" ] = cmd_dellink ( ) <EOL> subcommands [ "<STR_LIT>" ] = cmd_listcontainers ( ) <EOL> subcommands [ "<STR_LIT>" ] = cmd_getinheritance ( ) <EOL> subcommands [ "<STR_LIT>" ] = cmd_setinheritance ( ) <EOL> subcommands [ "<STR_LIT>" ] = cmd_fetch ( ) <EOL> subcommands [ "<STR_LIT>" ] = cmd_create ( ) <EOL> subcommands [ "<STR_LIT>" ] = cmd_del ( ) <EOL> subcommands [ "<STR_LIT>" ] = cmd_aclcheck ( ) </s>
