Fossil SCM
Fixes and enhancements to SEE integration on Windows.
Commit
57d8a71f4257418a8ccd12dd723d64bceda8de60d07a34ccc8379ed4baea9514
Parent
094fb2ef0cd96df…
5 files changed
+28
+57
-28
+57
-28
+2
+7
-5
M
src/db.c
+28
| --- src/db.c | ||
| +++ src/db.c | ||
| @@ -1182,10 +1182,36 @@ | ||
| 1182 | 1182 | } |
| 1183 | 1183 | }else{ |
| 1184 | 1184 | fossil_panic("failed to open pid %lu: %lu", processId, GetLastError()); |
| 1185 | 1185 | } |
| 1186 | 1186 | } |
| 1187 | + | |
| 1188 | +/* | |
| 1189 | +** This function evaluates the specified TH1 script and attempts to parse | |
| 1190 | +** its result as a colon-delimited triplet containing a process identifier, | |
| 1191 | +** address, and size (in bytes) of the database encryption key. This is | |
| 1192 | +** only necessary (or functional) on Windows. | |
| 1193 | +*/ | |
| 1194 | +void db_read_saved_encryption_key_from_process_via_th1( | |
| 1195 | + const char *zConfig /* The TH1 script to evaluate. */ | |
| 1196 | +){ | |
| 1197 | + int rc; | |
| 1198 | + char *zResult; | |
| 1199 | + Th_FossilInit(TH_INIT_DEFAULT | TH_INIT_NEED_CONFIG | TH_INIT_NO_REPO); | |
| 1200 | + rc = Th_Eval(g.interp, 0, zConfig, -1); | |
| 1201 | + zResult = (char*)Th_GetResult(g.interp, 0); | |
| 1202 | + if( rc!=TH_OK ){ | |
| 1203 | + fossil_fatal("script for pid key failed: %s", zResult); | |
| 1204 | + } | |
| 1205 | + if( zResult ){ | |
| 1206 | + DWORD processId = 0; | |
| 1207 | + LPVOID pAddress = NULL; | |
| 1208 | + SIZE_T nSize = 0; | |
| 1209 | + parse_pid_key_value(zResult, &processId, &pAddress, &nSize); | |
| 1210 | + db_read_saved_encryption_key_from_process(processId, pAddress, nSize); | |
| 1211 | + } | |
| 1212 | +} | |
| 1187 | 1213 | #endif /* defined(_WIN32) */ |
| 1188 | 1214 | #endif /* USE_SEE */ |
| 1189 | 1215 | |
| 1190 | 1216 | /* |
| 1191 | 1217 | ** If the database file zDbFile has a name that suggests that it is |
| @@ -1386,10 +1412,11 @@ | ||
| 1386 | 1412 | int rc; |
| 1387 | 1413 | sqlite3_wal_checkpoint(g.db, 0); |
| 1388 | 1414 | rc = sqlite3_close(g.db); |
| 1389 | 1415 | if( g.fSqlTrace ) fossil_trace("-- db_close_config(%d)\n", rc); |
| 1390 | 1416 | g.db = 0; |
| 1417 | + g.repositoryOpen = 0; | |
| 1391 | 1418 | }else{ |
| 1392 | 1419 | return; |
| 1393 | 1420 | } |
| 1394 | 1421 | fossil_free(g.zConfigDbName); |
| 1395 | 1422 | g.zConfigDbName = 0; |
| @@ -3932,10 +3959,11 @@ | ||
| 3932 | 3959 | sqlite3_open(":memory:", &g.db); |
| 3933 | 3960 | rDiff = db_double(0.0, "SELECT julianday('now') - julianday(%Q)", g.argv[2]); |
| 3934 | 3961 | fossil_print("Time differences: %s\n", db_timespan_name(rDiff)); |
| 3935 | 3962 | sqlite3_close(g.db); |
| 3936 | 3963 | g.db = 0; |
| 3964 | + g.repositoryOpen = 0; | |
| 3937 | 3965 | } |
| 3938 | 3966 | |
| 3939 | 3967 | /* |
| 3940 | 3968 | ** COMMAND: test-without-rowid |
| 3941 | 3969 | ** |
| 3942 | 3970 |
| --- src/db.c | |
| +++ src/db.c | |
| @@ -1182,10 +1182,36 @@ | |
| 1182 | } |
| 1183 | }else{ |
| 1184 | fossil_panic("failed to open pid %lu: %lu", processId, GetLastError()); |
| 1185 | } |
| 1186 | } |
| 1187 | #endif /* defined(_WIN32) */ |
| 1188 | #endif /* USE_SEE */ |
| 1189 | |
| 1190 | /* |
| 1191 | ** If the database file zDbFile has a name that suggests that it is |
| @@ -1386,10 +1412,11 @@ | |
| 1386 | int rc; |
| 1387 | sqlite3_wal_checkpoint(g.db, 0); |
| 1388 | rc = sqlite3_close(g.db); |
| 1389 | if( g.fSqlTrace ) fossil_trace("-- db_close_config(%d)\n", rc); |
| 1390 | g.db = 0; |
| 1391 | }else{ |
| 1392 | return; |
| 1393 | } |
| 1394 | fossil_free(g.zConfigDbName); |
| 1395 | g.zConfigDbName = 0; |
| @@ -3932,10 +3959,11 @@ | |
| 3932 | sqlite3_open(":memory:", &g.db); |
| 3933 | rDiff = db_double(0.0, "SELECT julianday('now') - julianday(%Q)", g.argv[2]); |
| 3934 | fossil_print("Time differences: %s\n", db_timespan_name(rDiff)); |
| 3935 | sqlite3_close(g.db); |
| 3936 | g.db = 0; |
| 3937 | } |
| 3938 | |
| 3939 | /* |
| 3940 | ** COMMAND: test-without-rowid |
| 3941 | ** |
| 3942 |
| --- src/db.c | |
| +++ src/db.c | |
| @@ -1182,10 +1182,36 @@ | |
| 1182 | } |
| 1183 | }else{ |
| 1184 | fossil_panic("failed to open pid %lu: %lu", processId, GetLastError()); |
| 1185 | } |
| 1186 | } |
| 1187 | |
| 1188 | /* |
| 1189 | ** This function evaluates the specified TH1 script and attempts to parse |
| 1190 | ** its result as a colon-delimited triplet containing a process identifier, |
| 1191 | ** address, and size (in bytes) of the database encryption key. This is |
| 1192 | ** only necessary (or functional) on Windows. |
| 1193 | */ |
| 1194 | void db_read_saved_encryption_key_from_process_via_th1( |
| 1195 | const char *zConfig /* The TH1 script to evaluate. */ |
| 1196 | ){ |
| 1197 | int rc; |
| 1198 | char *zResult; |
| 1199 | Th_FossilInit(TH_INIT_DEFAULT | TH_INIT_NEED_CONFIG | TH_INIT_NO_REPO); |
| 1200 | rc = Th_Eval(g.interp, 0, zConfig, -1); |
| 1201 | zResult = (char*)Th_GetResult(g.interp, 0); |
| 1202 | if( rc!=TH_OK ){ |
| 1203 | fossil_fatal("script for pid key failed: %s", zResult); |
| 1204 | } |
| 1205 | if( zResult ){ |
| 1206 | DWORD processId = 0; |
| 1207 | LPVOID pAddress = NULL; |
| 1208 | SIZE_T nSize = 0; |
| 1209 | parse_pid_key_value(zResult, &processId, &pAddress, &nSize); |
| 1210 | db_read_saved_encryption_key_from_process(processId, pAddress, nSize); |
| 1211 | } |
| 1212 | } |
| 1213 | #endif /* defined(_WIN32) */ |
| 1214 | #endif /* USE_SEE */ |
| 1215 | |
| 1216 | /* |
| 1217 | ** If the database file zDbFile has a name that suggests that it is |
| @@ -1386,10 +1412,11 @@ | |
| 1412 | int rc; |
| 1413 | sqlite3_wal_checkpoint(g.db, 0); |
| 1414 | rc = sqlite3_close(g.db); |
| 1415 | if( g.fSqlTrace ) fossil_trace("-- db_close_config(%d)\n", rc); |
| 1416 | g.db = 0; |
| 1417 | g.repositoryOpen = 0; |
| 1418 | }else{ |
| 1419 | return; |
| 1420 | } |
| 1421 | fossil_free(g.zConfigDbName); |
| 1422 | g.zConfigDbName = 0; |
| @@ -3932,10 +3959,11 @@ | |
| 3959 | sqlite3_open(":memory:", &g.db); |
| 3960 | rDiff = db_double(0.0, "SELECT julianday('now') - julianday(%Q)", g.argv[2]); |
| 3961 | fossil_print("Time differences: %s\n", db_timespan_name(rDiff)); |
| 3962 | sqlite3_close(g.db); |
| 3963 | g.db = 0; |
| 3964 | g.repositoryOpen = 0; |
| 3965 | } |
| 3966 | |
| 3967 | /* |
| 3968 | ** COMMAND: test-without-rowid |
| 3969 | ** |
| 3970 |
+57
-28
| --- src/main.c | ||
| +++ src/main.c | ||
| @@ -210,10 +210,14 @@ | ||
| 210 | 210 | Blob httpHeader; /* Complete text of the HTTP request header */ |
| 211 | 211 | UrlData url; /* Information about current URL */ |
| 212 | 212 | const char *zLogin; /* Login name. NULL or "" if not logged in. */ |
| 213 | 213 | const char *zSSLIdentity; /* Value of --ssl-identity option, filename of |
| 214 | 214 | ** SSL client identity */ |
| 215 | +#if defined(_WIN32) && USE_SEE | |
| 216 | + const char *zPidKey; /* Saved value of the --usepidkey option. Only | |
| 217 | + * applicable when using SEE on Windows. */ | |
| 218 | +#endif | |
| 215 | 219 | int useLocalauth; /* No login required if from 127.0.0.1 */ |
| 216 | 220 | int noPswd; /* Logged in without password (on 127.0.0.1) */ |
| 217 | 221 | int userUid; /* Integer user id */ |
| 218 | 222 | int isHuman; /* True if access by a human, not a spider or bot */ |
| 219 | 223 | int comFmtFlags; /* Zero or more "COMMENT_PRINT_*" bit flags, should be |
| @@ -758,10 +762,30 @@ | ||
| 758 | 762 | if( find_option("utc",0,0) ) g.fTimeFormat = 1; |
| 759 | 763 | if( find_option("localtime",0,0) ) g.fTimeFormat = 2; |
| 760 | 764 | if( zChdir && file_chdir(zChdir, 0) ){ |
| 761 | 765 | fossil_fatal("unable to change directories to %s", zChdir); |
| 762 | 766 | } |
| 767 | +#if defined(_WIN32) && USE_SEE | |
| 768 | + { | |
| 769 | + g.zPidKey = find_option("usepidkey",0,1); | |
| 770 | + if( g.zPidKey ){ | |
| 771 | + DWORD processId = 0; | |
| 772 | + LPVOID pAddress = NULL; | |
| 773 | + SIZE_T nSize = 0; | |
| 774 | + parse_pid_key_value(g.zPidKey, &processId, &pAddress, &nSize); | |
| 775 | + db_read_saved_encryption_key_from_process(processId, pAddress, nSize); | |
| 776 | + }else{ | |
| 777 | + const char *zSeeDbConfig = find_option("seedbcfg",0,1); | |
| 778 | + if( !zSeeDbConfig ){ | |
| 779 | + zSeeDbConfig = fossil_getenv("FOSSIL_SEE_DB_CONFIG"); | |
| 780 | + } | |
| 781 | + if( zSeeDbConfig ){ | |
| 782 | + db_read_saved_encryption_key_from_process_via_th1(zSeeDbConfig); | |
| 783 | + } | |
| 784 | + } | |
| 785 | + } | |
| 786 | +#endif | |
| 763 | 787 | if( find_option("help",0,0)!=0 ){ |
| 764 | 788 | /* If --help is found anywhere on the command line, translate the command |
| 765 | 789 | * to "fossil help cmdname" where "cmdname" is the first argument that |
| 766 | 790 | * does not begin with a "-" character. If all arguments start with "-", |
| 767 | 791 | * translate to "fossil help argv[1] argv[2]...". */ |
| @@ -2345,10 +2369,43 @@ | ||
| 2345 | 2369 | }else{ |
| 2346 | 2370 | fossil_fatal("failed to parse pid key"); |
| 2347 | 2371 | } |
| 2348 | 2372 | } |
| 2349 | 2373 | #endif |
| 2374 | + | |
| 2375 | +/* | |
| 2376 | +** WEBPAGE: test-pid | |
| 2377 | +** | |
| 2378 | +** Return the process identifier of the running Fossil server instance. | |
| 2379 | +** | |
| 2380 | +** Query parameters: | |
| 2381 | +** | |
| 2382 | +** usepidkey When present and available, also return the | |
| 2383 | +** address and size, within this server process, | |
| 2384 | +** of the saved database encryption key. This | |
| 2385 | +** is only supported when using SEE on Windows. | |
| 2386 | +*/ | |
| 2387 | +void test_pid_page(void){ | |
| 2388 | + login_check_credentials(); | |
| 2389 | + if( !g.perm.Setup ){ login_needed(0); return; } | |
| 2390 | +#if defined(_WIN32) && USE_SEE | |
| 2391 | + if( P("usepidkey")!=0 ){ | |
| 2392 | + if( g.zPidKey ){ | |
| 2393 | + @ %s(g.zPidKey) | |
| 2394 | + return; | |
| 2395 | + }else{ | |
| 2396 | + const char *zSavedKey = db_get_saved_encryption_key(); | |
| 2397 | + size_t savedKeySize = db_get_saved_encryption_key_size(); | |
| 2398 | + if( zSavedKey!=0 && savedKeySize>0 ){ | |
| 2399 | + @ %lu(GetCurrentProcessId()):%p(zSavedKey):%u(savedKeySize) | |
| 2400 | + return; | |
| 2401 | + } | |
| 2402 | + } | |
| 2403 | + } | |
| 2404 | +#endif | |
| 2405 | + @ %d(GETPID()) | |
| 2406 | +} | |
| 2350 | 2407 | |
| 2351 | 2408 | /* |
| 2352 | 2409 | ** COMMAND: http* |
| 2353 | 2410 | ** |
| 2354 | 2411 | ** Usage: %fossil http ?REPOSITORY? ?OPTIONS? |
| @@ -2413,13 +2470,10 @@ | ||
| 2413 | 2470 | const char *zInFile; |
| 2414 | 2471 | const char *zOutFile; |
| 2415 | 2472 | int useSCGI; |
| 2416 | 2473 | int noJail; |
| 2417 | 2474 | int allowRepoList; |
| 2418 | -#if defined(_WIN32) && USE_SEE | |
| 2419 | - const char *zPidKey; | |
| 2420 | -#endif | |
| 2421 | 2475 | |
| 2422 | 2476 | Th_InitTraceLog(); |
| 2423 | 2477 | |
| 2424 | 2478 | /* The winhttp module passes the --files option as --files-urlenc with |
| 2425 | 2479 | ** the argument being URL encoded, to avoid wildcard expansion in the |
| @@ -2466,21 +2520,10 @@ | ||
| 2466 | 2520 | cgi_replace_parameter("HTTPS","on"); |
| 2467 | 2521 | } |
| 2468 | 2522 | zHost = find_option("host", 0, 1); |
| 2469 | 2523 | if( zHost ) cgi_replace_parameter("HTTP_HOST",zHost); |
| 2470 | 2524 | |
| 2471 | -#if defined(_WIN32) && USE_SEE | |
| 2472 | - zPidKey = find_option("usepidkey", 0, 1); | |
| 2473 | - if( zPidKey ){ | |
| 2474 | - DWORD processId = 0; | |
| 2475 | - LPVOID pAddress = NULL; | |
| 2476 | - SIZE_T nSize = 0; | |
| 2477 | - parse_pid_key_value(zPidKey, &processId, &pAddress, &nSize); | |
| 2478 | - db_read_saved_encryption_key_from_process(processId, pAddress, nSize); | |
| 2479 | - } | |
| 2480 | -#endif | |
| 2481 | - | |
| 2482 | 2525 | /* We should be done with options.. */ |
| 2483 | 2526 | verify_all_options(); |
| 2484 | 2527 | |
| 2485 | 2528 | if( g.argc!=2 && g.argc!=3 ) usage("?REPOSITORY?"); |
| 2486 | 2529 | g.cgiOutput = 1; |
| @@ -2695,13 +2738,10 @@ | ||
| 2695 | 2738 | const char *zAltBase; /* Argument to the --baseurl option */ |
| 2696 | 2739 | const char *zFileGlob; /* Static content must match this */ |
| 2697 | 2740 | char *zIpAddr = 0; /* Bind to this IP address */ |
| 2698 | 2741 | int fCreate = 0; /* The --create flag */ |
| 2699 | 2742 | const char *zInitPage = 0; /* Start on this page. --page option */ |
| 2700 | -#if defined(_WIN32) && USE_SEE | |
| 2701 | - const char *zPidKey; | |
| 2702 | -#endif | |
| 2703 | 2743 | |
| 2704 | 2744 | #if defined(_WIN32) |
| 2705 | 2745 | const char *zStopperFile; /* Name of file used to terminate server */ |
| 2706 | 2746 | zStopperFile = find_option("stopper", 0, 1); |
| 2707 | 2747 | #endif |
| @@ -2745,21 +2785,10 @@ | ||
| 2745 | 2785 | } |
| 2746 | 2786 | if( find_option("localhost", 0, 0)!=0 ){ |
| 2747 | 2787 | flags |= HTTP_SERVER_LOCALHOST; |
| 2748 | 2788 | } |
| 2749 | 2789 | |
| 2750 | -#if defined(_WIN32) && USE_SEE | |
| 2751 | - zPidKey = find_option("usepidkey", 0, 1); | |
| 2752 | - if( zPidKey ){ | |
| 2753 | - DWORD processId = 0; | |
| 2754 | - LPVOID pAddress = NULL; | |
| 2755 | - SIZE_T nSize = 0; | |
| 2756 | - parse_pid_key_value(zPidKey, &processId, &pAddress, &nSize); | |
| 2757 | - db_read_saved_encryption_key_from_process(processId, pAddress, nSize); | |
| 2758 | - } | |
| 2759 | -#endif | |
| 2760 | - | |
| 2761 | 2790 | /* We should be done with options.. */ |
| 2762 | 2791 | verify_all_options(); |
| 2763 | 2792 | |
| 2764 | 2793 | if( g.argc!=2 && g.argc!=3 ) usage("?REPOSITORY?"); |
| 2765 | 2794 | if( isUiCmd ){ |
| 2766 | 2795 |
| --- src/main.c | |
| +++ src/main.c | |
| @@ -210,10 +210,14 @@ | |
| 210 | Blob httpHeader; /* Complete text of the HTTP request header */ |
| 211 | UrlData url; /* Information about current URL */ |
| 212 | const char *zLogin; /* Login name. NULL or "" if not logged in. */ |
| 213 | const char *zSSLIdentity; /* Value of --ssl-identity option, filename of |
| 214 | ** SSL client identity */ |
| 215 | int useLocalauth; /* No login required if from 127.0.0.1 */ |
| 216 | int noPswd; /* Logged in without password (on 127.0.0.1) */ |
| 217 | int userUid; /* Integer user id */ |
| 218 | int isHuman; /* True if access by a human, not a spider or bot */ |
| 219 | int comFmtFlags; /* Zero or more "COMMENT_PRINT_*" bit flags, should be |
| @@ -758,10 +762,30 @@ | |
| 758 | if( find_option("utc",0,0) ) g.fTimeFormat = 1; |
| 759 | if( find_option("localtime",0,0) ) g.fTimeFormat = 2; |
| 760 | if( zChdir && file_chdir(zChdir, 0) ){ |
| 761 | fossil_fatal("unable to change directories to %s", zChdir); |
| 762 | } |
| 763 | if( find_option("help",0,0)!=0 ){ |
| 764 | /* If --help is found anywhere on the command line, translate the command |
| 765 | * to "fossil help cmdname" where "cmdname" is the first argument that |
| 766 | * does not begin with a "-" character. If all arguments start with "-", |
| 767 | * translate to "fossil help argv[1] argv[2]...". */ |
| @@ -2345,10 +2369,43 @@ | |
| 2345 | }else{ |
| 2346 | fossil_fatal("failed to parse pid key"); |
| 2347 | } |
| 2348 | } |
| 2349 | #endif |
| 2350 | |
| 2351 | /* |
| 2352 | ** COMMAND: http* |
| 2353 | ** |
| 2354 | ** Usage: %fossil http ?REPOSITORY? ?OPTIONS? |
| @@ -2413,13 +2470,10 @@ | |
| 2413 | const char *zInFile; |
| 2414 | const char *zOutFile; |
| 2415 | int useSCGI; |
| 2416 | int noJail; |
| 2417 | int allowRepoList; |
| 2418 | #if defined(_WIN32) && USE_SEE |
| 2419 | const char *zPidKey; |
| 2420 | #endif |
| 2421 | |
| 2422 | Th_InitTraceLog(); |
| 2423 | |
| 2424 | /* The winhttp module passes the --files option as --files-urlenc with |
| 2425 | ** the argument being URL encoded, to avoid wildcard expansion in the |
| @@ -2466,21 +2520,10 @@ | |
| 2466 | cgi_replace_parameter("HTTPS","on"); |
| 2467 | } |
| 2468 | zHost = find_option("host", 0, 1); |
| 2469 | if( zHost ) cgi_replace_parameter("HTTP_HOST",zHost); |
| 2470 | |
| 2471 | #if defined(_WIN32) && USE_SEE |
| 2472 | zPidKey = find_option("usepidkey", 0, 1); |
| 2473 | if( zPidKey ){ |
| 2474 | DWORD processId = 0; |
| 2475 | LPVOID pAddress = NULL; |
| 2476 | SIZE_T nSize = 0; |
| 2477 | parse_pid_key_value(zPidKey, &processId, &pAddress, &nSize); |
| 2478 | db_read_saved_encryption_key_from_process(processId, pAddress, nSize); |
| 2479 | } |
| 2480 | #endif |
| 2481 | |
| 2482 | /* We should be done with options.. */ |
| 2483 | verify_all_options(); |
| 2484 | |
| 2485 | if( g.argc!=2 && g.argc!=3 ) usage("?REPOSITORY?"); |
| 2486 | g.cgiOutput = 1; |
| @@ -2695,13 +2738,10 @@ | |
| 2695 | const char *zAltBase; /* Argument to the --baseurl option */ |
| 2696 | const char *zFileGlob; /* Static content must match this */ |
| 2697 | char *zIpAddr = 0; /* Bind to this IP address */ |
| 2698 | int fCreate = 0; /* The --create flag */ |
| 2699 | const char *zInitPage = 0; /* Start on this page. --page option */ |
| 2700 | #if defined(_WIN32) && USE_SEE |
| 2701 | const char *zPidKey; |
| 2702 | #endif |
| 2703 | |
| 2704 | #if defined(_WIN32) |
| 2705 | const char *zStopperFile; /* Name of file used to terminate server */ |
| 2706 | zStopperFile = find_option("stopper", 0, 1); |
| 2707 | #endif |
| @@ -2745,21 +2785,10 @@ | |
| 2745 | } |
| 2746 | if( find_option("localhost", 0, 0)!=0 ){ |
| 2747 | flags |= HTTP_SERVER_LOCALHOST; |
| 2748 | } |
| 2749 | |
| 2750 | #if defined(_WIN32) && USE_SEE |
| 2751 | zPidKey = find_option("usepidkey", 0, 1); |
| 2752 | if( zPidKey ){ |
| 2753 | DWORD processId = 0; |
| 2754 | LPVOID pAddress = NULL; |
| 2755 | SIZE_T nSize = 0; |
| 2756 | parse_pid_key_value(zPidKey, &processId, &pAddress, &nSize); |
| 2757 | db_read_saved_encryption_key_from_process(processId, pAddress, nSize); |
| 2758 | } |
| 2759 | #endif |
| 2760 | |
| 2761 | /* We should be done with options.. */ |
| 2762 | verify_all_options(); |
| 2763 | |
| 2764 | if( g.argc!=2 && g.argc!=3 ) usage("?REPOSITORY?"); |
| 2765 | if( isUiCmd ){ |
| 2766 |
| --- src/main.c | |
| +++ src/main.c | |
| @@ -210,10 +210,14 @@ | |
| 210 | Blob httpHeader; /* Complete text of the HTTP request header */ |
| 211 | UrlData url; /* Information about current URL */ |
| 212 | const char *zLogin; /* Login name. NULL or "" if not logged in. */ |
| 213 | const char *zSSLIdentity; /* Value of --ssl-identity option, filename of |
| 214 | ** SSL client identity */ |
| 215 | #if defined(_WIN32) && USE_SEE |
| 216 | const char *zPidKey; /* Saved value of the --usepidkey option. Only |
| 217 | * applicable when using SEE on Windows. */ |
| 218 | #endif |
| 219 | int useLocalauth; /* No login required if from 127.0.0.1 */ |
| 220 | int noPswd; /* Logged in without password (on 127.0.0.1) */ |
| 221 | int userUid; /* Integer user id */ |
| 222 | int isHuman; /* True if access by a human, not a spider or bot */ |
| 223 | int comFmtFlags; /* Zero or more "COMMENT_PRINT_*" bit flags, should be |
| @@ -758,10 +762,30 @@ | |
| 762 | if( find_option("utc",0,0) ) g.fTimeFormat = 1; |
| 763 | if( find_option("localtime",0,0) ) g.fTimeFormat = 2; |
| 764 | if( zChdir && file_chdir(zChdir, 0) ){ |
| 765 | fossil_fatal("unable to change directories to %s", zChdir); |
| 766 | } |
| 767 | #if defined(_WIN32) && USE_SEE |
| 768 | { |
| 769 | g.zPidKey = find_option("usepidkey",0,1); |
| 770 | if( g.zPidKey ){ |
| 771 | DWORD processId = 0; |
| 772 | LPVOID pAddress = NULL; |
| 773 | SIZE_T nSize = 0; |
| 774 | parse_pid_key_value(g.zPidKey, &processId, &pAddress, &nSize); |
| 775 | db_read_saved_encryption_key_from_process(processId, pAddress, nSize); |
| 776 | }else{ |
| 777 | const char *zSeeDbConfig = find_option("seedbcfg",0,1); |
| 778 | if( !zSeeDbConfig ){ |
| 779 | zSeeDbConfig = fossil_getenv("FOSSIL_SEE_DB_CONFIG"); |
| 780 | } |
| 781 | if( zSeeDbConfig ){ |
| 782 | db_read_saved_encryption_key_from_process_via_th1(zSeeDbConfig); |
| 783 | } |
| 784 | } |
| 785 | } |
| 786 | #endif |
| 787 | if( find_option("help",0,0)!=0 ){ |
| 788 | /* If --help is found anywhere on the command line, translate the command |
| 789 | * to "fossil help cmdname" where "cmdname" is the first argument that |
| 790 | * does not begin with a "-" character. If all arguments start with "-", |
| 791 | * translate to "fossil help argv[1] argv[2]...". */ |
| @@ -2345,10 +2369,43 @@ | |
| 2369 | }else{ |
| 2370 | fossil_fatal("failed to parse pid key"); |
| 2371 | } |
| 2372 | } |
| 2373 | #endif |
| 2374 | |
| 2375 | /* |
| 2376 | ** WEBPAGE: test-pid |
| 2377 | ** |
| 2378 | ** Return the process identifier of the running Fossil server instance. |
| 2379 | ** |
| 2380 | ** Query parameters: |
| 2381 | ** |
| 2382 | ** usepidkey When present and available, also return the |
| 2383 | ** address and size, within this server process, |
| 2384 | ** of the saved database encryption key. This |
| 2385 | ** is only supported when using SEE on Windows. |
| 2386 | */ |
| 2387 | void test_pid_page(void){ |
| 2388 | login_check_credentials(); |
| 2389 | if( !g.perm.Setup ){ login_needed(0); return; } |
| 2390 | #if defined(_WIN32) && USE_SEE |
| 2391 | if( P("usepidkey")!=0 ){ |
| 2392 | if( g.zPidKey ){ |
| 2393 | @ %s(g.zPidKey) |
| 2394 | return; |
| 2395 | }else{ |
| 2396 | const char *zSavedKey = db_get_saved_encryption_key(); |
| 2397 | size_t savedKeySize = db_get_saved_encryption_key_size(); |
| 2398 | if( zSavedKey!=0 && savedKeySize>0 ){ |
| 2399 | @ %lu(GetCurrentProcessId()):%p(zSavedKey):%u(savedKeySize) |
| 2400 | return; |
| 2401 | } |
| 2402 | } |
| 2403 | } |
| 2404 | #endif |
| 2405 | @ %d(GETPID()) |
| 2406 | } |
| 2407 | |
| 2408 | /* |
| 2409 | ** COMMAND: http* |
| 2410 | ** |
| 2411 | ** Usage: %fossil http ?REPOSITORY? ?OPTIONS? |
| @@ -2413,13 +2470,10 @@ | |
| 2470 | const char *zInFile; |
| 2471 | const char *zOutFile; |
| 2472 | int useSCGI; |
| 2473 | int noJail; |
| 2474 | int allowRepoList; |
| 2475 | |
| 2476 | Th_InitTraceLog(); |
| 2477 | |
| 2478 | /* The winhttp module passes the --files option as --files-urlenc with |
| 2479 | ** the argument being URL encoded, to avoid wildcard expansion in the |
| @@ -2466,21 +2520,10 @@ | |
| 2520 | cgi_replace_parameter("HTTPS","on"); |
| 2521 | } |
| 2522 | zHost = find_option("host", 0, 1); |
| 2523 | if( zHost ) cgi_replace_parameter("HTTP_HOST",zHost); |
| 2524 | |
| 2525 | /* We should be done with options.. */ |
| 2526 | verify_all_options(); |
| 2527 | |
| 2528 | if( g.argc!=2 && g.argc!=3 ) usage("?REPOSITORY?"); |
| 2529 | g.cgiOutput = 1; |
| @@ -2695,13 +2738,10 @@ | |
| 2738 | const char *zAltBase; /* Argument to the --baseurl option */ |
| 2739 | const char *zFileGlob; /* Static content must match this */ |
| 2740 | char *zIpAddr = 0; /* Bind to this IP address */ |
| 2741 | int fCreate = 0; /* The --create flag */ |
| 2742 | const char *zInitPage = 0; /* Start on this page. --page option */ |
| 2743 | |
| 2744 | #if defined(_WIN32) |
| 2745 | const char *zStopperFile; /* Name of file used to terminate server */ |
| 2746 | zStopperFile = find_option("stopper", 0, 1); |
| 2747 | #endif |
| @@ -2745,21 +2785,10 @@ | |
| 2785 | } |
| 2786 | if( find_option("localhost", 0, 0)!=0 ){ |
| 2787 | flags |= HTTP_SERVER_LOCALHOST; |
| 2788 | } |
| 2789 | |
| 2790 | /* We should be done with options.. */ |
| 2791 | verify_all_options(); |
| 2792 | |
| 2793 | if( g.argc!=2 && g.argc!=3 ) usage("?REPOSITORY?"); |
| 2794 | if( isUiCmd ){ |
| 2795 |
+57
-28
| --- src/main.c | ||
| +++ src/main.c | ||
| @@ -210,10 +210,14 @@ | ||
| 210 | 210 | Blob httpHeader; /* Complete text of the HTTP request header */ |
| 211 | 211 | UrlData url; /* Information about current URL */ |
| 212 | 212 | const char *zLogin; /* Login name. NULL or "" if not logged in. */ |
| 213 | 213 | const char *zSSLIdentity; /* Value of --ssl-identity option, filename of |
| 214 | 214 | ** SSL client identity */ |
| 215 | +#if defined(_WIN32) && USE_SEE | |
| 216 | + const char *zPidKey; /* Saved value of the --usepidkey option. Only | |
| 217 | + * applicable when using SEE on Windows. */ | |
| 218 | +#endif | |
| 215 | 219 | int useLocalauth; /* No login required if from 127.0.0.1 */ |
| 216 | 220 | int noPswd; /* Logged in without password (on 127.0.0.1) */ |
| 217 | 221 | int userUid; /* Integer user id */ |
| 218 | 222 | int isHuman; /* True if access by a human, not a spider or bot */ |
| 219 | 223 | int comFmtFlags; /* Zero or more "COMMENT_PRINT_*" bit flags, should be |
| @@ -758,10 +762,30 @@ | ||
| 758 | 762 | if( find_option("utc",0,0) ) g.fTimeFormat = 1; |
| 759 | 763 | if( find_option("localtime",0,0) ) g.fTimeFormat = 2; |
| 760 | 764 | if( zChdir && file_chdir(zChdir, 0) ){ |
| 761 | 765 | fossil_fatal("unable to change directories to %s", zChdir); |
| 762 | 766 | } |
| 767 | +#if defined(_WIN32) && USE_SEE | |
| 768 | + { | |
| 769 | + g.zPidKey = find_option("usepidkey",0,1); | |
| 770 | + if( g.zPidKey ){ | |
| 771 | + DWORD processId = 0; | |
| 772 | + LPVOID pAddress = NULL; | |
| 773 | + SIZE_T nSize = 0; | |
| 774 | + parse_pid_key_value(g.zPidKey, &processId, &pAddress, &nSize); | |
| 775 | + db_read_saved_encryption_key_from_process(processId, pAddress, nSize); | |
| 776 | + }else{ | |
| 777 | + const char *zSeeDbConfig = find_option("seedbcfg",0,1); | |
| 778 | + if( !zSeeDbConfig ){ | |
| 779 | + zSeeDbConfig = fossil_getenv("FOSSIL_SEE_DB_CONFIG"); | |
| 780 | + } | |
| 781 | + if( zSeeDbConfig ){ | |
| 782 | + db_read_saved_encryption_key_from_process_via_th1(zSeeDbConfig); | |
| 783 | + } | |
| 784 | + } | |
| 785 | + } | |
| 786 | +#endif | |
| 763 | 787 | if( find_option("help",0,0)!=0 ){ |
| 764 | 788 | /* If --help is found anywhere on the command line, translate the command |
| 765 | 789 | * to "fossil help cmdname" where "cmdname" is the first argument that |
| 766 | 790 | * does not begin with a "-" character. If all arguments start with "-", |
| 767 | 791 | * translate to "fossil help argv[1] argv[2]...". */ |
| @@ -2345,10 +2369,43 @@ | ||
| 2345 | 2369 | }else{ |
| 2346 | 2370 | fossil_fatal("failed to parse pid key"); |
| 2347 | 2371 | } |
| 2348 | 2372 | } |
| 2349 | 2373 | #endif |
| 2374 | + | |
| 2375 | +/* | |
| 2376 | +** WEBPAGE: test-pid | |
| 2377 | +** | |
| 2378 | +** Return the process identifier of the running Fossil server instance. | |
| 2379 | +** | |
| 2380 | +** Query parameters: | |
| 2381 | +** | |
| 2382 | +** usepidkey When present and available, also return the | |
| 2383 | +** address and size, within this server process, | |
| 2384 | +** of the saved database encryption key. This | |
| 2385 | +** is only supported when using SEE on Windows. | |
| 2386 | +*/ | |
| 2387 | +void test_pid_page(void){ | |
| 2388 | + login_check_credentials(); | |
| 2389 | + if( !g.perm.Setup ){ login_needed(0); return; } | |
| 2390 | +#if defined(_WIN32) && USE_SEE | |
| 2391 | + if( P("usepidkey")!=0 ){ | |
| 2392 | + if( g.zPidKey ){ | |
| 2393 | + @ %s(g.zPidKey) | |
| 2394 | + return; | |
| 2395 | + }else{ | |
| 2396 | + const char *zSavedKey = db_get_saved_encryption_key(); | |
| 2397 | + size_t savedKeySize = db_get_saved_encryption_key_size(); | |
| 2398 | + if( zSavedKey!=0 && savedKeySize>0 ){ | |
| 2399 | + @ %lu(GetCurrentProcessId()):%p(zSavedKey):%u(savedKeySize) | |
| 2400 | + return; | |
| 2401 | + } | |
| 2402 | + } | |
| 2403 | + } | |
| 2404 | +#endif | |
| 2405 | + @ %d(GETPID()) | |
| 2406 | +} | |
| 2350 | 2407 | |
| 2351 | 2408 | /* |
| 2352 | 2409 | ** COMMAND: http* |
| 2353 | 2410 | ** |
| 2354 | 2411 | ** Usage: %fossil http ?REPOSITORY? ?OPTIONS? |
| @@ -2413,13 +2470,10 @@ | ||
| 2413 | 2470 | const char *zInFile; |
| 2414 | 2471 | const char *zOutFile; |
| 2415 | 2472 | int useSCGI; |
| 2416 | 2473 | int noJail; |
| 2417 | 2474 | int allowRepoList; |
| 2418 | -#if defined(_WIN32) && USE_SEE | |
| 2419 | - const char *zPidKey; | |
| 2420 | -#endif | |
| 2421 | 2475 | |
| 2422 | 2476 | Th_InitTraceLog(); |
| 2423 | 2477 | |
| 2424 | 2478 | /* The winhttp module passes the --files option as --files-urlenc with |
| 2425 | 2479 | ** the argument being URL encoded, to avoid wildcard expansion in the |
| @@ -2466,21 +2520,10 @@ | ||
| 2466 | 2520 | cgi_replace_parameter("HTTPS","on"); |
| 2467 | 2521 | } |
| 2468 | 2522 | zHost = find_option("host", 0, 1); |
| 2469 | 2523 | if( zHost ) cgi_replace_parameter("HTTP_HOST",zHost); |
| 2470 | 2524 | |
| 2471 | -#if defined(_WIN32) && USE_SEE | |
| 2472 | - zPidKey = find_option("usepidkey", 0, 1); | |
| 2473 | - if( zPidKey ){ | |
| 2474 | - DWORD processId = 0; | |
| 2475 | - LPVOID pAddress = NULL; | |
| 2476 | - SIZE_T nSize = 0; | |
| 2477 | - parse_pid_key_value(zPidKey, &processId, &pAddress, &nSize); | |
| 2478 | - db_read_saved_encryption_key_from_process(processId, pAddress, nSize); | |
| 2479 | - } | |
| 2480 | -#endif | |
| 2481 | - | |
| 2482 | 2525 | /* We should be done with options.. */ |
| 2483 | 2526 | verify_all_options(); |
| 2484 | 2527 | |
| 2485 | 2528 | if( g.argc!=2 && g.argc!=3 ) usage("?REPOSITORY?"); |
| 2486 | 2529 | g.cgiOutput = 1; |
| @@ -2695,13 +2738,10 @@ | ||
| 2695 | 2738 | const char *zAltBase; /* Argument to the --baseurl option */ |
| 2696 | 2739 | const char *zFileGlob; /* Static content must match this */ |
| 2697 | 2740 | char *zIpAddr = 0; /* Bind to this IP address */ |
| 2698 | 2741 | int fCreate = 0; /* The --create flag */ |
| 2699 | 2742 | const char *zInitPage = 0; /* Start on this page. --page option */ |
| 2700 | -#if defined(_WIN32) && USE_SEE | |
| 2701 | - const char *zPidKey; | |
| 2702 | -#endif | |
| 2703 | 2743 | |
| 2704 | 2744 | #if defined(_WIN32) |
| 2705 | 2745 | const char *zStopperFile; /* Name of file used to terminate server */ |
| 2706 | 2746 | zStopperFile = find_option("stopper", 0, 1); |
| 2707 | 2747 | #endif |
| @@ -2745,21 +2785,10 @@ | ||
| 2745 | 2785 | } |
| 2746 | 2786 | if( find_option("localhost", 0, 0)!=0 ){ |
| 2747 | 2787 | flags |= HTTP_SERVER_LOCALHOST; |
| 2748 | 2788 | } |
| 2749 | 2789 | |
| 2750 | -#if defined(_WIN32) && USE_SEE | |
| 2751 | - zPidKey = find_option("usepidkey", 0, 1); | |
| 2752 | - if( zPidKey ){ | |
| 2753 | - DWORD processId = 0; | |
| 2754 | - LPVOID pAddress = NULL; | |
| 2755 | - SIZE_T nSize = 0; | |
| 2756 | - parse_pid_key_value(zPidKey, &processId, &pAddress, &nSize); | |
| 2757 | - db_read_saved_encryption_key_from_process(processId, pAddress, nSize); | |
| 2758 | - } | |
| 2759 | -#endif | |
| 2760 | - | |
| 2761 | 2790 | /* We should be done with options.. */ |
| 2762 | 2791 | verify_all_options(); |
| 2763 | 2792 | |
| 2764 | 2793 | if( g.argc!=2 && g.argc!=3 ) usage("?REPOSITORY?"); |
| 2765 | 2794 | if( isUiCmd ){ |
| 2766 | 2795 |
| --- src/main.c | |
| +++ src/main.c | |
| @@ -210,10 +210,14 @@ | |
| 210 | Blob httpHeader; /* Complete text of the HTTP request header */ |
| 211 | UrlData url; /* Information about current URL */ |
| 212 | const char *zLogin; /* Login name. NULL or "" if not logged in. */ |
| 213 | const char *zSSLIdentity; /* Value of --ssl-identity option, filename of |
| 214 | ** SSL client identity */ |
| 215 | int useLocalauth; /* No login required if from 127.0.0.1 */ |
| 216 | int noPswd; /* Logged in without password (on 127.0.0.1) */ |
| 217 | int userUid; /* Integer user id */ |
| 218 | int isHuman; /* True if access by a human, not a spider or bot */ |
| 219 | int comFmtFlags; /* Zero or more "COMMENT_PRINT_*" bit flags, should be |
| @@ -758,10 +762,30 @@ | |
| 758 | if( find_option("utc",0,0) ) g.fTimeFormat = 1; |
| 759 | if( find_option("localtime",0,0) ) g.fTimeFormat = 2; |
| 760 | if( zChdir && file_chdir(zChdir, 0) ){ |
| 761 | fossil_fatal("unable to change directories to %s", zChdir); |
| 762 | } |
| 763 | if( find_option("help",0,0)!=0 ){ |
| 764 | /* If --help is found anywhere on the command line, translate the command |
| 765 | * to "fossil help cmdname" where "cmdname" is the first argument that |
| 766 | * does not begin with a "-" character. If all arguments start with "-", |
| 767 | * translate to "fossil help argv[1] argv[2]...". */ |
| @@ -2345,10 +2369,43 @@ | |
| 2345 | }else{ |
| 2346 | fossil_fatal("failed to parse pid key"); |
| 2347 | } |
| 2348 | } |
| 2349 | #endif |
| 2350 | |
| 2351 | /* |
| 2352 | ** COMMAND: http* |
| 2353 | ** |
| 2354 | ** Usage: %fossil http ?REPOSITORY? ?OPTIONS? |
| @@ -2413,13 +2470,10 @@ | |
| 2413 | const char *zInFile; |
| 2414 | const char *zOutFile; |
| 2415 | int useSCGI; |
| 2416 | int noJail; |
| 2417 | int allowRepoList; |
| 2418 | #if defined(_WIN32) && USE_SEE |
| 2419 | const char *zPidKey; |
| 2420 | #endif |
| 2421 | |
| 2422 | Th_InitTraceLog(); |
| 2423 | |
| 2424 | /* The winhttp module passes the --files option as --files-urlenc with |
| 2425 | ** the argument being URL encoded, to avoid wildcard expansion in the |
| @@ -2466,21 +2520,10 @@ | |
| 2466 | cgi_replace_parameter("HTTPS","on"); |
| 2467 | } |
| 2468 | zHost = find_option("host", 0, 1); |
| 2469 | if( zHost ) cgi_replace_parameter("HTTP_HOST",zHost); |
| 2470 | |
| 2471 | #if defined(_WIN32) && USE_SEE |
| 2472 | zPidKey = find_option("usepidkey", 0, 1); |
| 2473 | if( zPidKey ){ |
| 2474 | DWORD processId = 0; |
| 2475 | LPVOID pAddress = NULL; |
| 2476 | SIZE_T nSize = 0; |
| 2477 | parse_pid_key_value(zPidKey, &processId, &pAddress, &nSize); |
| 2478 | db_read_saved_encryption_key_from_process(processId, pAddress, nSize); |
| 2479 | } |
| 2480 | #endif |
| 2481 | |
| 2482 | /* We should be done with options.. */ |
| 2483 | verify_all_options(); |
| 2484 | |
| 2485 | if( g.argc!=2 && g.argc!=3 ) usage("?REPOSITORY?"); |
| 2486 | g.cgiOutput = 1; |
| @@ -2695,13 +2738,10 @@ | |
| 2695 | const char *zAltBase; /* Argument to the --baseurl option */ |
| 2696 | const char *zFileGlob; /* Static content must match this */ |
| 2697 | char *zIpAddr = 0; /* Bind to this IP address */ |
| 2698 | int fCreate = 0; /* The --create flag */ |
| 2699 | const char *zInitPage = 0; /* Start on this page. --page option */ |
| 2700 | #if defined(_WIN32) && USE_SEE |
| 2701 | const char *zPidKey; |
| 2702 | #endif |
| 2703 | |
| 2704 | #if defined(_WIN32) |
| 2705 | const char *zStopperFile; /* Name of file used to terminate server */ |
| 2706 | zStopperFile = find_option("stopper", 0, 1); |
| 2707 | #endif |
| @@ -2745,21 +2785,10 @@ | |
| 2745 | } |
| 2746 | if( find_option("localhost", 0, 0)!=0 ){ |
| 2747 | flags |= HTTP_SERVER_LOCALHOST; |
| 2748 | } |
| 2749 | |
| 2750 | #if defined(_WIN32) && USE_SEE |
| 2751 | zPidKey = find_option("usepidkey", 0, 1); |
| 2752 | if( zPidKey ){ |
| 2753 | DWORD processId = 0; |
| 2754 | LPVOID pAddress = NULL; |
| 2755 | SIZE_T nSize = 0; |
| 2756 | parse_pid_key_value(zPidKey, &processId, &pAddress, &nSize); |
| 2757 | db_read_saved_encryption_key_from_process(processId, pAddress, nSize); |
| 2758 | } |
| 2759 | #endif |
| 2760 | |
| 2761 | /* We should be done with options.. */ |
| 2762 | verify_all_options(); |
| 2763 | |
| 2764 | if( g.argc!=2 && g.argc!=3 ) usage("?REPOSITORY?"); |
| 2765 | if( isUiCmd ){ |
| 2766 |
| --- src/main.c | |
| +++ src/main.c | |
| @@ -210,10 +210,14 @@ | |
| 210 | Blob httpHeader; /* Complete text of the HTTP request header */ |
| 211 | UrlData url; /* Information about current URL */ |
| 212 | const char *zLogin; /* Login name. NULL or "" if not logged in. */ |
| 213 | const char *zSSLIdentity; /* Value of --ssl-identity option, filename of |
| 214 | ** SSL client identity */ |
| 215 | #if defined(_WIN32) && USE_SEE |
| 216 | const char *zPidKey; /* Saved value of the --usepidkey option. Only |
| 217 | * applicable when using SEE on Windows. */ |
| 218 | #endif |
| 219 | int useLocalauth; /* No login required if from 127.0.0.1 */ |
| 220 | int noPswd; /* Logged in without password (on 127.0.0.1) */ |
| 221 | int userUid; /* Integer user id */ |
| 222 | int isHuman; /* True if access by a human, not a spider or bot */ |
| 223 | int comFmtFlags; /* Zero or more "COMMENT_PRINT_*" bit flags, should be |
| @@ -758,10 +762,30 @@ | |
| 762 | if( find_option("utc",0,0) ) g.fTimeFormat = 1; |
| 763 | if( find_option("localtime",0,0) ) g.fTimeFormat = 2; |
| 764 | if( zChdir && file_chdir(zChdir, 0) ){ |
| 765 | fossil_fatal("unable to change directories to %s", zChdir); |
| 766 | } |
| 767 | #if defined(_WIN32) && USE_SEE |
| 768 | { |
| 769 | g.zPidKey = find_option("usepidkey",0,1); |
| 770 | if( g.zPidKey ){ |
| 771 | DWORD processId = 0; |
| 772 | LPVOID pAddress = NULL; |
| 773 | SIZE_T nSize = 0; |
| 774 | parse_pid_key_value(g.zPidKey, &processId, &pAddress, &nSize); |
| 775 | db_read_saved_encryption_key_from_process(processId, pAddress, nSize); |
| 776 | }else{ |
| 777 | const char *zSeeDbConfig = find_option("seedbcfg",0,1); |
| 778 | if( !zSeeDbConfig ){ |
| 779 | zSeeDbConfig = fossil_getenv("FOSSIL_SEE_DB_CONFIG"); |
| 780 | } |
| 781 | if( zSeeDbConfig ){ |
| 782 | db_read_saved_encryption_key_from_process_via_th1(zSeeDbConfig); |
| 783 | } |
| 784 | } |
| 785 | } |
| 786 | #endif |
| 787 | if( find_option("help",0,0)!=0 ){ |
| 788 | /* If --help is found anywhere on the command line, translate the command |
| 789 | * to "fossil help cmdname" where "cmdname" is the first argument that |
| 790 | * does not begin with a "-" character. If all arguments start with "-", |
| 791 | * translate to "fossil help argv[1] argv[2]...". */ |
| @@ -2345,10 +2369,43 @@ | |
| 2369 | }else{ |
| 2370 | fossil_fatal("failed to parse pid key"); |
| 2371 | } |
| 2372 | } |
| 2373 | #endif |
| 2374 | |
| 2375 | /* |
| 2376 | ** WEBPAGE: test-pid |
| 2377 | ** |
| 2378 | ** Return the process identifier of the running Fossil server instance. |
| 2379 | ** |
| 2380 | ** Query parameters: |
| 2381 | ** |
| 2382 | ** usepidkey When present and available, also return the |
| 2383 | ** address and size, within this server process, |
| 2384 | ** of the saved database encryption key. This |
| 2385 | ** is only supported when using SEE on Windows. |
| 2386 | */ |
| 2387 | void test_pid_page(void){ |
| 2388 | login_check_credentials(); |
| 2389 | if( !g.perm.Setup ){ login_needed(0); return; } |
| 2390 | #if defined(_WIN32) && USE_SEE |
| 2391 | if( P("usepidkey")!=0 ){ |
| 2392 | if( g.zPidKey ){ |
| 2393 | @ %s(g.zPidKey) |
| 2394 | return; |
| 2395 | }else{ |
| 2396 | const char *zSavedKey = db_get_saved_encryption_key(); |
| 2397 | size_t savedKeySize = db_get_saved_encryption_key_size(); |
| 2398 | if( zSavedKey!=0 && savedKeySize>0 ){ |
| 2399 | @ %lu(GetCurrentProcessId()):%p(zSavedKey):%u(savedKeySize) |
| 2400 | return; |
| 2401 | } |
| 2402 | } |
| 2403 | } |
| 2404 | #endif |
| 2405 | @ %d(GETPID()) |
| 2406 | } |
| 2407 | |
| 2408 | /* |
| 2409 | ** COMMAND: http* |
| 2410 | ** |
| 2411 | ** Usage: %fossil http ?REPOSITORY? ?OPTIONS? |
| @@ -2413,13 +2470,10 @@ | |
| 2470 | const char *zInFile; |
| 2471 | const char *zOutFile; |
| 2472 | int useSCGI; |
| 2473 | int noJail; |
| 2474 | int allowRepoList; |
| 2475 | |
| 2476 | Th_InitTraceLog(); |
| 2477 | |
| 2478 | /* The winhttp module passes the --files option as --files-urlenc with |
| 2479 | ** the argument being URL encoded, to avoid wildcard expansion in the |
| @@ -2466,21 +2520,10 @@ | |
| 2520 | cgi_replace_parameter("HTTPS","on"); |
| 2521 | } |
| 2522 | zHost = find_option("host", 0, 1); |
| 2523 | if( zHost ) cgi_replace_parameter("HTTP_HOST",zHost); |
| 2524 | |
| 2525 | /* We should be done with options.. */ |
| 2526 | verify_all_options(); |
| 2527 | |
| 2528 | if( g.argc!=2 && g.argc!=3 ) usage("?REPOSITORY?"); |
| 2529 | g.cgiOutput = 1; |
| @@ -2695,13 +2738,10 @@ | |
| 2738 | const char *zAltBase; /* Argument to the --baseurl option */ |
| 2739 | const char *zFileGlob; /* Static content must match this */ |
| 2740 | char *zIpAddr = 0; /* Bind to this IP address */ |
| 2741 | int fCreate = 0; /* The --create flag */ |
| 2742 | const char *zInitPage = 0; /* Start on this page. --page option */ |
| 2743 | |
| 2744 | #if defined(_WIN32) |
| 2745 | const char *zStopperFile; /* Name of file used to terminate server */ |
| 2746 | zStopperFile = find_option("stopper", 0, 1); |
| 2747 | #endif |
| @@ -2745,21 +2785,10 @@ | |
| 2785 | } |
| 2786 | if( find_option("localhost", 0, 0)!=0 ){ |
| 2787 | flags |= HTTP_SERVER_LOCALHOST; |
| 2788 | } |
| 2789 | |
| 2790 | /* We should be done with options.. */ |
| 2791 | verify_all_options(); |
| 2792 | |
| 2793 | if( g.argc!=2 && g.argc!=3 ) usage("?REPOSITORY?"); |
| 2794 | if( isUiCmd ){ |
| 2795 |
+2
| --- src/repolist.c | ||
| +++ src/repolist.c | ||
| @@ -141,10 +141,12 @@ | ||
| 141 | 141 | } |
| 142 | 142 | n = db_int(0, "SELECT count(*) FROM sfile"); |
| 143 | 143 | if( n==0 ){ |
| 144 | 144 | sqlite3_close(g.db); |
| 145 | 145 | g.db = 0; |
| 146 | + g.repositoryOpen = 0; | |
| 147 | + g.localOpen = 0; | |
| 146 | 148 | return 0; |
| 147 | 149 | }else{ |
| 148 | 150 | Stmt q; |
| 149 | 151 | double rNow; |
| 150 | 152 | blob_append_sql(&html, |
| 151 | 153 |
| --- src/repolist.c | |
| +++ src/repolist.c | |
| @@ -141,10 +141,12 @@ | |
| 141 | } |
| 142 | n = db_int(0, "SELECT count(*) FROM sfile"); |
| 143 | if( n==0 ){ |
| 144 | sqlite3_close(g.db); |
| 145 | g.db = 0; |
| 146 | return 0; |
| 147 | }else{ |
| 148 | Stmt q; |
| 149 | double rNow; |
| 150 | blob_append_sql(&html, |
| 151 |
| --- src/repolist.c | |
| +++ src/repolist.c | |
| @@ -141,10 +141,12 @@ | |
| 141 | } |
| 142 | n = db_int(0, "SELECT count(*) FROM sfile"); |
| 143 | if( n==0 ){ |
| 144 | sqlite3_close(g.db); |
| 145 | g.db = 0; |
| 146 | g.repositoryOpen = 0; |
| 147 | g.localOpen = 0; |
| 148 | return 0; |
| 149 | }else{ |
| 150 | Stmt q; |
| 151 | double rNow; |
| 152 | blob_append_sql(&html, |
| 153 |
+7
-5
| --- src/th_main.c | ||
| +++ src/th_main.c | ||
| @@ -30,11 +30,12 @@ | ||
| 30 | 30 | #define TH_INIT_NONE ((u32)0x00000000) /* No flags. */ |
| 31 | 31 | #define TH_INIT_NEED_CONFIG ((u32)0x00000001) /* Open configuration first? */ |
| 32 | 32 | #define TH_INIT_FORCE_TCL ((u32)0x00000002) /* Force Tcl to be enabled? */ |
| 33 | 33 | #define TH_INIT_FORCE_RESET ((u32)0x00000004) /* Force TH1 commands re-added? */ |
| 34 | 34 | #define TH_INIT_FORCE_SETUP ((u32)0x00000008) /* Force eval of setup script? */ |
| 35 | -#define TH_INIT_MASK ((u32)0x0000000F) /* All possible init flags. */ | |
| 35 | +#define TH_INIT_NO_REPO ((u32)0x00000010) /* Skip opening repository. */ | |
| 36 | +#define TH_INIT_MASK ((u32)0x0000001F) /* All possible init flags. */ | |
| 36 | 37 | |
| 37 | 38 | /* |
| 38 | 39 | ** Useful and/or "well-known" combinations of flag values. |
| 39 | 40 | */ |
| 40 | 41 | #define TH_INIT_DEFAULT (TH_INIT_NONE) /* Default flags. */ |
| @@ -44,13 +45,13 @@ | ||
| 44 | 45 | |
| 45 | 46 | /* |
| 46 | 47 | ** Flags set by functions in this file to keep track of integration state |
| 47 | 48 | ** information. These flags should not be used outside of this file. |
| 48 | 49 | */ |
| 49 | -#define TH_STATE_CONFIG ((u32)0x00000010) /* We opened the config. */ | |
| 50 | -#define TH_STATE_REPOSITORY ((u32)0x00000020) /* We opened the repository. */ | |
| 51 | -#define TH_STATE_MASK ((u32)0x00000030) /* All possible state flags. */ | |
| 50 | +#define TH_STATE_CONFIG ((u32)0x00000020) /* We opened the config. */ | |
| 51 | +#define TH_STATE_REPOSITORY ((u32)0x00000040) /* We opened the repository. */ | |
| 52 | +#define TH_STATE_MASK ((u32)0x00000060) /* All possible state flags. */ | |
| 52 | 53 | |
| 53 | 54 | #ifdef FOSSIL_ENABLE_TH1_HOOKS |
| 54 | 55 | /* |
| 55 | 56 | ** These are the "well-known" TH1 error messages that occur when no hook is |
| 56 | 57 | ** registered to be called prior to executing a command or processing a web |
| @@ -2085,10 +2086,11 @@ | ||
| 2085 | 2086 | int wasInit = 0; |
| 2086 | 2087 | int needConfig = flags & TH_INIT_NEED_CONFIG; |
| 2087 | 2088 | int forceReset = flags & TH_INIT_FORCE_RESET; |
| 2088 | 2089 | int forceTcl = flags & TH_INIT_FORCE_TCL; |
| 2089 | 2090 | int forceSetup = flags & TH_INIT_FORCE_SETUP; |
| 2091 | + int noRepo = flags & TH_INIT_NO_REPO; | |
| 2090 | 2092 | static unsigned int aFlags[] = { 0, 1, WIKI_LINKSONLY }; |
| 2091 | 2093 | static int anonFlag = LOGIN_ANON; |
| 2092 | 2094 | static int zeroInt = 0; |
| 2093 | 2095 | static struct _Command { |
| 2094 | 2096 | const char *zName; |
| @@ -2152,11 +2154,11 @@ | ||
| 2152 | 2154 | ** This function uses several settings which may be defined in the |
| 2153 | 2155 | ** repository and/or the global configuration. Since the caller |
| 2154 | 2156 | ** passed a non-zero value for the needConfig parameter, make sure |
| 2155 | 2157 | ** the necessary database connections are open prior to continuing. |
| 2156 | 2158 | */ |
| 2157 | - Th_OpenConfig(1); | |
| 2159 | + Th_OpenConfig(!noRepo); | |
| 2158 | 2160 | } |
| 2159 | 2161 | if( forceReset || forceTcl || g.interp==0 ){ |
| 2160 | 2162 | int created = 0; |
| 2161 | 2163 | int i; |
| 2162 | 2164 | if( g.interp==0 ){ |
| 2163 | 2165 |
| --- src/th_main.c | |
| +++ src/th_main.c | |
| @@ -30,11 +30,12 @@ | |
| 30 | #define TH_INIT_NONE ((u32)0x00000000) /* No flags. */ |
| 31 | #define TH_INIT_NEED_CONFIG ((u32)0x00000001) /* Open configuration first? */ |
| 32 | #define TH_INIT_FORCE_TCL ((u32)0x00000002) /* Force Tcl to be enabled? */ |
| 33 | #define TH_INIT_FORCE_RESET ((u32)0x00000004) /* Force TH1 commands re-added? */ |
| 34 | #define TH_INIT_FORCE_SETUP ((u32)0x00000008) /* Force eval of setup script? */ |
| 35 | #define TH_INIT_MASK ((u32)0x0000000F) /* All possible init flags. */ |
| 36 | |
| 37 | /* |
| 38 | ** Useful and/or "well-known" combinations of flag values. |
| 39 | */ |
| 40 | #define TH_INIT_DEFAULT (TH_INIT_NONE) /* Default flags. */ |
| @@ -44,13 +45,13 @@ | |
| 44 | |
| 45 | /* |
| 46 | ** Flags set by functions in this file to keep track of integration state |
| 47 | ** information. These flags should not be used outside of this file. |
| 48 | */ |
| 49 | #define TH_STATE_CONFIG ((u32)0x00000010) /* We opened the config. */ |
| 50 | #define TH_STATE_REPOSITORY ((u32)0x00000020) /* We opened the repository. */ |
| 51 | #define TH_STATE_MASK ((u32)0x00000030) /* All possible state flags. */ |
| 52 | |
| 53 | #ifdef FOSSIL_ENABLE_TH1_HOOKS |
| 54 | /* |
| 55 | ** These are the "well-known" TH1 error messages that occur when no hook is |
| 56 | ** registered to be called prior to executing a command or processing a web |
| @@ -2085,10 +2086,11 @@ | |
| 2085 | int wasInit = 0; |
| 2086 | int needConfig = flags & TH_INIT_NEED_CONFIG; |
| 2087 | int forceReset = flags & TH_INIT_FORCE_RESET; |
| 2088 | int forceTcl = flags & TH_INIT_FORCE_TCL; |
| 2089 | int forceSetup = flags & TH_INIT_FORCE_SETUP; |
| 2090 | static unsigned int aFlags[] = { 0, 1, WIKI_LINKSONLY }; |
| 2091 | static int anonFlag = LOGIN_ANON; |
| 2092 | static int zeroInt = 0; |
| 2093 | static struct _Command { |
| 2094 | const char *zName; |
| @@ -2152,11 +2154,11 @@ | |
| 2152 | ** This function uses several settings which may be defined in the |
| 2153 | ** repository and/or the global configuration. Since the caller |
| 2154 | ** passed a non-zero value for the needConfig parameter, make sure |
| 2155 | ** the necessary database connections are open prior to continuing. |
| 2156 | */ |
| 2157 | Th_OpenConfig(1); |
| 2158 | } |
| 2159 | if( forceReset || forceTcl || g.interp==0 ){ |
| 2160 | int created = 0; |
| 2161 | int i; |
| 2162 | if( g.interp==0 ){ |
| 2163 |
| --- src/th_main.c | |
| +++ src/th_main.c | |
| @@ -30,11 +30,12 @@ | |
| 30 | #define TH_INIT_NONE ((u32)0x00000000) /* No flags. */ |
| 31 | #define TH_INIT_NEED_CONFIG ((u32)0x00000001) /* Open configuration first? */ |
| 32 | #define TH_INIT_FORCE_TCL ((u32)0x00000002) /* Force Tcl to be enabled? */ |
| 33 | #define TH_INIT_FORCE_RESET ((u32)0x00000004) /* Force TH1 commands re-added? */ |
| 34 | #define TH_INIT_FORCE_SETUP ((u32)0x00000008) /* Force eval of setup script? */ |
| 35 | #define TH_INIT_NO_REPO ((u32)0x00000010) /* Skip opening repository. */ |
| 36 | #define TH_INIT_MASK ((u32)0x0000001F) /* All possible init flags. */ |
| 37 | |
| 38 | /* |
| 39 | ** Useful and/or "well-known" combinations of flag values. |
| 40 | */ |
| 41 | #define TH_INIT_DEFAULT (TH_INIT_NONE) /* Default flags. */ |
| @@ -44,13 +45,13 @@ | |
| 45 | |
| 46 | /* |
| 47 | ** Flags set by functions in this file to keep track of integration state |
| 48 | ** information. These flags should not be used outside of this file. |
| 49 | */ |
| 50 | #define TH_STATE_CONFIG ((u32)0x00000020) /* We opened the config. */ |
| 51 | #define TH_STATE_REPOSITORY ((u32)0x00000040) /* We opened the repository. */ |
| 52 | #define TH_STATE_MASK ((u32)0x00000060) /* All possible state flags. */ |
| 53 | |
| 54 | #ifdef FOSSIL_ENABLE_TH1_HOOKS |
| 55 | /* |
| 56 | ** These are the "well-known" TH1 error messages that occur when no hook is |
| 57 | ** registered to be called prior to executing a command or processing a web |
| @@ -2085,10 +2086,11 @@ | |
| 2086 | int wasInit = 0; |
| 2087 | int needConfig = flags & TH_INIT_NEED_CONFIG; |
| 2088 | int forceReset = flags & TH_INIT_FORCE_RESET; |
| 2089 | int forceTcl = flags & TH_INIT_FORCE_TCL; |
| 2090 | int forceSetup = flags & TH_INIT_FORCE_SETUP; |
| 2091 | int noRepo = flags & TH_INIT_NO_REPO; |
| 2092 | static unsigned int aFlags[] = { 0, 1, WIKI_LINKSONLY }; |
| 2093 | static int anonFlag = LOGIN_ANON; |
| 2094 | static int zeroInt = 0; |
| 2095 | static struct _Command { |
| 2096 | const char *zName; |
| @@ -2152,11 +2154,11 @@ | |
| 2154 | ** This function uses several settings which may be defined in the |
| 2155 | ** repository and/or the global configuration. Since the caller |
| 2156 | ** passed a non-zero value for the needConfig parameter, make sure |
| 2157 | ** the necessary database connections are open prior to continuing. |
| 2158 | */ |
| 2159 | Th_OpenConfig(!noRepo); |
| 2160 | } |
| 2161 | if( forceReset || forceTcl || g.interp==0 ){ |
| 2162 | int created = 0; |
| 2163 | int i; |
| 2164 | if( g.interp==0 ){ |
| 2165 |