-
Notifications
You must be signed in to change notification settings - Fork 149
/
XrdXrootdConfig.cc
1941 lines (1664 loc) · 69.4 KB
/
XrdXrootdConfig.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/******************************************************************************/
/* */
/* X r d X r o o t d C o n f i g . c c */
/* */
/* (c) 2010 by the Board of Trustees of the Leland Stanford, Jr., University */
/* Produced by Andrew Hanushevsky for Stanford University under contract */
/* DE-AC02-76-SFO0515 with the Deprtment of Energy */
/* */
/* This file is part of the XRootD software suite. */
/* */
/* XRootD is free software: you can redistribute it and/or modify it under */
/* the terms of the GNU Lesser General Public License as published by the */
/* Free Software Foundation, either version 3 of the License, or (at your */
/* option) any later version. */
/* */
/* XRootD is distributed in the hope that it will be useful, but WITHOUT */
/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
/* License for more details. */
/* */
/* You should have received a copy of the GNU Lesser General Public License */
/* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
/* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
/* */
/* The copyright holder's institutional names and contributor's names may not */
/* be used to endorse or promote products derived from this software without */
/* specific prior written permission of the institution or contributor. */
/******************************************************************************/
#include <unistd.h>
#include <ctype.h>
#include <fcntl.h>
#include <string.h>
#include <stdio.h>
#include <sys/param.h>
#include <sys/stat.h>
#include <sys/types.h>
#ifdef __solaris__
#include <sys/isa_defs.h>
#endif
#include <limits>
#include "XrdVersion.hh"
#include "XProtocol/XProtocol.hh"
#include "XrdSfs/XrdSfsInterface.hh"
#include "XrdNet/XrdNetOpts.hh"
#include "XrdNet/XrdNetSocket.hh"
#include "XrdOuc/XrdOuca2x.hh"
#include "XrdOuc/XrdOucEnv.hh"
#include "XrdOuc/XrdOucProg.hh"
#include "XrdOuc/XrdOucReqID.hh"
#include "XrdOuc/XrdOucStream.hh"
#include "XrdOuc/XrdOucTrace.hh"
#include "XrdOuc/XrdOucUtils.hh"
#include "XrdSec/XrdSecLoadSecurity.hh"
#include "XrdSys/XrdSysError.hh"
#include "XrdSys/XrdSysHeaders.hh"
#include "XrdSys/XrdSysLogger.hh"
#include "XrdXrootd/XrdXrootdAdmin.hh"
#include "XrdXrootd/XrdXrootdAio.hh"
#include "XrdXrootd/XrdXrootdCallBack.hh"
#include "XrdXrootd/XrdXrootdFile.hh"
#include "XrdXrootd/XrdXrootdFileLock.hh"
#include "XrdXrootd/XrdXrootdFileLock1.hh"
#include "XrdXrootd/XrdXrootdGSReal.hh"
#include "XrdXrootd/XrdXrootdJob.hh"
#include "XrdXrootd/XrdXrootdMonitor.hh"
#include "XrdXrootd/XrdXrootdPrepare.hh"
#include "XrdXrootd/XrdXrootdProtocol.hh"
#include "XrdXrootd/XrdXrootdStats.hh"
#include "XrdXrootd/XrdXrootdTrace.hh"
#include "XrdXrootd/XrdXrootdTransit.hh"
#include "XrdXrootd/XrdXrootdXPath.hh"
#include "Xrd/XrdBuffer.hh"
#include "Xrd/XrdInet.hh"
/******************************************************************************/
/* P r o t o c o l C o m m a n d L i n e O p t i o n s */
/******************************************************************************/
/* This is the XRootd server. The syntax is:
xrootd [options]
options: [<xopt>] [-r] [-t] [-y] [path]
Where:
xopt are xrd specified options that are screened out.
-r This is a redirecting server.
-t This server is a redirection target.
-y This server is a proxy server.
path Export path. Any number of paths may be specified.
By default, only '/tmp' is exported.
*/
/******************************************************************************/
/* G l o b a l s */
/******************************************************************************/
extern XrdOucTrace *XrdXrootdTrace;
XrdXrootdPrepare *XrdXrootdPrepQ;
const char *XrdXrootdInstance;
int XrdXrootdPort;
/******************************************************************************/
/* C o n f i g u r e */
/******************************************************************************/
int XrdXrootdProtocol::Configure(char *parms, XrdProtocol_Config *pi)
{
/*
Function: Establish configuration at load time.
Input: None.
Output: 0 upon success or !0 otherwise.
*/
extern XrdSfsFileSystem *XrdSfsGetDefaultFileSystem
(XrdSfsFileSystem *nativeFS,
XrdSysLogger *Logger,
const char *configFn,
XrdOucEnv *EnvInfo);
extern XrdSfsFileSystem *XrdXrootdloadFileSystem(XrdSysError *,
XrdSfsFileSystem *,
char *, int,
const char *, XrdOucEnv *);
extern XrdSfsFileSystem *XrdDigGetFS
(XrdSfsFileSystem *nativeFS,
XrdSysLogger *Logger,
const char *configFn,
const char *theParms);
extern int optind, opterr;
XrdOucEnv myEnv;
XrdXrootdXPath *xp;
char *adminp, *rdf, *bP, *tmp, c, buff[1024];
int i, n, deper = 0;
// Copy out the special info we want to use at top level
//
eDest.logger(pi->eDest->logger());
XrdXrootdTrace = new XrdOucTrace(&eDest);
SI = new XrdXrootdStats(pi->Stats);
Sched = pi->Sched;
BPool = pi->BPool;
hailWait = pi->hailWait;
readWait = pi->readWait;
Port = pi->Port;
myInst = pi->myInst;
Window = pi->WSize;
tlsPort = pi->tlsPort;
tlsCtx = pi->tlsCtx;
// Record globally accessible values
//
XrdXrootdInstance = pi->myInst;
XrdXrootdPort = pi->Port;
// Set the callback object static areas now!
//
XrdXrootdCallBack::setVals(&eDest, SI, Sched, Port);
// Prohibit this program from executing as superuser
//
if (geteuid() == 0)
{eDest.Emsg("Config", "Security reasons prohibit xrootd running as "
"superuser; xrootd is terminating.");
_exit(8);
}
// Process any command line options
//
opterr = 0; optind = 1;
if (pi->argc > 1 && '-' == *(pi->argv[1]))
while ((c=getopt(pi->argc,pi->argv,"mrst")) && ((unsigned char)c != 0xff))
{ switch(c)
{
case 'r': deper = 1;
XrdOucEnv::Export("XRDREDIRECT", "R");
break;
case 'm': XrdOucEnv::Export("XRDREDIRECT", "R");
break;
case 't': deper = 1;
XrdOucEnv::Export("XRDRETARGET", "1");
break;
case 's': XrdOucEnv::Export("XRDRETARGET", "1");
break;
case 'y': XrdOucEnv::Export("XRDREDPROXY", "1");
break;
default: eDest.Say("Config warning: ignoring invalid option '",pi->argv[optind-1],"'.");
}
}
// Check for deprecated options
//
if (deper) eDest.Say("Config warning: '-r -t' are deprecated; use '-m -s' instead.");
// Pick up exported paths
//
for ( ; optind < pi->argc; optind++) xexpdo(pi->argv[optind]);
// Pre-initialize some i/o values. Note that we now set maximum readv element
// transfer size to the buffer size (before it was a reasonable 256K).
//
if (!(as_miniosz = as_segsize/2)) as_miniosz = as_segsize;
n = (pi->theEnv ? pi->theEnv->GetInt("MaxBuffSize") : 0);
maxTransz = maxBuffsz = (n ? n : BPool->MaxSize());
memset(Route, 0, sizeof(Route));
// Now process and configuration parameters
//
rdf = (parms && *parms ? parms : pi->ConfigFN);
if (rdf && Config(rdf)) return 0;
if (pi->DebugON) XrdXrootdTrace->What = TRACE_ALL;
// Check if we are exporting a generic object name
//
if (XPList.Opts() & XROOTDXP_NOSLASH)
{eDest.Say("Config exporting ", XPList.Path(n)); n += 2;}
else n = 0;
// Check if we are exporting anything
//
if (!(xp = XPList.Next()) && !n)
{XPList.Insert("/tmp"); n = 8;
eDest.Say("Config warning: only '/tmp' will be exported.");
} else {
while(xp) {eDest.Say("Config exporting ", xp->Path(i));
n += i+2; xp = xp->Next();
}
}
// Export the exports
//
bP = tmp = (char *)malloc(n);
if (XPList.Opts() & XROOTDXP_NOSLASH)
{strcpy(bP, XPList.Path(i)); bP += i, *bP++ = ' ';}
xp = XPList.Next();
while(xp) {strcpy(bP, xp->Path(i)); bP += i; *bP++ = ' '; xp = xp->Next();}
*(bP-1) = '\0';
XrdOucEnv::Export("XRDEXPORTS", tmp); free(tmp);
// Initialize the security system if this is wanted
//
if (!ConfigSecurity(myEnv, pi->ConfigFN)) return 0;
// Set up the network for self-identification and display it
//
pi->NetTCP->netIF.Port(Port);
pi->NetTCP->netIF.Display("Config ");
// Establish our specific environment that will be passed along
//
myEnv.PutPtr("XrdInet*", (void *)(pi->NetTCP));
myEnv.PutPtr("XrdNetIF*", (void *)(&(pi->NetTCP->netIF)));
myEnv.PutPtr("XrdScheduler*", Sched);
// Copy over the xrd environment which contains plugin argv's
//
if (pi->theEnv) myEnv.PutPtr("xrdEnv*", pi->theEnv);
// Initialize monitoring (it won't do anything if it wasn't enabled)
//
if (!XrdXrootdMonitor::Init(Sched, &eDest, pi->myName, pi->myProg,
myInst, Port)) return 0;
// Config g-stream objects, as needed. This needs to be done before we
// load any plugins but after we initialize monitoring.
//
ConfigGStream(myEnv);
// Get the filesystem to be used
//
if (FSLib[0])
{TRACE(DEBUG, "Loading base filesystem library " <<FSLib[0]);
osFS = XrdXrootdloadFileSystem(&eDest, 0, FSLib[0], FSLvn[0],
pi->ConfigFN, &myEnv);
} else {
osFS = XrdSfsGetDefaultFileSystem(0,eDest.logger(),pi->ConfigFN,&myEnv);
}
if (!osFS)
{eDest.Emsg("Config", "Unable to load file system.");
return 0;
} else {
SI->setFS(osFS);
if (FSLib[0]) osFS->EnvInfo(&myEnv);
}
// Check if we have a wrapper library
//
if (FSLib[1])
{TRACE(DEBUG, "Loading wrapper filesystem library " <<FSLib[1]);
osFS = XrdXrootdloadFileSystem(&eDest, osFS, FSLib[1], FSLvn[1],
pi->ConfigFN, &myEnv);
if (!osFS)
{eDest.Emsg("Config", "Unable to load file system wrapper.");
return 0;
} else osFS->EnvInfo(&myEnv);
}
// Check if the file system includes a custom prepare handler as this will
// affect how we handle prepare requests.
//
if (myEnv.Get("XRD_PrepHandler")) PrepareAlt = true;
// Check if the diglib should be loaded. We only support the builtin one. In
// the future we will have to change this code to be like the above.
//
if (digParm)
{TRACE(DEBUG, "Loading dig filesystem builtin");
digFS = XrdDigGetFS(osFS, eDest.logger(), pi->ConfigFN, digParm);
if (!digFS) eDest.Emsg("Config","Unable to load digFS; "
"remote debugging disabled!");
}
// Check if we are going to be processing checksums locally
//
if (JobCKT && JobLCL)
{XrdOucErrInfo myError("Config");
XrdOucTList *tP = JobCKTLST;
do {if (osFS->chksum(XrdSfsFileSystem::csSize,tP->text,0,myError))
{eDest.Emsg("Config",tP->text,"checksum is not natively supported.");
return 0;
}
tP->ival[1] = myError.getErrInfo();
tP = tP->next;
} while(tP);
}
// Initialiaze for AIO
//
if (getenv("XRDXROOTD_NOAIO")) as_noaio = 1;
else if (!as_noaio) XrdXrootdAioReq::Init(as_segsize, as_maxperreq, as_maxpersrv);
else eDest.Say("Config warning: asynchronous I/O has been disabled!");
// Create the file lock manager
//
Locker = (XrdXrootdFileLock *)new XrdXrootdFileLock1();
XrdXrootdFile::Init(Locker, &eDest, as_nosf == 0);
if (as_nosf) eDest.Say("Config warning: sendfile I/O has been disabled!");
// Schedule protocol object cleanup (also advise the transit protocol)
//
ProtStack.Set(pi->Sched, XrdXrootdTrace, TRACE_MEM);
n = (pi->ConnMax/3 ? pi->ConnMax/3 : 30);
ProtStack.Set(n, 60*60);
XrdXrootdTransit::Init(pi->Sched, n, 60*60);
// Initialize the request ID generation object
//
PrepID = new XrdOucReqID(pi->urAddr, (int)Port);
// Initialize for prepare processing
//
XrdXrootdPrepQ = new XrdXrootdPrepare(&eDest, pi->Sched, PrepareAlt);
sprintf(buff, "%%s://%s:%d/&L=%%d&U=%%s", pi->myName, pi->Port);
Notify = strdup(buff);
// Set the redirect flag if we are a pure redirector
//
myRole = kXR_isServer; myRolf = kXR_DataServer;
if ((rdf = getenv("XRDREDIRECT"))
&& (!strcmp(rdf, "R") || !strcmp(rdf, "M")))
{isRedir = *rdf;
myRole = kXR_isManager; myRolf = kXR_LBalServer;
if (!strcmp(rdf, "M")) myRole |=kXR_attrMeta;
}
if (getenv("XRDREDPROXY")) myRole |=kXR_attrProxy;
// Check if we are redirecting anything
//
if ((xp = RPList.Next()))
{int k;
char buff[2048], puff[1024];
do {k = xp->Opts();
if (Route[k].Host[0] == Route[k].Host[1]
&& Route[k].Port[0] == Route[k].Port[1]) *puff = 0;
else sprintf(puff, "%%%s:%d", Route[k].Host[1], Route[k].Port[1]);
sprintf(buff," to %s:%d%s",Route[k].Host[0],Route[k].Port[0],puff);
eDest.Say("Config redirect static ", xp->Path(), buff);
xp = xp->Next();
} while(xp);
}
if ((xp = RQList.Next()))
{int k;
const char *cgi1, *cgi2;
char buff[2048], puff[1024], xCgi[RD_Num] = {0};
if (isRedir) {cgi1 = "+"; cgi2 = getenv("XRDCMSCLUSTERID");}
else {cgi1 = ""; cgi2 = pi->myName;}
myCNlen = snprintf(buff, sizeof(buff), "%s%s", cgi1, cgi2);
myCName = strdup(buff);
do {k = xp->Opts();
if (Route[k].Host[0] == Route[k].Host[1]
&& Route[k].Port[0] == Route[k].Port[1]) *puff = 0;
else sprintf(puff, "%%%s:%d", Route[k].Host[1], Route[k].Port[1]);
sprintf(buff," to %s:%d%s",Route[k].Host[0],Route[k].Port[0],puff);
eDest.Say("Config redirect enoent ", xp->Path(), buff);
if (!xCgi[k] && cgi2)
{bool isdup = Route[k].Host[0] == Route[k].Host[1]
&& Route[k].Port[0] == Route[k].Port[1];
for (i = 0; i < 2; i++)
{n = snprintf(buff,sizeof(buff), "%s?tried=%s%s",
Route[k].Host[i], cgi1, cgi2);
free(Route[k].Host[i]); Route[k].Host[i] = strdup(buff);
Route[k].RDSz[i] = n;
if (isdup) {Route[k].Host[1] = Route[k].Host[0];
Route[k].RDSz[1] = n; break;
}
}
}
xCgi[k] = 1;
xp = xp->Next();
} while(xp);
}
// Add all jobs that we can run to the admin object
//
if (JobCKS) XrdXrootdAdmin::addJob("chksum", JobCKS);
// Establish the path to be used for admin functions. We will loose this
// storage upon an error but we don't care because we'll just exit.
//
adminp = XrdOucUtils::genPath(pi->AdmPath, 0, ".xrootd");
// Setup the admin path (used in all roles).
//
if (!(AdminSock = XrdNetSocket::Create(&eDest, adminp, "admin", pi->AdmMode))
|| !XrdXrootdAdmin::Init(&eDest, AdminSock)) return 0;
// Setup pid file
//
PidFile();
// Indicate whether or not we support extened attributes
//
{XrdOucEnv myEnv;
XrdOucErrInfo eInfo("", &myEnv);
char buff[128];
if (osFS->FAttr(0, eInfo, 0) == SFS_OK)
{usxMaxNsz = myEnv.GetInt("usxMaxNsz");
if (usxMaxNsz < 0) usxMaxNsz = 0;
usxMaxVsz = myEnv.GetInt("usxMaxVsz");
if (usxMaxVsz < 0) usxMaxVsz = 0;
snprintf(buff, sizeof(buff), "%d %d", usxMaxNsz, usxMaxVsz);
usxParms = strdup(buff);
} else {
usxMaxNsz = 0;
usxMaxVsz = 0;
usxParms = strdup("0 0");
}
}
// Finally, check if we really need to be in bypass mode if it is set
//
if (OD_Bypass)
{const char *penv = getenv("XRDXROOTD_PROXY");
if (!penv || *penv != '=')
{OD_Bypass = false;
eDest.Say("Config warning: 'fsoverload bypass' ignored; "
"not a forwarding proxy.");
}
}
// Finally note whether or not we have TLS enabled
//
if (tlsCtx) myRole |= kXR_haveTLS;
// Return success
//
free(adminp);
return 1;
}
/******************************************************************************/
/* C o n f i g */
/******************************************************************************/
#define TS_Xeq(x,m) (!strcmp(x,var)) GoNo = m(Config)
int XrdXrootdProtocol::Config(const char *ConfigFN)
{
XrdOucEnv myEnv;
XrdOucStream Config(&eDest, getenv("XRDINSTANCE"), &myEnv, "=====> ");
char *var;
int cfgFD, GoNo, NoGo = 0, ismine;
// Open and attach the config file
//
if ((cfgFD = open(ConfigFN, O_RDONLY, 0)) < 0)
return eDest.Emsg("Config", errno, "open config file", ConfigFN);
Config.Attach(cfgFD);
// Process items
//
while((var = Config.GetMyFirstWord()))
{ if ((ismine = !strncmp("xrootd.", var, 7)) && var[7]) var += 7;
else if ((ismine = !strcmp("all.export", var))) var += 4;
else if ((ismine = !strcmp("all.pidpath",var))) var += 4;
else if ((ismine = !strcmp("all.seclib", var))) var += 4;
if (ismine)
{ if TS_Xeq("async", xasync);
else if TS_Xeq("chksum", xcksum);
else if TS_Xeq("diglib", xdig);
else if TS_Xeq("export", xexp);
else if TS_Xeq("fslib", xfsl);
else if TS_Xeq("fsoverload", xfso);
else if TS_Xeq("gpflib", xgpf);
else if TS_Xeq("log", xlog);
else if TS_Xeq("monitor", xmon);
else if TS_Xeq("pidpath", xpidf);
else if TS_Xeq("prep", xprep);
else if TS_Xeq("redirect", xred);
else if TS_Xeq("seclib", xsecl);
else if TS_Xeq("tls", xtls);
else if TS_Xeq("trace", xtrace);
else if TS_Xeq("limit", xlimit);
else {eDest.Say("Config warning: ignoring unknown directive '",var,"'.");
Config.Echo();
continue;
}
if (GoNo) {Config.Echo(); NoGo = 1;}
}
}
return NoGo;
}
/******************************************************************************/
/* P r i v a t e F u n c t i o n s */
/******************************************************************************/
/******************************************************************************/
/* P i d F i l e */
/******************************************************************************/
void XrdXrootdProtocol::PidFile()
{
int rc, xfd;
char buff[32], pidFN[1200];
char *ppath=XrdOucUtils::genPath(pidPath,XrdOucUtils::InstName(-1));
const char *xop = 0;
if ((rc = XrdOucUtils::makePath(ppath,XrdOucUtils::pathMode)))
{xop = "create"; errno = rc;}
else {snprintf(pidFN, sizeof(pidFN), "%s/xrootd.pid", ppath);
if ((xfd = open(pidFN, O_WRONLY|O_CREAT|O_TRUNC,0644)) < 0)
xop = "open";
else {if (write(xfd,buff,snprintf(buff,sizeof(buff),"%d",
static_cast<int>(getpid()))) < 0) xop = "write";
close(xfd);
}
}
free(ppath);
if (xop) eDest.Emsg("Config", errno, xop, pidFN);
}
/******************************************************************************/
/* C o n f i g G S t r e a m */
/******************************************************************************/
void XrdXrootdProtocol::ConfigGStream(XrdOucEnv &myEnv)
{
struct GSTable {const char *pin; int Mode; char Type;} gsObj[] =
{{"ccm", XROOTD_MON_CCM, XROOTD_MON_GSCCM},
{"pfc", XROOTD_MON_PFC, XROOTD_MON_GSPFC}
};
int numgs = sizeof(gsObj)/sizeof(struct GSTable);
int flint = XrdXrootdMonitor::Flushing();
char vbuff[64];
// For each enabled monitoring provider, allocate a g-stream and put
// its address in our environment.
//
for (int i = 0; i < numgs; i++)
{if (XrdXrootdMonitor::ModeEnabled(gsObj[i].Mode))
{XrdXrootdGStream *gs = new XrdXrootdGSReal(gsObj[i].pin,
gsObj[i].Type,
gsObj[i].Mode, flint);
snprintf(vbuff, sizeof(vbuff), "%s.gStream*", gsObj[i].pin);
myEnv.PutPtr(vbuff, (void *)gs);
}
}
}
/******************************************************************************/
/* C o n f i g S e c u r i t y */
/******************************************************************************/
int XrdXrootdProtocol::ConfigSecurity(XrdOucEnv &xEnv, const char *cfn)
{
XrdSecGetProt_t secGetProt = 0;
char idBuff[256];
int n;
// Obtain our uid and username
//
myUID = geteuid();
if ((n = XrdOucUtils::UidName(myUID, idBuff, sizeof(idBuff))))
{myUName = strdup(idBuff);
myUNLen = n;
}
// Obtain our gid and groupname
//
myGID = getegid();
if ((n = XrdOucUtils::GidName(myGID, idBuff, sizeof(idBuff))))
{myGName = strdup(idBuff);
myGNLen = n;
}
// TLS support is independent of security per se. Record context, if any.
//
if (tlsCtx) xEnv.PutPtr("XrdTLSContext*", (void *)tlsCtx);
// Check if we need to load anything
//
if (!SecLib)
{eDest.Say("Config warning: 'xrootd.seclib' not specified;"
" strong authentication disabled!");
xEnv.PutPtr("XrdSecGetProtocol*", (void *)0);
xEnv.PutPtr("XrdSecProtector*" , (void *)0);
return 1;
}
// Blad some debugging info
//
TRACE(DEBUG, "Loading security library " <<SecLib);
// Load the security server
//
if (!(CIA = XrdSecLoadSecService(&eDest, cfn,
(strcmp(SecLib,"default") ? SecLib : 0),
&secGetProt, &DHS)))
{eDest.Emsg("Config", "Unable to load security system.");
return 0;
}
// Set environmental pointers
//
xEnv.PutPtr("XrdSecGetProtocol*", (void *)secGetProt);
xEnv.PutPtr("XrdSecProtector*" , (void *)DHS);
return 1;
}
/******************************************************************************/
/* x a s y n c */
/******************************************************************************/
/* Function: xasync
Purpose: To parse directive: async [limit <aiopl>] [maxsegs <msegs>]
[maxtot <mtot>] [segsize <segsz>]
[minsize <iosz>] [maxstalls <cnt>]
[force] [syncw] [off] [nosf]
<aiopl> maximum number of async ops per link. Default 8.
<msegs> maximum number of async ops per request. Default 8.
<mtot> maximum number of async ops per server. Default is 20%
of maximum connection times aiopl divided by two.
<segsz> The aio segment size. This is the maximum size that data
will be read or written. The defaults to 64K but is
adjusted for each request to minimize latency.
<iosz> the minimum number of bytes that must be read or written
to allow async processing to occur (default is maxbsz/2
typically 1M).
<cnt> Maximum number of client stalls before synchronous i/o is
used. Async mode is tried after <cnt> requests.
force Uses async i/o for all requests, even when not explicitly
requested (this is compatible with synchronous clients).
syncw Use synchronous i/o for write requests.
off Disables async i/o
nosf Disables use of sendfile to send data to the client.
Output: 0 upon success or 1 upon failure.
*/
int XrdXrootdProtocol::xasync(XrdOucStream &Config)
{
char *val;
int i, ppp;
int V_force=-1, V_syncw = -1, V_off = -1, V_mstall = -1, V_nosf = -1;
int V_limit=-1, V_msegs=-1, V_mtot=-1, V_minsz=-1, V_segsz=-1;
int V_minsf=-1;
long long llp;
struct asyncopts {const char *opname; int minv; int *oploc;
const char *opmsg;} asopts[] =
{
{"force", -1, &V_force, ""},
{"off", -1, &V_off, ""},
{"nosf", -1, &V_nosf, ""},
{"syncw", -1, &V_syncw, ""},
{"limit", 0, &V_limit, "async limit"},
{"segsize", 4096, &V_segsz, "async segsize"},
{"maxsegs", 0, &V_msegs, "async maxsegs"},
{"maxstalls", 0, &V_mstall,"async maxstalls"},
{"maxtot", 0, &V_mtot, "async maxtot"},
{"minsfsz", 1, &V_minsf, "async minsfsz"},
{"minsize", 4096, &V_minsz, "async minsize"}};
int numopts = sizeof(asopts)/sizeof(struct asyncopts);
if (!(val = Config.GetWord()))
{eDest.Emsg("Config", "async option not specified"); return 1;}
while (val)
{for (i = 0; i < numopts; i++)
if (!strcmp(val, asopts[i].opname))
{if (asopts[i].minv >= 0 && !(val = Config.GetWord()))
{eDest.Emsg("Config","async",(char *)asopts[i].opname,
"value not specified");
return 1;
}
if (asopts[i].minv > 0)
if (XrdOuca2x::a2sz(eDest,asopts[i].opmsg, val, &llp,
(long long)asopts[i].minv)) return 1;
else *asopts[i].oploc = (int)llp;
else if (asopts[i].minv == 0)
if (XrdOuca2x::a2i(eDest,asopts[i].opmsg,val,&ppp,1))
return 1;
else *asopts[i].oploc = ppp;
else *asopts[i].oploc = 1;
break;
}
if (i >= numopts)
eDest.Emsg("Config", "Warning, invalid async option", val);
val = Config.GetWord();
}
// Make sure max values are consistent
//
if (V_limit > 0 && V_mtot > 0 && V_limit > V_mtot)
{eDest.Emsg("Config", "async limit may not be greater than maxtot");
return 1;
}
// Calculate the actual segment size
//
if (V_segsz > 0)
{i = BPool->Recalc(V_segsz);
if (!i) {eDest.Emsg("Config", "async segsize is too large"); return 1;}
if (i != V_segsz)
{char buff[64];
sprintf(buff, "%d readjusted to %d", V_segsz, i);
eDest.Emsg("Config", "async segsize", buff);
V_segsz = i;
}
}
// Establish async options
//
if (V_limit > 0) as_maxperlnk = V_limit;
if (V_msegs > 0) as_maxperreq = V_msegs;
if (V_mtot > 0) as_maxpersrv = V_mtot;
if (V_minsz > 0) as_miniosz = V_minsz;
if (V_segsz > 0) as_segsize = V_segsz;
if (V_mstall> 0) as_maxstalls = V_mstall;
if (V_force > 0) as_force = 1;
if (V_off > 0) as_noaio = 1;
if (V_syncw > 0) as_syncw = 1;
if (V_nosf > 0) as_nosf = 1;
if (V_minsf > 0) as_minsfsz = V_minsf;
return 0;
}
/******************************************************************************/
/* x c k s u m */
/******************************************************************************/
/* Function: xcksum
Purpose: To parse the directive: chksum [chkcgi] [max <n>] <type> [<path>]
max maximum number of simultaneous jobs
chkcgi Always check for checksum type in cgo info.
<type> algorithm of checksum (e.g., md5). If more than one
checksum is supported then they should be listed with
each separated by a space.
<path> the path of the program performing the checksum
If no path is given, the checksum is local.
Output: 0 upon success or !0 upon failure.
*/
int XrdXrootdProtocol::xcksum(XrdOucStream &Config)
{
static XrdOucProg *theProg = 0;
int (*Proc)(XrdOucStream *, char **, int) = 0;
XrdOucTList *tP, *algFirst = 0, *algLast = 0;
char *palg, prog[2048];
int jmax = 4, anum[2] = {0,0};
// Get the algorithm name and the program implementing it
//
JobCKCGI = 0;
while ((palg = Config.GetWord()) && *palg != '/')
{if (!strcmp(palg,"chkcgi")) {JobCKCGI = 1; continue;}
if (strcmp(palg, "max"))
{XrdOucUtils::toLower(palg);
XrdOucTList *xalg = new XrdOucTList(palg, anum); anum[0]++;
if (algLast) algLast->next = xalg;
else algFirst = xalg;
algLast = xalg;
continue;
}
if (!(palg = Config.GetWord()))
{eDest.Emsg("Config", "chksum max not specified"); return 1;}
if (XrdOuca2x::a2i(eDest, "chksum max", palg, &jmax, 0)) return 1;
}
// Verify we have an algoritm
//
if (!algFirst)
{eDest.Emsg("Config", "chksum algorithm not specified"); return 1;}
if (JobCKT) free(JobCKT);
JobCKT = strdup(algFirst->text);
// Handle alternate checksums
//
while((tP = JobCKTLST)) {JobCKTLST = tP->next; delete tP;}
JobCKTLST = algFirst;
if (algFirst->next) JobCKCGI = 2;
// Handle program if we have one
//
if (palg)
{int n = strlen(palg);
if (n+2 >= (int)sizeof(prog))
{eDest.Emsg("Config", "cksum program too long"); return 1;}
strcpy(prog, palg); palg = prog+n; *palg++ = ' '; n = sizeof(prog)-n-1;
if (!Config.GetRest(palg, n))
{eDest.Emsg("Config", "cksum parameters too long"); return 1;}
} else *prog = 0;
// Check if we have a program. If not, then this will be a local checksum and
// the algorithm will be verified after we load the filesystem.
//
if (*prog) JobLCL = 0;
else { JobLCL = 1; Proc = &CheckSum; strcpy(prog, "chksum");}
// Set up the program and job
//
if (!theProg) theProg = new XrdOucProg(0);
if (theProg->Setup(prog, &eDest, Proc)) return 1;
if (JobCKS) delete JobCKS;
if (jmax) JobCKS = new XrdXrootdJob(Sched, theProg, "chksum", jmax);
else JobCKS = 0;
return 0;
}
/******************************************************************************/
/* x d i g */
/******************************************************************************/
/* Function: xdig
Purpose: To parse the directive: diglib * <parms>
* use builtin digfs library (only one supported now).
parms parameters for digfs.
Output: 0 upon success or !0 upon failure.
*/
int XrdXrootdProtocol::xdig(XrdOucStream &Config)
{
char parms[4096], *val;
// Get the path
//
if (!(val = Config.GetWord()))
{eDest.Emsg("Config", "diglib not specified"); return 1;}
// Make sure it refers to an internal one
//
if (strcmp(val, "*"))
{eDest.Emsg("Config", "builtin diglib not specified"); return 1;}
// Grab the parameters
//
if (!Config.GetRest(parms, sizeof(parms)))
{eDest.Emsg("Config", "diglib parameters too long"); return 1;}
if (digParm) free(digParm);
digParm = strdup(parms);
// All done
//
return 0;
}
/******************************************************************************/
/* x e x p */
/******************************************************************************/
/* Function: xexp
Purpose: To parse the directive: export <path> [lock|nolock] [mwfiles]
<path> the path to be exported.
Output: 0 upon success or !0 upon failure.
*/
int XrdXrootdProtocol::xexp(XrdOucStream &Config)
{
char *val, pbuff[1024];
int popt = 0;
// Get the path
//
val = Config.GetWord();
if (!val || !val[0])
{eDest.Emsg("Config", "export path not specified"); return 1;}
strlcpy(pbuff, val, sizeof(pbuff));
// Get export lock option
//
while((val = Config.GetWord()))
{ if (!strcmp( "nolock", val)) popt |= XROOTDXP_NOLK;
else if (!strcmp( "lock", val)) popt &= ~XROOTDXP_NOLK;
else if (!strcmp("mwfiles", val)) popt |= XROOTDXP_NOMWCHK;
else {Config.RetToken(); break;}
}
// Add path to configuration
//
return xexpdo(pbuff, popt);
}
/******************************************************************************/
int XrdXrootdProtocol::xexpdo(char *path, int popt)
{
char *opaque;
int xopt;
// Check if we are exporting a generic name
//
if (*path == '*')
{popt |= XROOTDXP_NOSLASH | XROOTDXP_NOCGI;
if (*(path+1))
{if (*(path+1) == '?') popt &= ~XROOTDXP_NOCGI;
else {eDest.Emsg("Config","invalid export path -",path);return 1;}
}
XPList.Set(popt, path);
return 0;
}
// Make sure path start with a slash
//
if (rpCheck(path, &opaque))
{eDest.Emsg("Config", "non-absolute export path -", path); return 1;}
// Record the path
//
if (!(xopt = Squash(path)) || xopt != (popt|XROOTDXP_OK))
XPList.Insert(path, popt);
return 0;
}
/******************************************************************************/
/* x f s l */
/******************************************************************************/
/* Function: xfsl
Purpose: To parse the directive: fslib [throttle | [-2] <fspath2>]
{default | [-2] <fspath1>}
-2 Uses version2 of the plugin initializer.
This is ignored now because it's always done.
throttle load libXrdThrottle.so as the head interface.
<fspath2> load the named library as the head interface.
default load libXrdOfs.so ro libXrdPss.so as the tail
interface. This is the default.
<fspath1> load the named library as the tail interface.
Output: 0 upon success or !0 upon failure.
*/
int XrdXrootdProtocol::xfsl(XrdOucStream &Config)
{
char *val;