30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# include <zlib.h>
#endif
#ifndef _WIN32
# include "linenoise.h"
#endif
/*
** Implementation of the "content(X)" SQL function. Return the complete
** content of artifact identified by X as a blob.
*/
static void sqlcmd_content(
sqlite3_context *context,
int argc,
|
>
>
>
>
>
|
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# include <zlib.h>
#endif
#ifndef _WIN32
# include "linenoise.h"
#endif
/*
** True if the "fossil sql" command has the --test flag. False otherwise.
*/
static int local_bSqlCmdTest = 0;
/*
** Implementation of the "content(X)" SQL function. Return the complete
** content of artifact identified by X as a blob.
*/
static void sqlcmd_content(
sqlite3_context *context,
int argc,
|
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
|
/*
** Undocumented test SQL functions:
**
** db_protect(X)
** db_protect_pop(X)
**
** These invoke the corresponding C routines. Misuse may result in
** an assertion fault.
*/
static void sqlcmd_db_protect(
sqlite3_context *context,
int argc,
sqlite3_value **argv
){
unsigned mask = 0;
const char *z = (const char*)sqlite3_value_text(argv[0]);
if( sqlite3_stricmp(z,"user")==0 ) mask |= PROTECT_USER;
if( sqlite3_stricmp(z,"config")==0 ) mask |= PROTECT_CONFIG;
if( sqlite3_stricmp(z,"sensitive")==0 ) mask |= PROTECT_SENSITIVE;
if( sqlite3_stricmp(z,"readonly")==0 ) mask |= PROTECT_READONLY;
if( sqlite3_stricmp(z,"all")==0 ) mask |= PROTECT_ALL;
db_protect(mask);
}
static void sqlcmd_db_protect_pop(
sqlite3_context *context,
int argc,
sqlite3_value **argv
){
db_protect_pop();
}
/*
** This is the "automatic extension" initializer that runs right after
|
|
>
|
>
>
>
>
>
>
>
>
>
>
>
|
|
|
|
|
|
>
|
|
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
|
/*
** Undocumented test SQL functions:
**
** db_protect(X)
** db_protect_pop(X)
**
** These invoke the corresponding C routines.
**
** WARNING:
** Do not instantiate these functions for any Fossil webpage or command
** method of than the "fossil sql" command. If an attacker gains access
** to these functions, he will be able to disable other defense mechanisms.
**
** This routines are for interactiving testing only. They are experimental
** and undocumented (apart from this comments) and might go away or change
** in future releases.
**
** 2020-11-29: This functions are now only available if the "fossil sql"
** command is started with the --test option.
*/
static void sqlcmd_db_protect(
sqlite3_context *context,
int argc,
sqlite3_value **argv
){
unsigned mask = 0;
const char *z = (const char*)sqlite3_value_text(argv[0]);
if( z!=0 && local_bSqlCmdTest ){
if( sqlite3_stricmp(z,"user")==0 ) mask |= PROTECT_USER;
if( sqlite3_stricmp(z,"config")==0 ) mask |= PROTECT_CONFIG;
if( sqlite3_stricmp(z,"sensitive")==0 ) mask |= PROTECT_SENSITIVE;
if( sqlite3_stricmp(z,"readonly")==0 ) mask |= PROTECT_READONLY;
if( sqlite3_stricmp(z,"all")==0 ) mask |= PROTECT_ALL;
db_protect(mask);
}
}
static void sqlcmd_db_protect_pop(
sqlite3_context *context,
int argc,
sqlite3_value **argv
){
if( !local_bSqlCmdTest ) db_protect_pop();
}
/*
** This is the "automatic extension" initializer that runs right after
|
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
|
}
/* Arrange to trace close operations so that static prepared statements
** will get cleaned up when the shell closes the database connection */
if( g.fSqlTrace ) mTrace |= SQLITE_TRACE_PROFILE;
sqlite3_trace_v2(db, mTrace, db_sql_trace, 0);
db_protect_only(PROTECT_NONE);
sqlite3_set_authorizer(db, db_top_authorizer, db);
sqlite3_create_function(db, "db_protect", 1, SQLITE_UTF8, 0,
sqlcmd_db_protect, 0, 0);
sqlite3_create_function(db, "db_protect_pop", 0, SQLITE_UTF8, 0,
sqlcmd_db_protect_pop, 0, 0);
return SQLITE_OK;
}
/*
** atexit() handler that cleans up global state modified by this module.
*/
static void sqlcmd_atexit(void) {
|
>
|
|
|
|
>
|
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
|
}
/* Arrange to trace close operations so that static prepared statements
** will get cleaned up when the shell closes the database connection */
if( g.fSqlTrace ) mTrace |= SQLITE_TRACE_PROFILE;
sqlite3_trace_v2(db, mTrace, db_sql_trace, 0);
db_protect_only(PROTECT_NONE);
sqlite3_set_authorizer(db, db_top_authorizer, db);
if( local_bSqlCmdTest ){
sqlite3_create_function(db, "db_protect", 1, SQLITE_UTF8, 0,
sqlcmd_db_protect, 0, 0);
sqlite3_create_function(db, "db_protect_pop", 0, SQLITE_UTF8, 0,
sqlcmd_db_protect_pop, 0, 0);
}
return SQLITE_OK;
}
/*
** atexit() handler that cleans up global state modified by this module.
*/
static void sqlcmd_atexit(void) {
|
327
328
329
330
331
332
333
334
335
336
337
338
339
340
|
** --no-repository Skip opening the repository database.
**
** --readonly Open the repository read-only. No changes
** are allowed. This is a recommended safety
** precaution to prevent repository damage.
**
** -R REPOSITORY Use REPOSITORY as the repository database
**
** All of the standard sqlite3 command-line shell options should also
** work.
**
** The following SQL extensions are provided with this Fossil-enhanced
** version of the sqlite3 command-line shell:
**
|
>
>
>
|
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
|
** --no-repository Skip opening the repository database.
**
** --readonly Open the repository read-only. No changes
** are allowed. This is a recommended safety
** precaution to prevent repository damage.
**
** -R REPOSITORY Use REPOSITORY as the repository database
**
** --test Enable some testing and analysis features
** that are normally disabled.
**
** All of the standard sqlite3 command-line shell options should also
** work.
**
** The following SQL extensions are provided with this Fossil-enhanced
** version of the sqlite3 command-line shell:
**
|
395
396
397
398
399
400
401
402
403
404
405
406
407
408
|
int noRepository;
char *zConfigDb;
extern int sqlite3_shell(int, char**);
#ifdef FOSSIL_ENABLE_TH1_HOOKS
g.fNoThHook = 1;
#endif
noRepository = find_option("no-repository", 0, 0)!=0;
if( !noRepository ){
db_find_and_open_repository(OPEN_ANY_SCHEMA, 0);
}
db_open_config(1,0);
zConfigDb = fossil_strdup(g.zConfigDbName);
fossil_close(1, noRepository);
sqlite3_shutdown();
|
>
|
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
|
int noRepository;
char *zConfigDb;
extern int sqlite3_shell(int, char**);
#ifdef FOSSIL_ENABLE_TH1_HOOKS
g.fNoThHook = 1;
#endif
noRepository = find_option("no-repository", 0, 0)!=0;
local_bSqlCmdTest = find_option("test",0,0)!=0;
if( !noRepository ){
db_find_and_open_repository(OPEN_ANY_SCHEMA, 0);
}
db_open_config(1,0);
zConfigDb = fossil_strdup(g.zConfigDbName);
fossil_close(1, noRepository);
sqlite3_shutdown();
|