Loading...
Searching...
No Matches
XrdSysPriv Class Reference

`#include <XrdSysPriv.hh>`

Collaboration diagram for XrdSysPriv:

## Public Member Functions

virtual | ~XrdSysPriv ()

## Static Public Member Functions

static int | ChangePerm (uid_t uid, gid_t gid)

## Friends

class | XrdSysPrivGuard

## Detailed Description

Definition at line 54 of file XrdSysPriv.hh.

## Constructor & Destructor Documentation

## ~XrdSysPriv()

virtual XrdSysPriv::~XrdSysPriv | ( |  | ) |

inline virtual

Definition at line 71 of file XrdSysPriv.hh.

{ }

## Member Function Documentation

## ChangePerm()

int XrdSysPriv::ChangePerm | ( | uid_t | uid,
|  | gid_t | gid )

static

Definition at line 233 of file XrdSysPriv.cc.

{
// Change permanently to entity newuid. Requires super-userprivileges.
// Provides a way to drop permanently su privileges.
// Return 0 on success, < 0 (== -errno) if any error occurs.
// Atomic action
XrdSysPriv::fgMutex.Lock();
#if !defined(WINDOWS)
// Get UIDs
uid_t cruid = 0, ceuid = 0, csuid = 0;
if (getresuid(&cruid, &ceuid, &csuid) != 0) {
XrdSysPriv::fgMutex.UnLock();
return XSPERR(errno);
}
// Get GIDs
uid_t crgid = 0, cegid = 0, csgid = 0;
if (getresgid(&crgid, &cegid, &csgid) != 0) {
XrdSysPriv::fgMutex.UnLock();
return XSPERR(errno);
}
// Restore privileges, if needed
if (ceuid && XrdSysPriv::Restore(0) != 0) {
XrdSysPriv::fgMutex.UnLock();
return XSPERR(errno);
}
// Act only if needed
if (newgid != cegid || newgid != crgid) {
// Set newgid as GID, all levels
if (setresgid(newgid, newgid, newgid) != 0) {
XrdSysPriv::fgMutex.UnLock();
return XSPERR(errno);
}
// Get GIDs
uid_t rgid = 0, egid = 0, sgid = 0;
if (getresgid(&rgid, &egid, &sgid) != 0) {
XrdSysPriv::fgMutex.UnLock();
return XSPERR(errno);
}
// Make sure the new GIDs are all equal to the one asked
if (rgid != newgid || egid != newgid) {
XrdSysPriv::fgMutex.UnLock();
return XSPERR(errno);
}
}
// Act only if needed
if (newuid != ceuid || newuid != cruid) {
// Set newuid as UID, all levels
if (setresuid(newuid, newuid, newuid) != 0) {
XrdSysPriv::fgMutex.UnLock();
return XSPERR(errno);
}
// Get UIDs
uid_t ruid = 0, euid = 0, suid = 0;
if (getresuid(&ruid, &euid, &suid) != 0) {
XrdSysPriv::fgMutex.UnLock();
return XSPERR(errno);
}
// Make sure the new UIDs are all equal to the one asked
if (ruid != newuid || euid != newuid) {
XrdSysPriv::fgMutex.UnLock();
return XSPERR(errno);
}
}
#endif
// Release the mutex
XrdSysPriv::fgMutex.UnLock();
// Done
return 0;
}
XSPERR
#define XSPERR(x)
Definition XrdSysPriv.cc:53
getresgid
static int getresgid(gid_t *r, gid_t *e, gid_t *)
Definition XrdSysPriv.cc:89
setresgid
static int setresgid(gid_t r, gid_t e, gid_t)
Definition XrdSysPriv.cc:75
getresuid
static int getresuid(uid_t *r, uid_t *e, uid_t *)
Definition XrdSysPriv.cc:96
setresuid
static int setresuid(uid_t r, uid_t e, uid_t)
Definition XrdSysPriv.cc:82
XrdSysMutex::Lock
void Lock()
Definition XrdSysPthread.hh:222
XrdSysMutex::UnLock
void UnLock()
Definition XrdSysPthread.hh:224

References getresgid(), getresuid(), setresgid(), setresuid(), and XSPERR.

Here is the call graph for this function:

## Friends And Related Symbol Documentation

## XrdSysPrivGuard

friend class XrdSysPrivGuard

friend

Definition at line 56 of file XrdSysPriv.hh.

References XrdSysPrivGuard.

Referenced by XrdSysPrivGuard.

The documentation for this class was generated from the following files:

- XrdSysPriv.hh
- XrdSysPriv.cc