Radish alpha
H
HardenedBSD Package Manager
Radicle
Git (anonymous pull)
Log in to clone via SSH
pkg clean now find packages with cksum mismatch.
Julien Laffaye committed 13 years ago
commit 2e23a5711944667919aca81580f240d334d6d5fe
parent 8c63c46003f5227899241609f356c714d3f32a8b
3 files changed +57 -0
modified pkg/clean.c
@@ -49,6 +49,7 @@ struct deletion_list {
};
#define OUT_OF_DATE	(1U<<0)
#define REMOVED		(1U<<1)
+
#define CKSUM_MISMATCH	(1U<<2)

STAILQ_HEAD(dl_head, deletion_list);

@@ -156,6 +157,9 @@ display_dellist(struct dl_head *dl, const char *cachedir)
		case REMOVED:
			printf("Removed from repository\n");
			break;
+
		case CKSUM_MISMATCH:
+
			printf("Checksum mismatch\n");
+
			break;
		default:	/* not reached */
			break;
		}
@@ -305,6 +309,19 @@ exec_clean(int argc, char **argv)

			ret = add_to_dellist(&dl, OUT_OF_DATE, ent->fts_path,
					     origin, newname, newversion);
+
		} else {
+
			char local_cksum[SHA256_DIGEST_LENGTH * 2 +1];
+
			const char *cksum;
+

+
			pkg_get(p, PKG_CKSUM, &cksum);
+

+
			if (sha256_file(ent->fts_path, local_cksum) == EPKG_OK) {
+

+
				if (strcmp(cksum, local_cksum) != 0) {
+
					ret = add_to_dellist(&dl, CKSUM_MISMATCH, ent->fts_path,
+
						     origin, NULL, NULL);
+
				}
+
			}
		}

		if (ret != EPKG_OK && ret != EPKG_END) {
modified pkg/pkgcli.h
@@ -218,6 +218,7 @@ char *absolutepath(const char *src, char *dest, size_t dest_len);
void print_jobs_summary(struct pkg_jobs *j, pkg_jobs_t type,
			const char *msg, ...);
struct sbuf *exec_buf(const char *cmd);
+
int sha256_file(const char *, char[SHA256_DIGEST_LENGTH * 2 +1]);

int event_callback(void *data, struct pkg_event *ev);

modified pkg/utils.c
@@ -30,6 +30,7 @@
#include <sys/param.h>
#include <sys/stat.h>

+
#include <err.h>
#include <libutil.h>
#include <string.h>
#include <unistd.h>
@@ -688,3 +689,41 @@ exec_buf(const char *cmd) {

	return (res);
}
+

+
int
+
sha256_file(const char *path, char out[SHA256_DIGEST_LENGTH * 2 + 1])
+
{
+
	FILE *fp;
+
	char buffer[BUFSIZ];
+
	unsigned char hash[SHA256_DIGEST_LENGTH];
+
	size_t r = 0;
+
	SHA256_CTX sha256;
+

+
	if ((fp = fopen(path, "rb")) == NULL) {
+
		warn("fopen(%s)", path);
+
		return (EPKG_FATAL);
+
	}
+

+
	SHA256_Init(&sha256);
+

+
	while ((r = fread(buffer, 1, BUFSIZ, fp)) > 0)
+
		SHA256_Update(&sha256, buffer, r);
+

+
	if (ferror(fp) != 0) {
+
		fclose(fp);
+
		out[0] = '\0';
+
		warn("fread(%s)", path);
+
		return (EPKG_FATAL);
+
	}
+

+
	fclose(fp);
+

+
	SHA256_Final(hash, &sha256);
+

+
	for (int i = 0; i < SHA256_DIGEST_LENGTH; i++)
+
		sprintf(out + (i * 2), "%02x", hash[i]);
+

+
	out[SHA256_DIGEST_LENGTH * 2] = '\0';
+

+
	return (EPKG_OK);
+
}