~ubuntu-branches/ubuntu/raring/clamav/raring

« back to all changes in this revision

Viewing changes to freshclam/mirman.c

  • Committer: Bazaar Package Importer
  • Author(s): Stephen Gran
  • Date: 2008-09-05 17:25:34 UTC
  • mfrom: (0.35.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080905172534-yi3f8fkye1o7u1r3
* New upstream version (closes: #497662, #497773)
  - lots of new options for clamd.conf
  - fixes CVEs CVE-2008-3912, CVE-2008-3913, CVE-2008-3914, and
    CVE-2008-1389
* No longer supports --unzip option, so typo is gone (closes: #496276)
* Translations:
  - sv (thanks Martin Bagge <brother@bsnet.se>) (closes: #491760)

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 *  MA 02110-1301, USA.
17
17
 */
18
18
 
 
19
#ifdef  _MSC_VER
 
20
#include <winsock.h>
 
21
#endif
 
22
 
19
23
#if HAVE_CONFIG_H
20
24
#include "clamav-config.h"
21
25
#endif
35
39
#include <fcntl.h>
36
40
#include <time.h>
37
41
 
 
42
#ifndef C_WINDOWS
 
43
#include <sys/socket.h>
 
44
#include <netinet/in.h>
 
45
#include <arpa/inet.h>
 
46
#endif
 
47
 
38
48
#include "mirman.h"
39
49
 
40
50
#include "libclamav/cltypes.h"
46
56
#define O_BINARY    0
47
57
#endif
48
58
 
 
59
#ifndef SUPPORT_IPv6
 
60
#ifndef AF_INET6
 
61
#define AF_INET6    0xbeef  /* foo */
 
62
#endif
 
63
#endif
 
64
 
49
65
#define IGNTIME 3 * 86400
50
66
 
51
67
void mirman_free(struct mirdat *mdat)
94
110
    return 0;
95
111
}
96
112
 
97
 
int mirman_check(uint32_t ip, struct mirdat *mdat)
 
113
int mirman_check(uint32_t *ip, int af, struct mirdat *mdat, struct mirdat_ip **md)
98
114
{
99
115
        unsigned int i, flevel = cl_retflevel();
100
116
 
101
117
 
 
118
    if(md)
 
119
        *md = NULL;
 
120
 
102
121
    if(!mdat->active)
103
122
        return 0;
104
123
 
105
124
    for(i = 0; i < mdat->num; i++) {
106
 
        if(mdat->mirtab[i].atime && mdat->mirtab[i].ip == ip) {
 
125
 
 
126
        if((af == AF_INET && mdat->mirtab[i].ip4 == *ip) || (af == AF_INET6 && !memcmp(mdat->mirtab[i].ip6, ip, 4 * sizeof(uint32_t)))) {
 
127
 
 
128
            if(!mdat->mirtab[i].atime) {
 
129
                if(md)
 
130
                    *md = &mdat->mirtab[i];
 
131
                return 0;
 
132
            }
107
133
 
108
134
            if(mdat->dbflevel && (mdat->dbflevel > flevel) && (mdat->dbflevel - flevel > 3))
109
135
                if(time(NULL) - mdat->mirtab[i].atime < 4 * 3600)
112
138
            if(mdat->mirtab[i].ignore) {
113
139
                if(time(NULL) - mdat->mirtab[i].atime > IGNTIME) {
114
140
                    mdat->mirtab[i].ignore = 0;
 
141
                    if(md)
 
142
                        *md = &mdat->mirtab[i];
115
143
                    return 0;
116
144
                } else {
117
145
                    return 1;
118
146
                }
119
147
            }
 
148
 
 
149
            if(md)
 
150
                *md = &mdat->mirtab[i];
 
151
            return 0;
120
152
        }
121
153
    }
122
154
 
123
155
    return 0;
124
156
}
125
157
 
126
 
int mirman_update(uint32_t ip, struct mirdat *mdat, uint8_t broken)
 
158
int mirman_update(uint32_t *ip, int af, struct mirdat *mdat, uint8_t broken)
127
159
{
128
160
        unsigned int i, found = 0;
129
161
 
132
164
        return 0;
133
165
 
134
166
    for(i = 0; i < mdat->num; i++) {
135
 
        if(mdat->mirtab[i].ip == ip) {
 
167
        if((af == AF_INET && mdat->mirtab[i].ip4 == *ip) || (af == AF_INET6 && !memcmp(mdat->mirtab[i].ip6, ip, 4 * sizeof(uint32_t)))) {
136
168
            found = 1;
137
169
            break;
138
170
        }
160
192
            logg("!Can't allocate memory for new element in mdat->mirtab\n");
161
193
            return -1;
162
194
        }
163
 
        mdat->mirtab[mdat->num].ip = ip;
 
195
        if(af == AF_INET) {
 
196
            mdat->mirtab[mdat->num].ip4 = *ip;
 
197
        } else {
 
198
            mdat->mirtab[mdat->num].ip4 = 0;
 
199
            memcpy(mdat->mirtab[mdat->num].ip6, ip, 4 * sizeof(uint32_t));
 
200
        }
164
201
        mdat->mirtab[mdat->num].atime = 0;
165
202
        mdat->mirtab[mdat->num].succ = 0;
166
203
        mdat->mirtab[mdat->num].fail = 0;
179
216
void mirman_list(const struct mirdat *mdat)
180
217
{
181
218
        unsigned int i;
182
 
        unsigned char *ip;
183
219
        time_t tm;
 
220
        char ip[46];
184
221
 
185
222
 
186
223
    for(i = 0; i < mdat->num; i++) {
187
224
        printf("Mirror #%u\n", i + 1);
188
 
        ip = (unsigned char *) &mdat->mirtab[i].ip;
189
 
        printf("IP: %u.%u.%u.%u\n", ip[0], ip[1], ip[2], ip[3]);
 
225
#ifdef SUPPORT_IPv6
 
226
        if(mdat->mirtab[i].ip4)
 
227
            printf("IP: %s\n", inet_ntop(AF_INET, &mdat->mirtab[i].ip4, ip, sizeof(ip)));
 
228
        else
 
229
            printf("IP: %s\n", inet_ntop(AF_INET6, mdat->mirtab[i].ip6, ip, sizeof(ip)));
 
230
#else
 
231
        if(mdat->mirtab[i].ip4)
 
232
            printf("IP: %s\n", inet_ntoa(*(struct in_addr*) &mdat->mirtab[i].ip4));
 
233
#endif
190
234
        printf("Successes: %u\n", mdat->mirtab[i].succ);
191
235
        printf("Failures: %u\n", mdat->mirtab[i].fail);
192
236
        tm = mdat->mirtab[i].atime;
197
241
    }
198
242
}
199
243
 
 
244
void mirman_whitelist(struct mirdat *mdat)
 
245
{
 
246
        unsigned int i;
 
247
 
 
248
    logg("Whitelisting all mirrors\n");
 
249
    for(i = 0; i < mdat->num; i++)
 
250
        mdat->mirtab[i].ignore = 0;
 
251
}
 
252
 
200
253
int mirman_write(const char *file, struct mirdat *mdat)
201
254
{
202
255
        int fd;