Exemple #1
0
static int RemoveKeys(const char *host)
{
    char ip[CF_BUFSIZE];
    char digest[CF_BUFSIZE];

    strcpy(ip, Hostname2IPString(host));
    Address2Hostkey(ip, digest);

    RemoveHostFromLastSeen(digest);

    int removed_by_ip = RemovePublicKey(ip);
    int removed_by_digest = RemovePublicKey(digest);

    if ((removed_by_ip == -1) || (removed_by_digest == -1))
    {
        CfOut(cf_error, "", "Unable to remove keys for the host %s",
              remove_keys_host);
        return 255;
    }
    else if (removed_by_ip + removed_by_digest == 0)
    {
        CfOut(cf_error, "", "No keys for host %s were found", remove_keys_host);
        return 1;
    }
    else
    {
        CfOut(cf_inform, "", "Removed %d key(s) for host %s",
              removed_by_ip + removed_by_digest, remove_keys_host);
        return 0;
    }
}
Exemple #2
0
int RemoveKeys(const char *host)
{
    char digest[CF_BUFSIZE];
    char ipaddr[CF_MAX_IP_LEN];

    if (Hostname2IPString(ipaddr, host, sizeof(ipaddr)) == -1)
    {
        Log(LOG_LEVEL_ERR, 
            "ERROR, could not resolve %s, not removing", host);
        return 255;
    }

    Address2Hostkey(ipaddr, digest);
    RemoveHostFromLastSeen(digest);

    int removed_by_ip = RemovePublicKey(ipaddr);
    int removed_by_digest = RemovePublicKey(digest);

    if ((removed_by_ip == -1) || (removed_by_digest == -1))
    {
        Log(LOG_LEVEL_ERR, "Unable to remove keys for the host %s", host);
        return 255;
    }
    else if (removed_by_ip + removed_by_digest == 0)
    {
        Log(LOG_LEVEL_ERR, "No keys for host %s were found", host);
        return 1;
    }
    else
    {
        Log(LOG_LEVEL_INFO, "Removed %d key(s) for host %s",
              removed_by_ip + removed_by_digest, host);
        return 0;
    }
}
Exemple #3
0
/**
 * @brief removes all traces of entry 'input' from lastseen and filesystem
 *
 * @param[in] key digest (SHA/MD5 format) or free host name string
 * @param[in] must_be_coherent. false : delete if lastseen is incoherent, 
 *                              true :  don't if lastseen is incoherent
 * @retval 0 if entry was deleted, >0 otherwise
 */
int RemoveKeys(const char *input, bool must_be_coherent)
{
    int res = 0;
    char equivalent[CF_BUFSIZE];
    equivalent[0] = '\0';

    res = RemoveKeysFromLastSeen(input, must_be_coherent, equivalent);
    if (res!=0)
    {
        return res;
    }

    Log(LOG_LEVEL_INFO, "Removed corresponding entries from lastseen database.");

    int removed_input      = RemovePublicKey(input);
    int removed_equivalent = RemovePublicKey(equivalent);

    if ((removed_input == -1) || (removed_equivalent == -1))
    {
        Log(LOG_LEVEL_ERR, "Unable to remove keys for the entry %s", input);
        return 255;
    }
    else if (removed_input + removed_equivalent == 0)
    {
        Log(LOG_LEVEL_ERR, "No key file(s) for entry %s were found on the filesytem", input);
        return 1;
    }
    else
    {
        Log(LOG_LEVEL_INFO, "Removed %d corresponding key file(s) from filesystem.",
              removed_input + removed_equivalent);
        return 0;
    }

    return -1;
}