/*
* 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 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* This file contains public API functions for managing the legacy dhcptab
* container format. For the semantics of these functions, please see the
* Enterprise DHCP Architecture Document.
*/
#include <alloca.h>
#include <dhcp_svc_public.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "dhcptab.h"
#include "util.h"
int
{
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
{
return (syserr_to_dsvcerr(errno));
return (DSVC_SUCCESS);
}
/*
* Internal version of lookup_dt() used by both lookup_dt() and
* update_dt(); same semantics as lookup_dt() except that the `partial'
* argument has been generalized into a `flags' field and the handle has
* been turned into a FILE pointer.
*/
static int
{
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] == DTF_COMMENT_CHAR)
continue;
/*
* Parse out the entry into the dt_rec_t
*/
if (nfields < DTF_MAX_FIELDS)
continue;
/*
* See if we've got a match. If so, allocate the new
* record, fill it in, and continue.
*/
continue;
continue;
continue;
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 (dt_recpos_t) record.
*/
if (flags & FIND_POSITION)
else
if ((flags & FIND_PARTIAL) == 0)
break;
}
/*
* Fill in record; if FIND_POSITION flag is set, then pass
* back additional location information.
*/
if ((flags & FIND_PARTIAL) == 0)
break;
}
if (flags & FIND_POSITION) {
}
/*
* Chuck the record on the list; 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;
return (DSVC_ACCESS);
return (syserr_to_dsvcerr(errno));
return (retval);
}
/*
* Internal dhcptab record update routine, used to factor out the
* common code between add_dt(), delete_dt(), and modify_dt(). If
* `origp' is NULL, then act like add_dt(); if `newp' is NULL, then
* act like delete_dt(); otherwise act like modify_dt().
*/
static int
{
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 there's a new record, append it to the new container.
*/
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 `dtpath' to an alternate
* name since its vnode would still be active).
*/
return (retval);
out:
return (retval);
}
int
{
}
int
{
}
int
{
}
int
{
char **listpp;
switch (errno) {
case EACCES:
case EPERM:
return (DSVC_ACCESS);
case ENOENT:
return (DSVC_NO_LOCATION);
default:
break;
}
return (DSVC_INTERNAL);
}
*countp = 0;
return (DSVC_SUCCESS);
}
return (DSVC_NO_MEMORY);
return (DSVC_NO_MEMORY);
}
*countp = 1;
return (DSVC_SUCCESS);
}
/*
* Given a buffer `path' of `pathlen' bytes, fill it in with a path to
* the dhcptab in directory `dir' with a suffix of `suffix'.
*/
static void
{
}
/*
* Write the dt_rec_t pointed to by `recp' into the open container `fd' at
* offset `recoff'. Returns DSVC_* error code.
*/
static int
{
int entlen;
if (entlen == -1)
return (syserr_to_dsvcerr(errno));
goto again;
}
return (syserr_to_dsvcerr(errno));
return (DSVC_SUCCESS);
}