extern int ip_recv(int, uschar *, int, int);
extern int ip_socket(int, int);
+extern int ip_tcpsocket(const uschar *, uschar **, int);
+extern int ip_unixsocket(const uschar *, uschar **);
+extern int ip_streamsocket(const uschar *, uschar **, int);
+
extern uschar *local_part_quote(uschar *);
extern int log_create(uschar *);
extern int log_create_as_exim(uschar *);
}
+int
+ip_tcpsocket(const uschar * hostport, uschar ** errstr, int tmo)
+{
+ int scan;
+ uschar hostname[256];
+ unsigned int portlow, porthigh;
+
+ /* extract host and port part */
+ scan = sscanf(CS hostport, "%255s %u-%u", hostname, &portlow, &porthigh);
+ if ( scan != 3 ) {
+ if ( scan != 2 ) {
+ *errstr = string_sprintf("invalid socket '%s'", hostport);
+ return -1;
+ }
+ porthigh = portlow;
+ }
+
+ return ip_connectedsocket(SOCK_STREAM, hostname, portlow, porthigh,
+ tmo, NULL, errstr);
+}
+
+int
+ip_unixsocket(const uschar * path, uschar ** errstr)
+{
+ int sock;
+ struct sockaddr_un server;
+
+ if ((sock = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
+ *errstr = US"can't open UNIX socket.";
+ return -1;
+ }
+
+ server.sun_family = AF_UNIX;
+ Ustrncpy(server.sun_path, path, sizeof(server.sun_path)-1);
+ server.sun_path[sizeof(server.sun_path)-1] = '\0';
+ if (connect(sock, (struct sockaddr *) &server, sizeof(server)) < 0) {
+ int err = errno;
+ (void)close(sock);
+ *errstr = string_sprintf("unable to connect to UNIX socket (%s): %s",
+ path, strerror(err));
+ return -1;
+ }
+ return sock;
+}
+
+int
+ip_streamsocket(const uschar * spec, uschar ** errstr, int tmo)
+{
+ return *spec == '/'
+ ? ip_unixsocket(spec, errstr) : ip_tcpsocket(spec, errstr, tmo);
+}
+
/*************************************************
* Set keepalive on a socket *
*************************************************/
return ip_connectedsocket(SOCK_STREAM, hostname, port, port, 5, host, errstr);
}
-static int
-m_tcpsocket_fromdef(const uschar * hostport, uschar ** errstr)
-{
- int scan;
- uschar hostname[256];
- unsigned int portlow, porthigh;
-
- /* extract host and port part */
- scan = sscanf(CS hostport, "%255s %u-%u", hostname, &portlow, &porthigh);
- if ( scan != 3 ) {
- if ( scan != 2 ) {
- *errstr = string_sprintf("invalid socket '%s'", hostport);
- return -1;
- }
- porthigh = portlow;
- }
-
- return ip_connectedsocket(SOCK_STREAM, hostname, portlow, porthigh,
- 5, NULL, errstr);
-}
-
-static int
-m_unixsocket(const uschar * path, uschar ** errstr)
-{
- int sock;
- struct sockaddr_un server;
-
- if ((sock = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
- *errstr = US"can't open UNIX socket.";
- return -1;
- }
-
- server.sun_family = AF_UNIX;
- Ustrncpy(server.sun_path, path, sizeof(server.sun_path)-1);
- server.sun_path[sizeof(server.sun_path)-1] = '\0';
- if (connect(sock, (struct sockaddr *) &server, sizeof(server)) < 0) {
- int err = errno;
- (void)close(sock);
- *errstr = string_sprintf("unable to connect to UNIX socket (%s): %s",
- path, strerror(err));
- return -1;
- }
- return sock;
-}
-
-static inline int
-m_streamsocket(const uschar * spec, uschar ** errstr)
-{
- return *spec == '/'
- ? m_unixsocket(spec, errstr) : m_tcpsocket_fromdef(spec, errstr);
-}
-
static int
m_sock_send(int sock, uschar * buf, int cnt, uschar ** errstr)
{
if (!timeout) timeout = MALWARE_TIMEOUT;
tmo = time(NULL) + timeout;
- for (scanent = m_scans; ; scanent++) {
+ for (scanent = m_scans; ; scanent++)
+ {
if (!scanent->name)
return malware_errlog_defer(string_sprintf("unknown scanner type '%s'",
scanner_name));
break;
switch(scanent->conn)
{
- case MC_TCP: sock = m_tcpsocket_fromdef(scanner_options, &errstr); break;
- case MC_UNIX: sock = m_unixsocket(scanner_options, &errstr); break;
- case MC_STRM: sock = m_streamsocket(scanner_options, &errstr); break;
+ case MC_TCP: sock = ip_tcpsocket(scanner_options, &errstr, 5); break;
+ case MC_UNIX: sock = ip_unixsocket(scanner_options, &errstr); break;
+ case MC_STRM: sock = ip_streamsocket(scanner_options, &errstr, 5); break;
default: /* compiler quietening */ break;
}
if (sock < 0)
}
else
{
- if ((sock = m_unixsocket(scanner_options, &errstr)) < 0)
+ if ((sock = ip_unixsocket(scanner_options, &errstr)) < 0)
return m_errlog_defer(scanent, errstr);
}
string_sprintf("invalid option '%s'", scanner_options));
}
- if((sock = m_unixsocket(US "/var/run/mksd/socket", &errstr)) < 0)
+ if((sock = ip_unixsocket(US "/var/run/mksd/socket", &errstr)) < 0)
return m_errlog_defer(scanent, errstr);
malware_name = NULL;