devpolicy.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 2003 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <ctype.h>
#include <priv.h>
#include <string.h>
#include <libgen.h>
#include <errno.h>
#include <libintl.h>
#include <sys/devpolicy.h>
#include "message.h"
#include "plcysubr.h"
/* Cannot include devfsadm_impl.h because of static definitions */
#define err_print devfsadm_errprint
extern void err_print(char *, ...);
#define PLCY_CHUNK 128
/*
* devpolicy sort order sorts on three items to help the kernel;
* the kernel will verify but not sort.
*
* 1) major number - but default major will be first in sorted output
* 2) wildcard or not - non wildcard entries are sorted first.
* 2a) Expanded minor numbers first (empty name sorts first).
* 2b) Named minors.
* 3) length of wildcard entry - longest pattern first
*
* The last rule allows patterns such as *ctl and * to be used both
* unambiguously instead of current bogosities as found in /etc/minor_perm:
* rtvc:ctl 0644 root sys
* rtvc:rtvcctl* 0644 root sys
* rtvc:rtvc[!ctl]* 0666 root sys
*
* The last pattern only works by accident.
*
* This would simply become (in sorted order):
* rtvc:ctl
* rtvc:rtvcctl*
* rtvc:*
*/
static int
qcmp(const void *a, const void *b)
{
const devplcysys_t *pa = a;
const devplcysys_t *pb = b;
/* sort on major number, default major first in sort output */
return (-1);
return (1);
return (1);
return (-1);
/* sort the entry with the wildcard last */
/* entries without wildcards compare with strcmp() */
if (wilda == 0)
/* shortest wildcard last */
}
static int
{
int res = 0;
return (0);
if (*line == '\0')
continue;
*col = '\0';
!= 0)
continue;
}
(void) err_print("modctl(MODALLOCPRIV, %s): %s\n",
res = -1;
}
}
return (res);
}
static int
loadpolicy(const char *infile)
{
char *line;
int res;
char *maj;
char *tok;
char *min;
return (-1);
}
nalloc += PLCY_CHUNK;
nalloc * devplcysys_sz);
return (-1);
}
/* Readjust pointer to dflt after realloc */
/* LINTED: alignment */
}
continue;
/* LINTED: alignment */
return (-1);
}
} else {
return (-1);
}
*min++ = '\0';
"Too many ``:'' in entry\n");
return (-1);
}
} else
min = "*";
/* Silently ignore unknown devices. */
continue;
if (*min == '(') {
/* Numeric minor range */
char type;
return (-1);
}
} else {
return (-1);
}
}
}
return (-1);
}
}
cnt++;
}
else
return (-1);
}
return (res);
}
int
load_devpolicy(void)
{
int res;
devplcy_init();
return (res);
}