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

« back to all changes in this revision

Viewing changes to www/trampoline.c

  • Committer: mattgiuca
  • Date: 2007-12-20 03:14:17 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:93
New directory hierarchy.
Renamed src to www.
Added console, trampoline (currently empty).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <stdio.h>
 
2
#include <stdlib.h>
 
3
#include <string.h>
 
4
#include <unistd.h>
 
5
 
 
6
#include "conf.h"
 
7
 
 
8
int main(int argc, char* const argv[])
 
9
{
 
10
    if (argc < 6)
 
11
    {
 
12
        fprintf(stderr, "usage: %s <uid> <jail> <cwd> <interp> <script> [args...]\n", argv[0]);
 
13
        exit(1);
 
14
    }
 
15
 
 
16
    if (strlen(argv[2]) < 1 || argv[2][0] != '/'
 
17
            || strstr(argv[2], "/..")
 
18
            || strncmp(argv[2], jail_base, strlen(jail_base)))
 
19
    {
 
20
        fprintf(stderr, "bad path: %s\n", argv[2]);
 
21
        exit(1);
 
22
    }
 
23
 
 
24
    if (chroot(argv[2]))
 
25
    {
 
26
        perror("could not chroot");
 
27
        exit(1);
 
28
    }
 
29
 
 
30
    if (chdir(argv[3]))
 
31
    {
 
32
        perror("could not chdir");
 
33
        exit(1);
 
34
    }
 
35
 
 
36
    if (setuid(atoi(argv[1])))
 
37
    {
 
38
        perror("could not setuid");
 
39
        exit(1);
 
40
    }
 
41
 
 
42
    execv(argv[4], argv + 5);
 
43
 
 
44
    /* nb exec won't return unless there was an error */
 
45
    perror("could not exec");
 
46
    exit(1);
 
47
}