Intial commit

This commit is contained in:
Mario Fetka 2024-05-27 16:13:40 +02:00
parent f8dc12b10a
commit d71d446104
2495 changed files with 539746 additions and 0 deletions

1
archie/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
Makefile

89
archie/Makefile.in Executable file
View File

@ -0,0 +1,89 @@
#
# The makefile you're looking at contains rules that operate on the
# tree as a whole. Therefore, it doesn't need to be included in any
# other make files.
#
help:
@echo ""
@echo "Possible targets are: all all_clean all_depend all_newsys all_dist"
@echo ""
include $(ARCHIE_ROOT)/Makefile.pre
# Distribution directory
DISTDIR = $(DISTDIR)
# Redefine CC so make depend will work at this level, too.
CC = :
# Toast VPATH to avoid confusing `make dist' under GNU make.
VPATH =
#
# Recursively build each Archie module.
#
all:
for dir in $(SING_LEVEL_MODULES) ; do \
(cd $$dir/$(SYSTYPE) && $(MAKE) ) ; \
done
for dir in $(MULTI_LEVEL_MODULES) ; do \
(cd $$dir && $(MAKE) ) ; \
done
#
# Recursively clean each Archie module.
#
all_clean:
for dir in $(SING_LEVEL_MODULES) ; do \
(cd $$dir/$(SYSTYPE) && $(MAKE) clean) ; \
done
for dir in $(MULTI_LEVEL_MODULES) ; do \
(cd $$dir && $(MAKE) clean) ; \
done
for dir in $(GEN_MODULES) ; do \
(cd $$dir && $(MAKE) clean) ; \
done
#
# Recursively `depend' each module.
#
all_depend:
set -u ; find $(ARCHIE_ROOT) -name Makefile.in -print | sed 's/\(.*\)\.in/cp \1.in \1/' | sh
for dir in $(SING_LEVEL_MODULES) ; do \
(cd $$dir/$(SYSTYPE) && $(MAKE) depend) ; \
done
for dir in $(MULTI_LEVEL_MODULES) ; do \
(cd $$dir && $(MAKE) depend) ; \
done
for dir in $(GEN_MODULES) ; do \
(cd $$dir && $(MAKE) depend) ; \
done
all_newsys:
for dir in $(SING_LEVEL_MODULES) ; do \
(cd $$dir && $(MAKE) -f $(ARCHIE_ROOT)/Makefile.in newsys) ; \
done
for dir in $(MULTI_LEVEL_MODULES) ; do \
(cd $$dir && $(MAKE) -f Makefile.in indirect_newsys) ; \
done
#
# Recursively create distribution for each module.
#
all_dist:
for dir in $(BIN_SING_LEVEL_MODULES) ; do \
(cd $$dir/$(SYSTYPE) && $(MAKE) dist) ; \
done
for dir in $(MULTI_LEVEL_MODULES) ; do \
(cd $$dir && $(MAKE) all_dist) ; \
done
include $(ARCHIE_ROOT)/Makefile.post
# DO NOT DELETE THIS LINE -- make depend depends on it

48
archie/Makefile.multi Executable file
View File

@ -0,0 +1,48 @@
#
# This makefile is included by the makefiles in the directories
# listed in MULTI_LEVEL_MODULES.
#
#
# Recursively do all the directories. The variable DIRS must
# contain the list of subdirectories in which we must do further
# work.
#
all:
for dir in $(DIRS) ; do \
(cd $$dir/$(SYSTYPE) && $(MAKE)) ; \
done
#
# Recursively clean each directory module.
#
all_clean clean:
for dir in $(DIRS) ; do \
(cd $$dir/$(SYSTYPE) && $(MAKE) -f Makefile.in clean) ; \
done
#
# Recursively `depend' each directory module.
#
all_depend depend:
for dir in $(DIRS) ; do \
(cd $$dir/$(SYSTYPE) && $(MAKE) -f Makefile.in depend) ; \
done
all_dist:
for dir in $(BIN_DIRS) ; do \
(cd $$dir/$(SYSTYPE) && $(MAKE) dist) ; \
done
indirect_newsys:
for dir in $(DIRS) ; do \
(cd $$dir; mkdir $(SYSTYPE); \
cp $(ARCHIE_ROOT)/tmpl/Makefile.$(SYSTYPE) $(SYSTYPE)/Makefile.in) ; \
done
# DO NOT DELETE THIS LINE -- make depend depends on it

61
archie/Makefile.post Executable file
View File

@ -0,0 +1,61 @@
#
# Top level Makefile.post.
#
FORCE:
#
# Supply a list of rules for libraries, so we don't have to
# put them in each Makefile.post.
#
$(ANONFTP_MODULE)/lib/$(SYSTYPE)/libanonftp.a: FORCE
cd $(ANONFTP_MODULE)/lib/$(SYSTYPE) && $(MAKE) libanonftp.a
$(ARCHSEARCH_MODULE)/$(SYSTYPE)/libarchsearch.a: FORCE
cd $(ARCHSEARCH_MODULE)/$(SYSTYPE) && $(MAKE) libarchsearch.a
$(EXCHANGE_MODULE)/$(SYSTYPE)/libexchange.a: FORCE
cd $(EXCHANGE_MODULE)/$(SYSTYPE) && $(MAKE) libexchange.a
$(HOSTDB_MODULE)/$(SYSTYPE)/libhostdb.a: FORCE
cd $(HOSTDB_MODULE)/$(SYSTYPE) && $(MAKE) libhostdb.a
$(LIBARCHIE_MODULE)/$(SYSTYPE)/libarchie.a: FORCE
cd $(LIBARCHIE_MODULE)/$(SYSTYPE) && $(MAKE) libarchie.a
$(LIBPARCHIE_MODULE)/$(SYSTYPE)/libparchie.a: FORCE
cd $(LIBPARCHIE_MODULE)/$(SYSTYPE) && $(MAKE) libparchie.a
$(LIBPSARCHIE_MODULE)/$(SYSTYPE)/libpsarchie.a: FORCE
cd $(LIBPSARCHIE_MODULE)/$(SYSTYPE) && $(MAKE) libpsarchie.a
$(PATRIE_MODULE)/$(SYSTYPE)/libpatrie.a: FORCE
cd $(PATRIE_MODULE)/$(SYSTYPE) && $(MAKE) libpatrie.a
$(REGEX_MODULE)/$(SYSTYPE)/libregex.a: FORCE
cd $(REGEX_MODULE)/$(SYSTYPE) && $(MAKE) libregex.a
$(REPOSIX_MODULE)/$(SYSTYPE)/libregex.a: FORCE
cd $(REPOSIX_MODULE)/$(SYSTYPE) && $(MAKE) libregex.a
$(STARTDB_MODULE)/$(SYSTYPE)/libstartdb.a: FORCE
cd $(STARTDB_MODULE)/$(SYSTYPE) && $(MAKE) libstartdb.a
$(STRIDX_MODULE)/$(SYSTYPE)/libarchstridx.a: FORCE
cd $(STRIDX_MODULE)/$(SYSTYPE) && $(MAKE) libarchstridx.a
$(WEBINDEX_MODULE)/lib/$(SYSTYPE)/libwebindex.a: FORCE
cd $(WEBINDEX_MODULE)/lib/$(SYSTYPE) && $(MAKE) libwebindex.a
depend:
@echo Depending in `pwd`
@( echo '/^# DO NOT DELETE THIS LINE/,$$c' ; \
echo '# DO NOT DELETE THIS LINE -- make depend depends on it' ; \
echo "" ; \
(cd .. ; $(CC) $(SYS_DEPFLAG) $(DEP_FLAGS) $(SRCS)) ; \
echo . ; \
echo w ; \
echo q ) | ed -s Makefile
newsys:
mkdir $(SYSTYPE) ;\
cp $(ARCHIE_ROOT)/tmpl/Makefile.$(SYSTYPE) $(SYSTYPE)/Makefile.in
dist:
for file in $(EXES) ; do \
if [ -f $(DISTRIBUTION_MODULE)/$(SYSTYPE)/$$file ] ; then \
find $$file -newer $(DISTRIBUTION_MODULE)/$(SYSTYPE)/$$file -exec cp $$file $(DISTRIBUTION_MODULE)/$(SYSTYPE)/$$file \; ; \
else \
cp $$file $(DISTRIBUTION_MODULE)/$(SYSTYPE) ; \
fi \
done

161
archie/Makefile.pre Executable file
View File

@ -0,0 +1,161 @@
#
# Top level Makefile.pre.
#
#
# ARCHIE_ROOT is an environment variable pointing to root of the
# tree containing binaries and libraries for all platforms.
#
ANONFTP_MODULE = $(ARCHIE_ROOT)/anonftp
ARCHSEARCH_MODULE = $(ARCHIE_ROOT)/lib/archsearch
CLIENT_MODULE = $(ARCHIE_ROOT)/clients
CONTROL_MODULE = $(ARCHIE_ROOT)/control
DOC_MODULE = $(ARCHIE_ROOT)/doc
EXCHANGE_MODULE = $(ARCHIE_ROOT)/exchange
HOSTDB_MODULE = $(ARCHIE_ROOT)/lib/hostdb
INCLUDE_MODULE = $(ARCHIE_ROOT)/include
LESS_MODULE = $(ARCHIE_ROOT)/less
LIBARCHIE_MODULE = $(ARCHIE_ROOT)/lib/libarchie
LIBPARCHIE_MODULE = $(ARCHIE_ROOT)/lib/libparchie
LIBPSARCHIE_MODULE = $(ARCHIE_ROOT)/lib/libpsarchie
PATRIE_MODULE = $(ARCHIE_ROOT)/lib/patrie
PPC_MODULE = $(ARCHIE_ROOT)/ppc
REGEX_MODULE = $(ARCHIE_ROOT)/lib/regex
REPOSIX_MODULE = $(ARCHIE_ROOT)/lib/reposix
STARTDB_MODULE = $(ARCHIE_ROOT)/lib/startdb
STRIDX_MODULE = $(ARCHIE_ROOT)/lib/archstridx
TOOLS_MODULE = $(ARCHIE_ROOT)/tools
WEBINDEX_MODULE = $(ARCHIE_ROOT)/webindex
DOC_MODULE = $(ARCHIE_ROOT)/doc
DISTRIBUTION_MODULE = $(ARCHIE_ROOT)/dist
BIN_SING_LEVEL_MODULES = \
$(LESS_MODULE) \
$(CONTROL_MODULE) \
$(EXCHANGE_MODULE) \
$(TOOLS_MODULE)
BIN_MULTI_LEVEL_MODULES = \
$(CLIENT_MODULE) \
$(PPC_MODULE)
LIB_SING_LEVEL_MODULES = \
$(ARCHSEARCH_MODULE) \
$(HOSTDB_MODULE) \
$(LIBARCHIE_MODULE) \
$(LIBPARCHIE_MODULE) \
$(LIBPSARCHIE_MODULE) \
$(PATRIE_MODULE) \
$(REGEX_MODULE) \
$(REPOSIX_MODULE) \
$(STARTDB_MODULE) \
$(STRIDX_MODULE)
LIB_MULTI_LEVEL_MODULES = \
$(ANONFTP_MODULE) \
$(WEBINDEX_MODULE)
#
# The modules are grouped into three classes, single level, multi-level and
# generic. Single level modules are directories, containing source code that
# compiles to object files, immediately below the top level. Multi-level
# modules are similar, but they are subdirectories of directories at the top
# level. Generic modules are directories containing files that don't produce
# object files.
#
SING_LEVEL_MODULES = \
$(LIB_SING_LEVEL_MODULES) \
$(BIN_SING_LEVEL_MODULES)
MULTI_LEVEL_MODULES = \
$(LIB_MULTI_LEVEL_MODULES) \
$(BIN_MULTI_LEVEL_MODULES)
#
# GEN_MODULES is the list of modules that are system independent.
#
GEN_MODULES = \
$(DOC_MODULE) \
$(INCLUDE_MODULE)
#
# The following variables may be used to define options common
# to a particular module. They should be used within the make
# files in the various module directories.
#
# MOD_CFLAGS -- Compiler options for a particular module.
# MOD_DEBUG -- Debugging options for a particular module.
# MOD_DEFS -- Defines for a particular module.
# MOD_INCS -- Include files depending on the particular module.
# MOD_LIBS -- Libraries required for the particular module.
# MOD_OPT -- Optimization options for a particular module.
# MOD_WARN -- Warning options for a particular module.
#
#
# The following variables may be used to define options particular
# to a specific system (machine or architecture). They should be
# used within the make files in the various system directories.
#
# SYS_CFLAGS -- Compiler options for a particular system.
# SYS_DEBUG -- Debugging options for a particular system.
# SYS_DEFS -- Defines for a particular system.
# SYS_DEPFLAG -- Compiler options used to generate dependencies.
# SYS_INCS -- Include files depending on the particular system.
# SYS_LIBS -- Libraries required for the particular system.
# SYS_OPT -- Optimization options for a particular system.
# SYS_WARN -- Warning options for a particular system.
#
CC = gcc
#
# Note that MOD_LIBS and SYS_LIBS aren't included in the CFLAGS
# macro. Since they must appear after the .o files these two
# flags must be included in the build commands of the module
# Makefile.post file.
#
CFLAGS = $(MOD_CFLAGS) $(SYS_CFLAGS) \
$(MOD_DEBUG) $(SYS_DEBUG) \
$(MOD_WARN) $(SYS_WARN) \
$(MOD_OPT) $(SYS_OPT) \
$(MOD_DEFS) $(SYS_DEFS) \
$(MOD_INCS) $(SYS_INCS)
#
# A special case: the flag to cause the compiler to generate
# include file dependencies. This may vary from system to
# system. Override this from within the system level make
# file.
#
SYS_DEPFLAG = -M
#
# Pass these flags to the compiler when generating
# dependencies. This macro is just for convenience.
#
DEP_FLAGS = $(MOD_CFLAGS) $(SYS_CFLAGS) \
$(MOD_DEFS) $(SYS_DEFS) \
$(MOD_INCS) $(SYS_INCS)
#
# Auxilliary programs.
#
AR = gar
LD = ld
RANLIB = granlib
SENTINEL = memadvise
#
# VPATH gives make [%] a set of directories to search for the
# dependencies of the targets. In the case of .o files this
# would tell it where to look for the corresponding source files.
#
# [%] Well, any make that understands it (e.g. GNU make). Not
# all do...
#
VPATH = ..

943
archie/access/ar_search.c Normal file
View File

@ -0,0 +1,943 @@
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <memory.h>
#include <unistd.h>
#include <string.h>
#include "typedef.h"
#include "strings_index.h"
#ifdef OLD_FILES
# include "old-site_file.h"
# include "old-host_db.h"
#else
# include "site_file.h"
# include "host_db.h"
#endif
#include "plog.h"
#include "ar_search.h"
#include "db_ops.h"
#include "error.h"
#include "files.h"
#include "archie_strings.h"
#include "archie_dbm.h"
#include "times.h"
static struct match_cache *mcache = NULL;
static int cachecount = 0;
extern char hostname[];
extern char hostwport[];
#ifdef eric
char trash[10000];
#endif /* eric */
int search_files_db(strings, strings_idx, strings_hash, domaindb, hostdb, hostaux_db, hostbyaddr, search_req, vdir)
file_info_t *strings;
file_info_t *strings_idx;
file_info_t *strings_hash;
file_info_t *domaindb;
file_info_t *hostdb;
file_info_t *hostaux_db;
file_info_t *hostbyaddr;
search_req_t *search_req;
VDIR vdir;
{
VLINK curr_link;
char **path_name=NULL;
char **restricts=NULL;
char *chostname = (char*) NULL;
hostname_t primary_hostname;
char fullpath[MAX_PATH_LEN];
char tmp_str[MAX_PATH_LEN];
char **tmp_ptr=NULL;
char *tmp_ptr2=NULL;
domain_t domain_list[MAX_NO_DOMAINS];
file_info_t *site_file = create_finfo();
full_site_entry_t *site_ptr=NULL;
hostdb_aux_t hostaux_rec;
hostdb_t hostdb_rec;
index_t *index_list=NULL;
int count;
int domain_count;
int linkcount;
int this_host = 1;
int total;
int slen;
ip_addr_t old_addr = 0;
ip_addr_t new_addr;
site_entry_ptr_t site_entry;
strings_idx_t *s_index=NULL;
/* TESTING */
search_req -> max_uniq_hits = search_req -> max_filename_hits;
search_req -> curr_type = search_req -> orig_type;
if(search_req -> search_str[0] == '\0')
return(PRARCH_SUCCESS);
if(vdir->links) {
plog(L_DIR_ERR, NULL, NULL, "search_files_db handed non empty dir",0);
return(PRARCH_BAD_ARG);
}
if((search_req -> orig_type == S_FULL_REGEX)
|| (search_req -> orig_type == S_E_FULL_REGEX)
|| (search_req -> orig_type == S_X_REGEX)
|| (search_req -> orig_type == S_E_X_REGEX)){
/* Regular expression search begins with ".*", strip it*/
if((slen = strlen(search_req -> search_str)) >= 2){
if(strncmp(search_req -> search_str, ".*", 2) == 0){
search_string_t tmp_srch;
strcpy(tmp_srch, search_req -> search_str + 2);
strcpy(search_req -> search_str, tmp_srch);
if(search_req -> search_str[0] == '\0')
return(PRARCH_SUCCESS);
}
/* Regular expression search ends with ".*", strip it*/
if(strcmp(search_req -> search_str + slen - 2, ".*") == 0){
search_string_t tmp_srch;
strncpy(tmp_srch, search_req -> search_str, slen - 2);
tmp_srch[slen - 2] = '\0';
strcpy(search_req -> search_str, tmp_srch);
if(search_req -> search_str[0] == '\0')
return(PRARCH_SUCCESS);
}
}
}
/* See if we can use a less expensive search method */
if((search_req -> orig_type == S_FULL_REGEX) && (strpbrk(search_req -> search_str,"\\^$.,[]<>*+?|(){}/") == NULL)) {
search_req -> curr_type = S_SUB_CASE_STR;
}
else {
if((search_req -> orig_type == S_E_FULL_REGEX) && (strpbrk(search_req -> search_str,"\\^$.,[]<>*+?|(){}/") == NULL)) {
search_req -> curr_type = S_E_SUB_CASE_STR;
}
}
if((search_req -> orig_type == S_X_REGEX) && (strpbrk(search_req -> search_str,"\\^$.,[]<>*+?|(){}/") == NULL)) {
search_req -> curr_type = S_SUB_KASE;
}
else if((search_req -> orig_type == S_E_X_REGEX) && (search_req -> orig_type == S_E_X_REGEX)) {
search_req -> curr_type = S_E_SUB_KASE;
}
if(check_cache(search_req,&(vdir->links)) == TRUE) {
plog(L_DB_INFO, NULL, NULL, "Responding with cached data",0);
return(PSUCCESS);
}
SET_ARCHIE_DIR(search_req -> attrib_list);
/* If they have asked for 0 max_filename_hits, then make it as much
as the server internal defaults will allow */
if(search_req -> max_filename_hits == 0)
search_req -> max_filename_hits = DEFAULT_MAX_FILE_HITS;
if((index_list = (index_t *) malloc( ((search_req -> max_filename_hits) + 1) * sizeof(index_t))) == (index_t *) NULL) {
return(PRARCH_OUT_OF_MEMORY);
}
/* If there are pathname component restrictions on the search, then
break them out here */
if( search_req -> comp_restrict )
restricts = str_sep(search_req -> comp_restrict,':');
/* Same with the domain list */
if( search_req -> domains ){
if(compile_domains(search_req -> domains, domain_list, domaindb, &domain_count) == ERROR){
plog(L_DB_INFO, NULL, NULL, "Loop in domain database detected. Aborting search",0);
return(PRARCH_BAD_DOMAINDB);
}
}
if(mmap_file(strings_idx, O_RDONLY) != A_OK) {
plog(L_DB_INFO,NULL,NULL,"Can't mmap strings_idx db??");
return(PRARCH_BAD_MMAP);
}
switch(search_req -> curr_type) {
case S_E_FULL_REGEX:
case S_E_SUB_CASE_STR:
case S_E_SUB_NCASE_STR:
case S_EXACT:
case S_E_X_REGEX:
case S_E_ZUB_NCASE:
case S_E_SUB_KASE:
if(mmap_file(strings, O_RDONLY) != A_OK) {
plog(L_DB_INFO,NULL,NULL,"Can't mmap strings db??");
return(PRARCH_BAD_MMAP);
}
if(ar_exact_match( search_req, index_list, strings_hash ) != A_OK) {
if((search_req -> curr_type == S_E_FULL_REGEX) ||
(search_req -> curr_type == S_E_X_REGEX))
goto s_full_regex;
else
if((search_req -> curr_type == S_E_SUB_CASE_STR) ||
(search_req -> curr_type == S_E_SUB_KASE))
goto s_sub_case_str;
else
if((search_req -> curr_type == S_E_SUB_NCASE_STR) ||
(search_req -> curr_type == S_E_ZUB_NCASE))
goto s_sub_ncase_str;
else
return(PRARCH_SUCCESS);
}
break;
s_full_regex:
case S_X_REGEX:
case S_FULL_REGEX:
if(mmap_file(strings, O_RDONLY) != A_OK) {
plog(L_DB_INFO,NULL,NULL,"Can't mmap strings db??");
return(PRARCH_BAD_MMAP);
}
if(ar_regex_match( search_req, index_list, strings_idx, strings ) != A_OK) {
return(PRARCH_DB_ERROR);
}
break;
s_sub_case_str:
s_sub_ncase_str:
case S_ZUB_NCASE:
case S_SUB_KASE:
case S_SUB_CASE_STR:
case S_SUB_NCASE_STR:
if(mmap_file_private(strings, O_RDWR) != A_OK) {
return(PRARCH_BAD_MMAP);
}
if(ar_sub_match(search_req, index_list, strings_idx, strings) != A_OK){
return PRARCH_BAD_ARG ; /* BUG: fix later */
}
break;
default:
break;
}
/* Have list of indices which might point to what you want */
for(count = 0, total = 0; index_list[count] != -1; count++){
s_index = ((strings_idx_t *) strings_idx -> ptr) + index_list[count];
if(s_index -> index.site_addr == STRING_NOT_ACTIVE) /* Inactive string */
continue;
switch(search_req -> curr_type){
case S_E_X_REGEX:
case S_X_REGEX:
case S_E_SUB_KASE:
case S_SUB_KASE:
case S_E_ZUB_NCASE:
case S_ZUB_NCASE:
curr_link = (VLINK) vlalloc();
if(curr_link){
curr_link -> name = stcopy(strings -> ptr + s_index -> strings_offset, curr_link -> name);
curr_link -> type = stcopy("DIRECTORY");
curr_link -> linktype = 'L';
#if 0
if(gethostname(tmp_str, sizeof(tmp_str)) == -1){
plog(L_DB_INFO, NULL, NULL, "Can't get local hostname");
return(PRARCH_NO_HOSTNAME);
}
curr_link -> host = stcopy(tmp_str);
#else
curr_link -> host = stcopy(hostname);
#endif
sprintf(tmp_str,"ARCHIE/MATCH(%d,0,=)/%s",search_req -> max_uniq_hits, curr_link -> name);
curr_link -> filename = stcopy(tmp_str);
vl_insert(curr_link, vdir, VLI_NOSORT);
continue;
}
else{
plog(L_DB_INFO, NULL, NULL, "Can't allocate link!",0);
return(PRARCH_OUT_OF_MEMORY);
}
break;
default:
break;
}
site_entry = s_index -> index;
new_addr = site_entry.site_addr;
for(linkcount = 0;
(site_entry.site_addr != END_OF_CHAIN) && (linkcount != search_req -> max_uniq_hits);
linkcount++){
if(old_addr != new_addr) {
chostname = (char *) NULL;
this_host = 1;
if(site_file -> ptr != (char *) NULL) {
munmap_file(site_file);
close_file(site_file);
}
strcpy(site_file -> filename, files_db_filename( inet_ntoa( ipaddr_to_inet(site_entry.site_addr))));
if(open_file(site_file, O_RDONLY) != A_OK) {
plog(L_DB_INFO, NULL, NULL, "Can't open site file %s",inet_ntoa( ipaddr_to_inet(site_entry.site_addr)),0);
break;
}
if(mmap_file( site_file, O_RDONLY) != A_OK) {
plog(L_DB_INFO, NULL, NULL, "Can't mmap site file %s", inet_ntoa( ipaddr_to_inet(site_entry.site_addr)),0);
break;
}
memset(&hostdb_rec, '\0', sizeof(hostdb_t));
memset(&hostaux_rec, '\0', sizeof(hostdb_aux_t));
old_addr = new_addr;
}
/*
* For S_EXACT An orig_offset which is non zero means skip
* orig_offset links before continuing with processing
*/
if((search_req -> curr_type == S_EXACT) && (search_req -> orig_offset != 0))
if(linkcount != search_req -> orig_offset)
goto next_one;
if(search_req -> domains){
if(!this_host)
goto next_one;
else{
if(!chostname)
chostname = get_preferred_name(site_entry.site_addr, primary_hostname, hostdb, hostbyaddr);
if(find_in_domains(chostname, domain_list, domain_count) == 0){
this_host = 0;
goto next_one;
}
}
}
site_ptr = (full_site_entry_t *) (site_file -> ptr) + site_entry.recno;
path_name = dyna_find_ancestors((full_site_entry_t *) site_file -> ptr, site_ptr, strings);
if(search_req -> comp_restrict) {
if((path_name[0] == '\0') || (check_comp_restrict(restricts, path_name) != A_OK)){
free_opts(path_name);
goto next_one;
}
}
if(!chostname)
chostname = get_preferred_name(site_entry.site_addr, primary_hostname, hostdb, hostbyaddr);
/* Now allocate and set up the link */
curr_link = (VLINK) vlalloc();
if(!curr_link){
plog(L_DB_INFO, NULL, NULL, "Can't allocate link");
return(PRARCH_OUT_OF_MEMORY);
}
if( CSE_IS_DIR(site_ptr -> core )){
/*
* It's a directory - we should check to see if the site is
* running prospero, and if so return a pointer to the actual
* directory. If it isn't then we return a real pointer to a
* pseudo-directory maintained by this archie server.
*/
curr_link ->type = stcopy("DIRECTORY");
}
else {
/*
* It's a file - we should check to see if the site is running
* prospero, and if so return a pointer to the real file. If it
* isn't, then we generate an external link
*/
curr_link -> type = stcopy("EXTERNAL(AFTP,BINARY)");
UNSET_ARCHIE_DIR(search_req -> attrib_list);
}
if(GET_ARCHIE_DIR(search_req -> attrib_list))
curr_link -> host = stcopy(hostwport);
else
curr_link -> host = stcopy(chostname);
/* Get the the last component of name */
curr_link -> name = stcopy((strings -> ptr) + (site_ptr -> str_ind));
/* Set up the full path name */
tmp_str[0] = '\0';
for(tmp_ptr = path_name; *tmp_ptr != (char *) NULL; tmp_ptr++);
for(tmp_ptr2 = tmp_str, --tmp_ptr; tmp_ptr >= path_name; tmp_ptr--){
sprintf(tmp_ptr2,"/%s", *tmp_ptr);
tmp_ptr2 += strlen(*tmp_ptr) + 1;
}
/* if(*tmp_ptr != (char *) NULL)
sprintf(tmp_ptr2,"%s", *tmp_ptr); */
if(GET_ARCHIE_DIR(search_req -> attrib_list)) {
if(tmp_str[0] == '\0')
sprintf(fullpath,"ARCHIE/HOST/%s/%s%s", chostname, tmp_str, curr_link -> name);
else
sprintf(fullpath,"ARCHIE/HOST/%s%s/%s", chostname, tmp_str, curr_link -> name);
}
else {
sprintf(fullpath,"%s/%s",tmp_str, curr_link -> name);
}
curr_link -> filename = stcopy(fullpath);
/* Subcomponents look like pointers into mmapped stringsdb */
if(path_name)
free(path_name);
if(hostdb_rec.primary_hostname[0] == '\0'){
if(get_dbm_entry(primary_hostname, strlen(primary_hostname) + 1, &hostdb_rec, hostdb) == ERROR)
continue;
}
if(hostaux_rec.access_methods[0] == '\0'){
sprintf(tmp_str,"%s.%s", primary_hostname, ANONFTP_DB_NAME);
if(get_dbm_entry(tmp_str, strlen(tmp_str) + 1, &hostaux_rec, hostaux_db) == ERROR)
continue;
if(hostaux_rec.current_status != ACTIVE)
continue;
}
/* Do each attribute in turn */
if(GET_AR_H_IP_ADDR(search_req -> attrib_list)){
add_attribute(curr_link,NAME_AR_H_IP_ADDR,"ASCII", inet_ntoa(ipaddr_to_inet(new_addr)));
}
if(GET_AR_H_OS_TYPE(search_req -> attrib_list)){
char *ost;
switch(hostdb_rec.os_type){
case UNIX_BSD:
ost = OS_TYPE_UNIX_BSD;
break;
case VMS_STD:
ost = OS_TYPE_VMS_STD;
break;
default:
ost = "Unknown";
break;
}
add_attribute(curr_link, NAME_AR_H_OS_TYPE, "ASCII",ost);
}
if(GET_AR_H_TIMEZ(search_req -> attrib_list)){
sprintf(tmp_str,"%+d", hostdb_rec.timezone);
add_attribute(curr_link, NAME_AR_H_TIMEZ, "ASCII", tmp_str);
}
if(GET_AUTHORITY(search_req -> attrib_list)){
add_attribute(curr_link, NAME_AUTHORITY, "ASCII", hostaux_rec.source_archie_hostname);
}
if(GET_LK_LAST_MOD(search_req -> attrib_list)){
sprintf(tmp_str,"%sZ", cvt_from_inttime(site_ptr -> core.date));
add_attribute(curr_link, NAME_LK_LAST_MOD, "ASCII", tmp_str);
}
if(GET_AR_H_LAST_MOD(search_req -> attrib_list)){
sprintf(tmp_str,"%sZ", cvt_from_inttime(hostaux_rec.update_time));
add_attribute(curr_link, NAME_AR_H_LAST_MOD, "ASCII", tmp_str);
}
if(GET_AR_RECNO(search_req -> attrib_list)){
sprintf(tmp_str,"%d",hostaux_rec.no_recs);
add_attribute(curr_link, NAME_AR_RECNO, "ASCII", tmp_str);
}
if(GET_LINK_COUNT(search_req -> attrib_list)){
full_site_entry_t *sptr;
int no_children = 0;
if(CSE_IS_DIR(site_ptr -> core) && (site_ptr -> core.child_idx != -1)){
/* no children */
no_children++;
for(sptr = (full_site_entry_t *) site_file -> ptr + site_ptr -> core.child_idx;
((char *) sptr + sizeof(full_site_entry_t) < site_file -> ptr + site_file -> size)
&& (sptr -> core.parent_idx == (sptr + 1) -> core.parent_idx);
sptr++){
no_children++;
}
}
sprintf(tmp_str,"%d", no_children);
add_attribute(curr_link, NAME_LINK_COUNT, "ASCII", tmp_str);
}
if(GET_LINK_SIZE(search_req -> attrib_list)){
sprintf(tmp_str,"%d", site_ptr -> core.size);
add_attribute(curr_link, NAME_LINK_SIZE, "ASCII", tmp_str);
}
if(GET_NATIVE_MODES(search_req -> attrib_list)){
sprintf(tmp_str,"%d", site_ptr -> core.perms);
add_attribute(curr_link, NAME_NATIVE_MODES, "ASCII", tmp_str);
}
if(GET_LK_UNIX_MODES(search_req -> attrib_list)){
sprintf(tmp_str,"%s", unix_perms_itoa(site_ptr -> core.perms, CSE_IS_DIR(site_ptr -> core)));
add_attribute(curr_link, NAME_LK_UNIX_MODES, "ASCII", tmp_str);
}
vl_insert(curr_link, vdir, VLI_NOSORT);
next_one:
site_entry = ((full_site_entry_t *) site_file -> ptr + site_entry.recno) -> next;
new_addr = site_entry.site_addr;
}
} /* for */
/* Set curr_offset to the number of the last link */
if(search_req -> curr_type == S_EXACT)
search_req -> curr_offset = linkcount;
add_to_cache(vdir -> links, search_req);
free(index_list);
if(site_file -> ptr != (char *) NULL) {
munmap_file(site_file);
close_file(site_file);
}
if(munmap_file(strings_idx) != A_OK) {
return(PRARCH_BAD_MMAP);
}
if(munmap_file(strings) != A_OK) {
return(PRARCH_BAD_MMAP);
}
if(restricts)
free_opts(restricts);
return(PSUCCESS);
}
char **dyna_find_ancestors( site_begin, site_entry, strings)
void *site_begin;
full_site_entry_t *site_entry;
file_info_t *strings;
{
char **pathname;
int curr_path_comps;
int max_path_comps = DEF_MAX_PCOMPS;
full_site_entry_t *my_sentry;
pathname = (char **) malloc(max_path_comps * sizeof(char *));
memset(pathname, '\0', max_path_comps * sizeof(char *));
if(site_entry -> core.parent_idx == -1){
pathname[0] = (char *) NULL;
return(pathname);
}
for(curr_path_comps = 0, my_sentry = (full_site_entry_t *) site_begin + site_entry -> core.parent_idx;
my_sentry -> core.parent_idx != -1;curr_path_comps++){
pathname[curr_path_comps] = strings -> ptr + my_sentry -> str_ind;
if(curr_path_comps == max_path_comps){
char **newpath;
max_path_comps += DEF_INCR_PCOMPS;
newpath = (char **) realloc(pathname, max_path_comps * sizeof(char *));
if(!newpath){
pathname[0] = (char *) NULL;
return(pathname);
}
}
my_sentry = (full_site_entry_t *) site_begin + my_sentry -> core.parent_idx;
}
if(curr_path_comps == max_path_comps){
char **newpath;
max_path_comps += DEF_INCR_PCOMPS;
newpath = (char **) realloc(pathname, max_path_comps * sizeof(char *));
if(!newpath){
pathname[0] = (char *) NULL;
return(pathname);
}
}
pathname[curr_path_comps] = strings -> ptr + my_sentry -> str_ind;
pathname[++curr_path_comps] = (char *) NULL;
return(pathname);
}
status_t check_comp_restrict( restrict, pathname)
char **restrict;
char **pathname;
{
char **chptr;
char **mypath;
int found = FALSE;
for(chptr = restrict; (*chptr != (char *) NULL) && !found; chptr++){
for(mypath = pathname;(*mypath != (char *) NULL) && !found; mypath++){
if(strstr(*pathname, *chptr))
found = TRUE;
}
}
return( found ? A_OK : ERROR);
}
/*
* Find the site file associated with given site name
*/
int find_sitefile_in_db(site_name, sitefile, hostdb)
hostname_t site_name; /* site to be found in database */
file_info_t *sitefile; /* file info structure to be filled in */
file_info_t *hostdb;
{
AR_DNS *host_entry;
ip_addr_t **addr;
int i;
int finished = 0;
/* Get ip address of given site name, checking the local hostdb first */
if((host_entry = ar_open_dns_name(site_name, DNS_LOCAL_FIRST, hostdb)) == (struct hostent *) NULL )
return(PRARCH_SITE_NOT_FOUND);
for( addr = (ip_addr_t **) host_entry -> h_addr_list, i = 0;
addr[i] != (ip_addr_t *) NULL && !finished;
i++){
if( access( files_db_filename( inet_ntoa ( ipaddr_to_inet(*addr[i]))), F_OK) != -1)
finished = 1;
else{
error(A_SYSERR, "find_sitefile_in_db", "Error accessing site file %s", files_db_filename( inet_ntoa ( ipaddr_to_inet(*addr[i]))));
return(PRARCH_CANT_OPEN_FILE);
}
}
if( addr[i] == (ip_addr_t *) NULL )
return(PRARCH_SITE_NOT_FOUND);
strcpy( sitefile -> filename, files_db_filename( inet_ntoa ( ipaddr_to_inet(*addr[i]))));
ar_dns_close(host_entry);
return(A_OK);
}
/* Check for cached results */
int check_cache(search_req, linkpp)
search_req_t *search_req;
VLINK *linkpp;
{
char *arg;
int offset;
search_sel_t qtype;
struct match_cache *cachep = mcache;
struct match_cache *pcachep = NULL;
VLINK cur_link;
VLINK rest = NULL;
VLINK next = NULL;
int max_hits = search_req -> max_filename_hits;
int max_uniq_hits = search_req -> max_uniq_hits;
int count = max_hits * max_uniq_hits;
int archiedir = GET_ARCHIE_DIR(search_req -> attrib_list);
arg = search_req -> search_str;
qtype = search_req -> curr_type;
offset = search_req -> orig_offset;
while(cachep) {
if(((qtype == cachep->search_type)||(qtype == cachep->req_type))&&
(cachep->offset == offset) &&
/* All results are in cache - or enough to satisfy request */
((cachep->max_hits < 0) || (max_hits <= cachep->max_hits)) &&
(strcmp(cachep->arg,arg) == 0) &&
(cachep->archiedir == archiedir)) {
/* We have a match. Move to front of list */
if(pcachep) {
pcachep->next = cachep->next;
cachep->next = mcache;
mcache = cachep;
}
/* We now have to clear the expanded bits or the links */
/* returned in previous queries will not be returned */
/* We also need to truncate the list of there are more */
/* matches than requested */
cur_link = cachep->matches;
#ifdef NOTDEF /* OLD code that is not maintained, it is unnecessary */
/* but it does show how we used to handle two-dimensions */
while(cur_link) {
tmp_link = cur_link;
while(tmp_link) {
tmp_link->expanded = FALSE;
if(tmp_link == cur_link) tmp_link = tmp_link->replicas;
else tmp_link = tmp_link->next;
}
cur_link = cur_link->next;
}
#else /* One dimensional */
/* IMPORTANT: This code assumes the list is one */
/* dimensional, which is the case because we called */
/* vl_insert with the VLI_NOSORT option */
while(cur_link) {
cur_link->expanded = FALSE;
next = cur_link->next;
if(--count == 0) { /* truncate list */
rest = cur_link->next;
cur_link->next = NULL;
if(rest) rest->previous = NULL;
}
else if((next == NULL) && (rest == NULL)) {
next = cachep->more;
cur_link->next = next;
if(next) next->previous = cur_link;
cachep->more = NULL;
}
else if (next == NULL) {
cur_link->next = cachep->more;
if(cur_link->next)
cur_link->next->previous = cur_link;
cachep->more = rest;
}
cur_link = next;
}
#endif
*linkpp = cachep->matches;
return(TRUE);
}
pcachep = cachep;
cachep = cachep->next;
}
*linkpp = NULL;
return(FALSE);
}
/* Cache the response for later use */
int add_to_cache(vl, search_req)
VLINK vl;
search_req_t *search_req;
{
struct match_cache *newresults = NULL;
struct match_cache *pcachep = NULL;
if(cachecount < MATCH_CACHE_SIZE) { /* Create a new entry */
newresults = (struct match_cache *) malloc(sizeof(struct match_cache));
cachecount++;
newresults->next = mcache;
mcache = newresults;
newresults->arg = stcopy(search_req -> search_str);
newresults->max_hits = search_req -> max_filename_hits;
newresults->offset = search_req -> orig_offset;
newresults->search_type = search_req -> orig_type;
newresults->req_type = search_req -> curr_type;
newresults->archiedir = GET_ARCHIE_DIR(search_req -> attrib_list);
newresults->matches = NULL;
newresults->more = NULL;
}
else { /* Use last entry - Assumes list has at least two entries */
pcachep = mcache;
while(pcachep->next) pcachep = pcachep->next;
newresults = pcachep;
/* move to front of list */
newresults->next = mcache;
mcache = newresults;
/* Fix the last entry so we don't have a cycle */
while(pcachep->next != newresults) pcachep = pcachep->next;
pcachep->next = NULL;
/* Free the old results */
if(newresults->matches) {
newresults->matches->dontfree = FALSE;
vllfree(newresults->matches);
newresults->matches = NULL;
}
if(newresults->more) {
newresults->more->dontfree = FALSE;
vllfree(newresults->more);
newresults->more = NULL;
}
newresults->arg = stcopyr(search_req -> search_str,newresults->arg);
newresults->max_hits = search_req -> max_filename_hits;
newresults->offset = search_req -> orig_offset;
newresults->search_type = search_req -> orig_type;
newresults->req_type = search_req -> curr_type;
newresults->archiedir = GET_ARCHIE_DIR(search_req -> attrib_list);
}
/* Since we are caching the data. If there are any links, */
/* note that they should not be freed when sent back */
if(vl) vl->dontfree = TRUE;
newresults->matches = vl;
return(0);
}

