getdaent.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"
#include <stdio.h>
#include <string.h>
#include <malloc.h>
#define MAXINT 0x7fffffff;
#ifdef SunOS_CMW
extern char *calloc();
#endif
static struct _dabuff {
char *_DEVALLOC;
} *__dabuff;
static devalloc_t *interpret();
static int matchname();
/*
* trim_white(ptr) trims off leading and trailing white space from a NULL
* terminated string pointed to by "ptr". The leading white space is skipped
* by moving the pointer forward. The trailing white space is removed by
* nulling the white space characters. The pointer is returned to the white
* string. If the resulting string is null in length then a NULL pointer is
* returned. If "ptr" is NULL then a NULL pointer is returned.
*/
static char *
char *ptr;
{
register char *tptr;
register int cnt;
return (NULL);
ptr++;
}
if (cnt != 0) {
*tptr = '\0';
tptr--;
}
}
return (NULL);
return (ptr);
}
/*
* scan string pointed to by pointer "p"
* find next colin or end of line. Null it and
* return pointer to next char.
*/
static char *
daskip(p)
register char *p;
{
while (*p && *p != ';' && *p != '\n')
++p;
if (*p == '\n')
*p = '\0';
else if (*p != '\0')
*p++ = '\0';
return (p);
}
/*
* scan string pointed to by pointer "p"
* find next colin or end of line. Null it and
* return pointer to next char.
*/
static char *
dadskip(p)
register char *p;
{
while (*p && *p != ' ' && *p != '\n')
++p;
if (*p != '\0')
*p++ = '\0';
return (p);
}
/*
* _daalloc() allocates common buffers and structures used by the device
* allocate library routines. Then returns a pointer to a structure. The
* returned pointer will be null if there is an error condition.
*/
static struct _dabuff *
_daalloc()
{
if (_da == 0) {
if (_da == 0)
return (0);
DEVALLOC = "/etc/security/device_allocate";
}
return (__dabuff);
}
/*
* getdaline(buff,len,stream) reads one device allocate line from "stream" into
* "buff" on "len" bytes. Continued lines from "stream" are concatinated
* into one line in "buff". Comments are removed from "buff". The number of
* characters in "buff" is returned. If no characters are read or an err or
* occured then "0" is returned
*/
static int
char *buff;
int len;
{
char *cp;
char *ccp;
int tmpcnt;
int charcnt = 0;
int fileerr = 0;
int contline;
if (_da == 0)
return (0);
do {
do {
fileerr = 1;
break;
}
if (*ccp == '\\')
contline = 1;
else
contline = 0;
}
if (tmpcnt != 0) {
}
if (fileerr)
return (0);
else
return (charcnt);
}
char *
char *ptr;
{
static char *tptr;
return (NULL);
return (NULL);
return (NULL);
return (ptr);
}
char *
char *ptr;
{
static char *tptr;
} else {
}
return (NULL);
return (NULL);
return (NULL);
return (ptr);
}
/*
* getdadev(dev) searches from the beginning of the file until a logical
* device matching "dev" is found and returns a pointer to the particular
* structure in which it was found. If an EOF or an error is encountered on
* reading, these functions return a NULL pointer.
*/
#ifdef NOTDEF
register char *name;
{
devalloc_t *da;
if (_da == 0)
return (0);
setdaent();
if (!daf)
return ((devalloc_t *)NULL);
continue;
enddaent();
return (da);
}
}
enddaent();
return ((devalloc_t *)NULL);
}
#endif /* NOTDEF */
/*
* getdanam(name) searches from the beginning of the file until a audit-name
* matching "name" is found and returns a pointer to the particular structure
* in which it was found. If an EOF or an error is encountered on reading,
* these functions return a NULL pointer.
*/
register char *name;
{
devalloc_t *da;
if (_da == 0)
return (0);
setdaent();
if (!daf)
return ((devalloc_t *)NULL);
continue;
enddaent();
return (da);
}
}
enddaent();
return ((devalloc_t *)NULL);
}
/*
* setdaent() essentially rewinds the device_allocate file to the begining.
*/
void
setdaent()
{
if (_da == 0)
return;
} else
}
/*
* enddaent() may be called to close the device_allocate file when processing
* is complete.
*/
void
enddaent()
{
if (_da == 0)
return;
}
}
/*
* setdafile(name) changes the default device_allocate file to "name" thus
* allowing alternate device_allocate files to be used. Note: it does not
* close the previous file . If this is desired, enddaent should be called
* prior to it.
*/
void
char *file;
{
if (_da == 0)
return;
}
}
/*
* getdatype(tp) When first called, returns a pointer to the
* first devalloc_t structure in the file with device-type matching
* "tp"; thereafter, it returns a pointer to the next devalloc_t
* structure in the file with device-type matching "tp".
* Thus successive calls can be used to search the
* entire file for entries having device-type matching "tp".
* A null pointer is returned on error.
*/
char *tp;
{
devalloc_t *da;
if (_da == 0)
return (0);
return (NULL);
}
do {
return (NULL);
return (NULL);
return (da);
}
/*
* getdaent() When first called, returns a pointer to the first devalloc_t
* structure in the file; thereafter, it returns a pointer to the next
* devalloc_t structure in the file. Thus successive calls can be used to
* search the entire file. A null pointer is returned on error.
*/
getdaent()
{
devalloc_t *da;
if (_da == 0)
return (0);
return (NULL);
}
return (NULL);
return (NULL);
return (da);
}
/*
* matchdev(dap,dev) The dev_list in the structure pointed to by "dap" is
* searched for string "dev". If a match occures then a "1" is returned
* otherwise a "0" is returned.
*/
#ifdef NOTDEF
static
devalloc_t **dap;
char *dev;
{
int charcnt;
int tmpcnt;
char *cp;
char *tcp;
char *last;
if (_da == 0)
return (0);
return (0);
continue;
return (1);
}
return (0);
}
#endif /* NOTDEF */
/*
* matchname(dap,name) The audit-name in the structure pointed to by "dap" is
* searched for string "name". If a match occures then a "1" is returned
* otherwise a "0" is returned.
*/
static int
devalloc_t **dap;
char *name;
{
if (_da == 0)
return (0);
return (0);
return (0);
return (1);
return (0);
}
/*
* interpret(val) string "val" is parsed and the pointers in a devalloc_t
* structure are initialized to point to fields in "val". A pointer to this
* structure is returned.
*/
static devalloc_t *
char *val;
{
if (_da == 0)
return (0);
return (&interpdevalloc);
}