3 * Copyright (c) 2012 The FreeBSD Foundation
6 * This software was developed by Edward Tomasz Napierala under sponsorship
7 * from the FreeBSD Foundation.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 #include <sys/queue.h>
34 #include <sys/types.h>
49 static struct conf *conf;
50 static struct target *target;
52 extern void yyerror(const char *);
53 extern int yylex(void);
54 extern void yyrestart(FILE *);
58 %token AUTH_METHOD HEADER_DIGEST DATA_DIGEST TARGET_NAME TARGET_ADDRESS
59 %token INITIATOR_NAME INITIATOR_ADDRESS INITIATOR_ALIAS USER SECRET
60 %token MUTUAL_USER MUTUAL_SECRET SESSION_TYPE PROTOCOL IGNORED
61 %token EQUALS OPENING_BRACKET CLOSING_BRACKET
74 statements target_statement
77 target_statement: STR OPENING_BRACKET target_entries CLOSING_BRACKET
79 if (target_find(conf, $1) != NULL)
80 errx(1, "duplicated target %s", $1);
81 target->t_nickname = $1;
82 target = target_new(conf);
88 target_entries target_entry
94 target_address_statement
96 initiator_name_statement
98 initiator_address_statement
100 initiator_alias_statement
106 mutual_user_statement
108 mutual_secret_statement
110 auth_method_statement
112 header_digest_statement
114 data_digest_statement
116 session_type_statement
123 target_name_statement: TARGET_NAME EQUALS STR
125 if (target->t_name != NULL)
126 errx(1, "duplicated TargetName at line %d", lineno + 1);
131 target_address_statement: TARGET_ADDRESS EQUALS STR
133 if (target->t_address != NULL)
134 errx(1, "duplicated TargetAddress at line %d", lineno + 1);
135 target->t_address = $3;
139 initiator_name_statement: INITIATOR_NAME EQUALS STR
141 if (target->t_initiator_name != NULL)
142 errx(1, "duplicated InitiatorName at line %d", lineno + 1);
143 target->t_initiator_name = $3;
147 initiator_address_statement: INITIATOR_ADDRESS EQUALS STR
149 if (target->t_initiator_address != NULL)
150 errx(1, "duplicated InitiatorAddress at line %d", lineno + 1);
151 target->t_initiator_address = $3;
155 initiator_alias_statement: INITIATOR_ALIAS EQUALS STR
157 if (target->t_initiator_alias != NULL)
158 errx(1, "duplicated InitiatorAlias at line %d", lineno + 1);
159 target->t_initiator_alias = $3;
163 user_statement: USER EQUALS STR
165 if (target->t_user != NULL)
166 errx(1, "duplicated chapIName at line %d", lineno + 1);
171 secret_statement: SECRET EQUALS STR
173 if (target->t_secret != NULL)
174 errx(1, "duplicated chapSecret at line %d", lineno + 1);
175 target->t_secret = $3;
179 mutual_user_statement: MUTUAL_USER EQUALS STR
181 if (target->t_mutual_user != NULL)
182 errx(1, "duplicated tgtChapName at line %d", lineno + 1);
183 target->t_mutual_user = $3;
187 mutual_secret_statement:MUTUAL_SECRET EQUALS STR
189 if (target->t_mutual_secret != NULL)
190 errx(1, "duplicated tgtChapSecret at line %d", lineno + 1);
191 target->t_mutual_secret = $3;
195 auth_method_statement: AUTH_METHOD EQUALS STR
197 if (target->t_auth_method != AUTH_METHOD_UNSPECIFIED)
198 errx(1, "duplicated AuthMethod at line %d", lineno + 1);
199 if (strcasecmp($3, "none") == 0)
200 target->t_auth_method = AUTH_METHOD_NONE;
201 else if (strcasecmp($3, "chap") == 0)
202 target->t_auth_method = AUTH_METHOD_CHAP;
204 errx(1, "invalid AuthMethod at line %d; "
205 "must be either \"none\" or \"CHAP\"", lineno + 1);
209 header_digest_statement: HEADER_DIGEST EQUALS STR
211 if (target->t_header_digest != DIGEST_UNSPECIFIED)
212 errx(1, "duplicated HeaderDigest at line %d", lineno + 1);
213 if (strcasecmp($3, "none") == 0)
214 target->t_header_digest = DIGEST_NONE;
215 else if (strcasecmp($3, "CRC32C") == 0)
216 target->t_header_digest = DIGEST_CRC32C;
218 errx(1, "invalid HeaderDigest at line %d; "
219 "must be either \"none\" or \"CRC32C\"", lineno + 1);
223 data_digest_statement: DATA_DIGEST EQUALS STR
225 if (target->t_data_digest != DIGEST_UNSPECIFIED)
226 errx(1, "duplicated DataDigest at line %d", lineno + 1);
227 if (strcasecmp($3, "none") == 0)
228 target->t_data_digest = DIGEST_NONE;
229 else if (strcasecmp($3, "CRC32C") == 0)
230 target->t_data_digest = DIGEST_CRC32C;
232 errx(1, "invalid DataDigest at line %d; "
233 "must be either \"none\" or \"CRC32C\"", lineno + 1);
237 session_type_statement: SESSION_TYPE EQUALS STR
239 if (target->t_session_type != SESSION_TYPE_UNSPECIFIED)
240 errx(1, "duplicated SessionType at line %d", lineno + 1);
241 if (strcasecmp($3, "normal") == 0)
242 target->t_session_type = SESSION_TYPE_NORMAL;
243 else if (strcasecmp($3, "discovery") == 0)
244 target->t_session_type = SESSION_TYPE_DISCOVERY;
246 errx(1, "invalid SessionType at line %d; "
247 "must be either \"normal\" or \"discovery\"", lineno + 1);
251 protocol_statement: PROTOCOL EQUALS STR
253 if (target->t_protocol != PROTOCOL_UNSPECIFIED)
254 errx(1, "duplicated protocol at line %d", lineno + 1);
255 if (strcasecmp($3, "iscsi") == 0)
256 target->t_protocol = PROTOCOL_ISCSI;
257 else if (strcasecmp($3, "iser") == 0)
258 target->t_protocol = PROTOCOL_ISER;
260 errx(1, "invalid protocol at line %d; "
261 "must be either \"iscsi\" or \"iser\"", lineno + 1);
265 ignored_statement: IGNORED EQUALS STR
267 warnx("obsolete statement ignored at line %d", lineno + 1);
274 yyerror(const char *str)
277 errx(1, "error in configuration file at line %d near '%s': %s",
278 lineno + 1, yytext, str);
282 check_perms(const char *path)
287 error = stat(path, &sb);
292 if (sb.st_mode & S_IWOTH) {
293 warnx("%s is world-writable", path);
294 } else if (sb.st_mode & S_IROTH) {
295 warnx("%s is world-readable", path);
296 } else if (sb.st_mode & S_IXOTH) {
298 * Ok, this one doesn't matter, but still do it,
299 * just for consistency.
301 warnx("%s is world-executable", path);
305 * XXX: Should we also check for owner != 0?
310 conf_new_from_file(const char *path)
315 target = target_new(conf);
317 yyin = fopen(path, "r");
319 err(1, "unable to open configuration file %s", path);
327 assert(target->t_nickname == NULL);
328 target_delete(target);