libnwam_object.c revision 69b43529e65fb6eb0c88e6b7b42025e9bf025b8a
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2010 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <assert.h>
#include <stdlib.h>
#include <strings.h>
#include <string.h>
#include "libnwam_impl.h"
#include <libintl.h>
#include <libnwam.h>
/*
* Generic object manipulation functions. Given an object handle and
* etc. All object handles are "struct nwam_handle *" objects, sharing
* the same description based on the object type, name, original name
* (used in renaming) and associated data representing properties.
*/
struct nwam_handle **hpp)
{
return (NWAM_INVALID_ARG);
}
return (NWAM_NO_MEMORY);
return (NWAM_SUCCESS);
}
/*
* Read object of specified type from dbname.
*/
{
char dbname_copy[MAXPATHLEN];
return (err);
return (err);
if ((err = nwam_read_object_from_backend
return (err);
}
char *ncpname;
/*
* dbname_copy may have been changed due to case-insensitive
* match against the actual NCP configuration file.
*/
== NWAM_SUCCESS) {
}
}
return (NWAM_SUCCESS);
}
/*
* Create simply creates the handle - the object-specific function must
* then fill in property values.
*/
struct nwam_handle **hpp)
{
struct nwam_handle *hp;
return (NWAM_ENTITY_EXISTS);
}
/* Create handle */
}
{
return (NWAM_NO_MEMORY);
}
return (NWAM_SUCCESS);
}
{
if (hp->nwh_committed)
return (NWAM_ENTITY_READ_ONLY);
return (NWAM_INVALID_ARG);
return (NWAM_SUCCESS);
}
/* Compare object names c1 and c2 using strcasecmp() */
static int
{
/* If c1 and c2 are typed NCU names, compare names without the types */
== NWAM_SUCCESS &&
== NWAM_SUCCESS) {
/* For NCUs with the same name, compare their types */
if (ret == 0) {
ret = -1;
ret = 1;
}
return (ret);
}
}
/*
* Generic walk function takes the standard walk arguments, and in addition
* takes a selection callback that is object-specific. If this returns
* 0, the object is a valid selection for the walk and the callback is called.
* Otherwise, it is skipped.
*/
int(*cb)(struct nwam_handle *, void *),
{
void *objlist;
char **object_names;
uint_t i, num_objects = 0;
struct nwam_handle *hp;
int ret = 0;
/*
* To walk a set of objects, call nwam_read_object_from_backend()
* with a "dbname" argument set to the container db name and
* the object name set to NULL. This returns an nvlist with one
* member - the NWAM_OBJECT_NAMES_STRING - and the values it contains
* represent the names of the objects. Read each in turn, calling
* the callback function.
*/
&objlist)) != NWAM_SUCCESS) {
if (err == NWAM_ENTITY_NOT_FOUND) {
/*
* This indicates the dbname container is not present.
* Do not pass back an error in this case, since it is
* valid for a container not to exist.
*/
return (NWAM_SUCCESS);
}
return (err);
}
&value)) != NWAM_SUCCESS) {
return (err);
}
if (err != NWAM_SUCCESS) {
return (err);
}
/* sort the object names alphabetically */
for (i = 0; i < num_objects; i++) {
/* An object may have disappeared. If so, skip it. */
if (err == NWAM_ENTITY_NOT_FOUND)
continue;
if (err != NWAM_SUCCESS) {
return (err);
}
if (ret != 0) {
return (NWAM_WALK_HALTED);
}
}
}
return (err);
}
void
{
}
}
/*
* Copy object represented by oldhp to an object newname, all in container
* dbname.
*/
struct nwam_handle **newhpp)
{
struct nwam_handle *hp;
== NWAM_SUCCESS) {
return (NWAM_ENTITY_EXISTS);
}
!= NWAM_SUCCESS)
return (err);
return (err);
}
return (NWAM_SUCCESS);
}
/* ARGSUSED3 */
int (*cb)(const char *, nwam_value_t, void *),
{
int ret = 0;
return (err);
if (ret != 0)
/* Free value */
if (err != NWAM_SUCCESS)
break;
}
return (NWAM_SUCCESS);
return (err);
}
/*
* Note that prior to calling the generic commit function, object-specific
* validation should be carried out.
*/
{
struct nwam_handle *testhp;
/*
* NWAM_FLAG_ENTITY_KNOWN_WLAN is only used for Known WLANs and
* NWAM_FLAG_ENTITY_ENABLE is used for other objects (during enable
* and disable).
*/
!= NWAM_SUCCESS)
return (err);
/*
* Does object already exist? If not, action is ADD, otherwise REFRESH.
*/
&testhp)) {
case NWAM_ENTITY_NOT_FOUND:
break;
case NWAM_SUCCESS:
return (NWAM_ENTITY_EXISTS);
/* FALLTHRU */
default:
break;
}
if (err != NWAM_SUCCESS)
return (err);
/*
* Tell nwamd to reread this object. For NCUs, we need to convert
* the dbname to the NCP name in order to pass it to nwamd.
*/
if (is_ncu) {
char *ncpname;
}
} else {
}
return (NWAM_SUCCESS);
}
static boolean_t
{
state == NWAM_STATE_ONLINE));
}
{
char *name;
/* NWAM_FLAG_ENTITY_KNOWN_WLAN is only used for Known WLANs */
NWAM_FLAG_ENTITY_KNOWN_WLAN : 0))) != NWAM_SUCCESS)
return (err);
/* Check if object is active */
return (NWAM_ENTITY_IN_USE);
/* For NCPs, just remove the dbname file, otherwise remove the object */
/*
* Tell nwamd to remove this object. For NCUs, we need to convert the
* dbname filename to the NCP name to pass it to nwamd.
*/
if (is_ncu) {
char *ncpname;
}
} else {
}
return (err);
}
/*
* functions specifies the NCP for NCUs.
*/
{
}
{
}
{
}
struct nwam_prop_table_entry *
{
return (cur);
}
return (NULL);
}
const char **descriptionp)
{
struct nwam_prop_table_entry *pte;
*descriptionp = NULL;
return (NWAM_INVALID_ARG);
}
return (NWAM_SUCCESS);
}
{
struct nwam_prop_table_entry *pte;
return (NWAM_INVALID_ARG);
return (NWAM_SUCCESS);
}
{
struct nwam_prop_table_entry *pte;
return (NWAM_INVALID_ARG);
else
return (NWAM_SUCCESS);
}
{
struct nwam_prop_table_entry *pte;
return (NWAM_INVALID_ARG);
return (NWAM_SUCCESS);
}
/*
* Structure used to pass in prop table and errprop string pointer to internal
* validate function.
*/
struct validate_internal_arg {
struct nwam_prop_table table;
const char **errpropp;
};
/*
* Callback used by nwam_walk_props() in nwam_validate(), and
* by nwam_validate_prop() to determine that the number, type and
* range of values are correct, and that validation function (if present)
* succeeds.
*/
static int
void *arg)
{
struct nwam_prop_table_entry *pte;
int i;
!= NWAM_SUCCESS ||
return (err);
}
return (NWAM_INVALID_ARG);
/* have we get expected number of values? */
if (numvalues < 1)
return (NWAM_ENTITY_NO_VALUE);
else
return (NWAM_ENTITY_INVALID_VALUE);
}
/* Ensure type matches */
if (numvalues > 0) {
for (i = 0; i < numvalues; i++) {
return (NWAM_ENTITY_TYPE_MISMATCH);
}
}
}
/* Call property-specific validation function */
return (err);
}
return (NWAM_SUCCESS);
}
{
struct validate_internal_arg via;
}
const char **errpropp)
{
struct validate_internal_arg via;
0, (int *)&err2);
if (err1 != NWAM_SUCCESS)
return (err2);
return (NWAM_SUCCESS);
}
/*
* Given the type and class flag representations, return the list of properties
* property list that includes both the required and the optional properties.
* The type and class flags are only used for NCU objects at present.
*
* Caller needs to free prop_list.
*/
{
int i = 0;
*numvalues = 0;
return (NWAM_NO_MEMORY);
}
continue;
}
*numvalues = i;
return (NWAM_SUCCESS);
}