From: devzero@web.de
To: cygwin@cygwin.com
Cc: schulman.andrew@epamail.epa.gov
Subject: Aw: Problem with stunnel/rsync & tcp_wrappers under cygwin
Date: Thu, 06 Mar 2014 12:17:00 -0000 [thread overview]
Message-ID: <trinity-b50ef026-5b30-4d50-90e5-ac7dd061d75e-1394047765053@3capp-webde-bs47> (raw)
more searches and an pointer from the stunnel-maintainer - maybe it`s all about passing file descriptors...
http://wiki.osdev.org/Cygwin_Issues#Passing_file_descriptors
http://fossies.org/dox/stunnel-4.56/libwrap_8c_source.html
regards
roland
one step further - i would say, that fork() is the culprit.
i added some s_log in the librwap.c code and it appears, that "case 0" never is being executed.
i found http://cygwin.com/faq.html#faq.using.fixing-fork-failures , so there probably needs
to be done some special handling for that. (disable pthread on cygwin?)
regards
rolnd
2014.02.27 15:55:12 LOG7[16476:25769803872]: ECDH initialized with curve prime256v1
2014.02.27 15:55:12 LOG7[16476:25769803872]: SSL options set: 0x00000004
2014.02.27 15:55:12 LOG5[16476:25769803872]: Configuration successful
2014.02.27 15:55:12 LOG7[16476:25769803872]: child spawned
2014.02.27 15:55:12 LOG7[16476:25769803872]: default - close ipc_socket
2014.02.27 15:55:12 LOG7[16476:25769803872]: child spawned
2014.02.27 15:55:12 LOG7[16476:25769803872]: default - close ipc_socket
2014.02.27 15:55:12 LOG7[16476:25769803872]: child spawned
2014.02.27 15:55:12 LOG7[16476:25769803872]: default - close ipc_socket
2014.02.27 15:55:12 LOG7[16476:25769803872]: child spawned
2014.02.27 15:55:12 LOG7[16476:25769803872]: default - close ipc_socket
2014.02.27 15:55:12 LOG7[16476:25769803872]: child spawned
2014.02.27 15:55:12 LOG7[16476:25769803872]: default - close ipc_socket
2014.02.27 15:55:12 LOG7[16476:25769803872]: Service [rsync] (FD=11) bound to 0.0.0.0:1873
2014.02.27 15:55:12 LOG7[16476:25769803872]: Created pid file /var/run/stunnel.pid
2014.02.27 15:55:20 LOG7[16476:25769803872]: Service [rsync] accepted (FD=3) from 192.168.0.116:60302
2014.02.27 15:55:20 LOG7[16476:25770120192]: Service [rsync] started
2014.02.27 15:55:20 LOG7[16476:25770120192]: Waiting for a libwrap process
2014.02.27 15:55:20 LOG7[16476:25770120192]: Acquired libwrap process #0
2014.02.27 15:55:20 LOG7[16476:25770120192]: Releasing libwrap process #0
2014.02.27 15:55:20 LOG7[16476:25770120192]: Released libwrap process #0
2014.02.27 15:55:20 LOG4[16476:25770120192]: Service [rsync] REFUSED by libwrap from 192.168.0.116:60302
2014.02.27 15:55:20 LOG7[16476:25770120192]: See hosts_access(5) manual for details
2014.02.27 15:55:20 LOG5[16476:25770120192]: Connection reset: 0 byte(s) sent to SSL, 0 byte(s) sent to socket
2014.02.27 15:55:20 LOG7[16476:25770120192]: Local socket (FD=3) closed
2014.02.27 15:55:20 LOG7[16476:25770120192]: Service [rsync] finished (0 left)
libwrap.c
for(i=0; i<num_processes; ++i) { /* spawn a child */
s_log(LOG_DEBUG, "child spawned");
if(s_socketpair(AF_UNIX, SOCK_STREAM, 0, ipc_socket+2*i, 0, "libwrap_init")) {
s_log(LOG_DEBUG, "libwrap_init\n");
return 1; }
fflush(NULL);
switch(fork()) {
case -1: /* error */
s_log(LOG_DEBUG, "ioerror fork");
ioerror("fork");
return 1;
case 0: /* child */
s_log(LOG_DEBUG, "case 0");
drop_privileges(0); /* libwrap processes are not chrooted */
close(0); /* stdin */
close(1); /* stdout */
if(!global_options.option.foreground) /* for logging in read_fd */
close(2); /* stderr */
for(j=0; j<=i; ++j) /* close parent-side sockets created so far */
s_log(LOG_DEBUG, "close ipc socket\n");
close(ipc_socket[2*j]);
while(1) { /* main libwrap child loop */
s_log(LOG_DEBUG, "in ptrheads - main child loop - servname: %s \n",servname);
if(read_fd(ipc_socket[2*i+1], servname, SERVNAME_LEN, &rfd)<=0)
_exit(0);
s_log(LOG_DEBUG, "in ptrheads - servname: %s \n",servname);
result=check(servname, rfd);
write(ipc_socket[2*i+1], (u8 *)&result, sizeof result);
if(rfd>=0)
close(rfd);
}
default: /* parent */
s_log(LOG_DEBUG, "default - close ipc_socket");
close(ipc_socket[2*i+1]); /* child-side socket */
------
after a lot of digging into it, i found it must be a problem related to pthreads.
when i compile stunnel with --with-threads=fork , it works.
2014.02.27 14:19:21 LOG5[5500:0]: stunnel 4.56 on x86_64-unknown-cygwin platform
2014.02.27 14:19:21 LOG5[5500:0]: Compiled/running with OpenSSL 1.0.1e 11 Feb 2013
2014.02.27 14:19:21 LOG5[5500:0]: Threading:FORK Sockets:POLL,IPv6 SSL:ENGINE,OCSP Auth:LIBWRAP
2014.02.27 14:19:21 LOG5[5500:0]: Reading configuration from file /etc/stunnel/stunnel.conf
2014.02.27 14:19:21 LOG7[5500:0]: Compression not enabled
2014.02.27 14:19:21 LOG7[5500:0]: PRNG seeded successfully
2014.02.27 14:19:21 LOG6[5500:0]: Initializing service [rsync]
2014.02.27 14:19:21 LOG4[5500:0]: Insecure file permissions on /etc/stunnel/stunnel.pem
2014.02.27 14:19:21 LOG7[5500:0]: Certificate: /etc/stunnel/stunnel.pem
2014.02.27 14:19:21 LOG7[5500:0]: Certificate loaded
2014.02.27 14:19:21 LOG7[5500:0]: Key file: /etc/stunnel/stunnel.pem
2014.02.27 14:19:21 LOG7[5500:0]: Private key loaded
2014.02.27 14:19:21 LOG7[5500:0]: Using DH parameters from /etc/stunnel/stunnel.pem
2014.02.27 14:19:21 LOG7[5500:0]: DH initialized with 1024-bit key
2014.02.27 14:19:21 LOG7[5500:0]: ECDH initialized with curve prime256v1
2014.02.27 14:19:21 LOG7[5500:0]: SSL options set: 0x00000004
2014.02.27 14:19:21 LOG5[5500:0]: Configuration successful
2014.02.27 14:19:21 LOG7[5500:0]: Service [rsync] (FD=6) bound to 0.0.0.0:1873
2014.02.27 14:19:21 LOG7[5500:0]: Created pid file /var/run/stunnel.pid
2014.02.27 14:19:36 LOG7[5500:0]: Service [rsync] accepted (FD=3) from 192.168.0.116:60289
2014.02.27 14:19:36 LOG7[14636:0]: Service [rsync] started
2014.02.27 14:19:36 LOG7[14636:0]: Service [rsync] permitted by libwrap from 192.168.0.116:60289
2014.02.27 14:19:36 LOG5[14636:0]: Service [rsync] accepted connection from 192.168.0.116:60289
2014.02.27 14:19:36 LOG7[14636:0]: SSL state (accept): before/accept initialization
2014.02.27 14:19:36 LOG7[14636:0]: SNI: no virtual services defined
--snip--
>
> Hi,
> i have a strange problem with tcp_wrappers in conjunction with stunnel cygwin port. (cc`ing stunnel cygwin maintainer because of that).
>
> I`m trying to secure an rsync which is started in daemon-mode in an inetd-style via stunnel. I`m on Win8 64Bit with a recent 64bit Cygwin installation.
>
> When i put rsync: ALL in "/etc/hosts.allow" all is fine, but when i try to restrict connection to a single IP-Adress it doesn`t work. I spent some time on this but i don`t get this working.
>
> See the log snippets below this mail.
>
> successful connection looks like this:
> 2014.02.23 12:36:22 LOG7[16424:25770120176]: Released libwrap process #0
> 2014.02.23 12:36:22 LOG7[16424:25770120176]: Service [rsync] permitted by libwrap from 192.168.0.116:60222
> 2014.02.23 12:36:22 LOG5[16424:25770120176]: Service [rsync] accepted connection from 192.168.0.116:60222
>
> unsuccessful connection looks like this:
> 2014.02.23 12:34:34 LOG7[17800:25770120176]: Released libwrap process #0
> 2014.02.23 12:34:34 LOG4[17800:25770120176]: Service [rsync] REFUSED by libwrap from 192.168.0.116:60221
> 2014.02.23 12:34:34 LOG7[17800:25770120176]: See hosts_access(5) manual for details
>
> Afaik, tcpwrappers only checks for IP-address , not source port - correct ?
>
> I`m curious about IP:PORT in the logs.
>
> I`m no programmer, but if i get this right, the "accepted_address" is being passed to libwrap to be checked for authentication and libwrap tells if connection is permitted or not. So, i`m curious why "accepted_address" seems to contain IP:PORT where it should possibly only contain "IP".
>
> from the stunnel sources:
>
> client.c
> ---snipp---
> /* authenticate based on retrieved IP address of the client */
> accepted_address=s_ntop(&c->peer_addr, c->peer_addr_len);
> #ifdef USE_LIBWRAP
> libwrap_auth(c, accepted_address);
> #endif /* USE_LIBWRAP */
> auth_user(c, accepted_address);
> s_log(LOG_NOTICE, "Service [%s] accepted connection from %s",
> c->opt->servname, accepted_address);
> str_free(accepted_address);
> }
>
> ---snipp---
>
> libwrap.c
> ---snipp---
> #endif /* USE_PTHREAD */
> { /* use original, synchronous libwrap calls */
> enter_critical_section(CRIT_LIBWRAP);
> result=check(c->opt->servname, c->local_rfd.fd);
> leave_critical_section(CRIT_LIBWRAP);
> }
> if(!result) {
> s_log(LOG_WARNING, "Service [%s] REFUSED by libwrap from %s",
> c->opt->servname, accepted_address);
> s_log(LOG_DEBUG, "See hosts_access(5) manual for details");
> longjmp(c->err, 1);
> }
> s_log(LOG_DEBUG, "Service [%s] permitted by libwrap from %s",
> c->opt->servname, accepted_address);
> }
>
> ---snipp---
>
> Bug ?
>
> I`m out of ideas otherwise...
>
> regards
> Roland
>
>
>
>
> stunnel.exe info:
>
> 2014.02.23 12:36:16 LOG7[16424:25769803872]: Clients allowed=125
> 2014.02.23 12:36:16 LOG5[16424:25769803872]: stunnel 4.56 on x86_64-unknown-cygwin platform
> 2014.02.23 12:36:16 LOG5[16424:25769803872]: Compiled/running with OpenSSL 1.0.1e 11 Feb 2013
> 2014.02.23 12:36:16 LOG5[16424:25769803872]: Threading:PTHREAD Sockets:POLL,IPv6 SSL:ENGINE,OCSP Auth:LIBWRAP
> 2014.02.23 12:36:16 LOG5[16424:25769803872]: Reading configuration from file /etc/stunnel/stunnel.conf
>
>
> This one works:
>
> $ cat /etc/hosts.allow
> rsync: ALL
>
> stunnel log:
> 2014.02.23 12:36:22 LOG7[16424:25770120176]: Acquired libwrap process #0
> 2014.02.23 12:36:22 LOG7[16424:25770120176]: Releasing libwrap process #0
> 2014.02.23 12:36:22 LOG7[16424:25770120176]: Released libwrap process #0
> 2014.02.23 12:36:22 LOG7[16424:25770120176]: Service [rsync] permitted by libwrap from 192.168.0.116:60222
> 2014.02.23 12:36:22 LOG5[16424:25770120176]: Service [rsync] accepted connection from 192.168.0.116:60222
> 2014.02.23 12:36:22 LOG7[16424:25770120176]: SSL state (accept): before/accept initialization
> 2014.02.23 12:36:22 LOG7[16424:25770120176]: SNI: no virtual services defined
> 2014.02.23 12:36:22 LOG7[16424:25770120176]: SSL state (accept): SSLv3 read client hello A
> 2014.02.23 12:36:22 LOG7[16424:25770120176]: SSL state (accept): SSLv3 write server hello A
> 2014.02.23 12:36:22 LOG7[16424:25770120176]: SSL state (accept): SSLv3 write certificate A
> 2014.02.23 12:36:22 LOG7[16424:25770120176]: SSL state (accept): SSLv3 write key exchange A
> 2014.02.23 12:36:22 LOG7[16424:25770120176]: SSL state (accept): SSLv3 write certificate request A
>
>
> All of the following ones do NOT work
>
> $ cat /etc/hosts.allow
> rsync: 192.168.0.116
>
> 2014.02.23 11:48:01 LOG5[17800:25769803872]: Configuration successful
> 2014.02.23 11:48:01 LOG7[17800:25769803872]: Service [rsync] (FD=11) bound to 0.0.0.0:1873
> 2014.02.23 11:48:01 LOG7[17800:25769803872]: Created pid file /var/run/stunnel.pid
> 2014.02.23 12:34:34 LOG7[17800:25769803872]: Service [rsync] accepted (FD=3) from 192.168.0.116:60221
> 2014.02.23 12:34:34 LOG7[17800:25770120176]: Service [rsync] started
> 2014.02.23 12:34:34 LOG7[17800:25770120176]: Waiting for a libwrap process
> 2014.02.23 12:34:34 LOG7[17800:25770120176]: Acquired libwrap process #0
> 2014.02.23 12:34:34 LOG7[17800:25770120176]: Releasing libwrap process #0
> 2014.02.23 12:34:34 LOG7[17800:25770120176]: Released libwrap process #0
> 2014.02.23 12:34:34 LOG4[17800:25770120176]: Service [rsync] REFUSED by libwrap from 192.168.0.116:60221
> 2014.02.23 12:34:34 LOG7[17800:25770120176]: See hosts_access(5) manual for details
> 2014.02.23 12:34:34 LOG5[17800:25770120176]: Connection reset: 0 byte(s) sent to SSL, 0 byte(s) sent to socket
> 2014.02.23 12:34:34 LOG7[17800:25770120176]: Local socket (FD=3) closed
> 2014.02.23 12:34:34 LOG7[17800:25770120176]: Service [rsync] finished (0 left)
> 2014.02.23 12:34:34 LOG7[17800:25770120176]: str_stats: 1 block(s), 32 data byte(s), 58 control byte(s)
> 2014.02.23 12:36:15 LOG7[17800:25769803872]: Dispatching signals from the signal pipe
>
>
> $ cat /etc/hosts.allow
> rsync: 192.168.0.116 : allow
>
> 2014.02.23 12:44:36 LOG7[5248:25770120176]: Waiting for a libwrap process
> 2014.02.23 12:44:36 LOG7[5248:25770120176]: Acquired libwrap process #0
> 2014.02.23 12:44:36 LOG7[5248:25770120176]: Releasing libwrap process #0
> 2014.02.23 12:44:36 LOG7[5248:25770120176]: Released libwrap process #0
> 2014.02.23 12:44:36 LOG4[5248:25770120176]: Service [rsync] REFUSED by libwrap from 192.168.0.116:60223
> 2014.02.23 12:44:36 LOG7[5248:25770120176]: See hosts_access(5) manual for details
> 2014.02.23 12:44:36 LOG5[5248:25770120176]: Connection reset: 0 byte(s) sent to SSL, 0 byte(s) sent to socket
> 2014.02.23 12:44:36 LOG7[5248:25770120176]: Local socket (FD=3) closed
> 2014.02.23 12:44:36 LOG7[5248:25770120176]: Service [rsync] finished (0 left)
> 2014.02.23 12:44:36 LOG7[5248:25770120176]: str_stats: 1 block(s), 32 data byte(s), 58 control byte(s)
>
> $ cat /etc/hosts.allow
> rsync: 192.168.0.116/32 : allow
>
> 2014.02.23 12:46:02 LOG7[10392:25770120176]: Service [rsync] started
> 2014.02.23 12:46:02 LOG7[10392:25770120176]: Waiting for a libwrap process
> 2014.02.23 12:46:02 LOG7[10392:25770120176]: Acquired libwrap process #0
> 2014.02.23 12:46:02 LOG7[10392:25770120176]: Releasing libwrap process #0
> 2014.02.23 12:46:02 LOG7[10392:25770120176]: Released libwrap process #0
> 2014.02.23 12:46:02 LOG4[10392:25770120176]: Service [rsync] REFUSED by libwrap from 192.168.0.116:60224
> 2014.02.23 12:46:02 LOG7[10392:25770120176]: See hosts_access(5) manual for details
> 2014.02.23 12:46:02 LOG5[10392:25770120176]: Connection reset: 0 byte(s) sent to SSL, 0 byte(s) sent to socket
> 2014.02.23 12:46:02 LOG7[10392:25770120176]: Local socket (FD=3) closed
> 2014.02.23 12:46:02 LOG7[10392:25770120176]: Service [rsync] finished (0 left)
> 2014.02.23 12:46:02 LOG7[10392:25770120176]: str_stats: 1 block(s), 32 data byte(s), 58 control byte(s)
>
>
>
>
> $ cat /etc/stunnel/stunnel.conf
> client = no
> foreground = yes
>
> #setuid = root
> #setgid = root
> #
> pid = /var/run/stunnel.pid
>
> debug = 7
> output = /var/log/stunnel.log
>
> socket = l:TCP_NODELAY=1
> socket = r:TCP_NODELAY=1
>
> socket = l:SO_LINGER=1:60
>
>
> [rsync]
> accept = 1873
> cert = /etc/stunnel/stunnel.pem
> client = no
> verify = 0
> libwrap = yes
> exec = /usr/bin/rsync
> execargs = rsync --daemon --config /etc/rsync-ssl/rsync-ssl.conf
--
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
next reply other threads:[~2014-03-05 19:29 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-03-06 12:17 devzero [this message]
-- strict thread matches above, loose matches on Subject: below --
2014-02-27 15:34 devzero
2014-02-27 13:46 devzero
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=trinity-b50ef026-5b30-4d50-90e5-ac7dd061d75e-1394047765053@3capp-webde-bs47 \
--to=devzero@web.de \
--cc=cygwin@cygwin.com \
--cc=schulman.andrew@epamail.epa.gov \
/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).