libbrand.c (123807fb) | libbrand.c (f4b3ec61) |
---|---|
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 --- 6 unchanged lines hidden (view full) --- 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/* | 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 --- 6 unchanged lines hidden (view full) --- 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. | 23 * Copyright 2007 Sun Microsystems, Inc. All rights reserved. |
24 * Use is subject to license terms. 25 */ 26 27#pragma ident "%Z%%M% %I% %E% SMI" 28 29#include <assert.h> 30#include <dirent.h> 31#include <errno.h> --- 28 unchanged lines hidden (view full) --- 60#define DTD_ELEM_MODNAME ((const xmlChar *) "modname") 61#define DTD_ELEM_MOUNT ((const xmlChar *) "mount") 62#define DTD_ELEM_POSTCLONE ((const xmlChar *) "postclone") 63#define DTD_ELEM_PRIVILEGE ((const xmlChar *) "privilege") 64#define DTD_ELEM_SYMLINK ((const xmlChar *) "symlink") 65#define DTD_ELEM_VERIFY_CFG ((const xmlChar *) "verify_cfg") 66#define DTD_ELEM_VERIFY_ADM ((const xmlChar *) "verify_adm") 67 | 24 * Use is subject to license terms. 25 */ 26 27#pragma ident "%Z%%M% %I% %E% SMI" 28 29#include <assert.h> 30#include <dirent.h> 31#include <errno.h> --- 28 unchanged lines hidden (view full) --- 60#define DTD_ELEM_MODNAME ((const xmlChar *) "modname") 61#define DTD_ELEM_MOUNT ((const xmlChar *) "mount") 62#define DTD_ELEM_POSTCLONE ((const xmlChar *) "postclone") 63#define DTD_ELEM_PRIVILEGE ((const xmlChar *) "privilege") 64#define DTD_ELEM_SYMLINK ((const xmlChar *) "symlink") 65#define DTD_ELEM_VERIFY_CFG ((const xmlChar *) "verify_cfg") 66#define DTD_ELEM_VERIFY_ADM ((const xmlChar *) "verify_adm") 67 |
68#define DTD_ATTR_ALLOWEXCL ((const xmlChar *) "allow-exclusive-ip") |
|
68#define DTD_ATTR_ARCH ((const xmlChar *) "arch") 69#define DTD_ATTR_DIRECTORY ((const xmlChar *) "directory") | 69#define DTD_ATTR_ARCH ((const xmlChar *) "arch") 70#define DTD_ATTR_DIRECTORY ((const xmlChar *) "directory") |
71#define DTD_ATTR_IPTYPE ((const xmlChar *) "ip-type") |
|
70#define DTD_ATTR_MATCH ((const xmlChar *) "match") 71#define DTD_ATTR_MODE ((const xmlChar *) "mode") 72#define DTD_ATTR_NAME ((const xmlChar *) "name") 73#define DTD_ATTR_OPT ((const xmlChar *) "opt") 74#define DTD_ATTR_PATH ((const xmlChar *) "path") 75#define DTD_ATTR_SET ((const xmlChar *) "set") 76#define DTD_ATTR_SOURCE ((const xmlChar *) "source") 77#define DTD_ATTR_SPECIAL ((const xmlChar *) "special") 78#define DTD_ATTR_TARGET ((const xmlChar *) "target") 79#define DTD_ATTR_TYPE ((const xmlChar *) "type") 80 | 72#define DTD_ATTR_MATCH ((const xmlChar *) "match") 73#define DTD_ATTR_MODE ((const xmlChar *) "mode") 74#define DTD_ATTR_NAME ((const xmlChar *) "name") 75#define DTD_ATTR_OPT ((const xmlChar *) "opt") 76#define DTD_ATTR_PATH ((const xmlChar *) "path") 77#define DTD_ATTR_SET ((const xmlChar *) "set") 78#define DTD_ATTR_SOURCE ((const xmlChar *) "source") 79#define DTD_ATTR_SPECIAL ((const xmlChar *) "special") 80#define DTD_ATTR_TARGET ((const xmlChar *) "target") 81#define DTD_ATTR_TYPE ((const xmlChar *) "type") 82 |
83#define DTD_ENTITY_TRUE "true" 84 |
|
81static volatile boolean_t libbrand_initialized = B_FALSE; 82static char i_curr_arch[MAXNAMELEN]; 83static char i_curr_zone[ZONENAME_MAX]; 84 85/*ARGSUSED*/ 86static void 87brand_error_func(void *ctx, const char *msg, ...) 88{ --- 444 unchanged lines hidden (view full) --- 533 534int 535brand_is_native(brand_handle_t bh) 536{ 537 struct brand_handle *bhp = (struct brand_handle *)bh; 538 return ((strcmp(bhp->bh_name, NATIVE_BRAND_NAME) == 0) ? 1 : 0); 539} 540 | 85static volatile boolean_t libbrand_initialized = B_FALSE; 86static char i_curr_arch[MAXNAMELEN]; 87static char i_curr_zone[ZONENAME_MAX]; 88 89/*ARGSUSED*/ 90static void 91brand_error_func(void *ctx, const char *msg, ...) 92{ --- 444 unchanged lines hidden (view full) --- 537 538int 539brand_is_native(brand_handle_t bh) 540{ 541 struct brand_handle *bhp = (struct brand_handle *)bh; 542 return ((strcmp(bhp->bh_name, NATIVE_BRAND_NAME) == 0) ? 1 : 0); 543} 544 |
545boolean_t 546brand_allow_exclusive_ip(brand_handle_t bh) 547{ 548 struct brand_handle *bhp = (struct brand_handle *)bh; 549 xmlNodePtr node; 550 xmlChar *allow_excl; 551 boolean_t ret; 552 553 assert(bhp != NULL); 554 555 if ((node = xmlDocGetRootElement(bhp->bh_platform)) == NULL) 556 return (B_FALSE); 557 558 allow_excl = xmlGetProp(node, DTD_ATTR_ALLOWEXCL); 559 if (allow_excl == NULL) 560 return (B_FALSE); 561 562 /* Note: only return B_TRUE if it's "true" */ 563 if (strcmp((char *)allow_excl, DTD_ENTITY_TRUE) == 0) 564 ret = B_TRUE; 565 else 566 ret = B_FALSE; 567 568 xmlFree(allow_excl); 569 570 return (ret); 571} 572 |
|
541/* 542 * Iterate over brand privileges 543 * 544 * Walks the brand config, searching for <privilege> elements, calling the 545 * specified callback for each. Returns 0 on success, or -1 on failure. 546 */ 547int 548brand_config_iter_privilege(brand_handle_t bh, int (*func)(void *, --- 184 unchanged lines hidden (view full) --- 733/* 734 * Iterate over platform devices 735 * 736 * Walks the platform, searching for <device> elements, calling the 737 * specified callback for each. Returns 0 on success, or -1 on failure. 738 */ 739int 740brand_platform_iter_devices(brand_handle_t bh, const char *zonename, | 573/* 574 * Iterate over brand privileges 575 * 576 * Walks the brand config, searching for <privilege> elements, calling the 577 * specified callback for each. Returns 0 on success, or -1 on failure. 578 */ 579int 580brand_config_iter_privilege(brand_handle_t bh, int (*func)(void *, --- 184 unchanged lines hidden (view full) --- 765/* 766 * Iterate over platform devices 767 * 768 * Walks the platform, searching for <device> elements, calling the 769 * specified callback for each. Returns 0 on success, or -1 on failure. 770 */ 771int 772brand_platform_iter_devices(brand_handle_t bh, const char *zonename, |
741 int (*func)(void *, const char *, const char *), void *data) | 773 int (*func)(void *, const char *, const char *), void *data, 774 const char *curr_iptype) |
742{ 743 struct brand_handle *bhp = (struct brand_handle *)bh; 744 const char *curr_arch = get_curr_arch(); 745 xmlNodePtr node; | 775{ 776 struct brand_handle *bhp = (struct brand_handle *)bh; 777 const char *curr_arch = get_curr_arch(); 778 xmlNodePtr node; |
746 xmlChar *match, *name, *arch; | 779 xmlChar *match, *name, *arch, *iptype; |
747 char match_exp[MAXPATHLEN]; 748 boolean_t err = B_FALSE; 749 int ret = 0; 750 751 752 assert(bhp != NULL); 753 assert(zonename != NULL); 754 assert(func != NULL); | 780 char match_exp[MAXPATHLEN]; 781 boolean_t err = B_FALSE; 782 int ret = 0; 783 784 785 assert(bhp != NULL); 786 assert(zonename != NULL); 787 assert(func != NULL); |
788 assert(curr_iptype != NULL); |
|
755 756 if ((node = xmlDocGetRootElement(bhp->bh_platform)) == NULL) 757 return (-1); 758 759 for (node = node->xmlChildrenNode; node != NULL; node = node->next) { 760 761 if (xmlStrcmp(node->name, DTD_ELEM_DEVICE) != 0) 762 continue; 763 764 match = xmlGetProp(node, DTD_ATTR_MATCH); 765 name = xmlGetProp(node, DTD_ATTR_NAME); 766 arch = xmlGetProp(node, DTD_ATTR_ARCH); | 789 790 if ((node = xmlDocGetRootElement(bhp->bh_platform)) == NULL) 791 return (-1); 792 793 for (node = node->xmlChildrenNode; node != NULL; node = node->next) { 794 795 if (xmlStrcmp(node->name, DTD_ELEM_DEVICE) != 0) 796 continue; 797 798 match = xmlGetProp(node, DTD_ATTR_MATCH); 799 name = xmlGetProp(node, DTD_ATTR_NAME); 800 arch = xmlGetProp(node, DTD_ATTR_ARCH); |
767 if ((match == NULL) || (name == NULL) || (arch == NULL)) { | 801 iptype = xmlGetProp(node, DTD_ATTR_IPTYPE); 802 if ((match == NULL) || (name == NULL) || (arch == NULL) || 803 (iptype == NULL)) { |
768 err = B_TRUE; 769 goto next; 770 } 771 772 /* check if the arch matches */ 773 if ((strcmp((char *)arch, "all") != 0) && 774 (strcmp((char *)arch, curr_arch) != 0)) 775 goto next; 776 | 804 err = B_TRUE; 805 goto next; 806 } 807 808 /* check if the arch matches */ 809 if ((strcmp((char *)arch, "all") != 0) && 810 (strcmp((char *)arch, curr_arch) != 0)) 811 goto next; 812 |
813 /* check if the iptype matches */ 814 if ((strcmp((char *)iptype, "all") != 0) && 815 (strcmp((char *)iptype, curr_iptype) != 0)) 816 goto next; 817 |
|
777 /* Substitute token values as needed. */ 778 if ((ret = i_substitute_tokens((char *)match, 779 match_exp, sizeof (match_exp), 780 zonename, NULL, NULL, NULL, 0, NULL)) != 0) { 781 err = B_TRUE; 782 goto next; 783 } 784 --- 8 unchanged lines hidden (view full) --- 793 794next: 795 if (match != NULL) 796 xmlFree(match); 797 if (name != NULL) 798 xmlFree(name); 799 if (arch != NULL) 800 xmlFree(arch); | 818 /* Substitute token values as needed. */ 819 if ((ret = i_substitute_tokens((char *)match, 820 match_exp, sizeof (match_exp), 821 zonename, NULL, NULL, NULL, 0, NULL)) != 0) { 822 err = B_TRUE; 823 goto next; 824 } 825 --- 8 unchanged lines hidden (view full) --- 834 835next: 836 if (match != NULL) 837 xmlFree(match); 838 if (name != NULL) 839 xmlFree(name); 840 if (arch != NULL) 841 xmlFree(arch); |
842 if (iptype != NULL) 843 xmlFree(iptype); |
|
801 if (err) 802 return (-1); 803 if (ret != 0) 804 return (-1); 805 } 806 807 return (0); 808} | 844 if (err) 845 return (-1); 846 if (ret != 0) 847 return (-1); 848 } 849 850 return (0); 851} |