Exemplo n.º 1
0
char *PadStr(char*Dest, char Pad, int PadLen)
{
char *NewStr=NULL;
int i, len, abslen;

if (PadLen==0) return(Dest);
if (PadLen < 0) abslen=0-PadLen;
else abslen=PadLen;

for (i=0; i < abslen; i++) NewStr=AddCharToBuffer(NewStr,i,Pad);

if (PadLen > 0) 
{
	Dest=(CatStr(Dest, NewStr));
  DestroyString(NewStr);
}
//Negative values mean pad in front of text
else 
{
  NewStr=CatStr(NewStr,Dest);
  //NewStr is the replacement for Dest, so we destroy Dest
  DestroyString(Dest);
	Dest=NewStr;
}

return(Dest);
}
Exemplo n.º 2
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);
}
Exemplo n.º 3
0
char *HTMLQuote(char *RetBuff, char *Str)
{
char *RetStr=NULL, *Token=NULL, *ptr;
int len;

RetStr=CopyStr(RetStr,"");
len=StrLen(Str);

for (ptr=Str; ptr < (Str+len); ptr++)
{

switch (*ptr)
{
case '&': RetStr=CatStr(RetStr,"&amp;"); break;
case '<': RetStr=CatStr(RetStr,"&lt;"); break;
case '>': RetStr=CatStr(RetStr,"&gt;"); break;

default:
		 RetStr=AddCharToStr(RetStr,*ptr); 
break; 
}

}

DestroyString(Token);
return(RetStr);
}
Exemplo n.º 4
0
void PostProcessSettings(TSettings *Settings)
{
char *Tempstr=NULL, *Token=NULL, *ptr;

if (StrLen(Settings->DefaultUser)==0) Settings->DefaultUser=CopyStr(Settings->DefaultUser,GetDefaultUser());

Tempstr=CopyStr(Tempstr,"");
ptr=GetToken(Settings->HttpMethods,",",&Token,0);
while (ptr)
{
if (strcmp(Token,"BASE")==0) Tempstr=CatStr(Tempstr,"GET,POST,HEAD,OPTIONS,");
else if (strcmp(Token,"DAV")==0) Tempstr=CatStr(Tempstr,"GET,POST,HEAD,OPTIONS,DELETE,MKCOL,MOVE,COPY,PUT,PROPFIND,PROPPATCH,");
else if (strcmp(Token,"PROXY")==0) Tempstr=CatStr(Tempstr,"CONNECT,RGET,RPOST");
else Tempstr=MCatStr(Tempstr,Token,",",NULL);

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

Settings->HttpMethods=CopyStr(Settings->HttpMethods,Tempstr);

AuthenticateExamineMethods(Settings->AuthMethods, TRUE);

if (Settings->Port < 1)
{
  if (Settings->Flags & FLAG_SSL) Settings->Port=443;
  else Settings->Port=80;
}

DestroyString(Tempstr);
DestroyString(Token);
}
Exemplo n.º 5
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.º 6
0
void HTTPServerSendM3U(STREAM *S, HTTPSession *Session, char *Path, int NoOfFiles, TPathItem **Files)
{
char *Tempstr=NULL, *M3U=NULL, *URL=NULL, *Salt=NULL, *AccessToken=NULL, *ptr;
ListNode *Vars;
STREAM *F;
int i;

M3U=CopyStr(M3U,"#EXTM3U\n");

for (i=0; i < NoOfFiles; i++)
{
	if (InFileTypeList(Files[i]->Path,Settings.M3UFileTypes))
	{

		//Examine file for Artist/title information
		Vars=ListCreate();
		F=STREAMOpenFile(Files[i]->Path, SF_RDONLY);
		if (F) 
		{
			MediaReadDetails(F, Vars);
			STREAMClose(F);
		}
		ptr=GetVar(Vars, "Media-title");
		if (StrLen(ptr))
		{
			//#EXTINF - extra info - length (seconds), title
			Tempstr=CopyStr(Tempstr, GetVar(Vars, "Media-artist"));
			if (! StrLen(Tempstr)) Tempstr=CopyStr(Tempstr,"unknown-artist");
			M3U=MCatStr(M3U,"#EXTINF: -1, ", Tempstr, "-", GetVar(Vars,"Media-title"),"\n",NULL);
		}

		//Actually supply the URL
		M3U=CatStr(M3U,Files[i]->URL);

		//if we are supporting access token authentication, supply that
		if (AuthenticateExamineMethods(Settings.AuthMethods, FALSE) & AUTH_ACCESSTOKEN)
		{
			GenerateRandomBytes(&Salt,24,ENCODE_HEX);
			AccessToken=MakeAccessToken(AccessToken, Session->UserName, Salt, Session->ClientIP, Files[i]->URL);
			M3U=MCatStr(M3U,"?AccessToken=",AccessToken,NULL);
		}
		ListDestroy(Vars,DestroyString);
		M3U=CatStr(M3U,"\n");
	}	
}

Tempstr=MCopyStr(Tempstr,Path,".m3u",NULL);
SetVar(Session->Headers,"Content-disposition",Tempstr);
HTTPServerSendResponse(S, Session, "200 OK","audio/x-mpegurl",M3U);

DestroyString(AccessToken);
DestroyString(Tempstr);
DestroyString(Salt);
DestroyString(URL);
DestroyString(M3U);
}
Exemplo n.º 7
0
char *ParseVar(char *Buff, const char **Line, ListNode *LocalVars, int Flags)
{
char *VarName=NULL, *OutStr=NULL, *Tempstr=NULL;
const char *ptr, *vptr;

OutStr=Buff;
ptr=*Line;

if (*ptr=='(') ptr++;

	while ((*ptr !=')') && (*ptr !='\0'))
	{
		if (*ptr=='$') 
		{
			ptr++;
			Tempstr=ParseVar(Tempstr,&ptr,LocalVars,Flags);
			VarName=CatStr(VarName,Tempstr);
		}
		 else VarName=AddCharToStr(VarName,*ptr);
	 ptr++;
	}

*Line=ptr; //very important! Otherwise the calling process will not 
	   //know we have consumed some of the text!

	//Now lookup var/format/append to output
	if (! (Flags & SUBS_CASE_VARNAMES)) strlwr(VarName);

	vptr=GetVar(LocalVars,VarName);

	if (Flags & SUBS_QUOTE_VARS) OutStr=CatStr(OutStr,"'");

	if (Flags & SUBS_STRIP_VARS_WHITESPACE) 
	{
		Tempstr=CopyStr(Tempstr,vptr);
		StripTrailingWhitespace(Tempstr);
		StripLeadingWhitespace(Tempstr);
   	OutStr=CatStr(OutStr,Tempstr);
	}
  else OutStr=CatStr(OutStr, vptr);

	if (Flags & SUBS_QUOTE_VARS) OutStr=CatStr(OutStr,"'");

DestroyString(VarName);
DestroyString(Tempstr);

return(OutStr);
}
Exemplo n.º 8
0
char *FormatURL(char *Buff, HTTPSession *Session, const char *ItemPath)
{
char *Tempstr=NULL, *Quoted=NULL;
const char *ptr=NULL, *sd_ptr;
int len;

if (StrLen(Session->Host))
{
if (Settings.Flags & FLAG_SSL) Tempstr=MCopyStr(Buff,"https://",Session->Host,"/",NULL);
else Tempstr=MCopyStr(Buff,"http://",Session->Host,"/",NULL);
}
else Tempstr=CopyStr(Tempstr,"/");

ptr=ItemPath;
while (*ptr == '/') ptr++;

if (StrLen(Session->StartDir)) sd_ptr=Session->StartDir;
else sd_ptr="";

while (*sd_ptr == '/') sd_ptr++;

len=StrLen(sd_ptr);

if (strncmp(ptr, sd_ptr,len)==0) ptr+=len;
Quoted=HTTPQuoteChars(Quoted,ptr," ()[]{}\t?&%!,+\':;#");

Tempstr=CatStr(Tempstr,Quoted);

DestroyString(Quoted);
return(Tempstr);
}
Exemplo n.º 9
0
int AuthPasswdFile(TSession *Session)
{
struct passwd *pass_struct;
char *ptr;

AuthenticationsTried=CatStr(AuthenticationsTried,"passwd ");
pass_struct=getpwnam(Session->User);
if (pass_struct==NULL) return(USER_UNKNOWN);

#ifdef HAVE_LIBCRYPT

if (pass_struct->pw_passwd && Session->Passwd)
{
	ptr=crypt(Session->Passwd,pass_struct->pw_passwd);
	if (ptr && (strcmp(pass_struct->pw_passwd, ptr)==0))
	{
		Session->RealUser=CopyStr(Session->RealUser,Session->User);
		Session->HomeDir=CopyStr(Session->HomeDir,pass_struct->pw_passwd);
		return(TRUE);
	}
}

#endif

return(FALSE);
}
Exemplo n.º 10
0
int AuthPAM(TSession *Session)
{
int result;

AuthenticationsTried=CatStr(AuthenticationsTried,"pam ");


if(! PAMStart(Session, Session->User))
	{
		LogToFile(Settings.ServerLogPath,"PAM: No such user %s",Session->User);
  	return(USER_UNKNOWN);
	}

/* set the credentials for the remote user and remote host */

result=pam_authenticate(pamh,0);


if (result==PAM_SUCCESS)
{
	Session->Flags |= SESSION_PAM;
	Session->RealUser=CopyStr(Session->RealUser,Session->User);
	return(TRUE);
}
else return(FALSE);
}
Exemplo n.º 11
0
int OAuthSave(OAUTH *Ctx, const char *Path)
{
    STREAM *S;
    const char *Fields[]= {"client_id","client_secret","access_token","refresh_token",NULL};
    const char *ptr;
    char *Tempstr=NULL;
    int i;

    if (! StrValid(Path))
    {
        if (! StrValid(Ctx->SavePath)) return(FALSE);
        S=STREAMOpen(Ctx->SavePath,"aEL");
    }
    else S=STREAMOpen(Path,"aEL");
    if (S)
    {
        Tempstr=MCopyStr(Tempstr, "'", Ctx->Name,"' ",NULL);
        for (i=0; Fields[i] !=NULL; i++)
        {
            ptr=GetVar(Ctx->Vars,Fields[i]);
            if (StrValid(ptr)) Tempstr=MCatStr(Tempstr, Fields[i], "='", ptr, "' ",NULL);
        }
        Tempstr=CatStr(Tempstr,"\n");

        STREAMWriteLine(Tempstr, S);
        STREAMClose(S);
    }

    DestroyString(Tempstr);

    return(TRUE);
}
Exemplo n.º 12
0
int AuthPasswdFile(HTTPSession *Session, char **RealUser, char **HomeDir)
{
struct passwd *pass_struct;
char *ptr;

pass_struct=getpwnam(Session->UserName);
if (pass_struct==NULL) return(USER_UNKNOWN);

#ifdef HAVE_LIBCRYPT

if (
		StrLen(pass_struct->pw_passwd) && 
		StrLen(Session->Password)
	)
{
		ptr=crypt(Session->Password,pass_struct->pw_passwd);
		if (ptr && (strcmp(pass_struct->pw_passwd, ptr)==0) )
		{
			if (Settings.Flags & FLAG_LOG_VERBOSE) LogToFile(Settings.LogPath,"AUTH: UserName '%s' Authenticated via /etc/passwd.",Session->UserName);
			if (RealUser) *RealUser=CopyStr(*RealUser,Session->UserName);
			if (HomeDir) *HomeDir=CopyStr(*HomeDir, pass_struct->pw_dir);
			return(TRUE);
		}
}

AuthenticationsTried=CatStr(AuthenticationsTried,"passwd ");

#endif


return(FALSE);
}
Exemplo n.º 13
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);
}
Exemplo n.º 14
0
char *HTTPQuoteChars(char *RetBuff, char *Str, char *CharList)
{
char *RetStr=NULL, *Token=NULL, *ptr;
int olen=0, ilen;

RetStr=CopyStr(RetStr,"");
ilen=StrLen(Str);

for (ptr=Str; ptr < (Str+ilen); ptr++)
{
if (strchr(CharList,*ptr))
{
		Token=FormatStr(Token,"%%%02X",*ptr); 
		RetStr=CatStr(RetStr,Token);
		olen+=StrLen(Token);
}
else
{
		 RetStr=AddCharToBuffer(RetStr,olen,*ptr); 
		 olen++;
}
}


RetStr[olen]='\0';
DestroyString(Token);
return(RetStr);
}
Exemplo n.º 15
0
int AuthShadowFile(HTTPSession *Session)
{
char *sptr, *eptr, *Salt=NULL, *Digest=NULL;
int result=FALSE;

#ifdef HAVE_SHADOW_H
#include <shadow.h>
struct spwd *pass_struct=NULL;

pass_struct=getspnam(Session->UserName);

if (pass_struct==NULL) return(USER_UNKNOWN);

sptr=pass_struct->sp_pwdp;

#ifdef HAVE_LIBCRYPT

// this is an md5 password
if (
	(StrLen(sptr) > 4) && 
	(strncmp(sptr,"$1$",3)==0)
   )
{
	eptr=strchr(sptr+3,'$');
  Salt=CopyStrLen(Salt,sptr,eptr-sptr);

  Digest=CopyStr(Digest, crypt(Session->Password,Salt));
  if (sptr && (strcmp(Digest,sptr)==0) )
	{
		result=TRUE;
	}
}
else
{
   // assume old des crypt password

   sptr=crypt(Session->Password,pass_struct->sp_pwdp);
   if (sptr && (strcmp(pass_struct->sp_pwdp, sptr)==0))
   {
      result=TRUE;
   }
}

AuthenticationsTried=CatStr(AuthenticationsTried,"shadow ");

#endif

if (result && (Settings.Flags & FLAG_LOG_VERBOSE)) 
{
	LogToFile(Settings.LogPath,"AUTH: UserName '%s' Authenticated via /etc/shadow.",Session->UserName);
}

#endif
DestroyString(Salt);
DestroyString(Digest);

return(result);
}
Exemplo n.º 16
0
int AuthShadowFile(TSession *Session)
{
char *sptr, *eptr, *Salt=NULL, *Digest=NULL;
int result=FALSE;

#ifdef HAVE_SHADOW_H
#include <shadow.h>
struct spwd *pass_struct=NULL;

AuthenticationsTried=CatStr(AuthenticationsTried,"shadow ");
pass_struct=getspnam(Session->User);

if (pass_struct==NULL) return(USER_UNKNOWN);

sptr=pass_struct->sp_pwdp;

#ifdef HAVE_LIBCRYPT

// this is an md5 password
if (
	(StrLen(sptr) > 4) && 
	(strncmp(sptr,"$1$",3)==0)
   )
{
	eptr=strchr(sptr+3,'$');
  Salt=CopyStrLen(Salt,sptr,eptr-sptr);

  Digest=CopyStr(Digest, crypt(Session->Passwd,Salt));
  if (strcmp(Digest,sptr)==0) 
	{
		result=TRUE;
	}
}
else
{
   // assume old des crypt password
   if (Session->Passwd)
   {
   sptr=crypt(Session->Passwd,pass_struct->sp_pwdp);
   if (sptr && (strcmp(pass_struct->sp_pwdp, sptr)==0))
   {
      result=TRUE;
   }
	}
}


#endif

if (result) Session->RealUser=CopyStr(Session->RealUser,Session->User);

#endif
DestroyString(Salt);
DestroyString(Digest);

return(result);
}
Exemplo n.º 17
0
char *AddCharToStr(char *Dest,char Src)
{
char temp[2];
char *ptr=NULL;

temp[0]=Src;
temp[1]=0;
ptr=CatStr(Dest,temp);
return(ptr);
}
Exemplo n.º 18
0
void VPathHandleFilePath(STREAM *S,HTTPSession *Session, TPathItem *VPath, int SendData)
{
char *Tempstr=NULL, *ptr;
char *LocalPath=NULL, *ExternalPath=NULL, *DocName=NULL;

//Document name here is whatever part of the Path is *beyond* the VPath component
DocName=HTTPServerSubstituteArgs(DocName, Session->Path+StrLen(VPath->URL), Session);


ptr=GetToken(VPath->Path,":",&Tempstr,0);
while (ptr)
{
	if (*Tempstr=='/') ExternalPath=MCatStr(ExternalPath,Tempstr,":",NULL);
	else 
	{
		if (StrLen(Tempstr)==0) LocalPath=CatStr(LocalPath,"/:");
		else LocalPath=MCatStr(LocalPath,Tempstr,":",NULL);
	}
	ptr=GetToken(ptr,":",&Tempstr,0);
}

Tempstr=CopyStr(Tempstr,"");
if (StrLen(LocalPath)) Tempstr=FindFileInPath(Tempstr,DocName,LocalPath);

if (StrLen(Tempstr)) HTTPServerSendDocument(S, Session, Tempstr, HEADERS_SENDFILE|HEADERS_USECACHE|HEADERS_KEEPALIVE);
else if (StrLen(ExternalPath))
{
	if (strcmp(Session->Method,"POST")==0)
	{
		if (VPath->Flags & PATHITEM_UPLOAD)
		{
		LogToFile(Settings.LogPath,"%s@%s (%s) uploading to %s in VPATH %s", Session->UserName,Session->ClientHost,Session->ClientIP,DocName,ExternalPath);
		ChrootProcessRequest(S, Session, "POST", DocName, ExternalPath);
		}
		else 
		{
			LogToFile(Settings.LogPath,"%s@%s (%s) uploading DENIED to %s in VPATH %s", Session->UserName,Session->ClientHost,Session->ClientIP,DocName,ExternalPath);
			HTTPServerSendHTML(S, Session, "403 Forbidden","Uploads not allowed to this path.");
		}
	}
	else
	{
	LogToFile(Settings.LogPath,"%s@%s (%s) asking for external document %s in Search path %s", Session->UserName,Session->ClientHost,Session->ClientIP,DocName,ExternalPath);
	ChrootProcessRequest(S, Session, "GETF", DocName, ExternalPath);
	}
}
//This will send '404'
else HTTPServerSendDocument(S, Session, DocName, HEADERS_SENDFILE|HEADERS_USECACHE|HEADERS_KEEPALIVE);

DestroyString(DocName);
DestroyString(Tempstr);
DestroyString(LocalPath);
DestroyString(ExternalPath);
}
Exemplo n.º 19
0
char *CatStrLen(char *Dest, const char *Src,size_t len)
{
char *ptr;
size_t catlen=0;

catlen=StrLen(Dest);
ptr=CatStr(Dest,Src);
catlen+=len;
if (StrLen(ptr) > catlen) ptr[catlen]=0;
return(ptr);
}
Exemplo n.º 20
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);
}
Exemplo n.º 21
0
char *FinalizeDirListHTML(char *Buffer, HTTPSession *Session, const char *Path, const char *DirItemsHtml, const char *MimeIconsURL, int Flags)
{
char *HTML=NULL;

	HTML=FormatStr(Buffer,"<html>\r\n<head><title>/%s%s</title></head>\r\n<body>\r\n",Session->Host, Session->URL);

	if ((Flags & DIR_FANCY))
	{
		if (Flags & DIR_INTERACTIVE) HTML=CatStr(HTML,"<form>\r\n");

		HTML=CatStr(HTML,"<table align=center border=0><tr>\n");
		if (Settings.Flags & FLAG_SSL) HTML=MCatStr(HTML,"<td><font color=green size=-1>SECURE<br/>",Session->Cipher,"</font></td>\n",NULL);
		else HTML=MCatStr(HTML,"<td><font color=red size=-1>Unencrypted<br/>Connection</font></td>\n",NULL);

		HTML=MCatStr(HTML,"<td><b>",Session->URL,"</b> at ",Session->Host, " <i>",GetDateStrFromSecs("%Y/%m/%d %H:%M:%S",Now,NULL),"</i><br/>",NULL);

		HTML=DisplayDirActions(HTML,Session,Flags);
		HTML=CatStr(HTML,"</td>\n");


		HTML=MCatStr(HTML,"<td>User: "******"<br/>",NULL);
		if (Settings.Flags & FLAG_LOGOUT_AVAILABLE) HTML=MCatStr(HTML,"<a href=\"",GetLogoutPath(),"\">( Logout )</a>",NULL);
		HTML=CatStr(HTML,"</td></tr></table>\n");
	}
	HTML=MCatStr(HTML,DirItemsHtml,"<br />&nbsp;<br />",NULL);
	if (Flags & DIR_INTERACTIVE) HTML=CatStr(HTML,"</form>\r\n");
	HTML=CatStr(HTML,"</body></html>\r\n");

return(HTML);
}
Exemplo n.º 22
0
char *HTTPQuote(char *RetBuff, char *Str)
{
char *RetStr=NULL, *Token=NULL, *ptr;
int olen=0, ilen;

RetStr=CopyStr(RetStr,"");
ilen=StrLen(Str);

for (ptr=Str; ptr < (Str+ilen); ptr++)
{
switch (*ptr)
{
		case ' ':
			RetStr=AddCharToStr(RetStr,'+');
		break;

		case '(':
		case ')':
		case '[':
		case ']':
		case '{':
		case '}':
		case '\t':
		case '?':
		case '&':
		case '!':
		case ',':
		case '+':
		case '\'':
		case ':':
		case ';':
		case '/':
		case '\r':
		case '\n':
		Token=FormatStr(Token,"%%%02X",*ptr); 
		RetStr=CatStr(RetStr,Token);
		olen+=StrLen(Token);
		break;

		default:
	//	 RetStr=AddCharToBuffer(RetStr,olen,*ptr); 
		 RetStr=AddCharToStr(RetStr,*ptr); 
		 olen++;
		break;
}

}

DestroyString(Token);
return(RetStr);
}
Exemplo n.º 23
0
void DisplayTransferStatus(char *Line, unsigned int transferred, unsigned int total, unsigned int *percent, unsigned int secs,int CmdFlags, int Throttle)
{
int result=0, cols=80, bps=0;
char *Tempstr=NULL, *TimeStr=NULL, *ptr=NULL;
static int ThrotCount=0;
struct winsize w;


	if (Settings.Flags & FLAG_QUIET) return;
	if (CmdFlags & FLAG_QUIET) return;
	if (! isatty(1)) return;

	ptr=getenv("COLUMNS");
	if (ptr) cols=atoi(ptr);
	printf("\r");
	if (total==0) Tempstr=FormatStr(Tempstr,"%s bytes sent ",GetHumanReadableDataQty(transferred,0));
	else
	{
	result=(transferred * 100) / total;
//	if (result != *percent)
	{
		Tempstr=FormatStr(Tempstr,"%d%% %s of ",result,GetHumanReadableDataQty(transferred,0));
		Tempstr=CatStr(Tempstr,GetHumanReadableDataQty(total,0));
	}
	*percent=result;
	}

bps=transferred / secs;
TimeStr=FormatStr(TimeStr," in %d secs %s Bps ",secs,GetHumanReadableDataQty(bps,0) );

if ((Throttle > 0) && (bps > Throttle)) 
{
	ThrotCount++;
	usleep(ThrotCount * 250000);
}
else if (ThrotCount > 0) ThrotCount--;

if (ThrotCount > 0) Tempstr=MCatStr(Tempstr,TimeStr, Line, " (throttling)      ",NULL);
else Tempstr=MCatStr(Tempstr,TimeStr, Line, "           ",NULL);


ioctl(0, TIOCGWINSZ, &w);
if (StrLen(Tempstr) > w.ws_col) Tempstr[w.ws_col]='\0';

printf("%s",Tempstr);
fflush(NULL);

DestroyString(TimeStr);
DestroyString(Tempstr);
}
Exemplo n.º 24
0
char *AppendCookies(char *InStr, ListNode *CookieList)
{
	ListNode *Curr;
	int count=0;
	char *Tempstr=NULL;

	Tempstr=InStr;
	Curr=ListGetNext(CookieList);

	if (Curr) 
	{
		Tempstr=CatStr(Tempstr,"Cookie: ");
		while ( Curr )
		{
		Tempstr=CatStr(Tempstr,(char *)Curr->Item);
		Curr=ListGetNext(Curr);
		if (Curr) Tempstr=CatStr(Tempstr, "; ");
		}
		Tempstr=CatStr(Tempstr,"\r\n");
	}

return(Tempstr);
}
Exemplo n.º 25
0
void UploadSelectPage(STREAM *S,HTTPSession *Session,char *Path)
{
char *HTML=NULL, *Tempstr=NULL;
int i;

  HTML=MCopyStr(HTML,"<html>\r\n<head><title>Upload files to: ",Session->URL,"</title></head>\r\n<body><form method=\"post\" enctype=\"multipart/form-data\" action=\"",Session->URL,"\">\r\n",NULL);

  HTML=MCatStr(HTML,"<p align=center>Upload files to: ",Session->URL,"</p>\r\n",NULL);
	HTML=CatStr(HTML,"<table align=center border=0><tr><th bgcolor=#AAAAFF>Select files for upload</th></tr>\r\n");
	for (i=0; i < 10; i++)
	{
  Tempstr=FormatStr(Tempstr,"<tr><td><input type=file name=uploadfile:%d></td></tr>\r\n",i);
  HTML=CatStr(HTML,Tempstr);
	}
	HTML=MCatStr(HTML,"<tr><td><input type=submit value=Upload></td></tr></table>\r\n",NULL);

  HTML=MCatStr(HTML,"</form></body></html>\r\n",NULL);

	HTTPServerSendResponse(S, Session, "200 OK","text/html",HTML);

DestroyString(HTML);
DestroyString(Tempstr);
}
Exemplo n.º 26
0
//Sanitize is more than 'Clean', it clears out any HTML string
char *SanitizeStr(char *Buffer, char *Data)
{
char *TagNamespace=NULL, *TagType=NULL, *TagData=NULL, *ptr;
char *RetStr=NULL, *Tempstr=NULL;

ptr=XMLGetTag(Data, &TagNamespace, &TagType, &TagData);
while (ptr)
{
	if (StrLen(TagType)==0) Tempstr=CatStr(Tempstr,TagData);
	else
	{
		if (
				ListFindNamedItem(Settings.SanitizeArgumentsAllowedTags,TagType) ||
				((*TagType=='/') && ListFindNamedItem(Settings.SanitizeArgumentsAllowedTags,TagType+1))
			)
		{
			if (StrLen(TagNamespace)) Tempstr=MCatStr(Tempstr,"<",TagNamespace,":",TagType,NULL);
			else Tempstr=MCatStr(Tempstr,"<",TagType,NULL);
			if (StrLen(TagData)) Tempstr=MCatStr(Tempstr," ",TagData,NULL);
			Tempstr=CatStr(Tempstr,">");
		}
	}


ptr=XMLGetTag(ptr, &TagNamespace, &TagType, &TagData);
}

RetStr=HTTPQuote(Buffer,Tempstr);

DestroyString(TagNamespace);
DestroyString(Tempstr);
DestroyString(TagType);
DestroyString(TagData);


return(RetStr);
}
Exemplo n.º 27
0
pid_t HandleResolveIPRequest(STREAM *ClientCon, char *Data)
{
char *Tempstr=NULL;

//Can't use MCopyStr here because 'LookupHostIP' might return NULL,
//which would be taken as the last of the items in the string list
Tempstr=CopyStr(Tempstr,LookupHostIP(Data));
Tempstr=CatStr(Tempstr,"\n");

STREAMWriteLine(Tempstr,ClientCon);

DestroyString(Tempstr);

return(0);
}
Exemplo n.º 28
0
char *FormatEncryptArgs(char *RetBuff, int Flags, const char *Cipher, const char *Key, const char *InitVector, const char *Salt )
{
char *EncryptArgs=NULL, *Tempstr=NULL;

EncryptArgs=CopyStr(RetBuff,"");

EncryptArgs=CopyStr(EncryptArgs,"Cipher=");
EncryptArgs=CatStr(EncryptArgs,Cipher);


if (StrLen(Key))
{
if (Flags & FLAG_HEXKEY) Tempstr=FormatStr(Tempstr," hexkey='%s'",Key);
else Tempstr=FormatStr(Tempstr," key='%s'",Key);
EncryptArgs=CatStr(EncryptArgs,Tempstr);
}

if (StrLen(InitVector))
{
if (Flags & FLAG_HEXIV) Tempstr=FormatStr(Tempstr," hexiv='%s'",InitVector);
else Tempstr=FormatStr(Tempstr," iv='%s'",InitVector);
EncryptArgs=CatStr(EncryptArgs,Tempstr);
}

if (StrLen(Salt))
{
if (Flags & FLAG_HEXSALT) Tempstr=FormatStr(Tempstr," hexsalt='%s'",Salt);
else Tempstr=FormatStr(Tempstr," salt='%s'",Salt);
EncryptArgs=CatStr(EncryptArgs,Tempstr);
}


if (Flags & FLAG_NOPAD_DATA) EncryptArgs=CatStr(EncryptArgs," PadBlock=N");

return(EncryptArgs);
}
Exemplo n.º 29
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);
}
Exemplo n.º 30
0
void ESDSendFileData(int ConFD, char *SoundFilePath, int Vol)
{
char *Tempstr=NULL;
int id;

Tempstr=CopyStr(Tempstr,"ColLib:");
Tempstr=CatStr(Tempstr,SoundFilePath);

id=esd_sample_getid(ConFD,Tempstr);
if (id < 0)
{
   id=esd_file_cache(ConFD,"ColLib",SoundFilePath);
}
if (Vol != VOLUME_LEAVEALONE) esd_set_default_sample_pan(ConFD,id,Vol,Vol);
esd_sample_play(ConFD,id);

DestroyString(Tempstr);
}