입니다. 사용자가 sshfs에서 /를 사용하여 디렉토리를 마운트 할 수있는 프로그램을 작성하고 있습니다. 다음은 오류 처리 및 상용구가 생략 된 기본 레이아웃입니다.자식 프로세스가 루트로 설정해야합니다. 부모는
uid_t euid, ruid;
void mountDir(char *dirname, char *hostname){
childPid = fork();
if(childPid == 0){
char *sshfsArgs[6] = {"/usr/bin/sshfs", hostName, /*Other args*/};
seteuid(euid);
execv(sshfsArgs[0], sshfsArgs);
//I want to drop my setuid permissions with seteuid(ruid),
//but execv doesn't return.
}else{ //I'm the parent process.
//I don't want to have root permissions now.
wait(childPid);
}
}
void main(int argc, char **argv){
ruid = getuid();
euid = geteuid();
seteuid(ruid); //Drop the root permissions.
char **hostList = {"bulb.example.com", "char.example.com", argv[1]};
char * hostName = pickHost(hostList); //Pings them and picks one that responds.
mountDir("/net/home", hostName);
mountDir("/net/projects", hostName);
}
다시 오류 검사가 생략되었습니다. sshfs
을 실행할 때만 루트 권한을 갖고 싶습니다. fork()
을 호출하기 전에 seteuid
권한을 삭제하는 몇 가지 예가 있지만 여기서는 자식 프로세스에서만 이러한 권한을 얻고 싶습니다. execv
후에 바로 그 권한을 잃고 싶습니다. 어떻게하면 안전하게 처리 할 수 있습니까? 자식 프로세스가 루트로 seteuid
을 수행하면 어떻게됩니까? 상위 프로세스가 루트 권한을 얻습니까?