2 * "$Id: cups-exec.c 9931 2011-08-29 20:12:39Z mike $"
4 * Sandbox helper for CUPS.
6 * Copyright 2007-2011 by Apple Inc.
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/".
16 * cups-exec /path/to/profile /path/to/program argv0 argv1 ... argvN
20 * main() - Apply sandbox profile and execute program.
24 * Include necessary headers...
27 #include <cups/string-private.h>
31 # ifndef SANDBOX_NAMED_EXTERNAL
32 # define SANDBOX_NAMED_EXTERNAL 0x0003
33 # endif /* !SANDBOX_NAMED_EXTERNAL */
34 #endif /* HAVE_SANDBOX_H */
38 * 'main()' - Apply sandbox profile and execute program.
41 int /* O - Exit status */
42 main(int argc, /* I - Number of command-line args */
43 char *argv[]) /* I - Command-line arguments */
45 int i; /* Looping var */
47 char *sandbox_error = NULL; /* Sandbox error, if any */
48 #endif /* HAVE_SANDBOX_H */
52 * Check that we have enough arguments...
57 puts("Usage: cups-exec /path/to/profile /path/to/program argv0 argv1 ... "
64 * Run in a separate security profile...
67 if (strcmp(argv[1], "none") &&
68 sandbox_init(argv[1], SANDBOX_NAMED_EXTERNAL, &sandbox_error))
70 fprintf(stderr, "DEBUG: sandbox_init failed: %s (%s)\n", sandbox_error,
72 sandbox_free_error(sandbox_error);
75 #endif /* HAVE_SANDBOX_H */
78 * Close file descriptors we don't need (insurance):
88 for (i = 5; i < 1024; i ++)
92 * Execute the program...
95 execv(argv[2], argv + 3);
98 * If we get here, execv() failed...
101 fprintf(stderr, "DEBUG: execv failed: %s\n", strerror(errno));
107 * End of "$Id: cups-exec.c 9931 2011-08-29 20:12:39Z mike $".