libnetcfg.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) 2012, Oracle and/or its affiliates. All rights reserved. 2N/A * Communicate with the backend daemon (running in netcfgd) to retrieve or 2N/A * change configuration. 2N/A/* error codes and text description */ 2N/A * Returns a message string for the given libnetcfg error code. 2N/A /* no good analog for these */ 2N/A /* Need to skip if we're in an S10-branded zone */ 2N/A * Read nvlists from the door argument that is returned by the door call to 2N/A * netcfgd. If the arg datalen is non-zero, unpack the object nvlist. 2N/A * Set up door arguments and make the door_call(). 2N/A * Don't pass in a return buffer. The door server will allocate the 2N/A * return buffer. The rsize must be > 0, however, else the door acts 2N/A * as if no response was expected and doesn't pass back anything. 2N/A /* Check door fd is not old (from previous netcfgd) */ 2N/A * The size of *rbufp was not big enough and the door itself 2N/A * rellocated the return buffer. Reallocate *rbufp and copy 2N/A * the contents to the new buffer. 2N/A /* munmap() the door buffer */ 2N/A * Set up arguments for the door call and read in results returned from the 2N/A /* pack the nvlist of identifiers */ 2N/A /* For the commands that pass object data as well, pack the objlist */ 2N/A /* obj will be filled in when the returned nvlist is unpacked */ 2N/A /* populate the door call argument structure */ 2N/A /* add the packed id nvlist */ 2N/A /* and the packed data nvlist for updates */ 2N/A /* Check for an error return */ 2N/A /* If reading from file, parse out the return buffer */ 2N/A * Read object specified by the passed-in idlist, retrieving an object 2N/A * list representation. 2N/A * If idlist is NULL, obj is a list of string arrays consisting of the list 2N/A * If object-db-name is specified, but no object identifiers are included 2N/A * in idlist, read all objects in the specified dbname and create an object 2N/A * list containing a string array which represents each object. 2N/A * Otherwise, obj will point to a list of the properties for the object 2N/A * specified by idlist. 2N/A * Read in all objects from the DB and object specified by idlist and update 2N/A * with the properties recorded in obj, writing the results to the DB. 2N/A * Remove the object specified by cur_idlist from the DB, and create a new 2N/A * entry with the read-in property list and the passed-in new_idlist. 2N/A * Remove specified object from the DB by reading in the list of objects, 2N/A * removing the object identified by idlist, and writing the remainder. 2N/A * If idlist only identifies the DB, remove the DB altogether. 2N/A * Read the specified object, then fill in appropriate values for the 2N/A * properties passed in in objlist. If a passed-in property is not present 2N/A * in the db entry, remove it from the list before returning. 2N/A * Call the provided callback for each object in DB (specified by a dbname 2N/A * pair in the idlist), passing in the object and the provided argument. 2N/A * If selcb is specified, it will be called first for each entry, and will 2N/A * be passed both the idlist and objlist, as well as the flags. It should 2N/A * return 0 or non-zero to signify whether or not cb should be called for 2N/A * that particular entry; it may optionally return an alternate object arg 2N/A * to be passed to cb instead of the objlist. This allows libraries which 2N/A * consume this generic interface to implement library-specific filtering 2N/A * for walk functions which they in turn export. 2N/A * Calling netcfg_read_object() with an idlist containing just a 2N/A * dbname pair (and optional zoneid pair) returns an nvlist with 2N/A * one member: the NETCFG_OBJECT_ID_LIST; this object's value is 2N/A * an array of nvlists, where each nvlist is the list of 2N/A * identifiers for an object in the db. 2N/A /* now call the freecb() routine */ 2N/A * Walk a db, calling the provided callback for each link in the file. 2N/A * Passes the raw data string representing the current line to the 2N/A * callback, as well as a caller-specified argument. 2N/A * Calling netcfg_read_object() with an idlist containing just a 2N/A * dbname pair and NETCFG_DB_RAW_FLAG set returns an nvlist with 2N/A * one member: the NETCFG_OBJECT_RAW_BUFS; this object's value is 2N/A * an array of strings, where each string in the array maps to a 2N/A * single line from the file. 2N/A * The dbname container is not present; this is not 2N/A * an error case, it just means the db is empty, so 2N/A * there is nothing to walk. 2N/A * Create a new (or replace an existing) database. The new db is identified 2N/A * by the passed-in idlist; its contents are specified in the dblist param. 2N/A * This nvlist should contain an nvpair for each db entry; the name should 2N/A * be the string representation of the entry's idlist (the output of 2N/A * netcfg_idl2idstr()), the value should be an nvlist containing the entry 2N/A * Destroy the database specified by the passed-in idlist.