
Nmap Development mailing list archives
Re: [nmap-svn] r31969 - nmap-exp/d33tah/ncat-lua-callbacks/ncat
From: Jacek Wielemborek <wielemborekj1 () gmail com>
Date: Wed, 21 Aug 2013 01:38:03 +0200
2013/8/21 <commit-mailer () nmap org>:
Author: d33tah Date: Tue Aug 20 23:42:46 2013 New Revision: 31969 Log: Get rid of fdinfo_pending, instead move it into fdinfo_recv. That's where I plan to move the Lua hooks to make proxying work too. Modified: nmap-exp/d33tah/ncat-lua-callbacks/ncat/http.c nmap-exp/d33tah/ncat-lua-callbacks/ncat/ncat_core.c nmap-exp/d33tah/ncat-lua-callbacks/ncat/ncat_core.h nmap-exp/d33tah/ncat-lua-callbacks/ncat/ncat_proxy.c Modified: nmap-exp/d33tah/ncat-lua-callbacks/ncat/http.c ============================================================================== --- nmap-exp/d33tah/ncat-lua-callbacks/ncat/http.c (original) +++ nmap-exp/d33tah/ncat-lua-callbacks/ncat/http.c Tue Aug 20 23:42:46 2013 @@ -153,9 +153,11 @@ if (buf->p >= buf->end) { buf->p = buf->buffer; do { + int pending; errno = 0; - i = fdinfo_recv(&buf->fdn, buf->buffer, sizeof(buf->buffer)); + i = fdinfo_recv(&buf->fdn, buf->buffer, sizeof(buf->buffer), &pending); } while (i == -1 && errno == EINTR); + /* TODO: TESTME: how does it react to EAGAIN? */ if (i <= 0) return i; buf->end = buf->buffer + i; @@ -191,8 +193,9 @@ buf->p = buf->buffer; do { + int pending; errno = 0; - i = fdinfo_recv(&buf->fdn, buf->buffer, sizeof(buf->buffer)); + i = fdinfo_recv(&buf->fdn, buf->buffer, sizeof(buf->buffer), &pending); } while (i == -1 && errno == EINTR); if (i <= 0) { free(line); @@ -238,8 +241,9 @@ if (buf->p >= buf->end) { buf->p = buf->buffer; do { + int pending; errno = 0; - i = fdinfo_recv(&buf->fdn, buf->buffer, sizeof(buf->buffer)); + i = fdinfo_recv(&buf->fdn, buf->buffer, sizeof(buf->buffer), &pending); } while (i == -1 && errno == EINTR); if (i <= 0) return -1; Modified: nmap-exp/d33tah/ncat-lua-callbacks/ncat/ncat_core.c ============================================================================== --- nmap-exp/d33tah/ncat-lua-callbacks/ncat/ncat_core.c (original) +++ nmap-exp/d33tah/ncat-lua-callbacks/ncat/ncat_core.c Tue Aug 20 23:42:46 2013 @@ -283,24 +283,19 @@ } /* Do a recv on an fdinfo, without other side effects. */ -int fdinfo_recv(struct fdinfo *fdn, char *buf, size_t size) +int fdinfo_recv(struct fdinfo *fdn, char *buf, size_t size, int *pending) { #ifdef HAVE_OPENSSL - if (o.ssl && fdn->ssl) - return SSL_read(fdn->ssl, buf, size); + if (o.ssl && fdn->ssl){ + int ret = SSL_read(fdn->ssl, buf, size); + *pending = SSL_pending(fdn->ssl); + return ret; + } #endif + *pending = 0; return recv(fdn->fd, buf, size, 0); } -int fdinfo_pending(struct fdinfo *fdn) -{ -#ifdef HAVE_OPENSSL - if (o.ssl && fdn->ssl) - return SSL_pending(fdn->ssl); -#endif - return 0; -} - /* Read from a client socket into buf, returning the number of bytes read, or -1 on an error. This takes care of delays, Telnet negotiation, and logging. @@ -317,7 +312,7 @@ *pending = 0; - n = fdinfo_recv(fdn, buf, size); + n = fdinfo_recv(fdn, buf, size, pending); if (n <= 0) return n; @@ -328,11 +323,6 @@ dotelnet(fdn->fd, (unsigned char *) buf, n); ncat_log_recv(buf, n); - /* SSL can buffer our input, so doing another select() won't necessarily - work for us. Indicate to the caller that this function must be called - again to get more data. */ - *pending = fdinfo_pending(fdn); - return n; } Modified: nmap-exp/d33tah/ncat-lua-callbacks/ncat/ncat_core.h ============================================================================== --- nmap-exp/d33tah/ncat-lua-callbacks/ncat/ncat_core.h (original) +++ nmap-exp/d33tah/ncat-lua-callbacks/ncat/ncat_core.h Tue Aug 20 23:42:46 2013 @@ -226,10 +226,9 @@ struct sockaddr_storage *ss, size_t *sslen, int af); int fdinfo_close(struct fdinfo *fdn); -int fdinfo_recv(struct fdinfo *fdn, char *buf, size_t size); +int fdinfo_recv(struct fdinfo *fdn, char *buf, size_t size, int *pending); int fdinfo_send_raw(struct fdinfo *fdn, const char *buf, size_t size); int fdinfo_send(struct fdinfo *fdn, const char *buf, size_t size); -int fdinfo_pending(struct fdinfo *fdn); int ncat_recv(struct fdinfo *fdn, char *buf, size_t size, int *pending, int *error); int ncat_recv_raw(struct fdinfo *fdn, char *buf, size_t size, int *pending); Modified: nmap-exp/d33tah/ncat-lua-callbacks/ncat/ncat_proxy.c ============================================================================== --- nmap-exp/d33tah/ncat-lua-callbacks/ncat/ncat_proxy.c (original) +++ nmap-exp/d33tah/ncat-lua-callbacks/ncat/ncat_proxy.c Tue Aug 20 23:42:46 2013 @@ -543,9 +543,10 @@ zmem(buf, sizeof(buf)); if (FD_ISSET(client_sock->fdn.fd, &r)) { + int pending; do { do { - len = fdinfo_recv(&client_sock->fdn, buf, sizeof(buf)); + len = fdinfo_recv(&client_sock->fdn, buf, sizeof(buf), &pending); } while (len == -1 && socket_errno() == EINTR); if (len <= 0) goto end; @@ -555,7 +556,7 @@ } while (rc == -1 && socket_errno() == EINTR); if (rc == -1) goto end; - } while (fdinfo_pending(&client_sock->fdn)); + } while (pending); } if (FD_ISSET(s, &r)) { _______________________________________________ Sent through the svn mailing list http://nmap.org/mailman/listinfo/svn
Re-ran the tests at this point, looks like this commit didn't break anything. _______________________________________________ Sent through the dev mailing list http://nmap.org/mailman/listinfo/dev Archived at http://seclists.org/nmap-dev/
Current thread:
- Re: [nmap-svn] r31969 - nmap-exp/d33tah/ncat-lua-callbacks/ncat Jacek Wielemborek (Aug 20)