secure_getenv.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /* Look up an environment variable more securely.
  2. Copyright 2013 Free Software Foundation, Inc.
  3. This program is free software: you can redistribute it and/or modify it
  4. under the terms of the GNU General Public License as published
  5. by the Free Software Foundation; either version 3 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  13. #include <config.h>
  14. #include <stdlib.h>
  15. #if !HAVE___SECURE_GETENV
  16. # if HAVE_ISSETUGID
  17. # include <unistd.h>
  18. # else
  19. # undef issetugid
  20. # define issetugid() 1
  21. # endif
  22. #endif
  23. char *
  24. secure_getenv (char const *name)
  25. {
  26. #if HAVE___SECURE_GETENV
  27. return __secure_getenv (name);
  28. #else
  29. if (issetugid ())
  30. return 0;
  31. return getenv (name);
  32. #endif
  33. }