Ejemplo n.º 1
0
    def test_check_netbios_name(self):
        assert adtrustinstance.check_netbios_name("ABCDEF")
        assert not adtrustinstance.check_netbios_name("abcdef")
        assert adtrustinstance.check_netbios_name("ABCDE12345ABCDE")
        assert not adtrustinstance.check_netbios_name("ABCDE12345ABCDE1")
        assert not adtrustinstance.check_netbios_name("")

        assert adtrustinstance.check_netbios_name(U"ABCDEF")
        assert not adtrustinstance.check_netbios_name(U"abcdef")
        assert adtrustinstance.check_netbios_name(U"ABCDE12345ABCDE")
        assert not adtrustinstance.check_netbios_name(U"ABCDE12345ABCDE1")
Ejemplo n.º 2
0
    def test_check_netbios_name(self):
        assert adtrustinstance.check_netbios_name("ABCDEF")
        assert not adtrustinstance.check_netbios_name("abcdef")
        assert adtrustinstance.check_netbios_name("ABCDE12345ABCDE")
        assert not adtrustinstance.check_netbios_name("ABCDE12345ABCDE1")
        assert not adtrustinstance.check_netbios_name("")

        assert adtrustinstance.check_netbios_name(U"ABCDEF")
        assert not adtrustinstance.check_netbios_name(U"abcdef")
        assert adtrustinstance.check_netbios_name(U"ABCDE12345ABCDE")
        assert not adtrustinstance.check_netbios_name(U"ABCDE12345ABCDE1")
Ejemplo n.º 3
0
def read_netbios_name(netbios_default):
    netbios_name = ""

    print("Enter the NetBIOS name for the IPA domain.")
    print("Only up to 15 uppercase ASCII letters, digits "
          "and dashes are allowed.")
    print("Example: EXAMPLE.")
    print("")
    print("")
    if not netbios_default:
        netbios_default = "EXAMPLE"
    while True:
        netbios_name = ipautil.user_input(
            "NetBIOS domain name", netbios_default, allow_empty=False)
        print("")
        if adtrustinstance.check_netbios_name(netbios_name):
            break

        netbios_name_error(netbios_name)

    return netbios_name
Ejemplo n.º 4
0
def read_netbios_name(netbios_default):
    netbios_name = ""

    print("Enter the NetBIOS name for the IPA domain.")
    print("Only up to 15 uppercase ASCII letters, digits "
          "and dashes are allowed.")
    print("Example: EXAMPLE.")
    print("")
    print("")
    if not netbios_default:
        netbios_default = "EXAMPLE"
    while True:
        netbios_name = ipautil.user_input(
            "NetBIOS domain name", netbios_default, allow_empty=False)
        print("")
        if adtrustinstance.check_netbios_name(netbios_name):
            break

        netbios_name_error(netbios_name)

    return netbios_name
Ejemplo n.º 5
0
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)
Ejemplo n.º 6
0
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)
Ejemplo n.º 7
0
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)