AgentDiagnosticsResult AgentDiagnosticsCheckPublicKey(const char *workdir)
{
    char *path = PublicKeyFile(workdir);
    struct stat sb;
    AgentDiagnosticsResult res;

    if (stat(path, &sb) != 0)
    {
        res = AgentDiagnosticsResultNew(false, StringFormat("No public key found at '%s'", path));
    }
    else if (sb.st_mode != (S_IFREG | S_IWUSR | S_IRUSR))
    {
        res = AgentDiagnosticsResultNew(false, StringFormat("Public key found at '%s', but had incorrect permissions '%o'", path, sb.st_mode));
    }
    else if (sb.st_size != 426)
    {
        res = AgentDiagnosticsResultNew(false, StringFormat("Public key at '%s' had size %lld bytes, expected 426 bytes", path, (long long)sb.st_size));
    }
    else
    {
        res = AgentDiagnosticsResultNew(true, StringFormat("OK at '%s'", path));
    }

    free(path);
    return res;
}
static AgentDiagnosticsResult AgentDiagnosticsCheckDB(ARG_UNUSED const char *workdir, dbid id)
{
    char *dbpath = DBIdToPath(id);
    char *error = DBPrivDiagnose(dbpath);

    if (error)
    {
        free(dbpath);
        return AgentDiagnosticsResultNew(false, error);
    }
    else
    {
        int ret = CheckTokyoDBCoherence(dbpath);
        free(dbpath);
        if (ret)
        {
            return AgentDiagnosticsResultNew(false, xstrdup("Internal DB coherence problem"));
        }
        else
        {
            if (id == dbid_lastseen)
            {
                if (IsLastSeenCoherent() == false)
                {
                    return AgentDiagnosticsResultNew(false, xstrdup("Lastseen DB data coherence problem"));
                }
            }
            return AgentDiagnosticsResultNew(true, xstrdup("OK"));
            
        }
    }
}
Exemple #3
0
AgentDiagnosticsResult AgentDiagnosticsCheckPrivateKey(const char *workdir)
{
    const char *path = PrivateKeyFile(workdir);
    assert(path);
    struct stat sb;

    if (stat(path, &sb) != 0)
    {
        return AgentDiagnosticsResultNew(false, StringFormat("No private key found at '%s'", path));
    }

    if (sb.st_mode != (S_IFREG | S_IWUSR | S_IRUSR))
    {
        return AgentDiagnosticsResultNew(false, StringFormat("Private key found at '%s', but had incorrect permissions '%o'", path, sb.st_mode));
    }

    return AgentDiagnosticsResultNew(true, StringFormat("OK at '%s'", path));
}
AgentDiagnosticsResult AgentDiagnosticsCheckAmPolicyServer(ARG_UNUSED const char *workdir)
{
    bool am_policy_server = GetAmPolicyHub();
    return AgentDiagnosticsResultNew(am_policy_server,
                                     am_policy_server ? xstrdup("Acting as a policy server") : xstrdup("Not acting as a policy server"));
}
AgentDiagnosticsResult AgentDiagnosticsCheckIsBootstrapped(const char *workdir)
{
    char *policy_server = ReadPolicyServerFile(workdir);
    return AgentDiagnosticsResultNew(policy_server != NULL,
                                     policy_server != NULL ? policy_server : xstrdup("Not bootstrapped"));
}