Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 编辑sudoers文件无效_Php_Linux_Rights_Sudoers - Fatal编程技术网

Php 编辑sudoers文件无效

Php 编辑sudoers文件无效,php,linux,rights,sudoers,Php,Linux,Rights,Sudoers,各位程序员 我正在做我的学士学位项目,遇到了一点问题 目标是创建一个web应用程序,可以操作和修改WAGO PLC 750-8202的I/O(您可以将其想象为某种工业树莓PI),运行带有lighttpd web服务器的嵌入式linux。我已经制作了一些利用PLC提供的DAL(HAL)函数的C脚本 现在我想把它和我的web应用程序/网站链接起来。我有一个简单的PHP页面(忽略按钮,它什么也不做): Visudo没有在PLC linux系统中实现,因此我必须直接打开它。我将其更改为下面发布的代码,但

各位程序员

我正在做我的学士学位项目,遇到了一点问题

目标是创建一个web应用程序,可以操作和修改WAGO PLC 750-8202的I/O(您可以将其想象为某种工业树莓PI),运行带有lighttpd web服务器的嵌入式linux。我已经制作了一些利用PLC提供的DAL(HAL)函数的C脚本

现在我想把它和我的web应用程序/网站链接起来。我有一个简单的PHP页面(忽略按钮,它什么也不做):

Visudo没有在PLC linux系统中实现,因此我必须直接打开它。我将其更改为下面发布的代码,但是如果我尝试以lighttpd用户身份运行C脚本(使用su www),它仍然不起作用。我做错了什么

谢谢你的建议

# sudoers file.
#
# This file MUST be edited with the 'visudo' command as root.
#
# See the sudoers man page for the details on how to write a sudoers file.
#

# Host alias specification

# User alias specification

# Cmnd alias specification

# Defaults specification

# Runas alias specification

# User privilege specification 
root  ALL=(ALL) SETENV: ALL 
admin ALL=NOPASSWD: /etc/config-tools/get_user_info user 
ALL=NOPASSWD: /etc/config-tools/get_user_info 
www ALL=(ALL) NOPASSWD:ALL

# Uncomment to allow people in group wheel to run all commands
# and set environment variables.
# %wheel  ALL=(ALL) SETENV: ALL

# Same thing without a password
# %wheel  ALL=(ALL) NOPASSWD: SETENV: ALL

# Samples
# %users  ALL=/sbin/mount /cdrom,/sbin/umount /cdrom
# %users  localhost=/sbin/shutdown -h now

谢谢你的帮助。我让它工作了,我没有从PHP文件中调用sudo脚本。正如您所建议的,我将sudoers中的行更改为只允许一个特定脚本,因此我没有安全漏洞。

我认为您需要考虑的问题是为什么
kbusdemo1
仅在以root身份运行时才运行。它是否读取(不必要地)由root拥有的任何文件。您是否将kbusdemo1编译为root用户?(不必要地再次?)或者您编写的硬件交互需要根权限?可能是硬件交互需要根权限。它需要访问PLC的内部内存,获取有关I/O模块值的信息并更改它们,因此我认为脚本需要以root身份运行。好的,现在不需要尝试将二进制文件添加到sudoers文件中,您可以将文件的所有者更改为
root
,并尝试为二进制文件设置
suid
标志。这将允许任何用户以root身份运行二进制文件。您可以
chown
将二进制文件的所有者更改为root。然后切换到root并运行
chmod u+s kbusdemo1
。PHP、
system
sudo
是制作奇妙安全漏洞的原料。您应该看一看,了解一些安全问题。
sudo nano /etc/sudoers
# sudoers file.
#
# This file MUST be edited with the 'visudo' command as root.
#
# See the sudoers man page for the details on how to write a sudoers file.
#

# Host alias specification

# User alias specification

# Cmnd alias specification

# Defaults specification

# Runas alias specification

# User privilege specification 
root  ALL=(ALL) SETENV: ALL 
admin ALL=NOPASSWD: /etc/config-tools/get_user_info user 
ALL=NOPASSWD: /etc/config-tools/get_user_info 
www ALL=(ALL) NOPASSWD:ALL

# Uncomment to allow people in group wheel to run all commands
# and set environment variables.
# %wheel  ALL=(ALL) SETENV: ALL

# Same thing without a password
# %wheel  ALL=(ALL) NOPASSWD: SETENV: ALL

# Samples
# %users  ALL=/sbin/mount /cdrom,/sbin/umount /cdrom
# %users  localhost=/sbin/shutdown -h now