|
29 | 29 | * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
|
30 | 30 | * Portions Copyright (c) 1994, Regents of the University of California
|
31 | 31 | *
|
32 |
| - * $Id: pqcomm.c,v 1.108 2000/10/23 14:48:50 momjian Exp $ |
| 32 | + * $Id: pqcomm.c,v 1.109 2000/11/01 21:14:01 petere Exp $ |
33 | 33 | *
|
34 | 34 | *-------------------------------------------------------------------------
|
35 | 35 | */
|
|
63 | 63 | #include <signal.h>
|
64 | 64 | #include <errno.h>
|
65 | 65 | #include <fcntl.h>
|
| 66 | +#include <grp.h> |
66 | 67 | #include <unistd.h>
|
67 | 68 | #include <sys/types.h>
|
68 | 69 | #include <sys/stat.h>
|
|
84 | 85 | #endif
|
85 | 86 |
|
86 | 87 |
|
| 88 | +/* |
| 89 | + * Configuration options |
| 90 | + */ |
| 91 | +int Unix_socket_permissions; |
| 92 | +char * Unix_socket_group; |
| 93 | + |
| 94 | + |
87 | 95 | /*
|
88 | 96 | * Buffers for low-level I/O
|
89 | 97 | */
|
@@ -295,8 +303,60 @@ StreamServerPort(int family, unsigned short portName, int *fdP)
|
295 | 303 | */
|
296 | 304 |
|
297 | 305 | *fdP = fd;
|
| 306 | + |
298 | 307 | if (family == AF_UNIX)
|
299 |
| - chmod(sock_path, 0777); |
| 308 | + { |
| 309 | + Assert(Unix_socket_group); |
| 310 | + if (Unix_socket_group[0] != '\0') |
| 311 | + { |
| 312 | + char *endptr; |
| 313 | + unsigned long int val; |
| 314 | + gid_t gid; |
| 315 | + |
| 316 | + val = strtoul(Unix_socket_group, &endptr, 10); |
| 317 | + if (*endptr == '\0') |
| 318 | + { |
| 319 | + /* numeric group id */ |
| 320 | + gid = val; |
| 321 | + } |
| 322 | + else |
| 323 | + { |
| 324 | + /* convert group name to id */ |
| 325 | + struct group *gr; |
| 326 | + |
| 327 | + gr = getgrnam(Unix_socket_group); |
| 328 | + if (!gr) |
| 329 | + { |
| 330 | + snprintf(PQerrormsg, PQERRORMSG_LENGTH, |
| 331 | + "FATAL: no such group '%s'\n", |
| 332 | + Unix_socket_group); |
| 333 | + fputs(PQerrormsg, stderr); |
| 334 | + pqdebug("%s", PQerrormsg); |
| 335 | + return STATUS_ERROR; |
| 336 | + } |
| 337 | + gid = gr->gr_gid; |
| 338 | + } |
| 339 | + if (chown(sock_path, -1, gid) == -1) |
| 340 | + { |
| 341 | + snprintf(PQerrormsg, PQERRORMSG_LENGTH, |
| 342 | + "FATAL: could not set group of %s: %s\n", |
| 343 | + sock_path, strerror(errno)); |
| 344 | + fputs(PQerrormsg, stderr); |
| 345 | + pqdebug("%s", PQerrormsg); |
| 346 | + return STATUS_ERROR; |
| 347 | + } |
| 348 | + } |
| 349 | + |
| 350 | + if (chmod(sock_path, Unix_socket_permissions) == -1) |
| 351 | + { |
| 352 | + snprintf(PQerrormsg, PQERRORMSG_LENGTH, |
| 353 | + "FATAL: could not set permissions on %s: %s\n", |
| 354 | + sock_path, strerror(errno)); |
| 355 | + fputs(PQerrormsg, stderr); |
| 356 | + pqdebug("%s", PQerrormsg); |
| 357 | + return STATUS_ERROR; |
| 358 | + } |
| 359 | + } |
300 | 360 | return STATUS_OK;
|
301 | 361 | }
|
302 | 362 |
|
|
0 commit comments