summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2018-12-23 14:25:56 +0100
committerThomas Haller <thaller@redhat.com>2019-01-09 16:46:41 +0100
commite5fb1dd6e7fff3827eca0ec79e890b21ed96284d (patch)
treea0088274d92a6a8ead0c5e1e1c8f86bccd85021e
parentfce3243f12e3dd1714f6c207dd37967936bf5485 (diff)
downloadNetworkManager-e5fb1dd6e7fff3827eca0ec79e890b21ed96284d.tar.gz
netlink: track ucred via a boolean field in struct nl_msg
Also, accept NULL in nlmsg_set_creds() to clear the set credentials.
-rw-r--r--src/platform/nm-linux-platform.c3
-rw-r--r--src/platform/nm-netlink.c16
2 files changed, 9 insertions, 10 deletions
diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c
index 979e6a6eaa..d9af54c2c3 100644
--- a/src/platform/nm-linux-platform.c
+++ b/src/platform/nm-linux-platform.c
@@ -7422,8 +7422,7 @@ continue_reading:
_LOGt ("netlink: recvmsg: new message %s",
nl_nlmsghdr_to_str (hdr, buf_nlmsghdr, sizeof (buf_nlmsghdr)));
- if (creds)
- nlmsg_set_creds (msg, creds);
+ nlmsg_set_creds (msg, creds);
if (hdr->nlmsg_flags & NLM_F_MULTI)
multipart = TRUE;
diff --git a/src/platform/nm-netlink.c b/src/platform/nm-netlink.c
index 806f05b95b..a4feee0564 100644
--- a/src/platform/nm-netlink.c
+++ b/src/platform/nm-netlink.c
@@ -44,16 +44,14 @@
#define NETLINK_EXT_ACK 11
#endif
-#define NL_MSG_CRED_PRESENT 1
-
struct nl_msg {
int nm_protocol;
- int nm_flags;
struct sockaddr_nl nm_src;
struct sockaddr_nl nm_dst;
struct ucred nm_creds;
struct nlmsghdr * nm_nlh;
size_t nm_size;
+ bool nm_creds_has:1;
};
struct nl_sock {
@@ -610,7 +608,7 @@ nlmsg_set_src (struct nl_msg *msg, struct sockaddr_nl *addr)
struct ucred *
nlmsg_get_creds (struct nl_msg *msg)
{
- if (msg->nm_flags & NL_MSG_CRED_PRESENT)
+ if (msg->nm_creds_has)
return &msg->nm_creds;
return NULL;
}
@@ -618,8 +616,11 @@ nlmsg_get_creds (struct nl_msg *msg)
void
nlmsg_set_creds (struct nl_msg *msg, struct ucred *creds)
{
- memcpy (&msg->nm_creds, creds, sizeof (*creds));
- msg->nm_flags |= NL_MSG_CRED_PRESENT;
+ if (creds) {
+ memcpy (&msg->nm_creds, creds, sizeof (*creds));
+ msg->nm_creds_has = TRUE;
+ } else
+ msg->nm_creds_has = FALSE;
}
/*****************************************************************************/
@@ -1098,8 +1099,7 @@ continue_reading:
nlmsg_set_proto (msg, sk->s_proto);
nlmsg_set_src (msg, &nla);
- if (creds)
- nlmsg_set_creds (msg, creds);
+ nlmsg_set_creds (msg, creds);
nrecv++;