Re: wrapping dynamic syscalls with wrap(1)

From: Oliver Fromme <olli_at_lurza.secnetix.de>
Date: Thu, 27 Sep 2007 16:30:47 +0200 (CEST)
cpghost <cpghost_at_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
Received on Thu Sep 27 2007 - 12:32:16 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:39:18 UTC