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
00022 zoneHint = getZoneHintForGenQuery (genQueryInp);
00023
00024 status = getAndConnRcatHost(rsComm, SLAVE_RCAT, zoneHint,
00025 &rodsServerHost);
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 static int ruleResult=0;
00059
00060
00061 static int PrePostProcForGenQueryFlag = -2;
00062 int i, argc;
00063 ruleExecInfo_t rei2;
00064 char *args[MAX_NUM_OF_ARGS_IN_ACTION];
00065
00066 if (PrePostProcForGenQueryFlag < 0) {
00067 if (getenv("PREPOSTPROCFORGENQUERYFLAG") != NULL)
00068 PrePostProcForGenQueryFlag = 1;
00069 else
00070 PrePostProcForGenQueryFlag = 0;
00071 }
00072
00073 memset ((char*)&rei2, 0, sizeof (ruleExecInfo_t));
00074 rei2.rsComm = rsComm;
00075 if (rsComm != NULL) {
00076 rei2.uoic = &rsComm->clientUser;
00077 rei2.uoip = &rsComm->proxyUser;
00078 }
00079
00080
00081
00082 *genQueryOut = (genQueryOut_t*)malloc(sizeof(genQueryOut_t));
00083 memset((char *)*genQueryOut, 0, sizeof(genQueryOut_t));
00084
00085 if (ruleExecuted==0) {
00086 #if 0
00087 msParam_t *outMsParam;
00088 #endif
00089 memset((char*)&rei,0,sizeof(rei));
00090 rei.rsComm = rsComm;
00091 if (rsComm != NULL) {
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103 rei.uoic = &rsComm->clientUser;
00104 rei.uoip = &rsComm->proxyUser;
00105 }
00106 #ifdef RULE_ENGINE_N
00107 if (getRuleEngineStatus() == UNINITIALIZED) {
00108
00109
00110
00111
00112
00113 status = -1;
00114 }
00115 else
00116 #endif
00117 {
00118 status = applyRule ("acAclPolicy", NULL, &rei, NO_SAVE_REI);
00119 ruleResult = rei.status;
00120 }
00121 if (status==0) {
00122 ruleExecuted=1;
00123
00124
00125
00126
00127
00128 #if 0
00129
00130
00131
00132 outMsParam = getMsParamByLabel(&rei.inOutMsParamArray, "STRICT");
00133 printf("outMsParam=%x\n",(int)outMsParam);
00134 if (outMsParam != NULL) {
00135 ruleResult=1;
00136 }
00137 #endif
00138 }
00139 #if 0
00140 printf("rsGenQuery rule status=%d ruleResult=%d\n",status,ruleResult);
00141 #endif
00142 }
00143
00144 chlGenQueryAccessControlSetup(rsComm->clientUser.userName,
00145 rsComm->clientUser.rodsZone,
00146 rsComm->clientUser.authInfo.authFlag,
00147 -1);
00148 #if 0
00149 rodsLog (LOG_NOTICE,
00150 "_rsGenQuery debug: client %s %d proxy %s %d",
00151 rsComm->clientUser.userName,
00152 rsComm->clientUser.authInfo.authFlag,
00153 rsComm->proxyUser.userName,
00154 rsComm->proxyUser.authInfo.authFlag);
00155 #endif
00156
00157 if (PrePostProcForGenQueryFlag == 1) {
00158 args[0] = (char *) malloc(300);
00159 sprintf(args[0],"%ld",(long) genQueryInp);
00160 argc = 1;
00161 i = applyRuleArg("acPreProcForGenQuery",args,argc, &rei2, NO_SAVE_REI);
00162 free(args[0]);
00163 if (i < 0) {
00164 rodsLog (LOG_ERROR,
00165 "rsGenQuery:acPreProcForGenQuery error,stat=%d", i);
00166 if (i != NO_MICROSERVICE_FOUND_ERR)
00167 return i;
00168 }
00169 }
00170
00171
00172 status = chlGenQuery(*genQueryInp, *genQueryOut);
00173
00174
00175 if (PrePostProcForGenQueryFlag == 1) {
00176 args[0] = (char *) malloc(300);
00177 args[1] = (char *) malloc(300);
00178 args[2] = (char *) malloc(300);
00179 sprintf(args[0],"%ld",(long) genQueryInp);
00180 sprintf(args[1],"%ld",(long) *genQueryOut);
00181 sprintf(args[2],"%d",status);
00182 argc = 3;
00183 i = applyRuleArg("acPostProcForGenQuery",args,argc, &rei2, NO_SAVE_REI);
00184 free(args[0]);
00185 free(args[1]);
00186 free(args[2]);
00187 if (i < 0) {
00188 rodsLog (LOG_ERROR,
00189 "rsGenQuery:acPostProcForGenQuery error,stat=%d", i);
00190 if (i != NO_MICROSERVICE_FOUND_ERR)
00191 return i;
00192 }
00193 }
00194
00195
00196 if (status < 0) {
00197 clearGenQueryOut (*genQueryOut);
00198 free (*genQueryOut);
00199 *genQueryOut = NULL;
00200 if (status != CAT_NO_ROWS_FOUND) {
00201 rodsLog (LOG_NOTICE,
00202 "_rsGenQuery: genQuery status = %d", status);
00203 }
00204 return (status);
00205 }
00206 return (status);
00207 }
00208 #endif