197 addr.sun_family = AF_UNIX; |
197 addr.sun_family = AF_UNIX; |
198 strcpy(addr.sun_path, initial_path); |
198 strcpy(addr.sun_path, initial_path); |
199 ::unlink(initial_path); |
199 ::unlink(initial_path); |
200 int res = ::bind(listener, (struct sockaddr*)&addr, sizeof(addr)); |
200 int res = ::bind(listener, (struct sockaddr*)&addr, sizeof(addr)); |
201 if (res == -1) { |
201 if (res == -1) { |
202 RESTARTABLE(::close(listener), res); |
202 ::close(listener); |
203 return -1; |
203 return -1; |
204 } |
204 } |
205 |
205 |
206 // put in listen mode, set permissions, and rename into place |
206 // put in listen mode, set permissions, and rename into place |
207 res = ::listen(listener, 5); |
207 res = ::listen(listener, 5); |
343 // get the credentials of the peer and check the effective uid/guid |
343 // get the credentials of the peer and check the effective uid/guid |
344 // - check with jeff on this. |
344 // - check with jeff on this. |
345 uid_t puid; |
345 uid_t puid; |
346 gid_t pgid; |
346 gid_t pgid; |
347 if (::getpeereid(s, &puid, &pgid) != 0) { |
347 if (::getpeereid(s, &puid, &pgid) != 0) { |
348 int res; |
348 ::close(s); |
349 RESTARTABLE(::close(s), res); |
|
350 continue; |
349 continue; |
351 } |
350 } |
352 uid_t euid = geteuid(); |
351 uid_t euid = geteuid(); |
353 gid_t egid = getegid(); |
352 gid_t egid = getegid(); |
354 |
353 |
355 if (puid != euid || pgid != egid) { |
354 if (puid != euid || pgid != egid) { |
356 int res; |
355 ::close(s); |
357 RESTARTABLE(::close(s), res); |
|
358 continue; |
356 continue; |
359 } |
357 } |
360 |
358 |
361 // peer credential look okay so we read the request |
359 // peer credential look okay so we read the request |
362 BsdAttachOperation* op = read_request(s); |
360 BsdAttachOperation* op = read_request(s); |
363 if (op == NULL) { |
361 if (op == NULL) { |
364 int res; |
362 ::close(s); |
365 RESTARTABLE(::close(s), res); |
|
366 continue; |
363 continue; |
367 } else { |
364 } else { |
368 return op; |
365 return op; |
369 } |
366 } |
370 } |
367 } |
411 BsdAttachListener::write_fully(this->socket(), (char*) st->base(), st->size()); |
408 BsdAttachListener::write_fully(this->socket(), (char*) st->base(), st->size()); |
412 ::shutdown(this->socket(), 2); |
409 ::shutdown(this->socket(), 2); |
413 } |
410 } |
414 |
411 |
415 // done |
412 // done |
416 RESTARTABLE(::close(this->socket()), rc); |
413 ::close(this->socket()); |
417 |
414 |
418 // were we externally suspended while we were waiting? |
415 // were we externally suspended while we were waiting? |
419 thread->check_and_wait_while_suspended(); |
416 thread->check_and_wait_while_suspended(); |
420 |
417 |
421 delete this; |
418 delete this; |