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 * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 #pragma ident "%Z%%M% %I% %E% SMI" 28 29 #include <libintl.h> 30 31 #include "svccfg.h" 32 33 uu_list_pool_t *string_pool; 34 35 %} 36 37 %union { 38 int tok; 39 char *str; 40 uu_list_t *uul; 41 } 42 43 %start commands 44 45 %token SCC_VALIDATE SCC_IMPORT SCC_EXPORT SCC_ARCHIVE SCC_APPLY SCC_EXTRACT 46 %token SCC_REPOSITORY SCC_INVENTORY SCC_SET SCC_END SCC_HELP 47 %token SCC_LIST SCC_ADD SCC_DELETE SCC_SELECT SCC_UNSELECT 48 %token SCC_LISTPG SCC_ADDPG SCC_DELPG 49 %token SCC_LISTPROP SCC_SETPROP SCC_DELPROP SCC_EDITPROP 50 %token SCC_ADDPROPVALUE SCC_DELPROPVALUE SCC_SETENV SCC_UNSETENV 51 %token SCC_LISTSNAP SCC_SELECTSNAP SCC_REVERT 52 %token SCS_REDIRECT SCS_NEWLINE SCS_EQUALS SCS_LPAREN SCS_RPAREN 53 %token SCV_WORD SCV_STRING 54 55 %type <tok> command_token 56 %type <str> SCV_WORD SCV_STRING 57 %type <str> string opt_word 58 %type <uul> string_list multiline_string_list 59 60 %% 61 62 /* 63 * We could hoist the command terminator for all the rules up here, but then 64 * the parser would reduce before shifting the terminator, which would require 65 * an additional error rule (per command) to catch extra arguments. 66 * This way requires all input to be terminated, which is done by input() in 67 * svccfg.l. 68 */ 69 70 commands : command 71 | commands command 72 73 command : terminator 74 | validate_cmd 75 | import_cmd 76 | export_cmd 77 | archive_cmd 78 | apply_cmd 79 | extract_cmd 80 | repository_cmd 81 | inventory_cmd 82 | set_cmd 83 | end_cmd 84 | help_cmd 85 | list_cmd 86 | add_cmd 87 | delete_cmd 88 | select_cmd 89 | unselect_cmd 90 | listpg_cmd 91 | addpg_cmd 92 | delpg_cmd 93 | listprop_cmd 94 | setprop_cmd 95 | delprop_cmd 96 | editprop_cmd 97 | addpropvalue_cmd 98 | delpropvalue_cmd 99 | setenv_cmd 100 | unsetenv_cmd 101 | listsnap_cmd 102 | selectsnap_cmd 103 | revert_cmd 104 | unknown_cmd 105 | error terminator { semerr(gettext("Syntax error.\n")); } 106 107 unknown_cmd : SCV_WORD terminator 108 { 109 semerr(gettext("Unknown command \"%s\".\n"), $1); 110 free($1); 111 } 112 | SCV_WORD string_list terminator 113 { 114 string_list_t *slp; 115 void *cookie = NULL; 116 117 semerr(gettext("Unknown command \"%s\".\n"), $1); 118 119 while ((slp = uu_list_teardown($2, &cookie)) != NULL) { 120 free(slp->str); 121 free(slp); 122 } 123 124 uu_list_destroy($2); 125 free($1); 126 } 127 128 validate_cmd : SCC_VALIDATE SCV_WORD terminator 129 { 130 bundle_t *b = internal_bundle_new(); 131 lxml_get_bundle_file(b, $2, 0); 132 (void) internal_bundle_free(b); 133 free($2); 134 } 135 | SCC_VALIDATE error terminator { synerr(SCC_VALIDATE); return(0); } 136 137 import_cmd : SCC_IMPORT string_list terminator 138 { 139 string_list_t *slp; 140 void *cookie = NULL; 141 142 if (engine_import($2) == -2) { 143 synerr(SCC_IMPORT); 144 return(0); 145 } 146 147 while ((slp = uu_list_teardown($2, &cookie)) != NULL) { 148 free(slp->str); 149 free(slp); 150 } 151 152 uu_list_destroy($2); 153 } 154 | SCC_IMPORT error terminator { synerr(SCC_IMPORT); return(0); } 155 156 export_cmd : SCC_EXPORT SCV_WORD terminator 157 { 158 lscf_service_export($2, NULL); 159 free($2); 160 } 161 | SCC_EXPORT SCV_WORD SCS_REDIRECT SCV_WORD terminator 162 { 163 lscf_service_export($2, $4); 164 free($2); 165 free($4); 166 } 167 | SCC_EXPORT error terminator { synerr(SCC_EXPORT); return(0); } 168 169 archive_cmd : SCC_ARCHIVE terminator 170 { 171 lscf_archive(NULL); 172 } 173 | SCC_ARCHIVE SCS_REDIRECT SCV_WORD terminator 174 { 175 lscf_archive($3); 176 free($3); 177 } 178 | SCC_ARCHIVE error terminator { synerr(SCC_ARCHIVE); return(0); } 179 180 apply_cmd : SCC_APPLY SCV_WORD terminator 181 { (void) engine_apply($2); free($2); } 182 | SCC_APPLY error terminator { synerr(SCC_APPLY); return(0); } 183 184 extract_cmd: SCC_EXTRACT terminator { lscf_profile_extract(NULL); } 185 | SCC_EXTRACT SCS_REDIRECT SCV_WORD terminator 186 { 187 lscf_profile_extract($3); 188 free($3); 189 } 190 | SCC_EXTRACT error terminator { synerr(SCC_EXTRACT); return(0); } 191 192 repository_cmd: SCC_REPOSITORY SCV_WORD terminator 193 { 194 if (strcmp($2, "-f") == 0) { 195 synerr(SCC_REPOSITORY); 196 return(0); 197 } 198 lscf_set_repository($2, 0); 199 free($2); 200 } 201 | SCC_REPOSITORY SCV_WORD SCV_WORD terminator 202 { 203 if (strcmp($2, "-f") == 0) { 204 lscf_set_repository($3, 1); 205 free($2); 206 free($3); 207 } else { 208 synerr(SCC_REPOSITORY); 209 return(0); 210 } 211 } 212 | SCC_REPOSITORY error terminator { synerr(SCC_REPOSITORY); return(0); } 213 214 inventory_cmd : SCC_INVENTORY SCV_WORD terminator 215 { lxml_inventory($2); free($2); } 216 | SCC_INVENTORY error terminator { synerr(SCC_INVENTORY); return(0); } 217 218 set_cmd : SCC_SET string_list terminator 219 { 220 string_list_t *slp; 221 void *cookie = NULL; 222 223 (void) engine_set($2); 224 225 while ((slp = uu_list_teardown($2, &cookie)) != NULL) { 226 free(slp->str); 227 free(slp); 228 } 229 230 uu_list_destroy($2); 231 } 232 | SCC_SET error terminator { synerr(SCC_SET); return(0); } 233 234 end_cmd : SCC_END terminator { exit(0); } 235 | SCC_END error terminator { synerr (SCC_END); return(0); } 236 237 help_cmd : SCC_HELP terminator { help(0); } 238 | SCC_HELP command_token terminator { help($2); } 239 | SCC_HELP error terminator { synerr(SCC_HELP); return(0); } 240 241 list_cmd : SCC_LIST opt_word terminator { lscf_list($2); free($2); } 242 | SCC_LIST error terminator { synerr(SCC_LIST); return(0); } 243 244 add_cmd : SCC_ADD SCV_WORD terminator { lscf_add($2); free($2); } 245 | SCC_ADD error terminator { synerr(SCC_ADD); return(0); } 246 247 delete_cmd : SCC_DELETE SCV_WORD terminator 248 { lscf_delete($2, 0); free($2); } 249 | SCC_DELETE SCV_WORD SCV_WORD terminator 250 { 251 if (strcmp($2, "-f") == 0) { 252 lscf_delete($3, 1); 253 free($2); 254 free($3); 255 } else { 256 synerr(SCC_DELETE); 257 return(0); 258 } 259 } 260 | SCC_DELETE error terminator { synerr(SCC_DELETE); return(0); } 261 262 select_cmd : SCC_SELECT SCV_WORD terminator { lscf_select($2); free($2); } 263 | SCC_SELECT error terminator { synerr(SCC_SELECT); return(0) ;} 264 265 unselect_cmd : SCC_UNSELECT terminator { lscf_unselect(); } 266 | SCC_UNSELECT error terminator { synerr(SCC_UNSELECT); return(0); } 267 268 listpg_cmd : SCC_LISTPG opt_word terminator 269 { lscf_listpg($2); free($2); } 270 | SCC_LISTPG error terminator { synerr(SCC_LISTPG); return(0); } 271 272 addpg_cmd : SCC_ADDPG SCV_WORD SCV_WORD opt_word terminator 273 { 274 (void) lscf_addpg($2, $3, $4); 275 free($2); 276 free($3); 277 free($4); 278 } 279 | SCC_ADDPG error terminator { synerr(SCC_ADDPG); return(0); } 280 281 delpg_cmd : SCC_DELPG SCV_WORD terminator 282 { lscf_delpg($2); free($2); } 283 | SCC_DELPG error terminator { synerr(SCC_DELPG); return(0); } 284 285 listprop_cmd : SCC_LISTPROP opt_word terminator 286 { lscf_listprop($2); free($2); } 287 | SCC_LISTPROP error terminator { synerr(SCC_LISTPROP); return(0); } 288 289 setprop_cmd : SCC_SETPROP SCV_WORD SCS_EQUALS string terminator 290 { 291 lscf_setprop($2, NULL, $4, NULL); 292 free($2); 293 free($4); 294 } 295 | SCC_SETPROP SCV_WORD SCS_EQUALS SCV_WORD string terminator 296 { 297 (void) lscf_setprop($2, $4, $5, NULL); 298 free($2); 299 free($4); 300 free($5); 301 } 302 | SCC_SETPROP SCV_WORD SCS_EQUALS opt_word SCS_LPAREN 303 multiline_string_list SCS_RPAREN terminator 304 { 305 string_list_t *slp; 306 void *cookie = NULL; 307 308 (void) lscf_setprop($2, $4, NULL, $6); 309 310 free($2); 311 free($4); 312 313 while ((slp = uu_list_teardown($6, &cookie)) != NULL) { 314 free(slp->str); 315 free(slp); 316 } 317 318 uu_list_destroy($6); 319 } 320 | SCC_SETPROP error terminator { synerr(SCC_SETPROP); return(0); } 321 | SCC_SETPROP error { synerr(SCC_SETPROP); return(0); } 322 323 delprop_cmd : SCC_DELPROP SCV_WORD terminator 324 { lscf_delprop($2); free($2); } 325 | SCC_DELPROP error terminator { synerr(SCC_DELPROP); return(0); } 326 327 editprop_cmd : SCC_EDITPROP terminator { lscf_editprop(); } 328 | SCC_EDITPROP error terminator { synerr(SCC_EDITPROP); return(0); } 329 330 addpropvalue_cmd : SCC_ADDPROPVALUE SCV_WORD string terminator 331 { 332 lscf_addpropvalue($2, NULL, $3); 333 free($2); 334 free($3); 335 } 336 | SCC_ADDPROPVALUE SCV_WORD string string terminator 337 { 338 (void) lscf_addpropvalue($2, $3, $4); 339 free($2); 340 free($3); 341 free($4); 342 } 343 | SCC_ADDPROPVALUE error terminator { synerr(SCC_ADDPROPVALUE); return(0); } 344 345 delpropvalue_cmd : SCC_DELPROPVALUE SCV_WORD string terminator 346 { 347 lscf_delpropvalue($2, $3, 0); 348 free($2); 349 free($3); 350 } 351 | SCC_DELPROPVALUE error terminator { synerr(SCC_DELPROPVALUE); return(0); } 352 353 setenv_cmd : SCC_SETENV string_list terminator 354 { 355 string_list_t *slp; 356 void *cookie = NULL; 357 358 if (lscf_setenv($2, 0) == -2) { 359 synerr(SCC_SETENV); 360 return(0); 361 } 362 363 while ((slp = uu_list_teardown($2, &cookie)) != NULL) { 364 free(slp->str); 365 free(slp); 366 } 367 368 uu_list_destroy($2); 369 } 370 | SCC_SETENV error terminator { synerr(SCC_SETENV); return(0); } 371 372 unsetenv_cmd : SCC_UNSETENV string_list terminator 373 { 374 string_list_t *slp; 375 void *cookie = NULL; 376 377 if (lscf_setenv($2, 1) == -2) { 378 synerr(SCC_UNSETENV); 379 return(0); 380 } 381 382 while ((slp = uu_list_teardown($2, &cookie)) != NULL) { 383 free(slp->str); 384 free(slp); 385 } 386 387 uu_list_destroy($2); 388 } 389 | SCC_UNSETENV error terminator { synerr(SCC_UNSETENV); return(0); } 390 391 listsnap_cmd : SCC_LISTSNAP terminator { lscf_listsnap(); } 392 | SCC_LISTSNAP error terminator { synerr(SCC_LISTSNAP); return(0); } 393 394 selectsnap_cmd : SCC_SELECTSNAP opt_word terminator 395 { lscf_selectsnap($2); free($2); } 396 | SCC_SELECTSNAP error terminator 397 { synerr(SCC_SELECTSNAP); return(0); } 398 399 revert_cmd: SCC_REVERT opt_word terminator { lscf_revert($2); free ($2); } 400 | SCC_REVERT error terminator { synerr(SCC_REVERT); return(0); } 401 402 403 terminator : SCS_NEWLINE 404 405 string_list : 406 { 407 $$ = uu_list_create(string_pool, NULL, 0); 408 if ($$ == NULL) 409 uu_die(gettext("Out of memory\n")); 410 } 411 | string_list string 412 { 413 string_list_t *slp; 414 415 slp = safe_malloc(sizeof (*slp)); 416 417 slp->str = $2; 418 uu_list_node_init(slp, &slp->node, string_pool); 419 uu_list_append($1, slp); 420 $$ = $1; 421 } 422 423 multiline_string_list : string_list 424 { 425 $$ = $1; 426 } 427 | multiline_string_list SCS_NEWLINE string_list 428 { 429 void *cookie = NULL; 430 string_list_t *slp; 431 432 /* Append $3 to $1. */ 433 while ((slp = uu_list_teardown($3, &cookie)) != NULL) 434 uu_list_append($1, slp); 435 436 uu_list_destroy($3); 437 } 438 439 string : SCV_WORD { $$ = $1; } 440 | SCV_STRING { $$ = $1; } 441 442 opt_word : { $$ = NULL; } 443 | SCV_WORD { $$ = $1; } 444 445 command_token : SCC_VALIDATE { $$ = SCC_VALIDATE; } 446 | SCC_IMPORT { $$ = SCC_IMPORT; } 447 | SCC_EXPORT { $$ = SCC_EXPORT; } 448 | SCC_APPLY { $$ = SCC_APPLY; } 449 | SCC_EXTRACT { $$ = SCC_EXTRACT; } 450 | SCC_REPOSITORY { $$ = SCC_REPOSITORY; } 451 | SCC_ARCHIVE { $$ = SCC_ARCHIVE; } 452 | SCC_INVENTORY { $$ = SCC_INVENTORY; } 453 | SCC_SET { $$ = SCC_SET; } 454 | SCC_END { $$ = SCC_END; } 455 | SCC_HELP { $$ = SCC_HELP; } 456 | SCC_LIST { $$ = SCC_LIST; } 457 | SCC_ADD { $$ = SCC_ADD; } 458 | SCC_DELETE { $$ = SCC_DELETE; } 459 | SCC_SELECT { $$ = SCC_SELECT; } 460 | SCC_UNSELECT { $$ = SCC_UNSELECT; } 461 | SCC_LISTPG { $$ = SCC_LISTPG; } 462 | SCC_ADDPG { $$ = SCC_ADDPG; } 463 | SCC_DELPG { $$ = SCC_DELPG; } 464 | SCC_LISTPROP { $$ = SCC_LISTPROP; } 465 | SCC_SETPROP { $$ = SCC_SETPROP; } 466 | SCC_DELPROP { $$ = SCC_DELPROP; } 467 | SCC_EDITPROP { $$ = SCC_EDITPROP; } 468 | SCC_ADDPROPVALUE { $$ = SCC_ADDPROPVALUE; } 469 | SCC_DELPROPVALUE { $$ = SCC_DELPROPVALUE; } 470 | SCC_SETENV { $$ = SCC_SETENV; } 471 | SCC_UNSETENV { $$ = SCC_UNSETENV; } 472 | SCC_LISTSNAP { $$ = SCC_LISTSNAP; } 473 | SCC_SELECTSNAP { $$ = SCC_SELECTSNAP; } 474 | SCC_REVERT { $$ = SCC_REVERT; } 475