/* package.c and util.c immediately before pacman bdedf621 (GPL-2.0-or-later). * the removed package fields are parameters; public accessors replace private * handle access. hashing remains the installed C library's implementation. */ #ifndef V_ALPM_LEGACY_MD5_REFERENCE_H #define V_ALPM_LEGACY_MD5_REFERENCE_H #include #include #include #include #include #include static char *v_alpm_legacy_cache_find(alpm_handle_t *handle, const char *filename) { char path[PATH_MAX]; struct stat buf; alpm_list_t *i; for(i = alpm_option_get_cachedirs(handle); i; i = i->next) { snprintf(path, PATH_MAX, "%s%s", (char *)i->data, filename); if(stat(path, &buf) == 0 && S_ISREG(buf.st_mode)) { return strdup(path); } } return NULL; } static int v_alpm_legacy_test_md5(const char *filepath, const char *expected) { char *computed = alpm_compute_md5sum(filepath); int ret; if(expected == NULL || computed == NULL) { ret = -1; } else if(strcmp(expected, computed) != 0) { ret = 1; } else { ret = 0; } free(computed); return ret; } static int v_alpm_legacy_checkmd5sum(alpm_handle_t *handle, int origin, const char *filename, const char *md5sum, int *error) { char *fpath; int retval; *error = ALPM_ERR_OK; if(origin != ALPM_PKG_FROM_SYNCDB) { *error = ALPM_ERR_WRONG_ARGS; return -1; } fpath = v_alpm_legacy_cache_find(handle, filename); retval = v_alpm_legacy_test_md5(fpath, md5sum); free(fpath); if(retval == 1) { *error = ALPM_ERR_PKG_INVALID; retval = -1; } return retval; } #endif