|
3 | 3 | * procedural language |
4 | 4 | * |
5 | 5 | * IDENTIFICATION |
6 | | - * $Header: /cvsroot/pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.44 2001/05/28 19:33:24 tgl Exp $ |
| 6 | + * $Header: /cvsroot/pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.45 2001/07/11 18:54:18 momjian Exp $ |
7 | 7 | * |
8 | 8 | * This software is copyrighted by Jan Wieck - Hamburg. |
9 | 9 | * |
|
47 | 47 | #include "plpgsql.h" |
48 | 48 | #include "pl.tab.h" |
49 | 49 |
|
| 50 | +#include "miscadmin.h" |
50 | 51 | #include "access/heapam.h" |
51 | 52 | #include "catalog/pg_proc.h" |
52 | 53 | #include "catalog/pg_type.h" |
@@ -105,6 +106,8 @@ static int exec_stmt_exit(PLpgSQL_execstate * estate, |
105 | 106 | PLpgSQL_stmt_exit * stmt); |
106 | 107 | static int exec_stmt_return(PLpgSQL_execstate * estate, |
107 | 108 | PLpgSQL_stmt_return * stmt); |
| 109 | +static int exec_stmt_setauth(PLpgSQL_execstate * estate, |
| 110 | + PLpgSQL_stmt_setauth * stmt); |
108 | 111 | static int exec_stmt_raise(PLpgSQL_execstate * estate, |
109 | 112 | PLpgSQL_stmt_raise * stmt); |
110 | 113 | static int exec_stmt_execsql(PLpgSQL_execstate * estate, |
@@ -226,6 +229,9 @@ plpgsql_exec_function(PLpgSQL_function * func, FunctionCallInfo fcinfo) |
226 | 229 | case PLPGSQL_STMT_RETURN: |
227 | 230 | stmttype = "return"; |
228 | 231 | break; |
| 232 | + case PLPGSQL_STMT_SETAUTH: |
| 233 | + stmttype = "setauth"; |
| 234 | + break; |
229 | 235 | case PLPGSQL_STMT_RAISE: |
230 | 236 | stmttype = "raise"; |
231 | 237 | break; |
@@ -277,7 +283,10 @@ plpgsql_exec_function(PLpgSQL_function * func, FunctionCallInfo fcinfo) |
277 | 283 | estate.retistuple = func->fn_retistuple; |
278 | 284 | estate.retisset = func->fn_retset; |
279 | 285 | estate.exitlabel = NULL; |
280 | | - |
| 286 | + estate.invoker_uid = GetUserId(); |
| 287 | + estate.definer_uid = func->definer_uid; |
| 288 | + estate.auth_level = PLPGSQL_AUTH_INVOKER; |
| 289 | + |
281 | 290 | estate.found_varno = func->found_varno; |
282 | 291 | estate.ndatums = func->ndatums; |
283 | 292 | estate.datums = palloc(sizeof(PLpgSQL_datum *) * estate.ndatums); |
@@ -397,6 +406,9 @@ plpgsql_exec_function(PLpgSQL_function * func, FunctionCallInfo fcinfo) |
397 | 406 | elog(ERROR, "control reaches end of function without RETURN"); |
398 | 407 | } |
399 | 408 |
|
| 409 | + if (estate.auth_level!=PLPGSQL_AUTH_INVOKER) |
| 410 | + SetUserId(estate.invoker_uid); |
| 411 | + |
400 | 412 | /* |
401 | 413 | * We got a return value - process it |
402 | 414 | */ |
@@ -577,6 +589,9 @@ plpgsql_exec_trigger(PLpgSQL_function * func, |
577 | 589 | estate.retistuple = func->fn_retistuple; |
578 | 590 | estate.retisset = func->fn_retset; |
579 | 591 | estate.exitlabel = NULL; |
| 592 | + estate.invoker_uid = GetUserId(); |
| 593 | + estate.definer_uid = func->definer_uid; |
| 594 | + estate.auth_level = PLPGSQL_AUTH_INVOKER; |
580 | 595 |
|
581 | 596 | estate.found_varno = func->found_varno; |
582 | 597 | estate.ndatums = func->ndatums; |
@@ -760,6 +775,9 @@ plpgsql_exec_trigger(PLpgSQL_function * func, |
760 | 775 | elog(ERROR, "control reaches end of trigger procedure without RETURN"); |
761 | 776 | } |
762 | 777 |
|
| 778 | + if (estate.auth_level!=PLPGSQL_AUTH_INVOKER) |
| 779 | + SetUserId(estate.invoker_uid); |
| 780 | + |
763 | 781 | /* |
764 | 782 | * Check that the returned tuple structure has the same attributes, |
765 | 783 | * the relation that fired the trigger has. |
@@ -1022,6 +1040,10 @@ exec_stmt(PLpgSQL_execstate * estate, PLpgSQL_stmt * stmt) |
1022 | 1040 | rc = exec_stmt_return(estate, (PLpgSQL_stmt_return *) stmt); |
1023 | 1041 | break; |
1024 | 1042 |
|
| 1043 | + case PLPGSQL_STMT_SETAUTH: |
| 1044 | + rc = exec_stmt_setauth(estate, (PLpgSQL_stmt_setauth *) stmt); |
| 1045 | + break; |
| 1046 | + |
1025 | 1047 | case PLPGSQL_STMT_RAISE: |
1026 | 1048 | rc = exec_stmt_raise(estate, (PLpgSQL_stmt_raise *) stmt); |
1027 | 1049 | break; |
@@ -1645,6 +1667,29 @@ exec_stmt_return(PLpgSQL_execstate * estate, PLpgSQL_stmt_return * stmt) |
1645 | 1667 | return PLPGSQL_RC_RETURN; |
1646 | 1668 | } |
1647 | 1669 |
|
| 1670 | +/* ---------- |
| 1671 | + * exec_stmt_setauth Changes user ID to/from |
| 1672 | + * that of the function owner's |
| 1673 | + * ---------- |
| 1674 | + */ |
| 1675 | + |
| 1676 | +static int |
| 1677 | +exec_stmt_setauth(PLpgSQL_execstate * estate, PLpgSQL_stmt_setauth * stmt) |
| 1678 | +{ |
| 1679 | + switch(stmt->auth_level) |
| 1680 | + { |
| 1681 | + case PLPGSQL_AUTH_DEFINER: |
| 1682 | + SetUserId(estate->definer_uid); |
| 1683 | + break; |
| 1684 | + case PLPGSQL_AUTH_INVOKER: |
| 1685 | + SetUserId(estate->invoker_uid); |
| 1686 | + break; |
| 1687 | + } |
| 1688 | + |
| 1689 | + estate->auth_level=stmt->auth_level; |
| 1690 | + return PLPGSQL_RC_OK; |
| 1691 | +} |
| 1692 | + |
1648 | 1693 |
|
1649 | 1694 | /* ---------- |
1650 | 1695 | * exec_stmt_raise Build a message and throw it with |
|
0 commit comments