Fossil SCM
Simplify code and no longer rely on MAX_REDIRECTS because 20 password prompts are too many.
Commit
9493a9c763c891146265ab58eb4e39253f281f29
Parent
d581ef00574a91f…
1 file changed
+8
-21
+8
-21
| --- src/http.c | ||
| +++ src/http.c | ||
| @@ -28,10 +28,13 @@ | ||
| 28 | 28 | #endif |
| 29 | 29 | #ifndef fileno |
| 30 | 30 | #define fileno(s) _fileno(s) |
| 31 | 31 | #endif |
| 32 | 32 | #endif |
| 33 | + | |
| 34 | +/* Maximum number of HTTP Authorization attempts */ | |
| 35 | +#define MAX_HTTP_AUTH 2 | |
| 33 | 36 | |
| 34 | 37 | /* Keep track of HTTP Basic Authorization failures */ |
| 35 | 38 | static int fSeenHttpAuth = 0; |
| 36 | 39 | |
| 37 | 40 | /* |
| @@ -276,32 +279,16 @@ | ||
| 276 | 279 | while( (zLine = transport_receive_line(GLOBAL_URL()))!=0 && zLine[0]!=0 ){ |
| 277 | 280 | /* printf("[%s]\n", zLine); fflush(stdout); */ |
| 278 | 281 | if( fossil_strnicmp(zLine, "http/1.", 7)==0 ){ |
| 279 | 282 | if( sscanf(zLine, "HTTP/1.%d %d", &iHttpVersion, &rc)!=2 ) goto write_err; |
| 280 | 283 | if( rc==401 ){ |
| 281 | - transport_close(GLOBAL_URL()); | |
| 282 | - if( --maxRedirect == 0 ){ | |
| 283 | - fossil_fatal("http authorization limit exceeded"); | |
| 284 | - } | |
| 285 | - if( g.zHttpAuth==0 ){ | |
| 284 | + if( fSeenHttpAuth++ < MAX_HTTP_AUTH ){ | |
| 285 | + if( g.zHttpAuth ){ | |
| 286 | + if( g.zHttpAuth ) free(g.zHttpAuth); | |
| 287 | + } | |
| 286 | 288 | g.zHttpAuth = prompt_for_httpauth_creds(); |
| 287 | - } | |
| 288 | - if( g.zHttpAuth && g.zHttpAuth[0] ){ | |
| 289 | - if( fSeenHttpAuth ){ | |
| 290 | - free(g.zHttpAuth); | |
| 291 | - g.zHttpAuth = 0; | |
| 292 | - fSeenHttpAuth = 0; | |
| 293 | - }else{ | |
| 294 | - fSeenHttpAuth = 1; | |
| 295 | - } | |
| 296 | - return http_exchange(pSend, pReply, useLogin, maxRedirect); | |
| 297 | - }else{ | |
| 298 | - fossil_warning("HTTP Basic Authorization failed."); | |
| 299 | - if( g.zHttpAuth ){ | |
| 300 | - free(g.zHttpAuth); | |
| 301 | - g.zHttpAuth = 0; | |
| 302 | - } | |
| 289 | + transport_close(GLOBAL_URL()); | |
| 303 | 290 | return http_exchange(pSend, pReply, useLogin, maxRedirect); |
| 304 | 291 | } |
| 305 | 292 | } |
| 306 | 293 | if( rc!=200 && rc!=302 ){ |
| 307 | 294 | int ii; |
| 308 | 295 |
| --- src/http.c | |
| +++ src/http.c | |
| @@ -28,10 +28,13 @@ | |
| 28 | #endif |
| 29 | #ifndef fileno |
| 30 | #define fileno(s) _fileno(s) |
| 31 | #endif |
| 32 | #endif |
| 33 | |
| 34 | /* Keep track of HTTP Basic Authorization failures */ |
| 35 | static int fSeenHttpAuth = 0; |
| 36 | |
| 37 | /* |
| @@ -276,32 +279,16 @@ | |
| 276 | while( (zLine = transport_receive_line(GLOBAL_URL()))!=0 && zLine[0]!=0 ){ |
| 277 | /* printf("[%s]\n", zLine); fflush(stdout); */ |
| 278 | if( fossil_strnicmp(zLine, "http/1.", 7)==0 ){ |
| 279 | if( sscanf(zLine, "HTTP/1.%d %d", &iHttpVersion, &rc)!=2 ) goto write_err; |
| 280 | if( rc==401 ){ |
| 281 | transport_close(GLOBAL_URL()); |
| 282 | if( --maxRedirect == 0 ){ |
| 283 | fossil_fatal("http authorization limit exceeded"); |
| 284 | } |
| 285 | if( g.zHttpAuth==0 ){ |
| 286 | g.zHttpAuth = prompt_for_httpauth_creds(); |
| 287 | } |
| 288 | if( g.zHttpAuth && g.zHttpAuth[0] ){ |
| 289 | if( fSeenHttpAuth ){ |
| 290 | free(g.zHttpAuth); |
| 291 | g.zHttpAuth = 0; |
| 292 | fSeenHttpAuth = 0; |
| 293 | }else{ |
| 294 | fSeenHttpAuth = 1; |
| 295 | } |
| 296 | return http_exchange(pSend, pReply, useLogin, maxRedirect); |
| 297 | }else{ |
| 298 | fossil_warning("HTTP Basic Authorization failed."); |
| 299 | if( g.zHttpAuth ){ |
| 300 | free(g.zHttpAuth); |
| 301 | g.zHttpAuth = 0; |
| 302 | } |
| 303 | return http_exchange(pSend, pReply, useLogin, maxRedirect); |
| 304 | } |
| 305 | } |
| 306 | if( rc!=200 && rc!=302 ){ |
| 307 | int ii; |
| 308 |
| --- src/http.c | |
| +++ src/http.c | |
| @@ -28,10 +28,13 @@ | |
| 28 | #endif |
| 29 | #ifndef fileno |
| 30 | #define fileno(s) _fileno(s) |
| 31 | #endif |
| 32 | #endif |
| 33 | |
| 34 | /* Maximum number of HTTP Authorization attempts */ |
| 35 | #define MAX_HTTP_AUTH 2 |
| 36 | |
| 37 | /* Keep track of HTTP Basic Authorization failures */ |
| 38 | static int fSeenHttpAuth = 0; |
| 39 | |
| 40 | /* |
| @@ -276,32 +279,16 @@ | |
| 279 | while( (zLine = transport_receive_line(GLOBAL_URL()))!=0 && zLine[0]!=0 ){ |
| 280 | /* printf("[%s]\n", zLine); fflush(stdout); */ |
| 281 | if( fossil_strnicmp(zLine, "http/1.", 7)==0 ){ |
| 282 | if( sscanf(zLine, "HTTP/1.%d %d", &iHttpVersion, &rc)!=2 ) goto write_err; |
| 283 | if( rc==401 ){ |
| 284 | if( fSeenHttpAuth++ < MAX_HTTP_AUTH ){ |
| 285 | if( g.zHttpAuth ){ |
| 286 | if( g.zHttpAuth ) free(g.zHttpAuth); |
| 287 | } |
| 288 | g.zHttpAuth = prompt_for_httpauth_creds(); |
| 289 | transport_close(GLOBAL_URL()); |
| 290 | return http_exchange(pSend, pReply, useLogin, maxRedirect); |
| 291 | } |
| 292 | } |
| 293 | if( rc!=200 && rc!=302 ){ |
| 294 | int ii; |
| 295 |