/*
* 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
*/
/*
*/
#include "mt.h"
#include <ipsec_util.h>
#include <netdb.h>
#include <fcntl.h>
#include <unistd.h>
#include <synch.h>
#include <string.h>
#include <strings.h>
#include <stdlib.h>
#include <unistd.h>
#include <syslog.h>
/* Globals... */
static int num_protos;
void
{
int alg_offset;
return;
while (num-- != 0) {
alg_offset++)
alg_offset++)
}
}
/*
* Returns >= 0 if success (and > 0 means "increment").
* Returns -1 if failure.
*/
static int
{
int key_increment = 0;
/*
* Okay, let's check the format of the key string. It'll be either:
*
* enumeration: size1,size2...,sizeN
* range: defaultSize/sizeLow-sizeHi,increment
*
* In the case of an enumeration, the default key size is the
* first one in the list.
*/
/* key sizes specified by range */
/* default */
return (-1);
/* low */
return (-1);
/* high */
return (-1);
/* increment */
return (-1);
sizeof (int));
return (-1);
} else {
/* key sizes specified by enumeration */
return (-1);
num_sizes = 0;
return (-1);
}
*key_sizes = 0;
do {
int *nks;
sizeof (int) * ((++num_sizes) + 1));
return (-1);
}
/* Can't check for atoi() == 0 here... */
}
return (key_increment);
}
/*
* Find the execution mode corresponding to the given string.
* Returns 0 on success, -1 on failure.
*/
int
{
return (0);
return (0);
}
return (-1);
}
/*
* Given a file pointer, read all the text from the file and convert it into
* a bunch of ipsec_proto_t's, each with an array of struct ipsecalgent
* pointers - one for each algorithm.
*/
static ipsec_proto_t *
{
diag_buf[0] = '\0';
sizeof (LIBIPSEC_ALGS_LINE_PROTO) - 1) != 0 &&
sizeof (LIBIPSEC_ALGS_LINE_ALG) - 1) != 0 &&
sizeof (LIBIPSEC_ALGS_LINE_PKGSTART) - 1) != 0 &&
sizeof (LIBIPSEC_ALGS_LINE_PKGEND) - 1) != 0) {
token[0] == '#') {
continue;
} else {
"non-recognized start of line");
goto bail;
}
}
sizeof (LIBIPSEC_ALGS_LINE_PROTO) - 1) == 0) {
/* current line defines a new protocol */
/* skip the protocol token */
/* protocol number */
"invalid protocol number");
goto bail;
}
/* protocol name */
"cannot read protocol name");
goto bail;
}
proto_name = token;
/* execution mode */
"cannot read execution mode");
goto bail;
}
/* remove trailing '\n' */
"invalid execution mode: \"%s\"", token);
goto bail;
}
/* initialize protocol structure */
rc_num++;
sizeof (ipsec_proto_t) * rc_num);
goto bail;
new_proto->proto_numalgs = 0;
goto bail;
if (doing_pkg) {
/* record proto as being part of current pkg */
goto bail;
} else {
}
new_proto->proto_algs_npkgs = 0;
sizeof (LIBIPSEC_ALGS_LINE_ALG) - 1) == 0) {
/* current line defines a new algorithm */
/* skip the algorithm token */
/* protocol number */
"invalid algorithm number");
goto bail;
}
/* We can be O(N) for now. There aren't that many. */
new_proto++)
break;
"invalid protocol number %d for algorithm",
new_num);
goto bail;
}
/* algorithm number */
"cannot read algorithm number");
goto bail;
}
/* Can't check for 0 here. */
/* algorithm names */
"cannot read algorithm number");
goto bail;
}
/* mechanism name */
"cannot read mechanism name for alg %d "
"(proto %d)", alg_num,
goto bail;
}
/* key sizes */
"cannot read key sizes for alg %d "
"(proto %d)", alg_num,
goto bail;
}
key_string = token;
/* block sizes */
"cannot read block sizes for alg %d "
"(proto %d)", alg_num,
goto bail;
}
/*
* Check for mechanism params and flags. As these
* are optional, we won't bail if they don't exist.
*/
else
flags = 0;
/* extract key sizes */
if (key_increment == -1) {
"invalid key sizes for alg %d (proto %d)",
goto bail;
}
/* extract block sizes */
block_sizes = (int *)malloc(sizeof (int));
if (block_sizes == NULL) {
goto bail;
}
num_sizes = 0;
"invalid block sizes for alg %d (proto %d)",
goto bail;
}
*block_sizes = 0;
do {
int *nbk;
sizeof (int) * ((++num_sizes) + 1));
goto bail;
}
block_sizes = nbk;
/* Can't check for 0 here... */
block_sizes[num_sizes] = 0;
NULL);
/* extract mech params */
mech_params = (int *)malloc(sizeof (int));
if (mech_params == NULL) {
goto bail;
}
*mech_params = 0;
num_sizes = 0;
if (params_string != NULL) {
sizeof (diag_buf), "invalid mech "
"params for alg %d (proto %d)",
goto bail;
}
do {
int *nbk;
sizeof (int) * ((++num_sizes) + 1));
goto bail;
}
mech_params = nbk;
/* Can't check for 0 here... */
mech_params[num_sizes] = 0;
!= NULL);
}
/* Allocate a new struct ipsecalgent. */
sizeof (struct ipsecalgent), 1);
goto bail;
}
goto bail;
}
/* Set names. */
num_sizes = 0; /* Recycle "sizes" */
goto bail;
}
do {
char **nnames;
sizeof (char *) * ((++num_sizes) + 1));
goto bail;
}
goto bail;
}
NULL);
if (doing_pkg) {
/* record alg as being part of current pkg */
goto bail;
== NULL)
goto bail;
}
/* add new alg to protocol */
sizeof (struct ipsecalgent *));
if (newalglist == NULL) {
goto bail;
}
sizeof (LIBIPSEC_ALGS_LINE_PKGSTART) - 1) == 0) {
/* start of package delimiter */
if (doing_pkg) {
"duplicate package start delimiters");
goto bail;
}
(sizeof (LIBIPSEC_ALGS_LINE_PKGSTART) - 1),
sizeof (cur_pkg));
/* remove trailing '\n' */
} else {
/* end of package delimiter */
if (!doing_pkg) {
"end package delimiter without start");
goto bail;
}
/*
* Get specified pkg name, fail if it doesn't match
* the package specified by the last # Begin.
*/
(sizeof (LIBIPSEC_ALGS_LINE_PKGEND) - 1),
sizeof (tmp_pkg));
/* remove trailing '\n' */
goto bail;
}
}
return (rc);
bail:
}
return (NULL);
}
/*
* If alg_context is NULL, update the library's cached copy of
* INET_IPSECALGSFILE. If alg_context is non-NULL, hang a
* library-internal representation of a cached copy. The latter is useful
* for routines in libipsecutil that _write_ the contents out.
*/
void
{
FILE *f;
/*
* Construct new_protos from the file.
*/
if (alg_context == NULL) {
/*
* Check the time w/o holding the lock. This is just a
* cache reality check. We'll do it again for real if this
* surface check fails.
*/
return;
}
if (f != NULL) {
if (rc != -1) {
/*
* Update if the file is newer than our
* last cached copy.
*/
if (alg_context != NULL ||
}
/* Since f is read-only, can avoid all of the failures... */
(void) fclose(f);
}
if (alg_context == NULL) {
/*
* If we have failed anywhere above, new_protoss will be NULL.
* This way, the previous cached protos will still be intact.
*/
if (new_protos != NULL) {
protos = new_protos;
num_protos = rc;
} else {
/*
* Else the original protocols and algorithms lists
* remains the same.
*/
}
} else {
/*
* Assume caller has done the appropriate locking,
* cleanup, etc. And if new_protos is NULL, it's the caller's
* problem.
*/
}
}
/*
* Assume input is 0-terminated.
*/
static int *
{
return (NULL);
while (*iwalker != 0) {
allocsize += sizeof (int);
iwalker++;
}
return (iwalker);
}
/*
* Assume input is NULL terminated.
*/
static char **
{
int i;
char **swalker;
char **newbie;
return (NULL);
/* count number of elements in source array */
;
/* use calloc() to get NULL-initialization */
/* do the copy */
swalker++)
return (NULL);
}
}
}
return (newbie);
}
struct ipsecalgent *
{
/* use calloc() to get NULL-initialization. */
return (NULL);
return (NULL);
}
return (rc);
}
/*
* Assume the rwlock is held for reading.
*/
static ipsec_proto_t *
{
int i;
for (i = 0; i < num_protos; i++) {
return (protos + i);
}
return (NULL);
}
static ipsec_proto_t *
{
int i;
return (NULL);
for (i = 0; i < num_protos; i++) {
/* Can use strcasecmp because our proto_name is bounded. */
return (protos + i);
}
return (NULL);
}
int *
{
int *rc, i;
return (NULL);
*nentries = num_protos;
/*
* Allocate 1 byte if there are no protocols so a non-NULL return
* happens.
*/
for (i = 0; i < num_protos; i++)
}
return (rc);
}
int *
{
return (NULL);
/*
* Allocate 1 byte if there are no algorithms so a non-NULL
* return happens.
*/
proto->proto_numalgs * sizeof (int));
for (i = 0; i < proto->proto_numalgs; i++)
}
}
return (rc);
}
struct ipsecalgent *
{
char **name_check;
goto bail;
}
for (i = 0; i < proto->proto_numalgs; i++) {
/*
* Can use strcasecmp because our name_check
* is bounded.
*/
/* found match */
rc = _duplicate_alg(
proto->proto_algs[i]);
goto bail;
}
}
}
} else {
}
bail:
return (rc);
}
struct ipsecalgent *
{
for (i = 0; i < proto->proto_numalgs; i++) {
break;
}
}
} else {
}
return (rc);
}
int
{
return (rc);
}
char *
{
return (rc);
}
void
{
char **walker;
return;
}
/*
* Remember folks, free(NULL) works.
*/
}