secure_log_file.c

final_realms_fluffos_v1/lib/secure/simul_efun/secure_log_file.c · 589 B

From the archive final_realms_fluffos_v1.zip

Download the archive   « Back to the archive contents

// Originally done by Aragorn
// Tweaked by Radix
#define MAX_LOG_SIZE 200000
#define SECURE_LOG_DIR "/secure/log/"
void secure_log_file( string file, string text )
{
    if( !stringp( file ) || !stringp( text ) ) return; // syntax error
    if( -1 != strsrch( file, ".." ) ) return; // security error
    if( -1 != strsrch( file, "/" ) ) return; // security error
    file = SECURE_LOG_DIR + file; // would 'sprintf' be much better here?
   seteuid("Root");
    if( file_size( file ) > MAX_LOG_SIZE )
        rename( file, file + ".old" );
    write_file( file, text );
   seteuid(0);
}

Site Stats

Snippets: 1791
Codebases: 571