Back to index

nordugrid-arc-nox  1.1.0~rc6
Public Types | Public Member Functions | Private Attributes
JobUser Class Reference

#include <users.h>

Collaboration diagram for JobUser:
Collaboration graph
[legend]

List of all members.

Public Types

enum  jobinfo_share_t { jobinfo_share_private = 0, jobinfo_share_group = 1, jobinfo_share_all = 2 }

Public Member Functions

JobsListget_jobs () const
void operator= (JobsList *jobs_list)
 JobUser (void)
 JobUser (const std::string &unix_name, RunPlugin *cred_plugin=NULL)
 JobUser (uid_t uid, RunPlugin *cred_plugin=NULL)
 JobUser (const JobUser &user)
 ~JobUser (void)
void SetControlDir (const std::string &dir)
void SetSessionRoot (const std::string &dir)
void SetSessionRoot (const std::vector< std::string > &dirs)
void SetCacheParams (CacheConfig *params)
void SetLRMS (const std::string &lrms_name, const std::string &queue_name)
void SetKeepFinished (time_t ttl)
void SetKeepDeleted (time_t ttr)
void SetReruns (int n)
void SetDiskSpace (unsigned long long int n)
void SetStrictSession (bool v)
void SetShareLevel (jobinfo_share_t s)
bool CreateDirectories (void)
bool is_valid (void)
const std::string & ControlDir (void) const
const std::string & SessionRoot (std::string job_id="") const
const std::vector< std::string > & SessionRoots () const
CacheConfigCacheParams (void) const
bool CachePrivate (void) const
const std::string & DefaultLRMS (void) const
const std::string & DefaultQueue (void) const
const std::string & UnixName (void) const
const std::string & Home (void) const
time_t KeepFinished (void) const
time_t KeepDeleted (void) const
bool StrictSession (void) const
jobinfo_share_t ShareLevel (void) const
uid_t get_uid (void) const
gid_t get_gid (void) const
int Reruns (void) const
RunPluginCredPlugin (void)
unsigned long long int DiskSpace (void)
bool operator== (std::string name)
bool SwitchUser (bool su=true) const
void add_helper (const std::string &helper)
bool has_helpers (void)
bool run_helpers (void)
bool substitute (std::string &param) const

Private Attributes

std::string control_dir
std::vector< std::string > session_roots
CacheConfigcache_params
std::string default_lrms
std::string default_queue
std::string unix_name
std::string home
uid_t uid
gid_t gid
jobinfo_share_t sharelevel
time_t keep_finished
time_t keep_deleted
bool strict_session
int reruns
unsigned long long int diskspace
bool valid
std::list< JobUserHelperhelpers
JobsListjobs
RunPlugincred_plugin

Detailed Description

Definition at line 36 of file users.h.


Member Enumeration Documentation

Enumerator:
jobinfo_share_private 
jobinfo_share_group 
jobinfo_share_all 

Definition at line 38 of file users.h.


Constructor & Destructor Documentation

JobUser::JobUser ( void  )
JobUser::JobUser ( const std::string &  unix_name,
RunPlugin cred_plugin = NULL 
)

Definition at line 247 of file users.cpp.

                                                        {
  struct passwd pw_;
  struct passwd *pw;
  char buf[BUFSIZ];
  unix_name=u_name;  
  cred_plugin=cred;
  valid=false;
  /* resolve name */
  if(u_name.length() == 0) {
    uid=0;  
    gid=0;
    home="/tmp";
    valid=true;
  }
  else {
    getpwnam_r(u_name.c_str(),&pw_,buf,BUFSIZ,&pw);
    if(pw != NULL) {
      uid=pw->pw_uid;
      gid=pw->pw_gid;
      home=pw->pw_dir;
      valid=true;
    };
  };
  SetControlDir("");
  SetSessionRoot("");
  SetLRMS("","");
  jobs=NULL;
  cache_params=NULL;
  keep_finished=DEFAULT_KEEP_FINISHED;
  keep_deleted=DEFAULT_KEEP_DELETED;
  strict_session=false;
  sharelevel=jobinfo_share_private;
}

Here is the call graph for this function:

JobUser::JobUser ( uid_t  uid,
RunPlugin cred_plugin = NULL 
)

