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)  

rsRuleExecDel.cpp
Go to the documentation of this file.
1 #include "rcMisc.h"
2 #include "ruleExecSubmit.h"
3 #include "ruleExecDel.h"
4 #include "objMetaOpr.hpp"
6 #include "miscServerFunct.hpp"
8 #include "genQuery.h"
9 #include "rsRuleExecDel.hpp"
10 #include "rsGenQuery.hpp"
11 
12 int
13 getReInfoById( rsComm_t *rsComm, char *ruleExecId, genQueryOut_t **genQueryOut ) {
14  genQueryInp_t genQueryInp;
15  char tmpStr[NAME_LEN];
16  int status;
17 
18  memset( &genQueryInp, 0, sizeof( genQueryInp_t ) );
19 
20  addInxIval( &genQueryInp.selectInp, COL_RULE_EXEC_ID, 1 );
21  addInxIval( &genQueryInp.selectInp, COL_RULE_EXEC_NAME, 1 );
23  addInxIval( &genQueryInp.selectInp, COL_RULE_EXEC_USER_NAME, 1 );
24  addInxIval( &genQueryInp.selectInp, COL_RULE_EXEC_ADDRESS, 1 );
25  addInxIval( &genQueryInp.selectInp, COL_RULE_EXEC_TIME, 1 );
26  addInxIval( &genQueryInp.selectInp, COL_RULE_EXEC_FREQUENCY, 1 );
27  addInxIval( &genQueryInp.selectInp, COL_RULE_EXEC_PRIORITY, 1 );
31  addInxIval( &genQueryInp.selectInp, COL_RULE_EXEC_STATUS, 1 );
32 
33  snprintf( tmpStr, NAME_LEN, "='%s'", ruleExecId );
34  addInxVal( &genQueryInp.sqlCondInp, COL_RULE_EXEC_ID, tmpStr );
35 
36  genQueryInp.maxRows = MAX_SQL_ROWS;
37 
38  status = rsGenQuery( rsComm, &genQueryInp, genQueryOut );
39 
40  clearGenQueryInp( &genQueryInp );
41 
42  return status;
43 }
44 
45 int
46 rsRuleExecDel( rsComm_t *rsComm, ruleExecDelInp_t *ruleExecDelInp ) {
48  int status;
49 
50  if ( ruleExecDelInp == NULL ) {
52  "rsRuleExecDel error. NULL input" );
54  }
55 
57  if ( status < 0 ) {
58  return status;
59  }
60 
62  std::string svc_role;
63  irods::error ret = get_catalog_service_role(svc_role);
64  if(!ret.ok()) {
65  irods::log(PASS(ret));
66  return ret.code();
67  }
68 
69  if( irods::CFG_SERVICE_ROLE_PROVIDER == svc_role ) {
70  status = _rsRuleExecDel( rsComm, ruleExecDelInp );
71  } else if( irods::CFG_SERVICE_ROLE_CONSUMER == svc_role ) {
73  "rsRuleExecDel error. ICAT is not configured on this host" );
75  } else {
76  rodsLog(
77  LOG_ERROR,
78  "role not supported [%s]",
79  svc_role.c_str() );
81  }
82  }
83  else {
84  status = rcRuleExecDel( rodsServerHost->conn, ruleExecDelInp );
85  }
86  if ( status < 0 ) {
88  "rsRuleExecDel: rcRuleExecDel failed, status = %d",
89  status );
90  }
91  return status;
92 }
93 
94 int _rsRuleExecDel( rsComm_t *rsComm, ruleExecDelInp_t *ruleExecDelInp ) {
95  genQueryOut_t *genQueryOut = NULL;
96  int status;
97  sqlResult_t *reiFilePath;
98  sqlResult_t *ruleUserName;
99 
100  char reiDir[MAX_NAME_LEN];
101 
102  std::string svc_role;
103  irods::error ret = get_catalog_service_role(svc_role);
104  if(!ret.ok()) {
105  irods::log(PASS(ret));
106  return ret.code();
107  }
108 
109  status = getReInfoById( rsComm, ruleExecDelInp->ruleExecId,
110  &genQueryOut );
111 
112 
113  if ( status < 0 ) {
115  "_rsRuleExecDel: getReInfoById failed, status = %d",
116  status );
117  /* unregister it anyway */
118 
119 
120  if( irods::CFG_SERVICE_ROLE_PROVIDER == svc_role ) {
121  status = chlDelRuleExec( rsComm, ruleExecDelInp->ruleExecId );
122  if ( status < 0 ) {
124  "_rsRuleExecDel: chlDelRuleExec for %s error, status = %d",
125  ruleExecDelInp->ruleExecId, status );
126  }
127  return status;
128  } else if( irods::CFG_SERVICE_ROLE_CONSUMER == svc_role ) {
130  "_rsRuleExecDel: chlDelRuleExec only in ICAT host" );
131  return SYS_NO_RCAT_SERVER_ERR;
132  } else {
133  rodsLog(
134  LOG_ERROR,
135  "role not supported [%s]",
136  svc_role.c_str() );
138  }
139  }
140 
141  if ( ( reiFilePath = getSqlResultByInx( genQueryOut,
144  "_rsRuleExecDel: getSqlResultByInx for REI_FILE_PATH failed" );
145  return UNMATCHED_KEY_OR_INDEX;
146  }
147 
148  /* First check permission (now that API is allowed for non-admin users) */
150  if ( rsComm->proxyUser.authInfo.authFlag == LOCAL_USER_AUTH ) {
151  if ( ( ruleUserName = getSqlResultByInx( genQueryOut,
152  COL_RULE_EXEC_USER_NAME ) ) == NULL ) {
154  "_rsRuleExecDel: getSqlResultByInx for COL_RULE_EXEC_USER_NAME failed" );
155  return UNMATCHED_KEY_OR_INDEX;
156  }
157  if ( strncmp( ruleUserName->value,
158  rsComm->clientUser.userName, MAX_NAME_LEN ) != 0 ) {
159  return USER_ACCESS_DENIED;
160  }
161  }
162  else {
163  return USER_ACCESS_DENIED;
164  }
165  }
166 
167  /* some sanity check */
168  snprintf( reiDir, MAX_NAME_LEN,
169  "/%-s/%-s.", PACKED_REI_DIR, REI_FILE_NAME );
170 
171  if ( strstr( reiFilePath->value, reiDir ) == NULL ) {
172  if( irods::CFG_SERVICE_ROLE_PROVIDER == svc_role ) {
173  int i;
174  char errMsg[105];
175 
177  "_rsRuleExecDel: reiFilePath: %s is not a proper rei path",
178  reiFilePath->value );
179 
180  /* Try to unregister it anyway */
181  status = chlDelRuleExec( rsComm, ruleExecDelInp->ruleExecId );
182 
183  if ( status ) {
184  return ( status ); /* that failed too, report it */
185  }
186 
187  /* Add a message to the error stack for the client user */
188  snprintf( errMsg, sizeof errMsg, "Rule was removed but reiPath was invalid: %s",
189  reiFilePath->value );
190  i = addRErrorMsg( &rsComm->rError, 0, errMsg );
191  if ( i < 0 ) {
192  irods::log( ERROR( i, "addRErrorMsg failed" ) );
193  }
194  freeGenQueryOut( &genQueryOut );
195 
196  return SYS_INVALID_FILE_PATH;
197  } else if( irods::CFG_SERVICE_ROLE_CONSUMER == svc_role ) {
199  "_rsRuleExecDel: chlDelRuleExec only in ICAT host" );
200  return SYS_NO_RCAT_SERVER_ERR;
201  } else {
202  rodsLog(
203  LOG_ERROR,
204  "role not supported [%s]",
205  svc_role.c_str() );
207  }
208  }
209  status = unlink( reiFilePath->value );
210  if ( status < 0 ) {
211  status = UNIX_FILE_UNLINK_ERR - errno;
213  "_rsRuleExecDel: unlink of %s error, status = %d",
214  reiFilePath->value, status );
215  if ( errno != ENOENT ) {
216  freeGenQueryOut( &genQueryOut );
217  return status;
218  }
219  }
220  if( irods::CFG_SERVICE_ROLE_PROVIDER == svc_role ) {
221  int unlinkStatus = status;
222 
223  /* unregister it */
224  status = chlDelRuleExec( rsComm, ruleExecDelInp->ruleExecId );
225 
226  if ( status < 0 ) {
228  "_rsRuleExecDel: chlDelRuleExec for %s error, status = %d",
229  ruleExecDelInp->ruleExecId, status );
230  }
231  if ( unlinkStatus ) {
232  int i;
233  char errMsg[105];
234  /* Add a message to the error stack for the client user */
235  snprintf( errMsg, sizeof errMsg,
236  "Rule was removed but unlink of rei file failed" );
237  i = addRErrorMsg( &rsComm->rError, 0, errMsg );
238  if ( i < 0 ) {
239  irods::log( ERROR( i, "addRErrorMsg failed" ) );
240  }
241  snprintf( errMsg, sizeof errMsg,
242  "rei file: %s",
243  reiFilePath->value );
244  i = addRErrorMsg( &rsComm->rError, 1, errMsg );
245  if ( status == 0 ) {
246  status = unlinkStatus;
247  } /* return this error if
248  no other error occurred */
249 
250  }
251  freeGenQueryOut( &genQueryOut );
252 
253  return status;
254  } else if( irods::CFG_SERVICE_ROLE_CONSUMER == svc_role ) {
256  "_rsRuleExecDel: chlDelRuleExec only in ICAT host" );
257  return SYS_NO_RCAT_SERVER_ERR;
258  } else {
259  rodsLog(
260  LOG_ERROR,
261  "role not supported [%s]",
262  svc_role.c_str() );
264  }
265 }
rodsLog
void rodsLog(int level, const char *formatStr,...)
Definition: rodsLog.cpp:86
MAX_SQL_ROWS
#define MAX_SQL_ROWS
Definition: rodsGenQuery.h:16
NULL
#define NULL
Definition: rodsDef.h:70
COL_RULE_EXEC_TIME
#define COL_RULE_EXEC_TIME
Definition: rodsGenQuery.h:326
rsComm_t
Definition: rcConnect.h:145
irods::CFG_SERVICE_ROLE_CONSUMER
const std::string CFG_SERVICE_ROLE_CONSUMER("consumer")
COL_RULE_EXEC_NAME
#define COL_RULE_EXEC_NAME
Definition: rodsGenQuery.h:322
irods_configuration_keywords.hpp
SYS_INTERNAL_NULL_INPUT_ERR
@ SYS_INTERNAL_NULL_INPUT_ERR
Definition: rodsErrorTable.h:92
rodsServerHost::localFlag
int localFlag
Definition: rodsConnect.h:68
SYS_SERVICE_ROLE_NOT_SUPPORTED
@ SYS_SERVICE_ROLE_NOT_SUPPORTED
Definition: rodsErrorTable.h:217
UNMATCHED_KEY_OR_INDEX
@ UNMATCHED_KEY_OR_INDEX
Definition: rodsErrorTable.h:244
rodsServerHost::conn
rcComm_t * conn
Definition: rodsConnect.h:64
userInfo_t::userName
char userName[64]
Definition: rodsUser.h:66
PASS
#define PASS(prev_error_)
Definition: irods_error.hpp:118
GenQueryInp
Definition: rodsGenQuery.h:24
rcMisc.h
_rsRuleExecDel
int _rsRuleExecDel(rsComm_t *rsComm, ruleExecDelInp_t *ruleExecDelInp)
Definition: rsRuleExecDel.cpp:94
COL_RULE_EXEC_ESTIMATED_EXE_TIME
#define COL_RULE_EXEC_ESTIMATED_EXE_TIME
Definition: rodsGenQuery.h:329
LOCAL_HOST
#define LOCAL_HOST
Definition: rodsConnect.h:44
addInxVal
int addInxVal(inxValPair_t *inxValPair, int inx, const char *value)
Definition: rcMisc.cpp:921
LOG_ERROR
#define LOG_ERROR
Definition: rodsLog.h:43
ruleExecDel.h
GenQueryInp::selectInp
inxIvalPair_t selectInp
Definition: rodsGenQuery.h:53
GenQueryInp::maxRows
int maxRows
Definition: rodsGenQuery.h:25
rsRuleExecDel
int rsRuleExecDel(rsComm_t *rsComm, ruleExecDelInp_t *ruleExecDelInp)
Definition: rsRuleExecDel.cpp:46
rsRuleExecDel.hpp
rsComm_t::rError
rError_t rError
Definition: rcConnect.h:158
irods::error::code
long long code() const
Definition: irods_error.cpp:194
LOCAL_USER_AUTH
#define LOCAL_USER_AUTH
Definition: rodsUser.h:34
getSqlResultByInx
sqlResult_t * getSqlResultByInx(genQueryOut_t *genQueryOut, int attriInx)
Definition: rcMisc.cpp:1387
rsComm_t::proxyUser
userInfo_t proxyUser
Definition: rcConnect.h:152
COL_RULE_EXEC_ID
#define COL_RULE_EXEC_ID
Definition: rodsGenQuery.h:321
ruleExecSubmit.h
COL_RULE_EXEC_FREQUENCY
#define COL_RULE_EXEC_FREQUENCY
Definition: rodsGenQuery.h:327
irods::CFG_SERVICE_ROLE_PROVIDER
const std::string CFG_SERVICE_ROLE_PROVIDER("provider")
COL_RULE_EXEC_USER_NAME
#define COL_RULE_EXEC_USER_NAME
Definition: rodsGenQuery.h:324
GenQueryInp::sqlCondInp
inxValPair_t sqlCondInp
Definition: rodsGenQuery.h:56
genQuery.h
getAndConnReHost
int getAndConnReHost(rsComm_t *rsComm, rodsServerHost_t **rodsServerHost)
Definition: rodsConnect.cpp:1015
MAX_NAME_LEN
#define MAX_NAME_LEN
Definition: rodsDef.h:61
UNIX_FILE_UNLINK_ERR
@ UNIX_FILE_UNLINK_ERR
Definition: rodsErrorTable.h:305
addInxIval
int addInxIval(inxIvalPair_t *inxIvalPair, int inx, int value)
Definition: rcMisc.cpp:883
SYS_NO_RCAT_SERVER_ERR
@ SYS_NO_RCAT_SERVER_ERR
Definition: rodsErrorTable.h:110
GenQueryOut
Definition: rodsGenQuery.h:67
addRErrorMsg
int addRErrorMsg(rError_t *myError, int status, const char *msg)
Definition: rcMisc.cpp:121
COL_RULE_EXEC_STATUS
#define COL_RULE_EXEC_STATUS
Definition: rodsGenQuery.h:332
PACKED_REI_DIR
#define PACKED_REI_DIR
Definition: ruleExecSubmit.h:20
LOCAL_PRIV_USER_AUTH
#define LOCAL_PRIV_USER_AUTH
Definition: rodsUser.h:36
irods.pypyodbc.status
status
Definition: pypyodbc.py:467
chlDelRuleExec
int chlDelRuleExec(rsComm_t *rsComm, const char *ruleExecId)
Definition: icatHighLevelRoutines.cpp:769
irods::log
void log(const error &)
Definition: irods_log.cpp:13
LOG_NOTICE
#define LOG_NOTICE
Definition: rodsLog.h:33
rsComm_t::clientUser
userInfo_t clientUser
Definition: rcConnect.h:153
COL_RULE_EXEC_PRIORITY
#define COL_RULE_EXEC_PRIORITY
Definition: rodsGenQuery.h:328
ERROR
#define ERROR(code_, message_)
Definition: irods_error.hpp:117
COL_RULE_EXEC_REI_FILE_PATH
#define COL_RULE_EXEC_REI_FILE_PATH
Definition: rodsGenQuery.h:323
irods::error
Definition: irods_error.hpp:23
USER_ACCESS_DENIED
@ USER_ACCESS_DENIED
Definition: rodsErrorTable.h:271
miscServerFunct.hpp
rcRuleExecDel
int rcRuleExecDel(rcComm_t *conn, ruleExecDelInp_t *ruleExecDelInp)
Definition: rcRuleExecDel.cpp:35
SYS_INVALID_FILE_PATH
@ SYS_INVALID_FILE_PATH
Definition: rodsErrorTable.h:99
SqlResult::value
char * value
Definition: rodsGenQuery.h:64
COL_RULE_EXEC_LAST_EXE_TIME
#define COL_RULE_EXEC_LAST_EXE_TIME
Definition: rodsGenQuery.h:331
get_catalog_service_role
irods::error get_catalog_service_role(std::string &_role)
Definition: miscServerFunct.cpp:3153
rodsServerHost
Definition: rodsConnect.h:62
REI_FILE_NAME
#define REI_FILE_NAME
Definition: ruleExecSubmit.h:18
SqlResult
Definition: rodsGenQuery.h:61
COL_RULE_EXEC_ADDRESS
#define COL_RULE_EXEC_ADDRESS
Definition: rodsGenQuery.h:325
icatHighLevelRoutines.hpp
rsGenQuery.hpp
userInfo_t::authInfo
authInfo_t authInfo
Definition: rodsUser.h:70
freeGenQueryOut
int freeGenQueryOut(genQueryOut_t **genQueryOut)
Definition: rcMisc.cpp:1133
NAME_LEN
#define NAME_LEN
Definition: rodsDef.h:55
authInfo_t::authFlag
int authFlag
Definition: rodsUser.h:42
irods::error::ok
bool ok()
Definition: irods_error.cpp:258
ruleExecDelInp_t
Definition: ruleExecDel.h:7
ruleExecDelInp_t::ruleExecId
char ruleExecId[64]
Definition: ruleExecDel.h:8
COL_RULE_EXEC_NOTIFICATION_ADDR
#define COL_RULE_EXEC_NOTIFICATION_ADDR
Definition: rodsGenQuery.h:330
clearGenQueryInp
void clearGenQueryInp(void *voidInp)
Definition: rcMisc.cpp:1118
getReInfoById
int getReInfoById(rsComm_t *rsComm, char *ruleExecId, genQueryOut_t **genQueryOut)
Definition: rsRuleExecDel.cpp:13
rsGenQuery
int rsGenQuery(rsComm_t *rsComm, genQueryInp_t *genQueryInp, genQueryOut_t **genQueryOut)
Definition: rsGenQuery.cpp:604
objMetaOpr.hpp