xref: /illumos-gate/usr/src/lib/libscf/inc/libscf.h (revision 2aa8db5932a99c01d32f2aea7dbbf15b4898169b)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Copyright 2016 RackTop Systems.
25  * Copyright 2020 Joyent, Inc.
26  * Copyright 2026 Oxide Computer Company
27  */
28 
29 #ifndef	_LIBSCF_H
30 #define	_LIBSCF_H
31 
32 
33 #include <stddef.h>
34 #include <libnvpair.h>
35 
36 #ifndef NATIVE_BUILD
37 #include <sys/secflags.h>
38 #endif	/* NATIVE_BUILD */
39 #include <sys/types.h>
40 
41 #ifdef	__cplusplus
42 extern "C" {
43 #endif
44 
45 typedef unsigned long scf_version_t;
46 #define	SCF_VERSION		1UL
47 
48 /*
49  * Opaque structures
50  */
51 typedef struct scf_handle scf_handle_t;
52 typedef struct scf_scope scf_scope_t;
53 typedef struct scf_service scf_service_t;
54 typedef struct scf_instance scf_instance_t;
55 typedef struct scf_propertygroup scf_propertygroup_t;
56 typedef struct scf_property scf_property_t;
57 
58 typedef struct scf_snapshot scf_snapshot_t;
59 typedef struct scf_snaplevel scf_snaplevel_t;
60 
61 typedef struct scf_transaction scf_transaction_t;
62 typedef struct scf_transaction_entry scf_transaction_entry_t;
63 typedef struct scf_value scf_value_t;
64 
65 typedef struct scf_iter scf_iter_t;
66 
67 typedef struct scf_pg_tmpl scf_pg_tmpl_t;
68 typedef struct scf_prop_tmpl scf_prop_tmpl_t;
69 typedef struct scf_tmpl_errors scf_tmpl_errors_t;
70 
71 typedef struct scf_simple_app_props scf_simple_app_props_t;
72 typedef struct scf_simple_prop scf_simple_prop_t;
73 
74 /*
75  * Types
76  */
77 typedef enum {
78 	SCF_TYPE_INVALID = 0,
79 
80 	SCF_TYPE_BOOLEAN,
81 	SCF_TYPE_COUNT,
82 	SCF_TYPE_INTEGER,
83 	SCF_TYPE_TIME,
84 	SCF_TYPE_ASTRING,
85 	SCF_TYPE_OPAQUE,
86 
87 	SCF_TYPE_USTRING = 100,
88 
89 	SCF_TYPE_URI = 200,
90 	SCF_TYPE_FMRI,
91 
92 	SCF_TYPE_HOST = 300,
93 	SCF_TYPE_HOSTNAME,
94 	SCF_TYPE_NET_ADDR_V4,
95 	SCF_TYPE_NET_ADDR_V6,
96 	SCF_TYPE_NET_ADDR
97 } scf_type_t;
98 
99 /*
100  * Values returned by scf_type_to_string
101  */
102 #define	SCF_TYPE_STRING_BOOLEAN		"boolean"
103 #define	SCF_TYPE_STRING_COUNT		"count"
104 #define	SCF_TYPE_STRING_INTEGER		"integer"
105 #define	SCF_TYPE_STRING_TIME		"time"
106 #define	SCF_TYPE_STRING_ASTRING		"astring"
107 #define	SCF_TYPE_STRING_OPAQUE		"opaque"
108 #define	SCF_TYPE_STRING_USTRING		"ustring"
109 #define	SCF_TYPE_STRING_URI		"uri"
110 #define	SCF_TYPE_STRING_FMRI		"fmri"
111 #define	SCF_TYPE_STRING_HOST		"host"
112 #define	SCF_TYPE_STRING_HOSTNAME	"hostname"
113 #define	SCF_TYPE_STRING_NET_ADDR	"net_address"
114 #define	SCF_TYPE_STRING_NET_ADDR_V4	"net_address_v4"
115 #define	SCF_TYPE_STRING_NET_ADDR_V6	"net_address_v6"
116 
117 typedef struct scf_time {
118 	int64_t		t_seconds;
119 	int32_t		t_ns;
120 } scf_time_t;
121 
122 /*
123  * There is no explicit initializer for this structure.  Functions
124  * which set or populate this structure assume that it is either
125  * uninitialized or destroyed.
126  */
127 typedef struct scf_values {
128 	scf_type_t		value_type;
129 	void			*reserved;	/* reserved for future use */
130 	int			value_count;
131 	char			**values_as_strings;
132 	union {
133 		uint64_t	*v_count;
134 		uint8_t		*v_boolean;
135 		int64_t		*v_integer;
136 		char		**v_astring;
137 		char		**v_ustring;
138 		char		**v_opaque;
139 		scf_time_t	*v_time;
140 	} values;
141 } scf_values_t;
142 
143 typedef struct scf_count_ranges {
144 	int		scr_num_ranges;
145 	uint64_t	*scr_min;
146 	uint64_t	*scr_max;
147 } scf_count_ranges_t;
148 
149 typedef struct scf_int_ranges {
150 	int		sir_num_ranges;
151 	int64_t		*sir_min;
152 	int64_t		*sir_max;
153 } scf_int_ranges_t;
154 
155 /*
156  * Return codes
157  */
158 #define	SCF_SUCCESS			0
159 #define	SCF_COMPLETE			1
160 #define	SCF_FAILED			-1
161 
162 typedef enum scf_error {
163 	SCF_ERROR_NONE = 1000,		/* no error */
164 	SCF_ERROR_NOT_BOUND,		/* handle not bound */
165 	SCF_ERROR_NOT_SET,		/* cannot use unset argument */
166 	SCF_ERROR_NOT_FOUND,		/* nothing of that name found */
167 	SCF_ERROR_TYPE_MISMATCH,	/* type does not match value */
168 	SCF_ERROR_IN_USE,		/* cannot modify while in-use */
169 	SCF_ERROR_CONNECTION_BROKEN,	/* repository connection gone */
170 	SCF_ERROR_INVALID_ARGUMENT,	/* bad argument */
171 	SCF_ERROR_NO_MEMORY,		/* no memory available */
172 	SCF_ERROR_CONSTRAINT_VIOLATED,	/* required constraint not met */
173 	SCF_ERROR_EXISTS,		/* object already exists */
174 	SCF_ERROR_NO_SERVER,		/* repository server unavailable */
175 	SCF_ERROR_NO_RESOURCES,		/* server has insufficient resources */
176 	SCF_ERROR_PERMISSION_DENIED,	/* insufficient privileges for action */
177 	SCF_ERROR_BACKEND_ACCESS,	/* backend refused access */
178 	SCF_ERROR_HANDLE_MISMATCH,	/* mismatched SCF handles */
179 	SCF_ERROR_HANDLE_DESTROYED,	/* object bound to destroyed handle */
180 	SCF_ERROR_VERSION_MISMATCH,	/* incompatible SCF version */
181 	SCF_ERROR_BACKEND_READONLY,	/* backend is read-only */
182 	SCF_ERROR_DELETED,		/* object has been deleted */
183 	SCF_ERROR_TEMPLATE_INVALID,	/* template data is invalid */
184 
185 	SCF_ERROR_CALLBACK_FAILED = 1080, /* user callback function failed */
186 
187 	SCF_ERROR_INTERNAL = 1101	/* internal error */
188 } scf_error_t;
189 
190 /*
191  * This enum MUST be kept in sync with
192  * struct _scf_tmpl_error_desc em_desc() in scf_tmpl.c
193  */
194 typedef enum scf_tmpl_error_type {
195 	SCF_TERR_MISSING_PG,		/* property group missing */
196 	SCF_TERR_WRONG_PG_TYPE,		/* property group type incorrect */
197 	SCF_TERR_MISSING_PROP,		/* missing required property */
198 	SCF_TERR_WRONG_PROP_TYPE,	/* property type incorrect */
199 	SCF_TERR_CARDINALITY_VIOLATION,	/* wrong number of values */
200 	SCF_TERR_VALUE_CONSTRAINT_VIOLATED, /* constraint violated for value */
201 	SCF_TERR_RANGE_VIOLATION,	/* value violated specified range */
202 	SCF_TERR_PG_REDEFINE,		/* global or restarter pg_pattern */
203 					/* redefined by the instance */
204 	SCF_TERR_PROP_TYPE_MISMATCH,	/* property and value type mismatch */
205 	SCF_TERR_VALUE_OUT_OF_RANGE,	/* value is out of range in template */
206 	SCF_TERR_INVALID_VALUE,		/* value is not valid for the */
207 					/* template */
208 	SCF_TERR_PG_PATTERN_CONFLICT,	/* pg_pattern conflicts with higher */
209 					/* level definition */
210 	SCF_TERR_PROP_PATTERN_CONFLICT,	/* prop_pattern conflicts with higher */
211 					/* level definition */
212 	SCF_TERR_GENERAL_REDEFINE,	/* global or restarter template */
213 					/* redefined */
214 	SCF_TERR_INCLUDE_VALUES,	/* No supporting constraints or */
215 					/* values for include_values */
216 	SCF_TERR_PG_PATTERN_INCOMPLETE,	/* Required pg_pattern is missing */
217 					/* name or type attribute. */
218 	SCF_TERR_PROP_PATTERN_INCOMPLETE    /* Required prop_pattern is */
219 					    /* missing a type attribute. */
220 } scf_tmpl_error_type_t;
221 
222 typedef struct scf_tmpl_error scf_tmpl_error_t;
223 
224 /*
225  * This unfortunately needs to be public, because consumers of librestart must
226  * deal with it
227  */
228 typedef struct {
229 #ifndef NATIVE_BUILD
230 	secflagdelta_t ss_default;
231 	secflagdelta_t ss_lower;
232 	secflagdelta_t ss_upper;
233 #else
234 	/*
235 	 * This is never used, but is necessary for bootstrapping.
236 	 * Not even the size matters.
237 	 */
238 	void *ss_default;
239 	void *ss_lower;
240 	void *ss_upper;
241 #endif /* NATIVE_BUILD */
242 } scf_secflags_t;
243 
244 /*
245  * scf_tmpl_strerror() human readable flag
246  */
247 #define	SCF_TMPL_STRERROR_HUMAN	0x1
248 
249 /*
250  * Standard services
251  */
252 #define	SCF_SERVICE_CONFIGD	"svc:/system/svc/repository:default"
253 #define	SCF_INSTANCE_GLOBAL	"svc:/system/svc/global:default"
254 #define	SCF_SERVICE_GLOBAL	"svc:/system/svc/global"
255 #define	SCF_SERVICE_STARTD	"svc:/system/svc/restarter:default"
256 #define	SCF_INSTANCE_EMI	"svc:/system/early-manifest-import:default"
257 #define	SCF_INSTANCE_FS_MINIMAL	"svc:/system/filesystem/minimal:default"
258 #define	SCF_INSTANCE_MI		"svc:/system/manifest-import:default"
259 
260 /*
261  * Major milestones
262  */
263 #define	SCF_MILESTONE_SINGLE_USER	"svc:/milestone/single-user:default"
264 #define	SCF_MILESTONE_MULTI_USER	"svc:/milestone/multi-user:default"
265 #define	SCF_MILESTONE_MULTI_USER_SERVER \
266 	"svc:/milestone/multi-user-server:default"
267 
268 /*
269  * standard scope names
270  */
271 #define	SCF_SCOPE_LOCAL			"localhost"
272 
273 /*
274  * Property group types
275  */
276 #define	SCF_GROUP_APPLICATION		"application"
277 #define	SCF_GROUP_FRAMEWORK		"framework"
278 #define	SCF_GROUP_DEPENDENCY		"dependency"
279 #define	SCF_GROUP_METHOD		"method"
280 #define	SCF_GROUP_TEMPLATE		"template"
281 #define	SCF_GROUP_TEMPLATE_PG_PATTERN	"template_pg_pattern"
282 #define	SCF_GROUP_TEMPLATE_PROP_PATTERN	"template_prop_pattern"
283 
284 /*
285  * Dependency types
286  */
287 #define	SCF_DEP_REQUIRE_ALL		"require_all"
288 #define	SCF_DEP_REQUIRE_ANY		"require_any"
289 #define	SCF_DEP_EXCLUDE_ALL		"exclude_all"
290 #define	SCF_DEP_OPTIONAL_ALL		"optional_all"
291 
292 #define	SCF_DEP_RESET_ON_ERROR		"error"
293 #define	SCF_DEP_RESET_ON_RESTART	"restart"
294 #define	SCF_DEP_RESET_ON_REFRESH	"refresh"
295 #define	SCF_DEP_RESET_ON_NONE		"none"
296 
297 /*
298  * Standard property group names
299  */
300 #define	SCF_PG_GENERAL			"general"
301 #define	SCF_PG_GENERAL_OVR		"general_ovr"
302 #define	SCF_PG_RESTARTER		"restarter"
303 #define	SCF_PG_RESTARTER_ACTIONS	"restarter_actions"
304 #define	SCF_PG_METHOD_CONTEXT		"method_context"
305 #define	SCF_PG_APP_DEFAULT		"application"
306 #define	SCF_PG_DEPENDENTS		"dependents"
307 #define	SCF_PG_OPTIONS			"options"
308 #define	SCF_PG_OPTIONS_OVR		"options_ovr"
309 #define	SCF_PG_STARTD			"startd"
310 #define	SCF_PG_STARTD_PRIVATE		"svc-startd-private"
311 #define	SCF_PG_DEATHROW			"deathrow"
312 #define	SCF_PG_MANIFESTFILES		"manifestfiles"
313 
314 /*
315  * Template property group names and prefixes
316  */
317 #define	SCF_PG_TM_COMMON_NAME		"tm_common_name"
318 #define	SCF_PG_TM_DESCRIPTION		"tm_description"
319 
320 #define	SCF_PG_TM_MAN_PREFIX		"tm_man_"
321 #define	SCF_PG_TM_DOC_PREFIX		"tm_doc_"
322 
323 /*
324  * Standard property names
325  */
326 #define	SCF_PROPERTY_ACTIVE_POSTFIX		"active"
327 #define	SCF_PROPERTY_AUX_STATE			"auxiliary_state"
328 #define	SCF_PROPERTY_AUX_FMRI			"auxiliary_fmri"
329 #define	SCF_PROPERTY_AUX_TTY			"auxiliary_tty"
330 #define	SCF_PROPERTY_COMMENT			"comment"
331 #define	SCF_PROPERTY_CONTRACT			"contract"
332 #define	SCF_PROPERTY_COREFILE_PATTERN		"corefile_pattern"
333 #define	SCF_PROPERTY_DEGRADED			"degraded"
334 #define	SCF_PROPERTY_DEGRADE_IMMEDIATE		"degrade_immediate"
335 #define	SCF_PROPERTY_DODUMP			"do_dump"
336 #define	SCF_PROPERTY_DURATION			"duration"
337 #define	SCF_PROPERTY_ENABLED			"enabled"
338 #define	SCF_PROPERTY_DEATHROW			"deathrow"
339 #define	SCF_PROPERTY_ENTITY_STABILITY		"entity_stability"
340 #define	SCF_PROPERTY_ENTITIES			"entities"
341 #define	SCF_PROPERTY_EXEC			"exec"
342 #define	SCF_PROPERTY_GROUP			"group"
343 #define	SCF_PROPERTY_GROUPING			"grouping"
344 #define	SCF_PROPERTY_IGNORE			"ignore_error"
345 #define	SCF_PROPERTY_INTERNAL_SEPARATORS	"internal_separators"
346 #define	SCF_PROPERTY_LIMIT_PRIVILEGES		"limit_privileges"
347 #define	SCF_PROPERTY_MAINT_OFF			"maint_off"
348 #define	SCF_PROPERTY_MAINT_ON			"maint_on"
349 #define	SCF_PROPERTY_MAINT_ON_IMMEDIATE		"maint_on_immediate"
350 #define	SCF_PROPERTY_MAINT_ON_IMMTEMP		"maint_on_immtemp"
351 #define	SCF_PROPERTY_MAINT_ON_TEMPORARY		"maint_on_temporary"
352 #define	SCF_PROPERTY_METHOD_PID			"method_pid"
353 #define	SCF_PROPERTY_MILESTONE			"milestone"
354 #define	SCF_PROPERTY_NEED_SESSION		"need_session"
355 #define	SCF_PROPERTY_NEXT_STATE			"next_state"
356 #define	SCF_PROPERTY_PACKAGE			"package"
357 #define	SCF_PROPERTY_PRIVILEGES			"privileges"
358 #define	SCF_PROPERTY_PROFILE			"profile"
359 #define	SCF_PROPERTY_PROJECT			"project"
360 #define	SCF_PROPERTY_REFRESH			"refresh"
361 #define	SCF_PROPERTY_RESOURCE_POOL		"resource_pool"
362 #define	SCF_PROPERTY_ENVIRONMENT		"environment"
363 #define	SCF_PROPERTY_RESTART			"restart"
364 #define	SCF_PROPERTY_RESTARTER			"restarter"
365 #define	SCF_PROPERTY_RESTART_INTERVAL		"restart_interval"
366 #define	SCF_PROPERTY_RESTART_ON			"restart_on"
367 #define	SCF_PROPERTY_RESTORE			"restore"
368 #define	SCF_PROPERTY_SECFLAGS			"security_flags"
369 #define	SCF_PROPERTY_SINGLE_INSTANCE		"single_instance"
370 #define	SCF_PROPERTY_START_METHOD_TIMESTAMP	"start_method_timestamp"
371 #define	SCF_PROPERTY_START_METHOD_WAITSTATUS	"start_method_waitstatus"
372 #define	SCF_PROPERTY_START_PID			"start_pid"
373 #define	SCF_PROPERTY_STATE			"state"
374 #define	SCF_PROPERTY_STABILITY			"stability"
375 #define	SCF_PROPERTY_STATE_TIMESTAMP		"state_timestamp"
376 #define	SCF_PROPERTY_SUPP_GROUPS		"supp_groups"
377 #define	SCF_PROPERTY_TIMEOUT			"timeout_seconds"
378 #define	SCF_PROPERTY_TIMEOUT_RETRY		"timeout_retry"
379 #define	SCF_PROPERTY_TRANSIENT_CONTRACT		"transient_contract"
380 #define	SCF_PROPERTY_TYPE			"type"
381 #define	SCF_PROPERTY_USE_PROFILE		"use_profile"
382 #define	SCF_PROPERTY_USER			"user"
383 #define	SCF_PROPERTY_UTMPX_PREFIX		"utmpx_prefix"
384 #define	SCF_PROPERTY_WORKING_DIRECTORY		"working_directory"
385 
386 /*
387  * Template property names
388  */
389 #define	SCF_PROPERTY_TM_CARDINALITY_MIN		"cardinality_min"
390 #define	SCF_PROPERTY_TM_CARDINALITY_MAX		"cardinality_max"
391 #define	SCF_PROPERTY_TM_CHOICES_INCLUDE_VALUES	"choices_include_values"
392 #define	SCF_PROPERTY_TM_CHOICES_NAME		"choices_name"
393 #define	SCF_PROPERTY_TM_CHOICES_RANGE		"choices_range"
394 #define	SCF_PROPERTY_TM_CONSTRAINT_NAME		"constraint_name"
395 #define	SCF_PROPERTY_TM_CONSTRAINT_RANGE	"constraint_range"
396 #define	SCF_PROPERTY_TM_MANPATH			"manpath"
397 #define	SCF_PROPERTY_TM_NAME			"name"
398 #define	SCF_PROPERTY_TM_PG_PATTERN		"pg_pattern"
399 #define	SCF_PROPERTY_TM_REQUIRED		"required"
400 #define	SCF_PROPERTY_TM_SECTION			"section"
401 #define	SCF_PROPERTY_TM_TARGET			"target"
402 #define	SCF_PROPERTY_TM_TITLE			"title"
403 #define	SCF_PROPERTY_TM_TYPE			"type"
404 #define	SCF_PROPERTY_TM_URI			"uri"
405 #define	SCF_PROPERTY_TM_VALUE_PREFIX		"value_"
406 #define	SCF_PROPERTY_TM_VALUES_NAME		"values_name"
407 #define	SCF_PROPERTY_TM_VISIBILITY		"visibility"
408 #define	SCF_PROPERTY_TM_COMMON_NAME_PREFIX	"common_name_"
409 #define	SCF_PROPERTY_TM_DESCRIPTION_PREFIX	"description_"
410 #define	SCF_PROPERTY_TM_UNITS_PREFIX		"units_"
411 
412 /*
413  * Templates wildcard string
414  */
415 #define	SCF_TMPL_WILDCARD		"*"
416 
417 /*
418  * Strings used by restarters for state and next_state properties.
419  * MAX_SCF_STATE_STRING holds the max length of a state string, including the
420  * terminating null.
421  */
422 
423 #define	MAX_SCF_STATE_STRING_SZ		14
424 
425 #define	SCF_STATE_STRING_NONE		"none"
426 #define	SCF_STATE_STRING_UNINIT		"uninitialized"
427 #define	SCF_STATE_STRING_MAINT		"maintenance"
428 #define	SCF_STATE_STRING_OFFLINE	"offline"
429 #define	SCF_STATE_STRING_DISABLED	"disabled"
430 #define	SCF_STATE_STRING_ONLINE		"online"
431 #define	SCF_STATE_STRING_DEGRADED	"degraded"
432 #define	SCF_STATE_STRING_LEGACY		"legacy_run"
433 
434 #define	SCF_STATE_UNINIT		0x00000001
435 #define	SCF_STATE_MAINT			0x00000002
436 #define	SCF_STATE_OFFLINE		0x00000004
437 #define	SCF_STATE_DISABLED		0x00000008
438 #define	SCF_STATE_ONLINE		0x00000010
439 #define	SCF_STATE_DEGRADED		0x00000020
440 #define	SCF_STATE_ALL			0x0000003F
441 
442 /*
443  * software fma svc-transition class
444  */
445 #define	SCF_NOTIFY_PARAMS_VERSION	0X0
446 #define	SCF_NOTIFY_NAME_FMRI		"fmri"
447 #define	SCF_NOTIFY_NAME_VERSION		"version"
448 #define	SCF_NOTIFY_NAME_TSET		"tset"
449 #define	SCF_NOTIFY_PG_POSTFIX		"fmnotify"
450 #define	SCF_NOTIFY_PARAMS		"notify-params"
451 #define	SCF_NOTIFY_PARAMS_INST		"svc:/system/fm/notify-params:default"
452 #define	SCF_SVC_TRANSITION_CLASS	"ireport.os.smf.state-transition"
453 #define	SCF_NOTIFY_PARAMS_PG_TYPE	"notify_params"
454 
455 /*
456  * Useful transition macros
457  */
458 #define	SCF_TRANS_SHIFT_INITIAL_STATE(s)	((s) << 16)
459 #define	SCF_TRANSITION_ALL \
460 	(SCF_TRANS_SHIFT_INITIAL_STATE(SCF_STATE_ALL) | SCF_STATE_ALL)
461 #define	SCF_TRANS(f, t)	(SCF_TRANS_SHIFT_INITIAL_STATE(f) | (t))
462 #define	SCF_TRANS_VALID(t)	(!((t) & ~SCF_TRANSITION_ALL))
463 #define	SCF_TRANS_INITIAL_STATE(t)	((t) >> 16 & SCF_STATE_ALL)
464 #define	SCF_TRANS_FINAL_STATE(t)	((t) & SCF_STATE_ALL)
465 
466 /*
467  * Prefixes for states in state transition notification
468  */
469 #define	SCF_STN_PREFIX_FROM		"from-"
470 #define	SCF_STN_PREFIX_TO		"to-"
471 
472 #define	SCF_PG_FLAG_NONPERSISTENT	0x1
473 
474 #define	SCF_TRACE_LIBRARY		0x1
475 #define	SCF_TRACE_DAEMON		0x2
476 
477 #define	SMF_IMMEDIATE			0x1
478 #define	SMF_TEMPORARY			0x2
479 #define	SMF_AT_NEXT_BOOT		0x4
480 
481 scf_error_t scf_error(void);
482 const char *scf_strerror(scf_error_t);
483 
484 ssize_t scf_limit(uint32_t code);
485 #define	SCF_LIMIT_MAX_NAME_LENGTH	-2000U
486 #define	SCF_LIMIT_MAX_VALUE_LENGTH	-2001U
487 #define	SCF_LIMIT_MAX_PG_TYPE_LENGTH	-2002U
488 #define	SCF_LIMIT_MAX_FMRI_LENGTH	-2003U
489 
490 
491 #define	SCF_COMMENT_MAX_LENGTH		(1024)
492 
493 scf_handle_t *scf_handle_create(scf_version_t);
494 
495 int scf_handle_decorate(scf_handle_t *, const char *, scf_value_t *);
496 #define	SCF_DECORATE_CLEAR	((scf_value_t *)0)
497 
498 int scf_handle_bind(scf_handle_t *);
499 int scf_handle_unbind(scf_handle_t *);
500 void scf_handle_destroy(scf_handle_t *);
501 
502 int scf_type_base_type(scf_type_t type, scf_type_t *out);
503 const char *scf_type_to_string(scf_type_t);
504 scf_type_t scf_string_to_type(const char *);
505 
506 /* values */
507 scf_value_t *scf_value_create(scf_handle_t *);
508 scf_handle_t *scf_value_handle(const scf_value_t *);
509 void scf_value_destroy(scf_value_t *);
510 
511 scf_type_t scf_value_base_type(const scf_value_t *);
512 scf_type_t scf_value_type(const scf_value_t *);
513 int scf_value_is_type(const scf_value_t *, scf_type_t);
514 
515 void scf_value_reset(scf_value_t *);
516 
517 int scf_value_get_boolean(const scf_value_t *, uint8_t *);
518 int scf_value_get_count(const scf_value_t *, uint64_t *);
519 int scf_value_get_integer(const scf_value_t *, int64_t *);
520 int scf_value_get_time(const scf_value_t *, int64_t *, int32_t *);
521 ssize_t scf_value_get_astring(const scf_value_t *, char *, size_t);
522 ssize_t scf_value_get_ustring(const scf_value_t *, char *, size_t);
523 ssize_t scf_value_get_opaque(const scf_value_t *, void *, size_t);
524 
525 void scf_value_set_boolean(scf_value_t *, uint8_t);
526 void scf_value_set_count(scf_value_t *, uint64_t);
527 void scf_value_set_integer(scf_value_t *, int64_t);
528 int scf_value_set_time(scf_value_t *, int64_t, int32_t);
529 int scf_value_set_astring(scf_value_t *, const char *);
530 int scf_value_set_ustring(scf_value_t *, const char *);
531 int scf_value_set_opaque(scf_value_t *, const void *, size_t);
532 
533 ssize_t scf_value_get_as_string(const scf_value_t *, char *, size_t);
534 ssize_t scf_value_get_as_string_typed(const scf_value_t *, scf_type_t,
535     char *, size_t);
536 int scf_value_set_from_string(scf_value_t *, scf_type_t, const char *);
537 
538 scf_iter_t *scf_iter_create(scf_handle_t *);
539 scf_handle_t *scf_iter_handle(const scf_iter_t *);
540 void scf_iter_reset(scf_iter_t *);
541 void scf_iter_destroy(scf_iter_t *);
542 
543 int scf_iter_handle_scopes(scf_iter_t *, const scf_handle_t *);
544 int scf_iter_scope_services(scf_iter_t *, const scf_scope_t *);
545 int scf_iter_service_instances(scf_iter_t *, const scf_service_t *);
546 int scf_iter_service_pgs(scf_iter_t *, const scf_service_t *);
547 int scf_iter_instance_pgs(scf_iter_t *, const scf_instance_t *);
548 int scf_iter_instance_pgs_composed(scf_iter_t *, const scf_instance_t *,
549     const scf_snapshot_t *);
550 int scf_iter_service_pgs_typed(scf_iter_t *, const scf_service_t *,
551     const char *);
552 int scf_iter_instance_pgs_typed(scf_iter_t *, const scf_instance_t *,
553     const char *);
554 int scf_iter_instance_pgs_typed_composed(scf_iter_t *, const scf_instance_t *,
555     const scf_snapshot_t *, const char *);
556 int scf_iter_snaplevel_pgs(scf_iter_t *, const scf_snaplevel_t *);
557 int scf_iter_snaplevel_pgs_typed(scf_iter_t *, const scf_snaplevel_t *,
558     const char *);
559 int scf_iter_instance_snapshots(scf_iter_t *, const scf_instance_t *);
560 int scf_iter_pg_properties(scf_iter_t *, const scf_propertygroup_t *);
561 int scf_iter_property_values(scf_iter_t *, const scf_property_t *);
562 
563 int scf_iter_next_scope(scf_iter_t *, scf_scope_t *);
564 int scf_iter_next_service(scf_iter_t *, scf_service_t *);
565 int scf_iter_next_instance(scf_iter_t *, scf_instance_t *);
566 int scf_iter_next_pg(scf_iter_t *, scf_propertygroup_t *);
567 int scf_iter_next_property(scf_iter_t *, scf_property_t *);
568 int scf_iter_next_snapshot(scf_iter_t *, scf_snapshot_t *);
569 int scf_iter_next_value(scf_iter_t *, scf_value_t *);
570 
571 scf_scope_t *scf_scope_create(scf_handle_t *);
572 scf_handle_t *scf_scope_handle(const scf_scope_t *);
573 
574 /* XXX eventually remove this */
575 #define	scf_handle_get_local_scope(h, s) \
576 	scf_handle_get_scope((h), SCF_SCOPE_LOCAL, (s))
577 
578 int scf_handle_get_scope(scf_handle_t *, const char *, scf_scope_t *);
579 void scf_scope_destroy(scf_scope_t *);
580 ssize_t scf_scope_get_name(const scf_scope_t *, char *, size_t);
581 
582 ssize_t scf_scope_to_fmri(const scf_scope_t *, char *, size_t);
583 
584 scf_service_t *scf_service_create(scf_handle_t *);
585 scf_handle_t *scf_service_handle(const scf_service_t *);
586 void scf_service_destroy(scf_service_t *);
587 int scf_scope_get_parent(const scf_scope_t *, scf_scope_t *);
588 ssize_t scf_service_get_name(const scf_service_t *, char *, size_t);
589 ssize_t scf_service_to_fmri(const scf_service_t *, char *, size_t);
590 int scf_service_get_parent(const scf_service_t *, scf_scope_t *);
591 int scf_scope_get_service(const scf_scope_t *, const char *, scf_service_t *);
592 int scf_scope_add_service(const scf_scope_t *, const char *, scf_service_t *);
593 int scf_service_delete(scf_service_t *);
594 
595 scf_instance_t *scf_instance_create(scf_handle_t *);
596 scf_handle_t *scf_instance_handle(const scf_instance_t *);
597 void scf_instance_destroy(scf_instance_t *);
598 ssize_t scf_instance_get_name(const scf_instance_t *, char *, size_t);
599 ssize_t scf_instance_to_fmri(const scf_instance_t *, char *, size_t);
600 int scf_service_get_instance(const scf_service_t *, const char *,
601     scf_instance_t *);
602 int scf_service_add_instance(const scf_service_t *, const char *,
603     scf_instance_t *);
604 int scf_instance_delete(scf_instance_t *);
605 
606 scf_snapshot_t *scf_snapshot_create(scf_handle_t *);
607 scf_handle_t *scf_snapshot_handle(const scf_snapshot_t *);
608 void scf_snapshot_destroy(scf_snapshot_t *);
609 ssize_t scf_snapshot_get_name(const scf_snapshot_t *, char *, size_t);
610 int scf_snapshot_get_parent(const scf_snapshot_t *, scf_instance_t *);
611 int scf_instance_get_snapshot(const scf_instance_t *, const char *,
612     scf_snapshot_t *);
613 int scf_snapshot_update(scf_snapshot_t *);
614 
615 scf_snaplevel_t *scf_snaplevel_create(scf_handle_t *);
616 scf_handle_t *scf_snaplevel_handle(const scf_snaplevel_t *);
617 void scf_snaplevel_destroy(scf_snaplevel_t *);
618 int scf_snaplevel_get_parent(const scf_snaplevel_t *, scf_snapshot_t *);
619 ssize_t scf_snaplevel_get_scope_name(const scf_snaplevel_t *, char *, size_t);
620 ssize_t scf_snaplevel_get_service_name(const scf_snaplevel_t *, char *, size_t);
621 ssize_t scf_snaplevel_get_instance_name(const scf_snaplevel_t *, char *,
622     size_t);
623 int scf_snaplevel_get_pg(const scf_snaplevel_t *, const char *,
624     scf_propertygroup_t *pg);
625 int scf_snapshot_get_base_snaplevel(const scf_snapshot_t *, scf_snaplevel_t *);
626 int scf_snaplevel_get_next_snaplevel(const scf_snaplevel_t *,
627     scf_snaplevel_t *);
628 
629 scf_propertygroup_t *scf_pg_create(scf_handle_t *);
630 scf_handle_t *scf_pg_handle(const scf_propertygroup_t *);
631 void scf_pg_destroy(scf_propertygroup_t *);
632 ssize_t scf_pg_to_fmri(const scf_propertygroup_t *,  char *, size_t);
633 ssize_t scf_pg_get_name(const scf_propertygroup_t *, char *, size_t);
634 ssize_t scf_pg_get_type(const scf_propertygroup_t *, char *, size_t);
635 int scf_pg_get_flags(const scf_propertygroup_t *, uint32_t *);
636 int scf_pg_get_parent_service(const scf_propertygroup_t *, scf_service_t *);
637 int scf_pg_get_parent_instance(const scf_propertygroup_t *, scf_instance_t *);
638 int scf_pg_get_parent_snaplevel(const scf_propertygroup_t *, scf_snaplevel_t *);
639 int scf_service_get_pg(const scf_service_t *, const char *,
640     scf_propertygroup_t *);
641 int scf_instance_get_pg(const scf_instance_t *, const char *,
642     scf_propertygroup_t *);
643 int scf_instance_get_pg_composed(const scf_instance_t *, const scf_snapshot_t *,
644     const char *, scf_propertygroup_t *);
645 int scf_service_add_pg(const scf_service_t *,  const char *, const char *,
646     uint32_t, scf_propertygroup_t *);
647 int scf_instance_add_pg(const scf_instance_t *,  const char *, const char *,
648     uint32_t, scf_propertygroup_t *);
649 int scf_pg_delete(scf_propertygroup_t *);
650 
651 int scf_pg_get_underlying_pg(const scf_propertygroup_t *,
652     scf_propertygroup_t *);
653 int scf_instance_get_parent(const scf_instance_t *, scf_service_t *);
654 
655 int scf_pg_update(scf_propertygroup_t *);
656 
657 scf_property_t *scf_property_create(scf_handle_t *);
658 scf_handle_t *scf_property_handle(const scf_property_t *);
659 void scf_property_destroy(scf_property_t *);
660 int scf_property_is_type(const scf_property_t *, scf_type_t);
661 int scf_property_type(const scf_property_t *, scf_type_t *);
662 ssize_t scf_property_get_name(const scf_property_t *, char *, size_t);
663 int scf_property_get_value(const scf_property_t *, scf_value_t *);
664 ssize_t scf_property_to_fmri(const scf_property_t *, char *, size_t);
665 int scf_pg_get_property(const scf_propertygroup_t *,  const char *,
666     scf_property_t *);
667 
668 scf_transaction_t *scf_transaction_create(scf_handle_t *);
669 scf_handle_t *scf_transaction_handle(const scf_transaction_t *);
670 int scf_transaction_start(scf_transaction_t *, scf_propertygroup_t *);
671 void scf_transaction_destroy(scf_transaction_t *);
672 void scf_transaction_destroy_children(scf_transaction_t *);
673 
674 void scf_transaction_reset(scf_transaction_t *);
675 void scf_transaction_reset_all(scf_transaction_t *);
676 
677 int scf_transaction_commit(scf_transaction_t *);
678 
679 scf_transaction_entry_t *scf_entry_create(scf_handle_t *);
680 scf_handle_t *scf_entry_handle(const scf_transaction_entry_t *);
681 void scf_entry_reset(scf_transaction_entry_t *);
682 void scf_entry_destroy(scf_transaction_entry_t *);
683 void scf_entry_destroy_children(scf_transaction_entry_t *);
684 
685 int scf_transaction_property_change(scf_transaction_t *,
686     scf_transaction_entry_t *, const char *, scf_type_t);
687 int scf_transaction_property_delete(scf_transaction_t *,
688     scf_transaction_entry_t *, const char *);
689 int scf_transaction_property_new(scf_transaction_t *,
690     scf_transaction_entry_t *, const char *, scf_type_t);
691 int scf_transaction_property_change_type(scf_transaction_t *,
692     scf_transaction_entry_t *, const char *, scf_type_t);
693 
694 int scf_entry_add_value(scf_transaction_entry_t *, scf_value_t *);
695 
696 int scf_handle_decode_fmri(scf_handle_t *, const char *, scf_scope_t *,
697     scf_service_t *, scf_instance_t *, scf_propertygroup_t *, scf_property_t *,
698     int);
699 #define	SCF_DECODE_FMRI_EXACT			0x00000001
700 #define	SCF_DECODE_FMRI_TRUNCATE		0x00000002
701 #define	SCF_DECODE_FMRI_REQUIRE_INSTANCE	0x00000004
702 #define	SCF_DECODE_FMRI_REQUIRE_NO_INSTANCE	0x00000008
703 
704 ssize_t scf_myname(scf_handle_t *, char *, size_t);
705 
706 /*
707  * Property group template interfaces.
708  */
709 scf_pg_tmpl_t *scf_tmpl_pg_create(scf_handle_t *);
710 void scf_tmpl_pg_destroy(scf_pg_tmpl_t *);
711 void scf_tmpl_pg_reset(scf_pg_tmpl_t *);
712 int scf_tmpl_get_by_pg(scf_propertygroup_t *, scf_pg_tmpl_t *, int);
713 int scf_tmpl_get_by_pg_name(const char *, const char *,
714     const char *, const char *, scf_pg_tmpl_t *, int);
715 int scf_tmpl_iter_pgs(scf_pg_tmpl_t *, const char *, const char *,
716     const char *, int);
717 #define	SCF_PG_TMPL_FLAG_REQUIRED	0x1
718 #define	SCF_PG_TMPL_FLAG_EXACT		0x2
719 #define	SCF_PG_TMPL_FLAG_CURRENT	0x4
720 
721 ssize_t scf_tmpl_pg_name(const scf_pg_tmpl_t *, char **);
722 ssize_t scf_tmpl_pg_common_name(const scf_pg_tmpl_t *, const char *, char **);
723 ssize_t scf_tmpl_pg_description(const scf_pg_tmpl_t *, const char *, char **);
724 ssize_t scf_tmpl_pg_type(const scf_pg_tmpl_t *, char **);
725 
726 ssize_t scf_tmpl_pg_target(const scf_pg_tmpl_t *, char **);
727 #define	SCF_TM_TARGET_ALL		((const char *)"all")
728 #define	SCF_TM_TARGET_DELEGATE		((const char *)"delegate")
729 #define	SCF_TM_TARGET_INSTANCE		((const char *)"instance")
730 #define	SCF_TM_TARGET_THIS		((const char *)"this")
731 
732 int scf_tmpl_pg_required(const scf_pg_tmpl_t *, uint8_t *);
733 
734 /*
735  * Property template interfaces.
736  */
737 scf_prop_tmpl_t *scf_tmpl_prop_create(scf_handle_t *);
738 void scf_tmpl_prop_destroy(scf_prop_tmpl_t *);
739 void scf_tmpl_prop_reset(scf_prop_tmpl_t *);
740 int scf_tmpl_get_by_prop(scf_pg_tmpl_t *, const char *,
741     scf_prop_tmpl_t *, int);
742 int scf_tmpl_iter_props(scf_pg_tmpl_t *, scf_prop_tmpl_t *, int);
743 #define	SCF_PROP_TMPL_FLAG_REQUIRED	0x1
744 
745 ssize_t scf_tmpl_prop_name(const scf_prop_tmpl_t *, char **);
746 int scf_tmpl_prop_type(const scf_prop_tmpl_t *, scf_type_t *);
747 int scf_tmpl_prop_required(const scf_prop_tmpl_t *, uint8_t *);
748 ssize_t scf_tmpl_prop_common_name(const scf_prop_tmpl_t *, const char *,
749     char **);
750 ssize_t scf_tmpl_prop_description(const scf_prop_tmpl_t *, const char *,
751     char **);
752 ssize_t scf_tmpl_prop_units(const scf_prop_tmpl_t *, const char *, char **);
753 int scf_tmpl_prop_cardinality(const scf_prop_tmpl_t *prop, uint64_t *,
754     uint64_t *);
755 int scf_tmpl_prop_internal_seps(const scf_prop_tmpl_t *, scf_values_t *);
756 
757 int scf_tmpl_prop_visibility(const scf_prop_tmpl_t *, uint8_t *);
758 #define	SCF_TMPL_VISIBILITY_HIDDEN		1
759 #define	SCF_TMPL_VISIBILITY_READONLY		2
760 #define	SCF_TMPL_VISIBILITY_READWRITE		3
761 
762 const char *scf_tmpl_visibility_to_string(uint8_t);
763 #define	SCF_TM_VISIBILITY_HIDDEN	((const char *)"hidden")
764 #define	SCF_TM_VISIBILITY_READONLY	((const char *)"readonly")
765 #define	SCF_TM_VISIBILITY_READWRITE	((const char *)"readwrite")
766 
767 int scf_tmpl_value_name_constraints(const scf_prop_tmpl_t *prop,
768     scf_values_t *vals);
769 void scf_count_ranges_destroy(scf_count_ranges_t *);
770 void scf_int_ranges_destroy(scf_int_ranges_t *);
771 int scf_tmpl_value_count_range_constraints(const scf_prop_tmpl_t *,
772     scf_count_ranges_t *);
773 int scf_tmpl_value_int_range_constraints(const scf_prop_tmpl_t *,
774     scf_int_ranges_t *);
775 int scf_tmpl_value_count_range_choices(const scf_prop_tmpl_t *,
776     scf_count_ranges_t *);
777 int scf_tmpl_value_int_range_choices(const scf_prop_tmpl_t *,
778     scf_int_ranges_t *);
779 int scf_tmpl_value_name_choices(const scf_prop_tmpl_t *prop,
780     scf_values_t *vals);
781 
782 void scf_values_destroy(scf_values_t *);
783 
784 ssize_t scf_tmpl_value_common_name(const scf_prop_tmpl_t *, const char *,
785     const char *, char **);
786 ssize_t scf_tmpl_value_description(const scf_prop_tmpl_t *, const char *,
787     const char *, char **);
788 
789 int scf_tmpl_value_in_constraint(const scf_prop_tmpl_t *pt, scf_value_t *value,
790     scf_tmpl_errors_t **errs);
791 
792 /*
793  * Template validation interfaces
794  */
795 int scf_tmpl_validate_fmri(scf_handle_t *, const char *,
796     const char *, scf_tmpl_errors_t **, int);
797 #define	SCF_TMPL_VALIDATE_FLAG_CURRENT	0x1
798 
799 void scf_tmpl_errors_destroy(scf_tmpl_errors_t *errs);
800 scf_tmpl_error_t *scf_tmpl_next_error(scf_tmpl_errors_t *);
801 void scf_tmpl_reset_errors(scf_tmpl_errors_t *errs);
802 int scf_tmpl_strerror(scf_tmpl_error_t *err, char *s, size_t n, int flag);
803 int scf_tmpl_error_source_fmri(const scf_tmpl_error_t *, char **);
804 int scf_tmpl_error_type(const scf_tmpl_error_t *, scf_tmpl_error_type_t *);
805 int scf_tmpl_error_pg_tmpl(const scf_tmpl_error_t *, char **, char **);
806 int scf_tmpl_error_pg(const scf_tmpl_error_t *, char **, char **);
807 int scf_tmpl_error_prop_tmpl(const scf_tmpl_error_t *, char **, char **);
808 int scf_tmpl_error_prop(const scf_tmpl_error_t *, char **, char **);
809 int scf_tmpl_error_value(const scf_tmpl_error_t *, char **);
810 
811 /*
812  * Simplified calls that operate on the service and instance.
813  */
814 int smf_refresh_all_instances(scf_service_t *);
815 int smf_enable_instance_by_instance(scf_instance_t *, int, const char *);
816 int smf_disable_instance_by_instance(scf_instance_t *, int, const char *);
817 int smf_refresh_instance_by_instance(scf_instance_t *);
818 int smf_restart_instance_by_instance(scf_instance_t *);
819 int smf_maintain_instance_by_instance(scf_instance_t *, int);
820 int smf_degrade_instance_by_instance(scf_instance_t *, int);
821 int smf_restore_instance_by_instance(scf_instance_t *);
822 char *smf_get_state_by_instance(scf_instance_t *);
823 
824 /*
825  * Simplified calls
826  */
827 int smf_enable_instance(const char *, int);
828 int smf_disable_instance_with_comment(const char *, int, const char *);
829 int smf_disable_instance(const char *, int);
830 int smf_refresh_instance(const char *);
831 int smf_restart_instance(const char *);
832 int smf_maintain_instance(const char *, int);
833 int smf_degrade_instance(const char *, int);
834 int smf_restore_instance(const char *);
835 char *smf_get_state(const char *);
836 
837 int scf_simple_walk_instances(uint_t, void *,
838     int (*inst_callback)(scf_handle_t *, scf_instance_t *, void *));
839 
840 scf_simple_prop_t *scf_simple_prop_get(scf_handle_t *, const char *,
841     const char *, const char *);
842 void scf_simple_prop_free(scf_simple_prop_t *);
843 scf_simple_app_props_t *scf_simple_app_props_get(scf_handle_t *, const char *);
844 void scf_simple_app_props_free(scf_simple_app_props_t *);
845 const scf_simple_prop_t *scf_simple_app_props_next(
846     const scf_simple_app_props_t *, scf_simple_prop_t *);
847 const scf_simple_prop_t *scf_simple_app_props_search(
848     const scf_simple_app_props_t *, const char *, const char *);
849 ssize_t scf_simple_prop_numvalues(const scf_simple_prop_t *);
850 scf_type_t scf_simple_prop_type(const scf_simple_prop_t *);
851 char *scf_simple_prop_name(const scf_simple_prop_t *);
852 char *scf_simple_prop_pgname(const scf_simple_prop_t *);
853 uint8_t *scf_simple_prop_next_boolean(scf_simple_prop_t *);
854 uint64_t *scf_simple_prop_next_count(scf_simple_prop_t *);
855 int64_t *scf_simple_prop_next_integer(scf_simple_prop_t *);
856 int64_t *scf_simple_prop_next_time(scf_simple_prop_t *, int32_t *);
857 char *scf_simple_prop_next_astring(scf_simple_prop_t *);
858 char *scf_simple_prop_next_ustring(scf_simple_prop_t *);
859 void *scf_simple_prop_next_opaque(scf_simple_prop_t *, size_t *);
860 void scf_simple_prop_next_reset(scf_simple_prop_t *);
861 
862 /*
863  * smf_state_from_string()
864  * return SCF_STATE_* value for the input
865  * -1 on error. String "all" maps to SCF_STATE_ALL macro
866  */
867 int32_t smf_state_from_string(const char *);
868 
869 /*
870  * smf_state_to_string()
871  * return SCF_STATE_STRING* value for the input
872  * NULL on error.
873  */
874 const char *smf_state_to_string(int32_t);
875 
876 /*
877  * Notification interfaces
878  */
879 int smf_notify_set_params(const char *, nvlist_t *);
880 int smf_notify_get_params(nvlist_t **, nvlist_t *);
881 int smf_notify_del_params(const char *, const char *, int32_t);
882 
883 /*
884  * SMF exit status definitions
885  *
886  * The SMF_EXIT_NODAEMON exit status should be used when a method does not
887  * need to run any persistent process. This indicates success, abandons the
888  * contract, and allows dependencies to be met.
889  */
890 #define	SMF_EXIT_OK		  0
891 #define	SMF_EXIT_NODAEMON	 94
892 #define	SMF_EXIT_ERR_FATAL	 95
893 #define	SMF_EXIT_ERR_CONFIG	 96
894 #define	SMF_EXIT_MON_DEGRADE	 97
895 #define	SMF_EXIT_MON_OFFLINE	 98
896 #define	SMF_EXIT_ERR_NOSMF	 99
897 #define	SMF_EXIT_ERR_PERM	100
898 
899 #ifdef	__cplusplus
900 }
901 #endif
902 
903 #endif	/* _LIBSCF_H */
904