1 /* $Id: lc.c 6155 2003-01-19 19:58:25Z rra $
3 ** Routines for the local connect channel. Create a Unix-domain stream
4 ** socket that processes on the local server connect to. Once the
5 ** connection is set up, we speak NNTP. The connect channel is used only
6 ** by rnews to feed in articles from the UUCP sites.
12 #include "inn/innconf.h"
16 #if HAVE_UNIX_DOMAIN_SOCKETS
19 static char *LCpath = NULL;
20 static CHANNEL *LCchan;
24 ** Read function. Accept the connection and create an NNTP channel.
33 syslog(L_ERROR, "%s internal LCreader wrong channel 0x%p not 0x%p",
34 LogName, (void *)cp, (void *)LCchan);
38 if ((fd = accept(cp->fd, NULL, NULL)) < 0) {
39 syslog(L_ERROR, "%s cant accept CCreader %m", LogName);
42 if ((new = NCcreate(fd, false, true)) != NULL) {
43 memset( &new->Address, 0, sizeof( new->Address ) );
44 syslog(L_NOTICE, "%s connected %d", "localhost", new->fd);
45 NCwritereply(new, (char *)NCgreeting);
51 ** Write-done function. Shouldn't happen.
54 LCwritedone(CHANNEL *unused)
56 unused = unused; /* ARGSUSED */
57 syslog(L_ERROR, "%s internal LCwritedone", LogName);
60 #endif /* HAVE_UNIX_DOMAIN_SOCKETS */
64 ** Create the channel.
69 #if defined(HAVE_UNIX_DOMAIN_SOCKETS)
71 struct sockaddr_un server;
74 LCpath = concatpath(innconf->pathrun, _PATH_NNTPCONNECT);
75 /* Remove old detritus. */
76 if (unlink(LCpath) < 0 && errno != ENOENT) {
77 syslog(L_FATAL, "%s cant unlink %s %m", LogName, LCpath);
81 /* Create a socket and name it. */
82 if ((i = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
83 syslog(L_FATAL, "%s cant socket %s %m", LogName, LCpath);
86 memset(&server, 0, sizeof server);
87 server.sun_family = AF_UNIX;
88 strlcpy(server.sun_path, LCpath, sizeof(server.sun_path));
89 if (bind(i, (struct sockaddr *) &server, SUN_LEN(&server)) < 0) {
90 syslog(L_FATAL, "%s cant bind %s %m", LogName, LCpath);
94 /* Set it up to wait for connections. */
95 if (listen(i, MAXLISTEN) < 0) {
96 syslog(L_FATAL, "%s cant listen %s %m", LogName, LCpath);
99 LCchan = CHANcreate(i, CTlocalconn, CSwaiting, LCreader, LCwritedone);
100 syslog(L_NOTICE, "%s lcsetup %s", LogName, CHANname(LCchan));
102 #endif /* defined(HAVE_UNIX_DOMAIN_SOCKETS) */
107 ** Cleanly shut down the channel.
112 #if defined(HAVE_UNIX_DOMAIN_SOCKETS)
113 CHANclose(LCchan, CHANname(LCchan));
115 if (unlink(LCpath) < 0)
116 syslog(L_ERROR, "%s cant unlink %s %m", LogName, LCpath);
118 #endif /* defined(HAVE_UNIX_DOMAIN_SOCKETS) */