00001 #include "ruleExecSubmit.h"
00002 #include "ruleExecDel.h"
00003 #include "reServerLib.h"
00004 #include "objMetaOpr.h"
00005 #include "icatHighLevelRoutines.h"
00006
00007 int
00008 rsRuleExecDel (rsComm_t *rsComm, ruleExecDelInp_t *ruleExecDelInp)
00009 {
00010 rodsServerHost_t *rodsServerHost;
00011 int status;
00012
00013 if (ruleExecDelInp == NULL) {
00014 rodsLog(LOG_NOTICE,
00015 "rsRuleExecDel error. NULL input");
00016 return (SYS_INTERNAL_NULL_INPUT_ERR);
00017 }
00018
00019 status = getAndConnReHost (rsComm, &rodsServerHost);
00020 if (status < 0) {
00021 return(status);
00022 }
00023
00024 if (rodsServerHost->localFlag == LOCAL_HOST) {
00025 #ifdef RODS_CAT
00026 status = _rsRuleExecDel (rsComm, ruleExecDelInp);
00027 #else
00028 rodsLog(LOG_NOTICE,
00029 "rsRuleExecDel error. ICAT is not configured on this host");
00030 return (SYS_NO_RCAT_SERVER_ERR);
00031 #endif
00032 } else {
00033 status = rcRuleExecDel (rodsServerHost->conn, ruleExecDelInp);
00034 #if 0
00035 if (status < 0)
00036 replErrorStack (rodsServerHost->conn->rError, &rsComm->rError);
00037 #endif
00038 }
00039 if (status < 0) {
00040 rodsLog (LOG_ERROR,
00041 "rsRuleExecDel: rcRuleExecDel failed, status = %d",
00042 status);
00043 }
00044 return (status);
00045 }
00046
00047 int
00048 _rsRuleExecDel (rsComm_t *rsComm, ruleExecDelInp_t *ruleExecDelInp)
00049 {
00050 genQueryOut_t *genQueryOut = NULL;
00051 int status, unlinkStatus, unlinkErrno;
00052 sqlResult_t *reiFilePath;
00053 sqlResult_t *ruleUserName;
00054
00055 char reiDir[MAX_NAME_LEN];
00056
00057 status = getReInfoById (rsComm, ruleExecDelInp->ruleExecId,
00058 &genQueryOut);
00059
00060
00061 if (status < 0) {
00062 rodsLog (LOG_ERROR,
00063 "_rsRuleExecDel: getReInfoById failed, status = %d",
00064 status);
00065
00066 #ifdef RODS_CAT
00067 status = chlDelRuleExec(rsComm, ruleExecDelInp->ruleExecId);
00068 if (status < 0) {
00069 rodsLog (LOG_ERROR,
00070 "_rsRuleExecDel: chlDelRuleExec for %s error, status = %d",
00071 ruleExecDelInp->ruleExecId, status);
00072 }
00073 return status;
00074 #else
00075 rodsLog(LOG_ERROR,
00076 "_rsRuleExecDel: chlDelRuleExec only in ICAT host");
00077 return (SYS_NO_RCAT_SERVER_ERR);
00078 #endif
00079 }
00080
00081 if ((reiFilePath = getSqlResultByInx (genQueryOut,
00082 COL_RULE_EXEC_REI_FILE_PATH)) == NULL) {
00083 rodsLog (LOG_NOTICE,
00084 "_rsRuleExecDel: getSqlResultByInx for REI_FILE_PATH failed");
00085 return (UNMATCHED_KEY_OR_INDEX);
00086 }
00087
00088
00089 if (rsComm->proxyUser.authInfo.authFlag < LOCAL_PRIV_USER_AUTH) {
00090 if (rsComm->proxyUser.authInfo.authFlag == LOCAL_USER_AUTH) {
00091 if ((ruleUserName = getSqlResultByInx (genQueryOut,
00092 COL_RULE_EXEC_USER_NAME)) == NULL) {
00093 rodsLog (LOG_NOTICE,
00094 "_rsRuleExecDel: getSqlResultByInx for COL_RULE_EXEC_USER_NAME failed");
00095 return (UNMATCHED_KEY_OR_INDEX);
00096 }
00097 if (strncmp(ruleUserName->value,
00098 rsComm->clientUser.userName, MAX_NAME_LEN) != 0) {
00099 return(USER_ACCESS_DENIED);
00100 }
00101 }
00102 else {
00103 return (USER_ACCESS_DENIED);
00104 }
00105 }
00106
00107
00108 snprintf (reiDir, MAX_NAME_LEN,
00109 "/%-s/%-s.", PACKED_REI_DIR, REI_FILE_NAME);
00110
00111 if (strstr (reiFilePath->value, reiDir) == NULL) {
00112 #ifdef RODS_CAT
00113 int i;
00114 char errMsg[105];
00115
00116 rodsLog (LOG_NOTICE,
00117 "_rsRuleExecDel: reiFilePath: %s is not a proper rei path",
00118 reiFilePath->value);
00119
00120
00121 status = chlDelRuleExec(rsComm, ruleExecDelInp->ruleExecId);
00122
00123 if (status) return(status);
00124
00125
00126 snprintf(errMsg, sizeof errMsg, "Rule was removed but reiPath was invalid: %s",
00127 reiFilePath->value);
00128 i = addRErrorMsg (&rsComm->rError, 0, errMsg);
00129
00130 freeGenQueryOut (&genQueryOut);
00131
00132 return (SYS_INVALID_FILE_PATH);
00133 #else
00134 rodsLog(LOG_ERROR,
00135 "_rsRuleExecDel: chlDelRuleExec only in ICAT host");
00136 return (SYS_NO_RCAT_SERVER_ERR);
00137 #endif
00138 }
00139
00140 status = unlink (reiFilePath->value);
00141 if (status < 0) {
00142 unlinkErrno = errno;
00143 status = UNIX_FILE_UNLINK_ERR - errno;
00144 rodsLog (LOG_ERROR,
00145 "_rsRuleExecDel: unlink of %s error, status = %d",
00146 reiFilePath->value, status);
00147 if (errno != ENOENT) {
00148 freeGenQueryOut (&genQueryOut);
00149 return (status);
00150 }
00151 } else {
00152 unlinkErrno = 0;
00153 }
00154 unlinkStatus = status;
00155
00156
00157 #ifdef RODS_CAT
00158 status = chlDelRuleExec(rsComm, ruleExecDelInp->ruleExecId);
00159
00160 if (status < 0) {
00161 rodsLog (LOG_ERROR,
00162 "_rsRuleExecDel: chlDelRuleExec for %s error, status = %d",
00163 ruleExecDelInp->ruleExecId, status);
00164 }
00165 if (unlinkStatus) {
00166 int i;
00167 char errMsg[105];
00168
00169 snprintf(errMsg, sizeof errMsg,
00170 "Rule was removed but unlink of rei file failed");
00171 i = addRErrorMsg (&rsComm->rError, 0, errMsg);
00172 snprintf(errMsg, sizeof errMsg,
00173 "rei file: %s",
00174 reiFilePath->value);
00175 i = addRErrorMsg (&rsComm->rError, 1, errMsg);
00176 if (status==0) status = unlinkStatus;
00177
00178
00179 }
00180 freeGenQueryOut (&genQueryOut);
00181
00182 return (status);
00183 #else
00184 rodsLog(LOG_ERROR,
00185 "_rsRuleExecDel: chlDelRuleExec only in ICAT host");
00186 return (SYS_NO_RCAT_SERVER_ERR);
00187 #endif
00188
00189 }
00190