/*
* 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 2003 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*
* Device policy specific subroutines. We cannot merge them with
* drvsubr.c because of static linking requirements.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <ctype.h>
#include <priv.h>
#include <string.h>
#include <libgen.h>
#include <libintl.h>
#include <errno.h>
#include <alloca.h>
#include <sys/devpolicy.h>
#include <sys/sysmacros.h>
#include "addrem.h"
#include "errmsg.h"
#include "plcysubr.h"
/*
* New token types should be parsed in parse_plcy_entry.
*/
#define PSET 0
typedef struct token {
const char *token;
int type;
} token_t;
};
#define RDPOL 0
/*
* Compute the size of the datastructures needed.
*/
void
devplcy_init(void)
{
exit(1);
}
(char *)0;
(char *)0;
}
/*
* Read a configuration file line and return a static buffer pointing to it.
* It returns a static struct fileentry which has several fields:
* - rawbuf, which includes the lines including empty lines and comments
* leading up to the file and the entry as found in the file
* - orgentry, pointer in rawbuf to the start of the entry proper.
* - entry, a pre-parsed entry, escaped newlines removed.
* - startline, the line number of the first line in the file
*/
{
char *p;
int c, lastc, i;
return (NULL);
}
}
i = 0;
off = -1;
c = '\n';
buf[i++] = c;
if (i == sz) {
sz *= 2;
return (NULL);
}
if (c == '\n') {
linecnt++;
/* Newline, escaped or not yet processing an entry */
continue;
/* Start of more comments */
if (c == '#')
continue;
/* Found start of entry */
off = i - 1;
continue;
} else
continue;
buf[i] = '\0';
if (p == NULL)
return (NULL);
/* Remove <backslash><newline> */
if (p[0] == '\\' && p[1] == '\n') {
off += 2;
p++;
}
}
return (&fe);
}
return (NULL);
buf[i] = '\0';
linecnt = 1;
return (&fe);
}
/*
* Parse minor number ranges:
* (minor) or (lowminor-highminor)
* Return 0 for success, -1 for failure.
*/
int
{
unsigned long tmp;
char *p;
if (*range++ != '(')
return (-1);
errno = 0;
(*p != '-' && *p != ')'))
return (-1);
if (*p == '-') {
errno = 0;
return (-1);
}
return (-1);
switch (p[1]) {
case '\0':
*type = '\0';
break;
case 'c':
case 'C':
*type = 'c';
break;
case 'b':
case 'B':
*type = 'b';
break;
default:
return (-1);
}
return (0);
}
static void
{
/* Preserve preceeding comments */
if (type == '\0') {
} else {
}
}
static int
{
char *nfile;
int newfd;
char *mpart;
char rtype;
} else {
mpart++;
if (*mpart == '(') {
return (-1);
} else {
}
}
return (-1);
return (-1);
return (ERROR);
}
/* Copy permissions, ownership */
} else {
}
char *tok;
char *min;
char *tail;
char tc;
int len;
/* Trailing comments */
break;
}
tok++;
if (*tok == '\0') {
break;
}
/* Make sure we can recover the remainder incl. whitespace */
*tail = '\0';
if (min)
*min++ = '\0';
}
if (delrange) {
char type;
/*
* Delete or shrink overlapping ranges.
*/
/* Complete overlap, then drop it. */
continue;
/* Partial overlap, shrink range */
else
else
/* restore NULed character */
/* Split range? */
/*
* We have two ranges:
* lo ... newhi (== rlo - 1)
* newlo (== rhi + 1) .. hi
*/
} else {
}
continue;
}
/*
* Delete exact match.
*/
continue;
}
/* Copy unaffected entry. */
}
return (ERROR);
return (ERROR);
}
} else
return (0);
}
int
{
char *p, *single;
char *copy;
int ret = 0;
return (ERROR);
return (ret);
}
}
return (0);
}
/*
* Analyze the device policy token; new tokens should be added to
* toktab; new token types should be coded here.
*/
int
{
const char *perr;
int i;
return (1);
}
*val++ = '\0';
for (i = 0; i < NTOK; i++) {
/* standard pointer computation for tokens */
case PSET:
else
return (1);
}
break;
default:
"Internal Error: bad token type: %d\n",
return (1);
}
/* Standard cleanup & return for good tokens */
return (0);
}
}
return (1);
}
static int
{
char *p = *dstp;
*sz *= 2;
if (p == NULL) {
return (-1);
}
}
return (0);
}
/*
* Verify that the policy entry is valid and return the canonical entry.
*/
char *
{
char *res;
char *tok;
devplcy_init();
return (NULL);
}
*res = '\0';
/* It's not a token */
return (NULL);
}
return (NULL);
if (*tok == '(') {
char type;
return (NULL);
}
} else {
}
}
return (NULL);
return (NULL);
return (NULL);
} else {
if (*res == '\0') {
return (NULL);
return (NULL);
}
return (NULL);
}
return (NULL);
return (NULL);
}
}
return (NULL);
}
if (!todel)
return (NULL);
return (res);
}
int
{
if (repl) {
return (ERROR);
}
/*
* Split the entry in lines; then get the first token
* of each line.
*/
return (ERROR);
}
}
}
return (ERROR);
return (ERROR);
return (NOERR);
}
/*
* We need to allocate the privileges now or the privilege set
* parsing code will not allow them.
*/
int
{
char *pr;
if (l == NULL) {
return (ERROR);
}
/* Privilege already exists */
continue;
return (ERROR);
}
}
return (NOERR);
}