/[path-sandbox]/trunk/libsbutil/get_sandbox_lib.c
Gentoo

Diff of /trunk/libsbutil/get_sandbox_lib.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

trunk/src/sandbox_futils.c Revision 196 trunk/libsbutil/sbutil.c Revision 309
1/* 1/*
2 * sbutil.c
3 *
4 * Util functions.
5 *
6 * Copyright 1999-2006 Gentoo Foundation
7 *
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation version 2 of the License.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 675 Mass Ave, Cambridge, MA 02139, USA.
21 *
22 * Some parts might have Copyright:
23 *
2 * Copyright (C) 2002 Brad House <brad@mainstreetsoftworks.com> 24 * Copyright (C) 2002 Brad House <brad@mainstreetsoftworks.com>
3 * Distributed under the terms of the GNU General Public License, v2 or later
4 * Author: Brad House <brad@mainstreetsoftworks.com>
5 * 25 *
6 * $Header$ 26 * $Header$
7 *
8 */ 27 */
28
9 29
10#include <errno.h> 30#include <errno.h>
11#include <stdio.h> 31#include <stdio.h>
12#include <stdlib.h> 32#include <stdlib.h>
13#include <limits.h> 33#include <limits.h>
15#include <sys/stat.h> 35#include <sys/stat.h>
16#include <unistd.h> 36#include <unistd.h>
17#include <fcntl.h> 37#include <fcntl.h>
18#include <libgen.h> 38#include <libgen.h>
19 39
20#include "config.h"
21#include "localdecls.h"
22
23#include "sandbox.h" 40#include "sbutil.h"
24 41
25void get_sandbox_lib(char *path) 42void get_sandbox_lib(char *path)
26{ 43{
27#ifdef SB_HAVE_MULTILIB 44#ifdef SB_HAVE_MULTILIB
28 snprintf(path, SB_PATH_MAX, "%s", LIB_NAME); 45 snprintf(path, SB_PATH_MAX, "%s", LIB_NAME);
29#else 46#else
30 snprintf(path, SB_PATH_MAX, "%s/%s", LIBSANDBOX_PATH, LIB_NAME); 47 snprintf(path, SB_PATH_MAX, "%s/%s", LIBSANDBOX_PATH, LIB_NAME);
31 if (0 >= exists(path)) { 48 if (!rc_file_exists(path)) {
32 snprintf(path, SB_PATH_MAX, "%s", LIB_NAME); 49 snprintf(path, SB_PATH_MAX, "%s", LIB_NAME);
33 } 50 }
34#endif 51#endif
35} 52}
36
37#ifdef OUTSIDE_LIBSANDBOX
38 53
39void get_sandbox_rc(char *path) 54void get_sandbox_rc(char *path)
40{ 55{
41 snprintf(path, SB_PATH_MAX, "%s/%s", SANDBOX_BASHRC_PATH, BASHRC_NAME); 56 snprintf(path, SB_PATH_MAX, "%s/%s", SANDBOX_BASHRC_PATH, BASHRC_NAME);
42} 57}
91 } 106 }
92 107
93 return 0; 108 return 0;
94} 109}
95 110
96#endif /* OUTSIDE_LIBSANDBOX */
97
98int exists(const char *pathname)
99{
100 struct stat buf;
101 int retval;
102
103 if ((NULL == pathname) || (0 == strlen(pathname)))
104 return 0;
105
106 retval = lstat(pathname, &buf);
107 if (-1 != retval)
108 return 1;
109 /* Some or other error occurred */
110 if (ENOENT != errno)
111 return -1;
112
113 return 0;
114}
115
116#ifdef OUTSIDE_LIBSANDBOX
117
118int is_file(const char *pathname)
119{
120 struct stat buf;
121 int retval;
122
123 if ((NULL == pathname) || (0 == strlen(pathname)))
124 return 0;
125
126 retval = lstat(pathname, &buf);
127 if ((-1 != retval) && (S_ISREG(buf.st_mode)))
128 return 1;
129 /* Some or other error occurred */
130 if ((-1 == retval) && (ENOENT != errno))
131 return -1;
132
133 return 0;
134}
135
136int is_dir(const char *pathname, int follow_link)
137{
138 struct stat buf;
139 int retval;
140
141 if ((NULL == pathname) || (0 == strlen(pathname)))
142 return 0;
143
144 retval = follow_link ? stat(pathname, &buf) : lstat(pathname, &buf);
145 if ((-1 != retval) && (S_ISDIR(buf.st_mode)))
146 return 1;
147 /* Some or other error occurred */
148 if ((-1 == retval) && (ENOENT != errno))
149 return -1;
150
151 return 0;
152}
153
154long file_length(int fd) 111long file_length(int fd)
155{ 112{
156 struct stat st; 113 struct stat st;
157 int retval; 114 int retval;
158 115
161 return 0; 118 return 0;
162 119
163 return (st.st_size); 120 return (st.st_size);
164} 121}
165 122
166#endif /* OUTSIDE_LIBSANDBOX */ 123bool is_env_on (const char *env)
124{
125 if ((NULL != env) && (NULL != getenv(env)) &&
126 ((0 == strncasecmp(getenv(env), "1", 1)) ||
127 (0 == strncasecmp(getenv(env), "true", 4)) ||
128 (0 == strncasecmp(getenv(env), "yes", 3))))
129 return TRUE;
130
131 return FALSE;
132}
133
134bool is_env_off (const char *env)
135{
136 if ((NULL != env) && (NULL != getenv(env)) &&
137 ((0 == strncasecmp(getenv(env), "0", 1)) ||
138 (0 == strncasecmp(getenv(env), "false", 5)) ||
139 (0 == strncasecmp(getenv(env), "no", 2))))
140 return TRUE;
141
142 return FALSE;
143}
167 144
168 145
169// vim:noexpandtab noai:cindent ai 146// vim:noexpandtab noai:cindent ai

Legend:
Removed from v.196  
changed lines
  Added in v.309

  ViewVC Help
Powered by ViewVC 1.1.20