summaryrefslogtreecommitdiff
path: root/data/ld64
diff options
context:
space:
mode:
authorSam Bingner <sam@bingner.com>2018-10-15 11:20:05 -1000
committerSam Bingner <sam@bingner.com>2018-10-15 11:20:05 -1000
commitb02648341a24191aef60ef3a8bd3bcf99d5cce52 (patch)
tree5e85bdd8c78ba9d33c177bad401510259c0c2cd2 /data/ld64
parent24f6d59354df69788c96f26e8c046a50c383c886 (diff)
Update odcctools and ld64 to add ents automatically on phone and fix version of ldid and name of gnupg
Diffstat (limited to 'data/ld64')
l---------data/ld64/_metadata/ldid.dep1
-rw-r--r--data/ld64/make.sh6
-rw-r--r--data/ld64/wrapper.c64
3 files changed, 71 insertions, 0 deletions
diff --git a/data/ld64/_metadata/ldid.dep b/data/ld64/_metadata/ldid.dep
new file mode 120000
index 000000000..3dd0689cb
--- /dev/null
+++ b/data/ld64/_metadata/ldid.dep
@@ -0,0 +1 @@
+../../ldid \ No newline at end of file
diff --git a/data/ld64/make.sh b/data/ld64/make.sh
index 831f083f4..35f143104 100644
--- a/data/ld64/make.sh
+++ b/data/ld64/make.sh
@@ -1,4 +1,10 @@
pkg:setup
pkg:make
pkg:install
+pkg: mv /usr/bin/ld64 /usr/bin/ld64_
pkg: ln -s ld64 /usr/bin/ld
+pkg: "${PKG_TARG}-gcc" %/wrapper.c -o /usr/bin/ld64
+if [[ -f "${PKG_BASE}/arch/${PKG_ARCH}/${PKG_CFTARG}/entitlement.xml" ]]; then
+ pkg: mkdir -p /usr/share/ldid
+ cp "${PKG_BASE}/arch/${PKG_ARCH}/${PKG_CFTARG}/entitlement.xml" "${PKG_DEST}/usr/share/ldid/entitlements.xml"
+fi
diff --git a/data/ld64/wrapper.c b/data/ld64/wrapper.c
new file mode 100644
index 000000000..e6721a25d
--- /dev/null
+++ b/data/ld64/wrapper.c
@@ -0,0 +1,64 @@
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+#define LDID "/usr/bin/ldid"
+#define ENTS "/usr/share/ldid/entitlements.xml"
+
+int main (int argc, char **argv) {
+ int argcont;
+ char *output;
+ for (argcont = 0; argcont < argc - 1; argcont++) {
+ if (!strcmp(argv[argcont], "-o")) {
+ output = argv[argcont + 1];
+ }
+ }
+ if (access(output, F_OK) == 0 && remove(output) == -1) {
+ fprintf(stderr, "Unable to remove existing file: %s\n", strerror(errno));
+ exit(-1);
+ }
+ extern char** environ;
+ pid_t parent = getpid();
+ pid_t pid = fork();
+ int status;
+ if (pid > 0) {
+ waitpid(pid, &status, 0);
+ } else if (pid == 0) {
+ execve("/usr/bin/ld64_", argv, environ);
+ } else {
+ fprintf(stderr, "Unable to fork: %s\n", strerror(errno));
+ exit(-1);
+ }
+ if (WEXITSTATUS(status) == 0 && access(output, R_OK|W_OK) == 0) {
+ if (access(LDID, R_OK|X_OK) != 0) {
+ fprintf(stderr, "Unable to execute ldid: %s\n", strerror(errno));
+ return status;
+ }
+ char *entitlements = getenv("ENTITLEMENTS");
+ if (entitlements == (char*)-1 || entitlements == NULL) {
+ entitlements = ENTS;
+ }
+ if (access(entitlements, R_OK) != 0) {
+ fprintf(stderr, "Entitlements at \"%s\" are not accessible: %s\n", entitlements, strerror(errno));
+ return status;
+ }
+ parent = getpid();
+ pid = fork();
+ if (pid > 0) {
+ waitpid(pid, &status, 0);
+ } else if (pid == 0) {
+ char entstr[strlen(entitlements)+3];
+ entstr[0] = '-';
+ entstr[1] = 'S';
+ strcpy(entstr+2, entitlements);
+ execl(LDID, LDID, entstr, output, NULL);
+ } else {
+ fprintf(stderr, "Unable to fork: %s\n", strerror(errno));
+ }
+ } else {
+ fprintf(stderr, "Not signing file\n");
+ }
+ return WEXITSTATUS(status);
+}