setgid() failed with "errno=1, Operation not permitted"
Hi All:
I have a simple program attached below. I login as root, compiled and ran setgid_test.c as root also. The program simply tries to copy a file "seed_file" to a new "test_file". The new "test_file" should have user id: 40088, group id "40000". When I ran a.out, setuid() worked, but setgid() failed. I have to have this work, because I always login to a root, but will create files with different uids and gids to test a quota system. Please note that both uid and gid I used are valid. I have NIS client setup properly. [root@rtplab101 sunp]# ypcat passwd|grep 40088 |grep 40000 dvt_usr40088:aK5r4VXKZIBUo:40088:40000:quota_testing:/:/bin/csh My Linux client is running RedHat 5, Linux 2.6.18-92.el5PAE Very appreciate your help Peixing -rwxr-xr-x 1 root root 2406185 Jul 26 10:56 seed_file -rw-r--r-- 1 root root 632 Jul 26 2010 setgid_test.c -rwxr-xr-x 1 root root 5928 Jul 26 2010 a.out ./a.out setgid failed: errno=1, Operation not permitted ls -l test_file /* get the righ uid, but setgid failed */ -rw-r--r-- 1 40088 root 2408448 Jul 26 2010 test_file ====setgid_test.c=================== #include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <unistd.h> #include <errno.h> #include <string.h> #define BUFFER_SIZE 8192 const char *seed_file = "seed_file"; char *buffer[BUFFER_SIZE]; int main(){ FILE *fpin; FILE *fpout; if(setuid(40088)){ printf("setuid failed: %s\n", strerror(errno)); } if(setgid(40000)){ printf("setgid failed: errno=%d, %s\n", errno, strerror(errno)); } fpin = fopen(seed_file, "r"); fpout = fopen("test_file", "w"); while(!feof(fpin)){ fread(buffer, BUFFER_SIZE, 1, fpin); fwrite(buffer, BUFFER_SIZE, 1, fpout); } fclose(fpin); fclose(fpout); } |
Don't post the same question in multiple forums.
|
Please post your thread in only one forum. Posting a single thread in the most relevant forum will make it easier for members to help you and will keep the discussion in one place.
This thread has been reported for closure because it is a duplicate. |
All times are GMT -5. The time now is 06:40 AM. |