Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TRootSecContext.cxx
Go to the documentation of this file.
1// @(#)root/auth:$Id$
2// Author: G. Ganis 08/07/2005
3
4/*************************************************************************
5 * Copyright (C) 1995-2005, 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// TRootSecContext //
15// //
16// Special implementation of TSecContext //
17// //
18//////////////////////////////////////////////////////////////////////////
19
20#include "RConfigure.h"
21
22#include <stdlib.h>
23
24#include "TError.h"
25#include "TRootSecContext.h"
26#include "TROOT.h"
27#include "TSocket.h"
28#include "TUrl.h"
29#include "TVirtualMutex.h"
30
32
33////////////////////////////////////////////////////////////////////////////////
34/// Ctor for SecContext object.
35
36 TRootSecContext::TRootSecContext(const char *user, const char *host, Int_t meth,
37 Int_t offset, const char *id,
38 const char *token, TDatime expdate,
39 void *ctx, Int_t key)
40 : TSecContext(user, host, meth, offset, id, token, expdate, ctx)
41{
43
44 fRSAKey = key;
46}
47
48////////////////////////////////////////////////////////////////////////////////
49/// Ctor for SecContext object.
50/// User and host from url = `user@host` .
51
53 const char *id, const char *token,
54 TDatime expdate, void *ctx, Int_t key)
55 : TSecContext(url, meth, offset, id, token, expdate, ctx)
56{
58
59 fRSAKey = key;
61}
62
63////////////////////////////////////////////////////////////////////////////////
64/// Dtor: delete (deActivate, local/remote cleanup, list removal)
65/// all what is still active
66
71
72////////////////////////////////////////////////////////////////////////////////
73/// Set OffSet to -1 and expiring Date to default
74/// Remove from the list
75/// If Opt contains "C" or "c", ask for remote cleanup
76/// If Opt contains "R" or "r", remove from the list
77/// Default Opt="CR"
78
80{
81 // Ask remote cleanup of this context
82 Bool_t clean = (strstr(Opt,"C") || strstr(Opt,"c"));
83 if (clean && fOffSet > -1)
85
86 // Cleanup TPwdCtx object fro UsrPwd
88 if (fContext) {
89 delete (TPwdCtx *)fContext;
90 fContext = 0;
91 }
92
93 Bool_t remove = (strstr(Opt,"R") || strstr(Opt,"r"));
94 if (remove && fOffSet > -1){
96 // Remove from the global list
97 gROOT->GetListOfSecContexts()->Remove(this);
98 // Remove also from local lists in THostAuth objects
100 }
101
102 // Set inactive
103 fOffSet = -1;
105
106}
107
108////////////////////////////////////////////////////////////////////////////////
109/// Ask remote client to cleanup security context 'ctx'
110/// If 'all', all sec context with the same host as ctx
111/// are cleaned.
112
114{
116
117 // Nothing to do if inactive ...
118 if (!IsActive())
119 return kTRUE;
120
121 // Contact remote services that used this context,
122 // starting from the last ...
125 while ((nscc = (TSecContextCleanup *)last()) && !cleaned) {
126
127 // First check if remote daemon supports cleaning
128 Int_t srvtyp = nscc->GetType();
129 Int_t rproto = nscc->GetProtocol();
130 Int_t level = 2;
131 if ((srvtyp == TSocket::kROOTD && rproto < 10))
132 level = 1;
133 if ((srvtyp == TSocket::kROOTD && rproto < 8))
134 level = 0;
135 if (level) {
136 Int_t port = nscc->GetPort();
137
138 TSocket *news = new TSocket(fHost.Data(),port,-1);
139
140 if (news && news->IsValid()) {
141 news->SetOption(kNoDelay, 0);
142
143 // Backward compatibility: send socket size
144 if (srvtyp == TSocket::kROOTD && level == 1)
145 news->Send((Int_t)0, (Int_t)0);
146
147 if (all || level == 1) {
149 cleaned = kTRUE;
150 } else {
151 news->Send(Form("%d %d %d %s", TAuthenticate::fgProcessID, fMethod,
154 (char *)(fToken.Data())) == -1) {
155 Info("CleanupSecContext", "problems secure-sending token");
156 } else {
157 cleaned = kTRUE;
158 }
159 }
160 if (cleaned && gDebug > 2) {
161 char srvname[3][10] = {"sockd", "rootd"};
162 Info("CleanupSecContext",
163 "remote %s notified for cleanup (%s,%d)",
164 srvname[srvtyp],fHost.Data(),port);
165 }
166 }
168 }
169 }
170
171 if (!cleaned)
172 if (gDebug > 2)
173 Info("CleanupSecContext",
174 "unable to open valid socket for cleanup for %s", fHost.Data());
175
176 return cleaned;
177}
178
179////////////////////////////////////////////////////////////////////////////////
180/// If opt is "F" (default) print object content.
181/// If opt is "<number>" print in special form for calls within THostAuth
182/// with cardinality "<number>"
183/// If opt is "S" prints short in-line form for calls within TFTP,
184/// TSlave ...
185
187{
188 // Check if option is numeric
189 Int_t ord = -1, i = 0;
190 for (; i < (Int_t)strlen(opt); i++) {
191 if (opt[i] < 48 || opt[i] > 57) {
192 ord = -2;
193 break;
194 }
195 }
196 // If numeric get the cardinality and prepare the strings
197 if (ord == -1)
198 ord = atoi(opt);
199
200 if (!strncasecmp(opt,"F",1)) {
201 Info("Print",
202 "+------------------------------------------------------+");
203 Info("Print",
204 "+ Host:%s Method:%d (%s) User:'%s'",
206 fUser.Data());
207 Info("Print",
208 "+ OffSet:%d Id: '%s'", fOffSet, fID.Data());
209 if (fOffSet > -1)
210 Info("Print",
211 "+ Expiration time: %s",fExpDate.AsString());
212 Info("Print",
213 "+------------------------------------------------------+");
214 } else if (!strncasecmp(opt,"S",1)) {
215 if (fOffSet > -1) {
216 if (fID.BeginsWith("AFS"))
217 Printf("Security context: Method: AFS, not reusable");
218 else
219 Printf("Security context: Method: %d (%s) expiring on %s",
222 } else {
223 Printf("Security context: Method: %d (%s) not reusable",
225 }
226 } else {
227 // special printing form for THostAuth
228 Info("PrintEstblshed","+ %d \t h:%s met:%d (%s) us:'%s'",
230 fUser.Data());
231 Info("PrintEstblshed","+ \t offset:%d id: '%s'", fOffSet, fID.Data());
232 if (fOffSet > -1)
233 Info("PrintEstblshed","+ \t expiring: %s",fExpDate.AsString());
234 }
235}
236
237////////////////////////////////////////////////////////////////////////////////
238/// Returns short string with relevant information about this
239/// security context
240
242{
243 if (fOffSet > -1) {
244 if (fID.BeginsWith("AFS"))
245 out = Form("Method: AFS, not reusable");
246 else {
247 char expdate[32];
248 out = Form("Method: %d (%s) expiring on %s",
250 }
251 } else {
252 if (fOffSet == -1)
253 out = Form("Method: %d (%s) not reusable", fMethod, GetMethodName());
254 else if (fOffSet == -3)
255 out = Form("Method: %d (%s) authorized by /etc/hosts.equiv or $HOME/.rhosts",
257 else if (fOffSet == -4)
258 out = Form("No authentication required remotely");
259 }
260 return out.Data();
261}
@ kROOTD_CLEANUP
#define SafeDelete(p)
Definition RConfig.hxx:533
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
#define ClassImp(name)
Definition Rtypes.h:376
const Bool_t kIterBackward
Definition TCollection.h:43
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
Int_t gDebug
Global variable setting the debug level. Set to 0 to disable, increase it in steps of 1 to increase t...
Definition TROOT.cxx:627
R__EXTERN TVirtualMutex * gROOTMutex
Definition TROOT.h:63
#define gROOT
Definition TROOT.h:411
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:2496
void Printf(const char *fmt,...)
Formats a string in a circular formatting buffer and prints the string.
Definition TString.cxx:2510
@ kNoDelay
Definition TSystem.h:235
#define R__LOCKGUARD(mutex)
static Int_t fgProcessID
static Int_t SecureSend(TSocket *Socket, Int_t enc, Int_t KeyType, const char *In)
Encode null terminated str using the session private key indicated by enc and sends it over the netwo...
static void RemoveSecContext(TRootSecContext *ctx)
Tool for removing SecContext ctx from THostAuth listed in fgAuthInfo.
static const char * GetAuthMethod(Int_t idx)
Static method returning the method corresponding to idx.
This class stores the date and time with a precision of one second in an unsigned 32 bit word (950130...
Definition TDatime.h:37
const char * AsString() const
Return the date & time as a string (ctime() format).
Definition TDatime.cxx:102
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition TObject.cxx:1046
Bool_t CleanupSecContext(Bool_t all) override
Ask remote client to cleanup security context 'ctx' If 'all', all sec context with the same host as c...
void DeActivate(Option_t *opt="CR") override
Set OffSet to -1 and expiring Date to default Remove from the list If Opt contains "C" or "c",...
void Print(Option_t *option="F") const override
If opt is "F" (default) print object content.
const char * AsString(TString &out) override
Returns short string with relevant information about this security context.
virtual ~TRootSecContext()
Dtor: delete (deActivate, local/remote cleanup, list removal) all what is still active.
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
const char * GetMethodName() const
Definition TSecContext.h:78
TString fID
Definition TSecContext.h:45
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
friend class TRootSecContext
Definition TSecContext.h:38
Int_t fOffSet
Definition TSecContext.h:48
TString fToken
Definition TSecContext.h:49
TList * fCleanup
Definition TSecContext.h:42
TString fHost
Definition TSecContext.h:44
@ kROOTD
Definition TSocket.h:50
Basic string class.
Definition TString.h:138
const char * Data() const
Definition TString.h:384
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
Definition TString.h:631