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 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
00107 if (getRuleEngineStatus() == UNINITIALIZED) {
00108
00109
00110
00111
00112
00113 status = -1;
00114 }
00115 else
00116 {
00117 status = applyRule ("acAclPolicy", NULL, &rei, NO_SAVE_REI);
00118 ruleResult = rei.status;
00119 }
00120 if (status==0) {
00121 ruleExecuted=1;
00122
00123
00124
00125
00126
00127 #if 0
00128
00129
00130
00131 outMsParam = getMsParamByLabel(&rei.inOutMsParamArray, "STRICT");
00132 printf("outMsParam=%x\n",(int)outMsParam);
00133 if (outMsParam != NULL) {
00134 ruleResult=1;
00135 }
00136 #endif
00137 }
00138 #if 0
00139 printf("rsGenQuery rule status=%d ruleResult=%d\n",status,ruleResult);
00140 #endif
00141 }
00142
00143 chlGenQueryAccessControlSetup(rsComm->clientUser.userName,
00144 rsComm->clientUser.rodsZone,
00145 rsComm->clientUser.authInfo.authFlag,
00146 -1);
00147 #if 0
00148 rodsLog (LOG_NOTICE,
00149 "_rsGenQuery debug: client %s %d proxy %s %d",
00150 rsComm->clientUser.userName,
00151 rsComm->clientUser.authInfo.authFlag,
00152 rsComm->proxyUser.userName,
00153 rsComm->proxyUser.authInfo.authFlag);
00154 #endif
00155
00156 if (PrePostProcForGenQueryFlag == 1) {
00157 args[0] = (char *) malloc(300);
00158 sprintf(args[0],"%ld",(long) genQueryInp);
00159 argc = 1;
00160 i = applyRuleArg("acPreProcForGenQuery",args,argc, &rei2, NO_SAVE_REI);
00161 free(args[0]);
00162 if (i < 0) {
00163 rodsLog (LOG_ERROR,
00164 "rsGenQuery:acPreProcForGenQuery error,stat=%d", i);
00165 if (i != NO_MICROSERVICE_FOUND_ERR)
00166 return i;
00167 }
00168 }
00169
00170
00171 status = chlGenQuery(*genQueryInp, *genQueryOut);
00172
00173
00174 if (PrePostProcForGenQueryFlag == 1) {
00175 args[0] = (char *) malloc(300);
00176 args[1] = (char *) malloc(300);
00177 args[2] = (char *) malloc(300);
00178 sprintf(args[0],"%ld",(long) genQueryInp);
00179 sprintf(args[1],"%ld",(long) *genQueryOut);
00180 sprintf(args[2],"%d",status);
00181 argc = 3;
00182 i = applyRuleArg("acPostProcForGenQuery",args,argc, &rei2, NO_SAVE_REI);
00183 free(args[0]);
00184 free(args[1]);
00185 free(args[2]);
00186 if (i < 0) {
00187 rodsLog (LOG_ERROR,
00188 "rsGenQuery:acPostProcForGenQuery error,stat=%d", i);
00189 if (i != NO_MICROSERVICE_FOUND_ERR)
00190 return i;
00191 }
00192 }
00193
00194
00195 if (status < 0) {
00196 clearGenQueryOut (*genQueryOut);
00197 free (*genQueryOut);
00198 *genQueryOut = NULL;
00199 if (status != CAT_NO_ROWS_FOUND) {
00200 rodsLog (LOG_NOTICE,
00201 "_rsGenQuery: genQuery status = %d", status);
00202 }
00203 return (status);
00204 }
00205 return (status);
00206 }
00207 #endif