Print this page


Split Close
Expand all
Collapse all
          --- old/usr/src/lib/libzonecfg/common/getzoneent.c
          +++ new/usr/src/lib/libzonecfg/common/getzoneent.c
↓ open down ↓ 120 lines elided ↑ open up ↑
 121  121                  if ((cp = strpbrk(buf, "\r\n")) == NULL) {
 122  122                          /* this represents a line that's too long */
 123  123                          continue;
 124  124                  }
 125  125                  *cp = '\0';
 126  126                  cp = buf;
 127  127                  if (*cp == '#') {
 128  128                          /* skip comment lines */
 129  129                          continue;
 130  130                  }
 131      -
 132      -                /* zonename */
 133  131                  p = gettok(&cp);
 134  132                  if (*p == '\0' || strlen(p) >= ZONENAME_MAX) {
 135  133                          /*
 136  134                           * empty or very long zone names are not allowed
 137  135                           */
 138  136                          continue;
 139  137                  }
 140  138                  (void) strlcpy(ze->zone_name, p, ZONENAME_MAX);
 141  139  
 142      -                /* state */
 143  140                  p = gettok(&cp);
 144  141                  if (*p == '\0') {
 145  142                          /* state field should not be empty */
 146  143                          continue;
 147  144                  }
 148  145                  errno = 0;
 149  146                  if (strcmp(p, ZONE_STATE_STR_CONFIGURED) == 0) {
 150  147                          ze->zone_state = ZONE_STATE_CONFIGURED;
 151  148                  } else if (strcmp(p, ZONE_STATE_STR_INCOMPLETE) == 0) {
 152  149                          ze->zone_state = ZONE_STATE_INCOMPLETE;
 153  150                  } else if (strcmp(p, ZONE_STATE_STR_INSTALLED) == 0) {
 154  151                          ze->zone_state = ZONE_STATE_INSTALLED;
 155  152                  } else {
 156  153                          continue;
 157  154                  }
 158  155  
 159      -                /* zonepath */
 160  156                  p = gettok(&cp);
 161  157                  if (strlen(p) >= MAXPATHLEN) {
 162  158                          /* very long paths are not allowed */
 163  159                          continue;
 164  160                  }
 165  161                  (void) strlcpy(ze->zone_path, p, MAXPATHLEN);
 166  162  
 167      -                /* uuid */
 168  163                  p = gettok(&cp);
 169  164                  if (uuid_parse(p, ze->zone_uuid) == -1)
 170  165                          uuid_clear(ze->zone_uuid);
 171  166  
 172      -                /* brand [optional] */
 173      -                p = gettok(&cp);
 174      -                if (strlen(p) >= MAXNAMELEN) {
 175      -                        /* very long names are not allowed */
 176      -                        continue;
 177      -                }
 178      -                (void) strlcpy(ze->zone_brand, p, MAXNAMELEN);
 179      -
 180      -                /* IP type [optional] */
 181      -                p = gettok(&cp);
 182      -                if (strlen(p) >= MAXNAMELEN) {
 183      -                        /* very long names are not allowed */
 184      -                        continue;
 185      -                }
 186      -                ze->zone_iptype = ZS_SHARED;
 187      -                if (*p == 'e') {
 188      -                        ze->zone_iptype = ZS_EXCLUSIVE;
 189      -                }
 190      -
 191      -                /* debug ID [optional] */
 192      -                p = gettok(&cp);
 193      -                if (*p != '\0')
 194      -                        ze->zone_did = atoi(p);
 195      -
 196  167                  break;
 197  168          }
 198  169  
 199  170          return (ze);
 200  171  }
 201  172  
 202  173  static boolean_t
 203  174  path_common(char *path, size_t path_size, const char *stem)
 204  175  {
 205  176          const char *native_root = zone_get_nroot();
↓ open down ↓ 110 lines elided ↑ open up ↑
 316  287   * The file itself is not modified in place; rather, a copy is made which
 317  288   * is modified, then the copy is atomically renamed back to the main file.
 318  289   */
 319  290  int
 320  291  putzoneent(struct zoneent *ze, zoneent_op_t operation)
 321  292  {
 322  293          FILE *index_file, *tmp_file;
 323  294          char buf[MAX_INDEX_LEN];
 324  295          int tmp_file_desc, lock_fd, err;
 325  296          boolean_t exist, need_quotes;
 326      -        char *cp, *tmpp;
      297 +        char *cp;
 327  298          char tmp_path[MAXPATHLEN];
 328  299          char path[MAXPATHLEN];
 329  300          char uuidstr[UUID_PRINTABLE_STRING_LENGTH];
 330  301          size_t namelen;
 331      -        const char *zone_name, *zone_state, *zone_path, *zone_uuid,
 332      -            *zone_brand = "", *zone_iptype;
 333      -        zoneid_t zone_did;
      302 +        const char *zone_name, *zone_state, *zone_path, *zone_uuid;
 334  303  
 335  304          assert(ze != NULL);
 336  305  
 337  306          /*
 338  307           * Don't allow modification of Global Zone entry
 339  308           * in index file
 340  309           */
 341  310          if ((operation == PZE_MODIFY) &&
 342  311              (strcmp(ze->zone_name, GLOBAL_ZONENAME) == 0)) {
 343  312                  return (Z_OK);
↓ open down ↓ 32 lines elided ↑ open up ↑
 376  345                  goto error;
 377  346          }
 378  347          if ((index_file = fopen(path, "r")) == NULL) {
 379  348                  err = Z_MISC_FS;
 380  349                  goto error;
 381  350          }
 382  351  
 383  352          exist = B_FALSE;
 384  353          zone_name = ze->zone_name;
 385  354          namelen = strlen(zone_name);
 386      -        zone_brand = ze->zone_brand;
 387      -        zone_iptype = (ze->zone_iptype == ZS_SHARED ? "sh" : "ex");
 388      -        zone_did = ze->zone_did;
 389  355          for (;;) {
 390  356                  if (fgets(buf, sizeof (buf), index_file) == NULL) {
 391  357                          if (operation == PZE_ADD && !exist) {
 392  358                                  zone_state = zone_state_str(ze->zone_state);
 393  359                                  zone_path = ze->zone_path;
 394  360                                  zone_uuid = "";
 395  361                                  goto add_entry;
 396  362                          }
 397  363                          /*
 398  364                           * It's not considered an error to delete something
↓ open down ↓ 34 lines elided ↑ open up ↑
 433  399                  cp = strchr(buf, ':') + 1;
 434  400  
 435  401                  zone_state = gettok(&cp);
 436  402                  if (*zone_state == '\0') {
 437  403                          /* state field should not be empty */
 438  404                          err = Z_UPDATING_INDEX;
 439  405                          goto error;
 440  406                  }
 441  407                  zone_path = gettok(&cp);
 442  408                  zone_uuid = gettok(&cp);
 443      -                zone_brand = gettok(&cp);
 444      -                zone_iptype = gettok(&cp);
 445      -                tmpp = gettok(&cp);
 446      -                if (*tmpp != '\0')
 447      -                        zone_did = atoi(tmpp);
 448  409  
 449  410                  switch (operation) {
 450  411                  case PZE_ADD:
 451  412                          /* can't add same zone */
 452  413                          err = Z_UPDATING_INDEX;
 453  414                          goto error;
 454  415  
 455  416                  case PZE_MODIFY:
 456  417                          /*
 457  418                           * If the caller specified a new state for the zone,
 458  419                           * then use that.  Otherwise, use the current state.
 459  420                           */
 460  421                          if (ze->zone_state >= 0) {
 461  422                                  zone_state = zone_state_str(ze->zone_state);
      423 +
      424 +                                /*
      425 +                                 * If the caller is uninstalling this zone,
      426 +                                 * then wipe out the uuid.  The zone's contents
      427 +                                 * are no longer known.
      428 +                                 */
      429 +                                if (ze->zone_state < ZONE_STATE_INSTALLED)
      430 +                                        zone_uuid = "";
 462  431                          }
 463  432  
 464  433                          /* If a new name is supplied, use it. */
 465  434                          if (ze->zone_newname[0] != '\0')
 466  435                                  zone_name = ze->zone_newname;
 467  436  
 468  437                          if (ze->zone_path[0] != '\0')
 469  438                                  zone_path = ze->zone_path;
 470      -
 471      -                        /* If new UUID provided, replace it */
 472      -                        if (!uuid_is_null(ze->zone_uuid)) {
 473      -                                uuid_unparse(ze->zone_uuid, uuidstr);
 474      -                                zone_uuid = uuidstr;
 475      -                        }
 476      -
 477      -                        /* If a brand is supplied, use it. */
 478      -                        if (ze->zone_brand[0] != '\0') {
 479      -                                zone_brand = ze->zone_brand;
 480      -
 481      -                                /*
 482      -                                 * Since the brand, iptype and did are optional,
 483      -                                 * we we only reset the iptype and did if the
 484      -                                 * brand is provided.
 485      -                                 */
 486      -                                zone_iptype = (ze->zone_iptype == ZS_SHARED ?
 487      -                                    "sh" : "ex");
 488      -                                zone_did = ze->zone_did;
 489      -                        }
 490      -
 491  439                          break;
 492  440  
 493  441                  case PZE_REMOVE:
 494  442                  default:
 495  443                          continue;
 496  444                  }
 497  445  
 498  446          add_entry:
 499  447                  /*
 500  448                   * If the entry in the file is in greater than configured
↓ open down ↓ 11 lines elided ↑ open up ↑
 512  460                  /*
 513  461                   * We need to quote a path that contains a ":"; this should
 514  462                   * only affect the zonepath, as zone names do not allow such
 515  463                   * characters, and zone states do not have them either.  Same
 516  464                   * with double-quotes themselves: they are not allowed in zone
 517  465                   * names, and do not occur in zone states, and in theory should
 518  466                   * never occur in a zonepath since zonecfg does not support a
 519  467                   * method for escaping them.
 520  468                   */
 521  469                  need_quotes = (strchr(zone_path, ':') != NULL);
 522      -
 523      -                if (*zone_brand != '\0') {
 524      -                        (void) fprintf(tmp_file, "%s:%s:%s%s%s:%s:%s:%s:%d\n",
 525      -                            zone_name, zone_state, need_quotes ? "\"" : "",
 526      -                            zone_path, need_quotes ? "\"" : "", zone_uuid,
 527      -                            zone_brand, zone_iptype, zone_did);
 528      -                } else {
 529      -                        (void) fprintf(tmp_file, "%s:%s:%s%s%s:%s\n", zone_name,
 530      -                            zone_state, need_quotes ? "\"" : "", zone_path,
 531      -                            need_quotes ? "\"" : "", zone_uuid);
 532      -                }
      470 +                (void) fprintf(tmp_file, "%s:%s:%s%s%s:%s\n", zone_name,
      471 +                    zone_state, need_quotes ? "\"" : "", zone_path,
      472 +                    need_quotes ? "\"" : "", zone_uuid);
 533  473                  exist = B_TRUE;
 534  474          }
 535  475  
 536  476          (void) fclose(index_file);
 537  477          index_file = NULL;
 538  478          if (fclose(tmp_file) != 0) {
 539  479                  tmp_file = NULL;
 540  480                  err = Z_MISC_FS;
 541  481                  goto error;
 542  482          }
↓ open down ↓ 18 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX