17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5103b2b15Sgww * Common Development and Distribution License (the "License"). 6103b2b15Sgww * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 22b56bf881SAntonello Cruz * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved. 23*6c7c876cSJerry Jelinek * Copyright 2013, Joyent, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate #ifndef _LIBSCF_PRIV_H 277c478bd9Sstevel@tonic-gate #define _LIBSCF_PRIV_H 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate 307c478bd9Sstevel@tonic-gate #include <libscf.h> 317c478bd9Sstevel@tonic-gate #include <unistd.h> 327c478bd9Sstevel@tonic-gate 337c478bd9Sstevel@tonic-gate #ifdef __cplusplus 347c478bd9Sstevel@tonic-gate extern "C" { 357c478bd9Sstevel@tonic-gate #endif 367c478bd9Sstevel@tonic-gate 377c478bd9Sstevel@tonic-gate /* 387c478bd9Sstevel@tonic-gate * NOTE 397c478bd9Sstevel@tonic-gate * 407c478bd9Sstevel@tonic-gate * The contents of this file are private to the implementation of Solaris 417c478bd9Sstevel@tonic-gate * and are subject to change at any time without notice. 427c478bd9Sstevel@tonic-gate */ 437c478bd9Sstevel@tonic-gate 447c478bd9Sstevel@tonic-gate #define SCF_PG_GENERAL_TYPE SCF_GROUP_FRAMEWORK 457c478bd9Sstevel@tonic-gate #define SCF_PG_GENERAL_FLAGS 0 467c478bd9Sstevel@tonic-gate 477c478bd9Sstevel@tonic-gate #define SCF_PG_GENERAL_OVR_TYPE SCF_GROUP_FRAMEWORK 487c478bd9Sstevel@tonic-gate #define SCF_PG_GENERAL_OVR_FLAGS SCF_PG_FLAG_NONPERSISTENT 497c478bd9Sstevel@tonic-gate 5070cbfe41SPhilippe Jung #define SCF_PG_DEATHROW_TYPE SCF_GROUP_FRAMEWORK 5170cbfe41SPhilippe Jung #define SCF_PG_DEATHROW_FLAGS SCF_PG_FLAG_NONPERSISTENT 5270cbfe41SPhilippe Jung 537c478bd9Sstevel@tonic-gate #define SCF_PG_OPTIONS_TYPE SCF_GROUP_FRAMEWORK 547c478bd9Sstevel@tonic-gate #define SCF_PG_OPTIONS_FLAGS 0 557c478bd9Sstevel@tonic-gate 567c478bd9Sstevel@tonic-gate #define SCF_PG_OPTIONS_OVR_TYPE SCF_GROUP_FRAMEWORK 577c478bd9Sstevel@tonic-gate #define SCF_PG_OPTIONS_OVR_FLAGS SCF_PG_FLAG_NONPERSISTENT 587c478bd9Sstevel@tonic-gate 597c478bd9Sstevel@tonic-gate #define SCF_PG_RESTARTER_TYPE SCF_GROUP_FRAMEWORK 607c478bd9Sstevel@tonic-gate #define SCF_PG_RESTARTER_FLAGS SCF_PG_FLAG_NONPERSISTENT 617c478bd9Sstevel@tonic-gate 627c478bd9Sstevel@tonic-gate #define SCF_PG_RESTARTER_ACTIONS_TYPE SCF_GROUP_FRAMEWORK 637c478bd9Sstevel@tonic-gate #define SCF_PG_RESTARTER_ACTIONS_FLAGS SCF_PG_FLAG_NONPERSISTENT 647c478bd9Sstevel@tonic-gate 655b7f77adStw21770 #define SCF_PROPERTY_CLEAR ((const char *)"maint_off") 665b7f77adStw21770 #define SCF_PROPERTY_MAINTENANCE ((const char *)"maint_on") 675b7f77adStw21770 687c478bd9Sstevel@tonic-gate #define SCF_PROPERTY_LOGFILE ((const char *)"logfile") 697c478bd9Sstevel@tonic-gate #define SCF_PROPERTY_ALT_LOGFILE ((const char *)"alt_logfile") 707c478bd9Sstevel@tonic-gate 717c478bd9Sstevel@tonic-gate #define SCF_LEGACY_SERVICE ((const char *)"smf/legacy_run") 727c478bd9Sstevel@tonic-gate 737c478bd9Sstevel@tonic-gate #define SCF_LEGACY_PROPERTY_NAME ((const char *)"name") 747c478bd9Sstevel@tonic-gate #define SCF_LEGACY_PROPERTY_INODE ((const char *)"inode") 757c478bd9Sstevel@tonic-gate #define SCF_LEGACY_PROPERTY_SUFFIX ((const char *)"suffix") 767c478bd9Sstevel@tonic-gate 777c478bd9Sstevel@tonic-gate #define SCF_FMRI_TYPE_SVC 0x1 787c478bd9Sstevel@tonic-gate #define SCF_FMRI_TYPE_FILE 0x2 797c478bd9Sstevel@tonic-gate 805b7f77adStw21770 /* 815b7f77adStw21770 * Strings for use in constructing FMRIs 825b7f77adStw21770 */ 835b7f77adStw21770 #define SCF_FMRI_SVC_PREFIX "svc:" 845b7f77adStw21770 #define SCF_FMRI_FILE_PREFIX "file:" 855b7f77adStw21770 #define SCF_FMRI_SCOPE_PREFIX "//" 865b7f77adStw21770 #define SCF_FMRI_LOCAL_SCOPE "localhost" 875b7f77adStw21770 #define SCF_FMRI_SCOPE_SUFFIX "@localhost" 885b7f77adStw21770 #define SCF_FMRI_SERVICE_PREFIX "/" 895b7f77adStw21770 #define SCF_FMRI_INSTANCE_PREFIX ":" 905b7f77adStw21770 #define SCF_FMRI_PROPERTYGRP_PREFIX "/:properties/" 915b7f77adStw21770 #define SCF_FMRI_PROPERTY_PREFIX "/" 927b209c2cSacruz #define SCF_FMRI_LEGACY_PREFIX "lrc:" 937b209c2cSacruz 947b209c2cSacruz /* 957b209c2cSacruz * sulogin Service FMRI 967b209c2cSacruz */ 977b209c2cSacruz #define SVC_SULOGIN_FMRI ((const char *)"svc:/system/sulogin") 985b7f77adStw21770 997c478bd9Sstevel@tonic-gate typedef struct scf_decoration_info { 1007c478bd9Sstevel@tonic-gate const char *sdi_name; 1017c478bd9Sstevel@tonic-gate scf_type_t sdi_type; 1027c478bd9Sstevel@tonic-gate scf_value_t *sdi_value; /* can be SCF_DECORATE_CLEAR */ 1037c478bd9Sstevel@tonic-gate } scf_decoration_info_t; 1047c478bd9Sstevel@tonic-gate 1057c478bd9Sstevel@tonic-gate typedef int (*scf_decoration_func)(const scf_decoration_info_t *, void *); 1067c478bd9Sstevel@tonic-gate 1077c478bd9Sstevel@tonic-gate /* 1087c478bd9Sstevel@tonic-gate * calls a callback function for each decoration on the handle. If the 1097c478bd9Sstevel@tonic-gate * callback returns 0, the iteration stops and returns 0. If the callback 1107c478bd9Sstevel@tonic-gate * returns a non-zero value, the iteration continues. After full completion, 1117c478bd9Sstevel@tonic-gate * 1 is returned. On error, -1 is returned. 1127c478bd9Sstevel@tonic-gate */ 1137c478bd9Sstevel@tonic-gate int _scf_handle_decorations(scf_handle_t *, scf_decoration_func *, 1147c478bd9Sstevel@tonic-gate scf_value_t *, void *); 1157c478bd9Sstevel@tonic-gate 1167c478bd9Sstevel@tonic-gate /* 1177c478bd9Sstevel@tonic-gate * wait for a change to the propertygroup -- may return early. 1187c478bd9Sstevel@tonic-gate * For now, only one of these can be outstanding at a time. 1197c478bd9Sstevel@tonic-gate * 1207c478bd9Sstevel@tonic-gate * The second argument is how long, in seconds, to wait for a response. 1217c478bd9Sstevel@tonic-gate * 1227c478bd9Sstevel@tonic-gate * Returns SCF_COMPLETE on timeout, -1 on error, and SCF_SUCCESS in every 1237c478bd9Sstevel@tonic-gate * other case. You must call scf_pg_update() to see if the object has 1247c478bd9Sstevel@tonic-gate * actually changed. 1257c478bd9Sstevel@tonic-gate */ 1267c478bd9Sstevel@tonic-gate int _scf_pg_wait(scf_propertygroup_t *, int); 1277c478bd9Sstevel@tonic-gate 1287c478bd9Sstevel@tonic-gate /* 1297c478bd9Sstevel@tonic-gate * set up notifications for changes to a class of property groups (by name 1307c478bd9Sstevel@tonic-gate * and type) 1317c478bd9Sstevel@tonic-gate * 1327c478bd9Sstevel@tonic-gate * Only one thread can be sleeping in _scf_notify_wait() -- others will 1337c478bd9Sstevel@tonic-gate * fail. Deletions give an fmri in the output path. 1347c478bd9Sstevel@tonic-gate * 1357c478bd9Sstevel@tonic-gate * These do not survive unbind()->bind() -- in fact, that is currently the 1367c478bd9Sstevel@tonic-gate * only way to clear them. 1377c478bd9Sstevel@tonic-gate */ 1387c478bd9Sstevel@tonic-gate int _scf_notify_add_pgname(scf_handle_t *, const char *); 1397c478bd9Sstevel@tonic-gate int _scf_notify_add_pgtype(scf_handle_t *, const char *); 1407c478bd9Sstevel@tonic-gate int _scf_notify_wait(scf_propertygroup_t *, char *, size_t); 1417c478bd9Sstevel@tonic-gate 1427c478bd9Sstevel@tonic-gate /* 1437c478bd9Sstevel@tonic-gate * Internal interfaces for snapshot creation: 1447c478bd9Sstevel@tonic-gate * _scf_snapshot_take_new(), _scf_snapshot_take_new_named(), and 1457c478bd9Sstevel@tonic-gate * _scf_snapshot_take_attach() create a set of snaplevels 1467c478bd9Sstevel@tonic-gate * containing frozen versions of both the instance's property groups and 1477c478bd9Sstevel@tonic-gate * its parent service's property groups. _scf_snapshot_take_new() and 1487c478bd9Sstevel@tonic-gate * _scf_snapshot_take_new_named() create a new snapshot to which the 1497c478bd9Sstevel@tonic-gate * new snaplevels are attached, while _scf_snapshot_take_attach() 1507c478bd9Sstevel@tonic-gate * attaches the new snaplevels to a pre-existing snapshot. 1517c478bd9Sstevel@tonic-gate * 1527c478bd9Sstevel@tonic-gate * _scf_snapshot_take_new_named() records the passed in names into the 1537c478bd9Sstevel@tonic-gate * snaplevel instead of the instance and service name. This creates 1547c478bd9Sstevel@tonic-gate * an inconsistency, which should be resolved by using 1557c478bd9Sstevel@tonic-gate * _scf_snapshot_attach() to attach the new snaplevels to a snapshot 1567c478bd9Sstevel@tonic-gate * underneath the appropriate instance. The first snapshot can 1577c478bd9Sstevel@tonic-gate * then be deleted. 1587c478bd9Sstevel@tonic-gate * 1597c478bd9Sstevel@tonic-gate * _scf_snapshot_attach(snap1, snap2) points snap2 at the snaplevels 1607c478bd9Sstevel@tonic-gate * pointed to by snap1. After a call to either 1617c478bd9Sstevel@tonic-gate * _scf_snapshot_take_attach(snap1, snap2) or 1627c478bd9Sstevel@tonic-gate * _scf_snapshot_attach(inst, snap), scf_snapshot_update() will be 1637c478bd9Sstevel@tonic-gate * required for any open references to snap or snap2 to see the new 1647c478bd9Sstevel@tonic-gate * snaplevels. 1657c478bd9Sstevel@tonic-gate * 1667c478bd9Sstevel@tonic-gate * _scf_snapshot_delete() deletes the snapshot object. While 1677c478bd9Sstevel@tonic-gate * snaplevels, being only loosely connected to snapshots, stay 1687c478bd9Sstevel@tonic-gate * around until they are no longer referenced, any references *through 1697c478bd9Sstevel@tonic-gate * this snapshot object* will be invalidated. 1707c478bd9Sstevel@tonic-gate * 1717c478bd9Sstevel@tonic-gate * _scf_snapshot_take_new() can fail with at least _HANDLE_MISMATCH, 1727c478bd9Sstevel@tonic-gate * _CONNECTION_BROKEN, _INVALID_ARGUMENT, _NO_RESOURCES, _PERMISSION_DENIED, 1737c478bd9Sstevel@tonic-gate * _NOT_SET, _EXISTS. 1747c478bd9Sstevel@tonic-gate * 1757c478bd9Sstevel@tonic-gate * _scf_snapshot_take_new_named() can fail with at least _HANDLE_MISMATCH, 1767c478bd9Sstevel@tonic-gate * _CONNECTION_BROKEN, _INVALID_ARGUMENT, _NO_RESOURCES, _PERMISSION_DENIED, 1777c478bd9Sstevel@tonic-gate * _NOT_SET, _EXISTS. 1787c478bd9Sstevel@tonic-gate * 1797c478bd9Sstevel@tonic-gate * _scf_snapshot_take_attach() can fail with _CONNECTION_BROKEN, _NOT_SET, 1807c478bd9Sstevel@tonic-gate * _PERMISSION_DENIED, _NO_RESOURCES, _INVALID_ARGUMENT. 1817c478bd9Sstevel@tonic-gate * 1827c478bd9Sstevel@tonic-gate * _scf_snapshot_attach() can fail with _HANDLE_MISMATCH, _CONNECTION_BROKEN, 1837c478bd9Sstevel@tonic-gate * _NOT_SET, _NO_RESOURCES, _PERMISSION_DENIED. 1847c478bd9Sstevel@tonic-gate */ 1857c478bd9Sstevel@tonic-gate int _scf_snapshot_take_new(scf_instance_t *, const char *, scf_snapshot_t *); 1867c478bd9Sstevel@tonic-gate int _scf_snapshot_take_new_named(scf_instance_t *, 1877c478bd9Sstevel@tonic-gate const char *, const char *, const char *, scf_snapshot_t *); 1887c478bd9Sstevel@tonic-gate int _scf_snapshot_take_attach(scf_instance_t *, scf_snapshot_t *); 1897c478bd9Sstevel@tonic-gate int _scf_snapshot_attach(scf_snapshot_t *, scf_snapshot_t *); 1907c478bd9Sstevel@tonic-gate int _scf_snapshot_delete(scf_snapshot_t *); 1917c478bd9Sstevel@tonic-gate 1927c478bd9Sstevel@tonic-gate /* 1937c478bd9Sstevel@tonic-gate * Destructively portions up the first argument into the different portions 1947c478bd9Sstevel@tonic-gate * of a svc: fmri, and returns pointers to the applicable portions. Omitted 1957c478bd9Sstevel@tonic-gate * portions are set to NULL, except for the scope, which is set to the 1967c478bd9Sstevel@tonic-gate * default local scope if not specified. 1977c478bd9Sstevel@tonic-gate * 1987c478bd9Sstevel@tonic-gate * Parsing is attempted in the order of: svc:, file:. The identified type 1997c478bd9Sstevel@tonic-gate * of the service is returned in the second argument and may take a value 2007c478bd9Sstevel@tonic-gate * of: SCF_FMRI_TYPE_SVC or SCF_FMRI_TYPE_FILE. 2017c478bd9Sstevel@tonic-gate * 2027c478bd9Sstevel@tonic-gate * Note that some of the returned pointers (in particular the scope) may not 2037c478bd9Sstevel@tonic-gate * point into the passed buffer. 2047c478bd9Sstevel@tonic-gate */ 2057c478bd9Sstevel@tonic-gate int scf_parse_fmri(char *, int *, const char **, const char **, const char **, 2067c478bd9Sstevel@tonic-gate const char **, const char **); 2077c478bd9Sstevel@tonic-gate 2087c478bd9Sstevel@tonic-gate int scf_parse_svc_fmri(char *, const char **, const char **, const char **, 2097c478bd9Sstevel@tonic-gate const char **, const char **); 2107c478bd9Sstevel@tonic-gate 2117c478bd9Sstevel@tonic-gate int scf_parse_file_fmri(char *fmri, const char **scope, const char **path); 2127c478bd9Sstevel@tonic-gate 2137c478bd9Sstevel@tonic-gate ssize_t scf_canonify_fmri(const char *, char *, size_t); 2147c478bd9Sstevel@tonic-gate 2157c478bd9Sstevel@tonic-gate int _smf_refresh_instance_i(scf_instance_t *); 2167c478bd9Sstevel@tonic-gate 217d75e6a5dStn143363 typedef struct scf_simple_handle { 218d75e6a5dStn143363 scf_handle_t *h; 219d75e6a5dStn143363 scf_snapshot_t *snap; 220d75e6a5dStn143363 scf_instance_t *inst; 221d75e6a5dStn143363 scf_propertygroup_t *running_pg; 222d75e6a5dStn143363 scf_propertygroup_t *editing_pg; 223d75e6a5dStn143363 } scf_simple_handle_t; 224d75e6a5dStn143363 225d75e6a5dStn143363 void scf_simple_handle_destroy(scf_simple_handle_t *); 226d75e6a5dStn143363 scf_simple_handle_t *scf_general_pg_setup(const char *, const char *); 227d75e6a5dStn143363 scf_transaction_t *scf_transaction_setup(scf_simple_handle_t *); 228d75e6a5dStn143363 int scf_transaction_restart(scf_simple_handle_t *, scf_transaction_t *); 229d75e6a5dStn143363 int scf_read_count_property(scf_simple_handle_t *, char *, uint64_t *); 230d75e6a5dStn143363 int scf_set_count_property(scf_transaction_t *, char *, uint64_t, boolean_t); 231d75e6a5dStn143363 2327c478bd9Sstevel@tonic-gate /* 2337c478bd9Sstevel@tonic-gate * Walks all the instances matching a given fmri list. Each fmri in the array 2347c478bd9Sstevel@tonic-gate * can be one of the following: 2357c478bd9Sstevel@tonic-gate * 2367c478bd9Sstevel@tonic-gate * - Full instance name 2377c478bd9Sstevel@tonic-gate * - Full service name 2387c478bd9Sstevel@tonic-gate * - Full property group or property name 2397c478bd9Sstevel@tonic-gate * - Partial service or instance name 2407c478bd9Sstevel@tonic-gate * - A globbed pattern 2417c478bd9Sstevel@tonic-gate * 2427c478bd9Sstevel@tonic-gate * The matching rules for partial fmris are a slightly more complex. We allow 2437c478bd9Sstevel@tonic-gate * for any substring anchored at the end of the instance or service name, 2447c478bd9Sstevel@tonic-gate * provided it begins with a complete element in the fmri. For example, given 2457c478bd9Sstevel@tonic-gate * the fmri "svc:/system/filesystem/local:default", any of the following would 2467c478bd9Sstevel@tonic-gate * be acceptable matches: 'default', 'local', 'local:default', 2477c478bd9Sstevel@tonic-gate * 'filesystem/local'. The following would not be acceptable: 2487c478bd9Sstevel@tonic-gate * 'system/filesystem', 'filesystem/loc', 'system/local'. Possible flag values: 2497c478bd9Sstevel@tonic-gate * 2507c478bd9Sstevel@tonic-gate * SCF_WALK_MULTIPLE Allow individual arguments to correspond to 2517c478bd9Sstevel@tonic-gate * multiple instances. 2527c478bd9Sstevel@tonic-gate * 2537c478bd9Sstevel@tonic-gate * SCF_WALK_LEGACY Walk legacy services (indicated by a non-NULL 2547c478bd9Sstevel@tonic-gate * propery group). 2557c478bd9Sstevel@tonic-gate * 2567c478bd9Sstevel@tonic-gate * SCF_WALK_SERVICE If the user specifies a service, pass the 2577c478bd9Sstevel@tonic-gate * service to the callback without iterating over 2587c478bd9Sstevel@tonic-gate * its instances. 2597c478bd9Sstevel@tonic-gate * 2607c478bd9Sstevel@tonic-gate * SCF_WALK_PROPERTY Allow FMRIs which match property groups or 2617c478bd9Sstevel@tonic-gate * individual properties. Incompatible with 2627c478bd9Sstevel@tonic-gate * SCF_WALK_LEGACY. 2637c478bd9Sstevel@tonic-gate * 2647c478bd9Sstevel@tonic-gate * SCF_WALK_NOINSTANCE Walk only services. Must be used in 2657c478bd9Sstevel@tonic-gate * conjunction with SCF_WALK_SERVICE. 2667c478bd9Sstevel@tonic-gate * 2677c478bd9Sstevel@tonic-gate * SCF_WALK_EXPLICIT Walk only services if the match is exact 2687c478bd9Sstevel@tonic-gate * else return instances. Must be used in 2697c478bd9Sstevel@tonic-gate * conjunction with SCF_WALK_SERVICE. 2707c478bd9Sstevel@tonic-gate * 271*6c7c876cSJerry Jelinek * SCF_WALK_UNIPARTIAL Can be combined with SCF_WALK_MULTIPLE 272*6c7c876cSJerry Jelinek * so that an error is returned if a partial 273*6c7c876cSJerry Jelinek * fmri matches multiple instances, unless 274*6c7c876cSJerry Jelinek * a wildcard match is also used. 275*6c7c876cSJerry Jelinek * 2767c478bd9Sstevel@tonic-gate * If no arguments are given, then all instances in the service graph are 2777c478bd9Sstevel@tonic-gate * walked. 2787c478bd9Sstevel@tonic-gate * 2797c478bd9Sstevel@tonic-gate * The second to last parameter is set to UU_EXIT_FATAL if one of the arguments 2807c478bd9Sstevel@tonic-gate * is an invalid FMRI or matches multiple FMRIs when SCF_WALK_MULTIPLE is not 2817c478bd9Sstevel@tonic-gate * set. 2827c478bd9Sstevel@tonic-gate * 2837c478bd9Sstevel@tonic-gate * The last parameter is a user-supplied error function that is called when 2847c478bd9Sstevel@tonic-gate * reporting invalid arguments. 2857c478bd9Sstevel@tonic-gate */ 2867c478bd9Sstevel@tonic-gate 2877c478bd9Sstevel@tonic-gate #define SCF_WALK_MULTIPLE 0x01 2887c478bd9Sstevel@tonic-gate #define SCF_WALK_LEGACY 0x02 2897c478bd9Sstevel@tonic-gate #define SCF_WALK_SERVICE 0x04 2907c478bd9Sstevel@tonic-gate #define SCF_WALK_PROPERTY 0x08 2917c478bd9Sstevel@tonic-gate #define SCF_WALK_NOINSTANCE 0x10 2927c478bd9Sstevel@tonic-gate #define SCF_WALK_EXPLICIT 0x20 293*6c7c876cSJerry Jelinek #define SCF_WALK_UNIPARTIAL 0x40 2947c478bd9Sstevel@tonic-gate 295c0889d7aSstevep /* 296c0889d7aSstevep * The default locations of the repository dbs 297c0889d7aSstevep */ 298c0889d7aSstevep #define REPOSITORY_DB "/etc/svc/repository.db" 299c0889d7aSstevep #define NONPERSIST_DB "/etc/svc/volatile/svc_nonpersist.db" 300c0889d7aSstevep #define FAST_REPOSITORY_DB "/etc/svc/volatile/fast_repository.db" 3019444c26fSTom Whitten #define REPOSITORY_CHECKPOINT "/etc/svc/volatile/checkpoint_repository.db" 302c0889d7aSstevep 303c0889d7aSstevep 3047c478bd9Sstevel@tonic-gate typedef struct scf_walkinfo { 3057c478bd9Sstevel@tonic-gate const char *fmri; 3067c478bd9Sstevel@tonic-gate scf_scope_t *scope; 3077c478bd9Sstevel@tonic-gate scf_service_t *svc; 3087c478bd9Sstevel@tonic-gate scf_instance_t *inst; 3097c478bd9Sstevel@tonic-gate scf_propertygroup_t *pg; 3107c478bd9Sstevel@tonic-gate scf_property_t *prop; 3117c478bd9Sstevel@tonic-gate int count; /* svcprop special */ 3127c478bd9Sstevel@tonic-gate } scf_walkinfo_t; 3137c478bd9Sstevel@tonic-gate 3147c478bd9Sstevel@tonic-gate typedef int (*scf_walk_callback)(void *, scf_walkinfo_t *); 3157c478bd9Sstevel@tonic-gate 3167c478bd9Sstevel@tonic-gate scf_error_t scf_walk_fmri(scf_handle_t *, int, char **, int, 3177c478bd9Sstevel@tonic-gate scf_walk_callback, void *, int *, void (*)(const char *, ...)); 3187c478bd9Sstevel@tonic-gate 3197c478bd9Sstevel@tonic-gate /* 3207c478bd9Sstevel@tonic-gate * Requests a backup of the repository with a particular name, which 3217c478bd9Sstevel@tonic-gate * can be any alphabetic string. Only privileged users can do this. 3227c478bd9Sstevel@tonic-gate * 3237c478bd9Sstevel@tonic-gate * Can fail with: 3247c478bd9Sstevel@tonic-gate * _NOT_BOUND, _CONNECTION_BROKEN, _PERMISSION_DENIED, _INVALID_ARGUMENT, 3257c478bd9Sstevel@tonic-gate * _INTERNAL (path too long, or the backup failed for an odd reason), 3267c478bd9Sstevel@tonic-gate * _BACKEND_READONLY (filesystem is still read-only) 3277c478bd9Sstevel@tonic-gate */ 3287c478bd9Sstevel@tonic-gate int _scf_request_backup(scf_handle_t *, const char *); 3297c478bd9Sstevel@tonic-gate 330103b2b15Sgww /* 331c0889d7aSstevep * Repository switch client 332c0889d7aSstevep */ 333c0889d7aSstevep int _scf_repository_switch(scf_handle_t *, int); 334c0889d7aSstevep 335c0889d7aSstevep /* 3363eae19d9Swesolows * Determines whether a property group requires authorization to read; this 3373eae19d9Swesolows * does not in any way reflect whether the caller has that authorization. 3383eae19d9Swesolows * To determine that, the caller must attempt to read the value of one of the 3393eae19d9Swesolows * group's properties. 3403eae19d9Swesolows * 3413eae19d9Swesolows * Can fail with: 3423eae19d9Swesolows * _NOT_BOUND, _CONNECTION_BROKEN, _INVALID_ARGUMENT, _INTERNAL, 3433eae19d9Swesolows * _NO_RESOURCES, _CONSTRAINT_VIOLATED, _DELETED. 3443eae19d9Swesolows */ 3453eae19d9Swesolows int _scf_pg_is_read_protected(const scf_propertygroup_t *, boolean_t *); 3463eae19d9Swesolows 3473eae19d9Swesolows /* 3485b7f77adStw21770 * Sets annotation data for SMF audit logging. Once this function has been 3495b7f77adStw21770 * set, the next audit record will be preceded by an ADT_smf_annotation 3505b7f77adStw21770 * with the information provided in this function. This function is used 3515b7f77adStw21770 * to mark operations which comprise multiple primitive operations such as 3525b7f77adStw21770 * svccfg import. 3535b7f77adStw21770 */ 3545b7f77adStw21770 int _scf_set_annotation(scf_handle_t *h, const char *operation, 3555b7f77adStw21770 const char *file); 3565b7f77adStw21770 3575b7f77adStw21770 /* 358103b2b15Sgww * scf_pattern_t 359103b2b15Sgww */ 360103b2b15Sgww typedef struct scf_pattern { 361103b2b15Sgww enum { 362103b2b15Sgww PATTERN_INVALID, /* Uninitialized state */ 363103b2b15Sgww PATTERN_EXACT, 364103b2b15Sgww PATTERN_GLOB, 365103b2b15Sgww PATTERN_PARTIAL 366103b2b15Sgww } sp_type; 367103b2b15Sgww char *sp_arg; /* Original argument */ 368103b2b15Sgww struct scf_match *sp_matches; /* List of matches */ 369103b2b15Sgww int sp_matchcount; /* # of matches */ 370103b2b15Sgww } scf_pattern_t; 371103b2b15Sgww 372103b2b15Sgww int scf_cmp_pattern(char *, scf_pattern_t *); 373103b2b15Sgww 37494501b61Sskamm int gen_filenms_from_fmri(const char *, const char *, char *, char *); 37594501b61Sskamm 376dfac3eb2SDavid Powell /* 377dfac3eb2SDavid Powell * Interfaces for bulk access to SMF-stored configuration. 378dfac3eb2SDavid Powell * 379dfac3eb2SDavid Powell * Each scf_propvec_t represents a single property to be read (with 380dfac3eb2SDavid Powell * scf_read_propvec) or written (with scf_write_propvec). 381dfac3eb2SDavid Powell * 382dfac3eb2SDavid Powell * The fields of a scf_propvec_t have the following meanings: 383dfac3eb2SDavid Powell * 384dfac3eb2SDavid Powell * pv_prop - the name of the property 385dfac3eb2SDavid Powell * pv_desc - a description string (optional; to be consumed by the caller) 386dfac3eb2SDavid Powell * pv_type - the type of the property 387dfac3eb2SDavid Powell * pv_ptr - where to store the data read, or a pointer to the data to 388dfac3eb2SDavid Powell * be written 389dfac3eb2SDavid Powell * pv_aux - additional data influencing the interpretation of pv_ptr 390dfac3eb2SDavid Powell * 391dfac3eb2SDavid Powell * The meaning of pv_ptr and pv_aux depends on the type of property. For: 392dfac3eb2SDavid Powell * 393dfac3eb2SDavid Powell * boolean - if pv_aux is 0, pv_ptr is a pointer to a boolean_t 394dfac3eb2SDavid Powell * if pv_aux is non-0, pv_ptr is a pointer to a uint64_t, 395dfac3eb2SDavid Powell * where pv_aux indicates the bit holding the truth value. 396dfac3eb2SDavid Powell * count - pv_ptr is a pointer to a uint64_t; pv_aux is unused 397dfac3eb2SDavid Powell * integer - pv_ptr is a pointer to an int64_t; pv_aux is unused 398dfac3eb2SDavid Powell * time - pv_ptr is a pointer to an scf_time_t; pv_aux is unused 399dfac3eb2SDavid Powell * opaque - pv_ptr is a pointer to an scf_opaque_t; pv_aux is unused 400dfac3eb2SDavid Powell * strings - (scf_read_propvec) pv_ptr is a pointer to a char * 401dfac3eb2SDavid Powell * (scf_write_propvec) pv_ptr is a pointer to an array of char 402dfac3eb2SDavid Powell * (both) pv_aux is unused 403dfac3eb2SDavid Powell */ 404dfac3eb2SDavid Powell typedef struct { 405dfac3eb2SDavid Powell void *so_addr; 406dfac3eb2SDavid Powell size_t so_size; 407dfac3eb2SDavid Powell } scf_opaque_t; 408dfac3eb2SDavid Powell 409dfac3eb2SDavid Powell typedef struct { 410dfac3eb2SDavid Powell const char *pv_prop; 411dfac3eb2SDavid Powell const char *pv_desc; 412dfac3eb2SDavid Powell scf_type_t pv_type; 413dfac3eb2SDavid Powell void *pv_ptr; 414dfac3eb2SDavid Powell uint64_t pv_aux; 415dfac3eb2SDavid Powell } scf_propvec_t; 416dfac3eb2SDavid Powell 417dfac3eb2SDavid Powell void scf_clean_propvec(scf_propvec_t *); 418dfac3eb2SDavid Powell int scf_read_propvec(const char *, const char *, boolean_t, scf_propvec_t *, 419dfac3eb2SDavid Powell scf_propvec_t **); 420dfac3eb2SDavid Powell int scf_write_propvec(const char *, const char *, scf_propvec_t *, 421dfac3eb2SDavid Powell scf_propvec_t **); 422dfac3eb2SDavid Powell 4231f6eb021SLiane Praza scf_tmpl_errors_t *_scf_create_errors(const char *, int); 4241f6eb021SLiane Praza int _scf_tmpl_add_error(scf_tmpl_errors_t *errs, scf_tmpl_error_type_t type, 4251f6eb021SLiane Praza const char *pg_name, const char *prop_name, 4261f6eb021SLiane Praza const char *ev1, const char *ev2, const char *actual, 4271f6eb021SLiane Praza const char *tmpl_fmri, const char *tmpl_pg_name, const char *tmpl_pg_type, 4281f6eb021SLiane Praza const char *tmpl_prop_name, const char *tmpl_prop_type); 4291f6eb021SLiane Praza int _scf_tmpl_error_set_prefix(scf_tmpl_errors_t *, const char *); 4301f6eb021SLiane Praza 4311f6eb021SLiane Praza /* 4321f6eb021SLiane Praza * Templates definitions 4331f6eb021SLiane Praza */ 4341f6eb021SLiane Praza 4351f6eb021SLiane Praza /* 4361f6eb021SLiane Praza * For CARDINALITY_VIOLATION and RANGE_VIOLATION, te_ev1 holds 4371f6eb021SLiane Praza * the min value and te_ev2 holds the max value 4381f6eb021SLiane Praza * 4391f6eb021SLiane Praza * For MISSING_PG te_ev1 should hold the expected pg_name and 4401f6eb021SLiane Praza * expected2 holds the expected pg_type. 4411f6eb021SLiane Praza * 4421f6eb021SLiane Praza * For SCF_TERR_PG_PATTERN_CONFLICT and SCF_TERR_GENERAL_REDEFINE te_ev1 is 4431f6eb021SLiane Praza * the FMRI holding the conflicting pg_pattern. te_ev2 is the name of the 4441f6eb021SLiane Praza * conflicting pg_pattern, and actual is the type of the conflicting 4451f6eb021SLiane Praza * pg_pattern. 4461f6eb021SLiane Praza * 4471f6eb021SLiane Praza * SCF_TERR_PROP_PATTERN_CONFLICT te_ev1 is the FMRI holding the 4481f6eb021SLiane Praza * conflicting prop_pattern. te_ev2 is the name of the conflicting 4491f6eb021SLiane Praza * prop_pattern, and actual is the type of the conflicting prop_pattern. 4501f6eb021SLiane Praza * 4511f6eb021SLiane Praza * For SCF_TERR_INCLUDE_VALUES te_ev1 is the type specified for the 4521f6eb021SLiane Praza * include_values element. 4531f6eb021SLiane Praza * 4541f6eb021SLiane Praza * For all other errors, te_ev1 should hold the expected value and 4551f6eb021SLiane Praza * te_ev2 is ignored 4561f6eb021SLiane Praza * 4571f6eb021SLiane Praza * te_actual holds the current value of the property 4581f6eb021SLiane Praza */ 4591f6eb021SLiane Praza 4601f6eb021SLiane Praza struct scf_tmpl_error { 4611f6eb021SLiane Praza scf_tmpl_errors_t *te_errs; 4621f6eb021SLiane Praza scf_tmpl_error_type_t te_type; 4631f6eb021SLiane Praza const char *te_pg_name; 4641f6eb021SLiane Praza const char *te_prop_name; 4651f6eb021SLiane Praza const char *te_ev1; 4661f6eb021SLiane Praza const char *te_ev2; 4671f6eb021SLiane Praza const char *te_actual; 4681f6eb021SLiane Praza const char *te_tmpl_fmri; 4691f6eb021SLiane Praza const char *te_tmpl_pg_name; 4701f6eb021SLiane Praza const char *te_tmpl_pg_type; 4711f6eb021SLiane Praza const char *te_tmpl_prop_name; 4721f6eb021SLiane Praza const char *te_tmpl_prop_type; 4731f6eb021SLiane Praza }; 4741f6eb021SLiane Praza 4751f6eb021SLiane Praza /* 4761f6eb021SLiane Praza * The pg_pattern element has two optional attributes that play a part in 4771f6eb021SLiane Praza * selecting the appropriate prefix for the name of the pg_pattern property 4781f6eb021SLiane Praza * group. The two attributes are name and type. The appropriate prefix 4791f6eb021SLiane Praza * encodes the presence are absence of these attributes. 4801f6eb021SLiane Praza * 4811f6eb021SLiane Praza * SCF_PG_TM_PG_PATTERN_PREFIX neither attribute 4821f6eb021SLiane Praza * SCF_PG_TM_PG_PATTERN_N_PREFIX name only 4831f6eb021SLiane Praza * SCF_PG_TM_PG_PATTERN_T_PREFIX type only 4841f6eb021SLiane Praza * SCF_PG_TM_PG_PATTERN_NT_PREFIX both name and type 4851f6eb021SLiane Praza */ 4861f6eb021SLiane Praza #define SCF_PG_TM_PG_PAT_BASE "tm_pgpat" 4871f6eb021SLiane Praza #define SCF_PG_TM_PG_PATTERN_PREFIX ((const char *)SCF_PG_TM_PG_PAT_BASE \ 4881f6eb021SLiane Praza "_") 4891f6eb021SLiane Praza #define SCF_PG_TM_PG_PATTERN_N_PREFIX ((const char *)SCF_PG_TM_PG_PAT_BASE \ 4901f6eb021SLiane Praza "n_") 4911f6eb021SLiane Praza #define SCF_PG_TM_PG_PATTERN_T_PREFIX ((const char *)SCF_PG_TM_PG_PAT_BASE \ 4921f6eb021SLiane Praza "t_") 4931f6eb021SLiane Praza #define SCF_PG_TM_PG_PATTERN_NT_PREFIX ((const char *)SCF_PG_TM_PG_PAT_BASE \ 4941f6eb021SLiane Praza "nt_") 4951f6eb021SLiane Praza #define SCF_PG_TM_PROP_PATTERN_PREFIX ((const char *)"tm_proppat_") 4961f6eb021SLiane Praza 4971f6eb021SLiane Praza /* 4981f6eb021SLiane Praza * Pad character to use when encoding strings for property names. 4991f6eb021SLiane Praza */ 5001f6eb021SLiane Praza #define SCF_ENCODE32_PAD ('-') 5011f6eb021SLiane Praza 5021f6eb021SLiane Praza /* 5031f6eb021SLiane Praza * Functions for base 32 encoding/decoding 5041f6eb021SLiane Praza */ 5051f6eb021SLiane Praza int scf_decode32(const char *, size_t, char *, size_t, size_t *, char); 5061f6eb021SLiane Praza int scf_encode32(const char *, size_t, char *, size_t, size_t *, char); 5071f6eb021SLiane Praza 5081f6eb021SLiane Praza /* 5091f6eb021SLiane Praza * handy functions 5101f6eb021SLiane Praza */ 5111f6eb021SLiane Praza /* 5121f6eb021SLiane Praza * _scf_sanitize_locale 5131f6eb021SLiane Praza * Make sure a locale string has only alpha-numeric or '_' characters 5141f6eb021SLiane Praza */ 5151f6eb021SLiane Praza void _scf_sanitize_locale(char *); 5161f6eb021SLiane Praza 5171f6eb021SLiane Praza /* 5181f6eb021SLiane Praza * _scf_read_tmpl_prop_type_as_string() 5191f6eb021SLiane Praza * Handy function to get template property type as a string 5201f6eb021SLiane Praza */ 5211f6eb021SLiane Praza char *_scf_read_tmpl_prop_type_as_string(const scf_prop_tmpl_t *); 5221f6eb021SLiane Praza /* 5231f6eb021SLiane Praza * _scf_read_single_astring_from_pg() 5241f6eb021SLiane Praza * Given a property group (pg) and a property name (pn), this function 5251f6eb021SLiane Praza * retrives an astring value from pg/pn. 5261f6eb021SLiane Praza */ 5271f6eb021SLiane Praza char *_scf_read_single_astring_from_pg(scf_propertygroup_t *, const char *); 5281f6eb021SLiane Praza 529eb1a3463STruong Nguyen /* 530eb1a3463STruong Nguyen * scf_instance_delete_prop() 531eb1a3463STruong Nguyen * Given instance, property group, and property, delete the property. 532eb1a3463STruong Nguyen */ 533eb1a3463STruong Nguyen int 534eb1a3463STruong Nguyen scf_instance_delete_prop(scf_instance_t *, const char *, const char *); 535eb1a3463STruong Nguyen 536753a6d45SSherry Moore /* 537753a6d45SSherry Moore * Functions to extract boot config information from FMRI_BOOT_CONFIG 538753a6d45SSherry Moore */ 539753a6d45SSherry Moore void scf_get_boot_config(uint8_t *); 540c90a5fbeSSherry Moore void scf_get_boot_config_ovr(uint8_t *); 541753a6d45SSherry Moore int scf_is_fastboot_default(void); 542753a6d45SSherry Moore 543870ad75aSSean Wilcox /* 5444196e263SSherry Moore * Set value of "config_ovr/fastreboot_default". 5454196e263SSherry Moore */ 5464196e263SSherry Moore int scf_fastreboot_default_set_transient(boolean_t); 5474196e263SSherry Moore 5484196e263SSherry Moore /* 549870ad75aSSean Wilcox * scf_is_compatible_type() 550870ad75aSSean Wilcox * Return true if the second type is the same type, or a subtype of the 551870ad75aSSean Wilcox * first. 552870ad75aSSean Wilcox */ 553870ad75aSSean Wilcox int scf_is_compatible_type(scf_type_t, scf_type_t); 554870ad75aSSean Wilcox 555b56bf881SAntonello Cruz /* 556b56bf881SAntonello Cruz * Check an array of services and enable any that don't have the 557b56bf881SAntonello Cruz * "application/auto_enable" property set to "false", which is 558b56bf881SAntonello Cruz * the interface to turn off this behaviour (see PSARC 2004/739). 559b56bf881SAntonello Cruz */ 560b56bf881SAntonello Cruz void _check_services(char **); 561b56bf881SAntonello Cruz 562f6e214c7SGavin Maltby /* 563f6e214c7SGavin Maltby * _scf_handle_create_and_bind() 564f6e214c7SGavin Maltby * convenience function that creates and binds a handle 565f6e214c7SGavin Maltby */ 566f6e214c7SGavin Maltby scf_handle_t *_scf_handle_create_and_bind(scf_version_t); 567f6e214c7SGavin Maltby 568f6e214c7SGavin Maltby /* 569f6e214c7SGavin Maltby * _smf_refresh_all_instances() 570f6e214c7SGavin Maltby * refresh all intances of a service 571f6e214c7SGavin Maltby * return SCF_SUCCESS or SCF_FAILED on _PERMISSION_DENIED, _BACKEND_ACCESS 572f6e214c7SGavin Maltby * or _BACKEND_READONLY. 573f6e214c7SGavin Maltby */ 574f6e214c7SGavin Maltby int _smf_refresh_all_instances(scf_service_t *); 575f6e214c7SGavin Maltby 576f6e214c7SGavin Maltby /* 577f6e214c7SGavin Maltby * _scf_get_fma_notify_params() 578f6e214c7SGavin Maltby * Specialized fuction to get fma notifitation parameters 579f6e214c7SGavin Maltby */ 580f6e214c7SGavin Maltby int _scf_get_fma_notify_params(const char *, nvlist_t *, int); 581f6e214c7SGavin Maltby 582f6e214c7SGavin Maltby /* 583f6e214c7SGavin Maltby * _scf_get_svc_notify_params() 584f6e214c7SGavin Maltby * Specialized function to get SMF state transition notification parameters 585f6e214c7SGavin Maltby */ 586f6e214c7SGavin Maltby int _scf_get_svc_notify_params(const char *, nvlist_t *, int32_t, int, int); 587f6e214c7SGavin Maltby 588f6e214c7SGavin Maltby /* 589f6e214c7SGavin Maltby * _scf_notify_get_params() 590f6e214c7SGavin Maltby * Specialized function to get notification parametes from a pg into an 591f6e214c7SGavin Maltby * nvlist_t 592f6e214c7SGavin Maltby */ 593f6e214c7SGavin Maltby int _scf_notify_get_params(scf_propertygroup_t *, nvlist_t *); 594f6e214c7SGavin Maltby 595f6e214c7SGavin Maltby #define SCF_NOTIFY_PARAMS_SOURCE_NAME ((const char *)"preference_source") 596f6e214c7SGavin Maltby 5977c478bd9Sstevel@tonic-gate #ifdef __cplusplus 5987c478bd9Sstevel@tonic-gate } 5997c478bd9Sstevel@tonic-gate #endif 6007c478bd9Sstevel@tonic-gate 6017c478bd9Sstevel@tonic-gate #endif /* _LIBSCF_PRIV_H */ 602