Fixed IP detection over HTTPS output
This commit is contained in:
		
							parent
							
								
									0f12e107de
								
							
						
					
					
						commit
						4a621ea5c0
					
				
					 2 changed files with 19 additions and 1 deletions
				
			
		|  | @ -436,13 +436,21 @@ void Socket::Buffer::clear(){ | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void Socket::Connection::setBoundAddr(){ | void Socket::Connection::setBoundAddr(){ | ||||||
|  |   //If a bound address was set through environment (e.g. HTTPS output), restore it from there.
 | ||||||
|  |   char * envbound = getenv("MIST_BOUND_ADDR"); | ||||||
|  |   if (envbound){ | ||||||
|  |     boundaddr = envbound; | ||||||
|  |     return; | ||||||
|  |   } | ||||||
|  |   //If we can't read the address, don't try
 | ||||||
|   if (!isTrueSocket){ |   if (!isTrueSocket){ | ||||||
|     boundaddr = ""; |     boundaddr = ""; | ||||||
|     return; |     return; | ||||||
|   } |   } | ||||||
|  |   //Otherwise, read from socket pointer. Works for both SSL and non-SSL sockets, and real sockets passed as fd's, but not for non-sockets (duh)
 | ||||||
|   struct sockaddr_in6 tmpaddr; |   struct sockaddr_in6 tmpaddr; | ||||||
|   socklen_t len = sizeof(tmpaddr); |   socklen_t len = sizeof(tmpaddr); | ||||||
|   if (!getsockname(sSend, (sockaddr *)&tmpaddr, &len)){ |   if (!getsockname(getSocket(), (sockaddr *)&tmpaddr, &len)){ | ||||||
|     static char addrconv[INET6_ADDRSTRLEN]; |     static char addrconv[INET6_ADDRSTRLEN]; | ||||||
|     if (tmpaddr.sin6_family == AF_INET6){ |     if (tmpaddr.sin6_family == AF_INET6){ | ||||||
|       boundaddr = inet_ntop(AF_INET6, &(tmpaddr.sin6_addr), addrconv, INET6_ADDRSTRLEN); |       boundaddr = inet_ntop(AF_INET6, &(tmpaddr.sin6_addr), addrconv, INET6_ADDRSTRLEN); | ||||||
|  | @ -649,12 +657,18 @@ void Socket::Connection::drop(){ | ||||||
| 
 | 
 | ||||||
| /// Returns internal socket number.
 | /// Returns internal socket number.
 | ||||||
| int Socket::Connection::getSocket(){ | int Socket::Connection::getSocket(){ | ||||||
|  | #ifdef SSL | ||||||
|  |   if (sslConnected){return server_fd->fd;} | ||||||
|  | #endif | ||||||
|   if (sSend != -1){return sSend;} |   if (sSend != -1){return sSend;} | ||||||
|   return sRecv; |   return sRecv; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /// Returns non-piped internal socket number.
 | /// Returns non-piped internal socket number.
 | ||||||
| int Socket::Connection::getPureSocket(){ | int Socket::Connection::getPureSocket(){ | ||||||
|  | #ifdef SSL | ||||||
|  |   if (sslConnected){return server_fd->fd;} | ||||||
|  | #endif | ||||||
|   if (!isTrueSocket){return -1;} |   if (!isTrueSocket){return -1;} | ||||||
|   return sSend; |   return sSend; | ||||||
| } | } | ||||||
|  | @ -790,6 +804,8 @@ void Socket::Connection::open(std::string host, int port, bool nonblock, bool wi | ||||||
|       } |       } | ||||||
|     } |     } | ||||||
|     sslConnected = true; |     sslConnected = true; | ||||||
|  |     isTrueSocket = true; | ||||||
|  |     setBoundAddr(); | ||||||
|     Blocking = true; |     Blocking = true; | ||||||
|     if (nonblock){setBlocking(false);} |     if (nonblock){setBlocking(false);} | ||||||
|     DONTEVEN_MSG("SSL connect success"); |     DONTEVEN_MSG("SSL connect success"); | ||||||
|  |  | ||||||
|  | @ -111,7 +111,9 @@ namespace Mist{ | ||||||
|     } |     } | ||||||
|     args.push_back(""); |     args.push_back(""); | ||||||
|     Util::Procs::socketList.insert(fd[0]); |     Util::Procs::socketList.insert(fd[0]); | ||||||
|  |     setenv("MIST_BOUND_ADDR", myConn.getBoundAddress().c_str(), 1); | ||||||
|     pid_t http_proc = Util::Procs::StartPiped(args, &(fd[1]), &(fd[1]), &fderr); |     pid_t http_proc = Util::Procs::StartPiped(args, &(fd[1]), &(fd[1]), &fderr); | ||||||
|  |     unsetenv("MIST_BOUND_ADDR"); | ||||||
|     close(fd[1]); |     close(fd[1]); | ||||||
|     if (http_proc < 2){ |     if (http_proc < 2){ | ||||||
|       FAIL_MSG("Could not spawn MistOutHTTP process for SSL connection!"); |       FAIL_MSG("Could not spawn MistOutHTTP process for SSL connection!"); | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Thulinma
						Thulinma