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 51780Sgww * Common Development and Distribution License (the "License"). 61780Sgww * 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 */ 210Sstevel@tonic-gate /* 2212483SAntonello.Cruz@Sun.COM * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved. 230Sstevel@tonic-gate */ 240Sstevel@tonic-gate 250Sstevel@tonic-gate #ifndef _LIBSCF_PRIV_H 260Sstevel@tonic-gate #define _LIBSCF_PRIV_H 270Sstevel@tonic-gate 280Sstevel@tonic-gate 290Sstevel@tonic-gate #include <libscf.h> 300Sstevel@tonic-gate #include <unistd.h> 310Sstevel@tonic-gate 320Sstevel@tonic-gate #ifdef __cplusplus 330Sstevel@tonic-gate extern "C" { 340Sstevel@tonic-gate #endif 350Sstevel@tonic-gate 360Sstevel@tonic-gate /* 370Sstevel@tonic-gate * NOTE 380Sstevel@tonic-gate * 390Sstevel@tonic-gate * The contents of this file are private to the implementation of Solaris 400Sstevel@tonic-gate * and are subject to change at any time without notice. 410Sstevel@tonic-gate */ 420Sstevel@tonic-gate 430Sstevel@tonic-gate #define SCF_PG_GENERAL_TYPE SCF_GROUP_FRAMEWORK 440Sstevel@tonic-gate #define SCF_PG_GENERAL_FLAGS 0 450Sstevel@tonic-gate 460Sstevel@tonic-gate #define SCF_PG_GENERAL_OVR_TYPE SCF_GROUP_FRAMEWORK 470Sstevel@tonic-gate #define SCF_PG_GENERAL_OVR_FLAGS SCF_PG_FLAG_NONPERSISTENT 480Sstevel@tonic-gate 497475SPhilippe.Jung@Sun.COM #define SCF_PG_DEATHROW_TYPE SCF_GROUP_FRAMEWORK 507475SPhilippe.Jung@Sun.COM #define SCF_PG_DEATHROW_FLAGS SCF_PG_FLAG_NONPERSISTENT 517475SPhilippe.Jung@Sun.COM 520Sstevel@tonic-gate #define SCF_PG_OPTIONS_TYPE SCF_GROUP_FRAMEWORK 530Sstevel@tonic-gate #define SCF_PG_OPTIONS_FLAGS 0 540Sstevel@tonic-gate 550Sstevel@tonic-gate #define SCF_PG_OPTIONS_OVR_TYPE SCF_GROUP_FRAMEWORK 560Sstevel@tonic-gate #define SCF_PG_OPTIONS_OVR_FLAGS SCF_PG_FLAG_NONPERSISTENT 570Sstevel@tonic-gate 580Sstevel@tonic-gate #define SCF_PG_RESTARTER_TYPE SCF_GROUP_FRAMEWORK 590Sstevel@tonic-gate #define SCF_PG_RESTARTER_FLAGS SCF_PG_FLAG_NONPERSISTENT 600Sstevel@tonic-gate 610Sstevel@tonic-gate #define SCF_PG_RESTARTER_ACTIONS_TYPE SCF_GROUP_FRAMEWORK 620Sstevel@tonic-gate #define SCF_PG_RESTARTER_ACTIONS_FLAGS SCF_PG_FLAG_NONPERSISTENT 630Sstevel@tonic-gate 645777Stw21770 #define SCF_PROPERTY_CLEAR ((const char *)"maint_off") 655777Stw21770 #define SCF_PROPERTY_MAINTENANCE ((const char *)"maint_on") 665777Stw21770 670Sstevel@tonic-gate #define SCF_PROPERTY_LOGFILE ((const char *)"logfile") 680Sstevel@tonic-gate #define SCF_PROPERTY_ALT_LOGFILE ((const char *)"alt_logfile") 690Sstevel@tonic-gate 700Sstevel@tonic-gate #define SCF_LEGACY_SERVICE ((const char *)"smf/legacy_run") 710Sstevel@tonic-gate 720Sstevel@tonic-gate #define SCF_LEGACY_PROPERTY_NAME ((const char *)"name") 730Sstevel@tonic-gate #define SCF_LEGACY_PROPERTY_INODE ((const char *)"inode") 740Sstevel@tonic-gate #define SCF_LEGACY_PROPERTY_SUFFIX ((const char *)"suffix") 750Sstevel@tonic-gate 760Sstevel@tonic-gate #define SCF_FMRI_TYPE_SVC 0x1 770Sstevel@tonic-gate #define SCF_FMRI_TYPE_FILE 0x2 780Sstevel@tonic-gate 795777Stw21770 /* 805777Stw21770 * Strings for use in constructing FMRIs 815777Stw21770 */ 825777Stw21770 #define SCF_FMRI_SVC_PREFIX "svc:" 835777Stw21770 #define SCF_FMRI_FILE_PREFIX "file:" 845777Stw21770 #define SCF_FMRI_SCOPE_PREFIX "//" 855777Stw21770 #define SCF_FMRI_LOCAL_SCOPE "localhost" 865777Stw21770 #define SCF_FMRI_SCOPE_SUFFIX "@localhost" 875777Stw21770 #define SCF_FMRI_SERVICE_PREFIX "/" 885777Stw21770 #define SCF_FMRI_INSTANCE_PREFIX ":" 895777Stw21770 #define SCF_FMRI_PROPERTYGRP_PREFIX "/:properties/" 905777Stw21770 #define SCF_FMRI_PROPERTY_PREFIX "/" 916073Sacruz #define SCF_FMRI_LEGACY_PREFIX "lrc:" 926073Sacruz 936073Sacruz /* 946073Sacruz * sulogin Service FMRI 956073Sacruz */ 966073Sacruz #define SVC_SULOGIN_FMRI ((const char *)"svc:/system/sulogin") 975777Stw21770 980Sstevel@tonic-gate typedef struct scf_decoration_info { 990Sstevel@tonic-gate const char *sdi_name; 1000Sstevel@tonic-gate scf_type_t sdi_type; 1010Sstevel@tonic-gate scf_value_t *sdi_value; /* can be SCF_DECORATE_CLEAR */ 1020Sstevel@tonic-gate } scf_decoration_info_t; 1030Sstevel@tonic-gate 1040Sstevel@tonic-gate typedef int (*scf_decoration_func)(const scf_decoration_info_t *, void *); 1050Sstevel@tonic-gate 1060Sstevel@tonic-gate /* 1070Sstevel@tonic-gate * calls a callback function for each decoration on the handle. If the 1080Sstevel@tonic-gate * callback returns 0, the iteration stops and returns 0. If the callback 1090Sstevel@tonic-gate * returns a non-zero value, the iteration continues. After full completion, 1100Sstevel@tonic-gate * 1 is returned. On error, -1 is returned. 1110Sstevel@tonic-gate */ 1120Sstevel@tonic-gate int _scf_handle_decorations(scf_handle_t *, scf_decoration_func *, 1130Sstevel@tonic-gate scf_value_t *, void *); 1140Sstevel@tonic-gate 1150Sstevel@tonic-gate /* 1160Sstevel@tonic-gate * wait for a change to the propertygroup -- may return early. 1170Sstevel@tonic-gate * For now, only one of these can be outstanding at a time. 1180Sstevel@tonic-gate * 1190Sstevel@tonic-gate * The second argument is how long, in seconds, to wait for a response. 1200Sstevel@tonic-gate * 1210Sstevel@tonic-gate * Returns SCF_COMPLETE on timeout, -1 on error, and SCF_SUCCESS in every 1220Sstevel@tonic-gate * other case. You must call scf_pg_update() to see if the object has 1230Sstevel@tonic-gate * actually changed. 1240Sstevel@tonic-gate */ 1250Sstevel@tonic-gate int _scf_pg_wait(scf_propertygroup_t *, int); 1260Sstevel@tonic-gate 1270Sstevel@tonic-gate /* 1280Sstevel@tonic-gate * set up notifications for changes to a class of property groups (by name 1290Sstevel@tonic-gate * and type) 1300Sstevel@tonic-gate * 1310Sstevel@tonic-gate * Only one thread can be sleeping in _scf_notify_wait() -- others will 1320Sstevel@tonic-gate * fail. Deletions give an fmri in the output path. 1330Sstevel@tonic-gate * 1340Sstevel@tonic-gate * These do not survive unbind()->bind() -- in fact, that is currently the 1350Sstevel@tonic-gate * only way to clear them. 1360Sstevel@tonic-gate */ 1370Sstevel@tonic-gate int _scf_notify_add_pgname(scf_handle_t *, const char *); 1380Sstevel@tonic-gate int _scf_notify_add_pgtype(scf_handle_t *, const char *); 1390Sstevel@tonic-gate int _scf_notify_wait(scf_propertygroup_t *, char *, size_t); 1400Sstevel@tonic-gate 1410Sstevel@tonic-gate /* 1420Sstevel@tonic-gate * Internal interfaces for snapshot creation: 1430Sstevel@tonic-gate * _scf_snapshot_take_new(), _scf_snapshot_take_new_named(), and 1440Sstevel@tonic-gate * _scf_snapshot_take_attach() create a set of snaplevels 1450Sstevel@tonic-gate * containing frozen versions of both the instance's property groups and 1460Sstevel@tonic-gate * its parent service's property groups. _scf_snapshot_take_new() and 1470Sstevel@tonic-gate * _scf_snapshot_take_new_named() create a new snapshot to which the 1480Sstevel@tonic-gate * new snaplevels are attached, while _scf_snapshot_take_attach() 1490Sstevel@tonic-gate * attaches the new snaplevels to a pre-existing snapshot. 1500Sstevel@tonic-gate * 1510Sstevel@tonic-gate * _scf_snapshot_take_new_named() records the passed in names into the 1520Sstevel@tonic-gate * snaplevel instead of the instance and service name. This creates 1530Sstevel@tonic-gate * an inconsistency, which should be resolved by using 1540Sstevel@tonic-gate * _scf_snapshot_attach() to attach the new snaplevels to a snapshot 1550Sstevel@tonic-gate * underneath the appropriate instance. The first snapshot can 1560Sstevel@tonic-gate * then be deleted. 1570Sstevel@tonic-gate * 1580Sstevel@tonic-gate * _scf_snapshot_attach(snap1, snap2) points snap2 at the snaplevels 1590Sstevel@tonic-gate * pointed to by snap1. After a call to either 1600Sstevel@tonic-gate * _scf_snapshot_take_attach(snap1, snap2) or 1610Sstevel@tonic-gate * _scf_snapshot_attach(inst, snap), scf_snapshot_update() will be 1620Sstevel@tonic-gate * required for any open references to snap or snap2 to see the new 1630Sstevel@tonic-gate * snaplevels. 1640Sstevel@tonic-gate * 1650Sstevel@tonic-gate * _scf_snapshot_delete() deletes the snapshot object. While 1660Sstevel@tonic-gate * snaplevels, being only loosely connected to snapshots, stay 1670Sstevel@tonic-gate * around until they are no longer referenced, any references *through 1680Sstevel@tonic-gate * this snapshot object* will be invalidated. 1690Sstevel@tonic-gate * 1700Sstevel@tonic-gate * _scf_snapshot_take_new() can fail with at least _HANDLE_MISMATCH, 1710Sstevel@tonic-gate * _CONNECTION_BROKEN, _INVALID_ARGUMENT, _NO_RESOURCES, _PERMISSION_DENIED, 1720Sstevel@tonic-gate * _NOT_SET, _EXISTS. 1730Sstevel@tonic-gate * 1740Sstevel@tonic-gate * _scf_snapshot_take_new_named() can fail with at least _HANDLE_MISMATCH, 1750Sstevel@tonic-gate * _CONNECTION_BROKEN, _INVALID_ARGUMENT, _NO_RESOURCES, _PERMISSION_DENIED, 1760Sstevel@tonic-gate * _NOT_SET, _EXISTS. 1770Sstevel@tonic-gate * 1780Sstevel@tonic-gate * _scf_snapshot_take_attach() can fail with _CONNECTION_BROKEN, _NOT_SET, 1790Sstevel@tonic-gate * _PERMISSION_DENIED, _NO_RESOURCES, _INVALID_ARGUMENT. 1800Sstevel@tonic-gate * 1810Sstevel@tonic-gate * _scf_snapshot_attach() can fail with _HANDLE_MISMATCH, _CONNECTION_BROKEN, 1820Sstevel@tonic-gate * _NOT_SET, _NO_RESOURCES, _PERMISSION_DENIED. 1830Sstevel@tonic-gate */ 1840Sstevel@tonic-gate int _scf_snapshot_take_new(scf_instance_t *, const char *, scf_snapshot_t *); 1850Sstevel@tonic-gate int _scf_snapshot_take_new_named(scf_instance_t *, 1860Sstevel@tonic-gate const char *, const char *, const char *, scf_snapshot_t *); 1870Sstevel@tonic-gate int _scf_snapshot_take_attach(scf_instance_t *, scf_snapshot_t *); 1880Sstevel@tonic-gate int _scf_snapshot_attach(scf_snapshot_t *, scf_snapshot_t *); 1890Sstevel@tonic-gate int _scf_snapshot_delete(scf_snapshot_t *); 1900Sstevel@tonic-gate 1910Sstevel@tonic-gate /* 1920Sstevel@tonic-gate * Destructively portions up the first argument into the different portions 1930Sstevel@tonic-gate * of a svc: fmri, and returns pointers to the applicable portions. Omitted 1940Sstevel@tonic-gate * portions are set to NULL, except for the scope, which is set to the 1950Sstevel@tonic-gate * default local scope if not specified. 1960Sstevel@tonic-gate * 1970Sstevel@tonic-gate * Parsing is attempted in the order of: svc:, file:. The identified type 1980Sstevel@tonic-gate * of the service is returned in the second argument and may take a value 1990Sstevel@tonic-gate * of: SCF_FMRI_TYPE_SVC or SCF_FMRI_TYPE_FILE. 2000Sstevel@tonic-gate * 2010Sstevel@tonic-gate * Note that some of the returned pointers (in particular the scope) may not 2020Sstevel@tonic-gate * point into the passed buffer. 2030Sstevel@tonic-gate */ 2040Sstevel@tonic-gate int scf_parse_fmri(char *, int *, const char **, const char **, const char **, 2050Sstevel@tonic-gate const char **, const char **); 2060Sstevel@tonic-gate 2070Sstevel@tonic-gate int scf_parse_svc_fmri(char *, const char **, const char **, const char **, 2080Sstevel@tonic-gate const char **, const char **); 2090Sstevel@tonic-gate 2100Sstevel@tonic-gate int scf_parse_file_fmri(char *fmri, const char **scope, const char **path); 2110Sstevel@tonic-gate 2120Sstevel@tonic-gate ssize_t scf_canonify_fmri(const char *, char *, size_t); 2130Sstevel@tonic-gate 2140Sstevel@tonic-gate int _smf_refresh_instance_i(scf_instance_t *); 2150Sstevel@tonic-gate 2164119Stn143363 typedef struct scf_simple_handle { 2174119Stn143363 scf_handle_t *h; 2184119Stn143363 scf_snapshot_t *snap; 2194119Stn143363 scf_instance_t *inst; 2204119Stn143363 scf_propertygroup_t *running_pg; 2214119Stn143363 scf_propertygroup_t *editing_pg; 2224119Stn143363 } scf_simple_handle_t; 2234119Stn143363 2244119Stn143363 void scf_simple_handle_destroy(scf_simple_handle_t *); 2254119Stn143363 scf_simple_handle_t *scf_general_pg_setup(const char *, const char *); 2264119Stn143363 scf_transaction_t *scf_transaction_setup(scf_simple_handle_t *); 2274119Stn143363 int scf_transaction_restart(scf_simple_handle_t *, scf_transaction_t *); 2284119Stn143363 int scf_read_count_property(scf_simple_handle_t *, char *, uint64_t *); 2294119Stn143363 int scf_set_count_property(scf_transaction_t *, char *, uint64_t, boolean_t); 2304119Stn143363 2310Sstevel@tonic-gate /* 2320Sstevel@tonic-gate * Walks all the instances matching a given fmri list. Each fmri in the array 2330Sstevel@tonic-gate * can be one of the following: 2340Sstevel@tonic-gate * 2350Sstevel@tonic-gate * - Full instance name 2360Sstevel@tonic-gate * - Full service name 2370Sstevel@tonic-gate * - Full property group or property name 2380Sstevel@tonic-gate * - Partial service or instance name 2390Sstevel@tonic-gate * - A globbed pattern 2400Sstevel@tonic-gate * 2410Sstevel@tonic-gate * The matching rules for partial fmris are a slightly more complex. We allow 2420Sstevel@tonic-gate * for any substring anchored at the end of the instance or service name, 2430Sstevel@tonic-gate * provided it begins with a complete element in the fmri. For example, given 2440Sstevel@tonic-gate * the fmri "svc:/system/filesystem/local:default", any of the following would 2450Sstevel@tonic-gate * be acceptable matches: 'default', 'local', 'local:default', 2460Sstevel@tonic-gate * 'filesystem/local'. The following would not be acceptable: 2470Sstevel@tonic-gate * 'system/filesystem', 'filesystem/loc', 'system/local'. Possible flag values: 2480Sstevel@tonic-gate * 2490Sstevel@tonic-gate * SCF_WALK_MULTIPLE Allow individual arguments to correspond to 2500Sstevel@tonic-gate * multiple instances. 2510Sstevel@tonic-gate * 2520Sstevel@tonic-gate * SCF_WALK_LEGACY Walk legacy services (indicated by a non-NULL 2530Sstevel@tonic-gate * propery group). 2540Sstevel@tonic-gate * 2550Sstevel@tonic-gate * SCF_WALK_SERVICE If the user specifies a service, pass the 2560Sstevel@tonic-gate * service to the callback without iterating over 2570Sstevel@tonic-gate * its instances. 2580Sstevel@tonic-gate * 2590Sstevel@tonic-gate * SCF_WALK_PROPERTY Allow FMRIs which match property groups or 2600Sstevel@tonic-gate * individual properties. Incompatible with 2610Sstevel@tonic-gate * SCF_WALK_LEGACY. 2620Sstevel@tonic-gate * 2630Sstevel@tonic-gate * SCF_WALK_NOINSTANCE Walk only services. Must be used in 2640Sstevel@tonic-gate * conjunction with SCF_WALK_SERVICE. 2650Sstevel@tonic-gate * 2660Sstevel@tonic-gate * SCF_WALK_EXPLICIT Walk only services if the match is exact 2670Sstevel@tonic-gate * else return instances. Must be used in 2680Sstevel@tonic-gate * conjunction with SCF_WALK_SERVICE. 2690Sstevel@tonic-gate * 2700Sstevel@tonic-gate * If no arguments are given, then all instances in the service graph are 2710Sstevel@tonic-gate * walked. 2720Sstevel@tonic-gate * 2730Sstevel@tonic-gate * The second to last parameter is set to UU_EXIT_FATAL if one of the arguments 2740Sstevel@tonic-gate * is an invalid FMRI or matches multiple FMRIs when SCF_WALK_MULTIPLE is not 2750Sstevel@tonic-gate * set. 2760Sstevel@tonic-gate * 2770Sstevel@tonic-gate * The last parameter is a user-supplied error function that is called when 2780Sstevel@tonic-gate * reporting invalid arguments. 2790Sstevel@tonic-gate */ 2800Sstevel@tonic-gate 2810Sstevel@tonic-gate #define SCF_WALK_MULTIPLE 0x01 2820Sstevel@tonic-gate #define SCF_WALK_LEGACY 0x02 2830Sstevel@tonic-gate #define SCF_WALK_SERVICE 0x04 2840Sstevel@tonic-gate #define SCF_WALK_PROPERTY 0x08 2850Sstevel@tonic-gate #define SCF_WALK_NOINSTANCE 0x10 2860Sstevel@tonic-gate #define SCF_WALK_EXPLICIT 0x20 2870Sstevel@tonic-gate 2886035Sstevep /* 2896035Sstevep * The default locations of the repository dbs 2906035Sstevep */ 2916035Sstevep #define REPOSITORY_DB "/etc/svc/repository.db" 2926035Sstevep #define NONPERSIST_DB "/etc/svc/volatile/svc_nonpersist.db" 2936035Sstevep #define FAST_REPOSITORY_DB "/etc/svc/volatile/fast_repository.db" 29411996SThomas.Whitten@Sun.COM #define REPOSITORY_CHECKPOINT "/etc/svc/volatile/checkpoint_repository.db" 2956035Sstevep 2966035Sstevep 2970Sstevel@tonic-gate typedef struct scf_walkinfo { 2980Sstevel@tonic-gate const char *fmri; 2990Sstevel@tonic-gate scf_scope_t *scope; 3000Sstevel@tonic-gate scf_service_t *svc; 3010Sstevel@tonic-gate scf_instance_t *inst; 3020Sstevel@tonic-gate scf_propertygroup_t *pg; 3030Sstevel@tonic-gate scf_property_t *prop; 3040Sstevel@tonic-gate int count; /* svcprop special */ 3050Sstevel@tonic-gate } scf_walkinfo_t; 3060Sstevel@tonic-gate 3070Sstevel@tonic-gate typedef int (*scf_walk_callback)(void *, scf_walkinfo_t *); 3080Sstevel@tonic-gate 3090Sstevel@tonic-gate scf_error_t scf_walk_fmri(scf_handle_t *, int, char **, int, 3100Sstevel@tonic-gate scf_walk_callback, void *, int *, void (*)(const char *, ...)); 3110Sstevel@tonic-gate 3120Sstevel@tonic-gate /* 3130Sstevel@tonic-gate * Requests a backup of the repository with a particular name, which 3140Sstevel@tonic-gate * can be any alphabetic string. Only privileged users can do this. 3150Sstevel@tonic-gate * 3160Sstevel@tonic-gate * Can fail with: 3170Sstevel@tonic-gate * _NOT_BOUND, _CONNECTION_BROKEN, _PERMISSION_DENIED, _INVALID_ARGUMENT, 3180Sstevel@tonic-gate * _INTERNAL (path too long, or the backup failed for an odd reason), 3190Sstevel@tonic-gate * _BACKEND_READONLY (filesystem is still read-only) 3200Sstevel@tonic-gate */ 3210Sstevel@tonic-gate int _scf_request_backup(scf_handle_t *, const char *); 3220Sstevel@tonic-gate 3231780Sgww /* 3246035Sstevep * Repository switch client 3256035Sstevep */ 3266035Sstevep int _scf_repository_switch(scf_handle_t *, int); 3276035Sstevep 3286035Sstevep /* 3295040Swesolows * Determines whether a property group requires authorization to read; this 3305040Swesolows * does not in any way reflect whether the caller has that authorization. 3315040Swesolows * To determine that, the caller must attempt to read the value of one of the 3325040Swesolows * group's properties. 3335040Swesolows * 3345040Swesolows * Can fail with: 3355040Swesolows * _NOT_BOUND, _CONNECTION_BROKEN, _INVALID_ARGUMENT, _INTERNAL, 3365040Swesolows * _NO_RESOURCES, _CONSTRAINT_VIOLATED, _DELETED. 3375040Swesolows */ 3385040Swesolows int _scf_pg_is_read_protected(const scf_propertygroup_t *, boolean_t *); 3395040Swesolows 3405040Swesolows /* 3415777Stw21770 * Sets annotation data for SMF audit logging. Once this function has been 3425777Stw21770 * set, the next audit record will be preceded by an ADT_smf_annotation 3435777Stw21770 * with the information provided in this function. This function is used 3445777Stw21770 * to mark operations which comprise multiple primitive operations such as 3455777Stw21770 * svccfg import. 3465777Stw21770 */ 3475777Stw21770 int _scf_set_annotation(scf_handle_t *h, const char *operation, 3485777Stw21770 const char *file); 3495777Stw21770 3505777Stw21770 /* 3511780Sgww * scf_pattern_t 3521780Sgww */ 3531780Sgww typedef struct scf_pattern { 3541780Sgww enum { 3551780Sgww PATTERN_INVALID, /* Uninitialized state */ 3561780Sgww PATTERN_EXACT, 3571780Sgww PATTERN_GLOB, 3581780Sgww PATTERN_PARTIAL 3591780Sgww } sp_type; 3601780Sgww char *sp_arg; /* Original argument */ 3611780Sgww struct scf_match *sp_matches; /* List of matches */ 3621780Sgww int sp_matchcount; /* # of matches */ 3631780Sgww } scf_pattern_t; 3641780Sgww 3651780Sgww int scf_cmp_pattern(char *, scf_pattern_t *); 3661780Sgww 3673175Sskamm int gen_filenms_from_fmri(const char *, const char *, char *, char *); 3683175Sskamm 3697734SDavid.Powell@sun.com /* 3707734SDavid.Powell@sun.com * Interfaces for bulk access to SMF-stored configuration. 3717734SDavid.Powell@sun.com * 3727734SDavid.Powell@sun.com * Each scf_propvec_t represents a single property to be read (with 3737734SDavid.Powell@sun.com * scf_read_propvec) or written (with scf_write_propvec). 3747734SDavid.Powell@sun.com * 3757734SDavid.Powell@sun.com * The fields of a scf_propvec_t have the following meanings: 3767734SDavid.Powell@sun.com * 3777734SDavid.Powell@sun.com * pv_prop - the name of the property 3787734SDavid.Powell@sun.com * pv_desc - a description string (optional; to be consumed by the caller) 3797734SDavid.Powell@sun.com * pv_type - the type of the property 3807734SDavid.Powell@sun.com * pv_ptr - where to store the data read, or a pointer to the data to 3817734SDavid.Powell@sun.com * be written 3827734SDavid.Powell@sun.com * pv_aux - additional data influencing the interpretation of pv_ptr 3837734SDavid.Powell@sun.com * 3847734SDavid.Powell@sun.com * The meaning of pv_ptr and pv_aux depends on the type of property. For: 3857734SDavid.Powell@sun.com * 3867734SDavid.Powell@sun.com * boolean - if pv_aux is 0, pv_ptr is a pointer to a boolean_t 3877734SDavid.Powell@sun.com * if pv_aux is non-0, pv_ptr is a pointer to a uint64_t, 3887734SDavid.Powell@sun.com * where pv_aux indicates the bit holding the truth value. 3897734SDavid.Powell@sun.com * count - pv_ptr is a pointer to a uint64_t; pv_aux is unused 3907734SDavid.Powell@sun.com * integer - pv_ptr is a pointer to an int64_t; pv_aux is unused 3917734SDavid.Powell@sun.com * time - pv_ptr is a pointer to an scf_time_t; pv_aux is unused 3927734SDavid.Powell@sun.com * opaque - pv_ptr is a pointer to an scf_opaque_t; pv_aux is unused 3937734SDavid.Powell@sun.com * strings - (scf_read_propvec) pv_ptr is a pointer to a char * 3947734SDavid.Powell@sun.com * (scf_write_propvec) pv_ptr is a pointer to an array of char 3957734SDavid.Powell@sun.com * (both) pv_aux is unused 3967734SDavid.Powell@sun.com */ 3977734SDavid.Powell@sun.com typedef struct { 3987734SDavid.Powell@sun.com void *so_addr; 3997734SDavid.Powell@sun.com size_t so_size; 4007734SDavid.Powell@sun.com } scf_opaque_t; 4017734SDavid.Powell@sun.com 4027734SDavid.Powell@sun.com typedef struct { 4037734SDavid.Powell@sun.com const char *pv_prop; 4047734SDavid.Powell@sun.com const char *pv_desc; 4057734SDavid.Powell@sun.com scf_type_t pv_type; 4067734SDavid.Powell@sun.com void *pv_ptr; 4077734SDavid.Powell@sun.com uint64_t pv_aux; 4087734SDavid.Powell@sun.com } scf_propvec_t; 4097734SDavid.Powell@sun.com 4107734SDavid.Powell@sun.com void scf_clean_propvec(scf_propvec_t *); 4117734SDavid.Powell@sun.com int scf_read_propvec(const char *, const char *, boolean_t, scf_propvec_t *, 4127734SDavid.Powell@sun.com scf_propvec_t **); 4137734SDavid.Powell@sun.com int scf_write_propvec(const char *, const char *, scf_propvec_t *, 4147734SDavid.Powell@sun.com scf_propvec_t **); 4157734SDavid.Powell@sun.com 4167887SLiane.Praza@Sun.COM scf_tmpl_errors_t *_scf_create_errors(const char *, int); 4177887SLiane.Praza@Sun.COM int _scf_tmpl_add_error(scf_tmpl_errors_t *errs, scf_tmpl_error_type_t type, 4187887SLiane.Praza@Sun.COM const char *pg_name, const char *prop_name, 4197887SLiane.Praza@Sun.COM const char *ev1, const char *ev2, const char *actual, 4207887SLiane.Praza@Sun.COM const char *tmpl_fmri, const char *tmpl_pg_name, const char *tmpl_pg_type, 4217887SLiane.Praza@Sun.COM const char *tmpl_prop_name, const char *tmpl_prop_type); 4227887SLiane.Praza@Sun.COM int _scf_tmpl_error_set_prefix(scf_tmpl_errors_t *, const char *); 4237887SLiane.Praza@Sun.COM 4247887SLiane.Praza@Sun.COM /* 4257887SLiane.Praza@Sun.COM * Templates definitions 4267887SLiane.Praza@Sun.COM */ 4277887SLiane.Praza@Sun.COM 4287887SLiane.Praza@Sun.COM /* 4297887SLiane.Praza@Sun.COM * For CARDINALITY_VIOLATION and RANGE_VIOLATION, te_ev1 holds 4307887SLiane.Praza@Sun.COM * the min value and te_ev2 holds the max value 4317887SLiane.Praza@Sun.COM * 4327887SLiane.Praza@Sun.COM * For MISSING_PG te_ev1 should hold the expected pg_name and 4337887SLiane.Praza@Sun.COM * expected2 holds the expected pg_type. 4347887SLiane.Praza@Sun.COM * 4357887SLiane.Praza@Sun.COM * For SCF_TERR_PG_PATTERN_CONFLICT and SCF_TERR_GENERAL_REDEFINE te_ev1 is 4367887SLiane.Praza@Sun.COM * the FMRI holding the conflicting pg_pattern. te_ev2 is the name of the 4377887SLiane.Praza@Sun.COM * conflicting pg_pattern, and actual is the type of the conflicting 4387887SLiane.Praza@Sun.COM * pg_pattern. 4397887SLiane.Praza@Sun.COM * 4407887SLiane.Praza@Sun.COM * SCF_TERR_PROP_PATTERN_CONFLICT te_ev1 is the FMRI holding the 4417887SLiane.Praza@Sun.COM * conflicting prop_pattern. te_ev2 is the name of the conflicting 4427887SLiane.Praza@Sun.COM * prop_pattern, and actual is the type of the conflicting prop_pattern. 4437887SLiane.Praza@Sun.COM * 4447887SLiane.Praza@Sun.COM * For SCF_TERR_INCLUDE_VALUES te_ev1 is the type specified for the 4457887SLiane.Praza@Sun.COM * include_values element. 4467887SLiane.Praza@Sun.COM * 4477887SLiane.Praza@Sun.COM * For all other errors, te_ev1 should hold the expected value and 4487887SLiane.Praza@Sun.COM * te_ev2 is ignored 4497887SLiane.Praza@Sun.COM * 4507887SLiane.Praza@Sun.COM * te_actual holds the current value of the property 4517887SLiane.Praza@Sun.COM */ 4527887SLiane.Praza@Sun.COM 4537887SLiane.Praza@Sun.COM struct scf_tmpl_error { 4547887SLiane.Praza@Sun.COM scf_tmpl_errors_t *te_errs; 4557887SLiane.Praza@Sun.COM scf_tmpl_error_type_t te_type; 4567887SLiane.Praza@Sun.COM const char *te_pg_name; 4577887SLiane.Praza@Sun.COM const char *te_prop_name; 4587887SLiane.Praza@Sun.COM const char *te_ev1; 4597887SLiane.Praza@Sun.COM const char *te_ev2; 4607887SLiane.Praza@Sun.COM const char *te_actual; 4617887SLiane.Praza@Sun.COM const char *te_tmpl_fmri; 4627887SLiane.Praza@Sun.COM const char *te_tmpl_pg_name; 4637887SLiane.Praza@Sun.COM const char *te_tmpl_pg_type; 4647887SLiane.Praza@Sun.COM const char *te_tmpl_prop_name; 4657887SLiane.Praza@Sun.COM const char *te_tmpl_prop_type; 4667887SLiane.Praza@Sun.COM }; 4677887SLiane.Praza@Sun.COM 4687887SLiane.Praza@Sun.COM /* 4697887SLiane.Praza@Sun.COM * The pg_pattern element has two optional attributes that play a part in 4707887SLiane.Praza@Sun.COM * selecting the appropriate prefix for the name of the pg_pattern property 4717887SLiane.Praza@Sun.COM * group. The two attributes are name and type. The appropriate prefix 4727887SLiane.Praza@Sun.COM * encodes the presence are absence of these attributes. 4737887SLiane.Praza@Sun.COM * 4747887SLiane.Praza@Sun.COM * SCF_PG_TM_PG_PATTERN_PREFIX neither attribute 4757887SLiane.Praza@Sun.COM * SCF_PG_TM_PG_PATTERN_N_PREFIX name only 4767887SLiane.Praza@Sun.COM * SCF_PG_TM_PG_PATTERN_T_PREFIX type only 4777887SLiane.Praza@Sun.COM * SCF_PG_TM_PG_PATTERN_NT_PREFIX both name and type 4787887SLiane.Praza@Sun.COM */ 4797887SLiane.Praza@Sun.COM #define SCF_PG_TM_PG_PAT_BASE "tm_pgpat" 4807887SLiane.Praza@Sun.COM #define SCF_PG_TM_PG_PATTERN_PREFIX ((const char *)SCF_PG_TM_PG_PAT_BASE \ 4817887SLiane.Praza@Sun.COM "_") 4827887SLiane.Praza@Sun.COM #define SCF_PG_TM_PG_PATTERN_N_PREFIX ((const char *)SCF_PG_TM_PG_PAT_BASE \ 4837887SLiane.Praza@Sun.COM "n_") 4847887SLiane.Praza@Sun.COM #define SCF_PG_TM_PG_PATTERN_T_PREFIX ((const char *)SCF_PG_TM_PG_PAT_BASE \ 4857887SLiane.Praza@Sun.COM "t_") 4867887SLiane.Praza@Sun.COM #define SCF_PG_TM_PG_PATTERN_NT_PREFIX ((const char *)SCF_PG_TM_PG_PAT_BASE \ 4877887SLiane.Praza@Sun.COM "nt_") 4887887SLiane.Praza@Sun.COM #define SCF_PG_TM_PROP_PATTERN_PREFIX ((const char *)"tm_proppat_") 4897887SLiane.Praza@Sun.COM 4907887SLiane.Praza@Sun.COM /* 4917887SLiane.Praza@Sun.COM * Pad character to use when encoding strings for property names. 4927887SLiane.Praza@Sun.COM */ 4937887SLiane.Praza@Sun.COM #define SCF_ENCODE32_PAD ('-') 4947887SLiane.Praza@Sun.COM 4957887SLiane.Praza@Sun.COM /* 4967887SLiane.Praza@Sun.COM * Functions for base 32 encoding/decoding 4977887SLiane.Praza@Sun.COM */ 4987887SLiane.Praza@Sun.COM int scf_decode32(const char *, size_t, char *, size_t, size_t *, char); 4997887SLiane.Praza@Sun.COM int scf_encode32(const char *, size_t, char *, size_t, size_t *, char); 5007887SLiane.Praza@Sun.COM 5017887SLiane.Praza@Sun.COM /* 5027887SLiane.Praza@Sun.COM * handy functions 5037887SLiane.Praza@Sun.COM */ 5047887SLiane.Praza@Sun.COM /* 5057887SLiane.Praza@Sun.COM * _scf_sanitize_locale 5067887SLiane.Praza@Sun.COM * Make sure a locale string has only alpha-numeric or '_' characters 5077887SLiane.Praza@Sun.COM */ 5087887SLiane.Praza@Sun.COM void _scf_sanitize_locale(char *); 5097887SLiane.Praza@Sun.COM 5107887SLiane.Praza@Sun.COM /* 5117887SLiane.Praza@Sun.COM * _scf_read_tmpl_prop_type_as_string() 5127887SLiane.Praza@Sun.COM * Handy function to get template property type as a string 5137887SLiane.Praza@Sun.COM */ 5147887SLiane.Praza@Sun.COM char *_scf_read_tmpl_prop_type_as_string(const scf_prop_tmpl_t *); 5157887SLiane.Praza@Sun.COM /* 5167887SLiane.Praza@Sun.COM * _scf_read_single_astring_from_pg() 5177887SLiane.Praza@Sun.COM * Given a property group (pg) and a property name (pn), this function 5187887SLiane.Praza@Sun.COM * retrives an astring value from pg/pn. 5197887SLiane.Praza@Sun.COM */ 5207887SLiane.Praza@Sun.COM char *_scf_read_single_astring_from_pg(scf_propertygroup_t *, const char *); 5217887SLiane.Praza@Sun.COM 5228823STruong.Q.Nguyen@Sun.COM /* 5238823STruong.Q.Nguyen@Sun.COM * scf_instance_delete_prop() 5248823STruong.Q.Nguyen@Sun.COM * Given instance, property group, and property, delete the property. 5258823STruong.Q.Nguyen@Sun.COM */ 5268823STruong.Q.Nguyen@Sun.COM int 5278823STruong.Q.Nguyen@Sun.COM scf_instance_delete_prop(scf_instance_t *, const char *, const char *); 5288823STruong.Q.Nguyen@Sun.COM 5299160SSherry.Moore@Sun.COM /* 5309160SSherry.Moore@Sun.COM * Functions to extract boot config information from FMRI_BOOT_CONFIG 5319160SSherry.Moore@Sun.COM */ 5329160SSherry.Moore@Sun.COM void scf_get_boot_config(uint8_t *); 53310559SSherry.Moore@Sun.COM void scf_get_boot_config_ovr(uint8_t *); 5349160SSherry.Moore@Sun.COM int scf_is_fastboot_default(void); 5359160SSherry.Moore@Sun.COM 5369765SSean.Wilcox@Sun.COM /* 5379862SSherry.Moore@Sun.COM * Set value of "config_ovr/fastreboot_default". 5389862SSherry.Moore@Sun.COM */ 5399862SSherry.Moore@Sun.COM int scf_fastreboot_default_set_transient(boolean_t); 5409862SSherry.Moore@Sun.COM 5419862SSherry.Moore@Sun.COM /* 5429765SSean.Wilcox@Sun.COM * scf_is_compatible_type() 5439765SSean.Wilcox@Sun.COM * Return true if the second type is the same type, or a subtype of the 5449765SSean.Wilcox@Sun.COM * first. 5459765SSean.Wilcox@Sun.COM */ 5469765SSean.Wilcox@Sun.COM int scf_is_compatible_type(scf_type_t, scf_type_t); 5479765SSean.Wilcox@Sun.COM 54812483SAntonello.Cruz@Sun.COM /* 54912483SAntonello.Cruz@Sun.COM * Check an array of services and enable any that don't have the 55012483SAntonello.Cruz@Sun.COM * "application/auto_enable" property set to "false", which is 55112483SAntonello.Cruz@Sun.COM * the interface to turn off this behaviour (see PSARC 2004/739). 55212483SAntonello.Cruz@Sun.COM */ 55312483SAntonello.Cruz@Sun.COM void _check_services(char **); 55412483SAntonello.Cruz@Sun.COM 555*12967Sgavin.maltby@oracle.com /* 556*12967Sgavin.maltby@oracle.com * _scf_handle_create_and_bind() 557*12967Sgavin.maltby@oracle.com * convenience function that creates and binds a handle 558*12967Sgavin.maltby@oracle.com */ 559*12967Sgavin.maltby@oracle.com scf_handle_t *_scf_handle_create_and_bind(scf_version_t); 560*12967Sgavin.maltby@oracle.com 561*12967Sgavin.maltby@oracle.com /* 562*12967Sgavin.maltby@oracle.com * _smf_refresh_all_instances() 563*12967Sgavin.maltby@oracle.com * refresh all intances of a service 564*12967Sgavin.maltby@oracle.com * return SCF_SUCCESS or SCF_FAILED on _PERMISSION_DENIED, _BACKEND_ACCESS 565*12967Sgavin.maltby@oracle.com * or _BACKEND_READONLY. 566*12967Sgavin.maltby@oracle.com */ 567*12967Sgavin.maltby@oracle.com int _smf_refresh_all_instances(scf_service_t *); 568*12967Sgavin.maltby@oracle.com 569*12967Sgavin.maltby@oracle.com /* 570*12967Sgavin.maltby@oracle.com * _scf_get_fma_notify_params() 571*12967Sgavin.maltby@oracle.com * Specialized fuction to get fma notifitation parameters 572*12967Sgavin.maltby@oracle.com */ 573*12967Sgavin.maltby@oracle.com int _scf_get_fma_notify_params(const char *, nvlist_t *, int); 574*12967Sgavin.maltby@oracle.com 575*12967Sgavin.maltby@oracle.com /* 576*12967Sgavin.maltby@oracle.com * _scf_get_svc_notify_params() 577*12967Sgavin.maltby@oracle.com * Specialized function to get SMF state transition notification parameters 578*12967Sgavin.maltby@oracle.com */ 579*12967Sgavin.maltby@oracle.com int _scf_get_svc_notify_params(const char *, nvlist_t *, int32_t, int, int); 580*12967Sgavin.maltby@oracle.com 581*12967Sgavin.maltby@oracle.com /* 582*12967Sgavin.maltby@oracle.com * _scf_notify_get_params() 583*12967Sgavin.maltby@oracle.com * Specialized function to get notification parametes from a pg into an 584*12967Sgavin.maltby@oracle.com * nvlist_t 585*12967Sgavin.maltby@oracle.com */ 586*12967Sgavin.maltby@oracle.com int _scf_notify_get_params(scf_propertygroup_t *, nvlist_t *); 587*12967Sgavin.maltby@oracle.com 588*12967Sgavin.maltby@oracle.com #define SCF_NOTIFY_PARAMS_SOURCE_NAME ((const char *)"preference_source") 589*12967Sgavin.maltby@oracle.com 5900Sstevel@tonic-gate #ifdef __cplusplus 5910Sstevel@tonic-gate } 5920Sstevel@tonic-gate #endif 5930Sstevel@tonic-gate 5940Sstevel@tonic-gate #endif /* _LIBSCF_PRIV_H */ 595