Print this page
6862532 "cryptoadm: failed to parse configuration" error
6353443 domestic (crypt) source build leaves stuff it shouldn't
6818180 mac(1) printed "invalid key" error message when user input an invalid passphrase

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/cmd-crypto/cryptoadm/adm_kef_util.c
          +++ new/usr/src/cmd/cmd-crypto/cryptoadm/adm_kef_util.c
↓ open down ↓ 11 lines elided ↑ open up ↑
  12   12   *
  13   13   * When distributing Covered Code, include this CDDL HEADER in each
  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      - * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
       22 + * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
  23   23   * Use is subject to license terms.
  24   24   */
  25   25  
  26   26  #include <errno.h>
  27   27  #include <fcntl.h>
  28   28  #include <stdio.h>
  29   29  #include <stdlib.h>
  30   30  #include <strings.h>
  31   31  #include <time.h>
  32   32  #include <unistd.h>
↓ open down ↓ 2 lines elided ↑ open up ↑
  35   35  #include <zone.h>
  36   36  #include <sys/stat.h>
  37   37  #include "cryptoadm.h"
  38   38  
  39   39  static int err; /* To store errno which may be overwritten by gettext() */
  40   40  static int build_entrylist(entry_t *, entrylist_t **);
  41   41  static entry_t *dup_entry(entry_t *);
  42   42  static mechlist_t *dup_mechlist(mechlist_t *);
  43   43  static entry_t *getent(char *, entrylist_t *);
  44   44  static int interpret(char *, entry_t **);
  45      -static int parse_sup_dis_list(char *, entry_t *);
       45 +static int parse_sup_dis_list(const char *buf, entry_t *pent);
  46   46  
  47   47  
  48   48  /*
  49   49   * Duplicate the mechanism list.  A null pointer is returned if the storage
  50   50   * space available is insufficient or the input argument is NULL.
  51   51   */
  52   52  static mechlist_t *
  53   53  dup_mechlist(mechlist_t *plist)
  54   54  {
  55   55          mechlist_t      *pres = NULL;
↓ open down ↓ 115 lines elided ↑ open up ↑
 171  171   * in the kcf.conf configuration file.
 172  172   *
 173  173   * Arguments:
 174  174   *      buf: an input argument which is a char string with the format of
 175  175   *           "disabledlist=m1,m2,..." or "supportedlist=m1,m2,..."
 176  176   *      pent: the entry for the disabledlist.  This is an IN/OUT argument.
 177  177   *
 178  178   * Return value: SUCCESS or FAILURE.
 179  179   */
 180  180  static int
 181      -parse_sup_dis_list(char *buf, entry_t *pent)
      181 +parse_sup_dis_list(const char *buf, entry_t *pent)
 182  182  {
 183  183          mechlist_t      *pmech = NULL;
 184  184          mechlist_t      *phead = NULL;
 185  185          char            *next_token;
 186  186          char            *value;
 187  187          int             count;
 188  188          int             supflag = B_FALSE;
 189  189          int             disflag = B_FALSE;
 190  190          int             rc = SUCCESS;
 191  191  
↓ open down ↓ 16 lines elided ↑ open up ↑
 208  208          if ((next_token = strtok(value, SEP_COMMA)) == NULL) {
 209  209                  cryptodebug("failed to parse the kcf.conf file.");
 210  210                  return (FAILURE);
 211  211          }
 212  212  
 213  213          if ((pmech = create_mech(next_token)) == NULL) {
 214  214                  return (FAILURE);
 215  215          }
 216  216  
 217  217          if (supflag) {
 218      -                pent->suplist = phead = pmech;
      218 +                        if (pent->suplist != NULL) {
      219 +                                cryptodebug("multiple supportedlist entries "
      220 +                                    "for a mechanism in file kcf.conf.");
      221 +                                return (FAILURE);
      222 +                        } else {
      223 +                                pent->suplist = phead = pmech;
      224 +                        }
 219  225          } else if (disflag) {
 220      -                pent->dislist = phead = pmech;
      226 +                        if (pent->dislist != NULL) {
      227 +                                cryptodebug("multiple disabledlist entries "
      228 +                                    "for a mechanism in file kcf.conf.");
      229 +                                return (FAILURE);
      230 +                        } else {
      231 +                                pent->dislist = phead = pmech;
      232 +                        }
 221  233          }
 222  234  
 223  235          count = 1;
 224  236          while (next_token) {
 225  237                  if (next_token = strtok(NULL, SEP_COMMA)) {
 226  238                          if ((pmech = create_mech(next_token)) == NULL) {
 227  239                                  rc = FAILURE;
 228  240                                  break;
 229  241                          }
 230  242                          count++;
↓ open down ↓ 13 lines elided ↑ open up ↑
 244  256          }
 245  257  
 246  258          return (rc);
 247  259  }
 248  260  
 249  261  
 250  262  /*
 251  263   * Convert a char string containing a line about a provider
 252  264   * from kcf.conf into an entry_t structure.
 253  265   *
      266 + * Note: the input string, buf, may be modified by this function.
      267 + *
 254  268   * See ent2str(), the reverse of this function, for the format of
 255  269   * kcf.conf lines.
 256  270   */
 257  271  static int
 258  272  interpret(char *buf, entry_t **ppent)
 259  273  {
 260  274          entry_t *pent = NULL;
 261  275          char    *token1;
 262  276          char    *token2;
 263  277          char    *token3;
↓ open down ↓ 11 lines elided ↑ open up ↑
 275  289          }
 276  290  
 277  291          if ((token2 = strtok(NULL, SEP_SEMICOLON)) == NULL) {
 278  292                  /* The entry contains a provider name only */
 279  293                  free_entry(pent);
 280  294                  return (FAILURE);
 281  295          }
 282  296  
 283  297          if (strncmp(token2, EF_UNLOAD, strlen(EF_UNLOAD)) == 0) {
 284  298                  pent->load = B_FALSE; /* cryptoadm unload */
 285      -                if ((token2 = strtok(NULL, SEP_SEMICOLON)) == NULL) {
 286      -                        /* The entry contains a provider name:unload only */
 287      -                        free_entry(pent);
 288      -                        return (FAILURE);
 289      -                }
      299 +                token2 = strtok(NULL, SEP_SEMICOLON);
      300 +                /*
      301 +                 * If token2 is NULL, the entry contains a
      302 +                 * provider name:unload only
      303 +                 */
 290  304          }
 291  305  
 292      -        /* need to get token3 first to satisfy nested strtok invocations */
 293      -        token3 = strtok(NULL, SEP_SEMICOLON); /* optional */
      306 +        if (token2 != NULL) {
      307 +                /*
      308 +                 * Either supportedlist or disabledlist or both are present.
      309 +                 * Need to call strtok() to get token3 first, as function
      310 +                 * parse_sup_dis_list() makes strtok() calls on the
      311 +                 * token2 substring.
      312 +                 */
      313 +                token3 = strtok(NULL, SEP_SEMICOLON); /* optional */
 294  314  
 295      -        /* parse supportedlist (or disabledlist if no supportedlist) */
 296      -        if ((token2 != NULL) && ((rc = parse_sup_dis_list(token2, pent)) !=
 297      -            SUCCESS)) {
 298      -                free_entry(pent);
 299      -                return (rc);
 300      -        }
      315 +                /* parse supportedlist (or disabledlist if no supportedlist) */
      316 +                if ((rc = parse_sup_dis_list(token2, pent)) != SUCCESS) {
      317 +                        free_entry(pent);
      318 +                        return (rc);
      319 +                }
 301  320  
 302      -        /* parse disabledlist (if there's a supportedlist) */
 303      -        if ((token3 != NULL) && ((rc = parse_sup_dis_list(token3, pent)) !=
 304      -            SUCCESS)) {
 305      -                free_entry(pent);
 306      -                return (rc);
      321 +                /* parse disabledlist (if there's a supportedlist) */
      322 +                if ((token3 != NULL) && ((rc = parse_sup_dis_list(token3,
      323 +                    pent)) != SUCCESS)) {
      324 +                        free_entry(pent);
      325 +                        return (rc);
      326 +                }
 307  327          }
 308  328  
 309  329          *ppent = pent;
 310  330          return (SUCCESS);
 311  331  }
 312  332  
 313  333  
 314  334  /*
 315  335   * Add an entry about a provider from kcf.conf to the end of an entry list.
 316  336   * If the entry list pplist is NULL, create the linked list with pent as the
↓ open down ↓ 90 lines elided ↑ open up ↑
 407  427                  pnext = entrylist->next;
 408  428                  free_entry(entrylist->pent);
 409  429                  entrylist = pnext;
 410  430          }
 411  431  }
 412  432  
 413  433  
 414  434  /*
 415  435   * Convert an entry to a string.  This routine builds a string for the entry
 416  436   * to be inserted in the kcf.conf file.  Based on the content of each entry,
 417      - * the result string can be one of these 6 forms:
      437 + * the result string can be one of these 7 forms:
 418  438   *  - name:supportedlist=m1,m2,...,mj
 419  439   *  - name:disabledlist=m1,m2,...,mj
 420  440   *  - name:supportedlist=m1,...,mj;disabledlist=m1,m2,...,mk
 421  441   *
      442 + *  - name:unload
 422  443   *  - name:unload;supportedlist=m1,m2,...,mj
 423  444   *  - name:unload;disabledlist=m1,m2,...,mj
 424  445   *  - name:unload;supportedlist=m1,...,mj;disabledlist=m1,m2,...,mk
 425  446   *
 426  447   * Note that the caller is responsible for freeing the returned string
 427  448   * (with free_entry()).
 428  449   * See interpret() for the reverse of this function: converting a string
 429  450   * to an entry_t.
 430  451   */
 431  452  char *
↓ open down ↓ 947 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX