54
66
#include "server.h"
55
67
#include "session.h"
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)
74
unsigned char buf[CMSG_SPACE(sizeof(int))];
79
memset(&msg, 0, sizeof(msg));
80
iov[0].iov_base = &dummy;
84
msg.msg_control = buf;
85
msg.msg_controllen = sizeof(buf);
87
if (recvmsg(desc, &msg, 0) == -1) {
88
logg("recvmsg failed: %s!", strerror(errno));
91
if ((msg.msg_flags & MSG_TRUNC) || (msg.msg_flags & MSG_CTRUNC)) {
92
logg("control message truncated");
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);
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)
111
mdprintf(desc, "ERROR: FILDES support not compiled in\n");
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)
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;
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);
119
mdprintf(desc, "ClamAV "VERSION"\n");
177
mdprintf(desc, "ClamAV %s\n", get_version());
140
198
if(cfgopt(copt, "ExitOnOOM")->enabled)
141
199
return COMMAND_SHUTDOWN;
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;
144
206
mdprintf(desc, "UNKNOWN COMMAND\n");