diff options
-rw-r--r-- | src/common.c | 4 | ||||
-rw-r--r-- | src/common.h | 9 | ||||
-rw-r--r-- | src/main.c | 3 |
3 files changed, 7 insertions, 9 deletions
diff --git a/src/common.c b/src/common.c index 241d2fd..12f0ae7 100644 --- a/src/common.c +++ b/src/common.c @@ -63,13 +63,13 @@ int comparetimespec(t1, t2) return 0; } -#ifndef HAVE_CONF_CAP - void save_uids(void){ /* 這個一定要先執行,不然預設 uid 就是 0 */ procrealuid = getuid(); proceffuid = geteuid(); } +#ifndef HAVE_CONF_CAP + void disable_setuid(void){ #ifdef _POSIX_SAVED_IDS seteuid(procrealuid); diff --git a/src/common.h b/src/common.h index ca1f5f2..5d45377 100644 --- a/src/common.h +++ b/src/common.h @@ -9,19 +9,16 @@ void checktimespec(struct timespec*); void difftimespec(const struct timespec*, const struct timespec*, struct timespec*); int comparetimespec(const struct timespec*, const struct timespec*); - +void save_uids(void); /* 這個一定要先執行,不然預設 uid 就是 0 */ #ifndef HAVE_CONF_CAP -void save_uids(void); /* 這個一定要先執行,不然預設 uid 就是 0 */ void disable_setuid(void); void enable_setuid(void); #endif -#ifndef _POSIX_SAVED_IDS -/* 避免 disable_setuid() 之後 getuid() 得到錯誤的值,所以用這個變數來取代 */ +/* 避免 disable_setuid() 之後 getuid() 得到錯誤的值,所以用這些變數把最初的 + * UID 給記下來!*/ extern uid_t procrealuid; extern uid_t proceffuid; -#endif - #endif @@ -83,10 +83,11 @@ int main(int argc, char* argv[]){ struct group* grinfo; #endif + save_uids(); + #ifndef HAVE_CONF_CAP /* 即使有 setuid root,還是不能讓每個使用者拿到 root 權限 * 所以說只有在 fork 的時候才要把這個權限開起來,其他就關掉吧 */ - save_uids(); disable_setuid(); #endif |