如何授予用户访问网络服务的权限

发布于 2024-12-26 23:49:15 字数 267 浏览 3 评论 0原文

我有一个在 ubuntu 服务器上运行的网络服务。这个网络服务有一个方法:

...
main()
{
soap_serve(soap_new());
}
ns_call(std::string who, std::string &result)
{
int j;
j=system ("asterisk -rx \"reload\"");

return SOAP_OK;
}

在客户端,返回可以,但是命令行没有执行。为什么?请帮忙。我堆积如山

I have a webservice running on ubuntu server. This webservice has a method :

...
main()
{
soap_serve(soap_new());
}
ns_call(std::string who, std::string &result)
{
int j;
j=system ("asterisk -rx \"reload\"");

return SOAP_OK;
}

ON THE CLIENT SIDE THE RETURN IS OK BUT THE command line is not executed. WHY? please help. I am stacked

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

穿透光 2025-01-02 23:49:15

我假设该命令实际上正在运行,但它无法连接到 Asterisk 并发出重新加载命令,因为运行 Web 服务器的用户没有连接到 Asterisk 的权限。

两种解决方案。推荐第一个。

sudo

配置 sudo 以允许 Web 服务器用户以 asterisk 用户身份执行特定命令“asterisk -rx reload”:

www-data    (asterisk) NOPASSWD: /usr/sbin/asterisk -rx reload

然后使用此命令正如您传递给 system() 的命令:

system("sudo -u asterisk /usr/sbin/asterisk -rx reload");

套接字权限

asterisk -r 使用 UNIX 域套接字连接到 Asterisk 服务器。套接字的位置可能会根据您的系统而有所不同,但请查找类似 /var/run/asterisk.ctl 的内容。默认情况下,此套接字的权限可能设置为只有星号用户(或 root)可以连接。

您需要安排 Web 服务器用户有权读取和写入此套接字。例如,您可以将套接字 chmoda+rwx,以使其可供系统上的任何用户使用。 (如果系统上有不受信任的用户,请不要执行此操作!)或者您可以授予对此套接字的组写权限,并将其 chgrp 授予 Web 服务器运行所在的组。

无论您如何执行此操作,请注意您正在授予代表您的 Asterisk 服务器执行潜在危险操作的权限。

I am presuming that the command is actually running but it's not able to connect to Asterisk and issue the reload command because the user that is running the web server does not have permission to connect to Asterisk.

Two solutions. The first one is recommended.

sudo

Configure sudo to allow the web server user to execute the specific command "asterisk -rx reload" as the asterisk user:

www-data    (asterisk) NOPASSWD: /usr/sbin/asterisk -rx reload

And then use this as the command you pass to system():

system("sudo -u asterisk /usr/sbin/asterisk -rx reload");

socket permissions

asterisk -r uses a UNIX-domain socket to connect to the Asterisk server. The location of the socket may vary depending on your system but look for something like /var/run/asterisk.ctl. By default, the permissions of this socket are probably set so that only the asterisk user (or root) can connect.

You need to arrange for the web server user to have permission to read and write to this socket. For example, you could chmod the socket to a+rwx to make it usable by any user on the system. (Don't do this if you have untrusted users on the system!) Or you could grant grant group write permission to this socket and chgrp it to the group that the web server runs as.

No matter how you do it, be aware that you are granting permission for things to execute potentially dangerous actions on behalf of your Asterisk server.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文