我做了程序setuid根,但即使如此,cupsenable失败与“权限被拒绝”.然后我在system()之前插入了一个setuid(0)调用,并且看到它有效.
忽略有更好的方式给用户控制打印机的问题.可能有更好的方法.我感兴趣的是chmod的复杂与setuid(0)vs. system().为什么这样做呢?
解决方法
Do not use
system()
from a program with set-user-ID or set-group-ID privileges,because strange values for some environment variables might be used to subvert system integrity. Use theexec(3)
family of functions instead,but notexeclp(3)
orexecvp(3)
.system()
will not,in fact,work properly from programs with set-user-ID or set-group-ID privileges on systems on which/bin/sh
is bash version 2,since bash 2 drops privileges on startup.
和从男子bash:
If the shell is started with the effective user (group) id not equal to the real user (group) id,and the
-p
option is not supplied,no startup files are read,shell functions are not inherited from the environment,theSHELLOPTS
variable,if it appears in the environment,is ignored,and the effective user id is set to the real user id.
看来你的setuid(0)电话规避了这种保护.