This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Logging-in using ssh elevates the user privilege.


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>
#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;
}

--
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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]