xref: /titanic_51/usr/src/cmd/svc/svccfg/svccfg.y (revision 843e19887f64dde75055cf8842fc4db2171eff45)
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 2007 Sun Microsystems, Inc.  All rights reserved.
25  * Use is subject to license terms.
26  */
27 
28 #pragma ident	"%Z%%M%	%I%	%E% SMI"
29 
30 #include <libintl.h>
31 
32 #include "svccfg.h"
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_REPOSITORY SCC_INVENTORY SCC_SET SCC_END SCC_HELP SCC_RESTORE
48 %token SCC_LIST SCC_ADD SCC_DELETE SCC_SELECT SCC_UNSELECT
49 %token SCC_LISTPG SCC_ADDPG SCC_DELPG
50 %token SCC_LISTPROP SCC_SETPROP SCC_DELPROP SCC_EDITPROP
51 %token SCC_ADDPROPVALUE SCC_DELPROPVALUE SCC_SETENV SCC_UNSETENV
52 %token SCC_LISTSNAP SCC_SELECTSNAP SCC_REVERT
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 	| listprop_cmd
96 	| setprop_cmd
97 	| delprop_cmd
98 	| editprop_cmd
99 	| addpropvalue_cmd
100 	| delpropvalue_cmd
101 	| setenv_cmd
102 	| unsetenv_cmd
103 	| listsnap_cmd
104 	| selectsnap_cmd
105 	| revert_cmd
106 	| unknown_cmd
107 	| error terminator	{ semerr(gettext("Syntax error.\n")); }
108 
109 unknown_cmd : SCV_WORD terminator
110 	{
111 		semerr(gettext("Unknown command \"%s\".\n"), $1);
112 		free($1);
113 	}
114 	| SCV_WORD string_list terminator
115 	{
116 		string_list_t *slp;
117 		void *cookie = NULL;
118 
119 		semerr(gettext("Unknown command \"%s\".\n"), $1);
120 
121 		while ((slp = uu_list_teardown($2, &cookie)) != NULL) {
122 			free(slp->str);
123 			free(slp);
124 		}
125 
126 		uu_list_destroy($2);
127 		free($1);
128 	}
129 
130 validate_cmd : SCC_VALIDATE SCV_WORD terminator
131 	{
132 		bundle_t *b = internal_bundle_new();
133 		lxml_get_bundle_file(b, $2, SVCCFG_OP_IMPORT);
134 		(void) internal_bundle_free(b);
135 		free($2);
136 	}
137 	| SCC_VALIDATE error terminator	{ synerr(SCC_VALIDATE); return(0); }
138 
139 import_cmd : SCC_IMPORT string_list terminator
140 	{
141 		string_list_t *slp;
142 		void *cookie = NULL;
143 
144 		if (engine_import($2) == -2) {
145 			synerr(SCC_IMPORT);
146 			return(0);
147 		}
148 
149 		while ((slp = uu_list_teardown($2, &cookie)) != NULL) {
150 			free(slp->str);
151 			free(slp);
152 		}
153 
154 		uu_list_destroy($2);
155 	}
156 	| SCC_IMPORT error terminator	{ synerr(SCC_IMPORT); return(0); }
157 
158 export_cmd : SCC_EXPORT SCV_WORD terminator
159 	{
160 		lscf_service_export($2, NULL, 0);
161 		free($2);
162 	}
163 	| SCC_EXPORT SCV_WORD SCS_REDIRECT SCV_WORD terminator
164 	{
165 		lscf_service_export($2, $4, 0);
166 		free($2);
167 		free($4);
168 	}
169 	| SCC_EXPORT SCV_WORD SCV_WORD terminator
170 	{
171 		if (strcmp($2, "-a") == 0) {
172 			lscf_service_export($3, NULL, SCE_ALL_VALUES);
173 			free($2);
174 			free($3);
175 		} else {
176 			synerr(SCC_EXPORT);
177 			free($2);
178 			free($3);
179 			return (0);
180 		}
181 	}
182 	| SCC_EXPORT SCV_WORD SCV_WORD SCS_REDIRECT SCV_WORD terminator
183 	{
184 		if (strcmp($2, "-a") == 0) {
185 			lscf_service_export($3, $5, SCE_ALL_VALUES);
186 			free($2);
187 			free($3);
188 			free($5);
189 		} else {
190 			synerr(SCC_EXPORT);
191 			free($2);
192 			free($3);
193 			free($5);
194 			return (0);
195 		}
196 	}
197 	| SCC_EXPORT error terminator	{ synerr(SCC_EXPORT); return(0); }
198 
199 archive_cmd : SCC_ARCHIVE terminator
200 	{
201 		lscf_archive(NULL, 0);
202 	}
203 	| SCC_ARCHIVE SCV_WORD terminator
204 	{
205 		if (strcmp($2, "-a") == 0) {
206 			lscf_archive(NULL, SCE_ALL_VALUES);
207 			free($2);
208 		} else {
209 			synerr(SCC_ARCHIVE);
210 			free($2);
211 			return (0);
212 		}
213 	}
214 	| SCC_ARCHIVE SCS_REDIRECT SCV_WORD terminator
215 	{
216 		lscf_archive($3, 0);
217 		free($3);
218 	}
219 	| SCC_ARCHIVE SCV_WORD SCS_REDIRECT SCV_WORD terminator
220 	{
221 		if (strcmp($2, "-a") == 0) {
222 			lscf_archive($4, SCE_ALL_VALUES);
223 			free($2);
224 			free($4);
225 		} else {
226 			synerr(SCC_ARCHIVE);
227 			free($2);
228 			free($4);
229 			return (0);
230 		}
231 	}
232 	| SCC_ARCHIVE error terminator	{ synerr(SCC_ARCHIVE); return(0); }
233 
234 restore_cmd : SCC_RESTORE SCV_WORD terminator
235 	{
236 		(void) engine_restore($2);
237 		free($2);
238 	}
239 	| SCC_RESTORE error terminator	{ synerr(SCC_RESTORE); return(0); }
240 
241 apply_cmd : SCC_APPLY SCV_WORD terminator
242 					{ (void) engine_apply($2); free($2); }
243 	| SCC_APPLY error terminator	{ synerr(SCC_APPLY); return(0); }
244 
245 extract_cmd: SCC_EXTRACT terminator	{ lscf_profile_extract(NULL); }
246 	| SCC_EXTRACT SCS_REDIRECT SCV_WORD terminator
247 	{
248 		lscf_profile_extract($3);
249 		free($3);
250 	}
251 	| SCC_EXTRACT error terminator	{ synerr(SCC_EXTRACT); return(0); }
252 
253 repository_cmd: SCC_REPOSITORY SCV_WORD terminator
254 	{
255 		if (strcmp($2, "-f") == 0) {
256 			synerr(SCC_REPOSITORY);
257 			return(0);
258 		}
259 		lscf_set_repository($2, 0);
260 		free($2);
261 	}
262 	| SCC_REPOSITORY SCV_WORD SCV_WORD terminator
263 	{
264 		if (strcmp($2, "-f") == 0) {
265 			lscf_set_repository($3, 1);
266 			free($2);
267 			free($3);
268 		} else {
269 			synerr(SCC_REPOSITORY);
270 			return(0);
271 		}
272 	}
273 	| SCC_REPOSITORY error terminator   { synerr(SCC_REPOSITORY); return(0); }
274 
275 inventory_cmd : SCC_INVENTORY SCV_WORD terminator
276 					{ lxml_inventory($2); free($2); }
277 	| SCC_INVENTORY error terminator	{ synerr(SCC_INVENTORY); return(0); }
278 
279 set_cmd : SCC_SET string_list terminator
280 	{
281 		string_list_t *slp;
282 		void *cookie = NULL;
283 
284 		(void) engine_set($2);
285 
286 		while ((slp = uu_list_teardown($2, &cookie)) != NULL) {
287 			free(slp->str);
288 			free(slp);
289 		}
290 
291 		uu_list_destroy($2);
292 	}
293 	| SCC_SET error terminator		{ synerr(SCC_SET); return(0); }
294 
295 end_cmd : SCC_END terminator			{ exit(0); }
296 	| SCC_END error terminator		{ synerr (SCC_END); return(0); }
297 
298 help_cmd : SCC_HELP terminator			{ help(0); }
299 	| SCC_HELP command_token terminator	{ help($2); }
300 	| SCC_HELP error terminator		{ synerr(SCC_HELP); return(0); }
301 
302 list_cmd : SCC_LIST opt_word terminator	{ lscf_list($2); free($2); }
303 	| SCC_LIST error terminator	{ synerr(SCC_LIST); return(0); }
304 
305 add_cmd : SCC_ADD SCV_WORD terminator	{ lscf_add($2); free($2); }
306 	| SCC_ADD error terminator	{ synerr(SCC_ADD); return(0); }
307 
308 delete_cmd : SCC_DELETE SCV_WORD terminator
309 					{ lscf_delete($2, 0); free($2); }
310 	| SCC_DELETE SCV_WORD SCV_WORD terminator
311 	{
312 		if (strcmp($2, "-f") == 0) {
313 			lscf_delete($3, 1);
314 			free($2);
315 			free($3);
316 		} else {
317 			synerr(SCC_DELETE);
318 			free($2);
319 			free($3);
320 			return(0);
321 		}
322 	}
323 	| SCC_DELETE error terminator	{ synerr(SCC_DELETE); return(0); }
324 
325 select_cmd : SCC_SELECT SCV_WORD terminator	{ lscf_select($2); free($2); }
326 	| SCC_SELECT error terminator	{ synerr(SCC_SELECT); return(0) ;}
327 
328 unselect_cmd : SCC_UNSELECT terminator	{ lscf_unselect(); }
329 	| SCC_UNSELECT error terminator	{ synerr(SCC_UNSELECT); return(0); }
330 
331 listpg_cmd : SCC_LISTPG opt_word terminator
332 					{ lscf_listpg($2); free($2); }
333 	| SCC_LISTPG error terminator	{ synerr(SCC_LISTPG); return(0); }
334 
335 addpg_cmd : SCC_ADDPG SCV_WORD SCV_WORD opt_word terminator
336 	{
337 		(void) lscf_addpg($2, $3, $4);
338 		free($2);
339 		free($3);
340 		free($4);
341 	}
342 	| SCC_ADDPG error terminator	{ synerr(SCC_ADDPG); return(0); }
343 
344 delpg_cmd : SCC_DELPG SCV_WORD terminator
345 					{ lscf_delpg($2); free($2); }
346 	| SCC_DELPG error terminator	{ synerr(SCC_DELPG); return(0); }
347 
348 listprop_cmd : SCC_LISTPROP opt_word terminator
349 					{ lscf_listprop($2); free($2); }
350 	| SCC_LISTPROP error terminator	{ synerr(SCC_LISTPROP); return(0); }
351 
352 setprop_cmd : SCC_SETPROP SCV_WORD SCS_EQUALS string terminator
353 	{
354 		lscf_setprop($2, NULL, $4, NULL);
355 		free($2);
356 		free($4);
357 	}
358 	| SCC_SETPROP SCV_WORD SCS_EQUALS SCV_WORD string terminator
359 	{
360 		(void) lscf_setprop($2, $4, $5, NULL);
361 		free($2);
362 		free($4);
363 		free($5);
364 	}
365 	| SCC_SETPROP SCV_WORD SCS_EQUALS opt_word SCS_LPAREN
366 	      multiline_string_list SCS_RPAREN terminator
367 	{
368 		string_list_t *slp;
369 		void *cookie = NULL;
370 
371 		(void) lscf_setprop($2, $4, NULL, $6);
372 
373 		free($2);
374 		free($4);
375 
376 		while ((slp = uu_list_teardown($6, &cookie)) != NULL) {
377 			free(slp->str);
378 			free(slp);
379 		}
380 
381 		uu_list_destroy($6);
382 	}
383 	| SCC_SETPROP error terminator	{ synerr(SCC_SETPROP); return(0); }
384 	| SCC_SETPROP error		{ synerr(SCC_SETPROP); return(0); }
385 
386 delprop_cmd : SCC_DELPROP SCV_WORD terminator
387 					{ lscf_delprop($2); free($2); }
388 	| SCC_DELPROP error terminator	{ synerr(SCC_DELPROP); return(0); }
389 
390 editprop_cmd : SCC_EDITPROP terminator	{ lscf_editprop(); }
391 	| SCC_EDITPROP error terminator	{ synerr(SCC_EDITPROP); return(0); }
392 
393 addpropvalue_cmd : SCC_ADDPROPVALUE SCV_WORD string terminator
394 	{
395 		lscf_addpropvalue($2, NULL, $3);
396 		free($2);
397 		free($3);
398 	}
399 	| SCC_ADDPROPVALUE SCV_WORD string string terminator
400 	{
401 		(void) lscf_addpropvalue($2, $3, $4);
402 		free($2);
403 		free($3);
404 		free($4);
405 	}
406 	| SCC_ADDPROPVALUE error terminator { synerr(SCC_ADDPROPVALUE); return(0); }
407 
408 delpropvalue_cmd : SCC_DELPROPVALUE SCV_WORD string terminator
409 	{
410 		lscf_delpropvalue($2, $3, 0);
411 		free($2);
412 		free($3);
413 	}
414 	| SCC_DELPROPVALUE error terminator { synerr(SCC_DELPROPVALUE); return(0); }
415 
416 setenv_cmd : SCC_SETENV string_list terminator
417 	{
418 		string_list_t *slp;
419 		void *cookie = NULL;
420 
421 		if (lscf_setenv($2, 0) == -2) {
422 			synerr(SCC_SETENV);
423 			return(0);
424 		}
425 
426 		while ((slp = uu_list_teardown($2, &cookie)) != NULL) {
427 			free(slp->str);
428 			free(slp);
429 		}
430 
431 		uu_list_destroy($2);
432 	}
433 	| SCC_SETENV error terminator		{ synerr(SCC_SETENV); return(0); }
434 
435 unsetenv_cmd : SCC_UNSETENV string_list terminator
436 	{
437 		string_list_t *slp;
438 		void *cookie = NULL;
439 
440 		if (lscf_setenv($2, 1) == -2) {
441 			synerr(SCC_UNSETENV);
442 			return(0);
443 		}
444 
445 		while ((slp = uu_list_teardown($2, &cookie)) != NULL) {
446 			free(slp->str);
447 			free(slp);
448 		}
449 
450 		uu_list_destroy($2);
451 	}
452 	| SCC_UNSETENV error terminator	{ synerr(SCC_UNSETENV); return(0); }
453 
454 listsnap_cmd : SCC_LISTSNAP terminator	{ lscf_listsnap(); }
455 	| SCC_LISTSNAP error terminator	{ synerr(SCC_LISTSNAP); return(0); }
456 
457 selectsnap_cmd : SCC_SELECTSNAP opt_word terminator
458 					{ lscf_selectsnap($2); free($2); }
459 	| SCC_SELECTSNAP error terminator
460 					{ synerr(SCC_SELECTSNAP); return(0); }
461 
462 revert_cmd: SCC_REVERT opt_word terminator	{ lscf_revert($2); free ($2); }
463 	| SCC_REVERT error terminator		{ synerr(SCC_REVERT); return(0); }
464 
465 
466 terminator : SCS_NEWLINE
467 
468 string_list :
469 	{
470 		$$ = uu_list_create(string_pool, NULL, 0);
471 		if ($$ == NULL)
472 			uu_die(gettext("Out of memory\n"));
473 	}
474 	| string_list string
475 	{
476 		string_list_t *slp;
477 
478 		slp = safe_malloc(sizeof (*slp));
479 
480 		slp->str = $2;
481 		uu_list_node_init(slp, &slp->node, string_pool);
482 		uu_list_append($1, slp);
483 		$$ = $1;
484 	}
485 
486 multiline_string_list : string_list
487 	{
488 		$$ = $1;
489 	}
490 	| multiline_string_list SCS_NEWLINE string_list
491 	{
492 		void *cookie = NULL;
493 		string_list_t *slp;
494 
495 		/* Append $3 to $1. */
496 		while ((slp = uu_list_teardown($3, &cookie)) != NULL)
497 			uu_list_append($1, slp);
498 
499 		uu_list_destroy($3);
500 	}
501 
502 string : SCV_WORD	{ $$ = $1; }
503 	| SCV_STRING	{ $$ = $1; }
504 
505 opt_word :		{ $$ = NULL; }
506 	| SCV_WORD	{ $$ = $1; }
507 
508 command_token : SCC_VALIDATE	{ $$ = SCC_VALIDATE; }
509 	| SCC_IMPORT		{ $$ = SCC_IMPORT; }
510 	| SCC_EXPORT		{ $$ = SCC_EXPORT; }
511 	| SCC_APPLY		{ $$ = SCC_APPLY; }
512 	| SCC_EXTRACT		{ $$ = SCC_EXTRACT; }
513 	| SCC_REPOSITORY	{ $$ = SCC_REPOSITORY; }
514 	| SCC_ARCHIVE		{ $$ = SCC_ARCHIVE; }
515 	| SCC_INVENTORY		{ $$ = SCC_INVENTORY; }
516 	| SCC_SET		{ $$ = SCC_SET; }
517 	| SCC_END		{ $$ = SCC_END; }
518 	| SCC_HELP		{ $$ = SCC_HELP; }
519 	| SCC_LIST		{ $$ = SCC_LIST; }
520 	| SCC_ADD		{ $$ = SCC_ADD; }
521 	| SCC_DELETE		{ $$ = SCC_DELETE; }
522 	| SCC_SELECT		{ $$ = SCC_SELECT; }
523 	| SCC_UNSELECT		{ $$ = SCC_UNSELECT; }
524 	| SCC_LISTPG		{ $$ = SCC_LISTPG; }
525 	| SCC_ADDPG		{ $$ = SCC_ADDPG; }
526 	| SCC_DELPG		{ $$ = SCC_DELPG; }
527 	| SCC_LISTPROP		{ $$ = SCC_LISTPROP; }
528 	| SCC_SETPROP		{ $$ = SCC_SETPROP; }
529 	| SCC_DELPROP		{ $$ = SCC_DELPROP; }
530 	| SCC_EDITPROP		{ $$ = SCC_EDITPROP; }
531 	| SCC_ADDPROPVALUE	{ $$ = SCC_ADDPROPVALUE; }
532 	| SCC_DELPROPVALUE	{ $$ = SCC_DELPROPVALUE; }
533 	| SCC_SETENV		{ $$ = SCC_SETENV; }
534 	| SCC_UNSETENV		{ $$ = SCC_UNSETENV; }
535 	| SCC_LISTSNAP		{ $$ = SCC_LISTSNAP; }
536 	| SCC_SELECTSNAP	{ $$ = SCC_SELECTSNAP; }
537 	| SCC_REVERT		{ $$ = SCC_REVERT; }
538