12#ifndef ROOT_XrdProofdAux
13#define ROOT_XrdProofdAux
30#include "Xrd/XrdProtocol.hh"
32#include "XrdOuc/XrdOucHash.hh"
33#include "XrdOuc/XrdOucString.hh"
104 XrdOucStream *cfg,
bool reconfig);
117 {
return (*
fFun)(
this, val, cfg, reconfig); }
138 void Init(
const char *s);
145 XrdOucString
Export(
int &next);
148 int N()
const {
return fN; }
158 void Init(
const char *s);
163 XrdOucString
Get(
int i);
166 int N()
const {
return fN; }
182 const char *
Buf()
const {
return fBuf.c_str(); }
184 int Init(
const char *buf);
188 int Get(XrdOucString &s);
208 int Poll(
int to = -1);
210 int Post(
int type,
const char *msg);
226 const char *o =
"Ar:Av:",
const char *obscure =
"") :
230 return "Type=" +
fType +
"; URL=" +
fUrl +
231 "; Local=" + (
fLocal ?
"Yes" :
"No") +
232 "; RW=" + (
fRW ?
"Yes" :
"No") +
"; Options=" +
fOpts +
240#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__APPLE__)
241typedef struct kinfo_proc kinfo_proc;
255 static int CheckIf(XrdOucStream *s,
const char *
h);
257 static void Expand(XrdOucString &path);
259 static void Form(XrdOucString &s,
const char *fmt,
int ns,
const char *ss[5],
int ni,
int ii[6],
260 int np,
void *pp[5],
int nu = 0,
unsigned int ui = 0);
261 static void Form(XrdOucString &s,
const char *fmt,
const char *
s0,
const char *
s1 = 0,
262 const char *s2 = 0,
const char *s3 = 0,
const char *s4 = 0);
263 static void Form(XrdOucString &s,
const char *fmt,
int i0,
int i1 = 0,
int i2 = 0,
264 int i3 = 0,
int i4 = 0,
int i5 = 0);
265 static void Form(XrdOucString &s,
const char *fmt,
void *p0,
void *p1 = 0,
void *p2 = 0,
266 void *p3 = 0,
void *p4 = 0);
267 static void Form(XrdOucString &s,
const char *fmt,
int i0,
const char *
s0,
268 const char *
s1 = 0,
const char *s2 = 0,
const char *s3 = 0);
269 static void Form(XrdOucString &s,
const char *fmt,
const char *
s0,
270 int i0,
int i1 = 0,
int i2 = 0,
int i3 = 0);
271 static void Form(XrdOucString &s,
const char *fmt,
const char *
s0,
272 int i0,
int i1,
unsigned int u1);
273 static void Form(XrdOucString &s,
const char *fmt,
const char *
s0,
const char *
s1,
274 int i0,
int i1,
int i2);
275 static void Form(XrdOucString &s,
const char *fmt,
int i0,
int i1,
276 const char *
s0,
const char *
s1,
const char *s2);
277 static void Form(XrdOucString &s,
const char *fmt,
const char *
s0,
const char *
s1,
278 const char *s2,
int i0,
int i1 = 0,
279 const char *s3 = 0,
const char *s4 = 0);
280 static void Form(XrdOucString &s,
const char *fmt,
const char *
s0,
int i0,
int i1,
281 const char *
s1,
const char *s2,
283 static void Form(XrdOucString &s,
const char *fmt,
const char *
s0,
const char *
s1,
284 const char *s2,
int i0,
unsigned int u1);
285 static void Form(XrdOucString &s,
const char *fmt,
int i0,
int i1,
int i2,
286 const char *
s0,
const char *
s1);
288 static void Form(XrdOucString &s,
const char *fmt,
const char *
s0,
const char *
s1,
const char *s2,
289 const char *s3,
int i1);
290 static void Form(XrdOucString &s,
const char *fmt,
int i0,
int i1,
int i2,
int i3,
const char *
s0);
292 static void Form(XrdOucString &s,
const char *fmt,
int i0,
int i1,
void *p0);
293 static void Form(XrdOucString &s,
const char *fmt,
int i0,
int i1,
int i2,
void *p0);
294 static void Form(XrdOucString &s,
const char *fmt,
int i0,
int i1,
int i2,
int i3,
void *p0);
295 static void Form(XrdOucString &s,
const char *fmt,
int i0,
int i1,
void *p0,
int i2,
int i3 = 0);
296 static void Form(XrdOucString &s,
const char *fmt,
void *p0,
int i0,
int i1);
297 static void Form(XrdOucString &s,
const char *fmt,
const char *
s0,
void *p0,
int i0,
int i1);
298 static void Form(XrdOucString &s,
const char *fmt,
void *p0,
const char *
s0,
int i0);
299 static void Form(XrdOucString &s,
const char *fmt,
const char *
s0,
const char *
s1,
void *p0);
300 static void Form(XrdOucString &s,
const char *fmt,
int i0,
const char *
s0,
const char *
s1,
302 static void Form(XrdOucString &s,
const char *fmt,
int i0,
const char *
s0,
int i1,
int i2 = 0);
304 static int GetIDFromPath(
const char *path, XrdOucString &emsg);
305 static long int GetLong(
char *str);
306#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__APPLE__)
307 static int GetMacProcList(kinfo_proc **plist,
int &nproc);
312 static int GetProcesses(
const char *pn, std::map<int,XrdOucString> *plist);
315 static bool HasToken(
const char *s,
const char *tokens);
317 static void LogEmsgToFile(
const char *flog,
const char *emsg,
const char *pfx = 0);
318 static int MvDir(
const char *oldpath,
const char *newpath);
319 static int ParsePidPath(
const char *path, XrdOucString &before, XrdOucString &after);
320 static int ParseUsrGrp(
const char *path, XrdOucString &usr, XrdOucString &grp);
322 static int ReadMsg(
int fd, XrdOucString &msg);
323 static int RmDir(
const char *path);
324 static int SymLink(
const char *path,
const char *link);
325 static int Touch(
const char *path,
int opt = 0);
327 static int Write(
int fd,
const void *buf,
size_t nb);
332#define SafeDel(x) { if (x) { delete x; x = 0; } }
335#define SafeDelArray(x) { if (x) { delete[] x; x = 0; } }
338#define SafeFree(x) { if (x) free(x); x = 0; }
342#define INRANGE(x,y) ((x >= 0) && (x < (int)y->size()))
346#define DIGIT(x) (x >= 48 && x <= 57)
350#define LETTOIDX(x, ilet) \
351 if (x >= 97 && x <= 122) ilet = x - 96; \
352 if (x >= 65 && x <= 90) ilet = x - 38;
355#define IDXTOLET(ilet, x) \
356 if ((ilet) >= 1 && (ilet) <= 26) x = (ilet) + 96; \
357 if ((ilet) >= 27 && (ilet) <= 52) x = (ilet) + 38;
361#define XPDSWAP(a,b,t) { t = a ; a = b; b = t; }
365#define XpdBadPGuard(g,u) (!(g.Valid()) && (geteuid() != (uid_t)u))
369#define MHEAD "--- Proofd: "
372#define TRACELINK fLink
375#define RESPONSE fResponse
378#define XPDFORM XrdProofdAux::Form
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t np
Option_t Option_t TPoint TPoint const char mode
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
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 &)=default
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)
int changeown(const std::string &path, uid_t u, gid_t g)
Change the ownership of 'path' to the entity described by {u,g}.