Skip to content

Commit

Permalink
lib: Add restrict_access_get/set_dumpable
Browse files Browse the repository at this point in the history
  • Loading branch information
cmouse authored and villesavolainen committed Feb 12, 2018
1 parent 89366c3 commit 25fcd84
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
24 changes: 20 additions & 4 deletions src/lib/restrict-access.c
Expand Up @@ -477,14 +477,30 @@ const char *restrict_access_get_current_chroot(void)
return chroot_dir;
}

void restrict_access_allow_coredumps(bool allow ATTR_UNUSED)
void restrict_access_set_dumpable(bool allow ATTR_UNUSED)
{
#ifdef HAVE_PR_SET_DUMPABLE
if (prctl(PR_SET_DUMPABLE, allow ? 1 : 0, 0, 0, 0) < 0)
i_error("prctl(PR_SET_DUMPABLE) failed: %m");
#endif
}

bool restrict_access_get_dumpable(void)
{
#ifdef HAVE_PR_SET_DUMPABLE
bool allow = FALSE;
if (prctl(PR_GET_DUMPABLE, &allow, 0, 0, 0) < 0)
i_error("prctl(PR_GET_DUMPABLE) failed: %m");
return allow;
#endif
return TRUE;
}

void restrict_access_allow_coredumps(bool allow)
{
if (getenv("PR_SET_DUMPABLE") != NULL) {
if (prctl(PR_SET_DUMPABLE, allow ? 1 : 0, 0, 0, 0) < 0)
i_error("prctl(PR_SET_DUMPABLE) failed: %m");
restrict_access_set_dumpable(allow);
}
#endif
}

int restrict_access_use_priv_gid(void)
Expand Down
9 changes: 9 additions & 0 deletions src/lib/restrict-access.h
Expand Up @@ -57,6 +57,15 @@ const char *restrict_access_get_current_chroot(void);
*/
void restrict_access_allow_coredumps(bool allow);

/* Sets process dumpable true or false. Setting this true allows core dumping,
reading /proc/self/io, attaching with PTRACE_ATTACH, and also changes
ownership of /proc/[pid] directory. */
void restrict_access_set_dumpable(bool allow);

/* Gets process dumpability, returns TRUE if not supported, because
we then assume that constraint is not present. */
bool restrict_access_get_dumpable(void);

/* If privileged_gid was set, these functions can be used to temporarily
gain access to the group. */
int restrict_access_use_priv_gid(void);
Expand Down

0 comments on commit 25fcd84

Please sign in to comment.