Re: kill -9 again
Posted in 1994
The other way of dealing with this is to make the sqlturbo process itself immune to signals from the user. I knocked together the following sqlturbo startup program to do just that. It may be of interest. It is, of course, offered as-is. -------cut here------------- /* * sqlsafe.c - start an sqlexec or sqlturbo which is not killable * by the user. * * Author: Hugh Grierson (hugh@fujitsu.co.nz) * No warantee, etc. * * This was developed and tested on an SVR4 unix machine with Informix * SE and Online both at version 4.10. */ /* * The program works by changing the real uid of the sqlturbo process to * something other than the user's uid, preventing the user from killing * the process. The downside is that sqlturbo will then operate as that * "proxy" user, which will effect at least the following: * tables/indexes will be created as the proxy user * database/table/column privileges are evaluated for the proxy user * SELECT USER will return the proxy user's logname * * Decide for yourself if this is ok, or not. * * If your Unix doesn't handle setuid et al in the same way as my SVR4 does, * then some or all of this may not work. There is at least a runtime check * that both the real and effective uids have been set as expected. */ /* * Installation... * Edit this source and set PROXYUSER to your choice of username. * Compile. You will have to make changes for non-ansi systems. * Install the compiled program as $INFORMIXDIR/lib/sqlsafe (say) * Make it setuid-root (chown root sqlsafe; chmod 4755 sqlsafe) * Set $SQLENGINE to $INFORMIXDIR/lib/sqlturbo or sqlexec * Set $SQLEXEC to $INFORMIXDIR/lib/sqlsafe * Run isql * Run ps, notice the change from normal, and try to kill the engine. * In isql do SELECT USER FROM SYSTABLES WHERE TABID=1; and again notice * the change. */ /* * This proxy username must exist in /etc/passwd. * "root" would probably be a bad choice here. * "informix" is ok for testing, but not so good for real life. */ #define PROXYUSER "informix" #include <sys/types.h> #include <unistd.h> #include <stdlib.h> #include <stdio.h> #include <string.h> #include <pwd.h> /* The environment variable for finding the real sql engine */ #define SQLENGINE "SQLENGINE" main(int argc, char **argv) { char *sqlengine; struct passwd *pw; extern int errno; /* get name of the real sqlexec/turbo program */ if ((sqlengine = getenv(SQLENGINE)) == 0) { fprintf(stderr, "%s: $%s not set\\n", argv[0], SQLENGINE); exit(1); } /* lookup uid of the proxy user */ if ((pw = getpwnam(PROXYUSER)) == 0) { fprintf(stderr, "%s: cannot find password entry for %s\\n", argv[0], PROXYUSER); exit(1); } /* set the real and effective uid to that of the proxy user */ if (setuid(pw->pw_uid) == -1) { fprintf(stderr, "%s: setuid failed: %s\\n", argv[0], strerror(errno)); exit(1); } /* and check it, just to be sure */ if (getuid() != pw->pw_uid || geteuid() != pw->pw_uid) { fprintf(stderr, "%s: strange setuid failure\\n", argv[0]); exit(1); } /* optional, to tidy up 'ps' output */ argv[0] = sqlengine; /* start the real sql backend */ execv(sqlengine, argv); /* execv() failed! */ perror(sqlengine); exit(1); } -- Hugh Grierson hugh@fujitsu.co.nz 20C, light cloud cover