docmds.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 1996-2003 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <locale.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <search.h>
#include <dirent.h>
#include <fnmatch.h>
#include "rules.h"
extern char *mstrdup(const char *);
/*
* The do_base_dir() function is called when a BASE command is encountered
* in the input directives or end-of-file is reach on the input directive
* file. This function causes the commands associated with the previous
* BASE command to be executed. for example,
*
* BASE a/b/c
* LIST ...
* IGNORE ...
* BASE d/e/f (this command will cause do_base_dir() to be called for
* base directory a/b/c)
*
* Input arguments:
* dirpath - the BASE directory being operated on
* incld_lst - A list of strings to be matched obtained from the
* LIST commands associated with the BASE directory.
* excld_lst - A list of strings to be matched obtained from the
* IGNORE commands associated with the BASE directory.
* func - A function to be called for each matched file. The
* functions allow files to be packed, unpacked,
* examined and filenames printed.
*/
void
{
int err;
int files_processed = 0;
char linkbuf[MAXPATHLEN];
int sz;
char *s;
char *mk_base_dir(char *, char *);
#ifdef DEBUG
#endif /* DEBUG */
return;
#ifdef DEBUG
printf("do_base_dir: iitem->i_str = %s iitem->i_flag = %x\n",
#endif /* DEBUG */
if (err == 0) {
gettext("cachefspack: basedir = %s"),
dirpath);
gettext(" %s - no file(s) selected\n"),
}
};
/*
* Invoke 'func' for each component of the BASE
* directory.
*/
} else {
if (sz > 0) {
if (s != (char *)0) {
func_dir_path(s, func);
}
}
}
}
#ifdef DEBUG
#endif /* DEBUG */
return;
#ifdef DEBUG
printf("do_bas sl: iitem->i_str = %s iitem->i_flag = %x\n",
#endif /* DEBUG */
if (files_processed) {
/*
* Invoke 'func' for each component of the BASE
* directory.
*/
}
#ifdef DEBUG
#endif /* DEBUG */
}
}
/*
* The do_list_item() function is called for each LIST item associated with
* a BASE directory. It does the work of descending directories and matching
* filenames.
*
* Input arguments:
* dirpath - the BASE directory being operated on
* pat - The argument from the LIST command to match
* flags - Flags which affect how patterns are matched:
* beginning of the pattern to match.
* LF_REGEX - Means match the pattern as a regular expression.
* Otherwise, an exact match of characters is required.
* excld_lst - A list of strings to be matched obtained from the
* IGNORE commands associated with the BASE directory.
* func - A function to be called for each matched file. The
* functions allow files to be packed, unpacked,
* examined and filenames printed.
*
* Return values:
* 0 - 'func' NOT invoked for any file
* 1 - 'func' invoked for at least 1 file
*/
int
{
static char statnam[MAXPATHLEN];
static int glastpos = 0;
static int basedir_lastpos;
static int depth = 0;
static int unwind = 0;
static int do_dir = 0;
static int sl_cnt;
static int retval;
static char linkbuf[MAXPATHLEN];
int match;
int err;
int llastpos;
int excld_flag;
char *p;
int diropn;
int len;
int sz;
void process_symlk();
}
parent_dir = pdir;
if (depth == 0) {
retval = 0;
}
depth++;
diropn = 0;
goto out;
}
diropn = 1;
while (1) {
}
break;
}
/*
* If file is '..' skip it
*/
continue;
}
/*
* Apply excludes if this is not a LISTed directory
* NOTE: names from IGNORE commands are matched against the
* component name(a name between '/' marks), not the
* whole pathname.
*/
if (flags & LF_SYMLINK) {
} else {
}
if (match) {
excld_flag = 0;
if (match == 1) {
excld_flag = 1;
break;
}
}
if (excld_flag == 1) {
continue;
}
}
if (err < 0) {
gettext("cachefspack: %s - stat failed"),
statnam);
continue;
}
p = pat;
if (flags & LF_STRIP_DOTSLASH) {
p += 2;
}
}
#ifdef DEBUG
printf("directory: &statnam[basedir_lastpos] = %s\n",
#endif /* DEBUG */
match =
p);
} else {
match =
p) == 0);
}
if (match) {
/*
* Don't descend '.' directory
* but match it
*/
} else {
}
}
retval = 1;
goto out;
}
}
continue;
}
/*
* Don't descend '.' directory
*/
}
if (unwind) {
goto out;
}
continue;
}
if (flags & LF_SYMLINK)
continue;
#ifdef DEBUG
printf("sym link : &statnam[basedir_lastpos] = %s\n",
#endif /* DEBUG */
/*
* Symbolic link was explicitly specified or matches a
* regular expression in a LIST item. Thus we follow
* the link. Otherwise, just call 'func' for the link
* name.
*/
#ifdef DEBUG
#endif /* DEBUG */
match =
p);
} else {
match =
p) == 0);
}
#ifdef DEBUG
#endif /* DEBUG */
if (match) {
}
retval = 1;
#ifdef DEBUG
#endif /* DEBUG */
if (sz < 0) {
continue;
}
goto out;
}
}
}
}
retval = 1;
depth);
#ifdef DEBUG
#endif /* DEBUG */
if (sz < 0) {
continue;
}
goto out;
}
}
continue;
}
/*
* File must be a regular file -
* Does it match the specified pattern?
*/
#ifdef DEBUG
printf("reg file : &statnam[basedir_lastpos] = %s p = %s\n",
&statnam[basedir_lastpos], p);
#endif /* DEBUG */
} else {
}
if (!match) {
continue;
}
}
retval = 1;
/*
* If the file is an executable, check to see if shared
* libraries need to be packed.
*/
}
goto out;
}
}
out:
depth--;
if (depth == 0) {
unwind = 0;
}
if (do_dir) {
do_dir--;
#ifdef DEBUG
printf("out: call func\n");
#endif /* DEBUG */
do_dir = 0;
}
}
if (diropn)
return (retval);
}
/*
* Count all the '/' characters in the string except for those
* in the first character position and last character position
* of the string.
*/
int
{
char *p = str;
int len;
int i;
int count = 0;
#ifdef DEBUG
#endif /* DEBUG */
/*
* NOTE //a, /a and ./a are the same
*/
if (*p == '.')
p++;
while (*p == '/')
p++;
for (i = 0; i < len; i++) {
if (*p == '/') {
count++;
i--;
while (*p == '/') {
p++;
i++;
}
} else {
p++;
}
}
#ifdef DEBUG
#endif /* DEBUG */
return (count);
}
/*
* For each directory in the path name, call 'func'.
*/
int
{
char *dnam;
char *fnam;
char *pathtmp;
char *get_fname(char *);
char *get_dirname(char *);
#ifdef DEBUG
#endif /* DEBUG */
if (fnam != (char *)0) {
continue;
}
}
#ifdef DEBUG
if (fnam != (char *)0) {
}
printf("func_dir_path: dnam = %s pathtmp = %s\n",
#endif /* DEBUG */
/*
* If hash item data is 0, item has not been packed.
* If hash item data is 1, item has been packed.
*/
#ifdef DEBUG
printf("func_dir_path: key = %s hitemp->data = %x\n",
#endif /* DEBUG */
break;
} else {
gettext("cachefspack: hash table full\n"));
}
}
#ifdef DEBUG
#endif /* DEBUG */
return (-1);
}
} else {
}
}
return (0);
}
void
{
char *l;
int len;
/*
* if the link has a relative pathname, append the name to
* current path.
*/
if (*lkpath != '/') {
lkpath);
return;
}
l = relpath;
} else {
l = lkpath;
}
#ifdef DEBUG
printf("process_symlk: l = %s\n", l);
#endif /* DEBUG */
perror(" ");
return;
}
}
func_dir_path(l, func);
}
}
{
char *wild;
#ifdef DEBUG
#endif /* DEBUG */
/*
* if patterns are NOT being matched as regular expressions
* we can have at most 1 match. We got it so quit.
*/
#ifdef DEBUG
printf("discont_srch: ! LF_REGEX\n");
#endif /* DEBUG */
return (1);
}
/*
* if the pattern does not contain wildcard characters and
* we have found a match we are done.
*/
#ifdef DEBUG
#endif /* DEBUG */
return (1);
}
return (0);
}
#ifdef DEBUG
{
while (p != (struct item *)0) {
p = p->i_next;
}
}
#endif /* DEBUG */