2013-09-14 15:29:06 +00:00
|
|
|
%{
|
|
|
|
/*-
|
|
|
|
* Copyright (c) 2012 The FreeBSD Foundation
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This software was developed by Edward Tomasz Napierala under sponsorship
|
|
|
|
* from the FreeBSD Foundation.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* $FreeBSD$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/queue.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2015-04-12 09:36:50 +00:00
|
|
|
#include <libxo/xo.h>
|
|
|
|
|
2013-09-14 15:29:06 +00:00
|
|
|
#include "iscsictl.h"
|
|
|
|
|
|
|
|
extern FILE *yyin;
|
|
|
|
extern char *yytext;
|
|
|
|
extern int lineno;
|
|
|
|
|
|
|
|
static struct conf *conf;
|
|
|
|
static struct target *target;
|
|
|
|
|
|
|
|
extern void yyerror(const char *);
|
|
|
|
extern int yylex(void);
|
|
|
|
extern void yyrestart(FILE *);
|
|
|
|
|
|
|
|
%}
|
|
|
|
|
2016-05-31 11:32:07 +00:00
|
|
|
%token AUTH_METHOD ENABLE HEADER_DIGEST DATA_DIGEST TARGET_NAME TARGET_ADDRESS
|
2013-09-14 15:29:06 +00:00
|
|
|
%token INITIATOR_NAME INITIATOR_ADDRESS INITIATOR_ALIAS USER SECRET
|
2015-02-05 06:37:59 +00:00
|
|
|
%token MUTUAL_USER MUTUAL_SECRET SEMICOLON SESSION_TYPE PROTOCOL OFFLOAD
|
|
|
|
%token IGNORED EQUALS OPENING_BRACKET CLOSING_BRACKET
|
2013-09-14 15:29:06 +00:00
|
|
|
|
|
|
|
%union
|
|
|
|
{
|
|
|
|
char *str;
|
|
|
|
}
|
|
|
|
|
|
|
|
%token <str> STR
|
|
|
|
|
|
|
|
%%
|
|
|
|
|
2014-02-10 15:01:24 +00:00
|
|
|
targets:
|
2013-09-14 15:29:06 +00:00
|
|
|
|
|
2014-02-10 15:01:24 +00:00
|
|
|
targets target
|
2013-09-14 15:29:06 +00:00
|
|
|
;
|
|
|
|
|
2014-02-10 15:01:24 +00:00
|
|
|
target: STR OPENING_BRACKET target_entries CLOSING_BRACKET
|
2013-09-14 15:29:06 +00:00
|
|
|
{
|
|
|
|
if (target_find(conf, $1) != NULL)
|
2015-04-12 09:36:50 +00:00
|
|
|
xo_errx(1, "duplicated target %s", $1);
|
2013-09-14 15:29:06 +00:00
|
|
|
target->t_nickname = $1;
|
|
|
|
target = target_new(conf);
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
target_entries:
|
|
|
|
|
|
|
|
|
target_entries target_entry
|
2014-02-10 15:04:59 +00:00
|
|
|
|
|
|
|
|
target_entries target_entry SEMICOLON
|
2013-09-14 15:29:06 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
target_entry:
|
2014-02-10 15:01:24 +00:00
|
|
|
target_name
|
2013-09-14 15:29:06 +00:00
|
|
|
|
|
2014-02-10 15:01:24 +00:00
|
|
|
target_address
|
2013-09-14 15:29:06 +00:00
|
|
|
|
|
2014-02-10 15:01:24 +00:00
|
|
|
initiator_name
|
2013-09-14 15:29:06 +00:00
|
|
|
|
|
2014-02-10 15:01:24 +00:00
|
|
|
initiator_address
|
2013-09-14 15:29:06 +00:00
|
|
|
|
|
2014-02-10 15:01:24 +00:00
|
|
|
initiator_alias
|
2013-09-14 15:29:06 +00:00
|
|
|
|
|
2014-02-10 15:01:24 +00:00
|
|
|
user
|
2013-09-14 15:29:06 +00:00
|
|
|
|
|
2014-02-10 15:01:24 +00:00
|
|
|
secret
|
2013-09-14 15:29:06 +00:00
|
|
|
|
|
2014-02-10 15:01:24 +00:00
|
|
|
mutual_user
|
2013-09-14 15:29:06 +00:00
|
|
|
|
|
2014-02-10 15:01:24 +00:00
|
|
|
mutual_secret
|
2013-09-14 15:29:06 +00:00
|
|
|
|
|
2014-02-10 15:01:24 +00:00
|
|
|
auth_method
|
2013-09-14 15:29:06 +00:00
|
|
|
|
|
2014-02-10 15:01:24 +00:00
|
|
|
header_digest
|
2013-09-14 15:29:06 +00:00
|
|
|
|
|
2014-02-10 15:01:24 +00:00
|
|
|
data_digest
|
2013-09-14 15:29:06 +00:00
|
|
|
|
|
2014-02-10 15:01:24 +00:00
|
|
|
session_type
|
2013-09-14 15:29:06 +00:00
|
|
|
|
|
2016-05-31 11:32:07 +00:00
|
|
|
enable
|
|
|
|
|
|
2015-02-05 06:37:59 +00:00
|
|
|
offload
|
|
|
|
|
|
2014-02-10 15:01:24 +00:00
|
|
|
protocol
|
2013-09-14 15:29:06 +00:00
|
|
|
|
|
2014-02-10 15:01:24 +00:00
|
|
|
ignored
|
2013-09-14 15:29:06 +00:00
|
|
|
;
|
|
|
|
|
2014-02-10 15:01:24 +00:00
|
|
|
target_name: TARGET_NAME EQUALS STR
|
2013-09-14 15:29:06 +00:00
|
|
|
{
|
|
|
|
if (target->t_name != NULL)
|
2015-04-12 09:36:50 +00:00
|
|
|
xo_errx(1, "duplicated TargetName at line %d", lineno);
|
2013-09-14 15:29:06 +00:00
|
|
|
target->t_name = $3;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2014-02-10 15:01:24 +00:00
|
|
|
target_address: TARGET_ADDRESS EQUALS STR
|
2013-09-14 15:29:06 +00:00
|
|
|
{
|
|
|
|
if (target->t_address != NULL)
|
2015-04-12 09:36:50 +00:00
|
|
|
xo_errx(1, "duplicated TargetAddress at line %d", lineno);
|
2013-09-14 15:29:06 +00:00
|
|
|
target->t_address = $3;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2014-02-10 15:01:24 +00:00
|
|
|
initiator_name: INITIATOR_NAME EQUALS STR
|
2013-09-14 15:29:06 +00:00
|
|
|
{
|
|
|
|
if (target->t_initiator_name != NULL)
|
2015-04-12 09:36:50 +00:00
|
|
|
xo_errx(1, "duplicated InitiatorName at line %d", lineno);
|
2013-09-14 15:29:06 +00:00
|
|
|
target->t_initiator_name = $3;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2014-02-10 15:01:24 +00:00
|
|
|
initiator_address: INITIATOR_ADDRESS EQUALS STR
|
2013-09-14 15:29:06 +00:00
|
|
|
{
|
|
|
|
if (target->t_initiator_address != NULL)
|
2015-04-12 09:36:50 +00:00
|
|
|
xo_errx(1, "duplicated InitiatorAddress at line %d", lineno);
|
2013-09-14 15:29:06 +00:00
|
|
|
target->t_initiator_address = $3;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2014-02-10 15:01:24 +00:00
|
|
|
initiator_alias: INITIATOR_ALIAS EQUALS STR
|
2013-09-14 15:29:06 +00:00
|
|
|
{
|
|
|
|
if (target->t_initiator_alias != NULL)
|
2015-04-12 09:36:50 +00:00
|
|
|
xo_errx(1, "duplicated InitiatorAlias at line %d", lineno);
|
2013-09-14 15:29:06 +00:00
|
|
|
target->t_initiator_alias = $3;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2014-02-10 15:01:24 +00:00
|
|
|
user: USER EQUALS STR
|
2013-09-14 15:29:06 +00:00
|
|
|
{
|
|
|
|
if (target->t_user != NULL)
|
2015-04-12 09:36:50 +00:00
|
|
|
xo_errx(1, "duplicated chapIName at line %d", lineno);
|
2013-09-14 15:29:06 +00:00
|
|
|
target->t_user = $3;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2014-02-10 15:01:24 +00:00
|
|
|
secret: SECRET EQUALS STR
|
2013-09-14 15:29:06 +00:00
|
|
|
{
|
|
|
|
if (target->t_secret != NULL)
|
2015-04-12 09:36:50 +00:00
|
|
|
xo_errx(1, "duplicated chapSecret at line %d", lineno);
|
2013-09-14 15:29:06 +00:00
|
|
|
target->t_secret = $3;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2014-02-10 15:01:24 +00:00
|
|
|
mutual_user: MUTUAL_USER EQUALS STR
|
2013-09-14 15:29:06 +00:00
|
|
|
{
|
|
|
|
if (target->t_mutual_user != NULL)
|
2015-04-12 09:36:50 +00:00
|
|
|
xo_errx(1, "duplicated tgtChapName at line %d", lineno);
|
2013-09-14 15:29:06 +00:00
|
|
|
target->t_mutual_user = $3;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2014-02-10 15:01:24 +00:00
|
|
|
mutual_secret: MUTUAL_SECRET EQUALS STR
|
2013-09-14 15:29:06 +00:00
|
|
|
{
|
|
|
|
if (target->t_mutual_secret != NULL)
|
2015-04-12 09:36:50 +00:00
|
|
|
xo_errx(1, "duplicated tgtChapSecret at line %d", lineno);
|
2013-09-14 15:29:06 +00:00
|
|
|
target->t_mutual_secret = $3;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2014-02-10 15:01:24 +00:00
|
|
|
auth_method: AUTH_METHOD EQUALS STR
|
2013-09-14 15:29:06 +00:00
|
|
|
{
|
|
|
|
if (target->t_auth_method != AUTH_METHOD_UNSPECIFIED)
|
2015-04-12 09:36:50 +00:00
|
|
|
xo_errx(1, "duplicated AuthMethod at line %d", lineno);
|
2013-09-14 15:29:06 +00:00
|
|
|
if (strcasecmp($3, "none") == 0)
|
|
|
|
target->t_auth_method = AUTH_METHOD_NONE;
|
|
|
|
else if (strcasecmp($3, "chap") == 0)
|
|
|
|
target->t_auth_method = AUTH_METHOD_CHAP;
|
|
|
|
else
|
2015-04-12 09:36:50 +00:00
|
|
|
xo_errx(1, "invalid AuthMethod at line %d; "
|
2014-02-10 15:03:08 +00:00
|
|
|
"must be either \"none\" or \"CHAP\"", lineno);
|
2013-09-14 15:29:06 +00:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2014-02-10 15:01:24 +00:00
|
|
|
header_digest: HEADER_DIGEST EQUALS STR
|
2013-09-14 15:29:06 +00:00
|
|
|
{
|
|
|
|
if (target->t_header_digest != DIGEST_UNSPECIFIED)
|
2015-04-12 09:36:50 +00:00
|
|
|
xo_errx(1, "duplicated HeaderDigest at line %d", lineno);
|
2013-09-14 15:29:06 +00:00
|
|
|
if (strcasecmp($3, "none") == 0)
|
|
|
|
target->t_header_digest = DIGEST_NONE;
|
|
|
|
else if (strcasecmp($3, "CRC32C") == 0)
|
|
|
|
target->t_header_digest = DIGEST_CRC32C;
|
|
|
|
else
|
2015-04-12 09:36:50 +00:00
|
|
|
xo_errx(1, "invalid HeaderDigest at line %d; "
|
2014-02-10 15:03:08 +00:00
|
|
|
"must be either \"none\" or \"CRC32C\"", lineno);
|
2013-09-14 15:29:06 +00:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2014-02-10 15:01:24 +00:00
|
|
|
data_digest: DATA_DIGEST EQUALS STR
|
2013-09-14 15:29:06 +00:00
|
|
|
{
|
|
|
|
if (target->t_data_digest != DIGEST_UNSPECIFIED)
|
2015-04-12 09:36:50 +00:00
|
|
|
xo_errx(1, "duplicated DataDigest at line %d", lineno);
|
2013-09-14 15:29:06 +00:00
|
|
|
if (strcasecmp($3, "none") == 0)
|
|
|
|
target->t_data_digest = DIGEST_NONE;
|
|
|
|
else if (strcasecmp($3, "CRC32C") == 0)
|
|
|
|
target->t_data_digest = DIGEST_CRC32C;
|
|
|
|
else
|
2015-04-12 09:36:50 +00:00
|
|
|
xo_errx(1, "invalid DataDigest at line %d; "
|
2014-02-10 15:03:08 +00:00
|
|
|
"must be either \"none\" or \"CRC32C\"", lineno);
|
2013-09-14 15:29:06 +00:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2014-02-10 15:01:24 +00:00
|
|
|
session_type: SESSION_TYPE EQUALS STR
|
2013-09-14 15:29:06 +00:00
|
|
|
{
|
|
|
|
if (target->t_session_type != SESSION_TYPE_UNSPECIFIED)
|
2015-04-12 09:36:50 +00:00
|
|
|
xo_errx(1, "duplicated SessionType at line %d", lineno);
|
2013-09-14 15:29:06 +00:00
|
|
|
if (strcasecmp($3, "normal") == 0)
|
|
|
|
target->t_session_type = SESSION_TYPE_NORMAL;
|
|
|
|
else if (strcasecmp($3, "discovery") == 0)
|
|
|
|
target->t_session_type = SESSION_TYPE_DISCOVERY;
|
|
|
|
else
|
2015-04-12 09:36:50 +00:00
|
|
|
xo_errx(1, "invalid SessionType at line %d; "
|
2014-02-10 15:03:08 +00:00
|
|
|
"must be either \"normal\" or \"discovery\"", lineno);
|
2013-09-14 15:29:06 +00:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2016-05-31 11:32:07 +00:00
|
|
|
enable: ENABLE EQUALS STR
|
|
|
|
{
|
|
|
|
if (target->t_enable != ENABLE_UNSPECIFIED)
|
|
|
|
xo_errx(1, "duplicated enable at line %d", lineno);
|
|
|
|
target->t_enable = parse_enable($3);
|
|
|
|
if (target->t_enable == ENABLE_UNSPECIFIED)
|
|
|
|
xo_errx(1, "invalid enable at line %d; "
|
|
|
|
"must be either \"on\" or \"off\"", lineno);
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2015-02-05 06:37:59 +00:00
|
|
|
offload: OFFLOAD EQUALS STR
|
|
|
|
{
|
|
|
|
if (target->t_offload != NULL)
|
2015-04-12 09:36:50 +00:00
|
|
|
xo_errx(1, "duplicated offload at line %d", lineno);
|
2015-02-05 06:37:59 +00:00
|
|
|
target->t_offload = $3;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2014-02-10 15:01:24 +00:00
|
|
|
protocol: PROTOCOL EQUALS STR
|
2013-09-14 15:29:06 +00:00
|
|
|
{
|
|
|
|
if (target->t_protocol != PROTOCOL_UNSPECIFIED)
|
2015-04-12 09:36:50 +00:00
|
|
|
xo_errx(1, "duplicated protocol at line %d", lineno);
|
2013-09-14 15:29:06 +00:00
|
|
|
if (strcasecmp($3, "iscsi") == 0)
|
|
|
|
target->t_protocol = PROTOCOL_ISCSI;
|
|
|
|
else if (strcasecmp($3, "iser") == 0)
|
|
|
|
target->t_protocol = PROTOCOL_ISER;
|
|
|
|
else
|
2015-04-12 09:36:50 +00:00
|
|
|
xo_errx(1, "invalid protocol at line %d; "
|
2014-02-10 15:03:08 +00:00
|
|
|
"must be either \"iscsi\" or \"iser\"", lineno);
|
2013-09-14 15:29:06 +00:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2014-02-10 15:01:24 +00:00
|
|
|
ignored: IGNORED EQUALS STR
|
2013-09-14 15:29:06 +00:00
|
|
|
{
|
2015-04-12 09:36:50 +00:00
|
|
|
xo_warnx("obsolete statement ignored at line %d", lineno);
|
2013-09-14 15:29:06 +00:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
%%
|
|
|
|
|
|
|
|
void
|
|
|
|
yyerror(const char *str)
|
|
|
|
{
|
|
|
|
|
2015-04-12 09:36:50 +00:00
|
|
|
xo_errx(1, "error in configuration file at line %d near '%s': %s",
|
2014-02-10 15:03:08 +00:00
|
|
|
lineno, yytext, str);
|
2013-09-14 15:29:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
check_perms(const char *path)
|
|
|
|
{
|
|
|
|
struct stat sb;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
error = stat(path, &sb);
|
|
|
|
if (error != 0) {
|
2015-04-12 09:36:50 +00:00
|
|
|
xo_warn("stat");
|
2013-09-14 15:29:06 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (sb.st_mode & S_IWOTH) {
|
2015-04-12 09:36:50 +00:00
|
|
|
xo_warnx("%s is world-writable", path);
|
2013-09-14 15:29:06 +00:00
|
|
|
} else if (sb.st_mode & S_IROTH) {
|
2015-04-12 09:36:50 +00:00
|
|
|
xo_warnx("%s is world-readable", path);
|
2013-09-14 15:29:06 +00:00
|
|
|
} else if (sb.st_mode & S_IXOTH) {
|
|
|
|
/*
|
|
|
|
* Ok, this one doesn't matter, but still do it,
|
|
|
|
* just for consistency.
|
|
|
|
*/
|
2015-04-12 09:36:50 +00:00
|
|
|
xo_warnx("%s is world-executable", path);
|
2013-09-14 15:29:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX: Should we also check for owner != 0?
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
struct conf *
|
|
|
|
conf_new_from_file(const char *path)
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
|
|
|
conf = conf_new();
|
|
|
|
target = target_new(conf);
|
|
|
|
|
|
|
|
yyin = fopen(path, "r");
|
|
|
|
if (yyin == NULL)
|
2015-04-12 09:36:50 +00:00
|
|
|
xo_err(1, "unable to open configuration file %s", path);
|
2013-09-14 15:29:06 +00:00
|
|
|
check_perms(path);
|
2014-02-10 15:03:08 +00:00
|
|
|
lineno = 1;
|
2013-09-14 15:29:06 +00:00
|
|
|
yyrestart(yyin);
|
|
|
|
error = yyparse();
|
|
|
|
assert(error == 0);
|
|
|
|
fclose(yyin);
|
|
|
|
|
|
|
|
assert(target->t_nickname == NULL);
|
|
|
|
target_delete(target);
|
|
|
|
|
|
|
|
conf_verify(conf);
|
|
|
|
|
|
|
|
return (conf);
|
|
|
|
}
|