getdment.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;
static struct _dmapbuff {
char *_DEVMAP;
} *__dmapbuff;
static int matchdev();
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 *
trim_white(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 *
dmapskip(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 *
dmapdskip(register char *p)
{
while (*p && *p != ' ' && *p != '\n')
++p;
if (*p != '\0')
*p++ = '\0';
return (p);
}
/*
* _dmapalloc() allocates common buffers and structures used by the device
* maps library routines. Then returns a pointer to a structure. The
* returned pointer will be null if there is an error condition.
*/
static struct _dmapbuff *
_dmapalloc(void)
{
if (_dmap == 0) {
if (_dmap == 0)
return (0);
DEVMAP = "/etc/security/device_maps";
__dmapbuff = _dmap;
}
return (__dmapbuff);
}
/*
* getdmapline(buff,len,stream) reads one device maps 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 error
* occured then "0" is returned
*/
static int
{
char *cp;
char *ccp;
int charcnt = 0;
int fileerr = 0;
int contline;
if (_dmap == 0)
return (0);
do {
do {
fileerr = 1;
break;
}
if (*ccp == '\\')
contline = 1;
else
contline = 0;
}
if (tmpcnt != 0) {
}
return (0);
else
return (charcnt);
}
char
*getdmapfield(char *ptr)
{
static char *tptr;
return (NULL);
return (NULL);
return (NULL);
return (ptr);
}
char
*getdmapdfield(char *ptr)
{
static char *tptr;
} else {
}
return (NULL);
return (NULL);
return (NULL);
return (ptr);
}
/*
* getdmapdev(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.
*/
devmap_t *
getdmapdev(register char *name)
{
if (_dmap == 0)
return (0);
setdmapent();
if (!dmapf)
return (NULL);
continue;
enddmapent();
return (dmap);
}
}
enddmapent();
return (NULL);
}
/*
* getdmapnam(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.
*/
devmap_t *
getdmapnam(register char *name)
{
if (_dmap == 0)
return (0);
setdmapent();
if (!dmapf)
return (NULL);
continue;
enddmapent();
return (dmap);
}
}
enddmapent();
return (NULL);
}
/*
* setdmapent() essentially rewinds the device_maps file to the begining.
*/
void
setdmapent(void)
{
if (_dmap == 0)
return;
} else
}
/*
* enddmapent() may be called to close the device_maps file when processing
* is complete.
*/
void
enddmapent(void)
{
if (_dmap == 0)
return;
}
}
/*
* setdmapfile(name) changes the default device_maps file to "name" thus
* allowing alternate device_maps files to be used. Note: it does not
* close the previous file . If this is desired, enddmapent should be called
* prior to it.
*/
void
setdmapfile(char *file)
{
if (_dmap == 0)
return;
}
}
/*
* getdmaptype(tp) When first called, returns a pointer to the
* first devmap_t structure in the file with device-type matching
* "tp"; thereafter, it returns a pointer to the next devmap_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.
*/
devmap_t *
getdmaptype(char *tp)
{
if (_dmap == 0)
return (0);
return (NULL);
}
do {
return (NULL);
return (NULL);
return (dmap);
}
/*
* getdmapent() When first called, returns a pointer to the first devmap_t
* structure in the file; thereafter, it returns a pointer to the next devmap_t
* structure in the file. Thus successive calls can be used to search the
* entire file. A null pointer is returned on error.
*/
devmap_t *
getdmapent(void)
{
if (_dmap == 0)
return (0);
return (NULL);
}
return (NULL);
return (NULL);
return (dmap);
}
/*
* matchdev(dmapp,dev) The dev_list in the structure pointed to by "dmapp" is
* searched for string "dev". If a match occures then a "1" is returned
* otherwise a "0" is returned.
*/
static int
{
int charcnt;
int tmpcnt;
char *cp;
char *tcp;
char *last;
if (_dmap == 0)
return (0);
return (0);
continue;
return (1);
}
return (0);
}
/*
* matchname(dmapp,name) The audit-name in the structure pointed to by "dmapp"
* is searched for string "name". If a match occures then a "1" is returned
* otherwise a "0" is returned.
*/
static int
{
if (_dmap == 0)
return (0);
return (0);
return (0);
return (1);
return (0);
}
/*
* interpret(val) string "val" is parsed and the pointers in a devmap_t
* structure are initialized to point to fields in "val". A pointer to this
* structure is returned.
*/
static devmap_t *
{
if (_dmap == 0)
return (0);
return (&interpdevmap);
}