home *** CD-ROM | disk | FTP | other *** search
/ Serving the Web / ServingTheWeb1995.disc1of1.iso / linux / slacksrce / contrib / samba / samba-1.8 / samba-1 / samba-1.8.05 / smbrun.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-27  |  1.7 KB  |  76 lines

  1. /* 
  2.    Unix SMB/Netbios implementation.
  3.    Version 1.8.
  4.    Copyright (C) Andrew Tridgell 1992,1993,1994
  5.    
  6.    This program is free software; you can redistribute it and/or modify
  7.    it under the terms of the GNU General Public License as published by
  8.    the Free Software Foundation; either version 2 of the License, or
  9.    (at your option) any later version.
  10.    
  11.    This program is distributed in the hope that it will be useful,
  12.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.    GNU General Public License for more details.
  15.    
  16.    You should have received a copy of the GNU General Public License
  17.    along with this program; if not, write to the Free Software
  18.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19. */
  20.  
  21. #include "includes.h"
  22.  
  23. /*
  24. This is a wrapper around the system call to allow commands to run correctly 
  25. as non root from a program which is switching between root and non-root 
  26.  
  27. It takes one argument as argv[1] and runs it after becoming a non-root
  28. user
  29. */
  30. int main(int argc,char *argv[])
  31. {
  32.   close(0);
  33.   close(1);
  34.   close(2);
  35.  
  36.   if (getuid() != geteuid())
  37.     {
  38.       int uid,gid;
  39.       
  40.       if (getuid() < geteuid())
  41.     uid = geteuid();
  42.       else
  43.     uid = getuid();
  44.       
  45.       if (getgid() < getegid())
  46.     gid = getegid();
  47.       else
  48.     gid = getgid();
  49.       
  50. #ifdef USE_SETRES
  51.       setresgid(0,0,0);
  52.       setresuid(0,0,0);
  53.       setresgid(gid,gid,gid);
  54.       setresuid(uid,uid,uid);      
  55. #else      
  56.       setuid(0);
  57.       seteuid(0);
  58.       setgid(gid);
  59.       setegid(gid);
  60.       setuid(uid);
  61.       seteuid(uid);
  62. #endif
  63.  
  64.       if (getuid() != uid)
  65.     return(3);
  66.     }
  67.  
  68.   if (geteuid() != getuid())
  69.     return(1);
  70.  
  71.   if (argc < 2)
  72.     return(2);
  73.  
  74.   return(system(argv[1]));
  75. }
  76.