345
archie/access/casesrch.c Normal file
View File

@ -0,0 +1,345 @@
/*
* This code is no longer used, but for now it's simpler to keep it around to
* avoid undefined symbols in dirsrv.
*
* - wheelan (Wed Jun 5 21:00:19 EDT 1996)
*/
double tcmp = 0.0; /* to avoid an undefined symbol */
/*
search routine generated by gen.
skip=lC, match=fwd, guard=guard, shift=md2
*/
/*
* The authors of this software are Andrew Hume and Daniel Sunday.
*
* Copyright (c) 1991 by AT&T and Daniel Sunday.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose without fee is hereby granted, provided that this entire notice
* is included in all copies of any software which is or includes a copy
* or modification of this software and in all copies of the supporting
* documentation for such software.
*
* THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR AT&T MAKE ANY
* REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY
* OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
*/
#include <stdio.h>
#include <ctype.h>
#include <memory.h>
#ifdef DOUBLE_CHECK
#include <string.h>
#endif
#include "freq.h"
#include "sd.h"
#include "srch.h"
#include "protos.h"
#ifndef NO_PROSP_CHECK
#define PROSP_CHECK_IN \
do { static ckcnt = 0; if (ckcnt++ > 1000 /*?*/) { ckcnt = 0; ardp_accept(); } } while(0)
#endif
static struct
{
int patlen;
CHARTYPE pat[MAXPAT];
CHARTYPE upat[MAXPAT];
Tab delta[256];
int loopoffset; /* patlen-1 - skip loop char */
int rarec, rareoff;
int md2;
} pat;
#ifdef DOUBLE_CHECK
extern char *prog ;
#endif
#ifdef __STDC__
extern void lowercase(char *s, int n) ;
extern void ps(char *s, char *b) ;
extern void uppercase(char *s, int n) ;
#else
extern void lowercase(/* char *s, int n */) ;
extern void ps(/* char *s, char *b */) ;
extern void uppercase(/* char *s, int n */) ;
#endif
int
prep(base, m, ignore_case)
CHARTYPE *base ;
int m ;
int ignore_case ;
{
CHARTYPE *skipc, *uskipc = 0;
register CHARTYPE *pe, *pb;
register int j, r = 0;
register Tab *d;
double tmax, fr;
int rrr, rr;
register CHARTYPE *pmd2;
pat.patlen = m;
if(m > MAXPAT)
{
return 0 ;
}
memcpy(pat.pat, base, m);
if(ignore_case)
{
memcpy(pat.upat, pat.pat, m) ;
lowercase(pat.pat, m) ;
uppercase(pat.upat, m) ;
}
skipc = 0;
if(sd[m] == 0){
for(j = m; sd[j] == 0; j--)
sd[j] = 12;
}
/*
Find the character to check in the skip loop.
*/
tmax = 2+tcmp;
for(pb = pat.pat, pe = pb+pat.patlen-1; pb <= pe; pb++){
fr = (1+tcmp*freq[*pb])/sd[pb-pat.pat];
if(tmax > fr){
tmax = fr;
r = pb-pat.pat;
}
}
pat.loopoffset = m-1-r; /* offset from _end_ of pattern */
skipc = &pat.pat[m-1-pat.loopoffset]; /* address of this character */
if(ignore_case)
{
uskipc = &pat.upat[m-1-pat.loopoffset]; /* address of this character */
}
/*
Set up the array of skip distances.
*/
d = pat.delta;
for(j = 0; j < 256; j++)
d[j] = m-pat.loopoffset;
for(pb = pat.pat, pe = pb+m-1-pat.loopoffset; pb <= pe; pb++){
d[*pb] = pe-pb; /* case */
if(ignore_case)
{ d[toupper((int)*pb)] = pe-pb ;
}
}
/*
Find the rarest character in the pattern and its offset.
*/
rrr = 0;
for(rr = 1; rr < m; rr++){
if(freq[pat.pat[rr]] < freq[pat.pat[rrr]])
rrr = rr;
}
pat.rarec = pat.pat[rrr];
pat.rareoff = rrr;
/*
Find the distance between the skip loop character and its first
reoccurance to its left.
*/
for(pmd2 = skipc-1; pmd2 >= pat.pat; pmd2--)
if (*pmd2 == *skipc || (ignore_case && *pmd2 == *uskipc)) break;
pat.md2 = skipc - pmd2; /* *pmd2 is first leftward reoccurance of *pe */
return 1 ;
}
/*
Case sensitive match.
*/
int
cs_exec(base, n, hit_list, max_hits)
CHARTYPE *base ;
int n ;
index_t *hit_list ;
int max_hits ;
{
int nmatch = 0 ;
register CHARTYPE *e, *s ;
register Tab *d0 = pat.delta ;
register k, s_offset ;
register ro, rc ;
register CHARTYPE *p, *q ;
register CHARTYPE *ep ;
register md2 = pat.md2 ;
k = pat.patlen-1-pat.loopoffset ; /* k is index of char we loop on */
s = base+k ;
e = base+n ;
memset(e, pat.pat[k], pat.patlen) ;
s_offset = -k ;
ro = pat.rareoff+s_offset ; /* offset into s corresponding to rarest */
rc = pat.rarec ; /* character of pattern. */
ep = pat.pat + pat.patlen ;
while(s < e)
{
k = d0[*s] ;
while(k)
{
k = d0[*(s += k)] ;
k = d0[*(s += k)] ;
k = d0[*(s += k)] ;
}
if(s >= e) return nmatch ;
if(s[ro] != rc) goto mismatch ; /* case */
/*
compare from beginning of pattern
*/
for(p = pat.pat, q = s+s_offset; p < ep; ) /* case */
{
if(*q++ != *p++) goto mismatch ;
}
*hit_list++ = s + s_offset - base ; /* always first character of pattern? */
if(++nmatch >= max_hits)
{
#ifdef DOUBLE_CHECK
if(strstr(s+s_offset, pat.pat) == (char *)0)
{
fprintf(stderr, "%s: cs_exec: double check failed on (\"%s\", \"%s\").\n",
prog, s+s_offset, pat.pat) ;
}
#endif
return nmatch ;
}
while(*s++) ; /* move to next string */
continue;
mismatch:
s += md2 ;
PROSP_CHECK_IN;
}
return nmatch ;
}
/*
Case insensitive match.
*/
int
ci_exec(base, n, hit_list, max_hits)
CHARTYPE *base ;
int n ;
index_t *hit_list ;
int max_hits ;
{
int nmatch = 0 ;
register CHARTYPE *e, *s ;
register Tab *d0 = pat.delta ;
register k, s_offset ;
register ro, rc, urc ;
register CHARTYPE *p, *q, *up ;
register CHARTYPE *ep ;
register md2 = pat.md2 ;
k = pat.patlen-1-pat.loopoffset ; /* k is index of char we loop on */
s = base+k ;
e = base+n ;
memset(e, pat.pat[k], pat.patlen) ;
s_offset = -k ;
ro = pat.rareoff+s_offset ; /* offset into s corresponding to rarest */
rc = pat.rarec ; /* character of pattern. */
urc = toupper((int)rc) ;
ep = pat.pat + pat.patlen ;
while(s < e)
{
k = d0[*s] ;
while(k)
{
k = d0[*(s += k)] ;
k = d0[*(s += k)] ;
k = d0[*(s += k)] ;
}
if(s >= e) return nmatch ;
if(s[ro] != rc && s[ro] != urc) goto mismatch ; /* case */
/*
compare from beginning of pattern
*/
for(p = pat.pat, up = pat.upat, q = s+s_offset; p < ep; ) /* case */
{
CHARTYPE y = *q++, z = *up++ ;
if(y != *p++ && y != z) goto mismatch ;
}
*hit_list++ = s + s_offset - base ; /* always first character of pattern? */
if(++nmatch >= max_hits)
{
return nmatch ;
}
while(*s++) ; /* move to next string */
continue ;
mismatch:
s += md2 ;
PROSP_CHECK_IN;
}
return nmatch ;
}
void
lowercase(s, n)
char *s ;
int n ;
{
while(n--)
{
*s = tolower((int)*s) ;
s++ ;
}
}
void
ps(s, b)
char *s ;
char *b ;
{
char *p = s ;
while(*p && p-- > b) ;
p++ ;
#if 0
printf("%p %p '%s'\n", (void *)p, (void *)s, p) ;
#endif
}
void
uppercase(s, n)
char *s ;
int n ;
{
while(n--)
{
*s = toupper((int)*s) ;
s++ ;
}
}

392
archie/access/list_site.c Normal file
View File

@ -0,0 +1,392 @@
#include <stdio.h>
#include <sys/types.h>
#include <sys/mman.h>
#include <memory.h>
#include <malloc.h>
#include <strings.h>
#include "typedef.h"
#include "defines.h"
#include "plog.h"
#ifdef OLD_FILES
# include "old-site_file.h"
#else
# include "site_file.h"
#endif
#include "ar_search.h"
#include "error.h"
#ifdef OLD_FILES
# include "old-host_db.h"
#else
# include "host_db.h"
#endif
#include "db_ops.h"
#include "files.h"
#include "archie_strings.h"
#include "archie_dbm.h"
#include "times.h"
int prarch_host_dir(site_name,dbname,attrib_list,dirname,vd,hostdb_finfo, hostaux_db, strings_finfo)
hostname_t site_name; /* Name of host to be searched */
char *dbname;
attrib_list_t attrib_list;
char *dirname; /* Name of directory to be listed */
VDIR vd; /* Directory to be filled in */
file_info_t *hostdb_finfo; /* File info for host database */
file_info_t *hostaux_db;
file_info_t *strings_finfo; /* File info for strings database */
{
#ifdef __STC__
extern char *re_comp(char *);
extern int re_exec(char *);
#else
extern char *re_comp();
extern int re_exec();
#endif
pathname_t basepath;
full_site_entry_t *site_rec_ptr, *site_end;
char **dirptr;
index_t parent_i;
VLINK curr_link;
int unfinished;
file_info_t *sitefile = create_finfo();
pathname_t tmp_str;
hostdb_t hostdb_rec;
ptr_check(site_name, char, "prarch_host_dir", PRARCH_BAD_ARG);
ptr_check(hostdb_finfo, file_info_t, "prarch_host_dir", PRARCH_BAD_ARG);
ptr_check(strings_finfo, file_info_t, "prarch_host_dir", PRARCH_BAD_ARG);
memset(&hostdb_rec, '\0', sizeof(hostdb_t));
if(dirname != (char *) NULL){
if(dirname[0] != '/')
strcpy(basepath, dirname);
else
strcpy(basepath, dirname + 1);
}
/* check to see if the name contains an regex character */
/* "LIST" command */
if(strpbrk(site_name,"\\^$[]<>*+?|(){}/") != NULL){
hostname_t *hostlist;
int hostcount;
hostname_t *hostptr, *host_end;
int result;
hostdb_aux_t hostaux_rec;
if(get_hostnames(hostdb_finfo, &hostlist, &hostcount, (domain_t *) NULL, 0)== ERROR){
plog(L_DB_INFO, NULL, NULL, "Can't get list of hosts in database");
return(PRARCH_DB_ERROR);
}
if(re_comp(site_name) != (char *) NULL)
return(PRARCH_BAD_REGEX);
host_end = hostlist + hostcount;
for(hostptr = hostlist; hostptr < host_end; hostptr++){
if((result = re_exec(hostptr)) == -1)
return(PRARCH_INTERN_ERR);
if(result != 1)
continue;
if(get_dbm_entry(hostptr, strlen((char *) hostptr) + 1, &hostdb_rec, hostdb_finfo) == ERROR)
continue;
if(get_hostaux_ent(hostptr, (dbname == (char *) NULL ? ANONFTP_DB_NAME : dbname), &hostaux_rec, hostaux_db) == ERROR)
continue;
if(!(curr_link = (VLINK) vlalloc())){
plog(L_DB_INFO, NULL, NULL, "Can't allocate link for HOST command");
return(PRARCH_OUT_OF_MEMORY);
}
curr_link -> host = stcopy(hostptr);
curr_link -> name = stcopy("/");
/* Do each attribute in turn */
if(GET_AR_H_IP_ADDR(attrib_list)){
add_attribute(curr_link,NAME_AR_H_IP_ADDR,"ASCII", inet_ntoa(ipaddr_to_inet(hostdb_rec.primary_ipaddr)));
}
if(GET_AR_DB_STAT(attrib_list)){
char *ost;
switch(hostaux_rec.current_status){
case ACTIVE:
ost = "Active";
break;
case NOT_SUPPORTED:
ost = "OS Not Supported";
break;
case DEL_BY_ADMIN:
ost = "Scheduled for deletion by Site Administrator";
break;
case DEL_BY_ARCHIE:
ost = "Scheduled for deletion";
break;
case INACTIVE:
ost = "Inactive";
break;
case DELETED:
ost = "Deleted from system";
break;
case DISABLED:
ost = "Disabled in system";
break;
default:
ost = "Unknown";
break;
}
add_attribute(curr_link, NAME_AR_DB_STAT, "ASCII", ost);
}
if(GET_AR_H_OS_TYPE(attrib_list)){
char *ost;
switch(hostdb_rec.os_type){
case UNIX_BSD:
ost = "BSD Unix";
break;
case VMS_STD:
ost = "VMS";
break;
default:
ost = "Unknown";
break;
}
add_attribute(curr_link, NAME_AR_H_OS_TYPE, "ASCII",ost);
}
if(GET_AR_H_TIMEZ(attrib_list)){
sprintf(tmp_str,"%+d", hostdb_rec.timezone);
add_attribute(curr_link, NAME_AR_H_TIMEZ, "ASCII", tmp_str);
}
if(GET_AUTHORITY(attrib_list)){
add_attribute(curr_link, NAME_AUTHORITY, "ASCII", hostaux_rec.source_archie_hostname);
}
if(GET_AR_H_LAST_MOD(attrib_list)){
sprintf(tmp_str,"%sZ", cvt_from_inttime(hostaux_rec.update_time));
add_attribute(curr_link, NAME_AR_H_LAST_MOD, "ASCII", tmp_str);
}
if(GET_AR_RECNO(attrib_list)){
sprintf(tmp_str,"%d",hostaux_rec.no_recs);
add_attribute(curr_link, NAME_AR_RECNO, "ASCII", tmp_str);
}
vl_insert(curr_link, vd, VLI_NOSORT);
}
if(hostlist)
free(hostlist);
return(PRARCH_SUCCESS);
}
/* "SITE" command */
/* Currently only the anonftp database is supported */
if(dbname != (char *) NULL){
if(strcasecmp(dbname, ANONFTP_DB_NAME) != 0)
return(PRARCH_SUCCESS);
}
/* Get filename of host wanted */
if(get_dbm_entry(site_name, strlen(site_name) + 1, &hostdb_rec, hostdb_finfo) == ERROR)
return(PRARCH_SITE_NOT_FOUND);
if(mmap_file(strings_finfo, O_RDONLY) == ERROR){
plog(L_DB_INFO, NULL, NULL, "Can't mmap strings file");
return(PRARCH_BAD_MMAP);
}
strcpy(sitefile -> filename, files_db_filename( inet_ntoa( ipaddr_to_inet(hostdb_rec.primary_ipaddr))));
if(open_file(sitefile, O_RDONLY) == ERROR){
plog(L_DB_INFO, NULL, NULL, "Can't open site file %s",inet_ntoa( ipaddr_to_inet(hostdb_rec.primary_ipaddr)),0);
return(PRARCH_SITE_NOT_FOUND);
}
if(mmap_file( sitefile, O_RDONLY) != A_OK){
plog(L_DB_INFO, NULL, NULL, "Can't mmap site file %s",inet_ntoa( ipaddr_to_inet(hostdb_rec.primary_ipaddr)),0);
return(ERROR);
}
site_rec_ptr = (full_site_entry_t *) sitefile -> ptr;
/* Calculate address of the end of the site file */
site_end = site_rec_ptr + (sitefile -> size / sizeof(full_site_entry_t));
/* Go through path one component at a time finding the record in the
site file corresponding to that name. Will end up with correct
record or it won't be found */
/* While there are still components in the directory name */
for(dirptr = str_sep(basepath, '/'); (*dirptr != (char *) NULL) && (*dirptr[0] != '\0'); dirptr++){
for(parent_i = site_rec_ptr -> core.parent_idx, unfinished = 1;
(site_rec_ptr -> core.parent_idx == parent_i) &&
((unfinished = strcmp( (strings_finfo -> ptr) + (site_rec_ptr -> str_ind), *dirptr)) != 0) &&
site_rec_ptr < site_end;
site_rec_ptr++);
/* Directory in path not found */
if(unfinished == 1)
return(PRARCH_DIR_NOT_FOUND);
/* Given pathname component is a directory ? */
if(!CSE_IS_DIR( site_rec_ptr -> core) )
return(PRARCH_NOT_DIRECTORY);
/* set site file pointer to desired child of current directory */
site_rec_ptr = (site_rec_ptr -> core.child_idx) + (full_site_entry_t *) sitefile -> ptr;
}
/* site_rec_ptr points to first child of desired directory
go through all children constructing VLINK of files */
for(parent_i = site_rec_ptr -> core.parent_idx;
(site_rec_ptr -> core.parent_idx == parent_i) &&
site_rec_ptr < site_end;
site_rec_ptr++){
/* Fill in VLINK structure */
/* curr_link = atoplink( site_rec_ptr, archiedir, site_name, strings_finfo, dirname,0); */
if(!(curr_link = (VLINK) vlalloc())){
plog(L_DB_INFO, NULL, NULL, "Can't allocate link");
return(PRARCH_OUT_OF_MEMORY);
}
if( CSE_IS_DIR( site_rec_ptr -> core )){
/* It's a directory - we should check to see if the site is */
/* running prospero, and if so return a pointer to the actual */
/* directory. If it isn't then we return a real pointer to */
/* a pseudo-directory maintained by this archie server. */
curr_link ->type = stcopy("DIRECTORY");
}
else {
/* It's a file - we should check to see if the site is */
/* running prospero, and if so return a pointer to the real */
/* file. If it isn't, then we generate an external link */
curr_link -> type = stcopy("EXTERNAL(AFTP,BINARY)");
}
curr_link -> name = stcopy((strings_finfo -> ptr) + (site_rec_ptr -> str_ind));
curr_link -> host = stcopy(site_name);
if((dirname != (char *) NULL) && (dirname[0] != '/')){
sprintf(tmp_str,"/%s",dirname);
curr_link -> filename = stcopy(tmp_str);
}
else
curr_link -> filename = stcopy(dirname);
if(GET_LK_LAST_MOD(attrib_list)){
sprintf(tmp_str,"%sZ", cvt_from_inttime(site_rec_ptr -> core.date));
add_attribute(curr_link, NAME_LK_LAST_MOD, "ASCII", tmp_str);
}
if(GET_LINK_SIZE(attrib_list)){
sprintf(tmp_str,"%d", site_rec_ptr -> core.size);
add_attribute(curr_link, NAME_LINK_SIZE, "ASCII", tmp_str);
}
if(GET_NATIVE_MODES(attrib_list)){
sprintf(tmp_str,"%d", site_rec_ptr -> core.perms);
add_attribute(curr_link, NAME_NATIVE_MODES, "ASCII", tmp_str);
}
/* Insert link in list */
vl_insert(curr_link,vd,VLI_NOSORT);
}/* for */
if( munmap_file( sitefile ) != A_OK )
return(PRARCH_DB_ERROR);
if( close_file( sitefile ) != A_OK)
return(PRARCH_DB_ERROR);
if(munmap_file(strings_finfo) != A_OK)
return(PRARCH_BAD_MMAP);
return(A_OK);
}

158
archie/access/match.c Normal file
View File

@ -0,0 +1,158 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#ifdef SOLARIS
#include <regexpr.h>
#endif
#include "strings_index.h"
#include "typedef.h"
#include "ar_search.h"
#include "plog.h"
status_t ar_exact_match(s_req, index_list, strings_hash )
search_req_t *s_req;
index_t *index_list;
file_info_t *strings_hash;
{
datum string_search, string_data;
string_search.dptr = s_req -> search_str;
string_search.dsize = strlen( s_req -> search_str) + 1;
string_data = dbm_fetch(strings_hash -> fp_or_dbm.dbm, string_search);
if(dbm_error(strings_hash -> fp_or_dbm.dbm))
return(ERROR);
if(string_data.dptr == (char *) NULL)
return(ERROR);
memcpy(&index_list[0], string_data.dptr, string_data.dsize);
index_list[1] = -1;
return(A_OK);
}
status_t ar_regex_match(search_req, index_list, strings_idx, strings)
search_req_t *search_req;
index_t *index_list;
file_info_t *strings_idx;
file_info_t *strings;
{
#ifndef SOLARIS
extern char* re_comp PROTO((char *));
extern int re_exec PROTO(( char *));
#endif
char *strings_idx_end;
strings_idx_t *strings_idx_rec;
int recno;
int count;
int checkcount = 0;
#ifdef SOLARIS
char *re;
#endif
#ifndef SOLARIS
if((search_req -> error_string = re_comp(search_req -> search_str)) != (char *) NULL){
return(ERROR);
}
#else
if((re = compile(search_req -> search_str, (char *) NULL, (char *) NULL)) == (char *) NULL){
search_req -> error_string = strdup("Error in regular expression");
goto thend;
}
#endif
strings_idx_rec = (strings_idx_t *) strings_idx -> ptr + search_req -> orig_offset;
strings_idx_end = strings_idx -> ptr + strings_idx -> size;
if(strings_idx_rec >= (strings_idx_t *) strings_idx_end){
search_req -> error_string = strdup("Invalid offset given. Please try again");
goto thend;
}
for(recno = 0, count=0;
((char *) strings_idx_rec < strings_idx_end) && (count != search_req -> maxmatch);
strings_idx_rec++, recno++, checkcount++){
if(strings_idx_rec -> strings_offset < 0){
plog(L_DIR_ERR, NOREQ, "Likely corrupt database. Strings index at rec %d has offset %d", recno, strings_idx_rec -> strings_offset);
continue;
}
#ifndef SOLARIS
switch(re_exec((strings -> ptr) + strings_idx_rec -> strings_offset)){
case 1: /* String matched */
index_list[count++] = recno;
break;
case 0:
break;
case -1:
search_req -> error_string = strdup("Internal error");
index_list[++count] = -1;
return(ERROR);
break;
}
#else
switch(step(((strings -> ptr) + strings_idx_rec -> strings_offset), re)){
case 0:
break;
default: /* String matched */
index_list[count++] = recno;
break;
}
#endif
if(checkcount > 1000){
ardp_accept();
checkcount = 0;
}
}
/* End of List */
index_list[count] = -1;
/* set curr_offset to zero if we fell of the end of the file otherwise
set it to current strings_idx record number */
if((char *) strings_idx_rec >= strings_idx_end)
search_req -> curr_offset = 0;
else
search_req -> curr_offset = ((char *) strings_idx_rec - strings_idx_end) / sizeof(strings_idx_t);
#ifdef SOLARIS
if(re)
free(re);
#endif
return(A_OK);
thend:
#ifdef SOLARIS
if(re)
free(re);
#endif
return(ERROR);
}

231
archie/access/prarch.c Normal file
View File

@ -0,0 +1,231 @@
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <string.h>
#include "error.h"
#include "typedef.h"
#include "prarch.h"
#include "ar_search.h"
#include "db_ops.h"
#ifdef OLD_FILES
# include "old-host_db.h"
#else
# include "host_db.h"
#endif
#include "files.h"
#include "archie_strings.h"
#include "master.h"
#include "times.h"
char *hostname = "THISHOST";
char *hostwport = "THISHOST";
char *prog ;
void main(argc,argv)
int argc;
char *argv[];
{
VLINK clink;
VLINK conflink;
VDIR_ST dir_st;
VDIR dir = &dir_st;
PATTRIB atlink;
search_req_t search_req;
file_info_t *strings_idx = create_finfo();
file_info_t *strings = create_finfo();
file_info_t *strings_hash = create_finfo();
file_info_t *domaindb = create_finfo();
file_info_t *hostdb = create_finfo();
file_info_t *hostbyaddr = create_finfo();
file_info_t *hostaux_db = create_finfo();
extern int optind; /*NOT USED*/
extern char *optarg;
char **cmdline_ptr;
int cmdline_args;
char option;
prog = tail(argv[0]) ;
search_req.orig_type = S_EXACT;
search_req.domains = (char *) NULL;
search_req.comp_restrict = (char *) NULL;
search_req.attrib_list = (attrib_list_t) 0;
cmdline_ptr = argv + 1;
cmdline_args = argc - 1;
while((option = (int) getopt(argc, argv, "scerad:t:kzxKZX")) != EOF) {
switch(option) {
case 's':
search_req.orig_type = S_SUB_NCASE_STR;
cmdline_ptr ++;
cmdline_args --;
break;
case 'c':
search_req.orig_type = S_SUB_CASE_STR;
cmdline_ptr ++;
cmdline_args --;
break;
#if 0
case 'a':
search_req.attrib_flag = FALSE;
cmdline_ptr ++;
cmdline_args --;
break;
#endif
case 'Z':
search_req.orig_type = S_ZUB_NCASE;
cmdline_ptr ++;
cmdline_args --;
break;
case 'z':
search_req.orig_type = S_E_ZUB_NCASE;
cmdline_ptr ++;
cmdline_args --;
break;
case 'X':
search_req.orig_type = S_X_REGEX;
cmdline_ptr ++;
cmdline_args --;
break;
case 'x':
search_req.orig_type = S_E_X_REGEX;
cmdline_ptr ++;
cmdline_args --;
break;
case 'K':
search_req.orig_type = S_SUB_KASE;
cmdline_ptr ++;
cmdline_args --;
break;
case 'k':
search_req.orig_type = S_E_SUB_KASE;
cmdline_ptr ++;
cmdline_args --;
break;
case 'e':
search_req.orig_type = S_EXACT;
cmdline_ptr ++;
cmdline_args --;
break;
case 'r':
search_req.orig_type = S_FULL_REGEX;
cmdline_ptr ++;
cmdline_args --;
break;
case 'd':
search_req.domains = (char *) strdup(optarg);
cmdline_ptr += 2;
cmdline_args -= 2;
break;
case 't':
search_req.comp_restrict = (char *) strdup(optarg);
cmdline_ptr += 2;
cmdline_args -= 2;
break;
}
}
vdir_init(dir);
set_master_db_dir("");
/* Do only once */
set_files_db_dir("");
if(open_files_db(strings_idx, strings, strings_hash, O_RDONLY) != A_OK) {
fprintf(stderr,"prarch: Can't open database\n");
exit(1);
}
set_host_db_dir("");
if(open_host_dbs(hostbyaddr, hostdb, domaindb, hostaux_db, O_RDONLY) != A_OK) {
fprintf(stderr,"prarch: Can't open database\n");
exit(1);
}
strcpy(search_req.search_str, *cmdline_ptr);
search_req.orig_offset = 0;
search_req.max_uniq_hits = 5;
search_req.max_filename_hits = 100;
SET_LINK_SIZE(search_req.attrib_list);
SET_LK_LAST_MOD(search_req.attrib_list);
SET_LK_UNIX_MODES(search_req.attrib_list);
#if 0
if(argc == 2) retval = search_files_db(&strings, &strings_idx, &strings_hash, &search_req,dir,0);
else retval = prarch_host(argv[1],argv[2],dir,1);
#endif
#if 0
while(1){
search_files_db(strings, strings_idx, strings_hash, domaindb, hostdb, hostaux_db, hostbyaddr, &search_req,dir);
#else
search_files_db(strings, strings_idx, strings_hash, domaindb, hostdb, hostaux_db, hostbyaddr, &search_req,dir);
#endif
clink = dir->links;
while(clink) {
conflink = clink;
while(conflink) {
printf("\n String: %s\n",conflink->name);
printf(" ObjType: %s\n",conflink->type);
printf(" LinkType: %s\n",((conflink->linktype == 'U') ? "Union" : "Standard"));
printf(" HostType: %s\n",conflink->hosttype);
printf(" Host: %s\n",conflink->host);
printf(" NameType: %s\n",conflink->nametype);
printf(" Pathname: %s\n",conflink->filename);
if(conflink->version) printf(" Version: %d\n",conflink->version);
printf(" Magic: %d\n",conflink->f_magic_no);
atlink = conflink -> lattrib;
while(atlink){
printf(" Name: %s\n Value: %s\n", atlink -> aname, atlink -> value.ascii);
atlink = atlink -> next;
}
conflink = conflink->replicas;
}
clink = clink->next;
}
#if 0
printf("###DONE");
vdir_init(dir);
}
#endif
exit(0);
}

View File

