|
13 | 13 | *
|
14 | 14 | *
|
15 | 15 | * IDENTIFICATION
|
16 |
| - * $Header: /cvsroot/pgsql/src/backend/main/main.c,v 1.42 2001/03/22 03:59:30 momjian Exp $ |
| 16 | + * $Header: /cvsroot/pgsql/src/backend/main/main.c,v 1.43 2001/04/21 18:29:29 tgl Exp $ |
17 | 17 | *
|
18 | 18 | *-------------------------------------------------------------------------
|
19 | 19 | */
|
@@ -103,22 +103,46 @@ main(int argc, char *argv[])
|
103 | 103 | */
|
104 | 104 |
|
105 | 105 | /*
|
106 |
| - * Make sure we are not running as root. |
107 |
| - * |
108 |
| - * BeOS currently runs everything as root :-(, so this check must be |
109 |
| - * temporarily disabled there... |
| 106 | + * Skip permission checks if we're just trying to do --help or --version; |
| 107 | + * otherwise root will get unhelpful failure messages from initdb. |
110 | 108 | */
|
111 |
| -#ifndef __BEOS__ |
112 | 109 | if (!(argc > 1
|
113 |
| - && (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0 |
114 |
| - || strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)) |
115 |
| - && (geteuid() == 0)) |
| 110 | + && (strcmp(argv[1], "--help") == 0 || |
| 111 | + strcmp(argv[1], "-?") == 0 || |
| 112 | + strcmp(argv[1], "--version") == 0 || |
| 113 | + strcmp(argv[1], "-V") == 0))) |
116 | 114 | {
|
117 |
| - fprintf(stderr, "%s", NOROOTEXEC); |
118 |
| - exit(1); |
119 |
| - } |
| 115 | + /* |
| 116 | + * Make sure we are not running as root. |
| 117 | + * |
| 118 | + * BeOS currently runs everything as root :-(, so this check must be |
| 119 | + * temporarily disabled there... |
| 120 | + */ |
| 121 | +#ifndef __BEOS__ |
| 122 | + if (geteuid() == 0) |
| 123 | + { |
| 124 | + fprintf(stderr, "%s", NOROOTEXEC); |
| 125 | + exit(1); |
| 126 | + } |
120 | 127 | #endif /* __BEOS__ */
|
121 | 128 |
|
| 129 | + /* |
| 130 | + * Also make sure that real and effective uids are the same. |
| 131 | + * Executing Postgres as a setuid program from a root shell is a |
| 132 | + * security hole, since on many platforms a nefarious subroutine could |
| 133 | + * setuid back to root if real uid is root. (Since nobody actually |
| 134 | + * uses Postgres as a setuid program, trying to actively fix this |
| 135 | + * situation seems more trouble than it's worth; we'll just expend the |
| 136 | + * effort to check for it.) |
| 137 | + */ |
| 138 | + if (getuid() != geteuid()) |
| 139 | + { |
| 140 | + fprintf(stderr, "%s: real and effective userids must match\n", |
| 141 | + argv[0]); |
| 142 | + exit(1); |
| 143 | + } |
| 144 | + } |
| 145 | + |
122 | 146 | /*
|
123 | 147 | * Set up locale information from environment, in only the categories
|
124 | 148 | * needed by Postgres; leave other categories set to default "C".
|
@@ -162,7 +186,8 @@ main(int argc, char *argv[])
|
162 | 186 | pw = getpwuid(geteuid());
|
163 | 187 | if (pw == NULL)
|
164 | 188 | {
|
165 |
| - fprintf(stderr, "%s: invalid current euid", argv[0]); |
| 189 | + fprintf(stderr, "%s: invalid current euid %d\n", |
| 190 | + argv[0], (int) geteuid()); |
166 | 191 | exit(1);
|
167 | 192 | }
|
168 | 193 | /* Allocate new memory because later getpwuid() calls can overwrite it */
|
|
0 commit comments