00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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
00036
00037
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
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
00053 Bool_t isPROOF = (s->GetServType() == (Int_t)TSocket::kPROOFD);
00054 Bool_t isMASTER = kFALSE;
00055 if (isPROOF) {
00056
00057 isMASTER = kTRUE;
00058
00059 TString opt(TUrl(s->GetUrl()).GetOptions());
00060 if (!strncasecmp(opt.Data()+1, "C", 1)) {
00061 isMASTER = kFALSE;
00062 }
00063 }
00064
00065
00066 Bool_t isPROOFserv = (opts[0] == 'P') ? kTRUE : kFALSE;
00067
00068
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
00079 TAuthenticate *auth =
00080 new TAuthenticate(s, host, proto, user);
00081
00082
00083
00084
00085
00086
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
00106
00107
00108 if (isPROOFserv) {
00109 if (!(gEnv->GetValue("ProofServ.UseSSH",0)))
00110 auth->GetHostAuth()->RemoveMethod(TAuthenticate::kSSH);
00111 }
00112
00113
00114 if (!auth->Authenticate()) {
00115
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
00123 if (isPROOF)
00124 s->Send(Form("%d %s", gSystem->GetPid(), host), kROOTD_CLEANUP);
00125 } else {
00126
00127 rc = 1;
00128
00129 ctx = auth->GetSecContext();
00130 s->SetSecContext(ctx);
00131 }
00132
00133 delete auth;
00134
00135
00136
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
00145 return ctx;
00146 }
00147
00148
00149 Int_t TRootAuth::ClientVersion()
00150 {
00151
00152
00153 return TSocket::GetClientProtocol();
00154 }
00155
00156
00157 void TRootAuth::ErrorMsg(const char *where, Int_t ecode)
00158 {
00159
00160
00161 TAuthenticate::AuthError(where, ecode);
00162 }