Path: blob/master/tools/testing/selftests/filesystems/utils.h
26298 views
/* SPDX-License-Identifier: GPL-2.0 */12#ifndef __IDMAP_UTILS_H3#define __IDMAP_UTILS_H45#ifndef _GNU_SOURCE6#define _GNU_SOURCE7#endif8#include <errno.h>9#include <linux/types.h>10#include <sched.h>11#include <signal.h>12#include <stdbool.h>13#include <stdio.h>14#include <stdlib.h>15#include <string.h>16#include <syscall.h>17#include <sys/capability.h>18#include <sys/fsuid.h>19#include <sys/types.h>20#include <unistd.h>2122extern int get_userns_fd(unsigned long nsid, unsigned long hostid,23unsigned long range);2425extern int caps_down(void);26extern int cap_down(cap_value_t down);2728extern bool switch_ids(uid_t uid, gid_t gid);29extern int setup_userns(void);3031static inline bool switch_userns(int fd, uid_t uid, gid_t gid, bool drop_caps)32{33if (setns(fd, CLONE_NEWUSER))34return false;3536if (!switch_ids(uid, gid))37return false;3839if (drop_caps && !caps_down())40return false;4142return true;43}4445extern uint64_t get_unique_mnt_id(const char *path);4647#endif /* __IDMAP_UTILS_H */484950