Print this page
10109 libzonecfg needs a smatch fix


   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  * Copyright 2015 Nexenta Systems, Inc. All rights reserved.
  26  */
  27 
  28 #include <libsysevent.h>
  29 #include <pthread.h>
  30 #include <stdlib.h>
  31 #include <errno.h>
  32 #include <fnmatch.h>
  33 #include <strings.h>
  34 #include <unistd.h>
  35 #include <assert.h>
  36 #include <libgen.h>
  37 #include <libintl.h>
  38 #include <alloca.h>
  39 #include <ctype.h>
  40 #include <sys/acl.h>
  41 #include <sys/stat.h>
  42 #include <sys/brand.h>
  43 #include <sys/mntio.h>
  44 #include <sys/mnttab.h>


2964 static int
2965 zonecfg_devwalk_cb(const char *path, const struct stat *st, int f,
2966     struct FTW *ftw)
2967 {
2968         acl_t *acl;
2969         char *acl_txt = NULL;
2970 
2971         /* skip all but character and block devices */
2972         if (!S_ISBLK(st->st_mode) && !S_ISCHR(st->st_mode))
2973                 return (0);
2974 
2975         if ((acl_get(path, ACL_NO_TRIVIAL, &acl) == 0) &&
2976             acl != NULL) {
2977                 acl_txt = acl_totext(acl, ACL_NORESOLVE);
2978                 acl_free(acl);
2979         }
2980 
2981         if (strlen(path) <= g_devwalk_skip_prefix)
2982                 return (0);
2983 
2984         g_devwalk_cb(path + g_devwalk_skip_prefix, st->st_uid, st->st_gid,
2985             st->st_mode & S_IAMB, acl_txt != NULL ? acl_txt : "",
2986             g_devwalk_data);
2987         free(acl_txt);
2988         return (0);
2989 }
2990 
2991 /*
2992  * Walk the dev tree for the zone specified by hdl and call the
2993  * get_detach_dev_entry call-back function for each entry in the tree.  The
2994  * call-back will be passed the name, uid, gid, mode, acl string and the
2995  * handle input parameter for each dev entry.
2996  *
2997  * Data is passed to get_detach_dev_entry through the global variables
2998  * g_devwalk_data, *g_devwalk_cb, and g_devwalk_skip_prefix.  The
2999  * zonecfg_devwalk_cb function will actually call get_detach_dev_entry.
3000  */
3001 int
3002 zonecfg_dev_manifest(zone_dochandle_t hdl)
3003 {
3004         char path[MAXPATHLEN];
3005         int ret;




   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  * Copyright (c) 2018, Joyent, Inc.
  26  * Copyright 2015 Nexenta Systems, Inc. All rights reserved.
  27  */
  28 
  29 #include <libsysevent.h>
  30 #include <pthread.h>
  31 #include <stdlib.h>
  32 #include <errno.h>
  33 #include <fnmatch.h>
  34 #include <strings.h>
  35 #include <unistd.h>
  36 #include <assert.h>
  37 #include <libgen.h>
  38 #include <libintl.h>
  39 #include <alloca.h>
  40 #include <ctype.h>
  41 #include <sys/acl.h>
  42 #include <sys/stat.h>
  43 #include <sys/brand.h>
  44 #include <sys/mntio.h>
  45 #include <sys/mnttab.h>


2965 static int
2966 zonecfg_devwalk_cb(const char *path, const struct stat *st, int f,
2967     struct FTW *ftw)
2968 {
2969         acl_t *acl;
2970         char *acl_txt = NULL;
2971 
2972         /* skip all but character and block devices */
2973         if (!S_ISBLK(st->st_mode) && !S_ISCHR(st->st_mode))
2974                 return (0);
2975 
2976         if ((acl_get(path, ACL_NO_TRIVIAL, &acl) == 0) &&
2977             acl != NULL) {
2978                 acl_txt = acl_totext(acl, ACL_NORESOLVE);
2979                 acl_free(acl);
2980         }
2981 
2982         if (strlen(path) <= g_devwalk_skip_prefix)
2983                 return (0);
2984 
2985         (void) g_devwalk_cb(path + g_devwalk_skip_prefix, st->st_uid,
2986             st->st_gid, st->st_mode & S_IAMB, acl_txt != NULL ? acl_txt : "",
2987             g_devwalk_data);
2988         free(acl_txt);
2989         return (0);
2990 }
2991 
2992 /*
2993  * Walk the dev tree for the zone specified by hdl and call the
2994  * get_detach_dev_entry call-back function for each entry in the tree.  The
2995  * call-back will be passed the name, uid, gid, mode, acl string and the
2996  * handle input parameter for each dev entry.
2997  *
2998  * Data is passed to get_detach_dev_entry through the global variables
2999  * g_devwalk_data, *g_devwalk_cb, and g_devwalk_skip_prefix.  The
3000  * zonecfg_devwalk_cb function will actually call get_detach_dev_entry.
3001  */
3002 int
3003 zonecfg_dev_manifest(zone_dochandle_t hdl)
3004 {
3005         char path[MAXPATHLEN];
3006         int ret;