LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


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

Rep: Reputation: 0
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);
}
 
Old 07-26-2010, 04:27 PM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,689

Rep: Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972
Don't post the same question in multiple forums.
 
Old 07-26-2010, 07:27 PM   #3
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
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.
 
  


Closed Thread



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
"creating symbolic link" "operation not permitted" wheni Linux - Newbie 3 05-08-2011 01:36 AM
"setgid:Operation not permitted" after shadow install proRandom Linux From Scratch 3 10-21-2010 10:48 PM
setgid: Operation not permitted codon Linux - Security 2 05-03-2008 06:01 AM
Logged in as "root"/Fedora 8 but get "Operation not permitted" when using "chmod etc gosunlee Linux - Newbie 7 02-10-2008 05:56 AM
hdparm -d1 /dev/hda gives me "HDIO_SET_DMA failed: Operation not permitted" elluva Linux - Hardware 7 07-21-2007 03:49 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 10:47 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