10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 55040Swesolows * Common Development and Distribution License (the "License"). 65040Swesolows * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 215040Swesolows 220Sstevel@tonic-gate /* 235777Stw21770 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate 270Sstevel@tonic-gate #ifndef _CMD_SVCCFG_H 280Sstevel@tonic-gate #define _CMD_SVCCFG_H 290Sstevel@tonic-gate 300Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 310Sstevel@tonic-gate 320Sstevel@tonic-gate #include <sys/types.h> 330Sstevel@tonic-gate 340Sstevel@tonic-gate #include <libxml/tree.h> 350Sstevel@tonic-gate 360Sstevel@tonic-gate #include <libscf.h> 370Sstevel@tonic-gate #include <libtecla.h> 380Sstevel@tonic-gate #include <libuutil.h> 390Sstevel@tonic-gate 400Sstevel@tonic-gate #ifdef __cplusplus 410Sstevel@tonic-gate extern "C" { 420Sstevel@tonic-gate #endif 430Sstevel@tonic-gate 440Sstevel@tonic-gate /* Command scope bits for command tab completion */ 450Sstevel@tonic-gate #define CS_SCOPE 0x01 460Sstevel@tonic-gate #define CS_SVC 0x02 470Sstevel@tonic-gate #define CS_INST 0x04 480Sstevel@tonic-gate #define CS_SNAP 0x08 490Sstevel@tonic-gate #define CS_GLOBAL 0x0f 500Sstevel@tonic-gate 510Sstevel@tonic-gate /* Flags for lscf_bundle_import() & co. */ 520Sstevel@tonic-gate #define SCI_NOREFRESH 0x01 /* Don't refresh instances */ 530Sstevel@tonic-gate #define SCI_GENERALLAST 0x04 /* Add general property group last */ 540Sstevel@tonic-gate #define SCI_NOENABLED 0x08 /* Don't import general/enabled. */ 550Sstevel@tonic-gate #define SCI_FRESH 0x10 /* Freshly imported service */ 560Sstevel@tonic-gate #define SCI_FORCE 0x20 /* Override-import. */ 570Sstevel@tonic-gate #define SCI_KEEP 0x40 /* Don't delete when SCI_FORCEing */ 585040Swesolows #define SCI_NOSNAP 0x80 /* Don't take last-import snapshot */ 595040Swesolows 605040Swesolows /* Flags for lscf_service_export() */ 615040Swesolows #define SCE_ALL_VALUES 0x01 /* Include all property values */ 620Sstevel@tonic-gate 630Sstevel@tonic-gate #ifdef lint 640Sstevel@tonic-gate extern int yyerror(const char *); 650Sstevel@tonic-gate extern int yyparse(void); 660Sstevel@tonic-gate #endif /* lint */ 670Sstevel@tonic-gate 680Sstevel@tonic-gate extern int lex_lineno; 690Sstevel@tonic-gate 700Sstevel@tonic-gate #define MANIFEST_DTD_PATH "/usr/share/lib/xml/dtd/service_bundle.dtd.1" 710Sstevel@tonic-gate /* 720Sstevel@tonic-gate * The following list must be kept in the same order as that of 730Sstevel@tonic-gate * lxml_prop_types[] 740Sstevel@tonic-gate */ 750Sstevel@tonic-gate typedef enum element { 760Sstevel@tonic-gate SC_ASTRING = 0x0, SC_BOOLEAN, SC_COMMON_NAME, SC_COUNT, 770Sstevel@tonic-gate SC_INSTANCE_CREATE_DEFAULT, SC_DEPENDENCY, SC_DEPENDENT, SC_DESCRIPTION, 780Sstevel@tonic-gate SC_DOC_LINK, SC_DOCUMENTATION, SC_ENABLED, SC_EXEC_METHOD, SC_FMRI, 790Sstevel@tonic-gate SC_HOST, SC_HOSTNAME, SC_INSTANCE, SC_INTEGER, SC_LOCTEXT, SC_MANPAGE, 800Sstevel@tonic-gate SC_METHOD_CONTEXT, SC_METHOD_CREDENTIAL, SC_METHOD_PROFILE, 810Sstevel@tonic-gate SC_METHOD_ENVIRONMENT, SC_METHOD_ENVVAR, SC_NET_ADDR_V4, SC_NET_ADDR_V6, 820Sstevel@tonic-gate SC_OPAQUE, SC_PROPERTY, SC_PROPERTY_GROUP, SC_PROPVAL, SC_RESTARTER, 830Sstevel@tonic-gate SC_SERVICE, SC_SERVICE_BUNDLE, SC_SERVICE_FMRI, SC_INSTANCE_SINGLE, 840Sstevel@tonic-gate SC_STABILITY, SC_TEMPLATE, SC_TIME, SC_URI, SC_USTRING, SC_VALUE_NODE, 850Sstevel@tonic-gate SC_XI_FALLBACK, SC_XI_INCLUDE 860Sstevel@tonic-gate } element_t; 870Sstevel@tonic-gate 880Sstevel@tonic-gate typedef enum bundle_type { 890Sstevel@tonic-gate SVCCFG_UNKNOWN_BUNDLE, SVCCFG_MANIFEST, SVCCFG_PROFILE, SVCCFG_ARCHIVE 900Sstevel@tonic-gate } bundle_type_t; 910Sstevel@tonic-gate 920Sstevel@tonic-gate typedef struct bundle { 930Sstevel@tonic-gate uu_list_t *sc_bundle_services; 940Sstevel@tonic-gate 950Sstevel@tonic-gate xmlChar *sc_bundle_name; 960Sstevel@tonic-gate bundle_type_t sc_bundle_type; 970Sstevel@tonic-gate } bundle_t; 980Sstevel@tonic-gate 990Sstevel@tonic-gate typedef enum service_type { 1000Sstevel@tonic-gate SVCCFG_UNKNOWN_SERVICE = 0x0, SVCCFG_SERVICE, SVCCFG_RESTARTER, 1010Sstevel@tonic-gate SVCCFG_MILESTONE 1020Sstevel@tonic-gate } service_type_t; 1030Sstevel@tonic-gate 1040Sstevel@tonic-gate typedef enum entity_type { 1050Sstevel@tonic-gate SVCCFG_SERVICE_OBJECT = 0x0, SVCCFG_INSTANCE_OBJECT, 1060Sstevel@tonic-gate SVCCFG_TEMPLATE_OBJECT 1070Sstevel@tonic-gate } entity_type_t; 1080Sstevel@tonic-gate 1090Sstevel@tonic-gate enum import_state { 1100Sstevel@tonic-gate IMPORT_NONE = 0, 1110Sstevel@tonic-gate IMPORT_PREVIOUS, 1120Sstevel@tonic-gate IMPORT_PROP_BEGUN, 1130Sstevel@tonic-gate IMPORT_PROP_DONE, 1140Sstevel@tonic-gate IMPORT_COMPLETE, 1150Sstevel@tonic-gate IMPORT_REFRESHED 1160Sstevel@tonic-gate }; 1170Sstevel@tonic-gate 1185040Swesolows typedef enum svccfg_op { 1195040Swesolows SVCCFG_OP_IMPORT = 0, 1205040Swesolows SVCCFG_OP_APPLY, 1215040Swesolows SVCCFG_OP_RESTORE 1225040Swesolows } svccfg_op_t; 1235040Swesolows 1240Sstevel@tonic-gate typedef struct entity { 1250Sstevel@tonic-gate uu_list_node_t sc_node; 1260Sstevel@tonic-gate entity_type_t sc_etype; 1270Sstevel@tonic-gate 1280Sstevel@tonic-gate /* Common fields to all entities. */ 1290Sstevel@tonic-gate const char *sc_name; 1300Sstevel@tonic-gate const char *sc_fmri; 1310Sstevel@tonic-gate uu_list_t *sc_pgroups; 1320Sstevel@tonic-gate uu_list_t *sc_dependents; 1330Sstevel@tonic-gate struct entity *sc_parent; 1340Sstevel@tonic-gate enum import_state sc_import_state; 1350Sstevel@tonic-gate int sc_seen; 1360Sstevel@tonic-gate 1370Sstevel@tonic-gate union { 1380Sstevel@tonic-gate struct { 1390Sstevel@tonic-gate uu_list_t *sc_service_instances; 1400Sstevel@tonic-gate service_type_t sc_service_type; 1410Sstevel@tonic-gate uint_t sc_service_version; 1420Sstevel@tonic-gate 1430Sstevel@tonic-gate struct entity *sc_service_template; 1440Sstevel@tonic-gate } sc_service; 1450Sstevel@tonic-gate struct { 1460Sstevel@tonic-gate uint_t sc_instance_dummy; 1470Sstevel@tonic-gate } sc_instance; 1480Sstevel@tonic-gate struct { 1490Sstevel@tonic-gate uint_t sc_template_dummy; 1500Sstevel@tonic-gate } sc_template; 1510Sstevel@tonic-gate } sc_u; 1520Sstevel@tonic-gate } entity_t; 1530Sstevel@tonic-gate 1540Sstevel@tonic-gate typedef struct pgroup { 1550Sstevel@tonic-gate uu_list_node_t sc_node; 1560Sstevel@tonic-gate uu_list_t *sc_pgroup_props; 1570Sstevel@tonic-gate 1580Sstevel@tonic-gate const char *sc_pgroup_name; 1590Sstevel@tonic-gate const char *sc_pgroup_type; 1600Sstevel@tonic-gate uint_t sc_pgroup_flags; 1610Sstevel@tonic-gate struct entity *sc_parent; 1620Sstevel@tonic-gate 1630Sstevel@tonic-gate int sc_pgroup_delete; 1640Sstevel@tonic-gate int sc_pgroup_override; 1650Sstevel@tonic-gate const char *sc_pgroup_fmri; /* Used for dependents */ 1660Sstevel@tonic-gate 1670Sstevel@tonic-gate int sc_pgroup_seen; 1680Sstevel@tonic-gate } pgroup_t; 1690Sstevel@tonic-gate 1700Sstevel@tonic-gate typedef struct property { 1710Sstevel@tonic-gate uu_list_node_t sc_node; 1720Sstevel@tonic-gate uu_list_t *sc_property_values; 1730Sstevel@tonic-gate 1740Sstevel@tonic-gate char *sc_property_name; 1750Sstevel@tonic-gate scf_type_t sc_value_type; 1760Sstevel@tonic-gate 1770Sstevel@tonic-gate int sc_property_override; 1780Sstevel@tonic-gate int sc_seen; 1790Sstevel@tonic-gate } property_t; 1800Sstevel@tonic-gate 1810Sstevel@tonic-gate typedef struct value { 1820Sstevel@tonic-gate uu_list_node_t sc_node; 1830Sstevel@tonic-gate 1840Sstevel@tonic-gate scf_type_t sc_type; 1850Sstevel@tonic-gate 1860Sstevel@tonic-gate void (*sc_free)(struct value *); 1870Sstevel@tonic-gate 1880Sstevel@tonic-gate union { 1890Sstevel@tonic-gate uint64_t sc_count; 1900Sstevel@tonic-gate int64_t sc_integer; 1910Sstevel@tonic-gate char *sc_string; 1920Sstevel@tonic-gate } sc_u; 1930Sstevel@tonic-gate } value_t; 1940Sstevel@tonic-gate 1950Sstevel@tonic-gate typedef struct scf_callback { 1960Sstevel@tonic-gate scf_handle_t *sc_handle; 1970Sstevel@tonic-gate void *sc_parent; /* immediate parent: scope, service, */ 1980Sstevel@tonic-gate /* instance, property group, property */ 1990Sstevel@tonic-gate scf_transaction_t *sc_trans; 2000Sstevel@tonic-gate int sc_service; /* True if sc_parent is a service. */ 2010Sstevel@tonic-gate uint_t sc_flags; 2020Sstevel@tonic-gate pgroup_t *sc_general; /* pointer to general property group */ 2030Sstevel@tonic-gate 2040Sstevel@tonic-gate const char *sc_source_fmri; 2050Sstevel@tonic-gate const char *sc_target_fmri; 2060Sstevel@tonic-gate int sc_err; 2070Sstevel@tonic-gate } scf_callback_t; 2080Sstevel@tonic-gate 2090Sstevel@tonic-gate #ifndef NDEBUG 2100Sstevel@tonic-gate #define bad_error(func, err) { \ 2110Sstevel@tonic-gate (void) fprintf(stderr, "%s:%d: %s() failed with unexpected " \ 2120Sstevel@tonic-gate "error %d. Aborting.\n", __FILE__, __LINE__, (func), (err)); \ 2130Sstevel@tonic-gate abort(); \ 2140Sstevel@tonic-gate } 2150Sstevel@tonic-gate #else 2160Sstevel@tonic-gate #define bad_error(func, err) abort() 2170Sstevel@tonic-gate #endif 2180Sstevel@tonic-gate 2190Sstevel@tonic-gate #define SC_CMD_LINE 0x0 2200Sstevel@tonic-gate #define SC_CMD_FILE 0x1 2210Sstevel@tonic-gate #define SC_CMD_EOF 0x2 2220Sstevel@tonic-gate #define SC_CMD_IACTIVE 0x4 2230Sstevel@tonic-gate #define SC_CMD_DONT_EXIT 0x8 2240Sstevel@tonic-gate 2250Sstevel@tonic-gate typedef struct engine_state { 2260Sstevel@tonic-gate uint_t sc_cmd_flags; 2270Sstevel@tonic-gate FILE *sc_cmd_file; 2280Sstevel@tonic-gate uint_t sc_cmd_lineno; 2290Sstevel@tonic-gate const char *sc_cmd_filename; 2300Sstevel@tonic-gate char *sc_cmd_buf; 2310Sstevel@tonic-gate size_t sc_cmd_bufsz; 2320Sstevel@tonic-gate off_t sc_cmd_bufoff; 2330Sstevel@tonic-gate GetLine *sc_gl; 2340Sstevel@tonic-gate 2350Sstevel@tonic-gate pid_t sc_repo_pid; 2360Sstevel@tonic-gate const char *sc_repo_filename; 2370Sstevel@tonic-gate const char *sc_repo_doordir; 2380Sstevel@tonic-gate const char *sc_repo_doorname; 2390Sstevel@tonic-gate const char *sc_repo_server; 2400Sstevel@tonic-gate } engine_state_t; 2410Sstevel@tonic-gate 2420Sstevel@tonic-gate extern engine_state_t *est; 2430Sstevel@tonic-gate 2440Sstevel@tonic-gate typedef struct string_list { 2450Sstevel@tonic-gate uu_list_node_t node; 2460Sstevel@tonic-gate char *str; 2470Sstevel@tonic-gate } string_list_t; 2480Sstevel@tonic-gate 2490Sstevel@tonic-gate extern uu_list_pool_t *string_pool; 2500Sstevel@tonic-gate 2510Sstevel@tonic-gate struct help_message { 2520Sstevel@tonic-gate int token; 2530Sstevel@tonic-gate const char *message; 2540Sstevel@tonic-gate }; 2550Sstevel@tonic-gate 2560Sstevel@tonic-gate extern struct help_message help_messages[]; 2570Sstevel@tonic-gate 2580Sstevel@tonic-gate extern scf_handle_t *g_hndl; /* global repcached connection handle */ 2590Sstevel@tonic-gate extern int g_exitcode; 2600Sstevel@tonic-gate extern int g_verbose; 2610Sstevel@tonic-gate 2620Sstevel@tonic-gate extern ssize_t max_scf_fmri_len; 2630Sstevel@tonic-gate extern ssize_t max_scf_name_len; 2640Sstevel@tonic-gate extern ssize_t max_scf_value_len; 2650Sstevel@tonic-gate extern ssize_t max_scf_pg_type_len; 2660Sstevel@tonic-gate 2670Sstevel@tonic-gate /* Common strings */ 2680Sstevel@tonic-gate extern const char * const name_attr; 2690Sstevel@tonic-gate extern const char * const type_attr; 2700Sstevel@tonic-gate extern const char * const value_attr; 2710Sstevel@tonic-gate extern const char * const enabled_attr; 2720Sstevel@tonic-gate extern const char * const scf_pg_general; 2730Sstevel@tonic-gate extern const char * const scf_group_framework; 2740Sstevel@tonic-gate extern const char * const true; 2750Sstevel@tonic-gate extern const char * const false; 2760Sstevel@tonic-gate 2770Sstevel@tonic-gate #define uu_list_append(list, elem) uu_list_insert_before(list, NULL, elem) 2780Sstevel@tonic-gate #define uu_list_prepend(list, elem) uu_list_insert_after(list, NULL, elem) 2790Sstevel@tonic-gate 2800Sstevel@tonic-gate void *safe_malloc(size_t); 2810Sstevel@tonic-gate char *safe_strdup(const char *); 2820Sstevel@tonic-gate void warn(const char *, ...); 2830Sstevel@tonic-gate void synerr(int); 2840Sstevel@tonic-gate void semerr(const char *, ...); 2850Sstevel@tonic-gate 2860Sstevel@tonic-gate void internal_init(void); 2870Sstevel@tonic-gate void internal_dump(bundle_t *); 2880Sstevel@tonic-gate 2890Sstevel@tonic-gate int value_cmp(const void *, const void *, void *); 2900Sstevel@tonic-gate 2910Sstevel@tonic-gate bundle_t *internal_bundle_new(void); 2920Sstevel@tonic-gate void internal_bundle_free(bundle_t *); 2930Sstevel@tonic-gate entity_t *internal_service_new(const char *); 2940Sstevel@tonic-gate void internal_service_free(entity_t *); 2950Sstevel@tonic-gate entity_t *internal_instance_new(const char *); 2960Sstevel@tonic-gate void internal_instance_free(entity_t *); 2970Sstevel@tonic-gate entity_t *internal_template_new(void); 2980Sstevel@tonic-gate pgroup_t *internal_pgroup_new(void); 2990Sstevel@tonic-gate void internal_pgroup_free(pgroup_t *); 3000Sstevel@tonic-gate pgroup_t *internal_pgroup_find(entity_t *, const char *, const char *); 3010Sstevel@tonic-gate pgroup_t *internal_dependent_find(entity_t *, const char *); 3020Sstevel@tonic-gate pgroup_t *internal_pgroup_find_or_create(entity_t *, const char *, 3030Sstevel@tonic-gate const char *); 3040Sstevel@tonic-gate property_t *internal_property_new(void); 3050Sstevel@tonic-gate void internal_property_free(property_t *); 3060Sstevel@tonic-gate property_t *internal_property_find(pgroup_t *, const char *); 3070Sstevel@tonic-gate property_t *internal_property_create(const char *, scf_type_t, uint_t, ...); 3080Sstevel@tonic-gate value_t *internal_value_new(void); 3090Sstevel@tonic-gate 3100Sstevel@tonic-gate int internal_attach_service(bundle_t *, entity_t *); 3110Sstevel@tonic-gate int internal_attach_entity(entity_t *, entity_t *); 3120Sstevel@tonic-gate int internal_attach_pgroup(entity_t *, pgroup_t *); 3130Sstevel@tonic-gate int internal_attach_dependent(entity_t *, pgroup_t *); 3140Sstevel@tonic-gate int internal_attach_property(pgroup_t *, property_t *); 3150Sstevel@tonic-gate void internal_attach_value(property_t *, value_t *); 3160Sstevel@tonic-gate 3170Sstevel@tonic-gate int load_init(void); 3180Sstevel@tonic-gate void load_fini(void); 3190Sstevel@tonic-gate int load_pg_attrs(const scf_propertygroup_t *, pgroup_t **); 3200Sstevel@tonic-gate int load_pg(const scf_propertygroup_t *, pgroup_t **, const char *, 3210Sstevel@tonic-gate const char *); 3220Sstevel@tonic-gate int prop_equal(property_t *, property_t *, const char *, const char *, int); 323306Sbustos int pg_attrs_equal(const pgroup_t *, const pgroup_t *, const char *, int); 3240Sstevel@tonic-gate int pg_equal(pgroup_t *, pgroup_t *); 3250Sstevel@tonic-gate 3260Sstevel@tonic-gate void lscf_cleanup(void); 3270Sstevel@tonic-gate void lscf_prep_hndl(void); 3280Sstevel@tonic-gate void lscf_init(void); 3290Sstevel@tonic-gate int lscf_bundle_import(bundle_t *, const char *, uint_t); 3305777Stw21770 int lscf_bundle_apply(bundle_t *, const char *); 3310Sstevel@tonic-gate void lscf_delete(const char *, int); 3320Sstevel@tonic-gate void lscf_list(const char *); 3330Sstevel@tonic-gate void lscf_select(const char *); 3340Sstevel@tonic-gate void lscf_unselect(); 3350Sstevel@tonic-gate void lscf_get_selection_str(char *, size_t); 3360Sstevel@tonic-gate void lscf_add(const char *); 3370Sstevel@tonic-gate void lscf_listpg(const char *); 3380Sstevel@tonic-gate void lscf_addpg(const char *, const char *, const char *); 3390Sstevel@tonic-gate void lscf_delpg(char *); 3400Sstevel@tonic-gate void lscf_listprop(const char *); 3410Sstevel@tonic-gate void lscf_addprop(char *, const char *, const uu_list_t *); 3420Sstevel@tonic-gate void lscf_delprop(char *); 3430Sstevel@tonic-gate void lscf_listsnap(); 3440Sstevel@tonic-gate void lscf_selectsnap(const char *); 3450Sstevel@tonic-gate void lscf_revert(const char *); 346*5841Samaguire void lscf_refresh(); 3470Sstevel@tonic-gate char *filename_to_propname(const char *); 3480Sstevel@tonic-gate int lscf_retrieve_hash(const char *, unsigned char *); 3490Sstevel@tonic-gate int lscf_store_hash(const char *, unsigned char *); 3500Sstevel@tonic-gate CPL_MATCH_FN(complete_select); 3510Sstevel@tonic-gate CPL_MATCH_FN(complete_command); 3520Sstevel@tonic-gate 3530Sstevel@tonic-gate int lxml_init(void); 3545040Swesolows int lxml_get_bundle_file(bundle_t *, const char *, svccfg_op_t); 3550Sstevel@tonic-gate 3560Sstevel@tonic-gate void engine_init(void); 3570Sstevel@tonic-gate int engine_exec_cmd(void); 3580Sstevel@tonic-gate int engine_exec(char *); 3590Sstevel@tonic-gate int add_cmd_matches(WordCompletion *, const char *, int, uint32_t); 3600Sstevel@tonic-gate int engine_interp(void); 3610Sstevel@tonic-gate int engine_source(const char *, boolean_t); 3620Sstevel@tonic-gate int engine_import(uu_list_t *); 3630Sstevel@tonic-gate void help(int); 3640Sstevel@tonic-gate 3650Sstevel@tonic-gate int engine_cmd_getc(engine_state_t *); 3660Sstevel@tonic-gate int engine_cmd_ungetc(engine_state_t *, char); 3670Sstevel@tonic-gate void engine_cmd_nputs(engine_state_t *, char *, size_t); 3680Sstevel@tonic-gate 3690Sstevel@tonic-gate #ifdef __cplusplus 3700Sstevel@tonic-gate } 3710Sstevel@tonic-gate #endif 3720Sstevel@tonic-gate 3730Sstevel@tonic-gate #endif /* _CMD_SVCCFG_H */ 374