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 lex_lineno
;
79 #define MANIFEST_DTD_PATH "/usr/share/lib/xml/dtd/service_bundle.dtd.1"
81 * The following list must be kept in the same order as that of
84 typedef enum element
{
92 SC_INSTANCE_CREATE_DEFAULT
,
107 SC_INTERNAL_SEPARATORS
,
111 SC_METHOD_CREDENTIAL
,
113 SC_METHOD_ENVIRONMENT
,
118 SC_NOTIFICATION_PARAMETERS
,
148 typedef enum bundle_type
{
149 SVCCFG_UNKNOWN_BUNDLE
, SVCCFG_MANIFEST
, SVCCFG_PROFILE
, SVCCFG_ARCHIVE
152 typedef struct bundle
{
153 uu_list_t
*sc_bundle_services
;
155 xmlChar
*sc_bundle_name
;
156 bundle_type_t sc_bundle_type
;
159 typedef enum service_type
{
160 SVCCFG_UNKNOWN_SERVICE
= 0x0, SVCCFG_SERVICE
, SVCCFG_RESTARTER
,
164 typedef enum entity_type
{
165 SVCCFG_SERVICE_OBJECT
= 0x0, SVCCFG_INSTANCE_OBJECT
177 typedef enum svccfg_op
{
179 SVCCFG_OP_IMPORT
= 0,
185 * Return values for functions that validate an entity against the templates.
187 typedef enum tmpl_validate_status
{
190 * Either conversion of ASTRING property value to a number failed,
191 * or base 32 decoding of a property value failed.
194 /* Template is defective. */
196 /* Template type spec is invalid. */
197 TVS_INVALID_TYPE_SPECIFICATION
,
198 /* Property group is missing a type specification. */
200 /* Template with required == true is missing type specification. */
201 TVS_MISSING_TYPE_SPECIFICATION
,
202 /* No match was found for specified item. */
204 /* Validation error occurred */
206 /* Validation error that should not inhibit import. */
208 /* Could not validate because of fatal errors. */
210 } tmpl_validate_status_t
;
213 * The composed_pg structure is used for templates validation. It is
214 * defined in svccfg_tmpl.c
216 typedef struct composed_pg composed_pg_t
;
218 typedef struct entity
{
219 uu_list_node_t sc_node
;
220 entity_type_t sc_etype
;
222 /* Common fields to all entities. */
225 uu_list_t
*sc_pgroups
;
226 uu_list_t
*sc_dependents
;
227 struct entity
*sc_parent
;
228 enum import_state sc_import_state
;
229 boolean_t sc_miss_type
;
235 uu_list_t
*sc_service_instances
;
236 service_type_t sc_service_type
;
237 uint_t sc_service_version
;
238 /* Following used by template validation */
239 struct entity
*sc_restarter
;
240 struct entity
*sc_global
;
243 uu_avl_t
*sc_composed
;
244 /* Following used by template validation */
245 struct entity
*sc_instance_restarter
;
251 * sc_pgroup_composed is only used for templates validation of properties.
252 * It is created in build_composed_property_groups() and destroyed in
253 * composed_pg_destroy(). It will only be set for property groups that are
254 * part of an instance -- not for service property groups.
256 typedef struct pgroup
{
257 uu_list_node_t sc_node
;
258 uu_list_t
*sc_pgroup_props
;
259 composed_pg_t
*sc_pgroup_composed
; /* Composed properties */
261 const char *sc_pgroup_name
;
262 const char *sc_pgroup_type
;
263 uint_t sc_pgroup_flags
;
264 struct entity
*sc_parent
;
266 int sc_pgroup_delete
;
267 int sc_pgroup_override
;
268 const char *sc_pgroup_fmri
; /* Used for dependents */
273 typedef struct property
{
274 uu_list_node_t sc_node
;
275 uu_avl_node_t sc_composed_node
; /* Composed props linkage */
276 uu_list_t
*sc_property_values
;
278 char *sc_property_name
;
279 scf_type_t sc_value_type
;
281 int sc_property_override
;
285 typedef struct value
{
286 uu_list_node_t sc_node
;
290 void (*sc_free
)(struct value
*);
299 typedef struct scf_callback
{
300 scf_handle_t
*sc_handle
;
301 void *sc_parent
; /* immediate parent: scope, service, */
302 /* instance, property group, property */
303 scf_transaction_t
*sc_trans
;
304 int sc_service
; /* True if sc_parent is a service. */
306 pgroup_t
*sc_general
; /* pointer to general property group */
307 property_t
*sc_enable
; /* pointer to enable property */
309 const char *sc_source_fmri
;
310 const char *sc_target_fmri
;
315 * Collection of template validation errors.
317 typedef struct tmpl_errors tmpl_errors_t
;
319 #define bad_error(func, err) \
320 uu_panic("%s:%d: %s() failed with unexpected " \
321 "error %d. Aborting.\n", __FILE__, __LINE__, (func), (err));
323 #define SC_CMD_LINE 0x0
324 #define SC_CMD_FILE 0x1
325 #define SC_CMD_EOF 0x2
326 #define SC_CMD_IACTIVE 0x4
327 #define SC_CMD_DONT_EXIT 0x8
329 typedef struct engine_state
{
332 uint_t sc_cmd_lineno
;
333 const char *sc_cmd_filename
;
338 boolean_t sc_fs_minimal
; /* SCF_INSTANCE_FS_MINIMAL is online. */
339 boolean_t sc_in_emi
; /* During early import */
340 boolean_t sc_miss_type
; /* Apply profile found missing types */
343 const char *sc_repo_filename
;
344 const char *sc_repo_doordir
;
345 const char *sc_repo_doorname
;
346 const char *sc_repo_server
;
349 extern engine_state_t
*est
;
351 typedef struct string_list
{
356 extern uu_list_pool_t
*string_pool
;
358 struct help_message
{
363 extern struct help_message help_messages
[];
365 extern scf_handle_t
*g_hndl
; /* global repcached connection handle */
366 extern int g_exitcode
;
367 extern int g_verbose
;
369 extern ssize_t max_scf_fmri_len
;
370 extern ssize_t max_scf_name_len
;
371 extern ssize_t max_scf_value_len
;
372 extern ssize_t max_scf_pg_type_len
;
375 extern const char * const name_attr
;
376 extern const char * const type_attr
;
377 extern const char * const value_attr
;
378 extern const char * const enabled_attr
;
379 extern const char * const active_attr
;
380 extern const char * const scf_pg_general
;
381 extern const char * const scf_group_framework
;
382 extern const char * const true;
383 extern const char * const false;
385 #define uu_list_append(list, elem) uu_list_insert_before(list, NULL, elem)
386 #define uu_list_prepend(list, elem) uu_list_insert_after(list, NULL, elem)
388 void *safe_malloc(size_t);
389 char *safe_strdup(const char *);
390 void warn(const char *, ...);
392 void semerr(const char *, ...);
394 void internal_init(void);
395 void internal_dump(bundle_t
*);
397 int value_cmp(const void *, const void *, void *);
399 bundle_t
*internal_bundle_new(void);
400 void internal_bundle_free(bundle_t
*);
401 entity_t
*internal_service_new(const char *);
402 void internal_service_free(entity_t
*);
403 entity_t
*internal_instance_new(const char *);
404 void internal_instance_free(entity_t
*);
405 entity_t
*internal_template_new(void);
406 pgroup_t
*internal_pgroup_new(void);
407 void internal_pgroup_free(pgroup_t
*);
408 pgroup_t
*internal_pgroup_find(entity_t
*, const char *, const char *);
409 pgroup_t
*internal_dependent_find(entity_t
*, const char *);
410 pgroup_t
*internal_pgroup_find_or_create(entity_t
*, const char *,
412 pgroup_t
*internal_pgroup_create_strict(entity_t
*, const char *,
414 property_t
*internal_property_new(void);
415 void internal_property_free(property_t
*);
416 property_t
*internal_property_find(pgroup_t
*, const char *);
417 property_t
*internal_property_create(const char *, scf_type_t
, uint_t
, ...);
418 value_t
*internal_value_new(void);
420 int internal_attach_service(bundle_t
*, entity_t
*);
421 int internal_attach_entity(entity_t
*, entity_t
*);
422 int internal_attach_pgroup(entity_t
*, pgroup_t
*);
423 void internal_detach_pgroup(entity_t
*, pgroup_t
*);
424 int internal_attach_dependent(entity_t
*, pgroup_t
*);
425 int internal_attach_property(pgroup_t
*, property_t
*);
426 void internal_detach_property(pgroup_t
*, property_t
*);
427 void internal_attach_value(property_t
*, value_t
*);
430 void load_fini(void);
431 int load_instance(const char *, const char *, entity_t
**);
432 int load_pg_attrs(const scf_propertygroup_t
*, pgroup_t
**);
433 int load_pg(const scf_propertygroup_t
*, pgroup_t
**, const char *,
435 int prop_equal(property_t
*, property_t
*, const char *, const char *, int);
436 int pg_attrs_equal(const pgroup_t
*, const pgroup_t
*, const char *, int);
437 int pg_equal(pgroup_t
*, pgroup_t
*);
439 void lscf_cleanup(void);
440 void lscf_prep_hndl(void);
441 void lscf_init(void);
442 int lscf_bundle_import(bundle_t
*, const char *, uint_t
);
443 int lscf_bundle_apply(bundle_t
*, const char *);
444 void lscf_delete(const char *, int);
445 void lscf_list(const char *);
446 void lscf_select(const char *);
447 void lscf_unselect();
448 void lscf_get_selection_str(char *, size_t);
449 void lscf_add(const char *);
450 void lscf_listpg(const char *);
451 void lscf_addpg(const char *, const char *, const char *);
452 void lscf_delpg(char *);
453 void lscf_delhash(char *, int);
454 void lscf_listprop(const char *);
455 void lscf_addprop(char *, const char *, const uu_list_t
*);
456 void lscf_delprop(char *);
457 int lscf_describe(uu_list_t
*, int);
458 void lscf_listsnap();
459 void lscf_selectsnap(const char *);
460 void lscf_revert(const char *);
462 char *filename_to_propname(const char *);
463 int lscf_retrieve_hash(const char *, unsigned char *);
464 int lscf_store_hash(const char *, unsigned char *);
465 int lscf_service_cleanup(void *, scf_walkinfo_t
*);
466 int lscf_hash_cleanup();
467 void lscf_delnotify(const char *, int);
468 void lscf_listnotify(const char *, int);
469 int lscf_setnotify(uu_list_t
*);
471 CPL_MATCH_FN(complete_select
);
472 CPL_MATCH_FN(complete_command
);
475 int lxml_get_bundle_file(bundle_t
*, const char *, svccfg_op_t
);
476 void lxml_store_value(value_t
*, element_t
, const xmlChar
*);
478 void engine_init(void);
479 int engine_exec_cmd(void);
480 int engine_exec(char *);
481 int add_cmd_matches(WordCompletion
*, const char *, int, uint32_t);
482 int engine_interp(void);
483 int engine_source(const char *, boolean_t
);
484 int engine_import(uu_list_t
*);
485 int engine_cleanup(int);
488 int engine_cmd_getc(engine_state_t
*);
489 int engine_cmd_ungetc(engine_state_t
*, char);
490 void engine_cmd_nputs(engine_state_t
*, char *, size_t);
492 void tmpl_errors_destroy(tmpl_errors_t
*);
493 void tmpl_errors_print(FILE *, tmpl_errors_t
*, const char *);
494 void tmpl_init(void);
495 void tmpl_property_fini(property_t
*);
496 void tmpl_property_init(property_t
*);
497 tmpl_validate_status_t
tmpl_validate_bundle(bundle_t
*, tmpl_errors_t
**);
500 #define MIXED_TOKENS -1
501 #define INVALID_TOKENS -2
503 char **tokenize(char *, const char *);
504 int32_t check_tokens(char **);
505 const char *de_tag(const char *);
506 const char *tset_to_string(int32_t);
512 #endif /* _CMD_SVCCFG_H */