Logo ROOT   6.16/01
Reference Guide
TRootAuth.cxx
Go to the documentation of this file.
1// @(#)root/auth:$Id$
2// Author: Gerardo Ganis 08/07/05
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// TRootAuth //
15// //
16// TVirtualAuth implementation based on the old client authentication //
17// code. //
18// //
19//////////////////////////////////////////////////////////////////////////
20
21#include "TAuthenticate.h"
22#include "TEnv.h"
23#include "TError.h"
24#include "THostAuth.h"
25#include "TRootAuth.h"
26#include "TRootSecContext.h"
27#include "TSocket.h"
28#include "TSystem.h"
29#include "TUrl.h"
30
31////////////////////////////////////////////////////////////////////////////////
32/// Runs authentication on socket s.
33/// Invoked when dynamic loading is needed.
34/// Returns 1 on success, 0 on failure.
35
37 const char *user, Option_t *opts)
38{
39 TSecContext *ctx = 0;
40 Int_t rc = 0;
41
42 Int_t rproto = s->GetRemoteProtocol() % 1000;
43 if (s->GetServType() == (Int_t)TSocket::kROOTD) {
44 if (rproto > 6 && rproto < 10) {
45 // Middle aged versions expect client protocol now
47 Int_t kind = 0;
48 if (s->Recv(rproto, kind) < 0) {
49 Error("Authenticate", "receiving remote protocol");
50 return ctx;
51 }
52 s->SetRemoteProtocol(rproto);
53 }
54 }
55
56 // Find out if we are a PROOF master
57 Bool_t isPROOF = (s->GetServType() == (Int_t)TSocket::kPROOFD);
58 Bool_t isMASTER = kFALSE;
59 if (isPROOF) {
60 // Master by default
61 isMASTER = kTRUE;
62 // Parse option
63 TString opt(TUrl(s->GetUrl()).GetOptions());
64 if (!strncasecmp(opt.Data()+1, "C", 1)) {
65 isMASTER = kFALSE;
66 }
67 }
68
69 // Find out whether we are a proof serv
70 Bool_t isPROOFserv = (opts[0] == 'P') ? kTRUE : kFALSE;
71
72 // Build the protocol string for TAuthenticate
73 TString proto = TUrl(s->GetUrl()).GetProtocol();
74 if (proto == "") {
75 proto = "root";
76 } else if (proto.Contains("sockd") || proto.Contains("rootd") ||
77 proto.Contains("proofd")) {
78 proto.ReplaceAll("d",1,"",0);
79 }
80 proto += Form(":%d",rproto);
81
82 // Init authentication
83 TAuthenticate *auth =
84 new TAuthenticate(s, host, proto, user);
85
86 // If PROOF client and trasmission of the SRP password is
87 // requested make sure that ReUse is switched on to get and
88 // send also the Public Key
89 // Masters do this automatically upon reception of valid info
90 // (see TSlave.cxx)
91 if (isMASTER && !isPROOFserv) {
92 if (gEnv->GetValue("Proofd.SendSRPPwd",0)) {
94 TString detsSRP(auth->GetHostAuth()->GetDetails(kSRP));
95 Int_t pos = detsSRP.Index("ru:0");
96 if (pos > -1) {
97 detsSRP.ReplaceAll("ru:0",4,"ru:1",4);
98 auth->GetHostAuth()->SetDetails(kSRP,detsSRP);
99 } else {
100 TSubString ss = detsSRP.SubString("ru:no",TString::kIgnoreCase);
101 if (!ss.IsNull()) {
102 detsSRP.ReplaceAll(ss.Data(),5,"ru:1",4);
103 auth->GetHostAuth()->SetDetails(kSRP,detsSRP);
104 }
105 }
106 }
107 }
108
109 // No control on credential forwarding in case of SSH authentication;
110 // switched it off on PROOF servers, unless the user knows what they
111 // are doing
112 if (isPROOFserv) {
113 if (!(gEnv->GetValue("ProofServ.UseSSH",0)))
115 }
116
117 // Attempt authentication
118 if (!auth->Authenticate()) {
119 // Close the socket if unsuccessful
120 if (auth->HasTimedOut() > 0)
121 Error("Authenticate",
122 "timeout expired for %s@%s", auth->GetUser(), host);
123 else
124 Error("Authenticate",
125 "authentication failed for %s@%s", auth->GetUser(), host);
126 // This is to terminate properly remote proofd in case of failure
127 if (isPROOF)
128 s->Send(Form("%d %s", gSystem->GetPid(), host), kROOTD_CLEANUP);
129 } else {
130 // Set return flag;
131 rc = 1;
132 // Search pointer to relevant TSecContext
133 ctx = auth->GetSecContext();
134 s->SetSecContext(ctx);
135 }
136 // Cleanup
137 delete auth;
138
139 // If we are talking to a recent proofd send over a buffer with the
140 // remaining authentication related stuff
141 if (rc && isPROOF && rproto > 11) {
142 Bool_t client = !isPROOFserv;
143 if (TAuthenticate::ProofAuthSetup(s, client) !=0 ) {
144 Error("Authenticate", "PROOF: failed to finalize setup");
145 }
146 }
147
148 // We are done
149 return ctx;
150}
151
152////////////////////////////////////////////////////////////////////////////////
153/// Return client version;
154
156{
158}
159
160////////////////////////////////////////////////////////////////////////////////
161/// Print error string corresponding to ecode, prepending location
162
163void TRootAuth::ErrorMsg(const char *where, Int_t ecode)
164{
165 TAuthenticate::AuthError(where, ecode);
166}
@ kROOTD_PROTOCOL2
Definition: MessageTypes.h:133
@ kROOTD_CLEANUP
Definition: MessageTypes.h:136
int Int_t
Definition: RtypesCore.h:41
const Bool_t kFALSE
Definition: RtypesCore.h:88
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kTRUE
Definition: RtypesCore.h:87
const char Option_t
Definition: RtypesCore.h:62
R__EXTERN TEnv * gEnv
Definition: TEnv.h:171
void Error(const char *location, const char *msgfmt,...)
char * Form(const char *fmt,...)
R__EXTERN TSystem * gSystem
Definition: TSystem.h:540
const char * proto
Definition: civetweb.c:16604
TRootSecContext * GetSecContext() const
Int_t HasTimedOut() const
THostAuth * GetHostAuth() const
const char * GetUser() const
Bool_t Authenticate()
Authenticate to remote rootd or proofd server.
Int_t ProofAuthSetup()
Authentication related stuff setup in TProofServ.
static void AuthError(const char *where, Int_t error)
Print error string depending on error code.
virtual Int_t GetValue(const char *name, Int_t dflt) const
Returns the integer value for a resource.
Definition: TEnv.cxx:491
void SetDetails(Int_t level, const char *details)
Set authentication details for specified level.
Definition: THostAuth.cxx:403
void RemoveMethod(Int_t level)
Remove method 'meth' from the list, if there ...
Definition: THostAuth.cxx:310
const char * GetDetails(Int_t level)
Return authentication details for specified level or "" if the specified level does not exist for thi...
Definition: THostAuth.cxx:371
Int_t ClientVersion()
Return client version;.
Definition: TRootAuth.cxx:155
TSecContext * Authenticate(TSocket *, const char *host, const char *user, Option_t *options="")
Runs authentication on socket s.
Definition: TRootAuth.cxx:36
void ErrorMsg(const char *where, Int_t ecode=-1)
Print error string corresponding to ecode, prepending location.
Definition: TRootAuth.cxx:163
static Int_t GetClientProtocol()
Static method returning supported client protocol.
Definition: TSocket.cxx:1488
@ kROOTD
Definition: TSocket.h:72
@ kPROOFD
Definition: TSocket.h:72
Basic string class.
Definition: TString.h:131
TSubString SubString(const char *pat, Ssiz_t start=0, ECaseCompare cmp=kExact) const
Returns a substring matching "pattern", or the null substring if there is no such match.
Definition: TString.cxx:1565
const char * Data() const
Definition: TString.h:364
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition: TString.h:687
@ kIgnoreCase
Definition: TString.h:263
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Definition: TString.h:634
A zero length substring is legal.
Definition: TString.h:77
Bool_t IsNull() const
Definition: TString.h:121
const char * Data() const
Definition: TString.h:721
virtual int GetPid()
Get process id.
Definition: TSystem.cxx:716
This class represents a WWW compatible URL.
Definition: TUrl.h:35
const char * GetOptions() const
Definition: TUrl.h:74
const char * GetProtocol() const
Definition: TUrl.h:67
static constexpr double s