Fossil SCM
docker experiment: create project-code at first valid push.
Commit
98e3626c0a1229e7deabe3a9e98610fa39192dbe
Parent
06987be586ed5b6…
2 files changed
-6
+10
-5
M
src/db.c
-6
| --- src/db.c | ||
| +++ src/db.c | ||
| @@ -1335,16 +1335,10 @@ | ||
| 1335 | 1335 | db_multi_exec( |
| 1336 | 1336 | "INSERT INTO config(name,value,mtime)" |
| 1337 | 1337 | " VALUES('server-code', lower(hex(randomblob(20))),now());" |
| 1338 | 1338 | ); |
| 1339 | 1339 | } |
| 1340 | - if( db_get("project-code", 0)==0 ) { | |
| 1341 | - db_multi_exec( | |
| 1342 | - "INSERT INTO config(name,value,mtime)" | |
| 1343 | - " VALUES('project-code', lower(hex(randomblob(20))),now());" | |
| 1344 | - ); | |
| 1345 | - } | |
| 1346 | 1340 | } |
| 1347 | 1341 | } |
| 1348 | 1342 | |
| 1349 | 1343 | /* |
| 1350 | 1344 | ** Return a pointer to a string that contains the RHS of an IN operator |
| 1351 | 1345 |
| --- src/db.c | |
| +++ src/db.c | |
| @@ -1335,16 +1335,10 @@ | |
| 1335 | db_multi_exec( |
| 1336 | "INSERT INTO config(name,value,mtime)" |
| 1337 | " VALUES('server-code', lower(hex(randomblob(20))),now());" |
| 1338 | ); |
| 1339 | } |
| 1340 | if( db_get("project-code", 0)==0 ) { |
| 1341 | db_multi_exec( |
| 1342 | "INSERT INTO config(name,value,mtime)" |
| 1343 | " VALUES('project-code', lower(hex(randomblob(20))),now());" |
| 1344 | ); |
| 1345 | } |
| 1346 | } |
| 1347 | } |
| 1348 | |
| 1349 | /* |
| 1350 | ** Return a pointer to a string that contains the RHS of an IN operator |
| 1351 |
| --- src/db.c | |
| +++ src/db.c | |
| @@ -1335,16 +1335,10 @@ | |
| 1335 | db_multi_exec( |
| 1336 | "INSERT INTO config(name,value,mtime)" |
| 1337 | " VALUES('server-code', lower(hex(randomblob(20))),now());" |
| 1338 | ); |
| 1339 | } |
| 1340 | } |
| 1341 | } |
| 1342 | |
| 1343 | /* |
| 1344 | ** Return a pointer to a string that contains the RHS of an IN operator |
| 1345 |
+10
-5
| --- src/xfer.c | ||
| +++ src/xfer.c | ||
| @@ -1065,29 +1065,34 @@ | ||
| 1065 | 1065 | |
| 1066 | 1066 | /* pull SERVERCODE PROJECTCODE |
| 1067 | 1067 | ** push SERVERCODE PROJECTCODE |
| 1068 | 1068 | ** |
| 1069 | 1069 | ** The client wants either send or receive. The server should |
| 1070 | - ** verify that the project code matches. | |
| 1070 | + ** verify that the project code matches. If there is no project | |
| 1071 | + ** code yet, set the new project code to the provided one. | |
| 1071 | 1072 | */ |
| 1072 | 1073 | if( xfer.nToken==3 |
| 1073 | 1074 | && (blob_eq(&xfer.aToken[0], "pull") || blob_eq(&xfer.aToken[0], "push")) |
| 1074 | 1075 | && blob_is_uuid(&xfer.aToken[1]) |
| 1075 | 1076 | && blob_is_uuid(&xfer.aToken[2]) |
| 1076 | 1077 | ){ |
| 1077 | 1078 | const char *zPCode; |
| 1078 | 1079 | zPCode = db_get("project-code", 0); |
| 1080 | + login_check_credentials(); | |
| 1079 | 1081 | if( zPCode==0 ){ |
| 1080 | - fossil_panic("missing project code"); | |
| 1081 | - } | |
| 1082 | - if( !blob_eq_str(&xfer.aToken[2], zPCode, -1) ){ | |
| 1082 | + if( g.perm.Write ){ | |
| 1083 | + db_set("project-code", blob_str(&xfer.aToken[2]), 0); | |
| 1084 | + zPCode = db_get("project-code", 0); | |
| 1085 | + }else{ | |
| 1086 | + fossil_panic("missing project code"); | |
| 1087 | + } | |
| 1088 | + } else if( !blob_eq_str(&xfer.aToken[2], zPCode, -1) ){ | |
| 1083 | 1089 | cgi_reset_content(); |
| 1084 | 1090 | @ error wrong\sproject |
| 1085 | 1091 | nErr++; |
| 1086 | 1092 | break; |
| 1087 | 1093 | } |
| 1088 | - login_check_credentials(); | |
| 1089 | 1094 | if( blob_eq(&xfer.aToken[0], "pull") ){ |
| 1090 | 1095 | if( !g.perm.Read ){ |
| 1091 | 1096 | cgi_reset_content(); |
| 1092 | 1097 | @ error not\sauthorized\sto\sread |
| 1093 | 1098 | nErr++; |
| 1094 | 1099 |
| --- src/xfer.c | |
| +++ src/xfer.c | |
| @@ -1065,29 +1065,34 @@ | |
| 1065 | |
| 1066 | /* pull SERVERCODE PROJECTCODE |
| 1067 | ** push SERVERCODE PROJECTCODE |
| 1068 | ** |
| 1069 | ** The client wants either send or receive. The server should |
| 1070 | ** verify that the project code matches. |
| 1071 | */ |
| 1072 | if( xfer.nToken==3 |
| 1073 | && (blob_eq(&xfer.aToken[0], "pull") || blob_eq(&xfer.aToken[0], "push")) |
| 1074 | && blob_is_uuid(&xfer.aToken[1]) |
| 1075 | && blob_is_uuid(&xfer.aToken[2]) |
| 1076 | ){ |
| 1077 | const char *zPCode; |
| 1078 | zPCode = db_get("project-code", 0); |
| 1079 | if( zPCode==0 ){ |
| 1080 | fossil_panic("missing project code"); |
| 1081 | } |
| 1082 | if( !blob_eq_str(&xfer.aToken[2], zPCode, -1) ){ |
| 1083 | cgi_reset_content(); |
| 1084 | @ error wrong\sproject |
| 1085 | nErr++; |
| 1086 | break; |
| 1087 | } |
| 1088 | login_check_credentials(); |
| 1089 | if( blob_eq(&xfer.aToken[0], "pull") ){ |
| 1090 | if( !g.perm.Read ){ |
| 1091 | cgi_reset_content(); |
| 1092 | @ error not\sauthorized\sto\sread |
| 1093 | nErr++; |
| 1094 |
| --- src/xfer.c | |
| +++ src/xfer.c | |
| @@ -1065,29 +1065,34 @@ | |
| 1065 | |
| 1066 | /* pull SERVERCODE PROJECTCODE |
| 1067 | ** push SERVERCODE PROJECTCODE |
| 1068 | ** |
| 1069 | ** The client wants either send or receive. The server should |
| 1070 | ** verify that the project code matches. If there is no project |
| 1071 | ** code yet, set the new project code to the provided one. |
| 1072 | */ |
| 1073 | if( xfer.nToken==3 |
| 1074 | && (blob_eq(&xfer.aToken[0], "pull") || blob_eq(&xfer.aToken[0], "push")) |
| 1075 | && blob_is_uuid(&xfer.aToken[1]) |
| 1076 | && blob_is_uuid(&xfer.aToken[2]) |
| 1077 | ){ |
| 1078 | const char *zPCode; |
| 1079 | zPCode = db_get("project-code", 0); |
| 1080 | login_check_credentials(); |
| 1081 | if( zPCode==0 ){ |
| 1082 | if( g.perm.Write ){ |
| 1083 | db_set("project-code", blob_str(&xfer.aToken[2]), 0); |
| 1084 | zPCode = db_get("project-code", 0); |
| 1085 | }else{ |
| 1086 | fossil_panic("missing project code"); |
| 1087 | } |
| 1088 | } else if( !blob_eq_str(&xfer.aToken[2], zPCode, -1) ){ |
| 1089 | cgi_reset_content(); |
| 1090 | @ error wrong\sproject |
| 1091 | nErr++; |
| 1092 | break; |
| 1093 | } |
| 1094 | if( blob_eq(&xfer.aToken[0], "pull") ){ |
| 1095 | if( !g.perm.Read ){ |
| 1096 | cgi_reset_content(); |
| 1097 | @ error not\sauthorized\sto\sread |
| 1098 | nErr++; |
| 1099 |