char* get_executable_file() { return symlink_target("/proc/self/exe"); }
int check_pkg_symlinks(struct xbps_handle *xhp, const char *pkgname, void *arg) { xbps_array_t array; xbps_object_t obj; xbps_dictionary_t filesd = arg; unsigned int i; const char *file, *tgt = NULL; char *path, *p, *buf, *buf2, *lnk, *dname, *tgt_path; int rv; bool broken = false; array = xbps_dictionary_get(filesd, "links"); if (array == NULL) return false; for (i = 0; i < xbps_array_count(array); i++) { obj = xbps_array_get(array, i); if (!xbps_dictionary_get_cstring_nocopy(obj, "target", &tgt)) { xbps_warn_printf("%s: `%s' symlink with " "empty target object!\n", pkgname, file); continue; } xbps_dictionary_get_cstring_nocopy(obj, "file", &file); if (strcmp(tgt, "") == 0) { xbps_warn_printf("%s: `%s' symlink with " "empty target object!\n", pkgname, file); continue; } if (strcmp(xhp->rootdir, "/")) { tgt_path = xbps_xasprintf("%s%s", xhp->rootdir, tgt); path = xbps_xasprintf("%s%s", xhp->rootdir, file); } else { path = strdup(file); tgt_path = strdup(tgt); } lnk = symlink_target(pkgname, path); if (lnk == NULL) { free(tgt_path); free(path); continue; } p = strdup(path); assert(p); dname = dirname(p); buf = xbps_xasprintf("%s/%s", dname, lnk); buf2 = realpath(path, NULL); if (buf2 == NULL) { xbps_warn_printf("%s: broken symlink %s (target: %s)\n", pkgname, file, tgt); free(path); free(tgt_path); free(p); free(buf); free(lnk); continue; } rv = 1; if (lnk[0] != '/') { /* relative symlink */ if ((strcmp(lnk, tgt) == 0) || (strcmp(buf, tgt_path) == 0) || (strcmp(buf2, tgt_path) == 0)) rv = 0; } else { /* absolute symlink */ if (strcmp(lnk, tgt) == 0) rv = 0; } if (rv) { xbps_warn_printf("%s: modified symlink %s " "points to %s (shall be %s)\n", pkgname, file, lnk, tgt); broken = true; } free(p); free(buf); free(path); free(tgt_path); free(lnk); } return broken; }