@ -0,0 +1,593 @@
#include <stdio.h>
#include <sys/types.h>
#include <string.h>
#include <ctype.h>
#define _toupper(c) ((c)-'a'+'A')
#ifdef MMAP
#include <sys/mman.h>
#endif
/* Archie definitions */
#include <defines.h>
#include <error.h>
#include "prarch.h"
#include <pfs.h>
#include <perrno.h>
#include <plog.h>
VLINK atoplink();
char *re_comp();
char *make_lcase();
int get_match_list();
extern char *strings_begin;
extern long strings_table_size;
extern DBM *fast_strings;
/* So we can adjust our cache policy based on queue length */
extern int pQlen;
static char lowertable[256] = {
'\000','\001','\002','\003','\004','\005','\006','\007',
'\010','\011','\012','\013','\014','\015','\016','\017',
'\020','\021','\022','\023','\024','\025','\026','\027',
'\030','\031','\032','\033','\034','\035','\036','\037',
' ','!','"','#','$','%','&','\'',
'(',')','*','+',',','-','.','/',
'0','1','2','3','4','5','6','7',
'8','9',':',';','<','=','>','?',
'@','a','b','c','d','e','f','g',
'h','i','j','k','l','m','n','o',
'p','q','r','s','t','u','v','w',
'x','y','z','[','\\',']','^','_',
'`','a','b','c','d','e','f','g',
'h','i','j','k','l','m','n','o',
'p','q','r','s','t','u','v','w',
'x','y','z','{','|','}','~','\177',
'\200','\201','\202','\203','\204','\205','\206','\207',
'\210','\211','\212','\213','\214','\215','\216','\217',
'\220','\221','\222','\223','\224','\225','\226','\227',
'\230','\231','\232','\233','\234','\235','\236','\237',
'\240','\241','\242','\243','\244','\245','\246','\247',
'\250','\251','\252','\253','\254','\255','\256','\257',
'\260','\261','\262','\263','\264','\265','\266','\267',
'\270','\271','\272','\273','\274','\275','\276','\277',
'\300','\301','\302','\303','\304','\305','\306','\307',
'\310','\311','\312','\313','\314','\315','\316','\317',
'\320','\321','\322','\323','\324','\325','\326','\327',
'\330','\331','\332','\333','\334','\335','\336','\337',
'\340','\341','\342','\343','\344','\345','\346','\347',
'\350','\351','\352','\353','\354','\355','\356','\357',
'\360','\361','\362','\363','\364','\365','\366','\367',
'\370','\371','\372','\373','\374','\375','\376','\377'};
#define MATCH_CACHE_SIZE 15
struct match_cache {
char *arg; /* Matched regular expression */
int max_hits; /* Maximum matchess <0 = found all */
int offset; /* Offset */
search_sel search_type; /* Search method (the one used) */
search_sel req_type; /* Requested method */
VLINK matches; /* Matches */
VLINK more; /* Additional matches */
int archiedir; /* Flag: directory links are to archie */
struct match_cache *next; /* Next entry in cache */
};
static struct match_cache *mcache = NULL;
static int cachecount = 0;
/*
* prarch_match - Search archie database for specified file
*
* PRARCH_MATCH searches the archie database and returns
* a list of files matching the provided regular expression
*
* ARGS: program_name - regular expression for files to match
* max_hits - maximum number of entries to return (max hits)
* offset - start the search after this many hits
* search_type - search method
* vd - pointer to directory to be filled in
* archiedir - flag - directory links should be to archie
*
* Search method is one of: S_FULL_REGEX
* S_EXACT
* S_SUB_NCASE_STR
* S_SUB_CASE_STR
*/
int prarch_match(program_name,max_hits,offset,search_type,vd,archiedir)
char *program_name; /* Regular expression to be matched */
int max_hits; /* Maximum number of entries to return */
int offset; /* Skip this many matches before starting */
search_sel search_type; /* Search method */
VDIR vd; /* Directory to be filled in */
int archiedir; /* Flag: directory links s/b to archie */
{
/*
* Search the database for the string specified by 'program_name'. Use the
* fast dbm strings database if 'is_exact' is set, otherwise search through
* the strings table. Stop searching after all matches have been found, or
* 'max_hits' matches have been found, whichever comes first.
*/
char s_string[MAX_STRING_LEN];
char *strings_ptr;
char *strings_curr_off;
strings_header str_head;
datum search_key, key_value;
search_sel new_search_type = S_EXACT; /* Alternate search method */
search_sel or_search_type = search_type; /* Original search method */
int nocase = 0;
int hits_exceeded = FALSE; /* should be boolean? */
char *strings_end;
int match_number;
int patlen;
site_out **site_outptr;
site_out site_outrec;
int i;
VLINK cur_link;
int loopcount = 0;
int retval;
if(!program_name || !(*program_name)) return(PRARCH_BAD_ARG);
strcpy(s_string, program_name);
/* See if we can use a less expensive search method */
if((search_type == S_FULL_REGEX) &&
(strpbrk(s_string,"\\^$.,[]<>*+?|(){}/") == NULL))
or_search_type = search_type = S_SUB_CASE_STR;
else if((search_type == S_E_FULL_REGEX) &&
(strpbrk(s_string,"\\^$.,[]<>*+?|(){}/") == NULL))
or_search_type = search_type = S_E_SUB_CASE_STR;
/* The caching code assumes we are handed an empty directory */
/* if not, return an error for now. Eventually we will get */
/* rid of that assumption */
if(vd->links) {
plog(L_DIR_ERR, NULL, NULL, "Prarch_match handed non empty dir",0);
return(PRARCH_BAD_ARG);
}
if(check_cache(s_string,max_hits,offset,search_type,
archiedir,&(vd->links)) == TRUE) {
plog(L_DB_INFO, NULL, NULL, "Responding with cached data",0);
return(PSUCCESS);
}
site_outptr = (site_out **) malloc((unsigned)(sizeof(site_out) *
(max_hits + offset)));
if(!site_outptr) return(PRARCH_OUT_OF_MEMORY);
startsearch:
strings_ptr = strings_begin;
strings_end = strings_begin + (int) strings_table_size;
match_number = 0;
switch(search_type){
case S_E_SUB_CASE_STR:
new_search_type = S_SUB_CASE_STR;
goto exact_match;
case S_E_SUB_NCASE_STR:
new_search_type = S_SUB_NCASE_STR;
goto exact_match;
case S_E_FULL_REGEX:
new_search_type = S_FULL_REGEX;
exact_match:
case S_EXACT:
search_key.dptr = s_string;
search_key.dsize = strlen(s_string) + 1;
check_for_messages();
key_value = dbm_fetch(fast_strings, search_key) ;
if(key_value.dptr != (char *)NULL){ /* string in table */
int string_pos;
bcopy(key_value.dptr,(char *)&string_pos, key_value.dsize);
strings_ptr += string_pos;
bcopy(strings_ptr,(char *)&str_head,sizeof(strings_header));
check_for_messages();
if(str_head.filet_index != -1) {
retval = get_match_list((int) str_head.filet_index, max_hits +
offset, &match_number, site_outptr, FALSE);
if((retval != A_OK) && (retval != HITS_EXCEEDED)) {
plog(L_DB_ERROR,NULL,NULL,"get_match_list failed (%d)",retval,0);
goto cleanup;
}
if( match_number >= max_hits + offset ){
hits_exceeded = TRUE;
break;
}
}
}
else if (search_type != S_EXACT) { /* Not found - but try other method */
search_type = new_search_type;
goto startsearch;
}
break;
case S_FULL_REGEX:
if(re_comp(s_string) != (char *)NULL){
return (PRARCH_BAD_REGEX);
}
str_head.str_len = -1;
check_for_messages();
while((strings_curr_off = strings_ptr + str_head.str_len + 1) < strings_end){
if((loopcount++ & 0x7ff) == 0) check_for_messages();
strings_ptr = strings_curr_off;
bcopy(strings_ptr,(char *)&str_head,sizeof(strings_header));
strings_ptr += sizeof(strings_header);
if(re_exec( strings_ptr ) == 1 ){ /* TRUE */
strings_curr_off = strings_ptr;
check_for_messages();
if(str_head.filet_index != -1){
retval = get_match_list((int) str_head.filet_index, max_hits +
offset, &match_number, site_outptr, FALSE);
if((retval != A_OK) && (retval != HITS_EXCEEDED)) {
plog(L_DB_ERROR,NULL,NULL,"get_match_list failed (%d)",retval,0);
goto cleanup;
}
if( match_number >= max_hits + offset ){
hits_exceeded = TRUE;
break;
}
}
}
}
break;
#define TABLESIZE 256
case S_SUB_NCASE_STR:
nocase++;
case S_SUB_CASE_STR: {
char pattern[MAX_STRING_LEN];
int skiptab[TABLESIZE];
register int pc, tc;
register int local_loopcount = 0xfff;
char *bp1;
int skip;
int plen;
int plen_1;
int tlen;
unsigned char tchar;
plen = strlen(s_string);
plen_1 = plen -1;
/* Old code (replaced by inline code taken from initskip) */
/* patlen = strlen(s_string ) ; */
/* initskip(s_string, patlen, search_type == S_SUB_NCASE_STR) ; */
if(nocase) {
for(pc = 0; s_string[pc]; pc++)
pattern[pc] = lowertable[s_string[pc]];
pattern[pc] = '\0';
}
else strcpy(pattern,s_string);
for( i = 0 ; i < TABLESIZE ; i++ )
skiptab[ i ] = plen;
/* Note that we want both ucase and lcase in this table if nocase */
for( i = 0, tchar = *pattern; i < plen ; i++, tchar = *(pattern + i)) {
skiptab[tchar] = plen - 1 - i;
if(nocase && islower(tchar))
skiptab[_toupper(tchar)] = plen - 1 - i;
}
/* Begin heavily optimized and non portable code */
/* Note that we are depending on str_head being 8 bytes */
tlen = -9; /* str_head.str_len */
strings_curr_off = strings_ptr;
while((strings_curr_off += tlen + 9) < strings_end) {
if(--local_loopcount == 0) {
check_for_messages();
local_loopcount = 0xfff;
}
strings_ptr = strings_curr_off;
/* This is a kludge, non-portable, but it eliminates a pr call */
/* Note that the size is 8 on suns. Is there a better way? */
/* bcopy(strings_ptr,(char *)&str_head,sizeof(strings_header)); */
bp1 = (char *) &str_head;
/* The copying of the file index is done only on a match */
bp1[4] = strings_ptr[4]; bp1[5] = strings_ptr[5];
/* bp1[6] = strings_ptr[6]; bp1[7] = strings_ptr[7]; */
tlen = (unsigned short) str_head.str_len;
/* To catch database corruption, this is a sanity check */
if((tlen < 0) || (tlen > MAX_STRING_LEN)) {
plog(L_DB_ERROR,NULL,NULL,"Database corrupt: string length out of bounds",0);
break;
}
/* Old code (replaced by inline code taken from strfind) */
/* if(strfind(strings_ptr,str_head.str_len)) */
if( tlen <= plen_1 ) continue;
pc = tc = plen_1;
strings_ptr += 8;
/* Moved the nocase test outside the inner loop for performace */
/* Clauses are identical except for the first if */
if(nocase) do {
tchar = strings_ptr[tc];
/* improve efficiency of this test */
if(lowertable[tchar] == pattern[pc]) {--pc; --tc;}
else {
skip = skiptab[tchar] ;
tc += (skip < plen_1 - pc) ? plen : skip ;
pc = plen_1 ;
}
} while( pc >= 0 && tc < tlen ) ;
else /* (!nocase) */ do {
tchar = strings_ptr[tc];
/* improve efficiency of this test */
if(tchar == pattern[pc]) {--pc; --tc;}
else {
skip = skiptab[tchar] ;
tc += (skip < plen_1 - pc) ? plen : skip ;
pc = plen_1 ;
}
} while( pc >= 0 && tc < tlen ) ;
if(pc >= 0) continue;
/* We have a match */
/* Finish copying str_head - strings_curr_off */
/* is old strings_ptr. */
bp1[0] = strings_curr_off[0]; bp1[1] = strings_curr_off[1];
bp1[2] = strings_curr_off[2]; bp1[3] = strings_curr_off[3];
/* End heavily optimized and non portable code */
check_for_messages();
if(str_head.filet_index != -1){
retval = get_match_list((int) str_head.filet_index, max_hits +
offset, &match_number, site_outptr, FALSE);
if((retval != A_OK) && (retval != HITS_EXCEEDED)) {
plog(L_DB_ERROR,NULL,NULL,"get_match_list failed (%d)",retval,0);
goto cleanup;
}
if( match_number >= max_hits + offset){
hits_exceeded = TRUE;
break;
}
}
}
}
break;
default:
return(PRARCH_BAD_ARG);
cleanup:
for(i = 0;i < match_number; i++) free((char *)site_outptr[i]);
free((char *)site_outptr);
return(PRARCH_DB_ERROR);
}
for(i = 0;i < match_number; i++){
if((i & 0x7f) == 0) check_for_messages();
site_outrec = *site_outptr[i];
if(i >= offset) {
cur_link = atoplink(site_outrec,archiedir);
if(cur_link) vl_insert(cur_link,vd,VLI_NOSORT);
}
free((char *)site_outptr[i]);
}
free((char *)site_outptr);
if(hits_exceeded) {
/* Insert a continuation entry */
}
if((search_type == S_EXACT) && (pQlen > (MATCH_CACHE_SIZE - 5)))
return(PRARCH_SUCCESS);
add_to_cache(vd->links,s_string, (hits_exceeded ? max_hits : -max_hits),
offset,search_type,or_search_type,archiedir);
return(PRARCH_SUCCESS);
}
/* Check for cached results */
check_cache(arg,max_hits,offset,qtype,archiedir,linkpp)
char *arg;
int max_hits;
int offset;
search_sel qtype;
int archiedir;
VLINK *linkpp;
{
struct match_cache *cachep = mcache;
struct match_cache *pcachep = NULL;
VLINK tmp_link, cur_link;
VLINK rest = NULL;
VLINK next = NULL;
int count = max_hits;
while(cachep) {
if(((qtype == cachep->search_type)||(qtype == cachep->req_type))&&
(cachep->offset == offset) &&
/* All results are in cache - or enough to satisfy request */
((cachep->max_hits < 0) || (max_hits <= cachep->max_hits)) &&
(strcmp(cachep->arg,arg) == 0) &&
(cachep->archiedir == archiedir)) {
/* We have a match. Move to front of list */
if(pcachep) {
pcachep->next = cachep->next;
cachep->next = mcache;
mcache = cachep;
}
/* We now have to clear the expanded bits or the links */
/* returned in previous queries will not be returned */
/* We also need to truncate the list of there are more */
/* matches than requested */
cur_link = cachep->matches;
#ifdef NOTDEF /* OLD code that is not maintained, it is unnecessary */
/* but it does show how we used to handle two-dimensions */
while(cur_link) {
tmp_link = cur_link;
while(tmp_link) {
tmp_link->expanded = FALSE;
if(tmp_link == cur_link) tmp_link = tmp_link->replicas;
else tmp_link = tmp_link->next;
}
cur_link = cur_link->next;
}
#else /* One dimensional */
/* IMPORTANT: This code assumes the list is one */
/* dimensional, which is the case because we called */
/* vl_insert with the VLI_NOSORT option */
while(cur_link) {
cur_link->expanded = FALSE;
next = cur_link->next;
if(--count == 0) { /* truncate list */
rest = cur_link->next;
cur_link->next = NULL;
if(rest) rest->previous = NULL;
}
else if((next == NULL) && (rest == NULL)) {
next = cachep->more;
cur_link->next = next;
if(next) next->previous = cur_link;
cachep->more = NULL;
}
else if (next == NULL) {
cur_link->next = cachep->more;
if(cur_link->next)
cur_link->next->previous = cur_link;
cachep->more = rest;
}
cur_link = next;
}
#endif
*linkpp = cachep->matches;
return(TRUE);
}
pcachep = cachep;
cachep = cachep->next;
}
*linkpp = NULL;
return(FALSE);
}
/* Cache the response for later use */
add_to_cache(vl,arg,max_hits,offset,search_type,req_type,archiedir)
VLINK vl;
char *arg;
int max_hits;
int offset;
search_sel search_type;
search_sel req_type;
int archiedir;
{
struct match_cache *newresults = NULL;
struct match_cache *pcachep = NULL;
if(cachecount < MATCH_CACHE_SIZE) { /* Create a new entry */
newresults = (struct match_cache *) malloc(sizeof(struct match_cache));
cachecount++;
newresults->next = mcache;
mcache = newresults;
newresults->arg = stcopy(arg);
newresults->max_hits = max_hits;
newresults->offset = offset;
newresults->search_type = search_type;
newresults->req_type = req_type;
newresults->archiedir = archiedir;
newresults->matches = NULL;
newresults->more = NULL;
}
else { /* Use last entry - Assumes list has at least two entries */
pcachep = mcache;
while(pcachep->next) pcachep = pcachep->next;
newresults = pcachep;
/* move to front of list */
newresults->next = mcache;
mcache = newresults;
/* Fix the last entry so we don't have a cycle */
while(pcachep->next != newresults) pcachep = pcachep->next;
pcachep->next = NULL;
/* Free the old results */
if(newresults->matches) {
newresults->matches->dontfree = FALSE;
vllfree(newresults->matches);
newresults->matches = NULL;
}
if(newresults->more) {
newresults->more->dontfree = FALSE;
vllfree(newresults->more);
newresults->more = NULL;
}
newresults->arg = stcopyr(arg,newresults->arg);
newresults->max_hits = max_hits;
newresults->offset = offset;
newresults->search_type = search_type;
newresults->req_type = req_type;
newresults->archiedir = archiedir;
}
/* Since we are caching the data. If there are any links, */
/* note that they should not be freed when sent back */
if(vl) vl->dontfree = TRUE;
newresults->matches = vl;
}

86
archie/access/prlist.c Normal file
View File

@ -0,0 +1,86 @@
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include "error.h"
#include "typedef.h"
#include "prarch.h"
#include "ar_search.h"
#include "db_ops.h"
#ifdef OLD_FILES
# include "old-host_db.h"
#else
# include "host_db.h"
#endif
#include "files.h"
#include "master.h"
#include "ar_attrib.h"
char *hostname = "THISHOST";
char *hostwport = "THISHOST";
void main(argc,argv)
int argc;
char *argv[];
{
PATTRIB atlink;
VLINK conflink;
VDIR_ST dir_st;
VLINK clink;
file_info_t *strings_idx = create_finfo();
file_info_t *strings = create_finfo();
file_info_t *strings_hash = create_finfo();
file_info_t *domaindb = create_finfo();
file_info_t *hostdb = create_finfo();
file_info_t *hostaux_db = create_finfo();
file_info_t *hostbyaddr = create_finfo();
VDIR dir = &dir_st;
attrib_list_t attrib_list;
SET_ALL_ATTRIB(attrib_list);
set_master_db_dir("");
set_files_db_dir("");
if(open_files_db(strings_idx, strings, strings_hash, O_RDONLY) != A_OK) {
fprintf(stderr,"prarch: Can't open database\n");
exit(1);
}
set_host_db_dir("");
if(open_host_dbs(hostbyaddr, hostdb, domaindb, hostaux_db, O_RDONLY) != A_OK) {
fprintf(stderr,"prarch: Can't open database\n");
exit(1);
}
vdir_init(dir);
prarch_host_dir(argv[1], "anonftp", attrib_list, (argv[2] == NULL ? "" : argv[2]),dir, hostdb, hostaux_db, strings);
clink = dir->links;
while(clink) {
conflink = clink;
while(conflink) {
printf("\n Name: %s\n",conflink->name);
printf(" ObjType: %s\n",conflink->type);
printf(" LinkType: %s\n",((conflink->linktype == 'U') ? "Union" : "Standard"));
printf(" HostType: %s\n",conflink->hosttype);
printf(" Host: %s\n",conflink->host);
printf(" NameType: %s\n",conflink->nametype);
printf(" Pathname: %s\n",conflink->filename);
if(conflink->version) printf(" Version: %d\n",conflink->version);
printf(" Magic: %d\n",conflink->f_magic_no);
atlink = conflink -> lattrib;
while(atlink){
printf(" Name: %s\n Value: %s\n", atlink -> aname, atlink -> value.ascii);
atlink = atlink -> next;
}
conflink = conflink->replicas;
}
clink = clink->next;
}
}

23
archie/access/sys/370.c Normal file
View File

@ -0,0 +1,23 @@
#include <sys/types.h>
#include <sys/times.h>
#include <sys/param.h>
int hz = HZ;
double tcmp = 3.0;
#if 0
static struct tms start;
startclock()
{
times(&start);
}
stopclock()
{
struct tms t;
times(&t);
return(t.tms_utime - start.tms_utime);
}
#endif

23
archie/access/sys/386.c Normal file
View File

@ -0,0 +1,23 @@
#include <sys/types.h>
#include <sys/times.h>
#include <sys/param.h>
int hz = HZ;
double tcmp = 4.91;
#if 0
static struct tms start;
startclock()
{
times(&start);
}
stopclock()
{
struct tms t;
times(&t);
return(t.tms_utime - start.tms_utime);
}
#endif

23
archie/access/sys/68k.c Normal file
View File

@ -0,0 +1,23 @@
#include <sys/types.h>
#include <sys/times.h>
#include <sys/param.h>
int hz = HZ;
double tcmp = 2.97;
#if 0
static struct tms start;
startclock()
{
times(&start);
}
stopclock()
{
struct tms t;
times(&t);
return(t.tms_utime - start.tms_utime);
}
#endif

23
archie/access/sys/cray.c Normal file
View File

@ -0,0 +1,23 @@
#include <sys/types.h>
#include <sys/times.h>
#include <sys/machd.h>
int hz = HZ;
double tcmp = 3.34;
#if 0
static struct tms start;
startclock()
{
times(&start);
}
stopclock()
{
struct tms t;
times(&t);
return(t.tms_utime - start.tms_utime);
}
#endif

23
archie/access/sys/mips.c Normal file
View File

@ -0,0 +1,23 @@
#include <sys/types.h>
#include <sys/times.h>
#include <sys/param.h>
int hz = HZ;
double tcmp = 3.29;
#if 0
static struct tms start;
startclock()
{
times(&start);
}
stopclock()
{
struct tms t;
times(&t);
return(t.tms_utime - start.tms_utime);
}
#endif

25
archie/access/sys/sparc.c Normal file
View File

@ -0,0 +1,25 @@
#include <sys/types.h>
#include <sys/times.h>
#include <sys/param.h>
#if !defined(AIX) && !defined(SOLARIS)
int hz = HZ;
#endif
double tcmp = 3.04;
#if 0
static struct tms start;
startclock()
{
times(&start);
}
stopclock()
{
struct tms t;
times(&t);
return(t.tms_utime - start.tms_utime);
}
#endif

View File

@ -0,0 +1,23 @@
#include <sys/types.h>
#include <sys/times.h>
#include <sys/param.h>
int hz = HZ;
double tcmp = 3.1683;
#if 0
static struct tms start;
startclock()
{
times(&start);
}
stopclock()
{
struct tms t;
times(&t);
return(t.tms_utime - start.tms_utime);
}
#endif

22
archie/access/sys/vax.c Normal file
View File

@ -0,0 +1,22 @@
#include <sys/types.h>
#include <sys/times.h>
int hz = 60;
double tcmp = 3.86;
#if 0
static struct tms start;
startclock()
{
times(&start);
}
stopclock()
{
struct tms t;
times(&t);
return(t.tms_utime - start.tms_utime);
}
#endif

1
archie/anonftp/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
Makefile

15
archie/anonftp/Makefile.in Executable file
View File

@ -0,0 +1,15 @@
#
# anonftp
#
BIN_DIRS = \
parse \
retrieve \
update
DIRS = \
lib \
$(BIN_DIRS)
include $(ARCHIE_ROOT)/Makefile.multi

1
archie/anonftp/lib/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
Makefile

1
archie/anonftp/lib/AIX-2/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
Makefile

View File

@ -0,0 +1,11 @@
#
# Use GNU's fixed header files.
#
SYS_DEFS = -DAIX
SENT_FLAGS = -ffixed-%g2 -ffixed-%g3 -ffixed-%g4
include ../Makefile.pre
include ../Makefile.post
# DO NOT DELETE THIS LINE -- make depend depends on it

View File

@ -0,0 +1,16 @@
#
# Patrie module.
#
all: libanonftp.a
include $(ARCHIE_ROOT)/Makefile.post
libanonftp.a: $(OBJS)
$(AR) r $@ $?
$(RANLIB) $@
clean:
rm -f *.o $(EXES) libanonftp.a core

26
archie/anonftp/lib/Makefile.pre Executable file
View File

@ -0,0 +1,26 @@
#
# Anonftp/lib module.
#
MOD_CFLAGS = -ansi -pedantic -pipe
#MOD_CFLAGS = -traditional -pipe
MOD_DEBUG = -g3
MOD_WARN = -Wall -Wshadow -Wpointer-arith -Wcast-align \
-Wnested-externs
MOD_INCS = -I$(INCLUDE_MODULE) -I$(PROSPERO_ROOT)/include -I.
include $(ARCHIE_ROOT)/Makefile.pre
INCS = \
lang_libanonftp.h
SRCS = \
db_ops.c \
lang_libanonftp.c
OBJS = \
db_ops.o \
lang_libanonftp.o

View File

@ -0,0 +1 @@
Makefile

View File

@ -0,0 +1,10 @@
#
# Use GNU's fixed header files.
#
SYS_DEFS = -D__USE_FIXED_PROTOTYPES__ -DSUNOS
SENT_FLAGS = -ffixed-%g2 -ffixed-%g3 -ffixed-%g4
include ../Makefile.pre
include ../Makefile.post
# DO NOT DELETE THIS LINE -- make depend depends on it

View File

@ -0,0 +1 @@
Makefile

View File

@ -0,0 +1,12 @@
#
# Use GNU's fixed header files.
#
SYS_DEFS = -D__USE_FIXED_PROTOTYPES__ -DSOLARIS
SENT_FLAGS = -ffixed-%g2 -ffixed-%g3 -ffixed-%g4
SYS_LIBS = -lresolv
include ../Makefile.pre
RANLIB = :
include ../Makefile.post
# DO NOT DELETE THIS LINE -- make depend depends on it

View File

@ -0,0 +1 @@
SunOS-5.4

284
archie/anonftp/lib/db_ops.c Normal file
View File

@ -0,0 +1,284 @@
/*
* This file is copyright Bunyip Information Systems Inc., 1992. This file
* may not be reproduced, copied or transmitted by any means mechanical or
* electronic without the express written consent of Bunyip Information
* Systems Inc.
*/
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <malloc.h>
#include <string.h>
#include "typedef.h"
#include "db_ops.h"
#include "db_files.h"
#include "files.h"
#include "master.h"
#include "misc.h"
#include "error.h"
#include "lang_libanonftp.h"
#include "archie_dbm.h"
#include "protos.h"
/* Set up the directory name containing the files database */
extern char *prog;
char *set_files_db_dir(files_db_dir)
char *files_db_dir;
{
static pathname_t files_database_dir;
char *data_dir;
struct stat statbuf;
if(files_db_dir == (char *) NULL){
if((data_dir = (char *) malloc(strlen(files_database_dir) +1))
== (char *) NULL){
error(A_SYSERR,"set_database_dir","trying to malloc for database directory name");
return((char *) NULL);
}
strcpy(data_dir, files_database_dir);
return(data_dir);
}
if(files_db_dir[0] != '\0')
strcpy(files_database_dir, files_db_dir);
else
sprintf(files_database_dir, "%s/%s%s", get_master_db_dir(), DEFAULT_FILES_DB_DIR,DB_SUFFIX);
if(stat(files_database_dir, &statbuf) == -1){
error(A_SYSERR,"set_files_db_dir","Can't access dirctory %s", files_database_dir);
return((char *) NULL);
}
if(!S_ISDIR(statbuf.st_mode)){
error(A_ERR,"set_host_db_dir","%s is not a directory", files_database_dir);
return((char *) NULL);
}
return(files_database_dir);
}
char *get_files_db_dir()
{
return(set_files_db_dir((char *) NULL));
}
char *files_db_filename(filename,port)
char *filename;
int port;
{
static char tmp_db_filename[MAX_PATH_LEN];
char *gfdd = get_files_db_dir(); /* Need this to free memory allocated
in set_files_db_dir() */
if ( port > 0 )
sprintf(tmp_db_filename, "%s/%s:%d", gfdd , filename , port);
else
sprintf(tmp_db_filename, "%s/%s", gfdd , filename );
free(gfdd);
return (char *)tmp_db_filename;
}
/*
* Open all files database files
*/
status_t open_files_db(strings_idx_finfo, strings_finfo, strings_hash_finfo, mode)
file_info_t *strings_idx_finfo;
file_info_t *strings_finfo;
file_info_t *strings_hash_finfo;
int mode;
{
int tmp_fd;
int testmode = R_OK | F_OK;
if (strings_idx_finfo != (file_info_t *)NULL)
{
strcpy(strings_idx_finfo->filename, files_db_filename(DEFAULT_STRINGS_IDX, (int)(0)));
if (access(strings_idx_finfo->filename, mode == O_RDONLY ? testmode : testmode | W_OK) == -1)
{
if (mode == O_RDONLY)
{
error(A_SYSERR, "open_files_db", "can't access %s", strings_idx_finfo->filename);
return ERROR;
}
#if 0
else
{
error(A_SYSWARN, "open_files_db", "can't access %s. Attempting to create new file",
strings_idx_finfo->filename);
}
#endif
}
if ((tmp_fd = open(strings_idx_finfo->filename, (mode == O_RDONLY ? O_RDONLY : mode | O_CREAT),
DEFAULT_FILE_PERMS)) == -1)
{
error(A_SYSERR, "open_files_db", "can't access %s", strings_idx_finfo->filename);
return ERROR;
}
if ((strings_idx_finfo->fp_or_dbm.fp = fdopen(tmp_fd, mode == O_RDONLY ? "r" : "r+"))
== (FILE *)NULL)
{
error(A_ERR, "open_files_db", "opening %s file", DEFAULT_STRINGS_IDX);
return ERROR;
}
}
if (strings_finfo != (file_info_t *)NULL)
{
int new_file = 0;
strcpy(strings_finfo->filename, files_db_filename(DEFAULT_STRINGS_LIST,(int)(0)));
if (access(strings_finfo->filename, mode == O_RDONLY ? testmode : testmode | W_OK) == -1)
{
if (mode == O_RDONLY)
{
error(A_SYSERR, "open_files_db", "can't access %s", strings_finfo->filename);
return ERROR;
}
else
{
#if 0
error(A_SYSWARN, "open_files_db", "can't access %s. Attempting to create new file",
strings_finfo->filename);
#endif
new_file = TRUE;
}
}
if ((tmp_fd = open(strings_finfo->filename, (mode == O_RDONLY ? O_RDONLY : mode | O_CREAT),
DEFAULT_FILE_PERMS)) == -1)
{
error(A_SYSERR, "open_files_db", "can't access %s", strings_finfo->filename);
return ERROR;
}
if ((strings_finfo->fp_or_dbm.fp = fdopen(tmp_fd, mode == O_RDONLY ? "r" : "r+"))
== (FILE *)NULL)
{
error(A_SYSERR, "open_files_db", "opening %s file", DEFAULT_STRINGS_LIST);
return ERROR;
}
if (new_file && ftruncate(fileno(strings_finfo->fp_or_dbm.fp), INIT_STRING_SIZE) != 0)
{
error(A_SYSERR, "open_files_db", "extending strings file to default length");
return ERROR;
}
}
if (strings_hash_finfo != (file_info_t *)NULL)
{
strcpy(strings_hash_finfo->filename, files_db_filename(DEFAULT_STRINGS_HASH,(int)(0)));
strings_hash_finfo->fp_or_dbm.dbm = dbm_open(strings_hash_finfo->filename,
(mode == O_RDONLY ? O_RDONLY : mode | O_CREAT),
DEFAULT_FILE_PERMS);
if ((strings_hash_finfo->fp_or_dbm.dbm == (DBM *)NULL) ||
dbm_error(strings_hash_finfo->fp_or_dbm.dbm))
{
error(A_INTERR, "open_files_db", "error opening hashed strings database %s",
DEFAULT_STRINGS_HASH);
return ERROR;
}
}
return A_OK;
}
status_t close_files_db(strings_idx_finfo, strings_finfo, strings_hash_finfo)
file_info_t *strings_idx_finfo;
file_info_t *strings_finfo;
file_info_t *strings_hash_finfo;
{
if(strings_idx_finfo != (file_info_t *) NULL)
if(close_file(strings_idx_finfo) == ERROR){
error(A_INTERR, "close_files_db", "Can't close strings idx file %s", strings_idx_finfo -> filename);
}
if(strings_finfo != (file_info_t *) NULL)
if(close_file(strings_finfo) == ERROR){
error(A_INTERR, "close_files_db", "Can't close strings file %s", strings_finfo -> filename);
}
if(strings_hash_finfo != (file_info_t *) NULL)
dbm_close(strings_hash_finfo -> fp_or_dbm.dbm);
return(A_OK);
}
char *unix_perms_itoa(perms, directory, link)
int perms;
int directory;
int link;
{
static char result[ 16 ] ;
int i;
int tmp;
if(directory)
result[0] ='d';
else if(link)
result[0] ='l';
else
result[0] ='-';
result[1] = '\0';
for(i=8; i >= 0; i--){
tmp = 0x1;
if(perms & (tmp << i)){
switch(i){
case 8:
case 5:
case 2:
strcat(result,"r");
break;
case 7:
case 4:
case 1:
strcat(result,"w");
break;
case 6:
case 3:
case 0:
strcat(result,"x");
break;
}
}
else
strcat(result,"-");
}
return result ;
}

View File

@ -0,0 +1,6 @@
/* db_ops.c */
char* GET_INPUT_FILE_001 = "Host %s unknown";
char* GET_INPUT_FILE_002 = "Can't find host %s in primary database";
char* GET_INPUT_FILE_003 = "Can't find database %s host %s in local databases";

View File

@ -0,0 +1,10 @@
#ifndef _LANG_LIBANONFTP_H_
#define _LANG_LIBANONFTP_H_
/* db_ops.c */
extern char* GET_INPUT_FILE_001 ;
extern char* GET_INPUT_FILE_002 ;
extern char* GET_INPUT_FILE_003 ;
#endif

1
archie/anonftp/parse/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
Makefile

1
archie/anonftp/parse/AIX-2/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
Makefile

View File

@ -0,0 +1,12 @@
#
# Use GNU's fixed header files.
#
SYS_DEFS = -DAIX
SENT_FLAGS = -ffixed-%g2 -ffixed-%g3 -ffixed-%g4
SYS_LIBS = -L${BERKDB_ROOT}/${SYSTYPE} -ldb
include ../Makefile.pre
include ../Makefile.post
# DO NOT DELETE THIS LINE -- make depend depends on it

View File

@ -0,0 +1,50 @@
#
# module.
#
all: $(EXES)
include $(ARCHIE_ROOT)/Makefile.post
parse_anonftp_unix_bsd: \
$(LIBARCHIE_MODULE)/$(SYSTYPE)/libarchie.a \
$(HOSTDB_MODULE)/$(SYSTYPE)/libhostdb.a \
$(REGEX_MODULE)/$(SYSTYPE)/libregex.a \
unix.o unix2.o ${COMMON_OBJ}
${CC} ${CFLAGS} ${INCLUDES} -o parse_anonftp_unix_bsd unix.o unix2.o \
${COMMON_OBJ} ${LIBS} ${SYS_LIBS}
parse_anonftp_vms_std: \
$(LIBARCHIE_MODULE)/$(SYSTYPE)/libarchie.a \
$(HOSTDB_MODULE)/$(SYSTYPE)/libhostdb.a \
$(REGEX_MODULE)/$(SYSTYPE)/libregex.a \
vms.o vms2.o ${COMMON_OBJ}
${CC} ${CFLAGS} ${INCLUDES} -o parse_anonftp_vms_std vms.o vms2.o \
${COMMON_OBJ} ${LIBS} ${SYS_LIBS}
parse_anonftp_novell: \
$(LIBARCHIE_MODULE)/$(SYSTYPE)/libarchie.a \
$(HOSTDB_MODULE)/$(SYSTYPE)/libhostdb.a \
$(REGEX_MODULE)/$(SYSTYPE)/libregex.a \
novell.o novell2.o ${COMMON_OBJ}
${CC} ${CFLAGS} ${INCLUDES} -o parse_anonftp_novell novell.o novell2.o \
${COMMON_OBJ} ${LIBS} ${SYS_LIBS}
parse_anonftp: \
$(LIBARCHIE_MODULE)/$(SYSTYPE)/libarchie.a \
$(HOSTDB_MODULE)/$(SYSTYPE)/libhostdb.a \
$(REGEX_MODULE)/$(SYSTYPE)/libregex.a \
parse_anonftp.o lang_anonftp.o
${CC} ${CFLAGS} ${INCLUDES} -o parse_anonftp parse_anonftp.o lang_anonftp.o \
${LIBS} ${SYS_LIBS}
test-queue: test-queue.o queue.o
${CC} ${CFLAGS} ${INCLUDES} -o test-queue test-queue.o
test-vms_parser: test-vms_parser.o vms_parser.o
${CC} ${CFLAGS} ${INCLUDES} -o test-vms_parser test-vms_parser.o ${SYS_LIBS}
clean:
rm -f *.o $(EXES) core

