// Drops the program's group privileges.
-void Utility::dropGroupPrivs( int uid, int gid )
+void Utility::dropGroupPrivs( uid_t uid, gid_t gid )
{
- if(gid) {
+ if(gid && gid != getegid()) {
if(setgid(gid)<0) {
g_log<<Logger::Critical<<"Unable to set effective group id to "<<gid<<": "<<stringerror()<<endl;
exit(1);
// Drops the program's user privileges.
-void Utility::dropUserPrivs( int uid )
+void Utility::dropUserPrivs( uid_t uid )
{
- if(uid) {
+ if(uid && uid != geteuid()) {
if(setuid(uid)<0) {
g_log<<Logger::Critical<<"Unable to set effective user id to "<<uid<<": "<<stringerror()<<endl;
exit(1);
// Retrieves a gid using a groupname.
-int Utility::makeGidNumeric(const string &group)
+gid_t Utility::makeGidNumeric(const string &group)
{
- int newgid;
+ gid_t newgid;
if(!(newgid=atoi(group.c_str()))) {
errno=0;
struct group *gr=getgrnam(group.c_str());
// Retrieves an uid using a username.
-int Utility::makeUidNumeric(const string &username)
+uid_t Utility::makeUidNumeric(const string &username)
{
- int newuid;
+ uid_t newuid;
if(!(newuid=atoi(username.c_str()))) {
struct passwd *pw=getpwnam(username.c_str());
if(!pw) {
return newuid;
}
-
-// Returns a random number.
-long int Utility::random( void )
-{
- return rand();
-}
-
// Sets the random seed.
-void Utility::srandom( unsigned int seed )
+void Utility::srandom(void)
{
- ::srandom(seed);
+ struct timeval tv;
+ gettimeofday(&tv, 0);
+ ::srandom(tv.tv_sec ^ tv.tv_usec ^ getpid());
}
-
// Writes a vector.
int Utility::writev(int socket, const iovec *vector, size_t count )
{