diff options
Diffstat (limited to 'usr.sbin/rpki-client/rsync.c')
-rw-r--r-- | usr.sbin/rpki-client/rsync.c | 102 |
1 files changed, 21 insertions, 81 deletions
diff --git a/usr.sbin/rpki-client/rsync.c b/usr.sbin/rpki-client/rsync.c index 4500be20434..0285429d1d8 100644 --- a/usr.sbin/rpki-client/rsync.c +++ b/usr.sbin/rpki-client/rsync.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rsync.c,v 1.16 2021/02/03 09:29:22 claudio Exp $ */ +/* $OpenBSD: rsync.c,v 1.17 2021/02/16 08:52:00 claudio Exp $ */ /* * Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -45,110 +45,50 @@ struct rsyncproc { }; /* - * Conforms to RFC 5781. - * Note that "Source" is broken down into the module, path, and also - * file type relevant to RPKI. - * Any of the pointers (except "uri") may be NULL. - * Returns zero on failure, non-zero on success. + * Return the base of a rsync URI (rsync://hostname/module). The + * caRepository provided by the RIR CAs point deeper than they should + * which would result in many rsync calls for almost every subdirectory. + * This is inefficent so instead crop the URI to a common base. + * The returned string needs to be freed by the caller. */ -int -rsync_uri_parse(const char **hostp, size_t *hostsz, - const char **modulep, size_t *modulesz, - const char **pathp, size_t *pathsz, - enum rtype *rtypep, const char *uri) +char * +rsync_base_uri(const char *uri) { - const char *host, *module, *path; - size_t sz; - - /* Initialise all output values to NULL or 0. */ - - if (hostsz != NULL) - *hostsz = 0; - if (modulesz != NULL) - *modulesz = 0; - if (pathsz != NULL) - *pathsz = 0; - if (hostp != NULL) - *hostp = 0; - if (modulep != NULL) - *modulep = 0; - if (pathp != NULL) - *pathp = 0; - if (rtypep != NULL) - *rtypep = RTYPE_EOF; + const char *host, *module, *rest; /* Case-insensitive rsync URI. */ - - if (strncasecmp(uri, "rsync://", 8)) { + if (strncasecmp(uri, "rsync://", 8) != 0) { warnx("%s: not using rsync schema", uri); - return 0; + return NULL; } /* Parse the non-zero-length hostname. */ - host = uri + 8; if ((module = strchr(host, '/')) == NULL) { warnx("%s: missing rsync module", uri); - return 0; + return NULL; } else if (module == host) { warnx("%s: zero-length rsync host", uri); - return 0; + return NULL; } - if (hostp != NULL) - *hostp = host; - if (hostsz != NULL) - *hostsz = module - host; - /* The non-zero-length module follows the hostname. */ - - if (module[1] == '\0') { + module++; + if (*module == '\0') { warnx("%s: zero-length rsync module", uri); - return 0; + return NULL; } - module++; - /* The path component is optional. */ - - if ((path = strchr(module, '/')) == NULL) { - assert(*module != '\0'); - if (modulep != NULL) - *modulep = module; - if (modulesz != NULL) - *modulesz = strlen(module); - return 1; - } else if (path == module) { + if ((rest = strchr(module, '/')) == NULL) { + return strdup(uri); + } else if (rest == module) { warnx("%s: zero-length module", uri); - return 0; - } - - if (modulep != NULL) - *modulep = module; - if (modulesz != NULL) - *modulesz = path - module; - - path++; - sz = strlen(path); - - if (pathp != NULL) - *pathp = path; - if (pathsz != NULL) - *pathsz = sz; - - if (rtypep != NULL && sz > 4) { - if (strcasecmp(path + sz - 4, ".roa") == 0) - *rtypep = RTYPE_ROA; - else if (strcasecmp(path + sz - 4, ".mft") == 0) - *rtypep = RTYPE_MFT; - else if (strcasecmp(path + sz - 4, ".cer") == 0) - *rtypep = RTYPE_CER; - else if (strcasecmp(path + sz - 4, ".crl") == 0) - *rtypep = RTYPE_CRL; + return NULL; } - return 1; + return strndup(uri, rest - uri); } static void |