C/C++ setreuid() returns "operation not permitted" even it was sudo'ed

Rajeev_M

New Member


Messages: 1

Hello, I was testing one of my software on FreeBSD ,Where in the software i've been trying to replace the Real/Effective UID and GID of the process using below two functions

setregid(),setreuid(). But these both functions return -1 as a result(when i got the errno to print it ssys "operations not permitted") and I got to know from the man page that it has to deal with "EPERM",yet I've Sudo'ed the EXE same result and same even when ran as root.This code works fine with Linux distributions ain't sure what went wrong with my code and the BSD or what needs to be changed in order to swap the ID's

first in the code there is drop-down to privilege with the given ID and then they are changing the real UID/GID

Code:
if (setegid(gid)==0)
   {
       if (seteuid(uid)==0)
       {
        
           return true;
       }
   }
if (setregid(egid,m_rgid) == 0) where egid(is given),m_rgid is root 0
   {
    
       if (setreuid(euid,m_ruid) == 0)where euid(is given),m_ruid is root 0
       {
           .....
           return true;
       }
   }
would anyone shed some light on this
 
Last edited:
Top