Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TSecContext.cxx
Go to the documentation of this file.
1// @(#)root/net:$Id$
2// Author: G. Ganis 19/03/2003
3
4/*************************************************************************
5 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12//////////////////////////////////////////////////////////////////////////
13// //
14// TSecContext //
15// //
16// Contains details about an established security context //
17// Used by THostAuth //
18// //
19//////////////////////////////////////////////////////////////////////////
20
21#include "RConfigure.h"
22
23#include <cstdlib>
24
25#include "strlcpy.h"
26#include "snprintf.h"
27#include "TSecContext.h"
28#include "TSocket.h"
29#include "TUrl.h"
30#include "TROOT.h"
31#include "TError.h"
32#include "TVirtualMutex.h"
33
34
35const TDatime kROOTTZERO = 788914800;
36
37////////////////////////////////////////////////////////////////////////////////
38/// Ctor for SecContext object.
39
40TSecContext::TSecContext(const char *user, const char *host, Int_t meth,
41 Int_t offset, const char *id,
42 const char *token, TDatime expdate, void *ctx)
43 : TObject()
44{
46
47 fContext = ctx;
48 fCleanup = new TList;
50 if (offset > -1) {
51 if (fExpDate < TDatime()) {
52 // This means expdate was not initialized
53 // We set it to default, ie 1 day from now
54 fExpDate.Set(TDatime().GetDate() + 1, TDatime().GetTime());
55 }
56 }
57 fHost = host;
58 fID = id;
59 fMethod = meth;
60 fMethodName = "";
62 fToken = token;
63 fUser = user;
64
65 // Keep official list updated with active TSecContexts
66 if (fOffSet > -1) {
68 gROOT->GetListOfSecContexts()->Add(this);
69 }
70}
71
72////////////////////////////////////////////////////////////////////////////////
73/// Ctor for SecContext object.
74/// User and host from url = `user@host` .
75
77 const char *token, const char *id,
78 TDatime expdate, void *ctx)
79 : TObject()
80{
82
83 fContext = ctx;
84 fCleanup = new TList;
86 if (offset > -1) {
87 if (fExpDate < TDatime()) {
88 // This means expdate was not initialized
89 // We set it to default, ie 1 day from now
90 fExpDate.Set(TDatime().GetDate() + 1, TDatime().GetTime());
91 }
92 }
93 fHost = TUrl(url).GetHost();
94 fID = id;
95 fMethod = meth;
96 fMethodName = "";
98 fToken = token;
99 fUser = TUrl(url).GetUser();
100
101 // Keep official list updated with active TSecContexts
102 if (fOffSet > -1) {
104 gROOT->GetListOfSecContexts()->Add(this);
105 }
106}
107
108////////////////////////////////////////////////////////////////////////////////
109///copy constructor
110
112 TObject(sc),
113 fContext(sc.fContext),
114 fCleanup(sc.fCleanup),
115 fExpDate(sc.fExpDate),
116 fHost(sc.fHost),
117 fID(sc.fID),
118 fMethod(sc.fMethod),
119 fMethodName(sc.fMethodName),
120 fOffSet(sc.fOffSet),
121 fToken(sc.fToken),
122 fUser(sc.fUser)
123{
124}
125
126////////////////////////////////////////////////////////////////////////////////
127///assignement operator
128
130{
131 if(this!=&sc) {
133 fContext=sc.fContext;
134 fCleanup=sc.fCleanup;
135 fExpDate=sc.fExpDate;
136 fHost=sc.fHost;
137 fID=sc.fID;
138 fMethod=sc.fMethod;
139 fMethodName=sc.fMethodName;
140 fOffSet=sc.fOffSet;
141 fToken=sc.fToken;
142 fUser=sc.fUser;
143 }
144 return *this;
145}
146
147////////////////////////////////////////////////////////////////////////////////
148/// Dtor: delete (deActivate, local/remote cleanup, list removal)
149/// all what is still active
150
155////////////////////////////////////////////////////////////////////////////////
156/// Cleanup what is still active
157
159{
160 if (IsActive()) {
162 DeActivate("R");
163 // All have been remotely Deactivated
164 TIter nxtl(gROOT->GetListOfSecContexts());
166 while ((nscl = (TSecContext *)nxtl())) {
167 if (nscl != this && !strcmp(nscl->GetHost(), fHost.Data())) {
168 // Need to set ofs=-1 to avoid sending another
169 // cleanup request
170 nscl->DeActivate("");
171 }
172 }
173 }
174
175 // Delete the cleanup list
176 if (fCleanup) {
177 fCleanup->Delete();
178 delete fCleanup;
179 fCleanup = 0;
180 }
181}
182
183////////////////////////////////////////////////////////////////////////////////
184/// Set OffSet to -1 and expiring Date to default
185/// Remove from the list
186/// If Opt contains "C" or "c", ask for remote cleanup
187/// If Opt contains "R" or "r", remove from the list
188/// Default Opt="CR"
189
191{
192 // Ask remote cleanup of this context
193 Bool_t clean = (strstr(Opt,"C") || strstr(Opt,"c"));
194 if (clean && fOffSet > -1)
196
197 Bool_t remove = (strstr(Opt,"R") || strstr(Opt,"r"));
198 if (remove && fOffSet > -1){
200 // Remove from the global list
201 gROOT->GetListOfSecContexts()->Remove(this);
202 }
203
204 // Set inactive
205 fOffSet = -1;
207}
208
209////////////////////////////////////////////////////////////////////////////////
210/// Create a new TSecContextCleanup
211/// Internally is added to the list
212
219
220////////////////////////////////////////////////////////////////////////////////
221/// Checks if this security context is for method named 'methname'
222/// Case sensitive.
223
225{
226 return Bool_t(!strcmp(methname, GetMethodName()));
227}
228
229////////////////////////////////////////////////////////////////////////////////
230/// Check remote OffSet and expiring Date
231
233{
234 if (fOffSet > -1 && fExpDate > TDatime())
235 return kTRUE;
236 // Invalid
237 return kFALSE;
238}
239
240////////////////////////////////////////////////////////////////////////////////
241/// If opt is "F" (default) print object content.
242/// If opt is "<number>" print in special form for calls within THostAuth
243/// with cardinality "<number>"
244/// If opt is "S" prints short in-line form for calls within TFTP and similar
245
247{
248 char aOrd[16] = {0};
249 char aSpc[16] = {0};
250
251 // Check if option is numeric
252 Int_t ord = -1, i = 0;
253 for (; i < (Int_t)strlen(opt); i++) {
254 if (opt[i] < 48 || opt[i] > 57) {
255 ord = -2;
256 break;
257 }
258 }
259 // If numeric get the cardinality and prepare the strings
260 if (ord == -1)
261 ord = atoi(opt);
262
263 // If asked to print ordinal number, preapre the string
264 if (ord > -1) {
265 snprintf(aOrd, sizeof(aOrd), "%d)", ord);
266 // and take care of alignment
268 while (len--)
269 strlcat(aSpc, " ", sizeof(aSpc));
270 }
271
272 if (!strncasecmp(opt,"F",1)) {
273 Info("Print",
274 "+------------------------------------------------------+");
275 Info("Print",
276 "+ Host:%s Method:%d (%s) User:'%s'",
278 fUser.Data());
279 Info("Print",
280 "+ OffSet:%d, id:%s", fOffSet, fID.Data());
281 if (fOffSet > -1)
282 Info("Print",
283 "+ Expiration time: %s",fExpDate.AsString());
284 Info("Print",
285 "+------------------------------------------------------+");
286 } else if (!strncasecmp(opt,"S",1)) {
287 if (fOffSet > -1) {
288 Printf("Security context: Method: %d (%s) expiring on %s",
291 } else {
292 Printf("Security context: Method: %d (%s) not reusable",
294 }
295 } else {
296 // special printing form for THostAuth
297 Info("PrintEstblshed","+ %s h:%s met:%d (%s) us:'%s'",
299 fUser.Data());
300 Info("PrintEstblshed","+ %s offset:%d id:%s", aSpc, fOffSet, fID.Data());
301 if (fOffSet > -1)
302 Info("PrintEstblshed","+ %s expiring: %s",aSpc,fExpDate.AsString());
303 }
304}
305
306////////////////////////////////////////////////////////////////////////////////
307/// Returns short string with relevant information about this
308/// security context
309
311{
312 if (fOffSet > -1) {
313 char expdate[32];
314 out = Form("Method: %d (%s) expiring on %s",
316 } else {
317 if (fOffSet == -1)
318 out = Form("Method: %d (%s) not reusable", fMethod, GetMethodName());
319 else if (fOffSet == -3)
320 out = Form("Method: %d (%s) authorized by /etc/hosts.equiv or $HOME/.rhosts",
322 else if (fOffSet == -4)
323 out = Form("No authentication required remotely");
324 }
325 return out.Data();
326}
327
328////////////////////////////////////////////////////////////////////////////////
329/// Ask remote client to cleanup security context 'ctx'
330/// If 'all', all sec context with the same host as ctx
331/// are cleaned.
332
334{
335 AbstractMethod("CleanupSecContext");
336 return kFALSE;
337}
bool Bool_t
Boolean (0=false, 1=true) (bool)
Definition RtypesCore.h:77
int Int_t
Signed integer 4 bytes (int)
Definition RtypesCore.h:59
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
const char Option_t
Option string (const char)
Definition RtypesCore.h:80
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
#define R__ASSERT(e)
Checks condition e and reports a fatal error if it's false.
Definition TError.h:125
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h offset
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize id
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t UChar_t len
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
R__EXTERN TVirtualMutex * gROOTMutex
Definition TROOT.h:63
#define gROOT
Definition TROOT.h:411
const TDatime kROOTTZERO
R__EXTERN const TDatime kROOTTZERO
Definition TSecContext.h:30
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition TString.cxx:2495
void Printf(const char *fmt,...)
Formats a string in a circular formatting buffer and prints the string.
Definition TString.cxx:2509
#define R__LOCKGUARD(mutex)
const char * proto
Definition civetweb.c:18822
#define snprintf
Definition civetweb.c:1579
This class stores the date and time with a precision of one second in an unsigned 32 bit word (950130...
Definition TDatime.h:37
void Set()
Set Date/Time to current time as reported by the system.
Definition TDatime.cxx:288
const char * AsString() const
Return the date & time as a string (ctime() format).
Definition TDatime.cxx:101
A doubly linked list.
Definition TList.h:38
void Add(TObject *obj) override
Definition TList.h:81
void Delete(Option_t *option="") override
Remove all objects from the list AND delete all heap based objects.
Definition TList.cxx:467
Mother of all ROOT objects.
Definition TObject.h:41
void AbstractMethod(const char *method) const
Call this function within a function that you don't want to define as purely virtual,...
Definition TObject.cxx:1122
TObject & operator=(const TObject &rhs) noexcept
TObject assignment operator.
Definition TObject.h:299
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition TObject.cxx:1045
Bool_t IsActive() const
Check remote OffSet and expiring Date.
TString fMethodName
Definition TSecContext.h:47
void Cleanup()
Cleanup what is still active.
const char * GetHost() const
Definition TSecContext.h:75
void AddForCleanup(Int_t port, Int_t proto, Int_t type)
Create a new TSecContextCleanup Internally is added to the list.
const char * GetMethodName() const
Definition TSecContext.h:78
TString fID
Definition TSecContext.h:45
virtual ~TSecContext()
Dtor: delete (deActivate, local/remote cleanup, list removal) all what is still active.
void * fContext
Definition TSecContext.h:41
TDatime fExpDate
Definition TSecContext.h:43
Int_t fMethod
Definition TSecContext.h:46
TString fUser
Definition TSecContext.h:50
virtual void DeActivate(Option_t *opt="CR")
Set OffSet to -1 and expiring Date to default Remove from the list If Opt contains "C" or "c",...
TClass * IsA() const override
Definition TSecContext.h:94
TSecContext & operator=(const TSecContext &)
assignement operator
TSecContext(const TSecContext &)
copy constructor
Int_t fOffSet
Definition TSecContext.h:48
virtual const char * AsString(TString &out)
Returns short string with relevant information about this security context.
void Print(Option_t *option="F") const override
If opt is "F" (default) print object content.
TString fToken
Definition TSecContext.h:49
virtual Bool_t CleanupSecContext(Bool_t all)
Ask remote client to cleanup security context 'ctx' If 'all', all sec context with the same host as c...
TList * fCleanup
Definition TSecContext.h:42
TString fHost
Definition TSecContext.h:44
Basic string class.
Definition TString.h:138
const char * Data() const
Definition TString.h:384
This class represents a WWW compatible URL.
Definition TUrl.h:33
const char * GetUser() const
Definition TUrl.h:65
const char * GetHost() const
Definition TUrl.h:67