xref: /titanic_50/usr/src/cmd/zonecfg/zonecfg_grammar.y (revision bcd6185e1c81586e6929dc444ef32123263dd51c)
1 %{
2 /*
3  * CDDL HEADER START
4  *
5  * The contents of this file are subject to the terms of the
6  * Common Development and Distribution License (the "License").
7  * You may not use this file except in compliance with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 
23 /*
24  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
25  */
26 
27 #include <stdio.h>
28 #include <strings.h>
29 
30 #include "zonecfg.h"
31 
32 static cmd_t *cmd = NULL;		/* Command being processed */
33 static complex_property_ptr_t complex = NULL;
34 static list_property_ptr_t new_list = NULL, tmp_list, last,
35     list[MAX_EQ_PROP_PAIRS];
36 static property_value_t property[MAX_EQ_PROP_PAIRS];
37 
38 extern boolean_t newline_terminated;
39 extern int num_prop_vals;		/* # of property values */
40 
41 /* yacc externals */
42 extern int yydebug;
43 extern void yyerror(char *s);
44 
45 /*
46  * This function is used by the simple_prop_val reduction rules to set up
47  * a list_property_ptr_t and adjust the above global variables appropriately.
48  * Note that this function duplicates the specified string and makes
49  * the new list's lp_simple field point to the duplicate.  This function does
50  * not free the original string.
51  *
52  * This function returns a pointer to the duplicated string or NULL if an error
53  * occurred.  The simple_prop_val reduction rules that invoke this function
54  * should set $$ to the returned pointer.
55  */
56 static char *
57 simple_prop_val_func(const char *str)
58 {
59 	char *retstr;
60 
61 	if ((new_list = alloc_list()) == NULL)
62 		return (NULL);
63 	if ((retstr = strdup(str)) == NULL) {
64 		free_list(new_list);
65 		return (NULL);
66 	}
67 	new_list->lp_simple = retstr;
68 	new_list->lp_complex = NULL;
69 	new_list->lp_next = NULL;
70 	if (list[num_prop_vals] == NULL) {
71 		list[num_prop_vals] = new_list;
72 	} else {
73 		for (tmp_list = list[num_prop_vals]; tmp_list != NULL;
74 		    tmp_list = tmp_list->lp_next)
75 			last = tmp_list;
76 		last->lp_next = new_list;
77 	}
78 	return (retstr);
79 }
80 
81 /*
82  * This function is used by the complex_piece reduction rules to set up a
83  * complex_property_prt_t and adjust the above global variables appropriately.
84  * Note that this function duplicates the specified string and makes the new
85  * complex_property_ptr_t's cp_value field point to the duplicate.  It also sets
86  * the complex_property_ptr_t's cp_type field to cp_type and its cp_next field
87  * to cp_next.  This function does not free the original string.
88  *
89  * This function returns a pointer to the complex_property_t created for the
90  * complex_piece or NULL if an error occurred.  The complex_piece reduction
91  * rules that invoke this function should set $$ to the returned pointer.
92  */
93 static complex_property_ptr_t
94 complex_piece_func(int cp_type, const char *str, complex_property_ptr_t cp_next)
95 {
96 	complex_property_ptr_t retval;
97 
98 	if ((retval = alloc_complex()) == NULL)
99 		return (NULL);
100 	if ((retval->cp_value = strdup(str)) == NULL) {
101 		free_complex(retval);
102 		return (NULL);
103 	}
104 	retval->cp_type = cp_type;
105 	retval->cp_next = cp_next;
106 	complex = retval;
107 	return (retval);
108 }
109 
110 
111 %}
112 
113 %union {
114 	int ival;
115 	char *strval;
116 	cmd_t *cmd;
117 	complex_property_ptr_t complex;
118 	list_property_ptr_t list;
119 }
120 
121 %start commands
122 
123 %token HELP CREATE EXPORT ADD DELETE REMOVE SELECT SET INFO CANCEL END VERIFY
124 %token COMMIT REVERT EXIT SEMICOLON TOKEN ZONENAME ZONEPATH AUTOBOOT POOL NET
125 %token FS ATTR DEVICE RCTL SPECIAL RAW DIR OPTIONS TYPE ADDRESS PHYSICAL
126 %token IPTYPE HOSTID FS_ALLOWED ALLOWED_ADDRESS
127 %token NAME MATCH PRIV LIMIT ACTION VALUE EQUAL OPEN_SQ_BRACKET CLOSE_SQ_BRACKET
128 %token OPEN_PAREN CLOSE_PAREN COMMA DATASET LIMITPRIV BOOTARGS BRAND PSET PCAP
129 %token MCAP NCPUS IMPORTANCE SHARES MAXLWPS MAXSHMMEM MAXSHMIDS MAXMSGIDS
130 %token MAXSEMIDS LOCKED SWAP SCHED CLEAR DEFROUTER ADMIN USER AUTHS MAXPROCS
131 
132 %type <strval> TOKEN EQUAL OPEN_SQ_BRACKET CLOSE_SQ_BRACKET
133     property_value OPEN_PAREN CLOSE_PAREN COMMA simple_prop_val
134 %type <complex> complex_piece complex_prop_val
135 %type <ival> resource_type NET FS DEVICE RCTL ATTR DATASET PSET PCAP MCAP
136     ADMIN
137 %type <ival> property_name SPECIAL RAW DIR OPTIONS TYPE ADDRESS PHYSICAL NAME
138     MATCH ZONENAME ZONEPATH AUTOBOOT POOL LIMITPRIV BOOTARGS VALUE PRIV LIMIT
139     ACTION BRAND SCHED IPTYPE DEFROUTER HOSTID USER AUTHS FS_ALLOWED
140     ALLOWED_ADDRESS
141 %type <cmd> command
142 %type <cmd> add_command ADD
143 %type <cmd> cancel_command CANCEL
144 %type <cmd> commit_command COMMIT
145 %type <cmd> create_command CREATE
146 %type <cmd> delete_command DELETE
147 %type <cmd> end_command END
148 %type <cmd> exit_command EXIT
149 %type <cmd> export_command EXPORT
150 %type <cmd> help_command HELP
151 %type <cmd> info_command INFO
152 %type <cmd> remove_command REMOVE
153 %type <cmd> revert_command REVERT
154 %type <cmd> select_command SELECT
155 %type <cmd> set_command SET
156 %type <cmd> clear_command CLEAR
157 %type <cmd> verify_command VERIFY
158 %type <cmd> terminator
159 
160 %%
161 
162 commands: command terminator
163 	{
164 		if ($1 != NULL) {
165 			if ($1->cmd_handler != NULL)
166 				$1->cmd_handler($1);
167 			free_cmd($1);
168 			bzero(list, sizeof (list_property_t));
169 			num_prop_vals = 0;
170 		}
171 		return (0);
172 	}
173 	| command error terminator
174 	{
175 		if ($1 != NULL) {
176 			free_cmd($1);
177 			bzero(list, sizeof (list_property_t));
178 			num_prop_vals = 0;
179 		}
180 		if (YYRECOVERING())
181 			YYABORT;
182 		yyclearin;
183 		yyerrok;
184 	}
185 	| error terminator
186 	{
187 		if (YYRECOVERING())
188 			YYABORT;
189 		yyclearin;
190 		yyerrok;
191 	}
192 	| terminator
193 	{
194 		return (0);
195 	}
196 
197 command: add_command
198 	| cancel_command
199 	| clear_command
200 	| create_command
201 	| commit_command
202 	| delete_command
203 	| end_command
204 	| exit_command
205 	| export_command
206 	| help_command
207 	| info_command
208 	| remove_command
209 	| revert_command
210 	| select_command
211 	| set_command
212 	| verify_command
213 
214 terminator:	'\n'	{ newline_terminated = B_TRUE; }
215 	|	';'	{ newline_terminated = B_FALSE; }
216 
217 add_command: ADD
218 	{
219 		short_usage(CMD_ADD);
220 		(void) fputs("\n", stderr);
221 		usage(B_FALSE, HELP_RES_PROPS);
222 		YYERROR;
223 	}
224 	| ADD TOKEN
225 	{
226 		if (($$ = alloc_cmd()) == NULL)
227 			YYERROR;
228 		cmd = $$;
229 		$$->cmd_handler = &add_func;
230 		$$->cmd_argc = 1;
231 		$$->cmd_argv[0] = $2;
232 		$$->cmd_argv[1] = NULL;
233 	}
234 	| ADD resource_type
235 	{
236 		if (($$ = alloc_cmd()) == NULL)
237 			YYERROR;
238 		cmd = $$;
239 		$$->cmd_handler = &add_func;
240 		$$->cmd_argc = 0;
241 		$$->cmd_res_type = $2;
242 		$$->cmd_prop_nv_pairs = 0;
243 	}
244 	| ADD property_name property_value
245 	{
246 		if (($$ = alloc_cmd()) == NULL)
247 			YYERROR;
248 		cmd = $$;
249 		$$->cmd_handler = &add_func;
250 		$$->cmd_argc = 0;
251 		$$->cmd_prop_nv_pairs = 1;
252 		$$->cmd_prop_name[0] = $2;
253 		$$->cmd_property_ptr[0] = &property[0];
254 	}
255 
256 cancel_command: CANCEL
257 	{
258 		if (($$ = alloc_cmd()) == NULL)
259 			YYERROR;
260 		cmd = $$;
261 		$$->cmd_handler = &cancel_func;
262 		$$->cmd_argc = 0;
263 		$$->cmd_argv[0] = NULL;
264 	}
265 	| CANCEL TOKEN
266 	{
267 		if (($$ = alloc_cmd()) == NULL)
268 			YYERROR;
269 		cmd = $$;
270 		$$->cmd_handler = &cancel_func;
271 		$$->cmd_argc = 1;
272 		$$->cmd_argv[0] = $2;
273 		$$->cmd_argv[1] = NULL;
274 	}
275 
276 create_command: CREATE
277 	{
278 		if (($$ = alloc_cmd()) == NULL)
279 			YYERROR;
280 		cmd = $$;
281 		$$->cmd_handler = &create_func;
282 		$$->cmd_argc = 0;
283 		$$->cmd_argv[0] = NULL;
284 	}
285 	| CREATE TOKEN
286 	{
287 		if (($$ = alloc_cmd()) == NULL)
288 			YYERROR;
289 		cmd = $$;
290 		$$->cmd_handler = &create_func;
291 		$$->cmd_argc = 1;
292 		$$->cmd_argv[0] = $2;
293 		$$->cmd_argv[1] = NULL;
294 	}
295 	| CREATE TOKEN TOKEN
296 	{
297 		if (($$ = alloc_cmd()) == NULL)
298 			YYERROR;
299 		cmd = $$;
300 		$$->cmd_handler = &create_func;
301 		$$->cmd_argc = 2;
302 		$$->cmd_argv[0] = $2;
303 		$$->cmd_argv[1] = $3;
304 		$$->cmd_argv[2] = NULL;
305 	}
306 	| CREATE TOKEN TOKEN TOKEN
307 	{
308 		if (($$ = alloc_cmd()) == NULL)
309 			YYERROR;
310 		cmd = $$;
311 		$$->cmd_handler = &create_func;
312 		$$->cmd_argc = 3;
313 		$$->cmd_argv[0] = $2;
314 		$$->cmd_argv[1] = $3;
315 		$$->cmd_argv[2] = $4;
316 		$$->cmd_argv[3] = NULL;
317 	}
318 
319 commit_command: COMMIT
320 	{
321 		if (($$ = alloc_cmd()) == NULL)
322 			YYERROR;
323 		cmd = $$;
324 		$$->cmd_handler = &commit_func;
325 		$$->cmd_argc = 0;
326 		$$->cmd_argv[0] = NULL;
327 	}
328 	| COMMIT TOKEN
329 	{
330 		if (($$ = alloc_cmd()) == NULL)
331 			YYERROR;
332 		cmd = $$;
333 		$$->cmd_handler = &commit_func;
334 		$$->cmd_argc = 1;
335 		$$->cmd_argv[0] = $2;
336 		$$->cmd_argv[1] = NULL;
337 	}
338 
339 delete_command: DELETE
340 	{
341 		if (($$ = alloc_cmd()) == NULL)
342 			YYERROR;
343 		cmd = $$;
344 		$$->cmd_handler = &delete_func;
345 		$$->cmd_argc = 0;
346 		$$->cmd_argv[0] = NULL;
347 	}
348 	|	DELETE TOKEN
349 	{
350 		if (($$ = alloc_cmd()) == NULL)
351 			YYERROR;
352 		cmd = $$;
353 		$$->cmd_handler = &delete_func;
354 		$$->cmd_argc = 1;
355 		$$->cmd_argv[0] = $2;
356 		$$->cmd_argv[1] = NULL;
357 	}
358 
359 end_command: END
360 	{
361 		if (($$ = alloc_cmd()) == NULL)
362 			YYERROR;
363 		cmd = $$;
364 		$$->cmd_handler = &end_func;
365 		$$->cmd_argc = 0;
366 		$$->cmd_argv[0] = NULL;
367 	}
368 	| END TOKEN
369 	{
370 		if (($$ = alloc_cmd()) == NULL)
371 			YYERROR;
372 		cmd = $$;
373 		$$->cmd_handler = &end_func;
374 		$$->cmd_argc = 1;
375 		$$->cmd_argv[0] = $2;
376 		$$->cmd_argv[1] = NULL;
377 	}
378 
379 exit_command: EXIT
380 	{
381 		if (($$ = alloc_cmd()) == NULL)
382 			YYERROR;
383 		cmd = $$;
384 		$$->cmd_handler = &exit_func;
385 		$$->cmd_argc = 0;
386 		$$->cmd_argv[0] = NULL;
387 	}
388 	| EXIT TOKEN
389 	{
390 		if (($$ = alloc_cmd()) == NULL)
391 			YYERROR;
392 		cmd = $$;
393 		$$->cmd_handler = &exit_func;
394 		$$->cmd_argc = 1;
395 		$$->cmd_argv[0] = $2;
396 		$$->cmd_argv[1] = NULL;
397 	}
398 
399 export_command: EXPORT
400 	{
401 		if (($$ = alloc_cmd()) == NULL)
402 			YYERROR;
403 		cmd = $$;
404 		$$->cmd_handler = &export_func;
405 		$$->cmd_argc = 0;
406 		$$->cmd_argv[0] = NULL;
407 	}
408 	| EXPORT TOKEN
409 	{
410 		if (($$ = alloc_cmd()) == NULL)
411 			YYERROR;
412 		cmd = $$;
413 		$$->cmd_handler = &export_func;
414 		$$->cmd_argc = 1;
415 		$$->cmd_argv[0] = $2;
416 		$$->cmd_argv[1] = NULL;
417 	}
418 	| EXPORT TOKEN TOKEN
419 	{
420 		if (($$ = alloc_cmd()) == NULL)
421 			YYERROR;
422 		cmd = $$;
423 		$$->cmd_handler = &export_func;
424 		$$->cmd_argc = 2;
425 		$$->cmd_argv[0] = $2;
426 		$$->cmd_argv[1] = $3;
427 		$$->cmd_argv[2] = NULL;
428 	}
429 
430 help_command:	HELP
431 	{
432 		if (($$ = alloc_cmd()) == NULL)
433 			YYERROR;
434 		cmd = $$;
435 		$$->cmd_handler = &help_func;
436 		$$->cmd_argc = 0;
437 		$$->cmd_argv[0] = NULL;
438 	}
439 	|	HELP TOKEN
440 	{
441 		if (($$ = alloc_cmd()) == NULL)
442 			YYERROR;
443 		cmd = $$;
444 		$$->cmd_handler = &help_func;
445 		$$->cmd_argc = 1;
446 		$$->cmd_argv[0] = $2;
447 		$$->cmd_argv[1] = NULL;
448 	}
449 
450 info_command:	INFO
451 	{
452 		if (($$ = alloc_cmd()) == NULL)
453 			YYERROR;
454 		cmd = $$;
455 		$$->cmd_handler = &info_func;
456 		$$->cmd_res_type = RT_UNKNOWN;
457 		$$->cmd_prop_nv_pairs = 0;
458 	}
459 	|	INFO TOKEN
460 	{
461 		short_usage(CMD_INFO);
462 		(void) fputs("\n", stderr);
463 		usage(B_FALSE, HELP_RES_PROPS);
464 		free($2);
465 		YYERROR;
466 	}
467 	|	INFO resource_type
468 	{
469 		if (($$ = alloc_cmd()) == NULL)
470 			YYERROR;
471 		cmd = $$;
472 		$$->cmd_handler = &info_func;
473 		$$->cmd_res_type = $2;
474 		$$->cmd_prop_nv_pairs = 0;
475 	}
476 	|	INFO ZONENAME
477 	{
478 		if (($$ = alloc_cmd()) == NULL)
479 			YYERROR;
480 		cmd = $$;
481 		$$->cmd_handler = &info_func;
482 		$$->cmd_res_type = RT_ZONENAME;
483 		$$->cmd_prop_nv_pairs = 0;
484 	}
485 	|	INFO ZONEPATH
486 	{
487 		if (($$ = alloc_cmd()) == NULL)
488 			YYERROR;
489 		cmd = $$;
490 		$$->cmd_handler = &info_func;
491 		$$->cmd_res_type = RT_ZONEPATH;
492 		$$->cmd_prop_nv_pairs = 0;
493 	}
494 	|	INFO BRAND
495 	{
496 		if (($$ = alloc_cmd()) == NULL)
497 			YYERROR;
498 		cmd = $$;
499 		$$->cmd_handler = &info_func;
500 		$$->cmd_res_type = RT_BRAND;
501 		$$->cmd_prop_nv_pairs = 0;
502 	}
503 	|	INFO AUTOBOOT
504 	{
505 		if (($$ = alloc_cmd()) == NULL)
506 			YYERROR;
507 		cmd = $$;
508 		$$->cmd_handler = &info_func;
509 		$$->cmd_res_type = RT_AUTOBOOT;
510 		$$->cmd_prop_nv_pairs = 0;
511 	}
512 	|	INFO IPTYPE
513 	{
514 		if (($$ = alloc_cmd()) == NULL)
515 			YYERROR;
516 		cmd = $$;
517 		$$->cmd_handler = &info_func;
518 		$$->cmd_res_type = RT_IPTYPE;
519 		$$->cmd_prop_nv_pairs = 0;
520 	}
521 	|	INFO POOL
522 	{
523 		if (($$ = alloc_cmd()) == NULL)
524 			YYERROR;
525 		cmd = $$;
526 		$$->cmd_handler = &info_func;
527 		$$->cmd_res_type = RT_POOL;
528 		$$->cmd_prop_nv_pairs = 0;
529 	}
530 	|	INFO LIMITPRIV
531 	{
532 		if (($$ = alloc_cmd()) == NULL)
533 			YYERROR;
534 		cmd = $$;
535 		$$->cmd_handler = &info_func;
536 		$$->cmd_res_type = RT_LIMITPRIV;
537 		$$->cmd_prop_nv_pairs = 0;
538 	}
539 	|	INFO BOOTARGS
540 	{
541 		if (($$ = alloc_cmd()) == NULL)
542 			YYERROR;
543 		cmd = $$;
544 		$$->cmd_handler = &info_func;
545 		$$->cmd_res_type = RT_BOOTARGS;
546 		$$->cmd_prop_nv_pairs = 0;
547 	}
548 	|	INFO SCHED
549 	{
550 		if (($$ = alloc_cmd()) == NULL)
551 			YYERROR;
552 		cmd = $$;
553 		$$->cmd_handler = &info_func;
554 		$$->cmd_res_type = RT_SCHED;
555 		$$->cmd_prop_nv_pairs = 0;
556 	}
557 	|	INFO SHARES
558 	{
559 		if (($$ = alloc_cmd()) == NULL)
560 			YYERROR;
561 		cmd = $$;
562 		$$->cmd_handler = &info_func;
563 		$$->cmd_res_type = RT_SHARES;
564 		$$->cmd_prop_nv_pairs = 0;
565 	}
566 	|	INFO MAXLWPS
567 	{
568 		if (($$ = alloc_cmd()) == NULL)
569 			YYERROR;
570 		cmd = $$;
571 		$$->cmd_handler = &info_func;
572 		$$->cmd_res_type = RT_MAXLWPS;
573 		$$->cmd_prop_nv_pairs = 0;
574 	}
575 	|	INFO MAXPROCS
576 	{
577 		if (($$ = alloc_cmd()) == NULL)
578 			YYERROR;
579 		cmd = $$;
580 		$$->cmd_handler = &info_func;
581 		$$->cmd_res_type = RT_MAXPROCS;
582 		$$->cmd_prop_nv_pairs = 0;
583 	}
584 	|	INFO MAXSHMMEM
585 	{
586 		if (($$ = alloc_cmd()) == NULL)
587 			YYERROR;
588 		cmd = $$;
589 		$$->cmd_handler = &info_func;
590 		$$->cmd_res_type = RT_MAXSHMMEM;
591 		$$->cmd_prop_nv_pairs = 0;
592 	}
593 	|	INFO MAXSHMIDS
594 	{
595 		if (($$ = alloc_cmd()) == NULL)
596 			YYERROR;
597 		cmd = $$;
598 		$$->cmd_handler = &info_func;
599 		$$->cmd_res_type = RT_MAXSHMIDS;
600 		$$->cmd_prop_nv_pairs = 0;
601 	}
602 	|	INFO MAXMSGIDS
603 	{
604 		if (($$ = alloc_cmd()) == NULL)
605 			YYERROR;
606 		cmd = $$;
607 		$$->cmd_handler = &info_func;
608 		$$->cmd_res_type = RT_MAXMSGIDS;
609 		$$->cmd_prop_nv_pairs = 0;
610 	}
611 	|	INFO MAXSEMIDS
612 	{
613 		if (($$ = alloc_cmd()) == NULL)
614 			YYERROR;
615 		cmd = $$;
616 		$$->cmd_handler = &info_func;
617 		$$->cmd_res_type = RT_MAXSEMIDS;
618 		$$->cmd_prop_nv_pairs = 0;
619 	}
620 	|	INFO HOSTID
621 	{
622 		if (($$ = alloc_cmd()) == NULL)
623 			YYERROR;
624 		cmd = $$;
625 		$$->cmd_handler = &info_func;
626 		$$->cmd_res_type = RT_HOSTID;
627 		$$->cmd_prop_nv_pairs = 0;
628 	}
629 	|	INFO FS_ALLOWED
630 	{
631 		if (($$ = alloc_cmd()) == NULL)
632 			YYERROR;
633 		cmd = $$;
634 		$$->cmd_handler = &info_func;
635 		$$->cmd_res_type = RT_FS_ALLOWED;
636 		$$->cmd_prop_nv_pairs = 0;
637 	}
638 	|	INFO resource_type property_name EQUAL property_value
639 	{
640 		if (($$ = alloc_cmd()) == NULL)
641 			YYERROR;
642 		cmd = $$;
643 		$$->cmd_handler = &info_func;
644 		$$->cmd_res_type = $2;
645 		$$->cmd_prop_nv_pairs = 1;
646 		$$->cmd_prop_name[0] = $3;
647 		$$->cmd_property_ptr[0] = &property[0];
648 	}
649 	|	INFO resource_type property_name EQUAL property_value property_name EQUAL property_value
650 	{
651 		if (($$ = alloc_cmd()) == NULL)
652 			YYERROR;
653 		cmd = $$;
654 		$$->cmd_handler = &info_func;
655 		$$->cmd_res_type = $2;
656 		$$->cmd_prop_nv_pairs = 2;
657 		$$->cmd_prop_name[0] = $3;
658 		$$->cmd_property_ptr[0] = &property[0];
659 		$$->cmd_prop_name[1] = $6;
660 		$$->cmd_property_ptr[1] = &property[1];
661 	}
662 	|	INFO resource_type property_name EQUAL property_value property_name EQUAL property_value property_name EQUAL property_value
663 	{
664 		if (($$ = alloc_cmd()) == NULL)
665 			YYERROR;
666 		cmd = $$;
667 		$$->cmd_handler = &info_func;
668 		$$->cmd_res_type = $2;
669 		$$->cmd_prop_nv_pairs = 3;
670 		$$->cmd_prop_name[0] = $3;
671 		$$->cmd_property_ptr[0] = &property[0];
672 		$$->cmd_prop_name[1] = $6;
673 		$$->cmd_property_ptr[1] = &property[1];
674 		$$->cmd_prop_name[2] = $9;
675 		$$->cmd_property_ptr[2] = &property[2];
676 	}
677 
678 remove_command: REMOVE
679 	{
680 		short_usage(CMD_REMOVE);
681 		(void) fputs("\n", stderr);
682 		usage(B_FALSE, HELP_RES_PROPS);
683 		YYERROR;
684 	}
685 	| REMOVE TOKEN
686 	{
687 		short_usage(CMD_REMOVE);
688 		(void) fputs("\n", stderr);
689 		usage(B_FALSE, HELP_RES_PROPS);
690 		YYERROR;
691 	}
692 	| REMOVE resource_type
693 	{
694 		if (($$ = alloc_cmd()) == NULL)
695 			YYERROR;
696 		cmd = $$;
697 		$$->cmd_handler = &remove_func;
698 		$$->cmd_res_type = $2;
699 	}
700 	| REMOVE TOKEN resource_type
701 	{
702 		if (($$ = alloc_cmd()) == NULL)
703 			YYERROR;
704 		cmd = $$;
705 		$$->cmd_handler = &remove_func;
706 		$$->cmd_res_type = $3;
707 		$$->cmd_argc = 1;
708 		$$->cmd_argv[0] = $2;
709 		$$->cmd_argv[1] = NULL;
710 	}
711 	| REMOVE property_name property_value
712 	{
713 		if (($$ = alloc_cmd()) == NULL)
714 			YYERROR;
715 		cmd = $$;
716 		$$->cmd_handler = &remove_func;
717 		$$->cmd_prop_nv_pairs = 1;
718 		$$->cmd_prop_name[0] = $2;
719 		$$->cmd_property_ptr[0] = &property[0];
720 	}
721 	| REMOVE resource_type property_name EQUAL property_value
722 	{
723 		if (($$ = alloc_cmd()) == NULL)
724 			YYERROR;
725 		cmd = $$;
726 		$$->cmd_handler = &remove_func;
727 		$$->cmd_res_type = $2;
728 		$$->cmd_prop_nv_pairs = 1;
729 		$$->cmd_prop_name[0] = $3;
730 		$$->cmd_property_ptr[0] = &property[0];
731 	}
732 	| REMOVE resource_type property_name EQUAL property_value property_name EQUAL property_value
733 	{
734 		if (($$ = alloc_cmd()) == NULL)
735 			YYERROR;
736 		cmd = $$;
737 		$$->cmd_handler = &remove_func;
738 		$$->cmd_res_type = $2;
739 		$$->cmd_prop_nv_pairs = 2;
740 		$$->cmd_prop_name[0] = $3;
741 		$$->cmd_property_ptr[0] = &property[0];
742 		$$->cmd_prop_name[1] = $6;
743 		$$->cmd_property_ptr[1] = &property[1];
744 	}
745 	| REMOVE resource_type property_name EQUAL property_value property_name EQUAL property_value property_name EQUAL property_value
746 	{
747 		if (($$ = alloc_cmd()) == NULL)
748 			YYERROR;
749 		cmd = $$;
750 		$$->cmd_handler = &remove_func;
751 		$$->cmd_res_type = $2;
752 		$$->cmd_prop_nv_pairs = 3;
753 		$$->cmd_prop_name[0] = $3;
754 		$$->cmd_property_ptr[0] = &property[0];
755 		$$->cmd_prop_name[1] = $6;
756 		$$->cmd_property_ptr[1] = &property[1];
757 		$$->cmd_prop_name[2] = $9;
758 		$$->cmd_property_ptr[2] = &property[2];
759 	}
760 
761 revert_command: REVERT
762 	{
763 		if (($$ = alloc_cmd()) == NULL)
764 			YYERROR;
765 		cmd = $$;
766 		$$->cmd_handler = &revert_func;
767 		$$->cmd_argc = 0;
768 		$$->cmd_argv[0] = NULL;
769 	}
770 	| REVERT TOKEN
771 	{
772 		if (($$ = alloc_cmd()) == NULL)
773 			YYERROR;
774 		cmd = $$;
775 		$$->cmd_handler = &revert_func;
776 		$$->cmd_argc = 1;
777 		$$->cmd_argv[0] = $2;
778 		$$->cmd_argv[1] = NULL;
779 	}
780 
781 select_command: SELECT
782 	{
783 		short_usage(CMD_SELECT);
784 		(void) fputs("\n", stderr);
785 		usage(B_FALSE, HELP_RES_PROPS);
786 		YYERROR;
787 	}
788 	| SELECT PSET
789 	{
790 		if (($$ = alloc_cmd()) == NULL)
791 			YYERROR;
792 		cmd = $$;
793 		$$->cmd_handler = &select_func;
794 		$$->cmd_res_type = RT_DCPU;
795 	}
796 	| SELECT PCAP
797 	{
798 		if (($$ = alloc_cmd()) == NULL)
799 			YYERROR;
800 		cmd = $$;
801 		$$->cmd_handler = &select_func;
802 		$$->cmd_res_type = RT_PCAP;
803 	}
804 	| SELECT MCAP
805 	{
806 		if (($$ = alloc_cmd()) == NULL)
807 			YYERROR;
808 		cmd = $$;
809 		$$->cmd_handler = &select_func;
810 		$$->cmd_res_type = RT_MCAP;
811 	}
812 	| SELECT resource_type
813 	{
814 		short_usage(CMD_SELECT);
815 		YYERROR;
816 	}
817 	| SELECT resource_type property_name EQUAL property_value
818 	{
819 		if (($$ = alloc_cmd()) == NULL)
820 			YYERROR;
821 		cmd = $$;
822 		$$->cmd_handler = &select_func;
823 		$$->cmd_res_type = $2;
824 		$$->cmd_prop_nv_pairs = 1;
825 		$$->cmd_prop_name[0] = $3;
826 		$$->cmd_property_ptr[0] = &property[0];
827 	}
828 	| SELECT resource_type property_name EQUAL property_value property_name EQUAL property_value
829 	{
830 		if (($$ = alloc_cmd()) == NULL)
831 			YYERROR;
832 		cmd = $$;
833 		$$->cmd_handler = &select_func;
834 		$$->cmd_res_type = $2;
835 		$$->cmd_prop_nv_pairs = 2;
836 		$$->cmd_prop_name[0] = $3;
837 		$$->cmd_property_ptr[0] = &property[0];
838 		$$->cmd_prop_name[1] = $6;
839 		$$->cmd_property_ptr[1] = &property[1];
840 	}
841 	| SELECT resource_type property_name EQUAL property_value property_name EQUAL property_value property_name EQUAL property_value
842 	{
843 		if (($$ = alloc_cmd()) == NULL)
844 			YYERROR;
845 		cmd = $$;
846 		$$->cmd_handler = &select_func;
847 		$$->cmd_res_type = $2;
848 		$$->cmd_prop_nv_pairs = 3;
849 		$$->cmd_prop_name[0] = $3;
850 		$$->cmd_property_ptr[0] = &property[0];
851 		$$->cmd_prop_name[1] = $6;
852 		$$->cmd_property_ptr[1] = &property[1];
853 		$$->cmd_prop_name[2] = $9;
854 		$$->cmd_property_ptr[2] = &property[2];
855 	}
856 
857 set_command: SET
858 	{
859 		short_usage(CMD_SET);
860 		(void) fputs("\n", stderr);
861 		usage(B_FALSE, HELP_PROPS);
862 		YYERROR;
863 	}
864 	| SET property_name EQUAL OPEN_SQ_BRACKET CLOSE_SQ_BRACKET
865 	{
866 		if (($$ = alloc_cmd()) == NULL)
867 			YYERROR;
868 		cmd = $$;
869 		$$->cmd_handler = &set_func;
870 		$$->cmd_prop_nv_pairs = 0;
871 		$$->cmd_prop_name[0] = $2;
872 		property[0].pv_type = PROP_VAL_LIST;
873 		property[0].pv_list = NULL;
874 		$$->cmd_property_ptr[0] = &property[0];
875 	}
876 	| SET property_name EQUAL property_value
877 	{
878 		if (($$ = alloc_cmd()) == NULL)
879 			YYERROR;
880 		cmd = $$;
881 		$$->cmd_handler = &set_func;
882 		$$->cmd_prop_nv_pairs = 1;
883 		$$->cmd_prop_name[0] = $2;
884 		$$->cmd_property_ptr[0] = &property[0];
885 	}
886 	| SET TOKEN ZONEPATH EQUAL property_value
887 	{
888 		if (($$ = alloc_cmd()) == NULL)
889 			YYERROR;
890 		cmd = $$;
891 		$$->cmd_argc = 1;
892 		$$->cmd_argv[0] = $2;
893 		$$->cmd_argv[1] = NULL;
894 		$$->cmd_handler = &set_func;
895 		$$->cmd_prop_nv_pairs = 1;
896 		$$->cmd_prop_name[0] = PT_ZONEPATH;
897 		$$->cmd_property_ptr[0] = &property[0];
898 	}
899 
900 clear_command: CLEAR
901 	{
902 		short_usage(CMD_CLEAR);
903 		(void) fputs("\n", stderr);
904 		usage(B_FALSE, HELP_PROPS);
905 		YYERROR;
906 	}
907 	| CLEAR property_name
908 	{
909 		if (($$ = alloc_cmd()) == NULL)
910 			YYERROR;
911 		cmd = $$;
912 		$$->cmd_handler = &clear_func;
913 		$$->cmd_res_type = $2;
914 	}
915 
916 verify_command: VERIFY
917 	{
918 		if (($$ = alloc_cmd()) == NULL)
919 			YYERROR;
920 		cmd = $$;
921 		$$->cmd_handler = &verify_func;
922 		$$->cmd_argc = 0;
923 		$$->cmd_argv[0] = NULL;
924 	}
925 	| VERIFY TOKEN
926 	{
927 		if (($$ = alloc_cmd()) == NULL)
928 			YYERROR;
929 		cmd = $$;
930 		$$->cmd_handler = &verify_func;
931 		$$->cmd_argc = 1;
932 		$$->cmd_argv[0] = $2;
933 		$$->cmd_argv[1] = NULL;
934 	}
935 
936 resource_type: NET	{ $$ = RT_NET; }
937 	| FS		{ $$ = RT_FS; }
938 	| DEVICE	{ $$ = RT_DEVICE; }
939 	| RCTL		{ $$ = RT_RCTL; }
940 	| ATTR		{ $$ = RT_ATTR; }
941 	| DATASET	{ $$ = RT_DATASET; }
942 	| PSET		{ $$ = RT_DCPU; }
943 	| PCAP		{ $$ = RT_PCAP; }
944 	| MCAP		{ $$ = RT_MCAP; }
945 	| ADMIN		{ $$ = RT_ADMIN; }
946 
947 property_name: SPECIAL	{ $$ = PT_SPECIAL; }
948 	| RAW		{ $$ = PT_RAW; }
949 	| DIR		{ $$ = PT_DIR; }
950 	| TYPE		{ $$ = PT_TYPE; }
951 	| OPTIONS	{ $$ = PT_OPTIONS; }
952 	| ZONENAME	{ $$ = PT_ZONENAME; }
953 	| ZONEPATH	{ $$ = PT_ZONEPATH; }
954 	| AUTOBOOT	{ $$ = PT_AUTOBOOT; }
955 	| IPTYPE	{ $$ = PT_IPTYPE; }
956 	| POOL		{ $$ = PT_POOL; }
957 	| LIMITPRIV	{ $$ = PT_LIMITPRIV; }
958 	| BOOTARGS	{ $$ = PT_BOOTARGS; }
959 	| ADDRESS	{ $$ = PT_ADDRESS; }
960 	| ALLOWED_ADDRESS	{ $$ = PT_ALLOWED_ADDRESS; }
961 	| PHYSICAL	{ $$ = PT_PHYSICAL; }
962 	| DEFROUTER	{ $$ = PT_DEFROUTER; }
963 	| NAME		{ $$ = PT_NAME; }
964 	| VALUE		{ $$ = PT_VALUE; }
965 	| MATCH		{ $$ = PT_MATCH; }
966 	| PRIV		{ $$ = PT_PRIV; }
967 	| LIMIT		{ $$ = PT_LIMIT; }
968 	| ACTION	{ $$ = PT_ACTION; }
969 	| BRAND		{ $$ = PT_BRAND; }
970 	| NCPUS		{ $$ = PT_NCPUS; }
971 	| LOCKED	{ $$ = PT_LOCKED; }
972 	| SWAP		{ $$ = PT_SWAP; }
973 	| IMPORTANCE	{ $$ = PT_IMPORTANCE; }
974 	| SHARES	{ $$ = PT_SHARES; }
975 	| MAXLWPS	{ $$ = PT_MAXLWPS; }
976 	| MAXPROCS	{ $$ = PT_MAXPROCS; }
977 	| MAXSHMMEM	{ $$ = PT_MAXSHMMEM; }
978 	| MAXSHMIDS	{ $$ = PT_MAXSHMIDS; }
979 	| MAXMSGIDS	{ $$ = PT_MAXMSGIDS; }
980 	| MAXSEMIDS	{ $$ = PT_MAXSEMIDS; }
981 	| SCHED		{ $$ = PT_SCHED; }
982 	| HOSTID	{ $$ = PT_HOSTID; }
983 	| USER		{ $$ = PT_USER; }
984 	| AUTHS 	{ $$ = PT_AUTHS; }
985 	| FS_ALLOWED	{ $$ = PT_FS_ALLOWED; }
986 
987 /*
988  * The grammar builds data structures from the bottom up.  Thus various
989  * strings are lexed into TOKENs or commands or resource or property values.
990  * Below is where the resource and property values are built up into more
991  * complex data structures.
992  *
993  * There are three kinds of properties: simple (single valued), complex
994  * (one or more name=value pairs) and list (concatenation of one or more
995  * simple or complex properties).
996  *
997  * So the property structure has a type which is one of these, and the
998  * corresponding _simple, _complex or _list is set to the corresponding
999  * lower-level data structure.
1000  */
1001 
1002 property_value: simple_prop_val
1003 	{
1004 		property[num_prop_vals].pv_type = PROP_VAL_SIMPLE;
1005 		property[num_prop_vals].pv_simple = $1;
1006 		if (list[num_prop_vals] != NULL) {
1007 			free_outer_list(list[num_prop_vals]);
1008 			list[num_prop_vals] = NULL;
1009 		}
1010 		num_prop_vals++;
1011 	}
1012 	| complex_prop_val
1013 	{
1014 		property[num_prop_vals].pv_type = PROP_VAL_COMPLEX;
1015 		property[num_prop_vals].pv_complex = complex;
1016 		if (list[num_prop_vals] != NULL) {
1017 			free_outer_list(list[num_prop_vals]);
1018 			list[num_prop_vals] = NULL;
1019 		}
1020 		num_prop_vals++;
1021 	}
1022 	| list_prop_val
1023 	{
1024 		property[num_prop_vals].pv_type = PROP_VAL_LIST;
1025 		property[num_prop_vals].pv_list = list[num_prop_vals];
1026 		num_prop_vals++;
1027 	}
1028 
1029 /*
1030  * One level lower, lists are made up of simple or complex values, so
1031  * simple_prop_val and complex_prop_val fill in a list structure and
1032  * insert it into the linked list which is built up.  And because
1033  * complex properties can have multiple name=value pairs, we keep
1034  * track of them in another linked list.
1035  *
1036  * The complex and list structures for the linked lists are allocated
1037  * below, and freed by recursive functions which are ultimately called
1038  * by free_cmd(), which is called from the top-most "commands" part of
1039  * the grammar.
1040  *
1041  * NOTE: simple_prop_val and complex_piece need reduction rules for
1042  * property_name and resource_type so that the parser will accept property names
1043  * and resource type names as property values.
1044  */
1045 
1046 simple_prop_val: TOKEN
1047 	{
1048 		$$ = simple_prop_val_func($1);
1049 		free($1);
1050 		if ($$ == NULL)
1051 			YYERROR;
1052 	}
1053 	| resource_type
1054 	{
1055 		if (($$ = simple_prop_val_func(res_types[$1])) == NULL)
1056 			YYERROR;
1057 	}
1058 	| property_name
1059 	{
1060 		if (($$ = simple_prop_val_func(prop_types[$1])) == NULL)
1061 			YYERROR;
1062 	}
1063 
1064 complex_prop_val: OPEN_PAREN complex_piece CLOSE_PAREN
1065 	{
1066 		if ((new_list = alloc_list()) == NULL)
1067 			YYERROR;
1068 		new_list->lp_simple = NULL;
1069 		new_list->lp_complex = complex;
1070 		new_list->lp_next = NULL;
1071 		if (list[num_prop_vals] == NULL) {
1072 			list[num_prop_vals] = new_list;
1073 		} else {
1074 			for (tmp_list = list[num_prop_vals]; tmp_list != NULL;
1075 			    tmp_list = tmp_list->lp_next)
1076 				last = tmp_list;
1077 			last->lp_next = new_list;
1078 		}
1079 	}
1080 
1081 complex_piece: property_name EQUAL TOKEN
1082 	{
1083 		$$ = complex_piece_func($1, $3, NULL);
1084 		free($3);
1085 		if ($$ == NULL)
1086 			YYERROR;
1087 	}
1088 	| property_name EQUAL resource_type
1089 	{
1090 		if (($$ = complex_piece_func($1, res_types[$3], NULL)) == NULL)
1091 			YYERROR;
1092 	}
1093 	| property_name EQUAL property_name
1094 	{
1095 		if (($$ = complex_piece_func($1, prop_types[$3], NULL)) == NULL)
1096 			YYERROR;
1097 	}
1098 	| property_name EQUAL TOKEN COMMA complex_piece
1099 	{
1100 		$$ = complex_piece_func($1, $3, complex);
1101 		free($3);
1102 		if ($$ == NULL)
1103 			YYERROR;
1104 	}
1105 	| property_name EQUAL resource_type COMMA complex_piece
1106 	{
1107 		if (($$ = complex_piece_func($1, res_types[$3], complex)) ==
1108 		    NULL)
1109 			YYERROR;
1110 	}
1111 	| property_name EQUAL property_name COMMA complex_piece
1112 	{
1113 		if (($$ = complex_piece_func($1, prop_types[$3], complex)) ==
1114 		    NULL)
1115 			YYERROR;
1116 	}
1117 
1118 list_piece: simple_prop_val
1119 	| complex_prop_val
1120 	| simple_prop_val COMMA list_piece
1121 	| complex_prop_val COMMA list_piece
1122 
1123 list_prop_val: OPEN_SQ_BRACKET list_piece CLOSE_SQ_BRACKET
1124 %%
1125