View File

@ -0,0 +1,99 @@
#
# anonftp/parse module.
#
LIBS = \
-L$(LIBARCHIE_MODULE)/$(SYSTYPE) -larchie \
-L$(HOSTDB_MODULE)/$(SYSTYPE) -lhostdb \
-L$(REGEX_MODULE)/$(SYSTYPE) -lregex
#MOD_CFLAGS = -ansi -pedantic -pipe
#MOD_CFLAGS = -traditional -pipe
MOD_DEBUG = -g3
MOD_WARN = -Wall -Wshadow -Wpointer-arith -Wcast-align \
-Wnested-externs
MOD_INCS = -I$(INCLUDE_MODULE) -I$(REGEX_MODULE) -I.
MOD_LIBS = $(LIBS)
include $(ARCHIE_ROOT)/Makefile.pre
INCS = \
db2v.h \
info_cell.h \
input.h \
lang_parsers.h \
line_type.h \
mem_debug.h \
output.h \
pars_ent_holder.h \
parse.h \
queue.h \
queue_def.h \
stack.h \
storage.h \
str.h \
unix2.h \
utils.h \
vms2.h
COMMON_SRC = \
info_cell.c \
input.c \
lang_parsers.c \
output.c \
parse.c \
queue.c \
stack.c \
storage.c \
utils.c
COMMON_OBJ = \
info_cell.o \
input.o \
lang_parsers.o \
output.o \
parse.o \
queue.o \
stack.o \
storage.o \
utils.o
SRCS = \
${COMMON_SRC} \
db2v.c \
lang_anonftp.c \
mem_debug.c \
novell.c \
novell2.c \
parse_anonftp.c \
str.c \
test-queue.c \
test-vms_parser.c \
unix.c \
unix2.c \
vms.c \
vms2.c
OBJS = \
${COMMON_OBJ} \
db2v.o \
lang_anonftp.o \
mem_debug.o \
novell.o \
novell2.o \
parse_anonftp.o \
str.o \
test-queue.o \
test-vms_parser.o \
unix.o \
unix2.o \
vms.o \
vms2.o
EXES = \
parse_anonftp_unix_bsd \
parse_anonftp_vms_std \
parse_anonftp_novell \
parse_anonftp

View File

@ -0,0 +1 @@
Makefile

View File

@ -0,0 +1,11 @@
#
# Use GNU's fixed header files.
#
SYS_DEFS = -D__USE_FIXED_PROTOTYPES__ -DSUNOS
SENT_FLAGS = -ffixed-%g2 -ffixed-%g3 -ffixed-%g4
SYS_LIBS = -L${BERKDB_ROOT}/${SYSTYPE} -ldb
include ../Makefile.pre
include ../Makefile.post
# DO NOT DELETE THIS LINE -- make depend depends on it

View File

@ -0,0 +1 @@
Makefile

View File

@ -0,0 +1,11 @@
#
# Use GNU's fixed header files.
#
SYS_DEFS = -D__USE_FIXED_PROTOTYPES__ -DSOLARIS
SENT_FLAGS = -ffixed-%g2 -ffixed-%g3 -ffixed-%g4
SYS_LIBS = -lresolv -lnsl -lsocket -L${BERKDB_ROOT}/${SYSTYPE} -ldb
include ../Makefile.pre
include ../Makefile.post
# DO NOT DELETE THIS LINE -- make depend depends on it

View File

@ -0,0 +1 @@
SunOS-5.4

150
archie/anonftp/parse/db2v.c Normal file
View File

@ -0,0 +1,150 @@
#include <time.h>
#include <stdio.h>
#include "defines.h"
#include "parser_file.h"
#include "error.h"
/*
These routines take as arguments a pointer to a parser_entry_t and a
pointer to a string on which to write the conversions. All routines write
a nul terminator and return a pointer to the terminator.
*/
/*
'v' points to the first character of the date string.
E.g. "15-JUL-1991"
*/
char *
db2v_date(pe, s, slen)
parser_entry_t *pe ;
char *s ;
int slen ;
{
static char *months[13] = { "JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL",
"AUG", "SEP", "OCT", "NOV", "DEC", (char *)0 } ;
char *p = s ;
int dm ;
int m ;
int y ;
struct tm *bd_time ;
ptr_check(pe, parser_entry_t, "db2v_date", (char *)0) ;
ptr_check(s, char, "db2v_date", (char *)0) ;
if((bd_time = gmtime(&pe->core.date)) == (struct tm *)0)
{
error(A_ERR, "db2v_date", "error from gmtime() with [%ld]",
(long)pe->core.date) ;
return (char *)0 ;
}
#ifdef AIX
if(strftime(s, slen, "%d-%h-%Y %H:%M", bd_time) == 0)
#else
if(strftime(s, slen, "%d-%h-%Y %R", bd_time) == 0)
#endif
{
error(A_ERR, "db2v_date", "error from strftime()") ;
return (char *)0 ;
}
return s ;
}
char *
db2v_links(pe, s)
parser_entry_t *pe ;
char *s ;
{
ptr_check(pe, parser_entry_t, "db2v_links", (char *)0) ;
ptr_check(s, char, "db2v_links", (char *)0) ;
*s = '\0' ;
return s ;
}
char *
db2v_name(pe, s)
parser_entry_t *pe ;
char *s ;
{
ptr_check(pe, parser_entry_t, "db2v_name", (char *)0) ;
ptr_check(s, char, "db2v_name", (char *)0) ;
*s = '\0' ;
return s ;
}
char *
db2v_perms(pe, s)
parser_entry_t *pe ;
char *s ;
{
char *p_grp ;
char *p_own ;
char *p_sys ;
char *p_wrl ;
static char *pstr[16] =
{ "",
"D",
"E", "ED",
"W", "WD", "WE", "WED",
"R", "RD", "RE", "RED", "RW", "RWD", "RWE", "RWED"
} ;
ptr_check(pe, parser_entry_t, "db2v_perms", (char *)0) ;
ptr_check(s, char, "db2v_perms", (char *)0) ;
p_sys = pstr[(pe->core.perms >> 12) & 0x0f] ;
p_own = pstr[(pe->core.perms >> 8) & 0x0f] ;
p_grp = pstr[(pe->core.perms >> 4) & 0x0f] ;
p_wrl = pstr[(pe->core.perms >> 0) & 0x0f] ;
sprintf(s, "(%s,%s,%s,%s)", p_sys, p_own, p_grp, p_wrl) ;
return s ;
}
#define OWNER "[owner,owner]"
char *
db2v_owner(pe, s)
parser_entry_t *pe ;
char *s ;
{
ptr_check(pe, parser_entry_t, "db2v_owner", (char *)0) ;
ptr_check(s, char, "db2v_owner", (char *)0) ;
strcpy(s, OWNER) ;
return s ;
}
char *
db2v_size(pe, s)
parser_entry_t *pe ;
char *s ;
{
ptr_check(pe, parser_entry_t, "db2v_size", (char *)0) ;
ptr_check(s, char, "db2v_size", (char *)0) ;
sprintf(s, "%ld", (long)pe->core.size) ;
return s ;
}
char *
db2v_type(pe, s)
parser_entry_t *pe ;
char *s ;
{
ptr_check(pe, parser_entry_t, "db2v_type", (char *)0) ;
ptr_check(s, char, "db2v_type", (char *)0) ;
*s = '\0' ;
return s ;
}

View File

@ -0,0 +1,27 @@
#ifndef DB2V_H
#define DB2V_H
#include "parser_file.h"
#ifdef __STDC__
extern char *db2v_date(parser_entry_t *pe, char *s, int slen) ;
extern char *db2v_links(parser_entry_t *pe, char *s) ;
extern char *db2v_name(parser_entry_t *pe, char *s) ;
extern char *db2v_owner(parser_entry_t *pe, char *s) ;
extern char *db2v_perms(parser_entry_t *pe, char *s) ;
extern char *db2v_size(parser_entry_t *pe, char *s) ;
extern char *db2vype(parser_entry_t *pe, char *s) ;
#else
extern char *db2v_date(/* parser_entry_t *pe, char *s, int slen */) ;
extern char *db2v_links(/* parser_entry_t *pe, char *s */) ;
extern char *db2v_name(/* parser_entry_t *pe, char *s */) ;
extern char *db2v_owner(/* parser_entry_t *pe, char *s */) ;
extern char *db2v_perms(/* parser_entry_t *pe, char *s */) ;
extern char *db2v_size(/* parser_entry_t *pe, char *s */) ;
extern char *db2vype(/* parser_entry_t *pe, char *s */) ;
#endif
#endif

View File

@ -0,0 +1,61 @@
#include <string.h>
#include <stdio.h>
#include <stdlib.h> /* malloc? */
#include "parse.h"
#include "info_cell.h"
#include "error.h"
#include "lang_parsers.h"
/*
The 'name' field is assumed to point to malloc'ed storage.
*/
int
dispose_Info_cell(ic)
Info_cell *ic ;
{
ptr_check(ic, Info_cell, "init_Info_cell", 0) ;
if(ic->name != (char *)0)
{
free(ic->name) ;
}
free(ic) ;
return 1;
#ifdef 0
#ifndef __STDC__
#ifndef AIX
return free(ic) ;
#else
free(ic) ;
return 1;
#endif
#else
free(ic) ;
return 1;
#endif
#endif
}
Info_cell *
new_Info_cell(str)
char *str ;
{
Info_cell *ic ;
ptr_check(str, char, "init_Info_cell", 0) ;
if((ic = (Info_cell *)malloc(sizeof(Info_cell))) == (Info_cell *)0)
{
/* "Error malloc'ing %ld bytes*/
error(A_SYSERR, "new_Info_cell", NEW_INFO_CELL_001, (long)sizeof(Info_cell)) ;
return ic ;
}
ic->name = str ;
ic->idx = 0 ;
ic->addr = (Pars_ent_holder *)0 ;
return ic ;
}

View File

@ -0,0 +1,25 @@
#ifndef INFO_CELL_H
#define INFO_CELL_H
#include "typedef.h"
#include "pars_ent_holder.h"
typedef struct
{
char *name ;
index_t idx ;
Pars_ent_holder *addr ;
} Info_cell ;
#ifdef __STDC__
extern int dispose_Info_cell(Info_cell *ic) ;
extern Info_cell *new_Info_cell(char *str) ;
#else
extern int dispose_Info_cell(/* Info_cell *ic */) ;
extern Info_cell *new_Info_cell(/* char *str */) ;
#endif
#endif

View File

@ -0,0 +1,70 @@
#include <stdio.h>
#include "defines.h"
#include "utils.h"
#include "input.h"
#include "error.h"
#include "lang_parsers.h"
static int linenum = 0 ; /* number of input lines currently read */
static int skipline = 0 ; /* 1 -> return without reading a line */
int
init_line_num()
{
linenum = 0;
}
int
get_line(l, len, fp)
char *l ;
int len ;
FILE *fp ;
{
ptr_check(l, char, "get_line", 0) ;
ptr_check(fp, FILE, "get_line", 0) ;
if(skipline)
{
skipline = 0 ;
return 1 ;
}
else
{
if(fgets(l, len, fp) == (char *)0)
{
if(feof(fp))
{
return 0 ;
}
else
{
/* "Error from fgets()") */
error(A_ERR, "get_line", INPUT_001);
return 0 ;
}
}
else
{
nuke_nl(l) ;
linenum++ ;
return 1 ;
}
}
return 1 ; /* Not reached, but keeps gcc -Wall happy */
}
int
line_num()
{
return linenum ;
}
void
skip_line()
{
skipline = 1 ;
}

View File

@ -0,0 +1,17 @@
#ifndef INPUT_H
#define INPUT_H
#ifdef __STDC__
extern int get_line(char *l, int len, FILE *fp) ;
extern int line_num(void) ;
extern void skip_line(void) ;
#else
extern int get_line(/* char *l, int len, FILE *fp */) ;
extern int line_num(/* void */) ;
extern void skip_line(/* void */) ;
#endif
#endif

View File

@ -0,0 +1,283 @@
char* INSERT_ANONFTP_001 = "Can't open input file %s";
char* INSERT_ANONFTP_002 = "Can't read header record of %s";
char* INSERT_ANONFTP_003 = "Can't mmap() input file %s";
char* INSERT_ANONFTP_004 = "Can't open anonftp database";
char* INSERT_ANONFTP_005 = "Can't malloc() space for outlist";
char* INSERT_ANONFTP_006 = "Doing hostname lookup";
char* INSERT_ANONFTP_007 = "Error updating host database: %s";
char* INSERT_ANONFTP_008 = "File %s already exists in the database";
char* INSERT_ANONFTP_009 = "Reading input";
char* INSERT_ANONFTP_010 = "Error while processing input. No data has been lost";
char* INSERT_ANONFTP_011 = "Making internal links";
char* INSERT_ANONFTP_012 = "Error while making internal links. No data has been lost";
char* INSERT_ANONFTP_013 = "Can't rename %s to %s. anonftp database not changed.";
char* INSERT_ANONFTP_014 = "Making external links";
char* INSERT_ANONFTP_015 = "Can't make links into database for %s. Database may be corrupt";
char* INSERT_ANONFTP_016 = "Can't activate host database record for %s";
char* INSERT_ANONFTP_017 = "Can't set up output file %s";
char* INSERT_ANONFTP_019 = "Can't open log file %s";
char* INSERT_ANONFTP_020 = "Can't open default log file";
char* INSERT_ANONFTP_021 = "Error while trying to set master database directory";
char* INSERT_ANONFTP_022 = "Error while trying to set anonftp database directory";
char* INSERT_ANONFTP_023 = "Error while trying to set host database directory";
char* INSERT_ANONFTP_024 = "No site name or address given";
char* INSERT_ANONFTP_025 = "Can't unlink failed output file %s";
char* INSERT_ANONFTP_026 = "Input file %s contains no data after header";
char* INSERT_ANONFTP_027 = "Can't open dest file %s, errno = %d";
char* INSERT_ANONFTP_028 = "Can't open src file %s, errno = %d";
char* INSERT_ANONFTP_029 = "While copying file %s to %s, errno = %d";
char* SETUP_OUTPUT_FILE_001 = "Number of records %d. Ignoring";
char* SETUP_OUTPUT_FILE_002 = "Can't get new file info structure";
char* SETUP_OUTPUT_FILE_003 = "Can't get temporary name for file %s.";
char* SETUP_OUTPUT_FILE_004 = "Can't open output file %s";
char* SETUP_OUTPUT_FILE_005 = "Can't ftruncate output file %s";
char* SETUP_OUTPUT_FILE_006 = "Can't mmap() output file %s";
/* setup_insert.c */
char* ADD_TMP_STRING_001 = "Can't malloc space for new tmp_list element";
char* SETUP_HASH_TABLE_001 = "Can't allocate space for has table";
char* SETUP_INSERT_001 = "Can't setup hash table";
char* SETUP_INSERT_002 = "Possible zero length strings index file\nIgnore error message if this is a new database";
char* SETUP_INSERT_003 = "Can't malloc space for input string";
char* SETUP_INSERT_004 = "Can't add string to hash table";
char* SETUP_INSERT_005 = "Can't unmap strings index file";
char* SETUP_INSERT_006 = "Error while reading '%s' from hashed strings database";
char* DO_INTERNAL_001 = "Possible zero length strings index file\nIgnore error message if this is a new database";
char* DO_INTERNAL_002 = "Cannot process new or inactive record number %u, string %s";
char* DO_INTERNAL_003 = "Can't unmap strings index file" ;
char* MAKE_LINKS_001 = "Error while seeking end of strings_list file";
char* MAKE_LINKS_002 = "Error while extending strings_list file";
char* MAKE_LINKS_003 = "Error while seeking end of strings_idx file";
char* MAKE_LINKS_004 = "Error while seeking end of strings_idx file";
char* MAKE_LINKS_005 = "Error while reading last record in strings index file";
char* MAKE_LINKS_006 = "Error while seeking end of strings_idx file";
char* MAKE_LINKS_007 = "Error while seeking last string in strings file";
char* MAKE_LINKS_008 = "Error while reading last string in strings file";
char* MAKE_LINKS_009 = "Error while seeking end of last string in strings_list file";
char* MAKE_LINKS_010 = "Error while seeking beginning of strings_list file";
char* MAKE_LINKS_011 = "Can't insert new string into hash database";
char* MAKE_LINKS_012 = "Error writing strings_idx file";
char* MAKE_LINKS_013 = "Error writing new string in strings_list file";
char* MAKE_LINKS_014 = "Can't mmap() strings index file";
char* MAKE_LINKS_015 = "Can't unmap previous site file";
char* MAKE_LINKS_016 = "Can't close previous site file";
char* MAKE_LINKS_017 = "Can't open site file for link insertion";
char* MAKE_LINKS_018 = "Can't mmap() site file for link insertion";
char* MAKE_LINKS_019 = "Can't unmap strings index file";
/* delete.c */
char* DELETE_ANONFTP_001 = "No site name or address given";
char* DELETE_ANONFTP_002 = "Error while trying to set master database directory";
char* DELETE_ANONFTP_003 = "Error while trying to set anonftp database directory";
char* DELETE_ANONFTP_004 = "Error while trying to set host database directory";
char* DELETE_ANONFTP_005 = "Error while trying to open anonftp database";
char* DELETE_ANONFTP_006 = "Error while trying to open host database";
char* DELETE_ANONFTP_007 = "Can't determine input file for site %s";
char* DELETE_ANONFTP_008 = "Can't find input database file for %s";
char* DELETE_ANONFTP_009 = "Error while trying to inactivate %s in host database";
char* DELETE_ANONFTP_010 = "Error while trying to set up deletion of %s";
char* DELETE_ANONFTP_011 = "Can't remove the site file %s";
char* DELETE_ANONFTP_012 = "Can't close input file %s";
char* DELETE_ANONFTP_013 = "Can't open default log file";
char* DELETE_ANONFTP_014 = "Can't open log file %s";
/* setup_delete.c */
char* SETUP_DELETE_001 = "Can't malloc space for internal list";
char* SETUP_DELETE_002 = "No input file %s";
char* SETUP_DELETE_003 = "Can't mmap site file to be deleted %s";
char* SETUP_DELETE_004 = "Can't mmap strings index file";
char* SETUP_DELETE_005 = "Can't open site file %s";
char* SETUP_DELETE_006 = "Can't mmap site file %s";
char* SETUP_DELETE_007 = "Can't unmap site file %s";
char* SETUP_DELETE_008 = "Can't close site file %s";
char* SETUP_DELETE_009 = "Can't unmap strings index file";
char* SETUP_DELETE_010 = "Can't free internal list";
char* SETUP_DELETE_011 = "Can't fstat() input site file %s";
char* SETUP_DELETE_012 = "Number of records in host auxiliary database (%d) different from implied by file size (%d)";
char* SETUP_DELETE_013 = "Site %s record %d points to itself (previous)";
char* SETUP_DELETE_014 = "Site %s record %d points to itself (next)";
char* SETUP_DELETE_015 = "Site %s record %d points to already checked record";
/* parse_anonftp.c */
char* PARSE_ANONFTP_001 = "Can't open default log file";
char* PARSE_ANONFTP_002 = "Can't open log file %s";
char* PARSE_ANONFTP_003 = "No input file given";
char* PARSE_ANONFTP_004 = "No output file given";
char* PARSE_ANONFTP_005 = "Error while trying to set master database directory";
char* PARSE_ANONFTP_006 = "Can't open input file %s";
char* PARSE_ANONFTP_007 = "Error reading header of input file %s";
char* PARSE_ANONFTP_008 = "Input file %s not in raw format. Cannot process";
char* PARSE_ANONFTP_009 = "Can't get temporary name for file %s";
char* PARSE_ANONFTP_010 = "Can't open temporary file %s";
char* PARSE_ANONFTP_011 = "Error while writing header of output file";
char* PARSE_ANONFTP_012 = "Can't execlp() filter program %s";
char* PARSE_ANONFTP_013 = "Can't vfork() filter program %s";
char* PARSE_ANONFTP_014 = "Error while in wait() for filter program %s";
char* PARSE_ANONFTP_015 = "Filter program %s exited abnormally with exit code %d";
char* PARSE_ANONFTP_016 = "Filter program %s terminated abnormally with signal %d";
char* PARSE_ANONFTP_017 = "Can't close input file %s";
char* PARSE_ANONFTP_018 = "Can't close temporary file %s";
char* PARSE_ANONFTP_019 = "Can't execvp() parse program %s";
char* PARSE_ANONFTP_020 = "Can't vfork() parse program %s";
char* PARSE_ANONFTP_021 = "Error while in wait() for parse program %s";
char* PARSE_ANONFTP_022 = "Parse program %s exited abnormally with code %d";
char* PARSE_ANONFTP_023 = "Parse program %s terminated abnormally with signal %d";
char* PARSE_ANONFTP_024 = "Can't rename output file %s";
char* PARSE_ANONFTP_025 = "Can't unlink input file %s";
char* PARSE_ANONFTP_026 = "Can't unlink temporary file %s";
char* PARSE_ANONFTP_027 = "Can't malloc space for argument list";
char* PARSE_ANONFTP_028 = "Can't rename failed temporary file %s to %s";
char* PARSE_ANONFTP_029 = "Unable to parse access command in header";
/* net_anonftp.c */
char* NET_ANONFTP_001 = "Can't open default log file";
char* NET_ANONFTP_002 = "Can't open log file %s";
char* NET_ANONFTP_003 = "Error while trying to set master database directory";
char* NET_ANONFTP_004 = "Error while trying to set anonftp database directory";
char* NET_ANONFTP_005 = "Error while trying to set host database directory";
char* NET_ANONFTP_006 = "Error while trying to open anonftp database";
char* NET_ANONFTP_007 = "Error while trying to open host database";
char* NET_ANONFTP_008 = "No host specified for output mode";
char* NET_ANONFTP_009 = "Can't find requested host %s in local primary host database";
char* NET_ANONFTP_010 = "Can't find requested host %s database %s in local auxiliary host database";
char* NET_ANONFTP_012 = "Error sending anonftp site file";
char* NET_ANONFTP_013 = "Error receiving anonftp site file";
char* NET_ANONFTP_014 = "Broken pipe: remote data transfer process existed prematurely";
char* GET_ANONFTP_SITE_001 = "Error reading header of remote site file";
char* GET_ANONFTP_SITE_002 = "Error opening local site parser file %s";
char* GET_ANONFTP_SITE_003 = "Error writing header of local site parser file %s";
char* GET_ANONFTP_SITE_004 = "Can't open XDR stream for stdin";
char* GET_ANONFTP_SITE_005 = "Error in translating XDR input. Deleting output file.";
char* GET_ANONFTP_SITE_006 = "Can't rename temporary file %s to %s";
char* GET_ANONFTP_SITE_007 = "Can't unlink failed transfer file";
char* GET_ANONFTP_SITE_008 = "Can't open pipe to uncompression program";
char* GET_ANONFTP_SITE_009 = "Can't dup2 pipe to stdout";
char* GET_ANONFTP_SITE_010 = "Can't execute uncompression program %s";
char* GET_ANONFTP_SITE_011 = "Can't fork() for uncompression process";
char* GET_ANONFTP_SITE_012 = "Can't open incoming pipe";
char* GET_ANONFTP_SITE_013 = "Can't open XDR stream for fp";
char* GET_ANONFTP_SITE_014 = "Can't fstat() output file %s";
char* GET_ANONFTP_SITE_015 = "Transferred %d bytes in %d seconds (%6.2f bytes/sec)";
char* GET_ANONFTP_SITE_016 = "Input for %s in compressed format";
char* GET_ANONFTP_SITE_017 = "Input for %s not in compressed format";
char* GET_ANONFTP_SITE_018 = "Can't open pipe to cat program";
char* GET_ANONFTP_SITE_019 = "Can't execute cat program %s";
char* GET_ANONFTP_SITE_020 = "Can't fork() for cat process %s";
char* SEND_ANONFTP_SITE_001= "Can't open anonftp database sitefile %s";
char* SEND_ANONFTP_SITE_002= "Can't mmap anonftp database sitefile %s";
char* SEND_ANONFTP_SITE_003= "Can't open XDR stream for stdout";
char* SEND_ANONFTP_SITE_004= "Error translating site file to XDR stream";
char* SEND_ANONFTP_SITE_005= "Can't open pipe to compression program";
char* SEND_ANONFTP_SITE_006= "Can't dup2 pipe to stdin";
char* SEND_ANONFTP_SITE_007= "Can't execute compression program %s";
char* SEND_ANONFTP_SITE_008= "Can't open outgoing pipe";
char* SEND_ANONFTP_SITE_009= "Can't open XDR stream for compression ftp";
char* SEND_ANONFTP_SITE_010= "Can't fork() for compression process";
char* SEND_ANONFTP_SITE_011= "Error while writing header of output file";
char* SEND_ANONFTP_SITE_012= "Output for %s in compressed format";
char* COPY_PARSER_TO_XDR_001= "Can't mmap strings file";
char* COPY_PARSER_TO_XDR_002= "Conversion to XDR stream from raw format failed";
char* COPY_PARSER_TO_XDR_003= "Conversion of string to XDR opaque type from raw format failed";
char* COPY_PARSER_TO_XDR_004= "Can't umap strings file";
char* COPY_XDR_TO_PARSER_001= "Conversion to raw format from XDR format failed";
char* COPY_XDR_TO_PARSER_002= "Can't write out parser record %d";
char* COPY_XDR_TO_PARSER_003= "Conversion of string to parser from XDR format failed for record %d";
char* COPY_XDR_TO_PARSER_004= "Can't write out parser string %s record %d";
/* update_anonftp.c */
char* UPDATE_ANONFTP_001 = "Can't open log file %s";
char* UPDATE_ANONFTP_002 = "Can't open default log file";
char* UPDATE_ANONFTP_003 = "No input file given";
char* UPDATE_ANONFTP_004 = "Error while trying to set master database directory";
char* UPDATE_ANONFTP_005 = "Error while trying to set anonftp database directory";
char* UPDATE_ANONFTP_006 = "Can't open given input file %s";
char* UPDATE_ANONFTP_007 = "Can't read header on %s";
char* UPDATE_ANONFTP_008 = "Error while checking for lockfile %s";
char* UPDATE_ANONFTP_009 = "Can't open lock file %s";
char* UPDATE_ANONFTP_010 = "Update for %s (%s) at %s";
char* UPDATE_ANONFTP_011 = "Giving up after %d tries to update %s";
char* UPDATE_ANONFTP_012 = "Deleting %s";
char* UPDATE_ANONFTP_013 = "Can't execvp() delete program %s for %s database";
char* UPDATE_ANONFTP_014 = "Can't vfork() delete program %s";
char* UPDATE_ANONFTP_015 = "Error while in wait() for delete program %s";
char* UPDATE_ANONFTP_016 = "Delete program %s exited with value %u";
char* UPDATE_ANONFTP_017 = "Delete program %s terminated abnormally with signal %u";
char* UPDATE_ANONFTP_018 = "Inserting %s into %s with %s";
char* UPDATE_ANONFTP_019 = "Can't execvp() insert program %s for %s database";
char* UPDATE_ANONFTP_020 = "Can't vfork() insert program %s";
char* UPDATE_ANONFTP_021 = "Error while in wait() for insert program %s";
char* UPDATE_ANONFTP_022 = "Insert program %s exited with value %u";
char* UPDATE_ANONFTP_023 = "Insert program %s terminated abnormally with signal %d";
char* UPDATE_ANONFTP_025 = "Error while trying to open host database";
char* UPDATE_ANONFTP_026 = "Can't get auxiliary database entry for site %s database %s for deletion";
char* UPDATE_ANONFTP_027 = "Can't write deletion record for %s to auxiliary host database";
char* UPDATE_ANONFTP_028 = "Waiting for lock file %s";
char* UPDATE_ANONFTP_029 = "Can't unlink original input file %s";
char* UPDATE_ANONFTP_030 = "Can't malloc space for argument list";
char* UPDATE_ANONFTP_031 = "Input file %s has retrieve time older than current entry. Ignoring.";
/* added on Aug-14-95 to accomodate the set-to-zero change in update_naonftp*/
char* UPDATE_ANONFTP_032 = "Can't commit fail-count set to Zero for %s to auxiliary host database";
char* UPDATE_ANONFTP_033 = "Can't get auxiliary database entry for site %s database %s for updating information";
/* check_anonftp.c */
char* CHECK_ANONFTP_001 = "Can't open default log file";
char* CHECK_ANONFTP_002 = "Can't open log file %s";
char* CHECK_ANONFTP_003 = "Error while trying to set master database directory";
char* CHECK_ANONFTP_004 = "Error while trying to set anonftp database directory";
char* CHECK_ANONFTP_005 = "Error while trying to set host database directory";
char* CHECK_ANONFTP_006 = "Error while trying to open anonftp database";
char* CHECK_ANONFTP_007 = "Error while trying to open host database";
char* CHECK_ANONFTP_008 = "Can't find host %s in anonftp database";
char* CHECK_ANONFTP_009 = "Can't malloc space for file list";
char* CHECK_ANONFTP_010 = "Can't get list of files in directory %s" ;
char* CHECK_INDIV_001 = "Can't get host address cache entry for %s";
char* CHECK_INDIV_002 = "Checking site %s (%s)";
char* CHECK_INDIV_003 = "Ignoring %s";
char* CHECK_INDIV_004 = "Number of records in site file %s (%s) %d does not match auxiliary host database record %d";
char* CHECK_INDIV_005 = "Can't malloc space for checklist";
char* CHECK_INDIV_006 = "Site %s (%s) record %d points to itself!";
char* CHECK_INDIV_007 = "Site %s (%s) record %d has string %s but is on chain for record %d with string %s";
char* CHECK_INDIV_008 = "Site %s (%s) record %d has string index %d out of bounds";
char* CHECK_INDIV_009 = "Site %s (%s) record %d has string %s but is on chain for record %d with string %s";
char* CHECK_INDIV_010 = "Site %s (%s) rec %d -> rec %d -> site %s rec %d";
char* CHECK_INDIV_011 = "Site %s (%s) record %d points to next record, out of bounds";
char* CHECK_INDIV_012 = "Can't mmap strings file";
char* CHECK_INDIV_013 = "Site %s (%s) record %d points to site file %s record %d";
char* CHECK_INDIV_014 = "Site %s (%s) record %d points to site file %s record %d out of bounds (max: %d)";
char* CHECK_INDIV_015 = "Site %s (%s) record %d (string offset: %d \"%s\") points to site file %s record %d (strings offset: %d \"%s\")";
char* CHECK_INDIV_016 = "Site %s (%s) record %d points to site file %s record %d but not reverse (site %s record %d)";
char* CHECK_INDIV_017 = "Can't mmap strings index file" ;
char* CHECK_INDIV_018 = "Site %s (%s) rec: %d -> strings id rec: %d out of bounds (max: %d)";
char* CHECK_INDIV_019 = "Site %s (%s) rec: %d (off: %d \"%s\") -> strings idx rec: %d (off: %d, \"%s\") -> sitefile %s rec: %d";
char* CHECK_INDIV_020 = "Site %s (%s) rec: %d (offset: %d \"%s\") -> strings index rec: %d -> inactive string (off: %d) \"%s\"";
char* CHECK_INDIV_021 = "Site %s (%s) rec: %d (off: %d \"%s\") -> strings idx rec: %d -> string (off: %d \"%s\")";
char* CHECK_INDIV_022 = "Site %s (%s) rec %d -> site %s rec %d -> site %s rec %d";

View File

