According to seteuid(2):
According to POSIX.1, seteuid() (setegid()) need not permit euid (egid)
to be the same value as the current effective user (group) ID, and some
implementations do not permit this.
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
* cannot attach to this process with, e.g. ptrace, nor map this
* process memory.
*/
- ret = setegid(data->gid);
- if (ret < 0) {
- perror("setegid");
- exit(EXIT_FAILURE);
+ if (data->gid != getegid()) {
+ ret = setegid(data->gid);
+ if (ret < 0) {
+ perror("setegid");
+ exit(EXIT_FAILURE);
+ }
}
- ret = seteuid(data->uid);
- if (ret < 0) {
- perror("seteuid");
- exit(EXIT_FAILURE);
+ if (data->uid != geteuid()) {
+ ret = seteuid(data->uid);
+ if (ret < 0) {
+ perror("seteuid");
+ exit(EXIT_FAILURE);
+ }
}
/*
* Also set umask to 0 for mkdir executable bit.