Delay sending the real ID request until after a proxy request is granted.
[oweals/tinc.git] / src / proxy.c
index 2b8f87c13e36dcc5d32e47968ae8f33b2c14ae3c..32cb7973ffcb51e9a928b7f20d62e5d9c44722cb 100644 (file)
@@ -194,6 +194,8 @@ int receive_proxy_meta(connection_t *c, int start, int lenin) {
 
                        ifdebug(CONNECTIONS) logger(LOG_DEBUG, "Proxy request granted");
                        c->allow_request = ID;
+                       c->status.proxy_passed = true;
+                       send_id(c);
                        return 8;
                } else {
                        logger(LOG_ERR, "Proxy request rejected");
@@ -249,6 +251,8 @@ int receive_proxy_meta(connection_t *c, int start, int lenin) {
                } else {
                        ifdebug(CONNECTIONS) logger(LOG_DEBUG, "Proxy request granted");
                        c->allow_request = ID;
+                       c->status.proxy_passed = true;
+                       send_id(c);
                        return replen;
                }
 
@@ -257,8 +261,8 @@ int receive_proxy_meta(connection_t *c, int start, int lenin) {
                if(!p || p - c->buffer >= c->buflen)
                        return 0;
 
-               while(p = memchr(p + 1, '\n', c->buflen - (p + 1 - c->buffer))) {
-                       if(p[-1] == '\n')
+               while((p = memchr(p + 1, '\n', c->buflen - (p + 1 - c->buffer)))) {
+                       if(p > c->buffer + 3 && !memcmp(p - 3, "\r\n\r\n", 4))
                                break;
                }
 
@@ -275,8 +279,12 @@ int receive_proxy_meta(connection_t *c, int start, int lenin) {
                                logger(LOG_DEBUG, "Proxy request granted");
                                replen = p  + 1 - c->buffer;
                                c->allow_request = ID;
+                               c->status.proxy_passed = true;
+                               send_id(c);
                                return replen;
                        } else {
+                               p = memchr(c->buffer, '\n', c->buflen);
+                               p[-1] = 0;
                                logger(LOG_ERR, "Proxy request rejected: %s", c->buffer + 9);
                                return false;
                        }