Blame


1 15cd675b 2023-08-23 thomas /*
2 15cd675b 2023-08-23 thomas * Copyright (c) 2023 Thomas Adam <thomas@xteddy.org>
3 15cd675b 2023-08-23 thomas *
4 15cd675b 2023-08-23 thomas * Permission to use, copy, modify, and distribute this software for any
5 15cd675b 2023-08-23 thomas * purpose with or without fee is hereby granted, provided that the above
6 15cd675b 2023-08-23 thomas * copyright notice and this permission notice appear in all copies.
7 15cd675b 2023-08-23 thomas *
8 15cd675b 2023-08-23 thomas * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 15cd675b 2023-08-23 thomas * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 15cd675b 2023-08-23 thomas * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 15cd675b 2023-08-23 thomas * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 15cd675b 2023-08-23 thomas * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 15cd675b 2023-08-23 thomas * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 15cd675b 2023-08-23 thomas * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 15cd675b 2023-08-23 thomas */
16 15cd675b 2023-08-23 thomas
17 15cd675b 2023-08-23 thomas #include "got_compat.h"
18 15cd675b 2023-08-23 thomas
19 15cd675b 2023-08-23 thomas #include <stdio.h>
20 15cd675b 2023-08-23 thomas #include <unistd.h>
21 15cd675b 2023-08-23 thomas
22 15cd675b 2023-08-23 thomas #include "log.h"
23 15cd675b 2023-08-23 thomas
24 15cd675b 2023-08-23 thomas int
25 15cd675b 2023-08-23 thomas enter_chroot(const char *path)
26 15cd675b 2023-08-23 thomas {
27 15cd675b 2023-08-23 thomas log_info("chroot into %s", path);
28 15cd675b 2023-08-23 thomas if (chroot(path) == -1)
29 15cd675b 2023-08-23 thomas fatal("chroot");
30 15cd675b 2023-08-23 thomas if (chdir("/") == -1)
31 15cd675b 2023-08-23 thomas fatal("chdir(\"/\")");
32 15cd675b 2023-08-23 thomas
33 15cd675b 2023-08-23 thomas return 1;
34 15cd675b 2023-08-23 thomas }