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);
148 XrdOucString Export(
int &next);
150 bool Matches(
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); }
168 bool Matches(
const char *s);
169 int N()
const {
return fN; }
171 XrdOucString Export();
182 XpdMsg(
const char *buf = 0) { Init(buf); }
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 +
236 "; Obscure=" + fObscure;
243 #if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__APPLE__) 244 typedef struct kinfo_proc kinfo_proc;
252 static const char *AdminMsgType(
int type);
253 static int AssertBaseDir(
const char *path,
XrdProofUI ui);
255 static int ChangeMod(
const char *path,
unsigned int mode);
256 static int ChangeOwn(
const char *path,
XrdProofUI ui);
257 static int ChangeToDir(
const char *dir,
XrdProofUI ui,
bool changeown);
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);
312 static int GetNumCPUs();
313 static int GetGroupInfo(
const char *grp,
XrdProofGI &gi);
314 static int GetGroupInfo(
int gid,
XrdProofGI &gi);
315 static int GetProcesses(
const char *pn, std::map<int,XrdOucString> *plist);
316 static int GetUserInfo(
const char *usr,
XrdProofUI &ui);
317 static int GetUserInfo(
int uid,
XrdProofUI &ui);
318 static bool HasToken(
const char *s,
const char *tokens);
319 static int KillProcess(
int pid,
bool forcekill,
XrdProofUI ui,
bool changeown);
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);
324 static const char *ProofRequestTypes(
int type);
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);
329 static int VerifyProcessByID(
int pid,
const char *pname =
"proofserv");
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 double p3(double t, double a, double b, double c, double d)
virtual ~XrdProofdMultiStr()
XrdProofdPriority(const char *usr, int dp)
int DoDirectiveClass(XrdProofdDirective *, char *val, XrdOucStream *cfg, bool rcf)
Generic class directive processor.
XrdOucString ToString() const
int(* XrdFunDirective_t)(XrdProofdDirective *, char *, XrdOucStream *cfg, bool reconfig)
XrdProofUI(const XrdProofUI &ui)
int DoDirectiveInt(XrdProofdDirective *, char *val, XrdOucStream *cfg, bool rcf)
Process directive for an integer.
XrdProofGI(const XrdProofGI &gi)
static double p2(double t, double a, double b, double c)
XpdMsg(const char *buf=0)
int SetHostInDirectives(const char *, XrdProofdDirective *d, void *h)
Set host field for directive 'd' to (const char *h)
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}.
char * Form(const char *fmt,...)
XrdProofdMultiStrToken(const char *s=0)
static double p1(double t, double a, double b)
virtual ~XrdProofdMultiStrToken()
int DoDirectiveString(XrdProofdDirective *, char *val, XrdOucStream *cfg, bool rcf)
Process directive for a string.
XrdProofdFile(const char *fn=0, time_t mtime=0)
std::list< XrdProofdMultiStrToken > fTokens
XrdProofdMultiStr(const char *s)
int DoDirective(char *val, XrdOucStream *cfg, bool reconfig)
XrdProofdDSInfo(const char *t, const char *u, bool local, bool rw, const char *o="Ar:Av:", const char *obscure="")
static XrdSysRecMutex fgFormMutex