00001
00002
00003
00004
00005
00006 #include "genQuery.h"
00007 #include "icatHighLevelRoutines.h"
00008 #include "miscUtil.h"
00009 #include "cache.h"
00010
00011
00012
00013
00014 int
00015 rsGenQuery (rsComm_t *rsComm, genQueryInp_t *genQueryInp,
00016 genQueryOut_t **genQueryOut)
00017 {
00018 rodsServerHost_t *rodsServerHost;
00019 int status;
00020 char *zoneHint;
00021 zoneHint = getZoneHintForGenQuery (genQueryInp);
00022
00023 status = getAndConnRcatHost(rsComm, SLAVE_RCAT, zoneHint,
00024 &rodsServerHost);
00025
00026 if (status < 0) {
00027 return(status);
00028 }
00029
00030 if (rodsServerHost->localFlag == LOCAL_HOST) {
00031 #ifdef RODS_CAT
00032 status = _rsGenQuery (rsComm, genQueryInp, genQueryOut);
00033 #else
00034 rodsLog(LOG_NOTICE,
00035 "rsGenQuery error. RCAT is not configured on this host");
00036 return (SYS_NO_RCAT_SERVER_ERR);
00037 #endif
00038 } else {
00039 status = rcGenQuery(rodsServerHost->conn,
00040 genQueryInp, genQueryOut);
00041 }
00042 if (status < 0 && status != CAT_NO_ROWS_FOUND) {
00043 rodsLog (LOG_NOTICE,
00044 "rsGenQuery: rcGenQuery failed, status = %d", status);
00045 }
00046 return (status);
00047 }
00048
00049 #ifdef RODS_CAT
00050 int
00051 _rsGenQuery (rsComm_t *rsComm, genQueryInp_t *genQueryInp,
00052 genQueryOut_t **genQueryOut)
00053 {
00054 int status;
00055
00056 static int ruleExecuted=0;
00057 ruleExecInfo_t rei;
00058
00059
00060 static int PrePostProcForGenQueryFlag = -2;
00061 int i, argc;
00062 ruleExecInfo_t rei2;
00063 char *args[MAX_NUM_OF_ARGS_IN_ACTION];
00064
00065 if (PrePostProcForGenQueryFlag < 0) {
00066 if (getenv("PREPOSTPROCFORGENQUERYFLAG") != NULL)
00067 PrePostProcForGenQueryFlag = 1;
00068 else
00069 PrePostProcForGenQueryFlag = 0;
00070 }
00071
00072 memset ((char*)&rei2, 0, sizeof (ruleExecInfo_t));
00073 rei2.rsComm = rsComm;
00074 if (rsComm != NULL) {
00075 rei2.uoic = &rsComm->clientUser;
00076 rei2.uoip = &rsComm->proxyUser;
00077 }
00078
00079
00080
00081 *genQueryOut = (genQueryOut_t*)malloc(sizeof(genQueryOut_t));
00082 memset((char *)*genQueryOut, 0, sizeof(genQueryOut_t));
00083
00084 if (ruleExecuted==0) {
00085 memset((char*)&rei,0,sizeof(rei));
00086 rei.rsComm = rsComm;
00087 if (rsComm != NULL) {
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099 rei.uoic = &rsComm->clientUser;
00100 rei.uoip = &rsComm->proxyUser;
00101 }
00102
00103 if (getRuleEngineStatus() == UNINITIALIZED) {
00104
00105
00106
00107
00108
00109 status = -1;
00110 }
00111 else
00112 {
00113 status = applyRule ("acAclPolicy", NULL, &rei, NO_SAVE_REI);
00114 }
00115 if (status==0) {
00116 ruleExecuted=1;
00117
00118
00119
00120
00121
00122 }
00123 }
00124
00125 chlGenQueryAccessControlSetup(rsComm->clientUser.userName,
00126 rsComm->clientUser.rodsZone,
00127 rsComm->clientUser.authInfo.authFlag,
00128 -1);
00129 if (PrePostProcForGenQueryFlag == 1) {
00130 args[0] = (char *) malloc(300);
00131 sprintf(args[0],"%ld",(long) genQueryInp);
00132 argc = 1;
00133 i = applyRuleArg("acPreProcForGenQuery",args,argc, &rei2, NO_SAVE_REI);
00134 free(args[0]);
00135 if (i < 0) {
00136 rodsLog (LOG_ERROR,
00137 "rsGenQuery:acPreProcForGenQuery error,stat=%d", i);
00138 if (i != NO_MICROSERVICE_FOUND_ERR)
00139 return i;
00140 }
00141 }
00142
00143
00144 status = chlGenQuery(*genQueryInp, *genQueryOut);
00145
00146
00147 if (PrePostProcForGenQueryFlag == 1) {
00148 args[0] = (char *) malloc(300);
00149 args[1] = (char *) malloc(300);
00150 args[2] = (char *) malloc(300);
00151 sprintf(args[0],"%ld",(long) genQueryInp);
00152 sprintf(args[1],"%ld",(long) *genQueryOut);
00153 sprintf(args[2],"%d",status);
00154 argc = 3;
00155 i = applyRuleArg("acPostProcForGenQuery",args,argc, &rei2, NO_SAVE_REI);
00156 free(args[0]);
00157 free(args[1]);
00158 free(args[2]);
00159 if (i < 0) {
00160 rodsLog (LOG_ERROR,
00161 "rsGenQuery:acPostProcForGenQuery error,stat=%d", i);
00162 if (i != NO_MICROSERVICE_FOUND_ERR)
00163 return i;
00164 }
00165 }
00166
00167
00168 if (status < 0) {
00169 clearGenQueryOut (*genQueryOut);
00170 free (*genQueryOut);
00171 *genQueryOut = NULL;
00172 if (status != CAT_NO_ROWS_FOUND) {
00173 rodsLog (LOG_NOTICE,
00174 "_rsGenQuery: genQuery status = %d", status);
00175 }
00176 return (status);
00177 }
00178 return (status);
00179 }
00180 #endif