Przeglądaj źródła

finish packaging

Ralf S. Engelschall 22 lat temu
rodzic
commit
623b814d7a
6 zmienionych plików z 281 dodań i 65 usunięć
  1. 28 1
      sav/rc.sav
  2. 32 39
      sav/sav.spec
  3. 187 0
      sav/sweep.c
  4. 28 0
      sav/sweep.mk
  5. 6 3
      sav/sweep.sh
  6. 0 22
      sav/wrap_open.c

+ 28 - 1
sav/rc.sav

@@ -5,8 +5,35 @@
 
 %config
     sav_enable="$openpkg_rc_def"
+    sav_ides="http://www.sophos.com/downloads/ide/"
 
 %daily -u @l_susr@
     rcService sav enable yes || exit 0
-    #   FIXME: cs: periodic virus pattern fetching
+
+    #   determine information
+    sav_datadir="@l_prefix@/var/sav/data"
+    sav_version=`@l_prefix@/bin/sweep -v |\
+                 sed -n -e 's;^Product version[^0-9]*\([0-9]\)\.\([0-9.]*\).*$;\1\2;p'`
+    sav_zipfile="${sav_version}_ides.zip"
+    sav_tmpdir="${sav_version}_ides"
+
+    #   download and unpack latest IDEs
+    umask 077
+    cd ${sav_datadir} || exit 1
+    @l_prefix@/bin/curl -s -o ${sav_zipfile} ${sav_ides}/${sav_zipfile} || exit 1
+    mkdir ${sav_tmpdir}
+    (cd ${sav_tmpdir} && @l_prefix@/bin/unzip -jo ../${sav_zipfile}) || exit 1
+
+    #   update IDE repository
+    for ide in *.ide; do
+        if [ ! -f ${sav_tmpdir}/$ide ]; then
+            rm -f $ide
+        fi
+    done
+    cp ${sav_tmpdir}/*.ide .
+    chmod 644 *.ide
+
+    #   cleanup
+    rm -f  ${sav_zipfile} >/dev/null 2>&1 || true
+    rm -rf ${sav_tmpdir}  >/dev/null 2>&1 || true
 

+ 32 - 39
sav/sav.spec

@@ -23,10 +23,6 @@
 ##  SUCH DAMAGE.
 ##
 
-#   package versions
-%define       V_sav        2.14
-%define       V_ide        372
-
 #   package information
 Name:         sav
 Summary:      Sophos Anti-Virus
@@ -36,28 +32,27 @@ Packager:     The OpenPKG Project
 Distribution: OpenPKG [EVAL]
 Group:        System
 License:      Commercial/Free-Trail
-Version:      %{V_sav}
+Version:      2.14
 Release:      20030805
 
 #   list of sources
-Source0:      http://www.sophos.com/downloads/ide/%{V_ide}_ides.zip
-Source1:      http://downloads.sophos.com/dp/full/freebsd.elf.tar.Z
-Source2:      http://downloads.sophos.com/dp/full/linux.intel.libc6.tar.Z
-Source3:      http://downloads.sophos.com/dp/full/solaris.sparc.tar.Z
-Source4:      rc.sav
-Source5:      sav.conf
-Source6:      sweep.sh
-Source7:      wrap_open.c
+Source0:      http://downloads.sophos.com/dp/full/freebsd.elf.tar.Z
+Source1:      http://downloads.sophos.com/dp/full/linux.intel.libc6.tar.Z
+Source2:      http://downloads.sophos.com/dp/full/solaris.sparc.tar.Z
+Source3:      rc.sav
+Source4:      sav.conf
+Source5:      sweep.sh
+Source6:      sweep.c
+Source7:      sweep.mk
 %NoSource     0
 %NoSource     1
 %NoSource     2
-%NoSource     3
 
 #   build information
 Prefix:       %{l_prefix}
 BuildRoot:    %{l_buildroot}
-BuildPreReq:  OpenPKG, openpkg >= 20030717, gcc, infozip
-PreReq:       OpenPKG, openpkg >= 20030717
+BuildPreReq:  OpenPKG, openpkg >= 20030717, gcc
+PreReq:       OpenPKG, openpkg >= 20030717, curl, infozip
 AutoReq:      no
 AutoReqProv:  no
 
@@ -78,16 +73,17 @@ AutoReqProv:  no
     esac
     %{l_gzip} -d -c $engine | %{l_tar} xf -
 
-    #   decompress identity files (IDEs)
-    ( mkdir ides; cd ides;
-      %{l_prefix}/bin/unzip -x %{SOURCE %{V_ide}_ides.zip}
-    ) || exit $?
-
-    #   prepare open() wrapper (/etc/sav.conf -> %{l_prefix}/etc/sav/sav.conf)
-    %{l_shtool} install -c -m 644 %{l_value -s -a} %{SOURCE wrap_open.c} ./
-
 %build
-    %{l_cc} -ldl -shared -s -o wrap_open.so wrap_open.c
+    #   build open(2) wrapper DSO
+    #   (for mapping hard-coded /etc/sav.conf to %{l_prefix}/etc/sav/sav.conf)
+    %{l_shtool} install -c -m 644 %{l_value -s -a} \
+        %{SOURCE sweep.c} %{SOURCE sweep.mk} ./
+    case "%{l_target}" in
+        *-freebsd* ) target="freebsd" ;;
+        *-linux*   ) target="linux"   ;;
+        *-solaris* ) target="solaris" ;;
+    esac
+    %{l_make} %{l_mflags} -f sweep.mk $target
 
 %install
     rm -rf $RPM_BUILD_ROOT
@@ -102,9 +98,9 @@ AutoReqProv:  no
         $RPM_BUILD_ROOT%{l_prefix}/man/man1 \
         $RPM_BUILD_ROOT%{l_prefix}/var/sav/data
 
-    #   install open() wrapper library
+    #   install open(2) wrapper library
     %{l_shtool} install -c -m 755 \
-        wrap_open.so \
+        sweep.so \
         $RPM_BUILD_ROOT%{l_prefix}/libexec/sav/
 
     #   install binary wrapper script
@@ -114,7 +110,8 @@ AutoReqProv:  no
 
     #   install run-command script
     %{l_shtool} install -c -m 755 %{l_value -s -a} \
-        %{SOURCE rc.sav} $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d/
+        %{SOURCE rc.sav} \
+        $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d/
 
     #   install default configuration
     %{l_shtool} install -c -m 644 %{l_value -s -a} \
@@ -123,18 +120,17 @@ AutoReqProv:  no
 
     #   install SAVI library and add compatibility links
     %{l_shtool} install -c -m 755 \
-        sav-install/libsavi.so.3.* \
+        sav-install/libsavi.so* \
         $RPM_BUILD_ROOT%{l_prefix}/lib/sav/
     ( cd $RPM_BUILD_ROOT%{l_prefix}/lib/sav
-      %{l_shtool} mkln -s -f libsavi.so.3* libsavi.so.3
-      %{l_shtool} mkln -s -f libsavi.so.3* libsavi.so.2
-      %{l_shtool} mkln -s -f libsavi.so.3* libsavi.so
+      %{l_shtool} mkln -s -f libsavi.so.3.* libsavi.so.3
+      %{l_shtool} mkln -s -f libsavi.so.3.* libsavi.so
     ) || exit $?
 
     #   install original binary
     %{l_shtool} install -c -m 755 \
         sav-install/sweep \
-        $RPM_BUILD_ROOT%{l_prefix}/libexec/sav/sweep.bin
+        $RPM_BUILD_ROOT%{l_prefix}/libexec/sav/sweep
 
     #   install man page
     %{l_shtool} install -c -m 644 \
@@ -148,13 +144,10 @@ AutoReqProv:  no
     %{l_shtool} install -c -m 644 \
         sav-install/vdl*.vdb \
         $RPM_BUILD_ROOT%{l_prefix}/var/sav/data/
-    for ide in ides/*.ide; do
-        %{l_shtool} install -c -m 644 \
-           $ide $RPM_BUILD_ROOT%{l_prefix}/var/sav/data/
-    done
 
-    #   generate file list
-    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT %{l_files_std} \
+    #   determine installation files
+    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT \
+        %{l_files_std} \
         '%config %{l_prefix}/etc/sav/*'
 
 %files -f files

+ 187 - 0
sav/sweep.c

@@ -0,0 +1,187 @@
+/*
+**  sweep.c -- Sophos Anti-Virus binary RTLD wrapper
+*/
+
+#define CONFIG_OLD "/etc/sav.conf"
+#define CONFIG_NEW "@l_prefix@/etc/sav/sav.conf"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <string.h>
+#include <unistd.h>
+#include <limits.h>
+
+#if defined(PATH_MAX)
+#define PATH_ADJUST_MAXLEN PATH_MAX
+#elif defined(MAXPATHLEN)
+#define PATH_ADJUST_MAXLEN MAXPATHLEN
+#else
+#define PATH_ADJUST_MAXLEN 1024
+#endif
+
+static void path_adjust(char *buf, size_t buflen, const char *path)
+{
+    size_t pathlen;
+
+    /* special case first */
+    if (path == NULL) {
+        buf[0] = '\0';
+        return;
+    }
+
+    /* take over path into buffer */
+    pathlen = strlen(path);
+    if (pathlen > buflen)
+        pathlen = buflen;
+    strncpy(buf, path, pathlen);
+    buf[pathlen] = '\0';
+
+    /* apply path adjustments */
+    if (strcmp(buf, CONFIG_OLD) == 0)
+        strcpy(buf, CONFIG_NEW);
+
+    return;
+}
+
+#if OPENPKG_FREEBSD
+
+#include <dlfcn.h>
+#include <fcntl.h>
+
+int open(const char *path, int flags, ...)
+{
+    static int (*func)(const char *, int, ...) = NULL;
+    char path_adjusted[PATH_ADJUST_MAXLEN];
+    int rv;
+    int mode;
+    va_list ap;
+
+    /* initially resolve original open(2) function */
+    if (func == NULL)
+        func = dlsym(RTLD_NEXT, "open");
+
+    /* adjust path */
+    path_adjust(path_adjusted, sizeof(path_adjusted), path);
+
+    /* execute original function */
+    if (flags & O_CREAT) {
+        va_start(ap, flags);
+        mode = (int)va_arg(ap, int);
+        rv = func(path_adjusted, flags, mode);
+        va_end(ap);
+    }
+    else
+        rv = func(path_adjusted, flags);
+
+    /* pass-through return value */
+    return rv;
+}
+
+/*  -----------------------------------------------------------------  */
+
+#elif OPENPKG_LINUX
+
+#include <features.h>
+#define __USE_GNU
+#include <dlfcn.h>
+#undef __USE_GNU
+#include <fcntl.h>
+
+static int
+myopen(
+    const char *func_name,
+    int (**func_ptr)(const char *, int, ...),
+    char *buf,
+    size_t buflen,
+    const char *path,
+    int flags,
+    va_list ap)
+{
+    int rv;
+    int mode;
+
+    /* initially resolve original open(2) like function */
+    if (*func_ptr == NULL) {
+        if ((*func_ptr = dlsym(RTLD_NEXT, func_name)) == NULL) {
+            fprintf(stderr, "sweep.so: unable to resolve function \"%s\"\n", func_name);
+            abort();
+        }
+    }
+
+    /* adjust path */
+    path_adjust(buf, buflen, path);
+
+    /* execute original function */
+    if (flags & O_CREAT) {
+        mode = (int)va_arg(ap, int);
+        rv = (*func_ptr)(buf, flags, mode);
+    }
+    else
+        rv = (*func_ptr)(buf, flags);
+
+    /* pass-through return value */
+    return rv;
+}
+
+#define genstub(name) \
+int name(const char *path, int flags, ...) \
+{ \
+    static int (*func)(const char *, int, ...) = NULL; \
+    char path_adjusted[PATH_ADJUST_MAXLEN]; \
+    va_list ap; \
+    int rv; \
+\
+    va_start(ap, flags); \
+    rv = myopen(#name, &func, path_adjusted, sizeof(path_adjusted), path, flags, ap); \
+    va_end(ap); \
+    return rv; \
+}
+
+genstub(open)
+genstub(open64)
+genstub(__open)
+genstub(__open64)
+genstub(__libc_open)
+genstub(__libc_open64)
+
+#elif OPENPKG_SOLARIS
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <dlfcn.h>
+
+int open(const char *path, int flags, ...)
+{
+    static int (*func)(const char *, int, ...) = NULL;
+    char path_adjusted[PATH_ADJUST_MAXLEN];
+    int rv;
+    int mode;
+    va_list ap;
+
+    fprintf(stderr, "FUCK\n");
+
+    /* initially resolve original open(2) function */
+    if (func == NULL)
+        func = dlsym(RTLD_NEXT, "open");
+
+    /* adjust path */
+    path_adjust(path_adjusted, sizeof(path_adjusted), path);
+
+    /* execute original function */
+    if (flags & O_CREAT) {
+        va_start(ap, flags);
+        mode = (int)va_arg(ap, int);
+        rv = func(path_adjusted, flags, mode);
+        va_end(ap);
+    }
+    else
+        rv = func(path_adjusted, flags);
+
+    /* pass-through return value */
+    return rv;
+}
+
+#endif
+

+ 28 - 0
sav/sweep.mk

@@ -0,0 +1,28 @@
+
+PLATFORM =
+CC       = gcc
+CPPFLAGS = -DOPENPKG_$(PLATFORM)=1
+CFLAGS   = -Wall -fpic
+LD       = gcc
+LDFLAGS  = -shared
+LIBS     = 
+MFLAGS   = -f sweep.mk
+
+all: freebsd
+
+freebsd:
+	$(MAKE) $(MFLAGS) sweep.so PLATFORM=FREEBSD
+linux:
+	$(MAKE) $(MFLAGS) sweep.so PLATFORM=LINUX LIBS="-ldl"
+solaris:
+	$(MAKE) $(MFLAGS) sweep.so PLATFORM=SOLARIS
+
+sweep.o: sweep.c
+	$(CC) $(CFLAGS) $(CPPFLAGS) -c -o sweep.o sweep.c
+
+sweep.so: sweep.o
+	$(LD) $(LDFLAGS) -o sweep.so sweep.o $(LIBS)
+
+clean:
+	rm -f sweep.so sweep.o
+

+ 6 - 3
sav/sweep.sh

@@ -1,17 +1,20 @@
 #!/bin/sh
 ##
-##  sweep - Sophos Anti-Virus binary wrapper
+##  sweep -- Sophos Anti-Virus binary wrapper
 ##
 
 #   force DSO to be pre-loaded
-LD_PRELOAD="@l_prefix@/libexec/sav/wrap_open.so"
+LD_PRELOAD="@l_prefix@/libexec/sav/sweep.so"
 export LD_PRELOAD
 
+#   make sure shared libaries are found
 LD_LIBRARY_PATH="@l_prefix@/lib/sav:/usr/lib:/lib:$LD_LIBRARY_PATH"
 export LD_LIBRARY_PATH
+
+#   make sure private data is found
 SAV_IDE="@l_prefix@/var/sav/data"
 export SAV_IDE
 
 #   execute original executable
-exec @l_prefix@/libexec/sav/sweep.bin "$@"
+exec @l_prefix@/libexec/sav/sweep ${1+"$@"}
 

+ 0 - 22
sav/wrap_open.c

@@ -1,22 +0,0 @@
-/*
- * gcc -ldl -shared -o open.so open.c
- * LD_PRELOAD=/path/to/open.so
- * export LD_PRELOAD
- */
-
-#include <features.h>
-#define __USE_GNU
-#include <dlfcn.h>
-#undef __USE_GNU
-#include <stdio.h>
-#include <string.h>
-
-int __open(const char *path, int flags) {
-    if(strcmp(path, "/etc/sav.conf") == 0)
-        path = "@l_prefix@/etc/sav/sav.conf";
-
-    int (*orig_func) (const char *, int) = dlsym(RTLD_NEXT, "__open");
-
-    return orig_func(path, flags);
-}
-