dudek (09/28/82)
It has not proven practical to set up a grecial group here for maintaining the empire game (sorry - empire world). As a result, I have had to install the game set user-id and make the files 700 mode. As a result of this, people who gets ranaway empire processes are unable to kill them themselves (this seems to happen when a plane crashes, for one). In order to help people kill these processes, I've set up a program to allow people to kill empire processes themselves. Naturally, this program is set user-id. In case anybody else has had this problem, I am enclosing the program source. The main program must be set user-id, and I suggest the rest be unreadable to avoid attempts at nastiness. It works my making sure that the parent process-id is the same as the user-id of the person who is doing the kill, or the praent is init (in case the user logged off in desperation, and the parent is thus non-existent). I know it's messy, but at least it gets the job done. Greg Dudek -----empkill.c this is what you run --- make it 6755 mode ------- main(argc, argv) char **argv; { execl("/bin/sh","/bin/sh","/usr/src/games/psl/EMP/empkill.sh",argv[1],0); write(2, "Can't run\n", 10); exit(); } ----empkill.sh ---- this is the shell file to do the work -------- if test x$1 = x then echo "Usage: empkill empire-process-id" echo "You must be the real owner." exit fi : 'This is the directory for temp files. It should NOT be generally' : 'writable or nastly people may try replacing the file while' : 'empkill is running to kill others empires empf=/usr/src/games/psl/EMP : 'Cleanup if the user hits a interrupt, etc.' trap "/bin/rm -f $empf/kill$$ $empf/killid$$ $empf/dokill$$" 1 2 3 echo "This is slow" : 'a "ps -lax" is necessary' : 'Get the data on parents, etc.' /bin/ps lax > $empf/kill$$ : 'The line beginning with "setup" has the real user-id of the invoker on it' : 'in the format: "setup process-id-to-kill invoking-user-id' /bin/echo "setup: $1 `/u2/dudek/bin/uid`" > $empf/killid$$ : 'The awk script will print the actions to be taken, if it' : ' validates the user. i.e. it emits somewhing like "kill -9 32456"' /bin/awk -f $empf/empkill.awk $empf/killid$$ $empf/kill$$ $empf/kill$$ > $empf/dokill$$ /bin/sh $empf/dokill$$ /bin/rm -f $empf/kill$$ $empf/killid$$ $empf/dokill$$ ------empkill.awk --- this awk script is the workhorse ------fix the log file to be whatever you like: near the end. BEGIN { parent=999; PID=3; PPID=4; UID=2 } # base awk script for empkill program. # the line starting with "setup" has the target process-id # and the invoking user-id on it. /^setup:/ { killeeid = $2; killeruid = $3; print "/bin/echo process is ", killeeid," user is ",killeruid if (killeruid == "") exit print "/bin/echo Kill empire process ",killeeid print "/bin/echo this takes about 200 sec. -sleep time." } # lines beginning with numbers are data lines from the "ps" # they have the format: number EFFECT-UID PROC-ID PARENT-PROC-ID more stuff" # This scan should match the file on the first run through. # It gets the parent process-id to be used in next match. /[09]/ { # process entry - find parent process id. # if parent is 1 (init), parent is dead. Allow kill. if ( killeeid == $PID ) { parent = $PPID if (parent == 1) killeruid = 0 } } # This pattern again matches data lines from the "ps". # It may do nothing on the first pass through the file since the # parent entry, set above, must be found first, and it usually appears # before the actual process. /[09]/ { # on second pass, if parent was right user, kill the process if ( parent == $PID ) if ( $UID == killeruid ) { printf "/bin/kill -3 %d;/usr/bin/sleep 30;/bin/kill -1 %d;/usr/bin/sleep 30;/bin/kill -9 %d\n",killeeid,killeeid,killeeid } if ( parent == $PID ) if ( $UID != killeruid ) { # THE FOLLOWING FILE NAME IS A SYSTEM # DEPENDENT PARAMETER !!!!! printf "/bin/echo Bad kill on %d by %d >> /scr/ekills",killeeid,killeruid print "/bin/echo Bad Kill: Usage is empkill processid" } } -----------end of empkill sources.