[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Patch for you for wput
I have a wput patch for you
It resolves a situation with continued messages
For example 220-
The current implimentation causes a failed login on proftpd which has a
welcome message.
Reason: wput does an immediate recv to clear the input buf for login.
This does not work as proftpd has not already sent the welcome message
by then. This leads to wput then sending login and looking for the
password 331 - however the message it then gets is the 220 from the
welcome message and so it fails.
So a sleep() has been added at the start of the login sequence (ugly I
know, but it is the only way it works without a big rewrite). You could
also do this by seeing that if the password result is 220, check again
So then we do the get_msg - however the current code handling it is
flawed. It assumes that the socket will not have sent the second message
when the 220- is read. If it has then the get_msg will hang as the 220
that ends the sequence will already be in the buf and so get_msg sits
waiting for a new recv that will never happen.
The patch handles multiple messages in a single recv
You probably also want to think about handling very slow links where the
recv may not get the whole message in one go if the message is very
long. I would seriously suggest dumping recv and writing yourown socket
reading code.
You probably want to mangle the patch to your style of coding as my
style is a lot different to yours.
The patch is attached.
--
Michael Simms - CEO, Tux Games
http://www.tuxgames.com
63a64
> sleep(5);
801c802,803
< int get_msg(int csock, char * msg, int buflen){
---
> int get_msg(int csock, char * msg, int buflen)
> {
803,804c805,855
<
< do {
---
> int finished=0;
> char cmd[8],*ptr,*endptr;
>
> while (!finished)
> {
> finished=1;
>
> memset(msg, 0, buflen);
> res = recv(csock, msg, buflen-1, 0);
>
> ptr=msg;
>
> while (ptr[3] == '-' && finished)
> {
> sprintf(cmd,"\n%c%c%c-",msg[0],msg[1],msg[2]);
> endptr=strstr(ptr+1,cmd);
> if (!endptr)
> {
> cmd[0]='\r';
> endptr=strstr(ptr+1,cmd);
> }
> if (endptr)
> {
> ptr=endptr+1;
> continue;
> }
>
> /*We have no more ddd- messages, check for a ddd<32> message now*/
> cmd[0]='\n';
> cmd[4]=' ';
>
> endptr=strstr(ptr+1,cmd);
> if (!endptr)
> {
> cmd[0]='\r';
> endptr=strstr(ptr+1,cmd);
> }
> if (!endptr)
> {
> finished=0;
> continue;
> }
>
> /*Now we know we have the last bit, so move this up to the
> start of the buf*/
>
> ptr=endptr+1;
>
> endptr=(char *)malloc(strlen(endptr)+1);
> strcpy(endptr,ptr);
>
806,811c857,869
< res = recv(csock, msg, buflen-1, 0);
< printout(vDEBUG, "%s", msg);
< /* multiline messages are required by rfc to have a hiphen
< * after the command-code (e.g. 250-).
< * this counts for all but the last one, so look out for it. */
< } while(msg[3] == '-');
---
> strcpy(msg,endptr);
>
> free(endptr);
>
> res = strlen(msg);
> ptr=msg;
> }
>
> printout(vDEBUG, "%s", msg);
> /* multiline messages are required by rfc to have a hiphen
> * after the command-code (e.g. 250-).
> * this counts for all but the last one, so look out for it. */
> }