2014-01-31 13:27:05 +13:00
# Reads important GPO parameters and updates Samba
# Copyright (C) Luke Morrison <luc785@.hotmail.com> 2013
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import sys
import os
2017-05-25 07:27:27 -06:00
import tdb
2014-01-31 13:27:05 +13:00
sys . path . insert ( 0 , " bin/python " )
from samba import NTSTATUSError
2017-02-11 07:53:07 -07:00
from ConfigParser import ConfigParser
from StringIO import StringIO
2017-02-24 14:19:48 -07:00
from abc import ABCMeta , abstractmethod
2017-06-08 11:47:57 -06:00
import xml . etree . ElementTree as etree
2017-11-21 03:44:12 -07:00
import re
2017-06-08 11:47:57 -06:00
2017-06-12 16:00:38 -06:00
try :
from enum import Enum
GPOSTATE = Enum ( ' GPOSTATE ' , ' APPLY ENFORCE UNAPPLY ' )
except ImportError :
class GPOSTATE :
APPLY = 1
ENFORCE = 2
UNAPPLY = 3
2017-06-08 11:47:57 -06:00
class gp_log :
''' Log settings overwritten by gpo apply
2017-11-20 10:28:33 +13:00
The gp_log is an xml file that stores a history of gpo changes ( and the
original setting value ) .
2017-06-08 11:47:57 -06:00
The log is organized like so :
< gp >
< user name = " KDC-1$ " >
< applylog >
< guid count = " 0 " value = " { 31B2F340-016D-11D2-945F-00C04FB984F9} " / >
< / applylog >
< guid value = " { 31B2F340-016D-11D2-945F-00C04FB984F9} " >
< gp_ext name = " System Access " >
< attribute name = " minPwdAge " > - 864000000000 < / attribute >
< attribute name = " maxPwdAge " > - 36288000000000 < / attribute >
< attribute name = " minPwdLength " > 7 < / attribute >
< attribute name = " pwdProperties " > 1 < / attribute >
< / gp_ext >
< gp_ext name = " Kerberos Policy " >
< attribute name = " ticket_lifetime " > 1 d < / attribute >
< attribute name = " renew_lifetime " / >
< attribute name = " clockskew " > 300 < / attribute >
< / gp_ext >
< / guid >
< / user >
< / gp >
2017-11-20 10:28:33 +13:00
Each guid value contains a list of extensions , which contain a list of
attributes . The guid value represents a GPO . The attributes are the values
of those settings prior to the application of the GPO .
The list of guids is enclosed within a user name , which represents the user
the settings were applied to . This user may be the samaccountname of the
local computer , which implies that these are machine policies .
The applylog keeps track of the order in which the GPOs were applied , so
that they can be rolled back in reverse , returning the machine to the state
prior to policy application .
2017-06-08 11:47:57 -06:00
'''
def __init__ ( self , user , gpostore , db_log = None ) :
''' Initialize the gp_log
2017-11-20 10:28:33 +13:00
param user - the username ( or machine name ) that policies are
being applied to
param gpostore - the GPOStorage obj which references the tdb which
contains gp_logs
2017-06-08 11:47:57 -06:00
param db_log - ( optional ) a string to initialize the gp_log
'''
2017-06-12 16:00:38 -06:00
self . _state = GPOSTATE . APPLY
2017-06-08 11:47:57 -06:00
self . gpostore = gpostore
self . username = user
if db_log :
self . gpdb = etree . fromstring ( db_log )
else :
self . gpdb = etree . Element ( ' gp ' )
2017-11-20 06:41:19 -07:00
self . user = user
user_obj = self . gpdb . find ( ' user[@name= " %s " ] ' % user )
if user_obj is None :
user_obj = etree . SubElement ( self . gpdb , ' user ' )
user_obj . attrib [ ' name ' ] = user
2017-06-08 11:47:57 -06:00
2017-06-12 16:00:38 -06:00
def state ( self , value ) :
''' Policy application state
param value - APPLY , ENFORCE , or UNAPPLY
2017-11-20 10:28:33 +13:00
The behavior of the gp_log depends on whether we are applying policy ,
enforcing policy , or unapplying policy . During an apply , old settings
are recorded in the log . During an enforce , settings are being applied
but the gp_log does not change . During an unapply , additions to the log
should be ignored ( since function calls to apply settings are actually
2017-06-12 16:00:38 -06:00
reverting policy ) , but removals from the log are allowed .
'''
# If we're enforcing, but we've unapplied, apply instead
if value == GPOSTATE . ENFORCE :
2017-11-20 06:41:19 -07:00
user_obj = self . gpdb . find ( ' user[@name= " %s " ] ' % self . user )
apply_log = user_obj . find ( ' applylog ' )
2017-06-12 16:00:38 -06:00
if apply_log is None or len ( apply_log ) == 0 :
self . _state = GPOSTATE . APPLY
else :
self . _state = value
else :
self . _state = value
2017-06-08 11:47:57 -06:00
def set_guid ( self , guid ) :
''' Log to a different GPO guid
2017-11-20 10:28:33 +13:00
param guid - guid value of the GPO from which we ' re applying
policy
2017-06-08 11:47:57 -06:00
'''
2017-11-20 06:41:19 -07:00
self . guid = guid
user_obj = self . gpdb . find ( ' user[@name= " %s " ] ' % self . user )
obj = user_obj . find ( ' guid[@value= " %s " ] ' % guid )
if obj is None :
obj = etree . SubElement ( user_obj , ' guid ' )
obj . attrib [ ' value ' ] = guid
2017-06-12 16:00:38 -06:00
if self . _state == GPOSTATE . APPLY :
2017-11-20 06:41:19 -07:00
apply_log = user_obj . find ( ' applylog ' )
2017-06-12 16:00:38 -06:00
if apply_log is None :
2017-11-20 06:41:19 -07:00
apply_log = etree . SubElement ( user_obj , ' applylog ' )
2017-06-12 16:00:38 -06:00
item = etree . SubElement ( apply_log , ' guid ' )
item . attrib [ ' count ' ] = ' %d ' % ( len ( apply_log ) - 1 )
item . attrib [ ' value ' ] = guid
2017-06-08 11:47:57 -06:00
def apply_log_pop ( self ) :
''' Pop a GPO guid from the applylog
return - last applied GPO guid
2017-11-20 10:28:33 +13:00
Removes the GPO guid last added to the list , which is the most recently
applied GPO .
2017-06-08 11:47:57 -06:00
'''
2017-11-20 06:41:19 -07:00
user_obj = self . gpdb . find ( ' user[@name= " %s " ] ' % self . user )
apply_log = user_obj . find ( ' applylog ' )
2017-06-08 11:47:57 -06:00
if apply_log is not None :
ret = apply_log . find ( ' guid[@count= " %d " ] ' % ( len ( apply_log ) - 1 ) )
if ret is not None :
apply_log . remove ( ret )
return ret . attrib [ ' value ' ]
2017-11-20 06:41:19 -07:00
if len ( apply_log ) == 0 and apply_log in user_obj :
user_obj . remove ( apply_log )
2017-06-08 11:47:57 -06:00
return None
def store ( self , gp_ext_name , attribute , old_val ) :
''' Store an attribute in the gp_log
param gp_ext_name - Name of the extension applying policy
param attribute - The attribute being modified
2017-11-20 10:28:33 +13:00
param old_val - The value of the attribute prior to policy
application
2017-06-08 11:47:57 -06:00
'''
2017-06-12 16:00:38 -06:00
if self . _state == GPOSTATE . UNAPPLY or self . _state == GPOSTATE . ENFORCE :
return None
2017-11-20 06:41:19 -07:00
user_obj = self . gpdb . find ( ' user[@name= " %s " ] ' % self . user )
guid_obj = user_obj . find ( ' guid[@value= " %s " ] ' % self . guid )
assert guid_obj is not None , " gpo guid was not set "
ext = guid_obj . find ( ' gp_ext[@name= " %s " ] ' % gp_ext_name )
2017-06-08 11:47:57 -06:00
if ext is None :
2017-11-20 06:41:19 -07:00
ext = etree . SubElement ( guid_obj , ' gp_ext ' )
2017-06-08 11:47:57 -06:00
ext . attrib [ ' name ' ] = gp_ext_name
attr = ext . find ( ' attribute[@name= " %s " ] ' % attribute )
if attr is None :
attr = etree . SubElement ( ext , ' attribute ' )
attr . attrib [ ' name ' ] = attribute
2017-12-01 11:18:55 -07:00
attr . text = old_val
2017-06-08 11:47:57 -06:00
def retrieve ( self , gp_ext_name , attribute ) :
''' Retrieve a stored attribute from the gp_log
param gp_ext_name - Name of the extension which applied policy
param attribute - The attribute being retrieved
2017-11-20 10:28:33 +13:00
return - The value of the attribute prior to policy
application
2017-06-08 11:47:57 -06:00
'''
2017-11-20 06:41:19 -07:00
user_obj = self . gpdb . find ( ' user[@name= " %s " ] ' % self . user )
guid_obj = user_obj . find ( ' guid[@value= " %s " ] ' % self . guid )
assert guid_obj is not None , " gpo guid was not set "
ext = guid_obj . find ( ' gp_ext[@name= " %s " ] ' % gp_ext_name )
2017-06-08 11:47:57 -06:00
if ext is not None :
attr = ext . find ( ' attribute[@name= " %s " ] ' % attribute )
if attr is not None :
return attr . text
return None
def list ( self , gp_extensions ) :
2017-11-20 10:28:33 +13:00
''' Return a list of attributes, their previous values, and functions
to set them
param gp_extensions - list of extension objects , for retrieving attr to
func mappings
return - list of ( attr , value , apply_func ) tuples for
unapplying policy
2017-06-08 11:47:57 -06:00
'''
2017-11-20 06:41:19 -07:00
user_obj = self . gpdb . find ( ' user[@name= " %s " ] ' % self . user )
guid_obj = user_obj . find ( ' guid[@value= " %s " ] ' % self . guid )
assert guid_obj is not None , " gpo guid was not set "
2017-06-08 11:47:57 -06:00
ret = [ ]
data_maps = { }
for gp_ext in gp_extensions :
data_maps . update ( gp_ext . apply_map ( ) )
2017-11-20 06:41:19 -07:00
exts = guid_obj . findall ( ' gp_ext ' )
2017-06-08 11:47:57 -06:00
if exts is not None :
for ext in exts :
attrs = ext . findall ( ' attribute ' )
for attr in attrs :
2018-01-08 09:16:11 -07:00
func = None
if attr . attrib [ ' name ' ] in data_maps [ ext . attrib [ ' name ' ] ] :
func = data_maps [ ext . attrib [ ' name ' ] ] \
[ attr . attrib [ ' name ' ] ] [ - 1 ]
else :
for dmap in data_maps [ ext . attrib [ ' name ' ] ] . keys ( ) :
if data_maps [ ext . attrib [ ' name ' ] ] [ dmap ] [ 0 ] == \
attr . attrib [ ' name ' ] :
func = data_maps [ ext . attrib [ ' name ' ] ] [ dmap ] [ - 1 ]
break
ret . append ( ( attr . attrib [ ' name ' ] , attr . text , func ) )
2017-06-08 11:47:57 -06:00
return ret
2014-01-31 13:27:05 +13:00
2017-06-08 11:47:57 -06:00
def delete ( self , gp_ext_name , attribute ) :
''' Remove an attribute from the gp_log
2017-11-20 10:28:33 +13:00
param gp_ext_name - name of extension from which to remove the
attribute
2017-06-08 11:47:57 -06:00
param attribute - attribute to remove
'''
2017-11-20 06:41:19 -07:00
user_obj = self . gpdb . find ( ' user[@name= " %s " ] ' % self . user )
guid_obj = user_obj . find ( ' guid[@value= " %s " ] ' % self . guid )
assert guid_obj is not None , " gpo guid was not set "
ext = guid_obj . find ( ' gp_ext[@name= " %s " ] ' % gp_ext_name )
2017-06-08 11:47:57 -06:00
if ext is not None :
attr = ext . find ( ' attribute[@name= " %s " ] ' % attribute )
if attr is not None :
ext . remove ( attr )
if len ( ext ) == 0 :
2017-11-20 06:41:19 -07:00
guid_obj . remove ( ext )
2017-06-08 11:47:57 -06:00
def commit ( self ) :
''' Write gp_log changes to disk '''
self . gpostore . store ( self . username , etree . tostring ( self . gpdb , ' utf-8 ' ) )
class GPOStorage :
def __init__ ( self , log_file ) :
if os . path . isfile ( log_file ) :
self . log = tdb . open ( log_file )
2017-05-25 07:27:27 -06:00
else :
2017-06-08 11:47:57 -06:00
self . log = tdb . Tdb ( log_file , 0 , tdb . DEFAULT , os . O_CREAT | os . O_RDWR )
2017-05-25 07:27:27 -06:00
2017-06-08 11:47:57 -06:00
def start ( self ) :
self . log . transaction_start ( )
def get_int ( self , key ) :
2017-05-25 07:27:27 -06:00
try :
2017-06-08 11:47:57 -06:00
return int ( self . log . get ( key ) )
2017-05-25 07:27:27 -06:00
except TypeError :
2017-06-08 11:47:57 -06:00
return None
def get ( self , key ) :
return self . log . get ( key )
def get_gplog ( self , user ) :
return gp_log ( user , self , self . log . get ( user ) )
def store ( self , key , val ) :
self . log . store ( key , val )
def cancel ( self ) :
self . log . transaction_cancel ( )
2017-05-25 07:27:27 -06:00
2017-06-08 11:47:57 -06:00
def delete ( self , key ) :
self . log . delete ( key )
2017-05-25 07:27:27 -06:00
def commit ( self ) :
2017-06-08 11:47:57 -06:00
self . log . transaction_commit ( )
2017-05-25 07:27:27 -06:00
def __del__ ( self ) :
2017-06-08 11:47:57 -06:00
self . log . close ( )
2017-05-25 07:27:27 -06:00
2014-01-31 13:27:05 +13:00
class gp_ext ( object ) :
2017-02-24 14:19:48 -07:00
__metaclass__ = ABCMeta
@abstractmethod
2014-01-31 13:27:05 +13:00
def list ( self , rootpath ) :
2017-02-24 14:19:48 -07:00
pass
@abstractmethod
2017-06-08 11:47:57 -06:00
def apply_map ( self ) :
2017-02-24 14:19:48 -07:00
pass
2014-01-31 13:27:05 +13:00
2017-02-24 14:19:48 -07:00
@abstractmethod
2017-06-08 11:47:57 -06:00
def parse ( self , afile , ldb , conn , gp_db , lp ) :
2017-02-24 14:19:48 -07:00
pass
2014-01-31 13:27:05 +13:00
2017-06-08 11:47:57 -06:00
@abstractmethod
def __str__ ( self ) :
pass
2014-01-31 13:27:05 +13:00
2017-02-24 14:19:48 -07:00
class inf_to ( ) :
__metaclass__ = ABCMeta
2014-01-31 13:27:05 +13:00
2017-06-08 11:47:57 -06:00
def __init__ ( self , logger , ldb , gp_db , lp , attribute , val ) :
2017-02-11 07:53:07 -07:00
self . logger = logger
2014-01-31 13:27:05 +13:00
self . ldb = ldb
self . attribute = attribute
self . val = val
2017-02-24 14:19:48 -07:00
self . lp = lp
2017-06-08 11:47:57 -06:00
self . gp_db = gp_db
2017-02-24 14:19:48 -07:00
def explicit ( self ) :
return self . val
def update_samba ( self ) :
( upd_sam , value ) = self . mapper ( ) . get ( self . attribute )
upd_sam ( value ( ) )
@abstractmethod
def mapper ( self ) :
pass
2017-06-08 11:47:57 -06:00
@abstractmethod
def __str__ ( self ) :
pass
2017-08-09 11:30:00 -06:00
class inf_to_kdc_tdb ( inf_to ) :
def mins_to_hours ( self ) :
return ' %d ' % ( int ( self . val ) / 60 )
def days_to_hours ( self ) :
return ' %d ' % ( int ( self . val ) * 24 )
def set_kdc_tdb ( self , val ) :
old_val = self . gp_db . gpostore . get ( self . attribute )
2017-11-20 10:28:33 +13:00
self . logger . info ( ' %s was changed from %s to %s ' % ( self . attribute ,
old_val , val ) )
2017-08-09 11:30:00 -06:00
if val is not None :
self . gp_db . gpostore . store ( self . attribute , val )
self . gp_db . store ( str ( self ) , self . attribute , old_val )
else :
self . gp_db . gpostore . delete ( self . attribute )
self . gp_db . delete ( str ( self ) , self . attribute )
def mapper ( self ) :
return { ' kdc:user_ticket_lifetime ' : ( self . set_kdc_tdb , self . explicit ) ,
2017-11-20 10:28:33 +13:00
' kdc:service_ticket_lifetime ' : ( self . set_kdc_tdb ,
self . mins_to_hours ) ,
' kdc:renewal_lifetime ' : ( self . set_kdc_tdb ,
self . days_to_hours ) ,
2017-08-09 11:30:00 -06:00
}
def __str__ ( self ) :
return ' Kerberos Policy '
2017-02-24 14:19:48 -07:00
class inf_to_ldb ( inf_to ) :
2017-11-20 10:28:33 +13:00
''' This class takes the .inf file parameter (essentially a GPO file mapped
to a GUID ) , hashmaps it to the Samba parameter , which then uses an ldb
object to update the parameter to Samba4 . Not registry oriented whatsoever .
2017-02-24 14:19:48 -07:00
'''
2014-01-31 13:27:05 +13:00
def ch_minPwdAge ( self , val ) :
2017-06-08 11:47:57 -06:00
old_val = self . ldb . get_minPwdAge ( )
2017-11-20 10:28:33 +13:00
self . logger . info ( ' KDC Minimum Password age was changed from %s to %s ' \
% ( old_val , val ) )
2017-06-08 11:47:57 -06:00
self . gp_db . store ( str ( self ) , self . attribute , old_val )
2014-01-31 13:27:05 +13:00
self . ldb . set_minPwdAge ( val )
def ch_maxPwdAge ( self , val ) :
2017-06-08 11:47:57 -06:00
old_val = self . ldb . get_maxPwdAge ( )
2017-11-20 10:28:33 +13:00
self . logger . info ( ' KDC Maximum Password age was changed from %s to %s ' \
% ( old_val , val ) )
2017-06-08 11:47:57 -06:00
self . gp_db . store ( str ( self ) , self . attribute , old_val )
2014-01-31 13:27:05 +13:00
self . ldb . set_maxPwdAge ( val )
def ch_minPwdLength ( self , val ) :
2017-06-08 11:47:57 -06:00
old_val = self . ldb . get_minPwdLength ( )
2017-11-20 10:28:33 +13:00
self . logger . info (
' KDC Minimum Password length was changed from %s to %s ' \
% ( old_val , val ) )
2017-06-08 11:47:57 -06:00
self . gp_db . store ( str ( self ) , self . attribute , old_val )
2014-01-31 13:27:05 +13:00
self . ldb . set_minPwdLength ( val )
def ch_pwdProperties ( self , val ) :
2017-06-08 11:47:57 -06:00
old_val = self . ldb . get_pwdProperties ( )
2017-11-20 10:28:33 +13:00
self . logger . info ( ' KDC Password Properties were changed from %s to %s ' \
% ( old_val , val ) )
2017-06-08 11:47:57 -06:00
self . gp_db . store ( str ( self ) , self . attribute , old_val )
2014-01-31 13:27:05 +13:00
self . ldb . set_pwdProperties ( val )
2017-10-24 15:59:37 +13:00
def days2rel_nttime ( self ) :
2014-01-31 13:27:05 +13:00
seconds = 60
minutes = 60
hours = 24
sam_add = 10000000
val = ( self . val )
val = int ( val )
return str ( - ( val * seconds * minutes * hours * sam_add ) )
def mapper ( self ) :
''' ldap value : samba setter '''
2017-10-24 15:59:37 +13:00
return { " minPwdAge " : ( self . ch_minPwdAge , self . days2rel_nttime ) ,
" maxPwdAge " : ( self . ch_maxPwdAge , self . days2rel_nttime ) ,
2017-11-20 10:28:33 +13:00
# Could be none, but I like the method assignment in
# update_samba
2014-01-31 13:27:05 +13:00
" minPwdLength " : ( self . ch_minPwdLength , self . explicit ) ,
" pwdProperties " : ( self . ch_pwdProperties , self . explicit ) ,
}
2017-06-08 11:47:57 -06:00
def __str__ ( self ) :
return ' System Access '
2014-01-31 13:27:05 +13:00
class gp_sec_ext ( gp_ext ) :
''' This class does the following two things:
1 ) Identifies the GPO if it has a certain kind of filepath ,
2 ) Finally parses it .
'''
count = 0
2017-02-11 07:53:07 -07:00
def __init__ ( self , logger ) :
self . logger = logger
2014-01-31 13:27:05 +13:00
def __str__ ( self ) :
return " Security GPO extension "
def list ( self , rootpath ) :
2017-11-20 10:28:33 +13:00
return os . path . join ( rootpath ,
" MACHINE/Microsoft/Windows NT/SecEdit/GptTmpl.inf " )
2014-01-31 13:27:05 +13:00
def listmachpol ( self , rootpath ) :
2017-05-25 07:27:27 -06:00
return os . path . join ( rootpath , " Machine/Registry.pol " )
2014-01-31 13:27:05 +13:00
def listuserpol ( self , rootpath ) :
2017-05-25 07:27:27 -06:00
return os . path . join ( rootpath , " User/Registry.pol " )
2014-01-31 13:27:05 +13:00
2017-06-08 11:47:57 -06:00
def apply_map ( self ) :
2017-11-20 10:28:33 +13:00
return { " System Access " : { " MinimumPasswordAge " : ( " minPwdAge " ,
inf_to_ldb ) ,
" MaximumPasswordAge " : ( " maxPwdAge " ,
inf_to_ldb ) ,
" MinimumPasswordLength " : ( " minPwdLength " ,
inf_to_ldb ) ,
" PasswordComplexity " : ( " pwdProperties " ,
inf_to_ldb ) ,
2017-08-09 11:30:00 -06:00
} ,
2017-11-20 10:28:33 +13:00
" Kerberos Policy " : { " MaxTicketAge " : (
" kdc:user_ticket_lifetime " ,
inf_to_kdc_tdb
) ,
" MaxServiceAge " : (
" kdc:service_ticket_lifetime " ,
inf_to_kdc_tdb
) ,
" MaxRenewAge " : (
" kdc:renewal_lifetime " ,
inf_to_kdc_tdb
) ,
2017-08-09 11:30:00 -06:00
}
2014-01-31 13:27:05 +13:00
}
2017-05-25 07:27:27 -06:00
def read_inf ( self , path , conn ) :
2014-01-31 13:27:05 +13:00
ret = False
2017-06-08 11:47:57 -06:00
inftable = self . apply_map ( )
2014-01-31 13:27:05 +13:00
2017-03-03 12:54:30 -07:00
policy = conn . loadfile ( path . replace ( ' / ' , ' \\ ' ) )
2014-01-31 13:27:05 +13:00
current_section = None
# So here we would declare a boolean,
# that would get changed to TRUE.
#
# If at any point in time a GPO was applied,
# then we return that boolean at the end.
2017-02-11 07:53:07 -07:00
inf_conf = ConfigParser ( )
inf_conf . optionxform = str
2017-03-03 12:54:30 -07:00
try :
inf_conf . readfp ( StringIO ( policy ) )
except :
inf_conf . readfp ( StringIO ( policy . decode ( ' utf-16 ' ) ) )
2017-02-11 07:53:07 -07:00
for section in inf_conf . sections ( ) :
current_section = inftable . get ( section )
if not current_section :
continue
for key , value in inf_conf . items ( section ) :
2014-01-31 13:27:05 +13:00
if current_section . get ( key ) :
( att , setter ) = current_section . get ( key )
value = value . encode ( ' ascii ' , ' ignore ' )
ret = True
2017-11-20 10:28:33 +13:00
setter ( self . logger , self . ldb , self . gp_db , self . lp , att ,
value ) . update_samba ( )
2017-06-08 11:47:57 -06:00
self . gp_db . commit ( )
2014-01-31 13:27:05 +13:00
return ret
2017-06-08 11:47:57 -06:00
def parse ( self , afile , ldb , conn , gp_db , lp ) :
2014-01-31 13:27:05 +13:00
self . ldb = ldb
2017-06-08 11:47:57 -06:00
self . gp_db = gp_db
2017-02-24 14:19:48 -07:00
self . lp = lp
2014-01-31 13:27:05 +13:00
# Fixing the bug where only some Linux Boxes capitalize MACHINE
if afile . endswith ( ' inf ' ) :
try :
blist = afile . split ( ' / ' )
idx = afile . lower ( ) . split ( ' / ' ) . index ( ' machine ' )
2017-11-20 10:28:33 +13:00
for case in [ blist [ idx ] . upper ( ) , blist [ idx ] . capitalize ( ) ,
blist [ idx ] . lower ( ) ] :
bfile = ' / ' . join ( blist [ : idx ] ) + ' / ' + case + ' / ' + \
' / ' . join ( blist [ idx + 1 : ] )
2014-01-31 13:27:05 +13:00
try :
2017-05-25 07:27:27 -06:00
return self . read_inf ( bfile , conn )
2014-01-31 13:27:05 +13:00
except NTSTATUSError :
continue
except ValueError :
try :
2017-05-25 07:27:27 -06:00
return self . read_inf ( afile , conn )
2014-01-31 13:27:05 +13:00
except :
return None