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
36
37const TDatime kROOTTZERO = 788914800;
38
39////////////////////////////////////////////////////////////////////////////////
40/// Ctor for SecContext object.
41
42TSecContext::TSecContext(const char *user, const char *host, Int_t meth,
43 Int_t offset, const char *id,
44 const char *token, TDatime expdate, void *ctx)
45 : TObject()
46{
48
49 fContext = ctx;
50 fCleanup = new TList;
51 fExpDate = expdate;
52 if (offset > -1) {
53 if (fExpDate < TDatime()) {
54 // This means expdate was not initialized
55 // We set it to default, ie 1 day from now
56 fExpDate.Set(TDatime().GetDate() + 1, TDatime().GetTime());
57 }
58 }
59 fHost = host;
60 fID = id;
61 fMethod = meth;
62 fMethodName = "";
64 fToken = token;
65 fUser = user;
66
67 // Keep official list updated with active TSecContexts
68 if (fOffSet > -1) {
70 gROOT->GetListOfSecContexts()->Add(this);
71 }
72}
73
74////////////////////////////////////////////////////////////////////////////////
75/// Ctor for SecContext object.
76/// User and host from url = `user@host` .
77
79 const char *token, const char *id,
80 TDatime expdate, void *ctx)
81 : TObject()
82{
84
85 fContext = ctx;
86 fCleanup = new TList;
87 fExpDate = expdate;
88 if (offset > -1) {
89 if (fExpDate < TDatime()) {
90 // This means expdate was not initialized
91 // We set it to default, ie 1 day from now
92 fExpDate.Set(TDatime().GetDate() + 1, TDatime().GetTime());
93 }
94 }
95 fHost = TUrl(url).GetHost();
96 fID = id;
97 fMethod = meth;
98 fMethodName = "";
100 fToken = token;
101 fUser = TUrl(url).GetUser();
102
103 // Keep official list updated with active TSecContexts
104 if (fOffSet > -1) {
106 gROOT->GetListOfSecContexts()->Add(this);
107 }
108}
109
110////////////////////////////////////////////////////////////////////////////////
111///copy constructor
112
114 TObject(sc),
115 fContext(sc.fContext),
116 fCleanup(sc.fCleanup),
117 fExpDate(sc.fExpDate),
118 fHost(sc.fHost),
119 fID(sc.fID),
120 fMethod(sc.fMethod),
121 fMethodName(sc.fMethodName),
122 fOffSet(sc.fOffSet),
123 fToken(sc.fToken),
124 fUser(sc.fUser)
125{
126}
127
128////////////////////////////////////////////////////////////////////////////////
129///assignement operator
130
132{
133 if(this!=&sc) {
138 fHost=sc.fHost;
139 fID=sc.fID;
140 fMethod=sc.fMethod;
142 fOffSet=sc.fOffSet;
143 fToken=sc.fToken;
144 fUser=sc.fUser;
145 }
146 return *this;
147}
148
149////////////////////////////////////////////////////////////////////////////////
150/// Dtor: delete (deActivate, local/remote cleanup, list removal)
151/// all what is still active
152
154{
155 Cleanup();
156}
157////////////////////////////////////////////////////////////////////////////////
158/// Cleanup what is still active
159
161{
162 if (IsActive()) {
164 DeActivate("R");
165 // All have been remotely Deactivated
166 TIter nxtl(gROOT->GetListOfSecContexts());
167 TSecContext *nscl;
168 while ((nscl = (TSecContext *)nxtl())) {
169 if (nscl != this && !strcmp(nscl->GetHost(), fHost.Data())) {
170 // Need to set ofs=-1 to avoid sending another
171 // cleanup request
172 nscl->DeActivate("");
173 }
174 }
175 }
176
177 // Delete the cleanup list
178 if (fCleanup) {
179 fCleanup->Delete();
180 delete fCleanup;
181 fCleanup = 0;
182 }
183}
184
185////////////////////////////////////////////////////////////////////////////////
186/// Set OffSet to -1 and expiring Date to default
187/// Remove from the list
188/// If Opt contains "C" or "c", ask for remote cleanup
189/// If Opt contains "R" or "r", remove from the list
190/// Default Opt="CR"
191
193{
194 // Ask remote cleanup of this context
195 Bool_t clean = (strstr(Opt,"C") || strstr(Opt,"c"));
196 if (clean && fOffSet > -1)
198
199 Bool_t remove = (strstr(Opt,"R") || strstr(Opt,"r"));
200 if (remove && fOffSet > -1){
202 // Remove from the global list
203 gROOT->GetListOfSecContexts()->Remove(this);
204 }
205
206 // Set inactive
207 fOffSet = -1;
209}
210
211////////////////////////////////////////////////////////////////////////////////
212/// Create a new TSecContextCleanup
213/// Internally is added to the list
214
216{
218 fCleanup->Add(tscc);
219
220}
221
222////////////////////////////////////////////////////////////////////////////////
223/// Checks if this security context is for method named 'methname'
224/// Case sensitive.
225
226Bool_t TSecContext::IsA(const char *methname)
227{
228 return Bool_t(!strcmp(methname, GetMethodName()));
229}
230
231////////////////////////////////////////////////////////////////////////////////
232/// Check remote OffSet and expiring Date
233
235{
236 if (fOffSet > -1 && fExpDate > TDatime())
237 return kTRUE;
238 // Invalid
239 return kFALSE;
240}
241
242////////////////////////////////////////////////////////////////////////////////
243/// If opt is "F" (default) print object content.
244/// If opt is "<number>" print in special form for calls within THostAuth
245/// with cardinality "<number>"
246/// If opt is "S" prints short in-line form for calls within TFTP,
247/// TSlave, TProof ...
248
250{
251 char aOrd[16] = {0};
252 char aSpc[16] = {0};
253
254 // Check if option is numeric
255 Int_t ord = -1, i = 0;
256 for (; i < (Int_t)strlen(opt); i++) {
257 if (opt[i] < 48 || opt[i] > 57) {
258 ord = -2;
259 break;
260 }
261 }
262 // If numeric get the cardinality and prepare the strings
263 if (ord == -1)
264 ord = atoi(opt);
265
266 // If asked to print ordinal number, preapre the string
267 if (ord > -1) {
268 snprintf(aOrd, sizeof(aOrd), "%d)", ord);
269 // and take care of alignment
270 Int_t len=strlen(aOrd);
271 while (len--)
272 strlcat(aSpc, " ", sizeof(aSpc));
273 }
274
275 if (!strncasecmp(opt,"F",1)) {
276 Info("Print",
277 "+------------------------------------------------------+");
278 Info("Print",
279 "+ Host:%s Method:%d (%s) User:'%s'",
281 fUser.Data());
282 Info("Print",
283 "+ OffSet:%d, id:%s", fOffSet, fID.Data());
284 if (fOffSet > -1)
285 Info("Print",
286 "+ Expiration time: %s",fExpDate.AsString());
287 Info("Print",
288 "+------------------------------------------------------+");
289 } else if (!strncasecmp(opt,"S",1)) {
290 if (fOffSet > -1) {
291 Printf("Security context: Method: %d (%s) expiring on %s",
294 } else {
295 Printf("Security context: Method: %d (%s) not reusable",
297 }
298 } else {
299 // special printing form for THostAuth
300 Info("PrintEstblshed","+ %s h:%s met:%d (%s) us:'%s'",
301 aOrd, GetHost(), fMethod, GetMethodName(),
302 fUser.Data());
303 Info("PrintEstblshed","+ %s offset:%d id:%s", aSpc, fOffSet, fID.Data());
304 if (fOffSet > -1)
305 Info("PrintEstblshed","+ %s expiring: %s",aSpc,fExpDate.AsString());
306 }
307}
308
309////////////////////////////////////////////////////////////////////////////////
310/// Returns short string with relevant information about this
311/// security context
312
314{
315 if (fOffSet > -1) {
316 char expdate[32];
317 out = Form("Method: %d (%s) expiring on %s",
319 } else {
320 if (fOffSet == -1)
321 out = Form("Method: %d (%s) not reusable", fMethod, GetMethodName());
322 else if (fOffSet == -3)
323 out = Form("Method: %d (%s) authorized by /etc/hosts.equiv or $HOME/.rhosts",
325 else if (fOffSet == -4)
326 out = Form("No authentication required remotely");
327 }
328 return out.Data();
329}
330
331////////////////////////////////////////////////////////////////////////////////
332/// Ask remote client to cleanup security context 'ctx'
333/// If 'all', all sec context with the same host as ctx
334/// are cleaned.
335
337{
338 AbstractMethod("CleanupSecContext");
339 return kFALSE;
340}
bool Bool_t
Definition RtypesCore.h:63
int Int_t
Definition RtypesCore.h:45
constexpr Bool_t kFALSE
Definition RtypesCore.h:101
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:377
#define R__ASSERT(e)
Definition TError.h:118
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:406
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:2489
void Printf(const char *fmt,...)
Formats a string in a circular formatting buffer and prints the string.
Definition TString.cxx:2503
#define R__LOCKGUARD(mutex)
const char * proto
Definition civetweb.c:17536
#define snprintf
Definition civetweb.c:1540
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:289
const char * AsString() const
Return the date & time as a string (ctime() format).
Definition TDatime.cxx:102
A doubly linked list.
Definition TList.h:38
void Add(TObject *obj) override
Definition TList.h:83
void Delete(Option_t *option="") override
Remove all objects from the list AND delete all heap based objects.
Definition TList.cxx:468
Mother of all ROOT objects.
Definition TObject.h:41
void AbstractMethod(const char *method) const
Use this method to implement an "abstract" method that you don't want to leave purely abstract.
Definition TObject.cxx:1029
TObject & operator=(const TObject &rhs)
TObject assignment operator.
Definition TObject.h:296
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition TObject.cxx:961
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:139
const char * Data() const
Definition TString.h:376
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