Print this page
4095 minor cleanup up libshare

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/libshare/common/libshare.c
          +++ new/usr/src/lib/libshare/common/libshare.c
↓ open down ↓ 13 lines elided ↑ open up ↑
  14   14   * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15   15   * If applicable, add the following below this CDDL HEADER, with the
  16   16   * fields enclosed by brackets "[]" replaced with your own identifying
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  
  22   22  /*
  23   23   * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
       24 + * Copyright (c) 2013 RackTop Systems.
  24   25   */
  25   26  
  26   27  /*
  27   28   * Share control API
  28   29   */
  29   30  #include <stdio.h>
  30   31  #include <string.h>
  31   32  #include <ctype.h>
  32   33  #include <sys/types.h>
  33   34  #include <sys/stat.h>
↓ open down ↓ 24 lines elided ↑ open up ↑
  58   59  #define SA_TYPE_ALTSPACE        5
  59   60  
  60   61  /*
  61   62   * internal data structures
  62   63   */
  63   64  
  64   65  extern struct sa_proto_plugin *sap_proto_list;
  65   66  
  66   67  /* current SMF/SVC repository handle */
  67   68  extern void getlegacyconfig(sa_handle_t, char *, xmlNodePtr *);
  68      -extern int gettransients(sa_handle_impl_t, xmlNodePtr *);
       69 +extern int gettransients(sa_handle_t, xmlNodePtr *);
  69   70  extern char *sa_fstype(char *);
  70      -extern int sa_is_share(void *);
  71      -extern int sa_is_resource(void *);
       71 +extern boolean_t sa_is_share(void *);
       72 +extern boolean_t sa_is_resource(void *);
  72   73  extern ssize_t scf_max_name_len; /* defined in scfutil during initialization */
  73      -extern int sa_group_is_zfs(sa_group_t);
  74      -extern int sa_path_is_zfs(char *);
       74 +extern boolean_t sa_group_is_zfs(sa_group_t);
       75 +extern boolean_t sa_path_is_zfs(char *);
  75   76  extern int sa_zfs_set_sharenfs(sa_group_t, char *, int);
  76   77  extern int sa_zfs_set_sharesmb(sa_group_t, char *, int);
  77   78  extern void update_legacy_config(sa_handle_t);
  78   79  extern int issubdir(char *, char *);
  79      -extern int sa_zfs_init(sa_handle_impl_t);
  80      -extern void sa_zfs_fini(sa_handle_impl_t);
       80 +extern int sa_zfs_init(sa_handle_t);
       81 +extern void sa_zfs_fini(sa_handle_t);
  81   82  extern void sablocksigs(sigset_t *);
  82   83  extern void saunblocksigs(sigset_t *);
  83   84  static sa_group_t sa_get_optionset_parent(sa_optionset_t);
  84   85  static char *get_node_attr(void *, char *);
  85   86  extern void sa_update_sharetab_ts(sa_handle_t);
  86   87  
  87   88  /*
  88   89   * Data structures for finding/managing the document root to access
  89   90   * handle mapping. The list isn't expected to grow very large so a
  90   91   * simple list is acceptable. The purpose is to provide a way to start
  91   92   * with a group or share and find the library handle needed for
  92   93   * various operations.
  93   94   */
  94   95  mutex_t sa_global_lock;
  95   96  struct doc2handle {
  96   97          struct doc2handle       *next;
  97   98          xmlNodePtr              root;
  98      -        sa_handle_impl_t        handle;
       99 +        sa_handle_t             handle;
  99  100  };
 100  101  
 101  102  mutex_t sa_dfstab_lock;
 102  103  
 103  104  /* definitions used in a couple of property functions */
 104  105  #define SA_PROP_OP_REMOVE       1
 105  106  #define SA_PROP_OP_ADD          2
 106  107  #define SA_PROP_OP_UPDATE       3
 107  108  
 108  109  static struct doc2handle *sa_global_handles = NULL;