@ -0,0 +1,290 @@
/*
* This file is copyright Bunyip Information Systems Inc., 1993. This file
* may not be reproduced, copied or transmitted by any means mechanical or
* electronic without the express written consent of Bunyip Information
* Systems Inc.
*/
#ifndef _LANG_ANONFTP_H_
#define _LANG_ANONFTP_H_
extern char* INSERT_ANONFTP_001;
extern char* INSERT_ANONFTP_002;
extern char* INSERT_ANONFTP_003;
extern char* INSERT_ANONFTP_004;
extern char* INSERT_ANONFTP_005;
extern char* INSERT_ANONFTP_006;
extern char* INSERT_ANONFTP_007;
extern char* INSERT_ANONFTP_008;
extern char* INSERT_ANONFTP_009;
extern char* INSERT_ANONFTP_010;
extern char* INSERT_ANONFTP_011;
extern char* INSERT_ANONFTP_012;
extern char* INSERT_ANONFTP_013;
extern char* INSERT_ANONFTP_014;
extern char* INSERT_ANONFTP_015;
extern char* INSERT_ANONFTP_016;
extern char* INSERT_ANONFTP_017;
extern char* INSERT_ANONFTP_018;
extern char* INSERT_ANONFTP_019;
extern char* INSERT_ANONFTP_020;
extern char* INSERT_ANONFTP_021;
extern char* INSERT_ANONFTP_022;
extern char* INSERT_ANONFTP_023;
extern char* INSERT_ANONFTP_024;
extern char* INSERT_ANONFTP_025;
extern char* INSERT_ANONFTP_026;
extern char* INSERT_ANONFTP_027;
extern char* INSERT_ANONFTP_028;
extern char* INSERT_ANONFTP_029;
extern char* SETUP_OUTPUT_FILE_001;
extern char* SETUP_OUTPUT_FILE_002;
extern char* SETUP_OUTPUT_FILE_003;
extern char* SETUP_OUTPUT_FILE_004;
extern char* SETUP_OUTPUT_FILE_005;
extern char* SETUP_OUTPUT_FILE_006;
/* setup_insert.c */
extern char* ADD_TMP_STRING_001 ;
extern char* SETUP_HASH_TABLE_001 ;
extern char* SETUP_INSERT_001 ;
extern char* SETUP_INSERT_002 ;
extern char* SETUP_INSERT_003 ;
extern char* SETUP_INSERT_004 ;
extern char* SETUP_INSERT_005 ;
extern char* SETUP_INSERT_006 ;
extern char* DO_INTERNAL_001 ;
extern char* DO_INTERNAL_002 ;
extern char* DO_INTERNAL_003 ;
extern char* MAKE_LINKS_001 ;
extern char* MAKE_LINKS_002 ;
extern char* MAKE_LINKS_003 ;
extern char* MAKE_LINKS_004 ;
extern char* MAKE_LINKS_005 ;
extern char* MAKE_LINKS_006 ;
extern char* MAKE_LINKS_007 ;
extern char* MAKE_LINKS_008 ;
extern char* MAKE_LINKS_009 ;
extern char* MAKE_LINKS_010 ;
extern char* MAKE_LINKS_011 ;
extern char* MAKE_LINKS_012 ;
extern char* MAKE_LINKS_013 ;
extern char* MAKE_LINKS_014 ;
extern char* MAKE_LINKS_015 ;
extern char* MAKE_LINKS_016 ;
extern char* MAKE_LINKS_017 ;
extern char* MAKE_LINKS_018 ;
extern char* MAKE_LINKS_019 ;
/* delete.c */
extern char* DELETE_ANONFTP_001 ;
extern char* DELETE_ANONFTP_002;
extern char* DELETE_ANONFTP_003;
extern char* DELETE_ANONFTP_004 ;
extern char* DELETE_ANONFTP_005 ;
extern char* DELETE_ANONFTP_006 ;
extern char* DELETE_ANONFTP_007 ;
extern char* DELETE_ANONFTP_008 ;
extern char* DELETE_ANONFTP_009 ;
extern char* DELETE_ANONFTP_010 ;
extern char* DELETE_ANONFTP_011 ;
extern char* DELETE_ANONFTP_012 ;
extern char* DELETE_ANONFTP_013 ;
extern char* DELETE_ANONFTP_014 ;
/* setup_delete.c */
extern char* SETUP_DELETE_001 ;
extern char* SETUP_DELETE_002 ;
extern char* SETUP_DELETE_003 ;
extern char* SETUP_DELETE_004 ;
extern char* SETUP_DELETE_005 ;
extern char* SETUP_DELETE_006 ;
extern char* SETUP_DELETE_007 ;
extern char* SETUP_DELETE_008 ;
extern char* SETUP_DELETE_009 ;
extern char* SETUP_DELETE_010 ;
extern char* SETUP_DELETE_011 ;
extern char* SETUP_DELETE_012 ;
extern char* SETUP_DELETE_013 ;
extern char* SETUP_DELETE_014 ;
extern char* SETUP_DELETE_015 ;
/* parse_anonftp.c */
extern char* PARSE_ANONFTP_001 ;
extern char* PARSE_ANONFTP_002 ;
extern char* PARSE_ANONFTP_003 ;
extern char* PARSE_ANONFTP_004 ;
extern char* PARSE_ANONFTP_005 ;
extern char* PARSE_ANONFTP_006 ;
extern char* PARSE_ANONFTP_007 ;
extern char* PARSE_ANONFTP_008 ;
extern char* PARSE_ANONFTP_009 ;
extern char* PARSE_ANONFTP_010 ;
extern char* PARSE_ANONFTP_011 ;
extern char* PARSE_ANONFTP_012 ;
extern char* PARSE_ANONFTP_013 ;
extern char* PARSE_ANONFTP_014 ;
extern char* PARSE_ANONFTP_015 ;
extern char* PARSE_ANONFTP_016 ;
extern char* PARSE_ANONFTP_017 ;
extern char* PARSE_ANONFTP_018 ;
extern char* PARSE_ANONFTP_019 ;
extern char* PARSE_ANONFTP_020 ;
extern char* PARSE_ANONFTP_021 ;
extern char* PARSE_ANONFTP_022 ;
extern char* PARSE_ANONFTP_023 ;
extern char* PARSE_ANONFTP_024 ;
extern char* PARSE_ANONFTP_025 ;
extern char* PARSE_ANONFTP_026 ;
extern char* PARSE_ANONFTP_027 ;
extern char* PARSE_ANONFTP_028 ;
extern char* PARSE_ANONFTP_029 ;
/* net_anonftp.c */
extern char* NET_ANONFTP_001 ;
extern char* NET_ANONFTP_002 ;
extern char* NET_ANONFTP_003 ;
extern char* NET_ANONFTP_004 ;
extern char* NET_ANONFTP_005 ;
extern char* NET_ANONFTP_006 ;
extern char* NET_ANONFTP_007 ;
extern char* NET_ANONFTP_008 ;
extern char* NET_ANONFTP_009 ;
extern char* NET_ANONFTP_010 ;
extern char* NET_ANONFTP_011 ;
extern char* NET_ANONFTP_012 ;
extern char* NET_ANONFTP_013 ;
extern char* NET_ANONFTP_014 ;
extern char* GET_ANONFTP_SITE_001 ;
extern char* GET_ANONFTP_SITE_002 ;
extern char* GET_ANONFTP_SITE_003 ;
extern char* GET_ANONFTP_SITE_004 ;
extern char* GET_ANONFTP_SITE_005 ;
extern char* GET_ANONFTP_SITE_006 ;
extern char* GET_ANONFTP_SITE_007 ;
extern char* GET_ANONFTP_SITE_008 ;
extern char* GET_ANONFTP_SITE_009 ;
extern char* GET_ANONFTP_SITE_010 ;
extern char* GET_ANONFTP_SITE_011 ;
extern char* GET_ANONFTP_SITE_012 ;
extern char* GET_ANONFTP_SITE_013 ;
extern char* GET_ANONFTP_SITE_014 ;
extern char* GET_ANONFTP_SITE_015 ;
extern char* GET_ANONFTP_SITE_016 ;
extern char* GET_ANONFTP_SITE_017 ;
extern char* GET_ANONFTP_SITE_018 ;
extern char* GET_ANONFTP_SITE_019 ;
extern char* GET_ANONFTP_SITE_020 ;
extern char* SEND_ANONFTP_SITE_001;
extern char* SEND_ANONFTP_SITE_002;
extern char* SEND_ANONFTP_SITE_003;
extern char* SEND_ANONFTP_SITE_004;
extern char* SEND_ANONFTP_SITE_005;
extern char* SEND_ANONFTP_SITE_006;
extern char* SEND_ANONFTP_SITE_007;
extern char* SEND_ANONFTP_SITE_008;
extern char* SEND_ANONFTP_SITE_009;
extern char* SEND_ANONFTP_SITE_010;
extern char* SEND_ANONFTP_SITE_011;
extern char* SEND_ANONFTP_SITE_012;
extern char* COPY_PARSER_TO_XDR_001;
extern char* COPY_PARSER_TO_XDR_002;
extern char* COPY_PARSER_TO_XDR_003;
extern char* COPY_PARSER_TO_XDR_004;
extern char* COPY_XDR_TO_PARSER_001;
extern char* COPY_XDR_TO_PARSER_002;
extern char* COPY_XDR_TO_PARSER_003;
extern char* COPY_XDR_TO_PARSER_004;
/* update_anonftp.c */
extern char* UPDATE_ANONFTP_001 ;
extern char* UPDATE_ANONFTP_002 ;
extern char* UPDATE_ANONFTP_003 ;
extern char* UPDATE_ANONFTP_004 ;
extern char* UPDATE_ANONFTP_005 ;
extern char* UPDATE_ANONFTP_006 ;
extern char* UPDATE_ANONFTP_007 ;
extern char* UPDATE_ANONFTP_008 ;
extern char* UPDATE_ANONFTP_009 ;
extern char* UPDATE_ANONFTP_010 ;
extern char* UPDATE_ANONFTP_011 ;
extern char* UPDATE_ANONFTP_012 ;
extern char* UPDATE_ANONFTP_013 ;
extern char* UPDATE_ANONFTP_014 ;
extern char* UPDATE_ANONFTP_015 ;
extern char* UPDATE_ANONFTP_016 ;
extern char* UPDATE_ANONFTP_017 ;
extern char* UPDATE_ANONFTP_018 ;
extern char* UPDATE_ANONFTP_019 ;
extern char* UPDATE_ANONFTP_020 ;
extern char* UPDATE_ANONFTP_021 ;
extern char* UPDATE_ANONFTP_022 ;
extern char* UPDATE_ANONFTP_023 ;
extern char* UPDATE_ANONFTP_024 ;
extern char* UPDATE_ANONFTP_025 ;
extern char* UPDATE_ANONFTP_026 ;
extern char* UPDATE_ANONFTP_027 ;
extern char* UPDATE_ANONFTP_028 ;
extern char* UPDATE_ANONFTP_029 ;
extern char* UPDATE_ANONFTP_030 ;
extern char* UPDATE_ANONFTP_031 ;
extern char* UPDATE_ANONFTP_032 ;
extern char* UPDATE_ANONFTP_033 ;
/* check_anonftp.c */
extern char* CHECK_ANONFTP_001 ;
extern char* CHECK_ANONFTP_002 ;
extern char* CHECK_ANONFTP_003 ;
extern char* CHECK_ANONFTP_004 ;
extern char* CHECK_ANONFTP_005 ;
extern char* CHECK_ANONFTP_006 ;
extern char* CHECK_ANONFTP_007 ;
extern char* CHECK_ANONFTP_008 ;
extern char* CHECK_ANONFTP_009 ;
extern char* CHECK_ANONFTP_010 ;
extern char* CHECK_INDIV_001 ;
extern char* CHECK_INDIV_002 ;
extern char* CHECK_INDIV_003 ;
extern char* CHECK_INDIV_004 ;
extern char* CHECK_INDIV_005 ;
extern char* CHECK_INDIV_006 ;
extern char* CHECK_INDIV_007 ;
extern char* CHECK_INDIV_008 ;
extern char* CHECK_INDIV_009 ;
extern char* CHECK_INDIV_010 ;
extern char* CHECK_INDIV_011 ;
extern char* CHECK_INDIV_012 ;
extern char* CHECK_INDIV_013 ;
extern char* CHECK_INDIV_014 ;
extern char* CHECK_INDIV_015 ;
extern char* CHECK_INDIV_016 ;
extern char* CHECK_INDIV_017 ;
extern char* CHECK_INDIV_018 ;
extern char* CHECK_INDIV_019 ;
extern char* CHECK_INDIV_020 ;
extern char* CHECK_INDIV_021 ;
extern char* CHECK_INDIV_022 ;
#endif

View File

@ -0,0 +1,127 @@
/* new_Info_cell.c */
char* NEW_INFO_CELL_001 = "Error malloc'ing %ld bytes";
/* input.c */
char* INPUT_001 = "Error from fgets()";
/* output.c */
char* PRINT_CORE_INFO_001 = "Error fwrite'ing parser_entry_t structure" ;
char* PRINT_CORE_INFO_002 = "Error fwrite'ing file name";
char* PRINT_CORE_INFO_003 = "Error fwrite'ing padding";
/* parse.c */
char* PARSE_ANONFTP_001 = "Can't open file %s for reading";
char* PARSE_ANONFTP_002 = "Can't open file %s for writing";
char* PARSE_ANONFTP_003 = "Error from read_header() file %s";
char* PARSE_ANONFTP_004 = "Can't initialize line parser";
char* PARSE_ANONFTP_005 = "Error from set_elt_type()";
char* PARSE_ANONFTP_006 = "Can't initialize directory stack";
char* PARSE_ANONFTP_007 = "Error trying to initialize root directory";
char* PARSE_ANONFTP_008 = "Unexpected %s line #%d in listing";
char* PARSE_ANONFTP_009 = "Error initializing directory stack with root directory";
char* PARSE_ANONFTP_010 = "Unknown state = '%d' on line #%d";
char* PARSE_ANONFTP_011 = "Error from S_handle_file() on line #%d: aborting";
char* PARSE_ANONFTP_012 = "Error from handle_dir_start() on line #%d: aborting";
char* PARSE_ANONFTP_013 = "Unknown state = '%d' on line #%d";
char* PARSE_ANONFTP_014 = "Error at line #%d: '%s'";
char* PARSE_ANONFTP_015 = "Error from output_header(): aborting";
char* PARSE_ANONFTP_016 = "Error from check_stack() on line #%d: aborting";
char* PARSE_ANONFTP_017 = "Can't open default log file";
char* PARSE_ANONFTP_018 = "Can't open log file %s";
char* PARSE_ANONFTP_019 = "Trying to figure out the root_dir %s";
char* PARSE_ANONFTP_020 = "Cannot figure out root_dir due to usage of standard streams";
char* PARSE_ANONFTP_021 = "Cannot determine the root_dir";
char* CHECK_STACK_001 = "Expected listing for the directory '%s' at the end";
char* CHECK_STACK_002 = "Error removing queue element from top of stack";
char* HANDLE_DIR_START_001 = "Error from S_split_dir()";
char* HANDLE_DIR_START_002 = "Error from pop() while looking for non-empty queue";
char* HANDLE_DIR_START_003 = "directory '";
char* HANDLE_DIR_START_004 = "' was not previously declared.\n";
char* HANDLE_DIR_START_005 = "Error removing queue element from top of stack";
char* HANDLE_DIR_START_006 = "Error from push()";
char* HANDLE_DIR_START_007 = "Error expected listing for directory %s on line %d";
char* HANDLE_FILE_001 = "Error allocating space for parser record";
char* HANDLE_FILE_002 = "Error from S_file_parse(), line %d";
char* HANDLE_FILE_003 = "Error strdup'ing directory name";
char* HANDLE_FILE_004 = "Error adding directory to queue";
char* HANDLE_FILE_005 = "Error strdup'ing file name";
char* HANDLE_FILE_006 = "Error from write_header()";
char* PARSER_OUTPUT_001 = "Error from first_elt()";
char* PARSER_OUTPUT_002 = "Error from print_core_info()";
char* USAGE_001 = "Usage: %s [-h] [-i <input-file>] [-o <output-file>] [-p <prep-dir>] [-r <root-dir>]";
/* queue.c */
char* NEW_QUEUE_ELT_001 = "Error allocating %d bytes for new queue element";
char* NEW_QUEUE_ELT_002 = "Error from init_Info_cell()";
/* stack.c */
char* INIT_STACK_001 = "Root directory '%s' doesn't match pattern";
char* INIT_STACK_002 = "Error from S_split_dir()";
char* INIT_STACK_003 = "Error strdup'ing '%s'";
char* INIT_STACK_004 = "Error from new_Info_cell()";
char* INIT_STACK_005 = "Error from push()";
char* NEW_STACK_001 = "Error allocating %d bytes for new stack element";
char* POP_001 = "Stack is empty";
char* POP_002 = "Queue is not empty";
char* POP_003 = "Error from dispose_Info_cell()";
char* PRINT_STACK_001 = "Stack is empty";
char* PUSH_001 = "Error from new_Stack()";
/* unix.c */
char* U_S_FILE_PARSE_001 = "Error looking for white space after %s";
char* U_S_FILE_PARSE_002 = "Missing file name";
char* U_S_FILE_PARSE_003 = "Error from ";
char* U_S_FILE_PARSE_004 = "Error extracting field";
char* U_S_FILE_PARSE_005 = "Error from S_file_type()";
char* U_S_FILE_PARSE_006 = "can't find ` -> ' in name field of `%s' (line #%d)";
char* S_SPLIT_DIR_001 = "Expected ':' at end of path, but found '%c'";
/* unix2.c */
char* U2DB_TIME_001 = "Error in date '%s'";
char* U2DB_TIME_002 = "Error in time '%s'";
char* U2DB_TIME_003 = "Error in year '%s'";
char* U2DB_TIME_004 = "Day-of-month or year value error in '%s %s %s'";
char* U2DB_TIME_005 = "Hour or minute value error in '%s'";
char* U2DB_TIME_006 = "Error from timelocal()";
char* U2DB_TIME_007 = "Error from timegm()";
char* U2DB_PERM_001 = "Unknown permission character %c, line %s";
/* vms.c */
char* S_DUP_DIR_NAME_001 = "'%S' doesn't contain a '.'";
char* V_S_FILE_PARSE_001 = "Error looking for white space after %s";
char* V_S_FILE_PARSE_002 = "Error extracting field";
char* V_S_FILE_PARSE_003 = "Error from S_file_type()";
char* S_FILE_TYPE_001 = "Can't find '.' in file name '%s'";
/* vms2.c */
char* V2DB_DATE_001 = "Error in date '%s'";
char* V2DB_DATE_002 = "Error in time '%s'";
char* V2DB_DATE_003 = "Day-of-month or year value error in '%s'";
char* V2DB_DATE_004 = "Hour or minute value error in '%s'";
char* V2DB_DATE_005 = "Error from timegm()";
char* V2DB_ONE_SET_PERM_001 = "Unexpected character ('%c') in permissions '%s'";

View File

@ -0,0 +1,123 @@
extern char* NEW_INFO_CELL_001 ;
extern char* INPUT_001 ;
/* output.c */
extern char* PRINT_CORE_INFO_001 ;
extern char* PRINT_CORE_INFO_002 ;
extern char* PRINT_CORE_INFO_003 ;
/* parse.c */
extern char* PARSE_ANONFTP_001 ;
extern char* PARSE_ANONFTP_002 ;
extern char* PARSE_ANONFTP_003 ;
extern char* PARSE_ANONFTP_004 ;
extern char* PARSE_ANONFTP_005 ;
extern char* PARSE_ANONFTP_006 ;
extern char* PARSE_ANONFTP_007 ;
extern char* PARSE_ANONFTP_008 ;
extern char* PARSE_ANONFTP_009 ;
extern char* PARSE_ANONFTP_010 ;
extern char* PARSE_ANONFTP_011 ;
extern char* PARSE_ANONFTP_012 ;
extern char* PARSE_ANONFTP_013 ;
extern char* PARSE_ANONFTP_014 ;
extern char* PARSE_ANONFTP_015 ;
extern char* PARSE_ANONFTP_016 ;
extern char* PARSE_ANONFTP_017 ;
extern char* PARSE_ANONFTP_018 ;
extern char* PARSE_ANONFTP_019 ;
extern char* PARSE_ANONFTP_020 ;
extern char* PARSE_ANONFTP_021 ;
extern char* CHECK_STACK_001 ;
extern char* CHECK_STACK_002 ;
extern char* HANDLE_DIR_START_001 ;
extern char* HANDLE_DIR_START_002 ;
extern char* HANDLE_DIR_START_003 ;
extern char* HANDLE_DIR_START_004 ;
extern char* HANDLE_DIR_START_005 ;
extern char* HANDLE_DIR_START_006 ;
extern char* HANDLE_DIR_START_007 ;
extern char* HANDLE_FILE_001 ;
extern char* HANDLE_FILE_002 ;
extern char* HANDLE_FILE_003 ;
extern char* HANDLE_FILE_004 ;
extern char* HANDLE_FILE_005 ;
extern char* HANDLE_FILE_006 ;
extern char* PARSER_OUTPUT_001 ;
extern char* PARSER_OUTPUT_002 ;
extern char* USAGE_001 ;
/* queue.c */
extern char* NEW_QUEUE_ELT_001 ;
extern char* NEW_QUEUE_ELT_002 ;
/* stack.c */
extern char* INIT_STACK_001 ;
extern char* INIT_STACK_002 ;
extern char* INIT_STACK_003 ;
extern char* INIT_STACK_004 ;
extern char* INIT_STACK_005 ;
extern char* NEW_STACK_001 ;
extern char* POP_001 ;
extern char* POP_002 ;
extern char* POP_003 ;
extern char* PRINT_STACK_001 ;
extern char* PUSH_001 ;
/* unix.c */
extern char* U_S_FILE_PARSE_001 ;
extern char* U_S_FILE_PARSE_002 ;
extern char* U_S_FILE_PARSE_003 ;
extern char* U_S_FILE_PARSE_004 ;
extern char* U_S_FILE_PARSE_005 ;
extern char* U_S_FILE_PARSE_006 ;
extern char* S_SPLIT_DIR_001 ;
/* unix2.c */
extern char* U2DB_TIME_001 ;
extern char* U2DB_TIME_002 ;
extern char* U2DB_TIME_003 ;
extern char* U2DB_TIME_004 ;
extern char* U2DB_TIME_005 ;
extern char* U2DB_TIME_006 ;
extern char* U2DB_TIME_007 ;
extern char* U2DB_PERM_001 ;
/* vms.c */
extern char* S_DUP_DIR_NAME_001 ;
extern char* V_S_FILE_PARSE_001 ;
extern char* V_S_FILE_PARSE_002 ;
extern char* V_S_FILE_PARSE_003 ;
extern char* S_FILE_TYPE_001 ;
/* vms2.c */
extern char* V2DB_DATE_001 ;
extern char* V2DB_DATE_002 ;
extern char* V2DB_DATE_003 ;
extern char* V2DB_DATE_004 ;
extern char* V2DB_DATE_005 ;
extern char* V2DB_ONE_SET_PERM_001 ;

View File

@ -0,0 +1,41 @@
#ifndef LINE_TYPE_H
#define LINE_TYPE_H
#include "site_file.h"
#ifdef __STDC__
extern char *S_dup_dir_name(const char *name) ;
extern char *S_file_parse(char *in, parser_entry_t *pe, int *is_dir) ;
extern int S_file_type(const char *s, int *is_dir) ;
extern int S_handle_file(char *line, int state) ;
extern int S_init_parser(void) ;
extern int S_line_type(const char *line) ;
extern int S_split_dir(char *str, char *prep_dir, int *dev, int *n, char ***p) ;
#else
extern char *S_dup_dir_name(/* const char *name */) ;
extern char *S_file_parse(/* char *in, parser_entry_t *pe, int *is_dir */) ;
extern int S_file_type(/* const char *s, int *is_dir */) ;
extern int S_handle_file(/* char *line, int state */) ;
extern int S_init_parser(/* void */) ;
extern int S_line_type(/* const char *line */) ;
extern int S_split_dir(/* char *str, char *prep_dir, int *dev, int *n, char ***p */) ;
#endif
#define L_BLANK 0
#define L_CONT 1
#define L_DIR_START 2
#define L_ERROR 3
#define L_FILE 4
#define L_PARTIAL 5
#define L_TOTAL 6
#define L_UNREAD 7
#define L_UNKNOWN 8 /* code depends on this being the last valid value */
#define L_NUM_ELTS (L_UNKNOWN + 1)
#define L_INTERN_ERR L_NUM_ELTS
#endif

View File

@ -0,0 +1,96 @@
/*
Note: the debugging routines use the file /usr/lib/debug/malloc.o.
*/
#ifdef MEMORY_DEBUG
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define DEBUG_LEVEL 2
#ifdef __STDC__
extern void *memcpy(void *s1, const void *s2, size_t n) ; /* lacking real ANSI includes */
extern int malloc_debug(int level) ;
extern int malloc_verify(void) ;
#else
extern void *memcpy(/* void *s1, const void *s2, size_t n */) ; /* lacking real ANSI includes */
extern int malloc_debug(/* int level */) ;
extern int malloc_verify(/* void */) ;
#endif
static int debug_level = -1 ;
int
Free(ptr)
void *ptr ;
{
int rval ;
if( ! (rval = (free)(ptr)))
{
error(A_SYSERR, "Free", "error from free(0x%lx)", (long)ptr) ;
}
else
{
error(A_SYSERR, "Free", "free(0x%lx)", (long)ptr) ;
}
return rval ;
}
void *
Malloc(size)
size_t size ;
{
void *rval ;
if(debug_level == -1)
{
error(A_SYSERR, "Malloc", "setting debug level to %d", DEBUG_LEVEL) ;
debug_level = DEBUG_LEVEL ;
malloc_debug(debug_level) ;
}
if((rval = (malloc)(size)) == (void *)0)
{
error(A_SYSERR, "Malloc", "failed to malloc %ld bytes", (long)size) ;
}
else
{
error(A_SYSERR, "Malloc", "malloc\'ed %ld bytes at location 0x%lx", (long)size,
(long)rval) ;
}
return rval ;
}
void *
Memcpy(dst, src, size)
void *dst ;
void *src ;
size_t size ;
{
void *rval ;
if((rval = (memcpy)(dst, src, size)) != dst)
{
error(A_ERR, "Memcpy", "error from memcpy(%ld, %ld, %ld)",(long)dst, (long)src,
(long)size) ;
}
else
{
error(A_ERR, "Memcpy", "memcpy(%ld, %ld, %ld) successful", (long)dst, (long)src,
(long)size) ;
}
return rval ;
}
#endif

View File

@ -0,0 +1,37 @@
#ifndef MEM_DEBUG_H
#define MEM_DEBUG_H
#ifdef __STDC__
#include <stddef.h>
#endif
#ifdef MEMORY_DEBUG
#define free Free
#define malloc Malloc
#define memcpy Memcpy
#ifdef __STDC__
extern int Free(void *ptr) ;
extern void *Malloc(size_t size) ;
extern void *Memcpy(void *dst, void *src, size_t size) ;
#else
extern int Free(/* void *ptr */) ;
extern void *Malloc(/* size_t size */) ;
extern void *Memcpy(/* void *dst, void *src, size_t size */) ;
#endif
#define mck \
do { \
fprintf(stderr, "%s: malloc_verify at line %d in file %s: ", prog, __LINE__, __FILE__) ; \
fprintf(stderr, "%s\n", malloc_verify() ? "okay" : "failed") ; \
} while(0)
#else
#define mck
#endif
#endif

View File

@ -0,0 +1,373 @@
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include "../regex/regexp.h"
#include "defines.h"
#include "parser_file.h"
#include "parse.h"
#include "utils.h"
#include "queue.h"
#include "stack.h"
#include "output.h"
#include "line_type.h"
#include "storage.h"
#include "pars_ent_holder.h"
#include "unix2.h"
#include "error.h"
#include "lang_parsers.h"
#ifdef SOLARIS
#include "protos.h"
#endif
#define S_BLANK "^$"
#define S_CONT (regexp *)0 ;
#define S_DIR_START "^/?[^/]+(/[^/]+)*:$"
#define S_ERROR (regexp *)0 ;
#define S_FILE "^[-d][[][-R][-W][-C][-E][-M][-F][-A][]][ \t]+"
#define S_PARTIAL (regexp *)0 ;
#define S_TOTAL "^total:[ \t]+[0-9]+"
#define S_UNREAD "^[^ \t]+[ \t]+unreadable$"
#define S_UNKNOWN (regexp *)0 ;
enum /* declared as enum to make debugging easier */
{
F_PERM = 0,
F_LINKS,
F_OWNER,
F_GROUP,
F_SIZE,
F_MONTH,
F_DAY,
F_T_Y, /* time (16:36) or year (1992) */
F_NAME,
UNIX_NUM_FLDS /* this must be last */
} ;
static regexp *re[L_NUM_ELTS] ;
static int leading_blanks = -1;
char *S_dup_dir_name(name)
const char *name ;
{
return strdup(name) ;
}
/*
Given a file line (see below for example) produce a core site entry
and return a pointer to the file name. Return a null pointer upon
an error.
The input string will be overwritten.
An input line looks something like:
-rw------- 1 news 1630 Mar 18 16:15 #alt.music.alternative~
as well, a group name may be present and/or the time may be specified
differently:
-rw-r--r-- 1 news 12 Jul 11 1991 .rhosts
or
-rw-r--r-- 1 news news 12 Jul 11 1991 .rhosts
Then again, we may have a device with major and minor numbers in place of
the size:
crw-rw-rw- 1 0 1 3, 12 Mar 19 17:03 zero
*/
char *S_file_parse(in, pe, is_dir)
char *in ;
parser_entry_t *pe ;
int *is_dir ;
{
char *field[UNIX_NUM_FLDS] ;
char *p = in ;
int is_symlink = 0;
int num_blanks = 0;
ptr_check(in, char, "S_file_parse", (char *)0) ;
ptr_check(pe, parser_entry_t, "S_file_parse", (char *)0) ;
#define try_get_field(fld, instr, fldname) \
do \
{ \
instr += strspn(instr, WHITE_STR) ; \
if((field[fld] = strsep(&instr, WHITE_STR)) == (char *)0) \
{ \
/* "Error looking for white space after %s" */\
error(A_ERR, "S_file_parse", U_S_FILE_PARSE_001, fldname) ; \
return (char *)0 ; \
} \
} while(0)
try_get_field(F_PERM, p, "permissions") ;
try_get_field(F_LINKS, p, "links") ;
try_get_field(F_OWNER, p, "owner") ;
if(*field[F_PERM] == 'b' || *field[F_PERM] == 'c') /* devices */
{
try_get_field(F_GROUP, p, "group or major number") ;
if(*(field[F_GROUP] + strlen(field[F_GROUP]) - 1) == ',') /* is major number */
{
/* there is no group -- toss the major and minor numbers */
try_get_field(F_GROUP, p, "minor number") ;
field[F_GROUP] = (char *)0 ;
}
else /* is group */
{
/* there is a group -- still toss the major and minor numbers */
try_get_field(F_NAME, p, "major number") ;
try_get_field(F_NAME, p, "minor number") ;
}
field[F_SIZE] = "0" ;
try_get_field(F_MONTH, p, "month") ;
}
else /* non-devices */
{
is_symlink = *field[F_PERM] == 'l';
try_get_field(F_GROUP, p, "group or size") ; /* may be size */
try_get_field(F_SIZE, p, "size or month") ; /* may be month */
if(isdigit(*field[F_SIZE])) /* there was a group field */
{
try_get_field(F_MONTH, p, "month") ;
}
else /* no group field -- group was size, size was month */
{
field[F_MONTH] = field[F_SIZE] ;
field[F_SIZE] = field[F_GROUP] ;
field[F_GROUP] = (char *)0 ;
}
}
try_get_field(F_DAY, p, "day") ;
try_get_field(F_T_Y, p, "time or year") ;
num_blanks = strspn(p, WHITE_STR); /* Assume that there is 1 separating */
if ( leading_blanks > num_blanks ) {
leading_blanks = num_blanks;
error(A_INFO,"S_file_parse", "Confused by leading blank characters, will restart and try to be more intelligent !");
return 0;
}
if ( leading_blanks == -1 )
leading_blanks = num_blanks;
p+= leading_blanks;
field[F_NAME] = p ;
if(*field[F_NAME] == '\0')
{
/* "Missing file name" */
error(A_ERR, "S_file_parse", U_S_FILE_PARSE_002) ;
return (char *)0 ;
}
/*
If the file is a symbolic link, put a nul at the first occurrence
of " -> ".
*/
if (is_symlink)
{
char *p;
if ( ! (p = strstr(field[F_NAME], " -> ")))
{
error(A_WARN, "S_file_parse", U_S_FILE_PARSE_006, in, line_num());
}
else
{
*p = '\0';
}
}
#ifdef __STDC__
#define try_cvt_str(s) if( ! (s)) do { error(A_ERR, "S_file_parse", "Error from " #s "\n") ; return (char *)0 ; } while(0)
#else
/* "Error extracting field" */
#define try_cvt_str(s) if( ! (s)) do { error(A_ERR, "S_file_parse", U_S_FILE_PARSE_004) ; return (char *)0 ; } while(0)
#endif
try_cvt_str(u2db_perm(field[F_PERM], &pe->core)) ;
try_cvt_str(u2db_owner(field[F_OWNER], field[F_GROUP], &pe->core)) ;
try_cvt_str(u2db_size(field[F_SIZE], &pe->core)) ;
try_cvt_str(u2db_time(field[F_MONTH], field[F_DAY], field[F_T_Y], &pe->core)) ;
pe->slen = strlen(field[F_NAME]) ; /* when writing we don't include the nul terminator */
/* Is it an entry for a directory? */
if( ! S_file_type(field[F_PERM], is_dir))
{
/* "Error from S_file_type()" */
error(A_ERR, "S_file_parse", U_S_FILE_PARSE_005) ;
return (char *)0 ;
}
return field[F_NAME] ;
#undef try_get_field
#undef try_cvt_str
}
int S_file_type(s, is_dir)
const char *s ;
int *is_dir ;
{
ptr_check(s, char, "S_file_type", 0) ;
ptr_check(is_dir, int, "S_file_type", 0) ;
*is_dir = ((*s == 'd') || (*s == 'D'));
return 1 ;
}
int S_init_parser()
{
re[L_BLANK] = regcomp(S_BLANK) ;
re[L_CONT] = S_CONT ;
re[L_DIR_START] = regcomp(S_DIR_START) ;
re[L_ERROR] = S_ERROR ;
re[L_FILE] = regcomp(S_FILE) ;
re[L_PARTIAL] = S_PARTIAL ;
re[L_TOTAL] = regcomp(S_TOTAL) ;
re[L_UNREAD] = regcomp(S_UNREAD) ;
re[L_UNKNOWN] = S_UNKNOWN ;
return 1 ;
}
#ifdef DEBUG
# define dbg_show(t) error(A_INFO,"(unknown)", "D: %s '%s'\n", t, line) ;
#else
# define dbg_show(t) /* nothing */
#endif
int S_line_type(line)
const char *line ;
{
ptr_check(line, char, "S_line_type", L_INTERN_ERR) ;
if(regexec(re[L_FILE], line))
{
dbg_show("file") ;
return L_FILE ;
}
else if(regexec(re[L_BLANK], line))
{
dbg_show("blank") ;
return L_BLANK ;
}
else if(regexec(re[L_DIR_START], line))
{
dbg_show("dir_start") ;
return L_DIR_START ;
}
else if(regexec(re[L_TOTAL], line))
{
dbg_show("total") ;
return L_TOTAL ;
}
else if(regexec(re[L_UNREAD], line))
{
dbg_show("unreadable") ;
return L_UNREAD ;
}
else
{
dbg_show("unknown") ;
return L_UNKNOWN ;
}
}
/*
Split a directory path name into its components.
Return a pointer to an array of pointers into 'str', where each element
points to the start of a file name in the path. The number of path elements
will be returned in 'n'. If this type of listing has device name prefixes,
then '*dev' will point to it.
The string will be overwritten.
If an error occurs return a null pointer.
*/
int S_split_dir(str, prep_dir, dev, n, p)
char *str ;
char *prep_dir ;
int *dev ;
int *n ;
char ***p ;
{
static char *path[MAX_PATH_ELTS + 1] ;
char *s = str ;
int i = 0 ;
ptr_check(str, char, "S_split_dir", 0) ;
ptr_check(dev, int, "S_split_dir", 0) ;
ptr_check(n, int, "S_split_dir", 0) ;
ptr_check(p, char **, "S_split_dir", 0) ;
*dev = 0 ; /* UNIX sites don't have a device name prefix */
if(prep_dir != (char *)0)
{
path[i++] = prep_dir ;
}
if(*s == '/') /* any leading / is meaningless to us */
{
s++ ;
}
path[i++] = s ;
while(*s != '\0')
{
if(*s != '/')
{
*s = tolower(*s);
s++ ;
}
else
{
*s++ = '\0' ;
path[i++] = s ;
}
}
if(*--s == ':') /* knock off the trailing colon from the file name */
{
*s = '\0' ;
}
else
{
/* "Expected ':' at end of path, but found '%c'" */
error(A_ERR, "S_split_dir", S_SPLIT_DIR_001, *s) ;
return 0 ;
}
*n = i ;
*p = path ;
return 1 ;
}
int set_blanks(num)
int num;
{
if (leading_blanks != -1 )
leading_blanks -= num;
}

View File

@ -0,0 +1,331 @@
#include <stdio.h>
#include <string.h>
#include <time.h>
#if defined(AIX) || defined(SOLARIS)
#include <stdlib.h>
#include <ctype.h>
#endif
#include "defines.h"
#include "parse.h"
#include "site_file.h"
#include "unix2.h"
#include "error.h"
#include "lang_parsers.h"
/*
'mon' points to the first character of the month string.
E.g. "Mar"
'day' points to the first character of the day string.
E.g. "25"
't_y' points to the first character of the "time or year" string.
E.g. "13:51" or "1992"
Assume: time_t is the number of seconds since 00:00:00 Jan 1, 1970 GMT. ANSI does not
guarantee this.
*/
int
u2db_time(mon, day, t_y, cse)
const char *mon ;
const char *day ;
const char *t_y ;
core_site_entry_t *cse ;
{
extern int local_timezone;
static char *months[13] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul",
"Aug", "Sep", "Oct", "Nov", "Dec", (char *)0 } ;
static struct tm *mytime;
int dm ;
int hr ;
int m = 0 ;
int min ;
int y ;
struct tm bd_time ; /* broken down time */
time_t ltime;
time_t the_time ;
#if defined(AIX) || defined(SOLARIS)
extern long timezone;
#else
extern time_t time();
struct tm *our_time ; /* broken down time */
#endif
ptr_check(mon, char, "u2db_time", 0) ;
ptr_check(day, char, "u2db_time", 0) ;
ptr_check(t_y, char, "u2db_time", 0) ;
ptr_check(cse, core_site_entry_t, "u2db_time", 0) ;
if(mytime == (struct tm *) NULL){
the_time = time((time_t *) NULL);
if((mytime = (struct tm *) malloc(sizeof(struct tm))) == (struct tm *) NULL){
error(A_SYSERR, "u2db_time", "Can't malloc space for time structure");
return 0;
}
memcpy(mytime, gmtime(&the_time), sizeof(struct tm));
}
while(months[m] != (char *)0)
{
if(strncmp(mon, months[m], 4) == 0)
{
break ;
}
else
{
m++ ;
}
}
if(m == 12)
{
return 0 ;
}
if(sscanf(day, "%d", &dm) != 1)
{
/* "Error in date '%s'" */
error(A_ERR, "u2db_time", U2DB_TIME_001, day) ;
return 0 ;
}
if(t_y[2] == ':')
{
if(sscanf(t_y, "%2d:%2d", &hr, &min) != 2)
{
/* "Error in time '%s'" */
error(A_ERR, "u2db_time", U2DB_TIME_002, t_y) ;
return 0 ;
}
if(mytime -> tm_mon - m < 6 ){
if(mytime -> tm_mon - m < 0 )
y = mytime -> tm_year + 1900 - 1;
else
y = mytime -> tm_year + 1900;
}
else
y = mytime -> tm_year + 1900;
}
else
{
if(sscanf(t_y, "%d", &y) != 1)
{
/* "Error in year '%s'" */
error(A_ERR, "u2db_time", U2DB_TIME_003, t_y) ;
return 0 ;
}
hr = 0 ;
min = 0 ;
}
if(dm < 1 || dm > 31 || y < 1900)
{
/* "Day-of-month or year value error in '%s %s %s'" */
error(A_ERR, "u2db_time", U2DB_TIME_004, mon, day, t_y) ;
return 0 ;
}
#if defined(AIX) || defined(SOLARIS)
/* AIX can't handle dates less than 1970, so reset them to that */
if(y < 1970)
y = 1970;
#endif
if(hr < 0 || hr > 23 || min < 0 || min > 59)
{
/* "Hour or minute value error in '%s'" */
error(A_ERR, "u2db_time", U2DB_TIME_005, t_y) ;
return 0 ;
}
else
{
time_t timenow;
memset((void *)&bd_time, 0, sizeof bd_time) ;
bd_time.tm_sec = 0 ;
bd_time.tm_min = min ;
bd_time.tm_hour = hr ;
bd_time.tm_mday = dm ;
bd_time.tm_mon = m ;
bd_time.tm_year = y - 1900 ;
bd_time.tm_isdst = -1 ;
#if !defined(AIX) && !defined(SOLARIS)
timenow = time((time_t *) NULL);
our_time = localtime(&timenow);
ltime = our_time -> tm_gmtoff + local_timezone;
if((the_time = timelocal(&bd_time)) == -1)
{
/* "Error from timelocal()" */
error(A_ERR, "u2db_time", U2DB_TIME_006) ;
/* reset the time to "now" */
the_time = time((time_t) NULL);
}
#else
ltime = (timezone * timezone_sign()) + local_timezone;
if((the_time = mktime(&bd_time)) == -1)
{
/* "Error from timegm()" */
error(A_ERR, "u2db_time", U2DB_TIME_007) ;
return 0 ;
}
#endif
cse->date = the_time + ltime;
}
return 1 ;
}
int
u2db_links(v, cse)
const char *v ;
core_site_entry_t *cse ;
{
ptr_check(v, char, "u2db_links", 0) ;
ptr_check(cse, core_site_entry_t, "u2db_links", 0) ;
return 1 ;
}
int
u2db_name(v, cse)
const char *v ;
core_site_entry_t *cse ;
{
ptr_check(v, char, "u2db_name", 0) ;
ptr_check(cse, core_site_entry_t, "u2db_name", 0) ;
return 1 ;
}
int
u2db_owner(u, v, cse)
const char *u ;
const char *v ;
core_site_entry_t *cse ;
{
ptr_check(u, char, "u2db_owner", 0) ;
/* v (group) may be null */
ptr_check(cse, core_site_entry_t, "u2db_owner", 0) ;
return 1 ;
}
int
u2db_perm(v, cse)
const char *v ;
core_site_entry_t *cse ;
{
int i, j;
perms_t perms = 0 ;
ptr_check(v, char, "u2db_perm", 0) ;
ptr_check(cse, core_site_entry_t, "u2db_perm", 0) ;
for(i=0, j = 9 ; i < 9 ;i++, j--)
{
switch(v[j])
{
case 'R':
perms |= (0x01 << 2) | (0x01 << 5) | (0x01<< 8); /* like r--r--r-- */
break;
case 'W':
perms |= (0x01 << 1) | (0x01 << 4) | (0x01<<7); /* like -w--w--w- */
break;
case 'C':
perms |= (0x01 << 2) | (0x01 << 5) | (0x01<< 8); /* like r--r--r-- */
perms |= (0x01 << 1) | (0x01 << 4) | (0x01<<7); /* like -w--w--w- */
break ;
case 'F':
if ( CSE_IS_DIR((*cse)) ) {
perms |=( 0x01 << 0 | 0x01 << 3 | 0x01 << 6 );
}
break;
case 'E':
case 'M':
case 'A':
case '-':
case '[':
case ']':
break;
default:
/* "Unknown permission character %c, line %s" */
error(A_ERR, "u2db_perm", U2DB_PERM_001, v[j], v) ;
return 0 ;
}
}
cse->perms = perms ;
return 1 ;
}
int
u2db_size(v, cse)
const char *v ;
core_site_entry_t *cse ;
{
ptr_check(v, char, "u2db_size", 0) ;
ptr_check(cse, core_site_entry_t, "u2db_size", 0) ;
if( ! isdigit((int)*v))
{
return 0 ;
}
else
{
cse->size = atoi(v) ;
return 1 ;
}
}

View File

@ -0,0 +1,62 @@
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include "protos.h"
#include "parse.h"
#include "parser_file.h"
#include "output.h"
#include "lang_parsers.h"
#include "error.h"
/*
Write a parser entry, followd by the file name to the output file. The
file name is padded (with Satanic messages, when viewed backwards) to a
multiple of 4 bytes. The file name (when written) is not nul
terminated; the length field should reflect this.
*/
int
print_core_info(fp, pe,name)
FILE *fp ;
parser_entry_t *pe ;
char *name ;
{
char padding[PAD - 1] ;
int npad ;
ptr_check(fp, FILE, "print_core_info", 0) ;
ptr_check(pe, parser_entry_t, "print_core_info", 0) ;
ptr_check(name, char, "print_core_info", 0) ;
memset(padding, '\0', sizeof padding) ;
if(fwrite((void *)pe, sizeof *pe, (size_t)1, fp) != 1)
{
/* "Error fwrite'ing parser_entry_t structure" */
error(A_ERR, "print_core_info", PRINT_CORE_INFO_001);
return 0 ;
}
if(fwrite((void *)name, (size_t)pe->slen, (size_t)1, fp) != 1)
{
/* "Error fwrite'ing file name" */
error(A_ERR, "print_core_info", PRINT_CORE_INFO_002);
return 0 ;
}
if((npad = pe->slen % PAD) != 0)
{
if(fwrite((void *)padding, (size_t)(PAD - npad), (size_t)1, fp) != 1)
{
/* "Error fwrite'ing padding" */
error(A_ERR,"print_core_info", PRINT_CORE_INFO_003);
return 0 ;
}
}
return 1 ;
}

View File

@ -0,0 +1,12 @@
#ifndef OUTPUT_H
#define OUTPUT_H
#define PAD 4
#ifdef __STDC__
extern int print_core_info(FILE *fp, parser_entry_t *pe, char *name) ;
#else
extern int print_core_info(/* FILE *fp, parser_entry_t *pe, char *name */) ;
#endif
#endif

View File

@ -0,0 +1,13 @@
#ifndef PARS_ENT_HOLDER_H
#define PARS_ENT_HOLDER_H
#include "parser_file.h"
typedef struct
{
parser_entry_t pent ;
char *name ;
}
Pars_ent_holder ;
#endif

