1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 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 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626
|
/*
Derby - Class org.apache.derbyTesting.functionTests.tests.lang.DBOAccessTest
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to you under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package org.apache.derbyTesting.functionTests.tests.lang;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.SQLException;
import junit.framework.Test;
import org.apache.derbyTesting.junit.BaseTestSuite;
import org.apache.derbyTesting.junit.DatabasePropertyTestSetup;
import org.apache.derbyTesting.junit.SupportFilesSetup;
import org.apache.derbyTesting.junit.TestConfiguration;
import org.apache.derby.catalog.SystemProcedures;
/**
* Tests that certain operations can only be performed by the DBO.
*/
public class DBOAccessTest extends GeneratedColumnsHelper
{
///////////////////////////////////////////////////////////////////////////////////
//
// CONSTANTS
//
///////////////////////////////////////////////////////////////////////////////////
private static final String TEST_DBO = "TEST_DBO";
private static final String JANET = "JANET";
private static final String[] LEGAL_USERS = { TEST_DBO, JANET };
// Name of the log file to use when testing VTIs that expect one.
private static final String TEST_LOG_FILE = "sys_vti_test_derby.tstlog";
private static final String ONLY_DBO = "4251D";
private static final String HIDDEN_COLUMN = "4251E";
private static final String NULL_BACKUP_DIRECTORY = "XSRS6";
private static final String FIRST_CREDENTIALS = "4251K";
private static final String MISSING_OBJECT = "X0X13";
private static final String MISSING_TABLE = "42X05";
private static final String NO_SUCH_TABLE = "XIE0M";
private static final String UNKNOWN_USER = "XK001";
private static final String SQLJ_INVALID_JAR = "46001";
private static final String SYSCS_SET_DATABASE_PROPERTY = "SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY";
private static final String SYSCS_GET_DATABASE_PROPERTY = "SYSCS_UTIL.SYSCS_GET_DATABASE_PROPERTY";
private static final String SYSCS_FREEZE_DATABASE = "SYSCS_UTIL.SYSCS_FREEZE_DATABASE";
private static final String SYSCS_UNFREEZE_DATABASE = "SYSCS_UTIL.SYSCS_UNFREEZE_DATABASE";
private static final String SYSCS_CHECKPOINT_DATABASE = "SYSCS_UTIL.SYSCS_CHECKPOINT_DATABASE";
private static final String SYSCS_BACKUP_DATABASE = "SYSCS_UTIL.SYSCS_BACKUP_DATABASE";
private static final String SYSCS_BACKUP_DATABASE_NOWAIT = "SYSCS_UTIL.SYSCS_BACKUP_DATABASE_NOWAIT";
private static final String SYSCS_BACKUP_DATABASE_AND_ENABLE_LOG_ARCHIVE_MODE = "SYSCS_UTIL.SYSCS_BACKUP_DATABASE_AND_ENABLE_LOG_ARCHIVE_MODE";
private static final String SYSCS_BACKUP_DATABASE_AND_ENABLE_LOG_ARCHIVE_MODE_NOWAIT = "SYSCS_UTIL.SYSCS_BACKUP_DATABASE_AND_ENABLE_LOG_ARCHIVE_MODE_NOWAIT";
private static final String SYSCS_DISABLE_LOG_ARCHIVE_MODE = "SYSCS_UTIL.SYSCS_DISABLE_LOG_ARCHIVE_MODE";
private static final String SYSCS_CHECK_TABLE = "SYSCS_UTIL.SYSCS_CHECK_TABLE";
private static final String INSTALL_JAR = "SQLJ.INSTALL_JAR";
private static final String REPLACE_JAR = "SQLJ.REPLACE_JAR";
private static final String REMOVE_JAR = "SQLJ.REMOVE_JAR";
private static final String SYSCS_EXPORT_TABLE = "SYSCS_UTIL.SYSCS_EXPORT_TABLE";
private static final String SYSCS_IMPORT_TABLE = "SYSCS_UTIL.SYSCS_IMPORT_TABLE";
private static final String SYSCS_IMPORT_TABLE_LOBS_FROM_EXTFILE = "SYSCS_UTIL.SYSCS_IMPORT_TABLE_LOBS_FROM_EXTFILE";
private static final String SYSCS_IMPORT_DATA = "SYSCS_UTIL.SYSCS_IMPORT_DATA";
private static final String SYSCS_IMPORT_DATA_LOBS_FROM_EXTFILE = "SYSCS_UTIL.SYSCS_IMPORT_DATA_LOBS_FROM_EXTFILE";
private static final String SYSCS_BULK_INSERT = "SYSCS_UTIL.SYSCS_BULK_INSERT";
private static final String SYSCS_RELOAD_SECURITY_POLICY = "SYSCS_UTIL.SYSCS_RELOAD_SECURITY_POLICY";
private static final String SYSCS_SET_USER_ACCESS = "SYSCS_UTIL.SYSCS_SET_USER_ACCESS";
private static final String SYSCS_GET_USER_ACCESS = "SYSCS_UTIL.SYSCS_GET_USER_ACCESS";
private static final String SYSCS_INVALIDATE_STORED_STATEMENTS = "SYSCS_UTIL.SYSCS_INVALIDATE_STORED_STATEMENTS";
private static final String SYSCS_EMPTY_STATEMENT_CACHE = "SYSCS_UTIL.SYSCS_EMPTY_STATEMENT_CACHE";
private static final String SYSCS_SET_XPLAIN_MODE = "SYSCS_UTIL.SYSCS_SET_XPLAIN_MODE";
private static final String SYSCS_GET_XPLAIN_MODE = "SYSCS_UTIL.SYSCS_GET_XPLAIN_MODE";
private static final String SYSCS_SET_XPLAIN_SCHEMA = "SYSCS_UTIL.SYSCS_SET_XPLAIN_SCHEMA";
private static final String SYSCS_GET_XPLAIN_SCHEMA = "SYSCS_UTIL.SYSCS_GET_XPLAIN_SCHEMA";
private static final String SYSCS_CREATE_USER = "SYSCS_UTIL.SYSCS_CREATE_USER";
private static final String SYSCS_RESET_PASSWORD = "SYSCS_UTIL.SYSCS_RESET_PASSWORD";
private static final String SYSCS_DROP_USER = "SYSCS_UTIL.SYSCS_DROP_USER";
///////////////////////////////////////////////////////////////////////////////////
//
// STATE
//
///////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////
//
// CONSTRUCTOR
//
///////////////////////////////////////////////////////////////////////////////////
/**
* Create a new instance.
*/
public DBOAccessTest( String name )
{
super( name );
}
///////////////////////////////////////////////////////////////////////////////////
//
// OVERRIDABLE BEHAVIOR
//
///////////////////////////////////////////////////////////////////////////////////
public boolean authorizationIsOn() { return true; }
///////////////////////////////////////////////////////////////////////////////////
//
// NESTED CLASSES
//
///////////////////////////////////////////////////////////////////////////////////
public static final class NoAuthorization extends DBOAccessTest
{
public NoAuthorization( String name )
{
super( name );
}
public boolean authorizationIsOn() { return false; }
}
///////////////////////////////////////////////////////////////////////////////////
//
// JUnit BEHAVIOR
//
///////////////////////////////////////////////////////////////////////////////////
/**
* Construct top level suite in this JUnit test
*/
public static Test suite()
{
String[] testFiles = new String[] { "functionTests/tests/lang/" + TEST_LOG_FILE };
Test authorizedRun = TestConfiguration.embeddedSuite( DBOAccessTest.class );
authorizedRun = DatabasePropertyTestSetup.builtinAuthentication
( authorizedRun, LEGAL_USERS, "authorizationOnDBOAccessTest" );
authorizedRun = new SupportFilesSetup( authorizedRun, testFiles );
authorizedRun = TestConfiguration.sqlAuthorizationDecorator( authorizedRun );
Test unauthorizedRun = TestConfiguration.embeddedSuite( NoAuthorization.class );
unauthorizedRun = new SupportFilesSetup( unauthorizedRun, testFiles );
BaseTestSuite suite = new BaseTestSuite();
suite.addTest( authorizedRun );
suite.addTest( unauthorizedRun );
return suite;
}
///////////////////////////////////////////////////////////////////////////////////
//
// TESTS
//
///////////////////////////////////////////////////////////////////////////////////
/**
* <p>
* Tests that only the DBO can run diagnostic VTIs which return sensitive information.
* See DERBY-5395.
* </p>
*/
public void test_5395() throws Exception
{
println( "authorizationIsOn() = " + authorizationIsOn() );
Connection dboConnection = openUserConnection( TEST_DBO );
Connection janetConnection = openUserConnection( JANET );
minion_5395( dboConnection, true );
minion_5395( janetConnection, !authorizationIsOn() );
}
private void minion_5395( Connection conn, boolean shouldSucceed ) throws Exception
{
vet_5395( conn, shouldSucceed, "select * from syscs_diag.statement_cache" );
vet_5395( conn, shouldSucceed, "select * from syscs_diag.transaction_table" );
vet_5395( conn, shouldSucceed, "select * from table( syscs_diag.error_log_reader( ) ) s" );
vet_5395( conn, shouldSucceed, "select * from table( syscs_diag.statement_duration() ) s" );
java.net.URL logURL = SupportFilesSetup.getReadOnlyURL( TEST_LOG_FILE );
String vtiArg = "'" + logURL.getFile() + "'";
vet_5395( conn, shouldSucceed, "select * from table( syscs_diag.error_log_reader( " + vtiArg + " ) ) s" );
vet_5395( conn, shouldSucceed, "select * from table( syscs_diag.statement_duration( " + vtiArg + " ) ) s" );
}
private void vet_5395( Connection conn, boolean shouldSucceed, String query ) throws Exception
{
if ( shouldSucceed ) { goodStatement( conn, query ); }
else
{
expectCompilationError( conn, ONLY_DBO, query );
}
}
/**
* <p>
* Tests that only the DBO can select from SYSUSERS and no-one can SELECT
* SYSUSERS.PASSWORD.
* </p>
*/
public void testSYSUSERS() throws Exception
{
println( "testSYSUSERS authorizationIsOn() = " + authorizationIsOn() );
Connection dboConnection = openUserConnection( TEST_DBO );
Connection janetConnection = openUserConnection( JANET );
goodStatement( dboConnection, "create view v2 as select username, hashingscheme, lastmodified from sys.sysusers" );
if ( authorizationIsOn() ) { goodStatement( dboConnection, "grant select on v2 to public" ); }
goodStatement( dboConnection, "create view v3 as select username, hashingscheme, lastmodified from sys.sysusers where password is null" );
if ( authorizationIsOn() ) { goodStatement( dboConnection, "grant select on v3 to public" ); }
vetDBO_OKProbes( dboConnection, true );
vetDBO_OKProbes( janetConnection, !authorizationIsOn() );
vetUnauthorizedProbes( dboConnection, !authorizationIsOn(), HIDDEN_COLUMN );
vetUnauthorizedProbes( janetConnection, !authorizationIsOn(), ONLY_DBO );
}
// these statements should always succeed if the dbo is running
// them or if authorization is not enabled
private void vetDBO_OKProbes( Connection conn, boolean shouldSucceed )
throws Exception
{
vetUserProbes( conn, shouldSucceed, "select count(*) from sys.sysusers", ONLY_DBO );
vetUserProbes( conn, shouldSucceed, "select username, hashingscheme, lastmodified from sys.sysusers", ONLY_DBO );
vetUserProbes( conn, shouldSucceed, "select username from sys.sysusers", ONLY_DBO );
vetUserProbes( conn, shouldSucceed, "select username, lastmodified from sys.sysusers", ONLY_DBO );
vetUserProbes( conn, shouldSucceed, "select username, lastmodified from sys.sysusers where username = 'FRED'", ONLY_DBO );
// can't use views to subvert authorization checks
vetUserProbes( conn, shouldSucceed, "select count(*) from test_dbo.v2", ONLY_DBO );
vetUserProbes( conn, shouldSucceed, "select * from test_dbo.v2", ONLY_DBO );
vetUserProbes( conn, shouldSucceed, "select username, hashingscheme, lastmodified from test_dbo.v2", ONLY_DBO );
vetUserProbes( conn, shouldSucceed, "select username from test_dbo.v2", ONLY_DBO );
}
// these statements should always fail if authorization is enabled
private void vetUnauthorizedProbes( Connection conn, boolean shouldSucceed, String expectedSQLState )
throws Exception
{
vetUserProbes( conn, shouldSucceed, "select * from sys.sysusers", expectedSQLState );
vetUserProbes( conn, shouldSucceed, "select * from sys.sysusers where username='foo'", expectedSQLState );
vetUserProbes( conn, shouldSucceed, "select password from sys.sysusers", expectedSQLState );
vetUserProbes( conn, shouldSucceed, "select username, password from sys.sysusers", expectedSQLState );
vetUserProbes( conn, shouldSucceed, "select username from sys.sysusers where password = 'foo'", expectedSQLState );
vetUserProbes( conn, shouldSucceed, "select username, lastmodified from sys.sysusers where password is not null", expectedSQLState );
vetUserProbes( conn, shouldSucceed, "select * from test_dbo.v3", expectedSQLState );
}
private void vetUserProbes
( Connection conn, boolean shouldSucceed, String query, String expectedSQLState )
throws Exception
{
if ( shouldSucceed ) { goodStatement( conn, query ); }
else
{
expectCompilationError( conn, expectedSQLState, query );
}
}
/**
* <p>
* Tests that you can't subvert sql authorization by directly calling
* the entry points in SystemProcedures.
* </p>
*/
public void test_6616() throws Exception
{
Connection dboConnection = openUserConnection( TEST_DBO );
Connection janetConnection = openUserConnection( JANET );
goodStatement
(
dboConnection,
"create procedure runSystemRoutine( routineName varchar( 32672 ) )\n" +
"language java parameter style java modifies sql data\n" +
"external name 'org.apache.derbyTesting.functionTests.tests.lang.DBOAccessTest.runSystemRoutine'\n"
);
if ( authorizationIsOn() )
{
goodStatement
(
dboConnection,
"grant execute on procedure runSystemRoutine to public"
);
}
vet6616( dboConnection, janetConnection, SYSCS_SET_DATABASE_PROPERTY, false );
vet6616( dboConnection, janetConnection, SYSCS_GET_DATABASE_PROPERTY, true );
vet6616( dboConnection, janetConnection, SYSCS_FREEZE_DATABASE, false );
vet6616( dboConnection, janetConnection, SYSCS_UNFREEZE_DATABASE, false );
vet6616( dboConnection, janetConnection, SYSCS_CHECKPOINT_DATABASE, false );
vet6616( dboConnection, janetConnection, SYSCS_BACKUP_DATABASE, false );
vet6616( dboConnection, janetConnection, SYSCS_BACKUP_DATABASE_NOWAIT, false );
vet6616( dboConnection, janetConnection, SYSCS_BACKUP_DATABASE_AND_ENABLE_LOG_ARCHIVE_MODE, false );
vet6616( dboConnection, janetConnection, SYSCS_BACKUP_DATABASE_AND_ENABLE_LOG_ARCHIVE_MODE_NOWAIT, false );
vet6616( dboConnection, janetConnection, SYSCS_DISABLE_LOG_ARCHIVE_MODE, false );
vet6616( dboConnection, janetConnection, SYSCS_CHECK_TABLE, true );
vet6616( dboConnection, janetConnection, INSTALL_JAR, false );
vet6616( dboConnection, janetConnection, REPLACE_JAR, false );
vet6616( dboConnection, janetConnection, REMOVE_JAR, false );
vet6616( dboConnection, janetConnection, SYSCS_EXPORT_TABLE, false );
vet6616( dboConnection, janetConnection, SYSCS_IMPORT_TABLE, false );
vet6616( dboConnection, janetConnection, SYSCS_IMPORT_TABLE_LOBS_FROM_EXTFILE, false );
vet6616( dboConnection, janetConnection, SYSCS_IMPORT_DATA, false );
vet6616( dboConnection, janetConnection, SYSCS_IMPORT_DATA_LOBS_FROM_EXTFILE, false );
vet6616( dboConnection, janetConnection, SYSCS_BULK_INSERT, false );
vet6616( dboConnection, janetConnection, SYSCS_RELOAD_SECURITY_POLICY, false );
vet6616( dboConnection, janetConnection, SYSCS_SET_USER_ACCESS, false );
vet6616( dboConnection, janetConnection, SYSCS_GET_USER_ACCESS, true );
vet6616( dboConnection, janetConnection, SYSCS_INVALIDATE_STORED_STATEMENTS, false );
vet6616( dboConnection, janetConnection, SYSCS_EMPTY_STATEMENT_CACHE, false );
vet6616( dboConnection, janetConnection, SYSCS_SET_XPLAIN_MODE, false );
vet6616( dboConnection, janetConnection, SYSCS_GET_XPLAIN_MODE, true );
vet6616( dboConnection, janetConnection, SYSCS_SET_XPLAIN_SCHEMA, false );
vet6616( dboConnection, janetConnection, SYSCS_GET_XPLAIN_SCHEMA, true );
vet6616( dboConnection, janetConnection, SYSCS_CREATE_USER, false );
vet6616( dboConnection, janetConnection, SYSCS_RESET_PASSWORD, false );
vet6616( dboConnection, janetConnection, SYSCS_DROP_USER, false );
}
private void vet6616
( Connection dboConnection, Connection janetConnection, String routineName, boolean isFunction )
throws Exception
{
vet6616( dboConnection, true, routineName );
vet6616( janetConnection, !authorizationIsOn(), routineName );
if ( authorizationIsOn() )
{
boolean isFreeze = SYSCS_FREEZE_DATABASE.equals( routineName );
String routineType = isFunction ? "function" : "procedure";
goodStatement( dboConnection, "grant execute on " + routineType + " " + routineName + " to public" );
if ( isFreeze )
{
goodStatement( dboConnection, "grant execute on " + routineType + " " + SYSCS_UNFREEZE_DATABASE + " to public" );
}
vet6616( janetConnection, true, routineName );
goodStatement( dboConnection, "revoke execute on " + routineType + " " + routineName + " from public restrict" );
if ( isFreeze )
{
goodStatement
( dboConnection, "revoke execute on " + routineType + " " + SYSCS_UNFREEZE_DATABASE + " from public restrict" );
}
}
}
private void vet6616( Connection conn, boolean shouldSucceed, String routineName )
throws Exception
{
CallableStatement cs = conn.prepareCall( "call test_dbo.runSystemRoutine( ? )" );
cs.setString( 1, routineName );
try {
cs.execute();
if ( !shouldSucceed ) { fail( routineName + " should have failed!" ); }
}
catch (SQLException se)
{
if ( shouldSucceed )
{
fail( routineName + " should have succeeded", se );
}
else
{
assertSQLState( LACK_EXECUTE_PRIV, se );
}
}
}
///////////////////////////////////////////////////////////////////////////////////
//
// SQL ROUTINES
//
///////////////////////////////////////////////////////////////////////////////////
/** Run various system procedures and functions by calling them directly */
public static void runSystemRoutine( String routineName )
throws Exception
{
if ( SYSCS_SET_DATABASE_PROPERTY.equals( routineName ) )
{
SystemProcedures.SYSCS_SET_DATABASE_PROPERTY( "foo.bar.wibble", "wibble.bar.foo" );
}
else if ( SYSCS_GET_DATABASE_PROPERTY.equals( routineName ) )
{
SystemProcedures.SYSCS_GET_DATABASE_PROPERTY( "la.dee.dah" );
}
else if ( SYSCS_FREEZE_DATABASE.equals( routineName ) )
{
SystemProcedures.SYSCS_FREEZE_DATABASE();
// if that succeeded, then unfreeze the database immediately
SystemProcedures.SYSCS_UNFREEZE_DATABASE();
}
else if ( SYSCS_UNFREEZE_DATABASE.equals( routineName ) )
{
SystemProcedures.SYSCS_UNFREEZE_DATABASE();
}
else if ( SYSCS_CHECKPOINT_DATABASE.equals( routineName ) )
{
SystemProcedures.SYSCS_CHECKPOINT_DATABASE();
}
else if ( SYSCS_BACKUP_DATABASE.equals( routineName ) )
{
try {
SystemProcedures.SYSCS_BACKUP_DATABASE( null );
fail();
}
catch (SQLException se) { vetError( NULL_BACKUP_DIRECTORY, se ); }
}
else if ( SYSCS_BACKUP_DATABASE_NOWAIT.equals( routineName ) )
{
try {
SystemProcedures.SYSCS_BACKUP_DATABASE_NOWAIT( null );
fail();
}
catch (SQLException se) { vetError( NULL_BACKUP_DIRECTORY, se ); }
}
else if (SYSCS_BACKUP_DATABASE_AND_ENABLE_LOG_ARCHIVE_MODE.equals( routineName ) )
{
try {
SystemProcedures.SYSCS_BACKUP_DATABASE_AND_ENABLE_LOG_ARCHIVE_MODE( null, (short) 0 );
fail();
}
catch (SQLException se) { vetError( NULL_BACKUP_DIRECTORY, se ); }
}
else if (SYSCS_BACKUP_DATABASE_AND_ENABLE_LOG_ARCHIVE_MODE_NOWAIT.equals( routineName ) )
{
try {
SystemProcedures.SYSCS_BACKUP_DATABASE_AND_ENABLE_LOG_ARCHIVE_MODE_NOWAIT( null, (short) 0 );
fail();
}
catch (SQLException se) { vetError( NULL_BACKUP_DIRECTORY, se ); }
}
else if ( SYSCS_DISABLE_LOG_ARCHIVE_MODE.equals( routineName ) )
{
SystemProcedures.SYSCS_DISABLE_LOG_ARCHIVE_MODE( (short) 0 );
}
else if ( SYSCS_CHECK_TABLE.equals( routineName ) )
{
SystemProcedures.SYSCS_CHECK_TABLE( "SYS", "SYSTABLES" );
}
else if (INSTALL_JAR.equals( routineName ) )
{
try {
SystemProcedures.INSTALL_JAR( SupportFilesSetup.getReadOnlyFileName("foo"), "bar", 1 );
fail();
}
catch (SQLException se) {
vetError(SQLJ_INVALID_JAR, se);
}
}
else if (REPLACE_JAR.equals( routineName ) )
{
try {
SystemProcedures.REPLACE_JAR( SupportFilesSetup.getReadOnlyFileName("foo"), "bar" );
fail();
}
catch (SQLException se) {
vetError(SQLJ_INVALID_JAR, se);
}
}
else if (REMOVE_JAR.equals( routineName ) )
{
try {
SystemProcedures.REMOVE_JAR( "test_dbo.foo", 0 );
fail();
}
catch (SQLException se) { vetError( MISSING_OBJECT, se ); }
}
else if ( SYSCS_EXPORT_TABLE.equals( routineName ) )
{
try {
SystemProcedures.SYSCS_EXPORT_TABLE(
"TEST_DBO", "BAR",
SupportFilesSetup.getReadWriteFileName("WIBBLE"),
null, null, null);
fail();
}
catch (SQLException se) { vetError( MISSING_TABLE, se ); }
}
else if ( SYSCS_IMPORT_TABLE.equals( routineName ) )
{
try {
SystemProcedures.SYSCS_IMPORT_TABLE(
"TEST_DBO", "BAR",
SupportFilesSetup.getReadWriteFileName("WIBBLE"),
null, null, null, (short) 1);
fail();
}
catch (SQLException se) { vetError( NO_SUCH_TABLE, se ); }
}
else if ( SYSCS_IMPORT_TABLE_LOBS_FROM_EXTFILE.equals( routineName ) )
{
try {
SystemProcedures.SYSCS_IMPORT_TABLE_LOBS_FROM_EXTFILE( "TEST_DBO", "BAR", "WIBBLE", null, null, null, (short) 1 );
fail();
}
catch (SQLException se) { vetError( NO_SUCH_TABLE, se ); }
}
else if ( SYSCS_IMPORT_DATA.equals( routineName ) )
{
try {
SystemProcedures.SYSCS_IMPORT_DATA
( "TEST_DBO", "BAR", null, "1,3,4", "WIBBLE", null, null, null, (short) 1 );
fail();
}
catch (SQLException se) { vetError( NO_SUCH_TABLE, se ); }
}
else if ( SYSCS_IMPORT_DATA_LOBS_FROM_EXTFILE.equals( routineName ) )
{
try {
SystemProcedures.SYSCS_IMPORT_DATA_LOBS_FROM_EXTFILE
( "TEST_DBO", "BAR", null, "1,3,4", "WIBBLE", null, null, null, (short) 1 );
fail();
}
catch (SQLException se) { vetError( NO_SUCH_TABLE, se ); }
}
else if ( SYSCS_BULK_INSERT.equals( routineName ) )
{
try {
SystemProcedures.SYSCS_BULK_INSERT
( "TEST_DBO", "BAR", "WIBBLE", "wombat" );
fail();
}
catch (SQLException se) { vetError( SYNTAX_ERROR, se ); }
}
else if ( SYSCS_RELOAD_SECURITY_POLICY.equals( routineName ) )
{
SystemProcedures.SYSCS_RELOAD_SECURITY_POLICY();
}
else if ( SYSCS_SET_USER_ACCESS.equals( routineName ) )
{
SystemProcedures.SYSCS_SET_USER_ACCESS( "FOO", "FULLACCESS" );
}
else if ( SYSCS_GET_USER_ACCESS.equals( routineName ) )
{
SystemProcedures.SYSCS_GET_USER_ACCESS( "FOO" );
}
else if ( SYSCS_INVALIDATE_STORED_STATEMENTS.equals( routineName ) )
{
SystemProcedures.SYSCS_INVALIDATE_STORED_STATEMENTS();
}
else if ( SYSCS_EMPTY_STATEMENT_CACHE.equals( routineName ) )
{
SystemProcedures.SYSCS_EMPTY_STATEMENT_CACHE();
}
else if ( SYSCS_SET_XPLAIN_MODE.equals( routineName ) )
{
SystemProcedures.SYSCS_SET_XPLAIN_MODE( 0 );
}
else if ( SYSCS_GET_XPLAIN_MODE.equals( routineName ) )
{
SystemProcedures.SYSCS_GET_XPLAIN_MODE();
}
else if ( SYSCS_SET_XPLAIN_SCHEMA.equals( routineName ) )
{
SystemProcedures.SYSCS_SET_XPLAIN_SCHEMA( "" );
}
else if ( SYSCS_GET_XPLAIN_SCHEMA.equals( routineName ) )
{
SystemProcedures.SYSCS_GET_XPLAIN_SCHEMA();
}
else if (SYSCS_CREATE_USER.equals( routineName ) )
{
try {
SystemProcedures.SYSCS_CREATE_USER( "foo", "bar" );
fail();
}
catch (SQLException se) { vetError( FIRST_CREDENTIALS, se ); }
}
else if (SYSCS_RESET_PASSWORD.equals( routineName ) )
{
try {
SystemProcedures.SYSCS_RESET_PASSWORD( "foo", "bar" );
fail();
}
catch (SQLException se) { vetError( UNKNOWN_USER, se ); }
}
else if (SYSCS_DROP_USER.equals( routineName ) )
{
try {
SystemProcedures.SYSCS_DROP_USER( "foo" );
fail();
}
catch (SQLException se) { vetError( UNKNOWN_USER, se ); }
}
else
{
throw new Exception( "Unknown routine name: " + routineName );
}
}
private static void vetError( String sqlState, SQLException se )
throws SQLException
{
if ( sqlState.equals( se.getSQLState() ) )
{
println( "Caught expected error: " + sqlState );
}
else { throw se; }
}
}
|