00001
00002
00003
00004 #include <stdarg.h>
00005 #include "eraUtil.h"
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 int
00018 appendStrToBBuf(bytesBuf_t *dest, char *str)
00019 {
00020 int written;
00021
00022 if (str==NULL) {
00023 return (-1);
00024 }
00025
00026
00027 written = appendFormattedStrToBBuf(dest, strlen(str)+1, "%s", str);
00028
00029 return (written);
00030 }
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 int
00043 appendFormattedStrToBBuf(bytesBuf_t *dest, size_t size, const char *format, ...)
00044 {
00045 va_list ap;
00046 int written;
00047 size_t index=0;
00048 char *tmpPtr;
00049
00050
00051 if (dest->buf==NULL) {
00052 dest->len=size+1;
00053 dest->buf=(char *)malloc(dest->len);
00054 memset(dest->buf, '\0', dest->len);
00055 }
00056
00057
00058 index = strlen((char *)dest->buf);
00059
00060
00061 if (index+size >= (size_t)dest->len) {
00062 dest->len=2*(index+size);
00063 tmpPtr=(char *)malloc(dest->len);
00064 memset(tmpPtr, '\0', dest->len);
00065 strncpy(tmpPtr, (char*)dest->buf, dest->len);
00066 free(dest->buf);
00067 dest->buf=tmpPtr;
00068 }
00069
00070
00071 va_start(ap, format);
00072 written=vsnprintf(((char *)dest->buf)+index, size, format, ap);
00073 va_end(ap);
00074
00075 return (written);
00076 }
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086 int
00087 copyAVUMetadata(char *destPath, char *srcPath, rsComm_t *rsComm)
00088 {
00089 char destObjType[NAME_LEN];
00090 char srcObjType[NAME_LEN];
00091 modAVUMetadataInp_t modAVUMetadataInp;
00092 int status;
00093
00094
00095
00096 status = getObjType(rsComm, srcPath, srcObjType);
00097
00098 if (status == INVALID_OBJECT_TYPE) {
00099 rodsLogAndErrorMsg (LOG_ERROR, &rsComm->rError, status,
00100 "copyAVUMetadata: Invalid object type for source object: %s.", srcPath);
00101 return(status);
00102 }
00103
00104
00105
00106 status = getObjType(rsComm, destPath, destObjType);
00107
00108 if (status == INVALID_OBJECT_TYPE) {
00109 rodsLogAndErrorMsg (LOG_ERROR, &rsComm->rError, status,
00110 "copyAVUMetadata: Invalid object type for destination object: %s.", destPath);
00111 return(status);
00112 }
00113
00114
00115
00116 modAVUMetadataInp.arg0 = "cp";
00117 modAVUMetadataInp.arg1 = srcObjType;
00118 modAVUMetadataInp.arg2 = destObjType;
00119 modAVUMetadataInp.arg3 = srcPath;
00120 modAVUMetadataInp.arg4 = destPath;
00121 modAVUMetadataInp.arg5 = "";
00122 modAVUMetadataInp.arg6 = "";
00123 modAVUMetadataInp.arg7 = "";
00124 modAVUMetadataInp.arg8 = "";
00125 modAVUMetadataInp.arg9 = "";
00126
00127
00128
00129 status = rsModAVUMetadata(rsComm, &modAVUMetadataInp);
00130
00131 return(status);
00132
00133 }
00134
00135
00136
00137
00138
00139
00140
00141
00142 int
00143 recursiveCollCopy(collInp_t *destCollInp, collInp_t *srcCollInp, rsComm_t *rsComm)
00144 {
00145 char *destColl, *srcColl;
00146
00147 genQueryInp_t genQueryInp;
00148 genQueryOut_t *genQueryOut;
00149 char collQCond[2*MAX_NAME_LEN];
00150
00151 collInp_t collCreateInp;
00152 char destSubColl[MAX_NAME_LEN];
00153
00154 dataObjCopyInp_t dataObjCopyInp;
00155 dataObjInp_t srcDataObjInp, destDataObjInp;
00156 transferStat_t *transStat = NULL;
00157
00158 char *subCollName, *fileName;
00159
00160 int i;
00161 int status=0;
00162
00163
00164
00165 if (rsComm == NULL) {
00166 rodsLog (LOG_ERROR, "recursiveCollCopy: input rsComm is NULL");
00167 return (SYS_INTERNAL_NULL_INPUT_ERR);
00168 }
00169
00170
00171
00172 if ((destCollInp == NULL) || (destCollInp->collName == NULL)) {
00173 rodsLog (LOG_ERROR, "recursiveCollCopy: destination collection input is NULL");
00174 return (USER__NULL_INPUT_ERR);
00175 }
00176
00177 if ((srcCollInp == NULL) || (srcCollInp->collName == NULL)) {
00178 rodsLog (LOG_ERROR, "recursiveCollCopy: source collection input is NULL");
00179 return (USER__NULL_INPUT_ERR);
00180 }
00181
00182
00183
00184 destColl = destCollInp->collName;
00185 srcColl = srcCollInp->collName;
00186
00187
00188
00189
00190 memset (&genQueryInp, 0, sizeof (genQueryInp_t));
00191
00192
00193 genAllInCollQCond (srcColl, collQCond);
00194 addInxVal (&genQueryInp.sqlCondInp, COL_COLL_NAME, collQCond);
00195
00196
00197 addInxIval (&genQueryInp.selectInp, COL_COLL_NAME, 1);
00198
00199
00200 genQueryInp.maxRows = MAX_SQL_ROWS;
00201
00202
00203
00204 status = rsGenQuery (rsComm, &genQueryInp, &genQueryOut);
00205
00206
00207
00208 for (i=0; i < genQueryOut->rowCnt; i++) {
00209
00210
00211 subCollName = genQueryOut->sqlResult[0].value;
00212 subCollName += i*genQueryOut->sqlResult[0].len;
00213
00214
00215 snprintf(destSubColl, MAX_NAME_LEN, "%s%s", destColl, subCollName+strlen(srcColl));
00216
00217
00218 memset (&collCreateInp, 0, sizeof (collCreateInp));
00219 rstrcpy (collCreateInp.collName, destSubColl, MAX_NAME_LEN);
00220 rsCollCreate (rsComm, &collCreateInp);
00221
00222
00223 copyAVUMetadata(destSubColl, subCollName, rsComm);
00224 }
00225
00226
00227 while (status==0 && genQueryOut->continueInx > 0) {
00228 genQueryInp.continueInx=genQueryOut->continueInx;
00229 status = rsGenQuery (rsComm, &genQueryInp, &genQueryOut);
00230
00231 for (i=0; i < genQueryOut->rowCnt; i++) {
00232
00233
00234 subCollName = genQueryOut->sqlResult[0].value;
00235 subCollName += i*genQueryOut->sqlResult[0].len;
00236
00237
00238 snprintf(destSubColl, MAX_NAME_LEN, "%s%s", destColl, subCollName+strlen(srcColl));
00239
00240
00241 memset (&collCreateInp, 0, sizeof (collCreateInp));
00242 rstrcpy (collCreateInp.collName, destSubColl, MAX_NAME_LEN);
00243 rsCollCreate (rsComm, &collCreateInp);
00244
00245
00246 copyAVUMetadata(destSubColl, subCollName, rsComm);
00247 }
00248
00249
00250 }
00251
00252
00253
00254
00255
00256
00257 memset (&genQueryInp, 0, sizeof (genQueryInp_t));
00258
00259
00260 genAllInCollQCond (srcColl, collQCond);
00261 addInxVal (&genQueryInp.sqlCondInp, COL_COLL_NAME, collQCond);
00262
00263
00264 addInxIval (&genQueryInp.selectInp, COL_COLL_NAME, 1);
00265 addInxIval (&genQueryInp.selectInp, COL_DATA_NAME, 1);
00266
00267
00268 genQueryInp.maxRows = MAX_SQL_ROWS;
00269
00270
00271
00272 status = rsGenQuery (rsComm, &genQueryInp, &genQueryOut);
00273
00274 if (status == CAT_NO_ROWS_FOUND) {
00275 return (0);
00276 }
00277
00278
00279
00280 for (i=0; i < genQueryOut->rowCnt; i++) {
00281
00282
00283 memset (&srcDataObjInp, 0, sizeof (dataObjInp_t));
00284 memset (&destDataObjInp, 0, sizeof (dataObjInp_t));
00285
00286
00287 subCollName = genQueryOut->sqlResult[0].value;
00288 subCollName += i*genQueryOut->sqlResult[0].len;
00289
00290
00291 fileName = genQueryOut->sqlResult[1].value;
00292 fileName += i*genQueryOut->sqlResult[1].len;
00293
00294
00295 snprintf(srcDataObjInp.objPath, MAX_NAME_LEN, "%s/%s", subCollName, fileName);
00296
00297
00298 snprintf(destDataObjInp.objPath, MAX_NAME_LEN, "%s%s/%s", destColl, subCollName+strlen(srcColl), fileName);
00299
00300
00301
00302 dataObjCopyInp.srcDataObjInp = srcDataObjInp;
00303 dataObjCopyInp.destDataObjInp = destDataObjInp;
00304 rsDataObjCopy (rsComm, &dataObjCopyInp, &transStat);
00305
00306
00307 if (transStat != NULL) {
00308 free (transStat);
00309 }
00310
00311
00312 copyAVUMetadata(destDataObjInp.objPath, srcDataObjInp.objPath, rsComm);
00313
00314 }
00315
00316
00317 while (status==0 && genQueryOut->continueInx > 0) {
00318 genQueryInp.continueInx=genQueryOut->continueInx;
00319 status = rsGenQuery (rsComm, &genQueryInp, &genQueryOut);
00320
00321 for (i=0; i < genQueryOut->rowCnt; i++) {
00322
00323
00324 memset (&srcDataObjInp, 0, sizeof (dataObjInp_t));
00325 memset (&destDataObjInp, 0, sizeof (dataObjInp_t));
00326
00327
00328 subCollName = genQueryOut->sqlResult[0].value;
00329 subCollName += i*genQueryOut->sqlResult[0].len;
00330
00331
00332 fileName = genQueryOut->sqlResult[1].value;
00333 fileName += i*genQueryOut->sqlResult[1].len;
00334
00335
00336 snprintf(srcDataObjInp.objPath, MAX_NAME_LEN, "%s/%s", subCollName, fileName);
00337
00338
00339 snprintf(destDataObjInp.objPath, MAX_NAME_LEN, "%s%s/%s", destColl, subCollName+strlen(srcColl), fileName);
00340
00341
00342
00343 dataObjCopyInp.srcDataObjInp = srcDataObjInp;
00344 dataObjCopyInp.destDataObjInp = destDataObjInp;
00345 rsDataObjCopy (rsComm, &dataObjCopyInp, &transStat);
00346
00347
00348 if (transStat != NULL) {
00349 free (transStat);
00350 }
00351
00352
00353 copyAVUMetadata(destDataObjInp.objPath, srcDataObjInp.objPath, rsComm);
00354 }
00355
00356 }
00357
00358
00359 return(status);
00360 }
00361
00362
00363
00364
00365
00366
00367
00368 int
00369 getDataObjPSmeta(char *objPath, bytesBuf_t *mybuf, rsComm_t *rsComm)
00370 {
00371 genQueryInp_t genQueryInp;
00372 genQueryOut_t *genQueryOut;
00373 int i1a[10];
00374 int i1b[10];
00375 int i2a[10];
00376 char *condVal[10];
00377 char v1[MAX_NAME_LEN];
00378 char v2[MAX_NAME_LEN];
00379 char fullName[MAX_NAME_LEN];
00380 char myDirName[MAX_NAME_LEN];
00381 char myFileName[MAX_NAME_LEN];
00382 int printCount=0;
00383 int status;
00384
00385
00386 if (rsComm == NULL) {
00387 rodsLog (LOG_ERROR,
00388 "getDataObjPSmeta: input rsComm is NULL");
00389 return (SYS_INTERNAL_NULL_INPUT_ERR);
00390 }
00391
00392
00393 memset (&genQueryInp, 0, sizeof (genQueryInp_t));
00394
00395 i1a[0]=COL_META_DATA_ATTR_NAME;
00396 i1b[0]=0;
00397 i1a[1]=COL_META_DATA_ATTR_VALUE;
00398 i1b[1]=0;
00399 i1a[2]=COL_META_DATA_ATTR_UNITS;
00400 i1b[2]=0;
00401 genQueryInp.selectInp.inx = i1a;
00402 genQueryInp.selectInp.value = i1b;
00403 genQueryInp.selectInp.len = 3;
00404
00405
00406 strncpy(fullName, objPath, MAX_NAME_LEN);
00407 status = splitPathByKey(fullName, myDirName, myFileName, '/');
00408
00409 i2a[0]=COL_COLL_NAME;
00410 sprintf(v1,"='%s'",myDirName);
00411 condVal[0]=v1;
00412
00413 i2a[1]=COL_DATA_NAME;
00414 sprintf(v2,"='%s'",myFileName);
00415 condVal[1]=v2;
00416
00417
00418 genQueryInp.sqlCondInp.inx = i2a;
00419 genQueryInp.sqlCondInp.value = condVal;
00420 genQueryInp.sqlCondInp.len=2;
00421
00422 genQueryInp.maxRows=10;
00423 genQueryInp.continueInx=0;
00424 genQueryInp.condInput.len=0;
00425
00426
00427
00428 status = rsGenQuery(rsComm, &genQueryInp, &genQueryOut);
00429
00430
00431 if (status == CAT_NO_ROWS_FOUND) {
00432 i1a[0]=COL_D_DATA_PATH;
00433 genQueryInp.selectInp.len = 1;
00434 status = rsGenQuery(rsComm, &genQueryInp, &genQueryOut);
00435 if (status==0) {
00436 appendStrToBBuf(mybuf, "");
00437
00438 return(0);
00439 }
00440 if (status == CAT_NO_ROWS_FOUND) {
00441
00442 rodsLogAndErrorMsg (LOG_ERROR, &rsComm->rError, status,
00443 "getDataObjPSmeta: DataObject %s not found. status = %d", fullName, status);
00444 return (status);
00445 }
00446 printCount+=extractPSQueryResults(status, genQueryOut, mybuf, fullName);
00447 }
00448 else {
00449 printCount+=extractPSQueryResults(status, genQueryOut, mybuf, fullName);
00450 }
00451
00452 while (status==0 && genQueryOut->continueInx > 0) {
00453 genQueryInp.continueInx=genQueryOut->continueInx;
00454 status = rsGenQuery(rsComm, &genQueryInp, &genQueryOut);
00455 printCount+= extractPSQueryResults(status, genQueryOut, mybuf, fullName);
00456 }
00457
00458 return (status);
00459 }
00460
00461
00462
00463
00464
00465
00466
00467 int
00468 getCollectionPSmeta(char *objPath, bytesBuf_t *mybuf, rsComm_t *rsComm)
00469 {
00470 genQueryInp_t genQueryInp;
00471 genQueryOut_t *genQueryOut;
00472 int i1a[10];
00473 int i1b[10];
00474 int i2a[10];
00475 char *condVal[10];
00476 char v1[MAX_NAME_LEN];
00477 int printCount=0;
00478 int status;
00479
00480
00481
00482 if (rsComm == NULL) {
00483 rodsLog (LOG_ERROR,
00484 "getCollectionPSmeta: input rsComm is NULL");
00485 return (SYS_INTERNAL_NULL_INPUT_ERR);
00486 }
00487
00488
00489 memset (&genQueryInp, 0, sizeof (genQueryInp_t));
00490
00491 i1a[0]=COL_META_COLL_ATTR_NAME;
00492 i1b[0]=0;
00493 i1a[1]=COL_META_COLL_ATTR_VALUE;
00494 i1b[1]=0;
00495 i1a[2]=COL_META_COLL_ATTR_UNITS;
00496 i1b[2]=0;
00497 genQueryInp.selectInp.inx = i1a;
00498 genQueryInp.selectInp.value = i1b;
00499 genQueryInp.selectInp.len = 3;
00500
00501 i2a[0]=COL_COLL_NAME;
00502 sprintf(v1,"='%s'", objPath);
00503 condVal[0]=v1;
00504
00505 genQueryInp.sqlCondInp.inx = i2a;
00506 genQueryInp.sqlCondInp.value = condVal;
00507 genQueryInp.sqlCondInp.len=1;
00508
00509 genQueryInp.maxRows=10;
00510 genQueryInp.continueInx=0;
00511 genQueryInp.condInput.len=0;
00512
00513
00514
00515 status = rsGenQuery(rsComm, &genQueryInp, &genQueryOut);
00516
00517 if (status == CAT_NO_ROWS_FOUND) {
00518 i1a[0]=COL_COLL_COMMENTS;
00519 genQueryInp.selectInp.len = 1;
00520 status = rsGenQuery(rsComm, &genQueryInp, &genQueryOut);
00521 if (status==0) {
00522 appendStrToBBuf(mybuf, "");
00523
00524 return(0);
00525 }
00526 if (status == CAT_NO_ROWS_FOUND) {
00527
00528 rodsLogAndErrorMsg (LOG_ERROR, &rsComm->rError, status,
00529 "getCollectionPSmeta: Collection %s not found. status = %d", objPath, status);
00530 return (status);
00531 }
00532 }
00533
00534 printCount+=extractPSQueryResults(status, genQueryOut, mybuf, objPath);
00535
00536 while (status==0 && genQueryOut->continueInx > 0) {
00537 genQueryInp.continueInx=genQueryOut->continueInx;
00538 status = rsGenQuery(rsComm, &genQueryInp, &genQueryOut);
00539 printCount+= extractPSQueryResults(status, genQueryOut, mybuf, objPath);
00540 }
00541
00542 return (status);
00543
00544 }
00545
00546
00547
00548
00549
00550
00551
00552 int
00553 getDataObjACL(dataObjInp_t *myDataObjInp, bytesBuf_t *mybuf, rsComm_t *rsComm)
00554 {
00555 genQueryInp_t genQueryInp;
00556 genQueryOut_t *genQueryOut;
00557 rodsObjStat_t *rodsObjStatOut;
00558 char condStr[MAX_NAME_LEN];
00559
00560 int printCount=0;
00561 int status;
00562
00563
00564
00565 if (rsComm == NULL) {
00566 rodsLog (LOG_ERROR, "getDataObjACL: input rsComm is NULL");
00567 return (SYS_INTERNAL_NULL_INPUT_ERR);
00568 }
00569
00570
00571 memset (&genQueryInp, 0, sizeof (genQueryInp_t));
00572
00573
00574 status = rsObjStat(rsComm, myDataObjInp, &rodsObjStatOut);
00575
00576
00577 addInxIval (&genQueryInp.selectInp, COL_COLL_NAME, 1);
00578 addInxIval (&genQueryInp.selectInp, COL_DATA_NAME, 1);
00579 addInxIval (&genQueryInp.selectInp, COL_USER_NAME, 1);
00580 addInxIval (&genQueryInp.selectInp, COL_DATA_ACCESS_NAME, 1);
00581
00582
00583 snprintf (condStr, MAX_NAME_LEN, " = '%s'", rodsObjStatOut->dataId);
00584 addInxVal (&genQueryInp.sqlCondInp, COL_DATA_ACCESS_DATA_ID, condStr);
00585
00586
00587 snprintf (condStr, MAX_NAME_LEN, "='%s'", "access_type");
00588 addInxVal (&genQueryInp.sqlCondInp, COL_DATA_TOKEN_NAMESPACE, condStr);
00589
00590 genQueryInp.maxRows = MAX_SQL_ROWS;
00591
00592 status = rsGenQuery(rsComm, &genQueryInp, &genQueryOut);
00593
00594
00595 if (status == CAT_NO_ROWS_FOUND) {
00596
00597 addInxIval (&genQueryInp.selectInp, COL_D_DATA_PATH, 1);
00598 genQueryInp.selectInp.len = 1;
00599 status = rsGenQuery(rsComm, &genQueryInp, &genQueryOut);
00600
00601 if (status == CAT_NO_ROWS_FOUND) {
00602 rodsLogAndErrorMsg (LOG_ERROR, &rsComm->rError, status,
00603 "getDataObjACL: DataID %s not found. status = %d", rodsObjStatOut->dataId, status);
00604 return (status);
00605 }
00606
00607 printCount+=extractACLQueryResults(genQueryOut, mybuf, 0);
00608 }
00609
00610 else {
00611 printCount+=extractACLQueryResults(genQueryOut, mybuf, 0);
00612 }
00613
00614 while (status==0 && genQueryOut->continueInx > 0) {
00615 genQueryInp.continueInx=genQueryOut->continueInx;
00616 status = rsGenQuery(rsComm, &genQueryInp, &genQueryOut);
00617 printCount+=extractACLQueryResults(genQueryOut, mybuf, 0);
00618 }
00619
00620 return (status);
00621 }
00622
00623
00624
00625
00626
00627
00628
00629 int
00630 getCollectionACL(collInp_t *myCollInp, char *label, bytesBuf_t *mybuf, rsComm_t *rsComm)
00631 {
00632 genQueryInp_t genQueryInp;
00633 genQueryOut_t *genQueryOut;
00634 char condStr[MAX_NAME_LEN];
00635 rodsLong_t collId;
00636 int status;
00637
00638
00639 if (rsComm == NULL) {
00640 rodsLog (LOG_ERROR, "getCollectionACL: input rsComm is NULL");
00641 return (SYS_INTERNAL_NULL_INPUT_ERR);
00642 }
00643
00644
00645 status = isColl (rsComm, myCollInp->collName, &collId);
00646 if (status == CAT_NO_ROWS_FOUND)
00647 {
00648 rodsLog (LOG_ERROR, "getCollectionACL: collection %s not found.", myCollInp->collName);
00649 return (status);
00650 }
00651
00652
00653
00654
00655
00656 memset (&genQueryInp, 0, sizeof (genQueryInp_t));
00657 genQueryInp.maxRows = MAX_SQL_ROWS;
00658
00659
00660 addInxIval (&genQueryInp.selectInp, COL_COLL_NAME, 1);
00661 addInxIval (&genQueryInp.selectInp, COL_COLL_USER_NAME, 1);
00662 addInxIval (&genQueryInp.selectInp, COL_COLL_USER_ZONE, 1);
00663 addInxIval (&genQueryInp.selectInp, COL_COLL_ACCESS_NAME, 1);
00664
00665
00666 snprintf (condStr, MAX_NAME_LEN, " = '%s'", myCollInp->collName);
00667 addInxVal (&genQueryInp.sqlCondInp, COL_COLL_NAME, condStr);
00668
00669
00670 snprintf (condStr, MAX_NAME_LEN, "='%s'", "access_type");
00671 addInxVal (&genQueryInp.sqlCondInp, COL_COLL_TOKEN_NAMESPACE, condStr);
00672
00673
00674
00675 status = rsGenQuery(rsComm, &genQueryInp, &genQueryOut);
00676
00677
00678
00679 writeCollAclToBBuf(genQueryOut, mybuf);
00680
00681 while (status==0 && genQueryOut->continueInx > 0) {
00682 genQueryInp.continueInx=genQueryOut->continueInx;
00683 freeGenQueryOut (&genQueryOut);
00684 status = rsGenQuery(rsComm, &genQueryInp, &genQueryOut);
00685 writeCollAclToBBuf(genQueryOut, mybuf);
00686 }
00687
00688
00689 freeGenQueryOut (&genQueryOut);
00690
00691
00692 if (status < 0)
00693 {
00694 return (status);
00695 }
00696
00697
00698 if (!label || strcmp(label, "recursive"))
00699 {
00700 return (0);
00701 }
00702
00703
00704
00705
00706
00707 memset (&genQueryInp, 0, sizeof (genQueryInp_t));
00708 genQueryInp.maxRows = MAX_SQL_ROWS;
00709
00710
00711 addInxIval (&genQueryInp.selectInp, COL_COLL_NAME, 1);
00712 addInxIval (&genQueryInp.selectInp, COL_COLL_USER_NAME, 1);
00713 addInxIval (&genQueryInp.selectInp, COL_COLL_USER_ZONE, 1);
00714 addInxIval (&genQueryInp.selectInp, COL_COLL_ACCESS_NAME, 1);
00715
00716
00717 snprintf (condStr, MAX_NAME_LEN, " like '%s/%%'", myCollInp->collName);
00718 addInxVal (&genQueryInp.sqlCondInp, COL_COLL_NAME, condStr);
00719
00720
00721 snprintf (condStr, MAX_NAME_LEN, "='%s'", "access_type");
00722 addInxVal (&genQueryInp.sqlCondInp, COL_COLL_TOKEN_NAMESPACE, condStr);
00723
00724
00725
00726 status = rsGenQuery(rsComm, &genQueryInp, &genQueryOut);
00727
00728
00729
00730 writeCollAclToBBuf(genQueryOut, mybuf);
00731
00732 while (status==0 && genQueryOut->continueInx > 0) {
00733 genQueryInp.continueInx=genQueryOut->continueInx;
00734 freeGenQueryOut (&genQueryOut);
00735 status = rsGenQuery(rsComm, &genQueryInp, &genQueryOut);
00736 writeCollAclToBBuf(genQueryOut, mybuf);
00737 }
00738
00739
00740 freeGenQueryOut (&genQueryOut);
00741
00742
00743
00744 if (status < 0 && status != CAT_NO_ROWS_FOUND)
00745 {
00746 return (status);
00747 }
00748
00749
00750
00751
00752
00753 memset (&genQueryInp, 0, sizeof (genQueryInp_t));
00754 genQueryInp.maxRows = MAX_SQL_ROWS;
00755
00756
00757 addInxIval (&genQueryInp.selectInp, COL_COLL_NAME, 1);
00758 addInxIval (&genQueryInp.selectInp, COL_DATA_NAME, 1);
00759 addInxIval (&genQueryInp.selectInp, COL_USER_NAME, 1);
00760 addInxIval (&genQueryInp.selectInp, COL_USER_ZONE, 1);
00761 addInxIval (&genQueryInp.selectInp, COL_DATA_ACCESS_NAME, 1);
00762
00763
00764 snprintf (condStr, MAX_NAME_LEN, " like '%s/%%'", myCollInp->collName);
00765 addInxVal (&genQueryInp.sqlCondInp, COL_COLL_NAME, condStr);
00766
00767
00768 snprintf (condStr, MAX_NAME_LEN, "='%s'", "access_type");
00769 addInxVal (&genQueryInp.sqlCondInp, COL_DATA_TOKEN_NAMESPACE, condStr);
00770
00771
00772
00773 status = rsGenQuery(rsComm, &genQueryInp, &genQueryOut);
00774
00775
00776
00777 writeDataAclToBBuf(genQueryOut, mybuf);
00778
00779 while (status==0 && genQueryOut->continueInx > 0) {
00780 genQueryInp.continueInx=genQueryOut->continueInx;
00781 freeGenQueryOut (&genQueryOut);
00782 status = rsGenQuery(rsComm, &genQueryInp, &genQueryOut);
00783 writeDataAclToBBuf(genQueryOut, mybuf);
00784 }
00785
00786
00787 freeGenQueryOut (&genQueryOut);
00788
00789
00790
00791 if (status < 0 && status != CAT_NO_ROWS_FOUND)
00792 {
00793 return (status);
00794 }
00795
00796 return (0);
00797 }
00798
00799
00800
00801
00802
00803
00804
00805 int
00806 loadMetadataFromDataObj(dataObjInp_t *dataObjInp, rsComm_t *rsComm)
00807 {
00808 openedDataObjInp_t dataObjReadInp;
00809 openedDataObjInp_t dataObjCloseInp;
00810 openedDataObjInp_t dataObjLseekInp;
00811 fileLseekOut_t *dataObjLseekOut;
00812 bytesBuf_t *readBuf;
00813 int status;
00814 int objID;
00815 char *lineStart, *lineEnd;
00816 int bytesRead;
00817
00818
00819
00820 if (rsComm == NULL) {
00821 rodsLog (LOG_ERROR, "loadMetadataFromDataObj: input rsComm is NULL");
00822 return (SYS_INTERNAL_NULL_INPUT_ERR);
00823 }
00824
00825
00826 if (dataObjInp == NULL) {
00827 rodsLog (LOG_ERROR, "loadMetadataFromDataObj: input data object is NULL");
00828 return (USER__NULL_INPUT_ERR);
00829 }
00830
00831
00832
00833 if ((objID=rsDataObjOpen(rsComm, dataObjInp)) < 0) {
00834 return (objID);
00835 }
00836
00837
00838 readBuf = (bytesBuf_t *)malloc(sizeof(bytesBuf_t));
00839 readBuf->len = 5*1024*1024;
00840 readBuf->buf = (char *)malloc(readBuf->len);
00841 memset (readBuf->buf, '\0', readBuf->len);
00842
00843
00844
00845 memset (&dataObjReadInp, 0, sizeof (dataObjReadInp));
00846 dataObjReadInp.l1descInx = objID;
00847 dataObjReadInp.len = readBuf->len;
00848
00849
00850 dataObjLseekInp.l1descInx = objID;
00851 dataObjLseekInp.offset = 0;
00852
00853
00854
00855 while ((bytesRead = rsDataObjRead (rsComm, &dataObjReadInp, readBuf)) > 0) {
00856
00857
00858 appendStrToBBuf(readBuf, "");
00859
00860
00861 lineStart = (char*)readBuf->buf;
00862
00863 while ( (lineEnd=strstr(lineStart, "\n")) ) {
00864 lineEnd[0]='\0';
00865
00866 status = parseMetadataModLine(lineStart, rsComm);
00867
00868 lineStart=lineEnd+1;
00869 }
00870
00871
00872 dataObjLseekInp.offset = dataObjLseekInp.offset + bytesRead - strlen(lineStart);
00873 dataObjLseekInp.whence = SEEK_SET;
00874
00875
00876
00877 if (strlen(lineStart) >= (size_t)bytesRead) {
00878 parseMetadataModLine(lineStart, rsComm);
00879 break;
00880 }
00881
00882 status = rsDataObjLseek (rsComm, &dataObjLseekInp, &dataObjLseekOut);
00883
00884
00885 memset(readBuf->buf, 0, readBuf->len);
00886
00887
00888 }
00889
00890
00891
00892
00893 memset (&dataObjCloseInp, 0, sizeof (dataObjCloseInp));
00894 dataObjCloseInp.l1descInx = objID;
00895
00896 status = rsDataObjClose (rsComm, &dataObjCloseInp);
00897
00898
00899 return (status);
00900 }
00901
00902
00903
00904 char *unescape(char *myStr)
00905 {
00906 char *tmpPtr;
00907
00908 while ( (tmpPtr = strstr(myStr, "\\|")) ) {
00909 snprintf(tmpPtr, strlen(tmpPtr)+1, "%s", tmpPtr+1);
00910 }
00911
00912 return (myStr);
00913 }
00914
00915
00916
00917 int
00918 parseMetadataModLine(char *inpLine, rsComm_t *rsComm)
00919 {
00920 modAVUMetadataInp_t modAVUMetadataInp;
00921 int status;
00922 char *objPath, *attribute, *value, *units=NULL;
00923 char *tmpPtr;
00924 char *collPtr;
00925
00926
00927
00928 if (!rsComm) {
00929 rodsLog (LOG_ERROR, "parseMetadataModLine: rsComm is NULL");
00930 return (SYS_INTERNAL_NULL_INPUT_ERR);
00931 }
00932
00933 if (!inpLine) {
00934 rodsLog (LOG_ERROR, "parseMetadataModLine: inpLine is NULL");
00935 return (USER__NULL_INPUT_ERR);
00936 }
00937
00938
00939
00940 if (inpLine[0] == '#') {
00941 return (0);
00942 }
00943
00944
00945
00946
00947
00948
00949
00950 memset (&modAVUMetadataInp, 0, sizeof(modAVUMetadataInp_t));
00951 modAVUMetadataInp.arg0 = "add";
00952
00953
00954
00955 objPath = inpLine;
00956 if ( (tmpPtr = strstr(objPath, " |")) == NULL) {
00957 rodsLog (LOG_ERROR, "parseMetadataModLine: Parse error: object path is NULL");
00958 return (USER__NULL_INPUT_ERR);
00959 }
00960 tmpPtr[0] = '\0';
00961
00962
00963 collPtr = strstr(objPath, "C-");
00964 if (collPtr && (collPtr == objPath)) {
00965 modAVUMetadataInp.arg1 = "-c";
00966
00967
00968 objPath += 2;
00969 }
00970 else {
00971 modAVUMetadataInp.arg1 = "-d";
00972 }
00973
00974
00975
00976 modAVUMetadataInp.arg2 = unescape(objPath);
00977
00978
00979
00980 attribute = tmpPtr+2;
00981 if ( (tmpPtr = strstr(attribute, " |")) == NULL) {
00982 rodsLog (LOG_ERROR, "parseMetadataModLine: Parse error: attribute is NULL");
00983 return (USER__NULL_INPUT_ERR);
00984 }
00985 tmpPtr[0] = '\0';
00986
00987
00988
00989 modAVUMetadataInp.arg3 = unescape(attribute);
00990
00991
00992
00993 value = tmpPtr+2;
00994 if ( (tmpPtr = strstr(value, " |")) ) {
00995 tmpPtr[0] = '\0';
00996 units = tmpPtr+2;
00997 }
00998
00999
01000
01001 modAVUMetadataInp.arg4 = unescape(value);
01002
01003
01004
01005 if (units) {
01006
01007 modAVUMetadataInp.arg5 = unescape(units);
01008 }
01009 else {
01010 modAVUMetadataInp.arg5 = "";
01011 }
01012
01013
01014
01015 status = rsModAVUMetadata (rsComm, &modAVUMetadataInp);
01016
01017
01018 return (status);
01019 }
01020
01021
01022
01023
01024
01025
01026
01027
01028
01029
01030 int
01031 genQueryOutToXML(genQueryOut_t *genQueryOut, bytesBuf_t *mybuf, char **tags)
01032 {
01033 int printCount;
01034 int i, j;
01035 size_t size;
01036
01037 if (!genQueryOut) {
01038 return 0;
01039 }
01040
01041 printCount=0;
01042 for (i=0;i<genQueryOut->rowCnt;i++) {
01043
01044 if ( (tags[0] != NULL) && strlen(tags[0]) ) {
01045 appendFormattedStrToBBuf(mybuf, strlen(tags[0])+4, "<%s>\n", tags[0]);
01046 }
01047
01048 for (j=0;j<genQueryOut->attriCnt;j++) {
01049 char *tResult;
01050 tResult = genQueryOut->sqlResult[j].value;
01051 tResult += i*genQueryOut->sqlResult[j].len;
01052
01053 if ( (tags[j+1] != NULL) && strlen(tags[j+1]) ) {
01054 size = genQueryOut->sqlResult[j].len + 2*strlen(tags[j+1]) + 10;
01055 appendFormattedStrToBBuf(mybuf, size, "<%s>%s</%s>\n", tags[j+1], tResult, tags[j+1]);
01056 }
01057 else {
01058 size = genQueryOut->sqlResult[j].len + 1;
01059 appendFormattedStrToBBuf(mybuf, size, "%s\n",tResult);
01060 }
01061 printCount++;
01062 }
01063
01064 if ( (tags[0] != NULL) && strlen(tags[0]) ) {
01065 appendFormattedStrToBBuf(mybuf, strlen(tags[0])+5, "</%s>\n", tags[0]);
01066 }
01067
01068 }
01069
01070
01071
01072 return (printCount);
01073 }
01074
01075
01076
01077
01078
01079
01080
01081
01082 int
01083 extractPSQueryResults(int status, genQueryOut_t *genQueryOut, bytesBuf_t *mybuf, char *fullName)
01084 {
01085 int printCount;
01086 int i, j;
01087 size_t size;
01088
01089
01090 printCount=0;
01091
01092 if (status!=0) {
01093 rodsLog (LOG_ERROR, "extractPSQueryResults error: %d", status);
01094 return (status);
01095 }
01096 else {
01097 if (status !=CAT_NO_ROWS_FOUND) {
01098 for (i=0;i<genQueryOut->rowCnt;i++) {
01099
01100 appendFormattedStrToBBuf(mybuf, strlen(fullName)+1, fullName);
01101
01102 for (j=0;j<genQueryOut->attriCnt;j++) {
01103 char *tResult;
01104 tResult = genQueryOut->sqlResult[j].value;
01105 tResult += i*genQueryOut->sqlResult[j].len;
01106
01107
01108 if (j<2 || strlen(tResult)) {
01109 size = genQueryOut->sqlResult[j].len + 2;
01110 appendFormattedStrToBBuf(mybuf, size, "|%s",tResult);
01111 }
01112
01113 printCount++;
01114 }
01115
01116 appendStrToBBuf(mybuf, "\n");
01117
01118 }
01119 }
01120 }
01121
01122 return (printCount);
01123 }
01124
01125
01126
01127
01128
01129
01130 int
01131 extractGenQueryResults(genQueryOut_t *genQueryOut, bytesBuf_t *mybuf, char *header, char **descriptions)
01132 {
01133 int i, j;
01134 char localTime[20];
01135
01136 for (i=0;i<genQueryOut->rowCnt;i++) {
01137
01138 if ((header != NULL) && strlen(header)) {
01139 appendFormattedStrToBBuf(mybuf, strlen(header)+2, "%s|", header);
01140 }
01141
01142 for (j=0;j<genQueryOut->attriCnt;j++) {
01143 char *tResult;
01144 tResult = genQueryOut->sqlResult[j].value;
01145 tResult += i*genQueryOut->sqlResult[j].len;
01146
01147 if (j) {
01148 appendStrToBBuf(mybuf, "|");
01149 }
01150
01151
01152 if ((descriptions != NULL) && (descriptions[j] != NULL) && (strstr(descriptions[j],"time")!=0)) {
01153 getLocalTimeFromRodsTime(tResult, localTime);
01154 appendStrToBBuf(mybuf, localTime);
01155 }
01156 else {
01157 appendStrToBBuf(mybuf, tResult);
01158 }
01159
01160 }
01161
01162 appendStrToBBuf(mybuf, "\n");
01163 }
01164
01165 return (i);
01166 }
01167
01168
01169
01170
01171
01172
01173 int
01174 extractACLQueryResults(genQueryOut_t *genQueryOut, bytesBuf_t *mybuf, int coll_flag)
01175 {
01176 int i, j;
01177
01178 for (i=0;i<genQueryOut->rowCnt;i++) {
01179
01180 for (j=0;j<genQueryOut->attriCnt;j++) {
01181 char *tResult;
01182 tResult = genQueryOut->sqlResult[j].value;
01183 tResult += i*genQueryOut->sqlResult[j].len;
01184
01185 if (j) {
01186 if (j==1 && !coll_flag) {
01187
01188 appendStrToBBuf(mybuf, "/");
01189 }
01190 else {
01191 appendStrToBBuf(mybuf, "|");
01192 }
01193 }
01194
01195 appendStrToBBuf(mybuf, tResult);
01196 }
01197
01198 appendStrToBBuf(mybuf, "\n");
01199 }
01200
01201 return (i);
01202 }
01203
01204
01205
01206
01207
01208
01209 int
01210 writeDataAclToBBuf(genQueryOut_t *genQueryOut, bytesBuf_t *mybuf)
01211 {
01212 int i;
01213 sqlResult_t *collName, *dataName, *userName, *userZone, *dataAccess;
01214 char *collNameStr, *dataNameStr, *userNameStr, *userZoneStr, *dataAccessStr;
01215 char ACLStr[MAX_NAME_LEN];
01216
01217
01218 if ((collName = getSqlResultByInx (genQueryOut, COL_COLL_NAME)) == NULL)
01219 {
01220 rodsLog (LOG_ERROR,
01221 "writeDataAclToBBuf: getSqlResultByInx for COL_COLL_NAME failed");
01222 return (UNMATCHED_KEY_OR_INDEX);
01223 }
01224 if ((dataName = getSqlResultByInx (genQueryOut, COL_DATA_NAME)) == NULL)
01225 {
01226 rodsLog (LOG_ERROR,
01227 "writeDataAclToBBuf: getSqlResultByInx for COL_DATA_NAME failed");
01228 return (UNMATCHED_KEY_OR_INDEX);
01229 }
01230 if ((userName = getSqlResultByInx (genQueryOut, COL_USER_NAME)) == NULL)
01231 {
01232 rodsLog (LOG_ERROR,
01233 "writeDataAclToBBuf: getSqlResultByInx for COL_USER_NAME failed");
01234 return (UNMATCHED_KEY_OR_INDEX);
01235 }
01236 if ((userZone = getSqlResultByInx (genQueryOut, COL_USER_ZONE)) == NULL)
01237 {
01238 rodsLog (LOG_ERROR,
01239 "writeDataAclToBBuf: getSqlResultByInx for COL_USER_ZONE failed");
01240 return (UNMATCHED_KEY_OR_INDEX);
01241 }
01242
01243 if ((dataAccess = getSqlResultByInx (genQueryOut, COL_DATA_ACCESS_NAME)) == NULL)
01244 {
01245 rodsLog (LOG_ERROR,
01246 "writeDataAclToBBuf: getSqlResultByInx for COL_DATA_ACCESS_NAME failed");
01247 return (UNMATCHED_KEY_OR_INDEX);
01248 }
01249
01250
01251
01252 for (i=0;i<genQueryOut->rowCnt;i++)
01253 {
01254
01255 memset(ACLStr,'\0', MAX_NAME_LEN);
01256
01257 collNameStr = &collName->value[collName->len * i];
01258 dataNameStr = &dataName->value[dataName->len * i];
01259 userNameStr = &userName->value[userName->len * i];
01260 userZoneStr = &userZone->value[userZone->len * i];
01261 dataAccessStr = &dataAccess->value[dataAccess->len * i];
01262
01263 snprintf(ACLStr, MAX_NAME_LEN, "%s/%s|%s#%s|%s\n", collNameStr, dataNameStr, userNameStr, userZoneStr, dataAccessStr);
01264 appendStrToBBuf(mybuf, ACLStr);
01265
01266 }
01267
01268 return (i);
01269 }
01270
01271
01272
01273
01274
01275
01276
01277
01278 int
01279 writeCollAclToBBuf(genQueryOut_t *genQueryOut, bytesBuf_t *mybuf)
01280 {
01281 int i;
01282 sqlResult_t *collName, *userName, *userZone, *collAccess;
01283 char *collNameStr, *userNameStr, *userZoneStr, *collAccessStr;
01284 char ACLStr[MAX_NAME_LEN];
01285
01286
01287 if ((collName = getSqlResultByInx (genQueryOut, COL_COLL_NAME)) == NULL)
01288 {
01289 rodsLog (LOG_ERROR,
01290 "writeCollAclToBBuf: getSqlResultByInx for COL_COLL_NAME failed");
01291 return (UNMATCHED_KEY_OR_INDEX);
01292 }
01293 if ((userName = getSqlResultByInx (genQueryOut, COL_COLL_USER_NAME)) == NULL)
01294 {
01295 rodsLog (LOG_ERROR,
01296 "writeCollAclToBBuf: getSqlResultByInx for COL_COLL_USER_NAME failed");
01297 return (UNMATCHED_KEY_OR_INDEX);
01298 }
01299 if ((userZone = getSqlResultByInx (genQueryOut, COL_COLL_USER_ZONE)) == NULL)
01300 {
01301 rodsLog (LOG_ERROR,
01302 "writeCollAclToBBuf: getSqlResultByInx for COL_COLL_USER_ZONE failed");
01303 return (UNMATCHED_KEY_OR_INDEX);
01304 }
01305
01306 if ((collAccess = getSqlResultByInx (genQueryOut, COL_COLL_ACCESS_NAME)) == NULL)
01307 {
01308 rodsLog (LOG_ERROR,
01309 "writeCollAclToBBuf: getSqlResultByInx for COL_COLL_ACCESS_NAME failed");
01310 return (UNMATCHED_KEY_OR_INDEX);
01311 }
01312
01313
01314
01315 for (i=0;i<genQueryOut->rowCnt;i++)
01316 {
01317
01318 memset(ACLStr,'\0', MAX_NAME_LEN);
01319
01320 collNameStr = &collName->value[collName->len * i];
01321 userNameStr = &userName->value[userName->len * i];
01322 userZoneStr = &userZone->value[userZone->len * i];
01323 collAccessStr = &collAccess->value[collAccess->len * i];
01324
01325 snprintf(ACLStr, MAX_NAME_LEN, "%s|%s#%s|%s\n", collNameStr, userNameStr, userZoneStr, collAccessStr);
01326 appendStrToBBuf(mybuf, ACLStr);
01327
01328 }
01329
01330 return (i);
01331 }
01332
01333
01334
01335
01336
01337
01338 int
01339 getUserInfo(char *userName, bytesBuf_t *mybuf, rsComm_t *rsComm)
01340 {
01341 genQueryInp_t genQueryInp;
01342 genQueryOut_t *genQueryOut;
01343 char condStr[MAX_NAME_LEN];
01344 int status;
01345 char *attrs[] = {"name", "id", "type", "zone", "dn", "info", "comment",
01346 "create time", "modify time"};
01347
01348
01349 if (rsComm == NULL) {
01350 rodsLog (LOG_ERROR, "getUserInfo: input rsComm is NULL");
01351 return (SYS_INTERNAL_NULL_INPUT_ERR);
01352 }
01353
01354
01355 if (userName == NULL) {
01356 rodsLog (LOG_ERROR, "getUserInfo: username input is NULL");
01357 return (USER__NULL_INPUT_ERR);
01358 }
01359
01360
01361
01362
01363 memset (&genQueryInp, 0, sizeof (genQueryInp_t));
01364
01365
01366 addInxIval (&genQueryInp.selectInp, COL_USER_NAME, 1);
01367 addInxIval (&genQueryInp.selectInp, COL_USER_ID, 1);
01368 addInxIval (&genQueryInp.selectInp, COL_USER_TYPE, 1);
01369 addInxIval (&genQueryInp.selectInp, COL_USER_ZONE, 1);
01370
01371 addInxIval (&genQueryInp.selectInp, COL_USER_INFO, 1);
01372 addInxIval (&genQueryInp.selectInp, COL_USER_COMMENT, 1);
01373 addInxIval (&genQueryInp.selectInp, COL_USER_CREATE_TIME, 1);
01374 addInxIval (&genQueryInp.selectInp, COL_USER_MODIFY_TIME, 1);
01375
01376
01377
01378 if (strstr(userName, "%")) {
01379 snprintf (condStr, MAX_NAME_LEN, " like '%s'", userName);
01380 }
01381 else {
01382 snprintf (condStr, MAX_NAME_LEN, " = '%s'", userName);
01383 }
01384
01385 addInxVal (&genQueryInp.sqlCondInp, COL_USER_NAME, condStr);
01386
01387
01388 genQueryInp.maxRows = MAX_SQL_ROWS;
01389
01390
01391
01392 status = rsGenQuery (rsComm, &genQueryInp, &genQueryOut);
01393
01394
01395 if (status == 0) {
01396 extractGenQueryResults(genQueryOut, mybuf, NULL, attrs);
01397
01398
01399 while (status==0 && genQueryOut->continueInx > 0) {
01400 genQueryInp.continueInx=genQueryOut->continueInx;
01401 status = rsGenQuery(rsComm, &genQueryInp, &genQueryOut);
01402
01403 extractGenQueryResults(genQueryOut, mybuf, NULL, attrs);
01404 }
01405 }
01406
01407 return (0);
01408 }
01409
01410
01411
01412
01413
01414
01415
01416 int
01417 getUserACL(char *userName, bytesBuf_t *mybuf, rsComm_t *rsComm)
01418 {
01419 genQueryInp_t genQueryInp;
01420 genQueryOut_t *genQueryOut;
01421 char condStr[MAX_NAME_LEN];
01422 int status;
01423
01424
01425 if (rsComm == NULL) {
01426 rodsLog (LOG_ERROR, "getUserACL: input rsComm is NULL");
01427 return (SYS_INTERNAL_NULL_INPUT_ERR);
01428 }
01429
01430
01431 if (userName == NULL) {
01432 rodsLog (LOG_ERROR, "getUserACL: username input is NULL");
01433 return (USER__NULL_INPUT_ERR);
01434 }
01435
01436
01437
01438
01439 memset (&genQueryInp, 0, sizeof (genQueryInp_t));
01440
01441
01442 addInxIval (&genQueryInp.selectInp, COL_COLL_NAME, 1);
01443 addInxIval (&genQueryInp.selectInp, COL_DATA_NAME, 1);
01444 addInxIval (&genQueryInp.selectInp, COL_USER_NAME, 1);
01445 addInxIval (&genQueryInp.selectInp, COL_DATA_ACCESS_NAME, 1);
01446
01447
01448
01449 if (strstr(userName, "%")) {
01450 snprintf (condStr, MAX_NAME_LEN, " like '%s'", userName);
01451 }
01452 else {
01453 snprintf (condStr, MAX_NAME_LEN, " = '%s'", userName);
01454 }
01455
01456 addInxVal (&genQueryInp.sqlCondInp, COL_USER_NAME, condStr);
01457
01458
01459
01460
01461 snprintf (condStr, MAX_NAME_LEN, "='%s'", "access_type");
01462 addInxVal (&genQueryInp.sqlCondInp, COL_DATA_TOKEN_NAMESPACE, condStr);
01463
01464 genQueryInp.maxRows = MAX_SQL_ROWS;
01465
01466
01467
01468 status = rsGenQuery (rsComm, &genQueryInp, &genQueryOut);
01469
01470
01471 if (status == 0) {
01472 extractACLQueryResults(genQueryOut, mybuf, 0);
01473
01474
01475 while (status==0 && genQueryOut->continueInx > 0) {
01476 genQueryInp.continueInx=genQueryOut->continueInx;
01477 status = rsGenQuery(rsComm, &genQueryInp, &genQueryOut);
01478
01479 extractACLQueryResults(genQueryOut, mybuf, 0);
01480 }
01481 }
01482
01483
01484
01485
01486 memset (&genQueryInp, 0, sizeof (genQueryInp_t));
01487
01488
01489 addInxIval (&genQueryInp.selectInp, COL_COLL_NAME, 1);
01490 addInxIval (&genQueryInp.selectInp, COL_USER_NAME, 1);
01491 addInxIval (&genQueryInp.selectInp, COL_DATA_ACCESS_NAME, 1);
01492
01493
01494
01495 if (strstr(userName, "%")) {
01496 snprintf (condStr, MAX_NAME_LEN, " like '%s'", userName);
01497 }
01498 else {
01499 snprintf (condStr, MAX_NAME_LEN, " = '%s'", userName);
01500 }
01501
01502 addInxVal (&genQueryInp.sqlCondInp, COL_USER_NAME, condStr);
01503
01504
01505
01506
01507 snprintf (condStr, MAX_NAME_LEN, "='%s'", "access_type");
01508 addInxVal (&genQueryInp.sqlCondInp, COL_DATA_TOKEN_NAMESPACE, condStr);
01509
01510 genQueryInp.maxRows = MAX_SQL_ROWS;
01511
01512
01513
01514 status = rsGenQuery (rsComm, &genQueryInp, &genQueryOut);
01515
01516
01517 if (status == 0) {
01518 extractACLQueryResults(genQueryOut, mybuf, 1);
01519
01520
01521 while (status==0 && genQueryOut->continueInx > 0) {
01522 genQueryInp.continueInx=genQueryOut->continueInx;
01523 status = rsGenQuery(rsComm, &genQueryInp, &genQueryOut);
01524
01525 extractACLQueryResults(genQueryOut, mybuf, 1);
01526 }
01527 }
01528
01529 return (0);
01530 }
01531
01532
01533
01534
01535
01536
01537
01538 int
01539 genAdminOpFromDataObj(dataObjInp_t *dataObjInp, generalAdminInp_t *generalAdminInp, rsComm_t *rsComm)
01540 {
01541 openedDataObjInp_t dataObjReadInp;
01542 openedDataObjInp_t dataObjCloseInp;
01543 openedDataObjInp_t dataObjLseekInp;
01544 fileLseekOut_t *dataObjLseekOut;
01545 bytesBuf_t *readBuf;
01546 int status;
01547 int objID;
01548 char *lineStart, *lineEnd;
01549 int bytesRead;
01550
01551
01552
01553 if (rsComm == NULL) {
01554 rodsLog (LOG_ERROR, "genAdminOpFromDataObj: input rsComm is NULL");
01555 return (SYS_INTERNAL_NULL_INPUT_ERR);
01556 }
01557
01558
01559 if (dataObjInp == NULL) {
01560 rodsLog (LOG_ERROR, "genAdminOpFromDataObj: input data object is NULL");
01561 return (USER__NULL_INPUT_ERR);
01562 }
01563
01564
01565
01566 if (rsComm->clientUser.authInfo.authFlag != 5) {
01567 return (CAT_INSUFFICIENT_PRIVILEGE_LEVEL);
01568 }
01569
01570
01571
01572 if ((objID=rsDataObjOpen(rsComm, dataObjInp)) < 0) {
01573 return (objID);
01574 }
01575
01576
01577 readBuf = (bytesBuf_t *)malloc(sizeof(bytesBuf_t));
01578 readBuf->len = 5*1024*1024;
01579 readBuf->buf = (char *)malloc(readBuf->len);
01580 memset (readBuf->buf, '\0', readBuf->len);
01581
01582
01583
01584 memset (&dataObjReadInp, 0, sizeof (dataObjReadInp));
01585 dataObjReadInp.l1descInx = objID;
01586 dataObjReadInp.len = readBuf->len;
01587
01588
01589 dataObjLseekInp.l1descInx = objID;
01590 dataObjLseekInp.offset = 0;
01591
01592
01593
01594 while ((bytesRead = rsDataObjRead (rsComm, &dataObjReadInp, readBuf)) > 0) {
01595
01596
01597 appendStrToBBuf(readBuf, "");
01598
01599
01600 lineStart = (char*)readBuf->buf;
01601
01602 while ( (lineEnd=strstr(lineStart, "\n")) ) {
01603 lineEnd[0]='\0';
01604
01605 status = parseGenAdminLine(lineStart, generalAdminInp, rsComm);
01606
01607 lineStart=lineEnd+1;
01608 }
01609
01610
01611 dataObjLseekInp.offset = dataObjLseekInp.offset + bytesRead - strlen(lineStart);
01612 dataObjLseekInp.whence = SEEK_SET;
01613
01614
01615
01616 if (strlen(lineStart) >= (size_t)bytesRead) {
01617 parseGenAdminLine(lineStart, generalAdminInp, rsComm);
01618 break;
01619 }
01620
01621 status = rsDataObjLseek (rsComm, &dataObjLseekInp, &dataObjLseekOut);
01622
01623
01624 memset(readBuf->buf, 0, readBuf->len);
01625
01626
01627 }
01628
01629
01630
01631
01632 memset (&dataObjCloseInp, 0, sizeof (dataObjCloseInp));
01633 dataObjCloseInp.l1descInx = objID;
01634
01635 status = rsDataObjClose (rsComm, &dataObjCloseInp);
01636
01637
01638 return (status);
01639 }
01640
01641
01642
01643 int
01644 parseGenAdminLine(char *inpLine, generalAdminInp_t *generalAdminInp, rsComm_t *rsComm)
01645 {
01646 int status;
01647 char *userName, *userID, *userType, *userZone;
01648 char *field, *newValue;
01649 char *tmpPtr;
01650
01651
01652
01653
01654 if (!rsComm) {
01655 rodsLog (LOG_ERROR, "parseGenAdminLine: rsComm is NULL");
01656 return (SYS_INTERNAL_NULL_INPUT_ERR);
01657 }
01658
01659 if (!inpLine) {
01660 rodsLog (LOG_ERROR, "parseGenAdminLine: inpLine is NULL");
01661 return (USER__NULL_INPUT_ERR);
01662 }
01663
01664 if (!generalAdminInp->arg0 || !generalAdminInp->arg1) {
01665 rodsLog (LOG_ERROR, "parseGenAdminLine: Action type not specified");
01666 return (USER__NULL_INPUT_ERR);
01667 }
01668
01669
01670
01671 if (inpLine[0] == '#') {
01672 return (0);
01673 }
01674
01675
01676
01677
01678 if (!strcmp(generalAdminInp->arg0, "add") && !strcmp(generalAdminInp->arg1, "user")) {
01679
01680 userName = inpLine;
01681 if ( (tmpPtr = strstr(userName, "|")) == NULL) {
01682 rodsLog (LOG_ERROR, "parseGenAdminLine: Parse error: user name is NULL");
01683 return (USER__NULL_INPUT_ERR);
01684 }
01685 tmpPtr[0] = '\0';
01686
01687
01688 generalAdminInp->arg2 = userName;
01689
01690
01691
01692 userID = tmpPtr+1;
01693 if ( (tmpPtr = strstr(userID, "|")) == NULL) {
01694 rodsLog (LOG_ERROR, "parseGenAdminLine: Parse error: missing argument(s)");
01695 return (USER__NULL_INPUT_ERR);
01696 }
01697 tmpPtr[0] = '\0';
01698
01699
01700
01701 userType = tmpPtr+1;
01702 if ( (tmpPtr = strstr(userType, "|")) == NULL) {
01703 rodsLog (LOG_ERROR, "parseGenAdminLine: Parse error: missing argument(s)");
01704 return (USER__NULL_INPUT_ERR);
01705 }
01706 tmpPtr[0] = '\0';
01707
01708
01709 generalAdminInp->arg3 = userType;
01710
01711
01712
01713 userZone = tmpPtr+1;
01714 if ( (tmpPtr = strstr(userZone, "|")) == NULL) {
01715 rodsLog (LOG_ERROR, "parseGenAdminLine: Parse error: missing argument(s)");
01716 return (USER__NULL_INPUT_ERR);
01717 }
01718 tmpPtr[0] = '\0';
01719
01720
01721 generalAdminInp->arg4 = userZone;
01722
01723
01724
01725 generalAdminInp->arg5 = "";
01726
01727
01728
01729 status = rsGeneralAdmin(rsComm, generalAdminInp);
01730
01731 return (status);
01732 }
01733
01734
01735 if (!strcmp(generalAdminInp->arg0, "modify") && !strcmp(generalAdminInp->arg1, "user")) {
01736
01737 userName = inpLine;
01738 if ( (tmpPtr = strstr(userName, "|")) == NULL) {
01739 rodsLog (LOG_ERROR, "parseGenAdminLine: Parse error: user name is NULL");
01740 return (USER__NULL_INPUT_ERR);
01741 }
01742 tmpPtr[0] = '\0';
01743
01744
01745 generalAdminInp->arg2 = userName;
01746
01747
01748
01749 field = tmpPtr+1;
01750 if ( (tmpPtr = strstr(field, "|")) == NULL) {
01751 rodsLog (LOG_ERROR, "parseGenAdminLine: Parse error: missing argument(s)");
01752 return (USER__NULL_INPUT_ERR);
01753 }
01754 tmpPtr[0] = '\0';
01755
01756
01757 generalAdminInp->arg3 = field;
01758
01759
01760
01761 newValue = tmpPtr+1;
01762 if (!newValue || !strlen(newValue)) {
01763 generalAdminInp->arg4 = "";
01764 }
01765 else {
01766
01767 generalAdminInp->arg4 = newValue;
01768 }
01769
01770
01771 if (!strcmp(field,"password")) {
01772 int i, len, lcopy;
01773 char buf0[MAX_PASSWORD_LEN+10];
01774 char buf1[MAX_PASSWORD_LEN+10];
01775 char buf2[MAX_PASSWORD_LEN+10];
01776 char rand[]="1gCBizHWbwIYyWLoysGzTe6SyzqFKMniZX05faZHWAwQKXf6Fs";
01777
01778 snprintf(buf0, MAX_PASSWORD_LEN+1, "%s", newValue);
01779 len = strlen(newValue);
01780 lcopy = MAX_PASSWORD_LEN-10-len;
01781 if (lcopy > 15) {
01782 strncat(buf0, rand, lcopy);
01783 }
01784 i = obfGetPw(buf1);
01785 if (i !=0) {
01786
01787 rodsLog (LOG_ERROR, "parseGenAdminLine: Error getting password");
01788 return (USER__NULL_INPUT_ERR);
01789 }
01790 obfEncodeByKey(buf0, buf1, buf2);
01791
01792 generalAdminInp->arg4 = buf2;
01793 }
01794
01795
01796
01797 status = rsGeneralAdmin(rsComm, generalAdminInp);
01798
01799 return (status);
01800 }
01801
01802
01803 if (!strcmp(generalAdminInp->arg0, "rm") && !strcmp(generalAdminInp->arg1, "user")) {
01804
01805 userName = inpLine;
01806 if ( (tmpPtr = strstr(userName, "|")) != NULL) {
01807 tmpPtr[0] = '\0';
01808 }
01809
01810
01811 generalAdminInp->arg2 = userName;
01812
01813
01814
01815 generalAdminInp->arg3 = rsComm->clientUser.rodsZone;
01816
01817
01818
01819 status = rsGeneralAdmin(rsComm, generalAdminInp);
01820
01821 return (status);
01822 }
01823
01824
01825 return (0);
01826 }
01827
01828
01829
01830
01831
01832
01833
01834 int
01835 loadACLFromDataObj(dataObjInp_t *dataObjInp, rsComm_t *rsComm)
01836 {
01837 openedDataObjInp_t dataObjReadInp;
01838 openedDataObjInp_t dataObjCloseInp;
01839 openedDataObjInp_t dataObjLseekInp;
01840 fileLseekOut_t *dataObjLseekOut;
01841 bytesBuf_t *readBuf;
01842 int status;
01843 int objID;
01844 char *lineStart, *lineEnd;
01845 int bytesRead;
01846
01847
01848
01849 if (rsComm == NULL) {
01850 rodsLog (LOG_ERROR, "loadACLFromDataObj: input rsComm is NULL");
01851 return (SYS_INTERNAL_NULL_INPUT_ERR);
01852 }
01853
01854
01855 if (dataObjInp == NULL) {
01856 rodsLog (LOG_ERROR, "loadACLFromDataObj: input data object is NULL");
01857 return (USER__NULL_INPUT_ERR);
01858 }
01859
01860
01861
01862 if ((objID=rsDataObjOpen(rsComm, dataObjInp)) < 0) {
01863 return (objID);
01864 }
01865
01866
01867 readBuf = (bytesBuf_t *)malloc(sizeof(bytesBuf_t));
01868 readBuf->len = 5*1024*1024;
01869 readBuf->buf = (char *)malloc(readBuf->len);
01870 memset (readBuf->buf, '\0', readBuf->len);
01871
01872
01873
01874 memset (&dataObjReadInp, 0, sizeof (dataObjReadInp));
01875 dataObjReadInp.l1descInx = objID;
01876 dataObjReadInp.len = readBuf->len;
01877
01878
01879 dataObjLseekInp.l1descInx = objID;
01880 dataObjLseekInp.offset = 0;
01881
01882
01883
01884 while ((bytesRead = rsDataObjRead (rsComm, &dataObjReadInp, readBuf)) > 0) {
01885
01886
01887 appendStrToBBuf(readBuf, "");
01888
01889
01890 lineStart = (char*)readBuf->buf;
01891
01892 while ( (lineEnd=strstr(lineStart, "\n")) ) {
01893 lineEnd[0]='\0';
01894
01895 status = parseACLModLine(lineStart, rsComm);
01896
01897 lineStart=lineEnd+1;
01898 }
01899
01900
01901 dataObjLseekInp.offset = dataObjLseekInp.offset + bytesRead - strlen(lineStart);
01902 dataObjLseekInp.whence = SEEK_SET;
01903
01904
01905
01906 if (strlen(lineStart) >= (size_t)bytesRead) {
01907 parseACLModLine(lineStart, rsComm);
01908 break;
01909 }
01910
01911 status = rsDataObjLseek (rsComm, &dataObjLseekInp, &dataObjLseekOut);
01912
01913
01914 memset(readBuf->buf, 0, readBuf->len);
01915
01916
01917 }
01918
01919
01920
01921
01922 memset (&dataObjCloseInp, 0, sizeof (dataObjCloseInp));
01923 dataObjCloseInp.l1descInx = objID;
01924
01925 status = rsDataObjClose (rsComm, &dataObjCloseInp);
01926
01927
01928 return (status);
01929 }
01930
01931
01932
01933 int
01934 parseACLModLine(char *inpLine, rsComm_t *rsComm)
01935 {
01936 modAccessControlInp_t modAccessControl;
01937 int status;
01938 char *accessLevel, *user, *path;
01939 char userName[NAME_LEN];
01940 char zoneName[NAME_LEN];
01941 char *tmpPtr;
01942
01943
01944
01945 if (!rsComm) {
01946 rodsLog (LOG_ERROR, "parseACLModLine: rsComm is NULL");
01947 return (SYS_INTERNAL_NULL_INPUT_ERR);
01948 }
01949
01950 if (!inpLine) {
01951 rodsLog (LOG_ERROR, "parseACLModLine: inpLine is NULL");
01952 return (USER__NULL_INPUT_ERR);
01953 }
01954
01955
01956
01957 if (inpLine[0] == '#') {
01958 return (0);
01959 }
01960
01961
01962
01963 memset (&modAccessControl, 0, sizeof(modAccessControlInp_t));
01964 modAccessControl.recursiveFlag = 0;
01965
01966
01967
01968 path = inpLine;
01969 if ( (tmpPtr = strstr(path, "|")) == NULL) {
01970 rodsLog (LOG_ERROR, "parseACLModLine: Parse error: object path is NULL");
01971 return (USER__NULL_INPUT_ERR);
01972 }
01973 tmpPtr[0] = '\0';
01974
01975
01976 modAccessControl.path = path;
01977
01978
01979
01980 user = tmpPtr+1;
01981 if ( (tmpPtr = strstr(user, "|")) == NULL) {
01982 rodsLog (LOG_ERROR, "parseACLModLine: Parse error: user is NULL");
01983 return (USER__NULL_INPUT_ERR);
01984 }
01985 tmpPtr[0] = '\0';
01986
01987 status = parseUserName(user, userName, zoneName);
01988
01989
01990 modAccessControl.userName = userName;
01991 modAccessControl.zone = zoneName;
01992
01993
01994
01995 accessLevel = tmpPtr+1;
01996 if (!accessLevel || !strlen(accessLevel)) {
01997 rodsLog (LOG_ERROR, "parseACLModLine: Parse error: accessLevel is NULL");
01998 return (USER__NULL_INPUT_ERR);
01999 }
02000
02001
02002
02003 modAccessControl.accessLevel = accessLevel;
02004
02005
02006
02007 status = rsModAccessControl(rsComm, &modAccessControl);
02008
02009 return (status);
02010 }
02011
02012
02013
02014
02015
02016
02017
02018 int
02019 getSqlRowsByInx(genQueryOut_t *genQueryOut, intArray_t *indexes, bytesBuf_t *mybuf)
02020 {
02021 char *resultStringToken;
02022 sqlResult_t *sqlResult;
02023 int i, j;
02024
02025
02026 for (i=0;i<genQueryOut->rowCnt;i++) {
02027
02028 for (j=0;j<indexes->len;j++) {
02029 sqlResult = getSqlResultByInx (genQueryOut, indexes->value[j]);
02030
02031 resultStringToken = sqlResult->value + i*sqlResult->len;
02032
02033 appendStrToBBuf(mybuf, resultStringToken);
02034 appendStrToBBuf(mybuf, "|");
02035 }
02036
02037
02038 appendStrToBBuf(mybuf, "\n");
02039 }
02040
02041 return (i);
02042 }
02043
02044
02045
02046
02047
02048
02049
02050
02051 int
02052 getObjectByFilePath(char *filePath, char *rescName, char *objPath, rsComm_t *rsComm)
02053 {
02054 genQueryInp_t genQueryInp;
02055 genQueryOut_t *genQueryOut;
02056 char condStr[MAX_NAME_LEN];
02057 sqlResult_t *dataName, *collName;
02058 int status;
02059
02060
02061
02062 memset (&genQueryInp, 0, sizeof (genQueryInp_t));
02063 genQueryInp.maxRows = 1;
02064
02065
02066 addInxIval (&genQueryInp.selectInp, COL_COLL_NAME, 1);
02067 addInxIval (&genQueryInp.selectInp, COL_DATA_NAME, 1);
02068
02069
02070 snprintf (condStr, MAX_NAME_LEN, " = '%s'", filePath);
02071 addInxVal (&genQueryInp.sqlCondInp, COL_D_DATA_PATH, condStr);
02072
02073 snprintf (condStr, MAX_NAME_LEN, " = '%s'", rescName);
02074 addInxVal (&genQueryInp.sqlCondInp, COL_D_RESC_NAME, condStr);
02075
02076
02077 status = rsGenQuery (rsComm, &genQueryInp, &genQueryOut);
02078
02079 if (status >= 0)
02080 {
02081
02082 dataName = getSqlResultByInx (genQueryOut, COL_DATA_NAME);
02083 collName = getSqlResultByInx (genQueryOut, COL_COLL_NAME);
02084
02085
02086 snprintf(objPath, MAX_NAME_LEN, "%s/%s", collName->value, dataName->value);
02087 }
02088
02089 return (status);
02090 }
02091
02092
02093 void timestampDataObjName(dataObjCopyInp_t *myDataObjCopyInp)
02094 {
02095 char timestamp[TIMESTAMP_LEN + 1];
02096 time_t caltime;
02097 struct tm *tm_time;
02098 char *postfix_start_ptr = NULL;
02099 char *filename_start_ptr = NULL;
02100 int filename_len = 0;
02101 int postfix_len = 0;
02102
02103
02104 filename_start_ptr = strrchr(myDataObjCopyInp->srcDataObjInp.objPath, '/');
02105 if (filename_start_ptr == NULL) {
02106 filename_start_ptr = myDataObjCopyInp->srcDataObjInp.objPath;
02107 }
02108 filename_len = strlen(filename_start_ptr);
02109
02110
02111 postfix_start_ptr = strrchr(myDataObjCopyInp->srcDataObjInp.objPath, '.');
02112 if(postfix_start_ptr != NULL) {
02113 postfix_len = strlen(postfix_start_ptr);
02114 if (postfix_len > 1) {
02115 postfix_start_ptr++;
02116 }
02117 }
02118
02119
02120
02121 time(&caltime);
02122
02123
02124 tm_time = gmtime(&caltime);
02125
02126
02127 strftime(timestamp,TIMESTAMP_LEN,"_%Y%m%dT%H%M%SZ",tm_time);
02128
02129
02130
02131
02132 strncat(myDataObjCopyInp->destDataObjInp.objPath, filename_start_ptr, filename_len - (postfix_len));
02133 strcat(myDataObjCopyInp->destDataObjInp.objPath, timestamp);
02134
02135
02136 if ((postfix_len > 0) && (postfix_len < filename_len)) {
02137 strcat(myDataObjCopyInp->destDataObjInp.objPath, ".");
02138 strcat(myDataObjCopyInp->destDataObjInp.objPath, postfix_start_ptr);
02139 }
02140
02141 return;
02142 }
02143