C语言 错误:语言 c 的权限被拒绝

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7014437/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 09:21:12  来源:igfitidea点击:

ERROR: permission denied for language c

cpostgresql

提问by vchitta

When creating a function like this with a non-super user I am getting the error below:

使用非超级用户创建这样的函数时,出现以下错误:

ERROR: permission denied for language c SQL state: 42501

ERROR: permission denied for language c SQL state: 42501

The function created is :

创建的函数是:

CREATE OR REPLACE FUNCTION dblink_connect (text)
RETURNS text
AS '$libdir/dblink','dblink_connect'
LANGUAGE C STRICT;

But if I wanted to give permission on language C to my non-super user, I am getting the error below: postgres=# grant usage on language c to caixa; ERROR: language "c" is not trusted

但是,如果我想向非超级用户授予语言 C 的权限,则会收到以下错误: postgres=# grant usage on language c to caixa; ERROR: language "c" is not trusted

That means, non-super user can't create function with language C? or is there anything else I am doing wrong?

也就是说,非超级用户不能用 C 语言创建函数?还是我做错了什么?

回答by Grzegorz Szpetkowski

That's right, according to doc:

没错,根据doc

Only superusers can createfunctions in untrusted languages

只有超级用户才能使用不受信任的语言创建函数

Quick check:

快速检查:

SELECT lanpltrusted FROM pg_language WHERE lanname LIKE 'c';
 lanpltrusted 
--------------
 f
(1 row)

If you reallywant this, then you could modify pg_languagesystem catalog (ALTER LANGUAGEdoesn't have such option):

如果你真的想要这个,那么你可以修改pg_language系统目录(ALTER LANGUAGE没有这样的选项):

UPDATE pg_language SET lanpltrusted = true WHERE lanname LIKE 'c';

Per user @Otheus below: the UPDATE statement must be done in the DB where the function will reside.

每个用户@Otheus 下面: UPDATE 语句必须在函数所在的数据库中完成。

回答by Stephane Rolland

Instead of setting the language to trusted which is considered bad, and dangerous, you should rather use roles to provide superuser privilege temporarily to the user during the time he manipulates the stored procedures:

与其将语言设置为被认为是不好的危险的受信任的语言,不如使用角色在用户操作存储过程期间临时为用户提供超级用户权限:

as superuser:

作为超级用户:

create role dba with superuser noinherit;
grant dba to user;

then logged-in as user you can set role dba

然后以用户身份登录,您可以 set role dba

And then you could create stored procedures in C while you temporarily have the role dba.

然后您可以在临时拥有角色的同时用 C 语言创建存储过程dba

reset role;when you're finished to come back to normal rights.

reset role;当你完成恢复正常权利时。

More info here: https://dba.stackexchange.com/questions/37336/cannot-create-function-in-plpython3u-permission-denied

更多信息:https://dba.stackexchange.com/questions/37336/cannot-create-function-in-plpython3u-permission-denied