vshost-util-vserver

Build script and sources for util-vserver.
git clone https://ccx.te2000.cz/git/vshost-util-vserver
Log | Files | Refs

rpm-fake-test.c (1994B)


      1 // $Id$    --*- c -*--
      2 
      3 // Copyright (C) 2003 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
      4 //  
      5 // This program is free software; you can redistribute it and/or modify
      6 // it under the terms of the GNU General Public License as published by
      7 // the Free Software Foundation; version 2 of the License.
      8 //  
      9 // This program is distributed in the hope that it will be useful,
     10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
     11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     12 // GNU General Public License for more details.
     13 //  
     14 // You should have received a copy of the GNU General Public License
     15 // along with this program; if not, write to the Free Software
     16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
     17 
     18 
     19 #ifdef HAVE_CONFIG_H
     20 #  include <config.h>
     21 #endif
     22 
     23 
     24 #include <grp.h>
     25 #include <pwd.h>
     26 #include <unistd.h>
     27 #include <stdbool.h>
     28 #include <stdlib.h>
     29 #include <stdio.h>
     30 #include <string.h>
     31 
     32 #define ENSC_WRAPPERS_UNISTD	1
     33 #include <wrappers.h>
     34 
     35 int wrapper_exit_code = 1;
     36 
     37 int main(/*int argc, char *argv[]*/)
     38 {
     39   char		buf[1000];
     40 
     41   while (true) {
     42     char	*ptr = buf;
     43     char	c;
     44     do {
     45       if (read(0, &c, 1)==0) break;
     46       if (c=='\n') break;
     47       *ptr++ = c;
     48     } while (ptr<buf+sizeof(buf));
     49     *ptr = '\0';
     50     if (ptr==buf) break;
     51 
     52     switch (buf[0]) {
     53       case 'P'		: {
     54 	struct passwd	*pw;
     55 	
     56 	pw = getpwnam(buf+1);
     57 	printf("P(%s) = ", buf+1);
     58 	if (pw) printf("%u\n", pw->pw_uid);
     59 	else    printf("(null)\n");
     60 	
     61 	break;
     62       }
     63 
     64       case 'G'		: {
     65 	struct group	*gr;
     66 	
     67 	gr = getgrnam(buf+1);
     68 	printf("G(%s) = ", buf+1);
     69 	if (gr) printf("%u\n", gr->gr_gid);
     70 	else    printf("(null)\n");
     71 	
     72 	break;
     73       }
     74 
     75       case 'C'		:
     76 	switch (buf[1]) {
     77 	  case 'g'	:  endgrent(); break;
     78 	  case 'p'	:  endpwent(); break;
     79 	  default	:  abort(); break;
     80 	}
     81 	break;
     82 
     83       default		:
     84 	abort();
     85     }
     86   }
     87 
     88   {
     89     char *	cmd[] = { "/bin/grep", "^s_context", "/proc/self/status", 0 };
     90     Eexecv(cmd[0], cmd);
     91   }
     92 }