OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef NET_SOCKET_UNIX_DOMAIN_SERVER_SOCKET_POSIX_H_ | 5 #ifndef NET_SOCKET_UNIX_DOMAIN_SERVER_SOCKET_POSIX_H_ |
6 #define NET_SOCKET_UNIX_DOMAIN_SERVER_SOCKET_POSIX_H_ | 6 #define NET_SOCKET_UNIX_DOMAIN_SERVER_SOCKET_POSIX_H_ |
7 | 7 |
8 #include <sys/types.h> | 8 #include <sys/types.h> |
9 | 9 |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/callback.h" | 13 #include "base/callback.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
16 #include "net/base/net_export.h" | 16 #include "net/base/net_export.h" |
17 #include "net/socket/server_socket.h" | 17 #include "net/socket/server_socket.h" |
18 #include "net/socket/socket_descriptor.h" | 18 #include "net/socket/socket_descriptor.h" |
19 | 19 |
20 namespace net { | 20 namespace net { |
21 | 21 |
22 class SocketLibevent; | 22 class SocketLibevent; |
23 | 23 |
24 // Unix Domain Server Socket Implementation. Supports abstract namespaces on | 24 // Unix Domain Server Socket Implementation. Supports abstract namespaces on |
25 // Linux and Android. | 25 // Linux and Android. |
26 class NET_EXPORT UnixDomainServerSocket : public ServerSocket { | 26 class NET_EXPORT UnixDomainServerSocket : public ServerSocket { |
27 public: | 27 public: |
28 struct Credentials; | |
29 | |
28 // Callback that returns whether the already connected client, identified by | 30 // Callback that returns whether the already connected client, identified by |
29 // its process |user_id| and |group_id|, is allowed to keep the connection | 31 // its credentials, is allowed to keep the connection open. Note that |
30 // open. Note that the socket is closed immediately in case the callback | 32 // the socket is closed immediately in case the callback returns false. |
31 // returns false. | 33 typedef base::Callback<bool (const Credentials&)> AuthCallback; |
32 typedef base::Callback<bool (uid_t user_id, gid_t group_id)> AuthCallback; | |
33 | 34 |
34 UnixDomainServerSocket(const AuthCallback& auth_callack, | 35 UnixDomainServerSocket(const AuthCallback& auth_callack, |
35 bool use_abstract_namespace); | 36 bool use_abstract_namespace); |
36 virtual ~UnixDomainServerSocket(); | 37 virtual ~UnixDomainServerSocket(); |
37 | 38 |
38 // Gets UID and GID of peer to check permissions. | 39 // Gets credentials of peer to check permissions. |
39 static bool GetPeerIds(SocketDescriptor socket_fd, | 40 static bool GetPeerIds(SocketDescriptor socket_fd, |
byungchul
2014/08/04 22:18:02
GetCredentials
SeRya
2014/08/05 10:32:27
Renamed to GetPeerCredentials
| |
40 uid_t* user_id, | 41 Credentials* credentials); |
41 gid_t* group_id); | |
42 | 42 |
43 // ServerSocket implementation. | 43 // ServerSocket implementation. |
44 virtual int Listen(const IPEndPoint& address, int backlog) OVERRIDE; | 44 virtual int Listen(const IPEndPoint& address, int backlog) OVERRIDE; |
45 virtual int ListenWithAddressAndPort(const std::string& unix_domain_path, | 45 virtual int ListenWithAddressAndPort(const std::string& unix_domain_path, |
46 int port_unused, | 46 int port_unused, |
47 int backlog) OVERRIDE; | 47 int backlog) OVERRIDE; |
48 virtual int GetLocalAddress(IPEndPoint* address) const OVERRIDE; | 48 virtual int GetLocalAddress(IPEndPoint* address) const OVERRIDE; |
49 virtual int Accept(scoped_ptr<StreamSocket>* socket, | 49 virtual int Accept(scoped_ptr<StreamSocket>* socket, |
50 const CompletionCallback& callback) OVERRIDE; | 50 const CompletionCallback& callback) OVERRIDE; |
51 | 51 |
52 private: | 52 private: |
53 void AcceptCompleted(scoped_ptr<StreamSocket>* socket, | 53 void AcceptCompleted(scoped_ptr<StreamSocket>* socket, |
54 const CompletionCallback& callback, | 54 const CompletionCallback& callback, |
55 int rv); | 55 int rv); |
56 bool AuthenticateAndGetStreamSocket(scoped_ptr<StreamSocket>* socket); | 56 bool AuthenticateAndGetStreamSocket(scoped_ptr<StreamSocket>* socket); |
57 | 57 |
58 scoped_ptr<SocketLibevent> listen_socket_; | 58 scoped_ptr<SocketLibevent> listen_socket_; |
59 const AuthCallback auth_callback_; | 59 const AuthCallback auth_callback_; |
60 const bool use_abstract_namespace_; | 60 const bool use_abstract_namespace_; |
61 | 61 |
62 scoped_ptr<SocketLibevent> accept_socket_; | 62 scoped_ptr<SocketLibevent> accept_socket_; |
63 | 63 |
64 DISALLOW_COPY_AND_ASSIGN(UnixDomainServerSocket); | 64 DISALLOW_COPY_AND_ASSIGN(UnixDomainServerSocket); |
65 }; | 65 }; |
66 | 66 |
67 struct UnixDomainServerSocket::Credentials { | |
mmenke
2014/08/04 20:22:57
In net/, at least, public inner classes and struct
byungchul
2014/08/04 22:18:02
need NET_EXPORT
SeRya
2014/08/05 10:32:27
Moved inside.
SeRya
2014/08/05 10:32:27
Done.
| |
68 #if defined(OS_LINUX) || defined(OS_ANDROID) | |
69 pid_t process_id; | |
mmenke
2014/08/04 20:22:57
Think this is worth a comment (Code is pretty self
SeRya
2014/08/05 10:32:27
Done.
| |
70 #endif | |
71 uid_t user_id; | |
72 gid_t group_id; | |
73 }; | |
74 | |
67 } // namespace net | 75 } // namespace net |
68 | 76 |
69 #endif // NET_SOCKET_UNIX_DOMAIN_SOCKET_POSIX_H_ | 77 #endif // NET_SOCKET_UNIX_DOMAIN_SOCKET_POSIX_H_ |
OLD | NEW |