Definition at line 213 of file users.cpp.

                                           {
  struct passwd pw_;
  struct passwd *pw;
  char buf[BUFSIZ];
  uid=uid_;
  valid=false;
  cred_plugin=cred;
  /* resolve name */
  if(uid_ == 0) {
    unix_name="";  
    gid=0;
    home="/tmp";
    valid=true;
  }
  else {
    getpwuid_r(uid_,&pw_,buf,BUFSIZ,&pw);
    if(pw != NULL) {
      unix_name=pw->pw_name;  
      gid=pw->pw_gid;
      home=pw->pw_dir;
      valid=true;
    };
  };
  jobs=NULL;
  cache_params=NULL;
  SetControlDir("");
  SetSessionRoot("");
  SetLRMS("","");
  keep_finished=DEFAULT_KEEP_FINISHED;
  keep_deleted=DEFAULT_KEEP_DELETED;
  strict_session=false;
  sharelevel=jobinfo_share_private;
}

Here is the call graph for this function:

JobUser::JobUser ( const JobUser user)
JobUser::~JobUser ( void  )

Definition at line 299 of file users.cpp.

                      { 
  delete cache_params;
}

Member Function Documentation

void JobUser::add_helper ( const std::string &  helper) [inline]

Definition at line 124 of file users.h.

                                           {
    helpers.push_back(JobUserHelper(helper));
  };

Here is the caller graph for this function:

CacheConfig* JobUser::CacheParams ( void  ) const [inline]

Definition at line 105 of file users.h.

{ return cache_params; };
bool JobUser::CachePrivate ( void  ) const [inline]

Definition at line 106 of file users.h.

{ return false; };

Here is the caller graph for this function:

const std::string& JobUser::ControlDir ( void  ) const [inline]

Definition at line 102 of file users.h.

{ return control_dir; };
bool JobUser::CreateDirectories ( void  )