↓ open down ↓ 123 lines elided ↑ open up ↑
 232  233          return (ret);
 233  234  }
 234  235  
 235  236  /*
 236  237   * Document root to active handle mapping functions.  These are only
 237  238   * used internally. A mutex is used to prevent access while the list
 238  239   * is changing. In general, the list will be relatively short - one
 239  240   * item per thread that has called sa_init().
 240  241   */
 241  242  
 242      -sa_handle_impl_t
      243 +sa_handle_t
 243  244  get_handle_for_root(xmlNodePtr root)
 244  245  {
 245  246          struct doc2handle *item;
 246  247  
 247  248          (void) mutex_lock(&sa_global_lock);
 248  249          for (item = sa_global_handles; item != NULL; item = item->next) {
 249  250                  if (item->root == root)
 250  251                          break;
 251  252          }
 252  253          (void) mutex_unlock(&sa_global_lock);
 253  254          if (item != NULL)
 254  255                  return (item->handle);
 255  256          return (NULL);
 256  257  }
 257  258  
 258  259  static int
 259      -add_handle_for_root(xmlNodePtr root, sa_handle_impl_t handle)
      260 +add_handle_for_root(xmlNodePtr root, sa_handle_t handle)
 260  261  {
 261  262          struct doc2handle *item;
 262  263          int ret = SA_NO_MEMORY;
 263  264  
 264  265          item = (struct doc2handle *)calloc(sizeof (struct doc2handle), 1);
 265  266          if (item != NULL) {
 266  267                  item->root = root;
 267  268                  item->handle = handle;
 268  269                  (void) mutex_lock(&sa_global_lock);
 269  270                  item->next = sa_global_handles;
↓ open down ↓ 42 lines elided ↑ open up ↑
 312  313   */
 313  314  sa_handle_t
 314  315  sa_find_group_handle(sa_group_t group)
 315  316  {
 316  317          xmlNodePtr node = (xmlNodePtr)group;
 317  318          sa_handle_t handle;
 318  319  
 319  320          while (node != NULL) {
 320  321                  if (strcmp((char *)(node->name), "sharecfg") == 0) {
 321  322                          /* have the root so get the handle */
 322      -                        handle = (sa_handle_t)get_handle_for_root(node);
      323 +                        handle = get_handle_for_root(node);
 323  324                          return (handle);
 324  325                  }
 325  326                  node = node->parent;
 326  327          }
 327  328          return (NULL);
 328  329  }
 329  330  
 330  331  /*
 331  332   * set_legacy_timestamp(root, path, timevalue)
 332  333   *
 333  334   * add the current timestamp value to the configuration for use in
 334  335   * determining when to update the legacy files.  For SMF, this
 335  336   * property is kept in default/operation/legacy_timestamp
 336  337   */
 337  338  
 338  339  static void
 339  340  set_legacy_timestamp(xmlNodePtr root, char *path, uint64_t tval)
 340  341  {
 341  342          xmlNodePtr node;
 342  343          xmlChar *lpath = NULL;
 343      -        sa_handle_impl_t handle;
      344 +        sa_handle_t handle;
 344  345  
 345  346          /* Have to have a handle or else we weren't initialized. */
 346  347          handle = get_handle_for_root(root);
 347  348          if (handle == NULL)
 348  349                  return;
 349  350  
 350  351          for (node = root->xmlChildrenNode; node != NULL;
 351  352              node = node->next) {
 352  353                  if (xmlStrcmp(node->name, (xmlChar *)"legacy") == 0) {
 353  354                          /* a possible legacy node for this path */
↓ open down ↓ 239 lines elided ↑ open up ↑
 593  594          return (error);
 594  595  }
 595  596  
 596  597  /*
 597  598   * check to see if group/share is persistent.
 598  599   *
 599  600   * "group" can be either an sa_group_t or an sa_share_t. (void *)
 600  601   * works since both thse types are also void *.
 601  602   * If the share is a ZFS share, mark it as persistent.
 602  603   */
 603      -int
      604 +boolean_t
 604  605  sa_is_persistent(void *group)
 605  606  {
 606  607          char *type;
 607      -        int persist = 1;
      608 +        boolean_t persist = B_TRUE;
 608  609          sa_group_t grp;
 609  610  
 610  611          type = sa_get_group_attr((sa_group_t)group, "type");
 611  612          if (type != NULL) {
 612  613                  if (strcmp(type, "transient") == 0)
 613      -                        persist = 0;
      614 +                        persist = B_FALSE;
 614  615                  sa_free_attr_string(type);
 615  616          }
 616  617  
 617  618          grp = (sa_is_share(group)) ? sa_get_parent_group(group) : group;
 618  619          if (sa_group_is_zfs(grp))
 619      -                persist = 1;
      620 +                persist = B_TRUE;
 620  621  
 621  622          return (persist);
 622  623  }
 623  624  
 624  625  /*
 625  626   * sa_valid_group_name(name)
 626  627   *
 627  628   * check that the "name" contains only valid characters and otherwise
 628  629   * fits the required naming conventions. Valid names must start with
 629  630   * an alphabetic and the remainder may consist of only alphanumeric
↓ open down ↓ 196 lines elided ↑ open up ↑
 826  827  sa_handle_t
 827  828  sa_init(int init_service)
 828  829  {
 829  830          struct stat st;
 830  831          int legacy = 0;
 831  832          uint64_t tval = 0;
 832  833          int lockfd;
 833  834          sigset_t old;
 834  835          int updatelegacy = B_FALSE;
 835  836          scf_simple_prop_t *prop;
 836      -        sa_handle_impl_t handle;
      837 +        sa_handle_t handle;
 837  838          int err;
 838  839  
 839      -        handle = calloc(sizeof (struct sa_handle_impl), 1);
      840 +        handle = calloc(sizeof (struct sa_handle), 1);
 840  841  
 841  842          if (handle != NULL) {
 842  843                  /*
 843  844                   * Get protocol specific structures, but only if this
 844  845                   * is the only handle.
 845  846                   */
 846  847                  (void) mutex_lock(&sa_global_lock);
 847  848                  if (sa_global_handles == NULL)
 848  849                          (void) proto_plugin_init();
 849  850                  (void) mutex_unlock(&sa_global_lock);
↓ open down ↓ 132 lines elided ↑ open up ↑
 982  983                                  if (tval == 0) {
 983  984                                          /*
 984  985                                           * first time so make sure
 985  986                                           * default is setup
 986  987                                           */
 987  988                                          verifydefgroupopts(handle);
 988  989                                  }
 989  990  
 990  991                                  if (updatelegacy == B_TRUE) {
 991  992                                          sablocksigs(&old);
 992      -                                        getlegacyconfig((sa_handle_t)handle,
      993 +                                        getlegacyconfig(handle,
 993  994                                              SA_LEGACY_DFSTAB, &handle->tree);
 994  995                                          if (stat(SA_LEGACY_DFSTAB, &st) >= 0)
 995  996                                                  set_legacy_timestamp(
 996  997                                                      handle->tree,
 997  998                                                      SA_LEGACY_DFSTAB,
 998  999                                                      TSTAMP(st.st_ctim));
 999 1000                                          saunblocksigs(&old);
1000 1001                                          /*
1001 1002                                           * Safe to unlock now to allow
1002 1003                                           * others to run
1003 1004                                           */
1004 1005                                          (void) mutex_unlock(&sa_dfstab_lock);
1005 1006                                          (void) lockf(lockfd, F_ULOCK, 0);
1006 1007                                          (void) close(lockfd);
1007 1008                                  }
1008 1009                                  /* Get sharetab timestamp */
1009      -                                sa_update_sharetab_ts((sa_handle_t)handle);
     1010 +                                sa_update_sharetab_ts(handle);
1010 1011  
1011 1012                                  /* Get lastupdate (transaction) timestamp */
1012 1013                                  prop = scf_simple_prop_get(
1013 1014                                      handle->scfhandle->handle,
1014 1015                                      (const char *)SA_SVC_FMRI_BASE ":default",
1015 1016                                      "state", "lastupdate");
1016 1017                                  if (prop != NULL) {
1017 1018                                          char *str;
1018 1019                                          str =
1019 1020                                              scf_simple_prop_next_astring(prop);
↓ open down ↓ 2 lines elided ↑ open up ↑
1022 1023                                                      strtoull(str, NULL, 0);
1023 1024                                          else
1024 1025                                                  handle->tstrans = 0;
1025 1026                                          scf_simple_prop_free(prop);
1026 1027                                  }
1027 1028                                  legacy |= sa_get_zfs_shares(handle, "zfs");
1028 1029                                  legacy |= gettransients(handle, &handle->tree);
1029 1030                          }
1030 1031                  }
1031 1032          }
1032      -        return ((sa_handle_t)handle);
     1033 +        return (handle);
1033 1034  }
1034 1035  
1035 1036  /*
1036 1037   * sa_fini(handle)
1037 1038   *      Uninitialize the API structures including the configuration
1038 1039   *      data structures and ZFS related data.
1039 1040   */
1040 1041  
1041 1042  void
1042 1043  sa_fini(sa_handle_t handle)
1043 1044  {
1044      -        sa_handle_impl_t impl_handle = (sa_handle_impl_t)handle;
1045      -
1046      -        if (impl_handle != NULL) {
     1045 +        if (handle != NULL) {
1047 1046                  /*
1048 1047                   * Free the config trees and any other data structures
1049 1048                   * used in the handle.
1050 1049                   */
1051      -                if (impl_handle->doc != NULL)
1052      -                        xmlFreeDoc(impl_handle->doc);
     1050 +                if (handle->doc != NULL)
     1051 +                        xmlFreeDoc(handle->doc);
1053 1052  
1054 1053                  /* Remove and free the entry in the global list. */
1055      -                remove_handle_for_root(impl_handle->tree);
     1054 +                remove_handle_for_root(handle->tree);
1056 1055  
1057 1056                  /*
1058 1057                   * If this was the last handle to release, unload the
1059 1058                   * plugins that were loaded. Use a mutex in case
1060 1059                   * another thread is reinitializing.
1061 1060                   */
1062 1061                  (void) mutex_lock(&sa_global_lock);
1063 1062                  if (sa_global_handles == NULL)
1064 1063                          (void) proto_plugin_fini();
1065 1064                  (void) mutex_unlock(&sa_global_lock);
1066 1065  
1067      -                sa_scf_fini(impl_handle->scfhandle);
1068      -                sa_zfs_fini(impl_handle);
     1066 +                sa_scf_fini(handle->scfhandle);
     1067 +                sa_zfs_fini(handle);
1069 1068  
1070 1069                  /* Make sure we free the handle */
1071      -                free(impl_handle);
     1070 +                free(handle);
1072 1071  
1073 1072          }
1074 1073  }
1075 1074  
1076 1075  /*
1077 1076   * sa_get_protocols(char **protocol)
1078 1077   *      Get array of protocols that are supported
1079 1078   *      Returns pointer to an allocated and NULL terminated
1080 1079   *      array of strings.  Caller must free.
1081 1080   *      This really should be determined dynamically.
↓ open down ↓ 66 lines elided ↑ open up ↑
1148 1147   * sa_get_group(groupname)
1149 1148   *      Return the "group" specified.  If groupname is NULL,
1150 1149   *      return the first group of the list of groups.
1151 1150   */
1152 1151  sa_group_t
1153 1152  sa_get_group(sa_handle_t handle, char *groupname)
1154 1153  {
1155 1154          xmlNodePtr node = NULL;
1156 1155          char *subgroup = NULL;
1157 1156          char *group = NULL;
1158      -        sa_handle_impl_t impl_handle = (sa_handle_impl_t)handle;
1159 1157  
1160      -        if (impl_handle != NULL && impl_handle->tree != NULL) {
     1158 +        if (handle != NULL && handle->tree != NULL) {
1161 1159                  if (groupname != NULL) {
1162 1160                          group = strdup(groupname);
1163 1161                          if (group != NULL) {
1164 1162                                  subgroup = strchr(group, '/');
1165 1163                                  if (subgroup != NULL)
1166 1164                                          *subgroup++ = '\0';
1167 1165                          }
1168 1166                  }
1169 1167                  /*
1170 1168                   * We want to find the, possibly, named group. If
1171 1169                   * group is not NULL, then lookup the name. If it is
1172 1170                   * NULL, we only do the find if groupname is also
1173 1171                   * NULL. This allows lookup of the "first" group in
1174 1172                   * the internal list.
1175 1173                   */
1176 1174                  if (group != NULL || groupname == NULL)
1177      -                        node = find_group_by_name(impl_handle->tree,
     1175 +                        node = find_group_by_name(handle->tree,
1178 1176                              (xmlChar *)group);
1179 1177  
1180 1178                  /* if a subgroup, find it before returning */
1181 1179                  if (subgroup != NULL && node != NULL)
1182 1180                          node = find_group_by_name(node, (xmlChar *)subgroup);
1183 1181          }
1184 1182          if (node != NULL && (char *)group != NULL)
1185      -                (void) sa_get_instance(impl_handle->scfhandle, (char *)group);
     1183 +                (void) sa_get_instance(handle->scfhandle, (char *)group);
1186 1184          if (group != NULL)
1187 1185                  free(group);
1188 1186          return ((sa_group_t)(node));
1189 1187  }
1190 1188  
1191 1189  /*
1192 1190   * sa_get_next_group(group)
1193 1191   *      Return the "next" group after the specified group from
1194 1192   *      the internal group list.  NULL if there are no more.
1195 1193   */
↓ open down ↓ 299 lines elided ↑ open up ↑
1495 1493                   * check to see if the protocol is enabled on the
1496 1494                   * subgroup and then setup the share appropriately.
1497 1495                   */
1498 1496                  if (sa_group_is_zfs(group) &&
1499 1497                      sa_path_is_zfs(sharepath)) {
1500 1498                          if (sa_get_optionset(group, "nfs") != NULL)
1501 1499                                  err = sa_zfs_set_sharenfs(group, sharepath, 1);
1502 1500                          else if (sa_get_optionset(group, "smb") != NULL)
1503 1501                                  err = sa_zfs_set_sharesmb(group, sharepath, 1);
1504 1502                  } else {
1505      -                        sa_handle_impl_t impl_handle;
1506      -                        impl_handle =
1507      -                            (sa_handle_impl_t)sa_find_group_handle(group);
1508      -                        if (impl_handle != NULL) {
1509      -                                err = sa_commit_share(impl_handle->scfhandle,
     1503 +                        sa_handle_t handle = sa_find_group_handle(group);
     1504 +                        if (handle != NULL) {
     1505 +                                err = sa_commit_share(handle->scfhandle,
1510 1506                                      group, (sa_share_t)node);
1511 1507                          } else {
1512 1508                                  err = SA_SYSTEM_ERR;
1513 1509                          }
1514 1510                  }
1515 1511          }
1516 1512          if (err == SA_NO_PERMISSION && persist & SA_SHARE_PARSER)
1517 1513                  /* called by the dfstab parser so could be a show */
1518 1514                  err = SA_OK;
1519 1515  
↓ open down ↓ 214 lines elided ↑ open up ↑
1734 1730  
1735 1731          /*
1736 1732           * need to test if "busy"
1737 1733           */
1738 1734          /* only do SMF action if permanent */
1739 1735          if (!transient || zfs != NULL) {
1740 1736                  /* remove from legacy dfstab as well as possible SMF */
1741 1737                  ret = sa_delete_legacy(share, NULL);
1742 1738                  if (ret == SA_OK) {
1743 1739                          if (!sa_group_is_zfs(group)) {
1744      -                                sa_handle_impl_t impl_handle;
1745      -                                impl_handle = (sa_handle_impl_t)
     1740 +                                sa_handle_t handle =
1746 1741                                      sa_find_group_handle(group);
1747      -                                if (impl_handle != NULL) {
     1742 +                                if (handle != NULL) {
1748 1743                                          ret = sa_delete_share(
1749      -                                            impl_handle->scfhandle, group,
     1744 +                                            handle->scfhandle, group,
1750 1745                                              share);
1751 1746                                  } else {
1752 1747                                          ret = SA_SYSTEM_ERR;
1753 1748                                  }
1754 1749                          } else {
1755 1750                                  char *sharepath = sa_get_share_attr(share,
1756 1751                                      "path");
1757 1752                                  if (sharepath != NULL) {
1758 1753                                          ret = sa_zfs_set_sharenfs(group,
1759 1754                                              sharepath, 0);
↓ open down ↓ 22 lines elided ↑ open up ↑
1782 1777  int
1783 1778  sa_move_share(sa_group_t group, sa_share_t share)
1784 1779  {
1785 1780          sa_group_t oldgroup;
1786 1781          int ret = SA_OK;
1787 1782  
1788 1783          /* remove the node from its group then free the memory */
1789 1784  
1790 1785          oldgroup = sa_get_parent_group(share);
1791 1786          if (oldgroup != group) {
1792      -                sa_handle_impl_t impl_handle;
     1787 +                sa_handle_t handle;
1793 1788                  xmlUnlinkNode((xmlNodePtr)share);
1794 1789                  /*
1795 1790                   * now that the share isn't in its old group, add to
1796 1791                   * the new one
1797 1792                   */
1798 1793                  (void) xmlAddChild((xmlNodePtr)group, (xmlNodePtr)share);
1799 1794                  /* need to deal with SMF */
1800      -                impl_handle = (sa_handle_impl_t)sa_find_group_handle(group);
1801      -                if (impl_handle != NULL) {
     1795 +                handle = sa_find_group_handle(group);
     1796 +                if (handle != NULL) {
1802 1797                          /*
1803 1798                           * need to remove from old group first and then add to
1804 1799                           * new group. Ideally, we would do the other order but
1805 1800                           * need to avoid having the share in two groups at the
1806 1801                           * same time.
1807 1802                           */
1808      -                        ret = sa_delete_share(impl_handle->scfhandle, oldgroup,
     1803 +                        ret = sa_delete_share(handle->scfhandle, oldgroup,
1809 1804                              share);
1810 1805                          if (ret == SA_OK)
1811      -                                ret = sa_commit_share(impl_handle->scfhandle,
     1806 +                                ret = sa_commit_share(handle->scfhandle,
1812 1807                                      group, share);
1813 1808                  } else {
1814 1809                          ret = SA_SYSTEM_ERR;
1815 1810                  }
1816 1811          }
1817 1812          return (ret);
1818 1813  }
1819 1814  
1820 1815  /*
1821 1816   * sa_get_parent_group(share)
↓ open down ↓ 14 lines elided ↑ open up ↑
1836 1831                   * Eventually, groups of groups might come into being.
1837 1832                   */
1838 1833                  if (node == NULL ||
1839 1834                      xmlStrcmp(node->name, (xmlChar *)"sharecfg") == 0)
1840 1835                          node = NULL;
1841 1836          }
1842 1837          return ((sa_group_t)node);
1843 1838  }
1844 1839  
1845 1840  /*
1846      - * _sa_create_group(impl_handle, groupname)
     1841 + * _sa_create_group(handle, groupname)
1847 1842   *
1848 1843   * Create a group in the document. The caller will need to deal with
1849 1844   * configuration store and activation.
1850 1845   */
1851 1846  
1852 1847  sa_group_t
1853      -_sa_create_group(sa_handle_impl_t impl_handle, char *groupname)
     1848 +_sa_create_group(sa_handle_t handle, char *groupname)
1854 1849  {
1855 1850          xmlNodePtr node = NULL;
1856 1851  
1857 1852          if (sa_valid_group_name(groupname)) {
1858      -                node = xmlNewChild(impl_handle->tree, NULL, (xmlChar *)"group",
     1853 +                node = xmlNewChild(handle->tree, NULL, (xmlChar *)"group",
1859 1854                      NULL);
1860 1855                  if (node != NULL) {
1861 1856                          (void) xmlSetProp(node, (xmlChar *)"name",
1862 1857                              (xmlChar *)groupname);
1863 1858                          (void) xmlSetProp(node, (xmlChar *)"state",
1864 1859                              (xmlChar *)"enabled");
1865 1860                  }
1866 1861          }
1867 1862          return ((sa_group_t)node);
1868 1863  }
↓ open down ↓ 30 lines elided ↑ open up ↑
1899 1894   * operational properties must be added to the group at this point
1900 1895   * (via the SMF transaction model).
1901 1896   */
1902 1897  sa_group_t
1903 1898  sa_create_group(sa_handle_t handle, char *groupname, int *error)
1904 1899  {
1905 1900          xmlNodePtr node = NULL;
1906 1901          sa_group_t group;
1907 1902          int ret;
1908 1903          char rbacstr[SA_STRSIZE];
1909      -        sa_handle_impl_t impl_handle = (sa_handle_impl_t)handle;
1910 1904  
1911 1905          ret = SA_OK;
1912 1906  
1913      -        if (impl_handle == NULL || impl_handle->scfhandle == NULL) {
     1907 +        if (handle == NULL || handle->scfhandle == NULL) {
1914 1908                  ret = SA_SYSTEM_ERR;
1915 1909                  goto err;
1916 1910          }
1917 1911  
1918 1912          group = sa_get_group(handle, groupname);
1919 1913          if (group != NULL) {
1920 1914                  ret = SA_DUPLICATE_NAME;
1921 1915          } else {
1922 1916                  if (sa_valid_group_name(groupname)) {
1923      -                        node = xmlNewChild(impl_handle->tree, NULL,
     1917 +                        node = xmlNewChild(handle->tree, NULL,
1924 1918                              (xmlChar *)"group", NULL);
1925 1919                          if (node != NULL) {
1926 1920                                  (void) xmlSetProp(node, (xmlChar *)"name",
1927 1921                                      (xmlChar *)groupname);
1928 1922                                  /* default to the group being enabled */
1929 1923                                  (void) xmlSetProp(node, (xmlChar *)"state",
1930 1924                                      (xmlChar *)"enabled");
1931      -                                ret = sa_create_instance(impl_handle->scfhandle,
     1925 +                                ret = sa_create_instance(handle->scfhandle,
1932 1926                                      groupname);
1933 1927                                  if (ret == SA_OK) {
1934 1928                                          ret = sa_start_transaction(
1935      -                                            impl_handle->scfhandle,
     1929 +                                            handle->scfhandle,
1936 1930                                              "operation");
1937 1931                                  }
1938 1932                                  if (ret == SA_OK) {
1939 1933                                          ret = sa_set_property(
1940      -                                            impl_handle->scfhandle,
     1934 +                                            handle->scfhandle,
1941 1935                                              "state", "enabled");
1942 1936                                          if (ret == SA_OK) {
1943 1937                                                  ret = sa_end_transaction(
1944      -                                                    impl_handle->scfhandle,
1945      -                                                    impl_handle);
     1938 +                                                    handle->scfhandle,
     1939 +                                                    handle);
1946 1940                                          } else {
1947 1941                                                  sa_abort_transaction(
1948      -                                                    impl_handle->scfhandle);
     1942 +                                                    handle->scfhandle);
1949 1943                                          }
1950 1944                                  }
1951 1945                                  if (ret == SA_OK) {
1952 1946                                          /* initialize the RBAC strings */
1953 1947                                          ret = sa_start_transaction(
1954      -                                            impl_handle->scfhandle,
     1948 +                                            handle->scfhandle,
1955 1949                                              "general");
1956 1950                                          if (ret == SA_OK) {
1957 1951                                                  (void) snprintf(rbacstr,
1958 1952                                                      sizeof (rbacstr), "%s.%s",
1959 1953                                                      SA_RBAC_MANAGE, groupname);
1960 1954                                                  ret = sa_set_property(
1961      -                                                    impl_handle->scfhandle,
     1955 +                                                    handle->scfhandle,
1962 1956                                                      "action_authorization",
1963 1957                                                      rbacstr);
1964 1958                                          }
1965 1959                                          if (ret == SA_OK) {
1966 1960                                                  (void) snprintf(rbacstr,
1967 1961                                                      sizeof (rbacstr), "%s.%s",
1968 1962                                                      SA_RBAC_VALUE, groupname);
1969 1963                                                  ret = sa_set_property(
1970      -                                                    impl_handle->scfhandle,
     1964 +                                                    handle->scfhandle,
1971 1965                                                      "value_authorization",
1972 1966                                                      rbacstr);
1973 1967                                          }
1974 1968                                          if (ret == SA_OK) {
1975 1969                                                  ret = sa_end_transaction(
1976      -                                                    impl_handle->scfhandle,
1977      -                                                    impl_handle);
     1970 +                                                    handle->scfhandle,
     1971 +                                                    handle);
1978 1972                                          } else {
1979 1973                                                  sa_abort_transaction(
1980      -                                                    impl_handle->scfhandle);
     1974 +                                                    handle->scfhandle);
1981 1975                                          }
1982 1976                                  }
1983 1977                                  if (ret != SA_OK) {
1984 1978                                          /*
1985 1979                                           * Couldn't commit the group
1986 1980                                           * so we need to undo
1987 1981                                           * internally.
1988 1982                                           */
1989 1983                                          xmlUnlinkNode(node);
1990 1984                                          xmlFreeNode(node);
↓ open down ↓ 17 lines elided ↑ open up ↑
2008 2002   *
2009 2003   * Remove the specified group. This deletes from the SMF repository.
2010 2004   * All property groups and properties are removed.
2011 2005   */
2012 2006  
2013 2007  int
2014 2008  sa_remove_group(sa_group_t group)
2015 2009  {
2016 2010          char *name;
2017 2011          int ret = SA_OK;
2018      -        sa_handle_impl_t impl_handle;
     2012 +        sa_handle_t handle;
2019 2013  
2020      -        impl_handle = (sa_handle_impl_t)sa_find_group_handle(group);
2021      -        if (impl_handle != NULL) {
     2014 +        handle = sa_find_group_handle(group);
     2015 +        if (handle != NULL) {
2022 2016                  name = sa_get_group_attr(group, "name");
2023 2017                  if (name != NULL) {
2024      -                        ret = sa_delete_instance(impl_handle->scfhandle, name);
     2018 +                        ret = sa_delete_instance(handle->scfhandle, name);
2025 2019                          sa_free_attr_string(name);
2026 2020                  }
2027 2021                  xmlUnlinkNode((xmlNodePtr)group); /* make sure unlinked */
2028 2022                  xmlFreeNode((xmlNodePtr)group);   /* now it is gone */
2029 2023          } else {
2030 2024                  ret = SA_SYSTEM_ERR;
2031 2025          }
2032 2026          return (ret);
2033 2027  }
2034 2028  
↓ open down ↓ 76 lines elided ↑ open up ↑
2111 2105   *
2112 2106   * This will result in setting the property in the SMF repository as
2113 2107   * well as in the internal document.
2114 2108   */
2115 2109  
2116 2110  int
2117 2111  sa_set_group_attr(sa_group_t group, char *tag, char *value)
2118 2112  {
2119 2113          int ret;
2120 2114          char *groupname;
2121      -        sa_handle_impl_t impl_handle;
     2115 +        sa_handle_t handle;
2122 2116  
2123 2117          /*
2124 2118           * ZFS group/subgroup doesn't need the handle so shortcut.
2125 2119           */
2126 2120          if (sa_group_is_zfs(group)) {
2127 2121                  set_node_attr((void *)group, tag, value);
2128 2122                  return (SA_OK);
2129 2123          }
2130 2124  
2131      -        impl_handle = (sa_handle_impl_t)sa_find_group_handle(group);
2132      -        if (impl_handle != NULL) {
     2125 +        handle = sa_find_group_handle(group);
     2126 +        if (handle != NULL) {
2133 2127                  groupname = sa_get_group_attr(group, "name");
2134      -                ret = sa_get_instance(impl_handle->scfhandle, groupname);
     2128 +                ret = sa_get_instance(handle->scfhandle, groupname);
2135 2129                  if (ret == SA_OK) {
2136 2130                          set_node_attr((void *)group, tag, value);
2137      -                        ret = sa_start_transaction(impl_handle->scfhandle,
     2131 +                        ret = sa_start_transaction(handle->scfhandle,
2138 2132                              "operation");
2139 2133                          if (ret == SA_OK) {
2140      -                                ret = sa_set_property(impl_handle->scfhandle,
     2134 +                                ret = sa_set_property(handle->scfhandle,
2141 2135                                      tag, value);
2142 2136                                  if (ret == SA_OK)
2143 2137                                          ret = sa_end_transaction(
2144      -                                            impl_handle->scfhandle,
2145      -                                            impl_handle);
     2138 +                                            handle->scfhandle,
     2139 +                                            handle);
2146 2140                                  else
2147 2141                                          sa_abort_transaction(
2148      -                                            impl_handle->scfhandle);
     2142 +                                            handle->scfhandle);
2149 2143                          }
2150 2144                          if (ret == SA_SYSTEM_ERR)
2151 2145                                  ret = SA_NO_PERMISSION;
2152 2146                  }
2153 2147                  if (groupname != NULL)
2154 2148                          sa_free_attr_string(groupname);
2155 2149          } else {
2156 2150                  ret = SA_SYSTEM_ERR;
2157 2151          }
2158 2152          return (ret);
↓ open down ↓ 60 lines elided ↑ open up ↑
2219 2213                  if (resource != share && resource != NULL)
2220 2214                          ret = SA_DUPLICATE_NAME;
2221 2215          }
2222 2216          if (ret == SA_OK) {
2223 2217                  set_node_attr((void *)share, tag, value);
2224 2218                  if (group != NULL) {
2225 2219                          char *type;
2226 2220                          /* we can probably optimize this some */
2227 2221                          type = sa_get_share_attr(share, "type");
2228 2222                          if (type == NULL || strcmp(type, "transient") != 0) {
2229      -                                sa_handle_impl_t impl_handle;
2230      -                                impl_handle =
2231      -                                    (sa_handle_impl_t)sa_find_group_handle(
     2223 +                                sa_handle_t handle = sa_find_group_handle(
2232 2224                                      group);
2233      -                                if (impl_handle != NULL) {
     2225 +                                if (handle != NULL) {
2234 2226                                          ret = sa_commit_share(
2235      -                                            impl_handle->scfhandle, group,
     2227 +                                            handle->scfhandle, group,
2236 2228                                              share);
2237 2229                                  } else {
2238 2230                                          ret = SA_SYSTEM_ERR;
2239 2231                                  }
2240 2232                          }
2241 2233                          if (type != NULL)
2242 2234                                  sa_free_attr_string(type);
2243 2235                  }
2244 2236          }
2245 2237          return (ret);
↓ open down ↓ 274 lines elided ↑ open up ↑
2520 2512                  /* update a description */
2521 2513                  xmlNodeSetContent(node, (xmlChar *)content);
2522 2514          } else if (node != NULL && content == NULL) {
2523 2515                  /* remove an existing description */
2524 2516                  xmlUnlinkNode(node);
2525 2517                  xmlFreeNode(node);
2526 2518          }
2527 2519          group = sa_get_parent_group(share);
2528 2520          if (group != NULL &&
2529 2521              sa_is_persistent(share) && (!sa_group_is_zfs(group))) {
2530      -                sa_handle_impl_t impl_handle;
2531      -                impl_handle = (sa_handle_impl_t)sa_find_group_handle(group);
2532      -                if (impl_handle != NULL) {
2533      -                        ret = sa_commit_share(impl_handle->scfhandle, group,
     2522 +                sa_handle_t handle = sa_find_group_handle(group);
     2523 +                if (handle != NULL) {
     2524 +                        ret = sa_commit_share(handle->scfhandle, group,
2534 2525                              share);
2535 2526                  } else {
2536 2527                          ret = SA_SYSTEM_ERR;
2537 2528                  }
2538 2529          }
2539 2530          return (ret);
2540 2531  }
2541 2532  
2542 2533  /*
2543 2534   * fixproblemchars(string)
↓ open down ↓ 122 lines elided ↑ open up ↑
2666 2657                                      (sa_resource_t)group);
2667 2658                                  parent = sa_get_parent_group(share);
2668 2659                          }
2669 2660  
2670 2661                          sa_set_optionset_attr(optionset, "type", proto);
2671 2662  
2672 2663                          (void) sa_optionset_name(optionset, oname,
2673 2664                              sizeof (oname), id);
2674 2665                          groupname = sa_get_group_attr(parent, "name");
2675 2666                          if (groupname != NULL && sa_is_persistent(group)) {
2676      -                                sa_handle_impl_t impl_handle;
2677      -                                impl_handle =
2678      -                                    (sa_handle_impl_t)sa_find_group_handle(
     2667 +                                sa_handle_t handle = sa_find_group_handle(
2679 2668                                      group);
2680      -                                assert(impl_handle != NULL);
2681      -                                if (impl_handle != NULL) {
     2669 +                                assert(handle != NULL);
     2670 +                                if (handle != NULL) {
2682 2671                                          (void) sa_get_instance(
2683      -                                            impl_handle->scfhandle, groupname);
     2672 +                                            handle->scfhandle, groupname);
2684 2673                                          (void) sa_create_pgroup(
2685      -                                            impl_handle->scfhandle, oname);
     2674 +                                            handle->scfhandle, oname);
2686 2675                                  }
2687 2676                          }
2688 2677                          if (groupname != NULL)
2689 2678                                  sa_free_attr_string(groupname);
2690 2679                  }
2691 2680          }
2692 2681  
2693 2682          if (id != NULL)
2694 2683                  sa_free_attr_string(id);
2695 2684          return (optionset);
↓ open down ↓ 78 lines elided ↑ open up ↑
2774 2763   */
2775 2764  
2776 2765  int
2777 2766  sa_commit_properties(sa_optionset_t optionset, int clear)
2778 2767  {
2779 2768          sa_group_t group;
2780 2769          sa_group_t parent;
2781 2770          int zfs = 0;
2782 2771          int needsupdate = 0;
2783 2772          int ret = SA_OK;
2784      -        sa_handle_impl_t impl_handle;
     2773 +        sa_handle_t handle;
2785 2774  
2786 2775          group = sa_get_optionset_parent(optionset);
2787 2776          if (group != NULL && (sa_is_share(group) || is_zfs_group(group))) {
2788 2777                  /* only update ZFS if on a share */
2789 2778                  parent = sa_get_parent_group(group);
2790 2779                  zfs++;
2791 2780                  if (parent != NULL && is_zfs_group(parent))
2792 2781                          needsupdate = zfs_needs_update(group);
2793 2782                  else
2794 2783                          zfs = 0;
2795 2784          }
2796 2785          if (zfs) {
2797 2786                  if (!clear && needsupdate)
2798 2787                          ret = sa_zfs_update((sa_share_t)group);
2799 2788          } else {
2800      -                impl_handle = (sa_handle_impl_t)sa_find_group_handle(group);
2801      -                if (impl_handle != NULL) {
     2789 +                handle = sa_find_group_handle(group);
     2790 +                if (handle != NULL) {
2802 2791                          if (clear) {
2803 2792                                  (void) sa_abort_transaction(
2804      -                                    impl_handle->scfhandle);
     2793 +                                    handle->scfhandle);
2805 2794                          } else {
2806 2795                                  ret = sa_end_transaction(
2807      -                                    impl_handle->scfhandle, impl_handle);
     2796 +                                    handle->scfhandle, handle);
2808 2797                          }
2809 2798                  } else {
2810 2799                          ret = SA_SYSTEM_ERR;
2811 2800                  }
2812 2801          }
2813 2802          return (ret);
2814 2803  }
2815 2804  
2816 2805  /*
2817 2806   * sa_destroy_optionset(optionset)
↓ open down ↓ 19 lines elided ↑ open up ↑
2837 2826                          sa_resource_t resource = group;
2838 2827                          sa_share_t share = sa_get_resource_parent(resource);
2839 2828                          group = sa_get_parent_group(share);
2840 2829                          id = sa_get_share_attr(share, "id");
2841 2830                  } else if (sa_is_share(group)) {
2842 2831                          id = sa_get_share_attr((sa_share_t)group, "id");
2843 2832                  }
2844 2833                  ispersist = sa_is_persistent(group);
2845 2834          }
2846 2835          if (ispersist) {
2847      -                sa_handle_impl_t impl_handle;
     2836 +                sa_handle_t handle = sa_find_group_handle(group);
2848 2837                  len = sa_optionset_name(optionset, name, sizeof (name), id);
2849      -                impl_handle = (sa_handle_impl_t)sa_find_group_handle(group);
2850      -                if (impl_handle != NULL) {
     2838 +                if (handle != NULL) {
2851 2839                          if (len > 0) {
2852      -                                ret = sa_delete_pgroup(impl_handle->scfhandle,
     2840 +                                ret = sa_delete_pgroup(handle->scfhandle,
2853 2841                                      name);
2854 2842                          }
2855 2843                  } else {
2856 2844                          ret = SA_SYSTEM_ERR;
2857 2845                  }
2858 2846          }
2859 2847          xmlUnlinkNode((xmlNodePtr)optionset);
2860 2848          xmlFreeNode((xmlNodePtr)optionset);
2861 2849          if (id != NULL)
2862 2850                  sa_free_attr_string(id);
↓ open down ↓ 43 lines elided ↑ open up ↑
2906 2894                  security = (sa_security_t)xmlNewChild((xmlNodePtr)group,
2907 2895                      NULL, (xmlChar *)"security", NULL);
2908 2896                  if (security != NULL) {
2909 2897                          char oname[SA_STRSIZE];
2910 2898                          sa_set_security_attr(security, "type", proto);
2911 2899  
2912 2900                          sa_set_security_attr(security, "sectype", sectype);
2913 2901                          (void) sa_security_name(security, oname,
2914 2902                              sizeof (oname), id);
2915 2903                          if (groupname != NULL && sa_is_persistent(group)) {
2916      -                                sa_handle_impl_t impl_handle;
2917      -                                impl_handle =
2918      -                                    (sa_handle_impl_t)sa_find_group_handle(
     2904 +                                sa_handle_t handle = sa_find_group_handle(
2919 2905                                      group);
2920      -                                if (impl_handle != NULL) {
     2906 +                                if (handle != NULL) {
2921 2907                                          (void) sa_get_instance(
2922      -                                            impl_handle->scfhandle, groupname);
     2908 +                                            handle->scfhandle, groupname);
2923 2909                                          (void) sa_create_pgroup(
2924      -                                            impl_handle->scfhandle, oname);
     2910 +                                            handle->scfhandle, oname);
2925 2911                                  }
2926 2912                          }
2927 2913                  }
2928 2914          }
2929 2915          if (id != NULL)
2930 2916                  sa_free_attr_string(id);
2931 2917          if (groupname != NULL)
2932 2918                  sa_free_attr_string(groupname);
2933 2919          return (security);
2934 2920  }
↓ open down ↓ 22 lines elided ↑ open up ↑
2957 2943                  iszfs = sa_group_is_zfs(group);
2958 2944  
2959 2945          if (group != NULL && !iszfs) {
2960 2946                  if (sa_is_share(group))
2961 2947                          ispersist = sa_is_persistent(group);
2962 2948                  id = sa_get_share_attr((sa_share_t)group, "id");
2963 2949          }
2964 2950          if (ispersist) {
2965 2951                  len = sa_security_name(security, name, sizeof (name), id);
2966 2952                  if (!iszfs && len > 0) {
2967      -                        sa_handle_impl_t impl_handle;
2968      -                        impl_handle =
2969      -                            (sa_handle_impl_t)sa_find_group_handle(group);
2970      -                        if (impl_handle != NULL) {
2971      -                                ret = sa_delete_pgroup(impl_handle->scfhandle,
     2953 +                        sa_handle_t handle = sa_find_group_handle(group);
     2954 +                        if (handle != NULL) {
     2955 +                                ret = sa_delete_pgroup(handle->scfhandle,
2972 2956                                      name);
2973 2957                          } else {
2974 2958                                  ret = SA_SYSTEM_ERR;
2975 2959                          }
2976 2960                  }
2977 2961          }
2978 2962          xmlUnlinkNode((xmlNodePtr)security);
2979 2963          xmlFreeNode((xmlNodePtr)security);
2980 2964          if (iszfs)
2981 2965                  ret = sa_zfs_update(group);
↓ open down ↓ 88 lines elided ↑ open up ↑
3070 3054          char *name;
3071 3055          char *valstr;
3072 3056          int ret = SA_OK;
3073 3057          scf_transaction_entry_t *entry;
3074 3058          scf_value_t *value;
3075 3059          int opttype; /* 1 == optionset, 0 == security */
3076 3060          char *id = NULL;
3077 3061          int iszfs = 0;
3078 3062          sa_group_t parent = NULL;
3079 3063          sa_share_t share = NULL;
3080      -        sa_handle_impl_t impl_handle;
     3064 +        sa_handle_t handle;
3081 3065          scfutilhandle_t  *scf_handle;
3082 3066  
3083 3067          if (!sa_is_persistent(group)) {
3084 3068                  /*
3085 3069                   * if the group/share is not persistent we don't need
3086 3070                   * to do anything here
3087 3071                   */
3088 3072                  return (SA_OK);
3089 3073          }
3090      -        impl_handle = (sa_handle_impl_t)sa_find_group_handle(group);
3091      -        if (impl_handle == NULL || impl_handle->scfhandle == NULL)
     3074 +        handle = sa_find_group_handle(group);
     3075 +        if (handle == NULL || handle->scfhandle == NULL)
3092 3076                  return (SA_SYSTEM_ERR);
3093      -        scf_handle = impl_handle->scfhandle;
     3077 +        scf_handle = handle->scfhandle;
3094 3078          name = sa_get_property_attr(prop, "type");
3095 3079          valstr = sa_get_property_attr(prop, "value");
3096 3080          entry = scf_entry_create(scf_handle->handle);
3097 3081          opttype = is_nodetype((void *)optionset, "optionset");
3098 3082  
3099 3083          /*
3100 3084           * Check for share vs. resource since they need slightly
3101 3085           * different treatment given the hierarchy.
3102 3086           */
3103 3087          if (valstr != NULL && entry != NULL) {
↓ open down ↓ 177 lines elided ↑ open up ↑
3281 3265                  group = parent;
3282 3266          }
3283 3267  
3284 3268          if (property == NULL) {
3285 3269                  ret = SA_NO_MEMORY;
3286 3270          } else {
3287 3271                  char oname[SA_STRSIZE];
3288 3272  
3289 3273                  if (!is_zfs_group(group)) {
3290 3274                          char *id = NULL;
3291      -                        sa_handle_impl_t impl_handle;
     3275 +                        sa_handle_t handle;
3292 3276                          scfutilhandle_t  *scf_handle;
3293 3277  
3294      -                        impl_handle = (sa_handle_impl_t)sa_find_group_handle(
3295      -                            group);
3296      -                        if (impl_handle == NULL ||
3297      -                            impl_handle->scfhandle == NULL)
     3278 +                        handle = sa_find_group_handle(group);
     3279 +                        if (handle == NULL ||
     3280 +                            handle->scfhandle == NULL)
3298 3281                                  ret = SA_SYSTEM_ERR;
3299 3282                          if (ret == SA_OK) {
3300      -                                scf_handle = impl_handle->scfhandle;
     3283 +                                scf_handle = handle->scfhandle;
3301 3284                                  if (sa_is_share((sa_group_t)parent)) {
3302 3285                                          id = sa_get_share_attr(
3303 3286                                              (sa_share_t)parent, "id");
3304 3287                                  }
3305 3288                                  if (scf_handle->trans == NULL) {
3306 3289                                          if (is_nodetype(object, "optionset")) {
3307 3290                                                  (void) sa_optionset_name(
3308 3291                                                      (sa_optionset_t)object,
3309 3292                                                      oname, sizeof (oname), id);
3310 3293                                          } else {
↓ open down ↓ 478 lines elided ↑ open up ↑
3789 3772                                  (void) snprintf(istring, sizeof (istring), "%d",
3790 3773                                      index);
3791 3774                                  (void) xmlSetProp(node, (xmlChar *)"id",
3792 3775                                      (xmlChar *)istring);
3793 3776  
3794 3777                                  if (!sa_is_persistent((sa_group_t)share))
3795 3778                                          goto done;
3796 3779  
3797 3780                                  if (!sa_group_is_zfs(group)) {
3798 3781                                          /* ZFS doesn't use resource names */
3799      -                                        sa_handle_impl_t ihandle;
     3782 +                                        sa_handle_t handle;
3800 3783  
3801      -                                        ihandle = (sa_handle_impl_t)
3802      -                                            sa_find_group_handle(
     3784 +                                        handle = sa_find_group_handle(
3803 3785                                              group);
3804      -                                        if (ihandle != NULL)
     3786 +                                        if (handle != NULL)
3805 3787                                                  err = sa_commit_share(
3806      -                                                    ihandle->scfhandle, group,
     3788 +                                                    handle->scfhandle, group,
3807 3789                                                      share);
3808 3790                                          else
3809 3791                                                  err = SA_SYSTEM_ERR;
3810 3792                                  } else {
3811 3793                                          err = sa_zfs_update((sa_share_t)group);
3812 3794                                  }
3813 3795                          }
3814 3796                  }
3815 3797          }
3816 3798  done:
↓ open down ↓ 40 lines elided ↑ open up ↑
3857 3839  
3858 3840          /* Remove from the share */
3859 3841          xmlUnlinkNode((xmlNode *)resource);
3860 3842          xmlFreeNode((xmlNode *)resource);
3861 3843  
3862 3844          /* only do SMF action if permanent and not ZFS */
3863 3845          if (transient)
3864 3846                  return (ret);
3865 3847  
3866 3848          if (!sa_group_is_zfs(group)) {
3867      -                sa_handle_impl_t ihandle;
3868      -                ihandle = (sa_handle_impl_t)sa_find_group_handle(group);
3869      -                if (ihandle != NULL)
3870      -                        ret = sa_commit_share(ihandle->scfhandle, group, share);
     3849 +                sa_handle_t handle = sa_find_group_handle(group);
     3850 +                if (handle != NULL)
     3851 +                        ret = sa_commit_share(handle->scfhandle, group, share);
3871 3852                  else
3872 3853                          ret = SA_SYSTEM_ERR;
3873 3854          } else {
3874 3855                  ret = sa_zfs_update((sa_share_t)group);
3875 3856          }
3876 3857  
3877 3858          return (ret);
3878 3859  }
3879 3860  
3880 3861  /*
↓ open down ↓ 42 lines elided ↑ open up ↑
3923 3904          sa_handle_t handle = NULL;
3924 3905  
3925 3906          share = sa_get_resource_parent(resource);
3926 3907          if (share == NULL)
3927 3908                  return (ret);
3928 3909  
3929 3910          group = sa_get_parent_group(share);
3930 3911          if (group == NULL)
3931 3912                  return (ret);
3932 3913  
3933      -        handle = (sa_handle_impl_t)sa_find_group_handle(group);
     3914 +        handle = sa_find_group_handle(group);
3934 3915          if (handle == NULL)
3935 3916                  return (ret);
3936 3917  
3937 3918          target = sa_find_resource(handle, newname);
3938 3919          if (target != NULL) {
3939 3920                  ret = SA_DUPLICATE_NAME;
3940 3921          } else {
3941 3922                  /*
3942 3923                   * Everything appears to be valid at this
3943 3924                   * point. Change the name of the active share and then
3944 3925                   * update the share in the appropriate repository.
3945 3926                   */
3946 3927                  ret = proto_rename_resource(handle, group, resource, newname);
3947 3928                  set_node_attr(resource, "name", newname);
3948 3929  
3949 3930                  if (!sa_is_persistent((sa_group_t)share))
3950 3931                          return (ret);
3951 3932  
3952 3933                  if (!sa_group_is_zfs(group)) {
3953      -                        sa_handle_impl_t ihandle = (sa_handle_impl_t)handle;
3954      -                        ret = sa_commit_share(ihandle->scfhandle, group,
     3934 +                        ret = sa_commit_share(handle->scfhandle, group,
3955 3935                              share);
3956 3936                  } else {
3957 3937                          ret = sa_zfs_update((sa_share_t)group);
3958 3938                  }
3959 3939          }
3960 3940          return (ret);
3961 3941  }
3962 3942  
3963 3943  /*
3964 3944   * sa_get_resource_attr(resource, tag)
↓ open down ↓ 392 lines elided ↑ open up ↑
4357 4337          } else if (node != NULL && content == NULL) {
4358 4338                  /* remove an existing description */
4359 4339                  xmlUnlinkNode(node);
4360 4340                  xmlFreeNode(node);
4361 4341          }
4362 4342  
4363 4343          share = sa_get_resource_parent(resource);
4364 4344          group = sa_get_parent_group(share);
4365 4345          if (group != NULL &&
4366 4346              sa_is_persistent(share) && (!sa_group_is_zfs(group))) {
4367      -                sa_handle_impl_t impl_handle;
4368      -                impl_handle = (sa_handle_impl_t)sa_find_group_handle(group);
4369      -                if (impl_handle != NULL)
4370      -                        ret = sa_commit_share(impl_handle->scfhandle,
     4347 +                sa_handle_t handle = sa_find_group_handle(group);
     4348 +                if (handle != NULL)
     4349 +                        ret = sa_commit_share(handle->scfhandle,
4371 4350                              group, share);
4372 4351                  else
4373 4352                          ret = SA_SYSTEM_ERR;
4374 4353          }
4375 4354          return (ret);
4376 4355  }
4377 4356  
4378 4357  /*
4379 4358   * sa_get_resource_description(share)
4380 4359   *
↓ open down ↓ 21 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX