28 #include "XrdVersion.hh"
29 #include "Xrd/XrdProtocol.hh"
30 #include "XrdOuc/XrdOucEnv.hh"
31 #include "XrdOuc/XrdOucStream.hh"
67 typedef XrdProtocol *(*XrdProtocolLoader_t)(
const char *,
char *, XrdProtocol_Config *);
104 #if defined(LIBC_SCCS) && !defined(lint)
105 static char sccsid[] =
"@(#)getgrouplist.c 8.2 (Berkeley) 12/8/94";
107 #include <sys/cdefs.h>
108 __FBSDID(
"$FreeBSD: src/lib/libc/gen/getgrouplist.c,v 1.14 2005/05/03 16:20:03 delphij Exp $");
114 #include <sys/types.h>
119 getgrouplist(
const char *uname, gid_t agroup, gid_t *groups,
int *grpcnt)
121 const struct group *grp;
122 int i, maxgroups, ngroups, ret;
132 groups ? groups[ngroups++] = agroup : ngroups++;
134 groups ? groups[ngroups++] = agroup : ngroups++;
139 while ((grp = getgrent()) != NULL) {
141 for (i = 0; i < ngroups; i++) {
142 if (grp->gr_gid == groups[i])
146 for (i = 0; grp->gr_mem[i]; i++) {
147 if (!strcmp(grp->gr_mem[i], uname)) {
148 if (ngroups >= maxgroups) {
152 groups ? groups[ngroups++] = grp->gr_gid : ngroups++;
174 void *XrdProofdManagerCron(
void *p)
176 XPDLOC(PMGR,
"ManagerCron")
178 XrdProofdManager *mgr = (XrdProofdManager *)p;
180 TRACE(REQ,
"undefined manager: cannot start");
184 TRACE(REQ,
"started with frequency " << mgr->CronFrequency() <<
" sec");
188 int mid = XrdSysTimer::Midnight(now);
192 TRACE(REQ,
"midnight in " << (mid - now) <<
" secs");
196 TRACE(REQ,
"running periodical checks");
198 mgr->CheckLogFileOwnership();
200 int tw = mgr->CronFrequency();
202 if ((mid - now) <= tw) {
209 if (mgr->SessionMgr()) mgr->SessionMgr()->Config(1);
210 if (mgr->GroupsMgr()) mgr->GroupsMgr()->Config(mgr->GroupsMgr()->GetCfgFile());
212 XrdSysTimer::Wait(tw * 1000);
222 XrdProofdManager::XrdProofdManager(
char *parms, XrdProtocol_Config *pi, XrdSysError *edest)
223 : XrdProofdConfig(pi->ConfigFN, edest)
229 fSrvType = kXPD_AnyServer;
232 fPort = XPD_DEF_PORT;
241 fNamespace =
"/proofpool";
242 fMastersAllowed.clear();
243 fOperationMode = kXPD_OpModeOpen;
251 fDataDirUrlOpts =
"";
254 fXrootdLibPath =
"<>";
258 fAdminPath = pi->AdmPath;
259 fAdminPath +=
"/.xproofd.";
263 fRemoveROOTLibPaths = 0;
264 fLibPathsToRemove.Purge();
277 RegisterDirectives();
280 fAdmin =
new XrdProofdAdmin(
this, pi, edest);
283 fClientMgr =
new XrdProofdClientMgr(
this, pi, edest);
286 fNetMgr =
new XrdProofdNetMgr(
this, pi, edest);
289 fPriorityMgr =
new XrdProofdPriorityMgr(
this, pi, edest);
292 fROOTMgr =
new XrdROOTMgr(
this, pi, edest);
295 fSessionMgr =
new XrdProofdProofServMgr(
this, pi, edest);
301 XrdProofdManager::~XrdProofdManager()
305 SafeDelete(fClientMgr);
307 SafeDelete(fPriorityMgr);
308 SafeDelete(fProofSched);
309 SafeDelete(fROOTMgr);
310 SafeDelete(fSessionMgr);
311 SafeDelete(fXrootdPlugin);
317 XrdProtocol *XrdProofdManager::LoadXrootd(
char *parms, XrdProtocol_Config *pi, XrdSysError *edest)
319 XPDLOC(ALL,
"Manager::LoadXrootd")
321 XrdProtocol *xrp = 0;
324 fXrootdPlugin = new XrdSysPlugin((edest ? edest : (XrdSysError *)0), fXrootdLibPath.c_str());
325 if (!fXrootdPlugin) {
326 TRACE(XERR,
"could not create plugin instance for "<<fXrootdLibPath.c_str());
331 XrdProtocolLoader_t ep = (XrdProtocolLoader_t) fXrootdPlugin->getPlugin(
"XrdgetProtocol");
333 TRACE(XERR,
"could not find 'XrdgetProtocol()' in "<<fXrootdLibPath.c_str());
338 if (!(xrp = (*ep)(
"xrootd", parms, pi))) {
339 TRACE(XERR,
"Unable to create xrootd protocol service object via " << fXrootdLibPath.c_str());
340 SafeDelete(fXrootdPlugin);
343 TRACE(ALL,
"xrootd protocol service created");
352 void XrdProofdManager::CheckLogFileOwnership()
354 XPDLOC(ALL,
"Manager::CheckLogFileOwnership")
357 if (getuid()) return;
360 if (fstat(STDERR_FILENO, &st) != 0) {
361 if (errno != ENOENT) {
362 TRACE(XERR,
"could not stat log file; errno: " << errno);
367 TRACE(HDBG,
"uid: " << st.st_uid <<
", gid: " << st.st_gid);
370 struct passwd *epwd = getpwuid(XrdProofdProtocol::EUidAtStartup());
372 TRACE(XERR,
"could not get effective user identity; errno: " << errno);
377 if (st.st_uid != epwd->pw_uid || st.st_gid != epwd->pw_gid) {
378 if (fchown(STDERR_FILENO, epwd->pw_uid, epwd->pw_gid) != 0) {
379 TRACE(XERR,
"could not set stderr ownership; errno: " << errno);
388 bool XrdProofdManager::CheckMaster(
const char *m)
392 if (fMastersAllowed.size() > 0) {
395 std::list<XrdOucString *>::iterator i;
396 for (i = fMastersAllowed.begin(); i != fMastersAllowed.end(); ++i) {
397 if (wm.matches((*i)->c_str())) {
412 int XrdProofdManager::CheckUser(
const char *usr,
const char *grp,
413 XrdProofUI &ui, XrdOucString &e,
bool &su)
417 if (!usr || strlen(usr) <= 0) {
418 e =
"CheckUser: 'usr' string is undefined ";
423 if (strlen(usr) == 4 && !strcmp(usr,
"root")) {
424 e =
"CheckUser: 'root' logins not accepted ";
429 if (!grp || strlen(grp) <= 0) {
430 e =
"CheckUser: 'grp' string is undefined ";
434 XrdSysMutexHelper mtxh(&fMutex);
440 if (XrdProofdAux::GetUserInfo(usr, ui) != 0) {
441 e =
"CheckUser: unknown ClientID: ";
447 if (XrdProofdAux::GetUserInfo(geteuid(), ui) != 0) {
448 e =
"CheckUser: problems getting user info for id: ";
455 if (fSuperUsers.length() > 0) {
458 while ((from = fSuperUsers.tokenize(tkn, from,
',')) != -1) {
469 if (fOperationMode == kXPD_OpModeControlled) {
501 if (fAllowedGroups.Num() > 0) {
504 int ugrpok = 0, pgrpok = 0;
506 int ngrps = 10, neg, ig = 0;
507 #if defined(__APPLE__)
513 if ((neg = getgrouplist(usr, ui.fGid, grps, &ngrps)) < 0) neg = 10;
515 for (ig = 0; ig < neg; ig++) {
516 g.form(
"%d", (
int) grps[ig]);
517 int *st = fAllowedGroups.Find(g.c_str());
522 e =
"Controlled access (UNIX group): user '";
524 e =
"', UNIX group '";
526 e +=
"' denied to connect";
534 int *st = fAllowedGroups.Find(grp);
540 e =
"Controlled access";
541 e +=
" (PROOF group): user '";
543 e +=
"', PROOF group '";
545 e +=
"' denied to connect";
550 grpok = ((ugrpok == 1 && pgrpok >= 0) || (ugrpok >= 0 && pgrpok == 1)) ? 1 : 0;
554 if (fAllowedUsers.Num() > 0) {
556 if (fAllowedGroups.Num() <= 0) usrok = -1;
558 int *st = fAllowedUsers.Find(usr);
563 e =
"Controlled access: user '";
565 e +=
"', PROOF group '";
567 e +=
"' not allowed to connect";
579 if (usrok == -1 || (!grpok && usrok != 1))
return -1;
589 XrdProofSched *XrdProofdManager::LoadScheduler()
591 XPDLOC(ALL,
"Manager::LoadScheduler")
593 XrdProofSched *sched = 0;
594 XrdOucString name, lib, m;
596 const
char *cfn = CfgFile();
599 if (cfn && strlen(cfn) > 0) {
601 XrdOucStream cfg(fEDest, getenv(
"XRDINSTANCE"), &myEnv);
604 if ((cfgFD = open(cfn, O_RDONLY, 0)) >= 0) {
607 char *val = 0, *var = 0;
608 while ((var = cfg.GetMyFirstWord())) {
609 if (!(strcmp(
"xpd.sched", var))) {
625 XPDFORM(m,
"failure opening config file; errno: %d", errno);
631 if (name ==
"default" || !(name.length() > 0 && lib.length() > 0)) {
632 if ((name.length() <= 0 && lib.length() > 0) ||
633 (name.length() > 0 && lib.length() <= 0)) {
634 XPDFORM(m,
"missing or incomplete info (name: %s, lib: %s)", name.c_str(), lib.c_str());
637 TRACE(DBG,
"instantiating default scheduler");
638 sched =
new XrdProofSched(
"default",
this, fGroupsMgr, cfn, fEDest);
641 if (lib.beginswith(
"~") || lib.beginswith(
"$"))
642 XrdProofdAux::Expand(lib);
643 XrdSysPlugin *h =
new XrdSysPlugin(fEDest, lib.c_str());
645 return (XrdProofSched *)0;
647 XrdProofSchedLoader_t ep = (XrdProofSchedLoader_t) h->getPlugin(
"XrdgetProofSched", 1);
650 return (XrdProofSched *)0;
653 if (!(sched = (*ep)(cfn,
this, fGroupsMgr, cfn, fEDest))) {
654 TRACE(XERR,
"unable to create scheduler object from " << lib);
656 return (XrdProofSched *)0;
661 if (!(sched->IsValid())) {
662 TRACE(XERR,
" unable to instantiate the " << sched->Name() <<
" scheduler using " << (cfn ? cfn :
"<nul>"));
664 return (XrdProofSched *)0;
667 TRACE(ALL,
"scheduler loaded: type: " << sched->Name());
676 int XrdProofdManager::GetWorkers(XrdOucString &lw, XrdProofdProofServ *xps,
679 XPDLOC(ALL,
"Manager::GetWorkers")
686 TRACE(XERR,
"scheduler undefined");
691 std::list<XrdProofWorker *> wrks, uwrks;
692 if ((rc = fProofSched->GetWorkers(xps, &wrks, query)) < 0) {
693 TRACE(XERR,
"error getting list of workers from the scheduler");
696 std::list<XrdProofWorker *>::iterator iw, iaw;
700 TRACE(DBG,
"list size: " << wrks.size());
707 for (iw = wrks.begin(); iw != wrks.end() ; ++iw) {
708 XrdProofWorker *w = *iw;
711 for (iaw = uwrks.begin(); iaw != uwrks.end() ; ++iaw) {
712 XrdProofWorker *uw = *iaw;
713 if (w->fHost == uw->fHost && w->fPort == uw->fPort) {
724 XPDFORM(ord,
"%d", ii);
727 XrdProofWorker *uw =
new XrdProofWorker(*w);
732 xps->AddWorker(ord.c_str(), w);
733 w->AddProofServ(xps);
736 for (iw = uwrks.begin(); iw != uwrks.end() ; ++iw) {
737 XrdProofWorker *w = *iw;
739 if (w->fType ==
'M') {
740 if (lw.length() > 0) lw.insert(
'&',0);
741 lw.insert(w->Export(), 0);
744 if (lw.length() > 0) lw +=
'&';
753 for (iw = wrks.begin(); iw != wrks.end() ; ++iw) {
754 XrdProofWorker *w = *iw;
759 XPDFORM(ord,
"%d", ii);
761 xps->AddWorker(ord.c_str(), w);
763 w->AddProofServ(xps);
768 int proto = (xps->ROOT()) ? xps->ROOT()->SrvProtVers() : -1;
769 if (rc != 2 || (proto < 21 && rc == 0)) {
771 if (lw.length() <= 0) xps->ExportWorkers(lw);
772 TRACE(DBG,
"from ExportWorkers: " << lw);
773 }
else if (proto >= 21) {
775 lw = XPD_GW_QueryEnqueued;
778 if (TRACING(REQ)) fNetMgr->Dump();
781 if (!uwrks.empty()) {
783 while (iw != uwrks.end()) {
784 XrdProofWorker *w = *iw;
785 iw = uwrks.erase(iw);
796 static int FillKeyValues(
const char *k,
int *d,
void *s)
798 xpd_acm_lists_t *ls = (xpd_acm_lists_t *)s;
801 XrdOucString &ss = (*d == 1) ? ls->allowed : ls->denied;
808 if (ss.length() > 0) ss +=
",";
824 static int RemoveInvalidUsers(
const char *k,
int *,
void *s)
826 XrdOucString *ls = (XrdOucString *)s;
829 if (XrdProofdAux::GetUserInfo(k, ui) != 0) {
833 if (ls->length() > 0) *ls +=
",";
849 int XrdProofdManager::Config(
bool rcf)
851 XPDLOC(ALL,
"Manager::Config")
853 XrdSysMutexHelper mtxh(fMutex);
856 if (XrdProofdConfig::Config(rcf) != 0) {
857 XPDERR(
"problems parsing file ");
862 msg = (rcf) ?
"re-configuring" :
"configuring";
866 fChangeOwn = (fMultiUser && getuid()) ? 0 : 1;
869 XPDFORM(msg,
"listening on port %d", fPort);
873 uid_t effuid = XrdProofdProtocol::EUidAtStartup();
876 if (XrdProofdAux::GetUserInfo(effuid, ui) == 0) {
877 fEffectiveUser = ui.fUser;
879 XPDFORM(msg,
"could not resolve effective uid %d (errno: %d)", effuid, errno);
885 char *host = XrdSysDNS::getHostName();
886 fHost = host ? host :
"";
890 TRACE(ALL,
"using temp dir: " << fTMPdir);
893 const char *roles[] = {
"any",
"worker",
"submaster",
"master" };
894 TRACE(ALL,
"role set to: " << roles[fSrvType+1]);
898 if (XrdProofdAux::AssertDir(fAdminPath.c_str(), ui, fChangeOwn) != 0) {
899 XPDERR(
"unable to assert the admin path: " << fAdminPath);
902 TRACE(ALL,
"admin path set to: " << fAdminPath);
905 if (fSockPathDir.length() <= 0) {
907 XPDFORM(fSockPathDir,
"%s/socks", fAdminPath.c_str());
909 if (XrdProofdAux::AssertDir(fSockPathDir.c_str(), ui, fChangeOwn) != 0) {
910 XPDERR(
"unable to assert the admin path: " << fSockPathDir);
913 if (XrdProofdAux::ChangeMod(fSockPathDir.c_str(), 0777) != 0) {
914 XPDERR(
"unable to set mode 0777 on: " << fSockPathDir);
917 TRACE(ALL,
"unix sockets under: " << fSockPathDir);
920 XrdOucString pidfile(fAdminPath);
921 pidfile +=
"/xrootd.pid";
922 FILE *fpid = fopen(pidfile.c_str(),
"w");
924 XPDFORM(msg,
"unable to open pid file: %s; errno: %d", pidfile.c_str(), errno);
928 fprintf(fpid,
"%d", getpid());
931 if (XrdProofdAux::GetUserInfo(effuid, ui) == 0) {
932 XPDFORM(msg,
"could not resolve effective uid %d (errno: %d)", effuid, errno);
939 if (fWorkDir.length() > 0) {
941 if (XrdProofdAux::AssertDir(fWorkDir.c_str(), ui, fChangeOwn) != 0) {
942 XPDERR(
"unable to assert working dir: " << fWorkDir);
945 if (fMUWorkDir.length() > 0) {
946 fMUWorkDir.replace(
"<workdir>", fWorkDir);
947 int iph = fMUWorkDir.find(
"<");
948 if (iph != STR_NPOS) {
949 wdir.assign(fMUWorkDir, 0, iph - 2);
950 if (XrdProofdAux::AssertDir(wdir.c_str(), ui, fChangeOwn) != 0) {
951 XPDERR(
"unable to assert working dir: " << wdir);
958 wdir = (fMultiUser && fMUWorkDir.length() > 0) ? fMUWorkDir : fWorkDir;
959 if (wdir.length() > 0) {
960 TRACE(ALL,
"working directories under: " << wdir);
962 XrdProofdSandbox::SetWorkdir(wdir.c_str());
966 if (fDataDir.length() > 0) {
967 if (fDataDir.endswith(
'/')) fDataDir.erasefromend(1);
968 if (fDataDirOpts.length() > 0) {
970 if (XrdProofdAux::AssertDir(fDataDir.c_str(), ui, fChangeOwn) != 0) {
971 XPDERR(
"unable to assert data dir: " << fDataDir <<
" (opts: "<<fDataDirOpts<<
")");
975 XrdSysPrivGuard pGuard((uid_t)ui.fUid, (gid_t)ui.fGid);
976 if (XpdBadPGuard(pGuard, ui.fUid)) {
977 TRACE(XERR,
"could not get privileges to set/change ownership of " << fDataDir);
980 if (chmod(fDataDir.c_str(), 0777) != 0) {
981 XPDERR(
"problems setting permissions 0777 data dir: " << fDataDir);
985 TRACE(ALL,
"data directories under: " << fDataDir);
989 if (fSrvType == kXPD_Worker) {
990 if (fMastersAllowed.size() > 0) {
991 std::list<XrdOucString *>::iterator i;
992 for (i = fMastersAllowed.begin(); i != fMastersAllowed.end(); ++i)
993 TRACE(ALL,
"masters allowed to connect: " << (*i)->c_str());
995 TRACE(ALL,
"masters allowed to connect: any");
1000 if (fPoolURL.length() <= 0) {
1002 fPoolURL =
"root://";
1005 TRACE(ALL,
"PROOF pool: " << fPoolURL);
1006 TRACE(ALL,
"PROOF pool namespace: " << fNamespace);
1009 if (fSrvType != kXPD_Worker) {
1012 if (!(fProofSched = LoadScheduler())) {
1013 XPDERR(
"scheduler initialization failed");
1016 const char *st[] = {
"disabled",
"enabled" };
1017 TRACE(ALL,
"user config files are " << st[fNetMgr->WorkerUsrCfg()]);
1022 TRACE(ALL,
"multi-process on nodes handled with proof-lite");
1026 if (fSrvType != kXPD_Worker && fDataSetSrcs.size() > 0) {
1028 std::list<XrdProofdDSInfo *>::iterator ii = fDataSetSrcs.begin();
1030 for (ii = fDataSetSrcs.begin(); ii != fDataSetSrcs.end();) {
1031 TRACE(ALL,
">> Defined dataset: " << (*ii)->ToString());
1032 if ((*ii)->fType ==
"file") {
1033 if (!(goodsrc = ValidateLocalDataSetSrc((*ii)->fUrl, (*ii)->fLocal))) {
1034 XPDERR(
"source " << (*ii)->fUrl <<
" could not be validated");
1035 ii = fDataSetSrcs.erase(ii);
1042 TRACE(ALL,
"Skipping validation (no \"file\" type dataset source)");
1046 if (fDataSetSrcs.size() > 0) {
1047 TRACE(ALL, fDataSetSrcs.size() <<
" dataset sources defined");
1048 for (ii = fDataSetSrcs.begin(); ii != fDataSetSrcs.end(); ++ii) {
1049 TRACE(ALL,
">> Valid dataset: " << (*ii)->ToString());
1050 if ((*ii)->fLocal && (*ii)->fRW) {
1051 if (fDataSetExp.length() > 0) fDataSetExp +=
",";
1052 fDataSetExp += ((*ii)->fUrl).c_str();
1056 TRACE(ALL,
"no dataset sources defined");
1059 TRACE(ALL,
"no dataset sources defined");
1064 if (XrdProofdAux::GetUserInfo(XrdProofdProtocol::EUidAtStartup(), sui) == 0) {
1065 if (fSuperUsers.find(sui.fUser.c_str()) == STR_NPOS) {
1066 if (fSuperUsers.length() > 0) fSuperUsers +=
",";
1067 fSuperUsers += sui.fUser;
1070 XPDFORM(msg,
"could not resolve effective uid %d (errno: %d)",
1071 XrdProofdProtocol::EUidAtStartup(), errno);
1074 XPDFORM(msg,
"list of superusers: %s", fSuperUsers.c_str());
1078 if (fOperationMode == kXPD_OpModeControlled) {
1082 while ((from = fSuperUsers.tokenize(usr, from,
',')) != STR_NPOS) {
1083 fAllowedUsers.Add(usr.c_str(),
new int(1));
1089 fAllowedUsers.Apply(RemoveInvalidUsers, (
void *)&ius);
1091 XPDFORM(msg,
"running in controlled access mode: users removed because"
1092 " unknown to the system: %s", ius.c_str());
1097 xpd_acm_lists_t uls;
1098 fAllowedUsers.Apply(FillKeyValues, (
void *)&uls);
1099 if (uls.allowed.length()) {
1100 XPDFORM(msg,
"running in controlled access mode: users allowed: %s", uls.allowed.c_str());
1103 if (uls.denied.length()) {
1104 XPDFORM(msg,
"running in controlled access mode: users denied: %s", uls.denied.c_str());
1108 xpd_acm_lists_t gls;
1109 fAllowedGroups.Apply(FillKeyValues, (
void *)&gls);
1110 if (gls.allowed.length()) {
1111 XPDFORM(msg,
"running in controlled access mode: UNIX groups allowed: %s", gls.allowed.c_str());
1114 if (gls.denied.length()) {
1115 XPDFORM(msg,
"running in controlled access mode: UNIX groups denied: %s", gls.denied.c_str());
1121 if (getenv(XPD_LIBPATH)) {
1123 if (fRemoveROOTLibPaths || fLibPathsToRemove.Num() > 0) {
1125 XrdOucString paths = getenv(XPD_LIBPATH);
1128 while ((from = paths.tokenize(ldir, from,
':')) != STR_NPOS) {
1130 if (ldir.length() > 0) {
1131 if (fLibPathsToRemove.Num() > 0 && fLibPathsToRemove.Find(ldir.c_str())) {
1133 }
else if (fRemoveROOTLibPaths) {
1135 DIR *dir = opendir(ldir.c_str());
1138 struct dirent *ent = 0;
1139 while ((ent = (
struct dirent *)readdir(dir))) {
1140 if (!strncmp(ent->d_name,
"libCore", 7)) {
1151 if (fBareLibPath.length() > 0)
1152 fBareLibPath +=
":";
1153 fBareLibPath += ldir;
1156 ctrim =
" (lib paths filter applied)";
1160 ctrim += XPD_LIBPATH;
1162 fBareLibPath = getenv(XPD_LIBPATH);
1164 TRACE(ALL,
"bare lib path for proofserv" << ctrim <<
": " << fBareLibPath);
1170 fGroupsMgr =
new XrdProofGroupMgr;
1173 fGroupsMgr->Print(0);
1176 if (fAdmin && fAdmin->Config(rcf) != 0) {
1177 XPDERR(
"problems configuring the admin handler");
1182 if (fNetMgr && fNetMgr->Config(rcf) != 0) {
1183 XPDERR(
"problems configuring the network manager");
1188 if (fPriorityMgr && fPriorityMgr->Config(rcf) != 0) {
1189 XPDERR(
"problems configuring the priority manager");
1195 fROOTMgr->SetLogDir(fAdminPath.c_str());
1196 if (fROOTMgr && fROOTMgr->Config(rcf) != 0) {
1197 XPDERR(
"problems configuring the ROOT versions manager");
1203 if (fClientMgr && fClientMgr->Config(rcf) != 0) {
1204 XPDERR(
"problems configuring the client manager");
1209 if (fSessionMgr && fSessionMgr->Config(rcf) != 0) {
1210 XPDERR(
"problems configuring the session manager");
1215 if (fProofSched && fProofSched->Config(rcf) != 0) {
1216 XPDERR(
"problems configuring the scheduler");
1221 if (!(fXrootd = LoadXrootd(fParms, fPi, fEDest))) {
1222 TRACE(ALL,
"file serving (protocol: 'root://') not available");
1228 if (XrdSysThread::Run(&tid, XrdProofdManagerCron,
1229 (
void *)
this, 0,
"ProofdManager cron thread") != 0) {
1230 XPDERR(
"could not start cron thread");
1233 TRACE(ALL,
"manager cron thread started");
1245 bool XrdProofdManager::ValidateLocalDataSetSrc(XrdOucString &url,
bool &local)
1247 XPDLOC(ALL,
"Manager::ValidateLocalDataSetSrc")
1249 TRACE(ALL, "validating '" << url << "' ...");
1252 if (url.length() > 0) {
1254 if (url.beginswith(
"file:")) url.replace(
"file:",
"");
1255 if (url.beginswith(
"/")) {
1260 XrdProofdAux::GetUserInfo(XrdProofdProtocol::EUidAtStartup(), ui);
1261 if (XrdProofdAux::AssertDir(url.c_str(), ui, ChangeOwn()) == 0) {
1263 if (XrdProofdAux::ChangeMod(url.c_str(), 0777) != 0) {
1264 TRACE(XERR,
"Problems setting permissions 0777 on path '" << url <<
"'");
1267 TRACE(XERR,
"Cannot assert path '" << url <<
"' - ignoring");
1271 XrdOucString fnpath(url.c_str());
1272 fnpath +=
"/dataset.list";
1273 if (access(fnpath.c_str(), F_OK) != 0) {
1274 FILE *flst = fopen(fnpath.c_str(),
"w");
1276 TRACE(XERR,
"Cannot open file '" << fnpath <<
"' for the dataset list; errno: " << errno);
1279 if (fclose(flst) != 0)
1280 TRACE(XERR,
"Problems closing file '" << fnpath <<
"'; errno: " << errno);
1281 if (XrdProofdAux::ChangeOwn(fnpath.c_str(), ui) != 0) {
1282 TRACE(XERR,
"Problems asserting ownership of " << fnpath);
1287 if (goodsrc && XrdProofdAux::ChangeMod(fnpath.c_str(), 0666) != 0) {
1288 TRACE(XERR,
"Problems setting permissions to 0666 on file '" << fnpath <<
"'; errno: " << errno);
1293 fnpath.replace(
"/dataset.list",
"/lock.location");
1294 FILE *flck = fopen(fnpath.c_str(),
"a");
1296 TRACE(XERR,
"Cannot open file '" << fnpath <<
"' with the lock file path; errno: " << errno);
1299 off_t ofs = lseek(fileno(flck), 0, SEEK_CUR);
1302 XrdOucString fnlock(url);
1303 fnlock.replace(
"/",
"%");
1304 fnlock.replace(
":",
"%");
1305 fnlock.insert(
"/tmp/", 0);
1306 fprintf(flck,
"%s\n", fnlock.c_str());
1307 if (fclose(flck) != 0)
1308 TRACE(XERR,
"Problems closing file '" << fnpath <<
"'; errno: " << errno);
1310 if (XrdProofdAux::ChangeOwn(fnpath.c_str(), ui) != 0) {
1311 TRACE(XERR,
"Problems asserting ownership of " << fnpath);
1313 }
else if (ofs == (off_t)(-1)) {
1314 TRACE(XERR,
"Problems getting current position on file '" << fnpath <<
"'; errno: " << errno);
1316 if (flck && fclose(flck) != 0)
1317 TRACE(XERR,
"Problems closing file '" << fnpath <<
"'; errno: " << errno);
1321 if (goodsrc && XrdProofdAux::ChangeMod(fnpath.c_str(), 0644) != 0) {
1322 TRACE(XERR,
"Problems setting permissions to 0644 on file '" << fnpath <<
"'; errno: " << errno);
1328 TRACE(ALL,
"New dataset with no URL!");
1337 void XrdProofdManager::RegisterDirectives()
1340 Register(
"trace",
new XrdProofdDirective(
"trace",
this, &DoDirectiveClass));
1341 Register(
"groupfile",
new XrdProofdDirective(
"groupfile",
this, &DoDirectiveClass));
1342 Register(
"multiuser",
new XrdProofdDirective(
"multiuser",
this, &DoDirectiveClass));
1343 Register(
"maxoldlogs",
new XrdProofdDirective(
"maxoldlogs",
this, &DoDirectiveClass));
1344 Register(
"allow",
new XrdProofdDirective(
"allow",
this, &DoDirectiveClass));
1345 Register(
"allowedgroups",
new XrdProofdDirective(
"allowedgroups",
this, &DoDirectiveClass));
1346 Register(
"allowedusers",
new XrdProofdDirective(
"allowedusers",
this, &DoDirectiveClass));
1347 Register(
"role",
new XrdProofdDirective(
"role",
this, &DoDirectiveClass));
1348 Register(
"cron",
new XrdProofdDirective(
"cron",
this, &DoDirectiveClass));
1349 Register(
"port",
new XrdProofdDirective(
"port",
this, &DoDirectiveClass));
1350 Register(
"datadir",
new XrdProofdDirective(
"datadir",
this, &DoDirectiveClass));
1351 Register(
"datasetsrc",
new XrdProofdDirective(
"datasetsrc",
this, &DoDirectiveClass));
1352 Register(
"xrd.protocol",
new XrdProofdDirective(
"xrd.protocol",
this, &DoDirectiveClass));
1353 Register(
"filterlibpaths",
new XrdProofdDirective(
"filterlibpaths",
this, &DoDirectiveClass));
1354 Register(
"xrootd",
new XrdProofdDirective(
"xrootd",
this, &DoDirectiveClass));
1356 Register(
"tmp",
new XrdProofdDirective(
"tmp", (
void *)&fTMPdir, &DoDirectiveString));
1357 Register(
"poolurl",
new XrdProofdDirective(
"poolurl", (
void *)&fPoolURL, &DoDirectiveString));
1358 Register(
"namespace",
new XrdProofdDirective(
"namespace", (
void *)&fNamespace, &DoDirectiveString));
1359 Register(
"superusers",
new XrdProofdDirective(
"superusers", (
void *)&fSuperUsers, &DoDirectiveString));
1360 Register(
"image",
new XrdProofdDirective(
"image", (
void *)&fImage, &DoDirectiveString));
1361 Register(
"workdir",
new XrdProofdDirective(
"workdir", (
void *)&fWorkDir, &DoDirectiveString));
1362 Register(
"sockpathdir",
new XrdProofdDirective(
"sockpathdir", (
void *)&fSockPathDir, &DoDirectiveString));
1363 Register(
"remoteplite",
new XrdProofdDirective(
"remoteplite", (
void *)&fRemotePLite, &DoDirectiveInt));
1364 Register(
"stagereqrepo",
new XrdProofdDirective(
"stagereqrepo", (
void *)&fStageReqRepo, &DoDirectiveString));
1380 int XrdProofdManager::ResolveKeywords(XrdOucString &s, XrdProofdClient *pcl)
1382 XPDLOC(ALL,
"Manager::ResolveKeywords")
1386 TRACE(HDBG, "enter: " << s << " - WorkDir(): " << WorkDir());
1389 if (s.replace("<workdir>", WorkDir()))
1392 TRACE(HDBG, "after <workdir>: " << s);
1395 if (s.replace("<host>", Host()))
1398 TRACE(HDBG, "after <host>: " << s);
1401 if (s.find("<port>") != STR_NPOS) {
1404 if (s.replace(
"<port>", sport.c_str()))
1409 if (s.find(
"<effuser>") != STR_NPOS) {
1411 if (XrdProofdAux::GetUserInfo(geteuid(), eui) == 0) {
1412 if (s.replace(
"<effuser>", eui.fUser.c_str()))
1419 if (s.replace(
"<user>", pcl->User()))
1424 if (s.replace(
"<group>", pcl->Group()))
1429 if (s.replace(
"<homedir>", pcl->UI().fHomeDir.c_str()))
1433 if (pcl && (s.find(
"<uid>") != STR_NPOS)) {
1435 suid += pcl->UI().fUid;
1436 if (s.replace(
"<uid>", suid.c_str()))
1441 if (pcl && (s.find(
"<gid>") != STR_NPOS)) {
1443 sgid += pcl->UI().fGid;
1444 if (s.replace(
"<gid>", sgid.c_str()))
1448 TRACE(HDBG,
"exit: " << s);
1460 int XrdProofdManager::DoDirective(XrdProofdDirective *d,
1461 char *val, XrdOucStream *cfg,
bool rcf)
1463 XPDLOC(ALL,
"Manager::DoDirective")
1469 if (d->fName == "trace") {
1470 return DoDirectiveTrace(val, cfg, rcf);
1471 }
else if (d->fName ==
"groupfile") {
1472 return DoDirectiveGroupfile(val, cfg, rcf);
1473 }
else if (d->fName ==
"maxoldlogs") {
1474 return DoDirectiveMaxOldLogs(val, cfg, rcf);
1475 }
else if (d->fName ==
"allow") {
1476 return DoDirectiveAllow(val, cfg, rcf);
1477 }
else if (d->fName ==
"allowedgroups") {
1478 return DoDirectiveAllowedGroups(val, cfg, rcf);
1479 }
else if (d->fName ==
"allowedusers") {
1480 return DoDirectiveAllowedUsers(val, cfg, rcf);
1481 }
else if (d->fName ==
"role") {
1482 return DoDirectiveRole(val, cfg, rcf);
1483 }
else if (d->fName ==
"multiuser") {
1484 return DoDirectiveMultiUser(val, cfg, rcf);
1485 }
else if (d->fName ==
"port") {
1486 return DoDirectivePort(val, cfg, rcf);
1487 }
else if (d->fName ==
"datadir") {
1488 return DoDirectiveDataDir(val, cfg, rcf);
1489 }
else if (d->fName ==
"datasetsrc") {
1490 return DoDirectiveDataSetSrc(val, cfg, rcf);
1491 }
else if (d->fName ==
"rootd") {
1492 return DoDirectiveRootd(val, cfg, rcf);
1493 }
else if (d->fName ==
"rootdallow") {
1494 return DoDirectiveRootdAllow(val, cfg, rcf);
1495 }
else if (d->fName ==
"xrd.protocol") {
1496 return DoDirectivePort(val, cfg, rcf);
1497 }
else if (d->fName ==
"filterlibpaths") {
1498 return DoDirectiveFilterLibPaths(val, cfg, rcf);
1499 }
else if (d->fName ==
"xrootd") {
1500 return DoDirectiveXrootd(val, cfg, rcf);
1502 TRACE(XERR,
"unknown directive: " << d->fName);
1509 int XrdProofdManager::DoDirectiveTrace(
char *val, XrdOucStream *cfg,
bool)
1511 XPDLOC(ALL,
"Manager::DoDirectiveTrace")
1548 while (val && val[0]) {
1550 if (val[0] ==
'-') {
1554 if (!strcmp(val,
"err")) {
1556 }
else if (!strcmp(val,
"req")) {
1558 }
else if (!strcmp(val,
"dbg")) {
1560 TRACESET(LOGIN, on);
1563 }
else if (!strcmp(val,
"login")) {
1564 TRACESET(LOGIN, on);
1565 }
else if (!strcmp(val,
"fork")) {
1567 }
else if (!strcmp(val,
"mem")) {
1569 }
else if (!strcmp(val,
"hdbg")) {
1572 TRACESET(LOGIN, on);
1575 }
else if (!strcmp(val,
"rsp")) {
1577 }
else if (!strcmp(val,
"aux")) {
1579 }
else if (!strcmp(val,
"cmgr")) {
1581 }
else if (!strcmp(val,
"smgr")) {
1583 }
else if (!strcmp(val,
"nmgr")) {
1585 }
else if (!strcmp(val,
"pmgr")) {
1587 }
else if (!strcmp(val,
"gmgr")) {
1589 }
else if (!strcmp(val,
"sched")) {
1590 TRACESET(SCHED, on);
1591 }
else if (!strcmp(val,
"all") || !strcmp(val,
"dump")) {
1593 TRACE(ALL,
"Setting trace: " << on);
1594 XrdProofdTrace->What = (on) ? TRACE_ALL : 0;
1598 val = cfg->GetWord();
1607 int XrdProofdManager::DoDirectiveGroupfile(
char *val, XrdOucStream *cfg,
bool rcf)
1609 XPDLOC(ALL,
"Manager::DoDirectiveGroupfile")
1617 if (XrdProofdAux::CheckIf(cfg, Host()) == 0)
1622 SafeDelete(fGroupsMgr);
1623 }
else if (fGroupsMgr) {
1624 TRACE(XERR,
"groups manager already initialized: ignoring ");
1627 fGroupsMgr =
new XrdProofGroupMgr;
1628 fGroupsMgr->Config(val);
1635 int XrdProofdManager::DoDirectiveMaxOldLogs(
char *val, XrdOucStream *cfg,
bool)
1643 if (XrdProofdAux::CheckIf(cfg, Host()) == 0)
1647 int maxoldlogs = strtol(val, 0, 10);
1648 XrdProofdSandbox::SetMaxOldSessions(maxoldlogs);
1655 int XrdProofdManager::DoDirectiveAllow(
char *val, XrdOucStream *cfg,
bool)
1663 if (XrdProofdAux::CheckIf(cfg, Host()) == 0)
1667 fMastersAllowed.push_back(
new XrdOucString(val));
1674 int XrdProofdManager::DoDirectiveAllowedGroups(
char *val, XrdOucStream *cfg,
bool)
1682 if (XrdProofdAux::CheckIf(cfg, Host()) == 0)
1686 fOperationMode = kXPD_OpModeControlled;
1689 XrdOucString s = val;
1691 XrdOucString grp, gid;
1693 while ((from = s.tokenize(grp, from,
',')) != STR_NPOS) {
1695 if (grp.beginswith(
'-')) {
1697 grp.erasefromstart(1);
1700 if (XrdProofdAux::GetGroupInfo(grp.c_str(), gi) == 0) {
1702 gid.form(
"%d", (
int) gi.fGid);
1703 fAllowedGroups.Add(gid.c_str(),
new int(st));
1706 fAllowedGroups.Add(grp.c_str(),
new int(st));
1716 int XrdProofdManager::DoDirectiveAllowedUsers(
char *val, XrdOucStream *cfg,
bool)
1724 if (XrdProofdAux::CheckIf(cfg, Host()) == 0)
1728 fOperationMode = kXPD_OpModeControlled;
1731 XrdOucString s = val;
1735 while ((from = s.tokenize(usr, from,
',')) != STR_NPOS) {
1737 if (usr.beginswith(
'-')) {
1739 usr.erasefromstart(1);
1743 fAllowedUsers.Add(usr.c_str(),
new int(st));
1753 int XrdProofdManager::DoDirectiveRole(
char *val, XrdOucStream *cfg,
bool)
1761 if (XrdProofdAux::CheckIf(cfg, Host()) == 0)
1765 XrdOucString tval(val);
1766 if (tval ==
"supermaster") {
1767 fSrvType = kXPD_TopMaster;
1769 }
else if (tval ==
"master") {
1770 fSrvType = kXPD_TopMaster;
1771 }
else if (tval ==
"submaster") {
1772 fSrvType = kXPD_Master;
1773 }
else if (tval ==
"worker") {
1774 fSrvType = kXPD_Worker;
1775 }
else if (tval ==
"any") {
1776 fSrvType = kXPD_AnyServer;
1785 int XrdProofdManager::DoDirectivePort(
char *val, XrdOucStream *,
bool)
1791 XrdOucString port(val);
1792 if (port.beginswith(
"xproofd:")) {
1793 port.replace(
"xproofd:",
"");
1795 if (port.length() > 0 && port.isdigit()) {
1796 fPort = strtol(port.c_str(), 0, 10);
1798 fPort = (fPort < 0) ? XPD_DEF_PORT : fPort;
1806 int XrdProofdManager::DoDirectiveMultiUser(
char *val, XrdOucStream *cfg,
bool)
1808 XPDLOC(ALL,
"Manager::DoDirectiveMultiUser")
1815 int mu = strtol(val, 0, 10);
1816 fMultiUser = (mu == 1) ? 1 : fMultiUser;
1819 val = cfg->GetWord();
1820 if (val) fMUWorkDir = val;
1822 TRACE(DBG, "fMultiUser: "<< fMultiUser << " work dir template: " << fMUWorkDir);
1830 int XrdProofdManager::DoDirectiveDataSetSrc(
char *val, XrdOucStream *cfg,
bool)
1837 XrdOucString type(val), url, opts, obscure;
1838 bool rw = 0, local = 0, goodsrc = 1;
1840 while ((nxt = cfg->GetWord())) {
1841 if (!strcmp(nxt,
"rw=1") || !strcmp(nxt,
"rw:1")) {
1843 }
else if (!strncmp(nxt,
"url:", 4)) {
1845 XrdClientUrlInfo u(url);
1846 if (u.Proto ==
"" && u.HostWPort ==
"") local = 1;
1847 }
else if (!strncmp(nxt,
"opt:", 4)) {
1858 std::list<XrdProofdDSInfo *>::iterator ii = fDataSetSrcs.begin();
1860 for (ii = fDataSetSrcs.begin(); ii != fDataSetSrcs.end(); ++ii) {
1861 if ((*ii)->fLocal) {
1867 if (opts.length() <= 0) {
1868 opts = rw ?
"Ar:Av:" :
"-Ar:-Av:";
1870 XrdProofdDSInfo *dsi =
new XrdProofdDSInfo(type.c_str(), url.c_str(),
1871 local, rw, opts.c_str(), obscure.c_str());
1872 if (haslocal || !local) {
1873 fDataSetSrcs.push_back(dsi);
1875 fDataSetSrcs.push_front(dsi);
1884 int XrdProofdManager::DoDirectiveDataDir(
char *val, XrdOucStream *cfg,
bool)
1893 fDataDirUrlOpts =
"";
1896 while ((nxt = cfg->GetWord()) && (opts.length() == 0)) {
1899 if (opts.length() > 0) fDataDirOpts = opts;
1902 if ((iq = fDataDir.rfind(
'?')) != STR_NPOS) {
1903 fDataDirUrlOpts.assign(fDataDir, iq + 1);
1915 int XrdProofdManager::DoDirectiveXrootd(
char *val, XrdOucStream *,
bool)
1917 XPDLOC(ALL,
"Manager::DoDirectiveXrootd")
1922 TRACE(ALL, "val: "<< val);
1924 if (XrdMajorVNUM(XrdVNUMBER) < 4) {
1925 TRACE(ALL,
"WARNING: built against an XRootD version without libXrdXrootd.so :");
1926 TRACE(ALL,
"WARNING: loading external " << val <<
" may lead to incompatibilities");
1929 fXrootdLibPath = val;
1940 int XrdProofdManager::DoDirectiveRootd(
char *, XrdOucStream *,
bool)
1942 XPDLOC(ALL,
"Manager::DoDirectiveRootd")
1944 TRACE(ALL, "unsupported!!! ");
1955 int XrdProofdManager::DoDirectiveRootdAllow(
char *, XrdOucStream *,
bool)
1957 XPDLOC(ALL,
"Manager::DoDirectiveRootdAllow")
1959 TRACE(ALL, "unsupported!!! ");
1969 int XrdProofdManager::DoDirectiveFilterLibPaths(
char *val, XrdOucStream *cfg,
bool)
1971 XPDLOC(ALL,
"Manager::DoDirectiveRemoveLibPaths")
1978 fLibPathsToRemove.Purge();
1980 TRACE(ALL, "val: "<< val);
1983 fRemoveROOTLibPaths = (!strcmp(val, "1") || !strcmp(val, "yes")) ? 1 : 0;
1984 if (fRemoveROOTLibPaths)
1985 TRACE(ALL, "Filtering out ROOT lib paths from "<<XPD_LIBPATH);
1989 while ((nxt = cfg->GetWord())) {
1990 XrdOucString pps(nxt), p;
1992 while ((from = pps.tokenize(p, from,
',')) != -1) {
1993 if (p.length() > 0) {
1994 fLibPathsToRemove.Add(p.c_str(), 0, 0, Hash_data_is_key);
1995 TRACE(ALL,
"Filtering out from "<<XPD_LIBPATH<<
" lib path '"<<p<<
"'");
2007 int XrdProofdManager::Process(XrdProofdProtocol *p)
2009 XPDLOC(ALL,
"Manager::Process")
2012 XPD_SETRESP(p, "Process");
2014 TRACEP(p, REQ, "req
id: " << p->Request()->header.requestid << " (" <<
2015 XrdProofdAux::ProofRequestTypes(p->Request()->header.requestid) << ")");
2018 if (!p->Status() || !(p->Status() & XPD_LOGGEDIN)) {
2019 switch (p->Request()->header.requestid) {
2021 return fClientMgr->Auth(p);
2023 return fClientMgr->Login(p);
2025 TRACEP(p, XERR,
"invalid request: " << p->Request()->header.requestid);
2026 response->Send(kXR_InvalidRequest,
"Invalid request; user not logged in");
2027 return p->Link()->setEtext(
"protocol sequence error 1");
2033 switch (p->Request()->header.requestid) {
2035 int type = ntohl(p->Request()->proof.int1);
2036 return fAdmin->Process(p, type);
2039 return fNetMgr->ReadBuffer(p);
2044 return fSessionMgr->Process(p);
2046 emsg +=
"Invalid request: ";
2047 emsg += p->Request()->header.requestid;
2052 response->Send(kXR_InvalidRequest, emsg.c_str());