execl() fails with EACCES after setuid() call
Hello there,
myname is Matteo and I'm writing from Italy.
Maybe this is a very trivial issue but I'm going crazy on it.
I have a simple application, say test, owned by myuid.mygid, of course different from root, where myuid=31 mygid=31.
Inside it I just do:
...
res = setgid(31);
if (res != 0)
printf("setgid() failed\n");
res = setuid(31);
if (res != 0)
printf("setuid() failed\n");
res = execl("/usr/sbin/myapp", (char*) NULL);
printf("execl() returned %d\n", res);
if (res != 0)
printf("execl() error: %s (%d)\n", strerror(errno), errno);
...
Please note that myapp is owned by 0.mygid and is readable/executable by mygid and the same for /usr and /usr/sbin.
But execl() fails with EACCES.
It seems that setuid() is the real cause, because if I comment only it the result is OK.
Can anyone please tell me what's wrong?
Many many thanks,
Matteo.
|