326{
327
328
329
330
331
332
333
334 const char *xrdInst="XRDINSTANCE=";
335
336 int retc, NoGo = 0, clPort = -1;
337 const char *temp;
338 char c, buff[512], *dfltProt, *libProt = 0;
339 uid_t myUid = 0;
340 gid_t myGid = 0;
341 extern char *optarg;
342 extern int optind, opterr;
344 int pipeFD[2] = {-1, -1};
345 const char *pidFN = 0;
346 static const int myMaxc = 80;
347 char **urArgv, *myArgv[myMaxc], argBuff[myMaxc*3+8];
348 char *argbP = argBuff, *argbE = argbP+sizeof(argBuff)-4;
349 char *ifList = 0;
350 int myArgc = 1, urArgc = argc, i;
351 bool noV6, ipV4 = false, ipV6 = false, rootChk = true, optbg = false;
352
353
354
356 for (int k = 1; k < argc; k++)
357 {CmdLine += ' '; CmdLine += argv[k];}
358
359
360
361 retc = strlen(argv[0]);
362 while(retc--) if (argv[0][retc] == '/') break;
363 myProg = &argv[0][retc+1];
364
365
366
367
368
369
370 {char *p = dfltProt = strdup(myProg);
371 while(*p && (*p == '.' || *p == '-')) p++;
372 if (*p)
373 {char *dot = index(p, '.'), *dash = index(p, '-');
374 if (dot && (dot < dash || !dash)) p = dot;
375 else if (dash) p = dash;
376 else p = 0;
377 if (p) *p = '\0';
378 if (!strcmp("xrootd", dfltProt)) dfltProt[5] = 0;
379 else if (!strcmp("cmsd", dfltProt)) dfltProt[3] = 0;
380 }
381 }
382 myArgv[0] = argv[0];
383
384
385
386
387 i = 1;
388 while(i < argc)
389 {if (*(argv[i]) == '-' && *(argv[i]+1) == '+')
390 {int n = strlen(argv[i]+2), j = i+1, k = 1;
391 if (urArgc == argc) urArgc = i;
392 if (n) memcpy(buff, argv[i]+2, (n > 256 ? 256 : n));
393 strcpy(&(buff[n]), ".argv**");
394 while(j < argc && (*(argv[j]) != '-' || *(argv[j]+1) != '+')) j++;
395 urArgv = new char*[j-i+1];
396 urArgv[0] = argv[0];
397 i++;
398 while(i < j) urArgv[k++] = argv[i++];
399 urArgv[k] = 0;
401 strcpy(&(buff[n]), ".argc");
403 } else i++;
404 }
406
407
408
409
410 opterr = 0;
411 if (argc > 1 && '-' == *argv[1])
412 while ((c = getopt(urArgc,argv,":a:A:bc:dhHI:k:l:L:n:N:p:P:R:s:S:vw:W:z"))
413 && ((unsigned char)c != 0xff))
414 { switch(c)
415 {
416 case 'a': if (AdminPath) free(AdminPath);
417 AdminPath = strdup(optarg);
420 break;
421 case 'A': if (AdminPath) free(AdminPath);
422 AdminPath = strdup(optarg);
425 break;
426 case 'b': optbg = true;
427 break;
428 case 'c': if (ConfigFN) free(ConfigFN);
429 ConfigFN = strdup(optarg);
430 break;
434 break;
436 break;
438 break;
439 case 'I': if (!strcmp("v4", optarg)) {ipV4 = true; ipV6 = false;}
440 else if (!strcmp("v6", optarg)) {ipV4 = false; ipV6 = true;}
441 else {
Log.
Emsg(
"Config",
"Invalid -I argument -",optarg);
443 }
444 break;
446 {
Log.
Emsg(
"Config",
"Invalid -k argument -",optarg);
448 }
449 break;
450 case 'l': LogInfo.logArg = optarg;
451 break;
452 case 'L': if (!*optarg)
453 {
Log.
Emsg(
"Config",
"Protocol library path not specified.");
455 }
456 if (libProt) free(libProt);
457 libProt = strdup(optarg);
458 break;
459 case 'n': myInsName = (!strcmp(optarg,"anon")||!strcmp(optarg,"default")
460 ? 0 : optarg);
461 break;
463 break;
465 break;
466 case 'P': if (dfltProt) free(dfltProt);
467 dfltProt = strdup(optarg);
468 break;
469 case 'R':
if (!(getUG(optarg, myUid, myGid)))
Usage(1);
470 rootChk = false;
471 break;
472 case 's': pidFN = optarg;
473 break;
474 case 'S': mySitName = optarg;
475 break;
476 case ':': buff[0] =
'-'; buff[1] =
optopt; buff[2] = 0;
477 Log.
Emsg(
"Config", buff,
"parameter not specified.");
479 break;
480 case 'v': std::cerr <<XrdVSTRING <<std::endl;
481 _exit(0);
482 break;
483 case 'w': if (HomePath) free(HomePath);
484 HomePath = strdup(optarg);
485 HomeMode = S_IRWXU;
486 Specs |= hpSpec;
487 break;
488 case 'W': if (HomePath) free(HomePath);
489 HomePath = strdup(optarg);
490 HomeMode = S_IRWXU | S_IRGRP | S_IXGRP;
491 Specs |= hpSpec;
492 break;
493 case 'z': LogInfo.hiRes = true;
494 break;
495
497 {
Log.
Emsg(
"Config",
"Long options are not supported.");
499 }
500 if (myArgc >= myMaxc || argbP >= argbE)
501 {
Log.
Emsg(
"Config",
"Too many command line arguments.");
503 }
504 myArgv[myArgc++] = argbP;
505 *argbP++ =
'-'; *argbP++ =
optopt; *argbP++ = 0;
506 break;
507 }
508 }
509
510
511
513 {
Log.
Emsg(
"Config",
"Command line adminpath is not absolute.");
514 exit(17);
515 }
516
517
518
519 if (HomePath && *HomePath != '/')
520 {
Log.
Emsg(
"Config",
"Command line home path is not absolute.");
521 exit(17);
522 }
523
524
525
526
527 if (ConfigFN) setCFG(true);
528
529
530
533 else if (ipV6){
if (noV6)
Log.
Say(
"Config warning: ipV6 appears to be broken;"
534 " forced ipV6 mode not advised!");
536 }
537 else if (noV6)
Log.
Say(
"Config warning: ipV6 is misconfigured or "
538 "unavailable; reverting to ipV4.");
539
540
541
543
544
545
546 if (myGid && setegid(myGid))
547 {
Log.
Emsg(
"Config", errno,
"set effective gid"); exit(17);}
548 if (myUid && seteuid(myUid))
549 {
Log.
Emsg(
"Config", errno,
"set effective uid"); exit(17);}
550
551
552
553 if (rootChk && geteuid() == 0)
554 {
Log.
Emsg(
"Config",
"Security reasons prohibit running as "
555 "superuser; program is terminating.");
556 _exit(8);
557 }
558
559
560
561 if (urArgc-
optind+2 >= myMaxc)
562 {
Log.
Emsg(
"Config",
"Too many command line arguments.");
564 }
566
567
568
569 myArgv[myArgc] = 0;
572
573
574
575 if (optbg)
576 {
577#ifdef WIN32
579#else
580 if (pipe( pipeFD ) == -1)
581 {
Log.
Emsg(
"Config", errno,
"create a pipe"); exit(17);}
583#endif
584 }
585
586
587
588
590 if (!(myName = myIPAddr->
Name(0, &temp))) myName =
"";
591
592
593
598
599
600
601
602
603 sprintf(buff,
"%s%s %s@%s", xrdInst, myProg,
ProtInfo.
myInst, myName);
604 myInstance = strdup(buff);
605 putenv(myInstance);
606 myInstance += strlen(xrdInst);
610
611
612
613 if (LogInfo.logArg)
614 {LogInfo.xrdEnv = &
theEnv;
615 LogInfo.iName = myInsName;
616 LogInfo.cfgFn = ConfigFN;
620 }
621
622
623
624
625
626 if (!(*myName))
627 {
Log.
Emsg(
"Config",
"Unable to determine host name; ",
628 (temp ? temp : "reason unknown"),
629 "; execution terminated.");
630 _exit(16);
631 }
632
633
634
636
637
638
639 strcpy(buff, "Starting on ");
640 retc = strlen(buff);
643 Log.
Say(0, CmdLine.c_str());
645
646
647
648
649
651 {
Log.
Emsg(
"Config",myName,
"does not appear to be registered in the DNS.");
652 Log.
Emsg(
"Config",
"Verify that the '/etc/hosts' file is correct and "
653 "this machine is registered in DNS.");
654 Log.
Emsg(
"Config",
"Execution continues but connection failures may occur.");
655 myDomain = 0;
656 } else if (!(myDomain = index(myName, '.')))
657 Log.
Say(
"Config warning: this hostname, ", myName,
658 ", is registered without a domain qualification.");
659
660
661
662 Firstcp = Lastcp =
new XrdConfigProt(strdup(dfltProt), libProt, 0);
663
664
665
666 Log.
Say(
"++++++ ", myInstance,
" initialization started.");
667
668
669
670 devNull = XrdSysFD_Open(
"/dev/null", O_RDONLY);
672 {
Log.
Emsg(
"Config", errno,
"open '/dev/null' which is required!");
673 NoGo = 1;
674 }
675
676
677
678 if (ConfigFN)
679 {
Log.
Say(
"Config using configuration file ", ConfigFN);
681 NoGo = ConfigProc();
682 }
683 if (clPort >= 0) PortTCP = clPort;
687 }
688
689
690
691 NoGo |= SetupAPath();
692
693
694
695 if (!NoGo)
697 else {
Log.
Say(
"++++++ ", myInstance,
" TLS initialization started.");
698 if (SetupTLS())
699 {
Log.
Say(
"------ ",myInstance,
" TLS initialization ended.");
702 } else {
703 NoGo = 1;
704 Log.
Say(
"------ ",myInstance,
" TLS initialization failed.");
705 }
706 }
707 }
708
709
710
711
712 if (!NoGo)
714 {
Log.
Say(
"Config TLS port specification ignored; TLS not configured!");
715 PortTLS = -1;
716 } else {
719 }
720 }
721
722
723
725
726
727
730
731
732
734 {
Log.
Emsg(
"Config",
"Unable to determine interface addresses!");
735 NoGo = 1;
736 }
737
738
739
740 if ((myInsName || HomePath)
742
743
744
745 if (!PidFile(pidFN, optbg)) NoGo = 1;
746
747
748
749 if (!NoGo) Manifest(pidFN);
750
751
752
753 if (!NoGo) NoGo = Setup(dfltProt, libProt);
754
755
756
757 setCFG(false);
758
759
760
761
762 if (tmoInfo && !NoGo)
764 if (!theGS)
Log.
Say(
"Config warning: TCP monitoring not enabled; "
765 "tcpmonlib plugin not loaded!");
769 }
770 }
771
772
773
774#ifndef WIN32
775 if (optbg)
776 {
777 int status = NoGo ? 1 : 0;
778 if(
write( pipeFD[1], &status,
sizeof( status ) )) {};
780 }
781#endif
782
783
784
785 temp = (NoGo ? " initialization failed." : " initialization completed.");
786 sprintf(buff, "%s:%d", myInstance, PortTCP);
787 Log.
Say(
"------ ", buff, temp);
788 if (LogInfo.logArg)
789 {strcat(buff, " running ");
790 retc = strlen(buff);
793 }
794 return NoGo;
795}
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)
T * Load(const char *Symbol)
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)
XrdOucPinKing< XrdTcpMonPin > KingPin