コード例 #1
0
ファイル: cf-key.c プロジェクト: rpoyner/core
int main(int argc, char *argv[])
{
    EvalContext *ctx = EvalContextNew();

    GenericAgentConfig *config = CheckOpts(argc, argv);
    GenericAgentConfigApply(ctx, config);

    ReportContext *report_context = OpenReports(ctx, config->agent_type);
    GenericAgentDiscoverContext(ctx, config, report_context);

    if (SHOWHOSTS)
    {
        ShowLastSeenHosts();
        return 0;
    }

    if (print_digest_arg)
    {
        return PrintDigest(print_digest_arg);
    }

    if (REMOVEKEYS)
    {
        return RemoveKeys(remove_keys_host);
    }

    if(LICENSE_INSTALL)
    {
        bool success = LicenseInstall(LICENSE_SOURCE);
        return success ? 0 : 1;
    }

    if (trust_key_arg)
    {
        return TrustKey(trust_key_arg);
    }

    char *public_key_file, *private_key_file;

    if (KEY_PATH)
    {
        xasprintf(&public_key_file, "%s.pub", KEY_PATH);
        xasprintf(&private_key_file, "%s.priv", KEY_PATH);
    }
    else
    {
        public_key_file = xstrdup(PublicKeyFile());
        private_key_file = xstrdup(PrivateKeyFile());
    }

    KeepKeyPromises(public_key_file, private_key_file);

    free(public_key_file);
    free(private_key_file);

    ReportContextDestroy(report_context);
    GenericAgentConfigDestroy(config);
    EvalContextDestroy(ctx);
    return 0;
}
コード例 #2
0
ファイル: cf-key.c プロジェクト: nickanderson/core
int main(int argc, char *argv[])
{
    SetupSignalsForCfKey(HandleSignalsForAgent);

    GenericAgentConfig *config = CheckOpts(argc, argv);
    EvalContext *ctx = EvalContextNew();
    GenericAgentConfigApply(ctx, config);

    GenericAgentDiscoverContext(ctx, config);

    if (SHOWHOSTS)
    {
        SetupSignalsForCfKey(handleShowKeysSignal);
        ShowLastSeenHosts();
        return 0;
    }

    if (print_digest_arg)
    {
        return PrintDigest(print_digest_arg);
    }

    GenericAgentPostLoadInit(ctx);

    if (REMOVEKEYS)
    {
        int status;
        if (FORCEREMOVAL)
        {
            if (!strncmp(remove_keys_host, "SHA=", 3) ||
                !strncmp(remove_keys_host, "MD5=", 3))
            {
                status = ForceKeyRemoval(remove_keys_host);
            }
            else
            {
                status = ForceIpAddressRemoval(remove_keys_host);
            }
        }
        else
        {
            status = RemoveKeys(remove_keys_host, true);
            if (status == 0 || status == 1)
            {
                Log (LOG_LEVEL_VERBOSE,
                    "Forced removal of entry '%s' was successful",
                    remove_keys_host);
                return 0;
            }
        }
        return status;
    }

    if(LICENSE_INSTALL)
    {
        bool success = LicenseInstall(LICENSE_SOURCE);
        return success ? 0 : 1;
    }

    if (trust_key_arg != NULL)
    {
        char *filename, *ipaddr, *username;
        /* We will modify the argument to --trust-key. */
        char *arg = xstrdup(trust_key_arg);

        ParseKeyArg(arg, &filename, &ipaddr, &username);

        /* Server IP address required to trust key on the client side. */
        if (ipaddr == NULL)
        {
            Log(LOG_LEVEL_NOTICE, "Establishing trust might be incomplete. "
                "For completeness, use --trust-key IPADDR:filename");
        }

        bool ret = TrustKey(filename, ipaddr, username);

        free(arg);
        return ret ? EXIT_SUCCESS : EXIT_FAILURE;
    }

    char *public_key_file, *private_key_file;

    if (KEY_PATH)
    {
        xasprintf(&public_key_file, "%s.pub", KEY_PATH);
        xasprintf(&private_key_file, "%s.priv", KEY_PATH);
    }
    else
    {
        public_key_file = PublicKeyFile(GetWorkDir());
        private_key_file = PrivateKeyFile(GetWorkDir());
    }

    bool ret = KeepKeyPromises(public_key_file, private_key_file, KEY_SIZE);

    free(public_key_file);
    free(private_key_file);

    GenericAgentFinalize(ctx, config);

    return ret ? EXIT_SUCCESS : EXIT_FAILURE;
}