caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* on ocaml and set-user-id programs
@ 2005-03-27 10:01 Stefano Zacchiroli
  2005-03-27 10:31 ` [Caml-list] " Richard Jones
  2005-03-27 10:31 ` Kim Nguyen
  0 siblings, 2 replies; 5+ messages in thread
From: Stefano Zacchiroli @ 2005-03-27 10:01 UTC (permalink / raw)
  To: Inria Ocaml Mailing List

I've wrote an ocaml program that needs to be executed set-user-id root.

I managed to have it being executed with effective user id 0 only
compiling in native code or in custom bytecode. Both executing it as a
script using "ocamlrun ocaml" and compiling it to non-custom bytecode
make the program having effective user id of the user executing it.
(Example session at the end of this mail)

This behaviour is annoying and makes impossible to run ocaml set-user-id
programs where the native code compiler isn't available. Am I missing
something or is this a shortcoming of the current ocaml interpreter?

Thanks in advance,
Cheers.

          Attempt using ocamlrun ocaml (FAILED)
  
  $ cat a.ml
  #!/usr/bin/ocamlrun /usr/bin/ocaml
  #use "topfind";;
  #require "unix";;
  Printf.printf "UID = %d\nEUID = %d\n" (Unix.getuid ()) (Unix.geteuid ())
  $ su
  Password:
  # chown root a.ml
  # chmod 4755 a.ml
  # ls -l a.ml
  -rwsr-xr-x  1 root zack 143 2005-03-27 11:50 a.ml*
  # exit
  $ ./a.ml
  UID = 3148
  EUID = 3148
  $
  
          Attempt using non-custom bytecode (FAILED)
  
  $ cat b.ml
  Printf.printf "UID = %d\nEUID = %d\n" (Unix.getuid ()) (Unix.geteuid ())
  $ ocamlfind ocamlc -package unix -linkpkg -o b b.ml
  $ head -1 b
  #!/usr/bin/ocamlrun
  $ su
  Password:
  # chown root b
  # chmod 4755 b
  # ls -l b
  -rwsr-xr-x  1 root zack 70145 2005-03-27 11:52 b*
  # exit
  $ ./b
  UID = 3148
  EUID = 3148
  
          Attempt using custom bytecode (OK)
  
  $ ocamlfind ocamlc -custom -package unix -linkpkg -o b b.ml
  $ su
  Password:
  # chown root b
  # chmod 4755 b
  # exit
  $ ./b
  UID = 3148
  EUID = 0
  
          Attempt using native code (OK)
  
  $ ocamlfind opt -package unix -linkpkg -o b b.ml
  $ su
  Password:
  # chown root b
  # chmod 4755 b
  # exit
  $ ./b
  UID = 3148
  EUID = 0

-- 
Stefano Zacchiroli -*- Computer Science PhD student @ Uny Bologna, Italy
zack@{cs.unibo.it,debian.org,bononia.it} -%- http://www.bononia.it/zack/
If there's any real truth it's that the entire multidimensional infinity
of the Universe is almost certainly being run by a bunch of maniacs. -!-


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2005-03-27 15:33 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-03-27 10:01 on ocaml and set-user-id programs Stefano Zacchiroli
2005-03-27 10:31 ` [Caml-list] " Richard Jones
2005-03-27 10:31 ` Kim Nguyen
2005-03-27 13:34   ` Stefano Zacchiroli
2005-03-27 15:33     ` Richard Jones

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).