summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Kaivo <jkk@ung.org>2021-02-01 09:30:11 -0500
committerJakob Kaivo <jkk@ung.org>2021-02-01 09:30:11 -0500
commit60e2d482e83b15af98a0a0079e1654b2bf12a1cd (patch)
treed41de8f1fbad09a510eb10360f18c0577483a2f7
parente0b68d2c59184e309ac4c2bd5fd73abd7127f2ab (diff)
the setuid part
-rw-r--r--exec/Makefile26
-rw-r--r--exec/exec.c22
2 files changed, 48 insertions, 0 deletions
diff --git a/exec/Makefile b/exec/Makefile
new file mode 100644
index 0000000..eb98c60
--- /dev/null
+++ b/exec/Makefile
@@ -0,0 +1,26 @@
+.POSIX:
+
+# This Makefile was generated by maje
+# See https://gitlab.com/jkaivo/maje/ for more information
+# Do not edit this Makefile by hand
+
+CC=c99
+LD=$(CC)
+CFLAGS=-Wall -Wextra -Wpedantic -Werror -g
+LDFLAGS=
+LDLIBS=
+SRCDIR=.
+OBJDIR=.
+BINDIR=$(OBJDIR)
+
+all: $(BINDIR)/exec
+
+clean:
+ rm -f $(BINDIR)/exec $(OBJDIR)/*.o
+
+$(BINDIR)/exec: $(OBJDIR)/exec.o
+$(OBJDIR)/exec.o: $(SRCDIR)/exec.c
+ $(CC) $(CFLAGS) -o $@ -c $(SRCDIR)/exec.c
+
+$(BINDIR)/exec:
+ $(LD) $(LDFLAGS) -o $@ $(OBJDIR)/*.o $(LDLIBS)
diff --git a/exec/exec.c b/exec/exec.c
new file mode 100644
index 0000000..f3ee85e
--- /dev/null
+++ b/exec/exec.c
@@ -0,0 +1,22 @@
+#define _POSIX_SOURCE
+#include <errno.h>
+#include <stdio.h>
+#include <unistd.h>
+
+#define NOT_RUN (126)
+#define NOT_FOUND (127)
+
+int main(int argc, char *argv[])
+{
+ if (argc < 2 || argv == NULL) {
+ fprintf(stderr, "%s: missing operands\n", argv[0]);
+ return NOT_RUN;
+ }
+
+ execv(argv[1], argv + 1);
+ perror(argv[0]);
+ if (errno == ENOENT) {
+ return NOT_FOUND;
+ }
+ return NOT_RUN;
+}