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 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* This module contains public API functions for managing dhcp network
* containers.
*/
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <regexpr.h>
#include <dhcp_svc_public.h>
#include "nisplus_impl.h"
#include <libinetutil.h>
/*
* DHCP network table column description
*/
{ "cid", TA_SEARCHABLE, 0 },
{ "f_auto", TA_SEARCHABLE, 0 },
{ "f_manual", TA_SEARCHABLE, 0 },
{ "f_unusable", TA_SEARCHABLE, 0 },
{ "f_bootp", TA_SEARCHABLE, 0 },
{ "cip", TA_SEARCHABLE, 0 },
{ "sip", TA_SEARCHABLE, 0 },
{ "lease", TA_SEARCHABLE, 0 },
{ "macro", TA_SEARCHABLE, 0 },
{ "comment", 0, 0 }
};
/*
* Convert a dn_rec_t to a nis_object ENTRY_OBJ. Table related fields
* will be filled in by the functions with the appropriate context.
* Caller is responsible for freeing result.
*/
static int
{
unsigned int cid_buf_len;
return (DSVC_NO_MEMORY);
return (DSVC_NO_MEMORY);
}
return (DSVC_NO_MEMORY);
}
/* cid */
return (DSVC_NO_MEMORY);
}
return (DSVC_INTERNAL);
}
/* flags */
return (DSVC_NO_MEMORY);
}
/* cip */
return (DSVC_NO_MEMORY);
}
/* sip */
return (DSVC_NO_MEMORY);
}
/* lease */
return (DSVC_NO_MEMORY);
}
/* macro */
return (DSVC_NO_MEMORY);
}
/* comment */
return (DSVC_NO_MEMORY);
}
/* signature -> OID */
return (DSVC_SUCCESS);
}
/*
* Convert a nis_object ENTRY_OBJ to a dn_rec_t. Caller is responsible for
* freeing result.
*/
static int
{
return (DSVC_NO_MEMORY);
/* cid */
return (DSVC_INTERNAL);
}
/* flags */
/* cip */
return (DSVC_INTERNAL);
}
/* sip */
return (DSVC_INTERNAL);
}
/* lease */
/* macro */
/* comment */
sizeof (dnp->dn_comment));
/* oid -> signature */
return (DSVC_SUCCESS);
}
/*
* Given a dn_rec_t and a query, generate and return a nisplus search criteria
* string.
*
* cid, flags, cip, sip, lease, and macro are searchable.
*
* Returns dynamically allocated search criteria if successful, NULL otherwise.
*/
static char *
{
nis_object *op;
return (NULL);
/* cid */
}
/* flags */
DSVCNIS_INT, &i);
}
DSVCNIS_INT, &i);
}
}
DSVCNIS_INT, &i);
}
/* cip */
}
/* sip */
}
/* lease */
}
/* macro */
}
if (err != DSVC_SUCCESS) {
return (NULL);
}
/* if this is a NULL query, allocate just enough for start spec */
return (NULL);
}
return (NULL);
}
return (scp);
}
/*
* List the current number of dhcp network container objects located at the
* NIS_DIRECTORY 'location' in listppp. Return number of list elements in
* 'count'. If no objects exist, then 'count' is set to 0 and DSVC_SUCCESS
* is returned.
*
* Note - all objects of TYPE_DN which have *valid* names are returned.
*
* This function blocks if NIS+ is unavailable.
*/
int
{
*count = 0;
&resp, HARD_LOOKUP);
if (error != DSVC_SUCCESS)
return (error);
for (;;) {
if (error == DSVC_SUCCESS)
break;
if (error == DSVC_NO_TABLE) {
/* Not having any containers is a fine result */
return (DSVC_SUCCESS);
}
return (error);
(void) sleep(NIS_BUSY_PAUSE);
}
return (DSVC_NO_MEMORY);
}
for (i = 0; i < NIS_RES_NUMOBJ(resp); i++) {
for (;;) {
(void) sleep(NIS_BUSY_PAUSE);
else
break;
}
if (terr != DSVC_SUCCESS)
continue;
char *ip;
sizeof (char **));
break;
} else
break;
}
break;
}
} else
}
if (error != DSVC_SUCCESS) {
for (i = *count - 1; i >= 0; i--)
}
*count = 0;
}
return (error);
}
/*
* Creates or opens the dhcp network container netp (host order) with mask
* (host order) in location and initializes handlep to point to the instance
* handle. Performs any initialization needed by data store. New containers
* are created with the identity of the caller.
*/
/* ARGSUSED */
int
{
int error;
char netnm[INET_ADDRSTRLEN],
return (DSVC_INTERNAL);
location);
f_access |= NIS_READ_ACC;
if (flags & DSVC_WRITE)
if (flags & DSVC_CREATE) {
sizeof (owner))) != DSVC_SUCCESS)
return (error);
sizeof (group))) != DSVC_SUCCESS)
if (default_nis_access != 0)
if (default_nis_ttl == 0)
else
if (error != DSVC_SUCCESS)
return (error);
}
if (error != DSVC_SUCCESS) {
return (error);
}
return (DSVC_ACCESS);
}
return (DSVC_NO_MEMORY);
return (DSVC_SUCCESS);
}
/*
* Remove DHCP network container netp (host order) in location.
*
* This function blocks if NIS+ is unavailable.
*/
int
{
nis_object *op;
int error;
return (DSVC_INTERNAL);
location);
/* Empty the entire table */
for (;;) {
break;
return (error);
(void) sleep(NIS_BUSY_PAUSE);
}
/* now remove the table */
for (;;) {
&op);
if (error == DSVC_SUCCESS)
break;
return (error);
(void) sleep(NIS_BUSY_PAUSE);
}
for (;;) {
break;
(void) sleep(NIS_BUSY_PAUSE);
}
return (error);
}
/*
* Searches DHCP network container for instances that match the query
* described by the combination of query and targetp. If the partial
* argument is true, then lookup operations that are unable to
* complete entirely are allowed (and considered successful). The
* query argument consists of 2 fields, each 16 bits long. The lower
* 16 bits selects which fields {client_id, flags, client_ip,
* server_ip, expiration, macro, or comment} of targetp are to be
* considered in the query. The upper 16 bits identifies whether a
* particular field value must match (bit set) or not match (bit
* clear). Bits 7-15 in both 16 bit fields are currently unused, and
* must be set to 0. The count field specifies the maximum number of
* matching records to return, or -1 if any number of records may be
* returned. The recordspp argument is set to point to the resulting
* list of records; if recordspp is passed in as NULL then no records
* are actually returned. Note that these records are dynamically
* allocated, thus the caller is responsible for freeing them. The
* number of records found is returned in nrecordsp; a value of 0 means
* that no records matched the query.
*/
int
{
char *scp;
int error, i;
if (!dsvcnis_validate_handle(nhp))
return (DSVC_INVAL);
return (DSVC_ACCESS);
return (DSVC_NO_MEMORY);
flags |= HARD_LOOKUP;
if (error != DSVC_SUCCESS) {
if (error == DSVC_NOENT) {
/* no records matched the query */
*nrecordsp = 0;
}
return (error);
}
/*
* Fastpath for queries w/o negative aspects for which no records
* are to be returned.
*/
return (DSVC_SUCCESS);
}
if (error != DSVC_SUCCESS) {
if (partial)
break;
return (error);
}
/*
* The query has gotten the records that match
* the "positive" aspects of the query. Weed out
* the records that match the "negative" aspect.
*/
dnp->dn_cid_len) == 0) ||
continue;
}
if (partial)
break;
return (DSVC_NO_MEMORY);
} else {
num++;
}
}
return (DSVC_SUCCESS);
}
/*
* Add the record pointed to by addp from the dhcp network container
* referred to by the handle. addp's signature will be updated by the
* underlying public module.
*/
int
{
nis_object *op;
int error;
if (!dsvcnis_validate_handle(nhp))
return (DSVC_INVAL);
return (DSVC_ACCESS);
return (error);
return (error);
}
for (;;) {
(void) sleep(NIS_BUSY_PAUSE);
} else
break;
}
if (error == DSVC_SUCCESS) {
/* oid -> signature */
}
return (error);
}
/*
* Atomically modify the record origp with the record newp in the dhcp
* network container referred to by the handle. newp's signature will
* be updated by the underlying public module. If an update collision
* occurs, no update of the data store occurs.
*/
int
{
int error;
char *scp;
if (!dsvcnis_validate_handle(nhp))
return (DSVC_INVAL);
return (DSVC_ACCESS);
/*
* MOD_SAMEOBJ ensures that the signature of the obj to modify has
* not changed in the table (detects update collisions).
*/
return (DSVC_NO_MEMORY);
return (error);
}
return (error);
}
return (error);
}
/* copy object ID */
/* cid */
}
/* flags */
/* cip */
/*
* We set MOD_EXCLUSIVE because CIP is unique, and
* we want nisplus to check to see if there will be a
* collision (matching record), and not perform the modify
* if a collision occurs. Allows us to do an atomic
* modify.
*/
flags |= MOD_EXCLUSIVE;
}
/* sip */
/* lease */
/* macro */
/* comment */
for (;;) {
(void) sleep(NIS_BUSY_PAUSE);
} else
break;
}
if (error == DSVC_SUCCESS)
return (error);
}
/*
* Delete the record pointed to by pnp from the dhcp network container
* referred to by the handle. If an update collision occurs, no
* deletion of record in the data store occurs.
*/
int
{
nis_object *op;
int error;
char *scp;
if (!dsvcnis_validate_handle(nhp))
return (DSVC_INVAL);
return (DSVC_ACCESS);
return (DSVC_NO_MEMORY);
/* Caller is interested in knowing about a collision */
if (error != DSVC_SUCCESS) {
return (error);
}
} else
for (;;) {
(void) sleep(NIS_BUSY_PAUSE);
else
break;
}
return (error);
}