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
40 Int_t rproto = s->GetRemoteProtocol() % 1000;
41 if (s->GetServType() == (Int_t)TSocket::kROOTD) {
42 if (rproto > 6 && rproto < 10) {
43 // Middle aged versions expect client protocol now
45 Int_t kind = 0;
46 if (s->Recv(rproto, kind) < 0) {
47 Error("Authenticate", "receiving remote protocol");
48 return ctx;
49 }
51 }
52 }
53
54 // Build the protocol string for TAuthenticate
56 if (proto == "") {
57 proto = "root";
58 } else if (proto.Contains("sockd") || proto.Contains("rootd")) {
59 proto.ReplaceAll("d",1,"",0);
60 }
61 proto += Form(":%d",rproto);
62
63 // Init authentication
65 new TAuthenticate(s, host, proto, user);
66
67 // Attempt authentication
68 if (!auth->Authenticate()) {
69 // Close the socket if unsuccessful
70 if (auth->HasTimedOut() > 0)
71 Error("Authenticate",
72 "timeout expired for %s@%s", auth->GetUser(), host);
73 else
74 Error("Authenticate",
75 "authentication failed for %s@%s", auth->GetUser(), host);
76 } else {
77 // Search pointer to relevant TSecContext
78 ctx = auth->GetSecContext();
79 s->SetSecContext(ctx);
80 }
81 // Cleanup
82 delete auth;
83
84 // We are done
85 return ctx;
86}
87
88////////////////////////////////////////////////////////////////////////////////
89/// Return client version;
90
95
96////////////////////////////////////////////////////////////////////////////////
97/// Print error string corresponding to ecode, prepending location
98
@ kROOTD_PROTOCOL2
const char Option_t
Option string (const char)
Definition RtypesCore.h:80
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition TError.cxx:208
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition TString.cxx:2496
const char * proto
Definition civetweb.c:18822
static void AuthError(const char *where, Int_t error)
Print error string depending on error code.
void ErrorMsg(const char *where, Int_t ecode=-1) override
Print error string corresponding to ecode, prepending location.
Definition TRootAuth.cxx:99
TSecContext * Authenticate(TSocket *, const char *host, const char *user, Option_t *options="") override
Runs authentication on socket s.
Definition TRootAuth.cxx:35
Int_t ClientVersion() override
Return client version;.
Definition TRootAuth.cxx:91
void SetRemoteProtocol(Int_t rproto)
Definition TSocket.h:149
virtual Int_t Recv(TMessage *&mess)
Receive a TMessage object.
Definition TSocket.cxx:810
static Int_t GetClientProtocol()
Static method returning supported client protocol.
Definition TSocket.cxx:1436
Int_t GetRemoteProtocol() const
Definition TSocket.h:124
@ kROOTD
Definition TSocket.h:50
Int_t GetServType() const
Definition TSocket.h:115
void SetSecContext(TSecContext *ctx)
Definition TSocket.h:150
const char * GetUrl() const
Definition TSocket.h:128
virtual Int_t Send(const TMessage &mess)
Send a TMessage object.
Definition TSocket.cxx:514
Basic string class.
Definition TString.h:138
This class represents a WWW compatible URL.
Definition TUrl.h:33
const char * GetProtocol() const
Definition TUrl.h:64