Exemple #1
0
void prelude_start(char *profile, int argc, char **argv)
{
    int ret;
    prelude_client = NULL;

    ret = prelude_init(&argc, argv);
    if (ret < 0) {
        merror("%s: %s: Unable to initialize the Prelude library: %s.",
               ARGV0, prelude_strsource(ret), prelude_strerror(ret));
        return;
    }

    ret = prelude_client_new(&prelude_client,
                             profile != NULL ? profile : DEFAULT_ANALYZER_NAME);
    if (!prelude_client) {
        merror("%s: %s: Unable to create a prelude client object: %s.",
               ARGV0, prelude_strsource(ret), prelude_strerror(ret));

        return;
    }

    ret = setup_analyzer(prelude_client_get_analyzer(prelude_client));
    if (ret < 0) {
        merror("%s: %s: Unable to setup analyzer: %s",
               ARGV0, prelude_strsource(ret), prelude_strerror(ret));

        prelude_client_destroy(prelude_client,
                               PRELUDE_CLIENT_EXIT_STATUS_FAILURE);

        return;
    }

    ret = prelude_client_set_flags(prelude_client,
                                   prelude_client_get_flags(prelude_client)
                                   | PRELUDE_CLIENT_FLAGS_ASYNC_TIMER);
    if (ret < 0) {
        merror("%s: %s: Unable to set prelude client flags: %s.",
               ARGV0, prelude_strsource(ret), prelude_strerror(ret));
    }

    /* Set uid and gid of ossec */
    prelude_client_profile_set_uid(prelude_client_get_profile(prelude_client),
                                   Privsep_GetUser(USER));
    prelude_client_profile_set_gid(prelude_client_get_profile(prelude_client),
                                   Privsep_GetGroup(GROUPGLOBAL));

    ret = prelude_client_start(prelude_client);
    if (ret < 0) {
        merror("%s: %s: Unable to initialize prelude client: %s.",
               ARGV0, prelude_strsource(ret), prelude_strerror(ret));

        prelude_client_destroy(prelude_client,
                               PRELUDE_CLIENT_EXIT_STATUS_FAILURE);

        return;
    }

    return;
}
int prelude_initialize_client(const char *analyzer_name){
    int ret;

    prelude_client = NULL;

    ret = prelude_init(0, NULL);
    if ( ret < 0 )  {
        logg("Unable to initialize the prelude library : %s", prelude_strerror(ret));
        return -1;
    }


    ret = prelude_client_new(&prelude_client, analyzer_name);
    if ( ret < 0 )  {
        logg("Unable to create a prelude client object : %s", prelude_strerror(ret));
        return -1;
    }

    ret = idmef_analyzer_setup(prelude_client_get_analyzer(prelude_client), analyzer_name);
    if ( ret < 0 )  {
        logg("%s", prelude_strerror(ret));
        return -1;
    }

    ret = prelude_client_start(prelude_client);
    if ( ret < 0 || ! prelude_client ) {
        logg("Unable to start prelude client : %s", prelude_strerror(ret));
        prelude_client_destroy(prelude_client, PRELUDE_CLIENT_EXIT_STATUS_SUCCESS);
        return -1;
    }

    ret = prelude_client_set_flags(prelude_client, PRELUDE_CLIENT_FLAGS_ASYNC_SEND|PRELUDE_CLIENT_FLAGS_ASYNC_TIMER);
    if ( ret < 0) {
        logg("Unable to send asynchrnous send and timer : %s", prelude_strerror(ret));
        prelude_client_destroy(prelude_client, PRELUDE_CLIENT_EXIT_STATUS_SUCCESS);
        return -1;
    }

    return 0;
}
Exemple #3
0
Client::Client(const std::string& profile, const std::string& config, int permission)
{
  if ( prelude_client_new(&client_, profile.c_str()) < 0 )
      throw Exception(SYSTEM_SAVE_LOCATION, "Cannot create prelude client.");

  if ( prelude_client_set_config_filename(client_, config.c_str()) < 0 )
    throw Exception(SYSTEM_SAVE_LOCATION, "Error reading prelude config file " + config);

  prelude_client_set_required_permission(client_, (prelude_connection_permission_t) permission);

  const prelude_client_flags_t flags=static_cast<prelude_client_flags_t>(prelude_client_get_flags(client_) | PRELUDE_CLIENT_FLAGS_ASYNC_TIMER);
  if ( prelude_client_set_flags(client_, flags) < 0 )
    throw Exception(SYSTEM_SAVE_LOCATION, "Cannot set ASYNC TIMER.");

  prelude_client_profile_set_uid(prelude_client_get_profile(client_),getuid());
  prelude_client_profile_set_gid(prelude_client_get_profile(client_),getgid());

  if ( prelude_client_init(client_) < 0 )
    throw Exception(SYSTEM_SAVE_LOCATION, "Cannot initialize prelude client.");

  if ( prelude_client_start(client_) < 0 )
    throw Exception(SYSTEM_SAVE_LOCATION, "Cannot start prelude client.");
}