File: dropuidgidtest.c

package info (click to toggle)
tinyssh 20230101-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 2,244 kB
  • sloc: ansic: 12,106; sh: 1,168; python: 479; makefile: 42
file content (47 lines) | stat: -rw-r--r-- 773 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
20140320
Jan Mojzis
Public domain.
*/

#include <unistd.h>
#include "run.h"
#include "fail.h"
#include "dropuidgid.h"

static void droproot(void) {

    if (geteuid() == 0) {
        if (!dropuidgid(0, 1230, 1230)) _exit(111);
    }
    if (geteuid() == 0) _exit(111);
}


static void test1(void) {
    droproot();
    if (dropuidgid(0, 1231, getegid())) _exit(111);
    _exit(0);
}

static void test2(void) {
    droproot();
    if (!dropuidgid(0, geteuid(), getegid())) _exit(111);
    if (!dropuidgid(0, geteuid(), getegid())) _exit(111);
    _exit(0);
}

static void test3(void) {
    droproot();
    if (!dropuidgid(0, 0, 0)) _exit(111);
    _exit(0);
}


int main(void) {

    run_mustpass(test1);
    run_mustpass(test2);
    run_mustfail(test3);
    _exit(0);
}