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