[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
setgid() confusion
From: |
Nathan Straz |
Subject: |
setgid() confusion |
Date: |
Wed, 21 Mar 2001 14:55:47 -0600 |
User-agent: |
Mutt/1.3.15i |
I'm working on a negative test for setgid() and something isn't quite
clear to me. What range are considered valid gid_t values? i.e. what
are invalid values?
It seems that I can't provoke EINVAL, which probably isn't a big deal.
What struck me odd is that passing a value between -2 and -4095 will set
the gid and egid to -1.
What is the correct behavior?
Script started on Wed Mar 21 11:21:08 2001
address@hidden /extra/code% cat setgid_neg.c
#include <unistd.h>
#include <sys/types.h>
#include <errno.h>
#include <string.h>
int main()
{
gid_t bad_gid = -99;
int ret;
printf("gid: %d\n", getgid());
printf("egid: %d\n", getegid());
printf("bad_gid: %d\n", bad_gid);
ret = setgid(bad_gid);
printf("setgid(%d) = %d, errno: %d %s\n",
bad_gid, ret, errno, strerror(errno));
printf("gid: %d\n", getgid());
printf("egid: %d\n", getegid());
return ret;
}
address@hidden /extra/code% runcmd -u root ./setgid_neg
gid: 1049
egid: 1049
bad_gid: -99
setgid(-99) = 0, errno: 0 Success
gid: -1
egid: -1
address@hidden /extra/code% ./setgid_neg
gid: 1049
egid: 1049
bad_gid: -99
setgid(-99) = -1, errno: 1 Operation not permitted
gid: 1049
egid: 1049
address@hidden /extra/code% exit
Script done on Wed Mar 21 11:21:34 2001
--
Nate Straz address@hidden
sgi, inc http://www.sgi.com/
Linux Test Project http://oss.sgi.com/projects/ltp/
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- setgid() confusion,
Nathan Straz <=