irods  4.2.8
About: iRODS (the integrated Rule Oriented Data System) is a distributed data-management system for creating data grids, digital libraries, persistent archives, and real-time data systems.
  Fossies Dox: irods-4.2.8.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

rsChkObjPermAndStat.cpp
Go to the documentation of this file.
1 
3 /* rsChkObjPermAndStat.c
4  */
5 
6 #include "chkObjPermAndStat.h"
7 #include "apiHeaderAll.h"
9 #include "miscServerFunct.hpp"
11 #include "rsChkObjPermAndStat.hpp"
12 #include "rsOpenCollection.hpp"
13 #include "rsReadCollection.hpp"
14 #include "rsCloseCollection.hpp"
15 #include "rsPhyBundleColl.hpp"
16 
17 int
19 int
21 
22 int
24  chkObjPermAndStat_t *chkObjPermAndStatInp ) {
25  int status;
27 
29  rsComm,
30  SLAVE_RCAT,
31  ( const char* )chkObjPermAndStatInp->objPath,
32  &rodsServerHost );
33  if ( status < 0 || rodsServerHost == NULL ) { // JMC cppcheck
34  return status;
35  }
37  std::string svc_role;
38  irods::error ret = get_catalog_service_role(svc_role);
39  if(!ret.ok()) {
40  irods::log(PASS(ret));
41  return ret.code();
42  }
43 
44  if( irods::CFG_SERVICE_ROLE_PROVIDER == svc_role ) {
45  status = _rsChkObjPermAndStat( rsComm, chkObjPermAndStatInp );
46  } else if( irods::CFG_SERVICE_ROLE_CONSUMER == svc_role ) {
48  } else {
49  rodsLog(
50  LOG_ERROR,
51  "role not supported [%s]",
52  svc_role.c_str() );
54  }
55  }
56  else {
58  chkObjPermAndStatInp );
59  }
60 
61  return status;
62 }
63 
64 int
66  chkObjPermAndStat_t *chkObjPermAndStatInp ) {
67  std::string svc_role;
68  irods::error ret = get_catalog_service_role(svc_role);
69  if(!ret.ok()) {
70  irods::log(PASS(ret));
71  return ret.code();
72  }
73 
74  if( irods::CFG_SERVICE_ROLE_PROVIDER == svc_role ) {
75  int status;
76 
77  if ( ( chkObjPermAndStatInp->flags & CHK_COLL_FOR_BUNDLE_OPR ) != 0 ) {
78  status = chkCollForBundleOpr( rsComm, chkObjPermAndStatInp );
79  }
80  else {
82  "_rsChkObjPermAndStat: rsChkObjPermAndStat of %s error. flags = %d",
83  chkObjPermAndStatInp->objPath, chkObjPermAndStatInp->flags );
85  }
86  return status;
87  } else if( irods::CFG_SERVICE_ROLE_CONSUMER == svc_role ) {
89  } else {
90  rodsLog(
91  LOG_ERROR,
92  "role not supported [%s]",
93  svc_role.c_str() );
95  }
96 }
97 
98 int
100  chkObjPermAndStat_t *chkObjPermAndStatInp ) {
101  std::string svc_role;
102  irods::error ret = get_catalog_service_role(svc_role);
103  if(!ret.ok()) {
104  irods::log(PASS(ret));
105  return ret.code();
106  }
107 
108  if( irods::CFG_SERVICE_ROLE_PROVIDER == svc_role ) {
109  int status;
110  collInp_t openCollInp;
111  collEnt_t *collEnt = NULL;
112  collEnt_t *curCollEnt = NULL;
113  int handleInx;
114  int curCopyGood = False;
115  char *resource;
116  char *resc_hier;
117  rodsLong_t myId;
118  char myPath[MAX_NAME_LEN];
119 
120  if ( ( resource = getValByKey( &chkObjPermAndStatInp->condInput,
121  RESC_NAME_KW ) ) == NULL ) {
123  "chkCollForBundleOpr: RESC_NAME_KW not specified for %s",
124  chkObjPermAndStatInp->objPath );
125  return SYS_INVALID_RESC_INPUT;
126  }
127 
128  if ( ( resc_hier = getValByKey( &chkObjPermAndStatInp->condInput,
129  RESC_HIER_STR_KW ) ) == NULL ) {
131  "chkCollForBundleOpr: RESC_HIER_STR_KW not specified for %s",
132  chkObjPermAndStatInp->objPath );
133  return SYS_INVALID_RESC_INPUT;
134  }
135 
136  memset( &openCollInp, 0, sizeof( openCollInp ) );
137  rstrcpy( openCollInp.collName, chkObjPermAndStatInp->objPath, MAX_NAME_LEN );
138  openCollInp.flags =
140  handleInx = rsOpenCollection( rsComm, &openCollInp );
141  if ( handleInx < 0 ) {
143  "chkCollForBundleOpr: rsOpenCollection of %s error. status = %d",
144  openCollInp.collName, handleInx );
145  return handleInx;
146  }
147  while ( ( status = rsReadCollection( rsComm, &handleInx, &collEnt ) ) >= 0 ) {
148  if ( collEnt->specColl.collClass != NO_SPEC_COLL ) {
149  if ( strcmp( resource, collEnt->specColl.resource ) != 0 ) {
151  "chkCollForBundleOpr: specColl resc %s does not match %s",
152  collEnt->specColl.resource, resource );
153  rsCloseCollection( rsComm, &handleInx );
154  freeCollEntForChkColl( collEnt );
155  freeCollEntForChkColl( curCollEnt );
157  }
158  /* check permission */
159  myId = chlCheckAndGetObjectID( rsComm, "-c",
161  if ( myId < 0 ) {
162  status = myId;
164  "chkCollForBundleOpr: no accPerm to specColl %s. status = %d",
165  collEnt->specColl.collection, status );
166  rsCloseCollection( rsComm, &handleInx );
167  freeCollEntForChkColl( collEnt );
168  freeCollEntForChkColl( curCollEnt );
169  return status;
170  }
171  free( collEnt );
172  collEnt = NULL;
173  continue;
174  }
175 
176  if ( collEnt->objType == DATA_OBJ_T ) {
177  if ( curCollEnt == NULL ) {
178  curCollEnt = collEnt;
179  saveCollEntForChkColl( collEnt );
180  if ( collEnt->replStatus > 0 &&
181  strcmp( resource, collEnt->resource ) == 0 &&
182  strcmp( resc_hier, collEnt->resc_hier ) == 0 ) {
183  curCopyGood = True;
184  }
185  }
186  else {
187  if ( strcmp( curCollEnt->dataName, collEnt->dataName ) == 0 &&
188  strcmp( curCollEnt->collName, collEnt->collName ) == 0 ) {
189  if ( collEnt->replStatus > 0 &&
190  strcmp( resource, collEnt->resource ) == 0 &&
191  strcmp( resc_hier, collEnt->resc_hier ) == 0 ) {
192  /* a good copy */
193  freeCollEntForChkColl( curCollEnt );
194  curCopyGood = True;
195  curCollEnt = collEnt;
196  saveCollEntForChkColl( collEnt );
197  }
198  }
199  else {
200  /* encounter a new data obj */
201  snprintf( myPath, MAX_NAME_LEN, "%s/%s",
202  curCollEnt->collName, curCollEnt->dataName );
203 
204  if ( curCopyGood == False ) {
205  status = replDataObjForBundle( rsComm,
206  curCollEnt->collName, curCollEnt->dataName,
207  resource, curCollEnt->resc_hier, resc_hier, 0, NULL );
208 
209  if ( status < 0 ) {
211  "chkCollForBundleOpr: %s no good copy in %s [%d]",
212  myPath, resource, status );
213  rsCloseCollection( rsComm, &handleInx );
214  freeCollEntForChkColl( curCollEnt );
216  }
217  }
218  else {
219 
220  }
221  freeCollEntForChkColl( curCollEnt );
222  curCopyGood = False;
223  curCollEnt = NULL;
224 
225  /* we have a good copy. Check the permission */
226  myId = chlCheckAndGetObjectID( rsComm, "-d", myPath,
228  if ( myId < 0 && myId != CAT_UNKNOWN_FILE ) {
229  /* could return CAT_UNKNOWN_FILE if mounted files */
230  status = myId;
232  "chkCollForBundleOpr: no accPerm to %s. status = %d",
233  myPath, status );
234  rsCloseCollection( rsComm, &handleInx );
235  freeCollEntForChkColl( collEnt );
236  return status;
237  }
238  else {
239  /* copy is OK */
240  curCollEnt = collEnt;
241  saveCollEntForChkColl( collEnt );
242  collEnt = NULL;
243  if ( curCollEnt->replStatus > 0 &&
244  strcmp( resource, curCollEnt->resource ) == 0 &&
245  strcmp( resc_hier, curCollEnt->resc_hier ) == 0 ) {
246  /* a good copy */
247  curCopyGood = True;
248  }
249  }
250  }
251  }
252  }
253  else {
254  free( collEnt );
255  }
256  }
257 
258  /* handle what's left */
259  if ( curCollEnt != NULL ) {
260  if ( curCopyGood == False ) {
261  status = replDataObjForBundle( rsComm, curCollEnt->collName,
262  curCollEnt->dataName, resource, curCollEnt->resc_hier, resc_hier, 0, NULL );
263  freeCollEntForChkColl( curCollEnt );
264  if ( status < 0 ) {
266  "chkCollForBundleOpr:%s does not have a good copy in %s",
267  chkObjPermAndStatInp->objPath, resource );
269  }
270  }
271  else {
272  freeCollEntForChkColl( curCollEnt );
273  }
274  }
275  else {
276  status = 0;
277  }
278 
279  rsCloseCollection( rsComm, &handleInx );
280 
281  return 0;
282  } else if( irods::CFG_SERVICE_ROLE_CONSUMER == svc_role ) {
283  return SYS_NO_RCAT_SERVER_ERR;
284  } else {
285  rodsLog(
286  LOG_ERROR,
287  "role not supported [%s]",
288  svc_role.c_str() );
290  }
291 }
292 
293 /* saveCollEntForChkColl - save some of entries in collEnt_t used by
294  * chkCollForBundleOpr. These entry need to be saved because it could
295  * be freed if the query has continuation.
296  */
297 int
299  if ( collEnt == NULL ) {
300  return 0;
301  }
302  if ( collEnt->collName != NULL ) {
303  collEnt->collName = strdup( collEnt->collName );
304  }
305  if ( collEnt->dataName != NULL ) {
306  collEnt->dataName = strdup( collEnt->dataName );
307  }
308  if ( collEnt->resource != NULL ) {
309  collEnt->resource = strdup( collEnt->resource );
310  }
311  if ( collEnt->resc_hier != NULL ) {
312  collEnt->resc_hier = strdup( collEnt->resc_hier );
313  }
314  return 0;
315 }
316 
317 int
319  if ( collEnt == NULL ) {
320  return 0;
321  }
322  if ( collEnt->collName != NULL ) {
323  free( collEnt->collName );
324  }
325  if ( collEnt->dataName != NULL ) {
326  free( collEnt->dataName );
327  }
328  if ( collEnt->resource != NULL ) {
329  free( collEnt->resource );
330  }
331 
332  free( collEnt );
333  return 0;
334 }
rodsLog
void rodsLog(int level, const char *formatStr,...)
Definition: rodsLog.cpp:86
getValByKey
char * getValByKey(const keyValPair_t *condInput, const char *keyWord)
Definition: rcMisc.cpp:675
RESC_NAME_KW
#define RESC_NAME_KW
Definition: rodsKeyWdDef.h:19
LONG_METADATA_FG
#define LONG_METADATA_FG
Definition: miscUtil.h:90
NULL
#define NULL
Definition: rodsDef.h:70
ACCESS_READ_OBJECT
#define ACCESS_READ_OBJECT
Definition: icatDefines.h:52
rsComm_t
Definition: rcConnect.h:145
True
#define True
Definition: parseCommandLine.h:11
rsReadCollection
int rsReadCollection(rsComm_t *rsComm, int *handleInxInp, collEnt_t **collEnt)
Definition: rsReadCollection.cpp:15
irods::CFG_SERVICE_ROLE_CONSUMER
const std::string CFG_SERVICE_ROLE_CONSUMER("consumer")
chkCollForBundleOpr
int chkCollForBundleOpr(rsComm_t *rsComm, chkObjPermAndStat_t *chkObjPermAndStatInp)
Definition: rsChkObjPermAndStat.cpp:99
rsOpenCollection
int rsOpenCollection(rsComm_t *rsComm, collInp_t *openCollInp)
Definition: rsOpenCollection.cpp:16
irods_configuration_keywords.hpp
rodsServerHost::localFlag
int localFlag
Definition: rodsConnect.h:68
SYS_INVALID_RESC_INPUT
@ SYS_INVALID_RESC_INPUT
Definition: rodsErrorTable.h:100
SYS_SERVICE_ROLE_NOT_SUPPORTED
@ SYS_SERVICE_ROLE_NOT_SUPPORTED
Definition: rodsErrorTable.h:217
CollEnt::resource
char * resource
Definition: miscUtil.h:125
CollInp
Definition: dataObjInpOut.h:157
rodsServerHost::conn
rcComm_t * conn
Definition: rodsConnect.h:64
SpecColl::resource
char resource[64]
Definition: objInfo.h:83
PASS
#define PASS(prev_error_)
Definition: irods_error.hpp:118
CollEnt::collName
char * collName
Definition: miscUtil.h:119
rsPhyBundleColl.hpp
rsOpenCollection.hpp
rsChkObjPermAndStat.hpp
LOCAL_HOST
#define LOCAL_HOST
Definition: rodsConnect.h:44
chkObjPermAndStat.h
NO_TRIM_REPL_FG
#define NO_TRIM_REPL_FG
Definition: miscUtil.h:94
LOG_ERROR
#define LOG_ERROR
Definition: rodsLog.h:43
CollInp::flags
int flags
Definition: dataObjInpOut.h:159
rsReadCollection.hpp
CollEnt::replStatus
int replStatus
Definition: miscUtil.h:116
rsCloseCollection
int rsCloseCollection(rsComm_t *rsComm, int *handleInxInp)
Definition: rsCloseCollection.cpp:14
replDataObjForBundle
int replDataObjForBundle(rsComm_t *rsComm, char *collName, char *dataName, const char *rescName, char *rescHier, char *destRescHier, int adminFlag, dataObjInfo_t *outCacheObjInfo)
Definition: rsPhyBundleColl.cpp:648
_rsChkObjPermAndStat
int _rsChkObjPermAndStat(rsComm_t *rsComm, chkObjPermAndStat_t *chkObjPermAndStatInp)
Definition: rsChkObjPermAndStat.cpp:65
irods::error::code
long long code() const
Definition: irods_error.cpp:194
SYS_OPR_FLAG_NOT_SUPPORT
@ SYS_OPR_FLAG_NOT_SUPPORT
Definition: rodsErrorTable.h:150
RESC_HIER_STR_KW
#define RESC_HIER_STR_KW
Definition: rodsKeyWdDef.h:225
chkObjPermAndStat_t::objPath
char objPath[(1024+64)]
Definition: chkObjPermAndStat.h:10
chlCheckAndGetObjectID
int chlCheckAndGetObjectID(rsComm_t *, char *, char *, char *)
Definition: icatHighLevelRoutines.cpp:318
irods::CFG_SERVICE_ROLE_PROVIDER
const std::string CFG_SERVICE_ROLE_PROVIDER("provider")
CollEnt
Definition: miscUtil.h:113
CollEnt::specColl
specColl_t specColl
Definition: miscUtil.h:130
freeCollEntForChkColl
int freeCollEntForChkColl(collEnt_t *collEnt)
Definition: rsChkObjPermAndStat.cpp:318
MAX_NAME_LEN
#define MAX_NAME_LEN
Definition: rodsDef.h:61
saveCollEntForChkColl
int saveCollEntForChkColl(collEnt_t *collEnt)
Definition: rsChkObjPermAndStat.cpp:298
rcChkObjPermAndStat
int rcChkObjPermAndStat(rcComm_t *conn, chkObjPermAndStat_t *chkObjPermAndStatInp)
Definition: rcChkObjPermAndStat.cpp:23
CAT_UNKNOWN_FILE
@ CAT_UNKNOWN_FILE
Definition: rodsErrorTable.h:432
SYS_NO_RCAT_SERVER_ERR
@ SYS_NO_RCAT_SERVER_ERR
Definition: rodsErrorTable.h:110
irods.pypyodbc.status
status
Definition: pypyodbc.py:467
NO_SPEC_COLL
@ NO_SPEC_COLL
Definition: objInfo.h:46
irods::log
void log(const error &)
Definition: irods_log.cpp:13
RECUR_QUERY_FG
#define RECUR_QUERY_FG
Definition: miscUtil.h:92
irods::error
Definition: irods_error.hpp:23
miscServerFunct.hpp
DATA_OBJ_T
@ DATA_OBJ_T
Definition: rodsType.h:38
CHK_COLL_FOR_BUNDLE_OPR
#define CHK_COLL_FOR_BUNDLE_OPR
Definition: chkObjPermAndStat.h:7
CollEnt::dataName
char * dataName
Definition: miscUtil.h:120
getAndConnRcatHost
int getAndConnRcatHost(rsComm_t *rsComm, int rcatType, const char *rcatZoneHint, rodsServerHost_t **rodsServerHost)
Definition: rodsConnect.cpp:26
SpecColl::collection
char collection[(1024+64)]
Definition: objInfo.h:79
get_catalog_service_role
irods::error get_catalog_service_role(std::string &_role)
Definition: miscServerFunct.cpp:3153
rodsServerHost
Definition: rodsConnect.h:62
apiHeaderAll.h
rsChkObjPermAndStat
int rsChkObjPermAndStat(rsComm_t *rsComm, chkObjPermAndStat_t *chkObjPermAndStatInp)
Definition: rsChkObjPermAndStat.cpp:23
icatHighLevelRoutines.hpp
CollEnt::objType
objType_t objType
Definition: miscUtil.h:114
CollInp::collName
char collName[(1024+64)]
Definition: dataObjInpOut.h:158
SLAVE_RCAT
#define SLAVE_RCAT
Definition: rodsDef.h:86
chkObjPermAndStat_t::flags
int flags
Definition: chkObjPermAndStat.h:12
False
#define False
Definition: parseCommandLine.h:12
rstrcpy
char * rstrcpy(char *dest, const char *src, int maxLen)
Definition: stringOpr.cpp:51
irods::error::ok
bool ok()
Definition: irods_error.cpp:258
SYS_COPY_NOT_EXIST_IN_RESC
@ SYS_COPY_NOT_EXIST_IN_RESC
Definition: rodsErrorTable.h:144
CollEnt::resc_hier
char * resc_hier
Definition: miscUtil.h:126
chkObjPermAndStat_t::condInput
keyValPair_t condInput
Definition: chkObjPermAndStat.h:14
rsCloseCollection.hpp
rodsLong_t
long long rodsLong_t
Definition: rodsType.h:32
SpecColl::collClass
specCollClass_t collClass
Definition: objInfo.h:77
chkObjPermAndStat_t
Definition: chkObjPermAndStat.h:9