* fhandler_socket.cc (fhandler_socket::eid_pipe_name): Fix format
string. (fhandler_socket::connect): Set sun_path before running eid credential transaction. Run transaction only if OS connect was successful. (fhandler_socket::accept): Run transaction only if OS accept was successful.
This commit is contained in:
		| @@ -1,4 +1,13 @@ | |||||||
| 2005-03-08  Corinna Vinschen  <corinna@vinschen.de> | 2005-03-09  Corinna Vinschen  <corinna@vinschen.de> | ||||||
|  |  | ||||||
|  | 	* fhandler_socket.cc (fhandler_socket::eid_pipe_name): Fix format | ||||||
|  | 	string. | ||||||
|  | 	(fhandler_socket::connect): Set sun_path before running eid credential | ||||||
|  | 	transaction.  Run transaction only if OS connect was successful. | ||||||
|  | 	(fhandler_socket::accept): Run transaction only if OS accept was | ||||||
|  | 	successful. | ||||||
|  |  | ||||||
|  | 2005-03-09  Corinna Vinschen  <corinna@vinschen.de> | ||||||
|  |  | ||||||
| 	* signal.cc (sigprocmask): Rename first parameter to "how". | 	* signal.cc (sigprocmask): Rename first parameter to "how". | ||||||
| 	(handle_sigprocmask): Ditto.  Check "how" for being a valid "how" value. | 	(handle_sigprocmask): Ditto.  Check "how" for being a valid "how" value. | ||||||
|   | |||||||
| @@ -56,7 +56,8 @@ secret_event_name (char *buf, short port, int *secret_ptr) | |||||||
| char * | char * | ||||||
| fhandler_socket::eid_pipe_name (char *buf) | fhandler_socket::eid_pipe_name (char *buf) | ||||||
| { | { | ||||||
|   __small_sprintf (buf, "\\\\.\\pipe\\cygwin-unix-$s", get_sun_path ()); |   __small_sprintf (buf, "\\\\.\\pipe\\cygwin-unix-%s", get_sun_path ()); | ||||||
|  |   debug_printf ("%s", buf); | ||||||
|   return buf; |   return buf; | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -666,30 +667,34 @@ fhandler_socket::connect (const struct sockaddr *name, int namelen) | |||||||
| 	  res = -1; | 	  res = -1; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|       /* eid credential transaction. */ |       if (!res || in_progress) | ||||||
|       if (wincap.has_named_pipes ()) |  | ||||||
|         { |         { | ||||||
| 	  struct ucred in = { getpid (), geteuid32 (), getegid32 () }; | 	  /* eid credential transaction. */ | ||||||
| 	  struct ucred out = { (pid_t) 0, (__uid32_t) -1, (__gid32_t) -1 }; | 	  set_sun_path (name->sa_data); | ||||||
| 	  DWORD bytes = 0; | 	  if (wincap.has_named_pipes ()) | ||||||
| 	  if (CallNamedPipe(eid_pipe_name ((char *) alloca (CYG_MAX_PATH + 1)), |  | ||||||
| 			    &in, sizeof in, &out, sizeof out, &bytes, 1000)) |  | ||||||
| 	    { | 	    { | ||||||
| 	      debug_printf ("Received eid credentials: pid: %d, uid: %d, gid: %d", | 	      struct ucred in = { getpid (), geteuid32 (), getegid32 () }; | ||||||
| 			    out.pid, out.uid, out.gid); | 	      struct ucred out = { (pid_t) 0, (__uid32_t) -1, (__gid32_t) -1 }; | ||||||
| 	      sec_peer_pid = out.pid; | 	      DWORD bytes = 0; | ||||||
| 	      sec_peer_uid = out.uid; | 	      if (CallNamedPipe(eid_pipe_name ((char *) alloca (CYG_MAX_PATH + 1)), | ||||||
| 	      sec_peer_gid = out.gid; | 				&in, sizeof in, &out, sizeof out, &bytes, 1000)) | ||||||
|  | 		{ | ||||||
|  | 		  debug_printf ("Received eid credentials: pid: %d, uid: %d" | ||||||
|  | 		  		", gid: %d", out.pid, out.uid, out.gid); | ||||||
|  | 		  sec_peer_pid = out.pid; | ||||||
|  | 		  sec_peer_uid = out.uid; | ||||||
|  | 		  sec_peer_gid = out.gid; | ||||||
|  | 		} | ||||||
|  | 	      else | ||||||
|  | 		debug_printf ("Receiving eid credentials failed: %E"); | ||||||
|  | 	    } | ||||||
|  | 	  else /* 9x */ | ||||||
|  | 	    { | ||||||
|  | 	      /* Incorrect but wrong pid at least doesn't break getpeereid. */ | ||||||
|  | 	      sec_peer_pid = getpid (); | ||||||
|  | 	      sec_peer_uid = geteuid32 (); | ||||||
|  | 	      sec_peer_gid = getegid32 (); | ||||||
| 	    } | 	    } | ||||||
| 	  else |  | ||||||
| 	    debug_printf ("Receiving eid credentials failed: %E"); |  | ||||||
| 	} |  | ||||||
|       else /* 9x */ |  | ||||||
|         { |  | ||||||
| 	  /* Incorrect but wrong pid at least doesn't break getpeereid. */ |  | ||||||
| 	  sec_peer_pid = getpid (); |  | ||||||
| 	  sec_peer_uid = geteuid32 (); |  | ||||||
| 	  sec_peer_gid = getegid32 (); |  | ||||||
| 	} | 	} | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -796,31 +801,34 @@ fhandler_socket::accept (struct sockaddr *peer, int *len) | |||||||
| 	  return -1; | 	  return -1; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|       /* eid credential transaction. */ |       if ((SOCKET) res != INVALID_SOCKET || in_progress) | ||||||
|       if (wincap.has_named_pipes ()) |  | ||||||
|         { |         { | ||||||
| 	  DWORD bytes = 0; | 	  /* eid credential transaction. */ | ||||||
| 	  bool ret = ConnectNamedPipe (sec_pipe, NULL); | 	  if (wincap.has_named_pipes ()) | ||||||
| 	  if (ret || GetLastError () == ERROR_PIPE_CONNECTED) |  | ||||||
| 	    { | 	    { | ||||||
| 	      if (!ReadFile (sec_pipe, &out, sizeof out, &bytes, NULL)) | 	      DWORD bytes = 0; | ||||||
| 		debug_printf ("Receiving eid credentials failed: %E"); | 	      bool ret = ConnectNamedPipe (sec_pipe, NULL); | ||||||
|  | 	      if (ret || GetLastError () == ERROR_PIPE_CONNECTED) | ||||||
|  | 		{ | ||||||
|  | 		  if (!ReadFile (sec_pipe, &out, sizeof out, &bytes, NULL)) | ||||||
|  | 		    debug_printf ("Receiving eid credentials failed: %E"); | ||||||
|  | 		  else | ||||||
|  | 		    debug_printf ("Received eid credentials: pid: %d, uid: %d" | ||||||
|  | 		    		  ", gid: %d", out.pid, out.uid, out.gid); | ||||||
|  | 		  if (!WriteFile (sec_pipe, &in, sizeof in, &bytes, NULL)) | ||||||
|  | 		    debug_printf ("Sending eid credentials failed: %E"); | ||||||
|  | 		  DisconnectNamedPipe (sec_pipe); | ||||||
|  | 		} | ||||||
| 	      else | 	      else | ||||||
| 		 debug_printf ("Received eid credentials: pid: %d, uid: %d, gid: %d", | 		debug_printf ("Connecting the eid credential pipe failed: %E"); | ||||||
| 			       out.pid, out.uid, out.gid); | 	    } | ||||||
| 	      if (!WriteFile (sec_pipe, &in, sizeof in, &bytes, NULL)) | 	  else /* 9x */ | ||||||
| 		debug_printf ("Sending eid credentials failed: %E"); | 	    { | ||||||
| 	      DisconnectNamedPipe (sec_pipe); | 	      /* Incorrect but wrong pid at least doesn't break getpeereid. */ | ||||||
|  | 	      out.pid = sec_pid; | ||||||
|  | 	      out.uid = sec_uid; | ||||||
|  | 	      out.gid = sec_gid; | ||||||
| 	    } | 	    } | ||||||
| 	  else |  | ||||||
| 	    debug_printf ("Connecting the eid credential pipe failed: %E"); |  | ||||||
| 	} |  | ||||||
|       else /* 9x */ |  | ||||||
| 	{ |  | ||||||
| 	  /* Incorrect but wrong pid at least doesn't break getpeereid. */ |  | ||||||
| 	  out.pid = sec_pid; |  | ||||||
| 	  out.uid = sec_uid; |  | ||||||
| 	  out.gid = sec_gid; |  | ||||||
| 	} | 	} | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user