Back to index

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

#include <User.h>

Collaboration diagram for Arc::User:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 User ()
 User (const std::string name)
 User (int uid)
const std::string & Name (void) const
const std::string & Home (void) const
int get_uid (void) const
int get_gid (void) const
bool operator== (const std::string n)
int check_file_access (const std::string &path, int flags)
bool RunAs (std::string cmd)

Private Member Functions

void set (const struct passwd *)

Private Attributes

std::string name
std::string home
int uid
int gid

Detailed Description

Definition at line 12 of file User.h.


Constructor & Destructor Documentation

Arc::User::User ( void  )

Definition at line 56 of file User.cpp.

                 {
    uid = get_user_id();
    gid = get_group_id();
    struct passwd pwd;
    char pwdbuf[2048];
    struct passwd *pwd_p;
    getpwuid_r(uid, &pwd, pwdbuf, sizeof(pwdbuf), &pwd_p);
    set(pwd_p);
  }

Here is the call graph for this function:

Arc::User::User ( const std::string  name)

Definition at line 67 of file User.cpp.

                           {
    this->name = name;
    struct passwd pwd;
    char pwdbuf[2048];
    struct passwd *pwd_p;
    getpwnam_r(name.c_str(), &pwd, pwdbuf, sizeof(pwdbuf), &pwd_p);
    set(pwd_p);
  }
Arc::User::User ( int  uid)

Definition at line 76 of file User.cpp.

                    {
    this->uid = uid;
    this->gid = -1;
    struct passwd pwd;
    char pwdbuf[2048];
    struct passwd *pwd_p;
    getpwuid_r(uid, &pwd, pwdbuf, sizeof(pwdbuf), &pwd_p);
    set(pwd_p);
  }

Member Function Documentation

int Arc::User::check_file_access ( const std::string &  path,
int  flags 
)

Definition at line 91 of file User.cpp.

                                                              {
    int h;
    struct stat st;
    mode_t m;
    char **grmem;

    flags &= O_RDWR | O_RDONLY | O_WRONLY;
    if ((flags != O_RDWR) && (flags != O_RDONLY) && (flags != O_WRONLY))
      return -1;
    if (getuid() != 0) { /* not root - just try to open */
      if ((h = open(path.c_str(), flags)) == -1)
        return -1;
      close(h);
      return 0;
    }
    if (uid == 0)
      return 0;
    /* check for file */
    if (stat(path.c_str(), &st) != 0)
      return -1;
    if (!S_ISREG(st.st_mode))
      return -1;
    m = 0;
    if (st.st_uid == uid)
      m |= st.st_mode & (S_IRUSR | S_IWUSR);
    if (st.st_gid == gid)
      m |= st.st_mode & (S_IRGRP | S_IWGRP);
    else {
      char grbuf[2048];
      struct group grp;
      struct group *grp_p = NULL;
      char pwdbuf[2048];
      struct passwd pwd;
      struct passwd *pwd_p = NULL;
      getpwuid_r(uid, &pwd, pwdbuf, sizeof(pwdbuf), &pwd_p);
      getgrgid_r(st.st_gid, &grp, grbuf, sizeof(grbuf), &grp_p);
      if ((grp_p != NULL) && (pwd_p != NULL))
        for (grmem = grp_p->gr_mem; (*grmem) != NULL; grmem++)
          if (strcmp(*grmem, pwd_p->pw_name) == 0) {
            m |= st.st_mode & (S_IRGRP | S_IWGRP);
            break;
          }
    }
    m |= st.st_mode & (S_IROTH | S_IWOTH);
    if (flags == O_RDWR) {
      if (((m & (S_IRUSR | S_IRGRP | S_IROTH)) == 0) ||
          ((m & (S_IWUSR | S_IWGRP | S_IWOTH)) == 0))
        return 1;
    }
    else if (flags == O_RDONLY) {
      if ((m & (S_IRUSR | S_IRGRP | S_IROTH)) == 0)
        return 1;
    }
    else if (flags == O_WRONLY) {
      if ((m & (S_IWUSR | S_IWGRP | S_IWOTH)) == 0)
        return 1;
    }
    else
      return -1; /* check if all directories allow to read - not implemented yet */

    return 0;
  }

Here is the caller graph for this function:

int Arc::User::get_gid ( void  ) const [inline]

Definition at line 35 of file User.h.

                            {
      return (int)gid;
    }

Here is the caller graph for this function:

int Arc::User::get_uid ( void  ) const [inline]

Definition at line 32 of file User.h.

                            {
      return (int)uid;
    }

Here is the caller graph for this function:

const std::string& Arc::User::Home ( void  ) const [inline]

Definition at line 29 of file User.h.

                                      {
      return home;
    }

Here is the caller graph for this function:

const std::string& Arc::User::Name ( void  ) const [inline]

Definition at line 26 of file User.h.

                                      {
      return name;
    }
bool Arc::User::operator== ( const std::string  n) [inline]

Definition at line 38 of file User.h.

                                       {
      return (n == name);
    }
bool Arc::User::RunAs ( std::string  cmd)

Definition at line 86 of file User.cpp.

                            {
    // XXX NOP
    return false;
  }
void Arc::User::set ( const struct passwd pwd_p) [private]

Definition at line 45 of file User.cpp.

                                           {
    if (pwd_p == NULL)
      return;
    home = GetEnv("HOME");
    name = pwd_p->pw_name;
    if (home.empty())
      home = pwd_p->pw_dir;
    uid = pwd_p->pw_uid;
    gid = pwd_p->pw_gid;
  }

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

int Arc::User::gid [private]

Definition at line 18 of file User.h.

std::string Arc::User::home [private]

Definition at line 16 of file User.h.

std::string Arc::User::name [private]

Definition at line 15 of file User.h.

int Arc::User::uid [private]

Definition at line 17 of file User.h.


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