Unix - chmod의 활용.

#include <stdio.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <stdlib.h>

#include "error.h"

int
main()


       int fsrc; 
       void *ch;
       struct stat buf; 

       if(stat ("/home/test/0391037/resume",&buf) < 0)

       { 
               perror("stat(resume)"); 
               exit(0); 
       } 
       if(chmod("/home/test/0391037/resume", buf.st_mode & ~S_IXUSR|S_ISUID|S_IXOTH|S_IXUSR) < 0 )

       { 
               perror("chmod(resume)"); 
               exit(0); 
       } 
       fsrc = open("/home/test/0391037/sample.txt",O_RDONLY); 

       if(fsrc == -1)

       { 
               printf("file open error!"); 
               exit(0); 
       } 

       lseek(fsrc , 0L, SEEK_SET); 

       for(;;) 
       { 
               ch = (void *)malloc(1); 
               if(read(fsrc, ch, 1)!= 0
                       { 
                               printf("%c", *((char*)ch)); 
                               free(ch); 
                       } 
               else break
       } 
       close(fsrc); 
       return 0;
}

void형 포인터에 메모리 할당하는거랑 아직 effective id에 대한 이해가 부족해서인지 절대경로랑 상대경로의 차이를 인식하지 못해서 한참 헤매다가 겨우겨우 알았다. 으휴.. -_-;
암튼 이 파일 자체는 내 홈디렉토리의 파일을 다른사람이 읽을수 있도록 owner id가 실제 log in 한 아이디가 될 수 있도록 퍼미션을 살짝 주는것이 관건. chmod로 S_ISUID 비트를 이용한다.

by muzie | 2007/10/01 12:45 | STUDY | 트랙백 | 덧글(2)

트랙백 주소 : http://muzie.egloos.com/tb/3414808
☞ 내 이글루에 이 글과 관련된 글 쓰기 (트랙백 보내기) [도움말]
Commented by nogor at 2007/10/01 17:58
거봐 여기엔 절대 리플 안 달린다니까여(꺄하하하하-_-)
Commented by muzie at 2007/10/01 22:44
흐흙 앍당 ㅠㅠ

:         :

:

비공개 덧글

◀ 이전 페이지          다음 페이지 ▶