Print this page
10124 smatch fixes for cryptoadm


   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  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
  23  */
  24 /*
  25  * Copyright 2010 Nexenta Systems, Inc.  All rights reserved.

  26  */
  27 
  28 #include <fcntl.h>
  29 #include <stdio.h>
  30 #include <stdlib.h>
  31 #include <strings.h>
  32 #include <unistd.h>
  33 #include <locale.h>
  34 #include <libgen.h>
  35 #include <sys/types.h>
  36 #include <sys/varargs.h>
  37 #include <zone.h>
  38 #include <sys/crypto/ioctladmin.h>
  39 #include "cryptoadm.h"
  40 
  41 #define DEFAULT_DEV_NUM 5
  42 #define DEFAULT_SOFT_NUM 10
  43 
  44 static crypto_get_soft_info_t *setup_get_soft_info(char *, int);
  45 


 249 /*
 250  * Get the device list from kernel.
 251  */
 252 int
 253 get_dev_list(crypto_get_dev_list_t **ppdevlist)
 254 {
 255         crypto_get_dev_list_t   *pdevlist;
 256         int                     fd = -1;
 257         int                     count = DEFAULT_DEV_NUM;
 258 
 259         pdevlist = malloc(sizeof (crypto_get_dev_list_t) +
 260             sizeof (crypto_dev_list_entry_t) * (count - 1));
 261         if (pdevlist == NULL) {
 262                 cryptodebug("out of memory.");
 263                 return (FAILURE);
 264         }
 265 
 266         if ((fd = open(ADMIN_IOCTL_DEVICE, O_RDONLY)) == -1) {
 267                 cryptoerror(LOG_STDERR, gettext("failed to open %s: %s"),
 268                     ADMIN_IOCTL_DEVICE, strerror(errno));

 269                 return (FAILURE);
 270         }
 271 
 272         pdevlist->dl_dev_count = count;
 273         if (ioctl(fd, CRYPTO_GET_DEV_LIST, pdevlist) == -1) {
 274                 cryptodebug("CRYPTO_GET_DEV_LIST ioctl failed: %s",
 275                     strerror(errno));
 276                 free(pdevlist);
 277                 (void) close(fd);
 278                 return (FAILURE);
 279         }
 280 
 281         /* BUFFER is too small, get the number of devices and retry it. */
 282         if (pdevlist->dl_return_value == CRYPTO_BUFFER_TOO_SMALL) {
 283                 count = pdevlist->dl_dev_count;
 284                 free(pdevlist);
 285                 pdevlist = malloc(sizeof (crypto_get_dev_list_t) +
 286                     sizeof (crypto_dev_list_entry_t) * (count - 1));
 287                 if (pdevlist == NULL) {
 288                         cryptodebug("out of memory.");




   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  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
  23  */
  24 /*
  25  * Copyright 2010 Nexenta Systems, Inc.  All rights reserved.
  26  * Copyright (c) 2018, Joyent, Inc.
  27  */
  28 
  29 #include <fcntl.h>
  30 #include <stdio.h>
  31 #include <stdlib.h>
  32 #include <strings.h>
  33 #include <unistd.h>
  34 #include <locale.h>
  35 #include <libgen.h>
  36 #include <sys/types.h>
  37 #include <sys/varargs.h>
  38 #include <zone.h>
  39 #include <sys/crypto/ioctladmin.h>
  40 #include "cryptoadm.h"
  41 
  42 #define DEFAULT_DEV_NUM 5
  43 #define DEFAULT_SOFT_NUM 10
  44 
  45 static crypto_get_soft_info_t *setup_get_soft_info(char *, int);
  46 


 250 /*
 251  * Get the device list from kernel.
 252  */
 253 int
 254 get_dev_list(crypto_get_dev_list_t **ppdevlist)
 255 {
 256         crypto_get_dev_list_t   *pdevlist;
 257         int                     fd = -1;
 258         int                     count = DEFAULT_DEV_NUM;
 259 
 260         pdevlist = malloc(sizeof (crypto_get_dev_list_t) +
 261             sizeof (crypto_dev_list_entry_t) * (count - 1));
 262         if (pdevlist == NULL) {
 263                 cryptodebug("out of memory.");
 264                 return (FAILURE);
 265         }
 266 
 267         if ((fd = open(ADMIN_IOCTL_DEVICE, O_RDONLY)) == -1) {
 268                 cryptoerror(LOG_STDERR, gettext("failed to open %s: %s"),
 269                     ADMIN_IOCTL_DEVICE, strerror(errno));
 270                 free(pdevlist);
 271                 return (FAILURE);
 272         }
 273 
 274         pdevlist->dl_dev_count = count;
 275         if (ioctl(fd, CRYPTO_GET_DEV_LIST, pdevlist) == -1) {
 276                 cryptodebug("CRYPTO_GET_DEV_LIST ioctl failed: %s",
 277                     strerror(errno));
 278                 free(pdevlist);
 279                 (void) close(fd);
 280                 return (FAILURE);
 281         }
 282 
 283         /* BUFFER is too small, get the number of devices and retry it. */
 284         if (pdevlist->dl_return_value == CRYPTO_BUFFER_TOO_SMALL) {
 285                 count = pdevlist->dl_dev_count;
 286                 free(pdevlist);
 287                 pdevlist = malloc(sizeof (crypto_get_dev_list_t) +
 288                     sizeof (crypto_dev_list_entry_t) * (count - 1));
 289                 if (pdevlist == NULL) {
 290                         cryptodebug("out of memory.");