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 #include "net/socket/unix_domain_server_socket_posix.h" | 5 #include "net/socket/unix_domain_server_socket_posix.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <sys/socket.h> | 8 #include <sys/socket.h> |
9 #include <sys/un.h> | 9 #include <sys/un.h> |
10 #include <unistd.h> | 10 #include <unistd.h> |
(...skipping 11 matching lines...) Expand all Loading... | |
22 : auth_callback_(auth_callback), | 22 : auth_callback_(auth_callback), |
23 use_abstract_namespace_(use_abstract_namespace) { | 23 use_abstract_namespace_(use_abstract_namespace) { |
24 DCHECK(!auth_callback_.is_null()); | 24 DCHECK(!auth_callback_.is_null()); |
25 } | 25 } |
26 | 26 |
27 UnixDomainServerSocket::~UnixDomainServerSocket() { | 27 UnixDomainServerSocket::~UnixDomainServerSocket() { |
28 } | 28 } |
29 | 29 |
30 // static | 30 // static |
31 bool UnixDomainServerSocket::GetPeerIds(SocketDescriptor socket, | 31 bool UnixDomainServerSocket::GetPeerIds(SocketDescriptor socket, |
32 pid_t* process_id, | |
32 uid_t* user_id, | 33 uid_t* user_id, |
33 gid_t* group_id) { | 34 gid_t* group_id) { |
34 #if defined(OS_LINUX) || defined(OS_ANDROID) | 35 #if defined(OS_LINUX) || defined(OS_ANDROID) |
35 struct ucred user_cred; | 36 struct ucred user_cred; |
36 socklen_t len = sizeof(user_cred); | 37 socklen_t len = sizeof(user_cred); |
37 if (getsockopt(socket, SOL_SOCKET, SO_PEERCRED, &user_cred, &len) < 0) | 38 if (getsockopt(socket, SOL_SOCKET, SO_PEERCRED, &user_cred, &len) < 0) |
38 return false; | 39 return false; |
40 *process_id = user_cred.pid; | |
39 *user_id = user_cred.uid; | 41 *user_id = user_cred.uid; |
40 *group_id = user_cred.gid; | 42 *group_id = user_cred.gid; |
41 return true; | 43 return true; |
42 #else | 44 #else |
45 *process_id = 0; | |
mmenke
2014/08/01 16:26:52
Not a huge fan of just silently making process_id
SeRya
2014/08/04 10:47:03
It seems there is no consensus among UNIX systems
mmenke
2014/08/04 15:45:58
I'd prefer that approach. Setting it to 0 on some
SeRya
2014/08/04 20:14:25
Done.
| |
43 return getpeereid(socket, user_id, group_id) == 0; | 46 return getpeereid(socket, user_id, group_id) == 0; |
44 #endif | 47 #endif |
45 } | 48 } |
46 | 49 |
47 int UnixDomainServerSocket::Listen(const IPEndPoint& address, int backlog) { | 50 int UnixDomainServerSocket::Listen(const IPEndPoint& address, int backlog) { |
48 NOTIMPLEMENTED(); | 51 NOTIMPLEMENTED(); |
49 return ERR_NOT_IMPLEMENTED; | 52 return ERR_NOT_IMPLEMENTED; |
50 } | 53 } |
51 | 54 |
52 int UnixDomainServerSocket::ListenWithAddressAndPort( | 55 int UnixDomainServerSocket::ListenWithAddressAndPort( |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
123 // to the caller. | 126 // to the caller. |
124 rv = Accept(socket, callback); | 127 rv = Accept(socket, callback); |
125 if (rv != ERR_IO_PENDING) | 128 if (rv != ERR_IO_PENDING) |
126 callback.Run(rv); | 129 callback.Run(rv); |
127 } | 130 } |
128 | 131 |
129 bool UnixDomainServerSocket::AuthenticateAndGetStreamSocket( | 132 bool UnixDomainServerSocket::AuthenticateAndGetStreamSocket( |
130 scoped_ptr<StreamSocket>* socket) { | 133 scoped_ptr<StreamSocket>* socket) { |
131 DCHECK(accept_socket_); | 134 DCHECK(accept_socket_); |
132 | 135 |
136 pid_t process_id; | |
133 uid_t user_id; | 137 uid_t user_id; |
134 gid_t group_id; | 138 gid_t group_id; |
135 if (!GetPeerIds(accept_socket_->socket_fd(), &user_id, &group_id) || | 139 if (!GetPeerIds(accept_socket_->socket_fd(), |
136 !auth_callback_.Run(user_id, group_id)) { | 140 &process_id, &user_id, &group_id) || |
141 !auth_callback_.Run(process_id, user_id, group_id)) { | |
137 accept_socket_.reset(); | 142 accept_socket_.reset(); |
138 return false; | 143 return false; |
139 } | 144 } |
140 | 145 |
141 socket->reset(new UnixDomainClientSocket(accept_socket_.Pass())); | 146 socket->reset(new UnixDomainClientSocket(accept_socket_.Pass())); |
142 return true; | 147 return true; |
143 } | 148 } |
144 | 149 |
145 } // namespace net | 150 } // namespace net |
OLD | NEW |