TRootAuth.cxx

Go to the documentation of this file.
00001 // @(#)root/auth:$Id: TRootAuth.cxx 20882 2007-11-19 11:31:26Z rdm $
00002 // Author: Gerardo Ganis   08/07/05
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2005, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 //////////////////////////////////////////////////////////////////////////
00013 //                                                                      //
00014 // TRootAuth                                                            //
00015 //                                                                      //
00016 // TVirtualAuth implementation based on the old client authentication   //
00017 // code.                                                                //
00018 //                                                                      //
00019 //////////////////////////////////////////////////////////////////////////
00020 
00021 #include "TAuthenticate.h"
00022 #include "TEnv.h"
00023 #include "TError.h"
00024 #include "THostAuth.h"
00025 #include "TRootAuth.h"
00026 #include "TRootSecContext.h"
00027 #include "TSocket.h"
00028 #include "TSystem.h"
00029 #include "TUrl.h"
00030 
00031 //______________________________________________________________________________
00032 TSecContext *TRootAuth::Authenticate(TSocket *s, const char *host,
00033                                      const char *user, Option_t *opts)
00034 {
00035    // Runs authentication on socket s.
00036    // Invoked when dynamic loading is needed.
00037    // Returns 1 on success, 0 on failure.
00038    TSecContext *ctx = 0;
00039    Int_t rc = 0;
00040 
00041    Int_t rproto =  s->GetRemoteProtocol() % 1000;
00042    if (s->GetServType() == (Int_t)TSocket::kROOTD) {
00043       if (rproto > 6 && rproto < 10) {
00044          // Middle aged versions expect client protocol now
00045          s->Send(Form("%d", TSocket::GetClientProtocol()), kROOTD_PROTOCOL2);
00046          Int_t kind = 0;
00047          s->Recv(rproto, kind);
00048          s->SetRemoteProtocol(rproto);
00049       }
00050    }
00051 
00052    // Find out if we are a PROOF master
00053    Bool_t isPROOF = (s->GetServType() == (Int_t)TSocket::kPROOFD);
00054    Bool_t isMASTER = kFALSE;
00055    if (isPROOF) {
00056       // Master by default
00057       isMASTER = kTRUE;
00058       // Parse option
00059       TString opt(TUrl(s->GetUrl()).GetOptions());
00060       if (!strncasecmp(opt.Data()+1, "C", 1)) {
00061          isMASTER = kFALSE;
00062       }
00063    }
00064 
00065    // Find out whether we are a proof serv
00066    Bool_t isPROOFserv = (opts[0] == 'P') ? kTRUE : kFALSE;
00067 
00068    // Build the protocol string for TAuthenticate
00069    TString proto = TUrl(s->GetUrl()).GetProtocol();
00070    if (proto == "") {
00071       proto = "root";
00072    } else if (proto.Contains("sockd") || proto.Contains("rootd") ||
00073               proto.Contains("proofd")) {
00074       proto.ReplaceAll("d",1,"",0);
00075    }
00076    proto += Form(":%d",rproto);
00077 
00078    // Init authentication
00079    TAuthenticate *auth =
00080       new TAuthenticate(s, host, proto, user);
00081 
00082    // If PROOF client and trasmission of the SRP password is
00083    // requested make sure that ReUse is switched on to get and
00084    // send also the Public Key
00085    // Masters do this automatically upon reception of valid info
00086    // (see TSlave.cxx)
00087    if (isMASTER && !isPROOFserv) {
00088       if (gEnv->GetValue("Proofd.SendSRPPwd",0)) {
00089          Int_t kSRP = TAuthenticate::kSRP;
00090          TString detsSRP(auth->GetHostAuth()->GetDetails(kSRP));
00091          Int_t pos = detsSRP.Index("ru:0");
00092          if (pos > -1) {
00093             detsSRP.ReplaceAll("ru:0",4,"ru:1",4);
00094             auth->GetHostAuth()->SetDetails(kSRP,detsSRP);
00095          } else {
00096             TSubString ss = detsSRP.SubString("ru:no",TString::kIgnoreCase);
00097             if (!ss.IsNull()) {
00098                detsSRP.ReplaceAll(ss.Data(),5,"ru:1",4);
00099                auth->GetHostAuth()->SetDetails(kSRP,detsSRP);
00100             }
00101          }
00102       }
00103    }
00104 
00105    // No control on credential forwarding in case of SSH authentication;
00106    // switched it off on PROOF servers, unless the user knows what (s)he
00107    // is doing
00108    if (isPROOFserv) {
00109       if (!(gEnv->GetValue("ProofServ.UseSSH",0)))
00110          auth->GetHostAuth()->RemoveMethod(TAuthenticate::kSSH);
00111    }
00112 
00113    // Attempt authentication
00114    if (!auth->Authenticate()) {
00115       // Close the socket if unsuccessful
00116       if (auth->HasTimedOut() > 0)
00117          Error("Authenticate",
00118                "timeout expired for %s@%s", auth->GetUser(), host);
00119       else
00120          Error("Authenticate",
00121                "authentication failed for %s@%s", auth->GetUser(), host);
00122       // This is to terminate properly remote proofd in case of failure
00123       if (isPROOF)
00124          s->Send(Form("%d %s", gSystem->GetPid(), host), kROOTD_CLEANUP);
00125    } else {
00126       // Set return flag;
00127       rc = 1;
00128       // Search pointer to relevant TSecContext
00129       ctx = auth->GetSecContext();
00130       s->SetSecContext(ctx);
00131    }
00132    // Cleanup
00133    delete auth;
00134 
00135    // If we are talking to a recent proofd send over a buffer with the
00136    // remaining authentication related stuff
00137    if (rc && isPROOF && rproto > 11) {
00138       Bool_t client = !isPROOFserv;
00139       if (TAuthenticate::ProofAuthSetup(s, client) !=0 ) {
00140          Error("Authenticate", "PROOF: failed to finalize setup");
00141       }
00142    }
00143 
00144    // We are done
00145    return ctx;
00146 }
00147 
00148 //______________________________________________________________________________
00149 Int_t TRootAuth::ClientVersion()
00150 {
00151    // Return client version;
00152 
00153    return TSocket::GetClientProtocol();
00154 }
00155 
00156 //______________________________________________________________________________
00157 void TRootAuth::ErrorMsg(const char *where, Int_t ecode)
00158 {
00159    // Print error string corresponding to ecode, prepending location
00160 
00161    TAuthenticate::AuthError(where, ecode);
00162 }

Generated on Tue Jul 5 14:45:38 2011 for ROOT_528-00b_version by  doxygen 1.5.1