- snprintf(buffer, sizeof(buffer), "CONNECT %s:%d HTTP/1.0\r\n\r\n", host, port);
- if (write(fd, buffer, strlen(buffer)) != (int) strlen(buffer)) {
- rprintf(FERROR, "failed to write to proxy: %s\n",
- strerror(errno));
+ if (proxy_user && proxy_pass) {
+ stringjoin(buffer, sizeof buffer,
+ proxy_user, ":", proxy_pass, NULL);
+ len = strlen(buffer);
+
+ if ((len*8 + 5) / 6 >= (int)sizeof authbuf) {
+ rprintf(FERROR,
+ "authentication information is too long\n");
+ return -1;
+ }
+
+ base64_encode(buffer, len, authbuf);
+ authhdr = "\r\nProxy-Authorization: Basic ";
+ } else {
+ *authbuf = '\0';
+ authhdr = "";
+ }
+
+ snprintf(buffer, sizeof buffer, "CONNECT %s:%d HTTP/1.0%s%s\r\n\r\n",
+ host, port, authhdr, authbuf);
+ len = strlen(buffer);
+ if (write(fd, buffer, len) != len) {
+ rsyserr(FERROR, errno, "failed to write to proxy");