/[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 152 - (hide annotations) (download) (as text)
Wed Jul 27 18:04:35 2005 UTC (13 years, 2 months ago) by azarah
Original Path: trunk/sandbox_futils.c
File MIME type: text/x-csrc
File size: 3664 byte(s)
Do not resolve symlinks in PORTAGE_TMPDIR in sandbox .. we will handle that
in libsandbox .. bug #100309.

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     #include "sandbox.h"
21 ferringb 13 #include "config.h"
22 ferringb 2
23     /* glibc modified getcwd() functions */
24 azarah 43 SB_STATIC char *egetcwd(char *, size_t);
25 ferringb 2
26 azarah 140 SB_STATIC void get_sandbox_lib(char *path)
27 ferringb 2 {
28     #ifdef SB_HAVE_64BIT_ARCH
29 azarah 140 snprintf(path, SB_PATH_MAX, "%s", LIB_NAME);
30 ferringb 2 #else
31 azarah 140 snprintf(path, SB_PATH_MAX, "%s/%s", LIBSANDBOX_PATH, LIB_NAME);
32 azarah 139 if (0 >= exists(path)) {
33 azarah 140 snprintf(path, SB_PATH_MAX, "%s", LIB_NAME);
34 ferringb 2 }
35     #endif
36     }
37    
38 azarah 143 #ifdef OUTSIDE_LIBSANDBOX
39    
40 azarah 140 SB_STATIC void get_sandbox_rc(char *path)
41 ferringb 2 {
42 azarah 140 snprintf(path, SB_PATH_MAX, "%s/%s", SANDBOX_BASHRC_PATH, BASHRC_NAME);
43 ferringb 2 }
44    
45 azarah 140 SB_STATIC void get_sandbox_log(char *path)
46 ferringb 2 {
47     char *sandbox_log_env = NULL;
48    
49 azarah 97 sandbox_log_env = getenv(ENV_SANDBOX_LOG);
50    
51 ferringb 2 /* THIS CHUNK BREAK THINGS BY DOING THIS:
52     * SANDBOX_LOG=/tmp/sandbox-app-admin/superadduser-1.0.7-11063.log
53     */
54 azarah 97 if ((NULL != sandbox_log_env) &&
55     (NULL != strchr(sandbox_log_env, '/')))
56     sandbox_log_env = NULL;
57 ferringb 2
58 azarah 140 snprintf(path, SB_PATH_MAX, "%s%s%s%s%d%s",
59 azarah 134 SANDBOX_LOG_LOCATION, LOG_FILE_PREFIX,
60 azarah 99 (sandbox_log_env == NULL ? "" : sandbox_log_env),
61     (sandbox_log_env == NULL ? "" : "-"),
62     getpid(), LOG_FILE_EXT);
63 ferringb 2 }
64    
65 azarah 140 SB_STATIC void get_sandbox_debug_log(char *path)
66 azarah 101 {
67 azarah 97 char *sandbox_debug_log_env = NULL;
68    
69     sandbox_debug_log_env = getenv(ENV_SANDBOX_DEBUG_LOG);
70    
71     /* THIS CHUNK BREAK THINGS BY DOING THIS:
72     * SANDBOX_DEBUG_LOG=/tmp/sandbox-app-admin/superadduser-1.0.7-11063.log
73     */
74     if ((NULL != sandbox_debug_log_env) &&
75     (NULL != strchr(sandbox_debug_log_env, '/')))
76     sandbox_debug_log_env = NULL;
77    
78 azarah 140 snprintf(path, SB_PATH_MAX, "%s%s%s%s%d%s",
79 azarah 134 SANDBOX_LOG_LOCATION, DEBUG_LOG_FILE_PREFIX,
80 azarah 99 (sandbox_debug_log_env == NULL ? "" : sandbox_debug_log_env),
81     (sandbox_debug_log_env == NULL ? "" : "-"),
82     getpid(), LOG_FILE_EXT);
83 azarah 97 }
84    
85 azarah 140 SB_STATIC int get_tmp_dir(char *path)
86 ferringb 2 {
87 azarah 139 if (NULL == realpath(getenv(ENV_TMPDIR) ? getenv(ENV_TMPDIR)
88     : TMPDIR,
89 azarah 140 path)) {
90     if (NULL == realpath(TMPDIR, path))
91 azarah 139 return -1;
92 ferringb 2 }
93    
94 azarah 139 return 0;
95 ferringb 2 }
96    
97 azarah 143 #endif /* OUTSIDE_LIBSANDBOX */
98    
99 azarah 139 SB_STATIC int exists(const char *pathname)
100 ferringb 2 {
101 azarah 139 struct stat buf;
102     int retval;
103 ferringb 2
104 azarah 139 if ((NULL == pathname) || (0 == strlen(pathname)))
105     return 0;
106 ferringb 2
107 azarah 139 retval = lstat(pathname, &buf);
108     if (-1 != retval)
109     return 1;
110     /* Some or other error occurred */
111     if (ENOENT != errno)
112     return -1;
113 ferringb 2
114 azarah 139 return 0;
115 ferringb 2 }
116    
117 azarah 143 #ifdef OUTSIDE_LIBSANDBOX
118    
119 azarah 139 SB_STATIC int is_file(const char *pathname)
120 ferringb 2 {
121 azarah 139 struct stat buf;
122     int retval;
123 ferringb 2
124 azarah 139 if ((NULL == pathname) || (0 == strlen(pathname)))
125 ferringb 2 return 0;
126    
127 azarah 139 retval = lstat(pathname, &buf);
128     if ((-1 != retval) && (S_ISREG(buf.st_mode)))
129     return 1;
130     /* Some or other error occurred */
131     if ((-1 == retval) && (ENOENT != errno))
132     return -1;
133 ferringb 2
134 azarah 139 return 0;
135 ferringb 2 }
136    
137 azarah 152 SB_STATIC int is_dir(const char *pathname, int follow_link)
138     {
139     struct stat buf;
140     int retval;
141    
142     if ((NULL == pathname) || (0 == strlen(pathname)))
143     return 0;
144    
145     retval = follow_link ? stat(pathname, &buf) : lstat(pathname, &buf);
146     if ((-1 != retval) && (S_ISDIR(buf.st_mode)))
147     return 1;
148     /* Some or other error occurred */
149     if ((-1 == retval) && (ENOENT != errno))
150     return -1;
151    
152     return 0;
153     }
154    
155 azarah 43 SB_STATIC long file_length(int fd)
156 ferringb 2 {
157     long pos, len;
158 azarah 139
159     pos = lseek(fd, 0L, SEEK_CUR);
160 ferringb 2 len = lseek(fd, 0L, SEEK_END);
161     lseek(fd, pos, SEEK_SET);
162 azarah 139
163 ferringb 2 return (len);
164     }
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