Problem with suid bit for Unix

I wrote a program in c that does some calculations, then creates a folder. This folder owner is the root user. With another user, I am trying to run this application c. I have this error:

mkdir: lol: Permission denied

Well, I know that this error is in order, because I do not have rights to it, but I read on the Internet that if I set the suid bit to a file, this file will work with the owner’s rights, I used this command:

chmod +s filename

But it does not work ... :( Any ideas?

EDIT:
So, firstly, my Unix distribution is Mac OS X 10.5.8. And my file name is a.out, since I compiled it with ic.c using the command: gcc ic.c And I run the chmod command with the root user.

+5
source share
6 answers

I think you will also need setuid(0);in your program to become root. It is not enough to set only s-bits.

I agree with everyone else that doing all this is very risky ...

Edit

Jonathan Leffler is right in the comments. setuid(0);probably not needed in this case. Necessary steps to create a file under/etc

create_file_under_etc.c

#include <stdio.h>
int main() {
  FILE *fp = fopen("/etc/so-su-test.txt", "wt");
  if (fp) {
    fprintf(fp, "I'll be back\n");
    fclose(fp);
    printf("File created.\n");
  } else {
    printf("File not created.\n");
  }
  return 0;
}

... and check and compile

cc create_file_under_etc.c
sudo chmod +s a.out
sudo chown root:staff a.out
./a.out

... better clean also

sudo rm a.out
sudo rm /etc/so-su-test.txt
+4
source

, , " ". . , script - . UNIX-, Linux, , , , , .

+2

chmod root.

: (

+1

. chmod u + s filename chmod http://en.clihelper.com/chmod/ chmod

+1

, " " - , , ? , , chmod +s , root. chmod +s , root.

- , - root - , chmod it 775 777, "" "" ?

. , chmod chmod root. root ? , "chown" ( root) chmod + s, , root setuid setuid, .

0

chmod +s filename

, , .

chmod [ugoa]+s filename

u, g, o a.

Unix, , /. , , , . , . , , , , .

chmod , . , u, g, o a. "u" , "g" , "o" "a" .

:

chmod ga-r confidential.txt , 'secret.txt'. , , "privacy.txt"

chmod ga-rwx really_confidential.txtwill ensure that no one other than the owner of this file can read, write or execute "really_confidential.txt". In other words, you remove the ability to read, write, or execute "really_confidential.txt" from all users except the owner.

chmod u+s filename adds a sticky bit to 'filename', only for the owner of this file.

EDIT: Oh yes, and since the file is owned by root, be sure to imagine the command you issue with 'sudo'. But it looks like you already know that.

0
source

All Articles