/* * SPDsoft 1996 * Sun Sep 29 01:58:29 DST 1996 * * User shutdown from command line console */ #include #include #include #include #include #include #define PATH_SEP '/' #ifdef _TEST_ # define LOCK_F "allow.die" #else # define LOCK_F "/etc/allow.die" #endif #define TEXT1 "\ Por favor, asegurese antes de que no hay procesos importantes corriendo\n\ \n\ Que esta usted haciendo, Dave?\n\ \n\ Esta seguro de que desea apagar esta maquina [Si/No]? " #define TEXT2 "\ SE HA INICIADO EL PROCESO DE APAGADO. DISPONE DE 1 MINUTO PARA\n\ CANCELARLO PULSANDO ctrl-C\n\ \n\ No quiero morir!!!!\n" char *app; int main(int argc, char **argv, char **envp); void usage(void); void usage(void) { fprintf(stderr,"Use: %s\n", app); exit(0); } int main(int argc, char **argv, char **envp) { register char **p1, **p2; struct stat sbp; char *tty; char answer[3]; int p; char *cmd[] = { #ifdef _TEST_ /* "/sbin/echo",*/ "/usr/ucb/echo", #endif "/usr/sbin/shutdown","-y","-g60","-i5", "shutdown by user", NULL }; int opt; extern char *optarg; extern int optind,opterr; if ((app = strrchr(argv[0], PATH_SEP)) != NULL) app = app+1; else app = argv[0]; if ( argc != 1 ) usage(); if(0!=stat(LOCK_F,&sbp)) { fprintf(stderr, "%s: Sorry, %s locked by root. Try again later\n", app, app); exit(EACCES); } for(p1 = p2 = envp; *p1; p1++) { if (strncmp(*p1, "LD_", 3) != 0 && strncmp(*p1, "_RLD", 4) != 0 && strncmp(*p1, "LIBPATH=", 8) != 0 && strncmp(*p1, "ELF_LD_", 7) != 0 && strncmp(*p1, "AOUT_LD_", 8) != 0 && strncmp(*p1, "IFS=", 4) != 0 ) { *p2++ = *p1; } } *p2 = 0; if ( NULL == (tty = ttyname(0))) { fprintf(stderr, "%s: ttyname: %s\n", app, strerror(errno)); exit(2); } if ( 0 != strcmp( tty, "/dev/console" )) { fprintf(stderr, "%s: error: you are not on system console (%s)\n", app, tty); #ifndef _TEST_ exit(3); #endif } if( 0 != setuid((uid_t) 0)) { fprintf(stderr, "%s: setuid failed (%s)\n", app, strerror(errno)); #ifndef _TEST_ exit(4); #endif } fprintf(stdout, TEXT1); fflush(stdout); fread(answer, sizeof(char), sizeof(answer), stdin); if ( 0!= strncmp(answer,"Si",2)) exit(0); fprintf(stdout, TEXT2); fflush(stdout); execve( cmd[0], cmd, p2 ); perror("execve"); exit(5); }