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