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

« back to all changes in this revision

Viewing changes to bin/trampoline/trampoline.c

  • Committer: chadnickbok
  • Date: 2009-01-27 05:13:56 UTC
  • Revision ID: svn-v4:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:1176
Fixed a small issue with non-unicode strings being passed
into storm

Show diffs side-by-side

added added

removed removed

Lines of Context:
121
121
static void usage(const char* nm)
122
122
{
123
123
    fprintf(stderr,
124
 
        "usage: %s [-d] [-u] <uid> <base> <src> <system> <jail> <cwd> <program> [args...]\n", nm);
 
124
        "usage: %s [-d] [-u] <uid> <jail> <cwd> <program> [args...]\n", nm);
125
125
    exit(1);
126
126
}
127
127
 
137
137
    return ptr;
138
138
}
139
139
 
140
 
int checked_mount(const char *source, const char *target,
141
 
                  const char *filesystemtype, unsigned long mountflags,
142
 
                  const void *data)
143
 
{
144
 
    int result = mount(source, target, filesystemtype, mountflags, data);
145
 
    if (result)
146
 
    {
147
 
        syslog(LOG_ERR, "could not mount %s on %s\n", source, target);
148
 
        perror("could not mount");
149
 
        exit(1);
150
 
    }
151
 
 
152
 
    return result;
153
 
}
154
 
 
155
 
 
156
140
/* Find the path of the user components of a jail, given a mountpoint. */
157
 
char *jail_src(const char *jail_src_base, const char *jail_base,
158
 
               const char *jailpath)
 
141
char *jail_src(const char* jailpath)
159
142
{
160
143
    char* src;
161
144
    int srclen;
163
146
 
164
147
    srclen = strlen(jail_src_base);
165
148
    dstlen = strlen(jail_base);
166
 
 
 
149
    
167
150
    src = die_if_null(malloc(strlen(jailpath) + (srclen - dstlen) + 1));
168
151
    strcpy(src, jail_src_base);
169
152
    strcat(src, jailpath+dstlen);
174
157
/* Check for the validity of a jail in the given path, mounting it if it looks
175
158
 * empty.
176
159
 * TODO: Updating /etc/mtab would be nice. */
177
 
void mount_if_needed(const char *jail_src_base, const char *jail_base,
178
 
                     const char *jail_system, const char *jailpath)
 
160
void mount_if_needed(const char* jailpath)
179
161
{
180
162
    char *jailsrc;
181
163
    char *jaillib;
182
 
    char *source_bits;
183
 
    char *target_bits;
 
164
    char *mountdata;
184
165
 
185
166
    /* Check if there is something useful in the jail. If not, it's probably
186
167
     * not mounted. */
200
181
             }
201
182
             syslog(LOG_NOTICE, "created mountpoint %s\n", jailpath);
202
183
        }
203
 
 
204
 
        jailsrc = jail_src(jail_src_base, jail_base, jailpath);
205
 
        checked_mount(jail_system, jailpath, NULL, MS_BIND | MS_RDONLY, NULL);
206
 
 
207
 
        source_bits = die_if_null(malloc(strlen(jailsrc) + 5 + 1));
208
 
        target_bits = die_if_null(malloc(strlen(jailpath) + 5 + 1));
209
 
        sprintf(source_bits, "%s/home", jailsrc);
210
 
        sprintf(target_bits, "%s/home", jailpath);
211
 
 
212
 
        checked_mount(source_bits, target_bits, NULL, MS_BIND, NULL);
213
 
 
214
 
        sprintf(source_bits, "%s/tmp", jailsrc);
215
 
        sprintf(target_bits, "%s/tmp", jailpath);
216
 
 
217
 
        checked_mount(source_bits, target_bits, NULL, MS_BIND, NULL);
 
184
       
 
185
        jailsrc = jail_src(jailpath);
 
186
        mountdata = die_if_null(malloc(3 + strlen(jailsrc) + 4 + strlen(jail_system) + 3 + 1));
 
187
        sprintf(mountdata, "br:%s=rw:%s=ro", jailsrc, jail_system);
 
188
        if (mount("none", jailpath, "aufs", 0, mountdata))
 
189
        {
 
190
            syslog(LOG_ERR, "could not mount %s\n", jailpath);
 
191
            perror("could not mount");
 
192
            exit(1);
 
193
        } 
218
194
 
219
195
        syslog(LOG_INFO, "mounted %s\n", jailpath);
220
196
 
221
197
        free(jailsrc);
222
 
        free(source_bits);
223
 
        free(target_bits);
 
198
        free(mountdata);
224
199
    }
225
200
 
226
201
    free(jaillib);
242
217
 
243
218
int main(int argc, char* const argv[])
244
219
{
245
 
    char* jail_base;
246
 
    char* jail_src_base;
247
 
    char* jail_system;
248
220
    char* jailpath;
249
221
    char* work_dir;
250
222
    char* prog;
288
260
        arg_num++;
289
261
    }
290
262
    uid = atoi(argv[arg_num++]);
291
 
    jail_base = argv[arg_num++];
292
 
    jail_src_base = argv[arg_num++];
293
 
    jail_system = argv[arg_num++];
294
263
    jailpath = argv[arg_num++];
295
264
    work_dir = argv[arg_num++];
296
265
    prog = argv[arg_num];
320
289
    openlog("trampoline", LOG_CONS | LOG_PID | LOG_NDELAY, LOG_USER);
321
290
 
322
291
    #ifdef IVLE_AUFS_JAILS
323
 
    mount_if_needed(jail_src_base, jail_base, jail_system, canonical_jailpath);
 
292
    mount_if_needed(canonical_jailpath);
324
293
    #endif /* IVLE_AUFS_JAILS */
325
294
 
326
295
    /* chroot into the jail.