Ejemplo n.º 1
0
void sc_do_umount(const char *target, int flags)
{
	char buf[10000] = { 0 };
	const char *umount_cmd = NULL;

	if (sc_is_debug_enabled()) {
#ifdef SNAP_CONFINE_DEBUG_BUILD
		umount_cmd = sc_umount_cmd(buf, sizeof(buf), target, flags);
#else
		umount_cmd = use_debug_build;
#endif
		debug("performing operation: %s", umount_cmd);
	}
	if (sc_faulty("umount", NULL) || umount2(target, flags) < 0) {
		// Save errno as ensure can clobber it.
		int saved_errno = errno;

		// Drop privileges so that we can compute our nice error message
		// without risking an attack on one of the string functions there.
		sc_privs_drop();

		// Compute the equivalent umount command.
		umount_cmd = sc_umount_cmd(buf, sizeof(buf), target, flags);
		// Restore errno and die.
		errno = saved_errno;
		die("cannot perform operation: %s", umount_cmd);
	}
}
Ejemplo n.º 2
0
void sc_do_mount(const char *source, const char *target,
		 const char *fs_type, unsigned long mountflags,
		 const void *data)
{
	char buf[10000] = { 0 };
	const char *mount_cmd = NULL;

	if (sc_is_debug_enabled()) {
#ifdef SNAP_CONFINE_DEBUG_BUILD
		mount_cmd = sc_mount_cmd(buf, sizeof(buf), source,
					 target, fs_type, mountflags, data);
#else
		mount_cmd = use_debug_build;
#endif
		debug("performing operation: %s", mount_cmd);
	}
	if (sc_faulty("mount", NULL)
	    || mount(source, target, fs_type, mountflags, data) < 0) {
		// Save errno as ensure can clobber it.
		int saved_errno = errno;

		// Drop privileges so that we can compute our nice error message
		// without risking an attack on one of the string functions there.
		sc_privs_drop();

		// Compute the equivalent mount command.
		mount_cmd = sc_mount_cmd(buf, sizeof(buf), source,
					 target, fs_type, mountflags, data);
		// Restore errno and die.
		errno = saved_errno;
		die("cannot perform operation: %s", mount_cmd);
	}
}
Ejemplo n.º 3
0
static bool sc_do_mount_ex(const char *source, const char *target,
			   const char *fs_type,
			   unsigned long mountflags, const void *data,
			   bool optional)
{
	char buf[10000] = { 0 };
	const char *mount_cmd = NULL;

	if (sc_is_debug_enabled()) {
#ifdef SNAP_CONFINE_DEBUG_BUILD
		mount_cmd = sc_mount_cmd(buf, sizeof(buf), source,
					 target, fs_type, mountflags, data);
#else
		mount_cmd = use_debug_build;
#endif
		debug("performing operation: %s", mount_cmd);
	}
	if (sc_faulty("mount", NULL)
	    || mount(source, target, fs_type, mountflags, data) < 0) {
		int saved_errno = errno;
		if (optional && saved_errno == ENOENT) {
			// The special-cased value that is allowed to fail.
			return false;
		}
		// Drop privileges so that we can compute our nice error message
		// without risking an attack on one of the string functions there.
		sc_privs_drop();

		// Compute the equivalent mount command.
		mount_cmd = sc_mount_cmd(buf, sizeof(buf), source,
					 target, fs_type, mountflags, data);
		// Restore errno and die.
		errno = saved_errno;
		die("cannot perform operation: %s", mount_cmd);
	}
	return true;
}