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 2006 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 #ifndef _LIBZONECFG_H 28 #define _LIBZONECFG_H 29 30 #pragma ident "%Z%%M% %I% %E% SMI" 31 32 /* 33 * Zone configuration header file. 34 */ 35 36 #ifdef __cplusplus 37 extern "C" { 38 #endif 39 40 /* sys/socket.h is required by net/if.h, which has a constant needed here */ 41 #include <sys/param.h> 42 #include <sys/fstyp.h> 43 #include <sys/mount.h> 44 #include <priv.h> 45 #include <netinet/in.h> 46 #include <sys/socket.h> 47 #include <net/if.h> 48 #include <stdio.h> 49 #include <rctl.h> 50 #include <zone.h> 51 #include <sys/uuid.h> 52 53 #define ZONE_ID_UNDEFINED -1 54 55 #define Z_OK 0 56 #define Z_EMPTY_DOCUMENT 1 /* XML doc root element is null */ 57 #define Z_WRONG_DOC_TYPE 2 /* top-level XML doc element != zone */ 58 #define Z_BAD_PROPERTY 3 /* libxml-level property problem */ 59 #define Z_TEMP_FILE 4 /* problem creating temporary file */ 60 #define Z_SAVING_FILE 5 /* libxml error saving or validating */ 61 #define Z_NO_ENTRY 6 /* no such entry */ 62 #define Z_BOGUS_ZONE_NAME 7 /* illegal zone name */ 63 #define Z_REQD_RESOURCE_MISSING 8 /* required resource missing */ 64 #define Z_REQD_PROPERTY_MISSING 9 /* required property missing */ 65 #define Z_BAD_HANDLE 10 /* bad document handle */ 66 #define Z_NOMEM 11 /* out of memory (like ENOMEM) */ 67 #define Z_INVAL 12 /* invalid argument (like EINVAL) */ 68 #define Z_ACCES 13 /* permission denied (like EACCES) */ 69 #define Z_TOO_BIG 14 /* string won't fit in char array */ 70 #define Z_MISC_FS 15 /* miscellaneous file-system error */ 71 #define Z_NO_ZONE 16 /* no such zone */ 72 #define Z_NO_RESOURCE_TYPE 17 /* no/wrong resource type */ 73 #define Z_NO_RESOURCE_ID 18 /* no/wrong resource id */ 74 #define Z_NO_PROPERTY_TYPE 19 /* no/wrong property type */ 75 #define Z_NO_PROPERTY_ID 20 /* no/wrong property id */ 76 #define Z_BAD_ZONE_STATE 21 /* zone state invalid for given task */ 77 #define Z_INVALID_DOCUMENT 22 /* libxml can't validate against DTD */ 78 #define Z_NAME_IN_USE 23 /* zone name already in use (rename) */ 79 #define Z_NO_SUCH_ID 24 /* delete_index: no old ID */ 80 #define Z_UPDATING_INDEX 25 /* add/modify/delete_index problem */ 81 #define Z_LOCKING_FILE 26 /* problem locking index file */ 82 #define Z_UNLOCKING_FILE 27 /* problem unlocking index file */ 83 #define Z_SYSTEM 28 /* consult errno instead */ 84 #define Z_INSUFFICIENT_SPEC 29 /* resource insufficiently specified */ 85 #define Z_RESOLVED_PATH 34 /* resolved path mismatch */ 86 #define Z_IPV6_ADDR_PREFIX_LEN 35 /* IPv6 address prefix length needed */ 87 #define Z_BOGUS_ADDRESS 36 /* not IPv[4|6] address or host name */ 88 #define Z_PRIV_PROHIBITED 37 /* specified privilege is prohibited */ 89 #define Z_PRIV_REQUIRED 38 /* required privilege is missing */ 90 #define Z_PRIV_UNKNOWN 39 /* specified privilege is unknown */ 91 92 /* 93 * Warning: these are shared with the admin/install consolidation. 94 * Do not insert states between any of the currently defined states, 95 * and any new states must be evaluated for impact on range comparisons. 96 */ 97 #define ZONE_STATE_CONFIGURED 0 98 #define ZONE_STATE_INCOMPLETE 1 99 #define ZONE_STATE_INSTALLED 2 100 #define ZONE_STATE_READY 3 101 #define ZONE_STATE_RUNNING 4 102 #define ZONE_STATE_SHUTTING_DOWN 5 103 #define ZONE_STATE_DOWN 6 104 #define ZONE_STATE_MOUNTED 7 105 106 #define ZONE_STATE_MAXSTRLEN 14 107 108 #define LIBZONECFG_PATH "libzonecfg.so.1" 109 110 #define ZONE_CONFIG_ROOT "/etc/zones" 111 #define ZONE_INDEX_FILE ZONE_CONFIG_ROOT "/index" 112 113 /* The maximum length of the VERSION string in the pkginfo(4) file. */ 114 #define ZONE_PKG_VERSMAX 256 115 116 /* 117 * The integer field expresses the current values on a get. 118 * On a put, it represents the new values if >= 0 or "don't change" if < 0. 119 */ 120 struct zoneent { 121 char zone_name[ZONENAME_MAX]; /* name of the zone */ 122 int zone_state; /* configured | incomplete | installed */ 123 char zone_path[MAXPATHLEN]; /* path to zone storage */ 124 uuid_t zone_uuid; /* unique ID for zone */ 125 char zone_newname[ZONENAME_MAX]; /* for doing renames */ 126 }; 127 128 typedef struct zone_dochandle *zone_dochandle_t; /* opaque handle */ 129 130 typedef uint_t zone_state_t; 131 132 typedef struct zone_fsopt { 133 struct zone_fsopt *zone_fsopt_next; 134 char zone_fsopt_opt[MAX_MNTOPT_STR]; 135 } zone_fsopt_t; 136 137 struct zone_fstab { 138 char zone_fs_special[MAXPATHLEN]; /* special file */ 139 char zone_fs_dir[MAXPATHLEN]; /* mount point */ 140 char zone_fs_type[FSTYPSZ]; /* e.g. ufs */ 141 zone_fsopt_t *zone_fs_options; /* mount options */ 142 char zone_fs_raw[MAXPATHLEN]; /* device to fsck */ 143 }; 144 145 struct zone_nwiftab { 146 char zone_nwif_address[INET6_ADDRSTRLEN]; 147 char zone_nwif_physical[LIFNAMSIZ]; 148 }; 149 150 struct zone_devtab { 151 char zone_dev_match[MAXPATHLEN]; 152 }; 153 154 struct zone_rctlvaltab { 155 char zone_rctlval_priv[MAXNAMELEN]; 156 char zone_rctlval_limit[MAXNAMELEN]; 157 char zone_rctlval_action[MAXNAMELEN]; 158 struct zone_rctlvaltab *zone_rctlval_next; 159 }; 160 161 struct zone_rctltab { 162 char zone_rctl_name[MAXNAMELEN]; 163 struct zone_rctlvaltab *zone_rctl_valptr; 164 }; 165 166 struct zone_attrtab { 167 char zone_attr_name[MAXNAMELEN]; 168 char zone_attr_type[MAXNAMELEN]; 169 char zone_attr_value[2 * BUFSIZ]; 170 }; 171 172 struct zone_dstab { 173 char zone_dataset_name[MAXNAMELEN]; 174 }; 175 176 struct zone_pkgtab { 177 char zone_pkg_name[MAXNAMELEN]; 178 char zone_pkg_version[ZONE_PKG_VERSMAX]; 179 }; 180 181 struct zone_patchtab { 182 char zone_patch_id[MAXNAMELEN]; 183 }; 184 185 struct zone_devpermtab { 186 char zone_devperm_name[MAXPATHLEN]; 187 uid_t zone_devperm_uid; 188 gid_t zone_devperm_gid; 189 mode_t zone_devperm_mode; 190 char *zone_devperm_acl; 191 }; 192 193 /* 194 * Basic configuration management routines. 195 */ 196 extern zone_dochandle_t zonecfg_init_handle(void); 197 extern int zonecfg_get_handle(const char *, zone_dochandle_t); 198 extern int zonecfg_get_snapshot_handle(const char *, zone_dochandle_t); 199 extern int zonecfg_get_template_handle(const char *, const char *, 200 zone_dochandle_t); 201 extern int zonecfg_check_handle(zone_dochandle_t); 202 extern void zonecfg_fini_handle(zone_dochandle_t); 203 extern int zonecfg_destroy(const char *, boolean_t); 204 extern int zonecfg_destroy_snapshot(const char *); 205 extern int zonecfg_save(zone_dochandle_t); 206 extern int zonecfg_create_snapshot(const char *); 207 extern char *zonecfg_strerror(int); 208 extern int zonecfg_access(const char *, int); 209 extern void zonecfg_set_root(const char *); 210 extern const char *zonecfg_get_root(void); 211 extern boolean_t zonecfg_in_alt_root(void); 212 213 /* 214 * Zone name, path to zone directory, autoboot setting and pool. 215 */ 216 extern int zonecfg_validate_zonename(const char *); 217 extern int zonecfg_get_name(zone_dochandle_t, char *, size_t); 218 extern int zonecfg_set_name(zone_dochandle_t, char *); 219 extern int zonecfg_get_zonepath(zone_dochandle_t, char *, size_t); 220 extern int zonecfg_set_zonepath(zone_dochandle_t, char *); 221 extern int zonecfg_get_autoboot(zone_dochandle_t, boolean_t *); 222 extern int zonecfg_set_autoboot(zone_dochandle_t, boolean_t); 223 extern int zonecfg_get_pool(zone_dochandle_t, char *, size_t); 224 extern int zonecfg_set_pool(zone_dochandle_t, char *); 225 226 /* 227 * Filesystem configuration. 228 */ 229 extern int zonecfg_add_filesystem(zone_dochandle_t, struct zone_fstab *); 230 extern int zonecfg_delete_filesystem(zone_dochandle_t, 231 struct zone_fstab *); 232 extern int zonecfg_modify_filesystem(zone_dochandle_t, 233 struct zone_fstab *, struct zone_fstab *); 234 extern int zonecfg_lookup_filesystem(zone_dochandle_t, 235 struct zone_fstab *); 236 extern int zonecfg_add_ipd(zone_dochandle_t, struct zone_fstab *); 237 extern int zonecfg_delete_ipd(zone_dochandle_t, struct zone_fstab *); 238 extern int zonecfg_modify_ipd(zone_dochandle_t, 239 struct zone_fstab *, struct zone_fstab *); 240 extern int zonecfg_lookup_ipd(zone_dochandle_t, struct zone_fstab *); 241 extern int zonecfg_add_fs_option(struct zone_fstab *, char *); 242 extern int zonecfg_remove_fs_option(struct zone_fstab *, char *); 243 extern void zonecfg_free_fs_option_list(zone_fsopt_t *); 244 extern int zonecfg_find_mounts(char *, int(*)(const char *, void *), 245 void *); 246 247 /* 248 * Network interface configuration. 249 */ 250 extern int zonecfg_add_nwif(zone_dochandle_t, struct zone_nwiftab *); 251 extern int zonecfg_delete_nwif(zone_dochandle_t, struct zone_nwiftab *); 252 extern int zonecfg_modify_nwif(zone_dochandle_t, struct zone_nwiftab *, 253 struct zone_nwiftab *); 254 extern int zonecfg_lookup_nwif(zone_dochandle_t, struct zone_nwiftab *); 255 256 /* 257 * Device configuration and rule matching. 258 */ 259 extern int zonecfg_add_dev(zone_dochandle_t, struct zone_devtab *); 260 extern int zonecfg_delete_dev(zone_dochandle_t, struct zone_devtab *); 261 extern int zonecfg_modify_dev(zone_dochandle_t, struct zone_devtab *, 262 struct zone_devtab *); 263 extern int zonecfg_lookup_dev(zone_dochandle_t, struct zone_devtab *); 264 extern int zonecfg_match_dev(zone_dochandle_t, char *, 265 struct zone_devtab *); 266 267 /* 268 * Resource control configuration. 269 */ 270 extern int zonecfg_add_rctl(zone_dochandle_t, struct zone_rctltab *); 271 extern int zonecfg_delete_rctl(zone_dochandle_t, struct zone_rctltab *); 272 extern int zonecfg_modify_rctl(zone_dochandle_t, struct zone_rctltab *, 273 struct zone_rctltab *); 274 extern int zonecfg_lookup_rctl(zone_dochandle_t, struct zone_rctltab *); 275 extern int zonecfg_add_rctl_value(struct zone_rctltab *, 276 struct zone_rctlvaltab *); 277 extern int zonecfg_remove_rctl_value(struct zone_rctltab *, 278 struct zone_rctlvaltab *); 279 extern void zonecfg_free_rctl_value_list(struct zone_rctlvaltab *); 280 281 /* 282 * Generic attribute configuration and type/value extraction. 283 */ 284 extern int zonecfg_add_attr(zone_dochandle_t, struct zone_attrtab *); 285 extern int zonecfg_delete_attr(zone_dochandle_t, struct zone_attrtab *); 286 extern int zonecfg_modify_attr(zone_dochandle_t, struct zone_attrtab *, 287 struct zone_attrtab *); 288 extern int zonecfg_lookup_attr(zone_dochandle_t, struct zone_attrtab *); 289 extern int zonecfg_get_attr_boolean(const struct zone_attrtab *, 290 boolean_t *); 291 extern int zonecfg_get_attr_int(const struct zone_attrtab *, int64_t *); 292 extern int zonecfg_get_attr_string(const struct zone_attrtab *, char *, 293 size_t); 294 extern int zonecfg_get_attr_uint(const struct zone_attrtab *, uint64_t *); 295 296 /* 297 * ZFS configuration. 298 */ 299 extern int zonecfg_add_ds(zone_dochandle_t, struct zone_dstab *); 300 extern int zonecfg_delete_ds(zone_dochandle_t, struct zone_dstab *); 301 extern int zonecfg_modify_ds(zone_dochandle_t, struct zone_dstab *, 302 struct zone_dstab *); 303 extern int zonecfg_lookup_ds(zone_dochandle_t, struct zone_dstab *); 304 305 /* 306 * attach/detach support. 307 */ 308 extern int zonecfg_get_attach_handle(const char *, const char *, 309 boolean_t, zone_dochandle_t); 310 extern int zonecfg_detach_save(zone_dochandle_t); 311 extern int zonecfg_get_detach_info(zone_dochandle_t, boolean_t); 312 extern boolean_t zonecfg_detached(const char *); 313 extern void zonecfg_rm_detached(zone_dochandle_t, boolean_t forced); 314 extern int zonecfg_devwalk(zone_dochandle_t handle, 315 int (*cb)(const char *, uid_t, gid_t, mode_t, const char *, void *), 316 void *data); 317 extern int zonecfg_devperms_apply(zone_dochandle_t, const char *, 318 uid_t, gid_t, mode_t, const char *); 319 320 321 /* 322 * '*ent' iterator routines. 323 */ 324 extern int zonecfg_setfsent(zone_dochandle_t); 325 extern int zonecfg_getfsent(zone_dochandle_t, struct zone_fstab *); 326 extern int zonecfg_endfsent(zone_dochandle_t); 327 extern int zonecfg_setipdent(zone_dochandle_t); 328 extern int zonecfg_getipdent(zone_dochandle_t, struct zone_fstab *); 329 extern int zonecfg_endipdent(zone_dochandle_t); 330 extern int zonecfg_setnwifent(zone_dochandle_t); 331 extern int zonecfg_getnwifent(zone_dochandle_t, struct zone_nwiftab *); 332 extern int zonecfg_endnwifent(zone_dochandle_t); 333 extern int zonecfg_setdevent(zone_dochandle_t); 334 extern int zonecfg_getdevent(zone_dochandle_t, struct zone_devtab *); 335 extern int zonecfg_enddevent(zone_dochandle_t); 336 extern int zonecfg_setattrent(zone_dochandle_t); 337 extern int zonecfg_getattrent(zone_dochandle_t, struct zone_attrtab *); 338 extern int zonecfg_endattrent(zone_dochandle_t); 339 extern int zonecfg_setrctlent(zone_dochandle_t); 340 extern int zonecfg_getrctlent(zone_dochandle_t, struct zone_rctltab *); 341 extern int zonecfg_endrctlent(zone_dochandle_t); 342 extern int zonecfg_setdsent(zone_dochandle_t); 343 extern int zonecfg_getdsent(zone_dochandle_t, struct zone_dstab *); 344 extern int zonecfg_enddsent(zone_dochandle_t); 345 extern int zonecfg_setpkgent(zone_dochandle_t); 346 extern int zonecfg_getpkgent(zone_dochandle_t, struct zone_pkgtab *); 347 extern int zonecfg_endpkgent(zone_dochandle_t); 348 extern int zonecfg_setpatchent(zone_dochandle_t); 349 extern int zonecfg_getpatchent(zone_dochandle_t, struct zone_patchtab *); 350 extern int zonecfg_endpatchent(zone_dochandle_t); 351 extern int zonecfg_setdevperment(zone_dochandle_t); 352 extern int zonecfg_getdevperment(zone_dochandle_t, 353 struct zone_devpermtab *); 354 extern int zonecfg_enddevperment(zone_dochandle_t); 355 356 /* 357 * Privilege-related functions. 358 */ 359 extern int zonecfg_default_privset(priv_set_t *); 360 extern int zonecfg_get_privset(zone_dochandle_t, priv_set_t *, 361 char **); 362 extern int zonecfg_get_limitpriv(zone_dochandle_t, char **); 363 extern int zonecfg_set_limitpriv(zone_dochandle_t, char *); 364 365 /* 366 * Higher-level routines. 367 */ 368 extern int zone_get_rootpath(char *, char *, size_t); 369 extern int zone_get_zonepath(char *, char *, size_t); 370 extern int zone_get_state(char *, zone_state_t *); 371 extern int zone_set_state(char *, zone_state_t); 372 extern char *zone_state_str(zone_state_t); 373 extern int zonecfg_get_name_by_uuid(const uuid_t, char *, size_t); 374 extern int zonecfg_get_uuid(const char *, uuid_t); 375 376 /* 377 * Iterator for configured zones. 378 */ 379 extern FILE *setzoneent(void); 380 extern char *getzoneent(FILE *); 381 extern struct zoneent *getzoneent_private(FILE *); 382 extern void endzoneent(FILE *); 383 384 /* 385 * File-system-related convenience functions. 386 */ 387 extern boolean_t zonecfg_valid_fs_type(const char *); 388 389 /* 390 * Network-related convenience functions. 391 */ 392 extern boolean_t zonecfg_same_net_address(char *, char *); 393 extern int zonecfg_valid_net_address(char *, struct lifreq *); 394 395 /* 396 * Rctl-related common functions. 397 */ 398 extern boolean_t zonecfg_is_rctl(const char *); 399 extern boolean_t zonecfg_valid_rctlname(const char *); 400 extern boolean_t zonecfg_valid_rctlblk(const rctlblk_t *); 401 extern boolean_t zonecfg_valid_rctl(const char *, const rctlblk_t *); 402 extern int zonecfg_construct_rctlblk(const struct zone_rctlvaltab *, 403 rctlblk_t *); 404 405 /* 406 * Live Upgrade support functions. Shared between ON and install gate. 407 */ 408 extern FILE *zonecfg_open_scratch(const char *, boolean_t); 409 extern int zonecfg_lock_scratch(FILE *); 410 extern void zonecfg_close_scratch(FILE *); 411 extern int zonecfg_get_scratch(FILE *, char *, size_t, char *, size_t, char *, 412 size_t); 413 extern int zonecfg_find_scratch(FILE *, const char *, const char *, char *, 414 size_t); 415 extern int zonecfg_reverse_scratch(FILE *, const char *, char *, size_t, 416 char *, size_t); 417 extern int zonecfg_add_scratch(FILE *, const char *, const char *, 418 const char *); 419 extern int zonecfg_delete_scratch(FILE *, const char *); 420 extern boolean_t zonecfg_is_scratch(const char *); 421 422 #ifdef __cplusplus 423 } 424 #endif 425 426 #endif /* _LIBZONECFG_H */ 427