use new ensc_wrappers/ headers
[util-vserver.git] / util-vserver / src / testsuite / rpm-fake-test.c
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
31 #define ENSC_WRAPPERS_UNISTD    1
32 #include <wrappers.h>
33
34 int wrapper_exit_code = 1;
35
36 int main(int argc, char *argv[])
37 {
38   char          buf[1000];
39
40   while (true) {
41     char        *ptr = buf;
42     char        c;
43     do {
44       if (read(0, &c, 1)==0) break;
45       if (c=='\n') break;
46       *ptr++ = c;
47     } while (ptr<buf+sizeof(buf));
48     *ptr = '\0';
49     if (ptr==buf) break;
50
51     switch (buf[0]) {
52       case 'P'          : {
53         struct passwd   *pw;
54         
55         pw = getpwnam(buf+1);
56         printf("P(%s) = ", buf+1);
57         if (pw) printf("%u\n", pw->pw_uid);
58         else    printf("(null)\n");
59         
60         break;
61       }
62
63       case 'G'          : {
64         struct group    *gr;
65         
66         gr = getgrnam(buf+1);
67         printf("G(%s) = ", buf+1);
68         if (gr) printf("%u\n", gr->gr_gid);
69         else    printf("(null)\n");
70         
71         break;
72       }
73
74       case 'C'          :
75         switch (buf[1]) {
76           case 'g'      :  endgrent(); break;
77           case 'p'      :  endpwent(); break;
78           default       :  abort(); break;
79         }
80         break;
81
82       default           :
83         abort();
84     }
85   }
86
87   {
88     char const *        cmd[] = { "/bin/grep", "^s_context", "/proc/self/status", 0 };
89     Eexecv(cmd[0], cmd);
90   }
91 }