Exemple #1
0
static void ParseCrayonList(STREAM *S, TCrayon *Crayon)
{
char *Tempstr=NULL, *Token=NULL;
const char *ptr;
ListNode *Curr;
TCrayon *SubItem;

	if (! Crayon) return;
	Tempstr=STREAMReadLine(Tempstr,S);
	while (Tempstr)
	{
		StripTrailingWhitespace(Tempstr);
		StripLeadingWhitespace(Tempstr);

		ptr=GetToken(Tempstr,"\\S",&Token,0);
		if (StrLen(Token) && (*Token != '#'))
		{
			if (strcmp(Token,"}")==0) break;
		
			if (strcmp(Token,"{")==0) ParseCrayonList(S, SubItem);
			else if (CrayonType(Token) == CRAYON_ACTION) ParseCrayonAction(Crayon, Tempstr);
			else
			{
			SubItem=NewCrayonAction(Crayon, 0);
			ParseCrayonEntry(SubItem, Token,ptr);
			}
		}

	Tempstr=STREAMReadLine(Tempstr,S);
	}

Destroy(Tempstr);
Destroy(Token);
}
Exemple #2
0
int LogFileAppendTempLog(const char *LogPath, const char *TmpLogPath)
{
TLogFile *LogFile;
char *Tempstr=NULL;
STREAM *S;
int result=FALSE;

    LogFile=LogFileGetEntry(LogPath);
    LogFileClose(TmpLogPath);
    S=STREAMOpenFile(TmpLogPath,SF_RDONLY);
    if (LogFile && S)
    {

            STREAMLock(LogFile->S,LOCK_EX);
            Tempstr=STREAMReadLine(Tempstr,S);
            while(Tempstr)
            {
            STREAMWriteLine(Tempstr,LogFile->S);
            Tempstr=STREAMReadLine(Tempstr,S);
            }
            if (LogFile->Flags & LOGFILE_FLUSH) STREAMFlush(LogFile->S);
            STREAMLock(LogFile->S,LOCK_UN);
            unlink(TmpLogPath);
						result=TRUE;
    }
		if (S) STREAMClose(S);

DestroyString(Tempstr);

return(result);
}
Exemple #3
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);
}
Exemple #4
0
void ListNativeFile(STREAM *Out, char *Path)
{
STREAM *S;
char *Tempstr=NULL, *Token=NULL, *SendStr=NULL, *ptr;

S=STREAMOpenFile(Settings.AuthFile,O_RDONLY);
if (S)
{
  Tempstr=STREAMReadLine(Tempstr,S);
  while (Tempstr)
  {
    StripTrailingWhitespace(Tempstr);
    ptr=GetToken(Tempstr,":",&Token,0);
    SendStr=MCopyStr(SendStr,Token," ",NULL);

    ptr=GetToken(ptr,":",&Token,0); //passtype
    ptr=GetToken(ptr,":",&Token,0); //password
    ptr=GetToken(ptr,":",&Token,0); //realuser
    SendStr=MCatStr(SendStr,"realuser="******" ",NULL);
    ptr=GetToken(ptr,":",&Token,0); //homedir
    SendStr=MCatStr(SendStr,"homedir=",Token," ",NULL);
    SendStr=MCatStr(SendStr,ptr,"\n",NULL);

    STREAMWriteLine(SendStr,Out);
    Tempstr=STREAMReadLine(Tempstr,S);
  }
  STREAMClose(S);
}

STREAMFlush(Out);

DestroyString(Tempstr);
DestroyString(SendStr);
DestroyString(Token);
}
Exemple #5
0
void ParseFunction(STREAM *S, const char *Config)
{
char *Token=NULL, *Tempstr=NULL;
const char *ptr;
ListNode *Select;
TCrayon *Crayon;

if (! Functions) Functions=ListCreate();

ptr=GetToken(Config, "\\S", &Token, GETTOKEN_QUOTES);
Select=ListCreate();

ListAddNamedItem(Functions, Token, Select);

Tempstr=STREAMReadLine(Tempstr, S);
while (Tempstr)
{
	StripTrailingWhitespace(Tempstr);
	StripLeadingWhitespace(Tempstr);
	ptr=GetToken(Tempstr, "\\S", &Token, GETTOKEN_QUOTES);
	if (strcmp(Token,"}")==0) break;
	
	if (MatchActionType(Token) > -1)
	{
		 ParseCrayonization("action", Tempstr, Select);
	}
	else ParseCrayonization(Token, ptr, Select);
	Tempstr=STREAMReadLine(Tempstr, S);
}

Destroy(Tempstr);
Destroy(Token);
}
void GetClientHardwareAddress(TSession *Session)
{
STREAM *S;
char *Tempstr=NULL, *Token=NULL, *ptr;

S=STREAMOpenFile("/proc/net/arp",O_RDONLY);
if (S)
{
	Tempstr=STREAMReadLine(Tempstr,S);
	Tempstr=STREAMReadLine(Tempstr,S);
	while (Tempstr)
	{
		ptr=GetToken(Tempstr,"\\S",&Token,0);
		if (strcmp(Token,Session->ClientIP)==0)
		{
		//HW Type
		ptr=GetToken(ptr,"\\S",&Token,0);
		//Flags
		ptr=GetToken(ptr,"\\S",&Token,0);

		//MAC
		ptr=GetToken(ptr,"\\S",&Session->ClientMAC,0);
			
		}
	Tempstr=STREAMReadLine(Tempstr,S);
	}
	STREAMClose(S);
}

DestroyString(Tempstr);
DestroyString(Token);
}
Exemple #7
0
int DoHTTPProxyTunnel(STREAM *S, const char *Host, int Port, const char *Destination, int Flags)
{
char *Tempstr=NULL, *Token=NULL;
const char *ptr=NULL;
int result=FALSE;

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

	ptr=Destination;
	if (strncmp(ptr,"tcp:",4)==0) ptr+=4;
	Tempstr=FormatStr(Tempstr,"CONNECT %s HTTP/1.1\r\n\r\n",ptr);

	STREAMWriteLine(Tempstr,S);
	STREAMFlush(S);
	
	Tempstr=STREAMReadLine(Tempstr,S);
	StripTrailingWhitespace(Tempstr);

	ptr=GetToken(Tempstr," ",&Token,0);
	ptr=GetToken(ptr," ",&Token,0);

	if (*Token=='2') result=TRUE;
	while (StrLen(Tempstr))
	{
		Tempstr=STREAMReadLine(Tempstr,S);
		StripTrailingWhitespace(Tempstr);
	}

DestroyString(Tempstr);
DestroyString(Token);

return(result);
}
Exemple #8
0
int HashratCheckSignedFile(char *Path, HashratCtx *Ctx)
{
STREAM *S;
char *Tempstr=NULL, *HashStr=NULL;
THash *Hash, *tmpHash;
int LineCount=0;

S=STREAMOpenFile(Path, SF_RDWR);
if (! S) return(FALSE);

Hash=HashInit(Ctx->HashType);
Tempstr=STREAMReadLine(Tempstr, S);
while (Tempstr)
{
	LineCount++;

	//hashrat-integrity-mark: 2014/10/29 21:05:19 md5:nTnlHmvVowFowmxXtm0uNw==
	if (strncmp(Tempstr, "hashrat-integrity-mark: ",24)==0)
	{
		tmpHash=Hash->Clone(Hash);
		HashFinish(tmpHash,ENCODE_BASE64,&HashStr);

		HashratOutputSigningCheck(Ctx, HashStr, Tempstr, LineCount);
	}
  Hash->Update(Hash ,Tempstr, StrLen(Tempstr));

	
	Tempstr=STREAMReadLine(Tempstr, S);
}

DestroyString(Tempstr);
DestroyString(HashStr);

return(TRUE);
}
Exemple #9
0
void OAuthInstalledAppGetAccessToken(char *TokenURL, char *ClientID, char *ClientSecret, char *AuthCode, char *RedirectURL, char **AccessToken, char **RefreshToken)
{
char *Tempstr=NULL, *Encode=NULL;
ListNode *Vars=NULL;
STREAM *S;

Vars=ListCreate();

Tempstr=MCopyStr(Tempstr,TokenURL,"?client_id=",ClientID,NULL);
Tempstr=MCatStr(Tempstr,"&client_secret=",ClientSecret,NULL);
Tempstr=MCatStr(Tempstr,"&code=",AuthCode,NULL);
Tempstr=MCatStr(Tempstr,"&redirect_uri=",RedirectURL,NULL);
Tempstr=MCatStr(Tempstr,"&grant_type=","authorization_code",NULL);

S=HTTPMethod("POST",Tempstr,"","","","",0);
if (S)
{
Tempstr=STREAMReadLine(Tempstr,S);
while (Tempstr)
{
StripTrailingWhitespace(Tempstr);
fprintf(stderr,"OA: %s\n",Tempstr);
OAuthParseJSON(Tempstr, Vars);
Tempstr=STREAMReadLine(Tempstr,S);
}
}

*AccessToken=CopyStr(*AccessToken,GetVar(Vars,"access_token"));
*RefreshToken=CopyStr(*RefreshToken,GetVar(Vars,"refresh_token"));

ListDestroy(Vars,DestroyString);
DestroyString(Tempstr);
DestroyString(Encode);
}
Exemple #10
0
void ListNativeFile(char *Path)
{
STREAM *S;
char *Tempstr=NULL, *Token=NULL, *ptr;

S=STREAMOpenFile(Settings.AuthPath,SF_RDONLY);
if (S)
{
	Tempstr=STREAMReadLine(Tempstr,S);
	while (Tempstr)
	{
		StripTrailingWhitespace(Tempstr);
		ptr=GetToken(Tempstr,":",&Token,0);

		printf("%s ",Token);

		ptr=GetToken(ptr,":",&Token,0); //passtype
		ptr=GetToken(ptr,":",&Token,0); //password
		ptr=GetToken(ptr,":",&Token,0); //realuser
		printf("RealUser=%s ",Token);
		ptr=GetToken(ptr,":",&Token,0); //homedir
		printf("Dir=%s %s\n",Token,ptr);

		Tempstr=STREAMReadLine(Tempstr,S);
	}
	STREAMClose(S);
}

DestroyString(Tempstr);
DestroyString(Token);
}
int DoHTTPProxyTunnel(STREAM *S, char *Host, int Port, int Flags)
{
char *Tempstr=NULL, *Token=NULL, *ptr=NULL;
int result=FALSE;

	if (Flags & CONNECT_SSL) Tempstr=FormatStr(Tempstr,"CONNECT https://%s:%d HTTP/1.1\r\n\r\n",Host,Port);
	else Tempstr=FormatStr(Tempstr,"CONNECT http://%s:%d HTTP/1.1\r\n\r\n",Host,Port);
	STREAMWriteLine(Tempstr,S);
	STREAMFlush(S);
	
	Tempstr=STREAMReadLine(Tempstr,S);
	StripTrailingWhitespace(Tempstr);

	ptr=GetToken(Tempstr," ",&Token,0);
	ptr=GetToken(ptr," ",&Token,0);

	if (*Token==2) result=TRUE;
	while (StrLen(Tempstr))
	{
		Tempstr=STREAMReadLine(Tempstr,S);
		StripTrailingWhitespace(Tempstr);
	}

DestroyString(Tempstr);
DestroyString(Token);

return(result);
}
Exemple #12
0
void OAuthDeviceRefreshToken(char *TokenURL, char *ClientID, char *ClientSecret, char *RequestRefreshToken, char **AccessToken, char **RefreshToken)
{
char *Tempstr=NULL, *Encode=NULL;
ListNode *Vars=NULL;
STREAM *S;

Vars=ListCreate();

Tempstr=MCopyStr(Tempstr,TokenURL,"?client_id=",ClientID,NULL);
Tempstr=MCatStr(Tempstr,"&client_secret=",ClientSecret,NULL);
Tempstr=MCatStr(Tempstr,"&refresh_token=",RequestRefreshToken,NULL);
Tempstr=MCatStr(Tempstr,"&grant_type=","refresh_token",NULL);

S=HTTPMethod("POST",Tempstr,"","","","",0);
if (S)
{
Tempstr=STREAMReadLine(Tempstr,S);
while (Tempstr)
{
StripTrailingWhitespace(Tempstr);
OAuthParseJSON(Tempstr, Vars);

Tempstr=STREAMReadLine(Tempstr,S);
}
} 

*AccessToken=CopyStr(*AccessToken,GetVar(Vars,"access_token"));
*RefreshToken=CopyStr(*RefreshToken,GetVar(Vars,"refresh_token"));

ListDestroy(Vars,DestroyString);
DestroyString(Tempstr);
DestroyString(Encode);
}
Exemple #13
0
int OAuthLoad(OAUTH *Ctx, const char *ReqName, const char *Path)
{
    STREAM *S;
    char *Tempstr=NULL, *Token=NULL, *Name=NULL;
    const char *ptr;
    int result=FALSE;

    if (StrValid(ReqName)) Name=CopyStr(Name, ReqName);
    else Name=CopyStr(Name, Ctx->Name);
    Ctx->AccessToken=CopyStr(Ctx->AccessToken, "");
    Ctx->RefreshToken=CopyStr(Ctx->RefreshToken, "");
    if (! StrValid(Path)) S=STREAMOpen(Ctx->SavePath,"rl");
    else S=STREAMOpen(Path,"rl");
    if (S)
    {
        Tempstr=STREAMReadLine(Tempstr, S);
        while (Tempstr)
        {
            ptr=GetToken(Tempstr, "\\S", &Token, GETTOKEN_QUOTES);
            if (strcmp(Token, Name)==0)
            {
                OAuthParse(Ctx, Tempstr);
                if (StrValid(Ctx->AccessToken) || StrValid(Ctx->RefreshToken)) result=TRUE;
            }
            Tempstr=STREAMReadLine(Tempstr, S);
        }
        STREAMClose(S);
    }

    DestroyString(Tempstr);
    DestroyString(Token);
    DestroyString(Name);

    return(result);
}
Exemple #14
0
void HTTPReadHeaders(STREAM *S, HTTPInfoStruct *Header)
{
char *Tempstr=NULL;


ListClear(Header->ServerHeaders,DestroyString);
Header->ContentLength=0;
Header->RedirectPath=CopyStr(Header->RedirectPath,"");
Header->Flags &= ~(HTTP_CHUNKED | HTTP_GZIP | HTTP_DEFLATE);
Tempstr=STREAMReadLine(Tempstr,S);
if (Tempstr)
{
HTTPParseResponseLine(S, Header,Tempstr);
Tempstr=STREAMReadLine(Tempstr,S);
}

while (Tempstr)
{
StripTrailingWhitespace(Tempstr);
if (StrLen(Tempstr)==0) break;
HTTPParseHeader(S, Header,Tempstr);
Tempstr=STREAMReadLine(Tempstr,S);
}

S->BytesRead=0;
DestroyString(Tempstr);
}
Exemple #15
0
int AsciiSendFileData(STREAM *InStream,STREAM * OutStream, int Direction)
{
char *Tempstr=NULL;
int result;
struct stat FStat;
double FileSize=0;
int RetVal=FALSE;


Tempstr=STREAMReadLine(Tempstr,InStream);
while (Tempstr)
{
		StripCRLF(Tempstr);
		Tempstr=CatStr(Tempstr,"\r\n");
		result=StrLen(Tempstr);

	STREAMWriteLine(Tempstr,OutStream);
	Tempstr=STREAMReadLine(Tempstr,InStream);
	RetVal=TRUE;
}

STREAMFlush(OutStream);
DestroyString(Tempstr);

return(RetVal);
}
Exemple #16
0
int DownloadM3U(char *URL, char *Title, int Flags)
{
char *Tempstr=NULL, *ID=NULL, *Doc=NULL, *ptr;
int Port=0, BytesRead=0, len=0, count=0;
int RetVal=FALSE;
ListNode *Items, *Curr;
int M3UType=M3U_PLAYLIST;
STREAM *Con;

if (Flags & FLAG_DEBUG) fprintf(stderr,"M3U STREAM: %s\n",URL);


Items=ListCreate();
Con=ConnectAndRetryUntilDownload(URL, 0, 0);
if (Con)
{
Tempstr=STREAMReadLine(Tempstr,Con);
while (Tempstr)
{
StripTrailingWhitespace(Tempstr);
StripLeadingWhitespace(Tempstr);

if (Flags & (FLAG_DEBUG2 | FLAG_DEBUG3)) fprintf(stderr,"%s\n",Tempstr);
if (StrLen(Tempstr))
{
	if (strncmp("#EXT-X-STREAM-INF",Tempstr,StrLen("#EXT-X-STREAM-INF"))==0)
	{
			RetVal=M3UStreamInfo(Con,Title,URL,Tempstr,Flags);
			M3UType=M3U_STREAMINFO;
	}
	else if (strncmp("#EXT-X-MEDIA-SEQUENCE",Tempstr,StrLen("#EXT-X-MEDIA-SEQUENCE"))==0) M3UType=M3U_PLAYLIST;
	else if (*Tempstr != '#') 
	{
		if (strncasecmp(Tempstr,"http",4) !=0) 
		{
			Doc=CopyStr(Doc,URL);
			ptr=strrchr(Doc,'/');
			if (ptr) *ptr='\0';
			Doc=MCatStr(Doc,"/",Tempstr,NULL);
		}
		else Doc=CopyStr(Doc,Tempstr);
		ListAddItem(Items,CopyStr(NULL,Doc));
	}
}

Tempstr=STREAMReadLine(Tempstr,Con);
}

STREAMClose(Con);
if (M3UType == M3U_PLAYLIST) RetVal=DownloadStream(URL, Title, Items, Flags);
}

ListDestroy(Items,DestroyString);
DestroyString(Tempstr);
DestroyString(Doc);
DestroyString(ID);


return(RetVal);
}
Exemple #17
0
void OAuthDeviceGetAccessToken(char *TokenURL, char *ClientID, char *ClientSecret, char *DeviceCode, char **AccessToken, char **RefreshToken)
{
char *Tempstr=NULL, *Encode=NULL;
ListNode *Vars=NULL;
STREAM *S;

Vars=ListCreate();

Encode=HTTPQuote(Encode,ClientID);
Tempstr=MCopyStr(Tempstr,TokenURL,"?client_id=",Encode,NULL);
Encode=HTTPQuote(Encode,ClientSecret);
Tempstr=MCatStr(Tempstr,"&client_secret=",Encode,NULL);
Tempstr=MCatStr(Tempstr,"&code=",DeviceCode,NULL);
Tempstr=MCatStr(Tempstr,"&grant_type=","http://oauth.net/grant_type/device/1.0",NULL);

S=HTTPMethod("POST",Tempstr,"","","","",0);
if (S)
{
Tempstr=STREAMReadLine(Tempstr,S);
while (Tempstr)
{
StripTrailingWhitespace(Tempstr);
printf("OA: %s\n",Tempstr);
OAuthParseJSON(Tempstr, Vars);
Tempstr=STREAMReadLine(Tempstr,S);
}
}

*AccessToken=CopyStr(*AccessToken,GetVar(Vars,"access_token"));
*RefreshToken=CopyStr(*RefreshToken,GetVar(Vars,"refresh_token"));

ListDestroy(Vars,DestroyString);
DestroyString(Tempstr);
DestroyString(Encode);
}
Exemple #18
0
ListNode *ConfigFileLoadFileStores(char *Path)
{
STREAM *S;
TFileStore *FS=NULL;
char *Tempstr=NULL, *Token=NULL, *ptr;

if (! FileStores) FileStores=ListCreate();
S=STREAMOpenFile(Path,O_RDONLY);
if (S)
{
	Tempstr=STREAMReadLine(Tempstr,S);
	while (Tempstr)
	{
		StripTrailingWhitespace(Tempstr);
		ptr=GetToken(Tempstr," ",&Token,0);

		if (strcmp(Token,"FileStore")==0)
		{
			FS=ConfigFileReadFileStore(S, ptr);
			ListAddNamedItem(FileStores,FS->Name,FS);
		}

		Tempstr=STREAMReadLine(Tempstr,S);
	}

STREAMClose(S);
}

DestroyString(Tempstr);
DestroyString(Token);

return(FileStores);
}
Exemple #19
0
void HTTPReadHeaders(STREAM *S, HTTPInfoStruct *Info)
{
char *Tempstr=NULL, *ptr;


ListClear(Info->ServerHeaders,DestroyString);
Info->ContentLength=0;

//Not needed
//Info->RedirectPath=CopyStr(Info->RedirectPath,"");
Info->Flags &= ~(HTTP_CHUNKED | HTTP_GZIP | HTTP_DEFLATE);
Tempstr=STREAMReadLine(Tempstr,S);
if (Tempstr)
{
	if (Info->Flags & HTTP_DEBUG) fprintf(stderr,"RESPONSE: %s\n",Tempstr);
  if (strncmp(Tempstr,"HTTP/",5)==0)
  {
    ptr=strchr(Tempstr,' ');
    ptr++;

    Info->ResponseCode=CopyStrLen(Info->ResponseCode,ptr,3);
    STREAMSetValue(S,"HTTP:ResponseCode",Info->ResponseCode);
  
  }
Tempstr=STREAMReadLine(Tempstr,S);
}

while (Tempstr)
{
StripTrailingWhitespace(Tempstr);
if (StrLen(Tempstr)==0) break;
HTTPParseHeader(S, Info,Tempstr);
Tempstr=STREAMReadLine(Tempstr,S);
}

//Handle Response Codes
if (StrLen(Info->ResponseCode))
{
		if (*Info->ResponseCode=='3') 
		{
			//No longer a flag, HTTP Redirect is now just a response code
			//Info->Flags |= HTTP_REDIRECT;
		}

		if (strcmp(Info->ResponseCode,"401")==0) 
		{
			if (Info->Authorization) Info->Authorization->Flags |= HTTP_AUTH_BASIC;
		}

		if (strcmp(Info->ResponseCode,"407")==0) 
		{
			if (Info->ProxyAuthorization) Info->ProxyAuthorization->Flags |= HTTP_PROXY_AUTH;
		}

}

S->BytesRead=0;
DestroyString(Tempstr);
}
Exemple #20
0
int ConnectHopHTTPSProxy(STREAM *S, const char *Proxy, const char *Destination)
{
    char *Tempstr=NULL, *Token=NULL;
    char *Proto=NULL, *Host=NULL, *User=NULL, *Pass=NULL;
    const char *ptr=NULL;
    int result=FALSE, Port;

    ParseConnectDetails(Proxy, &Token, &Host, &Token, &User, &Pass, NULL);
    Port=atoi(Token);
    if (! (S->State & SS_INITIAL_CONNECT_DONE))
    {
        if (Port==0) Port=443;
        S->in_fd=TCPConnect(Host,Port,0);
        S->out_fd=S->in_fd;
        if (S->in_fd == -1)
        {
            RaiseError(0, "ConnectHopHTTPSProxy", "failed to connect to proxy at %s:%d", Host, Port);
            return(FALSE);
        }
    }

    ptr=Destination;
    if (strncmp(ptr,"tcp:",4)==0) ptr+=4;
    Tempstr=FormatStr(Tempstr,"CONNECT %s HTTP/1.1\r\n\r\n",ptr);

    STREAMWriteLine(Tempstr,S);
    STREAMFlush(S);

    Tempstr=STREAMReadLine(Tempstr,S);
    if (Tempstr)
    {
        StripTrailingWhitespace(Tempstr);

        ptr=GetToken(Tempstr," ",&Token,0);
        ptr=GetToken(ptr," ",&Token,0);

        if (*Token=='2') result=TRUE;
        else RaiseError(0, "ConnectHopHTTPSProxy", "proxy request to %s:%d failed. %s", Host, Port, Tempstr);

        while (StrLen(Tempstr))
        {
            Tempstr=STREAMReadLine(Tempstr,S);
            StripTrailingWhitespace(Tempstr);
        }
    }
    else RaiseError(0, "ConnectHopHTTPSProxy", "proxy request to %s:%d failed. Server Disconnectd.", Host, Port);

    DestroyString(Tempstr);
    DestroyString(Token);
    DestroyString(Host);
    DestroyString(User);
    DestroyString(Pass);

    return(result);
}
Exemple #21
0
int AuthNativeFile(HTTPSession *Session, int HTTPDigest, char **RealUser, char **HomeDir, char **UserSettings)
{
STREAM *S;
char *Tempstr=NULL, *ptr;
char *Name=NULL, *Pass=NULL, *PasswordType=NULL, *Trash=NULL;
int RetVal=USER_UNKNOWN;


S=STREAMOpenFile(Settings.AuthPath,SF_RDONLY);
if (! S) return(USER_UNKNOWN);

Tempstr=STREAMReadLine(Tempstr,S);
while (Tempstr)
{

  StripTrailingWhitespace(Tempstr);
	ptr=GetToken(Tempstr,":",&Name,0);

  if (strcasecmp(Name,Session->UserName)==0)
  {
		ptr=GetToken(ptr,":",&PasswordType,0);
		ptr=GetToken(ptr,":",&Pass,0);
		if (RealUser) ptr=GetToken(ptr,":",RealUser,0);
		else ptr=GetToken(ptr,":",&Trash,0);
		if (HomeDir) ptr=GetToken(ptr,":",HomeDir,0);
		else ptr=GetToken(ptr,":",&Trash,0);
		if (UserSettings) ptr=GetToken(ptr,":",UserSettings,0);
		else ptr=GetToken(ptr,":",&Trash,0);
	
		RetVal=FALSE;

		if (HTTPDigest) RetVal=NativeFileCheckHTTPDigestAuth(Session, PasswordType, Pass, Session->Password);
		else RetVal=NativeFileCheckPassword(Name,PasswordType,Pass,Session->Password);

		break;
  }

  Tempstr=STREAMReadLine(Tempstr,S);
}
STREAMClose(S);


if ((RetVal==TRUE) && (Settings.Flags & FLAG_LOG_VERBOSE)) LogToFile(Settings.LogPath,"AUTH: UserName '%s' Authenticated via %s.",Session->UserName,Settings.AuthPath);

AuthenticationsTried=CatStr(AuthenticationsTried,"native ");

DestroyString(Name);
DestroyString(Pass);
DestroyString(Tempstr);
DestroyString(PasswordType);

return(RetVal);
}
Exemple #22
0
TFileStore *ConfigFileReadFileStore(STREAM *S, char *Name)
{
char *Tempstr=NULL, *Token=NULL, *ptr;
TFileStore *FS=NULL;
char *Type=NULL, *Host=NULL, *Login=NULL, *Password=NULL, *RefreshToken=NULL;
int Flags=0;


Tempstr=STREAMReadLine(Tempstr,S);
while (Tempstr)
{
StripTrailingWhitespace(Tempstr);
StripTrailingWhitespace(Tempstr);

if (strcmp(Tempstr,"}")==0) break;

ptr=GetToken(Tempstr,":",&Token,0);
while (ptr && isspace(*ptr)) ptr++;

if (strcmp(Token,"Type")==0) Type=CopyStr(Type,ptr);
if (strcmp(Token,"Host")==0) Host=CopyStr(Host,ptr);
if (strcmp(Token,"Login")==0) Login=CopyStr(Login,ptr);
if (strcmp(Token,"Password")==0) Password=CopyStr(Password,ptr);
if (strcmp(Token,"RefreshToken")==0) RefreshToken=CopyStr(RefreshToken,ptr);
if (strcmp(Token,"OAuth")==0) Flags |= FS_OAUTH;

Tempstr=STREAMReadLine(Tempstr,S);
}

if (StrLen(Type) && StrLen(Host))
{
	if (StrLen(Login)) Tempstr=MCopyStr(Tempstr,Type,":",	Login,"@",Host,NULL);
	else Tempstr=MCopyStr(Tempstr,Type,":",	Host,NULL);

	if (StrLen(Password)) Tempstr=MCatStr(Tempstr," -password ",Password,NULL);

	FS=FileStoreCreate(Name,Tempstr);
	if (StrLen(RefreshToken)) SetVar(FS->Vars,"OAuthRefreshToken",RefreshToken);
	FS->Settings |= Flags;

}

DestroyString(Host);
DestroyString(Type);
DestroyString(Login);
DestroyString(Tempstr);
DestroyString(Password);
DestroyString(RefreshToken);

return(FS);
}
Exemple #23
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);
}
Exemple #24
0
void HMACSetup(HashratCtx *Ctx)
{
char *Tempstr=NULL, *ptr;
STREAM *S;

  ptr=GetVar(Ctx->Vars,"EncryptionKey");
  if (StrLen(ptr)==0)
  {
    if (isatty(0))
    {
      write(1, "Enter HMAC Key: ",16);

      S=STREAMFromFD(0);
      Tempstr=STREAMReadLine(Tempstr,S);
      StripTrailingWhitespace(Tempstr);
      SetVar(Ctx->Vars,"EncryptionKey",Tempstr);
      ptr=Tempstr;
      STREAMDisassociateFromFD(S);
    }

    //By now we must have an encryption key!
    if (! StrLen(ptr))
    {
      write(1,"ERROR: No HMAC Key given!\n",27);
      exit(2);
    }
  }
DestroyString(Tempstr);
}
Exemple #25
0
void SendToProxy(TSession *Session, char *Command, char *Arg)
{
char *Tempstr=NULL;

Tempstr=CopyStr(Tempstr,Command);
if (StrLen(Arg) > 0)
{
  Tempstr=CatStr(Tempstr," ");
  Tempstr=CatStr(Tempstr,Arg);
}
Tempstr=CatStr(Tempstr,"\r\n");
STREAMWriteLine(Tempstr,Session->ProxySock);
STREAMFlush(Session->ProxySock);

do
{
   Tempstr=STREAMReadLine(Tempstr,Session->ProxySock);
	StripTrailingWhitespace(Tempstr);
   SendLoggedLine(Session,Tempstr);
} while ( (Tempstr[3]=='-') || (isspace(Tempstr[0])) );

STREAMFlush(Session->ProxySock);
STREAMFlush(Session->ClientSock);
DestroyString(Tempstr);
}
Exemple #26
0
char *SMTPRead(char *RetStr, STREAM *S)
{
    char *Tempstr=NULL;

    RetStr=CopyStr(RetStr, "");
    Tempstr=STREAMReadLine(Tempstr, S);
    while (StrLen(Tempstr) > 3)
    {
        RetStr=CatStr(RetStr,Tempstr);
        if (Tempstr[3] == ' ') break;
        Tempstr=STREAMReadLine(Tempstr, S);
    }

    DestroyString(Tempstr);
    return(RetStr);
}
Exemple #27
0
int DownloadToTermStr(STREAM *Connection, STREAM *SaveFile, char *TermStr)
{
    char *Tempstr=NULL;

    Tempstr=STREAMReadLine(Tempstr,Connection);
    while (Tempstr)
    {
        if (strcmp(Tempstr,TermStr)==0)
        {
            break;
        }
        STREAMWriteLine(Tempstr,SaveFile);
        Tempstr=STREAMReadLine(Tempstr,Connection);
    }
    return(TRUE);
}
Exemple #28
0
int OAuthConnectBack(OAUTH *Ctx, int sock)
{
    int result;
    char *Tempstr=NULL, *Token=NULL;
    const char *ptr, *tptr;
    STREAM *S;

    result=IPServerAccept(sock, NULL);
    if (result > -1)
    {
        S=STREAMFromFD(result);
        Tempstr=STREAMReadLine(Tempstr, S);

        if (Tempstr)
        {
            //GET (or possibly POST)
            ptr=GetToken(Tempstr,"\\S", &Token,0);
            //URL
            ptr=GetToken(ptr,"\\S", &Token,0);
            if (ptr) 
						{
							tptr=strchr(Token, '?');
							if (tptr) tptr++;
							else tptr=Token;
							OAuthParseReply(Ctx, "application/x-www-form-urlencoded", tptr);
						}


            while (Tempstr)
            {
                StripTrailingWhitespace(Tempstr);
                if (StrLen(Tempstr) ==0) break;
                Tempstr=STREAMReadLine(Tempstr, S);
            }
        }

        Tempstr=MCopyStr(Tempstr, "HTTP/1.0 200 OK\r\nContent-Type: text/html\r\nConnection: close\r\n\r\n",GetVar(Ctx->Vars,"connect_back_page"),NULL);
        STREAMWriteLine(Tempstr, S);
        STREAMClose(S);
    }

    DestroyString(Tempstr);
    DestroyString(Token);
    if (result > -1) return(TRUE);
    return(FALSE);
}
Exemple #29
0
int DownloadASX(char *URL, char *Title, int Flags)
{
char *Tempstr=NULL, *Token=NULL, *ptr;
int Port=0, len=0;
int RetVal=FALSE;
STREAM *Con=NULL;
ListNode *Items;

if (Flags & FLAG_DEBUG) fprintf(stderr,"ASX STREAM: %s\n",URL);

Items=ListCreate();
Con=ConnectAndRetryUntilDownload(URL, 0, 0);
if (Con)
{
Tempstr=STREAMReadLine(Tempstr,Con);
while (Tempstr)
{
StripTrailingWhitespace(Tempstr);
StripLeadingWhitespace(Tempstr);

  if (Flags & (FLAG_DEBUG2 | FLAG_DEBUG3)) fprintf(stderr,"%s\n",Tempstr);
	if (StrLen(Tempstr) && (strncasecmp(Tempstr,"<Ref href",9)==0))
	{
		ptr=GetToken(Tempstr,"=",&Token,0);
		while (isspace(*ptr)) ptr++;
		if (*ptr=='"') ptr++;
		ptr=GetToken(ptr,"\"",&Token,0);

		ListAddItem(Items,CopyStr(NULL,Token));
	}

Tempstr=STREAMReadLine(Tempstr,Con);
}

STREAMClose(Con);

RetVal=DownloadStream(URL, Title, Items, Flags);
}
	
ListDestroy(Items,DestroyString);
DestroyString(Tempstr);


return(RetVal);
}
Exemple #30
0
int UploadReadMultipartHeaders(STREAM *S, char **Field, char **FileName)
{
char *Tempstr=NULL, *Name=NULL, *Value=NULL, *ptr;
int result=FALSE;

Tempstr=STREAMReadLine(Tempstr,S);
while (StrLen(Tempstr))
{
StripTrailingWhitespace(Tempstr);
ptr=GetToken(Tempstr,":",&Name,0);

if (strcasecmp(Name,"Content-Disposition")==0)
{
	ptr=GetNameValuePair(ptr,";","=",&Name,&Value);
	while (ptr)
	{
		StripLeadingWhitespace(Name);
		StripTrailingWhitespace(Name);
		StripLeadingWhitespace(Value);
		StripTrailingWhitespace(Value);
	if (strcasecmp(Name,"name")==0) 
	{
		*Field=CopyStr(*Field,Value);
		result=TRUE;
	}

	if (strcasecmp(Name,"filename")==0) 
	{
		*FileName=CopyStr(*FileName,Value);
		result=TRUE;
	}
	ptr=GetNameValuePair(ptr,";","=",&Name,&Value);
	}
}
Tempstr=STREAMReadLine(Tempstr,S);
StripTrailingWhitespace(Tempstr);
}

DestroyString(Tempstr);
DestroyString(Name);
DestroyString(Value);

return(result);
}