|
Lines 50-55
union semun
Link Here
|
| 50 |
#include <sys/utsname.h> |
50 |
#include <sys/utsname.h> |
| 51 |
#include <sys/systeminfo.h> |
51 |
#include <sys/systeminfo.h> |
| 52 |
#endif |
52 |
#endif |
|
|
53 |
#if defined(LINUX) |
| 54 |
#include <sys/capability.h> |
| 55 |
#endif |
| 53 |
#include "slap.h" |
56 |
#include "slap.h" |
| 54 |
#include "slapi-plugin.h" |
57 |
#include "slapi-plugin.h" |
| 55 |
#include "prinit.h" |
58 |
#include "prinit.h" |
|
Lines 366-371
fix_ownership(void)
Link Here
|
| 366 |
} |
369 |
} |
| 367 |
} |
370 |
} |
| 368 |
|
371 |
|
|
|
372 |
#ifdef LINUX |
| 373 |
/* |
| 374 |
* Drops the CAP_NET_BIND_SERVICE capability |
| 375 |
*/ |
| 376 |
static int |
| 377 |
main_drop_caps() |
| 378 |
{ |
| 379 |
cap_t caps; |
| 380 |
const cap_value_t cap_list[1] = { CAP_NET_BIND_SERVICE }; |
| 381 |
caps = cap_get_proc(); |
| 382 |
if (caps == NULL) { |
| 383 |
int oserr = errno; |
| 384 |
slapi_log_err(SLAPI_LOG_ERR, "main_setuid", "cap_get_proc() == NULL, error %d (%s)\n", |
| 385 |
oserr, slapd_system_strerror(oserr)); |
| 386 |
return -1; |
| 387 |
} |
| 388 |
|
| 389 |
if ( |
| 390 |
cap_set_flag(caps, CAP_EFFECTIVE, sizeof(cap_list) / sizeof(cap_value_t), cap_list, CAP_SET) == -1 || |
| 391 |
cap_set_flag(caps, CAP_PERMITTED, sizeof(cap_list) / sizeof(cap_value_t), cap_list, CAP_SET) == -1 || |
| 392 |
cap_set_flag(caps, CAP_INHERITABLE, sizeof(cap_list) / sizeof(cap_value_t), cap_list, CAP_SET) == -1) { |
| 393 |
int oserr = errno; |
| 394 |
slapi_log_err(SLAPI_LOG_ERR, "main_setuid", "cap_set_flag() == -1, error %d (%s)\n", |
| 395 |
oserr, slapd_system_strerror(oserr)); |
| 396 |
return -1; |
| 397 |
} |
| 398 |
|
| 399 |
if (cap_set_proc(caps) == -1) { |
| 400 |
int oserr = errno; |
| 401 |
slapi_log_err(SLAPI_LOG_ERR, "main_setuid", "cap_set_proc() == -1, error %d (%s)\n", |
| 402 |
oserr, slapd_system_strerror(oserr)); |
| 403 |
return -1; |
| 404 |
} |
| 405 |
|
| 406 |
if (cap_free(caps) == -1) { |
| 407 |
int oserr = errno; |
| 408 |
slapi_log_err(SLAPI_LOG_ERR, "main_setuid", "cap_free() == -1, error %d (%s)\n", |
| 409 |
oserr, slapd_system_strerror(oserr)); |
| 410 |
return -1; |
| 411 |
} |
| 412 |
|
| 413 |
return 0; |
| 414 |
} |
| 415 |
#endif |
| 416 |
|
| 369 |
/* Changes identity to the named user |
417 |
/* Changes identity to the named user |
| 370 |
* If username == NULL, does nothing. |
418 |
* If username == NULL, does nothing. |
| 371 |
* Does nothing on NT regardless. |
419 |
* Does nothing on NT regardless. |
|
Lines 373-378
fix_ownership(void)
Link Here
|
| 373 |
static int |
421 |
static int |
| 374 |
main_setuid(char *username) |
422 |
main_setuid(char *username) |
| 375 |
{ |
423 |
{ |
|
|
424 |
#ifdef LINUX |
| 425 |
if( geteuid() != 0 ) |
| 426 |
{ |
| 427 |
/* |
| 428 |
* Port binding must have happened using capabilities. So skip the |
| 429 |
* priv drop below and drop the CAP_NET_BIND_SERVICE capability instead |
| 430 |
*/ |
| 431 |
return main_drop_caps(); |
| 432 |
} |
| 433 |
#endif |
| 434 |
|
| 376 |
if (username != NULL) { |
435 |
if (username != NULL) { |
| 377 |
struct passwd *pw; |
436 |
struct passwd *pw; |
| 378 |
/* Make sure everything in the log and config directory |
437 |
/* Make sure everything in the log and config directory |