Changeset View
Standalone View
usr.sbin/pkg/pkg.c
Show First 20 Lines • Show All 79 Lines • ▼ Show 20 Lines | struct fingerprint { | ||||
hash_t type; | hash_t type; | ||||
char *name; | char *name; | ||||
char hash[BUFSIZ]; | char hash[BUFSIZ]; | ||||
STAILQ_ENTRY(fingerprint) next; | STAILQ_ENTRY(fingerprint) next; | ||||
}; | }; | ||||
STAILQ_HEAD(fingerprint_list, fingerprint); | STAILQ_HEAD(fingerprint_list, fingerprint); | ||||
static const char *extensions[6] = { ".txz", ".tzst", ".tbz", ".tgz", ".tar", | |||||
".bsd" }; | |||||
static int | static int | ||||
extract_pkg_static(int fd, char *p, int sz) | extract_pkg_static(int fd, char *p, int sz) | ||||
{ | { | ||||
struct archive *a; | struct archive *a; | ||||
struct archive_entry *ae; | struct archive_entry *ae; | ||||
char *end; | char *end; | ||||
int ret, r; | int ret, r; | ||||
▲ Show 20 Lines • Show All 729 Lines • ▼ Show 20 Lines | cleanup: | ||||
} | } | ||||
return (ret); | return (ret); | ||||
} | } | ||||
static int | static int | ||||
bootstrap_pkg(bool force) | bootstrap_pkg(bool force) | ||||
{ | { | ||||
int fd_pkg, fd_sig; | int fd_pkg, fd_sig; | ||||
kevans: I'd be tempted to move this out to the global scope, make it static, drop the NULL terminator… | |||||
Done Inline Actionsin discussion with @bapt we want to add also the .bsd extension, it's not used yet but he wants to use it as the generic extension for packages emaste: in discussion with @bapt we want to add also the `.bsd` extension, it's not used yet but he… | |||||
unsigned int i; | |||||
int ret; | int ret; | ||||
char url[MAXPATHLEN]; | char url[MAXPATHLEN]; | ||||
char tmppkg[MAXPATHLEN]; | char tmppkg[MAXPATHLEN]; | ||||
char tmpsig[MAXPATHLEN]; | char tmpsig[MAXPATHLEN]; | ||||
char packagename[MAXPATHLEN]; | |||||
const char *packagesite; | const char *packagesite; | ||||
const char *signature_type; | const char *signature_type; | ||||
char pkgstatic[MAXPATHLEN]; | char pkgstatic[MAXPATHLEN]; | ||||
fd_sig = -1; | fd_sig = -1; | ||||
ret = -1; | ret = -1; | ||||
if (config_string(PACKAGESITE, &packagesite) != 0) { | if (config_string(PACKAGESITE, &packagesite) != 0) { | ||||
Show All 9 Lines | bootstrap_pkg(bool force) | ||||
printf("Bootstrapping pkg from %s, please wait...\n", packagesite); | printf("Bootstrapping pkg from %s, please wait...\n", packagesite); | ||||
/* Support pkg+http:// for PACKAGESITE which is the new format | /* Support pkg+http:// for PACKAGESITE which is the new format | ||||
in 1.2 to avoid confusion on why http://pkg.FreeBSD.org has | in 1.2 to avoid confusion on why http://pkg.FreeBSD.org has | ||||
no A record. */ | no A record. */ | ||||
if (strncmp(URL_SCHEME_PREFIX, packagesite, | if (strncmp(URL_SCHEME_PREFIX, packagesite, | ||||
strlen(URL_SCHEME_PREFIX)) == 0) | strlen(URL_SCHEME_PREFIX)) == 0) | ||||
packagesite += strlen(URL_SCHEME_PREFIX); | packagesite += strlen(URL_SCHEME_PREFIX); | ||||
snprintf(url, MAXPATHLEN, "%s/Latest/pkg.txz", packagesite); | |||||
snprintf(tmppkg, MAXPATHLEN, "%s/pkg.txz.XXXXXX", | for (i = 0; i < nitems(extensions); i++) { | ||||
getenv("TMPDIR") ? getenv("TMPDIR") : _PATH_TMP); | snprintf(packagename, MAXPATHLEN, "pkg%s", extensions[i]); | ||||
snprintf( | |||||
url, MAXPATHLEN, "%s/Latest/%s", packagesite, packagename); | |||||
Done Inline Actions... loop here from 0 to nitems(extension) (macro provided by sys/param.h) kevans: ... loop here from 0 to `nitems(extension)` (macro provided by `sys/param.h`) | |||||
snprintf(tmppkg, MAXPATHLEN, "%s/%s.XXXXXX", | |||||
getenv("TMPDIR") ? getenv("TMPDIR") : _PATH_TMP, | |||||
packagename); | |||||
if ((fd_pkg = fetch_to_fd(url, tmppkg)) == -1) | if ((fd_pkg = fetch_to_fd(url, tmppkg)) == -1) | ||||
goto fetchfail; | continue; | ||||
Done Inline ActionsFreeBSD style is a 4 spaces for 2nd-level indents. clang-format should be able to help here, have a look at the instructions for clang-formatting a git patch at https://clang.llvm.org/docs/ClangFormat.html and see how it works, and then put those instructions on https://wiki.freebsd.org/Phabricator emaste: FreeBSD style is a 4 spaces for 2nd-level indents.
clang-format should be able to help here… | |||||
Not Done Inline ActionsAll paths through the oop after this either goto fetchfail or cleanup, so you could invert this condition and break out of the loop, dropping the rest of the loop's body out of it. Do we suspect that we could hit a failure mode where, e.g., pkg.txz exists but the rest of this won't line up and we need to try a different archive type? kevans: All paths through the oop after this either goto fetchfail or cleanup, so you could invert this… | |||||
Not Done Inline ActionsI believe that the desired behavior for when pkg.txz is fetched but reaches a failure state for whatever reason to attempt to fetch the next file from the extensions array to attempt recovery. zac_freebsdfoundation.org: I believe that the desired behavior for when pkg.txz is fetched but reaches a failure state for… | |||||
if (signature_type != NULL && | if (signature_type != NULL && | ||||
strcasecmp(signature_type, "NONE") != 0) { | strcasecmp(signature_type, "NONE") != 0) { | ||||
if (strcasecmp(signature_type, "FINGERPRINTS") == 0) { | if (strcasecmp(signature_type, "FINGERPRINTS") == 0) { | ||||
snprintf(tmpsig, MAXPATHLEN, "%s/pkg.txz.sig.XXXXXX", | snprintf(tmpsig, MAXPATHLEN, "%s/%s.sig.XXXXXX", | ||||
getenv("TMPDIR") ? getenv("TMPDIR") : _PATH_TMP); | getenv("TMPDIR") ? getenv("TMPDIR") : | ||||
snprintf(url, MAXPATHLEN, "%s/Latest/pkg.txz.sig", | _PATH_TMP, | ||||
packagesite); | packagename); | ||||
snprintf(url, MAXPATHLEN, "%s/Latest/%s.sig", | |||||
packagesite, packagename); | |||||
if ((fd_sig = fetch_to_fd(url, tmpsig)) == -1) { | if ((fd_sig = fetch_to_fd(url, tmpsig)) == -1) { | ||||
fprintf(stderr, "Signature for pkg not " | fprintf(stderr, | ||||
"Signature for pkg not " | |||||
"available.\n"); | "available.\n"); | ||||
goto fetchfail; | goto fetchfail; | ||||
} | } | ||||
if (verify_signature(fd_pkg, fd_sig) == false) | if (verify_signature(fd_pkg, fd_sig) == false) | ||||
goto cleanup; | goto cleanup; | ||||
} else if (strcasecmp(signature_type, "PUBKEY") == 0) { | } else if (strcasecmp(signature_type, "PUBKEY") == 0) { | ||||
snprintf(tmpsig, MAXPATHLEN, | snprintf(tmpsig, MAXPATHLEN, | ||||
"%s/pkg.txz.pubkeysig.XXXXXX", | "%s/%s.pubkeysig.XXXXXX", | ||||
getenv("TMPDIR") ? getenv("TMPDIR") : _PATH_TMP); | getenv("TMPDIR") ? getenv("TMPDIR") : | ||||
snprintf(url, MAXPATHLEN, "%s/Latest/pkg.txz.pubkeysig", | _PATH_TMP, | ||||
packagesite); | packagename); | ||||
snprintf(url, MAXPATHLEN, | |||||
"%s/Latest/%s.pubkeysig", packagesite, | |||||
packagename); | |||||
if ((fd_sig = fetch_to_fd(url, tmpsig)) == -1) { | if ((fd_sig = fetch_to_fd(url, tmpsig)) == -1) { | ||||
fprintf(stderr, "Signature for pkg not " | fprintf(stderr, | ||||
"Signature for pkg not " | |||||
"available.\n"); | "available.\n"); | ||||
goto fetchfail; | goto fetchfail; | ||||
} | } | ||||
if (verify_pubsignature(fd_pkg, fd_sig) == false) | if (verify_pubsignature(fd_pkg, fd_sig) == | ||||
false) | |||||
goto cleanup; | goto cleanup; | ||||
} else { | } else { | ||||
warnx("Signature type %s is not supported for " | warnx("Signature type %s is not supported for " | ||||
"bootstrapping.", signature_type); | "bootstrapping.", | ||||
signature_type); | |||||
goto cleanup; | goto cleanup; | ||||
} | } | ||||
} | } | ||||
if ((ret = extract_pkg_static(fd_pkg, pkgstatic, MAXPATHLEN)) == 0) | if ((ret = extract_pkg_static(fd_pkg, pkgstatic, MAXPATHLEN)) == | ||||
0) | |||||
ret = install_pkg_static(pkgstatic, tmppkg, force); | ret = install_pkg_static(pkgstatic, tmppkg, force); | ||||
goto cleanup; | goto cleanup; | ||||
} | |||||
fetchfail: | fetchfail: | ||||
warnx("Error fetching %s: %s", url, fetchLastErrString); | warnx("Error fetching %s: %s", url, fetchLastErrString); | ||||
if (fetchLastErrCode == FETCH_RESOLV) { | if (fetchLastErrCode == FETCH_RESOLV) { | ||||
fprintf(stderr, "Address resolution failed for %s.\n", packagesite); | fprintf(stderr, "Address resolution failed for %s.\n", packagesite); | ||||
fprintf(stderr, "Consider changing PACKAGESITE.\n"); | fprintf(stderr, "Consider changing PACKAGESITE.\n"); | ||||
} else { | } else { | ||||
fprintf(stderr, "A pre-built version of pkg could not be found for " | fprintf(stderr, "A pre-built version of pkg could not be found for " | ||||
▲ Show 20 Lines • Show All 212 Lines • Show Last 20 Lines |
I'd be tempted to move this out to the global scope, make it static, drop the NULL terminator, then...