简体   繁体   中英

Not understanding setuid

I created a VERY simple script:

//#escalate.c - a setuid utility so that we can call shutdown
//# and other things safely without needing root access.  We 
//# do need to:
//#   gcc escalate.c -o escalate.out
//#   sudo chown root:root escalate.out
//#   sudo chmod 4755 escalate.out

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

int main()
{
    int status;
    status = setuid( 0 );   // you can set it at run time also
    system("date > /tmp/date.fil");
    return errno;
 }

On Raspian it generates the file in /tmp, owned by the root and returns 0 as expected.

On Ubuntu 22 it created the file owned by ME and the return status is 1. What am I missing about setuid(0); ?

I tried creating, modifying the permissions and ownership etc. On Raspian it works like a charm, on Ubuntu it does not.

================== OK - solved it myself. On Ubuntu I was running with an encrypted home and so it was mounted with nosuid set.

the problem was that the file system was mounted nosuid

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM