Ejemplo n.º 1
0
def handled_list(ui_, params, stored_cfg):
    """ INTERNAL: HACKED"""
    if params['FMSREAD'] != 'listall' and params['FMSREAD'] != 'list':
        return False

    trust_map = None
    if params['FMSREAD'] == 'list':
        trust_map = stored_cfg.fmsread_trust_map.copy() # paranoid copy
        fms_ids = trust_map.keys()
        fms_ids.sort()
        ui_.status(("Only listing repo USKs from trusted "
                    + "FMS IDs:\n   %s\n\n") % '\n   '.join(fms_ids))

    parser = USKNotificationParser(trust_map)
    parser.add_default_repos(KNOWN_REPOS)
    recv_msgs(get_connection(stored_cfg.defaults['FMS_HOST'],
                             stored_cfg.defaults['FMS_PORT'],
                             None),
              parser,
              stored_cfg.fmsread_groups)
    show_table(parser, ui_.status)

    return True
Ejemplo n.º 2
0
def get_uri_from_hash(ui_, dummy, params, stored_cfg):
    """ Use FMS to get the URI for a repo hash. """

    show_fms_info(ui_, params, stored_cfg)

    parser = USKNotificationParser(get_trust_map(ui_, params, stored_cfg))
    parser.add_default_repos(KNOWN_REPOS)

    ui_.status("Raking through fms messages. This may take a while...\n")
    recv_msgs(get_connection(stored_cfg.defaults['FMS_HOST'],
                             stored_cfg.defaults['FMS_PORT'],
                             None),
              parser,
              stored_cfg.fmsread_groups,
              None,
              True)

    target_usk = None
    fms_id_map, announce_map, update_map = parser.invert_table()

    # Find URI
    for usk in announce_map:
        if params['FMSREAD_HASH'] == get_usk_hash(usk):
            # We don't care who announced. The hash matches.
            target_usk = usk
            break

    if target_usk is None:
        raise util.Abort(("No announcement found for [%s]. "
                          +"Use --uri to set the URI.") %
                         params['FMSREAD_HASH'])

    if params['VERBOSITY'] >= 2:
        ui_.status("Found URI announcement:\n%s\n" % target_usk)

    trusted_notifiers = stored_cfg.trusted_notifiers(params['FMSREAD_HASH'])

    notifiers = {}
    for clean_id in update_map[params['FMSREAD_HASH']]:
        notifiers[fms_id_map[clean_id]] = (parser.table[clean_id][1]
                                           [params['FMSREAD_HASH']])

    fms_ids = notifiers.keys()
    fms_ids.sort()

    ui_.status("Found Updates:\n")
    for fms_id in fms_ids:
        if fms_id in trusted_notifiers:
            ui_.status("   [trusted]:%i:%s\n" % (notifiers[fms_id], fms_id))
        else:
            ui_.status("   [untrusted]:%i:%s\n" % (notifiers[fms_id], fms_id))

    check_trust_map(ui_, stored_cfg, params['FMSREAD_HASH'],
                    notifiers, trusted_notifiers)

    # Check for updates against the updated trust map.
    trusted_notifiers = stored_cfg.trusted_notifiers(params['FMSREAD_HASH'])
    for fms_id in fms_ids:
        if fms_id in trusted_notifiers:
            if (notifiers[fms_id] >
                stored_cfg.get_index(params['FMSREAD_HASH'])):
                stored_cfg.update_index(params['FMSREAD_HASH'],
                                        notifiers[fms_id])

    return target_usk
Ejemplo n.º 3
0
def execute_fmsread(ui_, params, stored_cfg):
    """ Run the fmsread command. """

    if handled_trust_cmd(ui_, params, stored_cfg):
        return

    show_fms_info(ui_, params, stored_cfg)

    # Listing announced Repo USKs
    if handled_list(ui_, params, stored_cfg):
        return

    # Updating Repo USK indices for repos which are
    # listed in the fmsread_trust_map section of the
    # config file.
    trust_map = stored_cfg.fmsread_trust_map.copy() # paranoid copy

    dump_trust_map(ui_, params, trust_map)

    ui_.status("Raking through fms messages. This may take a while...\n")
    parser = USKNotificationParser()
    recv_msgs(get_connection(stored_cfg.defaults['FMS_HOST'],
                             stored_cfg.defaults['FMS_PORT'],
                             None),
              parser,
              stored_cfg.fmsread_groups)

    # IMPORTANT: Must include versions that are in the trust map
    #            but which we haven't seen before.
    full_version_table = stored_cfg.version_table.copy()
    for usk_hash in known_hashes(trust_map):
        if not usk_hash in full_version_table:
            full_version_table[usk_hash] = None # works

    changed, untrusted = parser.get_updated(trust_map, full_version_table)

    if params['VERBOSITY'] >= 2 and len(untrusted) > 0:
        text = 'Skipped untrusted updates:\n'
        for usk_hash in untrusted:
            text += "   %i:%s\n" % (untrusted[usk_hash][0], usk_hash)
        text += '\n'
        ui_.status(text)

    if len(changed) == 0:
        ui_.status('No updates found.\n')
        return

    # Back map to uris ? Can't always do it.
    if len(changed) > 0:
        text = 'Updates:\n'
        for usk_hash in changed:
            text += '%s:%i\n' % (usk_hash, changed[usk_hash])
        ui_.status(text)
        if ((not params['REQUEST_URI'] is None) and
            get_usk_hash(params['REQUEST_URI']) in changed):
            ui_.status("Current repo has update to index %s.\n" %
                       changed[get_usk_hash(params['REQUEST_URI'])])

    if params['DRYRUN']:
        ui_.status('Exiting without saving because --dryrun was set.\n')
        return

    for usk_hash in changed:
        stored_cfg.update_index(usk_hash, changed[usk_hash])

    Config.to_file(stored_cfg)
    ui_.status('Saved updated indices.\n')