aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2010-01-05 12:17:05 -0600
committerRob Landley <rob@landley.net>2010-01-05 12:17:05 -0600
commite0377fb294821a68112d4da09f836ac42e3d5956 (patch)
tree489d2a2b21393f7283870c2f21ed82b5818f1d82 /lib
parent1e01cd1f48bff3fdd12f45bf1c3adfab821ee287 (diff)
downloadtoybox-e0377fb294821a68112d4da09f836ac42e3d5956.tar.gz
Add TOYBOX_SUID.
Diffstat (limited to 'lib')
-rw-r--r--lib/lib.c10
-rw-r--r--lib/lib.h1
2 files changed, 11 insertions, 0 deletions
diff --git a/lib/lib.c b/lib/lib.c
index 48689d3d..08c991dd 100644
--- a/lib/lib.c
+++ b/lib/lib.c
@@ -369,6 +369,16 @@ void xmkpath(char *path, int mode)
if (!*p) break;
}
}
+
+// setuid() can fail (for example, too many processes belonging to that user),
+// which opens a security hole if the process continues as the original user.
+
+void xsetuid(uid_t uid)
+{
+ if (setuid(uid)) perror_exit("xsetuid");
+}
+
+
// Find all file in a colon-separated path with access type "type" (generally
// X_OK or R_OK). Returns a list of absolute paths to each file found, in
// order.
diff --git a/lib/lib.h b/lib/lib.h
index c6226aae..fb2215cf 100644
--- a/lib/lib.h
+++ b/lib/lib.h
@@ -81,6 +81,7 @@ void xstat(char *path, struct stat *st);
char *xabspath(char *path);
void xchdir(char *path);
void xmkpath(char *path, int mode);
+void xsetuid(uid_t uid);
struct string_list *find_in_path(char *path, char *filename);
void utoa_to_buf(unsigned n, char *buf, unsigned buflen);
void itoa_to_buf(int n, char *buf, unsigned buflen);