/***
This file is part of systemd.
Copyright 2013 Lennart Poettering
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <fcntl.h>
#include <unistd.h>
#include "bus-container.h"
#include "bus-internal.h"
#include "bus-socket.h"
#include "fd-util.h"
#include "process-util.h"
#include "util.h"
int r, error_buf = 0;
ssize_t n;
assert(b);
if (b->nspid <= 0) {
if (r < 0)
return r;
}
if (r < 0)
return r;
if (b->input_fd < 0)
return -errno;
bus_socket_setup(b);
return -errno;
if (child < 0)
return -errno;
if (child == 0) {
if (r < 0)
/* We just changed PID namespace, however it will only
* take effect on the children we now fork. Hence,
* let's fork another time, and connect from this
* grandchild, so that SO_PEERCRED of our connection
* comes from a process from within the container, and
* not outside of it */
grandchild = fork();
if (grandchild < 0)
if (grandchild == 0) {
if (r < 0) {
/* Try to send error up */
}
}
if (r < 0)
}
if (r < 0)
return r;
if (n < 0)
return -errno;
if (n > 0) {
if (n != sizeof(error_buf))
return -EIO;
if (error_buf < 0)
return -EIO;
if (error_buf == EINPROGRESS)
return 1;
if (error_buf > 0)
return -error_buf;
}
return -EIO;
return -EIO;
return bus_socket_start_auth(b);
}
union {
} control = {};
int error_buf = 0;
};
.msg_control = &control,
.msg_controllen = sizeof(control),
.msg_iovlen = 1,
};
ssize_t n;
assert(b);
if (b->nspid <= 0) {
if (r < 0)
return r;
}
if (r < 0)
return r;
return -errno;
if (child < 0)
return -errno;
if (child == 0) {
if (r < 0)
/* We just changed PID namespace, however it will only
* take effect on the children we now fork. Hence,
* let's fork another time, and connect from this
* grandchild, so that kdbus only sees the credentials
* of this process which comes from within the
* container, and not outside of it */
grandchild = fork();
if (grandchild < 0)
if (grandchild == 0) {
if (fd < 0) {
/* Try to send error up */
}
if (r < 0)
}
if (r < 0)
}
if (r < 0)
return r;
if (n < 0)
return -errno;
int *fds;
unsigned n_fds;
if (n_fds != 1) {
return -EIO;
}
}
}
/* If there's an fd passed, we are good. */
if (fd >= 0) {
return bus_kernel_take_fd(b);
}
/* If there's an error passed, use it */
return -error_buf;
/* Otherwise, we have no clue */
return -EIO;
}