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) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
24 */
25
26 #include <libsysevent.h>
27 #include <pthread.h>
28 #include <stdlib.h>
29 #include <errno.h>
30 #include <fnmatch.h>
31 #include <strings.h>
32 #include <unistd.h>
33 #include <assert.h>
34 #include <libgen.h>
35 #include <libintl.h>
36 #include <alloca.h>
37 #include <ctype.h>
38 #include <sys/acl.h>
39 #include <sys/stat.h>
40 #include <sys/brand.h>
41 #include <sys/mntio.h>
42 #include <sys/mnttab.h>
1750 void
1751 zonecfg_free_rctl_value_list(struct zone_rctlvaltab *valtab)
1752 {
1753 if (valtab == NULL)
1754 return;
1755 zonecfg_free_rctl_value_list(valtab->zone_rctlval_next);
1756 free(valtab);
1757 }
1758
1759 static boolean_t
1760 match_prop(xmlNodePtr cur, const xmlChar *attr, char *user_prop)
1761 {
1762 xmlChar *gotten_prop;
1763 int prop_result;
1764
1765 gotten_prop = xmlGetProp(cur, attr);
1766 if (gotten_prop == NULL) /* shouldn't happen */
1767 return (B_FALSE);
1768 prop_result = xmlStrcmp(gotten_prop, (const xmlChar *) user_prop);
1769 xmlFree(gotten_prop);
1770 return ((prop_result == 0));
1771 }
1772
1773 static int
1774 zonecfg_delete_filesystem_core(zone_dochandle_t handle,
1775 struct zone_fstab *tabptr)
1776 {
1777 xmlNodePtr cur = handle->zone_dh_cur;
1778 boolean_t dir_match, spec_match, raw_match, type_match;
1779
1780 for (cur = cur->xmlChildrenNode; cur != NULL; cur = cur->next) {
1781 if (xmlStrcmp(cur->name, DTD_ELEM_FS))
1782 continue;
1783 dir_match = match_prop(cur, DTD_ATTR_DIR, tabptr->zone_fs_dir);
1784 spec_match = match_prop(cur, DTD_ATTR_SPECIAL,
1785 tabptr->zone_fs_special);
1786 raw_match = match_prop(cur, DTD_ATTR_RAW,
1787 tabptr->zone_fs_raw);
1788 type_match = match_prop(cur, DTD_ATTR_TYPE,
1789 tabptr->zone_fs_type);
1790 if (dir_match && spec_match && raw_match && type_match) {
2238 return (Z_OK);
2239 }
2240
2241 static int
2242 zonecfg_delete_nwif_core(zone_dochandle_t handle, struct zone_nwiftab *tabptr)
2243 {
2244 xmlNodePtr cur = handle->zone_dh_cur;
2245 boolean_t addr_match, phys_match, allowed_addr_match;
2246
2247 for (cur = cur->xmlChildrenNode; cur != NULL; cur = cur->next) {
2248 if (xmlStrcmp(cur->name, DTD_ELEM_NET))
2249 continue;
2250
2251 addr_match = match_prop(cur, DTD_ATTR_ADDRESS,
2252 tabptr->zone_nwif_address);
2253 allowed_addr_match = match_prop(cur, DTD_ATTR_ALLOWED_ADDRESS,
2254 tabptr->zone_nwif_allowed_address);
2255 phys_match = match_prop(cur, DTD_ATTR_PHYSICAL,
2256 tabptr->zone_nwif_physical);
2257
2258 if ((addr_match || allowed_addr_match) && phys_match) {
2259 xmlUnlinkNode(cur);
2260 xmlFreeNode(cur);
2261 return (Z_OK);
2262 }
2263 }
2264 return (Z_NO_RESOURCE_ID);
2265 }
2266
2267 int
2268 zonecfg_delete_nwif(zone_dochandle_t handle, struct zone_nwiftab *tabptr)
2269 {
2270 int err;
2271
2272 if (tabptr == NULL)
2273 return (Z_INVAL);
2274
2275 if ((err = operation_prep(handle)) != Z_OK)
2276 return (err);
2277
2278 if ((err = zonecfg_delete_nwif_core(handle, tabptr)) != Z_OK)
|
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 2014 Gary Mills
24 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
25 */
26
27 #include <libsysevent.h>
28 #include <pthread.h>
29 #include <stdlib.h>
30 #include <errno.h>
31 #include <fnmatch.h>
32 #include <strings.h>
33 #include <unistd.h>
34 #include <assert.h>
35 #include <libgen.h>
36 #include <libintl.h>
37 #include <alloca.h>
38 #include <ctype.h>
39 #include <sys/acl.h>
40 #include <sys/stat.h>
41 #include <sys/brand.h>
42 #include <sys/mntio.h>
43 #include <sys/mnttab.h>
1751 void
1752 zonecfg_free_rctl_value_list(struct zone_rctlvaltab *valtab)
1753 {
1754 if (valtab == NULL)
1755 return;
1756 zonecfg_free_rctl_value_list(valtab->zone_rctlval_next);
1757 free(valtab);
1758 }
1759
1760 static boolean_t
1761 match_prop(xmlNodePtr cur, const xmlChar *attr, char *user_prop)
1762 {
1763 xmlChar *gotten_prop;
1764 int prop_result;
1765
1766 gotten_prop = xmlGetProp(cur, attr);
1767 if (gotten_prop == NULL) /* shouldn't happen */
1768 return (B_FALSE);
1769 prop_result = xmlStrcmp(gotten_prop, (const xmlChar *) user_prop);
1770 xmlFree(gotten_prop);
1771 return ((prop_result == 0)); /* empty strings will match */
1772 }
1773
1774 static int
1775 zonecfg_delete_filesystem_core(zone_dochandle_t handle,
1776 struct zone_fstab *tabptr)
1777 {
1778 xmlNodePtr cur = handle->zone_dh_cur;
1779 boolean_t dir_match, spec_match, raw_match, type_match;
1780
1781 for (cur = cur->xmlChildrenNode; cur != NULL; cur = cur->next) {
1782 if (xmlStrcmp(cur->name, DTD_ELEM_FS))
1783 continue;
1784 dir_match = match_prop(cur, DTD_ATTR_DIR, tabptr->zone_fs_dir);
1785 spec_match = match_prop(cur, DTD_ATTR_SPECIAL,
1786 tabptr->zone_fs_special);
1787 raw_match = match_prop(cur, DTD_ATTR_RAW,
1788 tabptr->zone_fs_raw);
1789 type_match = match_prop(cur, DTD_ATTR_TYPE,
1790 tabptr->zone_fs_type);
1791 if (dir_match && spec_match && raw_match && type_match) {
2239 return (Z_OK);
2240 }
2241
2242 static int
2243 zonecfg_delete_nwif_core(zone_dochandle_t handle, struct zone_nwiftab *tabptr)
2244 {
2245 xmlNodePtr cur = handle->zone_dh_cur;
2246 boolean_t addr_match, phys_match, allowed_addr_match;
2247
2248 for (cur = cur->xmlChildrenNode; cur != NULL; cur = cur->next) {
2249 if (xmlStrcmp(cur->name, DTD_ELEM_NET))
2250 continue;
2251
2252 addr_match = match_prop(cur, DTD_ATTR_ADDRESS,
2253 tabptr->zone_nwif_address);
2254 allowed_addr_match = match_prop(cur, DTD_ATTR_ALLOWED_ADDRESS,
2255 tabptr->zone_nwif_allowed_address);
2256 phys_match = match_prop(cur, DTD_ATTR_PHYSICAL,
2257 tabptr->zone_nwif_physical);
2258
2259 if (addr_match && allowed_addr_match && phys_match) {
2260 xmlUnlinkNode(cur);
2261 xmlFreeNode(cur);
2262 return (Z_OK);
2263 }
2264 }
2265 return (Z_NO_RESOURCE_ID);
2266 }
2267
2268 int
2269 zonecfg_delete_nwif(zone_dochandle_t handle, struct zone_nwiftab *tabptr)
2270 {
2271 int err;
2272
2273 if (tabptr == NULL)
2274 return (Z_INVAL);
2275
2276 if ((err = operation_prep(handle)) != Z_OK)
2277 return (err);
2278
2279 if ((err = zonecfg_delete_nwif_core(handle, tabptr)) != Z_OK)
|