static int pack_db(const char *name, const char *archive, char *path, struct rsa_key *rsa) { struct packing *pack; unsigned char *sigret = NULL; unsigned int siglen = 0; if (packing_init(&pack, archive, TXZ) != EPKG_OK) return (EPKG_FATAL); if (rsa != NULL) { if (rsa_sign(path, rsa, &sigret, &siglen) != EPKG_OK) { packing_finish(pack); return (EPKG_FATAL); } if (packing_append_buffer(pack, sigret, "signature", siglen + 1) != EPKG_OK) { free(sigret); free(pack); return (EPKG_FATAL); } free(sigret); } packing_append_file_attr(pack, path, name, "root", "wheel", 0644); unlink(path); packing_finish(pack); return (EPKG_OK); }
int pkg_finish_repo(char *path, pem_password_cb *password_cb, char *rsa_key_path) { char repo_path[MAXPATHLEN + 1]; char repo_archive[MAXPATHLEN + 1]; struct packing *pack; unsigned char *sigret = NULL; unsigned int siglen = 0; if (!is_dir(path)) { pkg_emit_error("%s is not a directory", path); return (EPKG_FATAL); } snprintf(repo_path, sizeof(repo_path), "%s/repo.sqlite", path); snprintf(repo_archive, sizeof(repo_archive), "%s/repo", path); packing_init(&pack, repo_archive, TXZ); if (rsa_key_path != NULL) { rsa_sign(repo_path, password_cb, rsa_key_path, &sigret, &siglen); packing_append_buffer(pack, sigret, "signature", siglen + 1); free(sigret); } packing_append_file_attr(pack, repo_path, "repo.sqlite", "root", "wheel", 0644); unlink(repo_path); packing_finish(pack); return (EPKG_OK); }
int pkg_finish_repo(char *path, pem_password_cb *password_cb, char *rsa_key_path) { char repo_path[MAXPATHLEN + 1]; char repo_archive[MAXPATHLEN + 1]; struct packing *pack; int max_len = 0; unsigned char *sigret = NULL; int siglen = 0; RSA *rsa = NULL; char sha256[SHA256_DIGEST_LENGTH * 2 +1]; snprintf(repo_path, sizeof(repo_path), "%s/repo.sqlite", path); snprintf(repo_archive, sizeof(repo_archive), "%s/repo", path); packing_init(&pack, repo_archive, TXZ); if (rsa_key_path != NULL) { if (access(rsa_key_path, R_OK) == -1) { pkg_emit_errno("access", rsa_key_path); return EPKG_FATAL; } SSL_load_error_strings(); OpenSSL_add_all_algorithms(); OpenSSL_add_all_ciphers(); rsa = load_rsa_private_key(rsa_key_path, password_cb); max_len = RSA_size(rsa); sigret = malloc(max_len + 1); memset(sigret, 0, max_len); sha256_file(repo_path, sha256); if (RSA_sign(NID_sha1, sha256, sizeof(sha256), sigret, &siglen, rsa) == 0) { /* XXX pass back RSA errors correctly */ pkg_emit_error("%s: %lu", rsa_key_path, ERR_get_error()); return EPKG_FATAL; } packing_append_buffer(pack, sigret, "signature", siglen + 1); free(sigret); RSA_free(rsa); ERR_free_strings(); } packing_append_file(pack, repo_path, "repo.sqlite"); unlink(repo_path); packing_finish(pack); return (EPKG_OK); }
/* The "no concessions to old pkg_tools" variant: just get everything * from the manifest */ int pkg_create_from_manifest(const char *outdir, pkg_formats format, const char *rootdir, const char *manifest, const char *plist) { struct pkg *pkg = NULL; struct packing *pkg_archive = NULL; char arch[BUFSIZ]; int ret = ENOMEM; struct pkg_manifest_key *keys = NULL; pkg_debug(1, "Creating package from stage directory: '%s'", rootdir); if(pkg_new(&pkg, PKG_FILE) != EPKG_OK) { ret = EPKG_FATAL; goto cleanup; } pkg_manifest_keys_new(&keys); if ((ret = pkg_parse_manifest_file(pkg, manifest, keys)) != EPKG_OK) { ret = EPKG_FATAL; goto cleanup; } /* if no arch autodetermine it */ if (pkg->abi == NULL) { pkg_get_myarch(arch, BUFSIZ); pkg->abi = strdup(arch); } if (plist != NULL && ports_parse_plist(pkg, plist, rootdir) != EPKG_OK) { ret = EPKG_FATAL; goto cleanup; } /* Create the archive */ pkg_archive = pkg_create_archive(outdir, pkg, format, 0); if (pkg_archive == NULL) { ret = EPKG_FATAL; /* XXX do better */ goto cleanup; } pkg_create_from_dir(pkg, rootdir, pkg_archive); ret = EPKG_OK; cleanup: free(pkg); pkg_manifest_keys_free(keys); packing_finish(pkg_archive); return (ret); }
/* The "no concessions to old pkg_tools" variant: just get everything * from the manifest */ int pkg_create_from_manifest(const char *outdir, pkg_formats format, const char *rootdir, const char *manifest, bool old) { struct pkg *pkg = NULL; struct packing *pkg_archive = NULL; char arch[BUFSIZ]; int ret = ENOMEM; char *buf; struct pkg_manifest_key *keys = NULL; pkg_debug(1, "Creating package from stage directory: '%s'", rootdir); if(pkg_new(&pkg, old ? PKG_OLD_FILE : PKG_FILE) != EPKG_OK) { ret = EPKG_FATAL; goto cleanup; } pkg_manifest_keys_new(&keys); if ((ret = pkg_parse_manifest_file(pkg, manifest, keys)) != EPKG_OK) { ret = EPKG_FATAL; goto cleanup; } /* if no arch autodetermine it */ pkg_get(pkg, PKG_ARCH, &buf); if (buf == NULL) { pkg_get_myarch(arch, BUFSIZ); pkg_set(pkg, PKG_ARCH, arch); } /* Create the archive */ pkg_archive = pkg_create_archive(outdir, pkg, format, 0); if (pkg_archive == NULL) { ret = EPKG_FATAL; /* XXX do better */ goto cleanup; } pkg_create_from_dir(pkg, rootdir, pkg_archive); ret = EPKG_OK; cleanup: free(pkg); pkg_manifest_keys_free(keys); if (ret == EPKG_OK) ret = packing_finish(pkg_archive); return (ret); }
int pkg_create_installed(const char *outdir, pkg_formats format, const char *rootdir, struct pkg *pkg) { struct packing *pkg_archive; int required_flags = PKG_LOAD_DEPS | PKG_LOAD_CONFLICTS | PKG_LOAD_FILES | PKG_LOAD_SCRIPTS | PKG_LOAD_OPTIONS | PKG_LOAD_MTREE; if (pkg->type != PKG_INSTALLED) return (ERROR_BAD_ARG("pkg")); pkg_archive = pkg_create_archive(outdir, pkg, format, required_flags); if (pkg_archive == NULL) return pkg_error_set(EPKG_FATAL, "unable to create archive"); /* XXX do better */ pkg_create_from_dir(pkg, rootdir, pkg_archive); return packing_finish(pkg_archive); }
int pkg_create_staged(const char *outdir, pkg_formats format, const char *rootdir, const char *md_dir, char *plist) { struct pkg *pkg = NULL; struct pkg_file *file = NULL; struct pkg_dir *dir = NULL; struct packing *pkg_archive = NULL; int ret = EPKG_FATAL; pkg_debug(1, "Creating package from stage directory: '%s'", rootdir); if ((ret = pkg_new(&pkg, PKG_FILE)) != EPKG_OK) goto cleanup; if ((ret = pkg_load_metadata(pkg, NULL, md_dir, plist, rootdir, false)) != EPKG_OK) goto cleanup; /* Create the archive */ pkg_archive = pkg_create_archive(outdir, pkg, format, 0); if (pkg_archive == NULL) { ret = EPKG_FATAL; /* XXX do better */ goto cleanup; } /* XXX: autoplist support doesn't work right with meta-ports */ if (0 && pkg_files(pkg, &file) != EPKG_OK && pkg_dirs(pkg, &dir) != EPKG_OK) { /* Now traverse the file directories, adding to the archive */ packing_append_tree(pkg_archive, md_dir, NULL); packing_append_tree(pkg_archive, rootdir, "/"); ret = EPKG_OK; } else { ret = pkg_create_from_dir(pkg, rootdir, pkg_archive); } cleanup: free(pkg); packing_finish(pkg_archive); return (ret); }
int pkg_create_fakeroot(const char *outdir, pkg_formats format, const char *rootdir, const char *metadatadir) { struct pkg *pkg = NULL; struct packing *pkg_archive = NULL; char *manifest = NULL, *manifest_path = NULL; int ret = ENOMEM; /* Load the manifest from the metadata directory */ if (asprintf(&manifest_path, "%s/+MANIFEST", metadatadir) == -1) goto cleanup; pkg_new(&pkg, PKG_FILE); if (pkg == NULL) goto cleanup; ret = pkg_load_manifest_file(pkg, manifest_path); /* Create the archive */ pkg_archive = pkg_create_archive(outdir, pkg, format, 0); if (pkg_archive == NULL) { ret = EPKG_FATAL; /* XXX do better */ goto cleanup; } /* Now traverse the file directories, adding to the archive */ packing_append_tree(pkg_archive, metadatadir, NULL); packing_append_tree(pkg_archive, rootdir, "/"); ret = EPKG_OK; cleanup: if (pkg != NULL) free(pkg); if (manifest_path != NULL) free(manifest_path); if (manifest != NULL) free(manifest); if (ret == EPKG_OK) ret = packing_finish(pkg_archive); return ret; }
int pkg_create_installed(const char *outdir, pkg_formats format, struct pkg *pkg) { struct packing *pkg_archive; unsigned required_flags = PKG_LOAD_DEPS | PKG_LOAD_FILES | PKG_LOAD_CATEGORIES | PKG_LOAD_DIRS | PKG_LOAD_SCRIPTS | PKG_LOAD_OPTIONS | PKG_LOAD_MTREE | PKG_LOAD_LICENSES ; assert(pkg->type == PKG_INSTALLED || pkg->type == PKG_OLD_FILE); pkg_archive = pkg_create_archive(outdir, pkg, format, required_flags); if (pkg_archive == NULL) { pkg_emit_error("unable to create archive"); return (EPKG_FATAL); } pkg_create_from_dir(pkg, NULL, pkg_archive); return packing_finish(pkg_archive); }
/* The "no concessions to old pkg_tools" variant: just get everything * from the manifest */ int pkg_create_from_manifest(const char *outdir, pkg_formats format, const char *rootdir, const char *manifest, const char *plist) { struct pkg *pkg = NULL; struct packing *pkg_archive = NULL; int ret = ENOMEM; pkg_debug(1, "Creating package from stage directory: '%s'", rootdir); if(pkg_new(&pkg, PKG_FILE) != EPKG_OK) { ret = EPKG_FATAL; goto cleanup; } if ((ret = pkg_load_metadata(pkg, manifest, NULL, plist, rootdir, false)) != EPKG_OK) { ret = EPKG_FATAL; goto cleanup; } /* Create the archive */ pkg_archive = pkg_create_archive(outdir, pkg, format, 0); if (pkg_archive == NULL) { ret = EPKG_FATAL; /* XXX do better */ goto cleanup; } if ((ret = pkg_create_from_dir(pkg, rootdir, pkg_archive)) != EPKG_OK) pkg_emit_error("package creation failed"); cleanup: free(pkg); packing_finish(pkg_archive); return (ret); }
int pkg_create_staged(const char *outdir, pkg_formats format, const char *rootdir, const char *md_dir, char *plist, bool old) { struct pkg *pkg = NULL; struct pkg_file *file = NULL; struct pkg_dir *dir = NULL; struct packing *pkg_archive = NULL; char *manifest = NULL; char path[MAXPATHLEN]; char arch[BUFSIZ]; int ret = ENOMEM; char *buf; int i; regex_t preg; regmatch_t pmatch[2]; size_t size; char *www = NULL; struct pkg_manifest_key *keys = NULL; pkg_debug(1, "Creating package from stage directory: '%s'", rootdir); /* Load the manifest from the metadata directory */ if (snprintf(path, sizeof(path), "%s/+MANIFEST", md_dir) == -1) goto cleanup; if(pkg_new(&pkg, old ? PKG_OLD_FILE : PKG_FILE) != EPKG_OK) { ret = EPKG_FATAL; goto cleanup; } pkg_manifest_keys_new(&keys); if ((ret = pkg_parse_manifest_file(pkg, path, keys)) != EPKG_OK) { ret = EPKG_FATAL; goto cleanup; } /* if no descriptions provided then try to get it from a file */ pkg_get(pkg, PKG_DESC, &buf); if (buf == NULL) { if (snprintf(path, sizeof(path), "%s/+DESC", md_dir) == -1) goto cleanup; if (access(path, F_OK) == 0) { pkg_debug(1, "Taking description from: '%s'", path); pkg_set_from_file(pkg, PKG_DESC, path, false); } } /* if no message try to get it from a file */ pkg_get(pkg, PKG_MESSAGE, &buf); if (buf == NULL) { ret = snprintf(path, sizeof(path), "%s/+DISPLAY", md_dir); if (ret == -1) goto cleanup; if (access(path, F_OK) == 0) { pkg_debug(1, "Taking message from: '%s'", path); pkg_set_from_file(pkg, PKG_MESSAGE, path, false); } } /* if no arch autodetermine it */ pkg_get(pkg, PKG_ARCH, &buf); if (buf == NULL) { pkg_get_myarch(arch, BUFSIZ); pkg_set(pkg, PKG_ARCH, arch); } /* if no mtree try to get it from a file */ pkg_get(pkg, PKG_MTREE, &buf); if (buf == NULL) { ret = snprintf(path, sizeof(path), "%s/+MTREE_DIRS", md_dir); if (ret == -1) goto cleanup; if (access(path, F_OK) == 0) { pkg_debug(1, "Taking mtree definition from: '%s'", path); pkg_set_from_file(pkg, PKG_MTREE, path, false); } } for (i = 0; scripts[i] != NULL; i++) { snprintf(path, sizeof(path), "%s/%s", md_dir, scripts[i]); if (access(path, F_OK) == 0) pkg_addscript_file(pkg, path); } if (plist != NULL && ports_parse_plist(pkg, plist, rootdir) != EPKG_OK) { ret = EPKG_FATAL; goto cleanup; } /* if www is not given then try to determine it from description */ if (www != NULL) { pkg_set(pkg, PKG_WWW, www); free(www); } pkg_get(pkg, PKG_WWW, &www); if (www == NULL) { pkg_get(pkg, PKG_DESC, &buf); if (buf == NULL) { pkg_emit_error("No www or desc defined in manifest"); ret = EPKG_FATAL; goto cleanup; } regcomp(&preg, "^WWW:[[:space:]]*(.*)$", REG_EXTENDED|REG_ICASE|REG_NEWLINE); if (regexec(&preg, buf, 2, pmatch, 0) == 0) { size = pmatch[1].rm_eo - pmatch[1].rm_so; www = strndup(&buf[pmatch[1].rm_so], size); pkg_set(pkg, PKG_WWW, www); free(www); } else { pkg_set(pkg, PKG_WWW, "UNKNOWN"); } regfree(&preg); } /* Create the archive */ pkg_archive = pkg_create_archive(outdir, pkg, format, 0); if (pkg_archive == NULL) { ret = EPKG_FATAL; /* XXX do better */ goto cleanup; } /* XXX: autoplist support doesn't work right with meta-ports */ if (0 && pkg_files(pkg, &file) != EPKG_OK && pkg_dirs(pkg, &dir) != EPKG_OK) { /* Now traverse the file directories, adding to the archive */ packing_append_tree(pkg_archive, md_dir, NULL); packing_append_tree(pkg_archive, rootdir, "/"); } else { pkg_create_from_dir(pkg, rootdir, pkg_archive); } ret = EPKG_OK; cleanup: free(pkg); free(manifest); pkg_manifest_keys_free(keys); if (ret == EPKG_OK) ret = packing_finish(pkg_archive); return ret; }
int pkg_create_staged(const char *outdir, pkg_formats format, const char *rootdir, const char *md_dir, char *plist) { struct pkg *pkg = NULL; struct pkg_file *file = NULL; struct pkg_dir *dir = NULL; struct packing *pkg_archive = NULL; char *manifest = NULL; char arch[BUFSIZ]; int ret = ENOMEM; int i, mfd; regex_t preg; regmatch_t pmatch[2]; size_t size; struct pkg_manifest_key *keys = NULL; pkg_debug(1, "Creating package from stage directory: '%s'", rootdir); if ((mfd = open(md_dir, O_DIRECTORY)) == -1) { pkg_emit_errno("open", md_dir); goto cleanup; } if(pkg_new(&pkg, PKG_FILE) != EPKG_OK) { ret = EPKG_FATAL; goto cleanup; } pkg_manifest_keys_new(&keys); /* Load the manifest from the metadata directory */ if ((ret = pkg_parse_manifest_fileat(mfd, pkg, "+MANIFEST", keys)) != EPKG_OK) { ret = EPKG_FATAL; goto cleanup; } /* if no descriptions provided then try to get it from a file */ if (pkg->desc == NULL) pkg_load_from_file(mfd, pkg, PKG_DESC, "+DESC"); /* if no message try to get it from a file */ if (pkg->message == NULL) { /* Try ucl version first */ if (pkg_load_message_from_file(mfd, pkg, "+DISPLAY.ucl", true) != EPKG_OK) { pkg_load_message_from_file(mfd, pkg, "+DISPLAY", false); } } /* if no arch autodetermine it */ if (pkg->abi == NULL) { pkg_get_myarch(arch, BUFSIZ); pkg->abi = strdup(arch); } for (i = 0; scripts[i] != NULL; i++) { if (faccessat(mfd, scripts[i], F_OK, 0) == 0) pkg_addscript_fileat(mfd, pkg, scripts[i]); } if (plist != NULL && ports_parse_plist(pkg, plist, rootdir) != EPKG_OK) { ret = EPKG_FATAL; goto cleanup; } if (pkg->www == NULL) { if (pkg->desc == NULL) { pkg_emit_error("No www or desc defined in manifest"); ret = EPKG_FATAL; goto cleanup; } regcomp(&preg, "^WWW:[[:space:]]*(.*)$", REG_EXTENDED|REG_ICASE|REG_NEWLINE); if (regexec(&preg, pkg->desc, 2, pmatch, 0) == 0) { size = pmatch[1].rm_eo - pmatch[1].rm_so; pkg->www = strndup(&pkg->desc[pmatch[1].rm_so], size); } else { pkg->www = strdup("UNKNOWN"); } regfree(&preg); } /* Create the archive */ pkg_archive = pkg_create_archive(outdir, pkg, format, 0); if (pkg_archive == NULL) { ret = EPKG_FATAL; /* XXX do better */ goto cleanup; } /* XXX: autoplist support doesn't work right with meta-ports */ if (0 && pkg_files(pkg, &file) != EPKG_OK && pkg_dirs(pkg, &dir) != EPKG_OK) { /* Now traverse the file directories, adding to the archive */ packing_append_tree(pkg_archive, md_dir, NULL); packing_append_tree(pkg_archive, rootdir, "/"); ret = EPKG_OK; } else { ret = pkg_create_from_dir(pkg, rootdir, pkg_archive); } cleanup: if (mfd != -1) close(mfd); free(pkg); free(manifest); pkg_manifest_keys_free(keys); packing_finish(pkg_archive); return (ret); }