4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Copyright (c) 2015, Joyent, Inc. All rights reserved.
31 #include <sys/types.h>
33 #include <libxml/tree.h>
36 #include <libscf_priv.h>
44 /* Command scope bits for command tab completion */
49 #define CS_GLOBAL 0x0f
51 /* Flags for lscf_bundle_import() & co. */
52 #define SCI_NOREFRESH 0x01 /* Don't refresh instances */
53 #define SCI_GENERALLAST 0x04 /* Add general property group last */
54 #define SCI_NOENABLED 0x08 /* Don't import general/enabled. */
55 #define SCI_FRESH 0x10 /* Freshly imported service */
56 #define SCI_FORCE 0x20 /* Override-import. */
57 #define SCI_KEEP 0x40 /* Don't delete when SCI_FORCEing */
58 #define SCI_NOSNAP 0x80 /* Don't take last-import snapshot */
59 #define SCI_DELAYENABLE 0x100 /* Delay the general/enable property */
61 #define SCI_OP_IMPORT 0x1000
62 #define SCI_OP_APPLY 0x2000
63 #define SCI_OP_RESTORE 0x4000
65 #define HASH_SVC "smf/manifest"
68 * If the filesystem/minimal service is not online, do not consider
69 * manifests in the /var file system.
71 #define IGNORE_VAR (!est->sc_fs_minimal)
73 /* Flags for lscf_service_export() */
74 #define SCE_ALL_VALUES 0x01 /* Include all property values */
77 extern int yyerror(const char *);
78 extern int yyparse(void);
81 extern int lex_lineno
;
83 #define MANIFEST_DTD_PATH "/usr/share/lib/xml/dtd/service_bundle.dtd.1"
85 * The following list must be kept in the same order as that of
88 typedef enum element
{
96 SC_INSTANCE_CREATE_DEFAULT
,
111 SC_INTERNAL_SEPARATORS
,
115 SC_METHOD_CREDENTIAL
,
117 SC_METHOD_ENVIRONMENT
,
122 SC_NOTIFICATION_PARAMETERS
,
152 typedef enum bundle_type
{
153 SVCCFG_UNKNOWN_BUNDLE
, SVCCFG_MANIFEST
, SVCCFG_PROFILE
, SVCCFG_ARCHIVE
156 typedef struct bundle
{
157 uu_list_t
*sc_bundle_services
;
159 xmlChar
*sc_bundle_name
;
160 bundle_type_t sc_bundle_type
;
163 typedef enum service_type
{
164 SVCCFG_UNKNOWN_SERVICE
= 0x0, SVCCFG_SERVICE
, SVCCFG_RESTARTER
,
168 typedef enum entity_type
{
169 SVCCFG_SERVICE_OBJECT
= 0x0, SVCCFG_INSTANCE_OBJECT
181 typedef enum svccfg_op
{
183 SVCCFG_OP_IMPORT
= 0,
189 * Return values for functions that validate an entity against the templates.
191 typedef enum tmpl_validate_status
{
194 * Either conversion of ASTRING property value to a number failed,
195 * or base 32 decoding of a property value failed.
198 /* Template is defective. */
200 /* Template type spec is invalid. */
201 TVS_INVALID_TYPE_SPECIFICATION
,
202 /* Property group is missing a type specification. */
204 /* Template with required == true is missing type specification. */
205 TVS_MISSING_TYPE_SPECIFICATION
,
206 /* No match was found for specified item. */
208 /* Validation error occurred */
210 /* Validation error that should not inhibit import. */
212 /* Could not validate because of fatal errors. */
214 } tmpl_validate_status_t
;
217 * The composed_pg structure is used for templates validation. It is
218 * defined in svccfg_tmpl.c
220 typedef struct composed_pg composed_pg_t
;
222 typedef struct entity
{
223 uu_list_node_t sc_node
;
224 entity_type_t sc_etype
;
226 /* Common fields to all entities. */
229 uu_list_t
*sc_pgroups
;
230 uu_list_t
*sc_dependents
;
231 struct entity
*sc_parent
;
232 enum import_state sc_import_state
;
233 boolean_t sc_miss_type
;
239 uu_list_t
*sc_service_instances
;
240 service_type_t sc_service_type
;
241 uint_t sc_service_version
;
242 /* Following used by template validation */
243 struct entity
*sc_restarter
;
244 struct entity
*sc_global
;
247 uu_avl_t
*sc_composed
;
248 /* Following used by template validation */
249 struct entity
*sc_instance_restarter
;
255 * sc_pgroup_composed is only used for templates validation of properties.
256 * It is created in build_composed_property_groups() and destroyed in
257 * composed_pg_destroy(). It will only be set for property groups that are
258 * part of an instance -- not for service property groups.
260 typedef struct pgroup
{
261 uu_list_node_t sc_node
;
262 uu_list_t
*sc_pgroup_props
;
263 composed_pg_t
*sc_pgroup_composed
; /* Composed properties */
265 const char *sc_pgroup_name
;
266 const char *sc_pgroup_type
;
267 uint_t sc_pgroup_flags
;
268 struct entity
*sc_parent
;
270 int sc_pgroup_delete
;
271 int sc_pgroup_override
;
272 const char *sc_pgroup_fmri
; /* Used for dependents */
277 typedef struct property
{
278 uu_list_node_t sc_node
;
279 uu_avl_node_t sc_composed_node
; /* Composed props linkage */
280 uu_list_t
*sc_property_values
;
282 char *sc_property_name
;
283 scf_type_t sc_value_type
;
285 int sc_property_override
;
289 typedef struct value
{
290 uu_list_node_t sc_node
;
294 void (*sc_free
)(struct value
*);
303 typedef struct scf_callback
{
304 scf_handle_t
*sc_handle
;
305 void *sc_parent
; /* immediate parent: scope, service, */
306 /* instance, property group, property */
307 scf_transaction_t
*sc_trans
;
308 int sc_service
; /* True if sc_parent is a service. */
310 pgroup_t
*sc_general
; /* pointer to general property group */
311 property_t
*sc_enable
; /* pointer to enable property */
313 const char *sc_source_fmri
;
314 const char *sc_target_fmri
;
319 * Collection of template validation errors.
321 typedef struct tmpl_errors tmpl_errors_t
;
323 #define bad_error(func, err) \
324 uu_panic("%s:%d: %s() failed with unexpected " \
325 "error %d. Aborting.\n", __FILE__, __LINE__, (func), (err));
327 #define SC_CMD_LINE 0x0
328 #define SC_CMD_FILE 0x1
329 #define SC_CMD_EOF 0x2
330 #define SC_CMD_IACTIVE 0x4
331 #define SC_CMD_DONT_EXIT 0x8
333 typedef struct engine_state
{
336 uint_t sc_cmd_lineno
;
337 const char *sc_cmd_filename
;
342 boolean_t sc_fs_minimal
; /* SCF_INSTANCE_FS_MINIMAL is online. */
343 boolean_t sc_in_emi
; /* During early import */
344 boolean_t sc_miss_type
; /* Apply profile found missing types */
347 const char *sc_repo_filename
;
348 const char *sc_repo_doordir
;
349 const char *sc_repo_doorname
;
350 const char *sc_repo_server
;
353 extern engine_state_t
*est
;
355 typedef struct string_list
{
360 extern uu_list_pool_t
*string_pool
;
362 struct help_message
{
367 extern struct help_message help_messages
[];
369 extern scf_handle_t
*g_hndl
; /* global repcached connection handle */
370 extern int g_exitcode
;
371 extern int g_verbose
;
373 extern ssize_t max_scf_fmri_len
;
374 extern ssize_t max_scf_name_len
;
375 extern ssize_t max_scf_value_len
;
376 extern ssize_t max_scf_pg_type_len
;
379 extern const char * const name_attr
;
380 extern const char * const type_attr
;
381 extern const char * const value_attr
;
382 extern const char * const enabled_attr
;
383 extern const char * const active_attr
;
384 extern const char * const scf_pg_general
;
385 extern const char * const scf_group_framework
;
386 extern const char * const true;
387 extern const char * const false;
389 #define uu_list_append(list, elem) uu_list_insert_before(list, NULL, elem)
390 #define uu_list_prepend(list, elem) uu_list_insert_after(list, NULL, elem)
392 void *safe_malloc(size_t);
393 char *safe_strdup(const char *);
394 void warn(const char *, ...);
396 void semerr(const char *, ...);
398 void internal_init(void);
399 void internal_dump(bundle_t
*);
401 int value_cmp(const void *, const void *, void *);
403 bundle_t
*internal_bundle_new(void);
404 void internal_bundle_free(bundle_t
*);
405 entity_t
*internal_service_new(const char *);
406 void internal_service_free(entity_t
*);
407 entity_t
*internal_instance_new(const char *);
408 void internal_instance_free(entity_t
*);
409 entity_t
*internal_template_new(void);
410 pgroup_t
*internal_pgroup_new(void);
411 void internal_pgroup_free(pgroup_t
*);
412 pgroup_t
*internal_pgroup_find(entity_t
*, const char *, const char *);
413 pgroup_t
*internal_dependent_find(entity_t
*, const char *);
414 pgroup_t
*internal_pgroup_find_or_create(entity_t
*, const char *,
416 pgroup_t
*internal_pgroup_create_strict(entity_t
*, const char *,
418 property_t
*internal_property_new(void);
419 void internal_property_free(property_t
*);
420 property_t
*internal_property_find(pgroup_t
*, const char *);
421 property_t
*internal_property_create(const char *, scf_type_t
, uint_t
, ...);
422 value_t
*internal_value_new(void);
424 int internal_attach_service(bundle_t
*, entity_t
*);
425 int internal_attach_entity(entity_t
*, entity_t
*);
426 int internal_attach_pgroup(entity_t
*, pgroup_t
*);
427 void internal_detach_pgroup(entity_t
*, pgroup_t
*);
428 int internal_attach_dependent(entity_t
*, pgroup_t
*);
429 int internal_attach_property(pgroup_t
*, property_t
*);
430 void internal_detach_property(pgroup_t
*, property_t
*);
431 void internal_attach_value(property_t
*, value_t
*);
434 void load_fini(void);
435 int load_instance(const char *, const char *, entity_t
**);
436 int load_pg_attrs(const scf_propertygroup_t
*, pgroup_t
**);
437 int load_pg(const scf_propertygroup_t
*, pgroup_t
**, const char *,
439 int prop_equal(property_t
*, property_t
*, const char *, const char *, int);
440 int pg_attrs_equal(const pgroup_t
*, const pgroup_t
*, const char *, int);
441 int pg_equal(pgroup_t
*, pgroup_t
*);
443 void lscf_cleanup(void);
444 void lscf_prep_hndl(void);
445 void lscf_init(void);
446 int lscf_bundle_import(bundle_t
*, const char *, uint_t
);
447 int lscf_bundle_apply(bundle_t
*, const char *);
448 void lscf_delete(const char *, int);
449 void lscf_list(const char *);
450 void lscf_select(const char *);
451 void lscf_unselect();
452 void lscf_get_selection_str(char *, size_t);
453 void lscf_add(const char *);
454 void lscf_listpg(const char *);
455 void lscf_addpg(const char *, const char *, const char *);
456 void lscf_delpg(char *);
457 void lscf_delhash(char *, int);
458 void lscf_listprop(const char *);
459 void lscf_addprop(char *, const char *, const uu_list_t
*);
460 void lscf_delprop(char *);
461 int lscf_describe(uu_list_t
*, int);
462 void lscf_listsnap();
463 void lscf_selectsnap(const char *);
464 void lscf_revert(const char *);
466 char *filename_to_propname(const char *);
467 int lscf_retrieve_hash(const char *, unsigned char *);
468 int lscf_store_hash(const char *, unsigned char *);
469 int lscf_service_cleanup(void *, scf_walkinfo_t
*);
470 int lscf_hash_cleanup();
471 void lscf_delnotify(const char *, int);
472 void lscf_listnotify(const char *, int);
473 int lscf_setnotify(uu_list_t
*);
475 CPL_MATCH_FN(complete_select
);
476 CPL_MATCH_FN(complete_command
);
479 int lxml_get_bundle_file(bundle_t
*, const char *, svccfg_op_t
);
480 void lxml_store_value(value_t
*, element_t
, const xmlChar
*);
482 void engine_init(void);
483 int engine_exec_cmd(void);
484 int engine_exec(char *);
485 int add_cmd_matches(WordCompletion
*, const char *, int, uint32_t);
486 int engine_interp(void);
487 int engine_source(const char *, boolean_t
);
488 int engine_import(uu_list_t
*);
489 int engine_cleanup(int);
492 int engine_cmd_getc(engine_state_t
*);
493 int engine_cmd_ungetc(engine_state_t
*, char);
494 void engine_cmd_nputs(engine_state_t
*, char *, size_t);
496 void tmpl_errors_destroy(tmpl_errors_t
*);
497 void tmpl_errors_print(FILE *, tmpl_errors_t
*, const char *);
498 void tmpl_init(void);
499 void tmpl_property_fini(property_t
*);
500 void tmpl_property_init(property_t
*);
501 tmpl_validate_status_t
tmpl_validate_bundle(bundle_t
*, tmpl_errors_t
**);
504 #define MIXED_TOKENS -1
505 #define INVALID_TOKENS -2
507 char **tokenize(char *, const char *);
508 int32_t check_tokens(char **);
509 const char *de_tag(const char *);
510 const char *tset_to_string(int32_t);
516 #endif /* _CMD_SVCCFG_H */