• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (c) Huawei Technologies Co., Ltd., 2015
4  * Copyright (C) 2022 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
5  */
6 
7 #ifndef COMMON_H
8 #define COMMON_H
9 
10 #include "tst_test.h"
11 
12 #define UID_MAP 0
13 #define GID_MAP 1
14 
updatemap(int cpid,int type,int idnum,int parentmappid)15 static inline void updatemap(int cpid, int type, int idnum, int parentmappid)
16 {
17 	char path[BUFSIZ];
18 	char content[BUFSIZ];
19 	int fd;
20 
21 	switch (type) {
22 	case UID_MAP:
23 		sprintf(path, "/proc/%d/uid_map", cpid);
24 		break;
25 	case GID_MAP:
26 		sprintf(path, "/proc/%d/gid_map", cpid);
27 		break;
28 	default:
29 		tst_brk(TBROK, "invalid type parameter");
30 		break;
31 	}
32 
33 	sprintf(content, "%d %d 1", idnum, parentmappid);
34 
35 	fd = SAFE_OPEN(path, O_WRONLY, 0644);
36 	SAFE_WRITE(SAFE_WRITE_ALL, fd, content, strlen(content));
37 	SAFE_CLOSE(fd);
38 }
39 
40 #endif
41