1 // Copyright 2019 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 // A binary that tests a lot of syscalls, to test the AddPolicyOnSyscall
16 // functionality.
17
18 #include <sys/stat.h>
19 #include <unistd.h>
20
21 #include <cerrno>
22
main()23 int main() {
24 unsigned int r, e, s;
25 char buf[1];
26 // 1000 is the UID/GID we use inside the namespaces.
27 if (getuid() != 1000) return 1;
28 if (getgid() != 1000) return 2;
29 if (geteuid() != 1000) return 3;
30 if (getegid() != 1000) return 4;
31 if (getresuid(&r, &e, &s) != -1 || errno != 42) return 5;
32 if (getresgid(&r, &e, &s) != -1 || errno != 42) return 6;
33 if (write(1, buf, 1) != -1 || errno != 43) return 8;
34
35 // Trigger a violation.
36 umask(0);
37 return 0;
38 }
39