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