Made astriumnet and poldifold work

Astriumnet had problems:
- The hash code stuff is number size dependent
- wrPos was not properly reset, thus leading to no new request being
  written.
Poldifold was tested and taken into operation
This commit is contained in:
2014-04-22 15:45:40 +02:00
parent ea78720a8c
commit fb2164ca2d
2 changed files with 24 additions and 15 deletions

View File

@ -4,7 +4,7 @@
* peculaties here:
*
* On connecting there is an authorisation exchange. This, the client, has to send a
* challenge. The server responds with a randam hash code. Then a password is encrypted
* challenge. The server responds with a random hash code. Then a password is encrypted
* with the hashcode and sent to the server. Who, hopefully, will respond with an AuthOK
* message.
*
@ -130,16 +130,21 @@ static int decodeXML(Ascon *a)
return 1;
}
/*-----------------------------------------------------------------------*/
static long calculateToken(char *password, long hash)
/*-----------------------------------------------------------------------
This code and the function below is sensitive to int sizes. The hash must
be a 64bit int. This is long on OSX and long long on SL6 32 bit. Setting
this to int64_t as defined in stdint.h does not solve the problem because
of the conversions to and from strings involved.
------------------------------------------------------------------------- */
static long long calculateToken(char *password, long long hash)
{
long tmp;
long long tmp;
int i;
tmp = hash ^ 0x80AA80AA;
for(i = 0; i < strlen(password); i++){
tmp += password[i] * (long)pow(2,i);
tmp -= password[i] * (long)pow(2,31-i);
tmp += password[i] * (long long)pow(2,i);
tmp -= password[i] * (long long)pow(2,31-i);
}
return tmp ^ hash;
}
@ -149,8 +154,8 @@ static int doWaitHash(Ascon *a)
pAstriumnet priv = NULL;
int ret;
char chr;
long hash;
char token[50];
long long hash;
char token[50], *pPtr, *endptr;
priv = (pAstriumnet)a->private;
ret = AsconReadChar(a->fd,&chr);
@ -158,7 +163,7 @@ static int doWaitHash(Ascon *a)
AsconError(a, "ASC5", errno);
return 0;
}
if(ret == 1) {
if(ret == 1 && (int)chr != 0x16) {
DynStringConcatChar(a->rdBuffer,chr);
}
if(GetDynStringLength(a->rdBuffer) >= 23) {
@ -166,10 +171,12 @@ static int doWaitHash(Ascon *a)
AsconError(a,"Invalid response when trying to get hash",0);
return 0;
}
hash = atol(GetCharArray(a->rdBuffer)+6);
pPtr = GetCharArray(a->rdBuffer);
pPtr += 6;
hash = strtoll(pPtr, &endptr,0);
hash = calculateToken(priv->password,hash);
DynStringCopy(priv->buffer,"<AuthToken>");
snprintf(token,sizeof(token),"%ld",hash);
snprintf(token,sizeof(token),"%lld",hash);
DynStringConcat(priv->buffer,token);
ret = AsconWriteChars(a->fd, GetCharArray(priv->buffer),
GetDynStringLength(priv->buffer));
@ -195,7 +202,7 @@ static int doWaitOK(Ascon *a)
AsconError(a, "ASC5", errno);
return 0;
}
if(ret == 1) {
if(ret == 1 && (int)chr != 0x16) {
DynStringConcatChar(a->rdBuffer,chr);
}
if(strchr(GetCharArray(a->rdBuffer),(int)'>') != NULL) {
@ -255,6 +262,7 @@ static int AstriumnetHandler(Ascon *a)
case AsconWriteStart:
encodeXML(a);
a->state = AsconWriting;
a->wrPos = 0;
return 1;
break;
case AsconReading:
@ -263,7 +271,7 @@ static int AstriumnetHandler(Ascon *a)
AsconError(a, "ASC5", errno);
return 0;
}
if(ret == 1) {
if(ret == 1 && (int)chr != 0x16) {
DynStringConcatChar(a->rdBuffer,chr);
}
if(strstr(GetCharArray(a->rdBuffer),"</Msg>") != NULL) {

View File

@ -36,7 +36,6 @@ static int PoldiFold (pSConnection pCon, pSicsInterp pInter, void
argv[1], argv[2]);
return 0;
}
pPtr = argv[3];
for(i = 0; i < 4; i++){
pPtr = stptok(pPtr,num,sizeof(num),",");
@ -44,6 +43,7 @@ static int PoldiFold (pSConnection pCon, pSicsInterp pInter, void
SCWrite(pCon,"ERROR: not enough values in the offset list",eError);
return 0;
}
offset[i] = atoi(num);
}
pPtr = stptok(pPtr,num,sizeof(num),",");
if(pPtr == NULL){
@ -52,7 +52,7 @@ static int PoldiFold (pSConnection pCon, pSicsInterp pInter, void
}
nTof = atoi(num);
dim = FindHdbNode(NULL,"../dim",pCon);
dim = GetHipadabaNode(source->mama,"dim");
if(dim == NULL){
SCPrintf(pCon,eError,"ERROR: failed to find dimensions beneath %s, no HM?",
argv[1]);
@ -86,6 +86,7 @@ static int PoldiFold (pSConnection pCon, pSicsInterp pInter, void
}
}
}
NotifyHipadabaPar(target,pCon);
SCSendOK(pCon);
return 1;
}