home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / sys / sun / admin / 4968 < prev    next >
Encoding:
Text File  |  1992-07-25  |  3.8 KB  |  125 lines

  1. Path: sparky!uunet!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!sdd.hp.com!elroy.jpl.nasa.gov!ucla-cs!ucla-ma!luna!zinar
  2. From: zinar@luna.math.ucla.edu (Richard Zinar)
  3. Newsgroups: comp.sys.sun.admin
  4. Subject: Setgid confusion
  5. Message-ID: <1992Jul24.210441.22667@math.ucla.edu>
  6. Date: 24 Jul 92 21:04:41 GMT
  7. Sender: news@math.ucla.edu
  8. Organization: UCLA Mathematics Department
  9. Lines: 114
  10.  
  11.  
  12. Hello ...
  13.  
  14.   We're experiencing a problem with a locally developed piece of
  15.   code which makes use of the "setuid" and "setgid" features of UNIX.
  16.   I've enclosed a program which recreates the problem.  The executable
  17.   program has the following settings:
  18.  
  19.         owner:  submit
  20.         group:  turnin
  21.         perms:  6711 (-rws--s--x)
  22.  
  23.   and is run with the current directory having:
  24.  
  25.         owner:   p10aaedh
  26.         group:   student
  27.         perms:   705 (drwx---r-x)
  28.  
  29.   The getwd() call fails, and produces the message "can't stat .", 
  30.   and the following stat () call also fails.
  31.  
  32.   The program is running on SunOS 4.1.1 on a SparcStation 2.
  33.   The program worked successfully on our old machines running SunOS 3.5,
  34.   but reviewing the documentation in "System Services Overview" didn't
  35.   shed any light on why it's no longer working.  The printed real and
  36.   effective UIDs and GIDs have the values I would expect to see, but 
  37.   it doesn't seem to affect the outcome of the getwd() call.
  38.  
  39.   The file system in which the directory passed to stat() is
  40.   located has mount options "rw,quota,grpid" (and "suid" is documented
  41.   as a default option).  Note that the program is NOT trying to access
  42.   an NFS-mounted file as root (or so I believe, anyway).
  43.  
  44. The program follows:
  45.  
  46.    #include <sys/param.h>
  47.    #include <sys/types.h>
  48.    #include <sys/stat.h>
  49.    #include <stdio.h>
  50.    #include <errno.h>
  51.    
  52.    main ()
  53.    {
  54.       char         pname[MAXPATHLEN];
  55.       struct stat statbuf;
  56.    
  57.       int  real_uid, eff_uid;
  58.       int  real_gid, eff_gid;
  59.    
  60.       extern char *getwd ();
  61.    
  62.    
  63.       real_uid = getuid ();
  64.       real_gid = getgid ();
  65.       eff_uid  = geteuid ();
  66.       eff_gid  = getegid ();
  67.    
  68.       printf ("Real uid: %d\n", real_uid);
  69.       printf ("Real gid: %d\n", real_gid);
  70.       printf ("Effective uid: %d\n", eff_uid);
  71.       printf ("Effective gid: %d\n", eff_gid);
  72.    
  73.       setgid (getegid ());
  74.       setuid (geteuid ());
  75.    
  76.       real_uid = getuid ();
  77.       real_gid = getgid ();
  78.       eff_uid  = geteuid ();
  79.       eff_gid  = getegid ();
  80.    
  81.       printf ("Real uid: %d\n", real_uid);
  82.       printf ("Real gid: %d\n", real_gid);
  83.       printf ("Effective uid: %d\n", eff_uid);
  84.       printf ("Effective gid: %d\n", eff_gid);
  85.    
  86.       if ( getwd (pname) == (char *) 0 )
  87.          printf ("Error: %s\n", pname);
  88.       else
  89.          printf ("Current directory: %s\n", pname);
  90.    
  91.       if ( stat (".", &statbuf) != 0 )
  92.          perror ("Stat call failed");
  93.       else  {
  94.          printf ("Current directory's uid: %d\n", statbuf.st_uid);
  95.          printf ("Current directory's gid: %d\n", statbuf.st_gid);
  96.       }
  97.    
  98.       exit (0);
  99.    }
  100.  
  101.  
  102. The  program output is as follows:
  103.  
  104.    Real uid: 3145
  105.    Real gid: 20
  106.    Effective uid: 56
  107.    Effective gid: 22
  108.    Real uid: 56
  109.    Real gid: 22
  110.    Effective uid: 56
  111.    Effective gid: 22
  112.    Error: getwd: can't stat .
  113.    Stat call failed: Permission denied
  114.  
  115.    In an edited version of the above test program, I used the getgroups()
  116.    system call to check the supplementary group ID(s) after the setuid and
  117.    setgid calls had been made, and found that it contained only
  118.    gid 20 (student), and not gid 22 (turnin), which seemed surprising.
  119.    Any insights into this behaviour would be greatly appreciated ...
  120.  
  121.                            Richard Zinar
  122.                                       Computing Support Staff
  123.                                       UCLA Mathematics Department
  124.                                       Email: zinar@math.ucla.edu
  125.