/[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 196 - (hide annotations) (download) (as text)
Thu Dec 1 11:33:20 2005 UTC (12 years, 7 months ago) by azarah
Original Path: trunk/src/sandbox_futils.c
File MIME type: text/x-csrc
File size: 3502 byte(s)
Wrap mknod() as well.  Misc cleanups.
1 ferringb 2 /*
2     * 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     *
6     * $Header$
7     *
8     */
9    
10     #include <errno.h>
11     #include <stdio.h>
12     #include <stdlib.h>
13     #include <limits.h>
14     #include <string.h>
15     #include <sys/stat.h>
16     #include <unistd.h>
17     #include <fcntl.h>
18 azarah 139 #include <libgen.h>
19 ferringb 2
20 ferringb 13 #include "config.h"
21 azarah 191 #include "localdecls.h"
22 ferringb 2
23 azarah 191 #include "sandbox.h"
24 ferringb 2
25 azarah 189 void get_sandbox_lib(char *path)
26 ferringb 2 {
27 azarah 181 #ifdef SB_HAVE_MULTILIB
28 azarah 140 snprintf(path, SB_PATH_MAX, "%s", LIB_NAME);
29 ferringb 2 #else
30 azarah 140 snprintf(path, SB_PATH_MAX, "%s/%s", LIBSANDBOX_PATH, LIB_NAME);
31 azarah 139 if (0 >= exists(path)) {
32 azarah 140 snprintf(path, SB_PATH_MAX, "%s", LIB_NAME);
33 ferringb 2 }
34     #endif
35     }
36    
37 azarah 143 #ifdef OUTSIDE_LIBSANDBOX
38    
39 azarah 189 void get_sandbox_rc(char *path)
40 ferringb 2 {
41 azarah 140 snprintf(path, SB_PATH_MAX, "%s/%s", SANDBOX_BASHRC_PATH, BASHRC_NAME);
42 ferringb 2 }
43    
44 azarah 189 void get_sandbox_log(char *path)
45 ferringb 2 {
46     char *sandbox_log_env = NULL;
47    
48 azarah 97 sandbox_log_env = getenv(ENV_SANDBOX_LOG);
49    
50 ferringb 2 /* THIS CHUNK BREAK THINGS BY DOING THIS:
51     * SANDBOX_LOG=/tmp/sandbox-app-admin/superadduser-1.0.7-11063.log
52     */
53 azarah 97 if ((NULL != sandbox_log_env) &&
54     (NULL != strchr(sandbox_log_env, '/')))
55     sandbox_log_env = NULL;
56 ferringb 2
57 azarah 140 snprintf(path, SB_PATH_MAX, "%s%s%s%s%d%s",
58 azarah 134 SANDBOX_LOG_LOCATION, LOG_FILE_PREFIX,
59 azarah 99 (sandbox_log_env == NULL ? "" : sandbox_log_env),
60     (sandbox_log_env == NULL ? "" : "-"),
61     getpid(), LOG_FILE_EXT);
62 ferringb 2 }
63    
64 azarah 189 void get_sandbox_debug_log(char *path)
65 azarah 101 {
66 azarah 97 char *sandbox_debug_log_env = NULL;
67    
68     sandbox_debug_log_env = getenv(ENV_SANDBOX_DEBUG_LOG);
69    
70     /* THIS CHUNK BREAK THINGS BY DOING THIS:
71     * SANDBOX_DEBUG_LOG=/tmp/sandbox-app-admin/superadduser-1.0.7-11063.log
72     */
73     if ((NULL != sandbox_debug_log_env) &&
74     (NULL != strchr(sandbox_debug_log_env, '/')))
75     sandbox_debug_log_env = NULL;
76    
77 azarah 140 snprintf(path, SB_PATH_MAX, "%s%s%s%s%d%s",
78 azarah 134 SANDBOX_LOG_LOCATION, DEBUG_LOG_FILE_PREFIX,
79 azarah 99 (sandbox_debug_log_env == NULL ? "" : sandbox_debug_log_env),
80     (sandbox_debug_log_env == NULL ? "" : "-"),
81     getpid(), LOG_FILE_EXT);
82 azarah 97 }
83    
84 azarah 189 int get_tmp_dir(char *path)
85 ferringb 2 {
86 azarah 139 if (NULL == realpath(getenv(ENV_TMPDIR) ? getenv(ENV_TMPDIR)
87     : TMPDIR,
88 azarah 140 path)) {
89     if (NULL == realpath(TMPDIR, path))
90 azarah 139 return -1;
91 ferringb 2 }
92    
93 azarah 139 return 0;
94 ferringb 2 }
95    
96 azarah 143 #endif /* OUTSIDE_LIBSANDBOX */
97    
98 azarah 189 int exists(const char *pathname)
99 ferringb 2 {
100 azarah 139 struct stat buf;
101     int retval;
102 ferringb 2
103 azarah 139 if ((NULL == pathname) || (0 == strlen(pathname)))
104     return 0;
105 ferringb 2
106 azarah 139 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 ferringb 2
113 azarah 139 return 0;
114 ferringb 2 }
115    
116 azarah 143 #ifdef OUTSIDE_LIBSANDBOX
117    
118 azarah 189 int is_file(const char *pathname)
119 ferringb 2 {
120 azarah 139 struct stat buf;
121     int retval;
122 ferringb 2
123 azarah 139 if ((NULL == pathname) || (0 == strlen(pathname)))
124 ferringb 2 return 0;
125    
126 azarah 139 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 ferringb 2
133 azarah 139 return 0;
134 ferringb 2 }
135    
136 azarah 189 int is_dir(const char *pathname, int follow_link)
137 azarah 152 {
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    
154 azarah 189 long file_length(int fd)
155 ferringb 2 {
156 azarah 195 struct stat st;
157     int retval;
158 azarah 139
159 azarah 195 retval = fstat(fd, &st);
160 azarah 196 if (-1 == retval)
161 azarah 195 return 0;
162 azarah 139
163 azarah 195 return (st.st_size);
164 ferringb 2 }
165    
166 azarah 143 #endif /* OUTSIDE_LIBSANDBOX */
167 ferringb 2
168 azarah 143
169 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