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

« back to all changes in this revision

Viewing changes to trampoline/trampoline.c

  • Committer: mattgiuca
  • Date: 2008-01-25 06:20:32 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:313
test/test_framework: Updated examples, a bit of better descriptions, sample
    partial solutions, etc.

Added all sample subject material.
This has been copied from test/test_framework and modified slightly.
There is now a subject "sample" with 2 worksheets. The 1st worksheet has 3
exercises. These work in IVLE by default.

setup.py: Added code to install subjects into the designated directory. This
means that installing IVLE will result in the sample subjects being
immediately available.

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
#include <stdlib.h>
38
38
#include <string.h>
39
39
#include <unistd.h>
40
 
#include <sys/types.h>
41
 
#include <sys/stat.h>
42
 
#include <sys/time.h>
43
 
#include <sys/resource.h>
44
 
#include <limits.h>
45
40
 
46
41
/* conf.h is admin-configured by the setup process.
47
42
 * It defines jail_base.
91
86
    /* At this point we are executing as the child process */
92
87
 
93
88
    /* Change the file mode mask */
94
 
    umask(022);
 
89
    umask(0);
95
90
 
96
91
    /* Create a new SID for the child process */
97
92
    sid = setsid();
114
109
static void usage(const char* nm)
115
110
{
116
111
    fprintf(stderr,
117
 
        "usage: %s [-d] [-u] <uid> <jail> <cwd> <program> [args...]\n", nm);
 
112
        "usage: %s [-d] <uid> <jail> <cwd> <program> [args...]\n", nm);
118
113
    exit(1);
119
114
}
120
115
 
127
122
    int uid;
128
123
    int arg_num = 1;
129
124
    int daemon_mode = 0;
130
 
    int unlimited = 0;
131
 
    char canonical_jailpath[PATH_MAX];
132
125
 
133
126
    /* Disallow execution from all users but the whitelisted ones, and root */
134
127
    if (!uid_allowed(getuid()))
152
145
        daemon_mode = 1;
153
146
        arg_num++;
154
147
    }
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
148
    uid = atoi(argv[arg_num++]);
166
149
    jailpath = argv[arg_num++];
167
150
    work_dir = argv[arg_num++];
175
158
        exit(1);
176
159
    }
177
160
 
178
 
    /* Jail path must be an absolute path,
179
 
     * and it must begin with jail_base.
 
161
    /* Jail path must:
 
162
     * Be non-empty
 
163
     * Start with a '/'
 
164
     * Not contain "/.."
 
165
     * Begin with jail_base
180
166
     */
181
 
    if (norm(canonical_jailpath, PATH_MAX, jailpath) != 0)
182
 
    {
183
 
        fprintf(stderr, "bad jail path: %s\n", jailpath);
184
 
        exit(1);
185
 
    }
186
 
    if (strncmp(canonical_jailpath, jail_base, strlen(jail_base)))
 
167
    if (strlen(jailpath) < 1 || jailpath[0] != '/'
 
168
            || strstr(jailpath, "/..")
 
169
            || strncmp(jailpath, jail_base, strlen(jail_base)))
187
170
    {
188
171
        fprintf(stderr, "bad jail path: %s\n", jailpath);
189
172
        exit(1);
191
174
 
192
175
    /* chroot into the jail.
193
176
     * Henceforth this process, and its children, cannot see anything above
194
 
     * canoncial_jailpath. */
195
 
    if (chroot(canonical_jailpath))
 
177
     * jailpath. */
 
178
    if (chroot(jailpath))
196
179
    {
197
180
        perror("could not chroot");
198
181
        exit(1);
208
191
    /* setuid to the given user ID.
209
192
     * Henceforth we will be running as this user instead of root.
210
193
     */
211
 
    if (setgid(uid))
212
 
    {
213
 
        perror("could not setgid");
214
 
        exit(1);
215
 
    }
216
 
 
217
194
    if (setuid(uid))
218
195
    {
219
196
        perror("could not setuid");
225
202
        daemonize();
226
203
    }
227
204
 
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
205
    /* exec (replace this process with the a new instance of the target
270
206
     * program). Pass along all the arguments.
271
207
     * Note that for script execution, the "program" will be the interpreter,