int SMTPSendMail(const char *Sender, const char *Recipient, const char *Subject, const char *Body, int Flags) { char *Tempstr=NULL; STREAM *S; int result=FALSE; S=SMTPConnect(Sender, Recipient, Flags); if (S) { if (! (Flags & SMTP_NOHEADER)) { Tempstr=MCopyStr(Tempstr,"Date: ", GetDateStr("%a, %d %b %Y %H:%M:%S", NULL), "\r\n", NULL); Tempstr=MCatStr(Tempstr,"From: ", Sender, "\r\n", NULL); Tempstr=MCatStr(Tempstr,"To: ", Recipient, "\r\n", NULL); Tempstr=MCatStr(Tempstr,"Subject: ", Subject, "\r\n\r\n", NULL); STREAMWriteLine(Tempstr, S); } STREAMWriteLine(Body, S); STREAMWriteLine("\r\n.\r\n", S); SMTPInteract("", S); SMTPInteract("QUIT\r\n", S); result=TRUE; STREAMClose(S); } DestroyString(Tempstr); return(result); }
void HashratSignFile(char *Path, HashratCtx *Ctx) { STREAM *S; char *Tempstr=NULL, *HashStr=NULL; double pos; THash *Hash; S=STREAMOpenFile(Path, SF_RDWR); if (! S) return; Hash=HashInit(Ctx->HashType); HashratFinishHash(&HashStr, Ctx, Hash); pos=STREAMSeek(S,0,SEEK_END); Tempstr=MCopyStr(Tempstr,"hashrat-placeholder---: ",GetDateStr("%Y/%m/%d %H:%M:%S",NULL)," ",Ctx->HashType,":", HashStr,"\n",NULL); STREAMWriteLine(Tempstr,S); STREAMFlush(S); STREAMSeek(S,0,SEEK_SET); Hash=HashInit(Ctx->HashType); HashratHashFile(Ctx, Hash, FT_FILE, Path, (off_t) pos); HashratFinishHash(&HashStr, Ctx, Hash); Tempstr=MCopyStr(Tempstr,"hashrat-integrity-mark: ",GetDateStr("%Y/%m/%d %H:%M:%S",NULL)," ",Ctx->HashType,":", HashStr,"\n",NULL); STREAMSeek(S,pos,SEEK_SET); STREAMWriteLine(Tempstr,S); STREAMFlush(S); DestroyString(Tempstr); DestroyString(HashStr); }
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); }
pid_t HandleChildRegisterRequest(STREAM *S, char *Data) { char *Tempstr=NULL, *Host=NULL, *ptr; int Flags=0; time_t LastTime; ptr=GetToken(Data,":",&Host,0); if (*ptr=='A') Flags |= LOGIN_CHECK_ALLOWED; if (*ptr=='I') Flags |= LOGGED_IN; if (*ptr=='F') Flags |= LOGIN_FAIL; if (*ptr=='C') Flags |= LOGIN_CHANGE; ptr=GetVar(Settings.HostConnections,Host); LastTime=time(NULL); if (Flags & LOGIN_CHECK_ALLOWED) { if (ptr && (strcmp(ptr,"logout")==0)) { SetVar(Settings.HostConnections,Host,""); STREAMWriteLine("logout\n",S); } else { STREAMWriteLine("okay\n",S); } } else if (Flags & LOGIN_CHANGE) { Tempstr=CopyStr(Tempstr,"logout"); SetVar(Settings.HostConnections,Host,Tempstr); STREAMWriteLine("okay\n",S); } else { if (Flags & LOGGED_IN) LastTime=0; Tempstr=FormatStr(Tempstr,"%ld",LastTime); SetVar(Settings.HostConnections,Host,Tempstr); STREAMWriteLine("okay\n",S); } STREAMFlush(S); DestroyString(Tempstr); DestroyString(Host); return(0); }
pid_t HandleProxyRequest(STREAM *ClientCon, char *Data) { HTTPSession *Response; char *Tempstr=NULL; int pid; pid=fork(); if (pid==0) { Response=ParseSessionInfo(Data); STREAMWriteLine("READY\n",ClientCon); STREAMFlush(ClientCon); if (strcmp(Response->Method,"POST")==0) Response->MethodID=METHOD_RPOST; else Response->MethodID=METHOD_RGET; HTTPProxyRGETURL(ClientCon,Response); //void HTTPProxyConnect(STREAM *S,HTTPSession *ClientHeads); LogFileFlushAll(TRUE); STREAMFlush(ClientCon); _exit(0); } else ClientCon->State |= SS_EMBARGOED; DestroyString(Tempstr); return(pid); }
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); }
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); }
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); }
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); }
int SMTPSendMailFile(const char *Sender, const char *Recipient, const char *Path, int Flags) { char *Tempstr=NULL; STREAM *S, *F; int result=FALSE; F=STREAMOpen(Path, "r"); if (F) { S=SMTPConnect(Sender, Recipient, Flags); if (S) { STREAMSendFile(F, S, 0, SENDFILE_LOOP); STREAMWriteLine("\r\n.\r\n", S); SMTPInteract("", S); SMTPInteract("QUIT\r\n", S); result=TRUE; STREAMClose(S); } STREAMClose(F); } else RaiseError(0,"SMTPSendMailFile","Failed to open file for sending"); DestroyString(Tempstr); return(result); }
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); }
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); }
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); }
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); }
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); }
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); }
pid_t RunEventScript(STREAM *S, const char *Script) { if (Spawn(Script,Settings.DefaultUser,"",NULL) ==-1) { LogToFile(Settings.LogPath, "ERROR: Failed to run event script '%s'. Error was: %s",Script, strerror(errno)); } else LogToFile(Settings.LogPath, "Script: '%s'. Error was: %s",Script, strerror(errno)); STREAMWriteLine("okay\n",S); return(0); }
STREAM *IDriveOpenFile(TFileStore *FS, TFileInfo *FI, int Flags) { char *URL=NULL, *Tempstr=NULL, *Boundary=NULL, *FullPath=NULL, *ptr; HTTPInfoStruct *Info; TFileInfo *tmpFI; if (Flags & OPEN_WRITE) { URL=MCopyStr(URL,"https://",FS->Host,"/evs/uploadFile",NULL); Info=HTTPInfoFromURL("POST",URL); Boundary=FormatStr(Boundary,"%x-%x-%x",getpid(),time(NULL),rand()); Info->PostContentType=MCopyStr(Info->ContentType,"multipart/form-data; boundary=",Boundary,NULL); Tempstr=MCopyStr(Tempstr,"--",Boundary,"\r\n","Content-disposition: form-data; name=uid\r\n\r\n",FS->Logon,"\r\n",NULL); Tempstr=MCatStr(Tempstr,"--",Boundary,"\r\n","Content-disposition: form-data; name=pwd\r\n\r\n",FS->Passwd,"\r\n",NULL); Tempstr=MCatStr(Tempstr,"--",Boundary,"\r\n","Content-disposition: form-data; name=p\r\n\r\n",FS->CurrDir,"\r\n",NULL); //Tempstr=MCatStr(Tempstr,"--",Boundary,"\r\n","Content-disposition: form-data; name=myfiles\r\n\r\n",Path,"\r\n",NULL); Tempstr=MCatStr(Tempstr,"--",Boundary,"\r\n","Content-disposition: form-data; charset=UTF-8; name=definition; filename=",FI->Path,"\r\nContent-type: image/jpeg\r\n\r\n",NULL); Info->PostContentLength=FI->Size+StrLen(Tempstr)+StrLen(Boundary)+8; FS->S=HTTPTransact(Info); FS->Extra=Info; STREAMWriteLine(Tempstr,FS->S); STREAMSetValue(FS->S,"Boundary",Boundary); Tempstr=FormatStr(Tempstr,"%d",FI->Size); STREAMSetValue(FS->S,"Transfer-Size",Tempstr); } else { if (*FI->Path=='/') FullPath=CopyStr(FullPath,FI->Path); else FullPath=MCopyStr(FullPath,FS->CurrDir,FI->Path,NULL); Tempstr=HTTPQuote(Tempstr,FullPath); // if (OpenFI->Version) FI=OpenFI; // else FI=FileStoreGetFileInfo(FS, FI->Path); URL=FormatStr(URL,"https://%s/evs/downloadFile?uid=%s&pwd=%s&p=%s&version=%d",FS->Host,FS->Logon,FS->Passwd,Tempstr,FI->Version); FS->S=HTTPMethod("POST",URL,"","","","",0); FS->Extra=NULL; // if (FI != OpenFI) FileInfoDestroy(FI); } DestroyString(URL); DestroyString(FullPath); DestroyString(Tempstr); DestroyString(Boundary); return(FS->S); }
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); }
int SendPublicKeyToRemote(STREAM *S, char *KeyFile, char *LocalPath) { char *Tempstr=NULL, *Line=NULL; STREAM *LocalFile; Tempstr=FormatStr(Tempstr,"rm -f %s ; touch %s; chmod 0600 %s\n",KeyFile,KeyFile,KeyFile); STREAMWriteLine(Tempstr,S); LocalFile=STREAMOpenFile(LocalPath,SF_RDONLY); if (LocalFile) { Line=STREAMReadLine(Line,LocalFile); while (Line) { StripTrailingWhitespace(Line); Tempstr=FormatStr(Tempstr,"echo '%s' >> %s\n",Line,KeyFile); STREAMWriteLine(Tempstr,S); Line=STREAMReadLine(Line,LocalFile); } STREAMClose(LocalFile); } return(TRUE); }
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); }
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); }
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); }
void HTTPServerOptions(STREAM *S,HTTPSession *ClientHeads) { char *Tempstr=NULL; STREAMWriteLine("HTTP/1.1 200 OK\r\n",S); Tempstr=CopyStr(Tempstr,GetDateStr("Date: %a, %d %b %Y %H:%M:%S %Z\r\n",NULL)); STREAMWriteLine(Tempstr,S); STREAMWriteLine("Content-Length: 0\r\n",S); STREAMWriteLine("Public: OPTIONS, TRACE, GET, HEAD, DELETE, PUT, POST, COPY, MOVE, MKCOL, PROPFIND, PROPPATCH, LOCK, UNLOCK, SEARCH\r\n",S); STREAMWriteLine("Allow: OPTIONS, GET, HEAD, DELETE, PUT, POST, COPY, MOVE, MKCOL, PROPFIND, PROPPATCH\r\n",S); STREAMWriteLine("DASL:\r\n",S); STREAMWriteLine("DAV: 1\r\n",S); DestroyString(Tempstr); }
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); }
int ProxyControlConnect(TSession *Session, char *Host, int Port) { char *Tempstr=NULL; int fd, result=FALSE; if (StrLen(Host)==0) { SendLoggedLine(Session,"421 ERROR: Proxy cannot connect. No destination host."); } else { Tempstr=IPCRequest(Tempstr, Session, "GetIP", Host); if (strcmp(Tempstr,"DENIED")==0) { Tempstr=FormatStr(Tempstr,"421 ERROR: Proxy connection denied for host %s:%d",Host,Port); SendLoggedLine(Session,Tempstr); } else { fd=ConnectToHost(Tempstr,Port,FALSE); if (fd==-1) { Tempstr=FormatStr(Tempstr,"421 ERROR: Proxy cannot connect to host %s:%d",Host,Port); SendLoggedLine(Session,Tempstr); } else { Session->ProxySock=STREAMFromFD(fd); result=TRUE; do { Tempstr=STREAMReadLine(Tempstr,Session->ProxySock); STREAMWriteLine(Tempstr,Session->ClientSock); } while ( (Tempstr[3]=='-') || (isspace(Tempstr[0])) ); STREAMFlush(Session->ClientSock); } } } DestroyString(Tempstr); return(result); }
int MemcachedSet(const char *Key, int TTL, const char *Value) { char *Tempstr=NULL; int result=FALSE; if (STREAMIsConnected(MCS)) { Tempstr=FormatStr(Tempstr,"set %s 0 %d %d\r\n%s\r\n",Key,TTL,StrLen(Value),Value); STREAMWriteLine(Tempstr,MCS); Tempstr=STREAMReadLine(Tempstr,MCS); StripTrailingWhitespace(Tempstr); if (StrLen(Tempstr) && (strcmp(Tempstr,"STORED")==0)) result=TRUE; } DestroyString(Tempstr); return(result); }
pid_t HandlePostFileRequest(STREAM *ClientCon, char *Data) { HTTPSession *Response; STREAM *S; char *Tempstr=NULL; pid_t pid; pid=fork(); if (pid==0) { Response=ParseSessionInfo(Data); Tempstr=FindFileInPath(Tempstr,Response->Path,Response->SearchPath); Response->Path=CopyStr(Response->Path, Tempstr); if (! SwitchGroup(Response->Group)) { LogToFile(Settings.LogPath,"WARN: Failed to switch to group '%s' when posting '%s'", Response->RealUser, Tempstr); } if (! SwitchUser(Response->RealUser)) { LogToFile(Settings.LogPath,"ERROR: Failed to switch to user '%s' when posting to document '%s'", Tempstr); LogFileFlushAll(TRUE); _exit(0); } LogToFile(Settings.LogPath,"SWITCH USER: '******' posting document '%s'", Response->RealUser, Response->Group, Tempstr); STREAMWriteLine("READY\n",ClientCon); STREAMFlush(ClientCon); HTTPServerHandlePost(ClientCon, Response); //exit 1 means that we can keep connection alive for re-use LogFileFlushAll(TRUE); if (Response->Flags & SESSION_KEEPALIVE) _exit(1); _exit(0); } else ClientCon->State |= SS_EMBARGOED; DestroyString(Tempstr); return(pid); }
int AddEncryptionHeader(STREAM *S, int Flags, const char *Cipher, const char *Key, const char *InitVector, const char *Salt) { char *EncryptArgs=NULL; char *Tempstr=NULL; int result=FALSE; EncryptArgs=FormatEncryptArgs(EncryptArgs,Flags, Cipher, Key, InitVector,Salt); if (STREAMAddStandardDataProcessor(S,"Crypto",Cipher,EncryptArgs)) { EncryptArgs=FormatEncryptArgs(EncryptArgs,Flags, Cipher, "", InitVector,Salt); Tempstr=FormatStr(Tempstr,"ENCR %s\n",EncryptArgs); STREAMWriteLine(Tempstr,S); result=TRUE; } DestroyString(Tempstr); DestroyString(EncryptArgs); return(result); }
int SMTPInteract(const char *Line, STREAM *S) { char *Tempstr=NULL; int result=FALSE; if (StrValid(Line)) STREAMWriteLine(Line, S); STREAMFlush(S); Tempstr=SMTPRead(Tempstr, S); /* syslog(LOG_DEBUG,"mail >> %s",Line); syslog(LOG_DEBUG,"mail << %s",Tempstr); */ if ( StrValid(Tempstr) && ( (*Tempstr=='2') || (*Tempstr=='3') ) ) result=TRUE; DestroyString(Tempstr); return(result); }