<s> import os <EOL> import errno <EOL> import sys <EOL> sys . path . extend ( [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ] ) <EOL> os . environ [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> from django . db . models . loading import cache <EOL> cache . get_apps ( ) <EOL> RESOLV_CONF_PATH = "<STR_LIT>" <EOL> from freenasUI . common . system import domaincontroller_enabled <EOL> from freenasUI . network . models import ( <EOL> GlobalConfiguration , <EOL> Interfaces <EOL> ) <EOL> from freenasUI . services . models import ( <EOL> CIFS , <EOL> DomainController <EOL> ) <EOL> def main ( ) : <EOL> domain = None <EOL> nameservers = [ ] <EOL> if domaincontroller_enabled ( ) : <EOL> try : <EOL> cifs = CIFS . objects . all ( ) [ <NUM_LIT:0> ] <EOL> dc = DomainController . objects . all ( ) [ <NUM_LIT:0> ] <EOL> domain = dc . dc_realm <EOL> if cifs . cifs_srv_bindip : <EOL> for ip in cifs . cifs_srv_bindip : <EOL> nameservers . append ( ip ) <EOL> else : <EOL> nameservers . append ( "<STR_LIT:127.0.0.1>" ) <EOL> except Exception as e : <EOL> print >> sys . stderr , "<STR_LIT>" % e <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> else : <EOL> try : <EOL> gc = GlobalConfiguration . objects . all ( ) [ <NUM_LIT:0> ] <EOL> if gc . gc_domain : <EOL> domain = gc . gc_domain <EOL> if gc . gc_nameserver1 : <EOL> nameservers . append ( gc . gc_nameserver1 ) <EOL> if gc . gc_nameserver2 : <EOL> nameservers . append ( gc . gc_nameserver2 ) <EOL> if gc . gc_nameserver3 : <EOL> nameservers . append ( gc . gc_nameserver3 ) <EOL> except Exception as e : <EOL> print >> sys . stderr , "<STR_LIT>" % e <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> if ( <EOL> not nameservers and <EOL> ( Interfaces . objects . count ( ) == <NUM_LIT:0> or Interfaces . objects . filter ( int_dhcp = True ) ) <EOL> ) : <EOL> try : <EOL> os . remove ( "<STR_LIT>" ) <EOL> except OSError as e : <EOL> if e . errno != errno . ENOENT : <EOL> raise <EOL> pass <EOL> sys . exit ( <NUM_LIT:0> ) <EOL> try : <EOL> fd = os . open ( RESOLV_CONF_PATH , os . O_WRONLY | os . O_CREAT | os . O_TRUNC , <NUM_LIT> ) <EOL> if domain : <EOL> os . write ( fd , "<STR_LIT>" % domain ) <EOL> for ns in nameservers : <EOL> os . write ( fd , "<STR_LIT>" % ns ) <EOL> os . close ( fd ) <EOL> with open ( "<STR_LIT>" , '<STR_LIT:w>' ) as f : <EOL> f . write ( <EOL> """<STR_LIT>""" <EOL> ) <EOL> os . chmod ( "<STR_LIT>" , <NUM_LIT> ) <EOL> except Exception as e : <EOL> print >> sys . stderr , "<STR_LIT>" % ( RESOLV_CONF_PATH , e ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> main ( ) </s>
