12 #ifndef ROOT_XrdProofdAux
13 #define ROOT_XrdProofdAux
30 #include "Xrd/XrdProtocol.hh"
32 #include "XrdOuc/XrdOucHash.hh"
33 #include "XrdOuc/XrdOucString.hh"
53 void Reset() { fUser =
""; fHomeDir =
""; fGroup =
""; fUid = -1; fGid = -1; }
68 void Reset() { fGroup =
""; fGid = -1; }
78 XrdProofdFile(
const char *fn = 0, time_t mtime = 0) : fName(fn), fMtime(mtime) { }
107 XrdOucStream *cfg,
bool reconfig);
117 fVal(v), fName(n), fFun(f), fRcf(rcf), fHost(0) { }
120 {
return (*fFun)(
this, val, cfg, reconfig); }
141 void Init(
const char *s);
151 int N()
const {
return fN; }
161 void Init(
const char *s);
166 XrdOucString
Get(
int i);
167 bool IsValid()
const {
return (fTokens.size() > 0 ? 1 : 0); }
169 int N()
const {
return fN; }
185 const char *
Buf()
const {
return fBuf.c_str(); }
187 int Init(
const char *buf);
191 int Get(XrdOucString &s);
209 bool IsValid()
const {
return (fPipe[0] > 0 && fPipe[1] > 0) ? 1 : 0; }
211 int Poll(
int to = -1);
213 int Post(
int type,
const char *msg);
229 const char *o =
"Ar:Av:",
const char *obscure =
"") :
230 fType(t), fUrl(u), fLocal(local), fRW(rw), fOpts(o),
231 fObscure(obscure) { }
233 return "Type=" + fType +
"; URL=" + fUrl +
234 "; Local=" + (fLocal ?
"Yes" :
"No") +
235 "; RW=" + (fRW ?
"Yes" :
"No") +
"; Options=" + fOpts +
243 #if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__APPLE__)
244 typedef struct kinfo_proc kinfo_proc;
255 static int ChangeMod(
const char *path,
unsigned int mode);
258 static int CheckIf(XrdOucStream *s,
const char *
h);
259 static char *
Expand(
char *p);
260 static void Expand(XrdOucString &path);
262 static void Form(XrdOucString &s,
const char *fmt,
int ns,
const char *ss[5],
int ni,
int ii[6],
263 int np,
void *pp[5],
int nu = 0,
unsigned int ui = 0);
264 static void Form(XrdOucString &s,
const char *fmt,
const char *s0,
const char *s1 = 0,
265 const char *s2 = 0,
const char *s3 = 0,
const char *s4 = 0);
266 static void Form(XrdOucString &s,
const char *fmt,
int i0,
int i1 = 0,
int i2 = 0,
267 int i3 = 0,
int i4 = 0,
int i5 = 0);
268 static void Form(XrdOucString &s,
const char *fmt,
void *p0,
void *
p1 = 0,
void *
p2 = 0,
269 void *
p3 = 0,
void *p4 = 0);
270 static void Form(XrdOucString &s,
const char *fmt,
int i0,
const char *s0,
271 const char *s1 = 0,
const char *s2 = 0,
const char *s3 = 0);
272 static void Form(XrdOucString &s,
const char *fmt,
const char *s0,
273 int i0,
int i1 = 0,
int i2 = 0,
int i3 = 0);
274 static void Form(XrdOucString &s,
const char *fmt,
const char *s0,
275 int i0,
int i1,
unsigned int u1);
276 static void Form(XrdOucString &s,
const char *fmt,
const char *s0,
const char *s1,
277 int i0,
int i1,
int i2);
278 static void Form(XrdOucString &s,
const char *fmt,
int i0,
int i1,
279 const char *s0,
const char *s1,
const char *s2);
280 static void Form(XrdOucString &s,
const char *fmt,
const char *s0,
const char *s1,
281 const char *s2,
int i0,
int i1 = 0,
282 const char *s3 = 0,
const char *s4 = 0);
283 static void Form(XrdOucString &s,
const char *fmt,
const char *s0,
int i0,
int i1,
284 const char *s1,
const char *s2,
286 static void Form(XrdOucString &s,
const char *fmt,
const char *s0,
const char *s1,
287 const char *s2,
int i0,
unsigned int u1);
288 static void Form(XrdOucString &s,
const char *fmt,
int i0,
int i1,
int i2,
289 const char *s0,
const char *s1);
291 static void Form(XrdOucString &s,
const char *fmt,
const char *s0,
const char *s1,
const char *s2,
292 const char *s3,
int i1);
293 static void Form(XrdOucString &s,
const char *fmt,
int i0,
int i1,
int i2,
int i3,
const char *s0);
295 static void Form(XrdOucString &s,
const char *fmt,
int i0,
int i1,
void *p0);
296 static void Form(XrdOucString &s,
const char *fmt,
int i0,
int i1,
int i2,
void *p0);
297 static void Form(XrdOucString &s,
const char *fmt,
int i0,
int i1,
int i2,
int i3,
void *p0);
298 static void Form(XrdOucString &s,
const char *fmt,
int i0,
int i1,
void *p0,
int i2,
int i3 = 0);
299 static void Form(XrdOucString &s,
const char *fmt,
void *p0,
int i0,
int i1);
300 static void Form(XrdOucString &s,
const char *fmt,
const char *s0,
void *p0,
int i0,
int i1);
301 static void Form(XrdOucString &s,
const char *fmt,
void *p0,
const char *s0,
int i0);
302 static void Form(XrdOucString &s,
const char *fmt,
const char *s0,
const char *s1,
void *p0);
303 static void Form(XrdOucString &s,
const char *fmt,
int i0,
const char *s0,
const char *s1,
305 static void Form(XrdOucString &s,
const char *fmt,
int i0,
const char *s0,
int i1,
int i2 = 0);
307 static int GetIDFromPath(
const char *path, XrdOucString &emsg);
308 static long int GetLong(
char *str);
309 #if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__APPLE__)
310 static int GetMacProcList(kinfo_proc **plist,
int &nproc);
315 static int GetProcesses(
const char *pn, std::map<int,XrdOucString> *plist);
318 static bool HasToken(
const char *s,
const char *tokens);
320 static void LogEmsgToFile(
const char *
flog,
const char *emsg,
const char *pfx = 0);
321 static int MvDir(
const char *oldpath,
const char *newpath);
322 static int ParsePidPath(
const char *path, XrdOucString &before, XrdOucString &after);
323 static int ParseUsrGrp(
const char *path, XrdOucString &usr, XrdOucString &grp);
325 static int ReadMsg(
int fd, XrdOucString &msg);
326 static int RmDir(
const char *path);
327 static int SymLink(
const char *path,
const char *
link);
328 static int Touch(
const char *path,
int opt = 0);
330 static int Write(
int fd,
const void *buf,
size_t nb);
335 #define SafeDel(x) { if (x) { delete x; x = 0; } }
338 #define SafeDelArray(x) { if (x) { delete[] x; x = 0; } }
341 #define SafeFree(x) { if (x) free(x); x = 0; }
345 #define INRANGE(x,y) ((x >= 0) && (x < (int)y->size()))
349 #define DIGIT(x) (x >= 48 && x <= 57)
353 #define LETTOIDX(x, ilet) \
354 if (x >= 97 && x <= 122) ilet = x - 96; \
355 if (x >= 65 && x <= 90) ilet = x - 38;
358 #define IDXTOLET(ilet, x) \
359 if ((ilet) >= 1 && (ilet) <= 26) x = (ilet) + 96; \
360 if ((ilet) >= 27 && (ilet) <= 52) x = (ilet) + 38;
364 #define XPDSWAP(a,b,t) { t = a ; a = b; b = t; }
368 #define XpdBadPGuard(g,u) (!(g.Valid()) && (geteuid() != (uid_t)u))
372 #define MHEAD "--- Proofd: "
375 #define TRACELINK fLink
378 #define RESPONSE fResponse
381 #define XPDFORM XrdProofdAux::Form
XrdProofdDirective(const char *n, void *v, XrdFunDirective_t f, bool rcf=1)
static int GetNumCPUs()
Find out and return the number of CPUs in the local machine.
static int Write(int fd, const void *buf, size_t nb)
Write nb bytes at buf to descriptor 'fd' ignoring interrupts Return the number of bytes written or -1...
int Poll(int to=-1)
Poll over the read pipe for to secs; return whatever poll returns.
static int AssertBaseDir(const char *path, XrdProofUI ui)
Make sure that the base dir of 'path' is either owned by 'ui' or gives full permissions to 'ui'...
static double p3(double t, double a, double b, double c, double d)
ClassImp(TSeqCollection) Int_t TSeqCollection TIter next(this)
Return index of object in collection.
static int GetUserInfo(const char *usr, XrdProofUI &ui)
Get information about user 'usr' in a thread safe way.
virtual ~XrdProofdMultiStr()
static const char * AdminMsgType(int type)
Translates the admin message type in a human readable string.
XrdProofdPriority(const char *usr, int dp)
int DoDirectiveClass(XrdProofdDirective *, char *val, XrdOucStream *cfg, bool rcf)
Generic class directive processor.
static int RmDir(const char *path)
Remove directory at path and its content.
int(* XrdFunDirective_t)(XrdProofdDirective *, char *, XrdOucStream *cfg, bool reconfig)
XrdProofUI(const XrdProofUI &ui)
int Init(const char *buf)
Init from buffer.
int DoDirectiveInt(XrdProofdDirective *, char *val, XrdOucStream *cfg, bool rcf)
Process directive for an integer.
static bool HasToken(const char *s, const char *tokens)
Returns true is 's' contains at least one of the comma-separated tokens in 'tokens'.
XrdProofGI(const XrdProofGI &gi)
int Recv(XpdMsg &msg)
Recv message from the pipe.
ClassImp(RooList) TObjOptLink *RooList TObjLink * link
Find the link corresponding to the named object in this list.
static int ParsePidPath(const char *path, XrdOucString &before, XrdOucString &after)
Parse a path in the form of "
[.][.]", filling 'rest' and returning 'pid'...
static int SymLink(const char *path, const char *link)
Create a symlink 'link' to 'path' Return 0 in case of success, -1 in case of error.
static double p2(double t, double a, double b, double c)
void Close()
If open, close and invalidated the pipe descriptors.
bool Matches(const char *s)
Return true if 's' is compatible with this multi-string.
XpdMsg(const char *buf=0)
static void Form(XrdOucString &s, const char *fmt, int ns, const char *ss[5], int ni, int ii[6], int np, void *pp[5], int nu=0, unsigned int ui=0)
Recreate the string according to 'fmt', the up to 5 'const char *', up to 6 'int' arguments...
int SetHostInDirectives(const char *, XrdProofdDirective *d, void *h)
Set host field for directive 'd' to (const char *h)
static const char * ProofRequestTypes(int type)
Translates the proof request type in a human readable string.
static int GetIDFromPath(const char *path, XrdOucString &emsg)
Extract an integer from a file.
XrdProofdPInfo(int i, const char *n)
int changeown(const std::string &path, uid_t u, gid_t g)
Change the ownership of 'path' to the entity described by {u,g}.
static int Touch(const char *path, int opt=0)
Set access (opt == 1), modify (opt =2 ) or access&modify (opt = 0, default) times of path to current ...
XrdProofdMultiStrToken(const char *s=0)
static double p1(double t, double a, double b)
virtual ~XrdProofdMultiStrToken()
static long int GetLong(char *str)
Extract first integer from string at 'str', if any.
static int GetGroupInfo(const char *grp, XrdProofGI &gi)
Get information about group with 'gid' in a thread safe way.
static int AssertDir(const char *path, XrdProofUI ui, bool changeown)
Make sure that 'path' exists and is owned by the entity described by 'ui'.
static int ReadMsg(int fd, XrdOucString &msg)
Receive 'msg' from pipe fd.
static int CheckIf(XrdOucStream *s, const char *h)
Check existence and match condition of an 'if' directive If none (valid) is found, return -1.
static char * Expand(char *p)
Expand path 'p' relative to: $HOME if begins with ~/ 's $HOME if begins with ~/ $PWD if d...
int DoDirectiveString(XrdProofdDirective *, char *val, XrdOucStream *cfg, bool rcf)
Process directive for a string.
static int ParseUsrGrp(const char *path, XrdOucString &usr, XrdOucString &grp)
Parse a path in the form of "
[.][.]", filling 'usr' and 'grp'.
XrdProofdFile(const char *fn=0, time_t mtime=0)
bool Matches(const char *s)
Return true if 's' is compatible with this token.
static int ChangeMod(const char *path, unsigned int mode)
Change the permission mode of 'path' to 'mode'.
XrdOucString Export()
Return a string with comma-separated elements.
virtual ~XrdProofdPipe()
Destructor.
std::list< XrdProofdMultiStrToken > fTokens
XrdProofdMultiStr(const char *s)
int DoDirective(char *val, XrdOucStream *cfg, bool reconfig)
int Get(int &i)
Get next token and interpret it as an int.
XrdOucString Get(int i)
Return i-th combination (i : 0 -> fN-1)
static int ChangeToDir(const char *dir, XrdProofUI ui, bool changeown)
Change current directory to 'dir'.
XrdProofdDSInfo(const char *t, const char *u, bool local, bool rw, const char *o="Ar:Av:", const char *obscure="")
static int ChangeOwn(const char *path, XrdProofUI ui)
Change the ownership of 'path' to the entity described by 'ui'.
int Post(int type, const char *msg)
Post message on the pipe.
void Init(const char *s)
Init the multi-string token.
static int VerifyProcessByID(int pid, const char *pname="proofserv")
Check if a process named 'pname' and process 'pid' is still in the process table. ...
void Init(const char *s)
Init the multi-string handler.
XrdProofdPipe()
Constructor: create the pipe.
static int GetProcesses(const char *pn, std::map< int, XrdOucString > *plist)
Get from the process table list of PIDs for processes named "proofserv' For {linux, sun, macosx} it uses the system info; for other systems it invokes the command shell 'ps ax' via popen.
static void LogEmsgToFile(const char *flog, const char *emsg, const char *pfx=0)
Logs error message 'emsg' to file 'flog' using standard technology.
XrdOucString Export(int &next)
Export 'next' token; use next < 0 start from the first.
static int MvDir(const char *oldpath, const char *newpath)
Move content of directory at oldpath to newpath.
XrdOucString ToString() const
static int KillProcess(int pid, bool forcekill, XrdProofUI ui, bool changeown)
Kill the process 'pid'.
static XrdSysRecMutex fgFormMutex