Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shelestov lab3 #694

Open
wants to merge 1 commit into
base: irtegov/accepted
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions 23213/k.shelestov/lab3/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
all: lab3.out file

file:
touch file
chmod 600 file

lab3.out: lab3.c
cc lab3.c -v -o lab3.out
chmod u+s lab3.out
37 changes: 37 additions & 0 deletions 23213/k.shelestov/lab3/lab3.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>

int main(){

uid_t real_id = getuid();
uid_t effective_id = geteuid();

printf("real id: %d\n effective id: %d\n", real_id, effective_id);

FILE* file = fopen("file", "r");
if (file == NULL){
perror("Error while opening file");
}
else{
fclose(file);
}

if (setuid(real_id) == -1)
perror("Error setting id");

effective_id = geteuid();

printf("real id: %d\n effective id: %d\n", real_id, effective_id);

file = fopen("file", "r");
if (file == NULL){
perror("Error while opening file");
}
else{
fclose(file);
}

return 0;
}