/*
* 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 (c) 1994 by Sun Microsystems, Inc.
*/
/*
* Copyright 1991, 1992 by Mortice Kern Systems Inc. All rights reserved.
*
* Standards Conformance :
*
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* Original ident string for reference
* ident "$Id: pathchk.c,v 1.29 1994/05/24 15:51:19 mark Exp $"
*/
#include <locale.h>
#include <libintl.h>
#include <limits.h>
#include <fcntl.h> /* for creat() prototype */
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <unistd.h>
#include <stdlib.h>
/*
* These are the characters in the portable filename character set defined
* in POSIX P1003.2.
*/
static char portfsset[] = \
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789._-";
#ifndef M_FSDELIM
#endif
pathconf(\"%s\", %s) returns '%s'. Using %s = %d\n";
static int checkpathname(char *, int);
static void usage(void);
/*
* mainline for pathchk
*/
int
{
int c;
int errors;
int pflag = 0;
#if !defined(TEXT_DOMAIN)
#endif
(void) textdomain(TEXT_DOMAIN);
switch (c) {
case 'p':
pflag = 1;
break;
case 'w':
/* turn off warning messages */
printWarnings = 0;
break;
default:
usage();
}
}
if (*argv == 0) {
usage();
/* NOTREACHED */
}
errors = 0;
while (*argv) {
argv += 1;
}
return (errors);
}
/*
* checkPathConf(const char *, int, long *)
*
* Calls pathconf(), and returns 1 if pathconf failed, zero
* otherwise. If pathconf() succeeded, then *valp contains the
* value returned
*/
static int
{
errno = 0;
/*
* pathconf() is not supported on some mounted filesystems
* (e.g NFS mounts) and pathconf() is known to fail.
* So, we print a warning and use the POSIX default values.
*/
if (type == _PC_PATH_MAX)
*valp = _POSIX_PATH_MAX;
else
*valp = _POSIX_NAME_MAX;
if (printWarnings) {
*valp);
}
}
}
{\
if (pflag) {\
return (1);\
}\
}
/*
* checkpathname(char *pname)
* pathchk a single pathname.
*/
int
{
int checkStat;
long nameMax;
long pathMax;
char *scomp;
char *ecomp;
register char *p;
p = path;
checkStat = 1;
/*
* Get the initial NAME_MAX and PATH_MAX values
*/
if (M_FSDELIM(*p)) {
buf[0] = *p;
} else {
/*
* This is a relative pathname, initial values
* are relative to the current directory
*/
UPDATE_LIMITS(".");
}
/*
* Check to make sure that the pathname doesn't exceed the
* current PATH_MAX
*/
return (1);
}
/*
* Now spin around checking all the prefixes of
* the pathname, until we hit the end of the
* argument
*/
while (*p != '\0') {
/*
* Find the beginning of the next
* component. Assume that
* M_FSDELIM('\0') == 0
*/
while (M_FSDELIM(*p))
p += 1;
if (*p == '\0') {
/*
* There were trailing fsdelim chars on
* the path provided, so we were
* finished, we just didn't know it.
*/
return (0);
}
scomp = p;
/*
* Find the end of the current component
* and check for valid characters in the component
*/
while (*p != '\0' && !M_FSDELIM(*p)) {
/*
* for pflag: check for PFCS characters
* otherwise assume all characters are valid
*/
if (isprint(*p)) {
} else {
}
return (1);
}
p += 1;
}
ecomp = p;
/*
* Make sure that this component does not exceed
* NAME_MAX in the current prefix directory
*/
return (1);
/*
* Perform the extra checks that
* are required when not just
* checking for portability.
*/
char fsdelim;
*ecomp = '\0';
/*
* We error out if an
* intermediate component
* is a file, when we
* were expecting a
* directory, or it is an
* unsearchable directory.
*/
path);
return (1);
checkStat = 0;
}
/*
* If the current prefix is a
* directory, then we need to
* update the limits for NAME_MAX
* for the next component and the suffix.
*/
&nameMax)) {
return (1);
}
}
/*
* restore the fsdelim char that we
* stomped to produce a prefix.
*/
} /* if (we need to stat the path) */
} /* while (more of this path to check) */
/*
* We successfully traversed the whole pathname
*/
return (0);
}
void
usage()
{
exit(2);
}