%{ /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License (the "License"). * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright 2010 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. * Copyright (c) 2016, Chris Fraire . */ #include #include #include #include "nwamcfg.h" #include "nwamcfg_grammar.tab.h" int lex_lineno = 1; /* line number for error reporting */ static int state = INITIAL; extern boolean_t cmd_file_mode; int yyerror(const char *s); char *safe_strdup(char *s); %} %a 7000 %p 5000 %e 2000 %n 800 %o 12000 %{ /* * The state below are for tokens. */ %} %s TSTATE %% "#"[^\n]* { } cancel { BEGIN TSTATE; state = TSTATE; return CANCEL; } clear { BEGIN TSTATE; state = TSTATE; return CLEAR; } commit { BEGIN TSTATE; state = TSTATE; return COMMIT; } create { BEGIN TSTATE; state = TSTATE; return CREATE; } destroy { BEGIN TSTATE; state = TSTATE; return DESTROY; } end { BEGIN TSTATE; state = TSTATE; return END; } exit|quit { BEGIN TSTATE; state = TSTATE; return EXIT; } export { BEGIN TSTATE; state = TSTATE; return EXPORT; } get { BEGIN TSTATE; state = TSTATE; return GET; } "?"|help { BEGIN TSTATE; state = TSTATE; return HELP; } list { BEGIN TSTATE; state = TSTATE; return LIST; } revert { BEGIN TSTATE; state = TSTATE; return REVERT; } select { BEGIN TSTATE; state = TSTATE; return SELECT; } set { BEGIN TSTATE; state = TSTATE; return SET; } verify { BEGIN TSTATE; state = TSTATE; return VERIFY; } walkprop { BEGIN TSTATE; state = TSTATE; return WALKPROP; } [Ll][Oo][Cc] { return LOC; } [Nn][Cc][Pp] { return NCP; } [Ee][Nn][Mm] { return ENM; } [Ww][Ll][Aa][Nn] { return WLAN; } [Nn][Cc][Uu] { return NCU; } [Pp][Hh][Yy][Ss] { return PHYS; } [Ii][Pp] { return IP; } unknown { return UNKNOWN; } activation-mode { return ACTIVATION_MODE; } conditions { return CONDITIONS; } enabled { return ENABLED; } type { return TYPE; } class { return CLASS; } parent { return PARENT; } priority-group { return PRIORITY_GROUP; } priority-mode { return PRIORITY_MODE; } link-mac-addr { return LINK_MACADDR; } link-autopush { return LINK_AUTOPUSH; } link-mtu { return LINK_MTU; } ip-version { return IP_VERSION; } ipv4-addrsrc { return IPV4_ADDRSRC; } ipv4-addr { return IPV4_ADDR; } ipv4-default-route { return IPV4_DEFAULT_ROUTE; } ipv6-addrsrc { return IPV6_ADDRSRC; } ipv6-addr { return IPV6_ADDR; } ipv6-default-route { return IPV6_DEFAULT_ROUTE; } ip-primary { return IP_PRIMARY; } ip-reqhost { return IP_REQHOST; } state { return ENM_STATE; } fmri { return ENM_FMRI; } start { return ENM_START; } stop { return ENM_STOP; } nameservices { return LOC_NAMESERVICES; } nameservices-config-file { return LOC_NAMESERVICES_CONFIG; } dns-nameservice-configsrc { return LOC_DNS_CONFIGSRC; } dns-nameservice-domain { return LOC_DNS_DOMAIN; } dns-nameservice-servers { return LOC_DNS_SERVERS; } dns-nameservice-search { return LOC_DNS_SEARCH; } nis-nameservice-configsrc { return LOC_NIS_CONFIGSRC; } nis-nameservice-servers { return LOC_NIS_SERVERS; } ldap-nameservice-configsrc { return LOC_LDAP_CONFIGSRC; } ldap-nameservice-servers { return LOC_LDAP_SERVERS; } default-domain { return LOC_DEFAULT_DOMAIN; } nfsv4-domain { return LOC_NFSV4_DOMAIN; } ipfilter-config-file { return LOC_IPF_CONFIG; } ipfilter-v6-config-file { return LOC_IPF_V6_CONFIG; } ipnat-config-file { return LOC_IPNAT_CONFIG; } ippool-config-file { return LOC_IPPOOL_CONFIG; } ike-config-file { return LOC_IKE_CONFIG; } ipsecpolicy-config-file { return LOC_IPSECPOL_CONFIG; } bssids { return WLAN_BSSIDS; } priority { return WLAN_PRIORITY; } keyname { return WLAN_KEYNAME; } keyslot { return WLAN_KEYSLOT; } security-mode { return WLAN_SECURITY_MODE; } = { return EQUAL; } \-[adftV] { /* matches options */ yylval.strval = safe_strdup(yytext); return OPTION; } [^ \t\n\";=\[\]\(\)]+ { /* matches non-quoted values */ yylval.strval = safe_strdup(yytext); return TOKEN; } \"[^\"\n]*[\"\n] { /* matches string with quotes */ yylval.strval = safe_strdup(yytext); return TOKEN; } \".*\"\,\".*\" { /* matches string list of the form "a","b",.. */ yylval.strval = safe_strdup(yytext); return TOKEN; } ";" { BEGIN INITIAL; return (yytext[0]); } \n { lex_lineno++; BEGIN INITIAL; return (yytext[0]); } [ \t] ; /* ignore white space */ . { /* matches all single otherwise unmatched characters */ return (yytext[0]); } %% char * safe_strdup(char *s) { char *result; if ((result = strdup(s)) == NULL) { (void) yyerror("Out of memory"); exit(1); } return (result); } int yyerror(const char *s) { /* feof(yyin) is not an error; anything else is, so we set saw_error */ if (yytext[0] == '\0') { if (!feof(yyin)) { saw_error = B_TRUE; (void) fprintf(stderr, gettext("%s, token expected\n"), s); } return (0); } saw_error = B_TRUE; if (cmd_file_mode) { (void) fprintf(stderr, gettext("%s on line %d at '%s'\n"), s, lex_lineno, (yytext[0] == '\n') ? "\\n" : yytext); } else { (void) fprintf(stderr, gettext("%s at '%s'\n\n"), s, (yytext[0] == '\n') ? "\\n" : yytext); } help_wrap(); return (0); }