srogue: improve privilege handling.

Setgid privileges are now dropped when not required.  restore() is now
less complex.
This commit is contained in:
John "Elwin" Edwards 2015-08-01 16:23:24 -04:00
parent bc5b26fece
commit 2e4f161e40
2 changed files with 3 additions and 45 deletions

View file

@ -121,7 +121,7 @@ char **envp;
#endif #endif
if (!use_savedir) if (!use_savedir)
md_droppriv(); md_normaluser();
/* get home and options from environment */ /* get home and options from environment */

View file

@ -131,17 +131,13 @@ game_err(int a)
/* /*
* dosave: * dosave:
* Set UID back to user and save the game * Save the game. UID/GID no longer get reset here.
*/ */
dosave() dosave()
{ {
FILE *savef; FILE *savef;
ignore(); ignore();
if (!use_savedir)
{
md_resetpriv();
}
umask(022); umask(022);
if (file_name[0] != '\0') { if (file_name[0] != '\0') {
@ -287,51 +283,13 @@ char *file, **envp;
#endif #endif
if (!wizard) if (!wizard)
{ {
#if defined(HAVE_WORKING_FORK) if (unlink(file) < 0)
{
endwin(); endwin();
if (!use_savedir)
{
while((pid = fork()) < 0)
sleep(1);
/* set id to unlink file */
if(pid == 0)
{
md_resetpriv();
unlink(file);
exit(0);
}
/* wait for unlink to finish */
else
{
while(wait(&ret_status) != pid)
continue;
if (ret_status < 0)
{
printf("Cannot unlink file\n"); printf("Cannot unlink file\n");
return FALSE; return FALSE;
} }
} }
}
else
{
/* Don't drop privileges, they're needed
* for the unlink. */
if (unlink(file) < 0)
{
printf("Cannot unlink file\n");
return FALSE;
}
}
#else
if (unlink(file) < 0)
{
printf("Cannot unlink file\n");
return FALSE;
}
#endif
}
if (him->s_hpt <= 0) { if (him->s_hpt <= 0) {
endwin(); endwin();