1

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?

Ali Maisam
  • 239
  • 1
  • 3
  • 15

2 Answers2

0

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.

  • It was working fine on less than 10.9, is there any specific changes in 10.9 that is restricting it from this. – Ali Maisam Nov 02 '13 at 11:11
0

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 */
Parag Bafna
  • 22,812
  • 8
  • 71
  • 144