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