示例#1
0
int IDriveRenameFile(TFileStore *FS, char *FromArg, char *ToArg)
{
char *Tempstr=NULL, *Error=NULL, *FromPath=NULL, *ToPath=NULL;
HTTPInfoStruct *Info;
ListNode *Headers;
int result, val;
STREAM *S;


FromPath=MakeFullPath(FromPath,FS, FromArg);
ToPath=MakeFullPath(ToPath,FS, ToArg);

Tempstr=MCopyStr(Tempstr,"https://",FS->Host,"/evs/renameFileFolder?uid=",FS->Logon,"&pwd=",FS->Passwd,"&oldpath=",FromPath,"&newpath=",ToPath,NULL);
S=HTTPMethod("POST",Tempstr,"","","","",0);

val=HTTPReadDocument(S, &Tempstr);
if (Settings.Flags & FLAG_VERBOSE) printf("\n%s\n",Tempstr);

Error=CopyStr(Error,"");
result=IDriveParseStatusResponse(Tempstr, &Error);

DestroyString(Tempstr);
DestroyString(Error);
DestroyString(FromPath);
DestroyString(ToPath);


return(result);
}
示例#2
0
int CheckNativeFileChallengePassword(char *Challenge, char *Password, char *ProvidedPass)
{
char *Token=NULL, *Digest=NULL, *Tempstr=NULL, *ptr;
int RetVal=FALSE;

	if (strcmp(Password,ProvidedPass)==0) return(TRUE);

	if (! StrLen(Challenge)) return(FALSE);

	ptr=GetToken(Settings.AuthMethods,",",&Token,0);
	while (ptr)
	{
		if (strncmp(Token,"hp-",3)==0)
		{
		Tempstr=MCopyStr(Tempstr,Challenge,Password,NULL);
		HashBytes(&Digest,Token+3,Tempstr,StrLen(Tempstr),ENCODE_HEX);
		if (StrLen(Digest) && (strcasecmp(ProvidedPass, Digest)==0)) RetVal=TRUE;
		}
	ptr=GetToken(ptr,",",&Token,0);
	}

	DestroyString(Tempstr);
	DestroyString(Digest);
	DestroyString(Token);
	return(RetVal);
}
示例#3
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);
}
示例#4
0
char *FindFileInPath(char *InBuff, const char *File, const char *Path)
{
char *Tempstr=NULL, *CurrPath=NULL, *RetStr=NULL, *ptr;

RetStr=CopyStr(InBuff,"");

if (*File=='/')
{
	CurrPath=CopyStr(CurrPath,"");
	ptr=""; //so we execute once below
}
else ptr=GetToken(Path,":",&CurrPath,0);

while (ptr)
{
CurrPath=SlashTerminateDirectoryPath(CurrPath);
Tempstr=MCopyStr(Tempstr,CurrPath,File,NULL);
if (access(Tempstr,F_OK)==0) 
{
RetStr=CopyStr(RetStr,Tempstr);
break;
}

ptr=GetToken(ptr,":",&CurrPath,0);
}

DestroyString(Tempstr);
DestroyString(CurrPath);

return(RetStr);
}
示例#5
0
int FindFilesInPath(const char *File, const char *Path, ListNode *Files)
{
char *Tempstr=NULL, *CurrPath=NULL, *ptr;
int i;
glob_t Glob;

if (*File=='/')
{
	CurrPath=CopyStr(CurrPath,"");
	ptr=""; //so we execute once below
}
else ptr=GetToken(Path,":",&CurrPath,0);
while (ptr)
{
CurrPath=SlashTerminateDirectoryPath(CurrPath);
Tempstr=MCopyStr(Tempstr,CurrPath,File,NULL);

glob(Tempstr,0,0,&Glob);
for (i=0; i < Glob.gl_pathc; i++) ListAddItem(Files,CopyStr(NULL,Glob.gl_pathv[i]));
globfree(&Glob);

ptr=GetToken(ptr,":",&CurrPath,0);
}

DestroyString(Tempstr);
DestroyString(CurrPath);

return(ListSize(Files));
}
示例#6
0
OAUTH *OAuthCreate(const char *Type, const char *Name, const char *ClientID, const char *ClientSecret, const char *Scopes, const char *RefreshURL)
{
    OAUTH *Ctx;
    char *Tempstr=NULL, *Token=NULL;
    const char *ptr;

    if (OAuthTypes==NULL) SetupOAuthTypes();
    ptr=GetVar(OAuthTypes, Type);
    if (! StrValid(ptr)) return(NULL);

    Ctx=(OAUTH *) calloc(1,sizeof(OAUTH));

    ptr=GetToken(ptr,",",&(Ctx->Stage1), 0);
    ptr=GetToken(ptr,",",&(Ctx->Stage2), 0);
    ptr=GetToken(ptr,",",&(Ctx->VerifyTemplate), 0);
    Ctx->Name=CopyStr(Ctx->Name, Name);
    Ctx->Vars=ListCreate();
    SetVar(Ctx->Vars,"client_name",ClientID);
    SetVar(Ctx->Vars,"client_id",ClientID);
    SetVar(Ctx->Vars,"client_secret",ClientSecret);
    Tempstr=HTTPQuote(Tempstr, Scopes);
    SetVar(Ctx->Vars,"scope",Tempstr);
    SetVar(Ctx->Vars,"redirect_uri","urn:ietf:wg:oauth:2.0:oob");
    SetVar(Ctx->Vars,"connect_back_page","<html><body><h1>Code Accepted By Application</h1><body></html>");
    Ctx->AccessToken=CopyStr(Ctx->AccessToken, "");
    Ctx->RefreshToken=CopyStr(Ctx->RefreshToken, "");
    Ctx->RefreshURL=CopyStr(Ctx->RefreshURL, RefreshURL);
    Ctx->SavePath=MCopyStr(Ctx->SavePath, GetCurrUserHomeDir(), "/.oauth.creds",NULL);

    if (strcasecmp(Type, "getpocket.com")==0)
    {
        ptr=GetToken(ClientID,"-",&Token,0);
        Tempstr=MCopyStr(Tempstr, "pocketapp",Token,":authorizationFinished",NULL);
        SetVar(Ctx->Vars, "redirect_uri",Tempstr);

//Ctx->VerifyURL=MCopyStr(Ctx->VerifyURL,"https://getpocket.com/auth/authorize?request_token=",Ctx->AccessToken,"&redirect_uri=",Args,NULL);
    }
    else if (strcasecmp(Type, "implicit")==0) Ctx->Flags |= OAUTH_IMPLICIT;

    if (! OAuthKeyChain) OAuthKeyChain=ListCreate();
    ListAddNamedItem(OAuthKeyChain, Name, Ctx);

    DestroyString(Tempstr);
    DestroyString(Token);
    return(Ctx);
}
示例#7
0
//this shouldn't really be in here, but the decision to launch an player happens in the 'DisplayProgress' function
void LaunchPlayer()
{
char *Tempstr=NULL;

Tempstr=MCopyStr(Tempstr,Player," ",OutputFilesGetFilePath(),NULL);
PlayerPid=Spawn(Tempstr);

DestroyString(Tempstr);
}
示例#8
0
文件: server.c 项目: ColumPaget/Alaya
void HTTPServerSendHeader(STREAM *S, char *Header, char *Value)
{
char *Tempstr=NULL;

Tempstr=MCopyStr(Tempstr,Header,": ",Value,"\r\n",NULL);
STREAMWriteLine(Tempstr,S);
if (Settings.Flags & FLAG_LOG_VERBOSE) LogToFile(Settings.LogPath,">> %s",Tempstr);
DestroyString(Tempstr);
}
示例#9
0
char *ItemCodeFromFileExtension(char *RetBuf, char *Default, char *Path)
{
char *Tempstr=NULL, *RetStr=NULL, *ptr;

Tempstr=CopyStr(Tempstr,Path);
ptr=strrchr(Tempstr,'?');
if (ptr) *ptr='\0';
ptr=strrchr(Tempstr,'.');
if (ptr)
{
ptr++;
RetStr=MCopyStr(RetBuf,"item:",ptr,NULL);
}
else RetStr=MCopyStr(RetBuf,Default);

DestroyString(Tempstr);
return(RetStr);
}
示例#10
0
int SMTPHelo(STREAM *S)
{
    int RetVal=0;
    char *Tempstr=NULL, *Token=NULL;
    const char *ptr;

    ptr=LibUsefulGetValue("SMTP:HELO");
    if (! StrValid(ptr)) ptr=STREAMGetValue(S,"SMTP:HELO");
    if (! StrValid(ptr))
    {
        Token=GetExternalIP(Token);
        ptr=Token;
    }

    Tempstr=MCopyStr(Tempstr, "EHLO ", ptr, "\r\n", NULL);
    STREAMWriteLine(Tempstr,S);
    Tempstr=SMTPRead(Tempstr, S);

    if (*Tempstr == '2')
    {
        RetVal |= CAP_EHLO;
        ptr=GetToken(Tempstr,"\n",&Token,0);
        while (ptr)
        {
            StripTrailingWhitespace(Token);
            RetVal |= SMTPParseCapabilities(Token);
            ptr=GetToken(ptr,"\n",&Token,0);
        }
    }
//Some old server that doesn't support EHLO, switch to HELO
    else
    {
        Tempstr=MCopyStr(Tempstr, "HELO ", ptr, "\r\n", NULL);
        STREAMWriteLine(Tempstr,S);
        if (SMTPInteract(Tempstr, S)) RetVal |= CAP_HELO;
    }




    DestroyString(Tempstr);
    DestroyString(Token);
    return(RetVal);
}
示例#11
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);
}
示例#12
0
void LibUsefulInitSettings()
{
char *Tempstr=NULL;

		LibUsefulSettings=ListCreate();
		SetVar(LibUsefulSettings,"LibUsefulVersion",__LIBUSEFUL_VERSION__);
		Tempstr=MCopyStr(Tempstr,__LIBUSEFUL_BUILD_DATE__," ",__LIBUSEFUL_BUILD_TIME__,NULL);
		SetVar(LibUsefulSettings,"LibUsefulBuildTime",Tempstr);
		DestroyString(Tempstr);
}
示例#13
0
int ProxyHandleFileTransfer(TSession *Session, char *Command, char *Path, int Direction)
{
STREAM *InFile;
int fd, KeepReading;
char *Tempstr=NULL;

Tempstr=MCopyStr(Tempstr,Command," ",Path,"\r\n",NULL);
STREAMWriteLine(Tempstr,Session->ProxySock); 
STREAMFlush(Session->ProxySock);
LogToFile(Settings.LogPath,"PROXY SEND: %s ",Tempstr);
if (! CopyToSock(Session->ProxySock, Session->ClientSock)) return(FALSE);


if (ProxyOpenDataConnection(Session,0)) 
{

	if (OpenDataConnection(Session,0))
	{
		if (Direction==FILE_SEND) SendFileData(Session->Flags & SESSION_ASCII_TRANSFERS,Session->DataConnection->Sock, Session->ProxyDataConnection->Sock,0);
		else
		{
			 SendFileData(Session->Flags & SESSION_ASCII_TRANSFERS,Session->ProxyDataConnection->Sock, Session->DataConnection->Sock,0);
		}
		CloseDataConnection(Session, Session->DataConnection);
  }

  CloseDataConnection(Session, Session->ProxyDataConnection);
  Tempstr=STREAMReadLine(Tempstr,Session->ProxySock);
  STREAMWriteLine(Tempstr,Session->ClientSock);
	STREAMFlush(Session->ClientSock);

  Session->DataConnection=NULL;
  Session->ProxyDataConnection=NULL;
}

/*
//One day will use this instead
LogToFile(Settings.LogPath, "MADE DATA CON");
DataCon->Input=DataCon->Sock;
LogToFile(Settings.LogPath, "ADD LOCAL CON");
DataCon->Output=Session->DataConnection->Sock;
LogToFile(Settings.LogPath, "SET FNAME");
DataCon->FileName=CopyStr(DataCon->FileName,"Proxy");
DataCon->Flags |= DC_RETR;
Session->DataConnection=NULL;
Session->ProxyDataConnection=NULL;
ListAddItem(Session->FileTransfers,DataCon);
*/



DestroyString(Tempstr);

return(TRUE);
}
示例#14
0
文件: common.c 项目: ColumPaget/Alaya
int CopyLocalItem(char *From, char *To)
{
glob_t Glob;
struct stat FStat;
char *Tempstr=NULL, *ptr;
int i,  RetVal=EFAULT;
STREAM *In=NULL, *Out=NULL;

stat(From,&FStat);
if (S_ISDIR(FStat.st_mode))
{
	mkdir(To,FStat.st_mode);
	Tempstr=MCopyStr(Tempstr, From, "/*", NULL);
	glob(Tempstr, 0, 0, &Glob);
	for (i=0; i < Glob.gl_pathc; i++)
	{
		ptr=strrchr(Glob.gl_pathv[i],'/');
		if (! ptr) ptr=Glob.gl_pathv[i];
		Tempstr=MCopyStr(Tempstr, To, ptr, NULL);
		CopyLocalItem(Glob.gl_pathv[i],Tempstr);
	}
	RetVal=0;
	globfree(&Glob);
}
else
{
	In=STREAMOpenFile(From,SF_RDONLY);
	if (In)
	{
		Out=STREAMOpenFile(To, SF_CREAT| SF_WRONLY | SF_TRUNC);
		if (Out) RetVal=STREAMSendFile(In, Out, 0, SENDFILE_KERNEL | SENDFILE_LOOP);
	}
}

//as In and Out are NULL if not opened, it's safe to close them 
//here as STREAMClose will ignore a NULL argument
STREAMClose(In);
STREAMClose(Out);
DestroyString(Tempstr);

return(RetVal);
}
示例#15
0
int FileSystemUnMount(const char *MountPoint, const char *Args)
{
int Flags=UMOUNT_NOFOLLOW;
int ExtraFlags=0;
char *Token=NULL;
const char *ptr;
struct stat FStat;
int i, result;
glob_t Glob;

ptr=GetToken(Args, " |,", &Token, GETTOKEN_MULTI_SEP);
while (ptr)
{
	if (strcmp(Token,"follow")==0) Flags &= ~UMOUNT_NOFOLLOW;
	if (strcmp(Token,"lazy")==0) Flags |= MNT_DETACH;
	if (strcmp(Token,"detach")==0) Flags |= MNT_DETACH;
	if (strcmp(Token,"recurse")==0) ExtraFlags |= UMOUNT_RECURSE;
	if (strcmp(Token,"rmdir")==0) ExtraFlags |= UMOUNT_RMDIR;

ptr=GetToken(ptr, " |,", &Token, GETTOKEN_MULTI_SEP);
}

if (ExtraFlags & UMOUNT_RECURSE)
{
	Token=MCopyStr(Token,MountPoint,"/*",NULL);
	glob(Token, 0, 0, &Glob);
	for (i=0; i < Glob.gl_pathc; i++)
	{
		stat(Glob.gl_pathv[i],&FStat);
		if (S_ISDIR(FStat.st_mode))
		{
			FileSystemUnMount(Glob.gl_pathv[i], Args);	
		}
	}
	globfree(&Glob);
}



#ifdef HAVE_UMOUNT2
result=umount2(MountPoint, Flags);
#elif HAVE_UMOUNT
result=umount(MountPoint);
#elif HAVE_UNMOUNT
result=unmount(MountPoint,0);
#else 
result=-1
#endif

if (ExtraFlags & UMOUNT_RMDIR) rmdir(MountPoint);
DestroyString(Token);

return(result);
}
示例#16
0
int DisplayAvailableFormats(ListNode *Vars, char *Formats, int ShowSize)
{
char *URL=NULL, *Token=NULL, *TokenID=NULL, *Tempstr=NULL, *ptr;
STREAM *S;
int result=TRUE;

fprintf(stderr, "\nFormats available for this Movie: ");

ptr=GetToken(Formats," ",&Token,0);
while (ptr)
{
if (StrLen(Token)) TokenID=MCopyStr(TokenID,"item:",Token,NULL);

URL=CopyStr(URL,GetVar(Vars,TokenID));

if (strcmp(Token,"reference") !=0)
{
	fprintf(stderr,"%s",Token);

	if (ShowSize)
	{
	S=HTTPMethod("HEAD",URL,NULL,NULL);
	if (S)
	{
		Tempstr=CopyStr(Tempstr,STREAMGetValue(S,"HTTP:ResponseCode"));
		if (strcmp(Tempstr,"403") ==0) 
		{
			printf("\nERROR: %s response for %s\n",Tempstr,URL);
			result=FALSE;
			break;
		}
		else if (strcmp(Tempstr,"200")==0)
		{
			Tempstr=CopyStr(Tempstr,STREAMGetValue(S,"HTTP:Content-length"));
			fprintf(stderr, " (%s)",GetHumanReadableDataQty(strtod(Tempstr,NULL),FALSE));
			STREAMClose(S);
		}
	}
	}
}
fprintf(stderr,", ");

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

fprintf(stderr,"\n\n",Tempstr);

DestroyString(Token);
DestroyString(TokenID);
DestroyString(Tempstr);
DestroyString(URL);

return(result);
}
示例#17
0
char *FormatFileType(char *RetStr, TPathItem *File, ListNode *Vars, const char *MimeIconsURL)
{
char *Tempstr=NULL, *URL=NULL, *ptr;
TFileMagic *FM;
ListNode *Curr;
TPathItem *PathItem;

RetStr=CopyStr(RetStr, "???");

//Book a content type against file so that things outside this function can use it
if (File->Type==PATHTYPE_DIR) File->ContentType=CopyStr(File->ContentType, "DIR");
else
{
	FM=GetFileTypeInfo(File->Name);
	if (! FM) File->ContentType=CopyStr(File->ContentType, "FILE");
	else File->ContentType=CopyStr(File->ContentType, FM->ContentType);
}

RetStr=CopyStr(RetStr,File->ContentType);

ptr=GetVar(Vars,"Thumbnail");
if (StrLen(ptr))
{
	RetStr=CopyStr(RetStr, ptr);
}
else if ((Settings.DirListFlags & DIR_MIMEICONS) && MimeIconsURL)
{
	ptr=strrchr(File->Name,'.');
	if (ptr) ptr++;

	if (File->Type==PATHTYPE_DIR) URL=MCopyStr(URL,MimeIconsURL,"?Type=folder&MimeType=inode/directory&FileExtn=",NULL);
	else URL=MCopyStr(URL,MimeIconsURL,"?MimeType=",RetStr,"&FileExtn=",ptr,NULL);
	Tempstr=MCopyStr(Tempstr,"<img src=\"",URL,"\" alt=\"",RetStr,"\">",NULL);
	RetStr=CopyStr(RetStr, Tempstr);
}

DestroyString(Tempstr);
DestroyString(URL);

return(RetStr);
}
示例#18
0
void OAuthInstalledAppURL(char *LoginURL, char *ClientID, char *Scope, char *RedirectURL, char **NextURL)
{
char *Encode=NULL;

Encode=HTTPQuote(Encode,ClientID);
*NextURL=MCopyStr(*NextURL,LoginURL,"?response_type=code&redirect_uri=",RedirectURL,"&client_id=",Encode,NULL);
Encode=HTTPQuote(Encode,Scope);
*NextURL=MCatStr(*NextURL,"&scope=",Encode,NULL);


DestroyString(Encode);
}
示例#19
0
文件: server.c 项目: ColumPaget/Alaya
void HTTPServerHandleAuthHeader(HTTPSession *Heads,int HeaderType, char *Type, char *Data)
{
char *Tempstr=NULL, *Name=NULL, *Value=NULL, *ptr;
char *nonce=NULL, *cnonce=NULL, *request_count=NULL, *qop=NULL, *algo=NULL, *uri=NULL;
int len;

if (strcmp(Type,"Basic")==0)
{
	Tempstr=DecodeBase64(Tempstr, &len, Data);
	ptr=GetToken(Tempstr,":",&Heads->UserName,0);
	Heads->Password=CopyStr(Heads->Password,ptr);
}
else if (strcmp(Type,"Digest")==0)
{
	uri=CopyStr(uri,"");
	algo=CopyStr(algo,"");
	ptr=GetNameValuePair(Data,",","=",&Name,&Value);
	while (ptr)
	{
		if (StrLen(Name) && StrLen(Value))
		{
		StripLeadingWhitespace(Name);
		StripLeadingWhitespace(Value);
		if (strcmp(Name,"username")==0) Heads->UserName=CopyStr(Heads->UserName,Value);
		if (strcmp(Name,"response")==0) Heads->Password=CopyStr(Heads->Password,Value);
		if (strcmp(Name,"nonce")==0) nonce=CopyStr(nonce,Value);
		if (strcmp(Name,"cnonce")==0) cnonce=CopyStr(cnonce,Value);
		if (strcmp(Name,"nc")==0) request_count=CopyStr(request_count,Value);
		if (strcmp(Name,"qop")==0) qop=CopyStr(qop,Value);
		if (strcmp(Name,"uri")==0) uri=CopyStr(uri,Value);
		if (strcmp(Name,"algorithm")==0) algo=CopyStr(algo,Value);
		}
		
	ptr=GetNameValuePair(ptr,",","=",&Name,&Value);
	}

// server nonce (nonce), request counter (nc), client nonce (cnonce), quality of protection code (qop) and HA2 result is calculated. The result is the "response" value provided by the client.

if (StrLen(qop)) Heads->AuthDetails=MCopyStr(Heads->AuthDetails,uri,":",algo,":",nonce,":",request_count,":",cnonce,":",qop, NULL);
else Heads->AuthDetails=CopyStr(Heads->AuthDetails,nonce);

}

DestroyString(qop);
DestroyString(uri);
DestroyString(algo);
DestroyString(Name);
DestroyString(Value);
DestroyString(nonce);
DestroyString(cnonce);
DestroyString(Tempstr);
DestroyString(request_count);
}
示例#20
0
char *ResolveURL(char *RetStr, const char *Parent, const char *SubItem)
{
    char *Proto=NULL, *Host=NULL, *Port=NULL, *Path=NULL;
    char *BasePath=NULL;

    ParseURL(Parent,&Proto,&Host,&Port,NULL,NULL,&Path,NULL);
    if (StrValid(Port)) BasePath=FormatStr(BasePath, "%s://%s:%s/", Proto,Host,Port);
    else BasePath=FormatStr(BasePath, "%s://%s/", Proto,Host);

//if it starts with '/' then we don't append to existing path
    if (*SubItem=='/') RetStr=MCopyStr(RetStr, BasePath, SubItem, NULL);
    else RetStr=MCopyStr(RetStr, BasePath, Path, "/", SubItem, NULL);

    DestroyString(Proto);
    DestroyString(Host);
    DestroyString(Port);
    DestroyString(Path);
    DestroyString(BasePath);

    return(RetStr);
}
示例#21
0
// PAM entry point for authentication. This function gets called by pam when
//a login occurs. argc and argv work just like argc and argv for the 'main' 
//function of programs, except they pass in the options defined for this
//module in the pam configuration files in /etc/pam.conf or /etc/pam.d/
PAM_EXTERN int pam_sm_authenticate(pam_handle_t *pamh, int flags, int argc, const char **argv) 
{
	char *Tempstr=NULL, *KeyList=NULL;
	char *ActiveUSBKeys=NULL;
	const char *ptr;
	int result=PAM_IGNORE, i;

	//These are defined as 'const char' because they passwd to us from the parent
	//library. When we called pam_get_<whatever> the pam library passes pointers
	//to strings in it's own code. Thus we must not change or free them
	const char *pam_user = NULL, *pam_tty=NULL, *pam_rhost=NULL;

	//get the user. If something goes wrong we return PAM_IGNORE. This tells
	//pam that our module failed in some way, so ignore it. Perhaps we should
	//return PAM_PERM_DENIED to deny login, but this runs the risk of a broken
	//module preventing anyone from logging into the system!
	if (pam_get_user(pamh, &pam_user, NULL) != PAM_SUCCESS) return(PAM_IGNORE);
	if (pam_user == NULL) return(PAM_IGNORE);

	//perhaps there will not be a tty if we are logging in remotely
	pam_get_item(pamh, PAM_TTY, (const void **) &pam_tty);
	if (! pam_tty) pam_tty="";

	//perhaps there will not be a remote host if we are logging in locally
	pam_get_item(pamh, PAM_RHOST, (const void **) &pam_rhost);
	if (! pam_rhost) pam_rhost="";


	for (i=0; i < argc; i++)
	{
		ptr=argv[i];

		if (strncmp(ptr,"key=",4)==0)   Tempstr=MCatStr(Tempstr, ptr, " ", NULL);
		if (strncmp(ptr,"keys=",5)==0)  Tempstr=MCatStr(Tempstr, ptr, " ", NULL);
		if (strncmp(ptr,"tty=",4)==0)   Tempstr=MCatStr(Tempstr, ptr, " ", NULL);
		if (strncmp(ptr,"ttys=",5)==0)  Tempstr=MCatStr(Tempstr, ptr, " ", NULL);
		if (strncmp(ptr,"user="******" ", NULL);
		if (strncmp(ptr,"users=",6)==0) Tempstr=MCatStr(Tempstr, ptr, " ", NULL);
	}

	if (StrLen(Tempstr)) KeyList=MCopyStr(KeyList, Tempstr, "|", NULL);


	ActiveUSBKeys=LoadActiveUSBSerialNums(ActiveUSBKeys);
	result=CheckAuth(KeyList, ActiveUSBKeys, pam_user, pam_tty, pam_rhost);

	Destroy(ActiveUSBKeys);
	Destroy(Tempstr);
	Destroy(KeyList);

  return(result);
}
示例#22
0
void HandleDecryptionHeader(STREAM *S, const char *Header, const char *Key)
{
const char *ptr;
char *Tempstr=NULL;

ptr=Header;
if (strncmp(ptr,"ENCR ",5)==0) ptr+=5;
Tempstr=MCopyStr(Tempstr,ptr," key='",Key,"'",NULL);

fprintf(stderr,"SASDP: [%s]\n",Tempstr);
STREAMAddStandardDataProcessor(S,"crypto","",Tempstr);
DestroyString(Tempstr);
}
示例#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);
}
示例#24
0
void ParseURL(char *URL, char **Proto, char **Host, char **Port, char **User, char **Password, char **Path, char **Args)
{
char *ptr, *aptr;
char *Token=NULL, *tProto=NULL;


//Even if they pass NULL for protocol, we need to take a copy for use in
//the 'guess the port' section below
ptr=GetToken(URL,":",&tProto,0);
strlwr(tProto);
if (Proto) *Proto=CopyStr(*Proto,tProto);

//some number of '//' follow protocol
while (*ptr=='/') ptr++;

ptr=GetToken(ptr,"/",&Token,0);
ParseHostDetails(Token,Host,Port,User,Password);

//Only split the HTTP CGI arguments from the document path if we were asked to return
//the args seperately
if (Args)
{
	aptr=strrchr(ptr,'?');
	if (aptr) 
	{
		*aptr='\0';
		aptr++;
		*Args=CopyStr(*Args,aptr);
	}
}

//the 'GetToken' call will have thrown away the '/' at the start of the path
//add it back in
if (Path) *Path=MCopyStr(*Path,"/",ptr,NULL);

if (Port && (! StrLen(*Port)))
{
	if (strcmp(tProto,"http")==0) *Port=CopyStr(*Port,"80");
	else if (strcmp(tProto,"https")==0) *Port=CopyStr(*Port,"443");
	else if (strcmp(tProto,"ssh")==0) *Port=CopyStr(*Port,"22");
	else if (strcmp(tProto,"ftp")==0) *Port=CopyStr(*Port,"21");
	else if (strcmp(tProto,"telnet")==0) *Port=CopyStr(*Port,"23");
	else if (strcmp(tProto,"smtp")==0) *Port=CopyStr(*Port,"25");
	else if (strcmp(tProto,"mailto")==0) *Port=CopyStr(*Port,"25");

}

DestroyString(Token);
DestroyString(tProto);
}
示例#25
0
char *OAuthFormatLoginURL(char *RetStr, const char *LoginURL, const char *ClientID, const char *Scope, const char *RedirectURL)
{
char *Encode=NULL;

if (RedirectURL==NULL) RedirectURL="urn:ietf:wg:oauth:2.0:oob";
Encode=HTTPQuote(Encode,ClientID);
RetStr=MCopyStr(RetStr,LoginURL,"?response_type=code&redirect_uri=",RedirectURL,"&client_id=",Encode,NULL);
Encode=HTTPQuote(Encode,Scope);
RetStr=MCatStr(RetStr,"&scope=",Encode,NULL);

DestroyString(Encode);

return(RetStr);
}
示例#26
0
int HTTPServerHandleRegister(HTTPSession *Session, int Flags)
{
char *Tempstr=NULL, *Name=NULL, *Value=NULL, *ptr;
char *FlagChar="";
int result=FALSE;


	if (Flags & LOGGED_IN) FlagChar="I";
	if (Flags & LOGIN_FAIL) FlagChar="F";
	Tempstr=MCopyStr(Tempstr,"REG ",Session->ClientIP,":",FlagChar,"\n",NULL);

	//Override above tempstr if Logout value found
	if (Flags & LOGIN_CHANGE) Tempstr=MCopyStr(Tempstr,"REG ",Session->Path,":C\n",NULL);
	if (Flags & LOGIN_CHECK_ALLOWED) 
	{
		FlagChar="A";
		ptr=GetNameValuePair(Session->Arguments,"&","=",&Name,&Value);
		while (ptr)
		{
			if (Name && (strcmp(Name,"Logout")==0)) Tempstr=MCopyStr(Tempstr,"REG ",Value,":",FlagChar,"\n",NULL);
			ptr=GetNameValuePair(ptr,"&","=",&Name,&Value);
		}
	}

	
	STREAMWriteLine(Tempstr,ParentProcessPipe);
	STREAMFlush(ParentProcessPipe);

	Tempstr=STREAMReadLine(Tempstr,ParentProcessPipe);
	if (strcmp(Tempstr,"okay\n")==0) result=TRUE;

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

return(result);
}
示例#27
0
int IDriveCloseFileWrite(TFileStore *FS, STREAM *S)
{
	char *Tempstr=NULL, *Error=NULL, *ptr;
	ListNode *Vars=NULL;
	HTTPInfoStruct *Info;
	int result=FALSE, val;

	Info=(HTTPInfoStruct *) FS->Extra;
	if (Info)
	{
	Tempstr=MCopyStr(Tempstr,"\r\n--",STREAMGetValue(S,"Boundary"),"--\r\n",NULL);
	STREAMWriteLine(Tempstr,S);
	STREAMFlush(S);

	HTTPTransact(Info);
			

	
/*
<?xml version="1.0" encoding="UTF-8"?>
<tree message="SUCCESS">
    <item filename="autoget.c" filesize="27620"
        lmd="1969/12/31 16:00:00" message="SUCCESS"/>
</tree>
*/

		val=HTTPReadDocument(S, &Tempstr);
		if (Settings.Flags & FLAG_VERBOSE) printf("\n%s\n",Tempstr);

		Vars=ListCreate();
		IDriveParseResponse(Tempstr, Vars);
		Tempstr=CopyStr(Tempstr,GetVar(Vars,"message"));
		if (strcmp(Tempstr,"SUCCESS")==0) 
		{
				val=atoi(STREAMGetValue(S,"Transfer-Size"));

				if (val==atoi(GetVar(Vars,"filesize"))) result=TRUE;	
				else result=ERR_INTERRUPTED;
		}
		else 
		{
			SetVar(FS->Vars,"Error",GetVar(Vars,"desc"));
			result=ERR_CUSTOM;
		}
	}

DestroyString(Tempstr);
return(result);
}
示例#28
0
int STREAMDeleteDataProcessor(STREAM *S, char *Class, char *Name)
{
ListNode *Curr;
char *Tempstr=NULL;
int len;

STREAMFlush(S);

Tempstr=MCopyStr(Tempstr,Class,":",Name,NULL);
Curr=ListFindNamedItem(S->ProcessingModules,Tempstr);
ListDeleteNode(Curr);

DestroyString(Tempstr);
return(TRUE);
}
示例#29
0
void AlayaLog(char *Msg)
{
char *Tempstr=NULL;
     
if (ParentProcessPipe)
{
  Tempstr=MCopyStr(Tempstr,"LOG ",Msg, "'\n",NULL);
  STREAMWriteLine(Tempstr,ParentProcessPipe);
  STREAMFlush(ParentProcessPipe);
}
else LogToFile(Settings.LogPath,Msg);


DestroyString(Tempstr);
}
示例#30
0
void ConfigFileSaveFileStores()
{
STREAM *S;
char *Tempstr=NULL, *PortStr=NULL, *ptr;
ListNode *Curr;
TFileStore *FS;


Tempstr=MCopyStr(Tempstr,GetCurrUserHomeDir(),"/.fileferry.conf",NULL);
S=STREAMOpenFile(Tempstr,O_CREAT | O_TRUNC | O_WRONLY);
if (S)
{
	Curr=ListGetNext(FileStores);
	while (Curr)
	{	
		FS=(TFileStore *) Curr->Item;	
		PortStr=FormatStr(PortStr,"%d",FS->Port);
		if (! StrLen(FS->Name)) Tempstr=MCopyStr(Tempstr,"FileStore ",FS->Type,":",FS->Logon,"@",FS->Host,"\n{\n",NULL);
		else Tempstr=MCopyStr(Tempstr,"FileStore ",FS->Name,"\n{\n",NULL);
		Tempstr=MCatStr(Tempstr, "Type: ",FS->Type,"\n","Host: ",FS->Host,"\n","Port: ",PortStr,"\n","Login: "******"\n","Password: "******"\n",NULL);
		if (FS->Settings & FS_OAUTH) 
		{
			ptr=GetVar(FS->Vars,"OAuthRefreshToken");
			if (StrLen(ptr)) Tempstr=MCatStr(Tempstr, "OAuth\nRefreshToken: ", ptr,"\n",NULL);
		}
		Tempstr=MCatStr(Tempstr, "}\n\n",NULL);
		STREAMWriteLine(Tempstr,S);
		Curr=ListGetNext(Curr);
	}
	STREAMClose(S);
}
else printf("ERROR: Failed to open config file\n");

DestroyString(Tempstr);
DestroyString(PortStr);
}