home *** CD-ROM | disk | FTP | other *** search
- #ifdef RCSID
- static char *RCSid =
- "$Header: osh.c,v 6.2 89/02/23 00:24:21 aespinei Exp $ osh.c Copyr (c) 1986 Oracle";
- #endif /* RCSID */
-
- /*
- ** Copyright (c) 1986 by Oracle Corporation
- **
- ** osh - Routine to modify a user's ulimit
- **
- ** Under UNIX the largest negating factor for large database is
- ** the process's "ulimit" parameter. Currently this only can be reset
- ** by the "super-user". This program needs to be run with the ownership
- ** of root and the "set uid" bit 'on'. The recommended mode of this program
- ** 4711 (-rws--x--x) which only allows this program to be "executed" but
- ** not copied. It raises the ulimit to a theoretical maximum and then
- ** "exec's" the shell specified in its name. "osh" will exec "sh", "ocsh"
- ** will exec "csh", etc. If the program is run by anybody other than the
- ** super-user, it automatically resets the program's uid to that of the
- ** person executing "osh" so as not to leave the user with unauthorized
- ** privelages.
- **
- ** PLEASE NOTE: Any program with a set uid bit set is a POTENTIAL security
- ** problem and needs to be carefully controlled.
- **
- ** Written:
- ** 11/01/84 Abbajay
- ** Modified:
- ** 07/20/86 Abbajay - Added optional "SHELL" variable lookup.
- ** 02/22/89 Andres - Added -l flag to print current ulimit.
- **
- ** Compile: cc -O osh.c -o osh
- ** Install: with set uid root (4711)
- */
-
- #include <stdio.h>
- #include <errno.h>
-
- #define NEWLIMIT 2113674 /* define newlimit for upping ulimit */
- #define DEFAULT_SHELL "/bin/sh" /* define deault shell */
-
- char *getenv();
-
- main(argc, argv, envp)
- int argc;
- char **argv;
- char **envp;
-
- {
- register char *cmd; /* command to execute */
- register long newlimit=NEWLIMIT; /* define newlimit for upping ulimit */
- char *shell;
- register int i;
- char *nargv[4096];
- long ulimit(), oldlimit;
-
- if((argc >= 1) && (strcmp(argv[1],"-l") == 0))
- {
- if ( (oldlimit = ulimit(1)) == -1)
- {
- fprintf(stderr, "%s: Couldn't get process ulimit.\n",argv[0]);
- exit(-1);
- } else {
- printf("%d\n",oldlimit);
- exit(0);
- }
- }
-
- if(ulimit(2, newlimit) == -1)
- {
- if (errno == EPERM)
- fprintf(stderr, "%s: Can't raise ulimit. Probably not 'suid root'.\n",
- argv[0]);
- else
- perror(argv[0]);
- exit(-1);
- }
- if(setuid(getuid())) /* set uid back to original */
- {
- perror(argv[0]);
- exit(-1);
- }
- if (argc == 1)
- {
- shell = nargv[0] = (nargv[0] = getenv("SHELL")) ? nargv[0] : DEFAULT_SHELL;
- nargv[1] = NULL;
- if (execve(shell, nargv, envp))
- {
- perror(argv[0]);
- exit(-1);
- }
- }
- else
- {
- i=1;
- while (argv[i] != NULL) {
- nargv[i-1] = argv[i];
- i++;
- }
- nargv[i]=NULL;
- if (execvp(nargv[0], nargv))
- {
- if (errno != ENOTTY) /* abort on any other error */
- {
- perror(argv[0]);
- exit(-1);
- }
- }
- }
- exit(0);
- }
- /* END PROGRAM */
-