]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * "$Id$" | |
3 | * | |
4 | * Sandbox helper for CUPS. | |
5 | * | |
6 | * Copyright 2007-2010 by Apple Inc. | |
7 | * | |
8 | * These coded instructions, statements, and computer programs are the | |
9 | * property of Apple Inc. and are protected by Federal copyright | |
10 | * law. Distribution and use rights are outlined in the file "LICENSE.txt" | |
11 | * which should have been included with this file. If this file is | |
12 | * file is missing or damaged, see the license at "http://www.cups.org/". | |
13 | * | |
14 | * Usage: | |
15 | * | |
16 | * cups-exec /path/to/profile /path/to/program argv0 argv1 ... argvN | |
17 | * | |
18 | * Contents: | |
19 | * | |
20 | * main() - Apply sandbox profile and execute program. | |
21 | */ | |
22 | ||
23 | /* | |
24 | * Include necessary headers... | |
25 | */ | |
26 | ||
27 | #include <cups/string-private.h> | |
28 | #include <unistd.h> | |
29 | #ifdef HAVE_SANDBOX_H | |
30 | # define __APPLE_API_PRIVATE | |
31 | # include <sandbox.h> | |
32 | #endif /* HAVE_SANDBOX_H */ | |
33 | ||
34 | ||
35 | /* | |
36 | * 'main()' - Apply sandbox profile and execute program. | |
37 | */ | |
38 | ||
39 | int /* O - Exit status */ | |
40 | main(int argc, /* I - Number of command-line args */ | |
41 | char *argv[]) /* I - Command-line arguments */ | |
42 | { | |
43 | #ifdef HAVE_SANDBOX_H | |
44 | char *sandbox_error = NULL; /* Sandbox error, if any */ | |
45 | #endif /* HAVE_SANDBOX_H */ | |
46 | ||
47 | ||
48 | /* | |
49 | * Check that we have enough arguments... | |
50 | */ | |
51 | ||
52 | if (argc < 4) | |
53 | { | |
54 | puts("Usage: cups-exec /path/to/profile /path/to/program argv0 argv1 ... " | |
55 | "argvN"); | |
56 | return (1); | |
57 | } | |
58 | ||
59 | #ifdef HAVE_SANDBOX_H | |
60 | /* | |
61 | * Run in a separate security profile... | |
62 | */ | |
63 | ||
64 | if (sandbox_init(argv[1], SANDBOX_NAMED_EXTERNAL, &sandbox_error)) | |
65 | { | |
66 | fprintf(stderr, "DEBUG: sandbox_init failed: %s (%s)\n", sandbox_error, | |
67 | strerror(errno)); | |
68 | sandbox_free_error(sandbox_error); | |
69 | return (1); | |
70 | } | |
71 | #endif /* HAVE_SANDBOX_H */ | |
72 | ||
73 | /* | |
74 | * Execute the program... | |
75 | */ | |
76 | ||
77 | execv(argv[2], argv + 3); | |
78 | ||
79 | /* | |
80 | * If we get here, execv() failed... | |
81 | */ | |
82 | ||
83 | fprintf(stderr, "DEBUG: execv failed: %s\n", strerror(errno)); | |
84 | return (1); | |
85 | } | |
86 | ||
87 | ||
88 | /* | |
89 | * End of "$Id$". | |
90 | */ |