diff options
author | LAN-TE <lantw44@gmail.com> | 2012-11-12 17:25:43 +0800 |
---|---|---|
committer | LAN-TE <lantw44@gmail.com> | 2012-11-12 17:25:43 +0800 |
commit | dd395f346b69a124608e22b64322c1f1d94e0df3 (patch) | |
tree | 7127a2bf4d93ef8d629607a8f160b2ed815dcc30 | |
parent | d7f706956e0c4914879d2d08c24227ba0bb6ef0f (diff) | |
download | sctjudge-dd395f346b69a124608e22b64322c1f1d94e0df3.tar.gz sctjudge-dd395f346b69a124608e22b64322c1f1d94e0df3.tar.zst sctjudge-dd395f346b69a124608e22b64322c1f1d94e0df3.zip |
修正 save_uids() 和 UID 相關變數的宣告
由於要避免使用 getuid(),相關宣告不再是僅限 --disable-cap 的狀況才需要,現在不
論是哪種情況,因為都要檢查 UID,所以一定需要這些東西。
-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 |