// 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
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 = {
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);
#include "sys_clone.h"
#include "util.h"
-#include <vserver.h>
+#include "lib/vserver.h"
+#include "lib/internal.h"
#include <sys/socket.h>
#include <dlfcn.h>
#include <pwd.h>
#include <grp.h>
+#define ENSC_WRAPPERS_PREFIX "rpm-fake.so: "
+#define ENSC_WRAPPERS_VSERVER 1
+#define ENSC_WRAPPERS_UNISTD 1
+#include <wrappers.h>
+
#ifndef CLONE_NEWNS
# define CLONE_NEWNS 0x00020000
#endif
#define PLATFORM_FILE "/etc/rpm/platform"
#define INIT(FILE,FUNC) FUNC##_func = ((__typeof__(FUNC) *) (xdlsym(FILE, #FUNC)))
-#define DECLARE(FUNC) static __typeof__(FUNC) * FUNC##_func = 0
+#define DECLARE(FUNC) static __typeof__(FUNC) * FUNC##_func = 0
#define DBG_INIT 0x0001
return res;
}
+static void
+setupContext(xid_t xid)
+{
+
+ if (vc_isSupported(vcFEATURE_MIGRATE)) {
+ xid_t rc = vc_create_context(xid);
+ if (rc==VC_NOCTX && errno!=EEXIST) {
+ perror("rpm-fake.so: vc_create_context()");
+ exit(255);
+ }
+
+ if (rc!=VC_NOCTX) {
+ char buf[128];
+ size_t l;
+ strcpy(buf, "rpm-fake.so #");
+ l = utilvserver_fmt_uint(buf+sizeof("rpm-fake.so #")-1, getppid());
+ Evc_set_vhi_name(rc, vcVHI_CONTEXT, buf, sizeof("rpm-fake.so #")+l-1);
+#warning set some sane capabilities
+ // context will be activated later...
+
+ xid = rc;
+ }
+ }
+
+ Ewrite(3, &xid, sizeof xid);
+}
+
#if 0
static void
initPwSocket()
if (gid) { *ptr++ = "-g"; *ptr++ = gid; }
if (ctx_s) { *ptr++ = "-c"; *ptr++ = ctx_s; }
*ptr++ = 0;
-
+
+ setupContext(ctx);
execve(resolver, (char **)args, (char **)env);
perror("rpm-fake.so: failed to exec resolver");
exit(255);
pw_sock = res_sock[0];
sync_sock = sync_pipe[0];
- if (read(sync_sock, &c, 1)!=1 ||
+ if (read(sync_sock, &ctx, sizeof ctx)!=sizeof(ctx) ||
+ read(sync_sock, &c, 1)!=1 ||
write(pw_sock, ".", 1)!=1 ||
read(pw_sock, &c, 1)!=1 ||
c!='.') {
{
int res;
- if ((res=vc_new_s_context(ctx,caps,flags))!=-1 &&
- (res=execv_func(path, argv)!=-1) ) {}
+ if (vc_isSupported(vcFEATURE_MIGRATE))
+ res = vc_migrate_context(ctx);
+ else
+ res = vc_new_s_context(ctx,caps,flags);
+
+ if (res!=-1)
+ res=execv_func(path, argv);
return res;
}