2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License, Version 1.0 only
2N/A * (the "License"). You may not use this file except in compliance
2N/A * with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
2N/A/* All Rights Reserved */
2N/A
2N/A
2N/A/*
2N/A * Copyright (c) 1997-2000 by Sun Microsystems, Inc.
2N/A * All rights reserved.
2N/A */
2N/A
2N/A#pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.2 */
2N/A/*LINTLIBRARY*/
2N/A
2N/A#include <string.h>
2N/A#include <ctype.h>
2N/A#include <sys/types.h>
2N/A#include "libadm.h"
2N/A
2N/Astatic char *rsvrd[] = {
2N/A "all",
2N/A "install",
2N/A "new",
2N/A NULL
2N/A};
2N/A
2N/A#define NMBRK ".*"
2N/A#define WILD1 ".*"
2N/A#define WILD2 "*"
2N/A#define WILD3 ".name"
2N/A#define ABI_NAMELNGTH 9
2N/A#define NON_ABI_NAMELNGTH 32
2N/A
2N/Astatic int abi_namelngth = 0;
2N/A
2N/Astatic int
2N/Avalname(char *pkg, int wild, int presvr4flg)
2N/A{
2N/A int count, i, n;
2N/A char *pt;
2N/A
2N/A /* wild == 1 allow wildcard specification as a name */
2N/A if (wild && (strcmp(pkg, "all") == 0))
2N/A return (0);
2N/A
2N/A /* check for reserved package names */
2N/A for (i = 0; rsvrd[i]; i++) {
2N/A n = (int)strlen(rsvrd[i]);
2N/A if ((strncmp(pkg, rsvrd[i], n) == 0) &&
2N/A (!pkg[n] || strchr(NMBRK, pkg[n])))
2N/A return (1);
2N/A }
2N/A
2N/A /*
2N/A * check for valid extensions; we must do this
2N/A * first since we need to look for SVR3 ".name"
2N/A * before we validate the package abbreviation
2N/A */
2N/A if (pt = strpbrk(pkg, NMBRK)) {
2N/A if (presvr4flg && (strcmp(pt, WILD3) == 0))
2N/A return (0); /* SVR3 packages have no validation */
2N/A else if ((strcmp(pt, WILD1) == 0) || (strcmp(pt, WILD2) == 0)) {
2N/A /* wildcard specification */
2N/A if (!wild)
2N/A return (1);
2N/A } else {
2N/A count = 0;
2N/A while (*++pt) {
2N/A count++;
2N/A if (!isalpha((unsigned char)*pt) &&
2N/A !isdigit((unsigned char)*pt) &&
2N/A !strpbrk(pt, "-+"))
2N/A return (-1);
2N/A }
2N/A if (!count || (count > 4))
2N/A return (-1);
2N/A }
2N/A }
2N/A
2N/A /* check for valid package name */
2N/A count = 0;
2N/A if (!isalnum((unsigned char)*pkg) ||
2N/A (!presvr4flg && !isalpha((unsigned char)*pkg)))
2N/A return (-1);
2N/A while (*pkg && !strchr(NMBRK, *pkg)) {
2N/A if (!isalnum((unsigned char)*pkg) && !strpbrk(pkg, "-+"))
2N/A return (-1);
2N/A count++, pkg++;
2N/A }
2N/A
2N/A /* Check for ABI package name length */
2N/A if (get_ABI_namelngth() == 1) {
2N/A if (count > ABI_NAMELNGTH)
2N/A return (-1);
2N/A } else if (count > NON_ABI_NAMELNGTH)
2N/A return (-1);
2N/A
2N/A return (0); /* pkg is valid */
2N/A}
2N/A
2N/A/* presvr4flg - check for pre-svr4 package names also ? */
2N/Aint
2N/Apkgnmchk(char *pkg, char *spec, int presvr4flg)
2N/A{
2N/A /* pkg is assumed to be non-NULL upon entry */
2N/A
2N/A /*
2N/A * this routine reacts based on the value passed in spec:
2N/A * NULL pkg must be valid and may be a wildcard spec
2N/A * "all" pkg must be valid and must be an instance
2N/A * "x.*" pkg must be valid and must be an instance of "x"
2N/A * "x*" pkg must be valid and must be an instance of "x"
2N/A */
2N/A
2N/A if (valname(pkg, ((spec == NULL) ? 1 : 0), presvr4flg))
2N/A return (1); /* invalid or reserved name */
2N/A
2N/A if ((spec == NULL) || (strcmp(spec, "all") == 0))
2N/A return (0);
2N/A
2N/A while (*pkg == *spec) {
2N/A if ((strcmp(spec, WILD1) == 0) || (strcmp(spec, WILD2) == 0) ||
2N/A (strcmp(spec, WILD3) == 0))
2N/A break; /* wildcard spec, so stop right here */
2N/A else if (*pkg++ == '\0')
2N/A return (0); /* identical match */
2N/A spec++;
2N/A }
2N/A
2N/A if ((strcmp(spec, WILD1) == 0) || (strcmp(spec, WILD2) == 0) ||
2N/A (strcmp(spec, WILD3) == 0)) {
2N/A if ((pkg[0] == '\0') || (pkg[0] == '.'))
2N/A return (0);
2N/A }
2N/A if ((spec[0] == '\0') && (strcmp(pkg, WILD3) == 0))
2N/A return (0); /* compare pkg.name to pkg */
2N/A return (1);
2N/A}
2N/A
2N/Avoid
2N/Aset_ABI_namelngth(void)
2N/A{
2N/A abi_namelngth = 1;
2N/A}
2N/A
2N/Aint
2N/Aget_ABI_namelngth(void)
2N/A{
2N/A return (abi_namelngth);
2N/A}