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

« back to all changes in this revision

Viewing changes to bin/trampoline/trampoline.c

  • Committer: William Grant
  • Date: 2009-06-24 10:47:38 UTC
  • mfrom: (1288 trunk)
  • mto: (1281.1.8 aufsless)
  • mto: This revision was merged to the branch mainline in revision 1300.
  • Revision ID: grantw@unimelb.edu.au-20090624104738-ezgfy17mjzwz09i3
MergeĀ fromĀ trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
 * Scripts (such as Python programs) should be executed by supplying
28
28
 * "/usr/bin/python" as the program, and the script as the first argument.
29
29
 *
 
30
 * Usage: trampoline uid jail-path working-path program [args...]
30
31
 * Must run as root. Will safely setuid to the supplied uid, checking that it
31
32
 * is not root. Recommended that the file is set up as follows:
32
33
 *  sudo chown root:root trampoline; sudo chroot +s trampoline
33
34
 */
34
35
 
35
36
#define _XOPEN_SOURCE
36
 
#define _BSD_SOURCE
37
37
 
38
38
#include <stdio.h>
39
39
#include <stdlib.h>
45
45
#include <sys/stat.h>
46
46
#include <sys/time.h>
47
47
#include <sys/resource.h>
48
 
#include <grp.h>
49
48
#include <limits.h>
50
49
#include <signal.h>
51
50
 
123
122
{
124
123
    fprintf(stderr,
125
124
        "usage: %s [-d] [-u] <uid> <base> <src> <system> <jail> <cwd> <program> [args...]\n", nm);
126
 
    fprintf(stderr, "  -d       \tDaemonize\n");
127
 
    fprintf(stderr, "  -u       \tPrint usage\n");
128
 
    fprintf(stderr, "  <uid>    \tUID to run program as\n");
129
 
    fprintf(stderr, "  <base>   \tDirectory that jails will be mounted in\n");
130
 
    fprintf(stderr, "  <src>    \tDirectory containing users jail data\n");
131
 
    fprintf(stderr, "  <system> \tDirectory containing main jail file system\n");
132
 
    fprintf(stderr, "  <jail>   \tDirectory of users mounted jail\n");
133
 
    fprintf(stderr, "  <cwd>    \tDirectory inside the jail to change dir to\n");
134
 
    fprintf(stderr, "  <program>\tProgram inside jail to execute\n");
135
125
    exit(1);
136
126
}
137
127
 
260
250
    char* prog;
261
251
    char* const * args;
262
252
    int uid;
263
 
    gid_t groups[1];
264
253
    int arg_num = 1;
265
254
    int daemon_mode = 0;
266
255
    int unlimited = 0;
360
349
        perror("could not setgid");
361
350
        exit(1);
362
351
    }
363
 
    
364
 
    groups[0] = uid;
365
 
    if (setgroups(1, groups))
366
 
    {
367
 
        perror("could not setgroups");
368
 
        exit(1);
369
 
    }
370
352
 
371
353
    if (setuid(uid))
372
354
    {
379
361
    {
380
362
        struct rlimit l;
381
363
        /* Process adress space in memory */
382
 
        l.rlim_cur = 448 * 1024 * 1024; /* 512MiB - 64MiB */
383
 
        l.rlim_max = 512 * 1024 * 1024; /* 512MiB */
 
364
        l.rlim_cur = 192 * 1024 * 1024; /* 192MiB */
 
365
        l.rlim_max = 256 * 1024 * 1024; /* 256MiB */
384
366
        if (setrlimit(RLIMIT_AS, &l))
385
367
        {
386
368
            perror("could not setrlimit/RLIMIT_AS");
391
373
         * Note: This requires a kernel patch to work correctly otherwise it is  
392
374
         * ineffective (thus you are only limited by RLIMIT_AS)
393
375
         */
394
 
        l.rlim_cur = 448 * 1024 * 1024; /* 512MiB - 64MiB */
395
 
        l.rlim_max = 512 * 1024 * 1024; /* 512MiB */
 
376
        l.rlim_cur = 192 * 1024 * 1024; /* 192MiB */
 
377
        l.rlim_max = 256 * 1024 * 1024; /* 256MiB */
396
378
        if (setrlimit(RLIMIT_DATA, &l))
397
379
        {
398
380
            perror("could not setrlimit/RLIMIT_DATA");
420
402
        /* File Size */
421
403
        l.rlim_cur = 64 * 1024 * 1024; /* 64MiB */
422
404
        l.rlim_max = 72 * 1024 * 1024; /* 72MiB */
423
 
        if (setrlimit(RLIMIT_FSIZE, &l))
 
405
if (setrlimit(RLIMIT_FSIZE, &l))
424
406
        {
425
407
            perror("could not setrlimit/RLIMIT_FSIZE");
426
408
            exit(1);
427
409
        }
428
 
        
429
 
        /* Number of Processes */
430
 
        l.rlim_cur = 50;
431
 
        l.rlim_max = 50;
432
 
        if (setrlimit(RLIMIT_NPROC, &l))
433
 
        {
434
 
            perror("could not setrlimit/RLIMIT_NPROC");
435
 
            exit(1);
436
 
        }
437
410
    }
438
411
 
439
412
    /* Remove any signal handler masks so we can send signals to the child */