Hi there!

I am a student studying computer science.

시스템 프로그래밍

시스템 프로그래밍 3장 - System call : File I/O Permission, ID

만능성구 2020. 5. 5. 13:51
728x90

파일 권한 속성


접근권한을 수정 or 확인하기 위해서 process id가 필요하다.

#include <sys/types.h>
#include <unistd.h>

uid_t getuid(void) // process creator’s uid
user id를 가져올 수 있는 syscall
return user id / -1
#include <sys/types.h>
#include <unistd.h>

uid_t getgid(void) // process creator’s uid
group id를 가져올 수 있는 syscall
return group id / -1
uid_t geteuid(void);

effective user id를 가져올 수 있는 syscall

kernel의 protection system에 대한 key값이다.

일반적으로 uid가 euid 같지만 dynamic protection system을 위해서 다른 경우가 있다.

return effective user id / -1
uid_t getegid(void);
effective group id를 가져올 수 있는 syscall
return effective group id / -1

File's ID

- user id에 의해서 file의 owner id가 결정된다. 

- process가 생성되면 user id가 할당된다.

- uid가 다른 경우 euid가 설정된다 // 일반적이지 않음

 

monut

시스템에 외부장치나 stroge장치 를 장착하는 system utility이다.

접근 권한이 없더라도 순간 접근할 수 있도록 해준다. 

how to?

chmod u+s a.out

chmod g+s a.out

특수 접근 권한 설정

Sticky bit

- 어떤 directory에 대해서 설정해줄 수 있는 bit

- 해당 directory은 모든 user가 접근할 수 있게 만들어준다.

- 자신이 생성하지 않은 파일을 접근은 가능하지만 지울 수는 없다.


프로세서 접근 권한

File access (read/write/execute) is allowed in the following cases

• if the effective UID of the process is 0 (supervisor)

• if the effective UID of the process is equal to that of file owner, and if the access permission bit of owner is SET

• if the effective GID of the process is equal to that of file owner, and if the access permission bit of group is SET

• if other’s access permission bit is SET


file 접근과 권한된 system call

#include<unistd.h>

int access(const char *path, int amode);
현재 file의 access권한 check하는 system call

path : path name

amode : access mode for the process to check 체크하고 싶은 access mode

- R_OK : READ permission check

- W_OK : WRITE permission check

- X_OK  : Execute or Exploration permission check

- F_OK : File existence check

return 0 / -1
#include<sys/types.h>
#include<sys/stat.h>

mode_t umask(mode_t cmask); 

file의 기본 permission 반대로 설정하는 system call

설정하지 않으면 기본적으로 0666으로 설정 dir은 0777

cmask : new umask
return 이전 umask

umask의 mode에 관한 Macro

#include<sys/types.h>
#include<sys/stat.h>

int chmod(const char *path, mode_t mode);
int fchmod(int fd, mode_t mode); 
file의 접근 권한을 변경해주는 system call

path : 1. file 이름 / 2. file descriptot

mode : 값

return 0 / -1

Ownership change

#include <unistd.h>
#include <sys/types.h>

int chown(const char *path, uid_t owner, gid_t group);
int lchown(const char *path, uid_t owner, gid_t group);
// doesn’t follow links
int fchown(int fd, uid_t owner, gid_t group);
특정 file에 대한 user(owner) 설정

특정 file에 대한 user 설정

일반 file일 경우 동일

symbolic link file의 경우

symbolic link의 자체에 대한

특정 file에 대한 user 설정

path : 파일 이름, 

owner : user id

group : group id

path : 파일 이름

owner : user id

group : group id

path : file descriptor

owner : user id

group : group id

return 0 / -1
728x90