And how to use setuid() ?
thanks
#include <unistd.h>
uid_t myuid(void)
{
return getuid();
}
No offense meant, but setuid is a major security risk. Don't go implementing your code on your system unless it is a home desktop that can be trashed.
setuid requires either root or the so-called sticky bit set to allow the program to change it's username.
It may seem simple but there is a lot to writing a setuid program:
http://nob.cs.ucdavis.edu/bishop/secprog/1987-sproglogin.pdf
setuid() is pretty integral to a safe unix process.
One basic mode is for a root privileged parent to acquire
resources only it can handle (ports < 1024) and then delegate service to setuid(> 0) children/threads, ala OpenSSH and many other pieces of software via IPC.
Given it's not easy to do securely and does pose a considerable security issue: mostly races and various abuses of unsafe programing practices in the privileged process.
thanks jim mcnamara,
i want catch value of getuid() to put into a logfile. How to do it?
one way:
id >> logfile
c code
/* myid.c */
#include <unistd.h>
uid_t myuid(void)
{
return getuid();
}
int main()
{
printf("%d\n", myuid() );
return 0;
}
cc myid.c -o myid
in your script
myid >> logfile