dhcp_network.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (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 (c) 2000-2001 by Sun Microsystems, Inc.
* All rights reserved.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* This file contains public functions for managing legacy DHCP network
* containers. For the semantics of these functions, please see the
* Enterprise DHCP Architecture Document.
*/
#include <alloca.h>
#include <ctype.h>
#include <dhcp_svc_public.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <libgen.h>
#include <libinetutil.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "dhcp_network.h"
#include "util.h"
/* ARGSUSED */
int
{
char dnpath[MAXPATHLEN];
int retval;
int fd;
return (DSVC_NO_MEMORY);
/*
* This is a legacy format which has no header, so we neither write
* nor verify a header (we just create the file or make sure it
* exists, depending on the value of `flags').
*/
if (retval != DSVC_SUCCESS) {
return (retval);
}
return (DSVC_SUCCESS);
}
int
{
return (DSVC_SUCCESS);
}
int
{
char dnpath[MAXPATHLEN];
return (syserr_to_dsvcerr(errno));
return (DSVC_SUCCESS);
}
static int
{
int retval = DSVC_SUCCESS;
unsigned int nfields;
return (DSVC_INTERNAL);
if (flags & FIND_POSITION)
break;
}
/*
* Skip pure comment lines; for now this just skips the
* header information at the top of the container.
*/
if (buf[0] == DNF_COMMENT_CHAR)
continue;
/*
* Tell field_split() that there's one less field than
* there really is. We do this so that the comment and the
* macro field both end up in the DNF_MACRO field, since
* both fields are optional and it requires some fancy
* footwork (below) to tell which (if any) the record
* contains.
*/
if (nfields < DNF_REQ_FIELDS)
continue;
if (nfields == DNF_REQ_FIELDS) {
} else {
/*
* Assume there is a comment; if we hit a comment
* delimiter char (DNF_COMMENT_CHAR), then simply
* change it to a NUL and advance commentp. If we
* hit whitespace, replace the first instance with
* NUL, and go searching for DNF_COMMENT_CHAR.
* This step is important since it efficiently
* handles the common case where a comment is
* preceded by a space.
*/
commentp++;
*commentp++ = '\0';
commentp = "";
}
if (*commentp == DNF_COMMENT_CHAR)
*commentp++ = '\0';
}
/*
* See if we've got a match, filling in dnf.dnf_rec as
* we go. If record_match() succeeds, dnf.dnf_rec will
* be completely filled in.
*/
continue;
/*
* Caller just wants a count of the number of matching
* records, not the records themselves; continue.
*/
nrecords++;
continue;
}
/*
* Allocate record; if FIND_POSITION flag is set, then
* we need to allocate an extended (dn_recpos_t) record.
*/
if (flags & FIND_POSITION)
else
if ((flags & FIND_PARTIAL) == 0)
break;
}
/*
* Fill in record; do a structure copy from our automatic
* dn. If FIND_POSITION flag is on, pass back additional
* position information.
*/
if (flags & FIND_POSITION) {
}
/*
* Chuck the record on the list and up the counter.
*/
if (new_records == NULL) {
if ((flags & FIND_PARTIAL) == 0)
break;
}
nrecords++;
}
if (retval == DSVC_SUCCESS) {
return (DSVC_SUCCESS);
}
return (retval);
}
int
{
int retval;
char dnpath[MAXPATHLEN];
return (DSVC_ACCESS);
return (syserr_to_dsvcerr(errno));
return (retval);
}
/*
* Compares the fields in fields[] agains the fields in target `targetp',
* using `query' to decide what fields to compare. Returns B_TRUE if `dnp'
* matches `targetp', B_FALSE if not. On success, `dnp' is completely
* filled in.
*/
static boolean_t
{
unsigned int i;
return (B_FALSE);
return (B_FALSE);
return (B_FALSE);
return (B_FALSE);
/*
* We use dn_cid_len since dnp->dn_cid_len is of type uchar_t but
* hexascii_to_octet() expects a uint_t *
*/
return (B_FALSE);
return (B_FALSE);
return (B_FALSE);
return (B_FALSE);
return (B_FALSE);
return (B_FALSE);
return (B_FALSE);
for (i = 0; i < sizeof (qflags) / sizeof (unsigned int); i++) {
return (B_FALSE);
return (B_FALSE);
}
sizeof (dnp->dn_comment));
return (B_TRUE);
}
/*
* Internal dhcp_network record update routine, used to factor out the
* common code between add_dn(), delete_dn(), and modify_dn(). If `origp'
* is NULL, then act like add_dn(); if `newp' is NULL, then act like
* delete_dn(); otherwise act like modify_dn().
*/
static int
{
int retval = DSVC_SUCCESS;
int newfd;
int query;
return (DSVC_ACCESS);
/*
* Open the container to update and a new container file which we
* will store the updated version of the container in. When the
* update is done, rename the new file to be the real container.
*/
return (syserr_to_dsvcerr(errno));
if (newfd == -1) {
return (syserr_to_dsvcerr(errno));
}
/*
* If we're adding a new record or changing a key for an existing
* record, bail if the record we want to add already exists.
*/
if (retval != DSVC_SUCCESS)
goto out;
if (found != 0) {
goto out;
}
}
}
/*
* If we're deleting or modifying record, make sure the record
* still exists. Note that we don't check signatures because this
* is a legacy format that has no signatures.
*/
&found);
if (retval != DSVC_SUCCESS)
goto out;
if (found == 0) {
retval = DSVC_NOENT;
goto out;
}
/*
* Note the offset of the record we're modifying or deleting
* for use down below.
*/
} else {
/*
* No record to modify or delete, so set `recoff' and
* `recnext' appropriately.
*/
recoff = 0;
recnext = 0;
}
/*
* Make a new copy of the container. If we're deleting or
* modifying a record, don't copy that record to the new container.
*/
goto out;
}
if (retval != DSVC_SUCCESS)
goto out;
if (retval != DSVC_SUCCESS)
goto out;
/*
*/
if (retval != DSVC_SUCCESS)
goto out;
}
/*
* Note: we close these descriptors before the rename(2) (rather
* than just having the `out:' label clean them up) to save NFS
* some work (otherwise, NFS has to save `dnpath' to an alternate
* name since its vnode would still be active).
*/
return (retval);
out:
return (retval);
}
int
{
}
int
{
}
int
{
}
int
{
char ipaddr[INET_ADDRSTRLEN];
unsigned int i, count = 0;
int error;
switch (errno) {
case EACCES:
case EPERM:
return (DSVC_ACCESS);
case ENOENT:
return (DSVC_NO_LOCATION);
default:
break;
}
return (DSVC_INTERNAL);
}
/*
* Compile a regular expression matching an IP address delimited by
* underscores. Note that the `$0' at the end allows us to save the
* IP address in ipaddr when calling regex(3C).
*/
return (DSVC_NO_MEMORY);
for (;;) {
/*
* readdir_r() is very broken; see 4329196 -- in the
* meantime, workaround as best we can.
*/
break;
(sizeof (char **)) * (count + 1));
if (new_listpp == NULL) {
goto fail;
}
listpp = new_listpp;
goto fail;
}
/*
* Change all underscores to dots.
*/
}
count++;
}
}
return (DSVC_SUCCESS);
fail:
for (i = 0; i < count; i++)
return (error);
}
/*
* Given a buffer `path' of `pathlen' bytes, fill it in with a path to the
* DHCP Network table for IP network `ip' located in directory `dir' with a
* suffix of `suffix'.
*/
static void
const char *suffix)
{
}
/*
* Write the dn_rec_t `recp' into the open container `fd' at offset
* `recoff'. Returns DSVC_* error code.
*/
static int
{
int entlen;
unsigned int dn_cid_len = sizeof (dn_cid);
&dn_cid_len) != 0)
return (DSVC_INTERNAL);
} else {
}
if (entlen == -1)
return (syserr_to_dsvcerr(errno));
goto again;
}
return (syserr_to_dsvcerr(errno));
return (DSVC_SUCCESS);
}