/**************************************************************************/ /* */ /* OCaml */ /* */ /* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ /* */ /* Copyright 1996 Institut National de Recherche en Informatique et */ /* en Automatique. */ /* */ /* All rights reserved. This file is distributed under the terms of */ /* the GNU Lesser General Public License version 2.1, with the */ /* special exception on linking described in the file LICENSE. */ /* */ /**************************************************************************/ #include #ifdef HAS_UNISTD #include #endif #include #ifdef HAS_GETAUXVAL #include #endif #include #include extern char ** environ; CAMLprim value unix_environment_unsafe(value unit) { if (environ != NULL) { return caml_copy_string_array((const char**)environ); } else { return Atom(0); } } static char **secure_environ(void) { #ifdef HAS_GETAUXVAL if (!getauxval(AT_SECURE)) return environ; else return NULL; #elif defined(HAS_ISSETUGID) if (!issetugid ()) return environ; else return NULL; #else if (geteuid () == getuid () && getegid () == getgid ()) return environ; else return NULL; #endif } CAMLprim value unix_environment(value unit) { char **e = secure_environ(); if (e != NULL) { return caml_copy_string_array((const char**)e); } else { return Atom(0); } }