20 #include "RConfigure.h"
31 ClassImp(TRootSecContext);
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,
40 : TSecContext(user, host, meth, offset, id, token, expdate, ctx)
45 fMethodName = TAuthenticate::GetAuthMethod(fMethod);
52 TRootSecContext::TRootSecContext(
const char *url, Int_t meth, Int_t offset,
53 const char *
id,
const char *token,
54 TDatime expdate,
void *ctx, Int_t key)
55 : TSecContext(url, meth, offset, id, token, expdate, ctx)
60 fMethodName = TAuthenticate::GetAuthMethod(fMethod);
67 TRootSecContext::~TRootSecContext()
69 TSecContext::Cleanup();
79 void TRootSecContext::DeActivate(Option_t *Opt)
82 Bool_t clean = (strstr(Opt,
"C") || strstr(Opt,
"c"));
83 if (clean && fOffSet > -1)
84 CleanupSecContext(kFALSE);
87 if (fMethod == TAuthenticate::kClear)
89 delete (TPwdCtx *)fContext;
93 Bool_t
remove = (strstr(Opt,
"R") || strstr(Opt,
"r"));
94 if (
remove && fOffSet > -1){
95 R__LOCKGUARD(gROOTMutex);
97 gROOT->GetListOfSecContexts()->Remove(
this);
99 TAuthenticate::RemoveSecContext(
this);
104 fExpDate = kROOTTZERO;
113 Bool_t TRootSecContext::CleanupSecContext(Bool_t all)
115 Bool_t cleaned = kFALSE;
123 TIter last(fCleanup,kIterBackward);
124 TSecContextCleanup *nscc = 0;
125 while ((nscc = (TSecContextCleanup *)last()) && !cleaned) {
128 Int_t srvtyp = nscc->GetType();
129 Int_t rproto = nscc->GetProtocol();
131 if ((srvtyp == TSocket::kROOTD && rproto < 10) ||
132 (srvtyp == TSocket::kPROOFD && rproto < 9))
134 if ((srvtyp == TSocket::kROOTD && rproto < 8) ||
135 (srvtyp == TSocket::kPROOFD && rproto < 7))
138 Int_t port = nscc->GetPort();
140 TSocket *news =
new TSocket(fHost.Data(),port,-1);
142 if (news && news->IsValid()) {
143 if (srvtyp == TSocket::kPROOFD) {
144 news->SetOption(kNoDelay, 1);
145 news->Send(
"cleaning request");
147 news->SetOption(kNoDelay, 0);
150 if (srvtyp == TSocket::kROOTD && level == 1)
151 news->Send((Int_t)0, (Int_t)0);
153 if (all || level == 1) {
154 news->Send(Form(
"%d",TAuthenticate::fgProcessID), kROOTD_CLEANUP);
157 news->Send(Form(
"%d %d %d %s", TAuthenticate::fgProcessID, fMethod,
158 fOffSet, fUser.Data()), kROOTD_CLEANUP);
159 if (TAuthenticate::SecureSend(news, 1, fRSAKey,
160 (
char *)(fToken.Data())) == -1) {
161 Info(
"CleanupSecContext",
"problems secure-sending token");
166 if (cleaned && gDebug > 2) {
167 char srvname[3][10] = {
"sockd",
"rootd",
"proofd"};
168 Info(
"CleanupSecContext",
169 "remote %s notified for cleanup (%s,%d)",
170 srvname[srvtyp],fHost.Data(),port);
179 Info(
"CleanupSecContext",
180 "unable to open valid socket for cleanup for %s", fHost.Data());
192 void TRootSecContext::Print(Option_t *opt)
const
195 Int_t ord = -1, i = 0;
196 for (; i < (Int_t)strlen(opt); i++) {
197 if (opt[i] < 48 || opt[i] > 57) {
206 if (!strncasecmp(opt,
"F",1)) {
208 "+------------------------------------------------------+");
210 "+ Host:%s Method:%d (%s) User:'%s'",
211 GetHost(), fMethod, GetMethodName(),
214 "+ OffSet:%d Id: '%s'", fOffSet, fID.Data());
217 "+ Expiration time: %s",fExpDate.AsString());
219 "+------------------------------------------------------+");
220 }
else if (!strncasecmp(opt,
"S",1)) {
222 if (fID.BeginsWith(
"AFS"))
223 Printf(
"Security context: Method: AFS, not reusable");
225 Printf(
"Security context: Method: %d (%s) expiring on %s",
226 fMethod, GetMethodName(),
227 fExpDate.AsString());
229 Printf(
"Security context: Method: %d (%s) not reusable",
230 fMethod, GetMethodName());
234 Info(
"PrintEstblshed",
"+ %d \t h:%s met:%d (%s) us:'%s'",
235 ord, GetHost(), fMethod, GetMethodName(),
237 Info(
"PrintEstblshed",
"+ \t offset:%d id: '%s'", fOffSet, fID.Data());
239 Info(
"PrintEstblshed",
"+ \t expiring: %s",fExpDate.AsString());
247 const char *TRootSecContext::AsString(TString &out)
250 if (fID.BeginsWith(
"AFS"))
251 out = Form(
"Method: AFS, not reusable");
254 out = Form(
"Method: %d (%s) expiring on %s",
255 fMethod, GetMethodName(), fExpDate.AsString(expdate));
259 out = Form(
"Method: %d (%s) not reusable", fMethod, GetMethodName());
260 else if (fOffSet == -3)
261 out = Form(
"Method: %d (%s) authorized by /etc/hosts.equiv or $HOME/.rhosts",
262 fMethod, GetMethodName());
263 else if (fOffSet == -4)
264 out = Form(
"No authentication required remotely");