xref: /titanic_52/usr/src/cmd/svc/svccfg/svccfg.y (revision f63f7506be0210195779706f51c58646e568cc40)
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, Version 1.0 only
7  * (the "License").  You may not use this file except in compliance
8  * with the License.
9  *
10  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11  * or http://www.opensolaris.org/os/licensing.
12  * See the License for the specific language governing permissions
13  * and limitations under the License.
14  *
15  * When distributing Covered Code, include this CDDL HEADER in each
16  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17  * If applicable, add the following below this CDDL HEADER, with the
18  * fields enclosed by brackets "[]" replaced with your own identifying
19  * information: Portions Copyright [yyyy] [name of copyright owner]
20  *
21  * CDDL HEADER END
22  *
23  * Copyright 2004 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); }
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 
145 		while ((slp = uu_list_teardown($2, &cookie)) != NULL) {
146 			free(slp->str);
147 			free(slp);
148 		}
149 
150 		uu_list_destroy($2);
151 	}
152 	| SCC_IMPORT error terminator		{ synerr(SCC_IMPORT); }
153 
154 export_cmd : SCC_EXPORT SCV_WORD terminator
155 	{
156 		lscf_service_export($2, NULL);
157 		free($2);
158 	}
159 	| SCC_EXPORT SCV_WORD SCS_REDIRECT SCV_WORD terminator
160 	{
161 		lscf_service_export($2, $4);
162 		free($2);
163 		free($4);
164 	}
165 	| SCC_EXPORT error terminator		{ synerr(SCC_EXPORT); }
166 
167 archive_cmd : SCC_ARCHIVE terminator
168 	{
169 		lscf_archive(NULL);
170 	}
171 	| SCC_ARCHIVE SCS_REDIRECT SCV_WORD terminator
172 	{
173 		lscf_archive($3);
174 		free($3);
175 	}
176 	| SCC_ARCHIVE error terminator		{ synerr(SCC_ARCHIVE); }
177 
178 apply_cmd : SCC_APPLY SCV_WORD terminator
179 					{ (void) engine_apply($2); free($2); }
180 	| SCC_APPLY error terminator	{ synerr(SCC_APPLY); }
181 
182 extract_cmd: SCC_EXTRACT terminator	{ lscf_profile_extract(NULL); }
183 	| SCC_EXTRACT SCS_REDIRECT SCV_WORD terminator
184 	{
185 		lscf_profile_extract($3);
186 		free($3);
187 	}
188 	| SCC_EXTRACT error terminator		{ synerr(SCC_EXTRACT); }
189 
190 repository_cmd : SCC_REPOSITORY SCV_WORD terminator
191 	{
192 		lscf_set_repository($2);
193 		free($2);
194 	}
195 	| SCC_REPOSITORY error terminator	{ synerr(SCC_REPOSITORY); }
196 
197 inventory_cmd : SCC_INVENTORY SCV_WORD terminator
198 					{ lxml_inventory($2); free($2); }
199 	| SCC_INVENTORY error terminator	{ synerr(SCC_INVENTORY); }
200 
201 set_cmd : SCC_SET string_list terminator
202 	{
203 		string_list_t *slp;
204 		void *cookie = NULL;
205 
206 		(void) engine_set($2);
207 
208 		while ((slp = uu_list_teardown($2, &cookie)) != NULL) {
209 			free(slp->str);
210 			free(slp);
211 		}
212 
213 		uu_list_destroy($2);
214 	}
215 	| SCC_SET error terminator		{ synerr(SCC_SET); }
216 
217 end_cmd : SCC_END terminator			{ exit(0); }
218 	| SCC_END error terminator		{ synerr (SCC_END); }
219 
220 help_cmd : SCC_HELP terminator			{ help(0); }
221 	| SCC_HELP command_token terminator	{ help($2); }
222 	| SCC_HELP error terminator		{ synerr(SCC_HELP); }
223 
224 list_cmd : SCC_LIST opt_word terminator	{ lscf_list($2); free($2); }
225 	| SCC_LIST error terminator	{ synerr(SCC_LIST); }
226 
227 add_cmd : SCC_ADD SCV_WORD terminator	{ lscf_add($2); free($2); }
228 	| SCC_ADD error terminator	{ synerr(SCC_ADD); }
229 
230 delete_cmd : SCC_DELETE SCV_WORD terminator
231 					{ lscf_delete($2, 0); free($2); }
232 	| SCC_DELETE SCV_WORD SCV_WORD terminator
233 	{
234 		if (strcmp($2, "-f") == 0) {
235 			lscf_delete($3, 1);
236 			free($2);
237 			free($3);
238 		} else {
239 			synerr(SCC_DELETE);
240 		}
241 	}
242 	| SCC_DELETE error terminator	{ synerr(SCC_DELETE); }
243 
244 select_cmd : SCC_SELECT SCV_WORD terminator	{ lscf_select($2); free($2); }
245 	| SCC_SELECT error terminator		{ synerr(SCC_SELECT); }
246 
247 unselect_cmd : SCC_UNSELECT terminator	{ lscf_unselect(); }
248 	| SCC_UNSELECT error terminator	{ synerr(SCC_UNSELECT); }
249 
250 listpg_cmd : SCC_LISTPG opt_word terminator
251 					{ lscf_listpg($2); free($2); }
252 	| SCC_LISTPG error terminator	{ synerr(SCC_LISTPG); }
253 
254 addpg_cmd : SCC_ADDPG SCV_WORD SCV_WORD opt_word terminator
255 	{
256 		(void) lscf_addpg($2, $3, $4);
257 		free($2);
258 		free($3);
259 		free($4);
260 	}
261 	| SCC_ADDPG error terminator	{ synerr(SCC_ADDPG); }
262 
263 delpg_cmd : SCC_DELPG SCV_WORD terminator
264 					{ lscf_delpg($2); free($2); }
265 	| SCC_DELPG error terminator	{ synerr(SCC_DELPG); }
266 
267 listprop_cmd : SCC_LISTPROP opt_word terminator
268 					{ lscf_listprop($2); free($2); }
269 	| SCC_LISTPROP error terminator	{ synerr(SCC_LISTPROP); }
270 
271 setprop_cmd : SCC_SETPROP SCV_WORD SCS_EQUALS string terminator
272 	{
273 		lscf_setprop($2, NULL, $4, NULL);
274 		free($2);
275 		free($4);
276 	}
277 	| SCC_SETPROP SCV_WORD SCS_EQUALS SCV_WORD string terminator
278 	{
279 		(void) lscf_setprop($2, $4, $5, NULL);
280 		free($2);
281 		free($4);
282 		free($5);
283 	}
284 	| SCC_SETPROP SCV_WORD SCS_EQUALS opt_word SCS_LPAREN
285 	      multiline_string_list SCS_RPAREN terminator
286 	{
287 		string_list_t *slp;
288 		void *cookie = NULL;
289 
290 		(void) lscf_setprop($2, $4, NULL, $6);
291 
292 		free($2);
293 		free($4);
294 
295 		while ((slp = uu_list_teardown($6, &cookie)) != NULL) {
296 			free(slp->str);
297 			free(slp);
298 		}
299 
300 		uu_list_destroy($6);
301 	}
302 	| SCC_SETPROP error terminator	{ synerr(SCC_SETPROP); }
303 	| SCC_SETPROP error		{ synerr(SCC_SETPROP); }
304 
305 delprop_cmd : SCC_DELPROP SCV_WORD terminator
306 					{ lscf_delprop($2); free($2); }
307 	| SCC_DELPROP error terminator	{ synerr(SCC_DELPROP); }
308 
309 editprop_cmd : SCC_EDITPROP terminator	{ lscf_editprop(); }
310 	| SCC_EDITPROP error terminator	{ synerr(SCC_EDITPROP); }
311 
312 addpropvalue_cmd : SCC_ADDPROPVALUE SCV_WORD string terminator
313 	{
314 		lscf_addpropvalue($2, NULL, $3);
315 		free($2);
316 		free($3);
317 	}
318 	| SCC_ADDPROPVALUE SCV_WORD string string terminator
319 	{
320 		(void) lscf_addpropvalue($2, $3, $4);
321 		free($2);
322 		free($3);
323 		free($4);
324 	}
325 	| SCC_ADDPROPVALUE error terminator { synerr(SCC_ADDPROPVALUE); }
326 
327 delpropvalue_cmd : SCC_DELPROPVALUE SCV_WORD string terminator
328 	{
329 		lscf_delpropvalue($2, $3, 0);
330 		free($2);
331 		free($3);
332 	}
333 	| SCC_DELPROPVALUE error terminator { synerr(SCC_DELPROPVALUE); }
334 
335 setenv_cmd : SCC_SETENV string_list terminator
336 	{
337 		string_list_t *slp;
338 		void *cookie = NULL;
339 
340 		if (lscf_setenv($2, 0) == -2)
341 			synerr(SCC_SETENV);
342 
343 		while ((slp = uu_list_teardown($2, &cookie)) != NULL) {
344 			free(slp->str);
345 			free(slp);
346 		}
347 
348 		uu_list_destroy($2);
349 	}
350 	| SCC_SETENV error terminator		{ synerr(SCC_SETENV); }
351 
352 unsetenv_cmd : SCC_UNSETENV string_list terminator
353 	{
354 		string_list_t *slp;
355 		void *cookie = NULL;
356 
357 		if (lscf_setenv($2, 1) == -2)
358 			synerr(SCC_UNSETENV);
359 
360 		while ((slp = uu_list_teardown($2, &cookie)) != NULL) {
361 			free(slp->str);
362 			free(slp);
363 		}
364 
365 		uu_list_destroy($2);
366 	}
367 	| SCC_UNSETENV error terminator		{ synerr(SCC_UNSETENV); }
368 
369 listsnap_cmd : SCC_LISTSNAP terminator	{ lscf_listsnap(); }
370 	| SCC_LISTSNAP error terminator	{ synerr(SCC_LISTSNAP); }
371 
372 selectsnap_cmd : SCC_SELECTSNAP opt_word terminator
373 					{ lscf_selectsnap($2); free($2); }
374 	| SCC_SELECTSNAP error terminator
375 					{ synerr(SCC_SELECTSNAP); }
376 
377 revert_cmd: SCC_REVERT opt_word terminator	{ lscf_revert($2); free ($2); }
378 	| SCC_REVERT error terminator		{ synerr(SCC_REVERT); }
379 
380 
381 terminator : SCS_NEWLINE
382 
383 string_list :
384 	{
385 		$$ = uu_list_create(string_pool, NULL, 0);
386 		if ($$ == NULL)
387 			uu_die(gettext("Out of memory\n"));
388 	}
389 	| string_list string
390 	{
391 		string_list_t *slp;
392 
393 		slp = safe_malloc(sizeof (*slp));
394 
395 		slp->str = $2;
396 		uu_list_node_init(slp, &slp->node, string_pool);
397 		uu_list_append($1, slp);
398 		$$ = $1;
399 	}
400 
401 multiline_string_list : string_list
402 	{
403 		$$ = $1;
404 	}
405 	| multiline_string_list SCS_NEWLINE string_list
406 	{
407 		void *cookie = NULL;
408 		string_list_t *slp;
409 
410 		/* Append $3 to $1. */
411 		while ((slp = uu_list_teardown($3, &cookie)) != NULL)
412 			uu_list_append($1, slp);
413 
414 		uu_list_destroy($3);
415 	}
416 
417 string : SCV_WORD	{ $$ = $1; }
418 	| SCV_STRING	{ $$ = $1; }
419 
420 opt_word :		{ $$ = NULL; }
421 	| SCV_WORD	{ $$ = $1; }
422 
423 command_token : SCC_VALIDATE	{ $$ = SCC_VALIDATE; }
424 	| SCC_IMPORT		{ $$ = SCC_IMPORT; }
425 	| SCC_EXPORT		{ $$ = SCC_EXPORT; }
426 	| SCC_APPLY		{ $$ = SCC_APPLY; }
427 	| SCC_EXTRACT		{ $$ = SCC_EXTRACT; }
428 	| SCC_REPOSITORY	{ $$ = SCC_REPOSITORY; }
429 	| SCC_ARCHIVE		{ $$ = SCC_ARCHIVE; }
430 	| SCC_INVENTORY		{ $$ = SCC_INVENTORY; }
431 	| SCC_SET		{ $$ = SCC_SET; }
432 	| SCC_END		{ $$ = SCC_END; }
433 	| SCC_HELP		{ $$ = SCC_HELP; }
434 	| SCC_LIST		{ $$ = SCC_LIST; }
435 	| SCC_ADD		{ $$ = SCC_ADD; }
436 	| SCC_DELETE		{ $$ = SCC_DELETE; }
437 	| SCC_SELECT		{ $$ = SCC_SELECT; }
438 	| SCC_UNSELECT		{ $$ = SCC_UNSELECT; }
439 	| SCC_LISTPG		{ $$ = SCC_LISTPG; }
440 	| SCC_ADDPG		{ $$ = SCC_ADDPG; }
441 	| SCC_DELPG		{ $$ = SCC_DELPG; }
442 	| SCC_LISTPROP		{ $$ = SCC_LISTPROP; }
443 	| SCC_SETPROP		{ $$ = SCC_SETPROP; }
444 	| SCC_DELPROP		{ $$ = SCC_DELPROP; }
445 	| SCC_EDITPROP		{ $$ = SCC_EDITPROP; }
446 	| SCC_ADDPROPVALUE	{ $$ = SCC_ADDPROPVALUE; }
447 	| SCC_DELPROPVALUE	{ $$ = SCC_DELPROPVALUE; }
448 	| SCC_SETENV		{ $$ = SCC_SETENV; }
449 	| SCC_UNSETENV		{ $$ = SCC_UNSETENV; }
450 	| SCC_LISTSNAP		{ $$ = SCC_LISTSNAP; }
451 	| SCC_SELECTSNAP	{ $$ = SCC_SELECTSNAP; }
452 	| SCC_REVERT		{ $$ = SCC_REVERT; }
453