MCPcopy Create free account
hub / github.com/acl-dev/acl / acl_chroot_uid

Function acl_chroot_uid

lib_acl/src/stdlib/sys/unix/acl_chroot_uid.c:27–91  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

25/* chroot_uid - restrict the damage that this program can do */
26
27int acl_chroot_uid(const char *root_dir, const char *user_name)
28{
29 struct passwd *pwd;
30 uid_t uid = 0;
31 gid_t gid;
32 int err = 0;
33
34 /*
35 * Look up the uid/gid before entering the jail, and save them so they
36 * can't be clobbered. Set up the primary and secondary groups.
37 */
38 if (user_name != 0) {
39 if ((pwd = getpwnam(user_name)) == 0) {
40 acl_msg_error("unknown user: %s", user_name);
41 return -1;
42 }
43
44 uid = pwd->pw_uid;
45 gid = pwd->pw_gid;
46 if (setgid(gid) < 0) {
47 acl_msg_error("setgid(%ld): %s", (long) gid,
48 acl_last_serror());
49 err++;
50 }
51 if (initgroups(user_name, gid) < 0) {
52 acl_msg_error("initgroups: %s", acl_last_serror());
53 err++;
54 }
55 }
56
57 /*
58 * Enter the jail.
59 */
60 if (root_dir) {
61 if (chroot(root_dir)) {
62 acl_msg_error("chroot(%s): %s",
63 root_dir, acl_last_serror());
64 err++;
65 } else if (chdir("/")) {
66 acl_msg_error("chdir(/): %s", acl_last_serror());
67 err++;
68 }
69 }
70
71 /*
72 * Drop the user privileges.
73 */
74 if (user_name != 0) {
75 if (setuid(uid) < 0) {
76 acl_msg_error("setuid(%ld): %s",
77 (long) uid, acl_last_serror());
78 err++;
79 }
80 }
81
82 /*
83 * Give the desperate developer a clue of what is happening.
84 */

Callers 10

acl_fiber_server_mainFunction · 0.85
acl_fiber_server_mainFunction · 0.85
fiber_mainFunction · 0.85
mainFunction · 0.85
server_mainFunction · 0.85
acl_udp_server_mainFunction · 0.85
acl_trigger_server_mainFunction · 0.85
acl_single_server_mainFunction · 0.85
start_childFunction · 0.85

Calls 3

acl_msg_errorFunction · 0.85
acl_last_serrorFunction · 0.85
acl_msg_infoFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…