【问题标题】:where can I find the source code of function "setcon" in libselinux?在哪里可以找到 libselinux 中函数“setcon”的源代码?
【发布时间】:2020-04-02 13:24:52
【问题描述】:

我试图弄清楚 Selinux 是如何工作的,我在几个地方看到了一个名为 setcon 的函数,它在 selinux/selinux.h 中声明,并且有一个手册页条目。但是我在 libselinux 的源代码中找不到这个函数的实现(即源代码)。谁能告诉我 setcon 的源代码在哪里?非常感谢。

/* Set the current security context to con.
   Note that use of this function requires that the entire application
   be trusted to maintain any desired separation between the old and new
   security contexts, unlike exec-based transitions performed via setexeccon.
   When possible, decompose your application and use setexeccon()+execve()
   instead. Note that the application may lose access to its open descriptors
   as a result of a setcon() unless policy allows it to use descriptors opened
   by the old context. */
extern int setcon(const char * con);

【问题讨论】:

    标签: selinux


    【解决方案1】:

    这是我自己想出来的。实际上,函数“setcon”是在/libselinux/src/proattr.c 使用几个宏定义的。

    #define setselfattr_def(fn, attr) \
    int set##fn(const char * c) \
    { \
        return setprocattrcon(c, 0, #attr); \
    }
    
    #define all_selfattr_def(fn, attr) \
      getselfattr_def(fn, attr)  \
      setselfattr_def(fn, attr)
    
    all_selfattr_def(con, current)
    

    从上面我们可以看出,真正的函数是“setprocattrcon”,它也是在同一个源文件中定义的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-09-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-06
      • 1970-01-01
      相关资源
      最近更新 更多