12#ifndef ROOT_XrdProofdAux
13#define ROOT_XrdProofdAux
30#include "Xrd/XrdProtocol.hh"
32#include "XrdOuc/XrdOucHash.hh"
33#include "XrdOuc/XrdOucString.hh"
107 XrdOucStream *cfg,
bool reconfig);
120 {
return (*
fFun)(
this, val, cfg, reconfig); }
141 void Init(
const char *
s);
148 XrdOucString
Export(
int &next);
151 int N()
const {
return fN; }
161 void Init(
const char *
s);
166 XrdOucString
Get(
int i);
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);
211 int Poll(
int to = -1);
213 int Post(
int type,
const char *msg);
229 const char *o =
"Ar:Av:",
const char *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__)
244typedef 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
static double p3(double t, double a, double b, double c, double d)
static double p1(double t, double a, double b)
static double p2(double t, double a, double b, double c)
int DoDirectiveString(XrdProofdDirective *, char *val, XrdOucStream *cfg, bool rcf)
Process directive for a string.
int SetHostInDirectives(const char *, XrdProofdDirective *d, void *h)
Set host field for directive 'd' to (const char *h)
int DoDirectiveClass(XrdProofdDirective *, char *val, XrdOucStream *cfg, bool rcf)
Generic class directive processor.
int DoDirectiveInt(XrdProofdDirective *, char *val, XrdOucStream *cfg, bool rcf)
Process directive for an integer.
int(* XrdFunDirective_t)(XrdProofdDirective *, char *, XrdOucStream *cfg, bool reconfig)
XpdMsg(const char *buf=0)
int Get(int &i)
Get next token and interpret it as an int.
int Init(const char *buf)
Init from buffer.
XrdProofGI(const XrdProofGI &gi)
XrdProofUI(const XrdProofUI &ui)
static int ChangeOwn(const char *path, XrdProofUI ui)
Change the ownership of 'path' to the entity described by 'ui'.
static int GetUserInfo(const char *usr, XrdProofUI &ui)
Get information about user 'usr' in a thread safe way.
static int MvDir(const char *oldpath, const char *newpath)
Move content of directory at oldpath to newpath.
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 ...
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,...
static int ParseUsrGrp(const char *path, XrdOucString &usr, XrdOucString &grp)
Parse a path in the form of "<usr>[.<grp>][.<pid>]", filling 'usr' and 'grp'.
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 VerifyProcessByID(int pid, const char *pname="proofserv")
Check if a process named 'pname' and process 'pid' is still in the process table.
static long int GetLong(char *str)
Extract first integer from string at 'str', if any.
static const char * ProofRequestTypes(int type)
Translates the proof request type in a human readable string.
static int KillProcess(int pid, bool forcekill, XrdProofUI ui, bool changeown)
Kill the process 'pid'.
static bool HasToken(const char *s, const char *tokens)
Returns true is 's' contains at least one of the comma-separated tokens in 'tokens'.
static int GetGroupInfo(const char *grp, XrdProofGI &gi)
Get information about group with 'gid' in a thread safe way.
static int ChangeToDir(const char *dir, XrdProofUI ui, bool changeown)
Change current directory to 'dir'.
static int ChangeMod(const char *path, unsigned int mode)
Change the permission mode of 'path' to 'mode'.
static int GetNumCPUs()
Find out and return the number of CPUs in the local machine.
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,...
static int ReadMsg(int fd, XrdOucString &msg)
Receive 'msg' from pipe fd.
static int GetIDFromPath(const char *path, XrdOucString &emsg)
Extract an integer from a file.
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...
static XrdSysRecMutex fgFormMutex
static void LogEmsgToFile(const char *flog, const char *emsg, const char *pfx=0)
Logs error message 'emsg' to file 'flog' using standard technology.
static int RmDir(const char *path)
Remove directory at path and its content.
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 const char * AdminMsgType(int type)
Translates the admin message type in a human readable string.
static int CheckIf(XrdOucStream *s, const char *h)
Check existence and match condition of an 'if' directive If none (valid) is found,...
static char * Expand(char *p)
Expand path 'p' relative to: $HOME if begins with ~/ <user>'s $HOME if begins with ~<user>/ $PWD if d...
static int ParsePidPath(const char *path, XrdOucString &before, XrdOucString &after)
Parse a path in the form of "<before>[.<pid>][.<after>]", filling 'rest' and returning 'pid'.
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'.
XrdOucString ToString() const
XrdProofdDSInfo(const char *t, const char *u, bool local, bool rw, const char *o="Ar:Av:", const char *obscure="")
int DoDirective(char *val, XrdOucStream *cfg, bool reconfig)
XrdProofdDirective(const char *n, void *v, XrdFunDirective_t f, bool rcf=1)
XrdProofdFile(const char *fn=0, time_t mtime=0)
XrdOucString Export(int &next)
Export 'next' token; use next < 0 start from the first.
bool Matches(const char *s)
Return true if 's' is compatible with this token.
void Init(const char *s)
Init the multi-string token.
virtual ~XrdProofdMultiStrToken()
XrdProofdMultiStrToken(const char *s=0)
XrdOucString Export()
Return a string with comma-separated elements.
void Init(const char *s)
Init the multi-string handler.
std::list< XrdProofdMultiStrToken > fTokens
XrdOucString Get(int i)
Return i-th combination (i : 0 -> fN-1)
XrdProofdMultiStr(const char *s)
bool Matches(const char *s)
Return true if 's' is compatible with this multi-string.
virtual ~XrdProofdMultiStr()
XrdProofdPInfo(int i, const char *n)
int Recv(XpdMsg &msg)
Recv message from the pipe.
int Poll(int to=-1)
Poll over the read pipe for to secs; return whatever poll returns.
void Close()
If open, close and invalidated the pipe descriptors.
XrdProofdPipe()
Constructor: create the pipe.
virtual ~XrdProofdPipe()
Destructor.
int Post(int type, const char *msg)
Post message on the pipe.
XrdProofdPriority(const char *usr, int dp)
static constexpr double s
static constexpr double ns
int changeown(const std::string &path, uid_t u, gid_t g)
Change the ownership of 'path' to the entity described by {u,g}.