Fossil SCM

Handle --once preference and prevent sending HTTP Authorization when the URL is named on the command line.

andybradford 2014-02-01 23:39 http-auth
Commit 2600f59f2d1e983439e55a38717c2de12245a710
+14 -8
--- src/clone.c
+++ src/clone.c
@@ -116,18 +116,17 @@
116116
** See also: init
117117
*/
118118
void clone_cmd(void){
119119
char *zPassword;
120120
const char *zDefaultUser; /* Optional name of the default user */
121
- int fUseHttpAuth; /* Use HTTP auth if requested by user */
122121
int nErr = 0;
123122
int bPrivate = 0; /* Also clone private branches */
124123
int urlFlags = URL_PROMPT_PW | URL_REMEMBER;
125124
126125
if( find_option("private",0,0)!=0 ) bPrivate = SYNC_PRIVATE;
127126
if( find_option("once",0,0)!=0) urlFlags &= ~URL_REMEMBER;
128
- fUseHttpAuth = find_option("httpauth","B",0)!=0;
127
+ g.fUseHttpAuth = find_option("httpauth","B",0)!=0;
129128
zDefaultUser = find_option("admin-user","A",1);
130129
clone_ssh_find_options();
131130
url_proxy_options();
132131
if( g.argc < 4 ){
133132
usage("?OPTIONS? FILE-OR-URL NEW-REPOSITORY");
@@ -162,11 +161,11 @@
162161
db_initial_setup(0, 0, zDefaultUser, 0);
163162
user_select();
164163
db_set("content-schema", CONTENT_SCHEMA, 0);
165164
db_set("aux-schema", AUX_SCHEMA, 0);
166165
db_set("rebuilt", get_version(), 0);
167
- remember_http_auth(fUseHttpAuth,g.argv[2]);
166
+ remember_or_get_http_auth(urlFlags & URL_REMEMBER, g.argv[2]);
168167
url_remember();
169168
if( g.zSSLIdentity!=0 ){
170169
/* If the --ssl-identity option was specified, store it as a setting */
171170
Blob fn;
172171
blob_zero(&fn);
@@ -204,16 +203,23 @@
204203
205204
/*
206205
** If user chooses to use HTTP Authentication over unencrypted HTTP,
207206
** remember decision. Otherwise, if the URL is being changed and no preference
208207
** has been indicated, err on the safe side and revert the decision.
208
+** Set the global preference if the URL is not being changed.
209209
*/
210
-void remember_http_auth(int fUseHttpAuth, const char *zUrl){
211
- if( fUseHttpAuth==1 ){
212
- db_set_int("use-http-auth", 1, 0);
213
- }else if( zUrl && zUrl[0] ){
214
- db_unset("use-http-auth", 0);
210
+void remember_or_get_http_auth(int fRemember, const char *zUrl){
211
+ if( fRemember ){
212
+ if( g.fUseHttpAuth==1 ){
213
+ db_set_int("use-http-auth", 1, 0);
214
+ }else if( zUrl && zUrl[0] ){
215
+ db_unset("use-http-auth", 0);
216
+ }else{
217
+ g.fUseHttpAuth = db_get_boolean("use-http-auth",0)!=0;
218
+ }
219
+ }else if( g.fUseHttpAuth==0 && zUrl==0 ){
220
+ g.fUseHttpAuth = db_get_boolean("use-http-auth",0)!=0;
215221
}
216222
}
217223
218224
/*
219225
** Look for SSH clone command line options and setup in globals.
220226
--- src/clone.c
+++ src/clone.c
@@ -116,18 +116,17 @@
116 ** See also: init
117 */
118 void clone_cmd(void){
119 char *zPassword;
120 const char *zDefaultUser; /* Optional name of the default user */
121 int fUseHttpAuth; /* Use HTTP auth if requested by user */
122 int nErr = 0;
123 int bPrivate = 0; /* Also clone private branches */
124 int urlFlags = URL_PROMPT_PW | URL_REMEMBER;
125
126 if( find_option("private",0,0)!=0 ) bPrivate = SYNC_PRIVATE;
127 if( find_option("once",0,0)!=0) urlFlags &= ~URL_REMEMBER;
128 fUseHttpAuth = find_option("httpauth","B",0)!=0;
129 zDefaultUser = find_option("admin-user","A",1);
130 clone_ssh_find_options();
131 url_proxy_options();
132 if( g.argc < 4 ){
133 usage("?OPTIONS? FILE-OR-URL NEW-REPOSITORY");
@@ -162,11 +161,11 @@
162 db_initial_setup(0, 0, zDefaultUser, 0);
163 user_select();
164 db_set("content-schema", CONTENT_SCHEMA, 0);
165 db_set("aux-schema", AUX_SCHEMA, 0);
166 db_set("rebuilt", get_version(), 0);
167 remember_http_auth(fUseHttpAuth,g.argv[2]);
168 url_remember();
169 if( g.zSSLIdentity!=0 ){
170 /* If the --ssl-identity option was specified, store it as a setting */
171 Blob fn;
172 blob_zero(&fn);
@@ -204,16 +203,23 @@
204
205 /*
206 ** If user chooses to use HTTP Authentication over unencrypted HTTP,
207 ** remember decision. Otherwise, if the URL is being changed and no preference
208 ** has been indicated, err on the safe side and revert the decision.
 
209 */
210 void remember_http_auth(int fUseHttpAuth, const char *zUrl){
211 if( fUseHttpAuth==1 ){
212 db_set_int("use-http-auth", 1, 0);
213 }else if( zUrl && zUrl[0] ){
214 db_unset("use-http-auth", 0);
 
 
 
 
 
 
215 }
216 }
217
218 /*
219 ** Look for SSH clone command line options and setup in globals.
220
--- src/clone.c
+++ src/clone.c
@@ -116,18 +116,17 @@
116 ** See also: init
117 */
118 void clone_cmd(void){
119 char *zPassword;
120 const char *zDefaultUser; /* Optional name of the default user */
 
121 int nErr = 0;
122 int bPrivate = 0; /* Also clone private branches */
123 int urlFlags = URL_PROMPT_PW | URL_REMEMBER;
124
125 if( find_option("private",0,0)!=0 ) bPrivate = SYNC_PRIVATE;
126 if( find_option("once",0,0)!=0) urlFlags &= ~URL_REMEMBER;
127 g.fUseHttpAuth = find_option("httpauth","B",0)!=0;
128 zDefaultUser = find_option("admin-user","A",1);
129 clone_ssh_find_options();
130 url_proxy_options();
131 if( g.argc < 4 ){
132 usage("?OPTIONS? FILE-OR-URL NEW-REPOSITORY");
@@ -162,11 +161,11 @@
161 db_initial_setup(0, 0, zDefaultUser, 0);
162 user_select();
163 db_set("content-schema", CONTENT_SCHEMA, 0);
164 db_set("aux-schema", AUX_SCHEMA, 0);
165 db_set("rebuilt", get_version(), 0);
166 remember_or_get_http_auth(urlFlags & URL_REMEMBER, g.argv[2]);
167 url_remember();
168 if( g.zSSLIdentity!=0 ){
169 /* If the --ssl-identity option was specified, store it as a setting */
170 Blob fn;
171 blob_zero(&fn);
@@ -204,16 +203,23 @@
203
204 /*
205 ** If user chooses to use HTTP Authentication over unencrypted HTTP,
206 ** remember decision. Otherwise, if the URL is being changed and no preference
207 ** has been indicated, err on the safe side and revert the decision.
208 ** Set the global preference if the URL is not being changed.
209 */
210 void remember_or_get_http_auth(int fRemember, const char *zUrl){
211 if( fRemember ){
212 if( g.fUseHttpAuth==1 ){
213 db_set_int("use-http-auth", 1, 0);
214 }else if( zUrl && zUrl[0] ){
215 db_unset("use-http-auth", 0);
216 }else{
217 g.fUseHttpAuth = db_get_boolean("use-http-auth",0)!=0;
218 }
219 }else if( g.fUseHttpAuth==0 && zUrl==0 ){
220 g.fUseHttpAuth = db_get_boolean("use-http-auth",0)!=0;
221 }
222 }
223
224 /*
225 ** Look for SSH clone command line options and setup in globals.
226
+4 -8
--- src/http.c
+++ src/http.c
@@ -76,15 +76,10 @@
7676
blob_reset(&pw);
7777
blob_reset(&sig);
7878
blob_reset(&nonce);
7979
}
8080
81
-/*
82
-** Use HTTP Basic Authorization if a 401 is seen.
83
-*/
84
-static int fUseHttpAuth = 0;
85
-
8681
/*
8782
** Construct an appropriate HTTP request header. Write the header
8883
** into pHdr. This routine initializes the pHdr blob. pPayload is
8984
** the complete payload (including the login card) already compressed.
9085
*/
@@ -101,11 +96,11 @@
10196
}
10297
blob_appendf(pHdr, "POST %s%sxfer/xfer HTTP/1.0\r\n", g.urlPath, zSep);
10398
if( g.urlProxyAuth ){
10499
blob_appendf(pHdr, "Proxy-Authorization: %s\r\n", g.urlProxyAuth);
105100
}
106
- if( g.urlPasswd && g.urlUser && fUseHttpAuth ){
101
+ if( g.urlPasswd && g.urlUser && g.fUseHttpAuth ){
107102
char *zCredentials = mprintf("%s:%s", g.urlUser, g.urlPasswd);
108103
char *zEncoded = encode64(zCredentials, -1);
109104
blob_appendf(pHdr, "Authorization: Basic %s\r\n", zEncoded);
110105
fossil_free(zEncoded);
111106
fossil_free(zCredentials);
@@ -205,12 +200,13 @@
205200
while( (zLine = transport_receive_line(GLOBAL_URL()))!=0 && zLine[0]!=0 ){
206201
/* printf("[%s]\n", zLine); fflush(stdout); */
207202
if( fossil_strnicmp(zLine, "http/1.", 7)==0 ){
208203
if( sscanf(zLine, "HTTP/1.%d %d", &iHttpVersion, &rc)!=2 ) goto write_err;
209204
if( rc==401 ){
210
- if( g.urlIsHttps || db_get_boolean("use-http-auth",0)!=0 ){
211
- fUseHttpAuth = 1;
205
+ if( g.urlIsHttps || g.fUseHttpAuth ){
206
+ /* set g.fUseHttpAuth to avoid loop when doing HTTPS */
207
+ g.fUseHttpAuth = 1;
212208
transport_close(GLOBAL_URL());
213209
if( --maxRedirect == 0 ){
214210
fossil_fatal("http authorization limit exceeded");
215211
}
216212
return http_exchange(pSend, pReply, useLogin, maxRedirect);
217213
--- src/http.c
+++ src/http.c
@@ -76,15 +76,10 @@
76 blob_reset(&pw);
77 blob_reset(&sig);
78 blob_reset(&nonce);
79 }
80
81 /*
82 ** Use HTTP Basic Authorization if a 401 is seen.
83 */
84 static int fUseHttpAuth = 0;
85
86 /*
87 ** Construct an appropriate HTTP request header. Write the header
88 ** into pHdr. This routine initializes the pHdr blob. pPayload is
89 ** the complete payload (including the login card) already compressed.
90 */
@@ -101,11 +96,11 @@
101 }
102 blob_appendf(pHdr, "POST %s%sxfer/xfer HTTP/1.0\r\n", g.urlPath, zSep);
103 if( g.urlProxyAuth ){
104 blob_appendf(pHdr, "Proxy-Authorization: %s\r\n", g.urlProxyAuth);
105 }
106 if( g.urlPasswd && g.urlUser && fUseHttpAuth ){
107 char *zCredentials = mprintf("%s:%s", g.urlUser, g.urlPasswd);
108 char *zEncoded = encode64(zCredentials, -1);
109 blob_appendf(pHdr, "Authorization: Basic %s\r\n", zEncoded);
110 fossil_free(zEncoded);
111 fossil_free(zCredentials);
@@ -205,12 +200,13 @@
205 while( (zLine = transport_receive_line(GLOBAL_URL()))!=0 && zLine[0]!=0 ){
206 /* printf("[%s]\n", zLine); fflush(stdout); */
207 if( fossil_strnicmp(zLine, "http/1.", 7)==0 ){
208 if( sscanf(zLine, "HTTP/1.%d %d", &iHttpVersion, &rc)!=2 ) goto write_err;
209 if( rc==401 ){
210 if( g.urlIsHttps || db_get_boolean("use-http-auth",0)!=0 ){
211 fUseHttpAuth = 1;
 
212 transport_close(GLOBAL_URL());
213 if( --maxRedirect == 0 ){
214 fossil_fatal("http authorization limit exceeded");
215 }
216 return http_exchange(pSend, pReply, useLogin, maxRedirect);
217
--- src/http.c
+++ src/http.c
@@ -76,15 +76,10 @@
76 blob_reset(&pw);
77 blob_reset(&sig);
78 blob_reset(&nonce);
79 }
80
 
 
 
 
 
81 /*
82 ** Construct an appropriate HTTP request header. Write the header
83 ** into pHdr. This routine initializes the pHdr blob. pPayload is
84 ** the complete payload (including the login card) already compressed.
85 */
@@ -101,11 +96,11 @@
96 }
97 blob_appendf(pHdr, "POST %s%sxfer/xfer HTTP/1.0\r\n", g.urlPath, zSep);
98 if( g.urlProxyAuth ){
99 blob_appendf(pHdr, "Proxy-Authorization: %s\r\n", g.urlProxyAuth);
100 }
101 if( g.urlPasswd && g.urlUser && g.fUseHttpAuth ){
102 char *zCredentials = mprintf("%s:%s", g.urlUser, g.urlPasswd);
103 char *zEncoded = encode64(zCredentials, -1);
104 blob_appendf(pHdr, "Authorization: Basic %s\r\n", zEncoded);
105 fossil_free(zEncoded);
106 fossil_free(zCredentials);
@@ -205,12 +200,13 @@
200 while( (zLine = transport_receive_line(GLOBAL_URL()))!=0 && zLine[0]!=0 ){
201 /* printf("[%s]\n", zLine); fflush(stdout); */
202 if( fossil_strnicmp(zLine, "http/1.", 7)==0 ){
203 if( sscanf(zLine, "HTTP/1.%d %d", &iHttpVersion, &rc)!=2 ) goto write_err;
204 if( rc==401 ){
205 if( g.urlIsHttps || g.fUseHttpAuth ){
206 /* set g.fUseHttpAuth to avoid loop when doing HTTPS */
207 g.fUseHttpAuth = 1;
208 transport_close(GLOBAL_URL());
209 if( --maxRedirect == 0 ){
210 fossil_fatal("http authorization limit exceeded");
211 }
212 return http_exchange(pSend, pReply, useLogin, maxRedirect);
213
+1
--- src/main.c
+++ src/main.c
@@ -139,10 +139,11 @@
139139
int fSqlTrace; /* True if --sqltrace flag is present */
140140
int fSqlStats; /* True if --sqltrace or --sqlstats are present */
141141
int fSqlPrint; /* True if -sqlprint flag is present */
142142
int fQuiet; /* True if -quiet flag is present */
143143
int fHttpTrace; /* Trace outbound HTTP requests */
144
+ int fUseHttpAuth; /* True if user requests HTTP Authorization */
144145
int fSystemTrace; /* Trace calls to fossil_system(), --systemtrace */
145146
int fSshTrace; /* Trace the SSH setup traffic */
146147
int fSshClient; /* HTTP client flags for SSH client */
147148
char *zSshCmd; /* SSH command string */
148149
int fNoSync; /* Do not do an autosync ever. --nosync */
149150
--- src/main.c
+++ src/main.c
@@ -139,10 +139,11 @@
139 int fSqlTrace; /* True if --sqltrace flag is present */
140 int fSqlStats; /* True if --sqltrace or --sqlstats are present */
141 int fSqlPrint; /* True if -sqlprint flag is present */
142 int fQuiet; /* True if -quiet flag is present */
143 int fHttpTrace; /* Trace outbound HTTP requests */
 
144 int fSystemTrace; /* Trace calls to fossil_system(), --systemtrace */
145 int fSshTrace; /* Trace the SSH setup traffic */
146 int fSshClient; /* HTTP client flags for SSH client */
147 char *zSshCmd; /* SSH command string */
148 int fNoSync; /* Do not do an autosync ever. --nosync */
149
--- src/main.c
+++ src/main.c
@@ -139,10 +139,11 @@
139 int fSqlTrace; /* True if --sqltrace flag is present */
140 int fSqlStats; /* True if --sqltrace or --sqlstats are present */
141 int fSqlPrint; /* True if -sqlprint flag is present */
142 int fQuiet; /* True if -quiet flag is present */
143 int fHttpTrace; /* Trace outbound HTTP requests */
144 int fUseHttpAuth; /* True if user requests HTTP Authorization */
145 int fSystemTrace; /* Trace calls to fossil_system(), --systemtrace */
146 int fSshTrace; /* Trace the SSH setup traffic */
147 int fSshClient; /* HTTP client flags for SSH client */
148 char *zSshCmd; /* SSH command string */
149 int fNoSync; /* Do not do an autosync ever. --nosync */
150
+2 -3
--- src/sync.c
+++ src/sync.c
@@ -83,19 +83,18 @@
8383
** of a server to sync against. If no argument is given, use the
8484
** most recently synced URL. Remember the current URL for next time.
8585
*/
8686
static void process_sync_args(unsigned *pConfigFlags, unsigned *pSyncFlags){
8787
const char *zUrl = 0;
88
- int fUseHttpAuth; /* Use HTTP auth if requested by user */
8988
unsigned configSync = 0;
9089
unsigned urlFlags = URL_REMEMBER | URL_PROMPT_PW;
9190
int urlOptional = 0;
9291
if( find_option("autourl",0,0)!=0 ){
9392
urlOptional = 1;
9493
urlFlags = 0;
9594
}
96
- fUseHttpAuth = find_option("httpauth",0,0)!=0;
95
+ g.fUseHttpAuth = find_option("httpauth",0,0)!=0;
9796
if( find_option("once",0,0)!=0 ) urlFlags &= ~URL_REMEMBER;
9897
if( find_option("private",0,0)!=0 ){
9998
*pSyncFlags |= SYNC_PRIVATE;
10099
}
101100
if( find_option("verbose","v",0)!=0 ){
@@ -118,11 +117,11 @@
118117
}
119118
if( urlFlags & URL_REMEMBER ){
120119
clone_ssh_db_set_options();
121120
}
122121
url_parse(zUrl, urlFlags);
123
- remember_http_auth(fUseHttpAuth,zUrl);
122
+ remember_or_get_http_auth(urlFlags & URL_REMEMBER, zUrl);
124123
url_remember();
125124
if( g.urlProtocol==0 ){
126125
if( urlOptional ) fossil_exit(0);
127126
usage("URL");
128127
}
129128
--- src/sync.c
+++ src/sync.c
@@ -83,19 +83,18 @@
83 ** of a server to sync against. If no argument is given, use the
84 ** most recently synced URL. Remember the current URL for next time.
85 */
86 static void process_sync_args(unsigned *pConfigFlags, unsigned *pSyncFlags){
87 const char *zUrl = 0;
88 int fUseHttpAuth; /* Use HTTP auth if requested by user */
89 unsigned configSync = 0;
90 unsigned urlFlags = URL_REMEMBER | URL_PROMPT_PW;
91 int urlOptional = 0;
92 if( find_option("autourl",0,0)!=0 ){
93 urlOptional = 1;
94 urlFlags = 0;
95 }
96 fUseHttpAuth = find_option("httpauth",0,0)!=0;
97 if( find_option("once",0,0)!=0 ) urlFlags &= ~URL_REMEMBER;
98 if( find_option("private",0,0)!=0 ){
99 *pSyncFlags |= SYNC_PRIVATE;
100 }
101 if( find_option("verbose","v",0)!=0 ){
@@ -118,11 +117,11 @@
118 }
119 if( urlFlags & URL_REMEMBER ){
120 clone_ssh_db_set_options();
121 }
122 url_parse(zUrl, urlFlags);
123 remember_http_auth(fUseHttpAuth,zUrl);
124 url_remember();
125 if( g.urlProtocol==0 ){
126 if( urlOptional ) fossil_exit(0);
127 usage("URL");
128 }
129
--- src/sync.c
+++ src/sync.c
@@ -83,19 +83,18 @@
83 ** of a server to sync against. If no argument is given, use the
84 ** most recently synced URL. Remember the current URL for next time.
85 */
86 static void process_sync_args(unsigned *pConfigFlags, unsigned *pSyncFlags){
87 const char *zUrl = 0;
 
88 unsigned configSync = 0;
89 unsigned urlFlags = URL_REMEMBER | URL_PROMPT_PW;
90 int urlOptional = 0;
91 if( find_option("autourl",0,0)!=0 ){
92 urlOptional = 1;
93 urlFlags = 0;
94 }
95 g.fUseHttpAuth = find_option("httpauth",0,0)!=0;
96 if( find_option("once",0,0)!=0 ) urlFlags &= ~URL_REMEMBER;
97 if( find_option("private",0,0)!=0 ){
98 *pSyncFlags |= SYNC_PRIVATE;
99 }
100 if( find_option("verbose","v",0)!=0 ){
@@ -118,11 +117,11 @@
117 }
118 if( urlFlags & URL_REMEMBER ){
119 clone_ssh_db_set_options();
120 }
121 url_parse(zUrl, urlFlags);
122 remember_or_get_http_auth(urlFlags & URL_REMEMBER, zUrl);
123 url_remember();
124 if( g.urlProtocol==0 ){
125 if( urlOptional ) fossil_exit(0);
126 usage("URL");
127 }
128

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button