socket-util: introduce type-safe, dereferencing wrapper CMSG_FIND_DATA around cmsg_find()

let's take this once step further, and add type-safety to cmsg_find(),
and imply the CMSG_DATA() macro for finding the cmsg payload.
This commit is contained in:
Lennart Poettering
2020-04-23 19:41:15 +02:00
parent dac556fa7b
commit 371d72e05b
6 changed files with 23 additions and 51 deletions
+2 -5
View File
@@ -940,15 +940,12 @@ int ask_password_agent(
continue;
}
if (msghdr.msg_controllen < CMSG_LEN(sizeof(struct ucred)) ||
control.cmsghdr.cmsg_level != SOL_SOCKET ||
control.cmsghdr.cmsg_type != SCM_CREDENTIALS ||
control.cmsghdr.cmsg_len != CMSG_LEN(sizeof(struct ucred))) {
ucred = CMSG_FIND_DATA(&msghdr, SOL_SOCKET, SCM_CREDENTIALS, struct ucred);
if (!ucred) {
log_debug("Received message without credentials. Ignoring.");
continue;
}
ucred = (struct ucred*) CMSG_DATA(&control.cmsghdr);
if (ucred->uid != 0) {
log_debug("Got request from unprivileged user. Ignoring.");
continue;