Back to index

nordugrid-arc-nox  1.1.0~rc6
Public Member Functions | Private Attributes
Arc::UserSwitch Class Reference

If this class is created user identity is switched to provided uid and gid. More...

#include <User.h>

List of all members.

Public Member Functions

 UserSwitch (int uid, int gid)
 ~UserSwitch (void)
 operator bool (void)

Private Attributes

int old_uid
int old_gid
bool valid

Detailed Description

If this class is created user identity is switched to provided uid and gid.

Due to internal lock there will be only one valid instance of this class. Any attempt to create another instance will block till first one is destroyed. If uid and gid are set to 0 then user identity is not switched. But lock is applied anyway. The lock has dual purpose. First and most important is to protect communication with underlying operating system which may depend on user identity. For that it is advisable for code which talks to operating system to acquire valid instance of this class. Care must be taken for not to hold that instance too long cause that may block other code in multithreaded envoronment. Other purpose of this lock is to provide workaround for glibc bug in __nptl_setxid. That bug causes lockup of seteuid() function if racing with fork. To avoid this problem the lock mentioned above is used by Run class while spawning new process.

Definition at line 63 of file User.h.

Constructor & Destructor Documentation

Arc::UserSwitch::UserSwitch ( int  uid,
int  gid 

Definition at line 245 of file User.cpp.

                                       :valid(false) {
    old_gid = getegid();
    old_uid = geteuid();
    if(gid) {
      if(old_gid != gid) {
        if(setegid(gid) == -1) {
    if(uid) {
      if(old_uid != uid) {
        if(seteuid(uid) == -1) {
          if(old_gid != gid) setegid(old_gid);

Definition at line 269 of file User.cpp.

    if(valid) {
      if(old_uid != geteuid()) seteuid(old_uid);
      if(old_gid != getegid()) setegid(old_gid);

Member Function Documentation

Arc::UserSwitch::operator bool ( void  ) [inline]

Definition at line 71 of file User.h.

{ return valid; };

Member Data Documentation

int Arc::UserSwitch::old_gid [private]

Definition at line 66 of file User.h.

int Arc::UserSwitch::old_uid [private]

Definition at line 65 of file User.h.

bool Arc::UserSwitch::valid [private]

Definition at line 67 of file User.h.

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