aboutsummaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
authorRyan Mallon <rmallon@gmail.com>2013-10-08 14:52:49 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2013-10-08 14:52:49 +0200
commit5906a5c26c392b9687d14951a6da3a5195b576be (patch)
tree0f7038d653988cb63f9efe431b9e6674173f60d1 /libbb
parent932e233a491b6a5b9293ace04ef74667a95d739c (diff)
downloadbusybox-w32-5906a5c26c392b9687d14951a6da3a5195b576be.tar.gz
busybox-w32-5906a5c26c392b9687d14951a6da3a5195b576be.tar.bz2
busybox-w32-5906a5c26c392b9687d14951a6da3a5195b576be.zip
libbb: Add xsetegid(), xseteuid(), xopen_as_uid_gid() functions
Signed-off-by: Ryan Mallon <rmallon@gmail.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb')
-rw-r--r--libbb/xfuncs_printf.c45
1 files changed, 36 insertions, 9 deletions
diff --git a/libbb/xfuncs_printf.c b/libbb/xfuncs_printf.c
index a70683241..e4ac6a002 100644
--- a/libbb/xfuncs_printf.c
+++ b/libbb/xfuncs_printf.c
@@ -140,15 +140,6 @@ int FAST_FUNC xopen(const char *pathname, int flags)
140 return xopen3(pathname, flags, 0666); 140 return xopen3(pathname, flags, 0666);
141} 141}
142 142
143/* Die if we can't open an existing file readonly with O_NONBLOCK
144 * and return the fd.
145 * Note that for ioctl O_RDONLY is sufficient.
146 */
147int FAST_FUNC xopen_nonblocking(const char *pathname)
148{
149 return xopen(pathname, O_RDONLY | O_NONBLOCK);
150}
151
152// Warn if we can't open a file and return a fd. 143// Warn if we can't open a file and return a fd.
153int FAST_FUNC open3_or_warn(const char *pathname, int flags, int mode) 144int FAST_FUNC open3_or_warn(const char *pathname, int flags, int mode)
154{ 145{
@@ -167,6 +158,32 @@ int FAST_FUNC open_or_warn(const char *pathname, int flags)
167 return open3_or_warn(pathname, flags, 0666); 158 return open3_or_warn(pathname, flags, 0666);
168} 159}
169 160
161/* Die if we can't open an existing file readonly with O_NONBLOCK
162 * and return the fd.
163 * Note that for ioctl O_RDONLY is sufficient.
164 */
165int FAST_FUNC xopen_nonblocking(const char *pathname)
166{
167 return xopen(pathname, O_RDONLY | O_NONBLOCK);
168}
169
170int FAST_FUNC xopen_as_uid_gid(const char *pathname, int flags, uid_t u, gid_t g)
171{
172 int fd;
173 uid_t old_euid = geteuid();
174 gid_t old_egid = getegid();
175
176 xsetegid(g);
177 xseteuid(u);
178
179 fd = xopen(pathname, flags);
180
181 xseteuid(old_euid);
182 xsetegid(old_egid);
183
184 return fd;
185}
186
170void FAST_FUNC xunlink(const char *pathname) 187void FAST_FUNC xunlink(const char *pathname)
171{ 188{
172 if (unlink(pathname)) 189 if (unlink(pathname))
@@ -351,6 +368,16 @@ void FAST_FUNC xsetuid(uid_t uid)
351 if (setuid(uid)) bb_perror_msg_and_die("setuid"); 368 if (setuid(uid)) bb_perror_msg_and_die("setuid");
352} 369}
353 370
371void FAST_FUNC xsetegid(gid_t egid)
372{
373 if (setegid(egid)) bb_perror_msg_and_die("setegid");
374}
375
376void FAST_FUNC xseteuid(uid_t euid)
377{
378 if (seteuid(euid)) bb_perror_msg_and_die("seteuid");
379}
380
354// Die if we can't chdir to a new path. 381// Die if we can't chdir to a new path.
355void FAST_FUNC xchdir(const char *path) 382void FAST_FUNC xchdir(const char *path)
356{ 383{