LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-26-2010, 03:35 PM   #1
sun_peixing
LQ Newbie
 
Registered: Jul 2010
Posts: 2

Rep: Reputation: 0
setgid() calls get error "


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 test_dir]# ypcat passwd|grep 40088 |grep 40000
dvt_usr40088:aK5r4VXKZIBUo:40088:40000:quota_testing:/:/bin/csh

I am running Redhat 5 on my Linux client.
Linux rtplab101 2.6.18-92.el5PAE #1 SMP Tue Apr 29 13:31:02 EDT 2008 i686 i686 i386 GNU/Linux

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);
}
 
Old 07-27-2010, 09:08 AM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Moved to Programming
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
"setgid:Operation not permitted" after shadow install proRandom Linux From Scratch 3 10-21-2010 10:48 PM
[SOLVED] Finding out which process calls a program/script ("/sbin/usbmod") JZL240I-U Linux - Software 4 06-01-2010 06:42 AM
a script calls another script which calls "bash" inside lordofring Linux - Software 10 03-18-2010 09:59 AM
diff between "system calls" and "kernel threads" shariefbe Linux - Software 5 12-13-2009 10:23 AM
LXer: German Design Firm Calls Its Car Concept "Open Source" LXer Syndicated Linux News 0 01-26-2009 09:30 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:26 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration