Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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 "TError.h"
23#include "THostAuth.h"
24#include "TRootAuth.h"
25#include "TRootSecContext.h"
26#include "TSocket.h"
27#include "TSystem.h"
28#include "TUrl.h"
29
30////////////////////////////////////////////////////////////////////////////////
31/// Runs authentication on socket s.
32/// Invoked when dynamic loading is needed.
33/// Returns 1 on success, 0 on failure.
34
36 const char *user, Option_t *opts)
37{
38 TSecContext *ctx = 0;
39 Int_t rc = 0;
40
41 Int_t rproto = s->GetRemoteProtocol() % 1000;
42 if (s->GetServType() == (Int_t)TSocket::kROOTD) {
43 if (rproto > 6 && rproto < 10) {
44 // Middle aged versions expect client protocol now
46 Int_t kind = 0;
47 if (s->Recv(rproto, kind) < 0) {
48 Error("Authenticate", "receiving remote protocol");
49 return ctx;
50 }
51 s->SetRemoteProtocol(rproto);
52 }
53 }
54
55 Bool_t isPROOF = (s->GetServType() == (Int_t)TSocket::kPROOFD);
56 Bool_t isPROOFserv = (opts[0] == 'P') ? kTRUE : kFALSE;
57
58 // Build the protocol string for TAuthenticate
60 if (proto == "") {
61 proto = "root";
62 } else if (proto.Contains("sockd") || proto.Contains("rootd") ||
63 proto.Contains("proofd")) {
64 proto.ReplaceAll("d",1,"",0);
65 }
66 proto += Form(":%d",rproto);
67
68 // Init authentication
69 TAuthenticate *auth =
70 new TAuthenticate(s, host, proto, user);
71
72 // Attempt authentication
73 if (!auth->Authenticate()) {
74 // Close the socket if unsuccessful
75 if (auth->HasTimedOut() > 0)
76 Error("Authenticate",
77 "timeout expired for %s@%s", auth->GetUser(), host);
78 else
79 Error("Authenticate",
80 "authentication failed for %s@%s", auth->GetUser(), host);
81 // This is to terminate properly remote proofd in case of failure
82 if (isPROOF)
83 s->Send(Form("%d %s", gSystem->GetPid(), host), kROOTD_CLEANUP);
84 } else {
85 // Set return flag;
86 rc = 1;
87 // Search pointer to relevant TSecContext
88 ctx = auth->GetSecContext();
89 s->SetSecContext(ctx);
90 }
91 // Cleanup
92 delete auth;
93
94 // If we are talking to a recent proofd send over a buffer with the
95 // remaining authentication related stuff
96 if (rc && isPROOF && rproto > 11) {
97 Bool_t client = !isPROOFserv;
98 if (TAuthenticate::ProofAuthSetup(s, client) !=0 ) {
99 Error("Authenticate", "PROOF: failed to finalize setup");
100 }
101 }
102
103 // We are done
104 return ctx;
105}
106
107////////////////////////////////////////////////////////////////////////////////
108/// Return client version;
109
111{
113}
114
115////////////////////////////////////////////////////////////////////////////////
116/// Print error string corresponding to ecode, prepending location
117
118void TRootAuth::ErrorMsg(const char *where, Int_t ecode)
119{
120 TAuthenticate::AuthError(where, ecode);
121}
@ kROOTD_PROTOCOL2
@ kROOTD_CLEANUP
int Int_t
Definition RtypesCore.h:45
const Bool_t kFALSE
Definition RtypesCore.h:92
const Bool_t kTRUE
Definition RtypesCore.h:91
const char Option_t
Definition RtypesCore.h:66
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition TError.cxx:187
char * Form(const char *fmt,...)
R__EXTERN TSystem * gSystem
Definition TSystem.h:559
const char * proto
Definition civetweb.c:16604
TRootSecContext * GetSecContext() const
Int_t HasTimedOut() 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.
Int_t ClientVersion()
Return client version;.
TSecContext * Authenticate(TSocket *, const char *host, const char *user, Option_t *options="")
Runs authentication on socket s.
Definition TRootAuth.cxx:35
void ErrorMsg(const char *where, Int_t ecode=-1)
Print error string corresponding to ecode, prepending location.
void SetRemoteProtocol(Int_t rproto)
Definition TSocket.h:151
virtual Int_t Recv(TMessage *&mess)
Receive a TMessage object.
Definition TSocket.cxx:818
static Int_t GetClientProtocol()
Static method returning supported client protocol.
Definition TSocket.cxx:1469
Int_t GetRemoteProtocol() const
Definition TSocket.h:126
@ kROOTD
Definition TSocket.h:52
@ kPROOFD
Definition TSocket.h:52
Int_t GetServType() const
Definition TSocket.h:117
void SetSecContext(TSecContext *ctx)
Definition TSocket.h:152
const char * GetUrl() const
Definition TSocket.h:130
virtual Int_t Send(const TMessage &mess)
Send a TMessage object.
Definition TSocket.cxx:522
Basic string class.
Definition TString.h:136
virtual int GetPid()
Get process id.
Definition TSystem.cxx:708
This class represents a WWW compatible URL.
Definition TUrl.h:33
const char * GetProtocol() const
Definition TUrl.h:64