version 0.29.201
[util-vserver.git] / util-vserver / src / rpm-fake-resolver.c
index f185c25..f24a609 100644 (file)
 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
 
+// Protocol:
+// 1. startup
+// 2. initialize (setuid, ctx-migrate, chroot, ...)
+// 3. send "." token to fd 3
+// 4. wait one character on fd 1
+// 5. process this character and consume further characters from fd 1 as far
+//    as needed
+// 6. go to 3) (or exit)
+
 #ifdef HAVE_CONFIG_H
 #  include <config.h>
 #endif
@@ -30,7 +39,9 @@
 #include <grp.h>
 #include <pwd.h>
 #include <fcntl.h>
+#include <errno.h>
 
+#define ENSC_WRAPPERS_PREFIX   "rpm-fake-resolver: "
 #define ENSC_WRAPPERS_VSERVER  1
 #define ENSC_WRAPPERS_UNISTD   1
 #define ENSC_WRAPPERS_FCNTL    1
@@ -225,10 +236,22 @@ daemonize(struct ArgInfo const UNUSED * args, int pid_fd)
   Eclose(p[0]);
 }
 
+static void
+activateContext(xid_t xid)
+{
+  if (vc_isSupported(vcFEATURE_MIGRATE)) {
+#warning TODO: activate the context here or migrate to it
+    abort();
+  }
+  else 
+    Evc_new_s_context(xid, 0, S_CTX_INFO_LOCK);
+    //Evc_new_s_context(args.ctx, ~(VC_CAP_SETGID|VC_CAP_SETUID), S_CTX_INFO_LOCK);
+}
+
 int main(int argc, char * argv[])
 {
   struct ArgInfo       args = {
-    .ctx      = VC_RANDCTX,
+    .ctx      = VC_DYNAMIC_XID,
     .uid      = 99,
     .gid      = 99,
     .do_fork  = true,
@@ -237,15 +260,21 @@ int main(int argc, char * argv[])
   };
   int                  pid_fd = -1;
 
+#ifndef __dietlibc__
+#  warning  *** rpm-fake-resolver is built against glibc; please do not report errors before trying a dietlibc version ***
+  WRITE_MSG(2,
+           "***  rpm-fake-resolver was built with glibc;  please do  ***\n"
+           "***  not report errors before trying a dietlibc version. ***\n");
+#endif
+
   parseArgs(&args, argc, argv);
   if (args.pid_file && args.do_fork)
-    pid_fd = Eopen(args.pid_file, O_CREAT|O_WRONLY, 0644);
+    pid_fd = EopenD(args.pid_file, O_CREAT|O_WRONLY, 0644);
   
   if (args.chroot) Echroot(args.chroot);
   Echdir("/");
 
-  //Evc_new_s_context(args.ctx, ~(VC_CAP_SETGID|VC_CAP_SETUID), S_CTX_INFO_LOCK);
-  Evc_new_s_context(args.ctx, 0, S_CTX_INFO_LOCK);
+  activateContext(args.ctx);
   Esetgroups(0, &args.gid);
   Esetgid(args.gid);
   Esetuid(args.uid);