rolling back r14887, #2884 as it caused regressions in debbuilder
This commit is contained in:
parent
03f3185b1c
commit
32c344ffdd
|
@ -31,6 +31,9 @@
|
|||
#include "rospack/rospack.h"
|
||||
|
||||
#include <stdexcept>
|
||||
#if !defined(WIN32)
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
|
@ -41,6 +44,27 @@ int main(int argc, char **argv)
|
|||
return 0;
|
||||
}
|
||||
|
||||
#if !defined(WIN32)
|
||||
// If it looks we're running under sudo, try to drop back to the normal
|
||||
// user, to avoid writing the cache with inappropriate permissions,
|
||||
// #2884.
|
||||
// Do the group first, because we can't do it after changing the user.
|
||||
char* sudo_gid_string = getenv("SUDO_GID");
|
||||
if(sudo_gid_string)
|
||||
{
|
||||
gid_t sudo_gid = (int)strtol(sudo_gid_string, (char **)NULL, 10);
|
||||
if(setgid(sudo_gid))
|
||||
perror("[rospack] Failed to change GID; cache permissions may need to be adjusted manually. setgid()");
|
||||
}
|
||||
char* sudo_uid_string = getenv("SUDO_UID");
|
||||
if(sudo_uid_string)
|
||||
{
|
||||
uid_t sudo_uid = (int)strtol(sudo_uid_string, (char **)NULL, 10);
|
||||
if(setuid(sudo_uid))
|
||||
perror("[rospack] Failed to change UID; cache permissions may need to be adjusted manually. setuid()");
|
||||
}
|
||||
#endif
|
||||
|
||||
int ret;
|
||||
bool quiet;
|
||||
try
|
||||
|
|
|
@ -42,8 +42,6 @@
|
|||
#include <dirent.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/types.h>
|
||||
#include <pwd.h>
|
||||
#endif
|
||||
#include <stdexcept>
|
||||
#include <time.h>
|
||||
|
@ -1580,15 +1578,7 @@ string ROSPack::getCachePath()
|
|||
cache_file_name = dotros + "\\rospack_cache";
|
||||
}
|
||||
#else // UNIX
|
||||
// Get the user's home directory by looking up the password entry based
|
||||
// on UID. If that doesn't work, we fall back on examining $HOME,
|
||||
// knowing that that can cause trouble when mixed with sudo (#2884).
|
||||
struct passwd* passwd_ent;
|
||||
// Look up based on effective UID, just in case we got here by set-uid
|
||||
if((passwd_ent = getpwuid(geteuid())))
|
||||
ros_home = passwd_ent->pw_dir;
|
||||
else
|
||||
ros_home = getenv("HOME");
|
||||
ros_home = getenv("HOME");
|
||||
if (ros_home)
|
||||
{
|
||||
// By providing the trailing slash, stat() will only succeed if the
|
||||
|
|
Loading…
Reference in New Issue