@@ -136,7 +136,7 @@ typedef struct st_status
136
136
ulong query_start_line;
137
137
char *file_name;
138
138
LINE_BUFFER *line_buff;
139
- bool batch,add_to_history;
139
+ bool batch, add_to_history, sandbox ;
140
140
} STATUS;
141
141
142
142
@@ -154,7 +154,7 @@ static my_bool ignore_errors=0,wait_flag=0,quick=0,
154
154
vertical=0 , line_numbers=1 , column_names=1 ,opt_html=0 ,
155
155
opt_xml=0 ,opt_nopager=1 , opt_outfile=0 , named_cmds= 0 ,
156
156
tty_password= 0 , opt_nobeep=0 , opt_reconnect=1 ,
157
- opt_secure_auth= 0 ,
157
+ opt_secure_auth= 0 ,
158
158
default_pager_set= 0 , opt_sigint_ignore= 0 ,
159
159
auto_vertical_output= 0 ,
160
160
show_warnings= 0 , executing_query= 0 ,
@@ -235,7 +235,8 @@ static int com_quit(String *str,char*),
235
235
com_rehash(String *str, char *), com_tee(String *str, char *),
236
236
com_notee(String *str, char *), com_charset(String *str,char *),
237
237
com_prompt(String *str, char *), com_delimiter(String *str, char *),
238
- com_warnings(String *str, char *), com_nowarnings(String *str, char *);
238
+ com_warnings(String *str, char *), com_nowarnings(String *str, char *),
239
+ com_sandbox(String *str, char *);
239
240
240
241
#ifdef USE_POPEN
241
242
static int com_nopager (String *str, char *), com_pager(String *str, char *),
@@ -311,6 +312,8 @@ static COMMANDS commands[] = {
311
312
{ " prompt" , ' R' , com_prompt, 1 , " Change your mysql prompt." },
312
313
{ " quit" , ' q' , com_quit, 0 , " Quit mysql." },
313
314
{ " rehash" , ' #' , com_rehash, 0 , " Rebuild completion hash." },
315
+ { " sandbox" , ' -' , com_sandbox, 0 ,
316
+ " Disallow commands that access the file system (except \\ P without an argument and \\ e)." },
314
317
{ " source" , ' .' , com_source, 1 ,
315
318
" Execute an SQL script file. Takes a file name as an argument." },
316
319
{ " status" , ' s' , com_status, 0 , " Get status information from the server." },
@@ -1675,6 +1678,8 @@ static struct my_option my_long_options[] =
1675
1678
&safe_updates, &safe_updates, 0 , GET_BOOL, NO_ARG, 0 , 0 , 0 , 0 , 0 , 0 },
1676
1679
{" i-am-a-dummy" , ' U' , " Synonym for option --safe-updates, -U." ,
1677
1680
&safe_updates, &safe_updates, 0 , GET_BOOL, NO_ARG, 0 , 0 , 0 , 0 , 0 , 0 },
1681
+ {" sandbox" , 0 , " Disallow commands that access the file system (except \\ P without an argument and \\ e)." ,
1682
+ &status.sandbox , &status.sandbox , 0 , GET_BOOL, NO_ARG, 0 , 0 , 0 , 0 , 0 , 0 },
1678
1683
{" secure-auth" , 0 , " Refuse client connecting to server if it"
1679
1684
" uses old (pre-4.1.1) protocol." , &opt_secure_auth,
1680
1685
&opt_secure_auth, 0 , GET_BOOL, NO_ARG, 0 , 0 , 0 , 0 , 0 , 0 },
@@ -4146,6 +4151,8 @@ static int com_tee(String *, char *line)
4146
4151
{
4147
4152
char file_name[FN_REFLEN], *end, *param;
4148
4153
4154
+ if (status.sandbox )
4155
+ return put_info (" Not allowed in the sandbox mode" , INFO_ERROR, 0 );
4149
4156
if (status.batch )
4150
4157
return 0 ;
4151
4158
while (my_isspace (charset_info, *line))
@@ -4226,6 +4233,8 @@ static int com_pager(String *, char *line)
4226
4233
}
4227
4234
else
4228
4235
{
4236
+ if (status.sandbox )
4237
+ return put_info (" Not allowed in the sandbox mode" , INFO_ERROR, 0 );
4229
4238
end= strmake_buf (pager_name, param);
4230
4239
while (end > pager_name && (my_isspace (charset_info,end[-1 ]) ||
4231
4240
my_iscntrl (charset_info,end[-1 ])))
@@ -4321,6 +4330,9 @@ static int com_shell(String *, char *line)
4321
4330
{
4322
4331
char *shell_cmd;
4323
4332
4333
+ if (status.sandbox )
4334
+ return put_info (" Not allowed in the sandbox mode" , INFO_ERROR, 0 );
4335
+
4324
4336
/* Skip space from line begin */
4325
4337
while (my_isspace (charset_info, *line))
4326
4338
line++;
@@ -4416,6 +4428,9 @@ static int com_source(String *, char *line)
4416
4428
FILE *sql_file;
4417
4429
my_bool save_ignore_errors;
4418
4430
4431
+ if (status.sandbox )
4432
+ return put_info (" Not allowed in the sandbox mode" , INFO_ERROR, 0 );
4433
+
4419
4434
/* Skip space from file name */
4420
4435
while (my_isspace (charset_info,*line))
4421
4436
line++;
@@ -4450,6 +4465,7 @@ static int com_source(String *, char *line)
4450
4465
bfill ((char *) &status,sizeof (status),(char ) 0 );
4451
4466
4452
4467
status.batch =old_status.batch ; // Run in batch mode
4468
+ status.sandbox =old_status.sandbox ;
4453
4469
status.line_buff =line_buff;
4454
4470
status.file_name =source_name;
4455
4471
glob_buffer.length (0 ); // Empty command buffer
@@ -4571,6 +4587,13 @@ static int com_use(String *, char *line)
4571
4587
return 0 ;
4572
4588
}
4573
4589
4590
+ static int com_sandbox (String *, char *)
4591
+ {
4592
+ status.sandbox = 1 ;
4593
+ put_info (" Sandbox mode." , INFO_INFO);
4594
+ return 0 ;
4595
+ }
4596
+
4574
4597
static int com_warnings (String *, char *)
4575
4598
{
4576
4599
show_warnings = 1 ;
0 commit comments