mirror of
https://github.com/roytam1/palemoon27.git
synced 2026-05-26 14:30:27 +00:00
36b2354fd4
- Bug 1186307 - StructuredCloneHelper in workers.postMessage(), r=smaug (0d3c817afa) - Bug 1183824 - Remove NS_ENSURE_TRUE(mCallback, NS_ERROR_NOT_INITIALIZED) warning from nsFrameMessageManager::DispatchAsyncMessageInternal. r=smaug (64dfd50f7f) - Bug 1167189: Use a size annotation on the OOM abort. r=bholley (5e7fb331a0) - missing crash reporter (47f183fab4) - Bug 1137151: Marked destructor of |nsClipboard| as protected, r=mwu (5655bf8862) - Bug 1194497 - Convert a few remaining PRUnichar to char16_t. r=roc (1554ffcec2) - Bug 952456 - Part 1: Implement gonk/nsClipboard for rich text and raw image. r=fabrice (419381f7af) - Bug 1198795 - ipc/StructuredCloneUtils should be merged with StructuredCloneHelper, r=smaug (02183262bd) - Bug 1201806 - part 1 - Remove OwningSerializedStructuredCloneBuffer and use StructuredCloneIPCHelper everywhere in IPC code, r=smaug (6dc69151b4) - Bug 1201806 - part 2 - nsStructuredCloneContainer should use StructuredCloneIPCHelper, r=smaug (b6ebaa8e95) - Bug 1202028 - Implement range based for loops for SavedFrame stacks. r=terrence (57c198910c) - missing bit of Bug 1106264 (fa67f8ab56) - Bug 1168806: Configurable I/O thread for socket IPC classes, r=kmachulis (213a8fb2b9) - Bug 1159209: Remove template parameters from |DataSocketIO|, r=kmachulis (0d658c5cf8) - Bug 1168806: Configurable consumer thread for socket IPC classes, r=kmachulis (ee054dd6b0) - Bug 1167207: Add |BluetoothDaemonConnectionConsumer|, r=shuang (b8b89290df) - Bug 1154281: Remove |UnixSocketConsumer| and its helpers, r=kmachulis (d40430b10f) - Bug 1166638: Add |StreamSocketConsumer|, r=kmachulis (59b5c1abf3) - Bug 1166638: Add |ListenSocketConsumer|, r=kmachulis (d119bcaa2a) - Bug 1168806: Use 'consumer thread' in socket interface, r=kmachulis (65d232d21c) - Bug 1170466: Inherit |ConnectionOrientedSocketIO| from |UnixSocketWatcher|, r=kmachulis (b91d0c624a) - Bug 1170466: Share socket I/O methods in |ConnectionOrientedSocketIO|, r=kmachulis (108fb6696e) - Bug 1170466: Implement accept and connect in |ConnectionOrientedSocketIO|, r=kmachulis (590b3b4617) - Bug 1172479: Replace |nsIThread| by |MessageLoop| in socket I/O code, r=kmachulis (618073dcef) - Bug 1203426 - Rename StructuredCloneIPCHelper to StructuredCloneData, r=smaug (dc31124113) - Bug 1167392 - Change nsFrameMessageManager::mParentManager to a smart pointer. r=ehsan (98d60c0398) - Bug 1186843 - Always cache delayed scripts in message manager (b0ab501959) - Bug 1189550 - In parent process, cpmm.initialProcessData should be same as ppmm.initialProcessData (r=smaug) (7a8ab62432) - Bug 1196057 - Use channel->Open2() in dom/base/nsFrameMessageManager.cpp (r=sicking) (a032d483d6) - missing parts of Bug 1132072 - Tab switch refactoring (r=mconley) (e6fbbb722a) - Bug 1175736 - Implement the iframe referrer attribute. r=ckerschb, r=bz (a5fc4e683b) - Bug 1171017: Rename |BluetoothDaemonConnectionConsumer| to |DaemonSocketConsumer|, r=shuang (0af5957609) - Bug 1170993: Manage socket buffers in sub-classes of |UnixSocketBuffer|, r=kmachulis (960de8be45) - Bug 1171017: Rename |BluetoothDaemonPDUConsumer| to |DaemonSocketIOConsumer|, r=shuang (eea1681ab8) - Bug 1171100 - Fix incorrect logic of handling Bluetooth Gatt Responses in daemon backend. r=tzimmermann (c385364d1e) - Bug 1171866 - Remove ReversedUuidToString; f=tzimmermann, r=jocelyn (9b58176c39) - Bug 1171017: Rename |BluetoothSocketPDU| to |DaemonSocketPDU|, r=shuang (ce1bbd9d4a) - Bug 1171017: Rename |BluetoothDaemonConnectionIO| to |DaemonSocketIO|, r=shuang (00f2a38220) - Bug 1171017: Rename |BluetoothDaemonConnection| to |DaemonSocket|, r=shuang (b3c3522719) - Bug 1171017: Move classes from ipc/bluetooth to ipc/hal, r=shuang (047714aee4) - Bug 1171994: Add |RilSocket| and |RilSocketConsumer|, r=htsai (276211bbb7) - Bug 1171994: Forward received RIL socket I/O via |WorkerCrossThreadDispatcher|, r=htsai (7825d1c837) - Bug 1185478: Add leak checks to socket I/O classes (40e2c01ce4) - Bug 1185478: Remove strong references from socket I/O class to socket classes (6fa94f34ff) - Bug 1163912: Set |Type| property of BluetoothDevice a initial value during LeScan; f=elin, r=jocelyn (bda66689ed) - Bug 1166215 - Cast 'BluetoothTypeOfDevice' to uint32_t before the BT signal is distributed to BluetoothAdapter. r=joliu (d38ad4e55f) - Bug 1170086 - Fix the parameter type of DispatchReplyError() in StartLeScan result handler. r=joliu (a24e23e02f) - Bug 1161956 - Fix crashes while using GATT client functions. r=jocelyn (cebfb8c700) - Bug 1171868 - Remove GeneratePathFromGattId(aId, aPath, aUuidStr); r=jocelyn (0eac291b3c) - Bug 1161945 - Fix empty characteristics and descriptors after searching services. f=elin, r=jocelyn (a0d816fee4) - Bug 1164387 - Use |btgatt_client_interface_t.get_device_type| to get the device type. r=jocelyn (c7b5c97a00) - Bug 1173139 - Reorder global creation on workers, r=khuey. (acb79ae54e) - Bug 1170071 - Part 1: Revise BluetoothGattInterface, result handler, and interface helper for daemon support of gatt server. r=shuang (0ad0c9244e) - Bug 1170071 - Part 2: Add helpers for Bluetooth daemon GATT server support. r=shuang (46a4062579) - Bug 1170071 - Part 3: Add gatt server support to GATT module for Bluetooth daemon. r=shuang (71d80aabea) - Bug 1170071 - Part 4: Add Gatt server interfaces for Bluetooth daemon. r=shuang (a556aaf048) - Bug 1187230: Convert Bluetooth to use daemon runnables, r=shuang (9be6501225) - Bug 1204382: Add #include for nsIInputStream.h to MediaParent.cpp, to fix a build error in --disable-webrtc builds. r=jib (8b20e934)
240 lines
5.8 KiB
C++
240 lines
5.8 KiB
C++
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
/* vim: set sw=2 ts=2 et ft=cpp: tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
#include "KeyStoreConnector.h"
|
|
#include <fcntl.h>
|
|
#include <pwd.h>
|
|
#include <sys/stat.h>
|
|
#include <sys/un.h>
|
|
#include "nsISupportsImpl.h" // for MOZ_COUNT_CTOR, MOZ_COUNT_DTOR
|
|
#include "nsThreadUtils.h" // For NS_IsMainThread.
|
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
#include <android/log.h>
|
|
#define KEYSTORE_LOG(args...) __android_log_print(ANDROID_LOG_INFO, "Gonk", args)
|
|
#else
|
|
#define KEYSTORE_LOG(args...) printf(args);
|
|
#endif
|
|
|
|
namespace mozilla {
|
|
namespace ipc {
|
|
|
|
static const char KEYSTORE_SOCKET_PATH[] = "/dev/socket/keystore";
|
|
|
|
KeyStoreConnector::KeyStoreConnector(const char** const aAllowedUsers)
|
|
: mAllowedUsers(aAllowedUsers)
|
|
{
|
|
MOZ_COUNT_CTOR_INHERITED(KeyStoreConnector, UnixSocketConnector);
|
|
}
|
|
|
|
KeyStoreConnector::~KeyStoreConnector()
|
|
{
|
|
MOZ_COUNT_DTOR_INHERITED(KeyStoreConnector, UnixSocketConnector);
|
|
}
|
|
|
|
nsresult
|
|
KeyStoreConnector::CreateSocket(int& aFd) const
|
|
{
|
|
unlink(KEYSTORE_SOCKET_PATH);
|
|
|
|
aFd = socket(AF_LOCAL, SOCK_STREAM, 0);
|
|
if (aFd < 0) {
|
|
KEYSTORE_LOG("Could not open KeyStore socket!");
|
|
return NS_ERROR_FAILURE;
|
|
}
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
nsresult
|
|
KeyStoreConnector::SetSocketFlags(int aFd) const
|
|
{
|
|
static const int sReuseAddress = 1;
|
|
|
|
// Set close-on-exec bit.
|
|
int flags = TEMP_FAILURE_RETRY(fcntl(aFd, F_GETFD));
|
|
if (flags < 0) {
|
|
return NS_ERROR_FAILURE;
|
|
}
|
|
flags |= FD_CLOEXEC;
|
|
int res = TEMP_FAILURE_RETRY(fcntl(aFd, F_SETFD, flags));
|
|
if (res < 0) {
|
|
return NS_ERROR_FAILURE;
|
|
}
|
|
|
|
// Set non-blocking status flag.
|
|
flags = TEMP_FAILURE_RETRY(fcntl(aFd, F_GETFL));
|
|
if (flags < 0) {
|
|
return NS_ERROR_FAILURE;
|
|
}
|
|
flags |= O_NONBLOCK;
|
|
res = TEMP_FAILURE_RETRY(fcntl(aFd, F_SETFL, flags));
|
|
if (res < 0) {
|
|
return NS_ERROR_FAILURE;
|
|
}
|
|
|
|
// Set socket addr to be reused even if kernel is still waiting to close.
|
|
res = setsockopt(aFd, SOL_SOCKET, SO_REUSEADDR, &sReuseAddress,
|
|
sizeof(sReuseAddress));
|
|
if (res < 0) {
|
|
return NS_ERROR_FAILURE;
|
|
}
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
nsresult
|
|
KeyStoreConnector::CheckPermission(int aFd) const
|
|
{
|
|
struct ucred userCred;
|
|
socklen_t len = sizeof(userCred);
|
|
|
|
if (getsockopt(aFd, SOL_SOCKET, SO_PEERCRED, &userCred, &len)) {
|
|
return NS_ERROR_FAILURE;
|
|
}
|
|
|
|
const struct passwd* userInfo = getpwuid(userCred.uid);
|
|
if (!userInfo) {
|
|
return NS_ERROR_FAILURE;
|
|
}
|
|
|
|
if (!mAllowedUsers) {
|
|
return NS_ERROR_FAILURE;
|
|
}
|
|
|
|
for (const char** user = mAllowedUsers; *user; ++user) {
|
|
if (!strcmp(*user, userInfo->pw_name)) {
|
|
return NS_OK;
|
|
}
|
|
}
|
|
|
|
return NS_ERROR_FAILURE;
|
|
}
|
|
|
|
nsresult
|
|
KeyStoreConnector::CreateAddress(struct sockaddr& aAddress,
|
|
socklen_t& aAddressLength) const
|
|
{
|
|
struct sockaddr_un* address =
|
|
reinterpret_cast<struct sockaddr_un*>(&aAddress);
|
|
|
|
size_t namesiz = strlen(KEYSTORE_SOCKET_PATH) + 1; // include trailing '\0'
|
|
|
|
if (namesiz > sizeof(address->sun_path)) {
|
|
KEYSTORE_LOG("Address too long for socket struct!");
|
|
return NS_ERROR_FAILURE;
|
|
}
|
|
|
|
address->sun_family = AF_UNIX;
|
|
memcpy(address->sun_path, KEYSTORE_SOCKET_PATH, namesiz);
|
|
|
|
aAddressLength = offsetof(struct sockaddr_un, sun_path) + namesiz;
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
// |UnixSocketConnector|
|
|
|
|
nsresult
|
|
KeyStoreConnector::ConvertAddressToString(const struct sockaddr& aAddress,
|
|
socklen_t aAddressLength,
|
|
nsACString& aAddressString)
|
|
{
|
|
MOZ_ASSERT(aAddress.sa_family == AF_UNIX);
|
|
|
|
const struct sockaddr_un* un =
|
|
reinterpret_cast<const struct sockaddr_un*>(&aAddress);
|
|
|
|
size_t len = aAddressLength - offsetof(struct sockaddr_un, sun_path);
|
|
|
|
aAddressString.Assign(un->sun_path, len);
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
nsresult
|
|
KeyStoreConnector::CreateListenSocket(struct sockaddr* aAddress,
|
|
socklen_t* aAddressLength,
|
|
int& aListenFd)
|
|
{
|
|
ScopedClose fd;
|
|
|
|
nsresult rv = CreateSocket(fd.rwget());
|
|
if (NS_FAILED(rv)) {
|
|
return rv;
|
|
}
|
|
rv = SetSocketFlags(fd);
|
|
if (NS_FAILED(rv)) {
|
|
return rv;
|
|
}
|
|
if (aAddress && aAddressLength) {
|
|
rv = CreateAddress(*aAddress, *aAddressLength);
|
|
if (NS_FAILED(rv)) {
|
|
return rv;
|
|
}
|
|
}
|
|
|
|
// Allow access for wpa_supplicant (different user, different group)
|
|
//
|
|
// TODO: Improve this by setting specific user/group for
|
|
// wpa_supplicant by calling |fchmod| and |fchown|.
|
|
//
|
|
chmod(KEYSTORE_SOCKET_PATH, S_IRUSR|S_IWUSR|
|
|
S_IRGRP|S_IWGRP|
|
|
S_IROTH|S_IWOTH);
|
|
|
|
aListenFd = fd.forget();
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
nsresult
|
|
KeyStoreConnector::AcceptStreamSocket(int aListenFd,
|
|
struct sockaddr* aAddress,
|
|
socklen_t* aAddressLength,
|
|
int& aStreamFd)
|
|
{
|
|
ScopedClose fd(
|
|
TEMP_FAILURE_RETRY(accept(aListenFd, aAddress, aAddressLength)));
|
|
if (fd < 0) {
|
|
NS_WARNING("Cannot accept file descriptor!");
|
|
return NS_ERROR_FAILURE;
|
|
}
|
|
nsresult rv = SetSocketFlags(fd);
|
|
if (NS_FAILED(rv)) {
|
|
return rv;
|
|
}
|
|
rv = CheckPermission(fd);
|
|
if (NS_FAILED(rv)) {
|
|
return rv;
|
|
}
|
|
|
|
aStreamFd = fd.forget();
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
nsresult
|
|
KeyStoreConnector::CreateStreamSocket(struct sockaddr* aAddress,
|
|
socklen_t* aAddressLength,
|
|
int& aStreamFd)
|
|
{
|
|
MOZ_CRASH("|KeyStoreConnector| does not support creating stream sockets.");
|
|
return NS_ERROR_FAILURE;
|
|
}
|
|
|
|
nsresult
|
|
KeyStoreConnector::Duplicate(UnixSocketConnector*& aConnector)
|
|
{
|
|
aConnector = new KeyStoreConnector(*this);
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
}
|
|
}
|