Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1077)

Side by Side Diff: ipc/ipc_channel_posix.cc

Issue 6280009: Adjust Unix domain IPC permissions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Change from fchmod() to chmod(), hopefully this will fix mac. Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "ipc/ipc_channel_posix.h" 5 #include "ipc/ipc_channel_posix.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <fcntl.h> 8 #include <fcntl.h>
9 #include <stddef.h> 9 #include <stddef.h>
10 #include <sys/types.h> 10 #include <sys/types.h>
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 if (fcntl(fd, F_SETFL, O_NONBLOCK) == -1) { 160 if (fcntl(fd, F_SETFL, O_NONBLOCK) == -1) {
161 PLOG(ERROR) << "fcntl(O_NONBLOCK) " << pipe_name; 161 PLOG(ERROR) << "fcntl(O_NONBLOCK) " << pipe_name;
162 if (HANDLE_EINTR(close(fd)) < 0) 162 if (HANDLE_EINTR(close(fd)) < 0)
163 PLOG(ERROR) << "close " << pipe_name; 163 PLOG(ERROR) << "close " << pipe_name;
164 return false; 164 return false;
165 } 165 }
166 166
167 // Delete any old FS instances. 167 // Delete any old FS instances.
168 unlink(pipe_name.c_str()); 168 unlink(pipe_name.c_str());
169 169
170 // Make sure the path we need exists. 170 // Make sure the path we need exists.
171 FilePath path(pipe_name); 171 FilePath path(pipe_name);
172 FilePath dir_path = path.DirName(); 172 FilePath dir_path = path.DirName();
173 if (!file_util::CreateDirectory(dir_path)) { 173 if (!file_util::CreateDirectory(dir_path)) {
174 return false; 174 return false;
175 } 175 }
176 176
177 // Create unix_addr structure 177 // Create unix_addr structure.
178 struct sockaddr_un unix_addr; 178 struct sockaddr_un unix_addr;
179 memset(&unix_addr, 0, sizeof(unix_addr)); 179 memset(&unix_addr, 0, sizeof(unix_addr));
180 unix_addr.sun_family = AF_UNIX; 180 unix_addr.sun_family = AF_UNIX;
181 int path_len = snprintf(unix_addr.sun_path, IPC::kMaxPipeNameLength, 181 int path_len = snprintf(unix_addr.sun_path, IPC::kMaxPipeNameLength,
182 "%s", pipe_name.c_str()); 182 "%s", pipe_name.c_str());
183 DCHECK_EQ(static_cast<int>(pipe_name.length()), path_len); 183 DCHECK_EQ(static_cast<int>(pipe_name.length()), path_len);
184 size_t unix_addr_len = offsetof(struct sockaddr_un, 184 size_t unix_addr_len = offsetof(struct sockaddr_un,
185 sun_path) + path_len + 1; 185 sun_path) + path_len + 1;
186 186
187 // Bind the socket. 187 // Bind the socket.
188 if (bind(fd, reinterpret_cast<const sockaddr*>(&unix_addr), 188 if (bind(fd, reinterpret_cast<const sockaddr*>(&unix_addr),
189 unix_addr_len) != 0) { 189 unix_addr_len) != 0) {
190 PLOG(ERROR) << "bind " << pipe_name; 190 PLOG(ERROR) << "bind " << pipe_name;
191 if (HANDLE_EINTR(close(fd)) < 0) 191 if (HANDLE_EINTR(close(fd)) < 0)
192 PLOG(ERROR) << "close " << pipe_name; 192 PLOG(ERROR) << "close " << pipe_name;
193 return false; 193 return false;
194 } 194 }
195 195
196 // Adjust the socket permissions.
197 if (chmod(pipe_name.c_str(), 0600)) {
198 PLOG(ERROR) << "fchmod " << pipe_name;
Nirnimesh 2011/01/21 02:41:55 s/fchmod/chmod/
199 if (HANDLE_EINTR(close(fd)) < 0)
200 PLOG(ERROR) << "close " << pipe_name;
201 return false;
202 }
203
196 // Start listening on the socket. 204 // Start listening on the socket.
197 const int listen_queue_length = 1; 205 const int listen_queue_length = 1;
198 if (listen(fd, listen_queue_length) != 0) { 206 if (listen(fd, listen_queue_length) != 0) {
199 PLOG(ERROR) << "listen " << pipe_name; 207 PLOG(ERROR) << "listen " << pipe_name;
200 if (HANDLE_EINTR(close(fd)) < 0) 208 if (HANDLE_EINTR(close(fd)) < 0)
201 PLOG(ERROR) << "close " << pipe_name; 209 PLOG(ERROR) << "close " << pipe_name;
202 return false; 210 return false;
203 } 211 }
204 212
205 *server_listen_fd = fd; 213 *server_listen_fd = fd;
(...skipping 943 matching lines...) Expand 10 before | Expand all | Expand 10 after
1149 1157
1150 bool Channel::HasAcceptedConnection() const { 1158 bool Channel::HasAcceptedConnection() const {
1151 return channel_impl_->HasAcceptedConnection(); 1159 return channel_impl_->HasAcceptedConnection();
1152 } 1160 }
1153 1161
1154 void Channel::ResetToAcceptingConnectionState() { 1162 void Channel::ResetToAcceptingConnectionState() {
1155 channel_impl_->ResetToAcceptingConnectionState(); 1163 channel_impl_->ResetToAcceptingConnectionState();
1156 } 1164 }
1157 1165
1158 } // namespace IPC 1166 } // namespace IPC
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698