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