00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157 #include "RConfigure.h"
00158 #include "RConfig.h"
00159
00160 #include <ctype.h>
00161 #include <fcntl.h>
00162 #include <pwd.h>
00163 #include <stdio.h>
00164 #include <string.h>
00165 #include <strings.h>
00166 #include <string>
00167 #include <stdlib.h>
00168 #include <unistd.h>
00169 #include <sys/types.h>
00170 #include <time.h>
00171 #include <sys/stat.h>
00172 #include <sys/socket.h>
00173 #include <sys/param.h>
00174 #include <netinet/in.h>
00175 #include <arpa/inet.h>
00176 #include <netdb.h>
00177 #include <errno.h>
00178 #include <sys/un.h>
00179 #include "snprintf.h"
00180
00181 #if defined(__CYGWIN__) && defined(__GNUC__)
00182 # define cygwingcc
00183 #endif
00184 #if defined(linux) || defined(__sun) || defined(__sgi) || \
00185 defined(_AIX) || defined(__FreeBSD__) || defined(__APPLE__) || \
00186 defined(__MACH__) || defined(cygwingcc) || defined(__OpenBSD__)
00187 #include <grp.h>
00188 #include <sys/types.h>
00189 #include <signal.h>
00190 #define ROOT_SIGNAL_INCLUDED
00191 #endif
00192
00193 #if defined(__alpha) && !defined(linux) && !defined(__FreeBSD__) && \
00194 !defined(__OpenBSD__)
00195 extern "C" int initgroups(const char *name, int basegid);
00196 #ifndef ROOT_SIGNAL_INCLUDED
00197 #include <signal.h>
00198 #endif
00199 #endif
00200
00201 #if defined(__sgi) && !defined(__GNUG__) && (SGI_REL<62)
00202 extern "C" {
00203 int seteuid(int euid);
00204 int setegid(int egid);
00205 }
00206 #endif
00207
00208 #if defined(_AIX)
00209 extern "C" {
00210
00211 int seteuid(uid_t euid);
00212 int setegid(gid_t egid);
00213 }
00214 #endif
00215
00216 #if defined(__sun)
00217 #if defined(R__SUNGCC3)
00218 extern "C" int gethostname(char *, unsigned int);
00219 #else
00220 extern "C" int gethostname(char *, int);
00221 #endif
00222 #endif
00223
00224 #include "proofdp.h"
00225 extern "C" {
00226 #include "rsadef.h"
00227 #include "rsalib.h"
00228 }
00229
00230
00231 int gDebug = 0;
00232
00233
00234
00235 const int kMaxSlaves = 32;
00236
00237 static std::string gAuthrc;
00238 static std::string gConfDir;
00239 static std::string gOpenHost;
00240 static std::string gRootBinDir;
00241 static std::string gRpdAuthTab;
00242 static std::string gTmpDir;
00243 static std::string gUser;
00244 static EService gService = kPROOFD;
00245 static int gProtocol = 14;
00246 static int gRemPid = -1;
00247 static std::string gReadHomeAuthrc = "0";
00248 static int gInetdFlag = 0;
00249 static int gMaster =-1;
00250 static int gRequireAuth = 1;
00251
00252 using namespace ROOT;
00253
00254
00255
00256
00257 void Err(int level, const char *msg, int size)
00258 {
00259 Perror((char *)msg, size);
00260 if (level > -1) NetSend(level, kROOTD_ERR);
00261 }
00262
00263 void ErrFatal(int level, const char *msg, int size)
00264 {
00265 Perror((char *)msg, size);
00266 if (level > -1) NetSend(msg, kMESS_STRING);
00267 exit(1);
00268 }
00269
00270 void ErrSys(int level, const char *msg, int size)
00271 {
00272 Perror((char *)msg, size);
00273 ErrFatal(level, msg, size);
00274 }
00275
00276
00277
00278 #if defined(__sun)
00279
00280 extern "C" { void ProofdTerm(int)
00281 {
00282
00283
00284 ErrorInfo("ProofdTerm: rootd.cxx: got a SIGTERM/SIGINT");
00285
00286 RpdAuthCleanup(0,0);
00287
00288 NetClose();
00289
00290 exit(0);
00291 }}
00292 #else
00293
00294 static void ProofdTerm(int)
00295 {
00296
00297
00298 ErrorInfo("ProofdTerm: rootd.cxx: got a SIGTERM/SIGINT");
00299
00300 RpdAuthCleanup(0,0);
00301
00302 NetClose();
00303
00304 exit(0);
00305 }
00306 #endif
00307
00308
00309 const char *RerouteUser()
00310 {
00311
00312
00313 std::string conffile = "proof.conf";
00314 FILE *proofconf;
00315
00316 if (getenv("HOME")) {
00317 conffile.insert(0,"/.");
00318 conffile.insert(0,getenv("HOME"));
00319
00320
00321 conffile[conffile.length()] = 0;
00322 }
00323 if (!(proofconf = fopen(conffile.c_str(), "r"))) {
00324 conffile = "/etc/";
00325 conffile.insert(0,gConfDir);
00326
00327
00328 conffile[conffile.length()] = 0;
00329 }
00330 if (proofconf || (proofconf = fopen(conffile.c_str(), "r")) != 0) {
00331
00332
00333 static char user_on_node[32];
00334 struct stat statbuf;
00335 char line[256];
00336 char node_name[kMaxSlaves][32];
00337 int nnodes = 0;
00338 int i;
00339
00340 strncpy(user_on_node, "any", 32);
00341 user_on_node[31] = 0;
00342
00343 while (fgets(line, sizeof(line), proofconf) != 0) {
00344 char word[4][64];
00345 if (line[0] == '#') continue;
00346
00347 int nword = sscanf(line, "%63s %63s %63s %63s",
00348 word[0], word[1], word[2], word[3]);
00349
00350
00351
00352
00353
00354 if (nword >= 2 && strcmp(word[0], "node") == 0) {
00355 if (gethostbyname(word[1]) != 0) {
00356 if (nnodes < kMaxSlaves) {
00357 if (strlen(word[1]) < 32) {
00358 strncpy(node_name[nnodes], word[1], 32);
00359 node_name[nnodes][31] = 0;
00360 }
00361 nnodes++;
00362 }
00363 }
00364 continue;
00365 }
00366
00367
00368
00369
00370
00371 if (nword >= 4 && strcmp(word[0], "user") == 0 &&
00372 strcmp(word[1], gUser.c_str()) == 0 &&
00373 strcmp(word[2], "on") == 0) {
00374
00375 if (strlen(word[3]) < 32) {
00376 strncpy(user_on_node, word[3], 32);
00377 user_on_node[31] = 0;
00378 }
00379 continue;
00380 }
00381 }
00382 fclose(proofconf);
00383
00384
00385 for (i = 0; i < nnodes; i++) {
00386 if (strcmp(node_name[i], user_on_node) == 0) {
00387 return user_on_node;
00388 }
00389 }
00390
00391
00392
00393
00394
00395 conffile = gConfDir + "/etc/next.node";
00396 proofconf = fopen(conffile.c_str(), "r");
00397 if (proofconf) {
00398 if (fstat(fileno(proofconf), &statbuf) == 0 &&
00399 difftime(time(0), statbuf.st_mtime) < 600) {
00400 if (fgets(line, sizeof(line), proofconf) != 0) {
00401 strncpy(user_on_node, line, 32);
00402 user_on_node[31] = 0;
00403 for (i = 0; i < nnodes; i++) {
00404 if (strcmp(node_name[i], user_on_node) == 0) {
00405 fclose(proofconf);
00406 return user_on_node;
00407 }
00408 }
00409 }
00410 }
00411 fclose(proofconf);
00412 }
00413 }
00414 return 0;
00415 }
00416
00417
00418 int RpdProofGetAuthSetup(char **abuf)
00419 {
00420
00421
00422 int nrec = -1;
00423
00424 if (RpdGetOffSet() > -1) {
00425 if ((nrec = RpdSecureRecv(abuf)) < 0) {
00426 ErrorInfo("RpdProofGetAuthSetup: sec: problems receiving buf");
00427 return -1;
00428 }
00429 } else {
00430
00431 EMessageTypes kind;
00432 char buflen[20];
00433 if (NetRecv(buflen, 20, kind) < 0) {
00434 ErrorInfo("RpdProofGetAuthSetup: plain: problems receiving buf length");
00435 return -1;
00436 }
00437 int len = atoi(buflen);
00438
00439
00440 *abuf = new char[len + 1];
00441 if ((nrec = NetRecvRaw(*abuf, len)) < 0) {
00442 ErrorInfo("RpdProofGetAuthSetup: plain: problems receiving buf");
00443 delete[] *abuf;
00444 return -1;
00445 }
00446 (*abuf)[len] = 0;
00447 }
00448
00449 if (gDebug > 1)
00450 ErrorInfo("RpdProofGetAuthSetup: proto: %d len: %d",
00451 RpdGetAuthProtocol(), nrec);
00452
00453 return nrec;
00454 }
00455
00456
00457 void ProofdExec()
00458 {
00459
00460
00461
00462 char *argvv[3];
00463 std::string arg0;
00464 std::string msg;
00465
00466 #ifdef R__DEBUG
00467 int debug = 1;
00468 while (debug)
00469 ;
00470 #endif
00471
00472
00473 NetGetRemoteHost(gOpenHost);
00474
00475
00476 int sockFd = NetGetSockFd();
00477
00478 if (gDebug > 0)
00479 ErrorInfo("ProofdExec: gOpenHost = %s", gOpenHost.c_str());
00480
00481 if (gDebug > 0)
00482 ErrorInfo("ProofdExec: gConfDir = %s", gConfDir.c_str());
00483
00484
00485 const char *node_name;
00486 if (gMaster && (node_name = RerouteUser()) != 0) {
00487
00488
00489 char host_name[32];
00490 gethostname(host_name, sizeof(host_name));
00491
00492
00493 if (strcmp(host_name, node_name) != 0) {
00494 struct hostent *host = gethostbyname(host_name);
00495 struct hostent *node;
00496
00497 if (host != 0) {
00498 struct in_addr *host_addr = (struct in_addr*)(host->h_addr);
00499 char host_numb[32];
00500 if (strlen(inet_ntoa(*host_addr)) < 32) {
00501 strncpy(host_numb, inet_ntoa(*host_addr), 32);
00502 host_numb[31] = 0;
00503 }
00504
00505 if ((node = gethostbyname(node_name)) != 0) {
00506 struct in_addr *node_addr = (struct in_addr*)(node->h_addr);
00507 char node_numb[32];
00508 strncpy(node_numb, inet_ntoa(*node_addr), 32);
00509 node_numb[31] = 0;
00510
00511
00512
00513
00514 if (strcmp(host_numb, node_numb) != 0) {
00515 msg = std::string("Reroute:").append(node_numb);
00516 NetSend(msg.c_str());
00517 exit(0);
00518 }
00519 }
00520 }
00521 }
00522 }
00523
00524
00525
00526 if (RpdGetClientProtocol() > 12 && gRequireAuth == 1) {
00527 char *authbuff = 0;
00528 int lab = 0;
00529 if ((lab = RpdProofGetAuthSetup(&authbuff)) > 0) {
00530
00531 char *rootproofauthsetup = new char[20+strlen(authbuff)];
00532 snprintf(rootproofauthsetup, 20 + strlen(authbuff), "ROOTPROOFAUTHSETUP=%s", authbuff);
00533 putenv(rootproofauthsetup);
00534 } else if (lab < 0) {
00535 ErrorInfo("ProofdExec: problems receiving auth buffer");
00536 }
00537 if (authbuff) delete[] authbuff;
00538 }
00539
00540 if(RpdGetClientProtocol() >= 16) {
00541 void *vb = 0;
00542 Int_t len = 0;
00543 EMessageTypes kind = kMESS_ANY;
00544
00545 int rc = NetRecvAllocate(vb, len, kind);
00546
00547 if (rc < 0) {
00548 ErrorInfo("ProofdExec: error receiving kPROOF_SETENV message");
00549 return;
00550 }
00551
00552 if (kind != kPROOF_SETENV) {
00553 ErrorInfo("ProofdExec: expecting kPROOF_SETENV, got %d", kind);
00554 return;
00555
00556 }
00557
00558 char *buf = (char *) vb;
00559 char *end = buf + len;
00560 const char name[] = "PROOF_ALLVARS=";
00561 int alen = strlen(name)+len;
00562 char *all = new char[alen];
00563 strlcpy(all, name, alen);
00564 while (buf < end) {
00565 if (gDebug > 0) ErrorInfo("ProofdExec: setting: %s", buf);
00566 char *p = index(buf, '=');
00567 if (p) {
00568 if (buf != (char *) vb) strlcat(all, ",", alen);
00569 strlcat(all, buf, alen);
00570 putenv(buf);
00571 }
00572 buf += strlen(buf) + 1;
00573 }
00574 if (gDebug > 0) ErrorInfo("ProofdExec: setting: %s", all);
00575 putenv(all);
00576 }
00577
00578 if (gDebug > 0)
00579 ErrorInfo("ProofdExec: send Okay (SockFd: %d)", sockFd);
00580 NetSend("Okay");
00581
00582
00583 if (sockFd == 0 || sockFd == 1 || sockFd == 2) {
00584 Int_t fd;
00585 struct stat stbuf;
00586 for (fd = 3; fd < NOFILE; fd++) {
00587 ResetErrno();
00588 if (fstat(fd, &stbuf) == -1 && GetErrno() == EBADF) {
00589 if (dup2(sockFd, fd) < 0)
00590 ErrorInfo("ProofdExec: problems executing 'dup2' (errno: %d)", errno);
00591 close(sockFd);
00592 sockFd = fd;
00593 close(2);
00594 close(1);
00595 close(0);
00596 RpdSetSysLogFlag(1);
00597 break;
00598 }
00599 }
00600
00601 if (fd == NOFILE) {
00602 NetSend("Cannot start proofserver -- no free filedescriptor");
00603 return;
00604 }
00605 }
00606
00607
00608
00609
00610 char *rootconf = new char[13+gConfDir.length()];
00611 snprintf(rootconf, 13+gConfDir.length(), "ROOTCONFDIR=%s", gConfDir.c_str());
00612 putenv(rootconf);
00613 if (gDebug > 0)
00614 ErrorInfo("ProofdExec: setting: %s", rootconf);
00615
00616 char *roottmp = new char[12+gTmpDir.length()];
00617 snprintf(roottmp, 12+gTmpDir.length(), "ROOTTMPDIR=%s", gTmpDir.c_str());
00618 putenv(roottmp);
00619 if (gDebug > 0)
00620 ErrorInfo("ProofdExec: setting: %s", roottmp);
00621
00622 char *rootentity = new char[gUser.length()+gOpenHost.length()+33];
00623 snprintf(rootentity, gUser.length()+gOpenHost.length()+33,
00624 "ROOTENTITY=%s:%d@%s", gUser.c_str(), gRemPid, gOpenHost.c_str());
00625 putenv(rootentity);
00626 if (gDebug > 2)
00627 ErrorInfo("ProofdExec: setting: %s", rootentity);
00628
00629 char *rootopensock = new char[33];
00630 snprintf(rootopensock, 33, "ROOTOPENSOCK=%d", sockFd);
00631 putenv(rootopensock);
00632 if (gDebug > 0)
00633 ErrorInfo("ProofdExec: setting: %s", rootopensock);
00634
00635 char *roothomeauthrc = new char[20];
00636 snprintf(roothomeauthrc, 20, "ROOTHOMEAUTHRC=%s", gReadHomeAuthrc.c_str());
00637 putenv(roothomeauthrc);
00638 if (gDebug > 0)
00639 ErrorInfo("ProofdExec: setting: %s", roothomeauthrc);
00640
00641 #ifdef R__GLBS
00642
00643 char *shmidcred = new char[25];
00644 snprintf(shmidcred, 25, "ROOTSHMIDCRED=%d", RpdGetShmIdCred());
00645 putenv(shmidcred);
00646 if (gDebug > 0)
00647 ErrorInfo("ProofdExec: setting: %s", shmidcred);
00648 #endif
00649
00650
00651 arg0 = gRootBinDir + "/proofserv";
00652 argvv[0] = (char *)arg0.c_str();
00653 argvv[1] = (char *)(gMaster ? "proofserv" : "proofslave");
00654 argvv[2] = 0;
00655
00656 #ifndef ROOTPREFIX
00657 char *rootsys = new char[9+gConfDir.length()];
00658 snprintf(rootsys, 9+gConfDir.length(), "ROOTSYS=%s", gConfDir.c_str());
00659 putenv(rootsys);
00660 if (gDebug > 0)
00661 ErrorInfo("ProofdExec: setting: %s", rootsys);
00662 #endif
00663 #ifndef ROOTLIBDIR
00664 char *oldpath, *ldpath;
00665 # if defined(__hpux) || defined(_HIUX_SOURCE)
00666 if ((oldpath = getenv("SHLIB_PATH")) && strlen(oldpath) > 0) {
00667 ldpath = new char[32+gConfDir.length()+strlen(oldpath)];
00668 snprintf(ldpath, 32+gConfDir.length()+strlen(oldpath),
00669 "SHLIB_PATH=%s/lib:%s", gConfDir.c_str(), oldpath);
00670 } else {
00671 ldpath = new char[32+gConfDir.length()];
00672 snprintf(ldpath, 32+gConfDir.length(), "SHLIB_PATH=%s/lib", gConfDir.c_str());
00673 }
00674 # elif defined(_AIX)
00675 if ((oldpath = getenv("LIBPATH")) && strlen(oldpath) > 0) {
00676 ldpath = new char[32+gConfDir.length()+strlen(oldpath)];
00677 snprintf(ldpath, 32+gConfDir.length()+strlen(oldpath),
00678 "LIBPATH=%s/lib:%s", gConfDir.c_str(), oldpath);
00679 } else {
00680 ldpath = new char[32+gConfDir.length()];
00681 snprintf(ldpath, 32+gConfDir.length(), "LIBPATH=%s/lib", gConfDir.c_str());
00682 }
00683 # elif defined(__APPLE__)
00684 if ((oldpath = getenv("DYLD_LIBRARY_PATH")) && strlen(oldpath) > 0) {
00685 ldpath = new char[32+gConfDir.length()+strlen(oldpath)];
00686 snprintf(ldpath, 32+gConfDir.length()+strlen(oldpath),
00687 "DYLD_LIBRARY_PATH=%s/lib:%s", gConfDir.c_str(), oldpath);
00688 } else {
00689 ldpath = new char[32+gConfDir.length()];
00690 snprintf(ldpath, 32+gConfDir.length(), "DYLD_LIBRARY_PATH=%s/lib", gConfDir.c_str());
00691 }
00692 # else
00693 if ((oldpath = getenv("LD_LIBRARY_PATH")) && strlen(oldpath) > 0) {
00694 ldpath = new char[32+gConfDir.length()+strlen(oldpath)];
00695 snprintf(ldpath, 32+gConfDir.length()+strlen(oldpath),
00696 "LD_LIBRARY_PATH=%s/lib:%s", gConfDir.c_str(), oldpath);
00697 } else {
00698 ldpath = new char[32+gConfDir.length()];
00699 snprintf(ldpath, 32+gConfDir.length(), "LD_LIBRARY_PATH=%s/lib", gConfDir.c_str());
00700 }
00701 # endif
00702 putenv(ldpath);
00703 if (gDebug > 0)
00704 ErrorInfo("ProofdExec: setting: %s", ldpath);
00705 #endif
00706
00707
00708
00709
00710 char *authrc = 0;
00711 if (gAuthrc.length()) {
00712 if (gDebug > 0)
00713 ErrorInfo("ProofdExec: setting ROOTAUTHRC to %s",gAuthrc.c_str());
00714 authrc = new char[15+gAuthrc.length()];
00715 snprintf(authrc, 15+gAuthrc.length(), "ROOTAUTHRC=%s", gAuthrc.c_str());
00716 putenv(authrc);
00717 if (gDebug > 0)
00718 ErrorInfo("ProofdExec: setting: %s", authrc);
00719 }
00720
00721
00722 char *keyfile = new char[15+strlen(RpdGetKeyRoot())];
00723 snprintf(keyfile, 15+strlen(RpdGetKeyRoot()), "ROOTKEYFILE=%s",RpdGetKeyRoot());
00724 putenv(keyfile);
00725 if (gDebug > 2)
00726 ErrorInfo("ProofdExec: setting: %s", keyfile);
00727
00728 if (gDebug > 0)
00729 ErrorInfo("ProofdExec: execv(%s, %s)", argvv[0], argvv[1]);
00730
00731
00732 execv(arg0.c_str(), argvv);
00733
00734
00735 msg = "Cannot start PROOF server --- make sure " + arg0 + " exists!";
00736 NetSend(msg.c_str());
00737 }
00738
00739
00740
00741 void Usage(const char* name, int rc)
00742 {
00743 fprintf(stderr, "\nUsage: %s [options] [rootsys-dir]\n", name);
00744 fprintf(stderr, "\nOptions:\n");
00745 fprintf(stderr, "\t-A [<rootauthrc>] Use $HOME/.rootauthrc or specified file\n");
00746 fprintf(stderr, "\t (see documentation)\n");
00747 fprintf(stderr, "\t-b tcpwindowsize Specify the tcp window size in bytes\n");
00748 #ifdef R__GLBS
00749 fprintf(stderr, "\t-C hostcertfile Specify the location of the Globus host certificate\n");
00750 #endif
00751 fprintf(stderr, "\t-d level set debug level [0..3]\n");
00752 fprintf(stderr, "\t-D rootdaemonrc Use alternate rootdaemonrc file\n");
00753 fprintf(stderr, "\t (see documentation)\n");
00754 fprintf(stderr, "\t-E Ignored for backward compatibility\n");
00755 fprintf(stderr, "\t-f Run in foreground\n");
00756 #ifdef R__GLBS
00757 fprintf(stderr, "\t-G gridmapfile Specify the location of th Globus gridmap\n");
00758 #endif
00759 fprintf(stderr, "\t-i Running from inetd\n");
00760 fprintf(stderr, "\t-noauth Do not require client authentication\n");
00761 fprintf(stderr, "\t-p port# Specify a different port to listen on\n");
00762 fprintf(stderr, "\t-s sshd_port# Specify the port for the sshd daemon\n");
00763 #ifdef R__KRB5
00764 fprintf(stderr, "\t-S keytabfile Use an alternate keytab file\n");
00765 #endif
00766 fprintf(stderr, "\t-T <tmpdir> Use an alternate temp dir\n");
00767 fprintf(stderr, "\t-w Do not check /etc/hosts.equiv and $HOME/.rhosts\n");
00768
00769 exit(rc);
00770 }
00771
00772
00773 int main(int argc, char **argv)
00774 {
00775 char *s;
00776 int checkhostsequiv = 1;
00777 int tcpwindowsize = 65535;
00778 int sshdport = 22;
00779 int port1 = 0;
00780 int port2 = 0;
00781 int reuseallow = 0x1F;
00782 int foregroundflag = 0;
00783 std::string altSRPpass = "";
00784 std::string daemonrc = "";
00785 std::string rootetcdir = "";
00786 #ifdef R__GLBS
00787 std::string gridmap = "";
00788 std::string hostcertconf = "";
00789 #endif
00790 char *progname = argv[0];
00791
00792
00793 RpdSetErrorHandler(Err, ErrSys, ErrFatal);
00794
00795
00796 ErrorInit(argv[0]);
00797
00798
00799 RpdSetSysLogFlag(1);
00800
00801
00802
00803
00804 int i = 1;
00805 for (i = 1; i < argc; i++) {
00806 if (!strncmp(argv[i],"-f",2))
00807 foregroundflag = 1;
00808 if (!strncmp(argv[i],"-i",2))
00809 gInetdFlag = 1;
00810 }
00811 if (foregroundflag) {
00812 if (isatty(0) && isatty(1)) {
00813 RpdSetSysLogFlag(0);
00814 ErrorInfo("main: running in foreground mode:"
00815 " sending output to stderr");
00816 }
00817 if (gInetdFlag)
00818 Error(ErrFatal,-1,"-i and -f options are incompatible");
00819 }
00820
00821
00822 signal(SIGTERM, ProofdTerm);
00823 signal(SIGINT, ProofdTerm);
00824
00825 while (--argc > 0 && (*++argv)[0] == '-')
00826 for (s = argv[0]+1; *s != 0; s++)
00827 switch (*s) {
00828
00829 case 'A':
00830 gReadHomeAuthrc = std::string("1");
00831
00832
00833 if((*(argv+1)) && (*(argv+1))[0] != '-') {
00834 gAuthrc = std::string(*(argv+1));
00835 struct stat st;
00836 if (stat(gAuthrc.c_str(),&st) == -1 || !S_ISREG(st.st_mode)) {
00837
00838 gAuthrc.erase();
00839 } else {
00840
00841 argc--;
00842 argv++;
00843 }
00844 }
00845 break;
00846
00847 case 'b':
00848 if (--argc <= 0) {
00849 Error(ErrFatal,-1,"-b requires a buffersize in bytes as"
00850 " argument");
00851 }
00852 tcpwindowsize = atoi(*++argv);
00853 break;
00854 #ifdef R__GLBS
00855 case 'C':
00856 if (--argc <= 0) {
00857 Error(ErrFatal,-1,"-C requires a file name for the host"
00858 " certificates file location");
00859 }
00860 hostcertconf = std::string(*++argv);
00861 break;
00862 #endif
00863 case 'd':
00864 if (--argc <= 0) {
00865 Error(ErrFatal,-1,"-d requires a debug level as argument");
00866 }
00867 gDebug = atoi(*++argv);
00868 break;
00869
00870 case 'D':
00871 if (--argc <= 0) {
00872 Error(ErrFatal, kErrFatal,"-D requires a file path name"
00873 " for the file defining access rules");
00874 }
00875 daemonrc = std::string(*++argv);
00876 break;
00877
00878 case 'E':
00879 Error(ErrFatal, kErrFatal,"Option '-E' is now dummy"
00880 " - ignored (see proofd/src/proofd.cxx for"
00881 " additional details)");
00882 break;
00883
00884 case 'f':
00885 if (gInetdFlag) {
00886 Error(ErrFatal,-1,"-i and -f options are incompatible");
00887 }
00888 foregroundflag = 1;
00889 break;
00890 #ifdef R__GLBS
00891 case 'G':
00892 if (--argc <= 0) {
00893 Error(ErrFatal,-1,"-G requires a file name for the gridmap"
00894 " file");
00895 }
00896 gridmap = std::string(*++argv);
00897 break;
00898 #endif
00899 case 'h':
00900 Usage(progname, 0);
00901 break;
00902
00903 case 'i':
00904 if (foregroundflag) {
00905 Error(ErrFatal,-1,"-i and -f options are incompatible");
00906 }
00907 gInetdFlag = 1;
00908 break;
00909
00910 case 'n':
00911 if (!strncmp(argv[0]+1,"noauth",6)) {
00912 gRequireAuth = 0;
00913 s += 5;
00914 }
00915 break;
00916
00917 case 'p':
00918 if (--argc <= 0) {
00919 Error(ErrFatal,-1,"-p requires a port number as argument");
00920 }
00921 char *p;
00922 port1 = strtol(*++argv, &p, 10);
00923 if (*p == '-') {
00924 p++;
00925 port2 = strtol(p, &p, 10);
00926 } else if (*p == '\0')
00927 port2 = port1;
00928 if (*p != '\0' || port2 < port1 || port2 < 0) {
00929 Error(ErrFatal,kErrFatal,"invalid port number or range: %s",
00930 *argv);
00931 }
00932 break;
00933
00934 case 'P':
00935 if (--argc <= 0) {
00936 Error(ErrFatal,kErrFatal,"-P requires a file name for SRP"
00937 " password file");
00938 }
00939 altSRPpass = std::string(*++argv);
00940 break;
00941
00942 case 'R':
00943 if (--argc <= 0) {
00944 Error(ErrFatal,kErrFatal,"-R requires a hex but mask as"
00945 " argument");
00946 }
00947 reuseallow = strtol(*++argv, (char **)0, 16);
00948 break;
00949
00950 case 's':
00951 if (--argc <= 0) {
00952 Error(ErrFatal,kErrFatal,"-s requires as argument a port"
00953 " number for the sshd daemon");
00954 }
00955 sshdport = atoi(*++argv);
00956 break;
00957 #ifdef R__KRB5
00958 case 'S':
00959 if (--argc <= 0) {
00960 Error(ErrFatal,-1,"-S requires a path to your keytab\n");
00961 }
00962 RpdSetKeytabFile((const char *)(*++argv));
00963 break;
00964 #endif
00965 case 'T':
00966 if (--argc <= 0) {
00967 Error(ErrFatal,kErrFatal,"-T requires a dir path for"
00968 " temporary files [/usr/tmp]");
00969 }
00970 gTmpDir = std::string(*++argv);
00971 break;
00972
00973 case 'w':
00974 checkhostsequiv = 0;
00975 break;
00976
00977 default:
00978 if (!foregroundflag) fprintf(stderr, "\nUnknown command line option: %c\n", *s);
00979 Error(0, -1, "unknown command line option: %c", *s);
00980 Usage(progname, 1);
00981 }
00982
00983
00984 if (!gTmpDir.length())
00985 gTmpDir = "/usr/tmp";
00986 if (access(gTmpDir.c_str(), W_OK) == -1)
00987 gTmpDir = "/tmp";
00988
00989 if (argc > 0) {
00990 gConfDir = std::string(*argv);
00991 } else {
00992
00993 #ifndef ROOTDATADIR
00994 if (getenv("ROOTSYS")) {
00995 gConfDir = getenv("ROOTSYS");
00996 if (gDebug > 0)
00997 ErrorInfo("main: no config directory specified using ROOTSYS (%s)",
00998 gConfDir.c_str());
00999 } else {
01000 Error(ErrFatal, -1, "main: no config directory specified");
01001 }
01002 #else
01003 gConfDir = ROOTDATADIR;
01004 #endif
01005 }
01006 #ifdef ROOTBINDIR
01007 gRootBinDir= ROOTBINDIR;
01008 #endif
01009 #ifdef ROOTETCDIR
01010 rootetcdir= ROOTETCDIR;
01011 #endif
01012
01013
01014 if (!gRootBinDir.length())
01015 gRootBinDir = std::string(gConfDir).append("/bin");
01016
01017
01018 std::string arg0 = std::string(gRootBinDir).append("/proofserv");
01019 if (access(arg0.c_str(), X_OK) == -1) {
01020 Error(ErrFatal,-1,"main: incorrect config directory specified (%s)",
01021 gConfDir.c_str());
01022 }
01023
01024 if (gRootBinDir.length()) {
01025 char *tmp = new char[15 + gRootBinDir.length()];
01026 snprintf(tmp, 15 + gRootBinDir.length(), "ROOTBINDIR=%s", gRootBinDir.c_str());
01027 putenv(tmp);
01028 }
01029
01030
01031 if (!rootetcdir.length())
01032 rootetcdir = std::string(gConfDir).append("/etc");
01033
01034 if (rootetcdir.length()) {
01035 char *tmp = new char[15 + rootetcdir.length()];
01036 snprintf(tmp, 15 + rootetcdir.length(), "ROOTETCDIR=%s", rootetcdir.c_str());
01037 putenv(tmp);
01038 }
01039
01040
01041 if (daemonrc.length()) {
01042 char *tmp = new char[15+daemonrc.length()];
01043 snprintf(tmp, 15+daemonrc.length(), "ROOTDAEMONRC=%s", daemonrc.c_str());
01044 putenv(tmp);
01045 }
01046 #ifdef R__GLBS
01047
01048 if (gridmap.length()) {
01049 char *tmp = new char[15+gridmap.length()];
01050 snprintf(tmp, 15+gridmap.length(), "GRIDMAP=%s", gridmap.c_str());
01051 putenv(tmp);
01052 }
01053
01054 if (hostcertconf.length()) {
01055 char *tmp = new char[15+hostcertconf.length()];
01056 snprintf(tmp, 15+hostcertconf.length(), "ROOTHOSTCERT=%s", hostcertconf.c_str());
01057 putenv(tmp);
01058 }
01059 #endif
01060
01061
01062 int proofdparentid = -1;
01063 if (!gInetdFlag)
01064 proofdparentid = getpid();
01065 else
01066 proofdparentid = getppid();
01067
01068
01069 unsigned int options = kDMN_RQAUTH | kDMN_HOSTEQ | kDMN_SYSLOG ;
01070
01071 if (!gRequireAuth)
01072 options &= ~kDMN_RQAUTH;
01073 if (!checkhostsequiv)
01074 options &= ~kDMN_HOSTEQ;
01075 if (foregroundflag)
01076 options &= ~kDMN_SYSLOG;
01077 RpdInit(gService, proofdparentid, gProtocol, options,
01078 reuseallow, sshdport,
01079 gTmpDir.c_str(),altSRPpass.c_str(),2);
01080
01081
01082 if (RpdGenRSAKeys(0)) {
01083 Error(Err, -1, "proofd: unable to generate local RSA keys");
01084 }
01085
01086 if (!gInetdFlag) {
01087
01088
01089
01090
01091
01092 if (!foregroundflag)
01093 DaemonStart(1, 0, gService);
01094
01095 NetInit(gService, port1, port2, tcpwindowsize);
01096 }
01097
01098 if (gDebug > 0)
01099 ErrorInfo("main: pid = %d, gInetdFlag = %d", getpid(), gInetdFlag);
01100
01101
01102
01103
01104
01105
01106 while (1) {
01107 if (NetOpen(gInetdFlag, gService) == 0) {
01108
01109
01110 if ((gMaster = RpdInitSession(gService, gUser, gRemPid)) < 0) {
01111 if (gMaster == -1)
01112 Error(ErrFatal, -1, "proofd: failure initializing session");
01113 else if (gMaster == -2)
01114
01115 exit(0);
01116 }
01117
01118 ProofdExec();
01119 NetClose();
01120 exit(0);
01121 }
01122
01123
01124
01125 }
01126
01127 }