Print this page
7806 svccfg restore segfaults in upgrade_manifestfiles
Reviewed by: Toomas Soome <tsoome@me.com>
Reviewed by: Jason King <jason.brian.king@gmail.com>


   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
  24  * Copyright 2015 Joyent, Inc.
  25  * Copyright 2012 Milan Jurik. All rights reserved.

  26  */
  27 
  28 
  29 #include <alloca.h>
  30 #include <assert.h>
  31 #include <ctype.h>
  32 #include <door.h>
  33 #include <errno.h>
  34 #include <fcntl.h>
  35 #include <fnmatch.h>
  36 #include <inttypes.h>
  37 #include <libintl.h>
  38 #include <libnvpair.h>
  39 #include <libscf.h>
  40 #include <libscf_priv.h>
  41 #include <libtecla.h>
  42 #include <libuutil.h>
  43 #include <limits.h>
  44 #include <locale.h>
  45 #include <stdarg.h>


3878         default:
3879                 bad_error("scf_transaction_destroy", scf_error());
3880                 /* NOTREACHED */
3881         }
3882 }
3883 
3884 /*
3885  * Used to add the manifests to the list of currently supported manifests.
3886  * We can modify the existing manifest list removing entries if the files
3887  * don't exist.
3888  *
3889  * Get the old list and the new file name
3890  * If the new file name is in the list return
3891  * If not then add the file to the list.
3892  * As we process the list check to see if the files in the old list exist
3893  *      if not then remove the file from the list.
3894  * Commit the list of manifest file names.
3895  *
3896  */
3897 static int
3898 upgrade_manifestfiles(pgroup_t *pg, const entity_t *ient,
3899     const scf_snaplevel_t *running, void *ent)
3900 {
3901         scf_propertygroup_t *ud_mfsts_pg = NULL;
3902         scf_property_t *ud_prop = NULL;
3903         scf_iter_t *ud_prop_iter;
3904         scf_value_t *fname_value;
3905         scf_callback_t cbdata;
3906         pgroup_t *mfst_pgroup;
3907         property_t *mfst_prop;
3908         property_t *old_prop;
3909         char *pname;
3910         char *fval;
3911         char *old_pname;
3912         char *old_fval;
3913         int no_upgrade_pg;
3914         int mfst_seen;
3915         int r;
3916 
3917         const int issvc = (ient->sc_etype == SVCCFG_SERVICE_OBJECT);
3918 


3948                         bad_error(running ? "scf_snaplevel_get_pg" :
3949                             "entity_get_pg", scf_error());
3950                 }
3951         }
3952 
3953         if (no_upgrade_pg) {
3954                 cbdata.sc_handle = g_hndl;
3955                 cbdata.sc_parent = ent;
3956                 cbdata.sc_service = issvc;
3957                 cbdata.sc_flags = SCI_FORCE;
3958                 cbdata.sc_source_fmri = ient->sc_fmri;
3959                 cbdata.sc_target_fmri = ient->sc_fmri;
3960 
3961                 if (entity_pgroup_import(pg, &cbdata) != UU_WALK_NEXT)
3962                         return (cbdata.sc_err);
3963 
3964                 return (0);
3965         }
3966 
3967         /* Fetch the new manifests property group */
3968         for (mfst_pgroup = uu_list_first(ient->sc_pgroups);
3969             mfst_pgroup != NULL;
3970             mfst_pgroup = uu_list_next(ient->sc_pgroups, mfst_pgroup)) {
3971                 if (strcmp(mfst_pgroup->sc_pgroup_name,
3972                     SCF_PG_MANIFESTFILES) == 0)
3973                         break;
3974         }
3975 
3976         if ((r = scf_iter_pg_properties(ud_prop_iter, ud_mfsts_pg)) !=
3977             SCF_SUCCESS)
3978                 return (-1);
3979 
3980         if ((pname = malloc(MAXPATHLEN)) == NULL)
3981                 return (ENOMEM);
3982         if ((fval = malloc(MAXPATHLEN)) == NULL) {
3983                 free(pname);
3984                 return (ENOMEM);
3985         }
3986 
3987         while ((r = scf_iter_next_property(ud_prop_iter, ud_prop)) == 1) {
3988                 mfst_seen = 0;
3989                 if (scf_property_get_name(ud_prop, pname, MAXPATHLEN) < 0)
3990                         continue;
3991 
3992                 for (mfst_prop = uu_list_first(mfst_pgroup->sc_pgroup_props);
3993                     mfst_prop != NULL;
3994                     mfst_prop = uu_list_next(mfst_pgroup->sc_pgroup_props,




   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
  24  * Copyright 2015 Joyent, Inc.
  25  * Copyright 2012 Milan Jurik. All rights reserved.
  26  * Copyright 2017 RackTop Systems.
  27  */
  28 
  29 
  30 #include <alloca.h>
  31 #include <assert.h>
  32 #include <ctype.h>
  33 #include <door.h>
  34 #include <errno.h>
  35 #include <fcntl.h>
  36 #include <fnmatch.h>
  37 #include <inttypes.h>
  38 #include <libintl.h>
  39 #include <libnvpair.h>
  40 #include <libscf.h>
  41 #include <libscf_priv.h>
  42 #include <libtecla.h>
  43 #include <libuutil.h>
  44 #include <limits.h>
  45 #include <locale.h>
  46 #include <stdarg.h>


3879         default:
3880                 bad_error("scf_transaction_destroy", scf_error());
3881                 /* NOTREACHED */
3882         }
3883 }
3884 
3885 /*
3886  * Used to add the manifests to the list of currently supported manifests.
3887  * We can modify the existing manifest list removing entries if the files
3888  * don't exist.
3889  *
3890  * Get the old list and the new file name
3891  * If the new file name is in the list return
3892  * If not then add the file to the list.
3893  * As we process the list check to see if the files in the old list exist
3894  *      if not then remove the file from the list.
3895  * Commit the list of manifest file names.
3896  *
3897  */
3898 static int
3899 upgrade_manifestfiles(pgroup_t *pg, entity_t *ient,
3900     const scf_snaplevel_t *running, void *ent)
3901 {
3902         scf_propertygroup_t *ud_mfsts_pg = NULL;
3903         scf_property_t *ud_prop = NULL;
3904         scf_iter_t *ud_prop_iter;
3905         scf_value_t *fname_value;
3906         scf_callback_t cbdata;
3907         pgroup_t *mfst_pgroup;
3908         property_t *mfst_prop;
3909         property_t *old_prop;
3910         char *pname;
3911         char *fval;
3912         char *old_pname;
3913         char *old_fval;
3914         int no_upgrade_pg;
3915         int mfst_seen;
3916         int r;
3917 
3918         const int issvc = (ient->sc_etype == SVCCFG_SERVICE_OBJECT);
3919 


3949                         bad_error(running ? "scf_snaplevel_get_pg" :
3950                             "entity_get_pg", scf_error());
3951                 }
3952         }
3953 
3954         if (no_upgrade_pg) {
3955                 cbdata.sc_handle = g_hndl;
3956                 cbdata.sc_parent = ent;
3957                 cbdata.sc_service = issvc;
3958                 cbdata.sc_flags = SCI_FORCE;
3959                 cbdata.sc_source_fmri = ient->sc_fmri;
3960                 cbdata.sc_target_fmri = ient->sc_fmri;
3961 
3962                 if (entity_pgroup_import(pg, &cbdata) != UU_WALK_NEXT)
3963                         return (cbdata.sc_err);
3964 
3965                 return (0);
3966         }
3967 
3968         /* Fetch the new manifests property group */
3969         mfst_pgroup = internal_pgroup_find_or_create(ient,
3970             SCF_PG_MANIFESTFILES, SCF_GROUP_FRAMEWORK);
3971         assert(mfst_pgroup != NULL);




3972 
3973         if ((r = scf_iter_pg_properties(ud_prop_iter, ud_mfsts_pg)) !=
3974             SCF_SUCCESS)
3975                 return (-1);
3976 
3977         if ((pname = malloc(MAXPATHLEN)) == NULL)
3978                 return (ENOMEM);
3979         if ((fval = malloc(MAXPATHLEN)) == NULL) {
3980                 free(pname);
3981                 return (ENOMEM);
3982         }
3983 
3984         while ((r = scf_iter_next_property(ud_prop_iter, ud_prop)) == 1) {
3985                 mfst_seen = 0;
3986                 if (scf_property_get_name(ud_prop, pname, MAXPATHLEN) < 0)
3987                         continue;
3988 
3989                 for (mfst_prop = uu_list_first(mfst_pgroup->sc_pgroup_props);
3990                     mfst_prop != NULL;
3991                     mfst_prop = uu_list_next(mfst_pgroup->sc_pgroup_props,