3 // Copyright (C) 2003 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
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.
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.
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.
34 #define ENSC_WRAPPERS_VSERVER 1
35 #define ENSC_WRAPPERS_UNISTD 1
36 #define ENSC_WRAPPERS_FCNTL 1
39 #define MAX_RQSIZE 0x1000
41 int wrapper_exit_code = 1;
48 char const * pid_file;
52 static struct option const
54 { "help", no_argument, 0, 'h' },
55 { "version", no_argument, 0, 'v' },
60 showHelp(int fd, char const *cmd, int res)
62 WRITE_MSG(fd, "Usage: ");
65 " [-c <ctx>] [-u <uid>] [-g <gid>] [-r <chroot>] [-n]\n"
66 "Please report bugs to " PACKAGE_BUGREPORT "\n");
74 "rpm-fake-resolver " VERSION " -- NSS resovler for rpm-fake\n"
75 "This program is part of " PACKAGE_STRING "\n\n"
76 "Copyright (C) 2003 Enrico Scholz\n"
77 VERSION_COPYRIGHT_DISCLAIMER);
83 parseArgs(struct ArgInfo *args, int argc, char *argv[])
86 int c = getopt_long(argc, argv, "c:u:g:r:n", CMDLINE_OPTIONS, 0);
90 case 'h' : showHelp(1, argv[0], 0);
91 case 'v' : showVersion();
93 case 'c' : args->ctx = atoi(optarg); break;
94 case 'u' : args->uid = atoi(optarg); break;
95 case 'g' : args->gid = atoi(optarg); break;
96 case 'r' : args->chroot = optarg; break;
97 case 'n' : args->do_fork = false; break;
99 WRITE_MSG(2, "Try '");
100 WRITE_STR(2, argv[0]);
101 WRITE_MSG(2, " --help\" for more information.\n");
108 WRITE_MSG(2, "No further options allowed; aborting ...\n");
112 if (args->chroot==0) {
113 WRITE_MSG(2, "No chroot specified; aborting...\n");
119 sendResult(bool state, uint32_t res)
122 static uint8_t ONE = 1;
123 Ewrite(1, &ONE, sizeof ONE);
126 static uint8_t ZERO = 0;
127 Ewrite(1, &ZERO, sizeof ZERO);
130 Ewrite(1, &res, sizeof res);
137 Eread(0, &len, sizeof len);
139 if (len<MAX_RQSIZE) {
146 if (res!=0) sendResult(true, res->pw_uid);
147 else sendResult(false, -1);
156 Eread(0, &len, sizeof len);
158 if (len<MAX_RQSIZE) {
165 if (res!=0) sendResult(true, res->gr_gid);
166 else sendResult(false, -1);
175 Eread(0, &what, sizeof what);
177 case 'p' : endpwent(); break;
178 case 'g' : endgrent(); break;
190 Eread (0, &c, sizeof c);
192 case 'P' : do_getpwnam(); break;
193 case 'G' : do_getgrnam(); break;
195 case 'C' : do_closenss(); break;
196 case '.' : Ewrite(1, ".", 1); break;
197 default : Ewrite(1, "?", 1); break;
203 daemonize(struct ArgInfo const UNUSED * args, int pid_fd)
214 char buf[sizeof(id_t)*3 + 2];
217 l = utilvserver_fmt_uint(buf, pid);
218 Ewrite(pid_fd, buf, l);
219 Ewrite(pid_fd, "\n", 1);
228 int main(int argc, char * argv[])
230 struct ArgInfo args = {
240 parseArgs(&args, argc, argv);
241 if (args.pid_file && args.do_fork)
242 pid_fd = Eopen(args.pid_file, O_CREAT|O_WRONLY, 0644);
244 if (args.chroot) Echroot(args.chroot);
247 //Evc_new_s_context(args.ctx, ~(VC_CAP_SETGID|VC_CAP_SETUID), S_CTX_INFO_LOCK);
248 Evc_new_s_context(args.ctx, 0, S_CTX_INFO_LOCK);
249 Esetgroups(0, &args.gid);
253 if (args.do_fork) daemonize(&args, pid_fd);
254 if (pid_fd!=-1) close(pid_fd);