00001
00002
00003
00004
00005
00006
00007
00008 #ifndef windows_platform
00009 #include <sys/wait.h>
00010 #endif
00011
00012
00013 #include "miscServerFunct.h"
00014 #include "dataObjOpen.h"
00015 #include "dataObjLseek.h"
00016 #include "dataObjOpr.h"
00017 #include "dataObjClose.h"
00018 #include "dataObjWrite.h"
00019 #include "dataObjRead.h"
00020 #include "rcPortalOpr.h"
00021 #include "initServer.h"
00022 #ifdef PARA_OPR
00023 #include <boost/thread/thread.hpp>
00024 #endif
00025 #if !defined(solaris_platform)
00026 char *__loc1;
00027 #endif
00028 #include "rsGlobalExtern.h"
00029 #include "rcGlobalExtern.h"
00030
00031 #include "md5.h"
00032
00033
00034
00035 #include "eirods_stacktrace.h"
00036 #include "eirods_network_factory.h"
00037 #include "eirods_buffer_encryption.h"
00038 #include "eirods_client_server_negotiation.h"
00039
00040 #include <iomanip>
00041
00042 int
00043 svrToSvrConnectNoLogin (rsComm_t *rsComm, rodsServerHost_t *rodsServerHost)
00044 {
00045 rErrMsg_t errMsg;
00046 int reconnFlag;
00047
00048
00049 if (rodsServerHost->conn == NULL) {
00050 if (getenv (RECONNECT_ENV) != NULL) {
00051 reconnFlag = RECONN_TIMEOUT;
00052 } else {
00053 reconnFlag = NO_RECONN;
00054 }
00055 rodsServerHost->conn = _rcConnect (rodsServerHost->hostName->name,
00056 ((zoneInfo_t *) rodsServerHost->zoneInfo)->portNum,
00057 rsComm->myEnv.rodsUserName, rsComm->myEnv.rodsZone,
00058 rsComm->clientUser.userName, rsComm->clientUser.rodsZone, &errMsg,
00059 rsComm->connectCnt, reconnFlag);
00060
00061 if (rodsServerHost->conn == NULL) {
00062 if (errMsg.status < 0) {
00063 return (errMsg.status);
00064 } else {
00065 return (SYS_SVR_TO_SVR_CONNECT_FAILED - errno);
00066 }
00067 }
00068 }
00069
00070 return (rodsServerHost->localFlag);
00071 }
00072
00073 int
00074 svrToSvrConnect (rsComm_t *rsComm, rodsServerHost_t *rodsServerHost)
00075 {
00076 int status;
00077
00078 status = svrToSvrConnectNoLogin (rsComm, rodsServerHost);
00079
00080 if (status < 0) {
00081 return status;
00082 }
00083
00084 status = clientLogin (rodsServerHost->conn);
00085 if (status < 0) {
00086 rodsLog (LOG_NOTICE,
00087 "svrToSvrConnect: clientLogin to %s failed",
00088 rodsServerHost->hostName->name);
00089 return (status);
00090 } else {
00091 return (rodsServerHost->localFlag);
00092 }
00093 }
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105 int
00106 setupSrvPortalForParaOpr (rsComm_t *rsComm, dataOprInp_t *dataOprInp,
00107 int oprType, portalOprOut_t **portalOprOut)
00108 {
00109 portalOprOut_t *myDataObjPutOut;
00110 int portalSock;
00111 int proto;
00112
00113 #ifdef RBUDP_TRANSFER
00114 if (getValByKey (&dataOprInp->condInput, RBUDP_TRANSFER_KW) != NULL) {
00115 proto = SOCK_DGRAM;
00116 } else {
00117 proto = SOCK_STREAM;
00118 }
00119 #else
00120 proto = SOCK_STREAM;
00121 #endif
00122
00123 myDataObjPutOut = (portalOprOut_t *) malloc (sizeof (portalOprOut_t));
00124 memset (myDataObjPutOut, 0, sizeof (portalOprOut_t));
00125
00126 *portalOprOut = myDataObjPutOut;
00127
00128 if (getValByKey (&dataOprInp->condInput, STREAMING_KW) != NULL ||
00129 proto == SOCK_DGRAM) {
00130
00131 myDataObjPutOut->numThreads = 1;
00132 } else {
00133 myDataObjPutOut->numThreads = getNumThreads (rsComm,
00134 dataOprInp->dataSize, dataOprInp->numThreads,
00135 &dataOprInp->condInput,
00136
00137 getValByKey (&dataOprInp->condInput, RESC_HIER_STR_KW), NULL);
00138 }
00139
00140 if (myDataObjPutOut->numThreads == 0) {
00141 return 0;
00142 } else {
00143 portalOpr_t *myPortalOpr;
00144
00145
00146 portalSock = createSrvPortal (rsComm, &myDataObjPutOut->portList,
00147 proto);
00148 if (portalSock < 0) {
00149 rodsLog (LOG_NOTICE,
00150 "setupSrvPortalForParaOpr: createSrvPortal error, ststus = %d",
00151 portalSock);
00152 myDataObjPutOut->status = portalSock;
00153 return portalSock;
00154 }
00155 myPortalOpr = rsComm->portalOpr =
00156 (portalOpr_t *) malloc (sizeof (portalOpr_t));
00157 myPortalOpr->oprType = oprType;
00158 myPortalOpr->portList = myDataObjPutOut->portList;
00159 myPortalOpr->dataOprInp = *dataOprInp;
00160 memset (&dataOprInp->condInput, 0, sizeof (dataOprInp->condInput));
00161 myPortalOpr->dataOprInp.numThreads = myDataObjPutOut->numThreads;
00162 }
00163
00164 return (0);
00165 }
00166
00167
00168
00169
00170
00171
00172 int
00173 createSrvPortal (rsComm_t *rsComm, portList_t *thisPortList, int proto)
00174 {
00175 int lsock = -1;
00176 int lport = 0;
00177 char *laddr = NULL;
00178 int udpsock = -1;
00179 int udpport = 0;
00180 char *udpaddr = NULL;
00181
00182
00183 if (proto != SOCK_DGRAM && proto != SOCK_STREAM) {
00184 rodsLog (LOG_ERROR,
00185 "createSrvPortal: invalid input protocol %d", proto);
00186 return SYS_INVALID_PROTOCOL_TYPE;
00187 }
00188
00189 if ((lsock = svrSockOpenForInConn (rsComm, &lport, &laddr,
00190 SOCK_STREAM)) < 0) {
00191 rodsLog (LOG_ERROR,
00192 "createSrvPortal: svrSockOpenForInConn failed: status=%d",
00193 lsock);
00194 return lsock;
00195 }
00196
00197 thisPortList->sock = lsock;
00198 thisPortList->cookie = random ();
00199 if (ProcessType == CLIENT_PT) {
00200 rstrcpy (thisPortList->hostAddr, laddr, LONG_NAME_LEN);
00201 } else {
00202 struct hostent *hostEnt;
00203
00204 if (LocalServerHost != NULL &&
00205 strcmp (LocalServerHost->hostName->name, "localhost") != 0 &&
00206 (hostEnt = gethostbyname (LocalServerHost->hostName->name)) != NULL){
00207 rstrcpy (thisPortList->hostAddr, hostEnt->h_name, LONG_NAME_LEN);
00208 } else {
00209 rstrcpy (thisPortList->hostAddr, laddr, LONG_NAME_LEN);
00210 }
00211 }
00212 free (laddr);
00213 thisPortList->portNum = lport;
00214 thisPortList->windowSize = rsComm->windowSize;
00215
00216 listen (lsock, SOMAXCONN);
00217
00218 if (proto == SOCK_DGRAM) {
00219 if ((udpsock = svrSockOpenForInConn (rsComm, &udpport, &udpaddr,
00220 SOCK_DGRAM)) < 0) {
00221 rodsLog (LOG_ERROR,
00222 "setupSrvPortal- sockOpenForInConn of SOCK_DGRAM failed: stat=%d",
00223 udpsock);
00224 CLOSE_SOCK (lsock);
00225 return udpsock;
00226 } else {
00227 addUdpPortToPortList (thisPortList, udpport);
00228 addUdpSockToPortList (thisPortList, udpsock);
00229 }
00230 }
00231 free (udpaddr);
00232
00233 return (lsock);
00234 }
00235
00236 int
00237 acceptSrvPortal (rsComm_t *rsComm, portList_t *thisPortList)
00238 {
00239 int myFd = -1;
00240 int myCookie;
00241 int nbytes;
00242 fd_set basemask;
00243 int nSockets, nSelected;
00244 int lsock = getTcpSockFromPortList (thisPortList);
00245 struct timeval selectTimeout;
00246
00247 nSockets = lsock + 1;
00248 FD_ZERO(&basemask);
00249 FD_SET(lsock, &basemask);
00250
00251
00252
00253 selectTimeout.tv_sec = SELECT_TIMEOUT_FOR_CONN;
00254 selectTimeout.tv_usec = 0;
00255
00256 while ((nSelected = select(nSockets, &basemask,
00257 (fd_set *) NULL, (fd_set *) NULL, &selectTimeout)) < 0) {
00258 if (errno == EINTR) {
00259 rodsLog (LOG_ERROR, "acceptSrvPortal: select interrupted\n");
00260 continue;
00261 }
00262 rodsLog (LOG_ERROR, "acceptSrvPortal: select select failed, errno = %d",
00263 errno);
00264 }
00265 myFd = accept (lsock, 0, 0);
00266 if (myFd < 0) {
00267 rodsLog (LOG_NOTICE,
00268 "acceptSrvPortal() -- accept() failed: errno=%d",
00269 errno);
00270 return SYS_SOCK_ACCEPT_ERR - errno;
00271 } else {
00272 rodsSetSockOpt (myFd, rsComm->windowSize);
00273 }
00274 #ifdef _WIN32
00275 nbytes = recv (myFd,&myCookie,sizeof(myCookie),0);
00276 #else
00277 nbytes = read (myFd, &myCookie,sizeof (myCookie));
00278 #endif
00279 myCookie = ntohl (myCookie);
00280 if (nbytes != sizeof (myCookie) || myCookie != thisPortList->cookie) {
00281 rodsLog (LOG_NOTICE,
00282 "acceptSrvPortal: cookie err, bytes read=%d,cookie=%d,inCookie=%d",
00283 nbytes, thisPortList->cookie, myCookie);
00284 CLOSE_SOCK (myFd);
00285 return SYS_PORT_COOKIE_ERR;
00286 }
00287 return (myFd);
00288 }
00289
00290 int
00291 svrPortalPutGet (rsComm_t *rsComm)
00292 {
00293 portalOpr_t *myPortalOpr;
00294 dataOprInp_t *dataOprInp;
00295 portList_t *thisPortList;
00296 rodsLong_t size0, size1, offset0;
00297 int lsock, portalFd;
00298 int i;
00299 int numThreads;
00300 portalTransferInp_t myInput[MAX_NUM_CONFIG_TRAN_THR];
00301 #ifdef PARA_OPR
00302 boost::thread* tid[MAX_NUM_CONFIG_TRAN_THR];
00303 #endif
00304 int oprType;
00305 int flags = 0;
00306 int retVal = 0;
00307
00308 myPortalOpr = rsComm->portalOpr;
00309
00310 if (myPortalOpr == NULL) {
00311 rodsLog (LOG_NOTICE, "svrPortalPut: NULL myPortalOpr");
00312 return (SYS_INTERNAL_NULL_INPUT_ERR);
00313 }
00314
00315 thisPortList = &myPortalOpr->portList;
00316 if (thisPortList == NULL) {
00317 rodsLog (LOG_NOTICE, "svrPortalPut: NULL portList");
00318 return (SYS_INTERNAL_NULL_INPUT_ERR);
00319 }
00320
00321 if (getUdpPortFromPortList (thisPortList) != 0) {
00322 #ifdef RBUDP_TRANSFER
00323
00324 retVal = svrPortalPutGetRbudp (rsComm);
00325 return retVal;
00326 #else
00327 return SYS_UDP_NO_SUPPORT_ERR;
00328 #endif
00329 }
00330
00331 oprType = myPortalOpr->oprType;
00332 dataOprInp = &myPortalOpr->dataOprInp;
00333
00334 if (getValByKey (&dataOprInp->condInput, STREAMING_KW)!= NULL) {
00335 flags |= STREAMING_FLAG;
00336 }
00337
00338 numThreads = dataOprInp->numThreads;
00339
00340 if (numThreads <= 0 || numThreads > MAX_NUM_CONFIG_TRAN_THR) {
00341 rodsLog (LOG_NOTICE,
00342 "svrPortalPut: numThreads %d out of range");
00343 return (SYS_INTERNAL_NULL_INPUT_ERR);
00344 }
00345
00346 memset (myInput, 0, sizeof (myInput));
00347 #ifdef PARA_OPR
00348 memset (tid, 0, sizeof (tid));
00349 #endif
00350
00351 size0 = dataOprInp->dataSize / numThreads;
00352
00353 size1 = dataOprInp->dataSize - size0 * (numThreads - 1);
00354 offset0 = dataOprInp->offset;
00355
00356 lsock = getTcpSockFromPortList (thisPortList);
00357
00358
00359 portalFd = acceptSrvPortal (rsComm, thisPortList);
00360 if (portalFd < 0) {
00361 rodsLog (LOG_NOTICE,
00362 "svrPortalPut: acceptSrvPortal error. errno = %d",
00363 errno);
00364
00365 CLOSE_SOCK (lsock);
00366
00367 return (portalFd);
00368 }
00369
00370 if (oprType == PUT_OPR) {
00371 fillPortalTransferInp (&myInput[0], rsComm,
00372 portalFd, dataOprInp->destL3descInx, 0, dataOprInp->destRescTypeInx,
00373 0, size0, offset0, flags );
00374 } else {
00375 fillPortalTransferInp (&myInput[0], rsComm,
00376 dataOprInp->srcL3descInx, portalFd, dataOprInp->srcRescTypeInx, 0,
00377 0, size0, offset0, flags );
00378 }
00379
00380 if (numThreads == 1) {
00381 if (oprType == PUT_OPR) {
00382 partialDataPut (&myInput[0]);
00383 } else {
00384 partialDataGet (&myInput[0]);
00385 }
00386
00387 CLOSE_SOCK (lsock);
00388
00389 return (myInput[0].status);
00390 } else {
00391 #ifdef PARA_OPR
00392 rodsLong_t mySize = 0;
00393 rodsLong_t myOffset = 0;
00394
00395 for (i = 1; i < numThreads; i++) {
00396 int l3descInx;
00397
00398 portalFd = acceptSrvPortal (rsComm, thisPortList);
00399 if (portalFd < 0) {
00400 rodsLog (LOG_NOTICE,
00401 "svrPortalPut: acceptSrvPortal error. errno = %d",
00402 errno);
00403
00404 CLOSE_SOCK (lsock);
00405
00406 return (portalFd);
00407 }
00408
00409 myOffset += size0;
00410
00411 if (i < numThreads - 1) {
00412 mySize = size0;
00413 } else {
00414 mySize = size1;
00415 }
00416
00417 if (oprType == PUT_OPR) {
00418
00419 l3descInx = l3OpenByHost( rsComm, dataOprInp->destRescTypeInx,
00420 dataOprInp->destL3descInx, O_WRONLY);
00421 fillPortalTransferInp(&myInput[i], rsComm,
00422 portalFd, l3descInx, 0,
00423 dataOprInp->destRescTypeInx,
00424 i, mySize, myOffset, flags);
00425 tid[i] = new boost::thread( partialDataPut, &myInput[i] );
00426
00427 } else {
00428 l3descInx = l3OpenByHost (rsComm, dataOprInp->srcRescTypeInx,
00429 dataOprInp->srcL3descInx, O_RDONLY);
00430 fillPortalTransferInp (&myInput[i], rsComm,
00431 l3descInx, portalFd, dataOprInp->srcRescTypeInx, 0,
00432 i, mySize, myOffset, flags);
00433 tid[i] = new boost::thread( partialDataGet, &myInput[i] );
00434 }
00435 }
00436
00437
00438
00439 if (oprType == PUT_OPR) {
00440 tid[0] = new boost::thread( partialDataPut, &myInput[0] );
00441 } else {
00442 tid[0] = new boost::thread( partialDataGet, &myInput[0] );
00443 }
00444
00445 for ( i = 0; i < numThreads; i++) {
00446 if (tid[i] != 0)
00447 tid[i]->join();
00448 if (myInput[i].status < 0) {
00449 retVal = myInput[i].status;
00450 }
00451 }
00452 CLOSE_SOCK (lsock);
00453 return (retVal);
00454
00455 #else
00456 CLOSE_SOCK (lsock);
00457 return (SYS_PARA_OPR_NO_SUPPORT);
00458 #endif
00459
00460 }
00461 }
00462
00463 int fillPortalTransferInp(
00464 portalTransferInp_t* myInput,
00465 rsComm_t* rsComm,
00466 int srcFd,
00467 int destFd,
00468 int srcRescTypeInx,
00469 int destRescTypeInx,
00470 int threadNum,
00471 rodsLong_t size,
00472 rodsLong_t offset,
00473 int flags ) {
00474
00475 if (myInput == NULL) {
00476 return (SYS_INTERNAL_NULL_INPUT_ERR);
00477 }
00478
00479 myInput->rsComm = rsComm;
00480 myInput->destFd = destFd;
00481 myInput->srcFd = srcFd;
00482 myInput->destRescTypeInx = destRescTypeInx;
00483 myInput->srcRescTypeInx = srcRescTypeInx;
00484 myInput->threadNum = threadNum;
00485 myInput->size = size;
00486 myInput->offset = offset;
00487 myInput->flags = flags;
00488
00489
00490
00491
00492 memcpy(
00493 myInput->shared_secret,
00494 rsComm->shared_secret,
00495 NAME_LEN );
00496
00497
00498
00499
00500 myInput->key_size = rsComm->key_size;
00501 myInput->salt_size = rsComm->salt_size;
00502 myInput->num_hash_rounds = rsComm->num_hash_rounds;
00503 strncpy(
00504 myInput->encryption_algorithm,
00505 rsComm->encryption_algorithm,
00506 NAME_LEN );
00507 return (0);
00508 }
00509
00510
00511 void
00512 partialDataPut (portalTransferInp_t *myInput)
00513 {
00514 int destL3descInx = 0, srcFd = 0, destRescTypeInx = 0;
00515 unsigned char *buf = 0;
00516 int bytesWritten = 0;
00517 rodsLong_t bytesToGet = 0;
00518 rodsLong_t myOffset = 0;
00519
00520 if (myInput == NULL) {
00521 rodsLog (LOG_SYS_FATAL, "partialDataPut: NULL myInput");
00522 return;
00523 }
00524
00525
00526
00527 bool use_encryption_flg =
00528 ( myInput->rsComm->negotiation_results ==
00529 eirods::CS_NEG_USE_SSL );
00530
00531 #ifdef PARA_TIMING
00532 time_t startTime, afterSeek, afterTransfer,
00533 endTime;
00534 startTime=time (0);
00535 #endif
00536
00537 myInput->status = 0;
00538 destL3descInx = myInput->destFd;
00539 srcFd = myInput->srcFd;
00540 destRescTypeInx = myInput->destRescTypeInx;
00541
00542 if (myInput->offset != 0) {
00543 myOffset = _l3Lseek (myInput->rsComm, destRescTypeInx,
00544 destL3descInx, myInput->offset, SEEK_SET);
00545 if (myOffset < 0) {
00546 myInput->status = myOffset;
00547 rodsLog (LOG_NOTICE,
00548 "_partialDataPut: _objSeek error, status = %d ",
00549 myInput->status);
00550 if (myInput->threadNum > 0)
00551 _l3Close (myInput->rsComm, destRescTypeInx, destL3descInx);
00552 CLOSE_SOCK (srcFd);
00553 return;
00554 }
00555 }
00556
00557 #ifdef PARA_TIMING
00558 afterSeek=time(0);
00559 #endif
00560
00561 bytesToGet = myInput->size;
00562
00563
00564
00565 int iv_size = 0;
00566 eirods::buffer_crypt::array_t iv;
00567 eirods::buffer_crypt::array_t this_iv;
00568 eirods::buffer_crypt::array_t cipher;
00569 eirods::buffer_crypt::array_t plain;
00570 eirods::buffer_crypt::array_t shared_secret;
00571 eirods::buffer_crypt crypt(
00572 myInput->key_size,
00573 myInput->salt_size,
00574 myInput->num_hash_rounds,
00575 myInput->encryption_algorithm );
00576
00577
00578
00579
00580 if( use_encryption_flg ) {
00581 iv_size = crypt.key_size();
00582 shared_secret.assign(
00583 &myInput->shared_secret[0],
00584 &myInput->shared_secret[iv_size] );
00585 }
00586
00587 buf = (unsigned char*)malloc ( ( 2*TRANS_BUF_SZ ) + sizeof( unsigned char ) );
00588
00589 while (bytesToGet > 0) {
00590 int toread0;
00591 int bytesRead;
00592
00593 #ifdef PARA_TIMING
00594 time_t tstart, tafterRead, tafterWrite;
00595 tstart=time(0);
00596 #endif
00597 if (myInput->flags & STREAMING_FLAG) {
00598 toread0 = bytesToGet;
00599 } else if (bytesToGet > TRANS_SZ) {
00600 toread0 = TRANS_SZ;
00601 } else {
00602 toread0 = bytesToGet;
00603 }
00604
00605 myInput->status = sendTranHeader (srcFd, PUT_OPR, myInput->flags,
00606 myOffset, toread0);
00607
00608 if (myInput->status < 0) {
00609 rodsLog (LOG_NOTICE,
00610 "partialDataPut: sendTranHeader error. status = %d",
00611 myInput->status);
00612 if (myInput->threadNum > 0)
00613 _l3Close (myInput->rsComm, destRescTypeInx, destL3descInx);
00614 CLOSE_SOCK (srcFd);
00615 free (buf);
00616 return;
00617 }
00618
00619 while (toread0 > 0) {
00620 int toread1 = 0;
00621
00622 if (toread0 > TRANS_BUF_SZ) {
00623 toread1 = TRANS_BUF_SZ;
00624 } else {
00625 toread1 = toread0;
00626 }
00627
00628
00629
00630 int new_size = toread1;
00631 if( use_encryption_flg ) {
00632 bytesRead = myRead(
00633 srcFd,
00634 &new_size,
00635 sizeof( int ),
00636 SOCK_TYPE,
00637 NULL, NULL);
00638 if( bytesRead != sizeof( int ) ) {
00639 rodsLog( LOG_ERROR, "_partialDataPut:Bytes Read != %d", sizeof( int ) );
00640 break;
00641 }
00642 }
00643
00644
00645
00646 bytesRead = myRead (
00647 srcFd,
00648 buf,
00649 new_size,
00650 SOCK_TYPE,
00651 NULL, NULL );
00652
00653 #ifdef PARA_TIMING
00654 tafterRead=time(0);
00655 #endif
00656
00657 if( bytesRead == new_size ) {
00658
00659
00660
00661 int plain_size = bytesRead;
00662 if( use_encryption_flg ) {
00663 this_iv.assign(
00664 &buf[0],
00665 &buf[ iv_size ] );
00666 cipher.assign(
00667 &buf[ iv_size ],
00668 &buf[ new_size ] );
00669 eirods::error ret = crypt.decrypt(
00670 shared_secret,
00671 this_iv,
00672 cipher,
00673 plain );
00674 #if 0
00675 std::string sec_hash = crypt.gen_hash( &shared_secret[0], shared_secret.size() );
00676 std::string iv_hash = crypt.gen_hash( &this_iv[0], this_iv.size() );
00677 std::string cipher_hash = crypt.gen_hash( &cipher[0], cipher.size() );
00678 std::string buf_hash = crypt.gen_hash( buf, new_size );
00679
00680 printf( "XXXX - %d - shared_secret [%s] sz - %d\n", myInput->threadNum, sec_hash.c_str(), shared_secret.size() );
00681 fflush( stdout );
00682 printf( "XXXX - %d - iv [%s] sz - %d\n", myInput->threadNum, iv_hash.c_str(), iv.size() );
00683 fflush( stdout );
00684 printf( "XXXX - %d - cipher [%s] sz - %d\n", myInput->threadNum, cipher_hash.c_str(), cipher.size() );
00685 fflush( stdout );
00686 printf( "XXXX - %d - buf [%s] sz - %d\n", myInput->threadNum, buf_hash.c_str(), new_size );
00687 fflush( stdout );
00688 #endif
00689
00690 if( !ret.ok() ) {
00691 eirods::log( PASS( ret ) );
00692 myInput->status = SYS_COPY_LEN_ERR;
00693 break;
00694 }
00695
00696 std::copy(
00697 plain.begin(),
00698 plain.end(),
00699 &buf[0] );
00700 plain_size = plain.size();
00701
00702 }
00703
00704 if ((bytesWritten = _l3Write(
00705 myInput->rsComm,
00706 destRescTypeInx,
00707 destL3descInx,
00708 buf,
00709 plain_size )) != ( plain_size ) ) {
00710 rodsLog (LOG_NOTICE,
00711 "_partialDataPut:Bytes written %d don't match read %d",
00712 bytesWritten, bytesRead);
00713
00714 if (bytesWritten < 0) {
00715 myInput->status = bytesWritten;
00716 } else {
00717 myInput->status = SYS_COPY_LEN_ERR;
00718 }
00719 break;
00720 }
00721 bytesToGet -= bytesWritten;
00722 toread0 -= bytesWritten;
00723 myOffset += bytesWritten;
00724
00725 } else if (bytesRead < 0) {
00726 myInput->status = bytesRead;
00727 break;
00728 } else {
00729 rodsLog (LOG_NOTICE,
00730 "_partialDataPut: toread %d bytes, %d bytes read, errno = %d",
00731 toread1, bytesRead, errno);
00732 myInput->status = SYS_COPY_LEN_ERR;
00733 break;
00734 }
00735 #ifdef PARA_TIMING
00736 tafterWrite=time(0);
00737 rodsLog (LOG_NOTICE,
00738 "Thr %d: sz=%d netReadTm=%d diskWriteTm=%d",
00739 myInput->threadNum, bytesWritten, tafterRead-tstart,
00740 tafterWrite-tafterRead);
00741 #endif
00742 }
00743 if (myInput->status < 0)
00744 break;
00745 }
00746 #ifdef PARA_TIMING
00747 afterTransfer=time(0);
00748 #endif
00749 free (buf);
00750 sendTranHeader (srcFd, DONE_OPR, 0, 0, 0);
00751 if (myInput->threadNum > 0)
00752 _l3Close (myInput->rsComm, destRescTypeInx, destL3descInx);
00753 mySockClose (srcFd);
00754 #ifdef PARA_TIMING
00755 endTime=time(0);
00756 rodsLog (LOG_NOTICE,
00757 "Thr %d: seekTm=%d transTm=%d endTm=%d",
00758 myInput->threadInx,
00759 afterSeek-afterConn, afterTransfer-afterSeek, endTime-afterTransfer);
00760 #endif
00761 return;
00762 }
00763
00764 void partialDataGet(
00765 portalTransferInp_t* myInput ) {
00766
00767
00768 int srcL3descInx = 0, destFd = 0, srcRescTypeInx = 0;
00769 unsigned char *buf = 0;
00770 int bytesWritten = 0;
00771 rodsLong_t bytesToGet = 0;
00772 rodsLong_t myOffset = 0;
00773
00774 #ifdef PARA_TIMING
00775 time_t startTime, afterSeek, afterTransfer,
00776 endTime;
00777 startTime=time (0);
00778 #endif
00779
00780 if (myInput == NULL) {
00781 rodsLog (LOG_SYS_FATAL, "partialDataGet: NULL myInput");
00782 return;
00783 }
00784
00785 myInput->status = 0;
00786 srcL3descInx = myInput->srcFd;
00787 destFd = myInput->destFd;
00788 srcRescTypeInx = myInput->srcRescTypeInx;
00789
00790 if (myInput->offset != 0) {
00791 myOffset = _l3Lseek (myInput->rsComm, srcRescTypeInx,
00792 srcL3descInx, myInput->offset, SEEK_SET);
00793 if (myOffset < 0) {
00794 myInput->status = myOffset;
00795 rodsLog (LOG_NOTICE,
00796 "_partialDataGet: _objSeek error, status = %d ",
00797 myInput->status);
00798 if (myInput->threadNum > 0)
00799 _l3Close (myInput->rsComm, srcRescTypeInx, srcL3descInx);
00800 CLOSE_SOCK (destFd);
00801 return;
00802 }
00803 }
00804
00805
00806
00807 bool use_encryption_flg =
00808 ( myInput->rsComm->negotiation_results ==
00809 eirods::CS_NEG_USE_SSL );
00810
00811
00812
00813 int iv_size = 0;
00814 eirods::buffer_crypt::array_t iv;
00815 eirods::buffer_crypt::array_t cipher;
00816 eirods::buffer_crypt::array_t in_buf;
00817 eirods::buffer_crypt::array_t shared_secret;
00818 eirods::buffer_crypt crypt(
00819 myInput->key_size,
00820 myInput->salt_size,
00821 myInput->num_hash_rounds,
00822 myInput->encryption_algorithm );
00823
00824
00825
00826 if( use_encryption_flg ) {
00827 iv_size = crypt.key_size();
00828 shared_secret.assign(
00829 &myInput->shared_secret[0],
00830 &myInput->shared_secret[iv_size] );
00831 }
00832
00833 buf = (unsigned char*)malloc ( ( 2*TRANS_BUF_SZ ) * sizeof( unsigned char ) );
00834
00835 #ifdef PARA_TIMING
00836 afterSeek=time(0);
00837 #endif
00838
00839 bytesToGet = myInput->size;
00840
00841 while (bytesToGet > 0) {
00842 int toread0;
00843 int bytesRead;
00844
00845 #ifdef PARA_TIMING
00846 time_t tstart, tafterRead, tafterWrite;
00847 tstart=time(0);
00848 #endif
00849 if (myInput->flags & STREAMING_FLAG) {
00850 toread0 = bytesToGet;
00851 } else if (bytesToGet > TRANS_SZ) {
00852 toread0 = TRANS_SZ;
00853 } else {
00854 toread0 = bytesToGet;
00855 }
00856
00857 myInput->status = sendTranHeader (destFd, GET_OPR, myInput->flags,
00858 myOffset, toread0);
00859
00860 if (myInput->status < 0) {
00861 rodsLog (LOG_NOTICE,
00862 "partialDataGet: sendTranHeader error. status = %d",
00863 myInput->status);
00864 if (myInput->threadNum > 0)
00865 _l3Close (myInput->rsComm, srcRescTypeInx, srcL3descInx);
00866 CLOSE_SOCK (destFd);
00867 free (buf);
00868 return;
00869 }
00870
00871 while (toread0 > 0) {
00872 int toread1;
00873
00874 if (toread0 > TRANS_BUF_SZ) {
00875 toread1 = TRANS_BUF_SZ;
00876 } else {
00877 toread1 = toread0;
00878 }
00879
00880 bytesRead = _l3Read( myInput->rsComm, srcRescTypeInx,srcL3descInx, buf, toread1 );
00881
00882 #ifdef PARA_TIMING
00883 tafterRead=time(0);
00884 #endif
00885 if (bytesRead == toread1) {
00886
00887
00888
00889 int new_size = bytesRead;
00890 if( use_encryption_flg ) {
00891 eirods::error ret = crypt.initialization_vector( iv );
00892 if( !ret.ok() ) {
00893 ret = PASS( ret );
00894 printf( "%s", ret.result().c_str() );
00895 break;
00896 }
00897
00898
00899
00900 in_buf.assign(
00901 &buf[0],
00902 &buf[ bytesRead ] );
00903
00904 ret = crypt.encrypt(
00905 shared_secret,
00906 iv,
00907 in_buf,
00908 cipher );
00909 if( !ret.ok() ) {
00910 ret = PASS( ret );
00911 printf( "%s", ret.result().c_str() );
00912 break;
00913 }
00914
00915
00916
00917 bzero( buf, sizeof( buf ) );
00918 std::copy(
00919 iv.begin(),
00920 iv.end(),
00921 &buf[0] );
00922 std::copy(
00923 cipher.begin(),
00924 cipher.end(),
00925 &buf[iv_size] );
00926
00927 new_size = iv_size + cipher.size();
00928
00929
00930
00931
00932 bytesWritten = myWrite(
00933 destFd,
00934 &new_size,
00935 sizeof( int ),
00936 SOCK_TYPE,
00937 &bytesWritten );
00938 }
00939
00940
00941
00942 bytesWritten = myWrite(
00943 destFd,
00944 buf,
00945 new_size,
00946 SOCK_TYPE,
00947 &bytesWritten );
00948
00949 if( bytesWritten != new_size ) {
00950 rodsLog (LOG_NOTICE,
00951 "_partialDataGet:Bytes written %d don't match read %d",
00952 bytesWritten, bytesRead);
00953
00954 if (bytesWritten < 0) {
00955 myInput->status = bytesWritten;
00956 } else {
00957 myInput->status = SYS_COPY_LEN_ERR;
00958 }
00959 break;
00960 }
00961
00962
00963
00964
00965 bytesToGet -= bytesRead;
00966 toread0 -= bytesRead;
00967 myOffset += bytesRead;
00968
00969 } else if (bytesRead < 0) {
00970 myInput->status = bytesRead;
00971 break;
00972
00973 } else {
00974 rodsLog (LOG_NOTICE,
00975 "_partialDataGet: toread %d bytes, %d bytes read",
00976 toread1, bytesRead);
00977 myInput->status = SYS_COPY_LEN_ERR;
00978 break;
00979 }
00980 #ifdef PARA_TIMING
00981 tafterWrite=time(0);
00982 rodsLog (LOG_NOTICE,
00983 "Thr %d: sz=%d netReadTm=%d diskWriteTm=%d",
00984 myInput->threadNum, bytesWritten, tafterRead-tstart,
00985 tafterWrite-tafterRead);
00986 #endif
00987 }
00988 if (myInput->status < 0)
00989 break;
00990 }
00991 #ifdef PARA_TIMING
00992 afterTransfer=time(0);
00993 #endif
00994 free (buf);
00995 sendTranHeader (destFd, DONE_OPR, 0, 0, 0);
00996 if (myInput->threadNum > 0)
00997 _l3Close (myInput->rsComm, srcRescTypeInx, srcL3descInx);
00998 CLOSE_SOCK (destFd);
00999 #ifdef PARA_TIMING
01000 endTime=time(0);
01001 rodsLog (LOG_NOTICE,
01002 "Thr %d: seekTm=%d transTm=%d endTm=%d",
01003 myInput->threadInx,
01004 afterSeek-afterConn, afterTransfer-afterSeek, endTime-afterTransfer);
01005 #endif
01006 return;
01007 }
01008
01009 void
01010 remToLocPartialCopy (portalTransferInp_t *myInput)
01011 {
01012 transferHeader_t myHeader;
01013 int destL3descInx = 0, srcFd = 0, destRescTypeInx = 0;
01014 unsigned char *buf = 0;
01015 rodsLong_t curOffset = 0;
01016 rodsLong_t myOffset = 0;
01017 int toRead, bytesRead = 0, bytesWritten = 0;
01018
01019 if (myInput == NULL) {
01020 rodsLog (LOG_NOTICE,
01021 "remToLocPartialCopy: NULL input");
01022 return;
01023 }
01024 #ifdef PARA_DEBUG
01025 printf ("remToLocPartialCopy: thread %d at start\n", myInput->threadNum);
01026 #endif
01027
01028 myInput->status = 0;
01029 destL3descInx = myInput->destFd;
01030 srcFd = myInput->srcFd;
01031 destRescTypeInx = myInput->destRescTypeInx;
01032 myInput->bytesWritten = 0;
01033
01034
01035
01036 bool use_encryption_flg =
01037 ( myInput->rsComm->negotiation_results ==
01038 eirods::CS_NEG_USE_SSL );
01039
01040
01041
01042 int iv_size = 0;
01043 eirods::buffer_crypt::array_t iv;
01044 eirods::buffer_crypt::array_t this_iv;
01045 eirods::buffer_crypt::array_t cipher;
01046 eirods::buffer_crypt::array_t plain;
01047 eirods::buffer_crypt::array_t shared_secret;
01048 eirods::buffer_crypt crypt(
01049 myInput->key_size,
01050 myInput->salt_size,
01051 myInput->num_hash_rounds,
01052 myInput->encryption_algorithm );
01053
01054
01055
01056
01057 if( use_encryption_flg ) {
01058 iv_size = crypt.key_size();
01059 shared_secret.assign(
01060 &myInput->shared_secret[0],
01061 &myInput->shared_secret[iv_size] );
01062 }
01063
01064 buf = (unsigned char*)malloc( ( 2*TRANS_BUF_SZ )*sizeof(unsigned char) );
01065
01066 while (myInput->status >= 0) {
01067 rodsLong_t toGet;
01068
01069 myInput->status = rcvTranHeader (srcFd, &myHeader);
01070
01071 #ifdef PARA_DEBUG
01072 printf ("remToLocPartialCopy: thread %d after rcvTranHeader\n",
01073 myInput->threadNum);
01074 printf ("remToLocPartialCopy: thread %d header offset %lld, len %lld\n",
01075 myInput->threadNum, myHeader.offset, myHeader.length);
01076
01077 #endif
01078
01079 if (myInput->status < 0) {
01080 break;
01081 }
01082
01083 if (myHeader.oprType == DONE_OPR) {
01084 break;
01085 }
01086 if (myHeader.offset != curOffset) {
01087 curOffset = myHeader.offset;
01088 myOffset = _l3Lseek (myInput->rsComm, destRescTypeInx,
01089 destL3descInx, myHeader.offset, SEEK_SET);
01090 if (myOffset < 0) {
01091 myInput->status = myOffset;
01092 rodsLog (LOG_NOTICE,
01093 "remToLocPartialCopy: _objSeek error, status = %d ",
01094 myInput->status);
01095 break;
01096 }
01097 }
01098
01099 toGet = myHeader.length;
01100 while (toGet > 0) {
01101
01102 if (toGet > TRANS_BUF_SZ) {
01103 toRead = TRANS_BUF_SZ;
01104 } else {
01105 toRead = toGet;
01106 }
01107
01108
01109
01110 int new_size = toRead;
01111 if( use_encryption_flg ) {
01112 bytesRead = myRead (srcFd, &new_size, sizeof( int ), SOCK_TYPE, NULL, NULL);
01113 if( bytesRead != sizeof( int ) ) {
01114 rodsLog( LOG_ERROR, "_partialDataPut:Bytes Read != %d", sizeof( int ) );
01115 break;
01116 }
01117 }
01118
01119
01120
01121 bytesRead = myRead ( srcFd, buf, new_size, SOCK_TYPE, NULL, NULL );
01122 if( bytesRead != new_size ) {
01123 if (bytesRead < 0) {
01124 myInput->status = bytesRead;
01125 rodsLogError (LOG_ERROR, bytesRead,
01126 "remToLocPartialCopy: copy error for %lld", bytesRead);
01127 } else if ((myInput->flags & NO_CHK_COPY_LEN_FLAG) == 0) {
01128 myInput->status = SYS_COPY_LEN_ERR - errno;
01129 rodsLog (LOG_ERROR,
01130 "remToLocPartialCopy: toGet %lld, bytesRead %d",
01131 toGet, bytesRead);
01132 }
01133 break;
01134 }
01135
01136
01137
01138
01139 int plain_size = bytesRead;
01140 if( use_encryption_flg ) {
01141 this_iv.assign(
01142 &buf[ 0 ],
01143 &buf[ iv_size ] );
01144 cipher.assign(
01145 &buf[ iv_size ],
01146 &buf[ new_size ] );
01147
01148 eirods::error ret = crypt.decrypt(
01149 shared_secret,
01150 this_iv,
01151 cipher,
01152 plain );
01153 if( !ret.ok() ) {
01154 eirods::log( PASS( ret ) );
01155 myInput->status = SYS_COPY_LEN_ERR;
01156 break;
01157 }
01158
01159 std::copy(
01160 plain.begin(),
01161 plain.end(),
01162 &buf[0] );
01163 plain_size = plain.size();
01164
01165 }
01166
01167 bytesWritten = _l3Write(
01168 myInput->rsComm,
01169 destRescTypeInx,
01170 destL3descInx,
01171 buf,
01172 plain_size );
01173
01174 if ( bytesWritten != plain_size ) {
01175 rodsLog (LOG_NOTICE,
01176 "_partialDataPut:Bytes written %d don't match read %d",
01177 bytesWritten, bytesRead);
01178
01179 if (bytesWritten < 0) {
01180 myInput->status = bytesWritten;
01181 } else {
01182 myInput->status = SYS_COPY_LEN_ERR;
01183 }
01184 break;
01185 }
01186
01187 toGet -= bytesWritten;
01188 }
01189 curOffset += myHeader.length;
01190 myInput->bytesWritten += myHeader.length;
01191 }
01192
01193 free (buf);
01194 if (myInput->threadNum > 0)
01195 _l3Close (myInput->rsComm, destRescTypeInx, destL3descInx);
01196 CLOSE_SOCK (srcFd);
01197 }
01198
01199
01200
01201
01202 #ifdef RBUDP_TRANSFER
01203 int
01204 rbudpRemLocCopy (rsComm_t *rsComm, dataCopyInp_t *dataCopyInp)
01205 {
01206 portalOprOut_t *portalOprOut;
01207 dataOprInp_t *dataOprInp;
01208 rodsLong_t dataSize;
01209 int oprType;
01210 int veryVerbose, sendRate, packetSize;
01211 char *tmpStr;
01212 int status;
01213
01214 if (dataCopyInp == NULL) {
01215 rodsLog (LOG_NOTICE,
01216 "rbudpRemLocCopy: NULL dataCopyInp input");
01217 return (SYS_INTERNAL_NULL_INPUT_ERR);
01218 }
01219 portalOprOut = &dataCopyInp->portalOprOut;
01220 dataOprInp = &dataCopyInp->dataOprInp;
01221 oprType = dataOprInp->oprType;
01222 dataSize = dataOprInp->dataSize;
01223
01224 if (getValByKey (&dataOprInp->condInput, VERY_VERBOSE_KW) != NULL) {
01225 veryVerbose = 2;
01226 } else {
01227 veryVerbose = 0;
01228 }
01229
01230 if ((tmpStr = getValByKey (&dataOprInp->condInput,
01231 RBUDP_PACK_SIZE_KW)) != NULL) {
01232 packetSize = atoi (tmpStr);
01233 } else {
01234 packetSize = DEF_UDP_PACKET_SIZE;
01235 }
01236
01237 if (oprType == COPY_TO_LOCAL_OPR) {
01238 int destL3descInx = dataOprInp->destL3descInx;
01239
01240 status = getFileToPortalRbudp (portalOprOut, NULL,
01241 FileDesc[destL3descInx].fd, dataSize,
01242 veryVerbose, packetSize );
01243
01244 } else {
01245 int srcL3descInx = dataOprInp->srcL3descInx;
01246
01247 if ((tmpStr = getValByKey (&dataOprInp->condInput,
01248 RBUDP_SEND_RATE_KW)) != NULL) {
01249 sendRate = atoi (tmpStr);
01250 } else {
01251 sendRate = DEF_UDP_SEND_RATE;
01252 }
01253 status = putFileToPortalRbudp (portalOprOut, NULL, NULL,
01254 FileDesc[srcL3descInx].fd, dataSize,
01255 veryVerbose, sendRate, packetSize );
01256 }
01257 return (status);
01258 }
01259 #endif
01260
01261
01262
01263
01264 int
01265 remLocCopy (rsComm_t *rsComm, dataCopyInp_t *dataCopyInp)
01266 {
01267 portalOprOut_t *portalOprOut;
01268 dataOprInp_t *dataOprInp;
01269 portList_t *myPortList;
01270 int i, sock, myFd;
01271 int numThreads;
01272 portalTransferInp_t myInput[MAX_NUM_CONFIG_TRAN_THR];
01273 #ifndef windows_platform
01274 boost::thread* tid[MAX_NUM_CONFIG_TRAN_THR];
01275 #endif
01276 int retVal = 0;
01277 rodsLong_t dataSize;
01278 int oprType;
01279
01280 if (dataCopyInp == NULL) {
01281 rodsLog (LOG_NOTICE,
01282 "remLocCopy: NULL dataCopyInp input");
01283 return (SYS_INTERNAL_NULL_INPUT_ERR);
01284 }
01285
01286 portalOprOut = &dataCopyInp->portalOprOut;
01287 numThreads = portalOprOut->numThreads;
01288 if (numThreads == 0) {
01289 retVal = singleRemLocCopy (rsComm, dataCopyInp);
01290 return retVal;
01291 }
01292
01293 dataOprInp = &dataCopyInp->dataOprInp;
01294 oprType = dataOprInp->oprType;
01295 dataSize = dataOprInp->dataSize;
01296
01297 if (getUdpPortFromPortList (&portalOprOut->portList) != 0) {
01298
01299 #ifdef RBUDP_TRANSFER
01300 retVal = rbudpRemLocCopy (rsComm, dataCopyInp);
01301 return (retVal);
01302 #else
01303 return (SYS_UDP_NO_SUPPORT_ERR);
01304 #endif
01305 }
01306
01307 if (numThreads > MAX_NUM_CONFIG_TRAN_THR || numThreads <= 0) {
01308 rodsLog (LOG_NOTICE,
01309 "remLocCopy: numThreads %d out of range",
01310 numThreads);
01311 return (SYS_INVALID_PORTAL_OPR);
01312 }
01313
01314
01315 myPortList = &portalOprOut->portList;
01316
01317 #ifndef windows_platform
01318 memset (tid, 0, sizeof (tid));
01319 #endif
01320 memset (myInput, 0, sizeof (myInput));
01321
01322 sock = connectToRhostPortal (myPortList->hostAddr,
01323 myPortList->portNum, myPortList->cookie, rsComm->windowSize);
01324 if (sock < 0) {
01325 return (sock);
01326 }
01327
01328 if (oprType == COPY_TO_LOCAL_OPR) {
01329 fillPortalTransferInp (&myInput[0], rsComm,
01330 sock, dataOprInp->destL3descInx, 0, dataOprInp->destRescTypeInx,
01331 0, 0, 0, 0 );
01332 } else {
01333 fillPortalTransferInp (&myInput[0], rsComm,
01334 dataOprInp->srcL3descInx, sock, dataOprInp->srcRescTypeInx, 0,
01335 0, 0, 0, 0 );
01336 }
01337
01338 if (numThreads == 1) {
01339 if (getValByKey (&dataOprInp->condInput,
01340 NO_CHK_COPY_LEN_KW) != NULL) {
01341 myInput[0].flags = NO_CHK_COPY_LEN_FLAG;
01342 }
01343 if (oprType == COPY_TO_LOCAL_OPR) {
01344 remToLocPartialCopy (&myInput[0]);
01345 } else {
01346 locToRemPartialCopy (&myInput[0]);
01347 }
01348 if (myInput[0].status < 0) {
01349 return (myInput[0].status);
01350 } else {
01351 if (myInput[0].bytesWritten == dataSize) {
01352 return (0);
01353 } else {
01354 rodsLog (LOG_NOTICE,
01355 "remLocCopy:bytesWritten %lld dataSize %lld mismatch",
01356 myInput[0].bytesWritten, dataSize);
01357 return (SYS_COPY_LEN_ERR);
01358 }
01359 }
01360 } else {
01361 #ifdef PARA_OPR
01362 rodsLong_t totalWritten = 0;
01363
01364 for (i = 1; i < numThreads; i++) {
01365 sock = connectToRhostPortal (myPortList->hostAddr,
01366 myPortList->portNum, myPortList->cookie, rsComm->windowSize);
01367 if (sock < 0) {
01368 return (sock);
01369 }
01370 if (oprType == COPY_TO_LOCAL_OPR) {
01371 myFd = l3OpenByHost (rsComm, dataOprInp->destRescTypeInx,
01372 dataOprInp->destL3descInx, O_WRONLY);
01373 if (myFd < 0) {
01374 retVal = myFd;
01375 rodsLog (LOG_NOTICE,
01376 "remLocCopy: cannot open file, status = %d",
01377 myFd);
01378 CLOSE_SOCK (sock);
01379 continue;
01380 }
01381
01382 fillPortalTransferInp (&myInput[i], rsComm,
01383 sock, myFd, 0, dataOprInp->destRescTypeInx,
01384 i, 0, 0, 0 );
01385
01386 tid[i] = new boost::thread( remToLocPartialCopy, &myInput[i] );
01387 } else {
01388 myFd = l3OpenByHost (rsComm, dataOprInp->srcRescTypeInx,
01389 dataOprInp->srcL3descInx, O_RDONLY);
01390 if (myFd < 0) {
01391 retVal = myFd;
01392 rodsLog (LOG_NOTICE,
01393 "remLocCopy: cannot open file, status = %d",
01394 myFd);
01395 CLOSE_SOCK (sock);
01396 continue;
01397 }
01398
01399 fillPortalTransferInp (&myInput[i], rsComm,
01400 myFd, sock, dataOprInp->destRescTypeInx, 0,
01401 i, 0, 0, 0 );
01402
01403 tid[i] = new boost::thread( locToRemPartialCopy, &myInput[i] );
01404 }
01405 }
01406
01407 if (oprType == COPY_TO_LOCAL_OPR) {
01408 tid[0] = new boost::thread( remToLocPartialCopy,&myInput[0] );
01409 } else {
01410 tid[0] = new boost::thread( locToRemPartialCopy, &myInput[0] );
01411 }
01412
01413
01414 if (retVal < 0) {
01415 return (retVal);
01416 }
01417
01418 for ( i = 0; i < numThreads; i++) {
01419 if (tid[i] != 0) {
01420 tid[i]->join();
01421 }
01422 totalWritten += myInput[i].bytesWritten;
01423 if (myInput[i].status < 0) {
01424 retVal = myInput[i].status;
01425 }
01426 }
01427 if (retVal < 0) {
01428 return (retVal);
01429 } else {
01430 if (dataSize <= 0 || totalWritten == dataSize) {
01431 return (0);
01432 } else {
01433 rodsLog (LOG_NOTICE,
01434 "remLocCopy: totalWritten %lld dataSize %lld mismatch",
01435 totalWritten, dataSize);
01436 return (SYS_COPY_LEN_ERR);
01437 }
01438 }
01439 #else
01440 return (SYS_PARA_OPR_NO_SUPPORT);
01441 #endif
01442 }
01443 }
01444
01445 int
01446 sameHostCopy (rsComm_t *rsComm, dataCopyInp_t *dataCopyInp)
01447 {
01448 dataOprInp_t *dataOprInp;
01449 int i, out_fd, in_fd;
01450 int numThreads;
01451 portalTransferInp_t myInput[MAX_NUM_CONFIG_TRAN_THR];
01452 #ifndef windows_platform
01453 boost::thread* tid[MAX_NUM_CONFIG_TRAN_THR];
01454 #endif
01455 int retVal = 0;
01456 rodsLong_t dataSize;
01457 rodsLong_t size0, size1, offset0;
01458
01459 if (dataCopyInp == NULL) {
01460 rodsLog (LOG_NOTICE,
01461 "sameHostCopy: NULL dataCopyInp input");
01462 return (SYS_INTERNAL_NULL_INPUT_ERR);
01463 }
01464
01465 dataOprInp = &dataCopyInp->dataOprInp;
01466
01467 numThreads = dataOprInp->numThreads;
01468
01469 dataSize = dataOprInp->dataSize;
01470
01471 if (numThreads == 0) {
01472 numThreads = 1;
01473 } else if (numThreads > MAX_NUM_CONFIG_TRAN_THR || numThreads < 0) {
01474 rodsLog (LOG_NOTICE,
01475 "sameHostCopy: numThreads %d out of range",
01476 numThreads);
01477 return (SYS_INVALID_PORTAL_OPR);
01478 }
01479
01480 #ifndef windows_platform
01481 memset (tid, 0, sizeof (tid));
01482 #endif
01483 memset (myInput, 0, sizeof (myInput));
01484
01485 size0 = dataOprInp->dataSize / numThreads;
01486 size1 = dataOprInp->dataSize - size0 * (numThreads - 1);
01487 offset0 = dataOprInp->offset;
01488
01489
01490
01491
01492
01493 fillPortalTransferInp (&myInput[0], rsComm,
01494 dataOprInp->srcL3descInx, dataOprInp->destL3descInx,
01495 dataOprInp->srcRescTypeInx, dataOprInp->destRescTypeInx,
01496 0, size0, offset0, 0 );
01497
01498 if (numThreads == 1) {
01499 if (getValByKey (&dataOprInp->condInput,
01500 NO_CHK_COPY_LEN_KW) != NULL) {
01501 myInput[0].flags = NO_CHK_COPY_LEN_FLAG;
01502 }
01503 sameHostPartialCopy (&myInput[0]);
01504 return (myInput[0].status);
01505 } else {
01506 #ifdef PARA_OPR
01507 rodsLong_t totalWritten = 0;
01508 rodsLong_t mySize = 0;
01509 rodsLong_t myOffset = 0;
01510
01511 for (i = 1; i < numThreads; i++) {
01512 myOffset += size0;
01513 if (i < numThreads - 1) {
01514 mySize = size0;
01515 } else {
01516 mySize = size1;
01517 }
01518
01519 out_fd = l3OpenByHost (rsComm, dataOprInp->destRescTypeInx,
01520 dataOprInp->destL3descInx, O_WRONLY);
01521 if (out_fd < 0) {
01522 retVal = out_fd;
01523 rodsLog (LOG_NOTICE,
01524 "sameHostCopy: cannot open dest file, status = %d",
01525 out_fd);
01526 continue;
01527 }
01528
01529 in_fd = l3OpenByHost (rsComm, dataOprInp->srcRescTypeInx,
01530 dataOprInp->srcL3descInx, O_RDONLY);
01531 if (in_fd < 0) {
01532 retVal = out_fd;
01533 rodsLog (LOG_NOTICE,
01534 "sameHostCopy: cannot open src file, status = %d", in_fd);
01535 continue;
01536 }
01537 fillPortalTransferInp(
01538 &myInput[i], rsComm,
01539 in_fd, out_fd,
01540 dataOprInp->srcRescTypeInx,
01541 dataOprInp->destRescTypeInx,
01542 i, mySize, myOffset, 0 );
01543
01544 tid[i] = new boost::thread( sameHostPartialCopy, &myInput[i] );
01545 }
01546
01547 tid[0] = new boost::thread( sameHostPartialCopy, &myInput[0] );
01548
01549 if (retVal < 0) {
01550 return (retVal);
01551 }
01552
01553 for ( i = 0; i < numThreads; i++) {
01554 if (tid[i] != 0) {
01555 tid[i]->join();
01556 }
01557 totalWritten += myInput[i].bytesWritten;
01558 if (myInput[i].status < 0) {
01559 retVal = myInput[i].status;
01560 }
01561 }
01562 if (retVal < 0) {
01563 return (retVal);
01564 } else {
01565 if (dataSize <= 0 || totalWritten == dataSize) {
01566 return (0);
01567 } else {
01568 rodsLog (LOG_NOTICE,
01569 "sameHostCopy: totalWritten %lld dataSize %lld mismatch",
01570 totalWritten, dataSize);
01571 return (SYS_COPY_LEN_ERR);
01572 }
01573 }
01574 #else
01575 return (SYS_PARA_OPR_NO_SUPPORT);
01576 #endif
01577 }
01578 }
01579
01580 void
01581 sameHostPartialCopy (portalTransferInp_t *myInput)
01582 {
01583 int destL3descInx, srcL3descInx, destRescTypeInx, srcRescTypeInx;
01584 void *buf;
01585 rodsLong_t myOffset = 0;
01586 rodsLong_t toCopy;
01587 int bytesRead, bytesWritten;
01588
01589 if (myInput == NULL) {
01590 rodsLog (LOG_NOTICE,
01591 "onsameHostPartialCopy: NULL input");
01592 return;
01593 }
01594 #ifdef PARA_DEBUG
01595 printf ("onsameHostPartialCopy: thread %d at start\n", myInput->threadNum);
01596 #endif
01597
01598 myInput->status = 0;
01599 destL3descInx = myInput->destFd;
01600 srcL3descInx = myInput->srcFd;
01601 destRescTypeInx = myInput->destRescTypeInx;
01602 srcRescTypeInx = myInput->srcRescTypeInx;
01603 myInput->bytesWritten = 0;
01604
01605 if (myInput->offset != 0) {
01606 myOffset = _l3Lseek (myInput->rsComm, destRescTypeInx,
01607 destL3descInx, myInput->offset, SEEK_SET);
01608 if (myOffset < 0) {
01609 myInput->status = myOffset;
01610 rodsLog (LOG_NOTICE,
01611 "sameHostPartialCopy: _objSeek error, status = %d ",
01612 myInput->status);
01613 if (myInput->threadNum > 0) {
01614 _l3Close (myInput->rsComm, destRescTypeInx, destL3descInx);
01615 _l3Close (myInput->rsComm, srcRescTypeInx, srcL3descInx);
01616 }
01617 return;
01618 }
01619 myOffset = _l3Lseek (myInput->rsComm, srcRescTypeInx,
01620 srcL3descInx, myInput->offset, SEEK_SET);
01621 if (myOffset < 0) {
01622 myInput->status = myOffset;
01623 rodsLog (LOG_NOTICE,
01624 "sameHostPartialCopy: _objSeek error, status = %d ",
01625 myInput->status);
01626 if (myInput->threadNum > 0) {
01627 _l3Close (myInput->rsComm, destRescTypeInx, destL3descInx);
01628 _l3Close (myInput->rsComm, srcRescTypeInx, srcL3descInx);
01629 }
01630 return;
01631 }
01632 }
01633
01634 buf = malloc (TRANS_BUF_SZ);
01635
01636 toCopy = myInput->size;
01637
01638 while (toCopy > 0) {
01639 int toRead;
01640
01641 if (toCopy > TRANS_BUF_SZ) {
01642 toRead = TRANS_BUF_SZ;
01643 } else {
01644 toRead = toCopy;
01645 }
01646
01647 bytesRead = _l3Read (myInput->rsComm, srcRescTypeInx,
01648 srcL3descInx, buf, toRead);
01649
01650 if (bytesRead <= 0) {
01651 if (bytesRead < 0) {
01652 myInput->status = bytesRead;
01653 rodsLogError (LOG_ERROR, bytesRead,
01654 "sameHostPartialCopy: copy error for %lld", bytesRead);
01655 } else if ((myInput->flags & NO_CHK_COPY_LEN_FLAG) == 0) {
01656 myInput->status = SYS_COPY_LEN_ERR - errno;
01657 rodsLog (LOG_ERROR,
01658 "sameHostPartialCopy: toCopy %lld, bytesRead %d",
01659 toCopy, bytesRead);
01660 }
01661 break;
01662 }
01663
01664 bytesWritten = _l3Write (myInput->rsComm, destRescTypeInx,
01665 destL3descInx, buf, bytesRead);
01666
01667 if (bytesWritten != bytesRead) {
01668 rodsLog (LOG_NOTICE,
01669 "sameHostPartialCopy:Bytes written %d don't match read %d",
01670 bytesWritten, bytesRead);
01671
01672 if (bytesWritten < 0) {
01673 myInput->status = bytesWritten;
01674 } else {
01675 myInput->status = SYS_COPY_LEN_ERR;
01676 }
01677 break;
01678 }
01679
01680 toCopy -= bytesWritten;
01681 myInput->bytesWritten += bytesWritten;
01682 }
01683
01684 free (buf);
01685 if (myInput->threadNum > 0) {
01686 _l3Close (myInput->rsComm, destRescTypeInx, destL3descInx);
01687 _l3Close (myInput->rsComm, srcRescTypeInx, srcL3descInx);
01688 }
01689 }
01690
01691 void
01692 locToRemPartialCopy (portalTransferInp_t *myInput)
01693 {
01694 transferHeader_t myHeader;
01695 int srcL3descInx = 0, destFd = 0, srcRescTypeInx = 0;
01696 unsigned char *buf = 0;
01697 rodsLong_t curOffset = 0;
01698 rodsLong_t myOffset = 0;
01699 int toRead = 0, bytesRead = 0, bytesWritten = 0;
01700
01701 if (myInput == NULL) {
01702 rodsLog (LOG_NOTICE,
01703 "locToRemPartialCopy: NULL input");
01704 return;
01705 }
01706 #ifdef PARA_DEBUG
01707 printf ("locToRemPartialCopy: thread %d at start\n", myInput->threadNum);
01708 #endif
01709
01710 myInput->status = 0;
01711 srcL3descInx = myInput->srcFd;
01712 destFd = myInput->destFd;
01713 srcRescTypeInx = myInput->srcRescTypeInx;
01714 myInput->bytesWritten = 0;
01715
01716
01717
01718 bool use_encryption_flg =
01719 ( myInput->rsComm->negotiation_results ==
01720 eirods::CS_NEG_USE_SSL );
01721
01722
01723
01724 int iv_size = 0;
01725 eirods::buffer_crypt::array_t iv;
01726 eirods::buffer_crypt::array_t cipher;
01727 eirods::buffer_crypt::array_t in_buf;
01728 eirods::buffer_crypt::array_t shared_secret;
01729 eirods::buffer_crypt crypt(
01730 myInput->key_size,
01731 myInput->salt_size,
01732 myInput->num_hash_rounds,
01733 myInput->encryption_algorithm );
01734
01735
01736
01737 if( use_encryption_flg ) {
01738 iv_size = crypt.key_size();
01739 shared_secret.assign(
01740 &myInput->shared_secret[0],
01741 &myInput->shared_secret[iv_size] );
01742
01743 }
01744
01745 buf = (unsigned char*)malloc( 2*TRANS_BUF_SZ * sizeof( unsigned char ) );
01746
01747 while (myInput->status >= 0) {
01748 rodsLong_t toGet;
01749
01750 myInput->status = rcvTranHeader (destFd, &myHeader);
01751
01752 #ifdef PARA_DEBUG
01753 printf ("locToRemPartialCopy: thread %d after rcvTranHeader\n",
01754 myInput->threadNum);
01755 #endif
01756
01757 if (myInput->status < 0) {
01758 break;
01759 }
01760
01761 if (myHeader.oprType == DONE_OPR) {
01762 break;
01763 }
01764 #ifdef PARA_DEBUG
01765 printf ("locToRemPartialCopy:thread %d header offset %lld, len %lld",
01766 myInput->threadNum, myHeader.offset, myHeader.length);
01767 #endif
01768
01769 if (myHeader.offset != curOffset) {
01770 curOffset = myHeader.offset;
01771 myOffset = _l3Lseek (myInput->rsComm, srcRescTypeInx,
01772 srcL3descInx, myHeader.offset, SEEK_SET);
01773 if (myOffset < 0) {
01774 myInput->status = myOffset;
01775 rodsLog (LOG_NOTICE,
01776 "locToRemPartialCopy: _objSeek error, status = %d ",
01777 myInput->status);
01778 break;
01779 }
01780 }
01781
01782 toGet = myHeader.length;
01783 while (toGet > 0) {
01784
01785 if (toGet > TRANS_BUF_SZ) {
01786 toRead = TRANS_BUF_SZ;
01787 } else {
01788 toRead = toGet;
01789 }
01790
01791 bytesRead = _l3Read ( myInput->rsComm, srcRescTypeInx,
01792 srcL3descInx, buf, toRead);
01793
01794 if (bytesRead != toRead) {
01795 if (bytesRead < 0) {
01796 myInput->status = bytesRead;
01797 rodsLogError (LOG_ERROR, bytesRead,
01798 "locToRemPartialCopy: copy error for %lld", bytesRead);
01799 } else if ((myInput->flags & NO_CHK_COPY_LEN_FLAG) == 0) {
01800 myInput->status = SYS_COPY_LEN_ERR - errno;
01801 rodsLog (LOG_ERROR,
01802 "locToRemPartialCopy: toGet %lld, bytesRead %d",
01803 toGet, bytesRead);
01804 }
01805 break;
01806 }
01807
01808
01809
01810
01811 int new_size = bytesRead;
01812 if( use_encryption_flg ) {
01813 eirods::error ret = crypt.initialization_vector( iv );
01814 if( !ret.ok() ) {
01815 ret = PASS( ret );
01816 printf( "%s", ret.result().c_str() );
01817 break;
01818 }
01819
01820
01821
01822 in_buf.assign(
01823 &buf[0],
01824 &buf[ bytesRead ] );
01825
01826 ret = crypt.encrypt(
01827 shared_secret,
01828 iv,
01829 in_buf,
01830 cipher );
01831 if( !ret.ok() ) {
01832 ret = PASS( ret );
01833 printf( "%s", ret.result().c_str() );
01834 break;
01835 }
01836
01837
01838
01839 std::copy(
01840 iv.begin(),
01841 iv.end(),
01842 &buf[0] );
01843 std::copy(
01844 cipher.begin(),
01845 cipher.end(),
01846 &buf[iv_size] );
01847
01848 new_size = iv.size() + cipher.size();
01849
01850
01851
01852
01853 bytesWritten = myWrite(
01854 destFd,
01855 &new_size,
01856 sizeof( int ),
01857 SOCK_TYPE,
01858 &bytesWritten );
01859 }
01860
01861 bytesWritten = myWrite(
01862 destFd,
01863 buf,
01864 new_size,
01865 SOCK_TYPE,
01866 NULL );
01867
01868 if( bytesWritten != new_size ) {
01869 rodsLog (LOG_NOTICE,
01870 "_partialDataPut:Bytes written %d don't match read %d",
01871 bytesWritten, bytesRead);
01872
01873 if (bytesWritten < 0) {
01874 myInput->status = bytesWritten;
01875 } else {
01876 myInput->status = SYS_COPY_LEN_ERR;
01877 }
01878 break;
01879 }
01880
01881 toGet -= bytesRead;
01882 }
01883
01884 curOffset += myHeader.length;
01885 myInput->bytesWritten += myHeader.length;
01886 }
01887
01888 free (buf);
01889 if (myInput->threadNum > 0)
01890 _l3Close (myInput->rsComm, srcRescTypeInx, srcL3descInx);
01891 CLOSE_SOCK (destFd);
01892 }
01893
01894
01895
01896
01897
01898
01899
01900 void
01901 getZoneServerId(char *zoneName, char *zoneSID) {
01902 zoneInfo_t *tmpZoneInfo;
01903 rodsServerHost_t *tmpRodsServerHost;
01904 int i;
01905 int zoneNameLen=0;
01906 char *localZoneName=NULL;
01907 char matchStr[MAX_NAME_LEN+2];
01908
01909 if (zoneName!=NULL) zoneNameLen=strlen(zoneName);
01910 if (zoneNameLen==0) {
01911 strncpy(zoneSID, localSID, MAX_PASSWORD_LEN);
01912 return;
01913 }
01914
01915
01916 tmpZoneInfo = ZoneInfoHead;
01917 while (tmpZoneInfo != NULL) {
01918 tmpRodsServerHost = (rodsServerHost_t *) tmpZoneInfo->masterServerHost;
01919 if (tmpRodsServerHost->rcatEnabled == LOCAL_ICAT) {
01920 localZoneName = tmpZoneInfo->zoneName;
01921 }
01922 tmpZoneInfo = tmpZoneInfo->next;
01923 }
01924
01925
01926 if (localZoneName!=NULL) {
01927 if (strncmp(localZoneName, zoneName, MAX_NAME_LEN)==0) {
01928 strncpy(zoneSID, localSID, MAX_PASSWORD_LEN);
01929 return;
01930 }
01931 }
01932
01933
01934 strncpy(matchStr, zoneName, MAX_NAME_LEN);
01935 strncat(matchStr, "-", MAX_NAME_LEN);
01936 for (i=0;i<MAX_FED_RSIDS;i++) {
01937 if (strncmp(matchStr, remoteSID[i], zoneNameLen+1)==0) {
01938 strncpy(zoneSID, (char*)&remoteSID[i][zoneNameLen+1],
01939 MAX_PASSWORD_LEN);
01940 return;
01941 }
01942 }
01943
01944 zoneSID[0]='\0';
01945 return;
01946 }
01947
01948 int
01949 isUserPrivileged(rsComm_t *rsComm)
01950 {
01951
01952 if (rsComm->clientUser.authInfo.authFlag < LOCAL_PRIV_USER_AUTH) {
01953 return(CAT_INSUFFICIENT_PRIVILEGE_LEVEL);
01954 }
01955 if (rsComm->proxyUser.authInfo.authFlag < LOCAL_PRIV_USER_AUTH) {
01956 return(CAT_INSUFFICIENT_PRIVILEGE_LEVEL);
01957 }
01958
01959 return(0);
01960 }
01961
01962 #if !defined(solaris_platform)
01963 char *regcmp (char *pat, char *end)
01964 {
01965 return(NULL);
01966 }
01967
01968 char *regex (char *rec, char *text, ...)
01969 {
01970 return(NULL);
01971 }
01972 #endif
01973
01974
01975
01976 int
01977 #ifdef __cplusplus
01978 intNoSupport( ... )
01979 #else
01980 intNoSupport()
01981 #endif
01982 {
01983 return SYS_NOT_SUPPORTED;
01984 }
01985
01986 rodsLong_t
01987 #ifdef __cplusplus
01988 longNoSupport( ... )
01989 #else
01990 longNoSupport()
01991 #endif
01992 {
01993 return (rodsLong_t) SYS_NOT_SUPPORTED;
01994 }
01995
01996 #ifdef RBUDP_TRANSFER
01997 int
01998 svrPortalPutGetRbudp (rsComm_t *rsComm)
01999 {
02000 portalOpr_t *myPortalOpr;
02001 portList_t *thisPortList;
02002 int lsock;
02003 int tcpSock, udpSockfd;
02004 int udpPortBuf;
02005 int status;
02006 #if defined(aix_platform)
02007 socklen_t laddrlen = sizeof(struct sockaddr);
02008 #elif defined(windows_platform)
02009 int laddrlen = sizeof(struct sockaddr);
02010 #else
02011 uint laddrlen = sizeof(struct sockaddr);
02012 #endif
02013 int packetSize;
02014 char *tmpStr;
02015 int verbose;
02016
02017 myPortalOpr = rsComm->portalOpr;
02018
02019 if (myPortalOpr == NULL) {
02020 rodsLog (LOG_NOTICE, "svrPortalPutGetRbudp: NULL myPortalOpr");
02021 return (SYS_INTERNAL_NULL_INPUT_ERR);
02022 }
02023
02024 thisPortList = &myPortalOpr->portList;
02025 if (thisPortList == NULL) {
02026 rodsLog (LOG_NOTICE, "svrPortalPutGetRbudp: NULL portList");
02027 return (SYS_INTERNAL_NULL_INPUT_ERR);
02028 }
02029
02030 lsock = getTcpSockFromPortList (thisPortList);
02031
02032 tcpSock = acceptSrvPortal (rsComm, thisPortList);
02033 if (tcpSock < 0) {
02034 rodsLog (LOG_NOTICE,
02035 "svrPortalPutGetRbudp: acceptSrvPortal error. errno = %d",
02036 errno);
02037 CLOSE_SOCK (lsock);
02038 return (tcpSock);
02039 } else {
02040 CLOSE_SOCK (lsock);
02041 }
02042 status = readn (tcpSock, (char *) &udpPortBuf, sizeof (udpPortBuf));
02043 if (status != sizeof (udpPortBuf)) {
02044 rodsLog (LOG_ERROR,
02045 "svrPortalPutGetRbudp: readn error. toread %d, bytes read %d ",
02046 sizeof (udpPortBuf), status);
02047 return (SYS_UDP_CONNECT_ERR);
02048 }
02049
02050 if ((tmpStr = getValByKey (&myPortalOpr->dataOprInp.condInput,
02051 RBUDP_PACK_SIZE_KW)) != NULL) {
02052 packetSize = atoi (tmpStr);
02053 } else {
02054 packetSize = DEF_UDP_PACKET_SIZE;
02055 }
02056
02057 if (getValByKey (&myPortalOpr->dataOprInp.condInput, VERY_VERBOSE_KW) !=
02058 NULL)
02059 verbose = 2;
02060 else
02061 verbose = 0;
02062
02063 udpSockfd = getUdpSockFromPortList (thisPortList);
02064
02065 checkbuf (udpSockfd, UDPSOCKBUF, verbose);
02066 if (myPortalOpr->oprType == PUT_OPR) {
02067 rbudpReceiver_t rbudpReceiver;
02068 bzero (&rbudpReceiver, sizeof (rbudpReceiver));
02069 int destL3descInx = myPortalOpr->dataOprInp.destL3descInx;
02070
02071 rbudpReceiver.rbudpBase.verbose = verbose;
02072 rbudpReceiver.rbudpBase.udpSockBufSize = UDPSOCKBUF;
02073 rbudpReceiver.rbudpBase.tcpPort = getTcpPortFromPortList (thisPortList);
02074 rbudpReceiver.rbudpBase.tcpSockfd = tcpSock;
02075 rbudpReceiver.rbudpBase.udpSockfd = udpSockfd;
02076 rbudpReceiver.rbudpBase.hasTcpSock = 0;
02077 rbudpReceiver.rbudpBase.udpRemotePort = ntohl (udpPortBuf);
02078
02079 if (getpeername (tcpSock,
02080 (struct sockaddr *) &rbudpReceiver.rbudpBase.udpServerAddr,
02081 &laddrlen) < 0) {
02082 rodsLog (LOG_NOTICE,
02083 "svrPortalPutGetRbudp() - getpeername() failed: errno=%d",
02084 errno);
02085 recvClose (&rbudpReceiver);
02086 return (USER_RODS_HOSTNAME_ERR);
02087 }
02088
02089 rbudpReceiver.rbudpBase.udpServerAddr.sin_port = htons (rbudpReceiver.rbudpBase.udpRemotePort);
02090
02091 status = getfileByFd(
02092 &rbudpReceiver,
02093 FileDesc[destL3descInx].fd,
02094 packetSize );
02095
02096 if (status < 0) {
02097 rodsLog (LOG_ERROR,
02098 "svrPortalPutGetRbudp: getfileByFd error for %s",
02099 FileDesc[destL3descInx].fileName);
02100 status += SYS_UDP_TRANSFER_ERR;
02101 }
02102 recvClose (&rbudpReceiver);
02103 } else if (myPortalOpr->oprType == GET_OPR) {
02104
02105 int sendRate;
02106 rbudpSender_t rbudpSender;
02107 int srcL3descInx = myPortalOpr->dataOprInp.srcL3descInx;
02108
02109 bzero (&rbudpSender, sizeof (rbudpSender));
02110 rbudpSender.rbudpBase.verbose = verbose;
02111 rbudpSender.rbudpBase.udpSockBufSize = UDPSOCKBUF;
02112 rbudpSender.rbudpBase.tcpPort = getTcpPortFromPortList (thisPortList);
02113 rbudpSender.rbudpBase.tcpSockfd = tcpSock;
02114 rbudpSender.rbudpBase.udpSockfd = udpSockfd;
02115 rbudpSender.rbudpBase.hasTcpSock = 0;
02116 rbudpSender.rbudpBase.udpRemotePort = ntohl (udpPortBuf);
02117
02118 if (getpeername (tcpSock,
02119 (struct sockaddr *) &rbudpSender.rbudpBase.udpServerAddr,
02120 &laddrlen) < 0) {
02121 rodsLog (LOG_NOTICE,
02122 "svrPortalPutGetRbudp() - getpeername() failed: errno=%d",
02123 errno);
02124 sendClose (&rbudpSender);
02125 return (USER_RODS_HOSTNAME_ERR);
02126 }
02127 rbudpSender.rbudpBase.udpServerAddr.sin_port =
02128 htons (rbudpSender.rbudpBase.udpRemotePort);
02129 if ((tmpStr = getValByKey (&myPortalOpr->dataOprInp.condInput,
02130 RBUDP_SEND_RATE_KW)) != NULL) {
02131 sendRate = atoi (tmpStr);
02132 } else {
02133 sendRate = DEF_UDP_SEND_RATE;
02134 }
02135
02136 status = sendfileByFd(
02137 &rbudpSender,
02138 sendRate,
02139 packetSize,
02140 FileDesc[srcL3descInx].fd );
02141
02142 if (status < 0) {
02143 rodsLog (LOG_ERROR,
02144 "svrPortalPutGetRbudp: sendfile error for %s",
02145 FileDesc[srcL3descInx].fileName);
02146 status += SYS_UDP_TRANSFER_ERR;
02147 }
02148 sendClose (&rbudpSender);
02149 }
02150
02151 return (status);
02152 }
02153 #endif
02154 #ifndef windows_platform
02155 void
02156 reconnManager (rsComm_t *rsComm)
02157 {
02158 fd_set basemask;
02159 int nSockets, nSelected;
02160 struct sockaddr_in remoteAddr;
02161 socklen_t len;
02162 int newSock;
02163 reconnMsg_t *reconnMsg;
02164 int acceptFailCnt = 0;
02165
02166 if (rsComm == NULL || rsComm->reconnSock <= 0) {
02167 return;
02168 }
02169
02170 listen (rsComm->reconnSock, 1);
02171
02172 nSockets = rsComm->reconnSock + 1;
02173 FD_ZERO(&basemask);
02174 FD_SET(rsComm->reconnSock, &basemask);
02175
02176 while (1) {
02177 while ((nSelected = select (nSockets, &basemask,
02178 (fd_set *) NULL, (fd_set *) NULL, NULL)) < 0) {
02179 if (errno == EINTR) {
02180 rodsLog (LOG_NOTICE, "reconnManager: select interrupted\n");
02181 continue;
02182 } else {
02183 rodsLog (LOG_ERROR, "reconnManager: select failed, errno = %d",
02184 errno);
02185 boost::unique_lock< boost::mutex > boost_lock( *rsComm->lock );
02186 close (rsComm->reconnSock);
02187 rsComm->reconnSock = 0;
02188 boost_lock.unlock();
02189 return;
02190
02191 }
02192
02193 }
02194
02195
02196 len = sizeof (remoteAddr);
02197 bzero (&remoteAddr, sizeof (remoteAddr));
02198 newSock = accept (rsComm->reconnSock, (struct sockaddr *) &remoteAddr,
02199 &len);
02200 if (newSock < 0) {
02201 acceptFailCnt++;
02202 rodsLog (LOG_ERROR,
02203 "reconnManager: accept for sock %d failed, errno = %d",
02204 rsComm->reconnSock, errno);
02205 if (acceptFailCnt > MAX_RECON_ERROR_CNT) {
02206 rodsLog (LOG_ERROR,
02207 "reconnManager: accept failed cnt > 10, reconnManager exit");
02208 close (rsComm->reconnSock);
02209 rsComm->reconnSock = -1;
02210 rsComm->reconnPort = 0;
02211 return;
02212 } else {
02213 continue;
02214 }
02215 }
02216
02217
02218
02219 eirods::network_object_ptr net_obj;
02220 eirods::error ret = eirods::network_factory( rsComm, net_obj );
02221 if( !ret.ok() ) {
02222 eirods::log( PASS( ret ) );
02223 return;
02224 }
02225
02226
02227
02228 net_obj->socket_handle( newSock );
02229
02230 ret = readReconMsg( net_obj, &reconnMsg );
02231 if( !ret.ok() ) {
02232 eirods::log( PASS( ret ) );
02233 close (newSock);
02234 continue;
02235 } else if (reconnMsg->cookie != rsComm->cookie) {
02236 rodsLog (LOG_ERROR,
02237 "reconnManager: cookie mistach, got = %d vs %d",
02238 reconnMsg->cookie, rsComm->cookie);
02239 close (newSock);
02240 free (reconnMsg);
02241 continue;
02242 }
02243
02244 boost::unique_lock<boost::mutex> boost_lock( *rsComm->lock );
02245 rsComm->clientState = reconnMsg->procState;
02246 rsComm->reconnectedSock = newSock;
02247
02248 while (rsComm->agentState == SENDING_STATE) {
02249
02250 rsComm->reconnThrState = CONN_WAIT_STATE;
02251 rsComm->cond->wait( boost_lock );
02252 }
02253
02254 rsComm->reconnThrState = PROCESSING_STATE;
02255 bzero (reconnMsg, sizeof (procState_t));
02256 reconnMsg->procState = rsComm->agentState;
02257 ret = sendReconnMsg ( net_obj, reconnMsg);
02258 free (reconnMsg);
02259 if( !ret.ok() ) {
02260 eirods::log( PASS( ret ) );
02261 close (newSock);
02262 rsComm->reconnectedSock = 0;
02263 boost_lock.unlock();
02264 continue;
02265 }
02266 if (rsComm->agentState == PROCESSING_STATE) {
02267 rodsLog (LOG_NOTICE,
02268 "reconnManager: svrSwitchConnect. cliState = %d,agState=%d",
02269 rsComm->clientState, rsComm->agentState);
02270 svrSwitchConnect (rsComm);
02271 }
02272 boost_lock.unlock();
02273 }
02274 }
02275
02276 int
02277 svrChkReconnAtSendStart (rsComm_t *rsComm)
02278 {
02279 if (rsComm->reconnSock > 0) {
02280
02281 boost::unique_lock<boost::mutex> boost_lock( *rsComm->lock );
02282 if (rsComm->reconnThrState == CONN_WAIT_STATE) {
02283
02284 rodsLog (LOG_NOTICE,
02285 "svrChkReconnAtSendStart: ThrState = CONN_WAIT_STATE, agentState=%d",
02286 rsComm->agentState);
02287 rsComm->agentState = PROCESSING_STATE;
02288 rsComm->cond->notify_all();
02289 }
02290 svrSwitchConnect (rsComm);
02291 rsComm->agentState = SENDING_STATE;
02292 boost_lock.unlock();
02293 }
02294 return 0;
02295 }
02296
02297 int
02298 svrChkReconnAtSendEnd (rsComm_t *rsComm)
02299 {
02300 if (rsComm->reconnSock > 0) {
02301
02302 boost::unique_lock<boost::mutex> boost_lock( *rsComm->lock );
02303 rsComm->agentState = PROCESSING_STATE;
02304 if (rsComm->reconnThrState == CONN_WAIT_STATE) {
02305 rsComm->cond->wait( boost_lock );
02306 }
02307 boost_lock.unlock();
02308 }
02309 return 0;
02310 }
02311
02312 int
02313 svrChkReconnAtReadStart (rsComm_t *rsComm)
02314 {
02315 if (rsComm->reconnSock > 0) {
02316
02317 boost::unique_lock< boost::mutex > boost_lock( *rsComm->lock );
02318 if (rsComm->reconnThrState == CONN_WAIT_STATE) {
02319
02320 rodsLog (LOG_NOTICE,
02321 "svrChkReconnAtReadStart: ThrState = CONN_WAIT_STATE, agentState=%d",
02322 rsComm->agentState);
02323 rsComm->agentState = PROCESSING_STATE;
02324 rsComm->cond->wait( boost_lock );
02325 }
02326 svrSwitchConnect (rsComm);
02327 rsComm->agentState = RECEIVING_STATE;
02328 boost_lock.unlock();
02329 }
02330 return 0;
02331 }
02332
02333 int
02334 svrChkReconnAtReadEnd (rsComm_t *rsComm)
02335 {
02336 if (rsComm->reconnSock > 0) {
02337
02338 boost::unique_lock< boost::mutex > boost_lock( *rsComm->lock );
02339 rsComm->agentState = PROCESSING_STATE;
02340 if (rsComm->reconnThrState == CONN_WAIT_STATE) {
02341 rsComm->cond->notify_all();
02342 }
02343 boost_lock.unlock();
02344 }
02345 return 0;
02346 }
02347
02348 #endif
02349
02350 int
02351 svrSockOpenForInConn (rsComm_t *rsComm, int *portNum, char **addr, int proto)
02352 {
02353 int status;
02354
02355 status = sockOpenForInConn (rsComm, portNum, addr, proto);
02356 if (status < 0) return status;
02357
02358 if (addr != NULL && *addr != NULL &&
02359 (strcmp (*addr, "127.0.0.1") == 0 || strcmp (*addr, "0.0.0.0") == 0 ||
02360 strcmp (*addr, "localhost") == 0)) {
02361
02362 char *myaddr;
02363
02364 myaddr = getLocalSvrAddr ();
02365 if (myaddr != NULL) {
02366 free (*addr);
02367 *addr = strdup (myaddr);
02368 } else {
02369 rodsLog (LOG_NOTICE,
02370 "svrSockOpenForInConn: problem resolving local host addr %s",
02371 *addr);
02372 }
02373 }
02374 return status;
02375 }
02376
02377 char *
02378 getLocalSvrAddr ()
02379 {
02380 char *myHost;
02381 myHost = _getSvrAddr (LocalServerHost);
02382 return myHost;
02383 }
02384
02385 char *
02386 _getSvrAddr (rodsServerHost_t *rodsServerHost)
02387 {
02388 hostName_t *tmpHostName;
02389
02390 if (rodsServerHost == NULL) return NULL;
02391
02392 tmpHostName = rodsServerHost->hostName;
02393 while (tmpHostName != NULL) {
02394 if (strcmp (tmpHostName->name, "localhost") != 0 &&
02395 strcmp (tmpHostName->name, "127.0.0.1") != 0 &&
02396 strcmp (tmpHostName->name, "0.0.0.0") != 0 &&
02397 strchr (tmpHostName->name, '.') != NULL) {
02398 return (tmpHostName->name);
02399 }
02400 tmpHostName = tmpHostName->next;
02401 }
02402 return (NULL);
02403 }
02404
02405 char *
02406 getSvrAddr (rodsServerHost_t *rodsServerHost)
02407 {
02408 char *myHost;
02409
02410 myHost = _getSvrAddr (rodsServerHost);
02411 if (myHost == NULL) {
02412
02413 myHost = rodsServerHost->hostName->name;
02414 }
02415 return myHost;
02416 }
02417
02418 int
02419 setLocalSrvAddr (char *outLocalAddr)
02420 {
02421 char *myHost;
02422
02423 if (outLocalAddr == NULL) return USER__NULL_INPUT_ERR;
02424
02425 myHost = getSvrAddr (LocalServerHost);
02426
02427 if (myHost != NULL) {
02428 rstrcpy (outLocalAddr, myHost, NAME_LEN);
02429 return 0;
02430 } else {
02431 return SYS_INVALID_SERVER_HOST;
02432 }
02433 }
02434
02435 int
02436 forkAndExec (char *av[])
02437 {
02438 int childPid = 0;
02439 int status = -1;
02440 int childStatus = 0;
02441
02442
02443 #ifndef windows_platform
02444 childPid = RODS_FORK ();
02445
02446 if (childPid == 0) {
02447
02448 execv(av[0], av);
02449
02450 exit(1);
02451 } else if (childPid < 0) {
02452 rodsLog (LOG_ERROR,
02453 "exectar: RODS_FORK failed. errno = %d", errno);
02454 return (SYS_FORK_ERROR);
02455 }
02456
02457
02458
02459 status = waitpid (childPid, &childStatus, 0);
02460 if (status >= 0 && childStatus != 0) {
02461 rodsLog (LOG_ERROR,
02462 "forkAndExec: waitpid status = %d, childStatus = %d",
02463 status, childStatus);
02464 status = EXEC_CMD_ERROR;
02465 }
02466 #else
02467 rodsLog (LOG_ERROR,
02468 "forkAndExec: fork and exec not supported");
02469
02470 status = SYS_NOT_SUPPORTED;
02471 #endif
02472 return status;
02473 }
02474
02475 int
02476 singleRemLocCopy (rsComm_t *rsComm, dataCopyInp_t *dataCopyInp)
02477 {
02478 dataOprInp_t *dataOprInp;
02479 int status = 0;
02480 int oprType;
02481
02482 if (dataCopyInp == NULL) {
02483 rodsLog (LOG_NOTICE,
02484 "remLocCopy: NULL dataCopyInp input");
02485 return (SYS_INTERNAL_NULL_INPUT_ERR);
02486 }
02487 dataOprInp = &dataCopyInp->dataOprInp;
02488 oprType = dataOprInp->oprType;
02489
02490 if (oprType == COPY_TO_LOCAL_OPR) {
02491 status = singleRemToLocCopy (rsComm, dataCopyInp);
02492 } else {
02493 status = singleLocToRemCopy (rsComm, dataCopyInp);
02494 }
02495 return status;
02496 }
02497
02498 int
02499 singleRemToLocCopy (rsComm_t *rsComm, dataCopyInp_t *dataCopyInp)
02500 {
02501 dataOprInp_t *dataOprInp;
02502 rodsLong_t dataSize;
02503 int l1descInx;
02504 int destL3descInx;
02505 int destRescTypeInx;
02506 bytesBuf_t dataObjReadInpBBuf;
02507 openedDataObjInp_t dataObjReadInp;
02508 int bytesWritten, bytesRead;
02509 rodsLong_t totalWritten = 0;
02510
02511
02512 if (dataCopyInp == NULL) {
02513 rodsLog (LOG_NOTICE,
02514 "singleRemToLocCopy: NULL dataCopyInp input");
02515 return (SYS_INTERNAL_NULL_INPUT_ERR);
02516 }
02517 dataOprInp = &dataCopyInp->dataOprInp;
02518 l1descInx = dataCopyInp->portalOprOut.l1descInx;
02519 destL3descInx = dataOprInp->destL3descInx;
02520 destRescTypeInx = dataOprInp->destRescTypeInx;
02521 dataSize = dataOprInp->dataSize;
02522
02523 bzero (&dataObjReadInp, sizeof (dataObjReadInp));
02524 dataObjReadInpBBuf.buf = malloc (TRANS_BUF_SZ);
02525 dataObjReadInpBBuf.len = dataObjReadInp.len = TRANS_BUF_SZ;
02526 dataObjReadInp.l1descInx = l1descInx;
02527 while ((bytesRead = rsDataObjRead (rsComm, &dataObjReadInp,
02528 &dataObjReadInpBBuf)) > 0) {
02529 bytesWritten = _l3Write (rsComm, destRescTypeInx,
02530 destL3descInx, dataObjReadInpBBuf.buf, bytesRead);
02531
02532 if (bytesWritten != bytesRead) {
02533 rodsLog (LOG_ERROR,
02534 "singleRemToLocCopy: Read %d bytes, Wrote %d bytes.\n ",
02535 bytesRead, bytesWritten);
02536 free (dataObjReadInpBBuf.buf);
02537 return (SYS_COPY_LEN_ERR);
02538 } else {
02539 totalWritten += bytesWritten;
02540 }
02541 }
02542 free (dataObjReadInpBBuf.buf);
02543 if (dataSize <= 0 || totalWritten == dataSize ||
02544 getValByKey (&dataOprInp->condInput, NO_CHK_COPY_LEN_KW) != NULL) {
02545 return (0);
02546 } else {
02547 rodsLog (LOG_ERROR,
02548 "singleRemToLocCopy: totalWritten %lld dataSize %lld mismatch",
02549 totalWritten, dataSize);
02550 return (SYS_COPY_LEN_ERR);
02551 }
02552 }
02553
02554 int
02555 singleLocToRemCopy (rsComm_t *rsComm, dataCopyInp_t *dataCopyInp)
02556 {
02557 dataOprInp_t *dataOprInp;
02558 rodsLong_t dataSize;
02559 int l1descInx;
02560 int srcL3descInx;
02561 int srcRescTypeInx;
02562 bytesBuf_t dataObjWriteInpBBuf;
02563 openedDataObjInp_t dataObjWriteInp;
02564 int bytesWritten, bytesRead;
02565 rodsLong_t totalWritten = 0;
02566
02567
02568 if (dataCopyInp == NULL) {
02569 rodsLog (LOG_NOTICE,
02570 "singleRemToLocCopy: NULL dataCopyInp input");
02571 return (SYS_INTERNAL_NULL_INPUT_ERR);
02572 }
02573 dataOprInp = &dataCopyInp->dataOprInp;
02574 l1descInx = dataCopyInp->portalOprOut.l1descInx;
02575 srcL3descInx = dataOprInp->srcL3descInx;
02576 srcRescTypeInx = dataOprInp->srcRescTypeInx;
02577 dataSize = dataOprInp->dataSize;
02578
02579 bzero (&dataObjWriteInp, sizeof (dataObjWriteInp));
02580 dataObjWriteInpBBuf.buf = malloc (TRANS_BUF_SZ);
02581 dataObjWriteInpBBuf.len = 0;
02582 dataObjWriteInp.l1descInx = l1descInx;
02583
02584 while ((bytesRead = _l3Read (rsComm, srcRescTypeInx,
02585 srcL3descInx, dataObjWriteInpBBuf.buf, TRANS_BUF_SZ)) > 0) {
02586 dataObjWriteInp.len = dataObjWriteInpBBuf.len = bytesRead;
02587 bytesWritten = rsDataObjWrite (rsComm, &dataObjWriteInp,
02588 &dataObjWriteInpBBuf);
02589 if (bytesWritten != bytesRead) {
02590 rodsLog (LOG_ERROR,
02591 "singleLocToRemCopy: Read %d bytes, Wrote %d bytes.\n ",
02592 bytesRead, bytesWritten);
02593 free (dataObjWriteInpBBuf.buf);
02594 return (SYS_COPY_LEN_ERR);
02595 } else {
02596 totalWritten += bytesWritten;
02597 }
02598 }
02599 free (dataObjWriteInpBBuf.buf);
02600 if (dataSize <= 0 || totalWritten == dataSize ||
02601 getValByKey (&dataOprInp->condInput, NO_CHK_COPY_LEN_KW) != NULL) {
02602 return (0);
02603 } else {
02604 rodsLog (LOG_ERROR,
02605 "singleLocToRemCopy: totalWritten %lld dataSize %lld mismatch",
02606 totalWritten, dataSize);
02607 return (SYS_COPY_LEN_ERR);
02608 }
02609 }
02610
02611
02612
02613
02614
02615 int
02616 readStartupPack(
02617 eirods::network_object_ptr _ptr,
02618 startupPack_t** startupPack,
02619 struct timeval* tv ) {
02620 int status;
02621 msgHeader_t myHeader;
02622 bytesBuf_t inputStructBBuf, bsBBuf, errorBBuf;
02623 eirods::error ret = readMsgHeader( _ptr, &myHeader, tv );
02624 if( !ret.ok() ) {
02625 eirods::log( PASS( ret ) );
02626 return ret.code();
02627 }
02628
02629 if (myHeader.msgLen > (int) sizeof (startupPack_t) * 2 ||
02630 myHeader.msgLen <= 0) {
02631 rodsLog (LOG_NOTICE,
02632 "readStartupPack: problem with myHeader.msgLen = %d",
02633 myHeader.msgLen);
02634 return (SYS_HEADER_READ_LEN_ERR);
02635 }
02636
02637 memset (&bsBBuf, 0, sizeof (bytesBuf_t));
02638 ret = readMsgBody(
02639 _ptr,
02640 &myHeader,
02641 &inputStructBBuf,
02642 &bsBBuf,
02643 &errorBBuf,
02644 XML_PROT,
02645 tv );
02646 if( !ret.ok() ) {
02647 eirods::log( PASS( ret ) );
02648 return ret.code();
02649 }
02650
02651
02652
02653 if (strcmp (myHeader.type, RODS_CONNECT_T) != 0) {
02654 if (inputStructBBuf.buf != NULL)
02655 free (inputStructBBuf.buf);
02656 if (bsBBuf.buf != NULL)
02657 free (inputStructBBuf.buf);
02658 if (errorBBuf.buf != NULL)
02659 free (inputStructBBuf.buf);
02660 rodsLog (LOG_NOTICE,
02661 "readStartupPack: wrong mag type - %s, expect %s",
02662 myHeader.type, RODS_CONNECT_T);
02663 return (SYS_HEADER_TYPE_LEN_ERR);
02664 }
02665
02666 if (myHeader.bsLen != 0) {
02667 if (bsBBuf.buf != NULL)
02668 free (inputStructBBuf.buf);
02669 rodsLog (LOG_NOTICE, "readStartupPack: myHeader.bsLen = %d is not 0",
02670 myHeader.bsLen);
02671 }
02672
02673 if (myHeader.errorLen != 0) {
02674 if (errorBBuf.buf != NULL)
02675 free (inputStructBBuf.buf);
02676 rodsLog (LOG_NOTICE,
02677 "readStartupPack: myHeader.errorLen = %d is not 0",
02678 myHeader.errorLen);
02679 }
02680
02681
02682 status = unpackStruct (inputStructBBuf.buf, (void **) startupPack,
02683 "StartupPack_PI", RodsPackTable, XML_PROT);
02684
02685 clearBBuf (&inputStructBBuf);
02686
02687 if (status >= 0) {
02688 if ((*startupPack)->clientUser[0] != '\0' &&
02689 (*startupPack)->clientRodsZone[0] == '\0') {
02690 char *zoneName;
02691
02692 if ((zoneName = getLocalZoneName ()) != NULL) {
02693 rstrcpy ((*startupPack)->clientRodsZone, zoneName, NAME_LEN);
02694 }
02695 }
02696 if ((*startupPack)->proxyUser[0] != '\0' &&
02697 (*startupPack)->proxyRodsZone[0] == '\0') {
02698 char *zoneName;
02699
02700 if ((zoneName = getLocalZoneName ()) != NULL) {
02701 rstrcpy ((*startupPack)->proxyRodsZone, zoneName, NAME_LEN);
02702 }
02703 }
02704 } else {
02705 rodsLogError (LOG_NOTICE, status,
02706 "readStartupPack:unpackStruct error. status = %d",
02707 status);
02708 }
02709
02710 return (status);
02711 }
02712
02713
02714 #ifdef RUN_SERVER_AS_ROOT
02715
02716
02717
02718
02719
02720
02721 int
02722 initServiceUser()
02723 {
02724 #ifndef windows_platform
02725 char *serviceUser;
02726 struct passwd *pwent;
02727
02728 serviceUser = getenv("irodsServiceUser");
02729 if (serviceUser == NULL || getuid() != 0) {
02730
02731
02732 return (0);
02733 }
02734
02735
02736
02737 errno = 0;
02738 pwent = getpwnam(serviceUser);
02739 if (pwent) {
02740 ServiceUid = pwent->pw_uid;
02741 return (changeToServiceUser());
02742 }
02743
02744 if (errno) {
02745 rodsLogError(LOG_ERROR, SYS_USER_RETRIEVE_ERR,
02746 "setServiceUser: error in getpwnam %s, errno = %d",
02747 serviceUser, errno);
02748 return (SYS_USER_RETRIEVE_ERR - errno);
02749 }
02750 else {
02751 rodsLogError(LOG_ERROR, SYS_USER_RETRIEVE_ERR,
02752 "setServiceUser: user %s doesn't exist", serviceUser);
02753 return (SYS_USER_RETRIEVE_ERR);
02754 }
02755 #else
02756 return (0);
02757 #endif
02758 }
02759
02760
02761
02762 int
02763 isServiceUserSet()
02764 {
02765 if (ServiceUid) {
02766 return 1;
02767 }
02768 else {
02769 return 0;
02770 }
02771 }
02772
02773
02774
02775
02776 int
02777 changeToRootUser()
02778 {
02779 int prev_errno, my_errno;
02780
02781 if (!isServiceUserSet()) {
02782
02783 return (0);
02784 }
02785
02786 #ifndef windows_platform
02787
02788
02789
02790 prev_errno = errno;
02791 if (seteuid(0) == -1) {
02792 my_errno = errno;
02793 errno = prev_errno;
02794 rodsLogError(LOG_ERROR, SYS_USER_NO_PERMISSION - my_errno,
02795 "changeToRootUser: can't change to root user id");
02796 return (SYS_USER_NO_PERMISSION - my_errno);
02797 }
02798 #endif
02799
02800 return (0);
02801 }
02802
02803
02804
02805
02806
02807 int
02808 changeToServiceUser()
02809 {
02810 int prev_errno, my_errno;
02811
02812 if (!isServiceUserSet()) {
02813
02814 return (0);
02815 }
02816
02817 #ifndef windows_platform
02818 prev_errno = errno;
02819 if (seteuid(ServiceUid) == -1) {
02820 my_errno = errno;
02821 errno = prev_errno;
02822 rodsLogError(LOG_ERROR, SYS_USER_NO_PERMISSION - my_errno,
02823 "changeToServiceUser: can't change to service user id");
02824 return (SYS_USER_NO_PERMISSION - my_errno);
02825 }
02826 #endif
02827
02828 return (0);
02829 }
02830
02831 #endif
02832
02833