home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 3 / 3349 / sub.c < prev   
Encoding:
C/C++ Source or Header  |  1991-05-17  |  1.5 KB  |  59 lines

  1. /*
  2.  * Copyright 1989, 1990, John F. Haugh II
  3.  * All rights reserved.
  4.  *
  5.  * Permission is granted to copy and create derivative works for any
  6.  * non-commercial purpose, provided this copyright notice is preserved
  7.  * in all copies of source code, or included in human readable form
  8.  * and conspicuously displayed on all copies of object code or
  9.  * distribution media.
  10.  */
  11.  
  12. #include <sys/types.h>
  13. #include <syslog.h>
  14.  
  15. #include "pwd.h"
  16.  
  17. #ifndef    lint
  18. static    char    sccsid[] = "@(#)sub.c    3.2    08:22:12    1/30/91";
  19. #endif
  20.  
  21. #define    BAD_SUBROOT    "Invalid root directory \"%s\"\n"
  22. #define    BAD_SUBROOT2    "invalid root `%s' for user `%s'\n"
  23. #define    NO_SUBROOT    "Can't change root directory to \"%s\"\n"
  24. #define    NO_SUBROOT2    "no subsystem root `%s' for user `%s'\n"
  25.  
  26. /*
  27.  * subsystem - change to subsystem root
  28.  *
  29.  *    A subsystem login is indicated by the presense of a "*" as
  30.  *    the first character of the login shell.  The given home
  31.  *    directory will be used as the root of a new filesystem which
  32.  *    the user is actually logged into.
  33.  */
  34.  
  35. void    subsystem (pw)
  36. struct    passwd    *pw;
  37. {
  38.     /*
  39.      * The new root directory must begin with a "/" character.
  40.      */
  41.  
  42.     if (pw->pw_dir[0] != '/') {
  43.         printf (BAD_SUBROOT, pw->pw_dir);
  44.         syslog (LOG_WARN, BAD_SUBROOT2, pw->pw_dir, pw->pw_name);
  45.         exit (1);
  46.     }
  47.  
  48.     /*
  49.      * The directory must be accessible and the current process
  50.      * must be able to change into it.
  51.      */
  52.  
  53.     if (chdir (pw->pw_dir) || chroot (pw->pw_dir)) {
  54.         printf (NO_SUBROOT, pw->pw_dir);
  55.         syslog (LOG_WARN, NO_SUBROOT2, pw->pw_dir, pw->pw_name);
  56.         exit (1);
  57.     }
  58. }
  59.