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 (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved. 24 */ 25 26 #ifndef _CMD_SVCCFG_H 27 #define _CMD_SVCCFG_H 28 29 30 #include <sys/types.h> 31 32 #include <libxml/tree.h> 33 34 #include <libscf.h> 35 #include <libscf_priv.h> 36 #include <libtecla.h> 37 #include <libuutil.h> 38 39 #ifdef __cplusplus 40 extern "C" { 41 #endif 42 43 /* Command scope bits for command tab completion */ 44 #define CS_SCOPE 0x01 45 #define CS_SVC 0x02 46 #define CS_INST 0x04 47 #define CS_SNAP 0x08 48 #define CS_GLOBAL 0x0f 49 50 /* Flags for lscf_bundle_import() & co. */ 51 #define SCI_NOREFRESH 0x01 /* Don't refresh instances */ 52 #define SCI_GENERALLAST 0x04 /* Add general property group last */ 53 #define SCI_NOENABLED 0x08 /* Don't import general/enabled. */ 54 #define SCI_FRESH 0x10 /* Freshly imported service */ 55 #define SCI_FORCE 0x20 /* Override-import. */ 56 #define SCI_KEEP 0x40 /* Don't delete when SCI_FORCEing */ 57 #define SCI_NOSNAP 0x80 /* Don't take last-import snapshot */ 58 #define SCI_DELAYENABLE 0x100 /* Delay the general/enable property */ 59 60 #define SCI_OP_IMPORT 0x1000 61 #define SCI_OP_APPLY 0x2000 62 #define SCI_OP_RESTORE 0x4000 63 64 #define HASH_SVC "smf/manifest" 65 66 /* 67 * If the filesystem/minimal service is not online, do not consider 68 * manifests in the /var file system. 69 */ 70 #define IGNORE_VAR (!est->sc_fs_minimal) 71 72 /* Flags for lscf_service_export() */ 73 #define SCE_ALL_VALUES 0x01 /* Include all property values */ 74 75 #ifdef lint 76 extern int yyerror(const char *); 77 extern int yyparse(void); 78 #endif /* lint */ 79 80 extern int lex_lineno; 81 82 #define MANIFEST_DTD_PATH "/usr/share/lib/xml/dtd/service_bundle.dtd.1" 83 /* 84 * The following list must be kept in the same order as that of 85 * lxml_prop_types[] 86 */ 87 typedef enum element { 88 SC_ASTRING = 0, 89 SC_BOOLEAN, 90 SC_CARDINALITY, 91 SC_CHOICES, 92 SC_COMMON_NAME, 93 SC_CONSTRAINTS, 94 SC_COUNT, 95 SC_INSTANCE_CREATE_DEFAULT, 96 SC_DEPENDENCY, 97 SC_DEPENDENT, 98 SC_DESCRIPTION, 99 SC_DOC_LINK, 100 SC_DOCUMENTATION, 101 SC_ENABLED, 102 SC_EVENT, 103 SC_EXEC_METHOD, 104 SC_FMRI, 105 SC_HOST, 106 SC_HOSTNAME, 107 SC_INCLUDE_VALUES, 108 SC_INSTANCE, 109 SC_INTEGER, 110 SC_INTERNAL_SEPARATORS, 111 SC_LOCTEXT, 112 SC_MANPAGE, 113 SC_METHOD_CONTEXT, 114 SC_METHOD_CREDENTIAL, 115 SC_METHOD_PROFILE, 116 SC_METHOD_ENVIRONMENT, 117 SC_METHOD_ENVVAR, 118 SC_NET_ADDR, 119 SC_NET_ADDR_V4, 120 SC_NET_ADDR_V6, 121 SC_NOTIFICATION_PARAMETERS, 122 SC_OPAQUE, 123 SC_PARAMETER, 124 SC_PARAMVAL, 125 SC_PG_PATTERN, 126 SC_PROP_PATTERN, 127 SC_PROPERTY, 128 SC_PROPERTY_GROUP, 129 SC_PROPVAL, 130 SC_RANGE, 131 SC_RESTARTER, 132 SC_SERVICE, 133 SC_SERVICE_BUNDLE, 134 SC_SERVICE_FMRI, 135 SC_INSTANCE_SINGLE, 136 SC_STABILITY, 137 SC_TEMPLATE, 138 SC_TIME, 139 SC_TYPE, 140 SC_UNITS, 141 SC_URI, 142 SC_USTRING, 143 SC_VALUE, 144 SC_VALUE_NODE, 145 SC_VALUES, 146 SC_VISIBILITY, 147 SC_XI_FALLBACK, 148 SC_XI_INCLUDE 149 } element_t; 150 151 typedef enum bundle_type { 152 SVCCFG_UNKNOWN_BUNDLE, SVCCFG_MANIFEST, SVCCFG_PROFILE, SVCCFG_ARCHIVE 153 } bundle_type_t; 154 155 typedef struct bundle { 156 uu_list_t *sc_bundle_services; 157 158 xmlChar *sc_bundle_name; 159 bundle_type_t sc_bundle_type; 160 } bundle_t; 161 162 typedef enum service_type { 163 SVCCFG_UNKNOWN_SERVICE = 0x0, SVCCFG_SERVICE, SVCCFG_RESTARTER, 164 SVCCFG_MILESTONE 165 } service_type_t; 166 167 typedef enum entity_type { 168 SVCCFG_SERVICE_OBJECT = 0x0, SVCCFG_INSTANCE_OBJECT 169 } entity_type_t; 170 171 enum import_state { 172 IMPORT_NONE = 0, 173 IMPORT_PREVIOUS, 174 IMPORT_PROP_BEGUN, 175 IMPORT_PROP_DONE, 176 IMPORT_COMPLETE, 177 IMPORT_REFRESHED 178 }; 179 180 typedef enum svccfg_op { 181 SVCCFG_OP_NONE = -1, 182 SVCCFG_OP_IMPORT = 0, 183 SVCCFG_OP_APPLY, 184 SVCCFG_OP_RESTORE 185 } svccfg_op_t; 186 187 /* 188 * Return values for functions that validate an entity against the templates. 189 */ 190 typedef enum tmpl_validate_status { 191 TVS_SUCCESS = 0, 192 /* 193 * Either conversion of ASTRING property value to a number failed, 194 * or base 32 decoding of a property value failed. 195 */ 196 TVS_BAD_CONVERSION, 197 /* Template is defective. */ 198 TVS_BAD_TEMPLATE, 199 /* Template type spec is invalid. */ 200 TVS_INVALID_TYPE_SPECIFICATION, 201 /* Property group is missing a type specification. */ 202 TVS_MISSING_PG_TYPE, 203 /* Template with required == true is missing type specification. */ 204 TVS_MISSING_TYPE_SPECIFICATION, 205 /* No match was found for specified item. */ 206 TVS_NOMATCH, 207 /* Validation error occurred */ 208 TVS_VALIDATION, 209 /* Validation error that should not inhibit import. */ 210 TVS_WARN, 211 /* Could not validate because of fatal errors. */ 212 TVS_FATAL = -1 213 } tmpl_validate_status_t; 214 215 /* 216 * The composed_pg structure is used for templates validation. It is 217 * defined in svccfg_tmpl.c 218 */ 219 typedef struct composed_pg composed_pg_t; 220 221 typedef struct entity { 222 uu_list_node_t sc_node; 223 entity_type_t sc_etype; 224 225 /* Common fields to all entities. */ 226 const char *sc_name; 227 const char *sc_fmri; 228 uu_list_t *sc_pgroups; 229 uu_list_t *sc_dependents; 230 struct entity *sc_parent; 231 enum import_state sc_import_state; 232 boolean_t sc_miss_type; 233 int sc_seen; 234 svccfg_op_t sc_op; 235 236 union { 237 struct { 238 uu_list_t *sc_service_instances; 239 service_type_t sc_service_type; 240 uint_t sc_service_version; 241 /* Following used by template validation */ 242 struct entity *sc_restarter; 243 struct entity *sc_global; 244 } sc_service; 245 struct { 246 uu_avl_t *sc_composed; 247 /* Following used by template validation */ 248 struct entity *sc_instance_restarter; 249 } sc_instance; 250 } sc_u; 251 } entity_t; 252 253 /* 254 * sc_pgroup_composed is only used for templates validation of properties. 255 * It is created in build_composed_property_groups() and destroyed in 256 * composed_pg_destroy(). It will only be set for property groups that are 257 * part of an instance -- not for service property groups. 258 */ 259 typedef struct pgroup { 260 uu_list_node_t sc_node; 261 uu_list_t *sc_pgroup_props; 262 composed_pg_t *sc_pgroup_composed; /* Composed properties */ 263 264 const char *sc_pgroup_name; 265 const char *sc_pgroup_type; 266 uint_t sc_pgroup_flags; 267 struct entity *sc_parent; 268 269 int sc_pgroup_delete; 270 int sc_pgroup_override; 271 const char *sc_pgroup_fmri; /* Used for dependents */ 272 273 int sc_pgroup_seen; 274 } pgroup_t; 275 276 typedef struct property { 277 uu_list_node_t sc_node; 278 uu_avl_node_t sc_composed_node; /* Composed props linkage */ 279 uu_list_t *sc_property_values; 280 281 char *sc_property_name; 282 scf_type_t sc_value_type; 283 284 int sc_property_override; 285 int sc_seen; 286 } property_t; 287 288 typedef struct value { 289 uu_list_node_t sc_node; 290 291 scf_type_t sc_type; 292 293 void (*sc_free)(struct value *); 294 295 union { 296 uint64_t sc_count; 297 int64_t sc_integer; 298 char *sc_string; 299 } sc_u; 300 } value_t; 301 302 typedef struct scf_callback { 303 scf_handle_t *sc_handle; 304 void *sc_parent; /* immediate parent: scope, service, */ 305 /* instance, property group, property */ 306 scf_transaction_t *sc_trans; 307 int sc_service; /* True if sc_parent is a service. */ 308 uint_t sc_flags; 309 pgroup_t *sc_general; /* pointer to general property group */ 310 property_t *sc_enable; /* pointer to enable property */ 311 312 const char *sc_source_fmri; 313 const char *sc_target_fmri; 314 int sc_err; 315 } scf_callback_t; 316 317 /* 318 * Collection of template validation errors. 319 */ 320 typedef struct tmpl_errors tmpl_errors_t; 321 322 #ifndef NDEBUG 323 #define bad_error(func, err) { \ 324 (void) fprintf(stderr, "%s:%d: %s() failed with unexpected " \ 325 "error %d. Aborting.\n", __FILE__, __LINE__, (func), (err)); \ 326 abort(); \ 327 } 328 #else 329 #define bad_error(func, err) abort() 330 #endif 331 332 #define SC_CMD_LINE 0x0 333 #define SC_CMD_FILE 0x1 334 #define SC_CMD_EOF 0x2 335 #define SC_CMD_IACTIVE 0x4 336 #define SC_CMD_DONT_EXIT 0x8 337 338 typedef struct engine_state { 339 uint_t sc_cmd_flags; 340 FILE *sc_cmd_file; 341 uint_t sc_cmd_lineno; 342 const char *sc_cmd_filename; 343 char *sc_cmd_buf; 344 size_t sc_cmd_bufsz; 345 off_t sc_cmd_bufoff; 346 GetLine *sc_gl; 347 boolean_t sc_fs_minimal; /* SCF_INSTANCE_FS_MINIMAL is online. */ 348 boolean_t sc_in_emi; /* During early import */ 349 boolean_t sc_miss_type; /* Apply profile found missing types */ 350 351 pid_t sc_repo_pid; 352 const char *sc_repo_filename; 353 const char *sc_repo_doordir; 354 const char *sc_repo_doorname; 355 const char *sc_repo_server; 356 } engine_state_t; 357 358 extern engine_state_t *est; 359 360 typedef struct string_list { 361 uu_list_node_t node; 362 char *str; 363 } string_list_t; 364 365 extern uu_list_pool_t *string_pool; 366 367 struct help_message { 368 int token; 369 const char *message; 370 }; 371 372 extern struct help_message help_messages[]; 373 374 extern scf_handle_t *g_hndl; /* global repcached connection handle */ 375 extern int g_exitcode; 376 extern int g_verbose; 377 378 extern ssize_t max_scf_fmri_len; 379 extern ssize_t max_scf_name_len; 380 extern ssize_t max_scf_value_len; 381 extern ssize_t max_scf_pg_type_len; 382 383 /* Common strings */ 384 extern const char * const name_attr; 385 extern const char * const type_attr; 386 extern const char * const value_attr; 387 extern const char * const enabled_attr; 388 extern const char * const active_attr; 389 extern const char * const scf_pg_general; 390 extern const char * const scf_group_framework; 391 extern const char * const true; 392 extern const char * const false; 393 394 #define uu_list_append(list, elem) uu_list_insert_before(list, NULL, elem) 395 #define uu_list_prepend(list, elem) uu_list_insert_after(list, NULL, elem) 396 397 void *safe_malloc(size_t); 398 char *safe_strdup(const char *); 399 void warn(const char *, ...); 400 void synerr(int); 401 void semerr(const char *, ...); 402 403 void internal_init(void); 404 void internal_dump(bundle_t *); 405 406 int value_cmp(const void *, const void *, void *); 407 408 bundle_t *internal_bundle_new(void); 409 void internal_bundle_free(bundle_t *); 410 entity_t *internal_service_new(const char *); 411 void internal_service_free(entity_t *); 412 entity_t *internal_instance_new(const char *); 413 void internal_instance_free(entity_t *); 414 entity_t *internal_template_new(void); 415 pgroup_t *internal_pgroup_new(void); 416 void internal_pgroup_free(pgroup_t *); 417 pgroup_t *internal_pgroup_find(entity_t *, const char *, const char *); 418 pgroup_t *internal_dependent_find(entity_t *, const char *); 419 pgroup_t *internal_pgroup_find_or_create(entity_t *, const char *, 420 const char *); 421 pgroup_t *internal_pgroup_create_strict(entity_t *, const char *, 422 const char *); 423 property_t *internal_property_new(void); 424 void internal_property_free(property_t *); 425 property_t *internal_property_find(pgroup_t *, const char *); 426 property_t *internal_property_create(const char *, scf_type_t, uint_t, ...); 427 value_t *internal_value_new(void); 428 429 int internal_attach_service(bundle_t *, entity_t *); 430 int internal_attach_entity(entity_t *, entity_t *); 431 int internal_attach_pgroup(entity_t *, pgroup_t *); 432 void internal_detach_pgroup(entity_t *, pgroup_t *); 433 int internal_attach_dependent(entity_t *, pgroup_t *); 434 int internal_attach_property(pgroup_t *, property_t *); 435 void internal_detach_property(pgroup_t *, property_t *); 436 void internal_attach_value(property_t *, value_t *); 437 438 int load_init(void); 439 void load_fini(void); 440 int load_instance(const char *, const char *, entity_t **); 441 int load_pg_attrs(const scf_propertygroup_t *, pgroup_t **); 442 int load_pg(const scf_propertygroup_t *, pgroup_t **, const char *, 443 const char *); 444 int prop_equal(property_t *, property_t *, const char *, const char *, int); 445 int pg_attrs_equal(const pgroup_t *, const pgroup_t *, const char *, int); 446 int pg_equal(pgroup_t *, pgroup_t *); 447 448 void lscf_cleanup(void); 449 void lscf_prep_hndl(void); 450 void lscf_init(void); 451 int lscf_bundle_import(bundle_t *, const char *, uint_t); 452 int lscf_bundle_apply(bundle_t *, const char *); 453 void lscf_delete(const char *, int); 454 void lscf_list(const char *); 455 void lscf_select(const char *); 456 void lscf_unselect(); 457 void lscf_get_selection_str(char *, size_t); 458 void lscf_add(const char *); 459 void lscf_listpg(const char *); 460 void lscf_addpg(const char *, const char *, const char *); 461 void lscf_delpg(char *); 462 void lscf_delhash(char *, int); 463 void lscf_listprop(const char *); 464 void lscf_addprop(char *, const char *, const uu_list_t *); 465 void lscf_delprop(char *); 466 int lscf_describe(uu_list_t *, int); 467 void lscf_listsnap(); 468 void lscf_selectsnap(const char *); 469 void lscf_revert(const char *); 470 void lscf_refresh(); 471 char *filename_to_propname(const char *); 472 int lscf_retrieve_hash(const char *, unsigned char *); 473 int lscf_store_hash(const char *, unsigned char *); 474 int lscf_service_cleanup(void *, scf_walkinfo_t *); 475 int lscf_hash_cleanup(); 476 void lscf_delnotify(const char *, int); 477 void lscf_listnotify(const char *, int); 478 int lscf_setnotify(uu_list_t *); 479 480 CPL_MATCH_FN(complete_select); 481 CPL_MATCH_FN(complete_command); 482 483 int lxml_init(void); 484 int lxml_get_bundle_file(bundle_t *, const char *, svccfg_op_t); 485 void lxml_store_value(value_t *, element_t, const xmlChar *); 486 487 void engine_init(void); 488 int engine_exec_cmd(void); 489 int engine_exec(char *); 490 int add_cmd_matches(WordCompletion *, const char *, int, uint32_t); 491 int engine_interp(void); 492 int engine_source(const char *, boolean_t); 493 int engine_import(uu_list_t *); 494 int engine_cleanup(int); 495 void help(int); 496 497 int engine_cmd_getc(engine_state_t *); 498 int engine_cmd_ungetc(engine_state_t *, char); 499 void engine_cmd_nputs(engine_state_t *, char *, size_t); 500 501 void tmpl_errors_destroy(tmpl_errors_t *); 502 void tmpl_errors_print(FILE *, tmpl_errors_t *, const char *); 503 void tmpl_init(void); 504 void tmpl_property_fini(property_t *); 505 void tmpl_property_init(property_t *); 506 tmpl_validate_status_t tmpl_validate_bundle(bundle_t *, tmpl_errors_t **); 507 508 #define FMA_TOKENS 0 509 #define MIXED_TOKENS -1 510 #define INVALID_TOKENS -2 511 512 char **tokenize(char *, const char *); 513 int32_t check_tokens(char **); 514 const char *de_tag(const char *); 515 const char *tset_to_string(int32_t); 516 517 #ifdef __cplusplus 518 } 519 #endif 520 521 #endif /* _CMD_SVCCFG_H */ 522