513 |
|
} |
514 |
|
|
515 |
|
int sg_drop_privileges() { |
516 |
+ |
#ifdef HAVE_SETEGID |
517 |
|
if (setegid(getgid()) != 0) { |
518 |
+ |
#elif defined(HAVE_SETRESGID) |
519 |
+ |
if (setresgid(getgid(), getgid(), getgid()) != 0) { |
520 |
+ |
#else |
521 |
+ |
{ |
522 |
+ |
#endif |
523 |
|
sg_set_error_with_errno(SG_ERROR_SETEGID, NULL); |
524 |
|
return -1; |
525 |
|
} |
526 |
+ |
#ifdef HAVE_SETEUID |
527 |
|
if (seteuid(getuid()) != 0) { |
528 |
+ |
#elif defined(HAVE_SETRESUID) |
529 |
+ |
if (setresuid(getuid(), getuid(), getuid()) != 0) { |
530 |
+ |
#else |
531 |
+ |
{ |
532 |
+ |
#endif |
533 |
|
sg_set_error_with_errno(SG_ERROR_SETEUID, NULL); |
534 |
|
return -1; |
535 |
|
} |
545 |
|
return tmp; |
546 |
|
} |
547 |
|
|
548 |
+ |
/* If we don't have a GNU compatible realloc, fake it. */ |
549 |
+ |
#if HAVE_REALLOC == 0 |
550 |
+ |
void *rpl_realloc(void *ptr, size_t size) { |
551 |
+ |
if (ptr == NULL && size == 0) { |
552 |
+ |
return NULL; |
553 |
+ |
} |
554 |
+ |
|
555 |
+ |
if (size == 0) { |
556 |
+ |
free(ptr); |
557 |
+ |
return NULL; |
558 |
+ |
} |
559 |
+ |
|
560 |
+ |
if (ptr == NULL) { |
561 |
+ |
return malloc(size); |
562 |
+ |
} |
563 |
+ |
|
564 |
+ |
#undef realloc |
565 |
+ |
return realloc(ptr, size); |
566 |
+ |
#define realloc rpl_realloc |
567 |
+ |
} |
568 |
+ |
#endif |