srogue: add and use more md_* portable functions.
Privileges and memory usage checks are now more portable.
This commit is contained in:
parent
791df4324f
commit
b9cc9cf3a7
6 changed files with 74 additions and 22 deletions
|
|
@ -413,6 +413,16 @@ md_getuid(void)
|
|||
#endif
|
||||
}
|
||||
|
||||
gid_t
|
||||
md_getgid(void)
|
||||
{
|
||||
#ifdef HAVE_GETGID
|
||||
return( getgid() );
|
||||
#else
|
||||
return(42);
|
||||
#endif
|
||||
}
|
||||
|
||||
pid_t
|
||||
md_getpid(void)
|
||||
{
|
||||
|
|
@ -1509,3 +1519,51 @@ md_stop_checkout_timer(void)
|
|||
|
||||
#endif
|
||||
|
||||
long
|
||||
md_memused(void)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
MEMORYSTATUS stat;
|
||||
|
||||
GlobalMemoryStatus(&stat);
|
||||
|
||||
return((long)stat.dwTotalPageFile);
|
||||
#else
|
||||
return( (long)sbrk(0) );
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
md_droppriv(void)
|
||||
{
|
||||
#if defined(HAVE_GETUID)
|
||||
uid_t realuid = getuid();
|
||||
|
||||
#if defined(HAVE_SETRESUID)
|
||||
if (setresuid(-1, realuid, realuid) != 0) {
|
||||
#elif defined (HAVE_SETREUID)
|
||||
if (setreuid(realuid, realuid) != 0) {
|
||||
#elif defined (HAVE_SETUID)
|
||||
if (setuid(realuid) != 0) {
|
||||
#else
|
||||
if (0) {
|
||||
#endif
|
||||
printf("Cannot change to effective uid: %d\n", realuid);
|
||||
exit(1);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
extern uid_t playuid;
|
||||
extern gid_t playgid;
|
||||
|
||||
void
|
||||
md_resetpriv(void)
|
||||
{
|
||||
#if defined (HAVE_SETUID)
|
||||
setuid(playuid);
|
||||
#endif
|
||||
#if defined (HAVE_SETGID)
|
||||
setgid(playgid);
|
||||
#endif
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue