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) 2004, 2010, Oracle and/or its affiliates. All rights reserved. 25 */ 26 27 28 #include <libintl.h> 29 30 #include "svccfg.h" 31 32 extern int yylex(void); 33 34 uu_list_pool_t *string_pool; 35 36 %} 37 38 %union { 39 int tok; 40 char *str; 41 uu_list_t *uul; 42 } 43 44 %start commands 45 46 %token SCC_VALIDATE SCC_IMPORT SCC_EXPORT SCC_ARCHIVE SCC_APPLY SCC_EXTRACT 47 %token SCC_CLEANUP 48 %token SCC_REPOSITORY SCC_INVENTORY SCC_SET SCC_END SCC_HELP SCC_RESTORE 49 %token SCC_LIST SCC_ADD SCC_DELETE SCC_SELECT SCC_UNSELECT 50 %token SCC_LISTPG SCC_ADDPG SCC_DELPG SCC_DELHASH 51 %token SCC_LISTPROP SCC_SETPROP SCC_DELPROP SCC_EDITPROP 52 %token SCC_DESCRIBE 53 %token SCC_ADDPROPVALUE SCC_DELPROPVALUE SCC_SETENV SCC_UNSETENV 54 %token SCC_LISTSNAP SCC_SELECTSNAP SCC_REVERT SCC_REFRESH 55 %token SCS_REDIRECT SCS_NEWLINE SCS_EQUALS SCS_LPAREN SCS_RPAREN 56 %token SCV_WORD SCV_STRING 57 %token SCC_DELNOTIFY SCC_SETNOTIFY SCC_LISTNOTIFY 58 59 %type <tok> command_token 60 %type <str> SCV_WORD SCV_STRING 61 %type <str> string opt_word 62 %type <uul> string_list multiline_string_list 63 64 %% 65 66 /* 67 * We could hoist the command terminator for all the rules up here, but then 68 * the parser would reduce before shifting the terminator, which would require 69 * an additional error rule (per command) to catch extra arguments. 70 * This way requires all input to be terminated, which is done by input() in 71 * svccfg.l. 72 */ 73 74 commands : command 75 | commands command 76 77 command : terminator 78 | validate_cmd 79 | import_cmd 80 | cleanup_cmd 81 | export_cmd 82 | archive_cmd 83 | restore_cmd 84 | apply_cmd 85 | extract_cmd 86 | repository_cmd 87 | inventory_cmd 88 | set_cmd 89 | end_cmd 90 | help_cmd 91 | list_cmd 92 | add_cmd 93 | delete_cmd 94 | select_cmd 95 | unselect_cmd 96 | listpg_cmd 97 | addpg_cmd 98 | delpg_cmd 99 | delhash_cmd 100 | listprop_cmd 101 | setprop_cmd 102 | delprop_cmd 103 | editprop_cmd 104 | describe_cmd 105 | addpropvalue_cmd 106 | delpropvalue_cmd 107 | setenv_cmd 108 | unsetenv_cmd 109 | listsnap_cmd 110 | selectsnap_cmd 111 | revert_cmd 112 | refresh_cmd 113 | unknown_cmd 114 | delnotify_cmd 115 | listnotify_cmd 116 | setnotify_cmd 117 | error terminator { semerr(gettext("Syntax error.\n")); } 118 119 unknown_cmd : SCV_WORD terminator 120 { 121 semerr(gettext("Unknown command \"%s\".\n"), $1); 122 free($1); 123 } 124 | SCV_WORD string_list terminator 125 { 126 string_list_t *slp; 127 void *cookie = NULL; 128 129 semerr(gettext("Unknown command \"%s\".\n"), $1); 130 131 while ((slp = uu_list_teardown($2, &cookie)) != NULL) { 132 free(slp->str); 133 free(slp); 134 } 135 136 uu_list_destroy($2); 137 free($1); 138 } 139 140 validate_cmd : SCC_VALIDATE SCV_WORD terminator 141 { 142 lscf_validate($2); 143 free($2); 144 } 145 | SCC_VALIDATE terminator { lscf_validate_fmri(NULL); } 146 | SCC_VALIDATE error terminator { synerr(SCC_VALIDATE); return(0); } 147 148 import_cmd : SCC_IMPORT string_list terminator 149 { 150 string_list_t *slp; 151 void *cookie = NULL; 152 153 if (engine_import($2) == -2) { 154 synerr(SCC_IMPORT); 155 return(0); 156 } 157 158 while ((slp = uu_list_teardown($2, &cookie)) != NULL) { 159 free(slp->str); 160 free(slp); 161 } 162 163 uu_list_destroy($2); 164 } 165 | SCC_IMPORT error terminator { synerr(SCC_IMPORT); return(0); } 166 167 cleanup_cmd : SCC_CLEANUP terminator 168 { 169 engine_cleanup(0); 170 } 171 | SCC_CLEANUP SCV_WORD terminator 172 { 173 if (strcmp($2, "-a") == 0) { 174 engine_cleanup(1); 175 free($2); 176 } else { 177 synerr(SCC_CLEANUP); 178 free($2); 179 return (0); 180 } 181 } 182 | SCC_CLEANUP error terminator { synerr(SCC_CLEANUP); return(0); } 183 184 185 export_cmd : SCC_EXPORT SCV_WORD terminator 186 { 187 lscf_service_export($2, NULL, 0); 188 free($2); 189 } 190 | SCC_EXPORT SCV_WORD SCS_REDIRECT SCV_WORD terminator 191 { 192 lscf_service_export($2, $4, 0); 193 free($2); 194 free($4); 195 } 196 | SCC_EXPORT SCV_WORD SCV_WORD terminator 197 { 198 if (strcmp($2, "-a") == 0) { 199 lscf_service_export($3, NULL, SCE_ALL_VALUES); 200 free($2); 201 free($3); 202 } else { 203 synerr(SCC_EXPORT); 204 free($2); 205 free($3); 206 return (0); 207 } 208 } 209 | SCC_EXPORT SCV_WORD SCV_WORD SCS_REDIRECT SCV_WORD terminator 210 { 211 if (strcmp($2, "-a") == 0) { 212 lscf_service_export($3, $5, SCE_ALL_VALUES); 213 free($2); 214 free($3); 215 free($5); 216 } else { 217 synerr(SCC_EXPORT); 218 free($2); 219 free($3); 220 free($5); 221 return (0); 222 } 223 } 224 | SCC_EXPORT error terminator { synerr(SCC_EXPORT); return(0); } 225 226 archive_cmd : SCC_ARCHIVE terminator 227 { 228 lscf_archive(NULL, 0); 229 } 230 | SCC_ARCHIVE SCV_WORD terminator 231 { 232 if (strcmp($2, "-a") == 0) { 233 lscf_archive(NULL, SCE_ALL_VALUES); 234 free($2); 235 } else { 236 synerr(SCC_ARCHIVE); 237 free($2); 238 return (0); 239 } 240 } 241 | SCC_ARCHIVE SCS_REDIRECT SCV_WORD terminator 242 { 243 lscf_archive($3, 0); 244 free($3); 245 } 246 | SCC_ARCHIVE SCV_WORD SCS_REDIRECT SCV_WORD terminator 247 { 248 if (strcmp($2, "-a") == 0) { 249 lscf_archive($4, SCE_ALL_VALUES); 250 free($2); 251 free($4); 252 } else { 253 synerr(SCC_ARCHIVE); 254 free($2); 255 free($4); 256 return (0); 257 } 258 } 259 | SCC_ARCHIVE error terminator { synerr(SCC_ARCHIVE); return(0); } 260 261 restore_cmd : SCC_RESTORE SCV_WORD terminator 262 { 263 (void) engine_restore($2); 264 free($2); 265 } 266 | SCC_RESTORE error terminator { synerr(SCC_RESTORE); return(0); } 267 268 apply_cmd : SCC_APPLY SCV_WORD terminator 269 { 270 if (engine_apply($2, 1) == -1) { 271 if ((est->sc_cmd_flags & (SC_CMD_IACTIVE|SC_CMD_DONT_EXIT)) == 0) 272 exit(1); 273 274 free($2); 275 return (0); 276 } 277 278 free($2); 279 } 280 | SCC_APPLY SCV_WORD SCV_WORD terminator 281 { 282 if (strcmp($2, "-n") == 0) { 283 (void) engine_apply($3, 0); 284 free($2); 285 free($3); 286 } else { 287 synerr(SCC_APPLY); 288 free($2); 289 free($3); 290 return (0); 291 } 292 } 293 | SCC_APPLY error terminator { synerr(SCC_APPLY); return(0); } 294 295 extract_cmd: SCC_EXTRACT terminator { lscf_profile_extract(NULL); } 296 | SCC_EXTRACT SCS_REDIRECT SCV_WORD terminator 297 { 298 lscf_profile_extract($3); 299 free($3); 300 } 301 | SCC_EXTRACT error terminator { synerr(SCC_EXTRACT); return(0); } 302 303 repository_cmd: SCC_REPOSITORY SCV_WORD terminator 304 { 305 if (strcmp($2, "-f") == 0) { 306 synerr(SCC_REPOSITORY); 307 return(0); 308 } 309 lscf_set_repository($2, 0); 310 free($2); 311 } 312 | SCC_REPOSITORY SCV_WORD SCV_WORD terminator 313 { 314 if (strcmp($2, "-f") == 0) { 315 lscf_set_repository($3, 1); 316 free($2); 317 free($3); 318 } else { 319 synerr(SCC_REPOSITORY); 320 return(0); 321 } 322 } 323 | SCC_REPOSITORY error terminator { synerr(SCC_REPOSITORY); return(0); } 324 325 inventory_cmd : SCC_INVENTORY SCV_WORD terminator 326 { lxml_inventory($2); free($2); } 327 | SCC_INVENTORY error terminator { synerr(SCC_INVENTORY); return(0); } 328 329 set_cmd : SCC_SET string_list terminator 330 { 331 string_list_t *slp; 332 void *cookie = NULL; 333 334 (void) engine_set($2); 335 336 while ((slp = uu_list_teardown($2, &cookie)) != NULL) { 337 free(slp->str); 338 free(slp); 339 } 340 341 uu_list_destroy($2); 342 } 343 | SCC_SET error terminator { synerr(SCC_SET); return(0); } 344 345 end_cmd : SCC_END terminator { exit(0); } 346 | SCC_END error terminator { synerr (SCC_END); return(0); } 347 348 help_cmd : SCC_HELP terminator { help(0); } 349 | SCC_HELP command_token terminator { help($2); } 350 | SCC_HELP error terminator { synerr(SCC_HELP); return(0); } 351 352 list_cmd : SCC_LIST opt_word terminator { lscf_list($2); free($2); } 353 | SCC_LIST error terminator { synerr(SCC_LIST); return(0); } 354 355 add_cmd : SCC_ADD SCV_WORD terminator { lscf_add($2); free($2); } 356 | SCC_ADD error terminator { synerr(SCC_ADD); return(0); } 357 358 delete_cmd : SCC_DELETE SCV_WORD terminator 359 { lscf_delete($2, 0); free($2); } 360 | SCC_DELETE SCV_WORD SCV_WORD terminator 361 { 362 if (strcmp($2, "-f") == 0) { 363 lscf_delete($3, 1); 364 free($2); 365 free($3); 366 } else { 367 synerr(SCC_DELETE); 368 free($2); 369 free($3); 370 return(0); 371 } 372 } 373 | SCC_DELETE error terminator { synerr(SCC_DELETE); return(0); } 374 375 select_cmd : SCC_SELECT SCV_WORD terminator { lscf_select($2); free($2); } 376 | SCC_SELECT error terminator { synerr(SCC_SELECT); return(0) ;} 377 378 unselect_cmd : SCC_UNSELECT terminator { lscf_unselect(); } 379 | SCC_UNSELECT error terminator { synerr(SCC_UNSELECT); return(0); } 380 381 listpg_cmd : SCC_LISTPG opt_word terminator 382 { lscf_listpg($2); free($2); } 383 | SCC_LISTPG error terminator { synerr(SCC_LISTPG); return(0); } 384 385 addpg_cmd : SCC_ADDPG SCV_WORD SCV_WORD opt_word terminator 386 { 387 (void) lscf_addpg($2, $3, $4); 388 free($2); 389 free($3); 390 free($4); 391 } 392 | SCC_ADDPG error terminator { synerr(SCC_ADDPG); return(0); } 393 394 delpg_cmd : SCC_DELPG SCV_WORD terminator 395 { lscf_delpg($2); free($2); } 396 | SCC_DELPG error terminator { synerr(SCC_DELPG); return(0); } 397 398 delhash_cmd : SCC_DELHASH SCV_WORD terminator 399 { 400 lscf_delhash($2, 0); free($2); 401 } 402 | SCC_DELHASH SCV_WORD SCV_WORD terminator 403 { 404 if (strcmp($2, "-d") == 0) { 405 lscf_delhash($3, 1); 406 free($2); 407 free($3); 408 } else { 409 synerr(SCC_DELHASH); 410 free($2); 411 free($3); 412 return(0); 413 } 414 } 415 | SCC_DELHASH error terminator { synerr(SCC_DELHASH); return(0); } 416 417 listprop_cmd : SCC_LISTPROP opt_word terminator 418 { lscf_listprop($2); free($2); } 419 | SCC_LISTPROP error terminator { synerr(SCC_LISTPROP); return(0); } 420 421 setprop_cmd : SCC_SETPROP SCV_WORD SCS_EQUALS string terminator 422 { 423 lscf_setprop($2, NULL, $4, NULL); 424 free($2); 425 free($4); 426 } 427 | SCC_SETPROP SCV_WORD SCS_EQUALS SCV_WORD string terminator 428 { 429 (void) lscf_setprop($2, $4, $5, NULL); 430 free($2); 431 free($4); 432 free($5); 433 } 434 | SCC_SETPROP SCV_WORD SCS_EQUALS opt_word SCS_LPAREN 435 multiline_string_list SCS_RPAREN terminator 436 { 437 string_list_t *slp; 438 void *cookie = NULL; 439 440 (void) lscf_setprop($2, $4, NULL, $6); 441 442 free($2); 443 free($4); 444 445 while ((slp = uu_list_teardown($6, &cookie)) != NULL) { 446 free(slp->str); 447 free(slp); 448 } 449 450 uu_list_destroy($6); 451 } 452 | SCC_SETPROP error terminator { synerr(SCC_SETPROP); return(0); } 453 | SCC_SETPROP error { synerr(SCC_SETPROP); return(0); } 454 455 delprop_cmd : SCC_DELPROP SCV_WORD terminator 456 { lscf_delprop($2); free($2); } 457 | SCC_DELPROP error terminator { synerr(SCC_DELPROP); return(0); } 458 459 editprop_cmd : SCC_EDITPROP terminator { lscf_editprop(); } 460 | SCC_EDITPROP error terminator { synerr(SCC_EDITPROP); return(0); } 461 462 describe_cmd : SCC_DESCRIBE string_list terminator 463 { 464 string_list_t *slp; 465 void *cookie = NULL; 466 467 if (lscf_describe($2, 1) == -2) { 468 synerr(SCC_DESCRIBE); 469 return(0); 470 } 471 472 while ((slp = uu_list_teardown($2, &cookie)) != NULL) { 473 free(slp->str); 474 free(slp); 475 } 476 477 uu_list_destroy($2); 478 } 479 | SCC_DESCRIBE terminator { lscf_describe(NULL, 0); } 480 | SCC_DESCRIBE error terminator { synerr(SCC_DESCRIBE); return(0); } 481 482 addpropvalue_cmd : SCC_ADDPROPVALUE SCV_WORD string terminator 483 { 484 lscf_addpropvalue($2, NULL, $3); 485 free($2); 486 free($3); 487 } 488 | SCC_ADDPROPVALUE SCV_WORD string string terminator 489 { 490 (void) lscf_addpropvalue($2, $3, $4); 491 free($2); 492 free($3); 493 free($4); 494 } 495 | SCC_ADDPROPVALUE error terminator { synerr(SCC_ADDPROPVALUE); return(0); } 496 497 delpropvalue_cmd : SCC_DELPROPVALUE SCV_WORD string terminator 498 { 499 lscf_delpropvalue($2, $3, 0); 500 free($2); 501 free($3); 502 } 503 | SCC_DELPROPVALUE error terminator { synerr(SCC_DELPROPVALUE); return(0); } 504 505 setenv_cmd : SCC_SETENV string_list terminator 506 { 507 string_list_t *slp; 508 void *cookie = NULL; 509 510 if (lscf_setenv($2, 0) == -2) { 511 synerr(SCC_SETENV); 512 return(0); 513 } 514 515 while ((slp = uu_list_teardown($2, &cookie)) != NULL) { 516 free(slp->str); 517 free(slp); 518 } 519 520 uu_list_destroy($2); 521 } 522 | SCC_SETENV error terminator { synerr(SCC_SETENV); return(0); } 523 524 unsetenv_cmd : SCC_UNSETENV string_list terminator 525 { 526 string_list_t *slp; 527 void *cookie = NULL; 528 529 if (lscf_setenv($2, 1) == -2) { 530 synerr(SCC_UNSETENV); 531 return(0); 532 } 533 534 while ((slp = uu_list_teardown($2, &cookie)) != NULL) { 535 free(slp->str); 536 free(slp); 537 } 538 539 uu_list_destroy($2); 540 } 541 | SCC_UNSETENV error terminator { synerr(SCC_UNSETENV); return(0); } 542 543 listsnap_cmd : SCC_LISTSNAP terminator { lscf_listsnap(); } 544 | SCC_LISTSNAP error terminator { synerr(SCC_LISTSNAP); return(0); } 545 546 selectsnap_cmd : SCC_SELECTSNAP opt_word terminator 547 { lscf_selectsnap($2); free($2); } 548 | SCC_SELECTSNAP error terminator 549 { synerr(SCC_SELECTSNAP); return(0); } 550 551 revert_cmd: SCC_REVERT opt_word terminator { lscf_revert($2); free ($2); } 552 | SCC_REVERT error terminator { synerr(SCC_REVERT); return(0); } 553 554 refresh_cmd: SCC_REFRESH terminator { lscf_refresh(); } 555 | SCC_REFRESH error terminator { synerr(SCC_REFRESH); return(0); } 556 557 delnotify_cmd : SCC_DELNOTIFY SCV_WORD terminator 558 { 559 lscf_delnotify($2, 0); 560 free($2); 561 } 562 | SCC_DELNOTIFY SCV_WORD SCV_WORD terminator 563 { 564 if (strcmp($2, "-g") == 0) { 565 lscf_delnotify($3, 1); 566 free($2); 567 free($3); 568 } else { 569 synerr(SCC_DELNOTIFY); 570 free($2); 571 free($3); 572 return(0); 573 } 574 } 575 | SCC_DELNOTIFY error terminator { synerr(SCC_DELNOTIFY); return(0); } 576 577 listnotify_cmd : SCC_LISTNOTIFY terminator 578 { 579 lscf_listnotify("all", 0); 580 } 581 | SCC_LISTNOTIFY SCV_WORD terminator 582 { 583 if (strcmp($2, "-g") == 0) { 584 lscf_listnotify("all", 1); 585 } else { 586 lscf_listnotify($2, 0); 587 } 588 free($2); 589 } 590 | SCC_LISTNOTIFY SCV_WORD SCV_WORD terminator 591 { 592 if (strcmp($2, "-g") == 0) { 593 lscf_listnotify($3, 1); 594 free($2); 595 free($3); 596 } else { 597 synerr(SCC_LISTNOTIFY); 598 free($2); 599 free($3); 600 return(0); 601 } 602 } 603 | SCC_LISTNOTIFY error terminator { synerr(SCC_LISTNOTIFY); return(0); } 604 605 setnotify_cmd : SCC_SETNOTIFY string_list terminator 606 { 607 string_list_t *slp; 608 void *cookie = NULL; 609 610 if (lscf_setnotify($2) == -2) 611 synerr(SCC_SETNOTIFY); 612 613 while ((slp = uu_list_teardown($2, &cookie)) != NULL) { 614 free(slp->str); 615 free(slp); 616 } 617 618 uu_list_destroy($2); 619 } 620 | SCC_SETNOTIFY error terminator { synerr(SCC_SETNOTIFY); return(0); } 621 622 terminator : SCS_NEWLINE 623 624 string_list : 625 { 626 $$ = uu_list_create(string_pool, NULL, 0); 627 if ($$ == NULL) 628 uu_die(gettext("Out of memory\n")); 629 } 630 | string_list string 631 { 632 string_list_t *slp; 633 634 slp = safe_malloc(sizeof (*slp)); 635 636 slp->str = $2; 637 uu_list_node_init(slp, &slp->node, string_pool); 638 uu_list_append($1, slp); 639 $$ = $1; 640 } 641 642 multiline_string_list : string_list 643 { 644 $$ = $1; 645 } 646 | multiline_string_list SCS_NEWLINE string_list 647 { 648 void *cookie = NULL; 649 string_list_t *slp; 650 651 /* Append $3 to $1. */ 652 while ((slp = uu_list_teardown($3, &cookie)) != NULL) 653 uu_list_append($1, slp); 654 655 uu_list_destroy($3); 656 } 657 658 string : SCV_WORD { $$ = $1; } 659 | SCV_STRING { $$ = $1; } 660 661 opt_word : { $$ = NULL; } 662 | SCV_WORD { $$ = $1; } 663 664 command_token : SCC_VALIDATE { $$ = SCC_VALIDATE; } 665 | SCC_IMPORT { $$ = SCC_IMPORT; } 666 | SCC_CLEANUP { $$ = SCC_CLEANUP; } 667 | SCC_EXPORT { $$ = SCC_EXPORT; } 668 | SCC_APPLY { $$ = SCC_APPLY; } 669 | SCC_EXTRACT { $$ = SCC_EXTRACT; } 670 | SCC_REPOSITORY { $$ = SCC_REPOSITORY; } 671 | SCC_ARCHIVE { $$ = SCC_ARCHIVE; } 672 | SCC_INVENTORY { $$ = SCC_INVENTORY; } 673 | SCC_SET { $$ = SCC_SET; } 674 | SCC_END { $$ = SCC_END; } 675 | SCC_HELP { $$ = SCC_HELP; } 676 | SCC_LIST { $$ = SCC_LIST; } 677 | SCC_ADD { $$ = SCC_ADD; } 678 | SCC_DELETE { $$ = SCC_DELETE; } 679 | SCC_SELECT { $$ = SCC_SELECT; } 680 | SCC_UNSELECT { $$ = SCC_UNSELECT; } 681 | SCC_LISTPG { $$ = SCC_LISTPG; } 682 | SCC_ADDPG { $$ = SCC_ADDPG; } 683 | SCC_DELPG { $$ = SCC_DELPG; } 684 | SCC_DELHASH { $$ = SCC_DELHASH; } 685 | SCC_LISTPROP { $$ = SCC_LISTPROP; } 686 | SCC_SETPROP { $$ = SCC_SETPROP; } 687 | SCC_DELPROP { $$ = SCC_DELPROP; } 688 | SCC_EDITPROP { $$ = SCC_EDITPROP; } 689 | SCC_ADDPROPVALUE { $$ = SCC_ADDPROPVALUE; } 690 | SCC_DELPROPVALUE { $$ = SCC_DELPROPVALUE; } 691 | SCC_SETENV { $$ = SCC_SETENV; } 692 | SCC_UNSETENV { $$ = SCC_UNSETENV; } 693 | SCC_LISTSNAP { $$ = SCC_LISTSNAP; } 694 | SCC_SELECTSNAP { $$ = SCC_SELECTSNAP; } 695 | SCC_REVERT { $$ = SCC_REVERT; } 696 | SCC_REFRESH { $$ = SCC_REFRESH; } 697 | SCC_DESCRIBE { $$ = SCC_DESCRIBE; } 698 | SCC_DELNOTIFY { $$ = SCC_DELNOTIFY; } 699 | SCC_LISTNOTIFY { $$ = SCC_LISTNOTIFY; } 700 | SCC_SETNOTIFY { $$ = SCC_SETNOTIFY; } 701