2 * Copyright (c) 1999 Marc Espie.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * 3. All advertising materials mentioning features or use of this software
13 * must display the following acknowledgement:
14 * This product includes software developed by Marc Espie for the OpenBSD
17 * THIS SOFTWARE IS PROVIDED BY THE OPENBSD PROJECT AND CONTRIBUTORS
18 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OPENBSD
21 * PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 * $OpenBSD: main.c,v 1.2 1999/10/04 21:46:28 espie Exp $
30 * $FreeBSD: src/usr.sbin/pkg_install/sign/main.c,v 1.2 2002/04/01 09:39:07 obrien Exp $
31 * $DragonFly: src/usr.sbin/pkg_install/sign/main.c,v 1.3 2004/07/30 06:46:14 dillon Exp $
34 #include <sys/types.h>
46 extern char *__progname
;
47 #define argv0 __progname
52 #define NM_SIGN "pkg_sign"
61 fprintf(stderr
, "usage: %s [-sc] [-t type] [-u userid] [-k keyfile] pkg1 ...\n", argv0
);
68 /* wrapper for the check_signature function (open file if needed) */
70 check(filename
, type
, userid
, envp
)
71 /*@observer@*/const char *filename
;
73 /*@null@*/const char *userid
;
79 if (strcmp(filename
, "-") == 0)
80 return check_signature(stdin
, userid
, envp
, "stdin");
81 file
= fopen(filename
, "r");
83 fprintf(stderr
, "Can't open %s\n", filename
);
86 result
= check_signature(file
, userid
, envp
, filename
);
87 if (fclose(file
) == 0) {
88 if (result
== PKG_BADSIG
|| result
== PKG_SIGERROR
)
97 main(argc
, argv
, envp
)
110 set_program_name(argv
[0]);
116 if ((argv0
= strrchr(argv
[0], '/')) != NULL
)
121 if (strcmp(argv0
, NM_SIGN
) == 0)
127 while ((ch
= getopt(argc
, argv
, "t:u:k:qscv")) != -1) {
130 if (strcmp(optarg
, "pgp") == 0)
132 else if (strcmp(optarg
, "sha1") == 0)
134 else if (strcmp(optarg
, "x509") == 0)
140 userid
= strdup(optarg
);
171 success
&= check("-", 0, userid
, envp
);
177 if (mode
== SIGN
&& type
== TAG_ANY
)
179 if (mode
== SIGN
&& type
== TAG_PGP
)
180 handle_pgp_passphrase();
182 for (i
= 0; i
< argc
; i
++)
183 success
&= (mode
== SIGN
? sign
: check
)(argv
[i
], type
, userid
, envp
);
184 exit(success
== 1 ? EXIT_SUCCESS
: EXIT_FAILURE
);