freebsd-ports/japanese/mozc-server/files/patch-ipc_unix_ipc.cc
Hiroki Sato 8a7acbced9 - Add Japan Post zip code dictionary.
- Add LICENSE.
 - Fix malformed BUILD_DEPENDS and remove unnecessary dependencies.
   Use USE_* in a consistent manner.
 - Fix inconsistency toolchain usage in build_tools and the others.
   Hardcoded g++ was always used only for the former even if both gcc
   and clang were available.
 - Enable -Werror.
 - Fix SSP issue on i386 platform.
 - Let cpp(1) to replace LOCALBASE instead of patching and sed(1).
 - Use GYP_DEFINES for build variables instead of patching.
 - Separate the stages of configuration and build from each other.
 - Add options for localbase and openssl-related configuration to gyp
   instead of patching.
 - Fix makesum target.
 - Fix whitespaces to make portlint happy.
 - Disable serialization for linking.  It is not needed.
 - Remove hardcoded mozc.xml.
 - Respect DISABLE_MAKE_JOBS=yes.  Do not calculate the factor using the
   number of CPUs.
 - Remove a confusing message after pkg-message.
 - Rename a deprecated function (inactivate-current-input-method-function)
   in mozc.el in a compatible fashion with the older emacsen [1].
 - Add leim-list.el for registration of mozc-mode via LEIM API.
   "(require 'mozc)" is no longer needed.
 - Fix a build problem when binutils is installed and ${LOCALBASE}/bin
   comes first in $PATH [2].

Submitted by:	Tadaaki Nagao [1]
Reported by:	Kenichi Niioka [2]
PR:		ports/178250
Approved by:	maintainer timeout (2 weeks)
2013-05-14 19:46:20 +00:00

89 lines
2.9 KiB
C++

--- ipc/unix_ipc.cc.orig 2013-03-29 13:33:26.000000000 +0900
+++ ipc/unix_ipc.cc 2013-04-27 15:23:08.000000000 +0900
@@ -41,6 +41,9 @@
#include <sys/time.h>
#include <sys/types.h>
#include <sys/un.h>
+#if defined(OS_MACOSX) || defined(OS_FREEBSD)
+#include <sys/ucred.h>
+#endif
#include <sys/wait.h>
#include <unistd.h>
@@ -123,6 +126,29 @@
bool IsPeerValid(int socket, pid_t *pid) {
*pid = 0;
+#if defined(OS_MACOSX) || defined(OS_FREEBSD)
+ // If the OS is MAC, we should validate the peer by using LOCAL_PEERCRED.
+ struct xucred peer_cred;
+ socklen_t peer_cred_len = sizeof(struct xucred);
+ if (::getsockopt(socket, 0, LOCAL_PEERCRED,
+ &peer_cred, &peer_cred_len) < 0) {
+ LOG(ERROR) << "cannot get peer credential. NOT a Unix socket?";
+ return false;
+ }
+ if (peer_cred.cr_version != XUCRED_VERSION) {
+ LOG(WARNING) << "credential version mismatch.";
+ return false;
+ }
+ if (peer_cred.cr_uid != ::geteuid()) {
+ LOG(WARNING) << "uid mismatch." << peer_cred.cr_uid << "!=" << ::geteuid();
+ return false;
+ }
+
+ // MacOS doesn't have cr_pid;
+ *pid = 0;
+#endif
+
+#if defined(OS_LINUX) && !defined(OS_FREEBSD)
// On ARM Linux, we do nothing and just return true since the platform
// sometimes doesn't support the getsockopt(sock, SOL_SOCKET, SO_PEERCRED)
// system call.
@@ -144,6 +170,7 @@
*pid = peer_cred.pid;
#endif // __arm__
+#endif
return true;
}
@@ -278,7 +305,12 @@
address.sun_family = AF_UNIX;
::memcpy(address.sun_path, server_address.data(), server_address_length);
address.sun_path[server_address_length] = '\0';
+#if defined(OS_MACOSX) || defined(OS_FREEBSD)
+ address.sun_len = SUN_LEN(&address);
+ const size_t sun_len = sizeof(address);
+#else
const size_t sun_len = sizeof(address.sun_family) + server_address_length;
+#endif
pid_t pid = 0;
if (::connect(socket_,
reinterpret_cast<const sockaddr*>(&address),
@@ -398,16 +430,21 @@
SO_REUSEADDR,
reinterpret_cast<char *>(&on),
sizeof(on));
+#if defined(OS_MACOSX) || defined(OS_FREEBSD)
+ addr.sun_len = SUN_LEN(&addr);
+ const size_t sun_len = sizeof(addr);
+#else
const size_t sun_len = sizeof(addr.sun_family) + server_address_.size();
- if (!IsAbstractSocket(server_address_)) {
- // Linux does not use files for IPC.
- ::chmod(server_address_.c_str(), 0600);
- }
+#endif
if (::bind(socket_, reinterpret_cast<sockaddr *>(&addr), sun_len) != 0) {
// The UNIX domain socket file (server_address_) already exists?
LOG(FATAL) << "bind() failed: " << strerror(errno);
return;
}
+ if (!IsAbstractSocket(server_address_)) {
+ // Linux does not use files for IPC.
+ ::chmod(server_address_.c_str(), 0600);
+ }
if (::listen(socket_, num_connections) < 0) {
LOG(FATAL) << "listen() failed: " << strerror(errno);