3 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
5 * Copyright (c) 2012 The FreeBSD Foundation
8 * This software was developed by Edward Tomasz Napierala under sponsorship
9 * from the FreeBSD Foundation.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 #include <sys/queue.h>
36 #include <sys/types.h>
52 static struct conf *conf;
53 static struct target *target;
55 extern void yyerror(const char *);
56 extern int yylex(void);
57 extern void yyrestart(FILE *);
61 %token AUTH_METHOD ENABLE HEADER_DIGEST DATA_DIGEST TARGET_NAME TARGET_ADDRESS
62 %token INITIATOR_NAME INITIATOR_ADDRESS INITIATOR_ALIAS USER SECRET
63 %token MUTUAL_USER MUTUAL_SECRET SEMICOLON SESSION_TYPE PROTOCOL OFFLOAD
64 %token IGNORED EQUALS OPENING_BRACKET CLOSING_BRACKET
80 target: STR OPENING_BRACKET target_entries CLOSING_BRACKET
82 if (target_find(conf, $1) != NULL)
83 xo_errx(1, "duplicated target %s", $1);
84 target->t_nickname = $1;
85 target = target_new(conf);
91 target_entries target_entry
93 target_entries target_entry SEMICOLON
132 target_name: TARGET_NAME EQUALS STR
134 if (target->t_name != NULL)
135 xo_errx(1, "duplicated TargetName at line %d", lineno);
140 target_address: TARGET_ADDRESS EQUALS STR
142 if (target->t_address != NULL)
143 xo_errx(1, "duplicated TargetAddress at line %d", lineno);
144 target->t_address = $3;
148 initiator_name: INITIATOR_NAME EQUALS STR
150 if (target->t_initiator_name != NULL)
151 xo_errx(1, "duplicated InitiatorName at line %d", lineno);
152 target->t_initiator_name = $3;
156 initiator_address: INITIATOR_ADDRESS EQUALS STR
158 if (target->t_initiator_address != NULL)
159 xo_errx(1, "duplicated InitiatorAddress at line %d", lineno);
160 target->t_initiator_address = $3;
164 initiator_alias: INITIATOR_ALIAS EQUALS STR
166 if (target->t_initiator_alias != NULL)
167 xo_errx(1, "duplicated InitiatorAlias at line %d", lineno);
168 target->t_initiator_alias = $3;
172 user: USER EQUALS STR
174 if (target->t_user != NULL)
175 xo_errx(1, "duplicated chapIName at line %d", lineno);
180 secret: SECRET EQUALS STR
182 if (target->t_secret != NULL)
183 xo_errx(1, "duplicated chapSecret at line %d", lineno);
184 target->t_secret = $3;
188 mutual_user: MUTUAL_USER EQUALS STR
190 if (target->t_mutual_user != NULL)
191 xo_errx(1, "duplicated tgtChapName at line %d", lineno);
192 target->t_mutual_user = $3;
196 mutual_secret: MUTUAL_SECRET EQUALS STR
198 if (target->t_mutual_secret != NULL)
199 xo_errx(1, "duplicated tgtChapSecret at line %d", lineno);
200 target->t_mutual_secret = $3;
204 auth_method: AUTH_METHOD EQUALS STR
206 if (target->t_auth_method != AUTH_METHOD_UNSPECIFIED)
207 xo_errx(1, "duplicated AuthMethod at line %d", lineno);
208 if (strcasecmp($3, "none") == 0)
209 target->t_auth_method = AUTH_METHOD_NONE;
210 else if (strcasecmp($3, "chap") == 0)
211 target->t_auth_method = AUTH_METHOD_CHAP;
213 xo_errx(1, "invalid AuthMethod at line %d; "
214 "must be either \"none\" or \"CHAP\"", lineno);
218 header_digest: HEADER_DIGEST EQUALS STR
220 if (target->t_header_digest != DIGEST_UNSPECIFIED)
221 xo_errx(1, "duplicated HeaderDigest at line %d", lineno);
222 if (strcasecmp($3, "none") == 0)
223 target->t_header_digest = DIGEST_NONE;
224 else if (strcasecmp($3, "CRC32C") == 0)
225 target->t_header_digest = DIGEST_CRC32C;
227 xo_errx(1, "invalid HeaderDigest at line %d; "
228 "must be either \"none\" or \"CRC32C\"", lineno);
232 data_digest: DATA_DIGEST EQUALS STR
234 if (target->t_data_digest != DIGEST_UNSPECIFIED)
235 xo_errx(1, "duplicated DataDigest at line %d", lineno);
236 if (strcasecmp($3, "none") == 0)
237 target->t_data_digest = DIGEST_NONE;
238 else if (strcasecmp($3, "CRC32C") == 0)
239 target->t_data_digest = DIGEST_CRC32C;
241 xo_errx(1, "invalid DataDigest at line %d; "
242 "must be either \"none\" or \"CRC32C\"", lineno);
246 session_type: SESSION_TYPE EQUALS STR
248 if (target->t_session_type != SESSION_TYPE_UNSPECIFIED)
249 xo_errx(1, "duplicated SessionType at line %d", lineno);
250 if (strcasecmp($3, "normal") == 0)
251 target->t_session_type = SESSION_TYPE_NORMAL;
252 else if (strcasecmp($3, "discovery") == 0)
253 target->t_session_type = SESSION_TYPE_DISCOVERY;
255 xo_errx(1, "invalid SessionType at line %d; "
256 "must be either \"normal\" or \"discovery\"", lineno);
260 enable: ENABLE EQUALS STR
262 if (target->t_enable != ENABLE_UNSPECIFIED)
263 xo_errx(1, "duplicated enable at line %d", lineno);
264 target->t_enable = parse_enable($3);
265 if (target->t_enable == ENABLE_UNSPECIFIED)
266 xo_errx(1, "invalid enable at line %d; "
267 "must be either \"on\" or \"off\"", lineno);
271 offload: OFFLOAD EQUALS STR
273 if (target->t_offload != NULL)
274 xo_errx(1, "duplicated offload at line %d", lineno);
275 target->t_offload = $3;
279 protocol: PROTOCOL EQUALS STR
281 if (target->t_protocol != PROTOCOL_UNSPECIFIED)
282 xo_errx(1, "duplicated protocol at line %d", lineno);
283 if (strcasecmp($3, "iscsi") == 0)
284 target->t_protocol = PROTOCOL_ISCSI;
285 else if (strcasecmp($3, "iser") == 0)
286 target->t_protocol = PROTOCOL_ISER;
288 xo_errx(1, "invalid protocol at line %d; "
289 "must be either \"iscsi\" or \"iser\"", lineno);
293 ignored: IGNORED EQUALS STR
295 xo_warnx("obsolete statement ignored at line %d", lineno);
302 yyerror(const char *str)
305 xo_errx(1, "error in configuration file at line %d near '%s': %s",
306 lineno, yytext, str);
310 check_perms(const char *path)
315 error = stat(path, &sb);
320 if (sb.st_mode & S_IWOTH) {
321 xo_warnx("%s is world-writable", path);
322 } else if (sb.st_mode & S_IROTH) {
323 xo_warnx("%s is world-readable", path);
324 } else if (sb.st_mode & S_IXOTH) {
326 * Ok, this one doesn't matter, but still do it,
327 * just for consistency.
329 xo_warnx("%s is world-executable", path);
333 * XXX: Should we also check for owner != 0?
338 conf_new_from_file(const char *path)
343 target = target_new(conf);
345 yyin = fopen(path, "r");
347 xo_err(1, "unable to open configuration file %s", path);
355 assert(target->t_nickname == NULL);
356 target_delete(target);