Beispiel #1
0
/* Send integrity checking information about a file to the server */
int intcheck_file(const char *file_name, const char *dir)
{
    struct stat statbuf;
    os_md5 mf_sum;
    os_sha1 sf_sum;
    char newsum[912 + 1];

    newsum[0] = '\0';
    newsum[912] = '\0';

    /* Stat the file */
#ifdef WIN32
    if (stat(file_name, &statbuf) < 0)
#else
    if (lstat(file_name, &statbuf) < 0)
#endif
    {
        snprintf(newsum, 911, "%c:%s:-1 %s%s", SYSCHECK_MQ, SYSCHECK,
                 dir, file_name);
        send_msg(0, newsum);

        return (1);
    }

    /* Generate new checksum */
#ifdef WIN32
    if (S_ISREG(statbuf.st_mode))
#else
    if (S_ISREG(statbuf.st_mode) || S_ISLNK(statbuf.st_mode))
#endif
    {
        /* Generate SHA-1 of the file */
        if (OS_SHA1_File(file_name, sf_sum, OS_TEXT) < 0) {
            strncpy(sf_sum, "xxx", 4);
        }

        /* Generate MD5 of the file */
        if (OS_MD5_File(file_name, mf_sum, OS_TEXT) < 0) {
            strncpy(mf_sum, "xxx", 4);
        }
    }

    snprintf(newsum, 911, "%c:%s:%d:%d:%d:%d:%s:%s %s%s",
             SYSCHECK_MQ, SYSCHECK,
             (int)statbuf.st_size,
             (int)statbuf.st_mode,
             (int)statbuf.st_uid,
             (int)statbuf.st_gid,
             mf_sum,
             sf_sum, dir, file_name);

    send_msg(0, newsum);
    return (1);
}
Beispiel #2
0
/* make main to compile (after the make md5)
 * Example of the md5 API use
 * Daniel B. Cid, [email protected]
 */
int main(int argc, char ** argv)
{
    os_sha1 filesum;

    if(argc < 2)
        usage(argv);
   
    
    if(OS_SHA1_File(argv[1], filesum) == 0)
    {
        printf("SHA1Sum for \"%s\" is: %s\n",argv[1],filesum);
    }
    else
    {
        printf("SHA1Sum for \"%s\" failed\n", argv[1]);
    }
    return(0);
}
Beispiel #3
0
/* Signs a log file */
void OS_SignLog(const char *logfile, const char *logfile_old, int log_missing)
{
    os_md5 mf_sum;
    os_md5 mf_sum_old;

    os_sha1 sf_sum;
    os_sha1 sf_sum_old;

    char logfilesum[OS_FLSIZE +1];
    char logfilesum_old[OS_FLSIZE +1];

    FILE *fp;


    /* Clearing the memory */
    memset(logfilesum, '\0', OS_FLSIZE +1);
    memset(logfilesum_old, '\0', OS_FLSIZE +1);


    /* Setting the umask */
    umask(0027);


    /* Creating the checksum file names */
    snprintf(logfilesum, OS_FLSIZE, "%s.sum", logfile);
    snprintf(logfilesum_old, OS_FLSIZE, "%s.sum", logfile_old);


    /* generating md5 of the old file */
    if(OS_MD5_File(logfilesum_old, mf_sum_old) < 0)
    {
        merror("%s: No previous md5 checksum found: '%s'. "
               "Starting over.", ARGV0, logfilesum_old);
        strncpy(mf_sum_old, "none", 6);
    }

    /* generating sha1 of the old file.  */
    if(OS_SHA1_File(logfilesum_old, sf_sum_old) < 0)
    {
        merror("%s: No previous sha1 checksum found: '%s'. "
               "Starting over.", ARGV0, logfilesum_old);
        strncpy(sf_sum_old, "none", 6);
    }


    /* Generating md5 of the current file */
    if(OS_MD5_File(logfile, mf_sum) < 0)
    {
        if(log_missing)
            merror("%s: File '%s' not found. MD5 checksum skipped.",
                                         ARGV0, logfile);
        strncpy(mf_sum, "none", 6);
    }

    /* Generating sha1 of the current file */
    if(OS_SHA1_File(logfile, sf_sum) < 0)
    {
        if(log_missing)
            merror("%s: File '%s' not found. SHA1 checksum skipped.",
                                        ARGV0, logfile);
        strncpy(sf_sum, "none", 6);
    }


    fp = fopen(logfilesum, "w");
    if(!fp)
    {
        merror(FOPEN_ERROR, ARGV0, logfilesum, errno, strerror(errno));
        return;
    }


    fprintf(fp, "Current checksum:\n");
    fprintf(fp, "MD5  (%s) = %s\n", logfile, mf_sum);
    fprintf(fp, "SHA1 (%s) = %s\n\n", logfile, sf_sum);

    fprintf(fp, "Chained checksum:\n");
    fprintf(fp, "MD5  (%s) = %s\n", logfilesum_old, mf_sum_old);
    fprintf(fp, "SHA1 (%s) = %s\n\n", logfilesum_old, sf_sum_old);
    fclose(fp);

    return;
}