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