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.
27 #include "wrappers-vserver.h"
35 #define MAX_RQSIZE 0x1000
37 int wrapper_exit_code = 1;
44 char const * pid_file;
48 static struct option const
50 { "help", no_argument, 0, 'h' },
51 { "version", no_argument, 0, 'v' },
56 showHelp(int fd, char const *cmd, int res)
58 WRITE_MSG(fd, "Usage: ");
61 " [-c <ctx>] [-u <uid>] [-g <gid>] [-r <chroot>] [-n]\n"
62 "Please report bugs to " PACKAGE_BUGREPORT "\n");
70 "rpm-fake-resolver " VERSION " -- NSS resovler for rpm-fake\n"
71 "This program is part of " PACKAGE_STRING "\n\n"
72 "Copyright (C) 2003 Enrico Scholz\n"
73 VERSION_COPYRIGHT_DISCLAIMER);
79 parseArgs(struct ArgInfo *args, int argc, char *argv[])
82 int c = getopt_long(argc, argv, "c:u:g:r:n", CMDLINE_OPTIONS, 0);
86 case 'h' : showHelp(1, argv[0], 0);
87 case 'v' : showVersion();
89 case 'c' : args->ctx = atoi(optarg); break;
90 case 'u' : args->uid = atoi(optarg); break;
91 case 'g' : args->gid = atoi(optarg); break;
92 case 'r' : args->chroot = optarg; break;
93 case 'n' : args->do_fork = false; break;
95 WRITE_MSG(2, "Try '");
96 WRITE_STR(2, argv[0]);
97 WRITE_MSG(2, " --help\" for more information.\n");
104 WRITE_MSG(2, "No further options allowed; aborting ...\n");
108 if (args->chroot==0) {
109 WRITE_MSG(2, "No chroot specified; aborting...\n");
115 sendResult(bool state, uint32_t res)
118 static uint8_t ONE = 1;
119 Ewrite(1, &ONE, sizeof ONE);
122 static uint8_t ZERO = 0;
123 Ewrite(1, &ZERO, sizeof ZERO);
126 Ewrite(1, &res, sizeof res);
133 Eread(0, &len, sizeof len);
135 if (len<MAX_RQSIZE) {
142 if (res!=0) sendResult(true, res->pw_uid);
143 else sendResult(false, -1);
152 Eread(0, &len, sizeof len);
154 if (len<MAX_RQSIZE) {
161 if (res!=0) sendResult(true, res->gr_gid);
162 else sendResult(false, -1);
171 Eread(0, &what, sizeof what);
173 case 'p' : endpwent(); break;
174 case 'g' : endgrent(); break;
186 Eread (0, &c, sizeof c);
188 case 'P' : do_getpwnam(); break;
189 case 'G' : do_getgrnam(); break;
191 case 'C' : do_closenss(); break;
192 case '.' : Ewrite(1, ".", 1); break;
193 default : Ewrite(1, "?", 1); break;
199 daemonize(struct ArgInfo const UNUSED * args, int pid_fd)
210 char buf[sizeof(id_t)*3 + 2];
213 l = utilvserver_fmt_uint(buf, pid);
214 Ewrite(pid_fd, buf, l);
215 Ewrite(pid_fd, "\n", 1);
224 int main(int argc, char * argv[])
226 struct ArgInfo args = {
236 parseArgs(&args, argc, argv);
237 if (args.pid_file && args.do_fork)
238 pid_fd = Eopen(args.pid_file, O_CREAT|O_WRONLY, 0644);
240 if (args.chroot) Echroot(args.chroot);
243 //Evc_new_s_context(args.ctx, ~(VC_CAP_SETGID|VC_CAP_SETUID), S_CTX_INFO_LOCK);
244 Evc_new_s_context(args.ctx, 0, S_CTX_INFO_LOCK);
245 Esetgroups(0, &args.gid);
249 if (args.do_fork) daemonize(&args, pid_fd);
250 if (pid_fd!=-1) close(pid_fd);