mirror of
git://github.com/lxc/lxc
synced 2025-08-29 19:09:52 +00:00
attach: simplify lsm_openat()
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
This commit is contained in:
parent
81f466d05f
commit
82b1f317c8
@ -85,12 +85,13 @@
|
||||
|
||||
lxc_log_define(lxc_attach, lxc);
|
||||
|
||||
/* /proc/pid-to-str/current\0 = (5 + 21 + 7 + 1) */
|
||||
#define __LSMATTRLEN (5 + 21 + 7 + 1)
|
||||
static int lsm_openat(int procfd, pid_t pid, int on_exec)
|
||||
{
|
||||
int ret = -1;
|
||||
int labelfd = -1;
|
||||
const char* name;
|
||||
#define __LSMATTRLEN /* /proc */ (5 + /* /pid-to-str */ 21 + /* /current */ 7 + /* \0 */ 1)
|
||||
const char *name;
|
||||
char path[__LSMATTRLEN];
|
||||
|
||||
name = lsm_name();
|
||||
@ -105,20 +106,16 @@ static int lsm_openat(int procfd, pid_t pid, int on_exec)
|
||||
if (strcmp(name, "AppArmor") == 0)
|
||||
on_exec = 0;
|
||||
|
||||
if (on_exec) {
|
||||
if (on_exec)
|
||||
ret = snprintf(path, __LSMATTRLEN, "%d/attr/exec", pid);
|
||||
if (ret < 0 || ret >= __LSMATTRLEN)
|
||||
return -1;
|
||||
labelfd = openat(procfd, path, O_RDWR);
|
||||
} else {
|
||||
else
|
||||
ret = snprintf(path, __LSMATTRLEN, "%d/attr/current", pid);
|
||||
if (ret < 0 || ret >= __LSMATTRLEN)
|
||||
return -1;
|
||||
labelfd = openat(procfd, path, O_RDWR);
|
||||
}
|
||||
if (ret < 0 || ret >= __LSMATTRLEN)
|
||||
return -1;
|
||||
|
||||
labelfd = openat(procfd, path, O_RDWR);
|
||||
if (labelfd < 0) {
|
||||
SYSERROR("Unable to open LSM label");
|
||||
SYSERROR("Unable to open file descriptor to set LSM label.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user