getzoneent.c revision 2
2N/A * The contents of this file are subject to the terms of the 2N/A * Common Development and Distribution License (the "License"). 2N/A * You may not use this file except in compliance with the License. 2N/A * See the License for the specific language governing permissions 2N/A * and limitations under the License. 2N/A * When distributing Covered Code, include this CDDL HEADER in each 2N/A * If applicable, add the following below this CDDL HEADER, with the 2N/A * fields enclosed by brackets "[]" replaced with your own identifying 2N/A * information: Portions Copyright [yyyy] [name of copyright owner] 2N/A * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved. 2N/A * This module contains functions used for reading and writing the index file. 2N/A * setzoneent() opens the file. getzoneent() parses the file, doing the usual 2N/A * skipping of comment lines, etc., and using gettok() to deal with the ":" 2N/A * delimiters. endzoneent() closes the file. putzoneent() updates the file, 2N/A * adding, deleting or modifying lines, locking and unlocking appropriately. 2N/A * gettok() is a helper function for parsing the index file, used to split 2N/A * the lines by their ":" delimiters. Note that an entry may contain a ":" 2N/A * inside double quotes; this should only affect the zonepath, as zone names 2N/A * do not allow such characters, and zone states do not have them either. 2N/A * Same with double-quotes themselves: they are not allowed in zone names, 2N/A * and do not occur in zone states, and in theory should never occur in a 2N/A * zonepath since zonecfg does not support a method for escaping them. 2N/A * It never returns NULL. 2N/A /* this represents a line that's too long */ 2N/A /* skip comment lines */ 2N/A * empty or very long zone names are not allowed 2N/A /* state field should not be empty */ 2N/A /* very long paths are not allowed */ 2N/A * This function adds or removes a zone name et al. to the index file. 2N/A * If ze->zone_state is < 0, it means leave the 2N/A * existing value unchanged; this is only meaningful when operation == 2N/A * PZE_MODIFY (i.e., it's bad on PZE_ADD and a no-op on PZE_REMOVE). 2N/A * A zero-length ze->zone_path means leave the existing value 2N/A * unchanged; this is only meaningful when operation == PZE_MODIFY 2N/A * (i.e., it's bad on PZE_ADD and a no-op on PZE_REMOVE). 2N/A * A zero-length ze->zone_newname means leave the existing name 2N/A * unchanged; otherwise the zone is renamed to zone_newname. This is 2N/A * only meaningful when operation == PZE_MODIFY. 2N/A * Locking and unlocking is done via the functions above. 2N/A * The file itself is not modified in place; rather, a copy is made which 2N/A * is modified, then the copy is atomically renamed back to the main file. 2N/A * Don't allow modification of Global Zone entry 2N/A /* using sizeof gives us room for the terminating NUL byte as well */ 2N/A * It's not considered an error to delete something 2N/A * that doesn't exist, but we can't modify a missing 2N/A /* skip and preserve comment lines */ 2N/A /* skip and preserve non-target lines */ 2N/A /* this represents a line that's too long; delete */ 2N/A * Skip over the zone name. Because we've already matched the 2N/A * target zone (above), we know for certain here that the zone 2N/A * name is present and correctly formed. No need to check. 2N/A /* state field should not be empty */ 2N/A /* can't add same zone */ 2N/A * If the caller specified a new state for the zone, 2N/A * then use that. Otherwise, use the current state. 2N/A * If the caller is uninstalling this zone, 2N/A * then wipe out the uuid. The zone's contents 2N/A * are no longer known. 2N/A /* If a new name is supplied, use it. */ 2N/A * If the entry in the file is in greater than configured 2N/A * state, then we must have a UUID. Make sure that we do. 2N/A * (Note that the file entry is only tokenized, not fully 2N/A * parsed, so we need to do a string comparison here.) 2N/A * We need to quote a path that contains a ":"; this should 2N/A * only affect the zonepath, as zone names do not allow such 2N/A * characters, and zone states do not have them either. Same 2N/A * with double-quotes themselves: they are not allowed in zone 2N/A * names, and do not occur in zone states, and in theory should 2N/A * never occur in a zonepath since zonecfg does not support a 2N/A * method for escaping them.