util.h revision a551a712
1a4f78defSmrg/*
2a4f78defSmrg * Copyright (c) 2015 NVIDIA Corporation
3a4f78defSmrg *
4a4f78defSmrg * Permission is hereby granted, free of charge, to any person obtaining a copy
5a4f78defSmrg * of this software and associated documentation files (the "Software"), to deal
6a4f78defSmrg * in the Software without restriction, including without limitation the rights
7a4f78defSmrg * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8a4f78defSmrg * copies of the Software, and to permit persons to whom the Software is
9a4f78defSmrg * furnished to do so, subject to the following conditions:
10a4f78defSmrg *
11a4f78defSmrg * The above copyright notice and this permission notice (including the next
12a4f78defSmrg * paragraph) shall be included in all copies or substantial portions of the
13a4f78defSmrg * Software.
14a4f78defSmrg *
15a4f78defSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16a4f78defSmrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17a4f78defSmrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
18a4f78defSmrg * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19a4f78defSmrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20a4f78defSmrg * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21a4f78defSmrg * SOFTWARE.
22a4f78defSmrg */
23a4f78defSmrg
24a4f78defSmrg#ifdef HAVE_CONFIG_H
25a4f78defSmrg#include "config.h"
26a4f78defSmrg#endif
27a4f78defSmrg
28a4f78defSmrg#include <unistd.h>
29a4f78defSmrg#include <stdlib.h>
30a4f78defSmrg
31a4f78defSmrgstatic char * getenv_wrapper(const char *name)
32a4f78defSmrg{
33a4f78defSmrg    if (getuid() == geteuid() && getgid() == getegid()) {
34a4f78defSmrg        return getenv(name);
35a4f78defSmrg    }
36a4f78defSmrg    else {
37a4f78defSmrg        return NULL;
38a4f78defSmrg    }
39a4f78defSmrg}
40a4f78defSmrg
41a551a712Smrg#if 0 // Just substituting it for the above equivalent
42a4f78defSmrg#  ifdef HAVE___SECURE_GETENV
43a4f78defSmrg#    define secure_getenv __secure_getenv
44a4f78defSmrg#  else
45a4f78defSmrg#    warning Neither secure_getenv nor __secure_getenv is available.
46a4f78defSmrg#    define secure_getenv getenv_wrapper
47a4f78defSmrg#  endif
48a4f78defSmrg#endif
49