00001
00002
00003
00004
00005
00006 #include "chkObjPermAndStat.h"
00007 #include "apiHeaderAll.h"
00008 #include "icatHighLevelRoutines.h"
00009 #include "icatHighLevelRoutines.h"
00010 int
00011 saveCollEntForChkColl (collEnt_t *collEnt);
00012 int
00013 freeCollEntForChkColl (collEnt_t *collEnt);
00014
00015 int
00016 rsChkObjPermAndStat (rsComm_t *rsComm,
00017 chkObjPermAndStat_t *chkObjPermAndStatInp)
00018 {
00019 int status;
00020 rodsServerHost_t *rodsServerHost = NULL;
00021
00022 status = getAndConnRcatHost (rsComm, SLAVE_RCAT,
00023 chkObjPermAndStatInp->objPath, &rodsServerHost);
00024 if (status < 0 || rodsServerHost == NULL ) {
00025 return(status);
00026 }
00027 if (rodsServerHost->localFlag == LOCAL_HOST) {
00028 #ifdef RODS_CAT
00029 status = _rsChkObjPermAndStat (rsComm, chkObjPermAndStatInp);
00030 #else
00031 status = SYS_NO_RCAT_SERVER_ERR;
00032 #endif
00033 } else {
00034 status = rcChkObjPermAndStat (rodsServerHost->conn,
00035 chkObjPermAndStatInp);
00036 }
00037
00038 return (status);
00039 }
00040
00041 int
00042 _rsChkObjPermAndStat (rsComm_t *rsComm,
00043 chkObjPermAndStat_t *chkObjPermAndStatInp)
00044 {
00045 #ifdef RODS_CAT
00046 int status;
00047
00048 if ((chkObjPermAndStatInp->flags & CHK_COLL_FOR_BUNDLE_OPR) != 0) {
00049 status = chkCollForBundleOpr (rsComm, chkObjPermAndStatInp);
00050 } else {
00051 rodsLog (LOG_ERROR,
00052 "_rsChkObjPermAndStat: rsChkObjPermAndStat of %s error. flags = %d",
00053 chkObjPermAndStatInp->objPath, chkObjPermAndStatInp->flags);
00054 return SYS_OPR_FLAG_NOT_SUPPORT;
00055 }
00056 return status;
00057 #else
00058 return (SYS_NO_RCAT_SERVER_ERR);
00059 #endif
00060 }
00061
00062
00063 int
00064 chkCollForBundleOpr (rsComm_t *rsComm,
00065 chkObjPermAndStat_t *chkObjPermAndStatInp)
00066 {
00067 #ifdef RODS_CAT
00068 int status;
00069 collInp_t openCollInp;
00070 collEnt_t *collEnt = NULL;
00071 collEnt_t *curCollEnt = NULL;
00072 int handleInx;
00073 int curCopyGood = False;
00074 char *resource;
00075 rodsLong_t myId;
00076 char myPath[MAX_NAME_LEN];
00077
00078 if ((resource = getValByKey (&chkObjPermAndStatInp->condInput,
00079 RESC_NAME_KW)) == NULL) {
00080 rodsLog (LOG_ERROR,
00081 "chkCollForBundleOpr: RESC_NAME_KW not specified for %s",
00082 chkObjPermAndStatInp->objPath);
00083 return SYS_INVALID_RESC_INPUT;
00084 }
00085
00086 memset (&openCollInp, 0, sizeof (openCollInp));
00087 rstrcpy (openCollInp.collName, chkObjPermAndStatInp->objPath, MAX_NAME_LEN);
00088 openCollInp.flags =
00089 RECUR_QUERY_FG | LONG_METADATA_FG | NO_TRIM_REPL_FG;
00090 handleInx = rsOpenCollection (rsComm, &openCollInp);
00091 if (handleInx < 0) {
00092 rodsLog (LOG_ERROR,
00093 "chkCollForBundleOpr: rsOpenCollection of %s error. status = %d",
00094 openCollInp.collName, handleInx);
00095 return (handleInx);
00096 }
00097
00098 while ((status = rsReadCollection (rsComm, &handleInx, &collEnt)) >= 0) {
00099 if (collEnt->specColl.collClass != NO_SPEC_COLL) {
00100 if (strcmp (resource, collEnt->specColl.resource) != 0) {
00101 rodsLog (LOG_ERROR,
00102 "chkCollForBundleOpr: specColl resc %s does not match %s",
00103 collEnt->specColl.resource, resource);
00104 rsCloseCollection (rsComm, &handleInx);
00105 return SYS_COPY_NOT_EXIST_IN_RESC;
00106 }
00107
00108 myId = checkAndGetObjectId (rsComm, "-c",
00109 collEnt->specColl.collection, ACCESS_READ_OBJECT);
00110 if (myId < 0) {
00111 status = myId;
00112 rodsLog (LOG_ERROR,
00113 "chkCollForBundleOpr: no accPerm to specColl %s. status = %d",
00114 collEnt->specColl.collection, status);
00115 rsCloseCollection (rsComm, &handleInx);
00116 return status;
00117 }
00118 free (collEnt);
00119 collEnt = NULL;
00120 continue;
00121 }
00122
00123 if (collEnt->objType == DATA_OBJ_T) {
00124 if (curCollEnt == NULL) {
00125 curCollEnt = collEnt;
00126 saveCollEntForChkColl (collEnt);
00127 if (collEnt->replStatus > 0 &&
00128 strcmp (resource, collEnt->resource) == 0) {
00129 curCopyGood = True;
00130 }
00131 } else {
00132 if (strcmp (curCollEnt->dataName, collEnt->dataName) == 0 &&
00133 strcmp (curCollEnt->collName, collEnt->collName) == 0) {
00134 if (collEnt->replStatus > 0 &&
00135 strcmp (resource, collEnt->resource) == 0) {
00136
00137 freeCollEntForChkColl (curCollEnt);
00138 curCopyGood = True;
00139 curCollEnt = collEnt;
00140 saveCollEntForChkColl (collEnt);
00141 }
00142 } else {
00143
00144 snprintf (myPath, MAX_NAME_LEN, "%s/%s",
00145 curCollEnt->collName,
00146 curCollEnt->dataName);
00147 if (curCopyGood == False) {
00148 status = replDataObjForBundle (rsComm,
00149 curCollEnt->collName, curCollEnt->dataName,
00150 resource, 0, NULL);
00151 if (status < 0) {
00152 rodsLog (LOG_ERROR,
00153 "chkCollForBundleOpr: %s no good copy in %s",
00154 myPath, resource);
00155 rsCloseCollection (rsComm, &handleInx);
00156 freeCollEntForChkColl (curCollEnt);
00157 return SYS_COPY_NOT_EXIST_IN_RESC;
00158 }
00159 }
00160 freeCollEntForChkColl (curCollEnt);
00161 curCopyGood = False;
00162 curCollEnt = NULL;
00163
00164
00165 myId = checkAndGetObjectId (rsComm, "-d", myPath,
00166 ACCESS_READ_OBJECT);
00167 if (myId < 0 && myId != CAT_UNKNOWN_FILE) {
00168
00169 status = myId;
00170 rodsLog (LOG_ERROR,
00171 "chkCollForBundleOpr: no accPerm to %s. status = %d",
00172 myPath, status);
00173 rsCloseCollection (rsComm, &handleInx);
00174 return status;
00175 } else {
00176
00177 curCollEnt = collEnt;
00178 saveCollEntForChkColl (collEnt);
00179 collEnt = NULL;
00180 if (curCollEnt->replStatus > 0 &&
00181 strcmp (resource, curCollEnt->resource) == 0) {
00182
00183 curCopyGood = True;
00184 }
00185 }
00186 }
00187 }
00188 } else {
00189 free (collEnt);
00190 }
00191 }
00192
00193
00194 if (curCollEnt != NULL) {
00195 if (curCopyGood == False) {
00196 status = replDataObjForBundle (rsComm, curCollEnt->collName,
00197 curCollEnt->dataName, resource, 0, NULL);
00198 if (status < 0) {
00199 rodsLog (LOG_ERROR,
00200 "chkCollForBundleOpr:%s does not have a good copy in %s",
00201 chkObjPermAndStatInp->objPath, resource);
00202 status = SYS_COPY_NOT_EXIST_IN_RESC;
00203 }
00204 } else {
00205 freeCollEntForChkColl (curCollEnt);
00206 }
00207 } else {
00208 status = 0;
00209 }
00210
00211 rsCloseCollection (rsComm, &handleInx);
00212
00213 return (0);
00214 #else
00215 return (SYS_NO_RCAT_SERVER_ERR);
00216 #endif
00217 }
00218
00219
00220
00221
00222
00223 int
00224 saveCollEntForChkColl (collEnt_t *collEnt)
00225 {
00226 if (collEnt == NULL) return 0;
00227 if (collEnt->collName != NULL)
00228 collEnt->collName = strdup (collEnt->collName);
00229 if (collEnt->dataName != NULL)
00230 collEnt->dataName = strdup (collEnt->dataName);
00231 if (collEnt->resource != NULL)
00232 collEnt->resource = strdup (collEnt->resource);
00233 return 0;
00234 }
00235
00236 int
00237 freeCollEntForChkColl (collEnt_t *collEnt)
00238 {
00239 if (collEnt == NULL) return 0;
00240 if (collEnt->collName != NULL) free (collEnt->collName);
00241 if (collEnt->dataName != NULL) free (collEnt->dataName);
00242 if (collEnt->resource != NULL) free (collEnt->resource);
00243
00244 free (collEnt);
00245 return 0;
00246 }
00247