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