Definition at line 101 of file users.cpp.

                                    {
  bool res = true;
  if(control_dir.length() != 0) {
    if(mkdir(control_dir.c_str(),S_IRWXU) != 0) {
      if(errno != EEXIST) res=false;
    } else {
      (chown(control_dir.c_str(),uid,gid) != 0);
      if(uid == 0) {
        chmod(control_dir.c_str(),S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
      } else {
        chmod(control_dir.c_str(),S_IRUSR | S_IWUSR | S_IXUSR);
      };
    };
    if(mkdir((control_dir+"/logs").c_str(),S_IRWXU) != 0) {
      if(errno != EEXIST) res=false;
    } else {
      (chown((control_dir+"/logs").c_str(),uid,gid) != 0);
    };
  };
  if(session_roots.size() != 0) {
    for(std::vector<std::string>::iterator i = session_roots.begin(); i != session_roots.end(); i++) {
      if(mkdir(i->c_str(),S_IRWXU) != 0) {
        if(errno != EEXIST) res=false;
      } else {
        (chown(i->c_str(),uid,gid) != 0);
        if(uid == 0) {
          chmod(i->c_str(),S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
        } else {
          chmod(i->c_str(),S_IRUSR | S_IWUSR | S_IXUSR);
        };
      };
    };
  };
  return res;
}
RunPlugin* JobUser::CredPlugin ( void  ) [inline]

Definition at line 118 of file users.h.

{ return cred_plugin; };

Here is the caller graph for this function:

const std::string& JobUser::DefaultLRMS ( void  ) const [inline]

Definition at line 107 of file users.h.

{ return default_lrms; };

Here is the caller graph for this function:

const std::string& JobUser::DefaultQueue ( void  ) const [inline]

Definition at line 108 of file users.h.

{ return default_queue; };

Here is the caller graph for this function:

unsigned long long int JobUser::DiskSpace ( void  ) [inline]

Definition at line 119 of file users.h.

{ return diskspace; };

Here is the caller graph for this function:

gid_t JobUser::get_gid ( void  ) const [inline]

Definition at line 116 of file users.h.

{ return gid; };

Here is the caller graph for this function:

JobsList* JobUser::get_jobs ( ) const [inline]

Definition at line 77 of file users.h.

                             { 
    return jobs;
  };
uid_t JobUser::get_uid ( void  ) const [inline]

Definition at line 115 of file users.h.

{ return uid; };

Here is the caller graph for this function:

bool JobUser::has_helpers ( void  ) [inline]

Definition at line 127 of file users.h.

{ return (helpers.size() != 0); };
const std::string& JobUser::Home ( void  ) const [inline]

Definition at line 110 of file users.h.

{ return home; };

Here is the caller graph for this function:

bool JobUser::is_valid ( void  ) [inline]

Definition at line 101 of file users.h.

{ return valid; };

Here is the caller graph for this function:

time_t JobUser::KeepDeleted ( void  ) const [inline]

Definition at line 112 of file users.h.

{ return keep_deleted; };

Here is the caller graph for this function:

time_t JobUser::KeepFinished ( void  ) const [inline]

Definition at line 111 of file users.h.

{ return keep_finished; };

Here is the caller graph for this function:

void JobUser::operator= ( JobsList jobs_list) [inline]

Definition at line 80 of file users.h.

                                      { 
    jobs=jobs_list;
  };
bool JobUser::operator== ( std::string  name) [inline]

Definition at line 120 of file users.h.

{ return (name == unix_name); };
int JobUser::Reruns ( void  ) const [inline]

Definition at line 117 of file users.h.

{ return reruns; };

Here is the caller graph for this function:

bool JobUser::run_helpers ( void  )

Definition at line 358 of file users.cpp.

                              {
//  if(unix_name.length() == 0) { /* special users can not run helpers */
//    return true;  
//  };
  bool started = true;
  for(std::list<JobUserHelper>::iterator i=helpers.begin();i!=helpers.end();++i) {
    started &= i->run(*this);
  };
  return started;
}

Here is the caller graph for this function:

const std::string & JobUser::SessionRoot ( std::string  job_id = "") const

Definition at line 74 of file users.cpp.

                                                             {
  if (session_roots.size() == 0) return empty_string;
  if (session_roots.size() == 1 || job_id.empty()) return session_roots[0];
  // search for this jobid's session dir
  struct stat st;
  for (std::vector<std::string>::const_iterator i = session_roots.begin(); i != session_roots.end(); i++) {
    std::string sessiondir(*i + '/' + job_id);
    if (stat(sessiondir.c_str(), &st) == 0 && S_ISDIR(st.st_mode))
      return *i;
  }
  return empty_string; // not found
}

Here is the call graph for this function:

Here is the caller graph for this function:

const std::vector<std::string>& JobUser::SessionRoots ( ) const [inline]

Definition at line 104 of file users.h.

{ return session_roots; };

Here is the caller graph for this function:

Definition at line 87 of file users.cpp.

                                                {
  std::vector<std::string> cache_dirs = params->getCacheDirs();
  for (std::vector<std::string>::iterator i = cache_dirs.begin(); i != cache_dirs.end(); i++) {
    substitute(*i);
  }
  params->setCacheDirs(cache_dirs);
  std::vector<std::string> drain_cache_dirs = params->getDrainingCacheDirs();
  for (std::vector<std::string>::iterator i = drain_cache_dirs.begin(); i != drain_cache_dirs.end(); i++) {
    substitute(*i);
  }
  params->setDrainingCacheDirs(drain_cache_dirs);
  cache_params = params;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void JobUser::SetControlDir ( const std::string &  dir)

Definition at line 48 of file users.cpp.

                                                {
  if(dir.length() == 0) {
    control_dir=home + "/.jobstatus";
  }
  else { control_dir=dir; };
}

Here is the caller graph for this function:

void JobUser::SetDiskSpace ( unsigned long long int  n) [inline]

Definition at line 97 of file users.h.

{ diskspace=n; };
void JobUser::SetKeepDeleted ( time_t  ttr) [inline]

Definition at line 95 of file users.h.

{ keep_deleted=ttr; };

Here is the caller graph for this function:

void JobUser::SetKeepFinished ( time_t  ttl) [inline]

Definition at line 94 of file users.h.

{ keep_finished=ttl; };

Here is the caller graph for this function:

void JobUser::SetLRMS ( const std::string &  lrms_name,
const std::string &  queue_name 
)

Definition at line 43 of file users.cpp.

                                                                            {
  default_lrms=lrms_name;
  default_queue=queue_name;
}

Here is the caller graph for this function:

void JobUser::SetReruns ( int  n) [inline]

Definition at line 96 of file users.h.

{ reruns=n; };
void JobUser::SetSessionRoot ( const std::string &  dir)

Definition at line 55 of file users.cpp.

                                                 {
  session_roots.clear();
  if(dir.length() == 0 || dir == "*") { session_roots.push_back(home + "/.jobs"); }
  else { session_roots.push_back(dir); };
}

Here is the caller graph for this function:

void JobUser::SetSessionRoot ( const std::vector< std::string > &  dirs)

Definition at line 61 of file users.cpp.

                                                             {
  session_roots.clear();
  if (dirs.empty()) {
    std::string dir;
    SetSessionRoot(dir);
  } else {
    for (std::vector<std::string>::const_iterator i = dirs.begin(); i != dirs.end(); i++) {
      if (*i == "*") session_roots.push_back(home + "/.jobs");
      else session_roots.push_back(*i);
    }
  }
}

Here is the call graph for this function:

Definition at line 99 of file users.h.

{ sharelevel=s; };
void JobUser::SetStrictSession ( bool  v) [inline]

Definition at line 98 of file users.h.

Here is the caller graph for this function:

jobinfo_share_t JobUser::ShareLevel ( void  ) const [inline]

Definition at line 114 of file users.h.

{ return sharelevel; };

Here is the caller graph for this function:

bool JobUser::StrictSession ( void  ) const [inline]

Definition at line 113 of file users.h.

{ return strict_session; };

Here is the caller graph for this function:

bool JobUser::substitute ( std::string &  param) const

Definition at line 152 of file users.cpp.

                                               {
  std::string::size_type curpos=0;
  for(;;) {
    if(curpos >= param.length()) break;
    std::string::size_type pos = param.find('%',curpos);
    if(pos == std::string::npos) break;
    pos++; if(pos>=param.length()) break;
    if(param[pos] == '%') { curpos=pos+1; continue; };
    std::string to_put;
    switch(param[pos]) {
      case 'R': to_put=SessionRoot(); break;
      case 'C': to_put=ControlDir(); break;
      case 'U': to_put=UnixName(); break;
      case 'H': to_put=Home(); break;
      case 'Q': to_put=DefaultQueue(); break;
      case 'L': to_put=DefaultLRMS(); break;
      case 'u': to_put=Arc::tostring(get_uid()); break;
      case 'g': to_put=Arc::tostring(get_gid()); break;
      case 'W': to_put=nordugrid_loc(); break;
      case 'G': to_put=globus_loc(); break;
      default: to_put=param.substr(pos-1,2);
    };
    curpos=pos+1+(to_put.length() - 2);
    param.replace(pos-1,2,to_put);
  };
  return true;
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool JobUser::SwitchUser ( bool  su = true) const

Definition at line 340 of file users.cpp.

                                      {
  std::string uid_s = Arc::tostring(uid);
  if(!Arc::SetEnv("USER_ID",uid_s)) if(!su) return false;
  if(!Arc::SetEnv("USER_NAME",unix_name)) if(!su) return false;
  /* set proper umask */
  umask(0177);
  if(!su) return true;
  uid_t cuid;
  if(((cuid=getuid()) != 0) && (uid != 0)) {
    if(cuid != uid) return false;
  };
  if(uid != 0) {
    setgid(gid); /* this is not an error if group failed, not a big deal */
    if(setuid(uid) != 0) return false;
  };
  return true;
}

Here is the call graph for this function:

Here is the caller graph for this function:

const std::string& JobUser::UnixName ( void  ) const [inline]

Definition at line 109 of file users.h.

{ return unix_name; };

Here is the caller graph for this function:


Member Data Documentation

Definition at line 49 of file users.h.

std::string JobUser::control_dir [private]

Definition at line 45 of file users.h.

Definition at line 75 of file users.h.

std::string JobUser::default_lrms [private]

Definition at line 51 of file users.h.

std::string JobUser::default_queue [private]

Definition at line 52 of file users.h.

unsigned long long int JobUser::diskspace [private]

Definition at line 68 of file users.h.

gid_t JobUser::gid [private]

Definition at line 57 of file users.h.

std::list<JobUserHelper> JobUser::helpers [private]

Definition at line 72 of file users.h.

std::string JobUser::home [private]

Definition at line 55 of file users.h.

JobsList* JobUser::jobs [private]

Definition at line 74 of file users.h.

time_t JobUser::keep_deleted [private]

Definition at line 62 of file users.h.

time_t JobUser::keep_finished [private]

Definition at line 61 of file users.h.

int JobUser::reruns [private]

Definition at line 66 of file users.h.

std::vector<std::string> JobUser::session_roots [private]

Definition at line 47 of file users.h.

Definition at line 58 of file users.h.

bool JobUser::strict_session [private]

Definition at line 63 of file users.h.

uid_t JobUser::uid [private]

Definition at line 56 of file users.h.

std::string JobUser::unix_name [private]

Definition at line 54 of file users.h.

bool JobUser::valid [private]

Definition at line 70 of file users.h.


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