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

« back to all changes in this revision

Viewing changes to clamd/session.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:
24
24
#include "clamav-config.h"
25
25
#endif
26
26
 
 
27
#if defined HAVE_FD_PASSING && defined FDPASS_NEED_XOPEN
 
28
/* to expose BSD 4.4/Unix98 semantics instead of BSD 4.3 semantics */
 
29
#define _XOPEN_SOURCE 500
 
30
#endif
 
31
 
27
32
#include <stdio.h>
28
33
#include <stdlib.h>
29
34
#include <string.h>
33
38
#include <sys/types.h>
34
39
#ifndef C_WINDOWS
35
40
#include <dirent.h>
 
41
 
36
42
#include <sys/socket.h>
 
43
#ifdef HAVE_FD_PASSING
 
44
#ifdef HAVE_SYS_UIO_H
 
45
#include <sys/uio.h>
 
46
#endif
 
47
#endif
 
48
 
37
49
#include <sys/time.h>
38
50
#endif
39
51
#include <pthread.h>
54
66
#include "server.h"
55
67
#include "session.h"
56
68
 
 
69
#ifdef HAVE_FD_PASSING
 
70
static int recvfd_and_scan(int desc, const struct cl_engine *engine, const struct cl_limits *limits, unsigned int options, const struct cfgstruct *copt)
 
71
{
 
72
        struct msghdr msg;
 
73
        struct cmsghdr *cmsg;
 
74
        unsigned char buf[CMSG_SPACE(sizeof(int))];
 
75
        struct iovec iov[1];
 
76
        char dummy;
 
77
        int ret=-1;
 
78
 
 
79
        memset(&msg, 0, sizeof(msg));
 
80
        iov[0].iov_base = &dummy;
 
81
        iov[0].iov_len = 1;
 
82
        msg.msg_iov = iov;
 
83
        msg.msg_iovlen = 1;
 
84
        msg.msg_control = buf;
 
85
        msg.msg_controllen = sizeof(buf);
 
86
 
 
87
        if (recvmsg(desc, &msg, 0) == -1) {
 
88
            logg("recvmsg failed: %s!", strerror(errno));
 
89
            return -1;
 
90
        }
 
91
        if ((msg.msg_flags & MSG_TRUNC) || (msg.msg_flags & MSG_CTRUNC)) {
 
92
            logg("control message truncated");
 
93
            return -1;
 
94
        }
 
95
        for (cmsg = CMSG_FIRSTHDR(&msg); cmsg != NULL;
 
96
            cmsg = CMSG_NXTHDR(&msg, cmsg)) {
 
97
                if (cmsg->cmsg_len == CMSG_LEN(sizeof(int)) &&
 
98
                    cmsg->cmsg_level == SOL_SOCKET &&
 
99
                    cmsg->cmsg_type == SCM_RIGHTS) {
 
100
                        int fd = *(int *)CMSG_DATA(cmsg);
 
101
                        ret = scanfd(fd, NULL, engine, limits, options, copt, desc);
 
102
                        close(fd);
 
103
                }
 
104
        }
 
105
        return ret;
 
106
}
 
107
 
 
108
#else
 
109
static int recvfd_and_scan(int desc, const struct cl_engine *engine, const struct cl_limits *limits, unsigned int options, const struct cfgstruct *copt)
 
110
{
 
111
        mdprintf(desc, "ERROR: FILDES support not compiled in\n");
 
112
        return -1;
 
113
}
 
114
#endif
 
115
 
57
116
int command(int desc, const struct cl_engine *engine, const struct cl_limits *limits, unsigned int options, const struct cfgstruct *copt, int timeout)
58
117
{
59
118
        char buff[1025];
60
 
        int bread, opt;
61
 
 
 
119
        int bread;
62
120
 
63
121
    bread = readsock(desc, buff, sizeof(buff)-1, '\n', timeout, 0, 1);
64
122
    if(bread == -2) /* timeout */
113
171
                char timestr[32];
114
172
                time_t t = (time_t) daily->stime;
115
173
 
116
 
            mdprintf(desc, "ClamAV "VERSION"/%d/%s", daily->version, cli_ctime(&t, timestr, sizeof(timestr)));
 
174
            mdprintf(desc, "ClamAV %s/%d/%s", get_version(), daily->version, cli_ctime(&t, timestr, sizeof(timestr)));
117
175
            cl_cvdfree(daily);
118
176
        } else {
119
 
            mdprintf(desc, "ClamAV "VERSION"\n");
 
177
            mdprintf(desc, "ClamAV %s\n", get_version());
120
178
        }
121
179
 
122
180
        free(path);
140
198
            if(cfgopt(copt, "ExitOnOOM")->enabled)
141
199
                return COMMAND_SHUTDOWN;
142
200
 
 
201
    } else if(!strncmp(buff, CMD14, strlen(CMD14))) { /* FILDES */
 
202
        if(recvfd_and_scan(desc, engine, limits, options, copt) == -2)
 
203
            if(cfgopt(copt, "ExitOnOOM")->enabled)
 
204
                return COMMAND_SHUTDOWN;
143
205
    } else {
144
206
        mdprintf(desc, "UNKNOWN COMMAND\n");
145
207
    }