From 516e2f5e68aa10306a346865922b35e9a1e299c2 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 1 Jun 2014 20:57:21 +0200 Subject: [PATCH] unix_msg: Lift sockaddr_un handling from unix_msg_send Signed-off-by: Volker Lendecke Reviewed-by: Jeremy Allison --- source3/lib/messages_dgm.c | 20 ++++++++------------ source3/lib/unix_msg/test_source.c | 6 +++++- source3/lib/unix_msg/tests.c | 14 +++++++------- source3/lib/unix_msg/unix_msg.c | 15 +++------------ source3/lib/unix_msg/unix_msg.h | 2 +- 5 files changed, 24 insertions(+), 33 deletions(-) diff --git a/source3/lib/messages_dgm.c b/source3/lib/messages_dgm.c index f71ec85959f..edef8892d35 100644 --- a/source3/lib/messages_dgm.c +++ b/source3/lib/messages_dgm.c @@ -300,21 +300,19 @@ static NTSTATUS messaging_dgm_send(struct server_id src, { struct messaging_dgm_context *ctx = talloc_get_type_abort( backend->private_data, struct messaging_dgm_context); - fstring pid_str; - char buf[PATH_MAX]; - char *dst_sock, *to_free; struct messaging_dgm_hdr hdr; struct iovec iov2[iovlen + 1]; - ssize_t pathlen; struct server_id_buf idbuf; + struct sockaddr_un dst; + ssize_t dst_pathlen; int ret; - fstr_sprintf(pid_str, "msg/%u", (unsigned)pid.pid); + dst = (struct sockaddr_un) { .sun_family = AF_UNIX }; - pathlen = full_path_tos(ctx->cache_dir, pid_str, buf, sizeof(buf), - &dst_sock, &to_free); - if (pathlen == -1) { - return NT_STATUS_NO_MEMORY; + dst_pathlen = snprintf(dst.sun_path, sizeof(dst.sun_path), + "%s/msg/%u", ctx->cache_dir, (unsigned)pid.pid); + if (dst_pathlen >= sizeof(dst.sun_path)) { + return NT_STATUS_NAME_TOO_LONG; } hdr.msg_version = MESSAGE_VERSION; @@ -331,11 +329,9 @@ static NTSTATUS messaging_dgm_send(struct server_id src, memcpy(iov2+1, iov, iovlen*sizeof(struct iovec)); become_root(); - ret = unix_msg_send(ctx->dgm_ctx, dst_sock, iov2, iovlen + 1); + ret = unix_msg_send(ctx->dgm_ctx, &dst, iov2, iovlen + 1); unbecome_root(); - TALLOC_FREE(to_free); - if (ret != 0) { return map_nt_error_from_unix(ret); } diff --git a/source3/lib/unix_msg/test_source.c b/source3/lib/unix_msg/test_source.c index 94984d88523..7f6a7a5e8c0 100644 --- a/source3/lib/unix_msg/test_source.c +++ b/source3/lib/unix_msg/test_source.c @@ -13,6 +13,7 @@ int main(int argc, const char *argv[]) int ret; unsigned i; unsigned num_ctxs = 1; + struct sockaddr_un dst; if (argc < 2) { fprintf(stderr, "Usage: %s [num_contexts]\n", argv[0]); @@ -57,11 +58,14 @@ int main(int argc, const char *argv[]) iov.iov_base = &i; iov.iov_len = sizeof(i); + dst = (struct sockaddr_un) { .sun_family = AF_UNIX }; + strlcpy(dst.sun_path, argv[1], sizeof(dst.sun_path)); + for (i=0; i= sizeof(dst.sun_path)) { - return ENAMETOOLONG; - } - dst = (struct sockaddr_un) { .sun_family = AF_UNIX }; - memcpy(dst.sun_path, dst_sock, dst_len); if (iovlen < 0) { return EINVAL; @@ -676,7 +667,7 @@ int unix_msg_send(struct unix_msg_ctx *ctx, const char *dst_sock, sizeof(struct iovec) * iovlen); } - return unix_dgram_send(ctx->dgram, &dst, tmp_iov, iovlen+1); + return unix_dgram_send(ctx->dgram, dst, tmp_iov, iovlen+1); } hdr.msglen = msglen; @@ -734,7 +725,7 @@ int unix_msg_send(struct unix_msg_ctx *ctx, const char *dst_sock, } sent += (fragment_len - sizeof(ctx->cookie) - sizeof(hdr)); - ret = unix_dgram_send(ctx->dgram, &dst, iov_copy, iov_index); + ret = unix_dgram_send(ctx->dgram, dst, iov_copy, iov_index); if (ret != 0) { break; } diff --git a/source3/lib/unix_msg/unix_msg.h b/source3/lib/unix_msg/unix_msg.h index bf9efe7c9e4..a712a8f1eed 100644 --- a/source3/lib/unix_msg/unix_msg.h +++ b/source3/lib/unix_msg/unix_msg.h @@ -95,7 +95,7 @@ int unix_msg_init(const struct sockaddr_un *addr, * @return 0 on success, errno on failure */ -int unix_msg_send(struct unix_msg_ctx *ctx, const char *dst_sock, +int unix_msg_send(struct unix_msg_ctx *ctx, const struct sockaddr_un *dst, const struct iovec *iov, int iovlen); /** -- 2.11.4.GIT