with this diff against the current clamav version, a client can pass an open filedescriptor to clamd for scanning.

I sent this diff also to Tomasz in a private mail.

this hand insofar as the user id, under wich clamd is running, does not need to have permission to access the file in the filesystem (which it needs when passing a path to clamd).

comments are very much appreciated.
Index: clamd/session.c
===================================================================
RCS file: /cvsroot/clamav/clamav-devel/clamd/session.c,v
retrieving revision 1.36
diff -u -r1.36 session.c
--- clamd/session.c     29 Oct 2006 18:23:33 -0000      1.36
+++ clamd/session.c     16 Jan 2007 15:47:35 -0000
@@ -232,7 +232,9 @@
 {
        char buff[1025];
        int bread, opt;
-
+       struct msghdr msg;
+       struct cmsghdr *cmsg;
+       unsigned char buf[CMSG_SPACE(sizeof(int))];
 
     bread = readsock(desc, buff, sizeof(buff)-1, '\n', timeout, 0, 1);
     if(bread == -2) /* timeout */
@@ -367,7 +369,29 @@
                    logg("%s: OK\n", path);
            }
        }
-
+    } else if(!strncmp(buff, CMD14, strlen(CMD14))) { /* FILDES */
+       memset(&msg, 0, sizeof(msg));
+       msg.msg_control = buf;
+       msg.msg_controllen = sizeof(buf);
+ 
+       if (recvmsg(desc, &msg, 0) == -1) {
+           logg("recvmsg failed!");
+           return -1;
+       }
+       if ((msg.msg_flags & MSG_TRUNC) || (msg.msg_flags & MSG_CTRUNC)) {
+           logg("control message truncated");
+           return -1;
+       }
+       for (cmsg = CMSG_FIRSTHDR(&msg); cmsg != NULL;
+           cmsg = CMSG_NXTHDR(&msg, cmsg)) {
+               if (cmsg->cmsg_len == CMSG_LEN(sizeof(int)) &&
+                   cmsg->cmsg_level == SOL_SOCKET &&
+                   cmsg->cmsg_type == SCM_RIGHTS) {
+                       int fd = *(int *)CMSG_DATA(cmsg);
+                       scanfd(fd, NULL, root, limits, options, copt, desc, 0);
+                       close(fd);
+               }
+       }
     } else {
        mdprintf(desc, "UNKNOWN COMMAND\n");
     }
Index: clamd/session.h
===================================================================
RCS file: /cvsroot/clamav/clamav-devel/clamd/session.h,v
retrieving revision 1.10
diff -u -r1.10 session.h
--- clamd/session.h     11 Sep 2006 23:10:29 -0000      1.10
+++ clamd/session.h     16 Jan 2007 15:47:35 -0000
@@ -38,6 +38,7 @@
 #define CMD11 "SHUTDOWN"
 #define CMD12 "FD"
 #define CMD13 "MULTISCAN"
+#define CMD14 "FILDES"
 
 #include "libclamav/clamav.h"
 #include "shared/cfgparser.h"
_______________________________________________
http://lurker.clamav.net/list/clamav-devel.html

Reply via email to