00001
00002
00003
00004
00005
00006 #include "authRequest.h"
00007 #include "authCheck.h"
00008 #include "icatHighLevelRoutines.h"
00009 #include "miscServerFunct.h"
00010
00011 int
00012 rsAuthCheck (rsComm_t *rsComm, authCheckInp_t *authCheckInp,
00013 authCheckOut_t **authCheckOut)
00014 {
00015 #ifdef RODS_CAT
00016 int status;
00017 int privLevel;
00018 int clientPrivLevel;
00019 authCheckOut_t *result;
00020 unsigned char *digest;
00021 char md5Buf[CHALLENGE_LEN+MAX_PASSWORD_LEN+2];
00022 MD5_CTX context;
00023 char ServerID[MAX_PASSWORD_LEN+2];
00024
00025 *authCheckOut = (authCheckOut_t*)malloc(sizeof(authCheckOut_t));
00026 memset((char *)*authCheckOut, 0, sizeof(authCheckOut_t));
00027
00028 rodsLog(LOG_NOTICE, "rsAuthCheck user %s", authCheckInp->username);
00029 status = chlCheckAuth(rsComm, authCheckInp->challenge,
00030 authCheckInp->response,
00031 authCheckInp->username,
00032 &privLevel, &clientPrivLevel);
00033 if (status < 0) {
00034 rodsLog (LOG_NOTICE,
00035 "rsAuthCheck: chlCheckAuth status = %d", status);
00036 }
00037
00038 if (status == 0) {
00039 int len, i;
00040 result = *authCheckOut;
00041 result->privLevel = privLevel;
00042 result->clientPrivLevel = clientPrivLevel;
00043
00044
00045 memset(md5Buf, 0, sizeof(md5Buf));
00046 strncpy(md5Buf, authCheckInp->challenge, CHALLENGE_LEN);
00047
00048 getZoneServerId("", ServerID);
00049 len = strlen(ServerID);
00050 digest = ( unsigned char* )malloc(RESPONSE_LEN+2);
00051 if (len <=0) {
00052 rodsLog (LOG_DEBUG,
00053 "rsAuthCheck: Warning, cannot authenticate this server to remote server, no LocalZoneSID defined in server.config", status);
00054 memset(digest, 0, RESPONSE_LEN);
00055 }
00056 else {
00057 strncpy(md5Buf+CHALLENGE_LEN, ServerID, len);
00058
00059 MD5Init (&context);
00060 MD5Update (&context, (unsigned char*)md5Buf,
00061 CHALLENGE_LEN+MAX_PASSWORD_LEN);
00062 MD5Final (digest, &context);
00063 for (i=0;i<RESPONSE_LEN;i++) {
00064 if (digest[i]=='\0') digest[i]++;
00065
00066 }
00067 }
00068 result->serverResponse = (char*)digest;
00069 }
00070
00071 return (status);
00072 #else
00073
00074 rodsServerHost_t *rodsServerHost;
00075 int status;
00076
00077 status = getAndConnRcatHostNoLogin (rsComm, SLAVE_RCAT,
00078 rsComm->proxyUser.rodsZone, &rodsServerHost);
00079
00080 if (status < 0) {
00081 rodsLog (LOG_NOTICE,
00082 "rsAuthCheck:getAndConnRcatHostNoLogin() failed. erro=%d", status);
00083 return (status);
00084 }
00085
00086 if (rodsServerHost->localFlag == LOCAL_HOST) {
00087 return ( SYS_NO_ICAT_SERVER_ERR);
00088 } else {
00089 status = rcAuthCheck (rodsServerHost->conn, authCheckInp, authCheckOut);
00090 }
00091 return status;
00092 #endif
00093 }
00094