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