[Mono-list] Aquire Root Privileges

Enqueue danielku15 at yahoo.de
Wed Jun 15 18:40:31 EDT 2011


Thanks for the idea. I did a lot of research but I don't get it work. I tried
to create a small application for testing purposes: 
<code>
using System;
using System.IO;
using System.Runtime.InteropServices;

namespace AdminTest {
    class AdminTest {
        public static void Main(string[] args) {
            Console.WriteLine("Current uid/gid: {0}/{1}", getuid(),
getgid());
            int resultGid = setgid(0);
            if(resultGid != 0) 
                Console.WriteLine("Errorcode gid: {0}",
Marshal.GetLastWin32Error());
            int resultUid = setuid(0);
            if(resultUid != 0) 
                Console.WriteLine("Errorcode uid: {0}",
Marshal.GetLastWin32Error());
            Console.WriteLine("Aquire root rights {0}", result);
        }
        [DllImport ("libc", SetLastError=true)]
        public static extern int setgid(int gid);
        [DllImport ("libc", SetLastError=true)]
        public static extern int getgid();
        [DllImport ("libc", SetLastError=true)]
        public static extern int setuid(int uid);
        [DllImport ("libc", SetLastError=true)]
        public static extern int getuid();
    }
}
</code>

After compiling and executing I only get:
<code>
Current uid/gid: 501/20
Errorcode gid: 1
Errorcode uid: 1
Aquire root rights -1/-1
Current uid/gid: 501/20
</code>
I tried the same exe under (sudo su):
<code>
Current uid/gid: 0/0
Aquire root rights 0/0
Current uid/gid: 0/0
</code>
I expected some kind of "Mono wants to access administrator
privileges"-Popup of the keychain but nothing happened. I would still need
to do some chown and chmod stuff (chown root.root, chmod +s) to allow the
application accessing root privileges and therefore I still have the same
problem. How do all those installers solve this problem?

Cheers


--
View this message in context: http://mono.1490590.n4.nabble.com/Aquire-Root-Privileges-tp3600287p3600761.html
Sent from the Mono - General mailing list archive at Nabble.com.


More information about the Mono-list mailing list