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.
35 #define ENSC_WRAPPERS_PREFIX "rpm-fake-resolver: "
36 #define ENSC_WRAPPERS_VSERVER 1
37 #define ENSC_WRAPPERS_UNISTD 1
38 #define ENSC_WRAPPERS_FCNTL 1
41 #define MAX_RQSIZE 0x1000
43 int wrapper_exit_code = 1;
50 char const * pid_file;
54 static struct option const
56 { "help", no_argument, 0, 'h' },
57 { "version", no_argument, 0, 'v' },
62 showHelp(int fd, char const *cmd, int res)
64 WRITE_MSG(fd, "Usage: ");
67 " [-c <ctx>] [-u <uid>] [-g <gid>] [-r <chroot>] [-n]\n"
68 "Please report bugs to " PACKAGE_BUGREPORT "\n");
76 "rpm-fake-resolver " VERSION " -- NSS resovler for rpm-fake\n"
77 "This program is part of " PACKAGE_STRING "\n\n"
78 "Copyright (C) 2003 Enrico Scholz\n"
79 VERSION_COPYRIGHT_DISCLAIMER);
85 parseArgs(struct ArgInfo *args, int argc, char *argv[])
88 int c = getopt_long(argc, argv, "c:u:g:r:n", CMDLINE_OPTIONS, 0);
92 case 'h' : showHelp(1, argv[0], 0);
93 case 'v' : showVersion();
95 case 'c' : args->ctx = atoi(optarg); break;
96 case 'u' : args->uid = atoi(optarg); break;
97 case 'g' : args->gid = atoi(optarg); break;
98 case 'r' : args->chroot = optarg; break;
99 case 'n' : args->do_fork = false; break;
101 WRITE_MSG(2, "Try '");
102 WRITE_STR(2, argv[0]);
103 WRITE_MSG(2, " --help\" for more information.\n");
110 WRITE_MSG(2, "No further options allowed; aborting ...\n");
114 if (args->chroot==0) {
115 WRITE_MSG(2, "No chroot specified; aborting...\n");
121 sendResult(bool state, uint32_t res)
124 static uint8_t ONE = 1;
125 Ewrite(1, &ONE, sizeof ONE);
128 static uint8_t ZERO = 0;
129 Ewrite(1, &ZERO, sizeof ZERO);
132 Ewrite(1, &res, sizeof res);
139 Eread(0, &len, sizeof len);
141 if (len<MAX_RQSIZE) {
148 if (res!=0) sendResult(true, res->pw_uid);
149 else sendResult(false, -1);
158 Eread(0, &len, sizeof len);
160 if (len<MAX_RQSIZE) {
167 if (res!=0) sendResult(true, res->gr_gid);
168 else sendResult(false, -1);
177 Eread(0, &what, sizeof what);
179 case 'p' : endpwent(); break;
180 case 'g' : endgrent(); break;
192 Eread (0, &c, sizeof c);
194 case 'P' : do_getpwnam(); break;
195 case 'G' : do_getgrnam(); break;
197 case 'C' : do_closenss(); break;
198 case '.' : Ewrite(1, ".", 1); break;
199 default : Ewrite(1, "?", 1); break;
205 daemonize(struct ArgInfo const UNUSED * args, int pid_fd)
216 char buf[sizeof(id_t)*3 + 2];
219 l = utilvserver_fmt_uint(buf, pid);
220 Ewrite(pid_fd, buf, l);
221 Ewrite(pid_fd, "\n", 1);
230 int main(int argc, char * argv[])
232 struct ArgInfo args = {
233 .ctx = VC_DYNAMIC_XID,
243 # warning *** rpm-fake-resolver is built against glibc; please do not report errors before trying a dietlibc version ***
245 "*** rpm-fake-resolver was built with glibc; please do ***\n"
246 "*** not report errors before trying a dietlibc version. ***\n");
249 parseArgs(&args, argc, argv);
250 if (args.pid_file && args.do_fork)
251 pid_fd = EopenD(args.pid_file, O_CREAT|O_WRONLY, 0644);
253 if (args.chroot) Echroot(args.chroot);
256 //Evc_new_s_context(args.ctx, ~(VC_CAP_SETGID|VC_CAP_SETUID), S_CTX_INFO_LOCK);
257 Evc_new_s_context(args.ctx, 0, S_CTX_INFO_LOCK);
258 Esetgroups(0, &args.gid);
262 if (args.do_fork) daemonize(&args, pid_fd);
263 if (pid_fd!=-1) close(pid_fd);