def test_make_netbios_name(self): s = adtrustinstance.make_netbios_name("ABCDEF") assert s == 'ABCDEF' and isinstance(s, str) s = adtrustinstance.make_netbios_name(U"ABCDEF") assert s == 'ABCDEF' and isinstance(s, unicode) s = adtrustinstance.make_netbios_name("abcdef") assert s == 'ABCDEF' s = adtrustinstance.make_netbios_name("abc.def") assert s == 'ABC' s = adtrustinstance.make_netbios_name("abcdefghijklmnopqr.def") assert s == 'ABCDEFGHIJKLMNO' s = adtrustinstance.make_netbios_name("A!$%B&/()C=?+*D") assert s == 'ABCD' s = adtrustinstance.make_netbios_name("!$%&/()=?+*") assert not s
def set_and_check_netbios_name(netbios_name, unattended, api): """ Depending if trust in already configured or not a given NetBIOS domain name must be handled differently. If trust is not configured the given NetBIOS is used or the NetBIOS is generated if none was given on the command line. If trust is already configured the given NetBIOS name is used to reset the stored NetBIOS name it it differs from the current one. """ flat_name_attr = 'ipantflatname' cur_netbios_name = None gen_netbios_name = None reset_netbios_name = False entry = None try: entry = api.Backend.ldap2.get_entry( DN(('cn', api.env.domain), api.env.container_cifsdomains, ipautil.realm_to_suffix(api.env.realm)), [flat_name_attr]) except errors.NotFound: # trust not configured pass else: cur_netbios_name = entry.get(flat_name_attr)[0] if cur_netbios_name and not netbios_name: # keep the current NetBIOS name netbios_name = cur_netbios_name reset_netbios_name = False elif cur_netbios_name and cur_netbios_name != netbios_name: # change the NetBIOS name print("Current NetBIOS domain name is %s, new name is %s.\n" % (cur_netbios_name, netbios_name)) print("Please note that changing the NetBIOS name might " "break existing trust relationships.") if unattended: reset_netbios_name = True print("NetBIOS domain name will be changed to %s.\n" % netbios_name) else: print("Say 'yes' if the NetBIOS shall be changed and " "'no' if the old one shall be kept.") reset_netbios_name = ipautil.user_input( 'Do you want to reset the NetBIOS domain name?', default=False, allow_empty=False) if not reset_netbios_name: netbios_name = cur_netbios_name elif cur_netbios_name and cur_netbios_name == netbios_name: # keep the current NetBIOS name reset_netbios_name = False elif not cur_netbios_name: if not netbios_name: gen_netbios_name = adtrustinstance.make_netbios_name( api.env.domain) if entry is not None: # Fix existing trust configuration print("Trust is configured but no NetBIOS domain name found, " "setting it now.") reset_netbios_name = True else: # initial trust configuration reset_netbios_name = False else: # all possible cases should be covered above raise Exception('Unexpected state while checking NetBIOS domain name') if unattended and netbios_name is None and gen_netbios_name: netbios_name = gen_netbios_name if not adtrustinstance.check_netbios_name(netbios_name): if unattended: netbios_name_error(netbios_name) raise ScriptError("Aborting installation.") else: if netbios_name: netbios_name_error(netbios_name) netbios_name = None if not unattended and not netbios_name: netbios_name = read_netbios_name(gen_netbios_name) return (netbios_name, reset_netbios_name)
def set_and_check_netbios_name(netbios_name, unattended, api): """ Depending on whether a trust is already configured or not, the passed NetBIOS domain name must be handled differently. If trust is not configured, the given NetBIOS is used. The NetBIOS is generated if none was given on the command line. If trust is already configured, the given NetBIOS name is used to reset the stored NetBIOS name in case it differs from the current one. """ cur_netbios_name = None gen_netbios_name = None reset_netbios_name = False if api.Backend.ldap2.isconnected(): cur_netbios_name = retrieve_netbios_name(api) else: logger.debug( "LDAP is not connected, can not retrieve NetBIOS name") if cur_netbios_name and not netbios_name: # keep the current NetBIOS name netbios_name = cur_netbios_name reset_netbios_name = False elif cur_netbios_name and cur_netbios_name != netbios_name: # change the NetBIOS name print("Current NetBIOS domain name is %s, new name is %s.\n" % (cur_netbios_name, netbios_name)) print("Please note that changing the NetBIOS name might " "break existing trust relationships.") if unattended: reset_netbios_name = True print("NetBIOS domain name will be changed to %s.\n" % netbios_name) else: print("Say 'yes' if the NetBIOS shall be changed and " "'no' if the old one shall be kept.") reset_netbios_name = ipautil.user_input( 'Do you want to reset the NetBIOS domain name?', default=False, allow_empty=False) if not reset_netbios_name: netbios_name = cur_netbios_name elif cur_netbios_name and cur_netbios_name == netbios_name: # keep the current NetBIOS name reset_netbios_name = False elif not cur_netbios_name: if not netbios_name: gen_netbios_name = adtrustinstance.make_netbios_name( api.env.domain) if gen_netbios_name is not None: # Fix existing trust configuration print("Trust is configured but no NetBIOS domain name found, " "setting it now.") reset_netbios_name = True else: # initial trust configuration reset_netbios_name = False else: # all possible cases should be covered above raise Exception('Unexpected state while checking NetBIOS domain name') if unattended and netbios_name is None and gen_netbios_name: netbios_name = gen_netbios_name if not adtrustinstance.check_netbios_name(netbios_name): if unattended: netbios_name_error(netbios_name) raise ScriptError("Aborting installation.") else: if netbios_name: netbios_name_error(netbios_name) netbios_name = None if not unattended and not netbios_name: netbios_name = read_netbios_name(gen_netbios_name) return (netbios_name, reset_netbios_name)
def set_and_check_netbios_name(netbios_name, unattended, api): """ Depending on whether a trust is already configured or not, the passed NetBIOS domain name must be handled differently. If trust is not configured, the given NetBIOS is used. The NetBIOS is generated if none was given on the command line. If trust is already configured, the given NetBIOS name is used to reset the stored NetBIOS name in case it differs from the current one. """ cur_netbios_name = None gen_netbios_name = None reset_netbios_name = False entry = None if api.Backend.ldap2.isconnected(): cur_netbios_name = retrieve_netbios_name(api) else: logger.debug( "LDAP is not connected, can not retrieve NetBIOS name") if cur_netbios_name and not netbios_name: # keep the current NetBIOS name netbios_name = cur_netbios_name reset_netbios_name = False elif cur_netbios_name and cur_netbios_name != netbios_name: # change the NetBIOS name print("Current NetBIOS domain name is %s, new name is %s.\n" % (cur_netbios_name, netbios_name)) print("Please note that changing the NetBIOS name might " "break existing trust relationships.") if unattended: reset_netbios_name = True print("NetBIOS domain name will be changed to %s.\n" % netbios_name) else: print("Say 'yes' if the NetBIOS shall be changed and " "'no' if the old one shall be kept.") reset_netbios_name = ipautil.user_input( 'Do you want to reset the NetBIOS domain name?', default=False, allow_empty=False) if not reset_netbios_name: netbios_name = cur_netbios_name elif cur_netbios_name and cur_netbios_name == netbios_name: # keep the current NetBIOS name reset_netbios_name = False elif not cur_netbios_name: if not netbios_name: gen_netbios_name = adtrustinstance.make_netbios_name( api.env.domain) if entry is not None: # Fix existing trust configuration print("Trust is configured but no NetBIOS domain name found, " "setting it now.") reset_netbios_name = True else: # initial trust configuration reset_netbios_name = False else: # all possible cases should be covered above raise Exception('Unexpected state while checking NetBIOS domain name') if unattended and netbios_name is None and gen_netbios_name: netbios_name = gen_netbios_name if not adtrustinstance.check_netbios_name(netbios_name): if unattended: netbios_name_error(netbios_name) raise ScriptError("Aborting installation.") else: if netbios_name: netbios_name_error(netbios_name) netbios_name = None if not unattended and not netbios_name: netbios_name = read_netbios_name(gen_netbios_name) return (netbios_name, reset_netbios_name)