am 191fe44c: Merge "run-as: Don\'t require CAP_DAC_READ_SEARCH"

* commit '191fe44c972e7f45f4bac1cee27522ae244da498':
  run-as: Don't require CAP_DAC_READ_SEARCH
This commit is contained in:
Nick Kralevich 2013-03-29 10:00:56 -07:00 committed by Android Git Automerger
commit a56b0b97dd
1 changed files with 18 additions and 1 deletions

View File

@ -80,13 +80,30 @@ map_file(const char* filename, size_t* filesize)
struct stat st;
size_t length = 0;
void* address = NULL;
gid_t oldegid;
*filesize = 0;
/*
* Temporarily switch effective GID to allow us to read
* the packages file
*/
oldegid = getegid();
if (setegid(AID_SYSTEM) < 0) {
return NULL;
}
/* open the file for reading */
fd = TEMP_FAILURE_RETRY(open(filename, O_RDONLY));
if (fd < 0)
if (fd < 0) {
return NULL;
}
/* restore back to our old egid */
if (setegid(oldegid) < 0) {
goto EXIT;
}
/* get its size */
ret = TEMP_FAILURE_RETRY(fstat(fd, &st));