OSDN Git Service

[Fix/Feature] 飛行モンスターが深い穴を超えられない現象を解消 #177
[hengbandforosx/hengbandosx.git] / src / io / uid-checker.cpp
1 #include "io/uid-checker.h"
2 #ifdef SET_UID
3 #ifdef SAFE_SETUID
4 #ifdef SAFE_SETUID_POSIX
5 #include "util.h"
6 #endif
7 #endif
8 #endif
9
10 /*!
11  * @brief ファイルのドロップパーミッションチェック / Hack -- drop permissions
12  */
13 void safe_setuid_drop(void)
14 {
15 #ifdef SET_UID
16 #ifdef SAFE_SETUID
17 #ifdef SAFE_SETUID_POSIX
18
19     if (setuid(getuid()) != 0) {
20         quit(_("setuid(): 正しく許可が取れません!", "setuid(): cannot set permissions correctly!"));
21     }
22     if (setgid(getgid()) != 0) {
23         quit(_("setgid(): 正しく許可が取れません!", "setgid(): cannot set permissions correctly!"));
24     }
25 #else
26     if (setreuid(geteuid(), getuid()) != 0) {
27         quit(_("setreuid(): 正しく許可が取れません!", "setreuid(): cannot set permissions correctly!"));
28     }
29     if (setregid(getegid(), getgid()) != 0) {
30         quit(_("setregid(): 正しく許可が取れません!", "setregid(): cannot set permissions correctly!"));
31     }
32 #endif
33 #endif
34 #endif
35 }
36
37 /*!
38  * @brief ファイルのグラブパーミッションチェック / Hack -- grab permissions
39  */
40 void safe_setuid_grab(player_type *player_ptr)
41 {
42 #ifdef SET_UID
43 #ifdef SAFE_SETUID
44 #ifdef SAFE_SETUID_POSIX
45
46     if (setuid(player_ptr->player_egid) != 0) {
47         quit(_("setuid(): 正しく許可が取れません!", "setuid(): cannot set permissions correctly!"));
48     }
49     if (setgid(player_ptr->player_egid) != 0) {
50         quit(_("setgid(): 正しく許可が取れません!", "setgid(): cannot set permissions correctly!"));
51     }
52 #else
53     (void)player_ptr;
54
55     if (setreuid(geteuid(), getuid()) != 0) {
56         quit(_("setreuid(): 正しく許可が取れません!", "setreuid(): cannot set permissions correctly!"));
57     }
58     if (setregid(getegid(), getgid()) != 0) {
59         quit(_("setregid(): 正しく許可が取れません!", "setregid(): cannot set permissions correctly!"));
60     }
61 #endif
62 #endif
63 #else
64     (void)player_ptr;
65 #endif
66 }