简体   繁体   中英

setuid(0) gives EPERM on Mac OS X 10.9

when executing this:

err = setuid(0);
if (err < 0) {
    fprintf(stderr, "return value: %d \n", err);
    fprintf(stderr, "error code: %d \n", errno);
 }

I am getting this output:

return value: -1 
error code: 1 

Error code 1 implies an EPERM error. Any ideas as to how should I fix it?

You cannot setuid() to root from a non-root user.

If you want to run your application as root, use Authorization Services , or sudo if it's a command-line tool.

SETUID(2) Man Pages

If the user is not the super user, or the uid specified is not the real, effective ID, or saved ID,these functions return -1.

setuid(0); will work only from root(SU) user.

error code: 1

#define EPERM       1       /* Operation not permitted */

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