"); html_( mes ); html_( mes1 ); html( mes2 ); html("
"); cgi_var_output(); html(""); html(""); } void execute( char file[], char user[], char *argv[], char *env[] ) { const int RUN_FOR = 20; char prog[255]; prog[0] = '\0'; strcat( prog, "~" ); strcat( prog, user ); strcat( prog, "/public_html/" ); char *path = map_uname( prog ); chdir( path ); // ~user/public_html/ pid_t pid = fork(); if ( pid == 0 ) { strcat( path, "cgi-bin/" ); strcat( path, file ); alarm( RUN_FOR ); execve( path, argv, env ); // prog cgi_error( "File not readable [", path, "]" ); } else { close(0); close(1); close(2); pid_t pid2 = fork(); if ( pid2 == 0 ) { sleep( RUN_FOR + 2 ); kill( pid, 9 ); // Hand of GOD } else { // Just die } } } char* map_uname( char *path ) { #ifndef NO_MAP if ( path[0] == '~' ) { char uname[255]; // Holds user name char *rest = &path[1]; // omit ~ char *p = &uname[0]; // user while ( *rest != '/' && *rest != '\0' ) { *p++ = *rest++; } *p = '\0'; // Terminator char *root = uname; // If fails passwd *pw = getpwnam( uname ); // Structure about user if ( pw != NULL ) { root = pw->pw_dir; // Users home directory } int len_root = strlen(root); int len_path = len_root + strlen(rest); char *new_path = new char[len_path+1]; // Dynamic string strcpy( &new_path[0], root ); // abs user path strcpy( &new_path[len_root], rest ); // remainder return new_path; } else { return path; } #endif return path; }