Check that we have enough rights to access all resources this request touches including resources it used indirectly via procedures or triggers.
| 474 | // Check that we have enough rights to access all resources this request touches including |
| 475 | // resources it used indirectly via procedures or triggers. |
| 476 | void Statement::verifyAccess(thread_db* tdbb) |
| 477 | { |
| 478 | if (flags & FLAG_INTERNAL) |
| 479 | return; |
| 480 | |
| 481 | SET_TDBB(tdbb); |
| 482 | |
| 483 | ExternalAccessList external; |
| 484 | const MetaName defaultUser; |
| 485 | buildExternalAccess(tdbb, external, defaultUser); |
| 486 | |
| 487 | for (ExternalAccess* item = external.begin(); item != external.end(); ++item) |
| 488 | { |
| 489 | const Routine* routine = NULL; |
| 490 | int aclType; |
| 491 | |
| 492 | if (item->exa_action == ExternalAccess::exa_procedure) |
| 493 | { |
| 494 | routine = MET_lookup_procedure_id(tdbb, item->exa_prc_id, false, false, 0); |
| 495 | if (!routine) |
| 496 | { |
| 497 | string name; |
| 498 | name.printf("id %d", item->exa_prc_id); |
| 499 | ERR_post(Arg::Gds(isc_prcnotdef) << name); |
| 500 | } |
| 501 | aclType = id_procedure; |
| 502 | } |
| 503 | else if (item->exa_action == ExternalAccess::exa_function) |
| 504 | { |
| 505 | routine = Function::lookup(tdbb, item->exa_fun_id, false, false, 0); |
| 506 | |
| 507 | if (!routine) |
| 508 | { |
| 509 | string name; |
| 510 | name.printf("id %d", item->exa_fun_id); |
| 511 | ERR_post(Arg::Gds(isc_funnotdef) << name); |
| 512 | } |
| 513 | |
| 514 | aclType = id_function; |
| 515 | } |
| 516 | else |
| 517 | { |
| 518 | jrd_rel* relation = MET_lookup_relation_id(tdbb, item->exa_rel_id, false); |
| 519 | |
| 520 | if (!relation) |
| 521 | continue; |
| 522 | |
| 523 | MetaName userName = item->user; |
| 524 | if (item->exa_view_id) |
| 525 | { |
| 526 | jrd_rel* view = MET_lookup_relation_id(tdbb, item->exa_view_id, false); |
| 527 | if (view && (view->rel_flags & REL_sql_relation)) |
| 528 | userName = view->rel_owner_name; |
| 529 | } |
| 530 | |
| 531 | switch (item->exa_action) |
| 532 | { |
| 533 | case ExternalAccess::exa_insert: |