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

« back to all changes in this revision

Viewing changes to trampoline/trampoline.c

  • Committer: stevenbird
  • Date: 2008-02-19 21:17:21 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:512
Renaming of problems to exercises (initial commit).
Fix up module naming (exercises sometimes called tutorials).

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
#include <unistd.h>
40
40
#include <sys/types.h>
41
41
#include <sys/stat.h>
42
 
#include <sys/time.h>
43
 
#include <sys/resource.h>
44
42
#include <limits.h>
45
43
 
46
44
/* conf.h is admin-configured by the setup process.
114
112
static void usage(const char* nm)
115
113
{
116
114
    fprintf(stderr,
117
 
        "usage: %s [-d] [-u] <uid> <jail> <cwd> <program> [args...]\n", nm);
 
115
        "usage: %s [-d] <uid> <jail> <cwd> <program> [args...]\n", nm);
118
116
    exit(1);
119
117
}
120
118
 
127
125
    int uid;
128
126
    int arg_num = 1;
129
127
    int daemon_mode = 0;
130
 
    int unlimited = 0;
131
128
    char canonical_jailpath[PATH_MAX];
132
129
 
133
130
    /* Disallow execution from all users but the whitelisted ones, and root */
152
149
        daemon_mode = 1;
153
150
        arg_num++;
154
151
    }
155
 
 
156
 
    if (strcmp(argv[arg_num], "-u") == 0)
157
 
    {
158
 
        if (argc < 6)
159
 
        {
160
 
            usage(argv[0]);
161
 
        }
162
 
        unlimited = 1;
163
 
        arg_num++;
164
 
    }
165
152
    uid = atoi(argv[arg_num++]);
166
153
    jailpath = argv[arg_num++];
167
154
    work_dir = argv[arg_num++];
208
195
    /* setuid to the given user ID.
209
196
     * Henceforth we will be running as this user instead of root.
210
197
     */
211
 
    if (setgid(uid))
212
 
    {
213
 
        perror("could not setgid");
214
 
        exit(1);
215
 
    }
216
 
 
217
198
    if (setuid(uid))
218
199
    {
219
200
        perror("could not setuid");
225
206
        daemonize();
226
207
    }
227
208
 
228
 
    /* set user resource limits */
229
 
    if (!unlimited)
230
 
    {
231
 
        struct rlimit l;
232
 
        /* Process size in virtual memory */
233
 
        l.rlim_cur = 64 * 1024 * 1024; /* 64Mb */
234
 
        l.rlim_max = 72 * 1024 * 1024; /* 64Mb */
235
 
        if (setrlimit(RLIMIT_AS, &l))
236
 
        {
237
 
            perror("could not setrlimit/RLIMIT_AS");
238
 
            exit(1);
239
 
        }
240
 
 
241
 
        /* Core */
242
 
        l.rlim_cur = 0;
243
 
        l.rlim_max = 0;
244
 
        if (setrlimit(RLIMIT_CORE, &l))
245
 
        {
246
 
            perror("could not setrlimit/RLIMIT_CORE");
247
 
            exit(1);
248
 
        }
249
 
 
250
 
        /* CPU */
251
 
        l.rlim_cur = 25;
252
 
        l.rlim_max = 30;
253
 
        if (setrlimit(RLIMIT_CPU, &l))
254
 
        {
255
 
            perror("could not setrlimit/RLIMIT_CPU");
256
 
            exit(1);
257
 
        }
258
 
 
259
 
        /* File Size */
260
 
        l.rlim_cur = 64 * 1024 * 1024; /* 64Mb */
261
 
        l.rlim_max = 72 * 1024 * 1024; /* 72Mb */
262
 
        if (setrlimit(RLIMIT_FSIZE, &l))
263
 
        {
264
 
            perror("could not setrlimit/RLIMIT_FSIZE");
265
 
            exit(1);
266
 
        }
267
 
    }
268
 
 
269
209
    /* exec (replace this process with the a new instance of the target
270
210
     * program). Pass along all the arguments.
271
211
     * Note that for script execution, the "program" will be the interpreter,