home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume38 / shadow / part13 / sub.c < prev    next >
C/C++ Source or Header  |  1993-08-14  |  2KB  |  73 lines

  1. /*
  2.  * Copyright 1989, 1990, 1991, 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 "config.h"
  14.  
  15. #ifdef    USE_SYSLOG
  16. #include <syslog.h>
  17.  
  18. #ifndef    LOG_WARN
  19. #define    LOG_WARN    LOG_WARNING
  20. #endif
  21. #endif
  22.  
  23. #include "pwd.h"
  24.  
  25. #ifndef    lint
  26. static    char    sccsid[] = "@(#)sub.c    3.3    09:08:19    28 May 1991";
  27. #endif
  28.  
  29. #define    BAD_SUBROOT    "Invalid root directory \"%s\"\n"
  30. #define    BAD_SUBROOT2    "invalid root `%s' for user `%s'\n"
  31. #define    NO_SUBROOT    "Can't change root directory to \"%s\"\n"
  32. #define    NO_SUBROOT2    "no subsystem root `%s' for user `%s'\n"
  33.  
  34. /*
  35.  * subsystem - change to subsystem root
  36.  *
  37.  *    A subsystem login is indicated by the presense of a "*" as
  38.  *    the first character of the login shell.  The given home
  39.  *    directory will be used as the root of a new filesystem which
  40.  *    the user is actually logged into.
  41.  */
  42.  
  43. void    subsystem (pw)
  44. struct    passwd    *pw;
  45. {
  46.     /*
  47.      * The new root directory must begin with a "/" character.
  48.      */
  49.  
  50.     if (pw->pw_dir[0] != '/') {
  51.         printf (BAD_SUBROOT, pw->pw_dir);
  52. #ifdef    USE_SYSLOG
  53.         syslog (LOG_WARN, BAD_SUBROOT2, pw->pw_dir, pw->pw_name);
  54.         closelog ();
  55. #endif
  56.         exit (1);
  57.     }
  58.  
  59.     /*
  60.      * The directory must be accessible and the current process
  61.      * must be able to change into it.
  62.      */
  63.  
  64.     if (chdir (pw->pw_dir) || chroot (pw->pw_dir)) {
  65.         printf (NO_SUBROOT, pw->pw_dir);
  66. #ifdef    USE_SYSLOG
  67.         syslog (LOG_WARN, NO_SUBROOT2, pw->pw_dir, pw->pw_name);
  68.         closelog ();
  69. #endif
  70.         exit (1);
  71.     }
  72. }
  73.