From 62a7cf84a840dd6f172eeb1a25741cb436dc4e04 Mon Sep 17 00:00:00 2001 From: Enrico Scholz Date: Thu, 11 Mar 2004 04:41:45 +0000 Subject: [PATCH] implemented most parts of the new migrate method git-svn-id: http://svn.linux-vserver.org/svn/util-vserver/trunk@1211 94cd875c-1c1d-0410-91d2-eb244daf1a30 --- util-vserver/src/rpm-fake-resolver.c | 24 +++++++++++++++-- util-vserver/src/rpm-fake.c | 52 +++++++++++++++++++++++++++++++----- 2 files changed, 68 insertions(+), 8 deletions(-) diff --git a/util-vserver/src/rpm-fake-resolver.c b/util-vserver/src/rpm-fake-resolver.c index 640946d..f24a609 100644 --- a/util-vserver/src/rpm-fake-resolver.c +++ b/util-vserver/src/rpm-fake-resolver.c @@ -16,6 +16,15 @@ // 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 #endif @@ -227,6 +236,18 @@ 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 = { @@ -253,8 +274,7 @@ int main(int argc, char * argv[]) 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); diff --git a/util-vserver/src/rpm-fake.c b/util-vserver/src/rpm-fake.c index 62cba0e..f53a9db 100644 --- a/util-vserver/src/rpm-fake.c +++ b/util-vserver/src/rpm-fake.c @@ -24,7 +24,8 @@ #include "sys_clone.h" #include "util.h" -#include +#include "lib/vserver.h" +#include "lib/internal.h" #include #include @@ -49,6 +50,11 @@ #include #include +#define ENSC_WRAPPERS_PREFIX "rpm-fake.so: " +#define ENSC_WRAPPERS_VSERVER 1 +#define ENSC_WRAPPERS_UNISTD 1 +#include + #ifndef CLONE_NEWNS # define CLONE_NEWNS 0x00020000 #endif @@ -57,7 +63,7 @@ #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 @@ -163,6 +169,33 @@ getAndClearEnv(char const *key, int dflt) 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() @@ -240,7 +273,8 @@ 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); @@ -253,7 +287,8 @@ initPwSocket() 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!='.') { @@ -471,8 +506,13 @@ execvWorker(char const *path, char * const argv[]) { 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; } -- 1.8.1.5