annotate VBoxFrontend/ProgramLoader.cs @ 0:e1ec7bf71313

Initial commit
author Ivo Smits
date Wed, 04 May 2011 00:59:43 +0200
parents
children b0033e69105a
rev   line source
0
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
1 ???using System;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
2 using System.Reflection;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
3 using System.Runtime.InteropServices;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
4
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
5 namespace ConsoleApplication1 {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
6 class ProgramLoader {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
7 [DllImport("/usr/lib/virtualbox/VBoxXPCOMC.so")]
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
8 private static extern Int32 RTR3InitAndSUPLib();
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
9
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
10 static unsafe int Main(string[] args) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
11 if (Environment.OSVersion.Platform == PlatformID.Unix) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
12 Console.WriteLine("UNIX based OS detected, doing some magic...");
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
13 int init = RTR3InitAndSUPLib();
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
14 if (init != 0) throw new COMException("Failed to initialize VirtualBox driver", init);
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
15 Unix_setuid();
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
16 Assembly.LoadFile("Interop.VirtualBox.XPCOM.dll");
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
17 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
18 return Main2(args);
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
19 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
20
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
21 static int Main2(String[] args) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
22 ProgramRun p = new ProgramRun();
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
23 return p.Run(args);
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
24 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
25
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
26 private static void Unix_setuid() {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
27 uint uid = Mono.Unix.Native.Syscall.getuid();
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
28 uint euid = Mono.Unix.Native.Syscall.geteuid();
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
29 Console.WriteLine("Running as user {0} effective {1}", uid, euid);
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
30 if (uid != euid) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
31 Console.WriteLine("Set user ID: {0}", uid);
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
32 Mono.Unix.Native.Syscall.setreuid(uid, uid);
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
33 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
34 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
35 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
36 }