/[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 141 - (show annotations) (download) (as text)
Thu Jul 7 22:08:17 2005 UTC (13 years, 2 months ago) by azarah
Original Path: trunk/sandbox_futils.c
File MIME type: text/x-csrc
File size: 3446 byte(s)
Remove sandbox_dir and co - we are not using it anymore.
1 /*
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 <fcntl.h>
12 #include <signal.h>
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include <limits.h>
16 #include <string.h>
17 #include <stdarg.h>
18 #include <sys/file.h>
19 #include <sys/stat.h>
20 #include <sys/time.h>
21 #include <sys/types.h>
22 #include <sys/resource.h>
23 #include <sys/wait.h>
24 #include <unistd.h>
25 #include <fcntl.h>
26 #include <libgen.h>
27
28 #include <grp.h>
29 #include <pwd.h>
30
31 #include "sandbox.h"
32 #include "config.h"
33
34 /* glibc modified getcwd() functions */
35 SB_STATIC char *egetcwd(char *, size_t);
36
37 SB_STATIC void get_sandbox_lib(char *path)
38 {
39 #ifdef SB_HAVE_64BIT_ARCH
40 snprintf(path, SB_PATH_MAX, "%s", LIB_NAME);
41 #else
42 snprintf(path, SB_PATH_MAX, "%s/%s", LIBSANDBOX_PATH, LIB_NAME);
43 if (0 >= exists(path)) {
44 snprintf(path, SB_PATH_MAX, "%s", LIB_NAME);
45 }
46 #endif
47 }
48
49 SB_STATIC void get_sandbox_rc(char *path)
50 {
51 snprintf(path, SB_PATH_MAX, "%s/%s", SANDBOX_BASHRC_PATH, BASHRC_NAME);
52 if (0 >= exists(path)) {
53 perror(">>> cannot open bashrc");
54 exit(EXIT_FAILURE);
55 }
56 }
57
58 SB_STATIC void get_sandbox_log(char *path)
59 {
60 char *sandbox_log_env = NULL;
61
62 sandbox_log_env = getenv(ENV_SANDBOX_LOG);
63
64 /* THIS CHUNK BREAK THINGS BY DOING THIS:
65 * SANDBOX_LOG=/tmp/sandbox-app-admin/superadduser-1.0.7-11063.log
66 */
67 if ((NULL != sandbox_log_env) &&
68 (NULL != strchr(sandbox_log_env, '/')))
69 sandbox_log_env = NULL;
70
71 snprintf(path, SB_PATH_MAX, "%s%s%s%s%d%s",
72 SANDBOX_LOG_LOCATION, LOG_FILE_PREFIX,
73 (sandbox_log_env == NULL ? "" : sandbox_log_env),
74 (sandbox_log_env == NULL ? "" : "-"),
75 getpid(), LOG_FILE_EXT);
76 }
77
78 SB_STATIC void get_sandbox_debug_log(char *path)
79 {
80 char *sandbox_debug_log_env = NULL;
81
82 sandbox_debug_log_env = getenv(ENV_SANDBOX_DEBUG_LOG);
83
84 /* THIS CHUNK BREAK THINGS BY DOING THIS:
85 * SANDBOX_DEBUG_LOG=/tmp/sandbox-app-admin/superadduser-1.0.7-11063.log
86 */
87 if ((NULL != sandbox_debug_log_env) &&
88 (NULL != strchr(sandbox_debug_log_env, '/')))
89 sandbox_debug_log_env = NULL;
90
91 snprintf(path, SB_PATH_MAX, "%s%s%s%s%d%s",
92 SANDBOX_LOG_LOCATION, DEBUG_LOG_FILE_PREFIX,
93 (sandbox_debug_log_env == NULL ? "" : sandbox_debug_log_env),
94 (sandbox_debug_log_env == NULL ? "" : "-"),
95 getpid(), LOG_FILE_EXT);
96 }
97
98 SB_STATIC int get_tmp_dir(char *path)
99 {
100 if (NULL == realpath(getenv(ENV_TMPDIR) ? getenv(ENV_TMPDIR)
101 : TMPDIR,
102 path)) {
103 if (NULL == realpath(TMPDIR, path))
104 return -1;
105 }
106
107 return 0;
108 }
109
110 SB_STATIC int exists(const char *pathname)
111 {
112 struct stat buf;
113 int retval;
114
115 if ((NULL == pathname) || (0 == strlen(pathname)))
116 return 0;
117
118 retval = lstat(pathname, &buf);
119 if (-1 != retval)
120 return 1;
121 /* Some or other error occurred */
122 if (ENOENT != errno)
123 return -1;
124
125 return 0;
126 }
127
128 SB_STATIC int is_file(const char *pathname)
129 {
130 struct stat buf;
131 int retval;
132
133 if ((NULL == pathname) || (0 == strlen(pathname)))
134 return 0;
135
136 retval = lstat(pathname, &buf);
137 if ((-1 != retval) && (S_ISREG(buf.st_mode)))
138 return 1;
139 /* Some or other error occurred */
140 if ((-1 == retval) && (ENOENT != errno))
141 return -1;
142
143 return 0;
144 }
145
146 SB_STATIC long file_length(int fd)
147 {
148 long pos, len;
149
150 pos = lseek(fd, 0L, SEEK_CUR);
151 len = lseek(fd, 0L, SEEK_END);
152 lseek(fd, pos, SEEK_SET);
153
154 return (len);
155 }
156
157
158 // 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