Exemplo n.º 1
0
int HashFinish(HASH *Hash, int Encoding, char **Return)
{
char *Token=NULL, *Bytes=NULL, *Hashed=NULL, *ptr;
int len;

ptr=GetToken(Hash->Type, "\\S", &Token, 0);
len=Hash->Finish(Hash, &Bytes);

while (StrValid(ptr)) 
{
	ptr=GetToken(ptr, "\\S", &Token, 0);
	len=HashBytes(&Hashed, Token, Bytes, len, 0);
	Bytes=SetStrLen(Bytes, len);
	memcpy(Bytes,Hashed,len);
}

if (Encoding > 0)
{
*Return=EncodeBytes(*Return, Bytes, len, Encoding);
len=StrLen(*Return);
}
else 
{
	*Return=SetStrLen(*Return, len);
	memcpy(*Return, Bytes, len);
}

DestroyString(Hashed);
DestroyString(Token);
DestroyString(Bytes);

return(len);
}
Exemplo n.º 2
0
int PBK2DF2(char **Return, char *Type, char *Bytes, int Len, char *Salt, int SaltLen, uint32_t Rounds, int Encoding)
{
char *Tempstr=NULL, *Hash=NULL;
uint32_t RoundsBE;
int i, len, hlen;

//Network byte order is big endian
RoundsBE=htonl(Rounds);

Tempstr=SetStrLen(Tempstr, Len + SaltLen + 20);
memcpy(Tempstr, Bytes, Len);
memcpy(Tempstr+Len, Salt, SaltLen);
memcpy(Tempstr+Len+SaltLen, &RoundsBE, sizeof(uint32_t));
len=Len+SaltLen+sizeof(uint32_t);
	
for (i=0; i <Rounds; i++)
{
	hlen=HashBytes(&Hash, Type, Tempstr, len, 0);
	Tempstr=SetStrLen(Tempstr, Len + hlen + 20);
	memcpy(Tempstr, Bytes, Len);
	memcpy(Tempstr+Len, Hash, hlen);
	len=Len + hlen;
}

*Return=EncodeBytes(*Return, Hash, hlen, Encoding);

DestroyString(Tempstr);
DestroyString(Hash);

StrLen(*Return);
}
Exemplo n.º 3
0
char *VFormatStr(char *InBuff, const char *InputFmtStr, va_list args)
{
int inc=100, count=1, result=0, FmtLen;
char *Tempstr=NULL, *FmtStr=NULL, *ptr;
va_list argscopy;

Tempstr=InBuff;

//Take a copy of the supplied Format string and change it.
//Do not allow '%n', it's useable for exploits

FmtLen=StrLen(InputFmtStr);
FmtStr=CopyStr(FmtStr,InputFmtStr);

//Deny %n. Replace it with %x which prints out the value of any supplied argument
ptr=strstr(FmtStr,"%n");
while (ptr)
{
  memcpy(ptr,"%x",2);
  ptr++;
  ptr=strstr(ptr,"%n");
}


inc=4 * FmtLen; //this should be a good average
for (count=1; count < 100; count++)
{
	result=inc * count +1;
  Tempstr=SetStrLen(Tempstr, result);

		//the vsnprintf function DESTROYS the arg list that is passed to it.
		//This is just plain WRONG, it's a long-standing bug. The solution is to
		//us va_copy to make a new one every time and pass that in.
		va_copy(argscopy,args);
     result=vsnprintf(Tempstr,result,FmtStr,argscopy);
		va_end(argscopy);

  /* old style returns -1 to say couldn't fit data into buffer.. so we */
  /* have to guess again */
  if (result==-1) continue;

  /* new style returns how long buffer should have been.. so we resize it */
  if (result > (inc * count))
  {
    Tempstr=SetStrLen(Tempstr, result+10);
		va_copy(argscopy,args);
    result=vsnprintf(Tempstr,result+10,FmtStr,argscopy);
		va_end(argscopy);
  }

   break;
}

DestroyString(FmtStr);

return(Tempstr);
}
Exemplo n.º 4
0
void HTTPServerRecieveURL(STREAM *S,HTTPSession *Heads)
{
STREAM *Doc;
struct stat FileStat;
char *Buffer=NULL, *Tempstr=NULL;
int BuffSize=4096;


Doc=STREAMOpenFile(Heads->Path, SF_CREAT | SF_TRUNC | SF_WRONLY);

if (! Doc) HTTPServerSendHTML(S, Heads, "403 Forbidden","Can't open document for write.");
else
{
	fchmod(Doc->in_fd,0660); 

	Buffer=SetStrLen(Buffer,BuffSize);
	STREAMSendFile(S,Doc,Heads->ContentSize, SENDFILE_KERNEL | SENDFILE_LOOP);
	STREAMClose(Doc);

	stat(Heads->Path,&FileStat);
	LogToFile(Settings.LogPath,"%s@%s (%s) uploaded %s (%d bytes)",Heads->UserName,Heads->ClientHost,Heads->ClientIP,Heads->Path,FileStat.st_size);
	HTTPServerSendHTML(S, Heads, "201 Created","");
}


DestroyString(Tempstr);
DestroyString(Buffer);
}
Exemplo n.º 5
0
int HTTPServerReadBody(HTTPSession *Session, char **Data)
{
char *Tempstr=NULL;
int bytes_read=0, len;

if (Session->ContentSize > 0)
{
	*Data=SetStrLen(*Data,Session->ContentSize+10);
  while (bytes_read < Session->ContentSize)
  {
  len=STREAMReadBytes(Session->S, (*Data) + bytes_read, Session->ContentSize-bytes_read);
  if (len < 1) break;
  bytes_read+=len;
  }
}
else
{
  Tempstr=STREAMReadLine(Tempstr,Session->S);
  while (Tempstr)
  {
		len=StrLen(Tempstr);
    *Data=CatStrLen(*Data,Tempstr,len);
		bytes_read+=len;
    Tempstr=STREAMReadLine(Tempstr,Session->S);
  }
}

DestroyString(Tempstr);
return(bytes_read);
}
Exemplo n.º 6
0
int HashFile(char **Return, const char *Type, const char *Path, int Encoding)
{
HASH *Hash;
STREAM *S;
char *Tempstr=NULL;
int result;

S=STREAMOpen(Path,"r");
if (! S) return(FALSE);

Hash=HashInit(Type);
if (! Hash) 
{
	STREAMClose(S);
	return(FALSE);
}


Tempstr=SetStrLen(Tempstr,4096);
result=STREAMReadBytes(S,Tempstr,4096);
while (result !=EOF)
{
	Hash->Update(Hash, Tempstr, result);
	result=STREAMReadBytes(S,Tempstr,4096);
}

DestroyString(Tempstr);
STREAMClose(S);

result=HashFinish(Hash, Encoding, Return);

return(result);
}
Exemplo n.º 7
0
const char *OpenSSLQueryCipher(STREAM *S)
{
void *ptr;

if (! S) return(NULL);
ptr=STREAMGetItem(S,"LIBUSEFUL-SSL-CTX");
if (! ptr) return(NULL);

#ifdef HAVE_LIBSSL
const SSL_CIPHER *Cipher;
char *Tempstr=NULL;

Cipher=SSL_get_current_cipher((const SSL *) ptr);

if (Cipher)
{
Tempstr=FormatStr(Tempstr,"%d bit %s",SSL_CIPHER_get_bits(Cipher,NULL), SSL_CIPHER_get_name(Cipher));
STREAMSetValue(S,"SSL-Cipher",Tempstr);

Tempstr=SetStrLen(Tempstr,1024);
Tempstr=SSL_CIPHER_description(Cipher, Tempstr, 1024);


STREAMSetValue(S,"SSL-Cipher-Details",Tempstr);
}

DestroyString(Tempstr);
return(STREAMGetValue(S,"SSL-Cipher"));

#else
return(NULL);
#endif
}
Exemplo n.º 8
0
int HashFinishWhirlpool(THash *Hash, int Encoding, char **HashStr)
{
int count, len;
char *Tempstr=NULL, *DigestBuff=NULL;

DigestBuff=(char *) calloc(1,WHIRLPOOL_DIGESTBYTES+1);
WHIRLPOOLfinalize((WHIRLPOOLstruct *) Hash->Ctx, DigestBuff);
free(Hash->Ctx);

if (Encoding > 0)
{
	 *HashStr=EncodeBytes(*HashStr, DigestBuff, WHIRLPOOL_DIGESTBYTES, Encoding);
	 len=StrLen(*HashStr);
}
else
{
len=WHIRLPOOL_DIGESTBYTES;
*HashStr=SetStrLen(*HashStr,len);
memcpy(*HashStr,DigestBuff,len);
}

DestroyString(DigestBuff);
DestroyString(Tempstr);

return(len);
}
Exemplo n.º 9
0
int HashFinishJH(THash *Hash, int Encoding, char **HashStr)
{
int count, len;
char *Tempstr=NULL, *DigestBuff=NULL;

DigestBuff=(char *) calloc(1,1024);

len=JHFinal((hashState *) Hash->Ctx, DigestBuff);
free(Hash->Ctx);

if (Encoding > 0)
{
	 *HashStr=EncodeBytes(*HashStr, DigestBuff, len, Encoding);
	 len=StrLen(*HashStr);
}
else
{
	*HashStr=SetStrLen(*HashStr,len);
	memcpy(*HashStr,DigestBuff,len);
}

DestroyString(DigestBuff);
DestroyString(Tempstr);

return(len);
}
Exemplo n.º 10
0
int HashFinishSHA1(THash *Hash, int Encoding, char **HashStr)
{
int count, len;
char *Tempstr=NULL, *DigestBuff=NULL;

DigestBuff=(char *) calloc(1,SHA1LEN+1);
sha1_finish_ctx((struct sha1_ctx *) Hash->Ctx, DigestBuff);
free(Hash->Ctx);

if (Encoding > 0)
{
	 *HashStr=EncodeBytes(*HashStr, DigestBuff, SHA1LEN, Encoding);
	 len=StrLen(*HashStr);
}
else
{
len=SHA1LEN;
*HashStr=SetStrLen(*HashStr,len);
memcpy(*HashStr,DigestBuff,len);
}

DestroyString(DigestBuff);
DestroyString(Tempstr);

return(len);
}
Exemplo n.º 11
0
int HashFinishSHA512(THash *Hash, int Encoding, char **HashStr)
{
int count, len;
char *Tempstr=NULL, *DigestBuff=NULL;

DigestBuff=(char *) calloc(1,SHA2_SHA512_DIGEST_LENGTH+1);
SHA2_SHA512_Final(DigestBuff, (SHA2_SHA512_CTX *) Hash->Ctx);
free(Hash->Ctx);

if (Encoding > 0)
{
	 *HashStr=EncodeBytes(*HashStr, DigestBuff, SHA2_SHA512_DIGEST_LENGTH, Encoding);
	 len=StrLen(*HashStr);
}
else
{
len=SHA2_SHA512_DIGEST_LENGTH;
*HashStr=SetStrLen(*HashStr,len);
memcpy(*HashStr,DigestBuff,len);
}

DestroyString(DigestBuff);
DestroyString(Tempstr);

return(len);
}
Exemplo n.º 12
0
int HashFinishMD5(THash *Hash, int Encoding, char **HashStr)
{
int count, len;
char *Tempstr=NULL, *DigestBuff=NULL;

DigestBuff=(char *) calloc(1,MD5LEN+1);
MD5Final(DigestBuff, (MD5_CTX *) Hash->Ctx);

free(Hash->Ctx);

if (Encoding > 0)
{
*HashStr=EncodeBytes(*HashStr, DigestBuff, MD5LEN, Encoding);
len=StrLen(*HashStr);
}
else
{
len=MD5LEN;
*HashStr=SetStrLen(*HashStr,len);
memcpy(*HashStr,DigestBuff,len);
}

DestroyString(DigestBuff);
DestroyString(Tempstr);

return(len);
}
Exemplo n.º 13
0
int STREAMAddDataProcessor(STREAM *S, TProcessingModule *Mod, const char *Args)
{
ListNode *Curr;
char *Tempstr=NULL;
int len;

STREAMFlush(S);

if (! S->ProcessingModules) S->ProcessingModules=ListCreate();
Tempstr=MCopyStr(Tempstr,Mod->Name,NULL);
ListAddNamedItem(S->ProcessingModules,Tempstr,Mod);

len=S->InEnd - S->InStart;
Tempstr=SetStrLen(Tempstr,len);
memcpy(Tempstr,S->InputBuff + S->InStart,len);
STREAMResetInputBuffers(S);

Curr=ListGetNext(Mod->Values);
while (Curr)
{
	STREAMSetValue(S,Curr->Tag,(char *) Curr->Item);
	Curr=ListGetNext(Curr);
}

STREAMReadThroughProcessors(S, Tempstr, len);

DestroyString(Tempstr);
return(TRUE);
}
Exemplo n.º 14
0
char *GetDateStrFromSecs(const char *DateFormat, time_t Secs, const char *TimeZone)
{
time_t val;
struct tm *TMS;
static char *Buffer=NULL;
char *Tempstr=NULL;
#define DATE_BUFF_LEN 255

val=Secs;

if (StrLen(TimeZone))
{
if (getenv("TZ")) Tempstr=CopyStr(Tempstr,getenv("TZ"));
setenv("TZ",TimeZone,TRUE);
tzset();
}
TMS=localtime(&val);
if (StrLen(TimeZone))
{
if (! Tempstr) unsetenv("TZ");
else setenv("TZ",Tempstr,TRUE);
tzset();
}

val=StrLen(DateFormat)+ DATE_BUFF_LEN;
Buffer=SetStrLen(Buffer,val);
strftime(Buffer,val,DateFormat,TMS);

DestroyString(Tempstr);
return(Buffer);
}
Exemplo n.º 15
0
void HTTPServerSendResponse(STREAM *S, HTTPSession *Session, char *ResponseLine, char *ContentType, char *Body)
{
HTTPSession *Response;
char *Tempstr=NULL;
long ResponseCode=0;

LogToFile(Settings.LogPath,"RESPONSE: '%s' to %s@%s for '%s %s'",ResponseLine,Session->UserName,Session->ClientIP,Session->Method,Session->Path);

ResponseCode=strtol(ResponseLine,NULL,10);

//Create 'Response' rather than using session, because things set by the client in 'Session' might
//get copied into the response and interfere with the response otherwise
Response=HTTPSessionCreate();

/*Copy Values from Session object into Response */
if (Session)
{
	Response->MethodID=Session->MethodID;
	Response->LastModified=Session->LastModified;
	Response->Flags |= Session->Flags & (SESSION_KEEPALIVE | SESSION_AUTHENTICATED);
	//Response->Flags |= SESSION_KEEPALIVE;
	Response->ClientIP=CopyStr(Response->ClientIP,Session->ClientIP);
	Response->Path=CopyStr(Response->Path,Session->Path);
	Response->Method=CopyStr(Response->Method,Session->Method);
	Response->URL=CopyStr(Response->URL,Session->URL);
	Response->UserName=CopyStr(Response->UserName,Session->UserName);
}

Response->ResponseCode=CopyStr(Response->ResponseCode,ResponseLine);
if (ResponseCode==302) SetVar(Response->Headers,"Location",Body);
else Response->ContentSize=StrLen(Body);
Response->ContentType=CopyStr(Response->ContentType,ContentType);


if (HTTPServerDecideToCompress(Session,NULL))
{
  Response->Flags |= SESSION_ENCODE_GZIP;
	Tempstr=SetStrLen(Tempstr,Response->ContentSize *2); 
  Response->ContentSize=CompressBytes(&Tempstr, "gzip",Body, StrLen(Body), 5);
}
else Tempstr=CopyStr(Tempstr,Body);


if ((ResponseCode==401) || (ResponseCode==407)) HTTPServerSendHeaders(S, Response,HEADERS_AUTH);
else HTTPServerSendHeaders(S, Response, HEADERS_KEEPALIVE);

STREAMWriteBytes(S,Tempstr,Response->ContentSize);
STREAMFlush(S);

/* If HTTPServerSendHeaders set SESSION_REUSE then set that in the Session object */
//if (Response->Flags & SESSION_REUSE) Session->Flags |= SESSION_REUSE;
//else Session->Flags &= ~SESSION_REUSE;


ProcessSessionEventTriggers(Response);
HTTPSessionDestroy(Response);

DestroyString(Tempstr);
}
Exemplo n.º 16
0
char *EncodeBase64(char *Return, char *Text, int len)
{
char *RetStr;

RetStr=SetStrLen(Return,len *2);
to64frombits(RetStr,Text,len);

return(RetStr);
}
Exemplo n.º 17
0
char *DecodeBase64(char *Return, int *len, char *Text)
{
char *RetStr;

RetStr=SetStrLen(Return,StrLen(Text) *2);
*len=from64tobits(RetStr,Text);

return(RetStr);
}
Exemplo n.º 18
0
char *HTTPHeadersAppendAuth(char *RetStr, char *AuthHeader, HTTPInfoStruct *Info, HTTPAuthStruct *AuthInfo)
{
char *SendStr=NULL, *Tempstr=NULL;
char *HA1=NULL, *HA2=NULL, *ClientNonce=NULL, *Digest=NULL;
int i, AuthCounter;

if (! AuthInfo) return(RetStr);

SendStr=CatStr(RetStr,"");

	//Authentication by an opaque authentication token that is handled 
	//elsewhere, and is set as the 'Password'
  if (AuthInfo->Flags & HTTP_AUTH_TOKEN)
	{
    SendStr=MCatStr(SendStr,AuthHeader,": ",AuthInfo->Password,"\r\n",NULL);
    AuthInfo->Flags |= HTTP_SENT_AUTH;
	}
  else if (AuthInfo->Flags & HTTP_AUTH_DIGEST)
  {
    AuthCounter++;
    Tempstr=FormatStr(Tempstr,"%s:%s:%s",AuthInfo->Logon,AuthInfo->AuthRealm,AuthInfo->Password);
    HashBytes(&HA1,"md5",Tempstr,StrLen(Tempstr),0);
    Tempstr=FormatStr(Tempstr,"%s:%s",Info->Method,Info->Doc);
    HashBytes(&HA2,"md5",Tempstr,StrLen(Tempstr),0);

    for (i=0; i < 10; i++)
    {
			Tempstr=FormatStr(Tempstr,"%x",rand() % 255);
			ClientNonce=CatStr(ClientNonce,Tempstr);
    }

    Tempstr=FormatStr(Tempstr,"%s:%s:%08d:%s:auth:%s",HA1,AuthInfo->AuthNonce,AuthCounter,ClientNonce,HA2);
    HashBytes(&Digest,"md5",Tempstr,StrLen(Tempstr),0);
    Tempstr=FormatStr(Tempstr,"%s: Digest username=\"%s\",realm=\"%s\",nonce=\"%s\",uri=\"%s\",qop=auth,nc=%08d,cnonce=\"%s\",response=\"%s\"\r\n",AuthHeader,AuthInfo->Logon,AuthInfo->AuthRealm,AuthInfo->AuthNonce,Info->Doc,AuthCounter,ClientNonce,Digest);
    SendStr=CatStr(SendStr,Tempstr);
    AuthInfo->Flags |= HTTP_SENT_AUTH;
  }
  else 
  {
    Tempstr=CopyStr(Tempstr,AuthInfo->Logon);
    Tempstr=CatStr(Tempstr,":");
    Tempstr=CatStr(Tempstr,AuthInfo->Password);
    Digest=SetStrLen(Digest,StrLen(Tempstr) *2);
    to64frombits(Digest,Tempstr,strlen(Tempstr));
    SendStr=MCatStr(SendStr,AuthHeader,": Basic ",Digest,"\r\n",NULL);
    AuthInfo->Flags |= HTTP_SENT_AUTH;
  }

DestroyString(HA1);
DestroyString(HA2);
DestroyString(ClientNonce);
DestroyString(Digest);
DestroyString(Tempstr);

return(SendStr);
}
Exemplo n.º 19
0
void HMACPrepare(HASH *HMAC, const char *Data, int Len)
{
int i;
char *Key=NULL, *Tempstr=NULL;

//Whatever we've been given as a key, we have to turn it into a
//key of 'HMAC_BLOCKSIZE', either by hashing it to make it shorter
//or by padding with NULLS
Key=SetStrLen(Key,HMAC_BLOCKSIZE);
memset(Key,0,HMAC_BLOCKSIZE);

if (Len > HMAC_BLOCKSIZE) 
{
	HMAC->Key1Len=HashBytes(&Tempstr,HMAC->Type,HMAC->Key1,HMAC->Key1Len,0);
	memcpy(Key,Tempstr,HMAC->Key1Len);
}
else 
{
	memcpy(Key,HMAC->Key1,HMAC->Key1Len);
}

HMAC->Key1=SetStrLen(HMAC->Key1,HMAC_BLOCKSIZE);
HMAC->Key2=SetStrLen(HMAC->Key2,HMAC_BLOCKSIZE);
HMAC->Key1Len=HMAC_BLOCKSIZE;
HMAC->Key2Len=HMAC_BLOCKSIZE;

for (i=0; i < HMAC_BLOCKSIZE; i++)
{
//inner key
HMAC->Key1[i]=Key[i] ^ 0x36;
//outer key
HMAC->Key2[i]=Key[i] ^ 0x5c;
}


//first thing to be hashed is the inner key, then data is 'concatted' onto it
HMACUpdate(HMAC, HMAC->Key1, HMAC->Key1Len);
HMACUpdate(HMAC, Data, Len);
HMAC->Update=HMACUpdate;

DestroyString(Tempstr);
DestroyString(Key);
}
Exemplo n.º 20
0
int HTTPChunkedRead(TProcessingModule *Mod, const char *InBuff, int InLen, char **OutBuff, int *OutLen)
{
int len=0, val=0;
THTTPChunk *Chunk;
char *ptr, *vptr;

Chunk=(THTTPChunk *) Mod->Data;
len=Chunk->BuffLen+InLen;
Chunk->Buffer=SetStrLen(Chunk->Buffer,len);
memcpy(Chunk->Buffer+Chunk->BuffLen,InBuff,InLen);
Chunk->BuffLen=len;
ptr=Chunk->Buffer;

if (Chunk->ChunkSize==0)
{
	vptr=ptr;
	if (*vptr=='\r') vptr++;
	if (*vptr=='\n') vptr++;
	ptr=strchr(vptr,'\n');
	if (ptr)
	{
	  *ptr='\0';
		ptr++;
	}
	else ptr=Chunk->Buffer;
	Chunk->ChunkSize=strtol(vptr,NULL,16);

	Chunk->BuffLen=Chunk->Buffer+len-ptr;
	memmove(Chunk->Buffer,ptr,Chunk->BuffLen);

	if (Chunk->ChunkSize==0) return(0);
}
else if (len >= Chunk->ChunkSize)
{
	val=Chunk->ChunkSize;

	//We should really grow OutBuff to take all the data
	//but for the sake of simplicity we'll just use the space
	//supplied
	if (val > *OutLen) val=*OutLen;
	memcpy(*OutBuff,Chunk->Buffer,val);

	ptr=Chunk->Buffer+val;
	Chunk->BuffLen-=val;
	Chunk->ChunkSize-=val;
	memmove(Chunk->Buffer, ptr, Chunk->BuffLen);

}

if (Chunk->ChunkSize < 0) Chunk->ChunkSize=0;

return(val);
}
Exemplo n.º 21
0
int HashFinishCRC(HASH *Hash, char **HashStr)
{
unsigned long crc;
int len;

len=sizeof(unsigned long);
crc32Finish((unsigned long *) Hash->Ctx);
crc=htonl(* (unsigned long *) Hash->Ctx);

*HashStr=SetStrLen(*HashStr,len);
memcpy(*HashStr,&crc,len);
return(len);
}
Exemplo n.º 22
0
void SendResponse(ConnectStruct *Con,DNSMessageStruct *Response)
{
struct sockaddr_in Send_sa;
short int sendlen;
int len, salen;
char *Buffer=NULL;
ListNode *Curr;
ResourceRecord *RR;

Buffer=SetStrLen(Buffer,1024);
len=CreateResponsePacket(Buffer,Buffer+1024,Response,&Settings);

if (len==0)
{
  LogToFile(Settings.LogFilePath,"ERROR: Zero length response packet");
	DestroyString(Buffer);
  return;
}

if (Con->Type==TCP_CONNECT)
{
   sendlen=htons(len);
   write(Con->fd, &sendlen, sizeof(short int));
   write(Con->fd, Buffer, len);
}
else if (Con->Type==UDP_CONNECT)
{
   Send_sa.sin_family=AF_INET;
   Send_sa.sin_addr.s_addr=Response->ClientIP;
   Send_sa.sin_port=Response->ClientPort;
   salen=sizeof(struct sockaddr_in);

   sendto(Con->fd,Buffer,len,0,(struct sockaddr *) &Send_sa,salen);
}
else LogToFile(Settings.LogFilePath,"ERROR: Unknown Comms Type %d on send",Con->Type);

if (Settings.LogLevel >= LOG_RESPONSES) 
{
	LogToFile(Settings.LogFilePath,"Sent %d answers to %s for %s query",ListSize(Response->Answers), IPtoStr(Response->ClientIP),Response->Question);

	Curr=ListGetNext(Response->Answers);
	while (Curr)
	{
		RR=(ResourceRecord *) Curr->Item;
		LogToFile(Settings.LogFilePath,"	ANS: %s->%s type=%d ttl=%d",RR->Question,RR->Answer,RR->Type,RR->TTL);
		Curr=ListGetNext(Curr);
	}
}

DestroyString(Buffer);
}
Exemplo n.º 23
0
int SMTPLogin(STREAM *S, int Caps, const char *User, const char *Pass)
{
    char *Tempstr=NULL, *Base64=NULL, *ptr;
    int len, result=FALSE;


    if (Caps & CAP_AUTH_LOGIN)
    {
        Tempstr=CopyStr(Tempstr, "AUTH LOGIN\r\n");
        if (SMTPInteract(Tempstr, S))
        {
            Base64=EncodeBytes(Base64, User, StrLen(User), ENCODE_BASE64);
            Tempstr=MCopyStr(Tempstr, Base64, "\r\n", NULL);
            if (SMTPInteract(Tempstr, S))
            {
                Base64=EncodeBytes(Base64, Pass, StrLen(Pass), ENCODE_BASE64);
                Tempstr=MCopyStr(Tempstr, Base64, "\r\n", NULL);
                if (SMTPInteract(Tempstr, S)) result=TRUE;
            }
        }
    }
    else if (Caps & CAP_AUTH_PLAIN)
    {
        Tempstr=SetStrLen(Tempstr, StrLen(User) + StrLen(Pass) +10);

				//this isn't what it looks like. The '\0' here do not terminate the string
				//as this authentication system uses a string with '\0' as separators
        len=StrLen(User);
        ptr=Tempstr;
        memcpy(ptr, User, len);
        ptr+=len;
        *ptr='\0';
        ptr++;

        len=StrLen(Pass);
        memcpy(ptr, Pass, len);
        ptr+=len;
        *ptr='\0';
        ptr++;

        Base64=EncodeBytes(Base64, Tempstr, ptr-Tempstr, ENCODE_BASE64);
        Tempstr=MCopyStr(Tempstr, "AUTH PLAIN ", Base64, "\r\n",NULL);
        if (SMTPInteract(Tempstr, S)) result=TRUE;
    }

    DestroyString(Tempstr);
    DestroyString(Base64);

    return(result);
}
Exemplo n.º 24
0
void HTTPCopyToSTREAM(STREAM *Con, STREAM *S)
{
char *Tempstr=NULL;
int result;

Tempstr=SetStrLen(Tempstr,BUFSIZ);
result=STREAMReadBytes(Con, Tempstr,BUFSIZ);
while (result > 0)
{
	STREAMWriteBytes(S,Tempstr,result);
	result=STREAMReadBytes(Con, Tempstr,BUFSIZ);
}

}
Exemplo n.º 25
0
int M3UStreamDownload(STREAM *ManifestCon, const char *URL, const char *Title)
{
STREAM *Con=NULL;
char *Tempstr=NULL, *BasePath=NULL, *Line=NULL;
const char *ptr;
ListNode *Segments, *Curr;
int result;
double BytesRead=0;

Segments=ListCreate();
ptr=strrchr(URL, '/');
if (ptr)
{
BasePath=CopyStrLen(BasePath, URL, ptr - URL);
	Line=STREAMReadLine(Line,ManifestCon);
	while (Line)
	{
		StripLeadingWhitespace(Line);
		StripTrailingWhitespace(Line);
		
		if (*Line != '#')
		{
			Tempstr=MCopyStr(Tempstr, BasePath, "/", Line, NULL);
			ListAddItem(Segments, CopyStr(NULL, Tempstr));
		}
	Line=STREAMReadLine(Line,ManifestCon);
	}

	OpenOutputFiles(Title, URL, &BytesRead);
	Tempstr=SetStrLen(Tempstr,BUFSIZ);
	Curr=ListGetNext(Segments);
	while (Curr)
	{
		Con=ConnectAndRetryUntilDownload(Curr->Item, 0, 0);
		if (Con)
		{
		TransferItem(Con, Title, URL, "m3u8-stream", 0, 0, &BytesRead, FALSE);
		STREAMClose(Con);
		}

	Curr=ListGetNext(Curr);
	}
	CloseOutputFiles();
}

ListDestroy(Segments, DestroyString);
DestroyString(Tempstr);
DestroyString(BasePath);
DestroyString(Line);
}
Exemplo n.º 26
0
int ConnectHopSocks(STREAM *S, int Type, const char *Host, int Port, const char *User, const char *Pass, const char *Path)
{
char *Tempstr=NULL;
uint8_t *ptr;
char *Token=NULL;
const char *tptr;
int result, RetVal=FALSE;

S->in_fd=ConnectToHost(Host,Port,0); 
S->out_fd=S->in_fd;
if (S->in_fd == -1) return(FALSE);


//Horrid binary protocol. 
Tempstr=SetStrLen(Tempstr, StrLen(User) +20);
ptr=Tempstr;
*ptr=4; //version number
ptr++;
*ptr=1; //outward connection (2 binds a port for incoming)
ptr++;

tptr=Path;
if (strncmp(tptr,"tcp:",4)==0) tptr+=4;
tptr=GetToken(tptr,":",&Token,0);

//destination port
*((uint16_t *) ptr) =htons(atoi(tptr));
ptr+=2;

//destination host
*((uint32_t *) ptr) =StrtoIP(Token);
ptr+=4;

strcpy(ptr,User);
ptr+=StrLen(User);
ptr++;
STREAMWriteBytes(S,Tempstr,(char *)ptr-Tempstr); STREAMFlush(S);
result=STREAMReadBytes(S,Tempstr,8);

//Positive response will be 0x00 0x5a 0x00 0x00 0x00 0x00 0x00 0x00
//although only the leading two bytes (0x00 0x5a, or \0Z) matters
if ((result==8) && (Tempstr[0]=='\0') && (Tempstr[1]=='Z')) RetVal=TRUE;


DestroyString(Tempstr);
DestroyString(Token);

return(RetVal);
}
Exemplo n.º 27
0
void SendICYMessage(STREAM *Output, const char *ICYMessage)
{
uint8_t len;
char *Tempstr=NULL;

	len=StrLen(ICYMessage);
	if (len > 0) len=(len / 16) + 1;
	Tempstr=SetStrLen(Tempstr,len * 16);
	memset(Tempstr,0,len * 16);
	strcpy(Tempstr,ICYMessage);
	STREAMWriteBytes(Output,(char *) &len,1);
	STREAMWriteBytes(Output,Tempstr,len * 16);

DestroyString(Tempstr);
}
Exemplo n.º 28
0
int HashFinishJH(HASH *Hash, char **HashStr)
{
int len;
char *DigestBuff=NULL;

DigestBuff=(char *) calloc(1,1024);

len=JHFinal((hashState *) Hash->Ctx, (unsigned char *) DigestBuff);
*HashStr=SetStrLen(*HashStr,len);
memcpy(*HashStr,DigestBuff,len);

DestroyString(DigestBuff);

return(len);
}
Exemplo n.º 29
0
int HashFinishWhirlpool(HASH *Hash, char **HashStr)
{
int len;
char *DigestBuff=NULL;

DigestBuff=(char *) calloc(1,WHIRLPOOL_DIGESTBYTES+1);
WHIRLPOOLfinalize((WHIRLPOOLstruct *) Hash->Ctx, (unsigned char *) DigestBuff);

len=WHIRLPOOL_DIGESTBYTES;
*HashStr=SetStrLen(*HashStr,len);
memcpy(*HashStr,DigestBuff,len);

DestroyString(DigestBuff);

return(len);
}
Exemplo n.º 30
0
int HashFinishSHA512(HASH *Hash, char **HashStr)
{
int len;
char *DigestBuff=NULL;

DigestBuff=(char *) calloc(1,SHA2_SHA512_DIGEST_LENGTH+1);
SHA2_SHA512_Final((unsigned char *) DigestBuff, (SHA2_SHA512_CTX *) Hash->Ctx);

len=SHA2_SHA512_DIGEST_LENGTH;
*HashStr=SetStrLen(*HashStr,len);
memcpy(*HashStr,DigestBuff,len);

DestroyString(DigestBuff);

return(len);
}