/*
* 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 <string.h>
#include <strings.h>
#include <stdlib.h>
#include <unistd.h>
#include <limits.h>
#include <device_info.h>
#include <dev_alloc.h>
#include <devalloc_impl.h>
#include <ctype.h>
#include <libdevinfo.h>
#include <fcntl.h>
char *strtok_r(char *, const char *, char **);
/* externs from getdaent.c */
extern char *trim_white(char *);
extern int pack_white(char *);
extern char *getdadmfield(char *, char *);
extern int getdadmline(char *, int, FILE *);
static struct _dmapbuff {
char *_DEVMAP;
} *__dmapbuff;
int dmap_matchdev(devmap_t *, char *);
int dmap_matchname(devmap_t *, char *);
/*
* _dmapalloc -
* allocates common buffers and structures.
* returns pointer to the new structure, else returns NULL on error.
*/
static struct _dmapbuff *
_dmapalloc(void)
{
(unsigned)sizeof (*__dmapbuff));
return (NULL);
DEVMAPS_FILE = "/etc/security/device_maps";
__dmapbuff = _dmap;
}
return (_dmap);
}
/*
* setdmapent -
* rewinds the device_maps file to the beginning.
*/
void
setdmapent(void)
{
return;
else
}
/*
* enddmapent -
* closes device_maps file.
*/
void
enddmapent(void)
{
return;
}
}
void
{
char **darp;
}
}
/*
* setdmapfile -
* changes the default device_maps file to the one specified.
* It does not close the previous file. If this is desired, enddmapent
* should be called prior to setdampfile.
*/
void
{
return;
}
DEVMAPS_FILE = file;
}
/*
* getdmapent -
* When first called, returns a pointer to the first devmap_t structure
* in device_maps; thereafter, it returns a pointer to the next devmap_t
* structure in the file. Thus successive calls can be used to read the
* entire file.
* call to getdmapent should be bracketed by setdmapent and enddmapent.
* returns pointer to devmap_t found, else returns NULL if no entry found
* or on error.
*/
devmap_t *
getdmapent(void)
{
return (NULL);
dmapf) != 0) {
&interpdevmap)) == NULL)
continue;
return (dmap);
}
return (NULL);
}
/*
* getdmapnam -
* searches from the beginning of device_maps for the device specified by
* its name.
* call to getdmapnam should be bracketed by setdmapent and enddmapent.
* returns pointer to devmapt_t for the device if it is found, else
* returns NULL if device not found or in case of error.
*/
devmap_t *
{
return (NULL);
dmapf) != 0) {
continue;
&interpdevmap)) == NULL)
continue;
continue;
enddmapent();
return (dmap);
}
}
return (NULL);
}
/*
* getdmapdev -
* searches from the beginning of device_maps for the device specified by
* its logical name.
* call to getdmapdev should be bracketed by setdmapent and enddmapent.
* returns pointer to the devmap_t for the device if device is found,
* else returns NULL if device not found or on error.
*/
devmap_t *
{
return (NULL);
dmapf) != 0) {
&interpdevmap)) == NULL)
continue;
enddmapent();
return (dmap);
}
}
return (NULL);
}
/*
* getdmaptype -
* searches from the beginning of device_maps for the device specified by
* its type.
* call to getdmaptype should be bracketed by setdmapent and enddmapent.
* returns pointer to devmap_t found, else returns NULL if no entry found
* or on error.
*/
devmap_t *
{
return (NULL);
dmapf) != 0) {
&interpdevmap)) == NULL)
continue;
continue;
return (dmap);
}
}
return (NULL);
}
/*
* dmap_follow_path
*
* Starting with a path, follow it as far as possible
* to the contents of the last symlink (even if the file
* being pointed to does not exist)
*
* Returns a pointer to a malloc'd string.
*
*/
static char *
{
return (strdup(initial_path));
return (retstr);
return (strdup(initial_path));
}
/*
* dmap_match_one_dev -
* Checks if the specified devmap_t contains strings
* for the same link as the device specified.
*
* Returns 1 for a match, else returns 0.
*/
static int
{
char **dmapva;
char *dmvp;
char *dmap_link;
char *dev_link;
int typedev;
int truncate_phys_path = 0;
return (0);
/*
* Check if both refer to same logical device.
*
* Disk and tape pathnames can have suffixes
* for the same physical device which only indicate slice
* or whether to rewind, irrelevant for us since we are
* trying to control entire removable devices.
*
* In addition, some non-ON software uses /dev instead of
* /devices, so libdevinfo might not always support /dev paths.
*/
switch (typedev) {
/* Disk types are a match even if slice numbers differ */
case DA_FLOPPY:
case DA_CD:
case DA_RMDISK:
truncate_phys_path = 1;
return (1);
break;
/* tapes, audio, unknown types require exact match for links */
case DA_TAPE:
/*FALLTHROUGH*/
default:
sizeof (stage_link));
return (1);
}
}
/*
* Check if both refer to same physical device. Since
* the organization of links varies considerably, we
* cannot count on the "disk" model to apply to all device
* types, so check all the links.
*/
== (char *)NULL)
return (0); /* should not happen */
/*
* If disk or tape, arrange to ignore slice or rewind minor
* information, it is not relevant to identifying the device
*/
if (truncate_phys_path &&
/* check for later digits, if found do not truncate */
while (*++tmp2 != '\0')
truncate_phys_path = 0;
break;
}
if (truncate_phys_path == 1)
}
/*
* The passed-in device link string for dargdev has not been
* broken into an array, it is a space-separated string.
* We need to step through the list.
*/
if ((dev_link =
return (0);
}
return (1);
}
}
}
return (0);
}
/*
* dmap_matchdev -
* checks if the specified devmap_t is for the device specified.
* returns 1 if it is, else returns 0.
*/
int
{
char **dva;
char *dv;
return (0);
return (1);
}
return (0);
}
/*
* Requires a match of the /dev/? links, not just the logical devname
* Returns 1 for match found, 0 for match not found, 2 for invalid arguments.
*
* Also looks for an instance number at the end of the logical name, and
* puts instance or -1 into *num.
*/
int
{
char *dv;
return (2);
*num = -1;
/* during some add processes, dev can be shorter than dmap */
}
/*
* dmap_matchtype -
* checks if the specified devmap_t is for the device specified.
* returns 1 if it is, else returns 0.
*/
int
{
return (0);
}
/*
* dmap_matchname -
* checks if the specified devmap_t is for the device specified.
* returns 1 if it is, else returns 0.
*/
int
{
return (0);
}
/*
* dmap_physname: path to /devices device
* Returns:
* strdup'd (i.e. malloc'd) real device file if successful
* NULL on error
*/
char *
{
char *oldlink;
return (NULL);
return (oldlink);
return (NULL);
}
/*
* dm_match -
* calls dmap_matchname or dmap_matchtype as appropriate.
*/
int
{
return (0);
}
/*
* dmap_interpret -
* calls dmap_interpretf and dmap_dlexpand to parse devmap_t line.
* returns pointer to parsed devmapt_t entry, else returns NULL on error.
*/
devmap_t *
{
return (NULL);
return (dmap_dlexpand(dm));
}
/*
* dmap_interpretf -
* parses string "val" and initializes pointers in the given devmap_t to
* fields in "val".
* returns pointer to updated devmap_t.
*/
static devmap_t *
{
return (NULL);
return (dm);
}
/*
* dmap_dlexpand -
* expands dmap_devlist of the form `devlist_generate`
* returns unexpanded form if there is no '\`' or in case of error.
*/
static devmap_t *
{
int count;
return (NULL);
} else {
*cp = '\0';
return (NULL);
}
/* cleanup the list */
return (NULL);
return (NULL);
}
darp++;
}
return (dmp);
}
/*
* dmapskip -
* scans input string to find next colon or end of line.
* returns pointer to next char.
*/
static char *
dmapskip(char *p)
{
while (*p && *p != ':' && *p != '\n')
++p;
if (*p == '\n')
*p = '\0';
else if (*p != '\0')
*p++ = '\0';
return (p);
}
/*
* dmapdskip -
* scans input string to find next space or end of line.
* returns pointer to next char.
*/
static char *
dmapdskip(p)
register char *p;
{
while (*p && *p != ' ' && *p != '\n')
++p;
if (*p != '\0')
*p++ = '\0';
return (p);
}
char *
{
static char *tptr;
return (NULL);
return (NULL);
return (NULL);
return (ptr);
}
char *
{
static char *tptr;
} else {
}
return (NULL);
return (NULL);
return (NULL);
return (ptr);
}