public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Takashi Yano <takashi.yano@nifty.ne.jp>
To: cygwin@cygwin.com
Subject: Re: Logging-in using ssh elevates the user privilege.
Date: Fri, 08 Mar 2019 14:01:00 -0000	[thread overview]
Message-ID: <20190308230138.b7f6b5ac90c9a14cde2647c1@nifty.ne.jp> (raw)
In-Reply-To: <51233666.20190307182445@yandex.ru>

[-- Attachment #1: Type: text/plain, Size: 1359 bytes --]

Hello,

Thank you for the information.

On Thu, 7 Mar 2019 18:24:45 +0300 Andrey Repin wrote:
> > GNU screen freeze without much of an effort under Cygwin.
> > Try detaching from running screen and then running screen -ls.
> 
> Past discussion
> http://sourceware.org/ml/cygwin/2017-05/msg00448.html
> mid:16810313565.20170527142723@yandex.ru

I looked into this problem of GNU screen and found the
cause is very different from that of the problem I had
reported.

The problem I had reported is due to the failure of
sending signal, which is caused by mismatch of tokens
between ssh session and mintty session.

On the other hand, the problem you mentioned is due
to the difference in the behaviour of socket API.

In Linux, connect() in the client returns befor the
server calls accept(). However, in cygwin, connect()
does not return until the server calls accept().

Attached test code clarifies the difference.

[Result in Linux]
Server: Created.
Server: Binded.
Server: Listened.
Client: Created.
Client: Connected.
Client: Written.
Server: Accepted.
10: 1234567890
Server: Read.

[Result in Cygwin]
Server: Created.
Server: Binded.
Server: Listened.
Client: Created.
Server: Accepted.
Client: Connected.
Client: Written.
10: 1234567890
Server: Read.

I am not sure why cygwin behaves differently from
linux.

-- 
Takashi Yano <takashi.yano@nifty.ne.jp>

[-- Attachment #2: sockunix.c --]
[-- Type: text/x-csrc, Size: 1701 bytes --]

#include <stdio.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/wait.h>
#include <signal.h>

#define SOCKNAME "sock_unix_test"

int main()
{
	int fd;
	struct sockaddr_un sunx;
	pid_t pid;
	ssize_t len;
	char buf[BUFSIZ];
	
	memset(&sunx, 0, sizeof(sunx));
	sunx.sun_family = AF_UNIX;
	strncpy (sunx.sun_path, SOCKNAME, sizeof(sunx.sun_path) -1 );

	pid = fork();
	if (pid) {
		int fd1;
		fd = socket(AF_UNIX, SOCK_STREAM, 0);
		printf("Server: Created.\n");
		if (fd < 0) {
			perror("socket");
			goto end_server;
		}
		if (bind(fd, (struct sockaddr *)&sunx, sizeof(sunx)) < 0) {
			perror("bind");
			goto end_server;
		}
		printf("Server: Binded.\n");
		if (listen(fd, 1) < 0) {
			perror("listen");
			goto end_server;
		}
		printf("Server: Listened.\n");

		usleep(2000000);

		fd1 = accept(fd, 0, 0);
		if (fd1 < 0) {
			perror("accept");
			goto end_server;
		}
		printf("Server: Accepted.\n");
		while ((len = read(fd1, buf, sizeof(buf))) > 0) {
			buf[len] = '\0';
			printf("%d: %s\n", len, buf);
		}
		printf("Server: Read.\n");
		close(fd1);
end_server:
		close(fd);
		kill(pid, SIGTERM);
		wait(NULL);
		if (unlink(SOCKNAME) < 0) {
			perror("unlink");
		}
	} else {
		usleep(1000000);
		fd = socket(AF_UNIX, SOCK_STREAM, 0);
		printf("Client: Created.\n");
		if (fd < 0) {
			perror("socket");
			goto end_client;
		}
		if (connect(fd, (struct sockaddr *)&sunx, sizeof(sunx)) < 0) {
			perror("connect");
			goto end_client;
		}
		printf("Client: Connected.\n");
		write(fd, "1234567890", 10);
		printf("Client: Written.\n");
end_client:
		close(fd);
	}
	
	return 0;
}


[-- Attachment #3: Type: text/plain, Size: 219 bytes --]


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

  reply	other threads:[~2019-03-08 14:01 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-06 16:00 Takashi Yano
2019-03-06 16:15 ` Corinna Vinschen
2019-03-06 16:17   ` Corinna Vinschen
2019-03-07 10:08     ` Takashi Yano
2019-03-06 18:33 ` Achim Gratz
2019-03-07 11:23   ` Takashi Yano
2019-03-07 11:20 ` Andrey Repin
2019-03-07 15:35   ` Andrey Repin
2019-03-08 14:01     ` Takashi Yano [this message]
2019-03-08 14:11       ` Corinna Vinschen
2019-03-08 14:46         ` Takashi Yano
2019-03-08 14:52           ` Corinna Vinschen
2019-03-08 17:57             ` Andrew Schulman
2019-03-08 22:36               ` Takashi Yano
2019-03-08 23:19                 ` Andrew Schulman
2019-03-09  1:49                   ` Takashi Yano
2019-03-09  7:47                     ` Michael Wild
2019-03-08 15:39         ` Takashi Yano
2019-03-08 15:56           ` Corinna Vinschen
2019-03-08 16:21             ` Takashi Yano
2019-03-08 17:14               ` Corinna Vinschen
2019-03-07 11:14 Takashi Yano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190308230138.b7f6b5ac90c9a14cde2647c1@nifty.ne.jp \
    --to=takashi.yano@nifty.ne.jp \
    --cc=cygwin@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).