svccfg.h revision 5040:ff6ebd8761a6
1/* 2 * CDDL HEADER START 3 * 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. 7 * 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. 12 * 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] 18 * 19 * CDDL HEADER END 20 */ 21 22/* 23 * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27#ifndef _CMD_SVCCFG_H 28#define _CMD_SVCCFG_H 29 30#pragma ident "%Z%%M% %I% %E% SMI" 31 32#include <sys/types.h> 33 34#include <libxml/tree.h> 35 36#include <libscf.h> 37#include <libtecla.h> 38#include <libuutil.h> 39 40#ifdef __cplusplus 41extern "C" { 42#endif 43 44/* Command scope bits for command tab completion */ 45#define CS_SCOPE 0x01 46#define CS_SVC 0x02 47#define CS_INST 0x04 48#define CS_SNAP 0x08 49#define CS_GLOBAL 0x0f 50 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 60/* Flags for lscf_service_export() */ 61#define SCE_ALL_VALUES 0x01 /* Include all property values */ 62 63#ifdef lint 64extern int yyerror(const char *); 65extern int yyparse(void); 66#endif /* lint */ 67 68extern int lex_lineno; 69 70#define MANIFEST_DTD_PATH "/usr/share/lib/xml/dtd/service_bundle.dtd.1" 71/* 72 * The following list must be kept in the same order as that of 73 * lxml_prop_types[] 74 */ 75typedef enum element { 76 SC_ASTRING = 0x0, SC_BOOLEAN, SC_COMMON_NAME, SC_COUNT, 77 SC_INSTANCE_CREATE_DEFAULT, SC_DEPENDENCY, SC_DEPENDENT, SC_DESCRIPTION, 78 SC_DOC_LINK, SC_DOCUMENTATION, SC_ENABLED, SC_EXEC_METHOD, SC_FMRI, 79 SC_HOST, SC_HOSTNAME, SC_INSTANCE, SC_INTEGER, SC_LOCTEXT, SC_MANPAGE, 80 SC_METHOD_CONTEXT, SC_METHOD_CREDENTIAL, SC_METHOD_PROFILE, 81 SC_METHOD_ENVIRONMENT, SC_METHOD_ENVVAR, SC_NET_ADDR_V4, SC_NET_ADDR_V6, 82 SC_OPAQUE, SC_PROPERTY, SC_PROPERTY_GROUP, SC_PROPVAL, SC_RESTARTER, 83 SC_SERVICE, SC_SERVICE_BUNDLE, SC_SERVICE_FMRI, SC_INSTANCE_SINGLE, 84 SC_STABILITY, SC_TEMPLATE, SC_TIME, SC_URI, SC_USTRING, SC_VALUE_NODE, 85 SC_XI_FALLBACK, SC_XI_INCLUDE 86} element_t; 87 88typedef enum bundle_type { 89 SVCCFG_UNKNOWN_BUNDLE, SVCCFG_MANIFEST, SVCCFG_PROFILE, SVCCFG_ARCHIVE 90} bundle_type_t; 91 92typedef struct bundle { 93 uu_list_t *sc_bundle_services; 94 95 xmlChar *sc_bundle_name; 96 bundle_type_t sc_bundle_type; 97} bundle_t; 98 99typedef enum service_type { 100 SVCCFG_UNKNOWN_SERVICE = 0x0, SVCCFG_SERVICE, SVCCFG_RESTARTER, 101 SVCCFG_MILESTONE 102} service_type_t; 103 104typedef enum entity_type { 105 SVCCFG_SERVICE_OBJECT = 0x0, SVCCFG_INSTANCE_OBJECT, 106 SVCCFG_TEMPLATE_OBJECT 107} entity_type_t; 108 109enum import_state { 110 IMPORT_NONE = 0, 111 IMPORT_PREVIOUS, 112 IMPORT_PROP_BEGUN, 113 IMPORT_PROP_DONE, 114 IMPORT_COMPLETE, 115 IMPORT_REFRESHED 116}; 117 118typedef enum svccfg_op { 119 SVCCFG_OP_IMPORT = 0, 120 SVCCFG_OP_APPLY, 121 SVCCFG_OP_RESTORE 122} svccfg_op_t; 123 124typedef struct entity { 125 uu_list_node_t sc_node; 126 entity_type_t sc_etype; 127 128 /* Common fields to all entities. */ 129 const char *sc_name; 130 const char *sc_fmri; 131 uu_list_t *sc_pgroups; 132 uu_list_t *sc_dependents; 133 struct entity *sc_parent; 134 enum import_state sc_import_state; 135 int sc_seen; 136 137 union { 138 struct { 139 uu_list_t *sc_service_instances; 140 service_type_t sc_service_type; 141 uint_t sc_service_version; 142 143 struct entity *sc_service_template; 144 } sc_service; 145 struct { 146 uint_t sc_instance_dummy; 147 } sc_instance; 148 struct { 149 uint_t sc_template_dummy; 150 } sc_template; 151 } sc_u; 152} entity_t; 153 154typedef struct pgroup { 155 uu_list_node_t sc_node; 156 uu_list_t *sc_pgroup_props; 157 158 const char *sc_pgroup_name; 159 const char *sc_pgroup_type; 160 uint_t sc_pgroup_flags; 161 struct entity *sc_parent; 162 163 int sc_pgroup_delete; 164 int sc_pgroup_override; 165 const char *sc_pgroup_fmri; /* Used for dependents */ 166 167 int sc_pgroup_seen; 168} pgroup_t; 169 170typedef struct property { 171 uu_list_node_t sc_node; 172 uu_list_t *sc_property_values; 173 174 char *sc_property_name; 175 scf_type_t sc_value_type; 176 177 int sc_property_override; 178 int sc_seen; 179} property_t; 180 181typedef struct value { 182 uu_list_node_t sc_node; 183 184 scf_type_t sc_type; 185 186 void (*sc_free)(struct value *); 187 188 union { 189 uint64_t sc_count; 190 int64_t sc_integer; 191 char *sc_string; 192 } sc_u; 193} value_t; 194 195typedef struct scf_callback { 196 scf_handle_t *sc_handle; 197 void *sc_parent; /* immediate parent: scope, service, */ 198 /* instance, property group, property */ 199 scf_transaction_t *sc_trans; 200 int sc_service; /* True if sc_parent is a service. */ 201 uint_t sc_flags; 202 pgroup_t *sc_general; /* pointer to general property group */ 203 204 const char *sc_source_fmri; 205 const char *sc_target_fmri; 206 int sc_err; 207} scf_callback_t; 208 209#ifndef NDEBUG 210#define bad_error(func, err) { \ 211 (void) fprintf(stderr, "%s:%d: %s() failed with unexpected " \ 212 "error %d. Aborting.\n", __FILE__, __LINE__, (func), (err)); \ 213 abort(); \ 214} 215#else 216#define bad_error(func, err) abort() 217#endif 218 219#define SC_CMD_LINE 0x0 220#define SC_CMD_FILE 0x1 221#define SC_CMD_EOF 0x2 222#define SC_CMD_IACTIVE 0x4 223#define SC_CMD_DONT_EXIT 0x8 224 225typedef struct engine_state { 226 uint_t sc_cmd_flags; 227 FILE *sc_cmd_file; 228 uint_t sc_cmd_lineno; 229 const char *sc_cmd_filename; 230 char *sc_cmd_buf; 231 size_t sc_cmd_bufsz; 232 off_t sc_cmd_bufoff; 233 GetLine *sc_gl; 234 235 pid_t sc_repo_pid; 236 const char *sc_repo_filename; 237 const char *sc_repo_doordir; 238 const char *sc_repo_doorname; 239 const char *sc_repo_server; 240} engine_state_t; 241 242extern engine_state_t *est; 243 244typedef struct string_list { 245 uu_list_node_t node; 246 char *str; 247} string_list_t; 248 249extern uu_list_pool_t *string_pool; 250 251struct help_message { 252 int token; 253 const char *message; 254}; 255 256extern struct help_message help_messages[]; 257 258extern scf_handle_t *g_hndl; /* global repcached connection handle */ 259extern int g_exitcode; 260extern int g_verbose; 261 262extern ssize_t max_scf_fmri_len; 263extern ssize_t max_scf_name_len; 264extern ssize_t max_scf_value_len; 265extern ssize_t max_scf_pg_type_len; 266 267/* Common strings */ 268extern const char * const name_attr; 269extern const char * const type_attr; 270extern const char * const value_attr; 271extern const char * const enabled_attr; 272extern const char * const scf_pg_general; 273extern const char * const scf_group_framework; 274extern const char * const true; 275extern const char * const false; 276 277#define uu_list_append(list, elem) uu_list_insert_before(list, NULL, elem) 278#define uu_list_prepend(list, elem) uu_list_insert_after(list, NULL, elem) 279 280void *safe_malloc(size_t); 281char *safe_strdup(const char *); 282void warn(const char *, ...); 283void synerr(int); 284void semerr(const char *, ...); 285 286void internal_init(void); 287void internal_dump(bundle_t *); 288 289int value_cmp(const void *, const void *, void *); 290 291bundle_t *internal_bundle_new(void); 292void internal_bundle_free(bundle_t *); 293entity_t *internal_service_new(const char *); 294void internal_service_free(entity_t *); 295entity_t *internal_instance_new(const char *); 296void internal_instance_free(entity_t *); 297entity_t *internal_template_new(void); 298pgroup_t *internal_pgroup_new(void); 299void internal_pgroup_free(pgroup_t *); 300pgroup_t *internal_pgroup_find(entity_t *, const char *, const char *); 301pgroup_t *internal_dependent_find(entity_t *, const char *); 302pgroup_t *internal_pgroup_find_or_create(entity_t *, const char *, 303 const char *); 304property_t *internal_property_new(void); 305void internal_property_free(property_t *); 306property_t *internal_property_find(pgroup_t *, const char *); 307property_t *internal_property_create(const char *, scf_type_t, uint_t, ...); 308value_t *internal_value_new(void); 309 310int internal_attach_service(bundle_t *, entity_t *); 311int internal_attach_entity(entity_t *, entity_t *); 312int internal_attach_pgroup(entity_t *, pgroup_t *); 313int internal_attach_dependent(entity_t *, pgroup_t *); 314int internal_attach_property(pgroup_t *, property_t *); 315void internal_attach_value(property_t *, value_t *); 316 317int load_init(void); 318void load_fini(void); 319int load_pg_attrs(const scf_propertygroup_t *, pgroup_t **); 320int load_pg(const scf_propertygroup_t *, pgroup_t **, const char *, 321 const char *); 322int prop_equal(property_t *, property_t *, const char *, const char *, int); 323int pg_attrs_equal(const pgroup_t *, const pgroup_t *, const char *, int); 324int pg_equal(pgroup_t *, pgroup_t *); 325 326void lscf_cleanup(void); 327void lscf_prep_hndl(void); 328void lscf_init(void); 329int lscf_bundle_import(bundle_t *, const char *, uint_t); 330int lscf_bundle_apply(bundle_t *); 331void lscf_delete(const char *, int); 332void lscf_list(const char *); 333void lscf_select(const char *); 334void lscf_unselect(); 335void lscf_get_selection_str(char *, size_t); 336void lscf_add(const char *); 337void lscf_listpg(const char *); 338void lscf_addpg(const char *, const char *, const char *); 339void lscf_delpg(char *); 340void lscf_listprop(const char *); 341void lscf_addprop(char *, const char *, const uu_list_t *); 342void lscf_delprop(char *); 343void lscf_listsnap(); 344void lscf_selectsnap(const char *); 345void lscf_revert(const char *); 346char *filename_to_propname(const char *); 347int lscf_retrieve_hash(const char *, unsigned char *); 348int lscf_store_hash(const char *, unsigned char *); 349CPL_MATCH_FN(complete_select); 350CPL_MATCH_FN(complete_command); 351 352int lxml_init(void); 353int lxml_get_bundle_file(bundle_t *, const char *, svccfg_op_t); 354 355void engine_init(void); 356int engine_exec_cmd(void); 357int engine_exec(char *); 358int add_cmd_matches(WordCompletion *, const char *, int, uint32_t); 359int engine_interp(void); 360int engine_source(const char *, boolean_t); 361int engine_import(uu_list_t *); 362void help(int); 363 364int engine_cmd_getc(engine_state_t *); 365int engine_cmd_ungetc(engine_state_t *, char); 366void engine_cmd_nputs(engine_state_t *, char *, size_t); 367 368#ifdef __cplusplus 369} 370#endif 371 372#endif /* _CMD_SVCCFG_H */ 373