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

« back to all changes in this revision

Viewing changes to trampoline/trampoline.c

  • Committer: stevenbird
  • Date: 2008-02-01 03:51:56 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:368
First version of a DTD for XML problem files

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 <limits.h>
40
43
 
41
44
/* conf.h is admin-configured by the setup process.
42
45
 * It defines jail_base.
122
125
    int uid;
123
126
    int arg_num = 1;
124
127
    int daemon_mode = 0;
 
128
    char canonical_jailpath[PATH_MAX];
125
129
 
126
130
    /* Disallow execution from all users but the whitelisted ones, and root */
127
131
    if (!uid_allowed(getuid()))
158
162
        exit(1);
159
163
    }
160
164
 
161
 
    /* Jail path must:
162
 
     * Be non-empty
163
 
     * Start with a '/'
164
 
     * Not contain "/.."
165
 
     * Begin with jail_base
 
165
    /* Jail path must be an absolute path,
 
166
     * and it must begin with jail_base.
166
167
     */
167
 
    if (strlen(jailpath) < 1 || jailpath[0] != '/'
168
 
            || strstr(jailpath, "/..")
169
 
            || strncmp(jailpath, jail_base, strlen(jail_base)))
 
168
    if (norm(canonical_jailpath, PATH_MAX, jailpath) != 0)
 
169
    {
 
170
        fprintf(stderr, "bad jail path: %s\n", jailpath);
 
171
        exit(1);
 
172
    }
 
173
    if (strncmp(canonical_jailpath, jail_base, strlen(jail_base)))
170
174
    {
171
175
        fprintf(stderr, "bad jail path: %s\n", jailpath);
172
176
        exit(1);
174
178
 
175
179
    /* chroot into the jail.
176
180
     * Henceforth this process, and its children, cannot see anything above
177
 
     * jailpath. */
178
 
    if (chroot(jailpath))
 
181
     * canoncial_jailpath. */
 
182
    if (chroot(canonical_jailpath))
179
183
    {
180
184
        perror("could not chroot");
181
185
        exit(1);