319{
320
321
322
323
324
325
326
327 const char *xrdInst="XRDINSTANCE=";
328
329 int retc, NoGo = 0, clPort = -1;
330 const char *temp;
331 char c, buff[512], *dfltProt, *libProt = 0;
332 uid_t myUid = 0;
333 gid_t myGid = 0;
334 extern char *optarg;
335 extern int optind, opterr;
336 struct XrdOucLogging::configLogInfo LogInfo;
337 int pipeFD[2] = {-1, -1};
338 const char *pidFN = 0;
339 static const int myMaxc = 80;
340 char **urArgv, *myArgv[myMaxc], argBuff[myMaxc*3+8];
341 char *argbP = argBuff, *argbE = argbP+sizeof(argBuff)-4;
342 char *ifList = 0;
343 int myArgc = 1, urArgc = argc, i;
344 bool noV6, ipV4 = false, ipV6 = false, rootChk = true, optbg = false;
345
346
347
348 XrdOucString CmdLine(argv[0]);
349 for (int k = 1; k < argc; k++)
350 {CmdLine += ' '; CmdLine += argv[k];}
351
352
353
354 retc = strlen(argv[0]);
355 while(retc--) if (argv[0][retc] == '/') break;
356 myProg = &argv[0][retc+1];
357
358
359
360
361
362
363 {char *p = dfltProt = strdup(myProg);
364 while(*p && (*p == '.' || *p == '-')) p++;
365 if (*p)
366 {char *dot = index(p, '.'), *dash = index(p, '-');
367 if (dot && (dot < dash || !dash)) p = dot;
368 else if (dash) p = dash;
369 else p = 0;
370 if (p) *p = '\0';
371 if (!strcmp("xrootd", dfltProt)) dfltProt[5] = 0;
372 else if (!strcmp("cmsd", dfltProt)) dfltProt[3] = 0;
373 }
374 }
375 myArgv[0] = argv[0];
376
377
378
379
380 i = 1;
381 while(i < argc)
382 {if (*(argv[i]) == '-' && *(argv[i]+1) == '+')
383 {int n = strlen(argv[i]+2), j = i+1, k = 1;
384 if (urArgc == argc) urArgc = i;
385 if (n) memcpy(buff, argv[i]+2, (n > 256 ? 256 : n));
386 strcpy(&(buff[n]), ".argv**");
387 while(j < argc && (*(argv[j]) != '-' || *(argv[j]+1) != '+')) j++;
388 urArgv = new char*[j-i+1];
389 urArgv[0] = argv[0];
390 i++;
391 while(i < j) urArgv[k++] = argv[i++];
392 urArgv[k] = 0;
394 strcpy(&(buff[n]), ".argc");
396 } else i++;
397 }
399
400
401
402
403 opterr = 0;
404 if (argc > 1 && '-' == *argv[1])
405 while ((c = getopt(urArgc,argv,":a:A:bc:dhHI:k:l:L:n:N:p:P:R:s:S:vw:W:z"))
406 && ((unsigned char)c != 0xff))
407 { switch(c)
408 {
409 case 'a': if (AdminPath) free(AdminPath);
410 AdminPath = strdup(optarg);
411 AdminMode =
ProtInfo.AdmMode = S_IRWXU;
413 break;
414 case 'A': if (AdminPath) free(AdminPath);
415 AdminPath = strdup(optarg);
416 AdminMode =
ProtInfo.AdmMode = S_IRWXU | S_IRWXG;
418 break;
419 case 'b': optbg = true;
420 break;
421 case 'c': if (ConfigFN) free(ConfigFN);
422 ConfigFN = strdup(optarg);
423 break;
427 break;
429 break;
431 break;
432 case 'I': if (!strcmp("v4", optarg)) {ipV4 = true; ipV6 = false;}
433 else if (!strcmp("v6", optarg)) {ipV4 = false; ipV6 = true;}
434 else {
Log.
Emsg(
"Config",
"Invalid -I argument -",optarg);
436 }
437 break;
439 {
Log.
Emsg(
"Config",
"Invalid -k argument -",optarg);
441 }
442 break;
443 case 'l': LogInfo.logArg = optarg;
444 break;
445 case 'L': if (!*optarg)
446 {
Log.
Emsg(
"Config",
"Protocol library path not specified.");
448 }
449 if (libProt) free(libProt);
450 libProt = strdup(optarg);
451 break;
452 case 'n': myInsName = (!strcmp(optarg,"anon")||!strcmp(optarg,"default")
453 ? 0 : optarg);
454 break;
456 break;
458 break;
459 case 'P': if (dfltProt) free(dfltProt);
460 dfltProt = strdup(optarg);
461 break;
462 case 'R':
if (!(getUG(optarg, myUid, myGid)))
Usage(1);
463 rootChk = false;
464 break;
465 case 's': pidFN = optarg;
466 break;
467 case 'S': mySitName = optarg;
468 break;
469 case ':': buff[0] =
'-'; buff[1] =
optopt; buff[2] = 0;
470 Log.
Emsg(
"Config", buff,
"parameter not specified.");
472 break;
473 case 'v': std::cerr <<XrdVSTRING <<std::endl;
474 _exit(0);
475 break;
476 case 'w': if (HomePath) free(HomePath);
477 HomePath = strdup(optarg);
478 HomeMode = S_IRWXU;
479 Specs |= hpSpec;
480 break;
481 case 'W': if (HomePath) free(HomePath);
482 HomePath = strdup(optarg);
483 HomeMode = S_IRWXU | S_IRGRP | S_IXGRP;
484 Specs |= hpSpec;
485 break;
486 case 'z': LogInfo.hiRes = true;
487 break;
488
490 {
Log.
Emsg(
"Config",
"Long options are not supported.");
492 }
493 if (myArgc >= myMaxc || argbP >= argbE)
494 {
Log.
Emsg(
"Config",
"Too many command line arguments.");
496 }
497 myArgv[myArgc++] = argbP;
498 *argbP++ =
'-'; *argbP++ =
optopt; *argbP++ = 0;
499 break;
500 }
501 }
502
503
504
506 {
Log.
Emsg(
"Config",
"Command line adminpath is not absolute.");
507 exit(17);
508 }
509
510
511
512 if (HomePath && *HomePath != '/')
513 {
Log.
Emsg(
"Config",
"Command line home path is not absolute.");
514 exit(17);
515 }
516
517
518
519
520 if (ConfigFN) setCFG(true);
521
522
523
526 else if (ipV6){
if (noV6)
Log.
Say(
"Config warning: ipV6 appears to be broken;"
527 " forced ipV6 mode not advised!");
529 }
530 else if (noV6)
Log.
Say(
"Config warning: ipV6 is misconfigured or "
531 "unavailable; reverting to ipV4.");
532
533
534
536
537
538
539 if (myGid && setegid(myGid))
540 {
Log.
Emsg(
"Config", errno,
"set effective gid"); exit(17);}
541 if (myUid && seteuid(myUid))
542 {
Log.
Emsg(
"Config", errno,
"set effective uid"); exit(17);}
543
544
545
546 if (rootChk && geteuid() == 0)
547 {
Log.
Emsg(
"Config",
"Security reasons prohibit running as "
548 "superuser; program is terminating.");
549 _exit(8);
550 }
551
552
553
554 if (urArgc-
optind+2 >= myMaxc)
555 {
Log.
Emsg(
"Config",
"Too many command line arguments.");
557 }
559
560
561
562 myArgv[myArgc] = 0;
565
566
567
568 if (optbg)
569 {
570#ifdef WIN32
572#else
573 if (pipe( pipeFD ) == -1)
574 {
Log.
Emsg(
"Config", errno,
"create a pipe"); exit(17);}
576#endif
577 }
578
579
580
581
582 static XrdNetAddr *myIPAddr = new XrdNetAddr((int)0);
583 if (!(myName = myIPAddr->
Name(0, &temp))) myName =
"";
584
585
586
591
592
593
594
595
596 sprintf(buff,
"%s%s %s@%s", xrdInst, myProg,
ProtInfo.myInst, myName);
597 myInstance = strdup(buff);
598 putenv(myInstance);
599 myInstance += strlen(xrdInst);
603
604
605
606 if (LogInfo.logArg)
607 {LogInfo.xrdEnv = &
theEnv;
608 LogInfo.iName = myInsName;
609 LogInfo.cfgFn = ConfigFN;
613 }
614
615
616
617
618
619 if (!(*myName))
620 {
Log.
Emsg(
"Config",
"Unable to determine host name; ",
621 (temp ? temp : "reason unknown"),
622 "; execution terminated.");
623 _exit(16);
624 }
625
626
627
629
630
631
632 strcpy(buff, "Starting on ");
633 retc = strlen(buff);
636 Log.
Say(0, CmdLine.c_str());
638
639
640
641
642
644 {
Log.
Emsg(
"Config",myName,
"does not appear to be registered in the DNS.");
645 Log.
Emsg(
"Config",
"Verify that the '/etc/hosts' file is correct and "
646 "this machine is registered in DNS.");
647 Log.
Emsg(
"Config",
"Execution continues but connection failures may occur.");
648 myDomain = 0;
649 } else if (!(myDomain = index(myName, '.')))
650 Log.
Say(
"Config warning: this hostname, ", myName,
651 ", is registered without a domain qualification.");
652
653
654
655 Firstcp = Lastcp = new XrdConfigProt(strdup(dfltProt), libProt, 0);
656
657
658
659 Log.
Say(
"++++++ ", myInstance,
" initialization started.");
660
661
662
663 devNull = XrdSysFD_Open(
"/dev/null", O_RDONLY);
665 {
Log.
Emsg(
"Config", errno,
"open '/dev/null' which is required!");
666 NoGo = 1;
667 }
668
669
670
671 if (ConfigFN)
672 {
Log.
Say(
"Config using configuration file ", ConfigFN);
674 NoGo = ConfigProc();
675 }
676 if (clPort >= 0) PortTCP = clPort;
680 }
681
682
683
684 NoGo |= SetupAPath();
685
686
687
688 if (!NoGo)
690 else {
Log.
Say(
"++++++ ", myInstance,
" TLS initialization started.");
691 if (SetupTLS())
692 {
Log.
Say(
"------ ",myInstance,
" TLS initialization ended.");
695 } else {
696 NoGo = 1;
697 Log.
Say(
"------ ",myInstance,
" TLS initialization failed.");
698 }
699 }
700 }
701
702
703
704
705 if (!NoGo)
707 {
Log.
Say(
"Config TLS port specification ignored; TLS not configured!");
708 PortTLS = -1;
709 } else {
711 ProtInfo.tlsPort = (PortTLS > 0 ? PortTLS : 0);
712 }
713 }
714
715
716
718
719
720
723
724
725
727 {
Log.
Emsg(
"Config",
"Unable to determine interface addresses!");
728 NoGo = 1;
729 }
730
731
732
733 if ((myInsName || HomePath)
735
736
737
738 if (!PidFile(pidFN, optbg)) NoGo = 1;
739
740
741
742 if (!NoGo) Manifest(pidFN);
743
744
745
746 if (!NoGo) NoGo = Setup(dfltProt, libProt);
747
748
749
750 setCFG(false);
751
752
753
754
755 if (tmoInfo && !NoGo)
757 if (!theGS)
Log.
Say(
"Config warning: TCP monitoring not enabled; "
758 "tcpmonlib plugin not loaded!");
759 else {tmoInfo->theEnv.PutPtr("TcpMon.gStream*", theGS);
760 TcpMonPin = tmoInfo->KingPin.Load(
"TcpMonPin");
762 }
763 }
764
765
766
767#ifndef WIN32
768 if (optbg)
769 {
770 int status = NoGo ? 1 : 0;
771 if(
write( pipeFD[1], &status,
sizeof( status ) )) {};
773 }
774#endif
775
776
777
778 temp = (NoGo ? " initialization failed." : " initialization completed.");
779 sprintf(buff, "%s:%d", myInstance, PortTCP);
780 Log.
Say(
"------ ", buff, temp);
781 if (LogInfo.logArg)
782 {strcat(buff, " running ");
783 retc = strlen(buff);
786 }
787 return NoGo;
788}
void Usage(const char *msg)
const sockaddr * SockAddr()
const char * Name(const char *eName=0, const char **eText=0)
static int GetIF(XrdOucTList **ifList, const char **eText=0)
static void SetMsgs(XrdSysError *erp)
static void SetFQN(const char *fqn)
void PutInt(const char *varname, long value)
static int Export(const char *Var, const char *Val)
void * GetPtr(const char *varname)
void PutPtr(const char *varname, void *value)
static bool configLog(XrdSysError &eDest, configLogInfo &logInfo)
static const char * Set(const char *name, int maxlen=15)
static const char * InstName(int TranOpt=0)
static void makeHome(XrdSysError &eDest, const char *inst)
static void Undercover(XrdSysError &eDest, int noLog, int *pipeFD=0)
static int a2p(XrdSysError &, const char *ptype, const char *val, bool anyOK=true)
int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0)
void Say(const char *text1, const char *text2=0, const char *txt3=0, const char *text4=0, const char *text5=0, const char *txt6=0)
XrdSysLogger * logger(XrdSysLogger *lp=0)
void AddMsg(const char *msg)
int ParseKeep(const char *arg)
static void setDebug(XrdSysError *erp)
static int FmtUname(char *buff, int blen)