Beispiel #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;
    }
}
Beispiel #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;
    }
}
Beispiel #3
0
static void test_remove(void **context)
{
    setup();

    UpdateLastSawHost("SHA-12345", "127.0.0.64", true, 555);
    UpdateLastSawHost("SHA-12345", "127.0.0.64", false, 556);

    RemoveHostFromLastSeen("SHA-12345");

    DBHandle *db;
    OpenDB(&db, dbid_lastseen);

    assert_int_equal(HasKeyDB(db, "qiSHA-12345", strlen("qiSHA-12345") + 1), false);
    assert_int_equal(HasKeyDB(db, "qoSHA-12345", strlen("qoSHA-12345") + 1), false);
    assert_int_equal(HasKeyDB(db, "kSHA-12345", strlen("kSHA-12345") + 1), false);
    assert_int_equal(HasKeyDB(db, "a127.0.0.64", strlen("a127.0.0.64") + 1), false);

    CloseDB(db);
}
Beispiel #4
0
static int RemoveKeys(const char *host)
{
RemoveHostFromLastSeen(host,NULL);
int removed_keys = RemovePublicKeys(remove_keys_host);

if (removed_keys < 0)
   {
   CfOut(cf_error, "", "Unable to remove keys for the host %s", remove_keys_host);
   return 255;
   }
else if (removed_keys == 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_keys, remove_keys_host);
   return 0;
   }
}