I'm not the process you think I am

From: Muli Ben-Yehuda (mulix_at_nonexisting.hamakor.org.il)
Date: Tue 31 Aug 2004 - 12:56:50 IDT


Salutations!

I would like to have a process that will
- run with de-facto root priviledges (can do anything root can do)
- appears to be running under a different user with standard ps / top
and friends

Any ideas on how to achieve this? I tried setting the real UID to X
and the effective UID to 0 (root), but the process appears as root's
in ps. Sample code attached:

#define _GNU_SOURCE
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>

static const uid_t root = 0;
static const uid_t user = 2252; /* whatever */

static inline void printid(const char* prompt)
{
        printf("%s: pid %d, ruid %d, euid %d\n",
               prompt, getpid(), getuid(),
               geteuid());
}

int main(void)
{
        int ret;
        pid_t pid;
        
        printid("starting");

        pid = fork();
        if (pid < 0) {
                perror("fork");
                exit(1);
        } else if (pid == 0) {
                /* child */
                printid("child");
                ret = setresuid(user, root, user);
                perror("setresuid user, root, user");

                printid("child after setresuid");

                pause();

                exit(0);
        }
        printid("father");

        return 0;
}

Cheers,
Muli

-- 
Muli Ben-Yehuda
http://www.mulix.org | http://mulix.livejournal.com/

=================================================================
To unsubscribe, send mail to linux-il-request_at_linux.org.il with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail linux-il-request_at_linux.org.il




This archive was generated by hypermail 2.1.7 : Tue 31 Aug 2004 - 13:09:56 IDT