--- projects/libstatgrab/src/libstatgrab/tools.c 2004/07/18 21:30:12 1.56 +++ projects/libstatgrab/src/libstatgrab/tools.c 2004/11/01 18:30:17 1.57 @@ -18,7 +18,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA * 02111-1307 USA * - * $Id: tools.c,v 1.56 2004/07/18 21:30:12 ats Exp $ + * $Id: tools.c,v 1.57 2004/11/01 18:30:17 tdb Exp $ */ #ifdef HAVE_CONFIG_H @@ -513,11 +513,23 @@ int sg_init(){ } int sg_drop_privileges() { +#ifdef HAVE_SETEGID if (setegid(getgid()) != 0) { +#elif defined(HAVE_SETRESGID) + if (setresgid(getgid(), getgid(), getgid()) != 0) { +#else + { +#endif sg_set_error_with_errno(SG_ERROR_SETEGID, NULL); return -1; } +#ifdef HAVE_SETEUID if (seteuid(getuid()) != 0) { +#elif defined(HAVE_SETRESUID) + if (setresuid(getuid(), getuid(), getuid()) != 0) { +#else + { +#endif sg_set_error_with_errno(SG_ERROR_SETEUID, NULL); return -1; } @@ -533,3 +545,24 @@ void *sg_realloc(void *ptr, size_t size) { return tmp; } +/* If we don't have a GNU compatible realloc, fake it. */ +#if HAVE_REALLOC == 0 +void *rpl_realloc(void *ptr, size_t size) { + if (ptr == NULL && size == 0) { + return NULL; + } + + if (size == 0) { + free(ptr); + return NULL; + } + + if (ptr == NULL) { + return malloc(size); + } + +#undef realloc + return realloc(ptr, size); +#define realloc rpl_realloc +} +#endif