~ubuntu-branches/ubuntu/wily/clamav/wily-proposed

« back to all changes in this revision

Viewing changes to .pc/0008-Add-upstream-systemd-support-for-clamav-daemon-and-c.patch/clamd/tcpserver.c

  • Committer: Package Import Robot
  • Author(s): Scott Kitterman, Sebastian Andrzej Siewior, Andreas Cadhalpun, Scott Kitterman, Javier Fernández-Sanguino
  • Date: 2015-01-28 00:25:13 UTC
  • mfrom: (0.48.14 sid)
  • Revision ID: package-import@ubuntu.com-20150128002513-lil2oi74cooy4lzr
Tags: 0.98.6+dfsg-1
[ Sebastian Andrzej Siewior ]
* update "fix-ssize_t-size_t-off_t-printf-modifier", include of misc.h was
  missing but was pulled in via the systemd patch.
* Don't leak return codes from libmspack to clamav API. (Closes: #774686).

[ Andreas Cadhalpun ]
* Add patch to avoid emitting incremental progress messages when not
  outputting to a terminal. (Closes: #767350)
* Update lintian-overrides for unused-file-paragraph-in-dep5-copyright.
* clamav-base.postinst: always chown /var/log/clamav and /var/lib/clamav
  to clamav:clamav, not only on fresh installations. (Closes: #775400)
* Adapt the clamav-daemon and clamav-freshclam logrotate scripts,
  so that they correctly work under systemd.
* Move the PidFile variable from the clamd/freshclam configuration files
  to the init scripts. This makes the init scripts more robust against
  misconfiguration and avoids error messages with systemd. (Closes: #767353)
* debian/copyright: drop files from Files-Excluded only present in github
  tarballs
* Drop Workaround-a-bug-in-libc-on-Hurd.patch, because hurd got fixed.
  (see #752237)
* debian/rules: Remove useless --with-system-tommath --without-included-ltdl
  configure options.

[ Scott Kitterman ]
* Stop stripping llvm when repacking the tarball as the system llvm on some
  releases is too old to use
* New upstream bugfix release
  - Library shared object revisions.
  - Includes a patch from Sebastian Andrzej Siewior making ClamAV pid files
    compatible with systemd.
  - Fix a heap out of bounds condition with crafted Yoda's crypter files.
    This issue was discovered by Felix Groebert of the Google Security Team.
  - Fix a heap out of bounds condition with crafted mew packer files. This
    issue was discovered by Felix Groebert of the Google Security Team.
  - Fix a heap out of bounds condition with crafted upx packer files. This
    issue was discovered by Kevin Szkudlapski of Quarkslab.
  - Fix a heap out of bounds condition with crafted upack packer files. This
    issue was discovered by Sebastian Andrzej Siewior. CVE-2014-9328.
  - Compensate a crash due to incorrect compiler optimization when handling
    crafted petite packer files. This issue was discovered by Sebastian
    Andrzej Siewior.
* Update lintian override for embedded zlib to match new so version

[ Javier Fernández-Sanguino ]
* Updated Spanish Debconf template translation (Closes: #773563)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *  Copyright (C) 2007-2009 Sourcefire, Inc.
3
 
 *
4
 
 *  Authors: Tomasz Kojm, Török Edvin
5
 
 *
6
 
 *  This program is free software; you can redistribute it and/or modify
7
 
 *  it under the terms of the GNU General Public License version 2 as
8
 
 *  published by the Free Software Foundation.
9
 
 *
10
 
 *  This program is distributed in the hope that it will be useful,
11
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 *  GNU General Public License for more details.
14
 
 *
15
 
 *  You should have received a copy of the GNU General Public License
16
 
 *  along with this program; if not, write to the Free Software
17
 
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18
 
 *  MA 02110-1301, USA.
19
 
 */
20
 
 
21
 
#if HAVE_CONFIG_H
22
 
#include "clamav-config.h"
23
 
#endif
24
 
 
25
 
#include <stdio.h>
26
 
#include <string.h>
27
 
#include <sys/types.h>
28
 
#ifdef HAVE_UNISTD_H
29
 
#include <unistd.h>
30
 
#endif
31
 
#ifndef _WIN32
32
 
#include <sys/socket.h>
33
 
#include <netinet/in.h>
34
 
#include <arpa/inet.h>
35
 
#include <netdb.h>
36
 
#endif
37
 
#include <errno.h>
38
 
 
39
 
#include "libclamav/clamav.h"
40
 
 
41
 
#include "shared/optparser.h"
42
 
#include "shared/output.h"
43
 
#include "shared/misc.h"
44
 
 
45
 
#include "others.h"
46
 
#include "server.h"
47
 
#include "tcpserver.h"
48
 
 
49
 
int tcpserver(int **lsockets, unsigned int *nlsockets, char *ipaddr, const struct optstruct *opts)
50
 
{
51
 
    struct addrinfo hints, *info, *p;
52
 
    char host[NI_MAXHOST], serv[NI_MAXSERV];
53
 
    int *sockets;
54
 
    int sockfd, backlog;
55
 
    int *t;
56
 
    char *estr, port[10];
57
 
    int yes = 1;
58
 
    int res;
59
 
    unsigned int i=0;
60
 
 
61
 
    sockets = *lsockets;
62
 
 
63
 
    snprintf(port, sizeof(port), "%lld", optget(opts, "TCPSocket")->numarg);
64
 
 
65
 
    memset(&hints, 0x00, sizeof(struct addrinfo));
66
 
    hints.ai_family = AF_UNSPEC;
67
 
    hints.ai_socktype = SOCK_STREAM;
68
 
    hints.ai_flags = AI_PASSIVE;
69
 
 
70
 
#ifdef AI_ADDRCONFIG
71
 
    hints.ai_flags |= AI_ADDRCONFIG;
72
 
#endif
73
 
 
74
 
    if ((res = getaddrinfo(ipaddr, port, &hints, &info))) {
75
 
        logg("!TCP: getaddrinfo failed: %s\n", gai_strerror(res));
76
 
        return -1;
77
 
    }
78
 
 
79
 
    for (p = info; p != NULL; p = p->ai_next, i++) {
80
 
        t = realloc(sockets, sizeof(int) * (*nlsockets + 1));
81
 
        if (!(t)) {
82
 
            for (i=0; i < *nlsockets; i++)
83
 
                close(sockets[i]);
84
 
 
85
 
            return -1;
86
 
        }
87
 
        sockets = t;
88
 
 
89
 
        if ((sockfd = socket(p->ai_family, p->ai_socktype, p->ai_protocol)) == -1) {
90
 
            estr = strerror(errno);
91
 
            logg("!TCP: socket() error: %s\n", estr);
92
 
            continue;
93
 
        }
94
 
 
95
 
        if(setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, (void *) &yes, sizeof(yes)) == -1) {
96
 
            logg("!TCP: setsocktopt(SO_REUSEADDR) error: %s\n", strerror(errno));
97
 
        }
98
 
 
99
 
#ifdef IPV6_V6ONLY
100
 
        if (p->ai_family == AF_INET6 &&
101
 
            setsockopt(sockfd, IPPROTO_IPV6, IPV6_V6ONLY, &yes, sizeof(yes)) == -1) {
102
 
            estr = strerror(errno);
103
 
            logg("!TCP: setsocktopt(IPV6_V6ONLY) error: %s\n", estr);
104
 
        }
105
 
#endif /* IPV6_V6ONLY */
106
 
 
107
 
#ifdef HAVE_GETNAMEINFO
108
 
        if ((res = getnameinfo(p->ai_addr, p->ai_addrlen, host, sizeof(host),
109
 
                               serv, sizeof(serv), NI_NUMERICHOST|NI_NUMERICSERV))) {
110
 
            logg("!TCP: getnameinfo failed: %s\n", gai_strerror(res));
111
 
            host[0] = '\0';
112
 
            serv[0] = '\0';
113
 
        }
114
 
#else
115
 
        strncpy(host, ipaddr, sizeof(host));
116
 
        host[sizeof(host)-1] = '\0';
117
 
        snprintf(serv, sizeof(serv), "%u", (unsigned int)(optget(opts, "TCPSocket")->numarg));
118
 
#endif
119
 
        if(bind(sockfd, p->ai_addr, p->ai_addrlen) == -1) {
120
 
            estr = strerror(errno);
121
 
            logg("!TCP: Cannot bind to [%s]:%s: %s\n", host, serv, estr);
122
 
            closesocket(sockfd);
123
 
 
124
 
            continue;
125
 
        }
126
 
        logg("#TCP: Bound to [%s]:%s\n", host, serv);
127
 
 
128
 
        backlog = optget(opts, "MaxConnectionQueueLength")->numarg;
129
 
        logg("#TCP: Setting connection queue length to %d\n", backlog);
130
 
 
131
 
        if(listen(sockfd, backlog) == -1) {
132
 
            estr = strerror(errno);
133
 
            logg("!TCP: Cannot listen on [%s]:%s: %s\n", host, serv, estr);
134
 
            closesocket(sockfd);
135
 
 
136
 
            continue;
137
 
        }
138
 
 
139
 
        sockets[*nlsockets] = sockfd;
140
 
        (*nlsockets)++;
141
 
    }
142
 
 
143
 
    freeaddrinfo(info);
144
 
    *lsockets = sockets;
145
 
 
146
 
    return 0;
147
 
}