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 authFlag;
00922 int status;
00923 char *objPath, *attribute, *value, *units=NULL;
00924 char *tmpPtr;
00925 char *collPtr;
00926
00927
00928
00929 if (!rsComm) {
00930 rodsLog (LOG_ERROR, "parseMetadataModLine: rsComm is NULL");
00931 return (SYS_INTERNAL_NULL_INPUT_ERR);
00932 }
00933
00934 if (!inpLine) {
00935 rodsLog (LOG_ERROR, "parseMetadataModLine: inpLine is NULL");
00936 return (USER__NULL_INPUT_ERR);
00937 }
00938
00939
00940
00941 if (inpLine[0] == '#') {
00942 return (0);
00943 }
00944
00945
00946
00947 authFlag = rsComm->clientUser.authInfo.authFlag;
00948
00949
00950
00951 memset (&modAVUMetadataInp, 0, sizeof(modAVUMetadataInp_t));
00952 modAVUMetadataInp.arg0 = "add";
00953
00954
00955
00956 objPath = inpLine;
00957 if ( (tmpPtr = strstr(objPath, " |")) == NULL) {
00958 rodsLog (LOG_ERROR, "parseMetadataModLine: Parse error: object path is NULL");
00959 return (USER__NULL_INPUT_ERR);
00960 }
00961 tmpPtr[0] = '\0';
00962
00963
00964 collPtr = strstr(objPath, "C-");
00965 if (collPtr && (collPtr == objPath)) {
00966 modAVUMetadataInp.arg1 = "-c";
00967
00968
00969 objPath += 2;
00970 }
00971 else {
00972 modAVUMetadataInp.arg1 = "-d";
00973 }
00974
00975
00976
00977 modAVUMetadataInp.arg2 = unescape(objPath);
00978
00979
00980
00981 attribute = tmpPtr+2;
00982 if ( (tmpPtr = strstr(attribute, " |")) == NULL) {
00983 rodsLog (LOG_ERROR, "parseMetadataModLine: Parse error: attribute is NULL");
00984 return (USER__NULL_INPUT_ERR);
00985 }
00986 tmpPtr[0] = '\0';
00987
00988
00989
00990 modAVUMetadataInp.arg3 = unescape(attribute);
00991
00992
00993
00994 value = tmpPtr+2;
00995 if ( (tmpPtr = strstr(value, " |")) ) {
00996 tmpPtr[0] = '\0';
00997 units = tmpPtr+2;
00998 }
00999
01000
01001
01002 modAVUMetadataInp.arg4 = unescape(value);
01003
01004
01005
01006 if (units) {
01007
01008 modAVUMetadataInp.arg5 = unescape(units);
01009 }
01010 else {
01011 modAVUMetadataInp.arg5 = "";
01012 }
01013
01014
01015
01016 status = rsModAVUMetadata (rsComm, &modAVUMetadataInp);
01017
01018
01019 return (status);
01020 }
01021
01022
01023
01024
01025
01026
01027
01028
01029
01030
01031 int
01032 genQueryOutToXML(genQueryOut_t *genQueryOut, bytesBuf_t *mybuf, char **tags)
01033 {
01034 int printCount;
01035 int i, j;
01036 size_t size;
01037
01038 printCount=0;
01039
01040
01041 for (i=0;i<genQueryOut->rowCnt;i++) {
01042
01043 if ( (tags[0] != NULL) && strlen(tags[0]) ) {
01044 appendFormattedStrToBBuf(mybuf, strlen(tags[0])+4, "<%s>\n", tags[0]);
01045 }
01046
01047 for (j=0;j<genQueryOut->attriCnt;j++) {
01048 char *tResult;
01049 tResult = genQueryOut->sqlResult[j].value;
01050 tResult += i*genQueryOut->sqlResult[j].len;
01051
01052 if ( (tags[j+1] != NULL) && strlen(tags[j+1]) ) {
01053 size = genQueryOut->sqlResult[j].len + 2*strlen(tags[j+1]) + 10;
01054 appendFormattedStrToBBuf(mybuf, size, "<%s>%s</%s>\n", tags[j+1], tResult, tags[j+1]);
01055 }
01056 else {
01057 size = genQueryOut->sqlResult[j].len + 1;
01058 appendFormattedStrToBBuf(mybuf, size, "%s\n",tResult);
01059 }
01060 printCount++;
01061 }
01062
01063 if ( (tags[0] != NULL) && strlen(tags[0]) ) {
01064 appendFormattedStrToBBuf(mybuf, strlen(tags[0])+5, "</%s>\n", tags[0]);
01065 }
01066
01067 }
01068
01069
01070
01071 return (printCount);
01072 }
01073
01074
01075
01076
01077
01078
01079
01080
01081 int
01082 extractPSQueryResults(int status, genQueryOut_t *genQueryOut, bytesBuf_t *mybuf, char *fullName)
01083 {
01084 int printCount;
01085 int i, j;
01086 size_t size;
01087
01088
01089 printCount=0;
01090
01091 if (status!=0) {
01092 rodsLog (LOG_ERROR, "extractPSQueryResults error: %d", status);
01093 return (status);
01094 }
01095 else {
01096 if (status !=CAT_NO_ROWS_FOUND) {
01097 for (i=0;i<genQueryOut->rowCnt;i++) {
01098
01099 appendFormattedStrToBBuf(mybuf, strlen(fullName)+1, fullName);
01100
01101 for (j=0;j<genQueryOut->attriCnt;j++) {
01102 char *tResult;
01103 tResult = genQueryOut->sqlResult[j].value;
01104 tResult += i*genQueryOut->sqlResult[j].len;
01105
01106
01107 if (j<2 || strlen(tResult)) {
01108 size = genQueryOut->sqlResult[j].len + 2;
01109 appendFormattedStrToBBuf(mybuf, size, "|%s",tResult);
01110 }
01111
01112 printCount++;
01113 }
01114
01115 appendStrToBBuf(mybuf, "\n");
01116
01117 }
01118 }
01119 }
01120
01121 return (printCount);
01122 }
01123
01124
01125
01126
01127
01128
01129 int
01130 extractGenQueryResults(genQueryOut_t *genQueryOut, bytesBuf_t *mybuf, char *header, char **descriptions)
01131 {
01132 int i, j;
01133 char localTime[20];
01134
01135 for (i=0;i<genQueryOut->rowCnt;i++) {
01136
01137 if ((header != NULL) && strlen(header)) {
01138 appendFormattedStrToBBuf(mybuf, strlen(header)+2, "%s|", header);
01139 }
01140
01141 for (j=0;j<genQueryOut->attriCnt;j++) {
01142 char *tResult;
01143 tResult = genQueryOut->sqlResult[j].value;
01144 tResult += i*genQueryOut->sqlResult[j].len;
01145
01146 if (j) {
01147 appendStrToBBuf(mybuf, "|");
01148 }
01149
01150
01151 if ((descriptions != NULL) && (descriptions[j] != NULL) && (strstr(descriptions[j],"time")!=0)) {
01152 getLocalTimeFromRodsTime(tResult, localTime);
01153 appendStrToBBuf(mybuf, localTime);
01154 }
01155 else {
01156 appendStrToBBuf(mybuf, tResult);
01157 }
01158
01159 }
01160
01161 appendStrToBBuf(mybuf, "\n");
01162 }
01163
01164 return (i);
01165 }
01166
01167
01168
01169
01170
01171
01172 int
01173 extractACLQueryResults(genQueryOut_t *genQueryOut, bytesBuf_t *mybuf, int coll_flag)
01174 {
01175 int i, j;
01176
01177 for (i=0;i<genQueryOut->rowCnt;i++) {
01178
01179 for (j=0;j<genQueryOut->attriCnt;j++) {
01180 char *tResult;
01181 tResult = genQueryOut->sqlResult[j].value;
01182 tResult += i*genQueryOut->sqlResult[j].len;
01183
01184 if (j) {
01185 if (j==1 && !coll_flag) {
01186
01187 appendStrToBBuf(mybuf, "/");
01188 }
01189 else {
01190 appendStrToBBuf(mybuf, "|");
01191 }
01192 }
01193
01194 appendStrToBBuf(mybuf, tResult);
01195 }
01196
01197 appendStrToBBuf(mybuf, "\n");
01198 }
01199
01200 return (i);
01201 }
01202
01203
01204
01205
01206
01207
01208 int
01209 writeDataAclToBBuf(genQueryOut_t *genQueryOut, bytesBuf_t *mybuf)
01210 {
01211 int i;
01212 sqlResult_t *collName, *dataName, *userName, *userZone, *dataAccess;
01213 char *collNameStr, *dataNameStr, *userNameStr, *userZoneStr, *dataAccessStr;
01214 char ACLStr[MAX_NAME_LEN];
01215
01216
01217 if ((collName = getSqlResultByInx (genQueryOut, COL_COLL_NAME)) == NULL)
01218 {
01219 rodsLog (LOG_ERROR,
01220 "writeDataAclToBBuf: getSqlResultByInx for COL_COLL_NAME failed");
01221 return (UNMATCHED_KEY_OR_INDEX);
01222 }
01223 if ((dataName = getSqlResultByInx (genQueryOut, COL_DATA_NAME)) == NULL)
01224 {
01225 rodsLog (LOG_ERROR,
01226 "writeDataAclToBBuf: getSqlResultByInx for COL_DATA_NAME failed");
01227 return (UNMATCHED_KEY_OR_INDEX);
01228 }
01229 if ((userName = getSqlResultByInx (genQueryOut, COL_USER_NAME)) == NULL)
01230 {
01231 rodsLog (LOG_ERROR,
01232 "writeDataAclToBBuf: getSqlResultByInx for COL_USER_NAME failed");
01233 return (UNMATCHED_KEY_OR_INDEX);
01234 }
01235 if ((userZone = getSqlResultByInx (genQueryOut, COL_USER_ZONE)) == NULL)
01236 {
01237 rodsLog (LOG_ERROR,
01238 "writeDataAclToBBuf: getSqlResultByInx for COL_USER_ZONE failed");
01239 return (UNMATCHED_KEY_OR_INDEX);
01240 }
01241
01242 if ((dataAccess = getSqlResultByInx (genQueryOut, COL_DATA_ACCESS_NAME)) == NULL)
01243 {
01244 rodsLog (LOG_ERROR,
01245 "writeDataAclToBBuf: getSqlResultByInx for COL_DATA_ACCESS_NAME failed");
01246 return (UNMATCHED_KEY_OR_INDEX);
01247 }
01248
01249
01250
01251 for (i=0;i<genQueryOut->rowCnt;i++)
01252 {
01253
01254 memset(ACLStr,'\0', MAX_NAME_LEN);
01255
01256 collNameStr = &collName->value[collName->len * i];
01257 dataNameStr = &dataName->value[dataName->len * i];
01258 userNameStr = &userName->value[userName->len * i];
01259 userZoneStr = &userZone->value[userZone->len * i];
01260 dataAccessStr = &dataAccess->value[dataAccess->len * i];
01261
01262 snprintf(ACLStr, MAX_NAME_LEN, "%s/%s|%s#%s|%s\n", collNameStr, dataNameStr, userNameStr, userZoneStr, dataAccessStr);
01263 appendStrToBBuf(mybuf, ACLStr);
01264
01265 }
01266
01267 return (i);
01268 }
01269
01270
01271
01272
01273
01274
01275
01276
01277 int
01278 writeCollAclToBBuf(genQueryOut_t *genQueryOut, bytesBuf_t *mybuf)
01279 {
01280 int i;
01281 sqlResult_t *collName, *userName, *userZone, *collAccess;
01282 char *collNameStr, *userNameStr, *userZoneStr, *collAccessStr;
01283 char ACLStr[MAX_NAME_LEN];
01284
01285
01286 if ((collName = getSqlResultByInx (genQueryOut, COL_COLL_NAME)) == NULL)
01287 {
01288 rodsLog (LOG_ERROR,
01289 "writeCollAclToBBuf: getSqlResultByInx for COL_COLL_NAME failed");
01290 return (UNMATCHED_KEY_OR_INDEX);
01291 }
01292 if ((userName = getSqlResultByInx (genQueryOut, COL_COLL_USER_NAME)) == NULL)
01293 {
01294 rodsLog (LOG_ERROR,
01295 "writeCollAclToBBuf: getSqlResultByInx for COL_COLL_USER_NAME failed");
01296 return (UNMATCHED_KEY_OR_INDEX);
01297 }
01298 if ((userZone = getSqlResultByInx (genQueryOut, COL_COLL_USER_ZONE)) == NULL)
01299 {
01300 rodsLog (LOG_ERROR,
01301 "writeCollAclToBBuf: getSqlResultByInx for COL_COLL_USER_ZONE failed");
01302 return (UNMATCHED_KEY_OR_INDEX);
01303 }
01304
01305 if ((collAccess = getSqlResultByInx (genQueryOut, COL_COLL_ACCESS_NAME)) == NULL)
01306 {
01307 rodsLog (LOG_ERROR,
01308 "writeCollAclToBBuf: getSqlResultByInx for COL_COLL_ACCESS_NAME failed");
01309 return (UNMATCHED_KEY_OR_INDEX);
01310 }
01311
01312
01313
01314 for (i=0;i<genQueryOut->rowCnt;i++)
01315 {
01316
01317 memset(ACLStr,'\0', MAX_NAME_LEN);
01318
01319 collNameStr = &collName->value[collName->len * i];
01320 userNameStr = &userName->value[userName->len * i];
01321 userZoneStr = &userZone->value[userZone->len * i];
01322 collAccessStr = &collAccess->value[collAccess->len * i];
01323
01324 snprintf(ACLStr, MAX_NAME_LEN, "%s|%s#%s|%s\n", collNameStr, userNameStr, userZoneStr, collAccessStr);
01325 appendStrToBBuf(mybuf, ACLStr);
01326
01327 }
01328
01329 return (i);
01330 }
01331
01332
01333
01334
01335
01336
01337 int
01338 getUserInfo(char *userName, bytesBuf_t *mybuf, rsComm_t *rsComm)
01339 {
01340 genQueryInp_t genQueryInp;
01341 genQueryOut_t *genQueryOut;
01342 char condStr[MAX_NAME_LEN];
01343 int status;
01344 char *attrs[] = {"name", "id", "type", "zone", "dn", "info", "comment",
01345 "create time", "modify time"};
01346
01347
01348 if (rsComm == NULL) {
01349 rodsLog (LOG_ERROR, "getUserInfo: input rsComm is NULL");
01350 return (SYS_INTERNAL_NULL_INPUT_ERR);
01351 }
01352
01353
01354 if (userName == NULL) {
01355 rodsLog (LOG_ERROR, "getUserInfo: username input is NULL");
01356 return (USER__NULL_INPUT_ERR);
01357 }
01358
01359
01360
01361
01362 memset (&genQueryInp, 0, sizeof (genQueryInp_t));
01363
01364
01365 addInxIval (&genQueryInp.selectInp, COL_USER_NAME, 1);
01366 addInxIval (&genQueryInp.selectInp, COL_USER_ID, 1);
01367 addInxIval (&genQueryInp.selectInp, COL_USER_TYPE, 1);
01368 addInxIval (&genQueryInp.selectInp, COL_USER_ZONE, 1);
01369
01370 addInxIval (&genQueryInp.selectInp, COL_USER_INFO, 1);
01371 addInxIval (&genQueryInp.selectInp, COL_USER_COMMENT, 1);
01372 addInxIval (&genQueryInp.selectInp, COL_USER_CREATE_TIME, 1);
01373 addInxIval (&genQueryInp.selectInp, COL_USER_MODIFY_TIME, 1);
01374
01375
01376
01377 if (strstr(userName, "%")) {
01378 snprintf (condStr, MAX_NAME_LEN, " like '%s'", userName);
01379 }
01380 else {
01381 snprintf (condStr, MAX_NAME_LEN, " = '%s'", userName);
01382 }
01383
01384 addInxVal (&genQueryInp.sqlCondInp, COL_USER_NAME, condStr);
01385
01386
01387 genQueryInp.maxRows = MAX_SQL_ROWS;
01388
01389
01390
01391 status = rsGenQuery (rsComm, &genQueryInp, &genQueryOut);
01392
01393
01394 if (status == 0) {
01395 extractGenQueryResults(genQueryOut, mybuf, NULL, attrs);
01396
01397
01398 while (status==0 && genQueryOut->continueInx > 0) {
01399 genQueryInp.continueInx=genQueryOut->continueInx;
01400 status = rsGenQuery(rsComm, &genQueryInp, &genQueryOut);
01401
01402 extractGenQueryResults(genQueryOut, mybuf, NULL, attrs);
01403 }
01404 }
01405
01406 return (0);
01407 }
01408
01409
01410
01411
01412
01413
01414
01415 int
01416 getUserACL(char *userName, bytesBuf_t *mybuf, rsComm_t *rsComm)
01417 {
01418 genQueryInp_t genQueryInp;
01419 genQueryOut_t *genQueryOut;
01420 char condStr[MAX_NAME_LEN];
01421 int status;
01422
01423
01424 if (rsComm == NULL) {
01425 rodsLog (LOG_ERROR, "getUserACL: input rsComm is NULL");
01426 return (SYS_INTERNAL_NULL_INPUT_ERR);
01427 }
01428
01429
01430 if (userName == NULL) {
01431 rodsLog (LOG_ERROR, "getUserACL: username input is NULL");
01432 return (USER__NULL_INPUT_ERR);
01433 }
01434
01435
01436
01437
01438 memset (&genQueryInp, 0, sizeof (genQueryInp_t));
01439
01440
01441 addInxIval (&genQueryInp.selectInp, COL_COLL_NAME, 1);
01442 addInxIval (&genQueryInp.selectInp, COL_DATA_NAME, 1);
01443 addInxIval (&genQueryInp.selectInp, COL_USER_NAME, 1);
01444 addInxIval (&genQueryInp.selectInp, COL_DATA_ACCESS_NAME, 1);
01445
01446
01447
01448 if (strstr(userName, "%")) {
01449 snprintf (condStr, MAX_NAME_LEN, " like '%s'", userName);
01450 }
01451 else {
01452 snprintf (condStr, MAX_NAME_LEN, " = '%s'", userName);
01453 }
01454
01455 addInxVal (&genQueryInp.sqlCondInp, COL_USER_NAME, condStr);
01456
01457
01458
01459
01460 snprintf (condStr, MAX_NAME_LEN, "='%s'", "access_type");
01461 addInxVal (&genQueryInp.sqlCondInp, COL_DATA_TOKEN_NAMESPACE, condStr);
01462
01463 genQueryInp.maxRows = MAX_SQL_ROWS;
01464
01465
01466
01467 status = rsGenQuery (rsComm, &genQueryInp, &genQueryOut);
01468
01469
01470 if (status == 0) {
01471 extractACLQueryResults(genQueryOut, mybuf, 0);
01472
01473
01474 while (status==0 && genQueryOut->continueInx > 0) {
01475 genQueryInp.continueInx=genQueryOut->continueInx;
01476 status = rsGenQuery(rsComm, &genQueryInp, &genQueryOut);
01477
01478 extractACLQueryResults(genQueryOut, mybuf, 0);
01479 }
01480 }
01481
01482
01483
01484
01485 memset (&genQueryInp, 0, sizeof (genQueryInp_t));
01486
01487
01488 addInxIval (&genQueryInp.selectInp, COL_COLL_NAME, 1);
01489 addInxIval (&genQueryInp.selectInp, COL_USER_NAME, 1);
01490 addInxIval (&genQueryInp.selectInp, COL_DATA_ACCESS_NAME, 1);
01491
01492
01493
01494 if (strstr(userName, "%")) {
01495 snprintf (condStr, MAX_NAME_LEN, " like '%s'", userName);
01496 }
01497 else {
01498 snprintf (condStr, MAX_NAME_LEN, " = '%s'", userName);
01499 }
01500
01501 addInxVal (&genQueryInp.sqlCondInp, COL_USER_NAME, condStr);
01502
01503
01504
01505
01506 snprintf (condStr, MAX_NAME_LEN, "='%s'", "access_type");
01507 addInxVal (&genQueryInp.sqlCondInp, COL_DATA_TOKEN_NAMESPACE, condStr);
01508
01509 genQueryInp.maxRows = MAX_SQL_ROWS;
01510
01511
01512
01513 status = rsGenQuery (rsComm, &genQueryInp, &genQueryOut);
01514
01515
01516 if (status == 0) {
01517 extractACLQueryResults(genQueryOut, mybuf, 1);
01518
01519
01520 while (status==0 && genQueryOut->continueInx > 0) {
01521 genQueryInp.continueInx=genQueryOut->continueInx;
01522 status = rsGenQuery(rsComm, &genQueryInp, &genQueryOut);
01523
01524 extractACLQueryResults(genQueryOut, mybuf, 1);
01525 }
01526 }
01527
01528 return (0);
01529 }
01530
01531
01532
01533
01534
01535
01536
01537 int
01538 genAdminOpFromDataObj(dataObjInp_t *dataObjInp, generalAdminInp_t *generalAdminInp, rsComm_t *rsComm)
01539 {
01540 openedDataObjInp_t dataObjReadInp;
01541 openedDataObjInp_t dataObjCloseInp;
01542 openedDataObjInp_t dataObjLseekInp;
01543 fileLseekOut_t *dataObjLseekOut;
01544 bytesBuf_t *readBuf;
01545 int status;
01546 int objID;
01547 char *lineStart, *lineEnd;
01548 int bytesRead;
01549
01550
01551
01552 if (rsComm == NULL) {
01553 rodsLog (LOG_ERROR, "genAdminOpFromDataObj: input rsComm is NULL");
01554 return (SYS_INTERNAL_NULL_INPUT_ERR);
01555 }
01556
01557
01558 if (dataObjInp == NULL) {
01559 rodsLog (LOG_ERROR, "genAdminOpFromDataObj: input data object is NULL");
01560 return (USER__NULL_INPUT_ERR);
01561 }
01562
01563
01564
01565 if (rsComm->clientUser.authInfo.authFlag != 5) {
01566 return (CAT_INSUFFICIENT_PRIVILEGE_LEVEL);
01567 }
01568
01569
01570
01571 if ((objID=rsDataObjOpen(rsComm, dataObjInp)) < 0) {
01572 return (objID);
01573 }
01574
01575
01576 readBuf = (bytesBuf_t *)malloc(sizeof(bytesBuf_t));
01577 readBuf->len = 5*1024*1024;
01578 readBuf->buf = (char *)malloc(readBuf->len);
01579 memset (readBuf->buf, '\0', readBuf->len);
01580
01581
01582
01583 memset (&dataObjReadInp, 0, sizeof (dataObjReadInp));
01584 dataObjReadInp.l1descInx = objID;
01585 dataObjReadInp.len = readBuf->len;
01586
01587
01588 dataObjLseekInp.l1descInx = objID;
01589 dataObjLseekInp.offset = 0;
01590
01591
01592
01593 while ((bytesRead = rsDataObjRead (rsComm, &dataObjReadInp, readBuf)) > 0) {
01594
01595
01596 appendStrToBBuf(readBuf, "");
01597
01598
01599 lineStart = (char*)readBuf->buf;
01600
01601 while ( (lineEnd=strstr(lineStart, "\n")) ) {
01602 lineEnd[0]='\0';
01603
01604 status = parseGenAdminLine(lineStart, generalAdminInp, rsComm);
01605
01606 lineStart=lineEnd+1;
01607 }
01608
01609
01610 dataObjLseekInp.offset = dataObjLseekInp.offset + bytesRead - strlen(lineStart);
01611 dataObjLseekInp.whence = SEEK_SET;
01612
01613
01614
01615 if (strlen(lineStart) >= (size_t)bytesRead) {
01616 parseGenAdminLine(lineStart, generalAdminInp, rsComm);
01617 break;
01618 }
01619
01620 status = rsDataObjLseek (rsComm, &dataObjLseekInp, &dataObjLseekOut);
01621
01622
01623 memset(readBuf->buf, 0, readBuf->len);
01624
01625
01626 }
01627
01628
01629
01630
01631 memset (&dataObjCloseInp, 0, sizeof (dataObjCloseInp));
01632 dataObjCloseInp.l1descInx = objID;
01633
01634 status = rsDataObjClose (rsComm, &dataObjCloseInp);
01635
01636
01637 return (status);
01638 }
01639
01640
01641
01642 int
01643 parseGenAdminLine(char *inpLine, generalAdminInp_t *generalAdminInp, rsComm_t *rsComm)
01644 {
01645 int status;
01646 char *userName, *userID, *userType, *userZone;
01647 char *field, *newValue;
01648 char *tmpPtr;
01649
01650
01651
01652
01653 if (!rsComm) {
01654 rodsLog (LOG_ERROR, "parseGenAdminLine: rsComm is NULL");
01655 return (SYS_INTERNAL_NULL_INPUT_ERR);
01656 }
01657
01658 if (!inpLine) {
01659 rodsLog (LOG_ERROR, "parseGenAdminLine: inpLine is NULL");
01660 return (USER__NULL_INPUT_ERR);
01661 }
01662
01663 if (!generalAdminInp->arg0 || !generalAdminInp->arg1) {
01664 rodsLog (LOG_ERROR, "parseGenAdminLine: Action type not specified");
01665 return (USER__NULL_INPUT_ERR);
01666 }
01667
01668
01669
01670 if (inpLine[0] == '#') {
01671 return (0);
01672 }
01673
01674
01675
01676
01677 if (!strcmp(generalAdminInp->arg0, "add") && !strcmp(generalAdminInp->arg1, "user")) {
01678
01679 userName = inpLine;
01680 if ( (tmpPtr = strstr(userName, "|")) == NULL) {
01681 rodsLog (LOG_ERROR, "parseGenAdminLine: Parse error: user name is NULL");
01682 return (USER__NULL_INPUT_ERR);
01683 }
01684 tmpPtr[0] = '\0';
01685
01686
01687 generalAdminInp->arg2 = userName;
01688
01689
01690
01691 userID = tmpPtr+1;
01692 if ( (tmpPtr = strstr(userID, "|")) == NULL) {
01693 rodsLog (LOG_ERROR, "parseGenAdminLine: Parse error: missing argument(s)");
01694 return (USER__NULL_INPUT_ERR);
01695 }
01696 tmpPtr[0] = '\0';
01697
01698
01699
01700 userType = tmpPtr+1;
01701 if ( (tmpPtr = strstr(userType, "|")) == NULL) {
01702 rodsLog (LOG_ERROR, "parseGenAdminLine: Parse error: missing argument(s)");
01703 return (USER__NULL_INPUT_ERR);
01704 }
01705 tmpPtr[0] = '\0';
01706
01707
01708 generalAdminInp->arg3 = userType;
01709
01710
01711
01712 userZone = tmpPtr+1;
01713 if ( (tmpPtr = strstr(userZone, "|")) == NULL) {
01714 rodsLog (LOG_ERROR, "parseGenAdminLine: Parse error: missing argument(s)");
01715 return (USER__NULL_INPUT_ERR);
01716 }
01717 tmpPtr[0] = '\0';
01718
01719
01720 generalAdminInp->arg4 = userZone;
01721
01722
01723
01724 generalAdminInp->arg5 = "";
01725
01726
01727
01728 status = rsGeneralAdmin(rsComm, generalAdminInp);
01729
01730 return (status);
01731 }
01732
01733
01734 if (!strcmp(generalAdminInp->arg0, "modify") && !strcmp(generalAdminInp->arg1, "user")) {
01735
01736 userName = inpLine;
01737 if ( (tmpPtr = strstr(userName, "|")) == NULL) {
01738 rodsLog (LOG_ERROR, "parseGenAdminLine: Parse error: user name is NULL");
01739 return (USER__NULL_INPUT_ERR);
01740 }
01741 tmpPtr[0] = '\0';
01742
01743
01744 generalAdminInp->arg2 = userName;
01745
01746
01747
01748 field = tmpPtr+1;
01749 if ( (tmpPtr = strstr(field, "|")) == NULL) {
01750 rodsLog (LOG_ERROR, "parseGenAdminLine: Parse error: missing argument(s)");
01751 return (USER__NULL_INPUT_ERR);
01752 }
01753 tmpPtr[0] = '\0';
01754
01755
01756 generalAdminInp->arg3 = field;
01757
01758
01759
01760 newValue = tmpPtr+1;
01761 if (!newValue || !strlen(newValue)) {
01762 generalAdminInp->arg4 = "";
01763 }
01764 else {
01765
01766 generalAdminInp->arg4 = newValue;
01767 }
01768
01769
01770 if (!strcmp(field,"password")) {
01771 int i, len, lcopy;
01772 char buf0[MAX_PASSWORD_LEN+10];
01773 char buf1[MAX_PASSWORD_LEN+10];
01774 char buf2[MAX_PASSWORD_LEN+10];
01775 char rand[]="1gCBizHWbwIYyWLoysGzTe6SyzqFKMniZX05faZHWAwQKXf6Fs";
01776
01777 snprintf(buf0, MAX_PASSWORD_LEN+1, "%s", newValue);
01778 len = strlen(newValue);
01779 lcopy = MAX_PASSWORD_LEN-10-len;
01780 if (lcopy > 15) {
01781 strncat(buf0, rand, lcopy);
01782 }
01783 i = obfGetPw(buf1);
01784 if (i !=0) {
01785
01786 rodsLog (LOG_ERROR, "parseGenAdminLine: Error getting password");
01787 return (USER__NULL_INPUT_ERR);
01788 }
01789 obfEncodeByKey(buf0, buf1, buf2);
01790
01791 generalAdminInp->arg4 = buf2;
01792 }
01793
01794
01795
01796 status = rsGeneralAdmin(rsComm, generalAdminInp);
01797
01798 return (status);
01799 }
01800
01801
01802 if (!strcmp(generalAdminInp->arg0, "rm") && !strcmp(generalAdminInp->arg1, "user")) {
01803
01804 userName = inpLine;
01805 if ( (tmpPtr = strstr(userName, "|")) != NULL) {
01806 tmpPtr[0] = '\0';
01807 }
01808
01809
01810 generalAdminInp->arg2 = userName;
01811
01812
01813
01814 generalAdminInp->arg3 = rsComm->clientUser.rodsZone;
01815
01816
01817
01818 status = rsGeneralAdmin(rsComm, generalAdminInp);
01819
01820 return (status);
01821 }
01822
01823
01824 return (0);
01825 }
01826
01827
01828
01829
01830
01831
01832
01833 int
01834 loadACLFromDataObj(dataObjInp_t *dataObjInp, rsComm_t *rsComm)
01835 {
01836 openedDataObjInp_t dataObjReadInp;
01837 openedDataObjInp_t dataObjCloseInp;
01838 openedDataObjInp_t dataObjLseekInp;
01839 fileLseekOut_t *dataObjLseekOut;
01840 bytesBuf_t *readBuf;
01841 int status;
01842 int objID;
01843 char *lineStart, *lineEnd;
01844 int bytesRead;
01845
01846
01847
01848 if (rsComm == NULL) {
01849 rodsLog (LOG_ERROR, "loadACLFromDataObj: input rsComm is NULL");
01850 return (SYS_INTERNAL_NULL_INPUT_ERR);
01851 }
01852
01853
01854 if (dataObjInp == NULL) {
01855 rodsLog (LOG_ERROR, "loadACLFromDataObj: input data object is NULL");
01856 return (USER__NULL_INPUT_ERR);
01857 }
01858
01859
01860
01861 if ((objID=rsDataObjOpen(rsComm, dataObjInp)) < 0) {
01862 return (objID);
01863 }
01864
01865
01866 readBuf = (bytesBuf_t *)malloc(sizeof(bytesBuf_t));
01867 readBuf->len = 5*1024*1024;
01868 readBuf->buf = (char *)malloc(readBuf->len);
01869 memset (readBuf->buf, '\0', readBuf->len);
01870
01871
01872
01873 memset (&dataObjReadInp, 0, sizeof (dataObjReadInp));
01874 dataObjReadInp.l1descInx = objID;
01875 dataObjReadInp.len = readBuf->len;
01876
01877
01878 dataObjLseekInp.l1descInx = objID;
01879 dataObjLseekInp.offset = 0;
01880
01881
01882
01883 while ((bytesRead = rsDataObjRead (rsComm, &dataObjReadInp, readBuf)) > 0) {
01884
01885
01886 appendStrToBBuf(readBuf, "");
01887
01888
01889 lineStart = (char*)readBuf->buf;
01890
01891 while ( (lineEnd=strstr(lineStart, "\n")) ) {
01892 lineEnd[0]='\0';
01893
01894 status = parseACLModLine(lineStart, rsComm);
01895
01896 lineStart=lineEnd+1;
01897 }
01898
01899
01900 dataObjLseekInp.offset = dataObjLseekInp.offset + bytesRead - strlen(lineStart);
01901 dataObjLseekInp.whence = SEEK_SET;
01902
01903
01904
01905 if (strlen(lineStart) >= (size_t)bytesRead) {
01906 parseACLModLine(lineStart, rsComm);
01907 break;
01908 }
01909
01910 status = rsDataObjLseek (rsComm, &dataObjLseekInp, &dataObjLseekOut);
01911
01912
01913 memset(readBuf->buf, 0, readBuf->len);
01914
01915
01916 }
01917
01918
01919
01920
01921 memset (&dataObjCloseInp, 0, sizeof (dataObjCloseInp));
01922 dataObjCloseInp.l1descInx = objID;
01923
01924 status = rsDataObjClose (rsComm, &dataObjCloseInp);
01925
01926
01927 return (status);
01928 }
01929
01930
01931
01932 int
01933 parseACLModLine(char *inpLine, rsComm_t *rsComm)
01934 {
01935 modAccessControlInp_t modAccessControl;
01936 int status;
01937 char *accessLevel, *user, *path;
01938 char userName[NAME_LEN];
01939 char zoneName[NAME_LEN];
01940 char *tmpPtr;
01941
01942
01943
01944 if (!rsComm) {
01945 rodsLog (LOG_ERROR, "parseACLModLine: rsComm is NULL");
01946 return (SYS_INTERNAL_NULL_INPUT_ERR);
01947 }
01948
01949 if (!inpLine) {
01950 rodsLog (LOG_ERROR, "parseACLModLine: inpLine is NULL");
01951 return (USER__NULL_INPUT_ERR);
01952 }
01953
01954
01955
01956 if (inpLine[0] == '#') {
01957 return (0);
01958 }
01959
01960
01961
01962 memset (&modAccessControl, 0, sizeof(modAccessControlInp_t));
01963 modAccessControl.recursiveFlag = 0;
01964
01965
01966
01967 path = inpLine;
01968 if ( (tmpPtr = strstr(path, "|")) == NULL) {
01969 rodsLog (LOG_ERROR, "parseACLModLine: Parse error: object path is NULL");
01970 return (USER__NULL_INPUT_ERR);
01971 }
01972 tmpPtr[0] = '\0';
01973
01974
01975 modAccessControl.path = path;
01976
01977
01978
01979 user = tmpPtr+1;
01980 if ( (tmpPtr = strstr(user, "|")) == NULL) {
01981 rodsLog (LOG_ERROR, "parseACLModLine: Parse error: user is NULL");
01982 return (USER__NULL_INPUT_ERR);
01983 }
01984 tmpPtr[0] = '\0';
01985
01986 status = parseUserName(user, userName, zoneName);
01987
01988
01989 modAccessControl.userName = userName;
01990 modAccessControl.zone = zoneName;
01991
01992
01993
01994 accessLevel = tmpPtr+1;
01995 if (!accessLevel || !strlen(accessLevel)) {
01996 rodsLog (LOG_ERROR, "parseACLModLine: Parse error: accessLevel is NULL");
01997 return (USER__NULL_INPUT_ERR);
01998 }
01999
02000
02001
02002 modAccessControl.accessLevel = accessLevel;
02003
02004
02005
02006 status = rsModAccessControl(rsComm, &modAccessControl);
02007
02008 return (status);
02009 }
02010
02011
02012
02013
02014
02015
02016
02017 int
02018 getSqlRowsByInx(genQueryOut_t *genQueryOut, intArray_t *indexes, bytesBuf_t *mybuf)
02019 {
02020 char *resultStringToken;
02021 sqlResult_t *sqlResult;
02022 int i, j;
02023
02024
02025 for (i=0;i<genQueryOut->rowCnt;i++) {
02026
02027 for (j=0;j<indexes->len;j++) {
02028 sqlResult = getSqlResultByInx (genQueryOut, indexes->value[j]);
02029
02030 resultStringToken = sqlResult->value + i*sqlResult->len;
02031
02032 appendStrToBBuf(mybuf, resultStringToken);
02033 appendStrToBBuf(mybuf, "|");
02034 }
02035
02036
02037 appendStrToBBuf(mybuf, "\n");
02038 }
02039
02040 return (i);
02041 }
02042
02043
02044
02045
02046
02047
02048
02049
02050 int
02051 getObjectByFilePath(char *filePath, char *rescName, char *objPath, rsComm_t *rsComm)
02052 {
02053 genQueryInp_t genQueryInp;
02054 genQueryOut_t *genQueryOut;
02055 char condStr[MAX_NAME_LEN];
02056 sqlResult_t *dataName, *collName;
02057 int status;
02058
02059
02060
02061 memset (&genQueryInp, 0, sizeof (genQueryInp_t));
02062 genQueryInp.maxRows = 1;
02063
02064
02065 addInxIval (&genQueryInp.selectInp, COL_COLL_NAME, 1);
02066 addInxIval (&genQueryInp.selectInp, COL_DATA_NAME, 1);
02067
02068
02069 snprintf (condStr, MAX_NAME_LEN, " = '%s'", filePath);
02070 addInxVal (&genQueryInp.sqlCondInp, COL_D_DATA_PATH, condStr);
02071
02072 snprintf (condStr, MAX_NAME_LEN, " = '%s'", rescName);
02073 addInxVal (&genQueryInp.sqlCondInp, COL_D_RESC_NAME, condStr);
02074
02075
02076 status = rsGenQuery (rsComm, &genQueryInp, &genQueryOut);
02077
02078 if (status >= 0)
02079 {
02080
02081 dataName = getSqlResultByInx (genQueryOut, COL_DATA_NAME);
02082 collName = getSqlResultByInx (genQueryOut, COL_COLL_NAME);
02083
02084
02085 snprintf(objPath, MAX_NAME_LEN, "%s/%s", collName->value, dataName->value);
02086 }
02087
02088 return (status);
02089 }
02090
02091
02092