1 /* $OpenBSD: check.c,v 1.2 1999/10/04 21:46:27 espie Exp $ */
3 * Copyright (c) 1999 Marc Espie.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by Marc Espie for the OpenBSD
18 * THIS SOFTWARE IS PROVIDED BY THE OPENBSD PROJECT AND CONTRIBUTORS
19 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OPENBSD
22 * PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 * $FreeBSD: src/usr.sbin/pkg_install/sign/check.c,v 1.1.2.2 2002/08/20 06:35:08 obrien Exp $
31 * $DragonFly: src/usr.sbin/pkg_install/sign/Attic/check.c,v 1.2 2003/06/17 04:29:59 dillon Exp $
34 /* Simple code for a stand-alone package checker */
35 #include <sys/types.h>
46 void (*add)(void *, const char *, size_t);
51 #define MAX_CHECKERS 20
54 check_signature(file, userid, envp, filename)
55 /*@dependent@*/FILE *file;
58 /*@observer@*/const char *filename;
60 struct signature *sign;
61 struct mygzip_header h;
65 struct checker checker[MAX_CHECKERS];
66 struct signature *sweep;
69 status = read_header_and_diagnose(file, &h, &sign, filename);
73 for (sweep = sign, i = 0;
74 sweep != NULL && i < MAX_CHECKERS;
75 sweep=sweep->next, i++) {
78 fprintf(stderr, "File %s uses old signatures, no longer supported\n",
80 checker[i].context = NULL;
83 checker[i].context = new_x509_checker(&h, sweep, userid, envp, filename);
84 checker[i].add = x509_add;
85 checker[i].get = x509_sign_ok;
88 checker[i].context = new_sha1_checker(&h, sweep, userid, envp, filename);
89 checker[i].add = sha1_add;
90 checker[i].get = sha1_sign_ok;
93 checker[i].context = new_pgp_checker(&h, sweep, userid, envp, filename);
94 checker[i].add = pgp_add;
95 checker[i].get = pgp_sign_ok;
101 while ((length = fread(buffer, 1, sizeof buffer, file)) > 0) {
102 for (j = 0; j < i; j++) {
103 if (checker[j].context) {
104 (*checker[j].add)(checker[j].context, buffer, length);
108 // for (j = i-1; j >= 0; j--)
109 for (j = 0; j < i; j++) {
110 if (checker[j].context) {
111 checker[j].status = (*checker[j].get)(checker[j].context);
113 checker[j].status = PKG_SIGERROR;
116 free_signature(sign);
117 return checker[0].status;