00001
00002
00003
00004
00005
00006 #include "genQuery.h"
00007 #include "icatHighLevelRoutines.h"
00008 #include "miscUtil.h"
00009 #include "cache.h"
00010 #include "rsGlobalExtern.h"
00011
00012 static
00013 eirods::error strip_eirods_query_terms(
00014 genQueryInp_t* _inp ) {
00015
00016
00017 inxIvalPair_t tmp;
00018 tmp.len = _inp->selectInp.len;
00019 tmp.inx = _inp->selectInp.inx;
00020 tmp.value = _inp->selectInp.value;
00021
00022
00023
00024
00025 bzero( &_inp->selectInp, sizeof( _inp->selectInp ) );
00026
00027
00028
00029 for( int i = 0; i < tmp.len; ++i ) {
00030 if( tmp.inx[ i ] == COL_R_RESC_CHILDREN ||
00031 tmp.inx[ i ] == COL_R_RESC_CONTEXT ||
00032 tmp.inx[ i ] == COL_R_RESC_PARENT ||
00033 tmp.inx[ i ] == COL_R_RESC_OBJCOUNT ||
00034 tmp.inx[ i ] == COL_D_RESC_HIER ) {
00035 continue;
00036 } else {
00037 addInxIval( &_inp->selectInp, tmp.inx[ i ], tmp.value[ i ] );
00038 }
00039
00040 }
00041
00042 return SUCCESS();
00043
00044 }
00045
00046 static
00047 eirods::error proc_query_terms_for_non_eirods_server(
00048 const std::string& _zone_hint,
00049 genQueryInp_t* _inp ) {
00050 bool done = false;
00051 zoneInfo_t* tmp_zone = ZoneInfoHead;
00052
00053
00054
00055 std::string zone_hint = _zone_hint;
00056 if( _zone_hint[0] == '/' ) {
00057 size_t pos = _zone_hint.find( "/", 1 );
00058 if( std::string::npos != pos ) {
00059 zone_hint = _zone_hint.substr( 1, pos-1 );
00060 } else {
00061 return ERROR(
00062 SYS_INVALID_INPUT_PARAM,
00063 "error finding zone hint" );
00064 }
00065 }
00066
00067
00068
00069 while( !done && tmp_zone ) {
00070 if( zone_hint == tmp_zone->zoneName &&
00071 tmp_zone->masterServerHost->conn &&
00072 tmp_zone->masterServerHost->conn->svrVersion &&
00073 tmp_zone->masterServerHost->conn->svrVersion->cookie < 301 ) {
00074 return strip_eirods_query_terms( _inp );
00075
00076 } else {
00077 tmp_zone = tmp_zone->next;
00078
00079 }
00080 }
00081
00082 return SUCCESS();
00083
00084 }
00085
00086
00087
00088 ;
00089 int
00090 rsGenQuery (rsComm_t *rsComm, genQueryInp_t *genQueryInp,
00091 genQueryOut_t **genQueryOut)
00092 {
00093 rodsServerHost_t *rodsServerHost;
00094 int status;
00095 char *zoneHint;
00096 zoneHint = getZoneHintForGenQuery (genQueryInp);
00097
00098 std::string zone_hint_str;
00099 if( zoneHint ) {
00100 zone_hint_str = zoneHint;
00101 }
00102
00103 status = getAndConnRcatHost(rsComm, SLAVE_RCAT, zoneHint,
00104 &rodsServerHost);
00105
00106 if (status < 0) {
00107 return(status);
00108 }
00109
00110
00111
00112 if( !zone_hint_str.empty() ) {
00113 eirods::error ret = proc_query_terms_for_non_eirods_server( zone_hint_str, genQueryInp );
00114 if( !ret.ok() ) {
00115 eirods::log( PASS( ret ) );
00116 }
00117 }
00118
00119 if (rodsServerHost->localFlag == LOCAL_HOST) {
00120 #ifdef RODS_CAT
00121 status = _rsGenQuery (rsComm, genQueryInp, genQueryOut);
00122 #else
00123 rodsLog(LOG_NOTICE,
00124 "rsGenQuery error. RCAT is not configured on this host");
00125 return (SYS_NO_RCAT_SERVER_ERR);
00126 #endif
00127 } else {
00128 status = rcGenQuery(rodsServerHost->conn,
00129 genQueryInp, genQueryOut);
00130 }
00131 if (status < 0 && status != CAT_NO_ROWS_FOUND) {
00132 rodsLog (LOG_NOTICE,
00133 "rsGenQuery: rcGenQuery failed, status = %d", status);
00134 }
00135 return (status);
00136 }
00137
00138 #ifdef RODS_CAT
00139 int
00140 _rsGenQuery (rsComm_t *rsComm, genQueryInp_t *genQueryInp,
00141 genQueryOut_t **genQueryOut)
00142 {
00143 int status;
00144
00145 static int ruleExecuted=0;
00146 ruleExecInfo_t rei;
00147
00148
00149 static int PrePostProcForGenQueryFlag = -2;
00150 int i, argc;
00151 ruleExecInfo_t rei2;
00152 char *args[MAX_NUM_OF_ARGS_IN_ACTION];
00153
00154 if (PrePostProcForGenQueryFlag < 0) {
00155 if (getenv("PREPOSTPROCFORGENQUERYFLAG") != NULL)
00156 PrePostProcForGenQueryFlag = 1;
00157 else
00158 PrePostProcForGenQueryFlag = 0;
00159 }
00160
00161 memset ((char*)&rei2, 0, sizeof (ruleExecInfo_t));
00162 rei2.rsComm = rsComm;
00163 if (rsComm != NULL) {
00164 rei2.uoic = &rsComm->clientUser;
00165 rei2.uoip = &rsComm->proxyUser;
00166 }
00167
00168
00169
00170 *genQueryOut = (genQueryOut_t*)malloc(sizeof(genQueryOut_t));
00171 memset((char *)*genQueryOut, 0, sizeof(genQueryOut_t));
00172
00173 if (ruleExecuted==0) {
00174 memset((char*)&rei,0,sizeof(rei));
00175 rei.rsComm = rsComm;
00176 if (rsComm != NULL) {
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188 rei.uoic = &rsComm->clientUser;
00189 rei.uoip = &rsComm->proxyUser;
00190 }
00191
00192 if (getRuleEngineStatus() == UNINITIALIZED) {
00193
00194
00195
00196
00197
00198 status = -1;
00199 }
00200 else
00201 {
00202 status = applyRule ("acAclPolicy", NULL, &rei, NO_SAVE_REI);
00203 }
00204 if (status==0) {
00205 ruleExecuted=1;
00206
00207
00208
00209
00210
00211 }
00212 }
00213
00214 chlGenQueryAccessControlSetup(rsComm->clientUser.userName,
00215 rsComm->clientUser.rodsZone,
00216 rsComm->clientUser.authInfo.authFlag,
00217 -1);
00218 if (PrePostProcForGenQueryFlag == 1) {
00219 args[0] = (char *) malloc(300);
00220 sprintf(args[0],"%ld",(long) genQueryInp);
00221 argc = 1;
00222 i = applyRuleArg("acPreProcForGenQuery",args,argc, &rei2, NO_SAVE_REI);
00223 free(args[0]);
00224 if (i < 0) {
00225 rodsLog (LOG_ERROR,
00226 "rsGenQuery:acPreProcForGenQuery error,stat=%d", i);
00227 if (i != NO_MICROSERVICE_FOUND_ERR)
00228 return i;
00229 }
00230 }
00231
00232
00233 status = chlGenQuery(*genQueryInp, *genQueryOut);
00234
00235
00236 if (PrePostProcForGenQueryFlag == 1) {
00237 args[0] = (char *) malloc(300);
00238 args[1] = (char *) malloc(300);
00239 args[2] = (char *) malloc(300);
00240 sprintf(args[0],"%ld",(long) genQueryInp);
00241 sprintf(args[1],"%ld",(long) *genQueryOut);
00242 sprintf(args[2],"%d",status);
00243 argc = 3;
00244 i = applyRuleArg("acPostProcForGenQuery",args,argc, &rei2, NO_SAVE_REI);
00245 free(args[0]);
00246 free(args[1]);
00247 free(args[2]);
00248 if (i < 0) {
00249 rodsLog (LOG_ERROR,
00250 "rsGenQuery:acPostProcForGenQuery error,stat=%d", i);
00251 if (i != NO_MICROSERVICE_FOUND_ERR)
00252 return i;
00253 }
00254 }
00255
00256
00257 if (status < 0) {
00258 clearGenQueryOut (*genQueryOut);
00259 free (*genQueryOut);
00260 *genQueryOut = NULL;
00261 if (status != CAT_NO_ROWS_FOUND) {
00262 rodsLog (LOG_NOTICE,
00263 "_rsGenQuery: genQuery status = %d", status);
00264 }
00265 return (status);
00266 }
00267 return (status);
00268 }
00269 #endif