21 #include "RConfigure.h"
47 #include <sys/types.h>
49 #if !defined(R__WIN32) && !defined(R__MACOSX) && !defined(R__FBSD) && \
56 #if defined(R__LINUX) || defined(R__FBSD) || defined(R__OBSD)
61 # include <sys/time.h>
64 #if defined(R__MACOSX)
65 extern "C" char *crypt(
const char *,
const char *);
75 # include <openssl/bio.h>
76 # include <openssl/err.h>
77 # include <openssl/pem.h>
78 # include <openssl/rand.h>
79 # include <openssl/rsa.h>
80 # include <openssl/ssl.h>
84 TList *TAuthenticate::fgAuthInfo = 0;
85 TString TAuthenticate::fgAuthMeth[] = {
"UsrPwd",
"SRP",
"Krb5",
86 "Globus",
"SSH",
"UidGid" };
97 TList *TAuthenticate::fgProofAuthInfo = 0;
101 Int_t TAuthenticate::fgRSAKey = -1;
102 Int_t TAuthenticate::fgRSAInit = 0;
107 BF_KEY TAuthenticate::fgBFKey;
113 Int_t TAuthenticate::fgLastError = -1;
114 Int_t TAuthenticate::fgAuthTO = -2;
117 Int_t TAuthenticate::fgProcessID = -1;
130 static
int auth_rand()
133 int frnd =
open(
"/dev/urandom", O_RDONLY);
134 if (frnd < 0) frnd =
open(
"/dev/random", O_RDONLY);
137 ssize_t rs =
read(frnd, (
void *) &r,
sizeof(
int));
140 if (rs ==
sizeof(
int))
return r;
142 Printf(
"+++ERROR+++ : auth_rand: neither /dev/urandom nor /dev/random are available or readable!");
144 if (gettimeofday(&tv,0) == 0) {
146 memcpy((
void *)&t1, (
void *)&tv.tv_sec,
sizeof(
int));
147 memcpy((
void *)&t2, (
void *)&tv.tv_usec,
sizeof(
int));
163 const char *proto,
const char *user)
165 if (
gDebug > 2 && gAuthenticateMutex)
170 if (
gROOT->IsProofServ())
187 Info(
"TAuthenticate",
"Enter: local host: %s, user is: %s (proto: %s)",
194 if (proto && strlen(proto) > 0) {
195 char *sproto =
StrDup(proto);
196 if ((pdd = strstr(sproto,
":")) != 0) {
197 int rproto = atoi(pdd + 1);
199 if (strstr(sproto,
"root") != 0) {
216 if (strstr(sproto,
"proof") != 0) {
231 Info(
"TAuthenticate",
232 "service: %s (remote protocol: %d): fVersion: %d", sproto,
242 if (user && strlen(user) > 0) {
248 checkUser = u->
fUser;
268 Info(
"TAuthenticate",
"RSA key: default type %d",
fgRSAKey);
282 fqdnsrv.
Form(
"%s:%d",fqdn.
Data(),servtype);
288 Info(
"TAuthenticate",
289 "number of HostAuth Instantiations in memory: %d",
310 Int_t nw = sscanf(tmp.
Data(),
"%5s %5s %5s %5s %5s %5s",
311 am[0], am[1], am[2], am[3], am[4], am[5]);
314 for( ; i < nw; i++) {
316 if (strlen(am[i]) > 1) {
321 if (met > -1 && met <
kMAXSEC) {
351 if (!strncmp(tmp.
Data(),
"up",2))
353 else if (!strncmp(tmp.
Data(),
"s",1))
355 else if (!strncmp(tmp.
Data(),
"k",1))
357 else if (!strncmp(tmp.
Data(),
"g",1))
359 else if (!strncmp(tmp.
Data(),
"h",1))
361 else if (!strncmp(tmp.
Data(),
"ug",2))
363 if (sec > -1 && sec <
kMAXSEC) {
389 Info(
"CatchTimeOut",
"%d sec timeout expired (protocol: %s)",
405 if (
gDebug > 2 && gAuthenticateMutex)
413 char noSupport[80] = { 0 };
414 char triedMeth[80] = { 0 };
428 alarm->SetInterruptSyscalls();
430 alarm->Connect(
"Timeout()",
"TAuthenticate",
this,
"CatchTimeOut()");
438 Info(
"Authenticate",
"try #: %d", ntry);
449 "trying authentication: method:%d, default details:%s",
453 if (strlen(triedMeth) > 0)
454 snprintf(triedMeth, 80,
"%s %s", triedMeth,
fgAuthMeth[fSecurity].
Data());
471 if (fSecurity ==
kClear) {
495 Error(
"Authenticate",
496 "unable to get user name for UsrPwd authentication");
499 }
else if (fSecurity ==
kSRP) {
533 Error(
"Authenticate",
534 "no support for SRP authentication available");
536 Error(
"Authenticate",
537 "unable to get user name for SRP authentication");
545 }
else if (fSecurity ==
kKrb5) {
562 Error(
"Authenticate",
563 "support for kerberos5 auth locally unavailable");
568 "remote daemon does not support Kerberos authentication");
569 if (strlen(noSupport) > 0)
570 snprintf(noSupport, 80,
"%s/Krb5", noSupport);
572 snprintf(noSupport, 80,
"Krb5");
575 }
else if (fSecurity ==
kGlobus) {
590 Error(
"Authenticate",
591 "no support for Globus authentication available");
596 "remote daemon does not support Globus authentication");
597 if (strlen(noSupport) > 0)
598 snprintf(noSupport, 80,
"%s/Globus", noSupport);
600 snprintf(noSupport, 80,
"Globus");
604 }
else if (fSecurity ==
kSSH) {
614 "remote daemon does not support SSH authentication");
615 if (strlen(noSupport) > 0)
616 snprintf(noSupport, 80,
"%s/SSH", noSupport);
618 snprintf(noSupport, 80,
"SSH");
621 }
else if (fSecurity ==
kRfio) {
631 "remote daemon does not support UidGid authentication");
632 if (strlen(noSupport) > 0)
633 snprintf(noSupport, 80,
"%s/UidGid", noSupport);
635 snprintf(noSupport, 80,
"UidGid");
640 if (alarm) alarm->Stop();
652 Int_t remloc = nmet - ntry;
654 Info(
"Authenticate",
"remloc: %d, ntry: %d, meth: %d, fSecurity: %d",
655 remloc, ntry, meth, fSecurity);
680 "negotiation not supported remotely: try next method, if any");
681 if (meth < nmet - 1) {
698 "after failed attempt: kind= %d, stat= %d", kind, stat);
705 char *answer =
new char[len];
714 "strings with accepted methods not received (%d:%d)",
717 sscanf(answer,
"%d %d %d %d %d %d", &rMth[0], &rMth[1],
718 &rMth[2], &rMth[3], &rMth[4], &rMth[5]);
719 if (
gDebug > 0 && remloc > 0)
721 "remotely allowed methods not yet tried: %s",
724 }
else if (stat == 0) {
726 "no more methods accepted remotely to be tried");
739 char locav[40] = { 0 };
741 for (i = 0; i < remMeth; i++) {
742 for (j = 0; j < nmet; j++) {
752 if (methfound)
break;
754 if (methfound)
break;
759 "no match with those locally available: %s", locav);
776 "method not even started: insufficient or wrong info: %s",
777 "try with next method, if any");
794 "status code -2 not expected from old daemons");
806 Info(
"Authenticate",
"got a timeout");
808 if (meth < nmet - 1) {
818 Info(
"Authenticate",
"unknown status code: %d - assume failure",st);
832 if (strlen(noSupport) > 0)
833 Info(
"Authenticate",
"attempted methods %s are not supported"
834 " by remote server version", noSupport);
836 "failure: list of attempted methods: %s", triedMeth);
861 Info(
"SetEnvironment",
862 "setting environment: fSecurity:%d, fDetails:%s",
fSecurity,
877 char pt[5] = { 0 }, ru[5] = { 0 };
878 Int_t hh = 0, mm = 0;
884 if ((ptr = strstr(
fDetails,
"pt:")) != 0) {
885 sscanf(ptr + 3,
"%4s %8191s", pt, usdef);
887 if (!strncasecmp(
gEnv->
GetValue(usrPromptDef,
""),
"no",2) ||
894 if ((ptr = strstr(
fDetails,
"ru:")) != 0) {
895 sscanf(ptr + 3,
"%4s %8191s", ru, usdef);
897 if (!strncasecmp(
gEnv->
GetValue(usrReUseDef,
""),
"no",2) ||
906 if ((pd = hours.Index(
":")) > -1) {
910 hh = atoi(hours.Data());
911 mm = atoi(minutes.
Data());
913 hh = atoi(hours.Data());
919 if ((ptr = strstr(
fDetails,
"cd:")) != 0)
920 sscanf(ptr,
"%8191s %8191s", cd, usdef);
921 if ((ptr = strstr(
fDetails,
"cf:")) != 0)
922 sscanf(ptr,
"%8191s %8191s", cf, usdef);
923 if ((ptr = strstr(
fDetails,
"kf:")) != 0)
924 sscanf(ptr,
"%8191s %8191s", kf, usdef);
925 if ((ptr = strstr(
fDetails,
"ad:")) != 0)
926 sscanf(ptr,
"%8191s %8191s", ad, usdef);
928 Info(
"SetEnvironment",
929 "details:%s, pt:%s, ru:%s, cd:%s, cf:%s, kf:%s, ad:%s",
933 if ((ptr = strstr(
fDetails,
"us:")) != 0)
934 sscanf(ptr + 3,
"%8191s %8191s", us, usdef);
935 if ((ptr = strstr(
fDetails,
"cp:")) != 0)
936 sscanf(ptr + 3,
"%8191s %8191s", cp, usdef);
938 Info(
"SetEnvironment",
"details:%s, pt:%s, ru:%s, us:%s cp:%s",
941 if ((ptr = strstr(
fDetails,
"us:")) != 0)
942 sscanf(ptr + 3,
"%8191s %8191s", us, usdef);
943 if ((ptr = strstr(
fDetails,
"pp:")) != 0)
944 sscanf(ptr + 3,
"%8191s %8191s", pp, usdef);
946 Info(
"SetEnvironment",
"details:%s, pt:%s, ru:%s, us:%s pp:%s",
949 if ((ptr = strstr(
fDetails,
"us:")) != 0)
950 sscanf(ptr + 3,
"%8191s %8191s", us, usdef);
952 Info(
"SetEnvironment",
"details:%s, pt:%s, ru:%s, us:%s",
957 if (!strncasecmp(pt,
"yes",3) || !strncmp(pt,
"1", 1))
963 if (!strncasecmp(ru,
"yes",3) || !strncmp(ru,
"1",1))
968 if (!strncasecmp(ru,
"no",2) || !strncmp(ru,
"0",1))
980 if (!strncmp(cp,
"no", 2) || !strncmp(cp,
"0", 1))
986 if (strlen(cd) > 0) { snprintf(usdef,8192,
" %s",cd); }
987 if (strlen(cf) > 0) { snprintf(usdef,8192,
"%s %s",usdef, cf); }
988 if (strlen(kf) > 0) { snprintf(usdef,8192,
"%s %s",usdef, kf); }
989 if (strlen(ad) > 0) { snprintf(usdef,8192,
"%s %s",usdef, ad); }
993 if (strlen(pp) > 0) {
997 if (strlen(us) > 0 && strstr(us,
"@"))
1004 if (strlen(us) > 0 && !strstr(us,
"@"))
1010 if (strlen(us) > 0) snprintf(usdef,
kMAXPATHLEN,
"%s", us);
1015 if (strlen(usdef) > 0) {
1016 fgDefaultUser = usdef;
1023 fgDefaultUser = u->
fUser;
1027 if (fgDefaultUser ==
"anonymous" || fgDefaultUser ==
"rootd" ||
1034 Info(
"SetEnvironment",
"usdef:%s", fgDefaultUser.Data());
1045 Info(
"GetUserPasswd",
"Enter: User: '%s' Hash:%d SRP:%d",
1065 Info(
"GetUserPasswd",
"In memory: User: '%s' Hash:%d",
1075 Info(
"GetUserPasswd",
"In memory: User: '%s' Hash:%d",
1081 if (user ==
"" || passwd ==
"") {
1083 Info(
"GetUserPasswd",
"Checking .netrc family ...");
1087 Info(
"GetUserPasswd",
"From .netrc family: User: '%s' Hash:%d",
1096 Error(
"GetUserPasswd",
"user name not set");
1116 return CheckNetrc(user, passwd, hash, srppwd);
1174 FILE *fd = fopen(net,
"r");
1176 while (fgets(line,
sizeof(line), fd) != 0) {
1180 int nword = sscanf(line,
"%63s %63s %63s %63s %63s %63s",
1181 word[0], word[1], word[2], word[3], word[4], word[5]);
1184 if (srppwd && strcmp(word[0],
"secure"))
1186 if (!srppwd && strcmp(word[0],
"machine"))
1188 if (strcmp(word[2],
"login"))
1190 if (srppwd && strcmp(word[4],
"password"))
1193 strcmp(word[4],
"password") && strcmp(word[4],
"password-hash"))
1205 if (!strcmp(word[4],
"password-hash"))
1210 if (!strcmp(word[3], user.
Data())) {
1212 if (!strcmp(word[4],
"password-hash"))
1223 "file %s exists but has not 0600 permission", net);
1227 if (first && !srppwd && !result) {
1307 if (idx < 0 || idx >
kMAXSEC-1) {
1308 ::Error(
"Authenticate::GetAuthMethod",
"idx out of bounds (%d)", idx);
1322 if (meth && meth[0]) {
1351 if (isatty(0) == 0 || isatty(1) == 0) {
1353 "not tty: cannot prompt for user, returning default");
1360 const char *usrIn = Getline(
Form(
"Name (%s:%s): ", remote, user));
1380 if (isatty(0) == 0 || isatty(1) == 0) {
1381 ::Warning(
"TAuthenticate::PromptPasswd",
1382 "not tty: cannot prompt for passwd, returning -1");
1383 static char noint[4] = {
"-1"};
1388 const char *pw = buf;
1393 gROOT->GetPluginManager()->FindHandler(
"TGPasswdDialog"))) {
1397 "could not load plugin for the password dialog box");
1407 while (
gROOT->IsInterrupted())
1411 Gl_config(
"noecho", 1);
1412 pw = Getline(prompt);
1413 Gl_config(
"noecho", 0);
1440 key = (key >= 0 && key <= 1) ? key : 0;
1457 if (key >= 0 && key <= 1)
1502 err = (err < kErrError) ? ((err > -1) ? err : -1) :
kErrError;
1510 lasterr =
"(last error only; re-run with gDebug > 0 for more details)";
1514 if (
gDebug > 0 || forceprint) {
1516 ::Error(
Form(
"TAuthenticate::%s", where),
"%s %s",
1520 "unknown error code: server must be running a newer ROOT version %s",
1538 if (user && user[0])
1552 if (passwd && passwd[0])
1598 if (defaultuser && defaultuser[0])
1663 FILE *
ferr = fopen(errorfile,
"r");
1668 Int_t lerr = strlen(serr);
1669 char *pc = (
char *)memchr(serr,
'"',lerr);
1672 pc = (
char *)memchr(pc+1,
'"',strlen(pc+1));
1676 while (fgets(line,
sizeof(line),
ferr)) {
1678 if (line[strlen(line)-1] ==
'\n')
1679 line[strlen(line)-1] =
'\0';
1681 Info(
"SshError",
"read line: %s",line);
1683 while (pc < serr + lerr) {
1684 if (pc[0] ==
'\0' || pc[0] ==
' ')
1688 Info(
"SshError",
"checking error: '%s'",pc);
1689 if (strstr(line,pc))
1698 if (serr)
delete [] serr;
1713 if (
gROOT->IsProofServ()) {
1716 Info(
"SshAuth",
"SSH protocol is switched OFF by default"
1717 " for PROOF servers: use 'ProofServ.UseSSH 1'"
1718 " to enable it (see system.rootrc)");
1728 char cmdref[2][5] = {
"ssh",
"scp"};
1733 while (notfound && sshproto > -1) {
1735 strlcpy(scmd,cmdref[sshproto],5);
1744 Info(
"SshAuth",
"%s not found in $PATH", scmd);
1747 if (strcmp(
gEnv->
GetValue(
"SSH.ExecDir",
"-1"),
"-1")) {
1749 Info(
"SshAuth",
"searching user defined path ...");
1753 Info(
"SshAuth",
"%s not executable", sshExe.
Data());
1759 if (notfound) sshproto--;
1767 Info(
"SshAuth",
"%s is %s (sshproto: %d)", scmd, sshExe.
Data(), sshproto);
1790 options.
Form(
"%d none %ld %s %d", opt,
1795 Int_t retval = reuse;
1830 Info(
"SshAuth",
"received from server command info: %s", cmdinfo);
1836 while (ci.Tokenize(tkn, from,
" ")) {
1837 if (from > 0) cmdinfo[from-1] =
'\0';
1851 if (isatty(0) == 0 || isatty(1) == 0) {
1852 noPrompt =
TString(
"-o 'PasswordAuthentication no' ");
1853 noPrompt +=
TString(
"-o 'StrictHostKeyChecking no' ");
1855 Info(
"SshAuth",
"using noprompt options: %s", noPrompt.
Data());
1867 if (sshproto == 0) {
1869 fileErr =
"rootsshtmp_";
1873 fileErr =
"rootsshtmp_";
1877 fileErr.
Append(
".error");
1879 sshcmd.
Form(
"%s -x -l %s %s", sshExe.
Data(), user.
Data(), noPrompt.
Data());
1887 while (ssh_rc && again && ntry--) {
1892 Info(
"SshAuth",
"%d: sleeping: rc: %d, again:%d, ntry: %d",
1907 TString fileLoc =
"rootsshtmp_";
1911 fileLoc =
"rootsshtmp_";
1918 if (chmod(fileLoc, 0600) == -1) {
1919 Info(
"SshAuth",
"fchmod error: %d", errno);
1922 floc = fopen(fileLoc,
"w");
1926 fprintf(floc,
"k: %d\n",
fRSAKey+1);
1934 fprintf(floc,
"k: -1\n");
1941 sshcmd.
Form(
"%s -p %s", sshExe.
Data(), noPrompt.
Data());
1955 while (ssh_rc && again && ntry--) {
1960 Info(
"SshAuth",
"%d: sleeping: rc: %d, again:%d, ntry: %d",
1982 Info(
"SshAuth",
"%d: system return code: %d (%d)",
1985 if (ssh_rc && sshproto == 0) {
2010 newsock->
Send(
"failure notification");
2013 char cd1[1024], pipe[1024], dum[1024];
2015 sscanf(cmdinfo,
"%1023s %d %1023s %1023s", cd1, &id3, pipe, dum);
2016 snprintf(secName,
kMAXPATHLEN,
"%d -1 0 %s %d %s %d",
2023 if (newsock->
Recv(retval, kind) >= 0) {
2024 char *buf =
new char[retval+1];
2025 if (newsock->
Recv(buf, retval+1, kind) >= 0) {
2026 if (strncmp(buf,
"OK",2)) {
2028 Info(
"SshAuth",
">> nothing listening on port %s %s",buf,
2029 "(supposed to be associated to sshd)");
2030 Info(
"SshAuth",
">> contact the daemon administrator at %s",
2035 Info(
"SshAuth",
">> something listening on the port"
2036 " supposed to be associated to sshd.");
2037 Info(
"SshAuth",
">> You have probably mistyped your"
2038 " password. Or you tried to hack the"
2040 Info(
"SshAuth",
">> If the problem persists you may"
2041 " consider contacting the daemon");
2057 }
else if (ssh_rc && sshproto > 0) {
2060 Info(
"SshAuth",
"error communicating failure");
2067 Info(
"SshAuth",
"error communicating success");
2075 Info(
"SshAuth",
"got message %d, flag: %d", kind, retval);
2083 if (reuse == 1 && sshproto == 0) {
2088 "problems recvn RSA key flag: got message %d, flag: %d",
2103 Info(
"SshAuth",
"got message %d, flag: %d", kind, retval);
2108 "problems recvn (user,offset) length (%d:%d bytes:%d)", kind,
2114 reclen = (retval+1 > 256) ? 256 : retval+1;
2115 if ((nrec =
fSocket->
Recv(answer, reclen, kind)) < 0)
2118 Warning(
"SshAuth",
"username and offset not received (%d:%d)", kind,
2124 sscanf(answer,
"%127s %d", lUser, &offset);
2126 Info(
"SshAuth",
"received from server: user: %s, offset: %d", lUser,
2131 if (reuse == 1 && offset > -1) {
2133 Warning(
"SshAuth",
"problems secure-receiving token -"
2134 " may result in corrupted token");
2139 Info(
"SshAuth",
"received from server: token: '%s' ", token);
2150 if (token)
delete [] token;
2156 Info(
"SshAuth",
"received from server: kind: %d, retval: %d", kind,
2214 if (!strcmp(href,
"*"))
2223 if (rename.
Index(href,&len) != -1 || strstr(href,
"-"))
2228 if (strstr(href,
"*"))
2240 ::Info(
"TAuthenticate::CheckHost",
"checking host IP: %s", theHost.
Data());
2251 if (pos > 0 && pos != (
Ssiz_t)(theHost.
Length()-strlen(href)))
2267 Info(
"RfioAuth",
"enter ... username %s", username.
Data());
2274 username = pw->fUser;
2278 if (pw->fUid != 0) {
2291 Info(
"RfioAuth",
"sending ... %s", sstr.
Data());
2296 Info(
"RfioAuth",
"sent ... %d bytes (expected > %d)", ns,
2304 Info(
"RfioAuth",
"after kROOTD_RFIO: kind= %d, stat= %d", kind,
2326 "%s@%s does not accept connections from %s%s",
2334 "%s@%s does not accept %s authentication from %s@%s",
2336 TAuthenticate::fgAuthMeth[5].
Data(),
2345 Warning(
"RfioAuth",
"UidGid login as \"root\" not allowed");
2362 Info(
"ClearAuth",
"enter: user: %s (passwd hashed?: %d)",
2374 Info(
"ClearAuth",
"ru:%d pt:%d cp:%d ns:%d rk:%d",
2403 options.
Form(
"%d %ld %s %ld %s", opt,
2425 Info(
"ClearAuth",
"anonymous user");
2434 char ctag[11] = {0};
2435 if (anon == 0 && cryptopt == 1) {
2442 "problems recvn RSA key flag: got message %d, flag: %d",
2448 Info(
"ClearAuth",
"get key request ...");
2462 Warning(
"ClearAuth",
"problems secure-receiving salt -"
2463 " may result in corrupted salt");
2464 Warning(
"ClearAuth",
"switch off reuse for this session");
2472 while (ltmp && tmpsalt[ltmp-1] !=
'#') ltmp--;
2474 if (tmpsalt[ltmp-1] ==
'#' &&
2475 tmpsalt[ltmp-10] ==
'#') {
2476 strlcpy(ctag,&tmpsalt[ltmp-10],11);
2495 Info(
"ClearAuth",
"got salt: '%s' (len: %d)", salt.
Data(), slen);
2498 Info(
"ClearAuth",
"Salt not required");
2501 Warning(
"ClearAuth",
"problems secure-receiving rndmtag -"
2502 " may result in corrupted rndmtag");
2505 strlcpy(ctag, tmptag, 11);
2531 if (localFQDN ==
"") {
2536 passwd.
Form(
"%s@%s", localuser.
Data(), localFQDN.
Data());
2539 "automatically generated anonymous passwd: %s",
2545 if (prompt == 1 || pashash.
Length() == 0) {
2554 Error(
"ClearAuth",
"password not set");
2559 if (needsalt && !pwdhash) {
2561 pashash =
TString(crypt(passwd, salt));
2587 if (anon == 0 && cryptopt == 1) {
2599 Warning(
"ClearAuth",
"problems secure-sending pass hash"
2600 " - may result in authentication failure");
2607 for (
int i = 0; i < passwd.
Length(); i++) {
2608 char inv = ~passwd(i);
2621 Info(
"ClearAuth",
"after kROOTD_PASS: kind= %d, stat= %d", kind,
2633 "problems recvn (user,offset) length (%d:%d bytes:%d)",
2638 int reclen = (stat+1 > 256) ? 256 : stat+1;
2639 if ((nrec =
fSocket->
Recv(answer, reclen, kind)) < 0)
2643 "username and offset not received (%d:%d)", kind,
2649 sscanf(answer,
"%127s %d", lUser, &offset);
2652 "received from server: user: %s, offset: %d (%s)", lUser,
2659 if (reuse == 1 && offset > -1) {
2661 if (cryptopt == 1) {
2664 "problems secure-receiving token -"
2665 " may result in corrupted token");
2670 token =
new char[tlen];
2676 Warning(
"ClearAuth",
"token not received (%d:%d)", kind,
2679 for (
int i = 0; i < (int) strlen(token); i++) {
2680 token[i] = ~token[i];
2685 Info(
"ClearAuth",
"received from server: token: '%s' ",
2747 "%s@%s does not accept connections from %s@%s",
2754 "%s@%s does not accept %s authentication from %s@%s",
2756 TAuthenticate::fgAuthMeth[0].
Data(),
2771 Error(
"ClearAuth",
"password not set");
2773 if (
fUser ==
"anonymous" ||
fUser ==
"rootd") {
2776 "please use passwd of form: user@host.do.main");
2787 for (
int i = 0; i < passwd.
Length(); i++) {
2788 char inv = ~passwd(i);
2800 Info(
"ClearAuth",
"after kROOTD_PASS: kind= %d, stat= %d", kind,
2829 ::Info(
"TAuthenticate::GetHostAuth",
"enter ... %s ... %s", host, user);
2835 char *ps = (
char *)strstr(host,
":");
2837 srvtyp = atoi(ps+1);
2841 if (strncmp(host,
"default",7) && !hostFQDN.
Contains(
"*")) {
2853 if (!strncasecmp(opt,
"P",1)) {
2861 while ((ai = (
THostAuth *) (*next)())) {
2863 ai->
Print(
"Authenticate::GetHostAuth");
2866 if (!(serverOK = (ai->
GetServer() == -1) ||
2871 if (!strcmp(ai->
GetHost(),
"default") && serverOK && notFound)
2881 if (hostFQDN == ai->
GetHost() &&
2903 ::Info(
"TAuthenticate::HasHostAuth",
"enter ... %s ... %s", host, user);
2909 char *ps = (
char *)strstr(host,
":");
2911 srvtyp = atoi(ps+1);
2914 if (strncmp(host,
"default",7) && !hostFQDN.
Contains(
"*")) {
2921 if (!strncasecmp(opt,
"P",1)) {
2926 while ((ai = (
THostAuth *) (*next)())) {
2928 if (hostFQDN == ai->
GetHost() &&
2950 ::Info(
"TAuthenticate::FileExpand",
"enter ... '%s' ... 0x%lx", fexp, (
Long_t)ftmp);
2952 fin = fopen(fexp,
"r");
2956 while (fgets(line,
sizeof(line), fin) != 0) {
2960 if (line[strlen(line) - 1] ==
'\n')
2961 line[strlen(line) - 1] =
'\0';
2963 ::Info(
"TAuthenticate::FileExpand",
"read line ... '%s'", line);
2964 int nw = sscanf(line,
"%19s %8191s", cinc, fileinc);
2967 if (strcmp(cinc,
"include") != 0) {
2969 fprintf(ftmp,
"%s\n", line);
2976 sscanf(ln.
Data(),
"%19s %8191s", cinc, fileinc);
2979 if (fileinc[0] ==
'$') {
2996 if (fileinc[0] ==
'~') {
3000 char *ffull =
new char[flen];
3010 "file specified by 'include' cannot be open or read (%s)",
3025 const char copt[2][5] = {
"no",
"yes" };
3028 ::Info(
"TAuthenticate::GetDefaultDetails",
3029 "enter ... %d ...pt:%d ... '%s'", sec, opt, usr);
3031 if (opt < 0 || opt > 1)
3036 if (!usr[0] || !strncmp(usr,
"*",1))
3038 snprintf(temp,
kMAXPATHLEN,
"pt:%s ru:%s cp:%s us:%s",
3045 if (!usr[0] || !strncmp(usr,
"*",1))
3053 if (!usr[0] || !strncmp(usr,
"*",1))
3068 if (!usr[0] || !strncmp(usr,
"*",1))
3076 if (!usr[0] || !strncmp(usr,
"*",1))
3082 ::Info(
"TAuthenticate::GetDefaultDetails",
"returning ... %s", temp);
3092 if (!strncasecmp(opt,
"P",1))
3121 " +--------------------------- BEGIN --------------------------------+");
3126 " + List fgProofAuthInfo has %4d members +",
3131 " +------------------------------------------------------------------+");
3139 " + List fgAuthInfo has %4d members +",
3144 " +------------------------------------------------------------------+");
3153 " +---------------------------- END ---------------------------------+");
3169 Info(
"AuthExists",
"%d: enter: msg: %d options: '%s'",
3170 method,*message, options);
3179 if (secctx->GetMethod() == method) {
3180 if (
fRemote == secctx->GetHost()) {
3182 (*checksecctx)(
username,secctx) == 1)
3192 if (secctx->GetMethod() == method) {
3193 if (
fRemote == secctx->GetHost()) {
3195 (*checksecctx)(
username,secctx) == 1) {
3208 offset = secctx->GetOffSet();
3209 token = secctx->GetToken();
3212 "found valid TSecContext: offset: %d token: '%s'",
3213 offset, token.
Data());
3224 Int_t reuse = *rflag;
3225 if (reuse == 1 && offset > -1) {
3234 Int_t stat = 1, kind;
3239 Warning(
"AuthExists",
"protocol error: expecting %d got %d"
3245 Info(
"AuthExists",
"offset OK");
3247 Int_t rsaKey = secctx->GetRSAKey();
3249 Info(
"AuthExists",
"key type: %d", rsaKey);
3258 snprintf(tag, 9,
"%08x",stat);
3265 Warning(
"AuthExists",
"problems secure-sending token %s",
3266 "- may trigger problems in proofing Id ");
3271 for (
int i = 0; i < token.
Length(); i++) {
3272 char inv = ~token(i);
3280 Info(
"AuthExists",
"offset not OK - rerun authentication");
3283 secctx->DeActivate(
"");
3291 Info(
"AuthExists",
"%d: after msg %d: kind= %d, stat= %d",
3292 method,*message, kind, stat);
3305 Error(
"AuthExists",
"%s@%s does not accept connections from %s@%s",
3311 "%s@%s does not accept %s authentication from %s@%s",
3319 secctx->DeActivate(
"");
3329 Info(
"AuthExists",
"valid authentication exists");
3331 Info(
"AuthExists",
"valid authentication exists: offset changed");
3333 Info(
"AuthExists",
"remote access authorized by /etc/hosts.equiv");
3335 Info(
"AuthExists",
"no authentication required remotely");
3344 secctx->SetOffSet(newOffSet);
3365 const char *randdev =
"/dev/urandom";
3368 if ((fd =
open(randdev, O_RDONLY)) != -1) {
3370 ::Info(
"InitRandom",
"taking seed from %s", randdev);
3371 if (
read(fd, &seed,
sizeof(seed)) !=
sizeof(seed))
3372 ::Warning(
"InitRandom",
"could not read seed from %s", randdev);
3376 ::Info(
"InitRandom",
"%s not available: using time()", randdev);
3391 Info(
"GenRSAKeys",
"enter");
3395 Info(
"GenRSAKeys",
"Keys prviously generated - return");
3417 Info(
"GenRSAKeys",
"SSL: Generate Blowfish key");
3426 OpenSSL_add_all_ciphers();
3432 nbits = (nbits >= 128) ? nbits : 128;
3435 nbits = (nbits <= 15912) ? nbits : 15912;
3438 Int_t klen = nbits / 8 ;
3442 RAND_seed(rbuf,strlen(rbuf));
3451 BF_set_key(&fgBFKey, klen, (
const unsigned char *)rbuf);
3460 Int_t l_n = 0, l_d = 0;
3467 Int_t nAttempts = 0;
3473 if (
gDebug > 2 && nAttempts > 1) {
3474 Info(
"GenRSAKeys",
"retry no. %d",nAttempts);
3487 Info(
"GenRSAKeys",
"equal primes: regenerate (%d times)",nPrimes);
3495 Info(
"GenRSAKeys",
"local: p1: '%s' ", buf);
3497 Info(
"GenRSAKeys",
"local: p2: '%s' ", buf);
3502 if (
gDebug > 2 && nAttempts > 1)
3503 Info(
"GenRSAKeys",
" genrsa: unable to generate keys (%d)",
3510 l_n = strlen(buf_n);
3513 l_e = strlen(buf_e);
3516 l_d = strlen(buf_d);
3520 Info(
"GenRSAKeys",
"local: n: '%s' length: %d", buf_n, l_n);
3521 Info(
"GenRSAKeys",
"local: e: '%s' length: %d", buf_e, l_e);
3522 Info(
"GenRSAKeys",
"local: d: '%s' length: %d", buf_d, l_d);
3531 char test[2 *
rsa_STRLEN] =
"ThisIsTheStringTest01203456-+/";
3534 strlcpy(test, tdum, lTes+1);
3538 Info(
"GenRSAKeys",
"local: test string: '%s' ", test);
3541 strlcpy(buf, test, lTes+1);
3547 "local: length of crypted string: %d bytes", lout);
3553 Info(
"GenRSAKeys",
"local: after private/public : '%s' ", buf);
3555 if (strncmp(test, buf, lTes))
3559 strlcpy(buf, test, lTes+1);
3564 Info(
"GenRSAKeys",
"local: length of crypted string: %d bytes ",
3571 Info(
"GenRSAKeys",
"local: after public/private : '%s' ", buf);
3573 if (strncmp(test, buf, lTes))
3590 Info(
"GenRSAKeys",
"local: generated keys are:");
3591 Info(
"GenRSAKeys",
"local: n: '%s' length: %d", buf_n, l_n);
3592 Info(
"GenRSAKeys",
"local: e: '%s' length: %d", buf_e, l_e);
3593 Info(
"GenRSAKeys",
"local: d: '%s' length: %d", buf_d, l_d);
3604 fgRSAPubExport[0].keys[0] =
'#';
3605 memcpy(fgRSAPubExport[0].keys + 1, buf_n, l_n);
3606 fgRSAPubExport[0].keys[l_n + 1] =
'#';
3607 memcpy(fgRSAPubExport[0].keys + l_n + 2, buf_d, l_d);
3608 fgRSAPubExport[0].keys[l_n + l_d + 2] =
'#';
3609 fgRSAPubExport[0].keys[l_n + l_d + 3] = 0;
3612 Info(
"GenRSAKeys",
"local: export pub: '%s'", fgRSAPubExport[0].keys);
3615 Info(
"GenRSAKeys",
"local: export pub length: %d bytes", fgRSAPubExport[0].len);
3634 unsigned int iimx[4][4] = {
3635 {0x0, 0xffffff08, 0xafffffff, 0x2ffffffe},
3636 {0x0, 0x3ff0000, 0x7fffffe, 0x7fffffe},
3637 {0x0, 0x3ff0000, 0x7e, 0x7e},
3638 {0x0, 0x3ffc000, 0x7fffffe, 0x7fffffe}
3641 const char *cOpt[4] = {
"Any",
"LetNum",
"Hex",
"Crypt" };
3644 if (opt < 0 || opt > 2) {
3647 Info(
"GetRandString",
"unknown option: %d : assume 0", opt);
3650 Info(
"GetRandString",
"enter ... len: %d %s", len, cOpt[opt]);
3653 char *buf =
new char[len + 1];
3663 for (m = 7; m < 32; m += 7) {
3664 i = 0x7F & (frnd >>
m);
3667 if ((iimx[opt][j] & (1 << l))) {
3679 Info(
"GetRandString",
"got '%s' ", buf);
3691 Int_t key,
const char *str)
3697 ::Info(
"TAuthenticate::SecureSend",
"local: enter ... (enc: %d)", enc);
3699 Int_t slen = strlen(str) + 1;
3704 strlcpy(buftmp, str, slen+1);
3714 }
else if (key == 1) {
3719 ttmp = ((ttmp + 8)/8) * 8;
3720 unsigned char iv[8];
3721 memset((
void *)&iv[0],0,8);
3722 BF_cbc_encrypt((
const unsigned char *)str, (
unsigned char *)buftmp,
3723 strlen(str), &fgBFKey, iv, BF_ENCRYPT);
3726 ::Info(
"TAuthenticate::SecureSend",
"not compiled with SSL support:"
3727 " you should not have got here!");
3731 ::Info(
"TAuthenticate::SecureSend",
"unknown key type (%d)",key);
3735 snprintf(buflen,20,
"%d",ttmp);
3738 nsen = sock->
SendRaw(buftmp, ttmp);
3740 ::Info(
"TAuthenticate::SecureSend",
3741 "local: sent %d bytes (expected: %d)", nsen,ttmp);
3763 if (sock->
Recv(buflen, 20, kind) < 0)
3765 Int_t len = atoi(buflen);
3767 ::Info(
"TAuthenticate::SecureRecv",
"got len '%s' %d (msg kind: %d)",
3772 if (!strncmp(buflen,
"-1", 2))
3776 if ((nrec = sock->
RecvRaw(buftmp, len)) < 0)
3787 const size_t strSize = strlen(buftmp) + 1;
3788 *str =
new char[strSize];
3789 strlcpy(*str, buftmp, strSize);
3791 }
else if (key == 1) {
3793 unsigned char iv[8];
3794 memset((
void *)&iv[0],0,8);
3795 *str =
new char[nrec + 1];
3796 BF_cbc_encrypt((
const unsigned char *)buftmp, (
unsigned char *)(*str),
3797 nrec, &fgBFKey, iv, BF_DECRYPT);
3798 (*str)[nrec] =
'\0';
3801 ::Info(
"TAuthenticate::SecureRecv",
"not compiled with SSL support:"
3802 " you should not have got here!");
3806 ::Info(
"TAuthenticate::SecureRecv",
"unknown key type (%d)",key);
3825 ::Info(
"TAuthenticate::DecodeRSAPublic",
3826 "enter: string length: %ld bytes", (
Long_t)strlen(rsaPubExport));
3829 Int_t klen = strlen(rsaPubExport);
3831 ::Info(
"TAuthenticate::DecodeRSAPublic",
3832 "key too long (%d): truncate to %d",klen,
kMAXPATHLEN);
3835 memcpy(str, rsaPubExport, klen);
3844 while (str[k] == 32) k++;
3846 if (str[k] ==
'#') {
3851 char *pd1 = strstr(str,
"#");
3852 char *pd2 = pd1 ? strstr(pd1 + 1,
"#") : (
char *)0;
3853 char *pd3 = pd2 ? strstr(pd2 + 1,
"#") : (
char *)0;
3854 if (pd1 && pd2 && pd3) {
3856 int l1 = (int) (pd2 - pd1 - 1);
3857 char *rsa_n_exp =
new char[l1 + 1];
3858 strlcpy(rsa_n_exp, pd1 + 1, l1+1);
3860 ::Info(
"TAuthenticate::DecodeRSAPublic",
3861 "got %ld bytes for rsa_n_exp", (
Long_t)strlen(rsa_n_exp));
3863 int l2 = (int) (pd3 - pd2 - 1);
3864 char *rsa_d_exp =
new char[l2 + 1];
3865 strlcpy(rsa_d_exp, pd2 + 1, 13);
3867 ::Info(
"TAuthenticate::DecodeRSAPublic",
3868 "got %ld bytes for rsa_d_exp", (
Long_t)strlen(rsa_d_exp));
3874 if (rsa_n_exp)
delete[] rsa_n_exp;
3876 if (rsa_d_exp)
delete[] rsa_d_exp;
3879 ::Info(
"TAuthenticate::DecodeRSAPublic",
"bad format for input string");
3888 BIO *bpub = BIO_new(BIO_s_mem());
3891 BIO_write(bpub,(
void *)str,strlen(str));
3894 if (!(rsatmp = PEM_read_bio_RSAPublicKey(bpub, 0, 0, 0))) {
3896 ::Info(
"TAuthenticate::DecodeRSAPublic",
3897 "unable to read pub key from bio");
3900 *rsassl = (
char *)rsatmp;
3902 ::Info(
"TAuthenticate::DecodeRSAPublic",
3903 "no space allocated for output variable");
3910 ::Info(
"TAuthenticate::DecodeRSAPublic",
"not compiled with SSL support:"
3911 " you should not have got here!");
3926 ::Info(
"TAuthenticate::SetRSAPublic",
3927 "enter: string length %ld bytes", (
Long_t)strlen(rsaPubExport));
3937 while (rsaPubExport[k0] == 32) k0++;
3946 if (rsaPubExport[k0] ==
'#' && rsaPubExport[k2] ==
'#') {
3947 char *p0 = (
char *)&rsaPubExport[k0];
3948 char *
p2 = (
char *)&rsaPubExport[k2];
3949 char *
p1 = strchr(p0+1,
'#');
3950 if (p1 > p0 && p1 < p2) {
3956 while (c < p1 && ((*c < 58 && *c > 47) || (*c < 91 && *c > 64)))
3960 while (c < p2 && ((*c < 58 && *c > 47) || (*c < 91 && *c > 64)))
3969 ::Info(
"TAuthenticate::SetRSAPublic",
" Key type: %d",rsakey);
3984 BF_set_key(&fgBFKey, klen, (
const unsigned char *)rsaPubExport);
3987 ::Info(
"TAuthenticate::SetRSAPublic",
3988 "not compiled with SSL support:"
3989 " you should not have got here!");
4009 ::Info(
"TAuthenticate::SendRSAPublicKey",
4010 "received key from server %ld bytes", (
Long_t)strlen(serverPubKey));
4019 RSA_free((RSA *)tmprsa);
4022 RSA *RSASSLServer = (RSA *)tmprsa;
4030 char buflen[20] = {0};
4036 snprintf(buflen, 20,
"%d", ttmp);
4037 }
else if (key == 1) {
4039 Int_t lcmax = RSA_size(RSASSLServer) - 11;
4044 Int_t lc = (ns > lcmax) ? lcmax : ns ;
4045 if ((ttmp = RSA_public_encrypt(lc,
4047 (
unsigned char *)&buftmp[ke],
4048 RSASSLServer,RSA_PKCS1_PADDING)) < 0) {
4051 ::Info(
"TAuthenticate::SendRSAPublicKey",
"SSL: error: '%s' ",errstr);
4058 snprintf(buflen, 20,
"%d", ttmp);
4061 ::Info(
"TAuthenticate::SendRSAPublicKey",
"not compiled with SSL support:"
4062 " you should not have got here!");
4067 ::Info(
"TAuthenticate::SendRSAPublicKey",
"unknown key type (%d)",key);
4070 RSA_free(RSASSLServer);
4081 ::Info(
"TAuthenticate::SendRSAPublicKey",
4082 "local: sent %d bytes (expected: %d)", nsen,ttmp);
4085 RSA_free(RSASSLServer);
4106 if (authrc &&
gDebug > 2)
4107 ::Info(
"TAuthenticate::ReadRootAuthrc",
"Checking file: %s", authrc);
4109 if (authrc &&
gDebug > 1)
4110 ::Info(
"TAuthenticate::ReadRootAuthrc",
4111 "file %s cannot be read (errno: %d)", authrc, errno);
4118 snprintf(etc, 1024,
"%s\\etc",
gRootDir);
4120 snprintf(etc, 1024,
"%s/etc",
gRootDir);
4125 ::Info(
"TAuthenticate::ReadRootAuthrc",
"Checking system file:%s",authrc);
4128 ::Info(
"TAuthenticate::ReadRootAuthrc",
4129 "file %s cannot be read (errno: %d)", authrc, errno);
4139 stat(tRootAuthrc, &si);
4142 ::Info(
"TAuthenticate::ReadRootAuthrc",
4143 "file %s already read", authrc);
4159 TString filetmp =
"rootauthrc";
4162 ::Info(
"TAuthenticate::ReadRootAuthrc",
"got tmp file: %s open at 0x%lx",
4175 fd = fopen(authrc,
"r");
4178 ::Info(
"TAuthenticate::ReadRootAuthrc",
4179 "file %s cannot be open (errno: %d)", authrc, errno);
4190 while (fgets(line,
sizeof(line), fd) != 0) {
4197 if (line[strlen(line) - 1] ==
'\n')
4198 line[strlen(line) - 1] =
'\0';
4205 const size_t tmpSize = strlen(line) + 1;
4206 char *tmp =
new char[tmpSize];
4208 ::Error(
"TAuthenticate::ReadRootAuthrc",
4209 "could not allocate temporary buffer");
4212 strlcpy(tmp, line, tmpSize);
4213 char *nxt = strtok(tmp,
" ");
4215 if (!strcmp(nxt,
"proofserv") || cont) {
4225 proofserv +=
TString((
const char *)ph);
4246 if (server ==
"0" || server.
BeginsWith(
"sock"))
4248 else if (server ==
"1" || server.
BeginsWith(
"root"))
4250 else if (server ==
"2" || server.
BeginsWith(
"proof"))
4257 nxt = strtok(0,
" ");
4258 if (!strncmp(nxt,
"user",4)) {
4259 nxt = strtok(0,
" ");
4260 if (strncmp(nxt,
"list",4) && strncmp(nxt,
"method",6)) {
4262 nxt = strtok(0,
" ");
4277 tmpAuthInfo.
Add(ha);
4280 if (!strncmp(nxt,
"list",4)) {
4283 char *mth = strtok(0,
" ");
4286 if (strlen(mth) > 1) {
4289 if (met == -1 &&
gDebug > 2)
4290 ::Info(
"TAuthenticate::ReadRootAuthrc",
4291 "unrecognized method (%s): ", mth);
4295 if (met > -1 && met <
kMAXSEC)
4297 mth = strtok(0,
" ");
4302 }
else if (!strncmp(nxt,
"method",6)) {
4305 char *mth = strtok(0,
" ");
4307 if (strlen(mth) > 1) {
4310 if (met == -1 &&
gDebug > 2)
4311 ::Info(
"TAuthenticate::ReadRootAuthrc",
4312 "unrecognized method (%s): ", mth);
4316 if (met > -1 && met <
kMAXSEC) {
4317 const char *det = 0;
4318 nxt = strtok(0,
" ");
4320 det = (
const char *)strstr(line,nxt);
4329 if (tmp)
delete [] tmp;
4347 TList tmpproofauthinfo;
4348 if (proofserv.
Length() > 0) {
4349 char *tmps =
new char[proofserv.
Length()+1];
4350 strlcpy(tmps,proofserv.
Data(),proofserv.
Length()+1);
4351 char *nxt = strtok(tmps,
" ");
4353 TString tmp((
const char *)nxt);
4357 if ((pdd = tmp.
Index(
":")) == -1) {
4368 if ((pdd = tmp.
Index(
":")) == -1) {
4380 while (tmp.
Length() > 0) {
4382 if ((pdd = tmp.
Index(
":")) > -1)
4387 if (met == -1 &&
gDebug > 2)
4388 ::Info(
"TAuthenticate::ReadRootAuthrc",
4389 "unrecognized method (%s): ",meth.
Data());
4390 }
else if (meth.
Length() == 1) {
4391 met = atoi(meth.
Data());
4392 if (met > -1 && met <
kMAXSEC)
4415 tmpproofauthinfo.
Add(ha);
4417 nxt = strtok(0,
" ");
4437 const char sshid[3][20] = {
"/.ssh/identity",
"/.ssh/id_dsa",
"/.ssh/id_rsa" };
4438 const char netrc[2][20] = {
"/.netrc",
"/.rootnetrc" };
4448 "not properly logged on (getpwuid unable to find relevant info)!");
4456 for (; i < 2; i++) {
4462 out.
Form(
"pt:0 ru:1 us:%s",user.
Data());
4468 out.
Form(
"pt:0 ru:1 us:%s",user.
Data());
4476 out.
Form(
"pt:0 ru:0 us:%s",user.
Data());
4485 if (lApp != 0 && lApp->
Argc() > 9) {
4486 if (
gROOT->IsProofServ()) {
4493 struct shmid_ds shm_ds;
4494 if (shmctl(ShmId, IPC_STAT, &shm_ds) == 0)
4506 Cdir.
Resize(Cdir.Last(
'/')+1);
4508 out.
Form(
"pt=0 ru:0 cd:%s cf:%s kf:%s ad:%s",
4509 Cdir.Data(),Ucer.Data(),Ukey.Data(),Adir.Data());
4519 for (; i < 3; i++) {
4525 out.
Form(
"pt:0 ru:1 us:%s",user.
Data());
4530 out.
Form(
"pt:0 ru:0 us:%s",user.
Data());
4535 if (strlen(out) > 0)
4536 ::
Info(
"CheckProofAuth",
4537 "meth: %d ... is available: details: %s", cSec, out.
Data());
4540 "meth: %d ... is NOT available", cSec);
4558 if (!strcmp(user,ctx->
GetUser()) &&
4559 strncmp(
"AFS", ctx->
GetID(), 3))
4589 while ((hanew = (
THostAuth *)nxnew())) {
4611 while ((hanew = (
THostAuth *)nxnew())) {
4675 Info(
"ProofAuthSetup",
"Buffer not found: nothing to do");
4689 *mess >> user >> passwd >> pwhash >> srppwd >> rsakey;
4707 Info(
"ProofAuthSetup",
"List of THostAuth not found");
4728 fromProofAI =
kTRUE;
4739 if (!master || fromProofAI) {
4803 if (remoteOffSet > -1 && (upwd || srp))
4807 if ((
gEnv->
GetValue(
"Proofd.SendSRPPwd",0)) && (remoteOffSet > -1))
4810 if (srp && pwdctx) {
4811 if (strcmp(pwdctx->
GetPasswd(),
"") && remoteOffSet > -1)
4816 if ((upwd && pwdctx) || (srp && sndsrp)) {
4827 mess << user << passwd << pwhash << srppwd << keytyp;
4833 char *mbuf = mess.
Buffer();
4838 ::Info(
"ProofAuthSetup",
"sending %d bytes", messb64.
Length());
4841 if (remoteOffSet > -1) {
4843 ::Error(
"ProofAuthSetup",
"problems secure-sending message buffer");
4849 snprintf(buflen,20,
"%d", messb64.
Length());
4851 ::Error(
"ProofAuthSetup",
"plain: problems sending message length");
4855 ::Error(
"ProofAuthSetup",
"problems sending message buffer");
4888 Int_t retval = 0, ns = 0;
4891 Error(
"SendHostAuth",
"invalid input: socket undefined");
4906 Info(
"SendHostAuth",
"sent %d bytes (%s)",ns,buf.
Data());
4913 Info(
"SendHostAuth",
"sent %d bytes for closing",ns);
4927 Error(
"RecvHostAuth",
"invalid input: socket undefined");
4942 Error(
"RecvHostAuth",
"received: kind: %d (%d bytes)", kind, nr);
4946 Info(
"RecvHostAuth",
"received %d bytes (%s)",nr,buf);
4948 while (strcmp(buf,
"END")) {
4968 fromProofAI =
kTRUE;
4979 if (!master || fromProofAI) {
5018 Info(
"RecvHostAuth",
"Error: received: kind: %d (%d bytes)", kind, nr);
5022 Info(
"RecvHostAuth",
"received %d bytes (%s)",nr,buf);
5057 if (remoteOffSet > -1 && (upwd || srp))
5061 if ((
gEnv->
GetValue(
"Proofd.SendSRPPwd",0)) && (remoteOffSet > -1))
5064 if (srp && pwdctx) {
5065 if (strcmp(pwdctx->
GetPasswd(),
"") && remoteOffSet > -1)
5070 if ((upwd && pwdctx) || (srp && sndsrp)) {
5074 Error(
"OldAuthSetup",
"failed to send offset in RSA key");
5085 if (remoteOffSet > -1)
5086 Warning(
"OldAuthSetup",
"problems secure-sending pass hash %s",
5087 "- may result in failures");
5090 for (
int i = 0; i < passwd.
Length(); i++) {
5091 char inv = ~passwd(i);
5096 if (sock->
Send(mess) < 0) {
5097 Error(
"OldAuthSetup",
"failed to send inverted password");
5107 Error(
"OldAuthSetup",
"failed to send no offset notification in RSA key");
5114 mess << user << pwhash << srppwd << ord << conf;
5116 if (sock->
Send(mess) < 0) {
5117 Error(
"OldAuthSetup",
"failed to send ordinal and config info");
5121 if (proofdProto > 6) {
5127 Error(
"OldAuthSetup",
"failed to send HostAuth info");
5146 if (sock->
Recv(retval, kind) != 2*
sizeof(
Int_t)) {
5148 Info(
"OldProofServAuthSetup",
5149 "socket has been closed due to protocol mismatch - Exiting");
5166 if ((fKey = fopen(keyfile.
Data(),
"r"))) {
5167 Int_t klen = fread((
void *)pubkey,1,
sizeof(pubkey),fKey);
5169 Error(
"OldProofServAuthSetup",
5170 "failed to read public key from '%s'", keyfile.
Data());
5179 Error(
"OldProofServAuthSetup",
"failed to open '%s'", keyfile.
Data());
5188 Error(
"OldProofServAuthSetup",
"failed to receive password");
5194 }
else if (retval == -1) {
5198 if ((sock->
Recv(mess) <= 0) || !mess) {
5199 Error(
"OldProofServAuthSetup",
"failed to receive inverted password");
5205 for (
Int_t i = 0; i < passwd.Length(); i++) {
5206 char inv = ~passwd(i);
5207 passwd.Replace(i, 1, inv);
5215 if ((sock->
Recv(mess) <= 0) || !mess) {
5216 Error(
"OldProofServAuthSetup",
"failed to receive ordinal and config info");
5224 (*mess) >> user >> pwhash >> srppwd >> conf;
5227 (*mess) >> user >> pwhash >> srppwd >> ord >> conf;
5232 (*mess) >> user >> pwhash >> srppwd >> iord;
5236 (*mess) >> user >> pwhash >> srppwd >> ord >> conf;
5258 Error(
"OldProofServAuthSetup",
"failed to receive HostAuth info");
void SetDetails(Int_t level, const char *details)
Set authentication details for specified level.
const Int_t kAUTH_SSALT_MSK
static Bool_t GetGlobalSRPPwd()
Static method returning the global SRP password flag.
static void SetKrb5AuthHook(Krb5Auth_t func)
Set kerberos5 authorization function.
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
Returns FALSE if one can access a file using the specified access mode.
static void SetDefaultUser(const char *defaultuser)
Set default user name.
double read(const std::string &file_name)
reading
static Int_t GetRSAInit()
Static method returning the RSA initialization flag.
virtual int GetPid()
Get process id.
static Int_t GetClientProtocol()
Static method returning supported client protocol.
static void InitRandom()
Initialize random machine using seed from /dev/urandom (or current time if /dev/urandom not available...
static Bool_t GetAuthReUse()
Static method returning the authentication reuse settings.
UInt_t Convert(Bool_t toGMT=kFALSE) const
Convert fDatime from TDatime format to the standard time_t format.
const char * GetHostName() const
static RSA_num_sput_t RSA_num_sput()
static Bool_t fgUsrPwdCrypt
void Set()
Set Date/Time to current time as reported by the system.
void AddForCleanup(Int_t port, Int_t proto, Int_t type)
Create a new TSecContextCleanup Internally is added to the list.
void * GetContext() const
static void RemoveSecContext(TRootSecContext *ctx)
Tool for removing SecContext ctx from THostAuth listed in fgAuthInfo or fgProofAuthInfo.
Int_t GetRemoteProtocol() const
Int_t(* Krb5Auth_t)(TAuthenticate *auth, TString &user, TString &det, Int_t version)
R__EXTERN const char * gRootdErrStr[]
void PrintEstablished() const
Print info about established authentication vis-a-vis of this Host.
ClassImp(TSeqCollection) Int_t TSeqCollection TIter next(this)
Return index of object in collection.
Int_t AuthExists(TString User, Int_t method, const char *Options, Int_t *Message, Int_t *Rflag, CheckSecCtx_t funcheck)
Check if we have a valid established sec context in memory Retrieves relevant info and negotiates wit...
static Bool_t fgPromptUser
Int_t GetServType() const
virtual Int_t Send(const TMessage &mess)
Send a TMessage object.
static void SetGlobalUser(const char *user)
Set global user name to be used for authentication to rootd or proofd.
TString & ReplaceAll(const TString &s1, const TString &s2)
int GetPathInfo(const char *path, Long_t *id, Long_t *size, Long_t *flags, Long_t *modtime)
Get info about a file: id, size, flags, modification time.
virtual Int_t Recv(TMessage *&mess)
Receive a TMessage object.
static RSA_decode_t RSA_decode()
Int_t SshAuth(TString &user)
SSH client authentication code.
Ssiz_t Index(const TString &str, Ssiz_t *len, Ssiz_t start=0) const
Find the first occurrence of the regexp in string and return the position, or -1 if there is no match...
Int_t OldProofServAuthSetup(TSocket *sock, Bool_t master, Int_t protocol, TString &user, TString &ord, TString &conf)
Authentication related setup in TProofServ run after successful startup.
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
static void RemoveHostAuth(THostAuth *ha, Option_t *opt="")
Remove THostAuth instance from the list.
const char * GetUser() const
This class represents an Internet Protocol (IP) address.
Int_t(* GlobusAuth_t)(TAuthenticate *auth, TString &user, TString &det)
virtual const char * HomeDirectory(const char *userName=0)
Return the user's home directory.
static TString Decode(const char *data)
Decode a base64 string date into a generic TString.
Regular expression class.
This class implements a mutex interface.
static GlobusAuth_t GetGlobusAuthHook()
Static method returning the globus authorization hook.
void AsString(TString &out) const
Return a static string with all info in a serialized form.
virtual UserGroup_t * GetGroupInfo(Int_t gid)
Returns all group info in the UserGroup_t structure.
double inv(double x)
For comparisons.
Int_t LoadPlugin()
Load the plugin library for this handler.
virtual int Load(const char *module, const char *entry="", Bool_t system=kFALSE)
Load a shared library.
const char * GetDetails(Int_t level)
Return authentication details for specified level or "" if the specified level does not exist for thi...
Int_t StdCheckSecCtx(const char *, TRootSecContext *)
Standard version of CheckSecCtx to be passed to TAuthenticate::AuthExists Check if User is matches th...
Bool_t IsActive() const
Check remote OffSet and expiring Date.
static TList * fgProofAuthInfo
virtual char * Which(const char *search, const char *file, EAccessMode mode=kFileExists)
Find location of file in a search path.
static char * GetDefaultDetails(Int_t method, Int_t opt, const char *user)
Determine default authentication details for method 'sec' and user 'usr'.
static RSA_num_sget_t RSA_num_sget()
void CountFailure(Int_t level)
Count failures for 'method'.
static const char * GetKrb5Principal()
Static method returning the principal to be used to init Krb5 tickets.
Long_t ExecPlugin(int nargs, const T &...params)
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
Bool_t HasMethod(Int_t level, Int_t *pos=0)
Return kTRUE if method 'level' is in the list.
Bool_t Authenticate()
Authenticate to remote rootd or proofd server.
static SecureAuth_t fgSecAuthHook
const Int_t kAUTH_RSATY_MSK
static void SetReadHomeAuthrc(Bool_t readhomeauthrc)
Set flag controlling the reading of $HOME/.rootauthrc.
Int_t ClearAuth(TString &user, TString &passwd, Bool_t &pwhash)
UsrPwd client authentication code.
Bool_t R_ISREG(Int_t mode)
TString & Replace(Ssiz_t pos, Ssiz_t n, const char *s)
void CountSuccess(Int_t level)
Count successes for 'method'.
const char * Data() const
virtual TObject * ReadObject(const TClass *cl)
Read object from I/O buffer.
static TPluginHandler * fgPasswdDialog
static TString Encode(const char *data)
Transform data into a null terminated base64 string.
virtual Int_t SendRaw(const void *buffer, Int_t length, ESendRecvOptions opt=kDefault)
Send a raw buffer of specified length.
static Int_t ReadRootAuthrc()
Read authentication directives from $ROOTAUTHRC, $HOME/.rootauthrc or <Root_etc_dir>/system.rootauthrc and create related THostAuth objects.
static TList * fgAuthInfo
static void SetPromptUser(Bool_t promptuser)
Set global PromptUser flag.
virtual int Unlink(const char *name)
Unlink, i.e. remove, a file.
static char * PromptPasswd(const char *prompt="Password: ")
Static method to prompt for the user's passwd to be used for authentication to rootd or proofd...
static GlobusAuth_t fgGlobusAuthHook
static RSA_assign_t RSA_assign()
static rsa_KEY fgRSAPubKey
void SetServer(Int_t server)
const char * GetHost() const
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString...
virtual FILE * TempFileName(TString &base, const char *dir=0)
Create a secure temporary file by appending a unique 6 letter string to base.
virtual void Sleep(UInt_t milliSec)
Sleep milliSec milli seconds.
UChar_t mod R__LOCKGUARD2(gSrvAuthenticateMutex)
static Int_t DecodeRSAPublic(const char *rsapubexport, rsa_NUMBER &n, rsa_NUMBER &d, char **rsassl=0)
Store RSA public keys from export string rsaPubExport.
static rsa_KEY_export fgRSAPubExport[2]
TLine l1(2.5, 4.5, 15.5, 4.5)
static double p2(double t, double a, double b, double c)
virtual const char * Getenv(const char *env)
Get environment variable.
void Info(const char *location, const char *msgfmt,...)
TString & Append(const char *cs)
std::vector< std::vector< double > > Data
Int_t ProofAuthSetup()
Authentication related stuff setup in TProofServ.
Int_t RfioAuth(TString &user)
UidGid client authentication code.
virtual UserGroup_t * GetUserInfo(Int_t uid)
Returns all user info in the UserGroup_t structure.
Int_t Atoi() const
Return integer value of string.
static RSA_genprim_t RSA_genprim()
static void SetTimeOut(Int_t to)
Set timeout (active if > 0)
static void SetGlobalSRPPwd(Bool_t srppwd)
Set global SRP passwd flag to be used for authentication to rootd or proofd.
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
static Bool_t GetPromptUser()
Static method returning the prompt user settings.
virtual TInetAddress GetHostByName(const char *server)
Get Internet Protocol (IP) address of host.
void Error(const char *location, const char *msgfmt,...)
TAuthenticate(TSocket *sock, const char *remote, const char *proto, const char *user="")
Create authentication object.
const Int_t kAUTH_REUSE_MSK
static Int_t SecureSend(TSocket *Socket, Int_t enc, Int_t KeyType, const char *In)
Encode null terminated str using the session private key indicated by enc and sends it over the netwo...
Int_t(* CheckSecCtx_t)(const char *subj, TRootSecContext *ctx)
TList * Established() const
Int_t SshError(const char *errfile)
SSH error parsing: returns 0 : no error or fatal 1 : should retry (eg 'connection closed by remote ho...
void RemoveMethod(Int_t level)
Remove method 'meth' from the list, if there ...
static void AuthError(const char *where, Int_t error)
Print error string depending on error code.
static RSA_cmp_t RSA_cmp()
virtual void Close(Option_t *opt="")
Close the socket.
static Krb5Auth_t fgKrb5AuthHook
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
Return true if string ends with the specified string.
R__EXTERN TSystem * gSystem
Bool_t IsA(const char *methodname)
Checks if this security context is for method named 'methname' Case sensitive.
ClassImp(TAuthenticate) static int auth_rand()
rand() implementation using /udev/random or /dev/random, if available
static void SetRSAInit(Int_t init=1)
Static method setting RSA initialization flag.
virtual Int_t GetValue(const char *name, Int_t dflt)
Returns the integer value for a resource.
virtual TObject * Remove(TObject *obj)
Remove object from the list.
const char * GetSshUser(TString user) const
Method returning the user to be used for the ssh login.
static TDatime GetGlobalExpDate()
Static method returning default expiring date for new validity contexts.
static void SetSecureAuthHook(SecureAuth_t func)
Set secure authorization function.
Int_t GenRSAKeys()
Generate a valid pair of private/public RSA keys to protect for authentication token exchange...
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
void SetID(const char *id)
char * Form(const char *fmt,...)
static char * PromptUser(const char *remote)
Static method to prompt for the user name to be used for authentication to rootd or proofd...
static TList * GetProofAuthInfo()
Static method returning the list with authentication directives to be sent to proof.
Int_t(* SecureAuth_t)(TAuthenticate *auth, const char *user, const char *passwd, const char *remote, TString &det, Int_t version)
static Int_t SetRSAPublic(const char *rsapubexport, Int_t klen)
Store RSA public keys from export string rsaPubExport.
Handles synchronous and a-synchronous timer events.
return fString CompareTo(((TObjString *) obj) ->fString)
const char * GetPasswd() const
static Bool_t CheckProofAuth(Int_t cSec, TString &det)
Check if the authentication method can be attempted for the client.
virtual Int_t Exec(const char *shellcmd)
Execute a command.
void AddMethod(Int_t level, const char *details=0)
Add method to the list.
static double p1(double t, double a, double b)
THostAuth * GetHostAuth() const
void Warning(const char *location, const char *msgfmt,...)
TRootSecContext * fSecContext
static const char * GetDefaultUser()
Static method returning the default user information.
static TDatime fgLastAuthrc
static void Show(Option_t *opt="S")
Print info about the authentication sector.
void SetHost(const char *host)
char * StrDup(const char *str)
Duplicate the string str.
static TList * GetAuthInfo()
Static method returning the list with authentication details.
TString & Remove(Ssiz_t pos)
static void SetAuthReUse(Bool_t authreuse)
Set global AuthReUse flag.
virtual Int_t GetEffectiveUid()
Returns the effective user id.
virtual Int_t GetSize() const
void SetUser(const char *user)
static TString fgKrb5Principal
TRootSecContext * CreateSecContext(const char *user, const char *host, Int_t meth, Int_t offset, const char *details, const char *token, TDatime expdate=kROOTTZERO, void *ctx=0, Int_t key=-1)
Create a Security context and add it to local list Return pointer to it to be stored in TAuthenticate...
const char * GetUser() const
void CatchTimeOut()
Called in connection with a timer timeout.
Int_t OldSlaveAuthSetup(TSocket *sock, Bool_t master, TString ord, TString conf)
Setup of authetication in PROOF run after successful opening of the socket.
virtual const char * HostName()
Return the system's host name.
char * DynamicPathName(const char *lib, Bool_t quiet=kFALSE)
Find a dynamic library called lib using the system search paths.
Bool_t GetUserPasswd(TString &user, TString &passwd, Bool_t &pwhash, Bool_t srppwd)
Try to get user name and passwd from several sources.
void SetEnvironment()
Set default authentication environment.
static void FileExpand(const char *fin, FILE *ftmp)
Expands include directives found in fexp files The expanded, temporary file, is pointed to by 'ftmp' ...
virtual void Print(Option_t *option="F") const
If opt is "F" (default) print object content.
static Int_t SecureRecv(TSocket *Socket, Int_t dec, Int_t KeyType, char **Out)
Receive str from sock and decode it using key indicated by key type Return number of received bytes o...
double func(double *x, double *p)
const char * GetID() const
void Print(Option_t *option="F") const
If opt is "F" (default) print object content.
#define SSL_load_error_strings
static Int_t SendHostAuth(TSocket *s)
Sends the list of the relevant THostAuth objects to the master or to the active slaves, typically data servers external to the proof cluster.
void ReOrder(Int_t nmet, Int_t *fmet)
Reorder nmet methods according fmet[nmet].
virtual void DispatchOneEvent(Bool_t pendingOnly=kFALSE)
Dispatch a single event.
static Bool_t CheckHost(const char *Host, const char *host)
Check if 'host' matches 'href': this means either equal or "containing" it, even with wild cards * ...
static void SetGlobalExpDate(TDatime expdate)
Set default expiring date for new validity contexts.
static TString fgDefaultUser
static void SetGlobusAuthHook(GlobusAuth_t func)
Set Globus authorization function.
static void SetGlobalPwHash(Bool_t pwhash)
Set global passwd hash flag to be used for authentication to rootd or proofd.
static void MergeHostAuthList(TList *Std, TList *New, Option_t *Opt="")
Tool for updating fgAuthInfo or fgProofAuthInfo 'nin' contains list of last input information through...
static const char * GetRSAPubExport(Int_t key=0)
Static method returning the RSA public keys.
static TString fgRootAuthrc
TSecContext * GetSecContext() const
Bool_t IsDigit() const
Returns true if all characters in string are digits (0-9) or white spaces, i.e.
Bool_t R_ISDIR(Int_t mode)
void SetFirst(Int_t level)
Set 'method' to be the first used (if in the list ...).
static const char * GetGlobalUser()
Static method returning the global user.
virtual void Add(TObject *obj)
R__EXTERN const char * gRootDir
virtual Int_t GetEffectiveGid()
Returns the effective group id.
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
static TString fgAuthMeth[kMAXSEC]
void WriteObject(const TObject *obj)
Write object to message buffer.
void Update(THostAuth *ha)
Update info with the one in ha Remaining methods, if any, get lower priority.
static RSA_encode_t RSA_encode()
static Bool_t fgReadHomeAuthrc
static Int_t GetClientProtocol()
Static method returning supported client protocol.
virtual void Print(Option_t *option="") const
Print object content.
static rsa_KEY fgRSAPriKey
Bool_t CheckNetrc(TString &user, TString &passwd)
Try to get user name and passwd from the ~/.rootnetrc or ~/.netrc files.
char * GetRandString(Int_t Opt, Int_t Len)
Allocates and fills a 0 terminated buffer of length len+1 with len random characters.
This class creates the ROOT Application Environment that interfaces to the windowing system eventloop...
static RSA_genrsa_t RSA_genrsa()
static void SetDefaultRSAKeyType(Int_t key)
Static method setting the default type of RSA key.
static Bool_t GetGlobalPwHash()
Static method returning the global password hash flag.
void SetLast(Int_t level)
Set 'method' to be the last used (if in the list ...).
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
static Bool_t fgAuthReUse
void AddFirst(Int_t level, const char *details=0)
Add new method in first position If already in the list, set as first method 'level' with authenticat...
virtual Int_t RecvRaw(void *buffer, Int_t length, ESendRecvOptions opt=kDefault)
Receive a raw buffer of specified length bytes.
Int_t GetMethod(Int_t idx) const
const Int_t kAUTH_CRYPT_MSK
virtual char * ConcatFileName(const char *dir, const char *name)
Concatenate a directory and a file name. User must delete returned string.
const char * cd(char *path=0)
static Int_t GetAuthMethodIdx(const char *meth)
Static method returning the method index (which can be used to find the method in GetAuthMethod())...
static THostAuth * HasHostAuth(const char *host, const char *user, Option_t *opt="R")
Checks if a THostAuth with exact match for {host,user} exists in the fgAuthInfo list If opt = "P" use...
static void SetGlobalPasswd(const char *passwd)
Set global passwd to be used for authentication to rootd or proofd.
void Resize(Ssiz_t n)
Resize the string. Truncate or add blanks as necessary.
static Int_t SendRSAPublicKey(TSocket *Socket, Int_t key=0)
Receives server RSA Public key Sends local RSA public key encoded.
This class stores the date and time with a precision of one second in an unsigned 32 bit word (950130...
static Int_t RecvHostAuth(TSocket *s, Option_t *opt)
Receive from client/master directives for authentications, create related THostAuth and add them to t...
static const char * GetAuthMethod(Int_t idx)
Static method returning the method corresponding to idx.
const char * GetHostAddress() const
Returns the IP address string "%d.%d.%d.%d".
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.