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

« back to all changes in this revision

Viewing changes to trampoline/trampoline.c

  • Committer: mattgiuca
  • Date: 2008-06-13 09:13:30 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:763
Zip file uploading now works.
(Patch submitted by wagrant, modified and approved by mgiuca).

2 bugs fixed: Paths were being created as filesystem-relative which should
have been jail-relative. Zip was being passed the string contents of the file,
when it should have been passed the file object.

common/zip.py: Now accepts an absolute path, not a URL path.
    (Doesn't munge the path).
    This is so it can be called from inside or outside the jail;
    the caller decides which filesystem it is relative to.
fileservice_lib/action.py:
    1. Now passes the absolute path within the jail.
    2. Now passes the field "file" not "data" (file object, not string).
        Static Typing: Sometimes It Is Good

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>
42
44
#include <limits.h>
43
45
 
44
46
/* conf.h is admin-configured by the setup process.
89
91
    /* At this point we are executing as the child process */
90
92
 
91
93
    /* Change the file mode mask */
92
 
    umask(0);
 
94
    umask(022);
93
95
 
94
96
    /* Create a new SID for the child process */
95
97
    sid = setsid();
112
114
static void usage(const char* nm)
113
115
{
114
116
    fprintf(stderr,
115
 
        "usage: %s [-d] <uid> <jail> <cwd> <program> [args...]\n", nm);
 
117
        "usage: %s [-d] [-u] <uid> <jail> <cwd> <program> [args...]\n", nm);
116
118
    exit(1);
117
119
}
118
120
 
125
127
    int uid;
126
128
    int arg_num = 1;
127
129
    int daemon_mode = 0;
 
130
    int unlimited = 0;
128
131
    char canonical_jailpath[PATH_MAX];
129
132
 
130
133
    /* Disallow execution from all users but the whitelisted ones, and root */
149
152
        daemon_mode = 1;
150
153
        arg_num++;
151
154
    }
 
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
    }
152
165
    uid = atoi(argv[arg_num++]);
153
166
    jailpath = argv[arg_num++];
154
167
    work_dir = argv[arg_num++];
195
208
    /* setuid to the given user ID.
196
209
     * Henceforth we will be running as this user instead of root.
197
210
     */
 
211
    if (setgid(uid))
 
212
    {
 
213
        perror("could not setgid");
 
214
        exit(1);
 
215
    }
 
216
 
198
217
    if (setuid(uid))
199
218
    {
200
219
        perror("could not setuid");
206
225
        daemonize();
207
226
    }
208
227
 
 
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
 
209
269
    /* exec (replace this process with the a new instance of the target
210
270
     * program). Pass along all the arguments.
211
271
     * Note that for script execution, the "program" will be the interpreter,