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> 86 "Globus",
"SSH",
"UidGid" };
107 BF_KEY TAuthenticate::fgBFKey;
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)
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);
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);
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);
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);
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);
860 Info(
"SetEnvironment",
861 "setting environment: fSecurity:%d, fDetails:%s",
fSecurity,
876 char pt[5] = { 0 }, ru[5] = { 0 };
877 Int_t hh = 0, mm = 0;
883 if ((ptr = strstr(
fDetails,
"pt:")) != 0) {
884 sscanf(ptr + 3,
"%4s %8191s", pt, usdef);
886 if (!strncasecmp(
gEnv->
GetValue(usrPromptDef,
""),
"no",2) ||
893 if ((ptr = strstr(
fDetails,
"ru:")) != 0) {
894 sscanf(ptr + 3,
"%4s %8191s", ru, usdef);
896 if (!strncasecmp(
gEnv->
GetValue(usrReUseDef,
""),
"no",2) ||
905 if ((pd = hours.Index(
":")) > -1) {
909 hh = atoi(hours.Data());
910 mm = atoi(minutes.
Data());
912 hh = atoi(hours.Data());
918 if ((ptr = strstr(
fDetails,
"cd:")) != 0)
919 sscanf(ptr,
"%8191s %8191s", cd, usdef);
920 if ((ptr = strstr(
fDetails,
"cf:")) != 0)
921 sscanf(ptr,
"%8191s %8191s", cf, usdef);
922 if ((ptr = strstr(
fDetails,
"kf:")) != 0)
923 sscanf(ptr,
"%8191s %8191s", kf, usdef);
924 if ((ptr = strstr(
fDetails,
"ad:")) != 0)
925 sscanf(ptr,
"%8191s %8191s", ad, usdef);
927 Info(
"SetEnvironment",
928 "details:%s, pt:%s, ru:%s, cd:%s, cf:%s, kf:%s, ad:%s",
932 if ((ptr = strstr(
fDetails,
"us:")) != 0)
933 sscanf(ptr + 3,
"%8191s %8191s", us, usdef);
934 if ((ptr = strstr(
fDetails,
"cp:")) != 0)
935 sscanf(ptr + 3,
"%8191s %8191s", cp, usdef);
937 Info(
"SetEnvironment",
"details:%s, pt:%s, ru:%s, us:%s cp:%s",
940 if ((ptr = strstr(
fDetails,
"us:")) != 0)
941 sscanf(ptr + 3,
"%8191s %8191s", us, usdef);
942 if ((ptr = strstr(
fDetails,
"pp:")) != 0)
943 sscanf(ptr + 3,
"%8191s %8191s", pp, usdef);
945 Info(
"SetEnvironment",
"details:%s, pt:%s, ru:%s, us:%s pp:%s",
948 if ((ptr = strstr(
fDetails,
"us:")) != 0)
949 sscanf(ptr + 3,
"%8191s %8191s", us, usdef);
951 Info(
"SetEnvironment",
"details:%s, pt:%s, ru:%s, us:%s",
956 if (!strncasecmp(pt,
"yes",3) || !strncmp(pt,
"1", 1))
962 if (!strncasecmp(ru,
"yes",3) || !strncmp(ru,
"1",1))
967 if (!strncasecmp(ru,
"no",2) || !strncmp(ru,
"0",1))
979 if (!strncmp(cp,
"no", 2) || !strncmp(cp,
"0", 1))
985 if (strlen(cd) > 0) {
snprintf(usdef,8192,
" %s",cd); }
986 if (strlen(cf) > 0) {
snprintf(usdef,8192,
"%s %s",usdef, cf); }
987 if (strlen(kf) > 0) {
snprintf(usdef,8192,
"%s %s",usdef, kf); }
988 if (strlen(ad) > 0) {
snprintf(usdef,8192,
"%s %s",usdef, ad); }
992 if (strlen(pp) > 0) {
996 if (strlen(us) > 0 && strstr(us,
"@"))
1003 if (strlen(us) > 0 && !strstr(us,
"@"))
1014 if (strlen(usdef) > 0) {
1015 fgDefaultUser = usdef;
1022 fgDefaultUser = u->
fUser;
1026 if (fgDefaultUser ==
"anonymous" || fgDefaultUser ==
"rootd" ||
1033 Info(
"SetEnvironment",
"usdef:%s", fgDefaultUser.Data());
1044 Info(
"GetUserPasswd",
"Enter: User: '%s' Hash:%d SRP:%d",
1064 Info(
"GetUserPasswd",
"In memory: User: '%s' Hash:%d",
1074 Info(
"GetUserPasswd",
"In memory: User: '%s' Hash:%d",
1080 if (user ==
"" || passwd ==
"") {
1082 Info(
"GetUserPasswd",
"Checking .netrc family ...");
1086 Info(
"GetUserPasswd",
"From .netrc family: User: '%s' Hash:%d",
1095 Error(
"GetUserPasswd",
"user name not set");
1115 return CheckNetrc(user, passwd, hash, srppwd);
1173 FILE *fd = fopen(net,
"r");
1175 while (fgets(line,
sizeof(line), fd) != 0) {
1179 int nword = sscanf(line,
"%63s %63s %63s %63s %63s %63s",
1180 word[0], word[1], word[2], word[3], word[4], word[5]);
1183 if (srppwd && strcmp(word[0],
"secure"))
1185 if (!srppwd && strcmp(word[0],
"machine"))
1187 if (strcmp(word[2],
"login"))
1189 if (srppwd && strcmp(word[4],
"password"))
1192 strcmp(word[4],
"password") && strcmp(word[4],
"password-hash"))
1204 if (!strcmp(word[4],
"password-hash"))
1209 if (!strcmp(word[3], user.
Data())) {
1211 if (!strcmp(word[4],
"password-hash"))
1222 "file %s exists but has not 0600 permission", net);
1226 if (first && !srppwd && !result) {
1306 if (idx < 0 || idx >
kMAXSEC-1) {
1307 ::Error(
"Authenticate::GetAuthMethod",
"idx out of bounds (%d)", idx);
1321 if (meth && meth[0]) {
1350 if (isatty(0) == 0 || isatty(1) == 0) {
1352 "not tty: cannot prompt for user, returning default");
1359 const char *usrIn = Getline(
Form(
"Name (%s:%s): ", remote, user));
1379 if (isatty(0) == 0 || isatty(1) == 0) {
1380 ::Warning(
"TAuthenticate::PromptPasswd",
1381 "not tty: cannot prompt for passwd, returning -1");
1382 static char noint[4] = {
"-1"};
1387 const char *pw = buf;
1392 gROOT->GetPluginManager()->FindHandler(
"TGPasswdDialog"))) {
1396 "could not load plugin for the password dialog box");
1406 while (
gROOT->IsInterrupted())
1410 Gl_config(
"noecho", 1);
1411 pw = Getline(prompt);
1412 Gl_config(
"noecho", 0);
1439 key = (key >= 0 && key <= 1) ? key : 0;
1456 if (key >= 0 && key <= 1)
1501 err = (err < kErrError) ? ((err > -1) ? err : -1) :
kErrError;
1509 lasterr =
"(last error only; re-run with gDebug > 0 for more details)";
1513 if (
gDebug > 0 || forceprint) {
1515 ::Error(
Form(
"TAuthenticate::%s", where),
"%s %s",
1519 "unknown error code: server must be running a newer ROOT version %s",
1537 if (user && user[0])
1551 if (passwd && passwd[0])
1597 if (defaultuser && defaultuser[0])
1662 FILE *
ferr = fopen(errorfile,
"r");
1667 Int_t lerr = strlen(serr);
1668 char *pc = (
char *)memchr(serr,
'"',lerr);
1671 pc = (
char *)memchr(pc+1,
'"',strlen(pc+1));
1675 while (fgets(line,
sizeof(line),
ferr)) {
1677 if (line[strlen(line)-1] ==
'\n')
1678 line[strlen(line)-1] =
'\0';
1680 Info(
"SshError",
"read line: %s",line);
1682 while (pc < serr + lerr) {
1683 if (pc[0] ==
'\0' || pc[0] ==
' ')
1687 Info(
"SshError",
"checking error: '%s'",pc);
1688 if (strstr(line,pc))
1697 if (serr)
delete [] serr;
1712 if (
gROOT->IsProofServ()) {
1715 Info(
"SshAuth",
"SSH protocol is switched OFF by default" 1716 " for PROOF servers: use 'ProofServ.UseSSH 1'" 1717 " to enable it (see system.rootrc)");
1727 char cmdref[2][5] = {
"ssh",
"scp"};
1732 while (notfound && sshproto > -1) {
1734 strlcpy(scmd,cmdref[sshproto],5);
1743 Info(
"SshAuth",
"%s not found in $PATH", scmd);
1746 if (strcmp(
gEnv->
GetValue(
"SSH.ExecDir",
"-1"),
"-1")) {
1748 Info(
"SshAuth",
"searching user defined path ...");
1752 Info(
"SshAuth",
"%s not executable", sshExe.
Data());
1758 if (notfound) sshproto--;
1766 Info(
"SshAuth",
"%s is %s (sshproto: %d)", scmd, sshExe.
Data(), sshproto);
1789 options.
Form(
"%d none %ld %s %d", opt,
1794 Int_t retval = reuse;
1829 Info(
"SshAuth",
"received from server command info: %s", cmdinfo);
1835 while (ci.Tokenize(tkn, from,
" ")) {
1836 if (from > 0) cmdinfo[from-1] =
'\0';
1850 if (isatty(0) == 0 || isatty(1) == 0) {
1851 noPrompt =
TString(
"-o 'PasswordAuthentication no' ");
1852 noPrompt +=
TString(
"-o 'StrictHostKeyChecking no' ");
1854 Info(
"SshAuth",
"using noprompt options: %s", noPrompt.
Data());
1866 if (sshproto == 0) {
1868 fileErr =
"rootsshtmp_";
1872 fileErr =
"rootsshtmp_";
1876 fileErr.
Append(
".error");
1878 sshcmd.
Form(
"%s -x -l %s %s", sshExe.
Data(), user.
Data(), noPrompt.
Data());
1886 while (ssh_rc && again && ntry--) {
1891 Info(
"SshAuth",
"%d: sleeping: rc: %d, again:%d, ntry: %d",
1906 TString fileLoc =
"rootsshtmp_";
1910 fileLoc =
"rootsshtmp_";
1917 if (chmod(fileLoc, 0600) == -1) {
1918 Info(
"SshAuth",
"fchmod error: %d", errno);
1921 floc = fopen(fileLoc,
"w");
1925 fprintf(floc,
"k: %d\n",
fRSAKey+1);
1933 fprintf(floc,
"k: -1\n");
1940 sshcmd.
Form(
"%s -p %s", sshExe.
Data(), noPrompt.
Data());
1954 while (ssh_rc && again && ntry--) {
1959 Info(
"SshAuth",
"%d: sleeping: rc: %d, again:%d, ntry: %d",
1981 Info(
"SshAuth",
"%d: system return code: %d (%d)",
1984 if (ssh_rc && sshproto == 0) {
2009 newsock->
Send(
"failure notification");
2012 char cd1[1024], pipe[1024], dum[1024];
2014 sscanf(cmdinfo,
"%1023s %d %1023s %1023s", cd1, &id3, pipe, dum);
2022 if (newsock->
Recv(retval, kind) >= 0) {
2023 char *buf =
new char[retval+1];
2024 if (newsock->
Recv(buf, retval+1, kind) >= 0) {
2025 if (strncmp(buf,
"OK",2)) {
2027 Info(
"SshAuth",
">> nothing listening on port %s %s",buf,
2028 "(supposed to be associated to sshd)");
2029 Info(
"SshAuth",
">> contact the daemon administrator at %s",
2034 Info(
"SshAuth",
">> something listening on the port" 2035 " supposed to be associated to sshd.");
2036 Info(
"SshAuth",
">> You have probably mistyped your" 2037 " password. Or you tried to hack the" 2039 Info(
"SshAuth",
">> If the problem persists you may" 2040 " consider contacting the daemon");
2056 }
else if (ssh_rc && sshproto > 0) {
2059 Info(
"SshAuth",
"error communicating failure");
2066 Info(
"SshAuth",
"error communicating success");
2074 Info(
"SshAuth",
"got message %d, flag: %d", kind, retval);
2082 if (reuse == 1 && sshproto == 0) {
2087 "problems recvn RSA key flag: got message %d, flag: %d",
2102 Info(
"SshAuth",
"got message %d, flag: %d", kind, retval);
2107 "problems recvn (user,offset) length (%d:%d bytes:%d)", kind,
2113 reclen = (retval+1 > 256) ? 256 : retval+1;
2114 if ((nrec =
fSocket->
Recv(answer, reclen, kind)) < 0)
2117 Warning(
"SshAuth",
"username and offset not received (%d:%d)", kind,
2123 sscanf(answer,
"%127s %d", lUser, &offset);
2125 Info(
"SshAuth",
"received from server: user: %s, offset: %d", lUser,
2130 if (reuse == 1 && offset > -1) {
2132 Warning(
"SshAuth",
"problems secure-receiving token -" 2133 " may result in corrupted token");
2138 Info(
"SshAuth",
"received from server: token: '%s' ", token);
2149 if (token)
delete [] token;
2155 Info(
"SshAuth",
"received from server: kind: %d, retval: %d", kind,
2213 if (!strcmp(href,
"*"))
2222 if (rename.
Index(href,&len) != -1 || strstr(href,
"-"))
2227 if (strstr(href,
"*"))
2239 ::Info(
"TAuthenticate::CheckHost",
"checking host IP: %s", theHost.
Data());
2250 if (pos > 0 && pos != (
Ssiz_t)(theHost.
Length()-strlen(href)))
2266 Info(
"RfioAuth",
"enter ... username %s", username.
Data());
2273 username = pw->fUser;
2277 if (pw->fUid != 0) {
2290 Info(
"RfioAuth",
"sending ... %s", sstr.
Data());
2295 Info(
"RfioAuth",
"sent ... %d bytes (expected > %d)", ns,
2303 Info(
"RfioAuth",
"after kROOTD_RFIO: kind= %d, stat= %d", kind,
2325 "%s@%s does not accept connections from %s%s",
2333 "%s@%s does not accept %s authentication from %s@%s",
2335 TAuthenticate::fgAuthMeth[5].
Data(),
2344 Warning(
"RfioAuth",
"UidGid login as \"root\" not allowed");
2361 Info(
"ClearAuth",
"enter: user: %s (passwd hashed?: %d)",
2373 Info(
"ClearAuth",
"ru:%d pt:%d cp:%d ns:%d rk:%d",
2402 options.
Form(
"%d %ld %s %ld %s", opt,
2424 Info(
"ClearAuth",
"anonymous user");
2433 char ctag[11] = {0};
2434 if (anon == 0 && cryptopt == 1) {
2441 "problems recvn RSA key flag: got message %d, flag: %d",
2447 Info(
"ClearAuth",
"get key request ...");
2461 Warning(
"ClearAuth",
"problems secure-receiving salt -" 2462 " may result in corrupted salt");
2463 Warning(
"ClearAuth",
"switch off reuse for this session");
2471 while (ltmp && tmpsalt[ltmp-1] !=
'#') ltmp--;
2473 if (tmpsalt[ltmp-1] ==
'#' &&
2474 tmpsalt[ltmp-10] ==
'#') {
2475 strlcpy(ctag,&tmpsalt[ltmp-10],11);
2494 Info(
"ClearAuth",
"got salt: '%s' (len: %d)", salt.
Data(), slen);
2497 Info(
"ClearAuth",
"Salt not required");
2500 Warning(
"ClearAuth",
"problems secure-receiving rndmtag -" 2501 " may result in corrupted rndmtag");
2504 strlcpy(ctag, tmptag, 11);
2530 if (localFQDN ==
"") {
2535 passwd.
Form(
"%s@%s", localuser.
Data(), localFQDN.
Data());
2538 "automatically generated anonymous passwd: %s",
2544 if (prompt == 1 || pashash.
Length() == 0) {
2553 Error(
"ClearAuth",
"password not set");
2558 if (needsalt && !pwdhash) {
2560 pashash =
TString(crypt(passwd, salt));
2586 if (anon == 0 && cryptopt == 1) {
2598 Warning(
"ClearAuth",
"problems secure-sending pass hash" 2599 " - may result in authentication failure");
2606 for (
int i = 0; i < passwd.
Length(); i++) {
2607 char inv = ~passwd(i);
2620 Info(
"ClearAuth",
"after kROOTD_PASS: kind= %d, stat= %d", kind,
2632 "problems recvn (user,offset) length (%d:%d bytes:%d)",
2637 int reclen = (stat+1 > 256) ? 256 : stat+1;
2638 if ((nrec =
fSocket->
Recv(answer, reclen, kind)) < 0)
2642 "username and offset not received (%d:%d)", kind,
2648 sscanf(answer,
"%127s %d", lUser, &offset);
2651 "received from server: user: %s, offset: %d (%s)", lUser,
2658 if (reuse == 1 && offset > -1) {
2660 if (cryptopt == 1) {
2663 "problems secure-receiving token -" 2664 " may result in corrupted token");
2669 token =
new char[tlen];
2675 Warning(
"ClearAuth",
"token not received (%d:%d)", kind,
2678 for (
int i = 0; i < (int) strlen(token); i++) {
2679 token[i] = ~token[i];
2684 Info(
"ClearAuth",
"received from server: token: '%s' ",
2746 "%s@%s does not accept connections from %s@%s",
2753 "%s@%s does not accept %s authentication from %s@%s",
2755 TAuthenticate::fgAuthMeth[0].
Data(),
2770 Error(
"ClearAuth",
"password not set");
2772 if (
fUser ==
"anonymous" ||
fUser ==
"rootd") {
2775 "please use passwd of form: user@host.do.main");
2786 for (
int i = 0; i < passwd.
Length(); i++) {
2787 char inv = ~passwd(i);
2799 Info(
"ClearAuth",
"after kROOTD_PASS: kind= %d, stat= %d", kind,
2828 ::Info(
"TAuthenticate::GetHostAuth",
"enter ... %s ... %s", host, user);
2834 char *ps = (
char *)strstr(host,
":");
2836 srvtyp = atoi(ps+1);
2840 if (strncmp(host,
"default",7) && !hostFQDN.
Contains(
"*")) {
2852 if (!strncasecmp(opt,
"P",1)) {
2860 while ((ai = (
THostAuth *) (*next)())) {
2862 ai->
Print(
"Authenticate::GetHostAuth");
2865 if (!(serverOK = (ai->
GetServer() == -1) ||
2870 if (!strcmp(ai->
GetHost(),
"default") && serverOK && notFound)
2880 if (hostFQDN == ai->
GetHost() &&
2902 ::Info(
"TAuthenticate::HasHostAuth",
"enter ... %s ... %s", host, user);
2908 char *ps = (
char *)strstr(host,
":");
2910 srvtyp = atoi(ps+1);
2913 if (strncmp(host,
"default",7) && !hostFQDN.
Contains(
"*")) {
2920 if (!strncasecmp(opt,
"P",1)) {
2925 while ((ai = (
THostAuth *) (*next)())) {
2927 if (hostFQDN == ai->
GetHost() &&
2949 ::Info(
"TAuthenticate::FileExpand",
"enter ... '%s' ... 0x%lx", fexp, (
Long_t)ftmp);
2951 fin = fopen(fexp,
"r");
2955 while (fgets(line,
sizeof(line), fin) != 0) {
2959 if (line[strlen(line) - 1] ==
'\n')
2960 line[strlen(line) - 1] =
'\0';
2962 ::Info(
"TAuthenticate::FileExpand",
"read line ... '%s'", line);
2963 int nw = sscanf(line,
"%19s %8191s", cinc, fileinc);
2966 if (strcmp(cinc,
"include") != 0) {
2968 fprintf(ftmp,
"%s\n", line);
2975 sscanf(ln.
Data(),
"%19s %8191s", cinc, fileinc);
2978 if (fileinc[0] ==
'$') {
2995 if (fileinc[0] ==
'~') {
2999 char *ffull =
new char[flen];
3009 "file specified by 'include' cannot be open or read (%s)",
3024 const char copt[2][5] = {
"no",
"yes" };
3027 ::Info(
"TAuthenticate::GetDefaultDetails",
3028 "enter ... %d ...pt:%d ... '%s'", sec, opt, usr);
3030 if (opt < 0 || opt > 1)
3035 if (!usr[0] || !strncmp(usr,
"*",1))
3044 if (!usr[0] || !strncmp(usr,
"*",1))
3052 if (!usr[0] || !strncmp(usr,
"*",1))
3067 if (!usr[0] || !strncmp(usr,
"*",1))
3075 if (!usr[0] || !strncmp(usr,
"*",1))
3081 ::Info(
"TAuthenticate::GetDefaultDetails",
"returning ... %s", temp);
3091 if (!strncasecmp(opt,
"P",1))
3120 " +--------------------------- BEGIN --------------------------------+");
3125 " + List fgProofAuthInfo has %4d members +",
3130 " +------------------------------------------------------------------+");
3138 " + List fgAuthInfo has %4d members +",
3143 " +------------------------------------------------------------------+");
3152 " +---------------------------- END ---------------------------------+");
3168 Info(
"AuthExists",
"%d: enter: msg: %d options: '%s'",
3169 method,*message, options);
3178 if (secctx->GetMethod() == method) {
3179 if (
fRemote == secctx->GetHost()) {
3181 (*checksecctx)(username,secctx) == 1)
3191 if (secctx->GetMethod() == method) {
3192 if (
fRemote == secctx->GetHost()) {
3194 (*checksecctx)(username,secctx) == 1) {
3207 offset = secctx->GetOffSet();
3208 token = secctx->GetToken();
3211 "found valid TSecContext: offset: %d token: '%s'",
3212 offset, token.
Data());
3223 Int_t reuse = *rflag;
3224 if (reuse == 1 && offset > -1) {
3233 Int_t stat = 1, kind;
3238 Warning(
"AuthExists",
"protocol error: expecting %d got %d" 3244 Info(
"AuthExists",
"offset OK");
3246 Int_t rsaKey = secctx->GetRSAKey();
3248 Info(
"AuthExists",
"key type: %d", rsaKey);
3264 Warning(
"AuthExists",
"problems secure-sending token %s",
3265 "- may trigger problems in proofing Id ");
3270 for (
int i = 0; i < token.
Length(); i++) {
3271 char inv = ~token(i);
3279 Info(
"AuthExists",
"offset not OK - rerun authentication");
3282 secctx->DeActivate(
"");
3290 Info(
"AuthExists",
"%d: after msg %d: kind= %d, stat= %d",
3291 method,*message, kind, stat);
3304 Error(
"AuthExists",
"%s@%s does not accept connections from %s@%s",
3310 "%s@%s does not accept %s authentication from %s@%s",
3318 secctx->DeActivate(
"");
3328 Info(
"AuthExists",
"valid authentication exists");
3330 Info(
"AuthExists",
"valid authentication exists: offset changed");
3332 Info(
"AuthExists",
"remote access authorized by /etc/hosts.equiv");
3334 Info(
"AuthExists",
"no authentication required remotely");
3343 secctx->SetOffSet(newOffSet);
3364 const char *randdev =
"/dev/urandom";
3367 if ((fd =
open(randdev, O_RDONLY)) != -1) {
3369 ::Info(
"InitRandom",
"taking seed from %s", randdev);
3370 if (
read(fd, &seed,
sizeof(seed)) !=
sizeof(seed))
3371 ::Warning(
"InitRandom",
"could not read seed from %s", randdev);
3375 ::Info(
"InitRandom",
"%s not available: using time()", randdev);
3390 Info(
"GenRSAKeys",
"enter");
3394 Info(
"GenRSAKeys",
"Keys prviously generated - return");
3416 Info(
"GenRSAKeys",
"SSL: Generate Blowfish key");
3425 OpenSSL_add_all_ciphers();
3431 nbits = (nbits >= 128) ? nbits : 128;
3434 nbits = (nbits <= 15912) ? nbits : 15912;
3437 Int_t klen = nbits / 8 ;
3441 RAND_seed(rbuf,strlen(rbuf));
3450 BF_set_key(&fgBFKey, klen, (
const unsigned char *)rbuf);
3459 Int_t l_n = 0, l_d = 0;
3466 Int_t nAttempts = 0;
3472 if (
gDebug > 2 && nAttempts > 1) {
3473 Info(
"GenRSAKeys",
"retry no. %d",nAttempts);
3486 Info(
"GenRSAKeys",
"equal primes: regenerate (%d times)",nPrimes);
3494 Info(
"GenRSAKeys",
"local: p1: '%s' ", buf);
3496 Info(
"GenRSAKeys",
"local: p2: '%s' ", buf);
3501 if (
gDebug > 2 && nAttempts > 1)
3502 Info(
"GenRSAKeys",
" genrsa: unable to generate keys (%d)",
3509 l_n = strlen(buf_n);
3512 l_e = strlen(buf_e);
3515 l_d = strlen(buf_d);
3519 Info(
"GenRSAKeys",
"local: n: '%s' length: %d", buf_n, l_n);
3520 Info(
"GenRSAKeys",
"local: e: '%s' length: %d", buf_e, l_e);
3521 Info(
"GenRSAKeys",
"local: d: '%s' length: %d", buf_d, l_d);
3533 strlcpy(test, tdum, lTes+1);
3537 Info(
"GenRSAKeys",
"local: test string: '%s' ", test);
3540 strlcpy(buf, test, lTes+1);
3546 "local: length of crypted string: %d bytes", lout);
3552 Info(
"GenRSAKeys",
"local: after private/public : '%s' ", buf);
3554 if (strncmp(test, buf, lTes))
3558 strlcpy(buf, test, lTes+1);
3563 Info(
"GenRSAKeys",
"local: length of crypted string: %d bytes ",
3570 Info(
"GenRSAKeys",
"local: after public/private : '%s' ", buf);
3572 if (strncmp(test, buf, lTes))
3589 Info(
"GenRSAKeys",
"local: generated keys are:");
3590 Info(
"GenRSAKeys",
"local: n: '%s' length: %d", buf_n, l_n);
3591 Info(
"GenRSAKeys",
"local: e: '%s' length: %d", buf_e, l_e);
3592 Info(
"GenRSAKeys",
"local: d: '%s' length: %d", buf_d, l_d);
3603 fgRSAPubExport[0].keys[0] =
'#';
3604 memcpy(fgRSAPubExport[0].keys + 1, buf_n, l_n);
3605 fgRSAPubExport[0].keys[l_n + 1] =
'#';
3606 memcpy(fgRSAPubExport[0].keys + l_n + 2, buf_d, l_d);
3607 fgRSAPubExport[0].keys[l_n + l_d + 2] =
'#';
3608 fgRSAPubExport[0].keys[l_n + l_d + 3] = 0;
3611 Info(
"GenRSAKeys",
"local: export pub: '%s'", fgRSAPubExport[0].keys);
3614 Info(
"GenRSAKeys",
"local: export pub length: %d bytes", fgRSAPubExport[0].len);
3633 unsigned int iimx[4][4] = {
3634 {0x0, 0xffffff08, 0xafffffff, 0x2ffffffe},
3635 {0x0, 0x3ff0000, 0x7fffffe, 0x7fffffe},
3636 {0x0, 0x3ff0000, 0x7e, 0x7e},
3637 {0x0, 0x3ffc000, 0x7fffffe, 0x7fffffe}
3640 const char *cOpt[4] = {
"Any",
"LetNum",
"Hex",
"Crypt" };
3643 if (opt < 0 || opt > 2) {
3646 Info(
"GetRandString",
"unknown option: %d : assume 0", opt);
3649 Info(
"GetRandString",
"enter ... len: %d %s", len, cOpt[opt]);
3652 char *buf =
new char[len + 1];
3662 for (m = 7; m < 32; m += 7) {
3663 i = 0x7F & (frnd >>
m);
3666 if ((iimx[opt][j] & (1 << l))) {
3678 Info(
"GetRandString",
"got '%s' ", buf);
3690 Int_t key,
const char *str)
3696 ::Info(
"TAuthenticate::SecureSend",
"local: enter ... (enc: %d)", enc);
3698 Int_t slen = strlen(str) + 1;
3703 strlcpy(buftmp, str, slen+1);
3713 }
else if (key == 1) {
3718 ttmp = ((ttmp + 8)/8) * 8;
3719 unsigned char iv[8];
3720 memset((
void *)&iv[0],0,8);
3721 BF_cbc_encrypt((
const unsigned char *)str, (
unsigned char *)buftmp,
3722 strlen(str), &fgBFKey, iv, BF_ENCRYPT);
3725 ::Info(
"TAuthenticate::SecureSend",
"not compiled with SSL support:" 3726 " you should not have got here!");
3730 ::Info(
"TAuthenticate::SecureSend",
"unknown key type (%d)",key);
3737 nsen = sock->
SendRaw(buftmp, ttmp);
3739 ::Info(
"TAuthenticate::SecureSend",
3740 "local: sent %d bytes (expected: %d)", nsen,ttmp);
3762 if (sock->
Recv(buflen, 20, kind) < 0)
3764 Int_t len = atoi(buflen);
3766 ::Info(
"TAuthenticate::SecureRecv",
"got len '%s' %d (msg kind: %d)",
3771 if (!strncmp(buflen,
"-1", 2))
3775 if ((nrec = sock->
RecvRaw(buftmp, len)) < 0)
3786 const size_t strSize = strlen(buftmp) + 1;
3787 *str =
new char[strSize];
3788 strlcpy(*str, buftmp, strSize);
3790 }
else if (key == 1) {
3792 unsigned char iv[8];
3793 memset((
void *)&iv[0],0,8);
3794 *str =
new char[nrec + 1];
3795 BF_cbc_encrypt((
const unsigned char *)buftmp, (
unsigned char *)(*str),
3796 nrec, &fgBFKey, iv, BF_DECRYPT);
3797 (*str)[nrec] =
'\0';
3800 ::Info(
"TAuthenticate::SecureRecv",
"not compiled with SSL support:" 3801 " you should not have got here!");
3805 ::Info(
"TAuthenticate::SecureRecv",
"unknown key type (%d)",key);
3824 ::Info(
"TAuthenticate::DecodeRSAPublic",
3825 "enter: string length: %ld bytes", (
Long_t)strlen(rsaPubExport));
3828 Int_t klen = strlen(rsaPubExport);
3830 ::Info(
"TAuthenticate::DecodeRSAPublic",
3831 "key too long (%d): truncate to %d",klen,
kMAXPATHLEN);
3834 memcpy(str, rsaPubExport, klen);
3843 while (str[k] == 32) k++;
3845 if (str[k] ==
'#') {
3850 char *pd1 = strstr(str,
"#");
3851 char *pd2 = pd1 ? strstr(pd1 + 1,
"#") : (
char *)0;
3852 char *pd3 = pd2 ? strstr(pd2 + 1,
"#") : (
char *)0;
3853 if (pd1 && pd2 && pd3) {
3855 int l1 = (int) (pd2 - pd1 - 1);
3856 char *rsa_n_exp =
new char[l1 + 1];
3857 strlcpy(rsa_n_exp, pd1 + 1, l1+1);
3859 ::Info(
"TAuthenticate::DecodeRSAPublic",
3860 "got %ld bytes for rsa_n_exp", (
Long_t)strlen(rsa_n_exp));
3862 int l2 = (int) (pd3 - pd2 - 1);
3863 char *rsa_d_exp =
new char[l2 + 1];
3864 strlcpy(rsa_d_exp, pd2 + 1, 13);
3866 ::Info(
"TAuthenticate::DecodeRSAPublic",
3867 "got %ld bytes for rsa_d_exp", (
Long_t)strlen(rsa_d_exp));
3876 ::Info(
"TAuthenticate::DecodeRSAPublic",
"bad format for input string");
3885 BIO *bpub = BIO_new(BIO_s_mem());
3888 BIO_write(bpub,(
void *)str,strlen(str));
3891 if (!(rsatmp = PEM_read_bio_RSAPublicKey(bpub, 0, 0, 0))) {
3893 ::Info(
"TAuthenticate::DecodeRSAPublic",
3894 "unable to read pub key from bio");
3897 *rsassl = (
char *)rsatmp;
3899 ::Info(
"TAuthenticate::DecodeRSAPublic",
3900 "no space allocated for output variable");
3907 ::Info(
"TAuthenticate::DecodeRSAPublic",
"not compiled with SSL support:" 3908 " you should not have got here!");
3923 ::Info(
"TAuthenticate::SetRSAPublic",
3924 "enter: string length %ld bytes", (
Long_t)strlen(rsaPubExport));
3934 while (rsaPubExport[k0] == 32) k0++;
3943 if (rsaPubExport[k0] ==
'#' && rsaPubExport[k2] ==
'#') {
3944 char *p0 = (
char *)&rsaPubExport[k0];
3945 char *
p2 = (
char *)&rsaPubExport[k2];
3946 char *
p1 = strchr(p0+1,
'#');
3947 if (p1 > p0 && p1 < p2) {
3953 while (c < p1 && ((*c < 58 && *c > 47) || (*c < 91 && *c > 64)))
3957 while (c < p2 && ((*c < 58 && *c > 47) || (*c < 91 && *c > 64)))
3966 ::Info(
"TAuthenticate::SetRSAPublic",
" Key type: %d",rsakey);
3981 BF_set_key(&fgBFKey, klen, (
const unsigned char *)rsaPubExport);
3984 ::Info(
"TAuthenticate::SetRSAPublic",
3985 "not compiled with SSL support:" 3986 " you should not have got here!");
4006 ::Info(
"TAuthenticate::SendRSAPublicKey",
4007 "received key from server %ld bytes", (
Long_t)strlen(serverPubKey));
4016 RSA_free((RSA *)tmprsa);
4019 RSA *RSASSLServer = (RSA *)tmprsa;
4027 char buflen[20] = {0};
4034 }
else if (key == 1) {
4036 Int_t lcmax = RSA_size(RSASSLServer) - 11;
4041 Int_t lc = (ns > lcmax) ? lcmax : ns ;
4042 if ((ttmp = RSA_public_encrypt(lc,
4044 (
unsigned char *)&buftmp[ke],
4045 RSASSLServer,RSA_PKCS1_PADDING)) < 0) {
4048 ::Info(
"TAuthenticate::SendRSAPublicKey",
"SSL: error: '%s' ",errstr);
4058 ::Info(
"TAuthenticate::SendRSAPublicKey",
"not compiled with SSL support:" 4059 " you should not have got here!");
4064 ::Info(
"TAuthenticate::SendRSAPublicKey",
"unknown key type (%d)",key);
4067 RSA_free(RSASSLServer);
4078 ::Info(
"TAuthenticate::SendRSAPublicKey",
4079 "local: sent %d bytes (expected: %d)", nsen,ttmp);
4082 RSA_free(RSASSLServer);
4103 if (authrc &&
gDebug > 2)
4104 ::Info(
"TAuthenticate::ReadRootAuthrc",
"Checking file: %s", authrc);
4106 if (authrc &&
gDebug > 1)
4107 ::Info(
"TAuthenticate::ReadRootAuthrc",
4108 "file %s cannot be read (errno: %d)", authrc, errno);
4122 ::Info(
"TAuthenticate::ReadRootAuthrc",
"Checking system file:%s",authrc);
4125 ::Info(
"TAuthenticate::ReadRootAuthrc",
4126 "file %s cannot be read (errno: %d)", authrc, errno);
4136 stat(tRootAuthrc, &si);
4139 ::Info(
"TAuthenticate::ReadRootAuthrc",
4140 "file %s already read", authrc);
4156 TString filetmp =
"rootauthrc";
4159 ::Info(
"TAuthenticate::ReadRootAuthrc",
"got tmp file: %s open at 0x%lx",
4172 fd = fopen(authrc,
"r");
4175 ::Info(
"TAuthenticate::ReadRootAuthrc",
4176 "file %s cannot be open (errno: %d)", authrc, errno);
4187 while (fgets(line,
sizeof(line), fd) != 0) {
4194 if (line[strlen(line) - 1] ==
'\n')
4195 line[strlen(line) - 1] =
'\0';
4202 const size_t tmpSize = strlen(line) + 1;
4203 char *tmp =
new char[tmpSize];
4205 ::Error(
"TAuthenticate::ReadRootAuthrc",
4206 "could not allocate temporary buffer");
4209 strlcpy(tmp, line, tmpSize);
4210 char *nxt = strtok(tmp,
" ");
4212 if (!strcmp(nxt,
"proofserv") || cont) {
4222 proofserv +=
TString((
const char *)ph);
4243 if (server ==
"0" || server.
BeginsWith(
"sock"))
4245 else if (server ==
"1" || server.
BeginsWith(
"root"))
4247 else if (server ==
"2" || server.
BeginsWith(
"proof"))
4254 nxt = strtok(0,
" ");
4255 if (!strncmp(nxt,
"user",4)) {
4256 nxt = strtok(0,
" ");
4257 if (strncmp(nxt,
"list",4) && strncmp(nxt,
"method",6)) {
4259 nxt = strtok(0,
" ");
4264 TIter next(&tmpAuthInfo);
4274 tmpAuthInfo.
Add(ha);
4277 if (!strncmp(nxt,
"list",4)) {
4280 char *mth = strtok(0,
" ");
4283 if (strlen(mth) > 1) {
4286 if (met == -1 &&
gDebug > 2)
4287 ::Info(
"TAuthenticate::ReadRootAuthrc",
4288 "unrecognized method (%s): ", mth);
4292 if (met > -1 && met <
kMAXSEC)
4294 mth = strtok(0,
" ");
4299 }
else if (!strncmp(nxt,
"method",6)) {
4302 char *mth = strtok(0,
" ");
4304 if (strlen(mth) > 1) {
4307 if (met == -1 &&
gDebug > 2)
4308 ::Info(
"TAuthenticate::ReadRootAuthrc",
4309 "unrecognized method (%s): ", mth);
4313 if (met > -1 && met <
kMAXSEC) {
4314 const char *det = 0;
4315 nxt = strtok(0,
" ");
4317 det = (
const char *)strstr(line,nxt);
4326 if (tmp)
delete [] tmp;
4344 TList tmpproofauthinfo;
4345 if (proofserv.
Length() > 0) {
4346 char *tmps =
new char[proofserv.
Length()+1];
4347 strlcpy(tmps,proofserv.
Data(),proofserv.
Length()+1);
4348 char *nxt = strtok(tmps,
" ");
4350 TString tmp((
const char *)nxt);
4354 if ((pdd = tmp.
Index(
":")) == -1) {
4365 if ((pdd = tmp.
Index(
":")) == -1) {
4377 while (tmp.
Length() > 0) {
4379 if ((pdd = tmp.
Index(
":")) > -1)
4384 if (met == -1 &&
gDebug > 2)
4385 ::Info(
"TAuthenticate::ReadRootAuthrc",
4386 "unrecognized method (%s): ",meth.
Data());
4387 }
else if (meth.
Length() == 1) {
4388 met = atoi(meth.
Data());
4389 if (met > -1 && met <
kMAXSEC)
4412 tmpproofauthinfo.
Add(ha);
4414 nxt = strtok(0,
" ");
4434 const char sshid[3][20] = {
"/.ssh/identity",
"/.ssh/id_dsa",
"/.ssh/id_rsa" };
4435 const char netrc[2][20] = {
"/.netrc",
"/.rootnetrc" };
4445 "not properly logged on (getpwuid unable to find relevant info)!");
4453 for (; i < 2; i++) {
4459 out.
Form(
"pt:0 ru:1 us:%s",user.
Data());
4465 out.
Form(
"pt:0 ru:1 us:%s",user.
Data());
4473 out.
Form(
"pt:0 ru:0 us:%s",user.
Data());
4482 if (lApp != 0 && lApp->
Argc() > 9) {
4483 if (
gROOT->IsProofServ()) {
4490 struct shmid_ds shm_ds;
4491 if (shmctl(ShmId, IPC_STAT, &shm_ds) == 0)
4503 Cdir.
Resize(Cdir.Last(
'/')+1);
4505 out.
Form(
"pt=0 ru:0 cd:%s cf:%s kf:%s ad:%s",
4506 Cdir.Data(),Ucer.Data(),Ukey.Data(),Adir.Data());
4516 for (; i < 3; i++) {
4522 out.
Form(
"pt:0 ru:1 us:%s",user.
Data());
4527 out.
Form(
"pt:0 ru:0 us:%s",user.
Data());
4532 if (strlen(out) > 0)
4533 ::
Info(
"CheckProofAuth",
4534 "meth: %d ... is available: details: %s", cSec, out.
Data());
4537 "meth: %d ... is NOT available", cSec);
4555 if (!strcmp(user,ctx->
GetUser()) &&
4556 strncmp(
"AFS", ctx->
GetID(), 3))
4586 while ((hanew = (
THostAuth *)nxnew())) {
4608 while ((hanew = (
THostAuth *)nxnew())) {
4672 Info(
"ProofAuthSetup",
"Buffer not found: nothing to do");
4686 *mess >> user >> passwd >> pwhash >> srppwd >> rsakey;
4704 Info(
"ProofAuthSetup",
"List of THostAuth not found");
4725 fromProofAI =
kTRUE;
4736 if (!master || fromProofAI) {
4800 if (remoteOffSet > -1 && (upwd || srp))
4804 if ((
gEnv->
GetValue(
"Proofd.SendSRPPwd",0)) && (remoteOffSet > -1))
4807 if (srp && pwdctx) {
4808 if (strcmp(pwdctx->
GetPasswd(),
"") && remoteOffSet > -1)
4813 if ((upwd && pwdctx) || (srp && sndsrp)) {
4824 mess << user << passwd << pwhash << srppwd << keytyp;
4830 char *mbuf = mess.
Buffer();
4835 ::Info(
"ProofAuthSetup",
"sending %d bytes", messb64.
Length());
4838 if (remoteOffSet > -1) {
4840 ::Error(
"ProofAuthSetup",
"problems secure-sending message buffer");
4848 ::Error(
"ProofAuthSetup",
"plain: problems sending message length");
4852 ::Error(
"ProofAuthSetup",
"problems sending message buffer");
4885 Int_t retval = 0, ns = 0;
4888 Error(
"SendHostAuth",
"invalid input: socket undefined");
4903 Info(
"SendHostAuth",
"sent %d bytes (%s)",ns,buf.
Data());
4910 Info(
"SendHostAuth",
"sent %d bytes for closing",ns);
4924 Error(
"RecvHostAuth",
"invalid input: socket undefined");
4939 Error(
"RecvHostAuth",
"received: kind: %d (%d bytes)", kind, nr);
4943 Info(
"RecvHostAuth",
"received %d bytes (%s)",nr,buf);
4945 while (strcmp(buf,
"END")) {
4965 fromProofAI =
kTRUE;
4976 if (!master || fromProofAI) {
5015 Info(
"RecvHostAuth",
"Error: received: kind: %d (%d bytes)", kind, nr);
5019 Info(
"RecvHostAuth",
"received %d bytes (%s)",nr,buf);
5054 if (remoteOffSet > -1 && (upwd || srp))
5058 if ((
gEnv->
GetValue(
"Proofd.SendSRPPwd",0)) && (remoteOffSet > -1))
5061 if (srp && pwdctx) {
5062 if (strcmp(pwdctx->
GetPasswd(),
"") && remoteOffSet > -1)
5067 if ((upwd && pwdctx) || (srp && sndsrp)) {
5071 Error(
"OldAuthSetup",
"failed to send offset in RSA key");
5082 if (remoteOffSet > -1)
5083 Warning(
"OldAuthSetup",
"problems secure-sending pass hash %s",
5084 "- may result in failures");
5087 for (
int i = 0; i < passwd.
Length(); i++) {
5088 char inv = ~passwd(i);
5093 if (sock->
Send(mess) < 0) {
5094 Error(
"OldAuthSetup",
"failed to send inverted password");
5104 Error(
"OldAuthSetup",
"failed to send no offset notification in RSA key");
5111 mess << user << pwhash << srppwd << ord << conf;
5113 if (sock->
Send(mess) < 0) {
5114 Error(
"OldAuthSetup",
"failed to send ordinal and config info");
5118 if (proofdProto > 6) {
5124 Error(
"OldAuthSetup",
"failed to send HostAuth info");
5143 if (sock->
Recv(retval, kind) != 2*
sizeof(
Int_t)) {
5145 Info(
"OldProofServAuthSetup",
5146 "socket has been closed due to protocol mismatch - Exiting");
5163 if ((fKey = fopen(keyfile.
Data(),
"r"))) {
5164 Int_t klen = fread((
void *)pubkey,1,
sizeof(pubkey),fKey);
5166 Error(
"OldProofServAuthSetup",
5167 "failed to read public key from '%s'", keyfile.
Data());
5176 Error(
"OldProofServAuthSetup",
"failed to open '%s'", keyfile.
Data());
5185 Error(
"OldProofServAuthSetup",
"failed to receive password");
5191 }
else if (retval == -1) {
5195 if ((sock->
Recv(mess) <= 0) || !mess) {
5196 Error(
"OldProofServAuthSetup",
"failed to receive inverted password");
5202 for (
Int_t i = 0; i < passwd.Length(); i++) {
5203 char inv = ~passwd(i);
5204 passwd.Replace(i, 1, inv);
5212 if ((sock->
Recv(mess) <= 0) || !mess) {
5213 Error(
"OldProofServAuthSetup",
"failed to receive ordinal and config info");
5221 (*mess) >> user >> pwhash >> srppwd >> conf;
5224 (*mess) >> user >> pwhash >> srppwd >> ord >> conf;
5229 (*mess) >> user >> pwhash >> srppwd >> iord;
5233 (*mess) >> user >> pwhash >> srppwd >> ord >> conf;
5255 Error(
"OldProofServAuthSetup",
"failed to receive HostAuth info");
THostAuth * GetHostAuth() const
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.
Int_t GetServType() const
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.
void AsString(TString &out) const
Return a static string with all info in a serialized form.
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.
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
static RSA_num_sput_t RSA_num_sput()
const char * GetHostAddress() const
Returns the IP address string "%d.%d.%d.%d".
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 PrintEstablished() const
Print info about established authentication vis-a-vis of this Host.
static void RemoveSecContext(TRootSecContext *ctx)
Tool for removing SecContext ctx from THostAuth listed in fgAuthInfo or fgProofAuthInfo.
R__EXTERN const char * gRootdErrStr[]
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(* GlobusAuth_t)(TAuthenticate *auth, TString &user, TString &det)
virtual void Print(Option_t *option="F") const
If opt is "F" (default) print object content.
const char * GetHostName() 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.
Int_t(* Krb5Auth_t)(TAuthenticate *auth, TString &user, TString &det, Int_t version)
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.
static int auth_rand()
rand() implementation using /udev/random or /dev/random, if available
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.
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.
static void RemoveHostAuth(THostAuth *ha, Option_t *opt="")
Remove THostAuth instance from the list.
This class represents an Internet Protocol (IP) address.
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.
const char * GetSshUser(TString user) const
Method returning the user to be used for the ssh login.
This class implements a mutex interface.
static GlobusAuth_t GetGlobusAuthHook()
Static method returning the globus authorization hook.
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
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...
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.
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
const char * GetUser() const
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'.
void Print(Option_t *option="F") const
If opt is "F" (default) print object content.
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.
Bool_t IsActive() const
Check remote OffSet and expiring Date.
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)
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.
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]
static double p2(double t, double a, double b, double c)
TList * Established() const
virtual const char * Getenv(const char *env)
Get environment variable.
void Info(const char *location, const char *msgfmt,...)
TString & Append(const char *cs)
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
Return true if string ends with the specified string.
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.
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.
const char * GetPasswd() const
static Bool_t GetPromptUser()
Static method returning the prompt user settings.
Int_t GetRemoteProtocol() const
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.
Int_t(* CheckSecCtx_t)(const char *subj, TRootSecContext *ctx)
const Int_t kAUTH_REUSE_MSK
const char * GetUser() const
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 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 ...
TVirtualMutex * gAuthenticateMutex
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
R__EXTERN TSystem * gSystem
Bool_t IsA(const char *methodname)
Checks if this security context is for method named 'methname' Case sensitive.
static void SetRSAInit(Int_t init=1)
Static method setting RSA initialization flag.
Long_t ExecPlugin(int nargs, const T &... params)
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.
static TDatime GetGlobalExpDate()
Static method returning default expiring date for new validity contexts.
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
Int_t(* SecureAuth_t)(TAuthenticate *auth, const char *user, const char *passwd, const char *remote, TString &det, Int_t version)
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)
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
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.
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.
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)
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.
#define R__LOCKGUARD2(mutex)
static TList * GetAuthInfo()
Static method returning the list with authentication details.
TString & Remove(Ssiz_t pos)
const char * GetID() const
static void SetAuthReUse(Bool_t authreuse)
Set global AuthReUse flag.
void * GetContext() const
virtual Int_t GetEffectiveUid()
Returns the effective user id.
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...
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.
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...
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.
const char * GetHost() const
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' ...
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)
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Int_t GetMethod(Int_t idx) const
#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.
UInt_t Convert(Bool_t toGMT=kFALSE) const
Convert fDatime from TDatime format to the standard time_t format.
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 * in...
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
Bool_t R_ISDIR(Int_t mode)
TSecContext * GetSecContext() const
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.
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.
Int_t Atoi() const
Return integer value of string.
static RSA_encode_t RSA_encode()
static Bool_t fgReadHomeAuthrc
static Int_t GetClientProtocol()
Static method returning supported client protocol.
Bool_t IsDigit() const
Returns true if all characters in string are digits (0-9) or white spaces, i.e.
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 ...).
virtual Int_t GetSize() 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.
virtual void Print(Option_t *option="") const
Print object content.
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.
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.
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
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...
const char * Data() const
static const char * GetAuthMethod(Int_t idx)
Static method returning the method corresponding to idx.