Beispiel #1
0
static bool complete_dbus_request(DBusMessage *message,
		int *sv, struct ucred *rcred, struct ucred *vcred)
{
	char buf[1];

	if (!dbus_connection_send(server_conn, message, NULL)) {
		nih_error("%s: failed to send dbus message", __func__);
		dbus_message_unref(message);
		return false;
	}
	dbus_connection_flush(server_conn);
	dbus_message_unref(message);

	if (proxyrecv(sv[0], buf, 1) != 1) {
		nih_error("%s: Error getting reply from server over socketpair",
			  __func__);
		return false;
	}
	if (send_creds(sv[0], rcred)) {
		nih_error("%s: Error sending pid over SCM_CREDENTIAL",
			__func__);
		return false;
	}

	if (!vcred) // this request only requires one scm_credential
		return true;

	if (proxyrecv(sv[0], buf, 1) != 1) {
		nih_error("%s: Error getting reply from server over socketpair",
			__func__);
		return false;
	}
	if (send_creds(sv[0], vcred)) {
		nih_error("%s: Error sending pid over SCM_CREDENTIAL",
			__func__);
		return false;
	}

	return true;
}
Beispiel #2
0
static int do_chown_cgroup(const char *controller, const char *cgroup_path,
		uid_t newuid)
{
	int sv[2] = {-1, -1}, optval = 1, ret = -1;
	char buf[1];
	struct pollfd fds;

	if (socketpair(AF_UNIX, SOCK_DGRAM, 0, sv) < 0) {
		SYSERROR("Error creating socketpair");
		goto out;
	}
	if (setsockopt(sv[1], SOL_SOCKET, SO_PASSCRED, &optval, sizeof(optval)) == -1) {
		SYSERROR("setsockopt failed");
		goto out;
	}
	if (setsockopt(sv[0], SOL_SOCKET, SO_PASSCRED, &optval, sizeof(optval)) == -1) {
		SYSERROR("setsockopt failed");
		goto out;
	}
	if ( cgmanager_chown_scm_sync(NULL, cgroup_manager, controller,
				       cgroup_path, sv[1]) != 0) {
		NihError *nerr;
		nerr = nih_error_get();
		ERROR("call to cgmanager_chown_scm_sync failed: %s", nerr->message);
		nih_free(nerr);
		goto out;
	}
	/* now send credentials */

	fds.fd = sv[0];
	fds.events = POLLIN;
	fds.revents = 0;
	if (poll(&fds, 1, -1) <= 0) {
		ERROR("Error getting go-ahead from server: %s", strerror(errno));
		goto out;
	}
	if (read(sv[0], &buf, 1) != 1) {
		ERROR("Error getting reply from server over socketpair");
		goto out;
	}
	if (send_creds(sv[0], getpid(), getuid(), getgid())) {
		SYSERROR("%s: Error sending pid over SCM_CREDENTIAL", __func__);
		goto out;
	}
	fds.fd = sv[0];
	fds.events = POLLIN;
	fds.revents = 0;
	if (poll(&fds, 1, -1) <= 0) {
		ERROR("Error getting go-ahead from server: %s", strerror(errno));
		goto out;
	}
	if (read(sv[0], &buf, 1) != 1) {
		ERROR("Error getting reply from server over socketpair");
		goto out;
	}
	if (send_creds(sv[0], getpid(), newuid, 0)) {
		SYSERROR("%s: Error sending pid over SCM_CREDENTIAL", __func__);
		goto out;
	}
	fds.fd = sv[0];
	fds.events = POLLIN;
	fds.revents = 0;
	if (poll(&fds, 1, -1) <= 0) {
		ERROR("Error getting go-ahead from server: %s", strerror(errno));
		goto out;
	}
	ret = read(sv[0], buf, 1);
out:
	close(sv[0]);
	close(sv[1]);
	if (ret == 1 && *buf == '1')
		return 0;
	return -1;
}
int handle_update(char *msg) {
	return send_creds(UPDATE, msg);
}
int handle_add(char *msg) {
	return send_creds(ADD, msg);
}