| OLD | NEW |
| (Empty) |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef IPC_UNIX_DOMAIN_SOCKET_UTIL_H_ | |
| 6 #define IPC_UNIX_DOMAIN_SOCKET_UTIL_H_ | |
| 7 | |
| 8 #include <stddef.h> | |
| 9 #include <sys/types.h> | |
| 10 | |
| 11 #include "ipc/ipc_export.h" | |
| 12 | |
| 13 namespace base { | |
| 14 class FilePath; | |
| 15 } // namespace base | |
| 16 | |
| 17 namespace IPC { | |
| 18 | |
| 19 // Creates a UNIX-domain socket at |socket_name| and bind()s it, then listen()s | |
| 20 // on it. If successful, |server_listen_fd| will be set to the new file | |
| 21 // descriptor, and the function will return true. Otherwise returns false. | |
| 22 // | |
| 23 // This function also effectively performs `mkdir -p` on the dirname of | |
| 24 // |socket_name| to ensure that all the directories up to |socket_name| exist. | |
| 25 // As a result of which this function must be run on a thread that allows | |
| 26 // blocking I/O, e.g. the FILE thread in Chrome's browser process. | |
| 27 IPC_EXPORT bool CreateServerUnixDomainSocket(const base::FilePath& socket_name, | |
| 28 int* server_listen_fd); | |
| 29 | |
| 30 // Opens a UNIX-domain socket at |socket_name| and connect()s to it. If | |
| 31 // successful, |client_socket| will be set to the new file descriptor, and the | |
| 32 // function will return true. Otherwise returns false. | |
| 33 IPC_EXPORT bool CreateClientUnixDomainSocket(const base::FilePath& socket_name, | |
| 34 int* client_socket); | |
| 35 | |
| 36 // Gets the effective user ID of the other end of the UNIX-domain socket | |
| 37 // specified by |fd|. If successful, sets |peer_euid| to the uid, and returns | |
| 38 // true. Otherwise returns false. | |
| 39 IPC_EXPORT bool GetPeerEuid(int fd, uid_t* peer_euid); | |
| 40 | |
| 41 // Checks that the process on the other end of the UNIX domain socket | |
| 42 // represented by |peer_fd| shares the same EUID as this process. | |
| 43 IPC_EXPORT bool IsPeerAuthorized(int peer_fd); | |
| 44 | |
| 45 // Accepts a client attempting to connect to |server_listen_fd|, storing the | |
| 46 // new file descriptor for the connection in |server_socket|. | |
| 47 // | |
| 48 // Returns false if |server_listen_fd| encounters an unrecoverable error. | |
| 49 // Returns true if it's valid to keep listening on |server_listen_fd|. In this | |
| 50 // case, it's possible that a connection wasn't successfully established; then, | |
| 51 // |server_socket| will be set to -1. | |
| 52 IPC_EXPORT bool ServerOnConnect(int server_listen_fd, | |
| 53 int* server_socket); | |
| 54 | |
| 55 // The maximum length of the name of a socket for MODE_NAMED_SERVER or | |
| 56 // MODE_NAMED_CLIENT if you want to pass in your own socket. | |
| 57 // The standard size on linux is 108, mac is 104. To maintain consistency | |
| 58 // across platforms we standardize on the smaller value. | |
| 59 static const size_t kMaxSocketNameLength = 104; | |
| 60 | |
| 61 } // namespace IPC | |
| 62 | |
| 63 #endif // IPC_UNIX_DOMAIN_SOCKET_UTIL_H_ | |
| OLD | NEW |