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

Contents of /trunk/libsbutil/get_sandbox_lib.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 309 - (hide annotations) (download) (as text)
Sun Jul 9 19:13:57 2006 UTC (12 years, 1 month ago) by azarah
Original Path: trunk/libsbutil/sbutil.c
File MIME type: text/x-csrc
File size: 3572 byte(s)
As we are using a symbol map for libsandbox, its no longer needed
to have all the internal functions static, and thus we can break
things out a bit and make the source layout more sane.  Start by
moving librcutil to libsbutil, and adding all the defines and
helper functions needed by both libsandbox and sandbox.

1 ferringb 2 /*
2 azarah 309 * sbutil.c
3 ferringb 2 *
4 azarah 309 * 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     *
24     * Copyright (C) 2002 Brad House <brad@mainstreetsoftworks.com>
25     *
26 ferringb 2 * $Header$
27     */
28    
29 azarah 309
30 ferringb 2 #include <errno.h>
31     #include <stdio.h>
32     #include <stdlib.h>
33     #include <limits.h>
34     #include <string.h>
35     #include <sys/stat.h>
36     #include <unistd.h>
37     #include <fcntl.h>
38 azarah 139 #include <libgen.h>
39 ferringb 2
40 azarah 309 #include "sbutil.h"
41 ferringb 2
42 azarah 189 void get_sandbox_lib(char *path)
43 ferringb 2 {
44 azarah 181 #ifdef SB_HAVE_MULTILIB
45 azarah 140 snprintf(path, SB_PATH_MAX, "%s", LIB_NAME);
46 ferringb 2 #else
47 azarah 140 snprintf(path, SB_PATH_MAX, "%s/%s", LIBSANDBOX_PATH, LIB_NAME);
48 azarah 282 if (!rc_file_exists(path)) {
49 azarah 140 snprintf(path, SB_PATH_MAX, "%s", LIB_NAME);
50 ferringb 2 }
51     #endif
52     }
53    
54 azarah 189 void get_sandbox_rc(char *path)
55 ferringb 2 {
56 azarah 140 snprintf(path, SB_PATH_MAX, "%s/%s", SANDBOX_BASHRC_PATH, BASHRC_NAME);
57 ferringb 2 }
58    
59 azarah 189 void get_sandbox_log(char *path)
60 ferringb 2 {
61     char *sandbox_log_env = NULL;
62    
63 azarah 97 sandbox_log_env = getenv(ENV_SANDBOX_LOG);
64    
65 ferringb 2 /* THIS CHUNK BREAK THINGS BY DOING THIS:
66     * SANDBOX_LOG=/tmp/sandbox-app-admin/superadduser-1.0.7-11063.log
67     */
68 azarah 97 if ((NULL != sandbox_log_env) &&
69     (NULL != strchr(sandbox_log_env, '/')))
70     sandbox_log_env = NULL;
71 ferringb 2
72 azarah 140 snprintf(path, SB_PATH_MAX, "%s%s%s%s%d%s",
73 azarah 134 SANDBOX_LOG_LOCATION, LOG_FILE_PREFIX,
74 azarah 99 (sandbox_log_env == NULL ? "" : sandbox_log_env),
75     (sandbox_log_env == NULL ? "" : "-"),
76     getpid(), LOG_FILE_EXT);
77 ferringb 2 }
78    
79 azarah 189 void get_sandbox_debug_log(char *path)
80 azarah 101 {
81 azarah 97 char *sandbox_debug_log_env = NULL;
82    
83     sandbox_debug_log_env = getenv(ENV_SANDBOX_DEBUG_LOG);
84    
85     /* THIS CHUNK BREAK THINGS BY DOING THIS:
86     * SANDBOX_DEBUG_LOG=/tmp/sandbox-app-admin/superadduser-1.0.7-11063.log
87     */
88     if ((NULL != sandbox_debug_log_env) &&
89     (NULL != strchr(sandbox_debug_log_env, '/')))
90     sandbox_debug_log_env = NULL;
91    
92 azarah 140 snprintf(path, SB_PATH_MAX, "%s%s%s%s%d%s",
93 azarah 134 SANDBOX_LOG_LOCATION, DEBUG_LOG_FILE_PREFIX,
94 azarah 99 (sandbox_debug_log_env == NULL ? "" : sandbox_debug_log_env),
95     (sandbox_debug_log_env == NULL ? "" : "-"),
96     getpid(), LOG_FILE_EXT);
97 azarah 97 }
98    
99 azarah 189 int get_tmp_dir(char *path)
100 ferringb 2 {
101 azarah 139 if (NULL == realpath(getenv(ENV_TMPDIR) ? getenv(ENV_TMPDIR)
102     : TMPDIR,
103 azarah 140 path)) {
104     if (NULL == realpath(TMPDIR, path))
105 azarah 139 return -1;
106 ferringb 2 }
107    
108 azarah 139 return 0;
109 ferringb 2 }
110    
111 azarah 189 long file_length(int fd)
112 ferringb 2 {
113 azarah 195 struct stat st;
114     int retval;
115 azarah 139
116 azarah 195 retval = fstat(fd, &st);
117 azarah 196 if (-1 == retval)
118 azarah 195 return 0;
119 azarah 139
120 azarah 195 return (st.st_size);
121 ferringb 2 }
122    
123 azarah 260 bool is_env_on (const char *env)
124     {
125     if ((NULL != env) && (NULL != getenv(env)) &&
126     ((0 == strncasecmp(getenv(env), "1", 1)) ||
127 azarah 263 (0 == strncasecmp(getenv(env), "true", 4)) ||
128 azarah 260 (0 == strncasecmp(getenv(env), "yes", 3))))
129 azarah 280 return TRUE;
130 azarah 260
131 azarah 280 return FALSE;
132 azarah 260 }
133    
134 azarah 263 bool 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 azarah 280 return TRUE;
141 azarah 263
142 azarah 280 return FALSE;
143 azarah 263 }
144    
145 azarah 280
146 azarah 30 // vim:noexpandtab noai:cindent ai

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.20