~azzar1/unity/add-show-desktop-key

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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#include "conf.h"

int main(int argc, char* const argv[])
{
    if (argc < 6)
    {
        fprintf(stderr, "usage: %s <uid> <jail> <cwd> <interp> <script> [args...]\n", argv[0]);
        exit(1);
    }

    if (strlen(argv[2]) < 1 || argv[2][0] != '/'
            || strstr(argv[2], "/..")
            || strncmp(argv[2], jail_base, strlen(jail_base)))
    {
        fprintf(stderr, "bad path: %s\n", argv[2]);
        exit(1);
    }

    if (chroot(argv[2]))
    {
        perror("could not chroot");
        exit(1);
    }

    if (chdir(argv[3]))
    {
        perror("could not chdir");
        exit(1);
    }

    if (setuid(atoi(argv[1])))
    {
        perror("could not setuid");
        exit(1);
    }

    execv(argv[4], argv + 5);

    /* nb exec won't return unless there was an error */
    perror("could not exec");
    exit(1);
}