1029
archie/anonftp/parse/parse.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,73 @@
#ifndef DEFS_H
#define DEFS_H
#include "mem_debug.h"
#define MAX_FIELDS 16
#define MAX_LINE_LEN 512
#define MAX_PATH_ELTS 50
#define MAX_RE_LEN 512
#define WHITE_STR " \t"
#define DEV_WHITE_STR " \t"
/*
ANSI C.
*/
#if 0
#ifdef __STDC__
#ifndef PARAM_CHECK
# define ptr_check(ptr, type, func, ret_val)
#else
# define ptr_check(ptr, type, func, ret_val) \
do \
{ \
if((ptr) == (type *)0) \
{ \
fprintf(stderr, "%s: %s: parameter '" #ptr "' is a null pointer.\n", prog, func) ; \
return ret_val ; \
} \
} while(0)
#endif
extern char *prog ;
extern void regerr(int c) ;
typedef void *Void_ptr ;
#else
/*
K&R C.
*/
#ifndef PARAM_CHECK
# define ptr_check(ptr, type, func, ret_val)
#else
# define ptr_check(ptr, type, func, ret_val) \
do { if((ptr) == (type *)0) { \
fprintf(stderr, "%s: %s: a parameter is a null pointer.\n", prog, func) ; \
return ret_val ; \
} \
} while(0)
#endif
#endif
extern char *prog ;
extern void regerr(/* int c */) ;
#define const
typedef char *Void_ptr ;
#endif
#endif
extern int verbose ;
#define vfprintf if(verbose) fprintf

View File

@ -0,0 +1,723 @@
/*
* This file is copyright Bunyip Information Systems Inc., 1992. This file
* may not be reproduced, copied or transmitted by any means mechanical or
* electronic without the express written consent of Bunyip Information
* Systems Inc.
*
* $Id: parse_anonftp.c,v 2.0 1996/08/20 22:42:27 archrlse Exp $
*/
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#if !defined(AIX) && !defined(SOLARIS)
#include <vfork.h>
#endif
#include <sys/wait.h>
#include <time.h>
#include "typedef.h"
#include "header.h"
#include "db_files.h"
#include "error.h"
#include "files.h"
#include "lang_anonftp.h"
#include "master.h"
#include "protos.h"
/*
* parse_anonftp: handles the parsing of an anonftp listing, spawning the
* appropriate parser
argv, argc are used.
Parameters:
-i <input filename> Mandatory
-o <output filename> Mandatory
-t <tmp directory>
-f <filter program>
-M <master database pathname>
-h <host database pathname>
-l write to log file (default)
-L <log file>
*/
int verbose = 0;
char *prog;
int main(argc, argv)
int argc;
char *argv[];
{
#if 0
#ifdef __STDC__
extern int getopt(int, char **, char *);
extern time_t time(time_t *);
#else
extern int getopt();
extern time_t time();
#endif
#endif
extern int opterr;
extern char *optarg;
char **cmdline_ptr;
int cmdline_args;
int option;
/* Directory pathnames */
pathname_t master_database_dir;
pathname_t host_database_dir;
pathname_t tmp_dir;
/* log filename */
pathname_t logfile;
/* Filter and parser programs */
pathname_t filter_pgm;
pathname_t process_pgm;
pathname_t outname;
pathname_t outname2;
char **arglist;
int logging = 0;
int finished;
int erron = 0;
file_info_t *input_file = create_finfo();
file_info_t *output_file = create_finfo();
file_info_t *tmp_file = create_finfo();
char *str;
header_t header_rec;
int status, result;
char retr_list[MAX_ACCESS_COMM];
char retr_string[MAX_ACCESS_COMM];
char user[MAX_ACCESS_METHOD];
char pass[MAX_ACCESS_METHOD];
char acct[MAX_ACCESS_METHOD];
char root_dir[MAX_ACCESS_METHOD];
opterr = 0;
tmp_dir[0] = '\0';
host_database_dir[0] = master_database_dir[0] = filter_pgm[0] = '\0';
logfile[0] = '\0';
/* ignore argv[0] */
cmdline_ptr = argv + 1;
cmdline_args = argc - 1;
while((option = (int) getopt(argc, argv, "h:M:t:L:i:o:f:lv")) != EOF){
switch(option){
/* Log filename */
case 'L':
strcpy(logfile, optarg);
logging = 1;
cmdline_ptr += 2;
cmdline_args -= 2;
break;
/* master database directory */
case 'M':
strcpy(master_database_dir,optarg);
cmdline_ptr += 2;
cmdline_args -= 2;
break;
/* name of filter program */
case 'f':
strcpy(filter_pgm, optarg);
cmdline_ptr += 2;
cmdline_args -= 2;
break;
/* host database directory */
case 'h':
strcpy(host_database_dir,optarg);
cmdline_ptr += 2;
cmdline_args -= 2;
break;
/* input filename */
case 'i':
strcpy(input_file -> filename, optarg);
cmdline_ptr += 2;
cmdline_args -= 2;
break;
/* log output, default file */
case 'l':
logging = 1;
cmdline_ptr++;
cmdline_args--;
break;
/* output filename */
case 'o':
strcpy(output_file -> filename, optarg);
cmdline_ptr += 2;
cmdline_args -= 2;
break;
/* tmp directory */
case 't':
strcpy(tmp_dir,optarg);
cmdline_ptr += 2;
cmdline_args -= 2;
break;
/* verbose */
case 'v':
verbose = 1;
cmdline_ptr++;
cmdline_args--;
break;
}
}
if(logging){
if(logfile[0] == '\0'){
if(open_alog((char *) NULL, A_INFO, tail(argv[0])) == ERROR){
/* "Can't open default log file" */
error(A_ERR, "parse_anonftp", PARSE_ANONFTP_001);
exit(ERROR);
}
}
else{
if(open_alog(logfile, A_INFO, tail(argv[0])) == ERROR){
/* "Can't open log file %s" */
error(A_ERR, "parse_anonftp", PARSE_ANONFTP_002, logfile);
exit(ERROR);
}
}
}
/* Check to see that input and output filename were given */
if(input_file -> filename[0] == '\0'){
/* "No input file given" */
error(A_ERR,"parse_anonftp", PARSE_ANONFTP_003);
exit(ERROR);
}
if(output_file -> filename[0] == '\0'){
error(A_ERR,"parse_anonftp", PARSE_ANONFTP_004);
exit(ERROR);
}
if(set_master_db_dir(master_database_dir) == (char *) NULL){
/* "Error while trying to set master database directory"*/
error(A_ERR, "parse_anonftp", PARSE_ANONFTP_005);
exit(ERROR);
}
if(tmp_dir[0] == '\0')
sprintf(tmp_dir,"%s/%s",get_master_db_dir(), DEFAULT_TMP_DIR);
if(open_file(input_file, O_RDONLY) == ERROR){
/* "Can't open input file %s" */
error(A_ERR, "parse_anonftp", PARSE_ANONFTP_006, input_file -> filename);
exit(ERROR);
}
if(read_header(input_file -> fp_or_dbm.fp, &header_rec, (u32 *) NULL, 0, 1) == ERROR){
/* "Error reading header of input file %s" */
error(A_ERR, "parse_anonftp", PARSE_ANONFTP_007, input_file -> filename);
goto onerr;
}
if(header_rec.format != FRAW){
/* "Input file %s not in raw format. Cannot process" */
error(A_ERR,"parse_anonftp", PARSE_ANONFTP_008, input_file -> filename);
goto onerr;
}
/* Generate a "random" file name */
srand(time((time_t *) NULL));
for(finished = 0; !finished;){
sprintf(outname,"%s_%d%s%s", output_file -> filename, rand() % 100, SUFFIX_UPDATE, TMP_SUFFIX);
if(access(outname, R_OK | F_OK) == -1)
finished = 1;
}
str = get_tmp_filename(tmp_dir);
if(str)
strcpy(tmp_file -> filename, str);
else{
/* "Can't get temporary name for file %s" */
error(A_INTERR,"parse_anonftp", PARSE_ANONFTP_009, input_file -> filename);
goto onerr;
}
if(open_file(tmp_file, O_WRONLY) == ERROR){
/* "Can't open temporary file %s" */
error(A_ERR, "parse_anonftp", PARSE_ANONFTP_010, tmp_file -> filename);
goto onerr;
}
if ( header_rec.os_type == NOVELL ) {
retr_list[0] = retr_string[0] = user[0] = pass[0] = acct[0] = root_dir[0] = '\0';
/* Check what method is to be used to retrieve info */
if(HDR_GET_ACCESS_COMMAND(header_rec.header_flags)){
strcpy(retr_string, header_rec.access_command);
if(str_decompose(retr_string,NET_DELIM_CHAR,retr_list,user,pass,acct,root_dir) == ERROR){
/* "Unable to parse access command in header" */
do_error_header(tmp_file, output_file,0, &header_rec, SUFFIX_PARSE, PARSE_ANONFTP_029);
return(ERROR);
}
sprintf(retr_string,"%s:%s:%s:%s:%s",retr_list,user,pass,acct,root_dir);
}
}
if(write_header(tmp_file -> fp_or_dbm.fp, &header_rec, (u32 *) NULL, 0, 0) == ERROR){
/* "Error while writing header of output file" */
error(A_ERR, "parse_anonftp", PARSE_ANONFTP_011);
goto onerr;
}
switch(header_rec.os_type){
case UNIX_BSD:
if(filter_pgm[0] == '\0')
sprintf(filter_pgm,"%s/%s/%s%s_%s", get_archie_home(), DEFAULT_BIN_DIR, FILTER_PREFIX, header_rec.access_methods, OS_TYPE_UNIX_BSD);
break;
case VMS_STD:
if(filter_pgm[0] == '\0')
sprintf(filter_pgm,"%s/%s/%s%s_%s", get_archie_home(), DEFAULT_BIN_DIR, FILTER_PREFIX, header_rec.access_methods, OS_TYPE_VMS_STD);
break;
case NOVELL:
if(filter_pgm[0] == '\0')
sprintf(filter_pgm,"%s/%s/%s%s_%s", get_archie_home(), DEFAULT_BIN_DIR, FILTER_PREFIX, header_rec.access_methods, OS_TYPE_NOVELL);
break;
}
/* first fork the filter program */
#ifndef AIX
if((result = vfork()) == 0){
#else
if((result = fork()) == 0){
#endif
/* Make the input file the stdin of filter and tmp_file the stdout */
dup2(fileno(input_file -> fp_or_dbm.fp), 0);
dup2(fileno(tmp_file -> fp_or_dbm.fp), 1);
execlp(filter_pgm, filter_pgm, (char *) NULL);
/* if we've gotten here then the execlp didn't work */
/* "Can't execlp() filter program %s" */
error(A_SYSERR, "parse_anonftp", PARSE_ANONFTP_012, filter_pgm);
}
if(result == -1){
/* "Can't vfork() filter program %s" */
error(A_SYSERR,"parse_anonftp", PARSE_ANONFTP_013, filter_pgm);
goto onerr;
}
if(wait(&status) == -1){
/* "Error while in wait() for filter program %s" */
error(A_SYSERR,"parse_anonftp", PARSE_ANONFTP_014, filter_pgm);
goto onerr;
}
if(WIFEXITED(status) && WEXITSTATUS(status)){
/* "Filter program %s exited abnormally with exit code %d" */
error(A_ERR,"parse_anonftp", PARSE_ANONFTP_015, filter_pgm, WEXITSTATUS(status));
goto onerr;
}
if(WIFSIGNALED(status)){
/* "Filter program %s terminated abnormally with signal %d" */
error(A_ERR,"parse_anonftp", PARSE_ANONFTP_016, filter_pgm, WTERMSIG(status));
goto onerr;
}
if(close_file(input_file) == ERROR){
/* "Can't close input file %s" */
error(A_ERR, "parse_anonftp", PARSE_ANONFTP_017, input_file -> filename);
}
if(close_file(tmp_file) == ERROR){
/* "Can't close temporary file %s" */
error(A_ERR, "parse_anonftp", PARSE_ANONFTP_018, tmp_file -> filename);
}
if((arglist = (char **) malloc(MAX_NO_PARAMS * sizeof(char *))) == (char **) NULL){
/* "Can't malloc space for argument list" */
error(A_SYSERR, "parse_anonftp", PARSE_ANONFTP_027);
exit(ERROR);
}
switch(header_rec.os_type){
case UNIX_BSD:
sprintf(process_pgm,"%s/%s/%s%s_%s", get_archie_home(), DEFAULT_BIN_DIR, PARSE_PREFIX, header_rec.access_methods, OS_TYPE_UNIX_BSD);
break;
case VMS_STD:
sprintf(process_pgm,"%s/%s/%s%s_%s", get_archie_home(), DEFAULT_BIN_DIR, PARSE_PREFIX, header_rec.access_methods, OS_TYPE_VMS_STD);
break;
case NOVELL:
sprintf(process_pgm,"%s/%s/%s%s_%s", get_archie_home(), DEFAULT_BIN_DIR, PARSE_PREFIX, header_rec.access_methods, OS_TYPE_NOVELL);
break;
}
/* launch the parsing process */
if((result = fork()) == 0){
switch(header_rec.os_type){
char *logname;
int i;
case UNIX_BSD:
i = 0;
arglist[i++] = process_pgm;
arglist[i++] = "-r";
arglist[i++] = ".:";
arglist[i++] = "-p";
arglist[i++] = ".";
arglist[i++] = "-i";
arglist[i++] = tmp_file -> filename;
arglist[i++] = "-o";
arglist[i++] = outname;
logname = get_archie_logname();
if(logname[0]){
arglist[i++] = "-L";
arglist[i++] = logname;
}
if(verbose)
arglist[i++] = "-v";
arglist[i] = (char *) NULL;
if(verbose){
int j;
pathname_t holds;
pathname_t thold;
holds[0] = '\0';
for(j = 0; j < i; j++){
sprintf(thold, " %s", arglist[j]);
strcat(holds, thold);
}
error(A_INFO, "parse_anonftp", "Calling %s %s", process_pgm, holds);
}
execv(process_pgm, arglist);
break;
case VMS_STD:
i = 0;
arglist[i++] = process_pgm;
arglist[i++] = "-i";
arglist[i++] = tmp_file -> filename;
arglist[i++] = "-o";
arglist[i++] = outname;
logname = get_archie_logname();
if(logname[0]){
arglist[i++] = "-L";
arglist[i++] = logname;
}
if(verbose)
arglist[i++] = "-v";
arglist[i] = (char *) NULL;
if(verbose){
int j;
pathname_t holds;
pathname_t thold;
holds[0] = '\0';
for(j = 0; j < i; j++){
sprintf(thold, " %s", arglist[j]);
strcat(holds, thold);
}
error(A_INFO, "parse_anonftp", "Calling %s %s", process_pgm, holds);
}
execv(process_pgm, arglist);
break;
case NOVELL:
i = 0;
arglist[i++] = process_pgm;
arglist[i++] = "-i";
arglist[i++] = tmp_file -> filename;
arglist[i++] = "-o";
arglist[i++] = outname;
/* arglist[i++] = "-r";
arglist[i++] = ".:";
*/
arglist[i++] = "-r";
arglist[i++] = root_dir;
strcat(arglist[i-1],":");
logname = get_archie_logname();
if(logname[0]){
arglist[i++] = "-L";
arglist[i++] = logname;
}
if(verbose)
arglist[i++] = "-v";
arglist[i] = (char *) NULL;
if(verbose){
int j;
pathname_t holds;
pathname_t thold;
holds[0] = '\0';
for(j = 0; j < i; j++){
sprintf(thold, " %s", arglist[j]);
strcat(holds, thold);
}
error(A_INFO, "parse_anonftp", "Calling %s %s", process_pgm, holds);
}
execv(process_pgm, arglist);
break;
}
/* "Can't execv() parse program %s" */
error(A_SYSERR, "parse_anonftp", PARSE_ANONFTP_019, process_pgm);
goto onerr;
}
free(arglist);
if(result == -1){
/* "Can't vfork() parse program %s" */
error(A_SYSERR,"parse_anonftp", PARSE_ANONFTP_020, process_pgm);
goto onerr;
}
if(wait(&status) == -1){
/* "Error while in wait() for parse program %s" */
error(A_ERR,"parse_anonftp", PARSE_ANONFTP_021, process_pgm);
goto onerr;
}
if(WIFEXITED(status) && WEXITSTATUS(status)){
/* "Parse program %s exited abnormally with code %d" */
error(A_ERR,"parse_anonftp", PARSE_ANONFTP_022, process_pgm, WEXITSTATUS(status));
goto onerr;
}
if(WIFSIGNALED(status)){
/* "Parse program %s terminated abnormally with signal %d" */
error(A_ERR,"parse_anonftp", PARSE_ANONFTP_023, process_pgm, WTERMSIG(status));
goto onerr;
}
goto jumpos;
onerr:
erron = 1;
jumpos:
for(finished = 0; !finished;){
sprintf(outname2,"%s_%d%s", output_file -> filename, rand() % 100, SUFFIX_UPDATE);
if(access(outname2, R_OK | F_OK) == -1)
finished = 1;
}
if(rename(outname, outname2) == -1){
/* "Can't rename output file %s" */
error(A_SYSERR,"parse_anonftp", PARSE_ANONFTP_024, outname);
erron = 1;
}
/* Don't unlink files if there is an error in parsing */
if(!erron){
if(unlink(input_file -> filename) == -1){
/* "Can't unlink input file %s" */
error(A_SYSERR,"parse_anonftp", PARSE_ANONFTP_025, input_file -> filename);
erron = 1;
}
if(unlink(tmp_file -> filename) == -1){
/* "Can't unlink temporary file %s" */
error(A_SYSERR,"parse_anonftp", PARSE_ANONFTP_026, tmp_file -> filename);
erron = 1;
}
}
else{
/* Rename the tmp file to something more useful */
sprintf(outname2,"%s_%d%s", output_file -> filename, rand() % 100, SUFFIX_FILTERED);
if(rename(tmp_file -> filename, outname2) == -1){
/* "Can't rename failed temporary file %s to %s" */
error(A_SYSERR,"parse_anonftp", PARSE_ANONFTP_028, tmp_file -> filename, outname2);
}
}
if(erron)
exit(ERROR);
exit(A_OK);
return(A_OK);
}

View File

@ -0,0 +1,95 @@
.TH PARSER 1 "4 August 1992"
.SH NAME
parser \- generate input to the insertion routine from recursive listings
.SH SYNOPSIS
\fIsys_type\fB_parser
[
.B \-h
] [
.B \-i
.I input\-file
] [
.B \-o
.I output\-file
] [
.B \-p
.I prep\-dir
] [
.B \-r
.I root\-dir
]
.SH DESCRIPTION
.LP
\fIsys_type\fB_parser\fR describes a family of parsers, currenly with members
.B unix_parser
and
.BR vms_parser .
.PP
\fIsys_type\fB_parser\fR
reads a recursive directory listing obtained under the \fIsys_type\fR operating
system.
Its output is intended to be the input to the program which inserts site
listings into the archie(TM) database.
.SH OPTIONS
.LP
.TP 5n
.B \-h
No headers.
The listing is not expected to have a special header (normally used by all
programs in the database insertion pipeline), nor will it generate one on
output. This option can be used for debugging or to test raw (unprocessed) listings.
.TP 5n
.B \-i
Input.
The next argument is the name of the file containing the recursive listing. If
unspecified,
.I stdin
is assumed.
.TP 5n
.B \-o
Output.
The next argument is the name of the file to which the output will be written.
If unspecified,
.I stdout
is assumed.
.TP 5n
.B \-p
Prepended directory.
Currently, this is used only by the UNIX parser. The next argument is
prepended to the start of all \fIdirectory definitions\fR. For
example, an argument of `.' can be used to turn the \fIdirectory
definition\fR `bin:' into `./bin:', which is more easily digested by the parser.
.TP 5n
.B \-r
Root directory.
This is currently only used by the UNIX parser. The next argument is the name
the root directory from which the listing is assumed to be taken. This option
is often, but not always, used in conjunction with the
.B \-p
option, and is typically the same string, but with the trailing `/' replaced
with a `:'. For example, together these arguments might be `-r .: -p .'.
.TP 5n
.B \-v
Verbose.
Unless this option is given,
\fIsys_type\fB_parser\fR will emit no warnings or error messages. The only
indication that something has gone wrong will be the return code, and the
truncated (but valid) output.
.SH SEE ALSO
.BR foo (5),
.SH BUGS
Lots, probably.
.SH AUTHOR
The archie Group
.br
Bunyip Information Systems
.br
.br
Montr\o"\'e"al, Qu\o"\'e"bec, Canada

View File

@ -0,0 +1,145 @@
#include <stdio.h>
#include <stdlib.h> /* malloc? */
#include "defines.h"
#include "parse.h"
#include "stack.h"
#include "info_cell.h"
#include "queue.h"
#include "error.h"
#include "lang_parsers.h"
/*
Add an element to the tail of the queue.
*/
int
addq(nqe, s)
Queue_elt *nqe ;
Stack *s ;
{
ptr_check(nqe, Queue_elt, "addq", 0) ;
ptr_check(s, Stack, "addq", 0) ;
nqe->next = s->q.tail ;
nqe->prev = (Queue_elt *)0 ;
if(s->q.tail != (Queue_elt *)0)
{
s->q.tail->prev = nqe ;
}
s->q.tail = nqe ;
if(s->q.head == (Queue_elt *)0)
{
s->q.head = nqe ;
}
return 1 ;
}
int
dispose_Queue_elt(qe)
Queue_elt *qe ;
{
ptr_check(qe, Queue_elt, "dispose_Queue_elt", 0) ;
if(qe->ident != (Info_cell *)0)
{
dispose_Info_cell(qe->ident) ;
}
free(qe) ;
return 1 ;
}
/*
's' may be null if we have popped the stack until it is empty.
*/
int
empty_queue(s)
const Stack *s ;
{
if(s == (Stack *)0)
{
return 0 ;
}
return s->q.head == (Queue_elt *)0 ;
}
Queue_elt *
new_Queue_elt(s)
char *s ;
{
Queue_elt *qe = (Queue_elt *)0 ;
ptr_check(s, char, "new_Queue_elt", qe) ;
if((qe = (Queue_elt *)malloc((unsigned)sizeof(Queue_elt))) == (Queue_elt *)0)
{
/* "Error allocating %d bytes for new queue element" */
error(A_ERR, "new_Queue_elt", NEW_QUEUE_ELT_001, sizeof(Queue_elt)) ;
}
else
{
if((qe->ident = new_Info_cell(s)) != (Info_cell *)0)
{
qe->next = qe->prev = (Queue_elt *)0 ;
}
else
{
/* "Error from init_Info_cell()" */
error(A_ERR, "new_Queue_elt", NEW_QUEUE_ELT_002) ;
free(qe) ;
qe = (Queue_elt *)0 ;
}
}
return qe ;
}
int
print_queue(q)
const Queue_elt *q ;
{
Queue_elt *qe = q ;
fprintf(stderr, "-|") ;
while(qe != (Queue_elt *)0)
{
fprintf(stderr, "%s|", qe->ident->name) ;
qe = qe->next ;
}
fprintf(stderr, "-\n") ;
return 1 ;
}
Queue_elt *
remq(s)
Stack *s ;
{
Queue_elt *qe = (Queue_elt *)0 ;
ptr_check(s, Stack, "remq", qe) ;
if(s->q.head == (Queue_elt *)0)
{
return qe ;
}
qe = s->q.head ;
s->q.head = qe->prev ;
if(s->q.head != (Queue_elt *)0)
{
qe->prev->next = (Queue_elt *)0 ;
}
else
{
s->q.tail = (Queue_elt *)0 ;
}
qe->prev = (Queue_elt *)0 ;
return qe ;
}

View File

@ -0,0 +1,28 @@
#ifndef QUEUE_H
#define QUEUE_H
#include "queue_def.h"
#include "stack.h"
#ifdef __STDC__
extern int addq(Queue_elt *nqe, Stack *s) ;
extern int dispose_Queue_elt(Queue_elt *qe) ;
extern int empty_queue(const Stack *s) ;
extern int print_queue(const Queue_elt *q) ;
extern Queue_elt *new_Queue_elt(char *s) ;
extern Queue_elt *remq(Stack *s) ;
extern Queue *new_queue_t(void) ;
#else
extern int addq(/* Queue_elt *nqe, Stack *s */) ;
extern int dispose_Queue_elt(/* Queue_elt *qe */) ;
extern int empty_queue(/* const Stack *s */) ;
extern int print_queue(/* const Queue_elt *q */) ;
extern Queue_elt *new_Queue_elt(/* char *s */) ;
extern Queue_elt *remq(/* Stack *s */) ;
extern Queue *new_queue_t(/* void */) ;
#endif
#endif

View File

@ -0,0 +1,22 @@
#ifndef QUEUE_DEF_H
#define QUEUE_DEF_H
#include "info_cell.h"
typedef struct Queue_elt Queue_elt ;
struct Queue_elt
{
Info_cell *ident ;
Queue_elt *next ;
Queue_elt *prev ;
} ;
typedef struct queue_t
{
Queue_elt *head ;
Queue_elt *tail ;
} Queue ;
#endif

View File

@ -0,0 +1,296 @@
#include <string.h>
#include <stdio.h>
#include <stdlib.h> /* malloc? */
#include "parse.h"
#include "line_type.h"
#include "queue.h"
#include "info_cell.h"
#include "stack.h"
#include "error.h"
#include "lang_parsers.h"
#ifdef SOLARIS
#include "protos.h"
#else
#ifdef __STDC__
static Stack *new_Stack(Info_cell *ic) ;
#else
static Stack *new_Stack(/* Info_cell *ic */) ;
#endif
#endif
static Stack *stop = (Stack *)0 ;
int
empty_stack()
{
return stop == (Stack *)0 ;
}
int
init_stack(root_dir)
char *root_dir ;
{
if(root_dir != (char *)0)
{
if(S_line_type(root_dir) != L_DIR_START)
{
/* "Root directory '%s' doesn't match pattern" */
error(A_ERR, "init_stack", INIT_STACK_001, root_dir) ;
return 0 ;
}
else
{
char **path ;
int i ;
int has_dev ;
int npath ;
if( ! S_split_dir(root_dir, (char *)0, &has_dev, &npath, &path))
{
/* "Error from S_split_dir()" */
error(A_ERR, "init_stack", INIT_STACK_002) ;
return 0 ;
}
for(i = 0 ; i < npath ; i++)
{
char *s ;
Info_cell *ic ;
if((s = strdup(path[i])) == (char *)0)
{
/* "Error strdup'ing '%s'" */
error(A_ERR, "init_stack", INIT_STACK_003, path[i]) ;
return 0 ;
}
if((ic = new_Info_cell(s)) == (Info_cell *)0)
{
/* "Error from new_Info_cell()" */
error(A_ERR, "init_stack", INIT_STACK_004) ;
return 0 ;
}
if ( i != npath-1 || npath == 1 ) {
ic->idx = -1 ;
if( ! push(ic))
{
/* "Error from push()" */
error(A_ERR, "init_stack", INIT_STACK_005) ;
return 0 ;
}
}
else {
Pars_ent_holder *peh ;
Queue_elt *qe ;
if((peh = (Pars_ent_holder *)new_elt()) == (Pars_ent_holder *)0)
{
/* "Error allocating space for parser record" */
error(A_ERR, "handle_file", HANDLE_FILE_001);
return 0 ;
}
CSE_SET_DIR(peh->pent.core) ;
qe = new_Queue_elt(strdup(s)) ;
qe->ident->addr = peh ;
qe->ident->idx = elt_num() ;
if( ! addq(qe, tos()))
{
/* "Error adding directory to queue" */
error(A_ERR, "handle_file", HANDLE_FILE_004);
return 0 ;
}
peh->pent.core.parent_idx = tos()->ident->idx ;
if((peh->name = strdup(s)) == (char *)0)
{
/* "Error strdup'ing file name" */
error(A_ERR, "handle_file", HANDLE_FILE_005);
return 0 ;
}
peh->pent.slen = strlen(peh->name);
ic->idx = -1 ;
if( ! push(ic))
{
/* "Error from push()" */
error(A_ERR, "init_stack", INIT_STACK_005) ;
return 0 ;
}
}
}
}
}
return 1 ;
}
/*
Create a new stack element. 'str' is assumed to point to storage which may be freed by
pop.
*/
static Stack *
new_Stack(ic)
Info_cell *ic ;
{
Stack *s ;
ptr_check(ic, Info_cell, "new_Stack", 0) ;
if((s = (Stack *)malloc((unsigned)sizeof(Stack))) == (Stack *)0)
{
/* "Error allocating %d bytes for new stack element" */
error(A_SYSERR, "new_Stack", NEW_STACK_001, sizeof(Stack)) ;
return((Stack *) NULL);
}
s->ident = ic ;
s->q.head = s->q.tail = (Queue_elt *)0 ;
return s ;
}
int
pop()
{
Stack *s ;
if(stop == (Stack *)0)
{
#if 0
/* "Stack is empty" */
error(A_ERR, "pop", POP_001) ;
#endif
return 0 ;
}
if( ! empty_queue(tos()))
{
/* "Queue is not empty" */
#if 0
error(A_ERR, "pop", POP_002) ;
#endif
return 0 ;
}
s = stop ;
stop = stop->prev ;
if( ! dispose_Info_cell(s->ident))
{
/* "Error from dispose_Info_cell()" */
error(A_ERR, "pop", POP_003) ;
return 0 ;
}
free(s) ;
return 1 ;
}
int
print_stack()
{
if(stop == (Stack *)0)
{
/* "Stack is empty" */
fprintf(stderr, PRINT_STACK_001) ;
}
else
{
Stack *s = stop ;
fprintf(stderr, "------ stack -----\n") ;
while(s != (Stack *)0)
{
fprintf(stderr, "%s: ", s->ident->name) ;
print_queue(s->q.tail) ;
s = s->prev ;
}
fprintf(stderr, "==================\n") ;
}
return 1 ;
}
int
push(ic)
Info_cell *ic ;
{
Stack *s ;
ptr_check(ic, Info_cell, "push", 0) ;
if((s = new_Stack(ic)) == (Stack *)0)
{
/* "Error from new_Stack()" */
error(A_ERR, "push", PUSH_001) ;
return 0 ;
}
s->prev = stop ;
stop = s ;
return 1 ;
}
int
stack_match(p, n)
const char **p ;
int n ;
{
int i ;
Stack *s = stop ;
ptr_check(p, char *, "stack_match", 0) ;
if(stop == (Stack *)0)
{
return n == 0 ;
}
for(i = n ; i > 0 ; --i, s = s->prev)
{
if(s == (Stack *)0)
{
break ;
}
if(strcmp(s->ident->name, *(p + i - 1)) != 0)
{
return 0 ;
}
}
return i == 0 && s == (Stack *)0 ;
}
Stack *
tos()
{
return stop ;
}

View File

@ -0,0 +1,38 @@
#ifndef STACK_H
#define STACK_H
#include "queue_def.h"
typedef struct Stack Stack ;
struct Stack
{
Info_cell *ident ;
Queue q ;
Stack *prev ;
} ;
#ifdef __STDC__
extern int empty_stack(void) ;
extern int init_stack(char *root_dir) ;
extern int pop(void) ;
extern int print_stack(void) ;
extern int push(Info_cell *ic) ;
extern int stack_match(const char **p, int n) ;
extern Stack *tos(void) ;
#else
extern int empty_stack(/* void */) ;
extern int init_stack(/* char *root_dir */) ;
extern int pop(/* void */) ;
extern int print_stack(/* void */) ;
extern int push(/* Info_cell *ic */) ;
extern int stack_match(/* const char **p, int n */) ;
extern Stack *tos(/* void */) ;
#endif
#endif

View File

@ -0,0 +1,228 @@
/*
We assume that a series of memory allocations of fixed length are to be
done, followed by a single 'free' of all allocated memory.
We provide routines to allocate an element.
*/
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include "parse.h"
#include "error.h"
/* default number of elements in a block */
#define NELTS 512
typedef struct block Block ;
struct block
{
void *mem ; /* pointer to first entry in block */
void *end ; /* pointer to last entry in block */
struct block *next ; /* pointer to next block */
} ;
typedef struct header Header ;
struct header
{
int elts_per_blk ; /* counter of number of elements in each block */
int elt_size ; /* size of each element */
int block_size ; /* derived: size of each block of elements */
int curr_elt ;
int total_elts ; /* number of elements used in all blocks */
void *next_elt ; /* pointer to next available element */
Block *first ; /* pointer to first block of elements */
Block *last ; /* pointer to last (current) block of elements */
} ;
static Header hd ;
int
free_elts()
{
Block *b ;
mck ;
for(b = hd.first ; b != (Block *)0 ; )
{
Block *tmp;
free(b->mem) ;
tmp = b->next;
free((void *)b) ;
b = tmp;
}
hd.total_elts = hd.elts_per_blk = hd.elt_size = hd.block_size = 0 ;
hd.curr_elt = -1;
hd.next_elt = (void *)0 ;
hd.first = hd.last = (Block *)0 ;
mck ;
return 1 ;
}
int elt_num()
{
return hd.curr_elt ;
}
static Block *
new_block()
{
Block *b ;
mck ;
if((b = (Block *)malloc(sizeof(Block))) != (Block *)0)
{
void *p ;
if((p = malloc((size_t)hd.block_size)) == (void *)0)
{
free((void *)b) ;
b = (Block *)0 ;
}
else
{
b->next = (Block *)0 ;
b->mem = (Block *)p ;
b->end = (void *)((char *)b->mem + (hd.elts_per_blk - 1) * hd.elt_size) ;
}
}
mck ;
return b ;
}
/*
Upon entry hd.next_elt points to the next unused memory location.
*/
void *
new_elt()
{
void *p = hd.next_elt ;
mck ;
if(hd.next_elt < hd.last->end)
{
hd.next_elt = (void *)((char *)hd.next_elt + hd.elt_size) ;
}
else
{
Block *b = new_block() ;
if(b == (Block *)0)
{
return (void *)0 ;
}
else
{
hd.next_elt = b->mem ;
hd.last->next = b ;
hd.last = b ;
}
}
hd.curr_elt++ ;
hd.total_elts++ ;
mck ;
memset(p,0,hd.elt_size);
return p ;
}
static Block *curr_blk = (Block *)0 ;
static void *curr_mem = (void *)0 ;
void *
first_elt()
{
void *p = (void *)0 ;
mck ;
if(hd.first == (Block *)0)
{
error(A_ERR, "first_elt", "storage has not been initialized") ;
}
else if(hd.total_elts > 0)
{
curr_blk = hd.first ;
p = curr_mem = hd.first->mem ;
hd.curr_elt = 0 ;
}
mck ;
return p ;
}
/*
Upon entry curr_elt is the number of elements returned and curr_mem points to the last
entry returned.
*/
void *
next_elt()
{
void *p = (void *)0 ;
mck ;
if(hd.curr_elt < hd.total_elts - 1) /* hd.curr_elt counts from 0 */
{
if(curr_mem != curr_blk->end)
{
hd.curr_elt++ ;
p = curr_mem = (void *)((char *)curr_mem + hd.elt_size) ;
}
else /* go to next block */
{
if((curr_blk = curr_blk->next) != (Block *)0) /* have we done the last block? */
{
hd.curr_elt++ ;
p = curr_mem = curr_blk->mem ;
}
}
}
mck ;
return p ;
}
int
set_elt_size(size)
size_t size ;
{
mck ;
if(hd.elt_size != 0)
{
error(A_ERR, "set_elt_type", "element type has already been set") ;
return 0 ;
}
else
{
Block *b ;
hd.elt_size = size ;
hd.elts_per_blk = NELTS ;
hd.block_size = hd.elt_size * hd.elts_per_blk ;
if((b = new_block()) != (Block *)0)
{
hd.total_elts = 0 ;
hd.next_elt = b->mem ;
hd.first = hd.last = b ;
}
hd.curr_elt = -1 ; /* cuz we want to start at 0 */
mck ;
return b != (Block *)0 ;
}
}

View File

@ -0,0 +1,25 @@
#ifndef STORAGE_H
#define STORAGE_H
#ifdef __STDC__
#include <stddef.h>
extern int elt_num(void) ;
extern int free_elts(void) ;
extern int set_elt_size(size_t size) ;
extern void *first_elt(void) ;
extern void *new_elt(void) ;
extern void *next_elt(void) ;
#else
extern int elt_num(/* void */) ;
extern int free_elts(/* void */) ;
extern int set_elt_size(/* size_t size */) ;
extern void *first_elt(/* void */) ;
extern void *new_elt(/* void */) ;
extern void *next_elt(/* void */) ;
#endif
#endif

View File

@ -0,0 +1,55 @@
#include <strings.h>
extern char *malloc() ;
char *
strdup(s)
char *s ;
{
char *t = malloc((unsigned)(strlen(s)+1)) ;
return t == (char *)0 ? t : strcpy(t, s) ;
}
static char *
findfirst(s, set)
char *s ;
char *set ;
{
char *p ;
for( ; *s != '\0' ; s++)
{
for(p = set ; *p != '\0' ; p++)
{
if(*p == *s)
{
return s ;
}
}
}
return (char *)0 ;
}
char *
strsep(s, set)
char **s ;
char *set ;
{
char *p ;
char *start = *s ;
if((p = findfirst(*s, set)) == (char *)0)
{
return (char *)0 ;
}
else
{
*p = '\0' ;
*s = ++p ;
return start ;
}
}

View File

@ -0,0 +1,10 @@
#ifndef STR_H
#define STR_H
#ifdef __STDC__
#else
extern char *strdup() ;
extern char *strsep() ;
#endif
#endif

View File

@ -0,0 +1,80 @@
#include <signal.h>
#include <stdio.h>
#include "queue.h"
#ifdef __STDC__
extern void sig(int s) ;
#else
extern void sig(int s) ;
#endif
char *prog = "tq" ;
volatile int trap = 0 ;
int main()
{
char s[128] ;
int i ;
Queue_elt *qe ;
Queue *q1 = new_Queue() ;
Queue *q2 = new_Queue() ;
signal(SIGINT, sig) ;
while(trap == 0)
{
/* fprintf(stderr, "start\n") ; sleep(1) ;*/
for(i = 0 ; i < 1 ; i++)
{
if((qe = new_Queue_elt(sprintf(s, "foo %d", i))) == (Queue_elt *)0)
{
fprintf(stderr, "new_queue_elt failed.\n") ;
exit(1) ;
}
if( ! addq(qe, q1))
{
fprintf(stderr, "addq failed.\n") ;
exit(1) ;
}
}
/* fprintf(stderr, "created 1\n") ;*/
while((qe = remq(q1)) != (Queue_elt *)0)
{
addq(qe, q2) ;
}
/* fprintf(stderr, "moved 1 to 2\n") ;*/
while((qe = remq(q2)) != (Queue_elt *)0)
{
dispose_Queue_elt(qe) ;
}
/* fprintf(stderr, "disposed of 2\n") ;*/
}
printq("q1", q1) ;
printq("q2", q2) ;
return 1 ;
}
int
printq(s, q)
char *s ;
Queue *q ;
{
Queue_elt *qe = q->head ;
ptr_check(s, char, "printq", 0) ;
while(qe != (Queue_elt *)0)
{
printf("%s: %s\n", s, qe->str) ;
qe = qe->prev ;
}
return 1 ;
}
void sig(s)
int s ;
{
trap = 1 ;
}

View File

@ -0,0 +1,187 @@
#include <stddef.h>
#ifdef NULL
# undef NULL
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "defines.h"
#include "utils.h"
#include "db2v.h"
#include "parser_file.h"
#include "archie_inet.h"
#include "header.h"
#include "host_db.h"
#include "error.h"
#ifdef __STDC__
extern int print_parser_info(FILE *fp, parser_entry_t *pe, char *name, int n) ;
extern void usage(void) ;
#else
extern int print_parser_info(/* FILE *fp, parser_entry_t *pe, char *name, int n */) ;
extern void usage(/* void */) ;
#endif
#define MAX_LINE_LEN 512
char *prog ;
int verbose = 1 ;
int
main(ac, av)
int ac ;
char **av ;
{
header_t h ;
int ignore_header = 0 ;
int len ;
long n = 0 ;
parser_entry_t pe ;
prog = tail(av[0]) ;
while(av++, --ac)
{
if(av[0][0] != '-')
{
usage() ;
}
else
{
switch(av[0][1])
{
case 'h':
ignore_header = 1 ;
break ;
default:
usage() ;
break ;
}
}
}
if( ! ignore_header)
{
if(read_header(stdin, &h, (u32 *)0, 0,0) != A_OK)
{
fprintf(stderr, "%s: error from read_header().\n", prog) ;
exit(1) ;
}
if(write_header(stdout, &h, (u32 *)0, 0) != A_OK)
{
fprintf(stderr, "%s: error from write_header().\n", prog) ;
exit(1) ;
}
}
while(1)
{
char name[MAX_LINE_LEN] ;
if(fread((void *)&pe, sizeof pe, (size_t)1, stdin) < 1)
{
if(feof(stdin))
{
if(ignore_header)
{
exit(0) ;
}
else
{
if(n == h.no_recs)
{
exit(0) ;
}
else
{
fflush(stdout) ;
fprintf(stderr, "%s: expected %ld records, but actually saw %ld.\n", prog,
(long)h.no_recs, n) ;
exit(1) ;
}
}
}
else
{
fflush(stdout) ;
fprintf(stderr, "%s: error fread'ing parser entry.\n", prog) ;
exit(1) ;
}
}
len = (pe.slen + 3) & ~0x03 ;
if(fread((void *)name, (size_t)len, (size_t)1, stdin) < 1)
{
if(feof(stdin))
{
fflush(stdout) ;
fprintf(stderr, "%s: unexpected eof while trying to read file name (rec #%ld).\n",
prog, n) ;
exit(1) ;
}
else
{
fflush(stdout) ;
fprintf(stderr, "%s: error fread'ing %ld bytes for file name (rec #%ld).\n",
prog, (long)len, n) ;
exit(1) ;
}
}
*(name + len) = '\0' ;
if( ! print_parser_info(stdout, &pe, name, n))
{
fflush(stdout) ;
fprintf(stderr, "%s: error from print_parser_info() (rec #%ld).\n", prog, n) ;
exit(1) ;
}
n++ ;
}
return 0 ; /* for gcc -Wall */
}
int
print_parser_info(fp, pe, name, n)
FILE *fp ;
parser_entry_t *pe ;
char *name ;
int n ;
{
char out[MAX_LINE_LEN] ;
char *s = out ;
ptr_check(fp, FILE, "print_parser_info", 0) ;
ptr_check(pe, parser_entry_t, "print_parser_info", 0) ;
ptr_check(name, char, "print_parser_info", 0) ;
if(CSE_IS_DIR(pe->core))
{
sprintf(out, "%5d %5d %5d\t", n, pe->core.parent_idx, pe->core.child_idx) ;
}
else
{
sprintf(out, "%5d %5d %5s\t", n, pe->core.parent_idx, " ") ;
}
strcat(out, name) ; strcat(out, " ") ;
db2v_size(pe, s = strend(s)) ; strcat(out, " ") ;
db2v_date(pe, s = strend(s), 64) ; strcat(out, " ") ;
db2v_owner(pe, s = strend(s)) ; strcat(out, " ") ;
db2v_perms(pe, s = strend(s)) ;
return puts(out) != EOF ;
}
void
usage()
{
fprintf(stderr, "Usage: %s [-h]\n", prog) ;
exit(1) ;
}

413
archie/anonftp/parse/unix.c Normal file
View File

@ -0,0 +1,413 @@
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include "regexp.h"
#include "defines.h"
#include "parser_file.h"
#include "parse.h"
#include "utils.h"
#include "queue.h"
#include "stack.h"
#include "output.h"
#include "line_type.h"
#include "storage.h"
#include "pars_ent_holder.h"
#include "unix2.h"
#include "error.h"
#include "lang_parsers.h"
#ifdef SOLARIS
#include "protos.h"
#endif
#define S_BLANK "^$"
#define S_CONT (regexp *)0 ;
#define S_DIR_START "^/?[^/]+(/[^/]+)*:$"
#define S_ERROR (regexp *)0 ;
#define S_FILE "^[-bcdlpsyDFL][-r][-w][-xsSl][-r][-w][-xsSl][-r][-w][-xtT][ \t]+"
#define S_PARTIAL (regexp *)0 ;
#define S_TOTAL "^total[ \t]+[0-9]+"
#define S_UNREAD "^[^ \t]+[ \t]+unreadable$"
#define S_UNKNOWN (regexp *)0 ;
enum /* declared as enum to make debugging easier */
{
F_PERM = 0,
F_LINKS,
F_OWNER,
F_GROUP,
F_SIZE,
F_MONTH,
F_DAY,
F_T_Y, /* time (16:36) or year (1992) */
F_NAME,
UNIX_NUM_FLDS /* this must be last */
} ;
static regexp *re[L_NUM_ELTS] ;
static int leading_blanks = -1;
char *S_dup_dir_name(name)
const char *name ;
{
return strdup(name) ;
}
/*
Given a file line (see below for example) produce a core site entry
and return a pointer to the file name. Return a null pointer upon
an error.
The input string will be overwritten.
An input line looks something like:
-rw------- 1 news 1630 Mar 18 16:15 #alt.music.alternative~
as well, a group name may be present and/or the time may be specified
differently:
-rw-r--r-- 1 news 12 Jul 11 1991 .rhosts
or
-rw-r--r-- 1 news news 12 Jul 11 1991 .rhosts
Then again, we may have a device with major and minor numbers in place of
the size:
crw-rw-rw- 1 0 1 3, 12 Mar 19 17:03 zero
*/
char *S_file_parse(in, pe, is_dir)
char *in ;
parser_entry_t *pe ;
int *is_dir ;
{
char *field[UNIX_NUM_FLDS] ;
char *p = in ;
int is_symlink = 0;
int num_blanks;
ptr_check(in, char, "S_file_parse", (char *)0) ;
ptr_check(pe, parser_entry_t, "S_file_parse", (char *)0) ;
#define try_get_dev_field(fld, instr, fldname) \
do \
{ \
instr += strspn(instr, DEV_WHITE_STR) ; \
if((field[fld] = strsep(&instr, DEV_WHITE_STR)) == (char *)0) \
{ \
/* "Error looking for white space after %s" */\
error(A_ERR, "S_file_parse", U_S_FILE_PARSE_001, fldname) ; \
return (char *)0 ; \
} \
} while(0)
#define try_get_field(fld, instr, fldname) \
do \
{ \
instr += strspn(instr, WHITE_STR) ; \
if((field[fld] = strsep(&instr, WHITE_STR)) == (char *)0) \
{ \
/* "Error looking for white space after %s" */\
error(A_ERR, "S_file_parse", U_S_FILE_PARSE_001, fldname) ; \
return (char *)0 ; \
} \
} while(0)
try_get_field(F_PERM, p, "permissions") ;
try_get_field(F_LINKS, p, "links") ;
try_get_field(F_OWNER, p, "owner") ;
if(*field[F_PERM] == 'b' || *field[F_PERM] == 'c') /* devices */
{
try_get_dev_field(F_GROUP, p, "group or major number") ;
if(*(field[F_GROUP] + strlen(field[F_GROUP]) - 1) == ',' ) /* is major number */
{
/* there is no group -- toss the major and minor numbers */
try_get_field(F_GROUP, p, "minor number") ;
field[F_GROUP] = (char *)0 ;
}
else /* is group */
{
/* there is a group -- still toss the major and minor numbers */
#if 0
p+= strspn(p, DEV_WHITE_STR) ;
if((field[F_NAME] = strsep(&p, DEV_WHITE_STR)) == (char *)0)
{
/* "Error looking for white space after %s" */
error(A_ERR, "S_file_parse", U_S_FILE_PARSE_001, "major") ;
return (char *)0 ;
}
p += strspn(p, DEV_WHITE_STR) ;
if((field[F_NAME] = strsep(&p, DEV_WHITE_STR)) == (char *)0)
{
/* "Error looking for white space after %s" */
error(A_ERR, "S_file_parse", U_S_FILE_PARSE_001, "minor") ;
return (char *)0 ;
}
#endif
if ( strchr(field[F_GROUP],',') == NULL ) {
char *ptr;
try_get_dev_field(F_NAME, p, "major number") ;
ptr = strchr(field[F_NAME],',');
if ( ptr == NULL || ptr-field[F_NAME] == strlen(field[F_NAME])-1 )
try_get_dev_field(F_NAME, p, "minor number") ;
}
}
field[F_SIZE] = "0" ;
try_get_field(F_MONTH, p, "month") ;
}
else /* non-devices */
{
is_symlink = *field[F_PERM] == 'l';
try_get_field(F_GROUP, p, "group or size") ; /* may be size */
try_get_field(F_SIZE, p, "size or month") ; /* may be month */
if(isdigit(*field[F_SIZE])) /* there was a group field */
{
try_get_field(F_MONTH, p, "month") ;
}
else /* no group field -- group was size, size was month */
{
field[F_MONTH] = field[F_SIZE] ;
field[F_SIZE] = field[F_GROUP] ;
field[F_GROUP] = (char *)0 ;
}
}
try_get_field(F_DAY, p, "day") ;
try_get_field(F_T_Y, p, "time or year") ;
num_blanks = strspn(p, WHITE_STR); /* Assume that there is 1 separating */
if ( leading_blanks > num_blanks ) {
leading_blanks = num_blanks;
error(A_INFO,"S_file_parse", "Confused by leading blank characters, will restart and try to be more intelligent !");
return 0;
}
if ( leading_blanks == -1 )
leading_blanks = num_blanks;
p+= leading_blanks;
field[F_NAME] = p ;
if(*field[F_NAME] == '\0')
{
/* "Missing file name" */
error(A_ERR, "S_file_parse", U_S_FILE_PARSE_002) ;
return (char *)0 ;
}
/*
If the file is a symbolic link, put a nul at the first occurrence
of " -> ".
*/
if (is_symlink)
{
char *p;
if ( ! (p = strstr(field[F_NAME], " -> ")))
{
error(A_WARN, "S_file_parse", U_S_FILE_PARSE_006, in, line_num());
}
else
{
*p = '\0';
}
}
#ifdef __STDC__
#define try_cvt_str(s) if( ! (s)) do { error(A_ERR, "S_file_parse", "Error from " #s "\n") ; return (char *)0 ; } while(0)
#else
/* "Error extracting field" */
#define try_cvt_str(s) if( ! (s)) do { error(A_ERR, "S_file_parse", U_S_FILE_PARSE_004) ; return (char *)0 ; } while(0)
#endif
try_cvt_str(u2db_perm(field[F_PERM], &pe->core)) ;
try_cvt_str(u2db_owner(field[F_OWNER], field[F_GROUP], &pe->core)) ;
try_cvt_str(u2db_size(field[F_SIZE], &pe->core)) ;
try_cvt_str(u2db_time(field[F_MONTH], field[F_DAY], field[F_T_Y], &pe->core)) ;
pe->slen = strlen(field[F_NAME]) ; /* when writing we don't include the nul terminator */
/* Is it an entry for a directory? */
if( ! S_file_type(field[F_PERM], is_dir))
{
/* "Error from S_file_type()" */
error(A_ERR, "S_file_parse", U_S_FILE_PARSE_005) ;
return (char *)0 ;
}
return field[F_NAME] ;
#undef try_get_field
#undef try_cvt_str
}
int S_file_type(s, is_dir)
const char *s ;
int *is_dir ;
{
ptr_check(s, char, "S_file_type", 0) ;
ptr_check(is_dir, int, "S_file_type", 0) ;
*is_dir = ((*s == 'd') || (*s == 'D'));
return 1 ;
}
int S_init_parser()
{
re[L_BLANK] = regcomp(S_BLANK) ;
re[L_CONT] = S_CONT ;
re[L_DIR_START] = regcomp(S_DIR_START) ;
re[L_ERROR] = S_ERROR ;
re[L_FILE] = regcomp(S_FILE) ;
re[L_PARTIAL] = S_PARTIAL ;
re[L_TOTAL] = regcomp(S_TOTAL) ;
re[L_UNREAD] = regcomp(S_UNREAD) ;
re[L_UNKNOWN] = S_UNKNOWN ;
return 1 ;
}
#ifdef DEBUG
# define dbg_show(t) error(A_INFO,"(unknown)", "D: %s '%s'\n", t, line) ;
#else
# define dbg_show(t) /* nothing */
#endif
int S_line_type(line)
const char *line ;
{
ptr_check(line, char, "S_line_type", L_INTERN_ERR) ;
if(regexec(re[L_FILE], line))
{
dbg_show("file") ;
return L_FILE ;
}
else if(regexec(re[L_BLANK], line))
{
dbg_show("blank") ;
return L_BLANK ;
}
else if(regexec(re[L_DIR_START], line))
{
dbg_show("dir_start") ;
return L_DIR_START ;
}
else if(regexec(re[L_TOTAL], line))
{
dbg_show("total") ;
return L_TOTAL ;
}
else if(regexec(re[L_UNREAD], line))
{
dbg_show("unreadable") ;
return L_UNREAD ;
}
else
{
dbg_show("unknown") ;
return L_UNKNOWN ;
}
}
/*
Split a directory path name into its components.
Return a pointer to an array of pointers into 'str', where each element
points to the start of a file name in the path. The number of path elements
will be returned in 'n'. If this type of listing has device name prefixes,
then '*dev' will point to it.
The string will be overwritten.
If an error occurs return a null pointer.
*/
int S_split_dir(str, prep_dir, dev, n, p)
char *str ;
char *prep_dir ;
int *dev ;
int *n ;
char ***p ;
{
static char *path[MAX_PATH_ELTS + 1] ;
char *s = str ;
int i = 0 ;
ptr_check(str, char, "S_split_dir", 0) ;
ptr_check(dev, int, "S_split_dir", 0) ;
ptr_check(n, int, "S_split_dir", 0) ;
ptr_check(p, char **, "S_split_dir", 0) ;
*dev = 0 ; /* UNIX sites don't have a device name prefix */
if(prep_dir != (char *)0)
{
path[i++] = prep_dir ;
}
if(*s == '/') /* any leading / is meaningless to us */
{
s++ ;
}
path[i++] = s ;
while(*s != '\0')
{
if(*s != '/')
{
s++ ;
}
else
{
*s++ = '\0' ;
path[i++] = s ;
}
}
if(*--s == ':') /* knock off the trailing colon from the file name */
{
*s = '\0' ;
}
else
{
/* "Expected ':' at end of path, but found '%c'" */
error(A_ERR, "S_split_dir", S_SPLIT_DIR_001, *s) ;
return 0 ;
}
*n = i ;
*p = path ;
return 1 ;
}
int set_blanks(num)
int num;
{
if (leading_blanks != -1 )
leading_blanks -= num;
}

View File

@ -0,0 +1,325 @@
#include <stdio.h>
#include <string.h>
#include <time.h>
#if defined(AIX) || defined(SOLARIS)
#include <stdlib.h>
#include <ctype.h>
#endif
#include "defines.h"
#include "parse.h"
#include "site_file.h"
#include "unix2.h"
#include "error.h"
#include "lang_parsers.h"
/*
'mon' points to the first character of the month string.
E.g. "Mar"
'day' points to the first character of the day string.
E.g. "25"
't_y' points to the first character of the "time or year" string.
E.g. "13:51" or "1992"
Assume: time_t is the number of seconds since 00:00:00 Jan 1, 1970 GMT. ANSI does not
guarantee this.
*/
int
u2db_time(mon, day, t_y, cse)
const char *mon ;
const char *day ;
const char *t_y ;
core_site_entry_t *cse ;
{
extern int local_timezone;
static char *months[13] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul",
"Aug", "Sep", "Oct", "Nov", "Dec", (char *)0 } ;
static struct tm *mytime;
int dm ;
int hr ;
int m = 0 ;
int min ;
int y ;
struct tm bd_time ; /* broken down time */
time_t ltime;
time_t the_time ;
#if defined(AIX) || defined(SOLARIS)
extern long timezone;
#else
extern time_t time();
struct tm *our_time ; /* broken down time */
#endif
ptr_check(mon, char, "u2db_time", 0) ;
ptr_check(day, char, "u2db_time", 0) ;
ptr_check(t_y, char, "u2db_time", 0) ;
ptr_check(cse, core_site_entry_t, "u2db_time", 0) ;
if(mytime == (struct tm *) NULL){
the_time = time((time_t *) NULL);
if((mytime = (struct tm *) malloc(sizeof(struct tm))) == (struct tm *) NULL){
error(A_SYSERR, "u2db_time", "Can't malloc space for time structure");
return 0;
}
memcpy(mytime, gmtime(&the_time), sizeof(struct tm));
}
while(months[m] != (char *)0)
{
if(strncmp(mon, months[m], 4) == 0)
{
break ;
}
else
{
m++ ;
}
}
if(m == 12)
{
return 0 ;
}
if(sscanf(day, "%d", &dm) != 1)
{
/* "Error in date '%s'" */
error(A_ERR, "u2db_time", U2DB_TIME_001, day) ;
return 0 ;
}
if(t_y[2] == ':')
{
if(sscanf(t_y, "%2d:%2d", &hr, &min) != 2)
{
/* "Error in time '%s'" */
error(A_ERR, "u2db_time", U2DB_TIME_002, t_y) ;
return 0 ;
}
if(mytime -> tm_mon - m < 6 ){
if(mytime -> tm_mon - m < 0 )
y = mytime -> tm_year + 1900 - 1;
else
y = mytime -> tm_year + 1900;
}
else
y = mytime -> tm_year + 1900;
}
else
{
if(sscanf(t_y, "%d", &y) != 1)
{
/* "Error in year '%s'" */
error(A_ERR, "u2db_time", U2DB_TIME_003, t_y) ;
return 0 ;
}
hr = 0 ;
min = 0 ;
}
if(dm < 1 || dm > 31 || y < 1900)
{
/* "Day-of-month or year value error in '%s %s %s'" */
error(A_ERR, "u2db_time", U2DB_TIME_004, mon, day, t_y) ;
return 0 ;
}
#if defined(AIX) || defined(SOLARIS)
/* AIX can't handle dates less than 1970, so reset them to that */
if(y < 1970)
y = 1970;
#endif
if(hr < 0 || hr > 23 || min < 0 || min > 59)
{
/* "Hour or minute value error in '%s'" */
error(A_ERR, "u2db_time", U2DB_TIME_005, t_y) ;
return 0 ;
}
else
{
time_t timenow;
memset((void *)&bd_time, 0, sizeof bd_time) ;
bd_time.tm_sec = 0 ;
bd_time.tm_min = min ;
bd_time.tm_hour = hr ;
bd_time.tm_mday = dm ;
bd_time.tm_mon = m ;
bd_time.tm_year = y - 1900 ;
bd_time.tm_isdst = -1 ;
#if !defined(AIX) && !defined(SOLARIS)
timenow = time((time_t *) NULL);
our_time = localtime(&timenow);
ltime = our_time -> tm_gmtoff + local_timezone;
if((the_time = timelocal(&bd_time)) == -1)
{
/* "Error from timelocal()" */
error(A_ERR, "u2db_time", U2DB_TIME_006) ;
/* reset the time to "now" */
the_time = time((time_t) NULL);
}
#else
ltime = (timezone * timezone_sign()) + local_timezone;
if((the_time = mktime(&bd_time)) == -1)
{
/* "Error from timegm()" */
error(A_ERR, "u2db_time", U2DB_TIME_007) ;
/* reset the time to "now" */
the_time = time((time_t) NULL);
}
#endif
cse->date = the_time + ltime;
}
return 1 ;
}
int
u2db_links(v, cse)
const char *v ;
core_site_entry_t *cse ;
{
ptr_check(v, char, "u2db_links", 0) ;
ptr_check(cse, core_site_entry_t, "u2db_links", 0) ;
return 1 ;
}
int
u2db_name(v, cse)
const char *v ;
core_site_entry_t *cse ;
{
ptr_check(v, char, "u2db_name", 0) ;
ptr_check(cse, core_site_entry_t, "u2db_name", 0) ;
return 1 ;
}
int
u2db_owner(u, v, cse)
const char *u ;
const char *v ;
core_site_entry_t *cse ;
{
ptr_check(u, char, "u2db_owner", 0) ;
/* v (group) may be null */
ptr_check(cse, core_site_entry_t, "u2db_owner", 0) ;
return 1 ;
}
int
u2db_perm(v, cse)
const char *v ;
core_site_entry_t *cse ;
{
int i, j;
perms_t perms = 0 ;
ptr_check(v, char, "u2db_perm", 0) ;
ptr_check(cse, core_site_entry_t, "u2db_perm", 0) ;
for(i=0, j = 9 ; i < 9 ;i++, j--)
{
switch(v[j])
{
case 'r':
case 'w':
case 'x':
case 't':
case 's':
case 'l':
case 'S':
case 'T':
perms |= 0x01 << i;
break ;
case '-':
break;
default:
/* "Unknown permission character %c, line %s" */
error(A_ERR, "u2db_perm", U2DB_PERM_001, v[j], v) ;
return 0 ;
}
}
cse->perms = perms ;
return 1 ;
}
int
u2db_size(v, cse)
const char *v ;
core_site_entry_t *cse ;
{
ptr_check(v, char, "u2db_size", 0) ;
ptr_check(cse, core_site_entry_t, "u2db_size", 0) ;
if( ! isdigit((int)*v))
{
return 0 ;
}
else
{
cse->size = atoi(v) ;
return 1 ;
}
}

View File

@ -0,0 +1,25 @@
#ifndef UNIX2_H
#define UNIX2_H
#ifdef __STDC__
extern int u2db_links(const char *v, core_site_entry_t *cse) ;
extern int u2db_name(const char *v, core_site_entry_t *cse) ;
extern int u2db_owner(const char *u, const char *v, core_site_entry_t *cse) ;
extern int u2db_perm(const char *v, core_site_entry_t *cse) ;
extern int u2db_size(const char *v, core_site_entry_t *cse) ;
extern int u2db_time(const char *mon, const char *day, const char *t_y, core_site_entry_t *cse) ;
extern int u2db_type(const char *v, core_site_entry_t *cse) ;
#else
extern int u2db_links(/* const char *v, core_site_entry_t *cse */) ;
extern int u2db_name(/* const char *v, core_site_entry_t *cse */) ;
extern int u2db_owner(/* const char *u, const char *v, core_site_entry_t *cse */) ;
extern int u2db_perm(/* const char *v, core_site_entry_t *cse */) ;
extern int u2db_size(/* const char *v, core_site_entry_t *cse */) ;
extern int u2db_time(/* const char *mon, const char *day, const char *t_y, core_site_entry_t *cse */) ;
extern int u2db_type(/* const char *v, core_site_entry_t *cse */) ;
#endif
#endif

View File

@ -0,0 +1,26 @@
#!/bin/sh
#
# Filter UNIX listings to get rid of selected bogosities.
#
# - Bill Heelan (wheelan@cs.mcgill.ca)
#
sed '
# trash the line with the error and the one following it.
/: Permission denied$/{
N
d
}
# trash the line with the error
/[ ]not found$/d
/: Could not open/d
/^can not access directory/d
/^Total: [0-9][0-9]* kbytes$/d
# separate any permissions and links fields that have been
# squashed together
/^\([-bcdlps][-r][-w][-xsS][-r][-w][-xsS][-r][-w][-xtT]\)\([0-9][0-9]*\)[ ]/s//\1 \2 /
'

View File

@ -0,0 +1,147 @@
#include <stdio.h>
#include <string.h>
#include "defines.h"
#include "parse.h"
#include "error.h"
int
vfprintf_path(fp, p, n)
FILE *fp ;
char **p ;
int n ;
{
ptr_check(fp, FILE, "vfprintf_path", 0) ;
ptr_check(p, char *, "vfprintf_path", 0) ;
if(n < 1)
{
return 0 ;
}
else
{
int i ;
for(i = 0 ; i < n - 1 ; i++)
{
fprintf(stderr, "%s/", p[i]) ;
}
fprintf(stderr, "%s", p[i]) ;
return 1 ;
}
}
char *
nuke_nl(s)
char *s ;
{
char *p ;
ptr_check(s, char, "nuke_nl", (char *)0) ;
p = strchr(s, '\n') ;
if(p != (char *)0)
{
*p = '\0' ;
}
return s ;
}
#if 0
char *
strdup(s)
char *s ;
{
char *t ;
ptr_check(s, char, "strdup", (char *)0) ;
t = (char *)malloc((size_t)(strlen(s)+1)) ;
return t == (char *)0 ? t : strcpy(t, s) ;
}
#endif
/*
Return a pointer to the nul in a nul terminated string.
*/
char *
strend(s)
char *s ;
{
ptr_check(s, char, "strend", (char *)0) ;
for( ; *s != '\0' ; s++)
;
return s ;
}
static char *
findfirst(s, set)
char *s ;
char *set ;
{
char *p ;
ptr_check(s, char, "findfirst", (char *)0) ;
ptr_check(set, char, "findfirst", (char *)0) ;
for( ; *s != '\0' ; s++)
{
for(p = set ; *p != '\0' ; p++)
{
if(*p == *s)
{
return s ;
}
}
}
return (char *)0 ;
}
/*
Return a pointer to the first occurence in '*s' of a character in 'set'. If none
exists return the null pointer.
If a character is found, set it to '\0' and set *s to point to the first character
after the '\0'.
*/
char *
strsep(s, set)
char **s ;
char *set ;
{
char *p ;
char *start = *s ;
ptr_check(s, char *, "strsep", (char *)0) ;
ptr_check(*s, char, "strsep", (char *)0) ;
ptr_check(set, char, "strsep", (char *)0) ;
if((p = findfirst(*s, set)) == (char *)0)
{
return (char *)0 ;
}
else
{
*p = '\0' ;
*s = ++p ;
return start ;
}
}
#if 0
char *
tail(path)
char *path ;
{
char *p ;
ptr_check(path, char, "tail", (char *)0) ;
p = strrchr(path, '/') ;
return p == (char *)0 ? path : ++p ;
}
#endif

View File

@ -0,0 +1,21 @@
#ifndef UTILS_H
#define UTILS_H
#ifdef __STDC__
extern char *nuke_nl(char *s) ;
extern char *strend(char *s) ;
extern char *strsep(char **s, char *set) ;
extern char *tail(char *path) ;
extern int fprintf_path(FILE *fp, char **p, int n) ;
#else
extern char *nuke_nl(/* char *s */) ;
extern char *strend(/* char *s */) ;
extern char *strsep(/* char **s, char *set */) ;
extern char *tail(/* char *path */) ;
extern int fprintf_path(/* FILE *fp, char **p, int n */) ;
#endif
#endif

318
archie/anonftp/parse/vms.c Normal file
View File

@ -0,0 +1,318 @@
/*
vms.c
*/
#include <stdio.h>
#include <string.h>
#include "defines.h"
#include "regexp.h"
#include "parser_file.h"
#include "parse.h"
#include "utils.h"
#include "queue.h"
#include "stack.h"
#include "output.h"
#include "line_type.h"
#include "storage.h"
#include "pars_ent_holder.h"
#include "error.h"
#include "lang_parsers.h"
#include "vms2.h"
#ifdef SOLARIS
#include "protos.h"
#endif
static regexp *re_cont ;
static regexp *re_dir_start ;
static regexp *re_error ;
static regexp *re_file ;
static regexp *re_partial ;
#define S_BLANK "^$"
#define S_CONT "^[ \t]+[%0-9]"
#define S_DIR_START "^([^:]+):\\[([^].]+)(\\.[^].]+)*\\]"
#define S_ERROR "^[^.]*\\.[^;]*;[0-9]+[ \t]+[%0-9]"
#define S_FILE "^[^.]*\\.[^;]*;[0-9]+[ \t]+[0-9]+"
#define S_PARTIAL "^[^.]*\\.[^;]*;[0-9]+"
#define S_TOTAL "^Total of|^Grand total of"
#define S_UNKNOWN (regexp *)0 ;
static regexp *re[L_NUM_ELTS] ;
#define F_NAME 0
#define F_SIZE 1
#define F_DATE 2
#define F_TIME 3
#define F_OWN 4
#define F_PERM 5
#define VMS_NUM_FLDS (F_PERM+1)
char *
S_dup_dir_name(name)
const char *name ;
{
char *d = strchr(name, '.') ; /* can it only have one '.'? */
if(d == (char *)0)
{
/* "'%S' doesn't contain a '.'" */
error(A_ERR, "S_dup_dir_name", S_DUP_DIR_NAME_001, name) ;
return (char *)0 ;
}
else
{
char *s ;
*d = '\0' ;
s = strdup(name) ;
*d = '.' ;
return s ;
}
}
/*
Given a file line (see below for example) produce a core site entry
and return a pointer to the file name. Return a null pointer upon
an error.
The input string will be overwritten.
An input line looks something like:
ARIZONET.DIS;10 2 8-NOV-1989 17:05 NETINFO (RWED,RWED,RWED,RE)
*/
char *
S_file_parse(in, pe, is_dir)
char *in ;
parser_entry_t *pe ;
int *is_dir ;
{
char *field[VMS_NUM_FLDS] ;
ptr_check(in, char, "S_file_parse", (char *)0) ;
ptr_check(pe, parser_entry_t, "S_file_parse", (char *)0) ;
#define try_get_field(fld, instr, fldname) \
if((field[fld] = strtok(instr, WHITE_STR)) == (char *)0) \
do \
{ \
/* "Error looking for white space after %s" */\
error(A_ERR, "S_file_parse", V_S_FILE_PARSE_001, fldname) ; \
return (char *)0 ; \
} while(0)
try_get_field(F_NAME, in, "file name") ;
try_get_field(F_SIZE, (char *)0, "file size") ;
try_get_field(F_DATE, (char *)0, "date") ;
try_get_field(F_TIME, (char *)0, "time") ;
try_get_field(F_OWN, (char *)0, "owner") ;
try_get_field(F_PERM, (char *)0, "permissions") ;
#ifdef __STDC__
#define try_cvt_str(s) \
if( ! (s)) \
do \
{ \
error(A_ERR, "S_file_parse","Error from " #s "\n") ; return (char *)0 ; \
} while(0)
#else
#define try_cvt_str(s) \
if( ! (s)) \
do \
{ \
/* "Error extracting field" */\
error(A_ERR, "S_file_parse", V_S_FILE_PARSE_002) ; return (char *)0 ; \
} while(0)
#endif
try_cvt_str(v2db_perm(field[F_PERM], &pe->core)) ;
try_cvt_str(v2db_owner(field[F_OWN], &pe->core)) ; /* includes group owner */
try_cvt_str(v2db_size(field[F_SIZE], &pe->core)) ;
try_cvt_str(v2db_time(field[F_DATE], field[F_TIME], &pe->core)) ;
pe->slen = strlen(field[F_NAME]) ; /* when writing we don't include the nul terinator */
/* Is it an entry for a directory? */
if( ! S_file_type(field[F_NAME], is_dir))
{
/* "Error from S_file_type()" */
error(A_ERR, "S_file_parse", V_S_FILE_PARSE_003) ;
return (char *)0 ;
}
return field[F_NAME] ;
#undef try_get_field
#undef try_cvt_str
}
int
S_file_type(s, is_dir)
const char *s ;
int *is_dir ;
{
char *d = strchr(s, '.') ;
ptr_check(s, char, "S_file_type", 0) ;
ptr_check(is_dir, int, "S_file_type", 0) ;
if(d == (char *)0)
{
/* "Can't find '.' in file name '%s'" */
error(A_ERR, "S_file_type", S_FILE_TYPE_001, s) ;
return 0 ;
}
else
{
*is_dir = strncmp(d, ".DIR;", 5) == 0 ;
return 1 ;
}
}
int
S_init_parser()
{
re[L_BLANK] = regcomp(S_BLANK) ;
re[L_CONT] = regcomp(S_CONT) ;
re[L_DIR_START] = regcomp(S_DIR_START) ;
re[L_ERROR] = regcomp(S_ERROR) ;
re[L_FILE] = regcomp(S_FILE) ;
re[L_PARTIAL] = regcomp(S_PARTIAL) ;
re[L_TOTAL] = regcomp(S_TOTAL) ;
re[L_UNKNOWN] = S_UNKNOWN ;
return 1 ;
}
#ifdef DEBUG
# define dbg_show(t) error(A_INFO, "(unknown)", "D: %s '%s'", t, nuke_nl(line)) ;
#else
# define dbg_show(t) /* nothing */
#endif
int
S_line_type(line)
const char *line ;
{
ptr_check(line, char, "S_line_type", L_INTERN_ERR) ;
if(regexec(re[L_FILE], line))
{
dbg_show("file") ;
return L_FILE ;
}
else if(regexec(re[L_BLANK], line))
{
dbg_show("blank") ;
return L_BLANK ;
}
else if(regexec(re[L_DIR_START], line))
{
dbg_show("dir_start") ;
return L_DIR_START ;
}
else if(regexec(re[L_ERROR], line))
{
dbg_show("error") ;
return L_ERROR ;
}
else if(regexec(re[L_PARTIAL], line)) /* should check length as well */
{
dbg_show("partial") ;
return L_PARTIAL ;
}
else if(regexec(re[L_CONT], line))
{
dbg_show("cont") ;
return L_CONT ;
}
else if(regexec(re[L_TOTAL], line))
{
dbg_show("total") ;
return L_TOTAL ;
}
else
{
dbg_show("unknown") ;
return L_UNKNOWN ;
}
}
/*
Split a directory path name into its components.
Return a pointer to an array of pointers into 'str', where each
element points to the start of a file name in the path. The
number of path elements will be returned in 'n'.
If this type of listing has device name prefixes, then '*dev' will
point to it.
The string will be overwritten.
If an error occurs return a null pointer.
*/
#define DEV_TERM ':'
#define PATH_START '['
#define PATH_SEP '.'
#define PATH_END ']'
int
S_split_dir(str, prep_dir, dev, n, p)
char *str ;
char *prep_dir ;
int *dev ;
int *n ;
char ***p ;
{
static char *path[MAX_PATH_ELTS + 1] ;
char *s = str ;
int i = 0 ;
ptr_check(str, char, "S_split_dir", 0) ;
ptr_check(dev, int, "S_split_dir", 0) ;
ptr_check(n, int, "S_split_dir", 0) ;
ptr_check(p, char **, "S_split_dir", 0) ;
*dev = 1 ; /* VMS sites have a device name prefix */
path[i++] = s ;
*(s = strchr(s, DEV_TERM)) = '\0' ;
s += 2 ;
do
{
path[i++] = s ;
switch(*(s = strpbrk(s, ".]")))
{
case '.':
*s++ = '\0' ;
break ;
case ']':
*s = '\0' ; /* terminate the loop */
break ;
}
}
while(*s != '\0') ;
*n = i ;
*p = path ;
return 1 ;
}
int set_blanks(num)
int num;
{
/* if (leading_blanks != -1 )
leading_blanks -= num;
*/
}

309
archie/anonftp/parse/vms2.c Normal file
View File

@ -0,0 +1,309 @@
#include <stdio.h>
#include <string.h>
#include <time.h>
#if defined(AIX) || defined(SOLARIS)
#include <stdlib.h>
#include <ctype.h>
#endif
#include "defines.h"
#include "parse.h"
#include "site_file.h"
#include "error.h"
#include "lang_parsers.h"
/*
'd' points to the first character of the date string.
E.g. "15-JUL-1991"
't' points to the first character of the time string.
E.g. "13:51"
Assume: time_t is the number of seconds since 00:00:00 Jan 1, 1970 GMT. ANSI does not
guarantee this.
*/
int
v2db_time(d, t, cse)
char *d ;
char *t ;
core_site_entry_t *cse ;
{
extern int local_timezone;
static char *months[13] = { "JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL",
"AUG", "SEP", "OCT", "NOV", "DEC", (char *)0 } ;
char mstr[4] ; /* error waiting to happen... */
date_time_t dt = 0 ;
int dm ;
int hr ;
int m = 0 ;
int min ;
int y ;
struct tm bd_time ; /* broken down time */
time_t the_time ;
time_t ltime ;
#if defined(AIX) || defined(SOLARIS)
extern long timezone;
#else
struct tm *our_time ; /* broken down time */
#endif
ptr_check(d, char, "v2db_time", 0) ;
ptr_check(t, char, "v2db_time", 0) ;
ptr_check(cse, core_site_entry_t, "v2db_time", 0) ;
if(sscanf(d, "%d-%[^-]-%d", &dm, mstr, &y) != 3)
{
/* "Error in date '%s'" */
error(A_ERR, "v2db_date", V2DB_DATE_001, d) ;
return 0 ;
}
if(sscanf(t, "%2d:%2d", &hr, &min) != 2)
{
/* "Error in time '%s'" */
error(A_ERR, "v2db_date", V2DB_DATE_002, t) ;
return 0 ;
}
if(dm > 31 || y < 1970)
{
/* "Day-of-month or year value error in '%s'" */
error(A_ERR, "v2db_date", V2DB_DATE_003, d) ;
return 0 ;
}
if(hr > 23 || min > 59)
{
/* "Hour or minute value error in '%s'" */
error(A_ERR, "v2db_date", V2DB_DATE_004, t) ;
return 0 ;
}
else
{
time_t timenow;
while(months[m] != (char *)0)
{
if(strncmp(mstr, months[m], 3) == 0)
{
break ;
}
else
{
m++ ;
}
}
if(m == 12)
{
return 0 ;
}
memset((void *)&bd_time, 0, sizeof bd_time) ;
bd_time.tm_sec = 0 ;
bd_time.tm_min = min ;
bd_time.tm_hour = hr ;
bd_time.tm_mday = dm ;
bd_time.tm_mon = m ;
bd_time.tm_year = y - 1900 ;
bd_time.tm_isdst = -1 ;
#if !defined(AIX) && !defined(SOLARIS)
timenow = time((time_t *) NULL);
our_time = localtime(&timenow);
ltime = our_time -> tm_gmtoff + local_timezone;
if((the_time = timelocal(&bd_time)) == -1)
{
/* "Error from timegm()" */
error(A_ERR, "v2db_time", V2DB_DATE_005 ) ;
return 0 ;
}
#else
ltime = timezone + local_timezone;
if((the_time = mktime(&bd_time)) == -1)
{
/* "Error from timegm()" */
error(A_ERR, "v2db_time", V2DB_DATE_005 ) ;
return 0 ;
}
#endif
cse->date = the_time + ltime;
}
return 1 ;
}
int
v2db_links(v, cse)
char *v ;
core_site_entry_t *cse ;
{
ptr_check(v, char, "v2db_links", 0) ;
return 1 ;
}
int
v2db_name(v, cse)
char *v ;
core_site_entry_t *cse ;
{
ptr_check(v, char, "v2db_name", 0) ;
return 1 ;
}
static int
v2db_one_set_perm(in, perm)
char *in ;
perms_t *perm ;
{
char *iptr = in ;
perms_t p = 0 ;
ptr_check(in, char, "v2db_one_set_perm", 0) ;
ptr_check(perm, perms_t, "v2db_one_set_perm", 0) ;
while(*iptr != ',' && *iptr != ')')
{
switch(*iptr++)
{
case 'R': p |= 0x08 ; break ;
case 'W': p |= 0x04 ; break ;
case 'E': p |= 0x02 ; break ;
case 'D': p |= 0x01 ; break ;
default:
/* "Unexpected character ('%c') in permissions '%s'" */
error(A_ERR, "v2db_one_set_perm", V2DB_ONE_SET_PERM_001, *(iptr - 1), in) ;
return 0 ;
}
}
*perm = p ;
return 1 ;
}
int
v2db_owner(v, cse)
char *v ;
core_site_entry_t *cse ;
{
ptr_check(v, char, "v2db_owner", 0) ;
ptr_check(cse, core_site_entry_t, "v2db_owner", 0) ;
return 1 ;
}
int
v2db_perm(v, cse)
char *v ;
core_site_entry_t *cse ;
{
perms_t p = 0 ;
perms_t perms = 0 ;
ptr_check(v, char, "v2db_perm", 0) ;
ptr_check(cse, core_site_entry_t, "v2db_perm", 0) ;
/* Probably should do some error checking in here. */
++v ;
v2db_one_set_perm(v, &p) ;
perms = p << 12 ;
while(*v++ != ',') ;
v2db_one_set_perm(v, &p) ;
perms |= p << 8 ;
while(*v++ != ',') ;
v2db_one_set_perm(v, &p) ;
perms |= p << 4 ;
while(*v++ != ',') ;
v2db_one_set_perm(v, &p) ;
perms |= p ;
cse->perms |= perms ;
return 1 ;
}
int
v2db_size(v, cse)
char *v ;
core_site_entry_t *cse ;
{
ptr_check(v, char, "v2db_size", 0) ;
ptr_check(cse, core_site_entry_t, "v2db_size", 0) ;
if( ! isdigit((int)*v))
{
return 0 ;
}
else
{
cse->size = atoi(v) ;
return 1 ;
}
}
#if 0 /* Directory or non-directory is determined higher up */
int
v2db_type(v, cse)
char *v ;
core_site_entry_t *cse ;
{
char *p ;
ptr_check(v, char, "v2db_type", 0) ;
ptr_check(cse, core_site_entry_t, "v2db_type", 0) ;
if((p = strrchr(v, ';')) == (char *)0)
{
return 0 ;
}
else
{
if(*--p == 'R' && *--p == 'I' && *--p == 'D' && *--p == '.')
{
cse->perms |= 01000 ;
}
else
{
cse->perms &= ~01000 ;
}
return 1 ;
}
}
#endif

View File

@ -0,0 +1,27 @@
#ifndef VMS2_H
#define VMS2_H
#ifdef __STDC__
extern int v2db_type(char *v, core_site_entry_t *cse) ;
extern int v2db_time(char *v, char *x, core_site_entry_t *cse) ;
extern int v2db_size(char *v, core_site_entry_t *cse) ;
extern int v2db_perm(char *v, core_site_entry_t *cse) ;
extern int v2db_owner(char *v, core_site_entry_t *cse) ;
extern int v2db_name(char *v, core_site_entry_t *cse) ;
extern int v2db_links(char *v, core_site_entry_t *cse) ;
extern int v2db_date(char *v, core_site_entry_t *cse) ;
#else
extern int v2db_type(/* char *v, core_site_entry_t *cse */) ;
extern int v2db_time(/* char *v, core_site_entry_t *cse */) ;
extern int v2db_size(/* char *v, core_site_entry_t *cse */) ;
extern int v2db_perm(/* char *v, core_site_entry_t *cse */) ;
extern int v2db_owner(/* char *v, core_site_entry_t *cse */) ;
extern int v2db_name(/* char *v, core_site_entry_t *cse */) ;
extern int v2db_links(/* char *v, core_site_entry_t *cse */) ;
extern int v2db_date(/* char *v, core_site_entry_t *cse */) ;
#endif
#endif

1
archie/anonftp/retrieve/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
Makefile

View File

@ -0,0 +1 @@
Makefile

View File

@ -0,0 +1,12 @@
#
# Use GNU's fixed header files.
#
SYS_DEFS = -DAIX
SENT_FLAGS = -ffixed-%g2 -ffixed-%g3 -ffixed-%g4
SYS_LIBS = -L${BERKDB_ROOT}/${SYSTYPE} -ldb
include ../Makefile.pre
include ../Makefile.post
# DO NOT DELETE THIS LINE -- make depend depends on it

View File

@ -0,0 +1,18 @@
#
# anonftp/retrieve module.
#
all: $(EXES)
include $(ARCHIE_ROOT)/Makefile.post
retrieve_anonftp: \
$(LIBARCHIE_MODULE)/$(SYSTYPE)/libarchie.a \
$(HOSTDB_MODULE)/$(SYSTYPE)/libhostdb.a \
${OBJS}
${CC} ${CFLAGS} -o $@ ${OBJS} ${MOD_LIBS} ${SYS_LIBS}
clean:
rm -f *.o $(EXES) core

View File

@ -0,0 +1,33 @@
#
# Anonftp/retrieve module.
#
#MOD_CFLAGS = -traditional -pipe
MOD_DEBUG = -g3
MOD_WARN = -Wall -Wshadow -Wpointer-arith -Wcast-align
MOD_INCS = -I$(INCLUDE_MODULE) -I$(REGEX_MODULE) -I.
MOD_LIBS = \
-L$(LIBARCHIE_MODULE)/$(SYSTYPE) -larchie \
-L$(HOSTDB_MODULE)/$(SYSTYPE) -lhostdb
include $(ARCHIE_ROOT)/Makefile.pre
INCS = \
ftp.h \
ftp_getfile.h \
lang_retrieve.h
SRCS = \
ftp.c \
ftp_getfile.c \
lang_retrieve.c
OBJS = \
ftp.o \
ftp_getfile.o \
lang_retrieve.o
EXES = \
retrieve_anonftp

View File

@ -0,0 +1 @@
Makefile

View File

@ -0,0 +1,11 @@
#
# Use GNU's fixed header files.
#
SYS_DEFS = -D__USE_FIXED_PROTOTYPES__ -DPOSIX_SOURCE -DSUNOS
SENT_FLAGS = -ffixed-%g2 -ffixed-%g3 -ffixed-%g4
SYS_LIBS = -lresolv -L${BERKDB_ROOT}/${SYSTYPE} -ldb
include ../Makefile.pre
include ../Makefile.post
# DO NOT DELETE THIS LINE -- make depend depends on it

View File

@ -0,0 +1 @@
Makefile

View File

@ -0,0 +1,11 @@
#
# Use GNU's fixed header files.
#
SYS_DEFS = -D__USE_FIXED_PROTOTYPES__ -DSOLARIS
SENT_FLAGS = -ffixed-%g2 -ffixed-%g3 -ffixed-%g4
SYS_LIBS = -lresolv -lnsl -lsocket -L${BERKDB_ROOT}/${SYSTYPE} -ldb
include ../Makefile.pre
include ../Makefile.post
# DO NOT DELETE THIS LINE -- make depend depends on it

View File

@ -0,0 +1 @@
SunOS-5.4

View File

@ -0,0 +1,492 @@
/*
* This file is copyright Bunyip Information Systems Inc., 1992. This file
* may not be reproduced, copied or transmitted by any means mechanical or
* electronic without the express written consent of Bunyip Information
* Systems Inc.
*/
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <varargs.h>
#include <arpa/telnet.h>
#include <ctype.h>
#include <sys/time.h>
#include <signal.h>
#ifdef AIX
#include <sys/select.h>
#endif
#include <unistd.h>
#include "protos.h"
#include "typedef.h"
#include "error.h"
#include "ftp.h"
#include "lang_retrieve.h"
/* ftp.c: low level ftp routines */
static pathname_t reply_string;
static pathname_t out_string;
/*
* get_reply_string: return the last reply string from the ftp session
*/
extern char *prog;
char *get_reply_string()
{
static char rep_str[BUFSIZ];
strcpy(rep_str, reply_string);
rep_str[strlen(rep_str) - 1] = '\0';
return(rep_str);
}
/*
* get_request_string: return the last command to the remote ftp server
*/
char *get_request_string()
{
static char req_str[BUFSIZ];
strcpy(req_str, out_string);
return(req_str);
}
void put_request_string(s)
char *s;
{
strcpy(out_string, s);
}
void put_reply_string(s)
char *s;
{
strcpy(reply_string, s);
}
/*
* ftp_connect: connect to the given hostname on the port and return two
* file pointers to the input and output streams
*/
con_status_t ftp_connect(hostname, port, command_in, command_out, timeout)
hostname_t hostname; /* host name to connect to */
int port; /* port number to connect to */
FILE **command_in; /* returned input file pointer */
FILE **command_out; /* returned output file pointer */
int timeout;
{
#ifdef __STDC__
extern int fclose(FILE *);
#else
extern int fclose();
extern setsockopt();
#endif
extern int verbose;
int command_fd;
int on = 1;
int retcode;
if(verbose){
/* "Trying to connect to %s on port %u" */
error(A_INFO,"ftp_connect", FTP_CONNECT_001, hostname, port);
}
if((retcode = cliconnect(hostname, port, &command_fd)) != A_OK)
return(retcode);
if(verbose){
/* "Connected to %s" */
error(A_INFO,"ftp_connect", FTP_CONNECT_002, hostname);
}
if((*command_in = fdopen(command_fd, "r")) == (FILE *) NULL){
/* "Can't open file I/O for incoming connection" */
error(A_ERR,"ftp_connect", FTP_CONNECT_003);
return(ERROR);
}
if((*command_out = fdopen(command_fd, "w")) == (FILE *) NULL){
/* "Can't open file I/O for outgoing connection" */
error(A_ERR,"ftp_connect", FTP_CONNECT_004);
if(command_in)
fclose(*command_in);
return(ERROR);
}
#ifdef SO_OOBINLINE
if(setsockopt(command_fd, SOL_SOCKET, SO_OOBINLINE, (char *) &on, sizeof(on)) == -1){
/* "Can't set socket options" */
error(A_SYSERR, "ftp_connect", FTP_CONNECT_005);
return(CON_SOCKETFAILED);
}
#endif
/* get the login message */
if(get_reply(*command_in, *command_out, &retcode,0, timeout) == ERROR)
return(retcode);
return(A_OK);
}
/*
* ftp_login: perform the login sequence to the remote ftp server
*/
int ftp_login(comm_in, comm_out, user, pass, acct, timeout)
FILE *comm_in;
FILE *comm_out;
char *user;
char *pass;
char *acct;
int timeout;
{
int retcode;
retcode = send_command(comm_in, comm_out,0,timeout,"USER %s", user);
if(retcode == FTP_USER_OK){ /* User name ok, need password */
if((retcode = send_command(comm_in, comm_out,0, timeout, "PASS %s", pass)) == FTP_LOGIN_OK){
/* User logged in OK */
return(A_OK);
}
else{
if(retcode == FTP_ACCT_WANTED){ /* Need "ACCT" name */
if((retcode = send_command(comm_in, comm_out,0, timeout, "ACCT %s", acct)) == FTP_LOGIN_OK){
/* User logged in OK */
return(A_OK);
}
else{
/* "ACCT command '%s' not accepted" */
/* error(A_ERR,"ftp_login", FTP_LOGIN_001, acct); */
return(retcode); /* ACCT not accepted */
}
}
else{
/* "FTP password '%s' not accepted" */
/* error(A_ERR,"ftp_login", FTP_LOGIN_002, pass); */
return(retcode); /* Login incorrect */
}
}
}
else
if(retcode == FTP_LOGIN_OK) /* User logged in without password */
return(A_OK);
else if(retcode == FTP_NOT_LOGGED_IN){
/* "Login not accepted. Service not currently available" */
/* error(A_ERR,"ftp_login", FTP_LOGIN_003, retcode); */
return(retcode);
}else{
/* "Login not accepted. FTP code %u" */
/* error(A_ERR,"ftp_login", FTP_LOGIN_004, retcode); */
return(retcode);
}
}
/*
* send_command: send an ftp command. varargs
*/
int send_command(va_alist)
va_dcl
/* FILE *comm_in;
FILE *comm_out;
int expecteof;
int timeout;
char *format;
arglist */
{
extern int vfprintf();
extern int vsprintf();
#ifdef __STDC__
extern int fflush(FILE *);
#else
extern int fflush();
#endif
extern int verbose;
FILE *comm_in;
FILE *comm_out;
va_list al;
char *format;
int retcode;
char outformat[BUFSIZ];
int expecteof;
int timeout;
va_start(al);
comm_in = va_arg(al, FILE *);
comm_out = va_arg(al, FILE *);
expecteof = va_arg(al, int);
timeout = va_arg(al, int);
format = va_arg(al, char *);
sprintf(outformat,"%s\r\n", format);
vfprintf(comm_out, outformat, al);
vsprintf(out_string, format, al);
if(verbose)
error(A_INFO, "send_command","%s", out_string);
fflush(comm_out);
va_end(al);
if(get_reply(comm_in, comm_out, &retcode,0, timeout) == ERROR)
return(-1);
else
return(retcode);
}
/*
* get_reply: read the reply from the remote ftp daemon
*/
status_t get_reply(comm_in, comm_out, retcode, expecteof, timeout)
FILE *comm_in; /* input file pointer */
FILE *comm_out; /* output file pointer */
int *retcode; /* returned pointer to ftp return code */
int expecteof; /* non-zero if EOF condition expected on next read from remote daemon */
int timeout; /* Time to wait for reply */
{
extern void sig_handle();
extern int signal_set;
extern int verbose;
int c, n;
int code;
char *cp;
int dig;
int continuation = 0;
int originalcode = 0;
#if 0
fd_set read_set;
int select_code;
struct timeval timev_struct;
timev_struct.tv_sec = timeout;
timev_struct.tv_usec = 0L;
FD_ZERO(&read_set);
FD_SET(fileno(comm_in),&read_set);
if((select_code = select(FD_SETSIZE, &read_set, (fd_set *) NULL, (fd_set *) NULL, &timev_struct)) < 0){
/* "Error in select() while waiting for reply from remote server" */
error(A_SYSERR, "get_reply", GET_REPLY_001);
*retcode = FTP_LOST_CONN;
return(ERROR);
}
else{
/* timeout */
if(select_code == 0){
/* "Timed out while waiting for reply from remote ftp server" */
error(A_ERR, "get_reply", GET_REPLY_002);
put_reply_string(GET_REPLY_002);
*retcode = FTP_LOST_CONN;
return(ERROR);
}
}
#endif
#ifndef SOLARIS
/*
* Don't restart the system call (a read) if we are interrupted by
* sigalarm. This is the default behaviour under Solaris, so we don't
* need this call
*/
siginterrupt(SIGALRM, 1);
#endif
signal_set = 0;
signal(SIGALRM, sig_handle);
alarm(timeout);
c = getc(comm_in);
if(signal_set){
/* "Timed out while waiting for reply from remote ftp server" */
error(A_ERR, "get_reply", GET_REPLY_002);
put_reply_string(GET_REPLY_002);
*retcode = FTP_LOST_CONN;
return(ERROR);
}
alarm(0);
signal(SIGALRM, SIG_DFL);
#ifndef SOLARIS
siginterrupt(SIGALRM, 0);
#endif
ungetc(c, comm_in);
while(1){
dig = n = code = 0;
cp = reply_string;
while((c = getc(comm_in)) != '\n'){
if(c == IAC){ /* handle telnet comms */
switch (c = getc(comm_in)) {
case WILL:
case WONT:
c = getc(comm_in);
fprintf(comm_out, "%c%c%c",IAC,DONT,c);
fflush(comm_out);
break;
case DO:
case DONT:
c = getc(comm_in);
fprintf(comm_out, "%c%c%c",IAC,WONT,c);
fflush(comm_out);
break;
default:
break;
}
continue;
}
dig++;
if(c == EOF){
if(expecteof){
*retcode = FTP_QUIT;
return (A_OK);
}
*retcode = FTP_LOST_CONN;
return(ERROR);
}
if(dig < 4 && isdigit(c))
code = code * 10 + (c - '0');
if(dig == 4 && c == '-'){
if(continuation)
code = 0;
continuation++;
}
if(n == 0)
n = c;
if(cp < &reply_string[sizeof(reply_string) - 1])
*cp++ = c;
}
if(continuation && (code != originalcode)){
if(originalcode == 0)
originalcode = code;
continue;
}
*cp = '\0';
if(verbose)
error(A_INFO,"get_reply","%s", reply_string);
if(code == FTP_LOST_CONN || originalcode == FTP_LOST_CONN){
return(ERROR);
}
*retcode = code;
return(A_OK);
}
}

View File

@ -0,0 +1,55 @@
#ifndef _FTP_H_
#define _FTP_H_
#include "archie_inet.h"
#define FTP_DATACONN_OPEN 125
#define FTP_OPEN_DATACONN 150
#define FTP_COMMAND_OK 200
#define FTP_FILE_STATUS 213
#define FTP_QUIT 221 /* Quit OK */
#define FTP_TRANSFER_COMPLETE 226 /* File transfer completed */
#define FTP_LOGIN_OK 230 /* Login OK */
#define FTP_FILE_ACTION_OK 250
#define FTP_PATHNAME_NONRFC 251
#define FTP_PATHNAME_CREATED 257 /* Returned on successful PWD */
#define FTP_USER_OK 331 /* Give USER */
#define FTP_ACCT_WANTED 332 /* Give ACCT */
#define FTP_LOST_CONN 421 /* Lost connection to site */
#define FTP_CANT_DATACONN 425 /* Can't build data connection */
#define FTP_ABORT_DATACONN 426 /* Data conection aborted */
#define FTP_FILE_UNAVAILABLE 450 /* File unavailable */
#define FTP_LOCAL_ERROR 451 /* Action aborted, local processing error */
#define FTP_COMMAND_NOT_IMPL 500 /* Command not implemented */
#define FTP_COMM_PARAM_NOT_IMPL 504 /* Given parameters to command not implemented */
#define FTP_NOT_LOGGED_IN 530 /* Currently not logged in */
#define FTP_ACTION_NOT_TAKEN 550 /* Action not taken, file unavailable */
#ifdef __STDC__
extern int send_command( );
extern status_t get_reply(FILE *, FILE *, int *, int, int);
extern con_status_t ftp_connect(hostname_t, int, FILE **, FILE **, int);
extern int ftp_login(FILE *, FILE *, char *, char *, char *, int);
extern status_t setup_dataconn(FILE **,int *);
extern char * get_reply_string(void);
extern char * get_request_string(void);
#else
extern status_t get_reply();
extern int send_command();
extern con_status_t ftp_connect();
extern int ftp_login();
extern status_t setup_dataconn();
extern char * get_reply_string();
extern char * get_request_string();
#endif
extern void put_request_string PROTO((char*));
extern void put_reply_string PROTO((char*));
#endif

File diff suppressed because it is too large Load Diff

Some files were not shown because too many files have changed in this diff Show More