2 /* $NetBSD: veriexecctl_parse.y,v 1.25 2008/08/31 23:37:45 dholland Exp $ */
5 * Copyright 2005 Elad Efrat <elad@NetBSD.org>
6 * Copyright 2005 Brett Lymn <blymn@netbsd.org>
10 * This code has been donated to The NetBSD Foundation by the Author.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. The name of the author may not be used to endorse or promote products
18 * derived from this software withough specific prior written permission
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 #include <sys/verified_exec.h>
42 #include <prop/proplib.h>
44 #include "veriexecctl.h"
46 extern
int yylex(void);
48 extern
int verbose
, error;
50 bool keep_filename
= false
, eval_on_load
= false
;
51 prop_dictionary_t load_params
;
60 %token
<string> STRING
61 %token EOL TOKEN_COMMA
65 statement
: /* empty */
66 | statement path type fingerprint flags eol
{
70 if
(stat
(dict_gets
(load_params
, "file"), &sb
) == -1) {
72 warnx
("Line %zu: Can't stat `%s'", line
,
73 dict_gets
(load_params
, "file"));
78 /* Only regular files */
79 if
(!S_ISREG
(sb.st_mode
)) {
81 warnx
("Line %zu: %s is not a regular file", line
,
82 dict_gets
(load_params
, "file"));
88 (void)printf
( "Adding file `%s'.\n",
89 dict_gets
(load_params
, "file"));
92 prop_dictionary_set
(load_params
, "keep-filename",
93 prop_bool_create
(keep_filename
));
95 prop_dictionary_set
(load_params
, "eval-on-load",
96 prop_bool_create
(eval_on_load
));
98 if
(prop_dictionary_send_ioctl
(load_params
, gfd
, VERIEXEC_LOAD
) != 0) {
100 warn
("Cannot load params from `%s'",
101 dict_gets
(load_params
, "file"));
102 error = EXIT_FAILURE
;
106 prop_object_release
(load_params
);
110 | statement
error eol
{
116 if
(load_params
== NULL
)
117 load_params
= prop_dictionary_create
();
119 dict_sets
(load_params
, "file", $1);
124 dict_sets
(load_params
, "fp-type", $1);
129 fingerprint
: STRING
{
133 fp
= malloc
(strlen
($1) / 2);
135 err
(1, "Cannot allocate memory for fingerprint");
138 if
(n
== (size_t)-1) {
141 warnx
("Bad fingerprint `%s' in line %zu", $1, line
);
142 error = EXIT_FAILURE
;
146 dict_setd
(load_params
, "fp", fp
, n
);
155 flags_spec
: flag_spec
156 | flags_spec TOKEN_COMMA flag_spec
162 prop_dictionary_get_uint8
(load_params
, "entry-type", &t
);
164 if
(strcasecmp
($1, "direct") == 0) {
165 t |
= VERIEXEC_DIRECT
;
166 } else if
(strcasecmp
($1, "indirect") == 0) {
167 t |
= VERIEXEC_INDIRECT
;
168 } else if
(strcasecmp
($1, "file") == 0) {
170 } else if
(strcasecmp
($1, "program") == 0) {
171 t |
= VERIEXEC_DIRECT
;
172 } else if
(strcasecmp
($1, "interpreter") == 0) {
173 t |
= VERIEXEC_INDIRECT
;
174 } else if
(strcasecmp
($1, "script") == 0) {
175 t |
= (VERIEXEC_FILE | VERIEXEC_DIRECT
);
176 } else if
(strcasecmp
($1, "library") == 0) {
177 t |
= (VERIEXEC_FILE | VERIEXEC_INDIRECT
);
178 } else if
(strcasecmp
($1, "untrusted") == 0) {
179 t |
= VERIEXEC_UNTRUSTED
;
182 warnx
("Bad flag `%s' in line %zu", $1, line
);
183 error = EXIT_FAILURE
;
187 prop_dictionary_set_uint8
(load_params
, "entry-type", t
);
197 * Takes the hexadecimal string pointed to by "fp" and converts it to a
198 * "count" byte binary number which is stored in the array pointed to
199 * by "out". Returns the number of bytes converted or -1 if the conversion
203 convert
(char *fp
, u_char
*out
)
211 * if there are not an even number of hex digits then there is
212 * not an integral number of bytes in the fingerprint.
214 if
((count %
2) != 0)
220 if
(isdigit
((unsigned char) cv
)) \
221 value
+= (cv
) - '0'; \
222 else if
(isxdigit
((unsigned char) cv
)) \
223 value
+= 10 + tolower
((unsigned char) cv
) - 'a'; \
227 for
(i
= 0; i
< count
; i
++) {
239 yyerror(const char *msg
)
242 warnx
("%s in line %zu", msg
, line
);