Ejemplo n.º 1
0
/*
 * snoopy_log_syscall
 *
 * Description:
 *     Log the call to one of the syscalls
 *
 * Params:
 *     syscallName:   system call name to log
 *
 * Return:
 *     void
 */
void snoopy_log_syscall (
    const char *syscallName
) {
    char *logMessage = NULL;

    /* Initialize snoopy */
    snoopy_init();

    /* Initialize empty log message */
    logMessage    = malloc(SNOOPY_LOG_MESSAGE_MAX_SIZE);
    logMessage[0] = '\0';

    /* Generate log message in specified format */
    snoopy_message_generateFromFormat(logMessage, snoopy_configuration.message_format);

#if defined(SNOOPY_FILTERING_ENABLED)
    /* Should message be passed to syslog or not? */
    if (
        (SNOOPY_FALSE == snoopy_configuration.filtering_enabled)
        ||
        (
            (SNOOPY_TRUE == snoopy_configuration.filtering_enabled)
            &&
            (SNOOPY_FILTER_PASS == snoopy_filtering_check_chain(logMessage, snoopy_configuration.filter_chain))
        )
    ) {
#endif
        snoopy_log_dispatch(logMessage, SNOOPY_LOG_MESSAGE);
#if defined(SNOOPY_FILTERING_ENABLED)
    }
#endif

    /* Housekeeping */
    free(logMessage);
    snoopy_cleanup();
}
Ejemplo n.º 2
0
int main (int argc, char **argv)
{
    char *logMessage       = NULL;

    /* Initialize snoopy */
    snoopy_init();

    /* Initialize empty log message */
    logMessage    = malloc(SNOOPY_LOG_MESSAGE_MAX_SIZE);
    logMessage[0] = '\0';

    snoopy_inputdatastorage_store_filename(argv[0]);
    snoopy_inputdatastorage_store_argv(argv);

    if (SNOOPY_TRUE == snoopy_configuration.configfile_enabled) {
        printf("Configuration file is enabled: %s\n", snoopy_configuration.configfile_path);
        if (SNOOPY_TRUE == snoopy_configuration.configfile_found) {
            printf("Configuration file found.\n");
        } else {
            printf("WARNING: Configuration file does not exist!\n");
        }
        if (SNOOPY_TRUE == snoopy_configuration.configfile_parsed) {
            printf("Configuration file was parsed sucessfully.\n");
        } else {
            printf("WARNING: Configuration file parsing FAILED!\n");
        }
    } else {
        printf("INFO: Configuration file is NOT enabled.\n");
    }

    snoopy_message_generateFromFormat(logMessage, snoopy_configuration.message_format);
    printf("Message generated:\n");
    printf("\n");
    printf("%s\n", logMessage);
    printf("\n");

#if defined(SNOOPY_FILTERING_ENABLED)
    /* Should message be passed to syslog or not? */
    if (
        (SNOOPY_FALSE == snoopy_configuration.filtering_enabled)
        ||
        (
            (SNOOPY_TRUE == snoopy_configuration.filtering_enabled)
            &&
            (SNOOPY_FILTER_PASS == snoopy_filtering_check_chain(logMessage, snoopy_configuration.filter_chain))
        )
    ) {
#endif
        snoopy_log_dispatch(logMessage, SNOOPY_LOG_MESSAGE);
        printf("Message sent to output '%s(%s)'.\n", snoopy_configuration.output, snoopy_configuration.output_arg);
        printf("If snoopy is already enabled on your system, you should see two identical messages.\n");
        printf("If you are testing snoopy via LD_PRELOAD environmental variable, you will see another identical message.\n");
#if defined(SNOOPY_FILTERING_ENABLED)
    } else {
            printf("Message NOT sent to syslog. One of the filters dropped it.\n");
    }
#endif

    /* Housekeeping */
    free(logMessage);
    snoopy_cleanup();
    return 0;
}