Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 27 Sep 2007 16:30:47 +0200 (CEST)
From:      Oliver Fromme <olli@lurza.secnetix.de>
To:        freebsd-current@FreeBSD.ORG, cpghost@cordula.ws, Daichi GOTO <daichi@FreeBSD.ORG>
Subject:   Re: wrapping dynamic syscalls with wrap(1)
Message-ID:  <200709271430.l8REUl1v017380@lurza.secnetix.de>
In-Reply-To: <20070927155519.114cac72@epia-2.farid-hajji.net>

next in thread | previous in thread | raw e-mail | index | archive | help
cpghost <cpghost@cordula.ws> wrote:
 > Daichi GOTO wrote:
 > > And unusual commands like chflags I just suppose are no much

I think that chflags(1) is not "unusual".  A non-standard
extension to rm(1) would be unusual.

 > > point in this case. What is important is that adding mistake
 > > protecting functions into common commands like rm(1) itself.
 > 
 > Perhaps the solution is not general enough: rm(1) is but one
 > program using the unlink(2) syscall. Why not protect unlink(2)
 > itself by wrapping it into a function that does all this checking
 > that you're putting into safety-rm right now?
 > 
 > Users who want to protect themselves could then dynamically
 > link this unlink-wrapper into all their applications. When an
 > application calls unlink(2), that call will be diverted to
 > unlink(3), the wrapper.

That's an interesting idea.

 > Ideally, users should have a generic way to wrap syscalls (or
 > other dynamic library calls) with a program similar to env(1),
 > let's call it wrap(1). A call to wrap(1):
 > 
 > $ wrap lib1 lib2 lib3 ... prog

How is that different from this:

$ LD_PRELOAD="lib1 lib2 lib3 ..." prog

Well, if you want to save a little bit of typing, wrap(1)
could be trivially implemented as a shell script:

#/bin/sh -
if [ $# -lt 1 ]; then
	echo "Usage:  ${0##*/} [<lib> ...] <prog>" >&2
	exit 1
fi
eval PROG=\$$#
LIBS=${*%$PROG}
LD_PRELOAD="${LIBS% }" exec "$PROG"

By the way, I have used the LD_PRELOAD trick in the past;
it works fine.  I used it to wrap a few functions in libX11
in order to capture video and audio from certain closed-
source player applications that didn't allow to save media
files to disk.

Best regards
   Oliver

-- 
Oliver Fromme, secnetix GmbH & Co. KG, Marktplatz 29, 85567 Grafing b. M.
Handelsregister: Registergericht Muenchen, HRA 74606,  Geschäftsfuehrung:
secnetix Verwaltungsgesellsch. mbH, Handelsregister: Registergericht Mün-
chen, HRB 125758,  Geschäftsführer: Maik Bachmann, Olaf Erb, Ralf Gebhart

FreeBSD-Dienstleistungen, -Produkte und mehr:  http://www.secnetix.de/bsd

"FreeBSD is Yoda, Linux is Luke Skywalker"
        -- Daniel C. Sobral



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200709271430.l8REUl1v017380>