home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright 1989, 1990, John F. Haugh II
- * All rights reserved.
- *
- * Use, duplication, and disclosure prohibited without
- * the express written permission of the author.
- */
-
- #include <sys/types.h>
- #include <pwd.h>
- #include <utmp.h>
- #ifndef BSD
- #include <string.h>
- #include <memory.h>
- #else
- #include <strings.h>
- #define strchr index
- #define strrchr rindex
- #endif
- #include "config.h"
-
- #ifndef lint
- static char _sccsid[] = "@(#)setup.c 2.2 19:24:10 7/29/90";
- #endif
-
- extern char home[];
- extern char prog[];
- extern char name[];
- extern char mail[];
-
- #ifndef PATH
- #define PATH ":/bin:/usr/bin"
- #endif
-
- #ifndef SUPATH
- #define SUPATH ":/bin:/usr/bin:/etc"
- #endif
-
- #ifndef MAILDIR
- #define MAILDIR "/usr/spool/mail"
- #endif
-
- #ifndef TTYPERM
- #define TTYPERM 0622
- #endif
-
- #ifndef SU
- extern struct utmp utent;
- #endif
-
- #ifdef QUOTAS
- long strtol ();
- #ifdef ULIMIT
- long ulimit ();
- #endif
- #endif
-
- void addenv ();
-
- void setup (info)
- struct passwd *info;
- {
- extern int errno;
- char logname[30];
- #ifndef SU
- char tty[30];
- #endif
- char *cp;
- int i;
- long l;
-
- #ifndef SU
- (void) strcat (strcpy (tty, "/dev/"), utent.ut_line);
- if (chown (tty, info->pw_uid, info->pw_gid) ||
- chmod (tty, TTYPERM))
- perror (tty);
- #endif
- if (chdir (info->pw_dir) == -1) {
- (void) printf ("Unable to change directory to \"%s\"\n", info->pw_dir);
- exit (errno);
- }
- #ifdef QUOTAS
- for (cp = info->pw_gecos;cp != (char *) 0;cp = strchr (cp, ',')) {
- if (*cp == ',')
- cp++;
-
- if (strncmp (cp, "pri=", 4) == 0) {
- i = atoi (cp + 4);
- if (i >= -20 && i <= 20)
- (void) nice (i);
-
- continue;
- }
- #ifdef ULIMIT
- if (strncmp (cp, "ulimit=", 7) == 0) {
- l = strtol (cp + 7, (char **) 0, 10);
- (void) ulimit (2, l);
-
- continue;
- }
- #endif
- if (strncmp (cp, "umask=", 6) == 0) {
- i = strtol (cp + 6, (char **) 0, 8) & 0777;
- (void) umask (i);
-
- continue;
- }
- }
- #endif
- if (setgid (info->pw_gid) == -1) {
- puts ("Bad group id");
- exit (errno);
- }
- #ifndef BSD
- if (setuid (info->pw_uid))
- #else
- if (setreuid (info->pw_uid, info->pw_uid))
- #endif
- {
- puts ("Bad user id");
- exit (errno);
- }
- (void) strcat (strcpy (home, "HOME="), info->pw_dir);
- addenv (home);
-
- if (info->pw_shell == (char *) 0)
- info->pw_shell = "/bin/sh";
-
- (void) strcat (strcpy (prog, "SHELL="), info->pw_shell);
- addenv (prog);
-
- if (info->pw_uid == 0)
- addenv (SUPATH);
- else
- addenv (PATH);
-
- (void) strcat (strcpy (logname, "LOGNAME="), name);
- addenv (logname);
-
- (void) strcat (strcat (strcpy (mail, "MAIL="), MAILDIR), name);
- addenv (mail);
- }
-