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
prospero/user/vcache/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
Makefile

View File

@@ -0,0 +1,15 @@
FILES
Makefile
aftpget.c
cmds.c
ftp.c
ftp.h
ftp_var.h
gopherget.c
main.c
pclose.c
ruserpass.c
telnet.h
vcache.c
vcache.h
vcache_macros.h

151
prospero/user/vcache/Makefile.in Executable file
View File

@@ -0,0 +1,151 @@
#
# Derived from Berkeley ftp code. Those parts are:
# Copyright (c) 1988 Regents of the University of California.
# All rights reserved.
#
# Redistribution and use in source and binary forms are permitted
# provided that the above copyright notice and this paragraph are
# duplicated in all such forms and that any documentation,
# advertising materials, and other materials related to such
# distribution and use acknowledge that the software was developed
# by the University of California, Berkeley. The name of the
# University may not be used to endorse or promote products derived
# from this software without specific prior written permission.
# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
# WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
#
# @(#)Makefile 5.6 (Berkeley) 6/29/88
#
# You must #define WAIS to include WAIS support, and uncomment the WAIS
# lines. See the comment in main.c
# Footnote: ignore the above comment. There are now two distinct types of WAIS support (aiee).
# The OLD one is no longer in use, but the hooks remain.
# This should be cleaned up one day. --swa
SOURCEBASE=../..
include $(SOURCEBASE)/Makefile.config
LIBOBJECTS = cmds.o ftp.o pclose.o aftpget.o ruserpass.o gopherget.o vcache.o
XLIBOBJECTS = main.o
CFILES = \
aftpget.c \
cmds.c \
ftp.c \
gopherget.c \
main.c \
pclose.c \
ruserpass.c \
vcache.c
OBJECTS = $(LIBOBJECTS) $(XLIBOBJECTS)
SPECIAL_PROGS = vcache
all: ${VCACHE_LIB} vcache
# PFS_VCACHE_LIBS* defined in Makefile.boilerplate
vcache: $(XLIBOBJECTS) $(PFS_VCACHE_LIBS_DEPENDENCIES)
${CC} ${CFLAGS} -o vcache $(XLIBOBJECTS) $(PFS_VCACHE_LIBS) ../../../libpsarchie/libpsarchie.a
# This is for the OLD wais support. Ignore.
#wais.dir:
# cd wais ; \
# ${MAKE} libwais.a
# This is one possibility for testing. Uncomment during development.
#TV = ./vcache -v -D -t
#TVD = /tmp/test_vcache
#test:
# -mkdir $(TVD)
# -$(TV) $(TVD)/gopher0 GOPHER INTERNET-D "GOPHER.PATH.NET(8001)" ASCII 0/testarea/About TEXT
# -$(TV) $(TVD)/aftp AFTP INTERNET-D PROSPERO.ISI.EDU ASCII /pub/prospero/papers/.messages ASCII
# -$(TV) $(TVD)/aftp AFTP INTERNET-D ftp.path.net ASCII /pub/iiirdoc ascii
install:
${INSTALL} -c -o ${OWNER} -g ${GROUP} -m $(INSTALL_EXE_MODE) vcache \
${P_BINARIES}/vcache${GENERATIONSUFFIX}
${GENERATION} ${P_BINARIES}/vcache
# This library is not generally installed.
# ${INSTALL} -c -o ${OWNER} -g ${GROUP} -m 644 ${VCACHE_LIB} \
# ${P_BINARIES}/${VCACHE_LIB}${GENERATIONSUFFIX}
# ${RANLIB} ${P_BINARIES}/${VCACHE_LIB}${GENERATIONSUFFIX}
# ${GENERATION} ${P_BINARIES}/${VCACHE_LIB}
${VCACHE_LIB}: ${LIBOBJECTS}
rm -f ${VCACHE_LIB}
ar r${AR_FLAGS} ${VCACHE_LIB} ${LIBOBJECTS}
${RANLIB} ${VCACHE_LIB}
# Dependencies
aftpget.o : ftp_var.h \
../../include/posix_signal.h \
../../include/pfs.h \
../../include/pfs_utils.h ../../include/ardp.h ../../include/pfs_threads.h \
../../include/list_macros.h \
../../include/../lib/ardp/flocks.h ../../include/implicit_fixes.h \
../../include/pmachine.h \
../../include/perrno.h ../../include/pcompat.h \
vcache_macros.h
cmds.o : ftp_var.h \
../../include/posix_signal.h \
../../include/pmachine.h \
../../include/perrno.h \
../../include/pfs_threads.h ../../include/pfs_utils.h vcache_macros.h ../../include/ardp.h \
../../include/list_macros.h \
../../include/../lib/ardp/flocks.h ../../include/pfs.h \
../../include/implicit_fixes.h \
../../include/vcache.h
ftp.o : ftp_var.h \
../../include/posix_signal.h \
../../include/pcompat.h \
../../include/pfs_threads.h ../../include/pfs_utils.h \
../../include/pmachine.h \
../../include/perrno.h vcache_macros.h ../../include/ardp.h \
../../include/list_macros.h ../../include/../lib/ardp/flocks.h \
../../include/pfs.h \
../../include/implicit_fixes.h \
../../include/vcache.h ../../include/sockettime.h
gopherget.o : \
../../include/perrno.h ../../include/pfs_threads.h \
../../include/pfs_utils.h ../../include/pmachine.h \
../../include/pfs.h ../../include/ardp.h \
../../include/list_macros.h \
../../include/../lib/ardp/flocks.h ../../include/implicit_fixes.h \
vcache_macros.h
main.o : \
../../include/pfs.h ../../include/pfs_utils.h \
../../include/ardp.h ../../include/pfs_threads.h \
../../include/list_macros.h ../../include/../lib/ardp/flocks.h \
../../include/implicit_fixes.h \
../../include/pmachine.h \
../../include/pcompat.h \
../../include/perrno.h
pclose.o : \
../../include/posix_signal.h \
../../include/pmachine.h \
../../include/implicit_fixes.h \
../../include/pfs_threads.h ../../include/pfs_utils.h
ruserpass.o : \
ftp_var.h \
vcache_macros.h ../../include/ardp.h ../../include/pfs_threads.h \
../../include/pfs_utils.h \
../../include/list_macros.h ../../include/../lib/ardp/flocks.h \
../../include/pfs.h ../../include/pmachine.h \
../../include/implicit_fixes.h \
../../include/perrno.h ../../include/string_with_strcasecmp.h
vcache.o : \
../../include/pmachine.h \
vcache.h \
../../include/pfs.h ../../include/pfs_utils.h ../../include/ardp.h \
../../include/pfs_threads.h \
../../include/list_macros.h ../../include/../lib/ardp/flocks.h ../../include/implicit_fixes.h \
../../include/psite.h ../../include/perrno.h vcache_macros.h

View File

@@ -0,0 +1,170 @@
/*
* Derived from Berkeley ftp code. Those parts are
* Copyright (c) 1985 Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
#ifndef lint
/* Made static to avoid conflicting with definition of 'copyright' in other
programs. */
static char copyright[] =
"@(#) Copyright (c) 1985 Regents of the University of California.\n\
All rights reserved.\n";
#endif /* not lint */
#ifndef lint
static char sccsid[] = "@(#)main.c 5.11 (Berkeley) 6/29/88";
#endif /* not lint */
/*
* FTP User Program -- Command Interface.
*/
#include "ftp_var.h" /* Ambiguous includes !!*/
/* SCO needs sys/types.h before sys/socket.h */
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <arpa/ftp.h>
#include <posix_signal.h>
#include <stdio.h>
#include <errno.h>
#include <ctype.h>
#include <netdb.h>
#include <pwd.h>
#include <string.h>
#include <pfs.h>
#include <perrno.h>
#include <pcompat.h>
#include <pmachine.h>
#include "vcache_macros.h"
uid_t getuid();
void intr();
void lostpeer();
extern char *home;
char *getlogin();
char *readheader();
int
aftpget(host,local,ftsuffix,trans_mode)
char *host;
char *local;
char *ftsuffix;
char *trans_mode;
{
int top;
int retval;
if (strequal(trans_mode, "TEXT")) trans_mode = "ASCII";
/* Remove local if it already exists */
unlink(local);
assert(P_IS_THIS_THREAD_MASTER()); /*SOLARIS: getservbyname MT-Unsafe*/
DISABLE_PFS(sp = getservbyname("ftp", "tcp"));
if (sp == 0) {
ERRSYS( "ftp: ftp/tcp: unknown service:%s %s");
return(1);
}
ftpport = sp->s_port;
doglob = 1;
interactive = 1;
autologin = 1;
cpend = 0; /* no pending replies */
proxy = 0; /* proxy not active */
crflag = 1; /* strip c.r. on ascii gets */
if (setjmp(toplevel))
return(0);
(void) signal(SIGINT, intr);
(void) signal(SIGPIPE, lostpeer);
DISABLE_PFS(setpeer(host));
top = setjmp(toplevel) == 0;
if (top) {
(void) signal(SIGINT, intr);
(void) signal(SIGPIPE, lostpeer);
}
set_type(trans_mode);
/* Do not disable here if output file is a Vname */
DISABLE_PFS(retval = recvrequest("RETR", local, ftsuffix, "w"));
quitnoexit(); /* This used to do an exit(0) in all cases */
return(retval);
}
void
intr()
{
longjmp(toplevel, 1);
}
void
lostpeer()
{
extern FILE *cout;
extern int data;
if (connected) {
if (cout != NULL) {
(void) shutdown(fileno(cout), 1+1);
(void) fclose(cout);
cout = NULL;
}
if (data >= 0) {
(void) shutdown(data, 1+1);
(void) close(data);
data = -1;
}
connected = 0;
}
pswitch(1);
if (connected) {
if (cout != NULL) {
(void) shutdown(fileno(cout), 1+1);
(void) fclose(cout);
cout = NULL;
}
connected = 0;
}
proxflag = 0;
pswitch(0);
}
/*char *
tail(filename)
char *filename;
{
register char *s;
while (*filename) {
s = rindex(filename, '/');
if (s == NULL)
break;
if (s[1])
return (s + 1);
*s = '\0';
}
return (filename);
}
*/

180
prospero/user/vcache/cmds.c Normal file
View File

@@ -0,0 +1,180 @@
/*
* Derived from Berkeley ftp code. Those parts are
* Copyright (c) 1985 Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
#ifndef lint
static char sccsid[] = "@(#)cmds.c 5.8 (Berkeley) 6/29/88";
#endif /* not lint */
/*
* FTP User Program -- Command Routines.
*/
#include "ftp_var.h" /* Dangerous ambiguous includes !!*/
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/ftp.h>
#include <posix_signal.h>
#include <stdio.h>
#include <errno.h>
#include <ctype.h>
#include <sys/wait.h>
#include <netdb.h>
#include <pmachine.h> /* after netdb.h */
#include <perrno.h>
#include "vcache_macros.h"
#include <vcache.h>
extern char *home;
extern short gflag;
extern char *getenv();
extern char *index();
extern char *rindex();
char *mname;
jmp_buf jabort;
/* Forward declerations */
static void disconnect(void);
/*
* Connect to peer server and
* auto-login, if possible.
*/
void
setpeer(char *hostn)
{
char *host, *hookup();
host = hookup(hostn, ftpport);
if (host) {
connected = 1;
if (autologin)
(void) login(hostn);
}
}
struct types {
char *t_name;
char *t_mode;
int t_type;
char *t_arg;
} types[] = {
{ "ascii", "A", TYPE_A, 0 },
{ "binary", "I", TYPE_I, 0 },
{ "image", "I", TYPE_I, 0 },
{ "ebcdic", "E", TYPE_E, 0 },
{ "tenex", "L", TYPE_L, bytename },
{ "ASCII", "A", TYPE_A, 0 },
{ "BINARY", "I", TYPE_I, 0 },
{ "IMAGE", "I", TYPE_I, 0 },
{ "EBCDIC", "E", TYPE_E, 0 },
{ "TENEX", "L", TYPE_L, bytename },
0
};
/*
* Set transfer type.
*/
void
set_type(char *t)
{
register struct types *p;
int comret;
for (p = types; p->t_name; p++)
if (strcmp(t, p->t_name) == 0)
break;
if (p->t_name == 0) {
ERR("%s: unknown mode %s", t);
code = -1;
return;
}
if ((p->t_arg != NULL) && (*(p->t_arg) != '\0'))
comret = command ("TYPE %s %s", p->t_mode, p->t_arg, 0);
else
comret = command("TYPE %s", p->t_mode, 0);
if (comret == COMPLETE) {
(void) strcpy(typename, p->t_name);
type = p->t_type;
}
}
char *
onoff(bool)
int bool;
{
return (bool ? "on" : "off");
}
void disconnect();
/* Quiting at this level is nasty, it prevents the caching from working */
void
quitnoexit()
{
if (connected)
disconnect();
pswitch(1);
if (connected) {
disconnect();
}
}
#ifdef NEVERDEFINED
/*
* Terminate session and exit.
*/
quit()
{
quitnoexit();
exit(0);
}
#endif
/*
* Terminate session, but don't exit.
*/
static void
disconnect()
{
extern FILE *cout;
extern int data;
if (!connected)
return;
(void) command("QUIT",0);
if (cout) {
(void) fclose(cout);
}
cout = NULL;
connected = 0;
data = -1;
if (!proxy) {
macnum = 0;
}
}
#ifdef NEVERDEFINED
/* Luckily this isnt ever used, it does an exit which defeats caching */
fatal(msg)
char *msg;
{
ERR("ftp: %s\n", msg);
exit(1);
}
#endif /*NEVERDEFINED*/

1436
prospero/user/vcache/ftp.c Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,93 @@
/*
* Copyright (c) 1983, 1989 Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
* provided that: (1) source distributions retain this entire copyright
* notice and comment, and (2) distributions including binaries display
* the following acknowledgement: ``This product includes software
* developed by the University of California, Berkeley and its contributors''
* in the documentation or other materials provided with the distribution
* and in all advertising materials mentioning features or use of this
* software. Neither the name of the University nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* @(#)ftp.h 5.5 (Berkeley) 6/1/90
*/
/*
* Definitions for FTP
* See RFC-765
*/
/*
* Reply codes.
*/
#define PRELIM 1 /* positive preliminary */
#define COMPLETE 2 /* positive completion */
#define CONTINUE 3 /* positive intermediate */
#define TRANSIENT 4 /* transient negative completion */
#define ERROR 5 /* permanent negative completion */
/*
* Type codes
*/
#define TYPE_A 1 /* ASCII */
#define TYPE_E 2 /* EBCDIC */
#define TYPE_I 3 /* image */
#define TYPE_L 4 /* local byte size */
#ifdef FTP_NAMES
char *typenames[] = {"0", "ASCII", "EBCDIC", "Image", "Local" };
#endif
/*
* Form codes
*/
#define FORM_N 1 /* non-print */
#define FORM_T 2 /* telnet format effectors */
#define FORM_C 3 /* carriage control (ASA) */
#ifdef FTP_NAMES
char *formnames[] = {"0", "Nonprint", "Telnet", "Carriage-control" };
#endif
/*
* Structure codes
*/
#define STRU_F 1 /* file (no record structure) */
#define STRU_R 2 /* record structure */
#define STRU_P 3 /* page structure */
#ifdef FTP_NAMES
char *strunames[] = {"0", "File", "Record", "Page" };
#endif
/*
* Mode types
*/
#define MODE_S 1 /* stream */
#define MODE_B 2 /* block */
#define MODE_C 3 /* compressed */
#ifdef FTP_NAMES
char *modenames[] = {"0", "Stream", "Block", "Compressed" };
#endif
/*
* Record Tokens
*/
#define REC_ESC '\377' /* Record-mode Escape */
#define REC_EOR '\001' /* Record-mode End-of-Record */
#define REC_EOF '\002' /* Record-mode End-of-File */
/*
* Block Header
*/
#define BLK_EOR 0x80 /* Block is End-of-Record */
#define BLK_EOF 0x40 /* Block is End-of-File */
#define BLK_ERRORS 0x20 /* Block is suspected of containing errors */
#define BLK_RESTART 0x10 /* Block is Restart Marker */
#define BLK_BYTECOUNT 2 /* Bytes in this block */

View File

@@ -0,0 +1,114 @@
/*
* Copyright (c) 1985 Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* @(#)ftp_var.h 5.5 (Berkeley) 6/29/88
*/
/*
* FTP global variables.
*/
/*
* Options and other state info.
*/
int trace; /* trace packets exchanged */
int hash; /* print # for each buffer transferred */
int sendport; /* use PORT cmd for each data connection */
int verbose; /* print messages coming back from server */
int connected; /* connected to server */
int fromatty; /* input is from a terminal */
int interactive; /* interactively prompt on m* cmds */
int debug; /* debugging level */
int bell; /* ring bell on cmd completion */
int doglob; /* glob local file names */
int autologin; /* establish user account on connection */
int anonlogin; /* login user as anonymous */
int proxy; /* proxy server connection active */
int proxflag; /* proxy connection exists */
int sunique; /* store files on server with unique name */
int runique; /* store local files with unique name */
int mcase; /* map upper to lower case for mget names */
int ntflag; /* use ntin ntout tables for name translation */
int mapflag; /* use mapin mapout templates on file names */
int code; /* return/reply code for ftp command */
int crflag; /* if 1, strip car. rets. on ascii gets */
char pasv[64]; /* passive port for proxy data connection */
char *altarg; /* argv[1] with no shell-like preprocessing */
char ntin[17]; /* input translation table */
char ntout[17]; /* output translation table */
#include <sys/param.h>
#ifndef MAXPATHLEN
#define MAXPATHLEN 1024
#endif
char mapin[MAXPATHLEN]; /* input map template */
char mapout[MAXPATHLEN]; /* output map template */
char typename[32]; /* name of file transfer type */
int type; /* file transfer type */
char structname[32]; /* name of file transfer structure */
int stru; /* file transfer structure */
char formname[32]; /* name of file transfer format */
int form; /* file transfer format */
char modename[32]; /* name of file transfer mode */
int mode; /* file transfer mode */
char bytename[32]; /* local byte size in ascii */
int bytesize; /* local byte size in binary */
char *hostname; /* name of host connected to */
struct servent *sp; /* service spec for tcp/ftp */
int ftpport; /* FTP port obtained from sp */
#include <setjmp.h>
jmp_buf toplevel; /* non-local goto stuff for cmd scanner */
char line[200]; /* input line buffer */
char *stringbase; /* current scan point in line buffer */
char argbuf[200]; /* argument storage buffer */
char *argbase; /* current storage point in arg buffer */
int margc; /* count of arguments on input line */
char *margv[20]; /* args parsed from input line */
int cpend; /* flag: if != 0, then pending server reply */
int mflag; /* flag: if != 0, then active multi command */
int options; /* used during socket creation */
/*
* Format of command table.
*/
struct cmd {
char *c_name; /* name of command */
char *c_help; /* help string */
char c_bell; /* give bell when command completes */
char c_conn; /* must be connected to use command */
char c_proxy; /* proxy server may execute */
int (*c_handler)(); /* function to call */
};
struct macel {
char mac_name[9]; /* macro name */
char *mac_start; /* start of macro in macbuf */
char *mac_end; /* end of macro in macbuf */
};
int macnum; /* number of defined macros */
struct macel macros[16];
char macbuf[4096];
extern char *tail();
extern char *remglob();
extern char *mktemp();
#include <string.h>
#include <errno.h>

View File

@@ -0,0 +1,470 @@
/*
* Copyright (c) 1992, 1993 by the University of Southern California
*
* For copying and distribution information, please see the file <usc-copyr.h>.
*/
/* gopherget.c
Part of the program "vcache" in the Prospero distribution.
This allows Prospero clients to use the GOPHER access method (i.e., to
retrieve files sitting on Gopher servers.)
Written: swa@isi.edu, 7/13/92 -- 7/15/92
Comments improved 8/6/92
Gopher TEXT access method made considerably looser 6/30/93
Got rid of necessity for writev. 9/15/93
*/
#include <usc-copyr.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <perrno.h>
#include <pmachine.h>
#ifdef HAVE_WRITEV
#include <sys/uio.h> /* for writev */
#endif
#include <pfs.h> /* for assert() and internal_error() */
#include "vcache_macros.h"
/* If it doesnt respond in 5 secs, its probably gone away */
#define G_READ_TIMEOUT 5
#define G_OPEN_TIMEOUT 5
extern int pfs_debug, cache_verbose;
/* Use the Gopher protocol. Get the file denoted by the SELECTOR_STRING
from the Gopher server running at port PORT of HOST. Stores that file in
the local file named LOCAL. Return non-zero on error; 0 if OK. If it
returns non-zero, the existence and contents of the file LOCAL are
indeterminate. (If this presents a problem, we'll have to rewrite the code
to do the unlinking). */
int
gopherget(char *host, char *local, char *selector_string, int port,
int gophertype /* actually char, but make sure default
promotions work. */ )
{
FILE *local_file; /* file pointer for local destination */
int remote_sock; /* File Descriptor for remote socket. */
int retval; /* error status return. */
static int vcache_open_tcp_stream(), send_line();
int (*retrieval_method)(); /* What method will we use to retrieve this
file? Null means none. */
/* function to call to find out Gopher retrieval method. */
/* precede 'gophertype' with an _ to get rid of bogus whines from GCC 2.5.8
with -Wshadow. */
static int (*get_retrieval_method(int _gophertype))();
TRACE(5, "vcache: Attempting to retrieve remote document \"%s\" \n\
via Gopher from port %d of host %s\n", selector_string, port, host);
retrieval_method = get_retrieval_method(gophertype);
if (!retrieval_method)
return 1; /* Failure. */
/* Open Local Destination file. Note that PFS has already been disabled.
*/
local_file = fopen(local, "w");
if (local_file == NULL) {
ERRSYS("vcache: Couldn't create the local file %s:%s %s ", local);
return 1;
}
/* Open TCP stream to remote gopher server. */
TRACE(5,"Calling vcache_open_tcp_stream(host = %s, port = %d)\n",
host, port);
if ((remote_sock = vcache_open_tcp_stream(host, port)) < 0) {
/* No need to set p_err_string, vcache_open_tcp_stream will */
fclose(local_file);
return 1;
}
TRACE(5,"Sending selector string to remote GOPHER: %s\n",
selector_string);
/* At this point, if any errors occur, we still try to clean up as neatly
as possible. */
retval = send_line(remote_sock, selector_string);
if (!retval)
retval = (*retrieval_method)(remote_sock, local_file);
if (!retval && cache_verbose)
puts("vcache: Retrieval completed.");
if (fclose(local_file)) {
TRACE(5, "vcache: Error attempting to close local file \
%s\n", local);
retval = 1;
}
/* Close down both ends of the connection. shutdown() allegedly performs
actions that close() defers. */
if (shutdown(remote_sock, 2)) {
ERRSYS("vcache: shutdown(remote_sock, 2) failed:%s %s");
retval = 1;
}
if (close(remote_sock)) {
ERRSYS("vcache: close(remote_sock) failed:%s %s");
retval = 1;
}
if (retval)
return 1; /* failure. */
else
return 0; /* Done. Success! */
}
/* Open a TCP stream from here to the HOST at the PORT. */
/* Return socket descriptor on success, or -1 on failure. */
/* On failure set p_err_string to "user" friendly error message */
static int
vcache_open_tcp_stream(char host[],int port)
{
TRACE(2,"vcache: quick_open_tcp_stream(host=%s;port=%d;time=%d)\n",
host, port, G_OPEN_TIMEOUT);
/* Dont need to set error message - quick_open_tcp_stream sets p_err_string
to user-friendly error message */
return(quick_open_tcp_stream(host,port, G_OPEN_TIMEOUT));
}
/* Send a line to the remote host. The line we're given is NOT crlf
terminated. */
/* We use writev because it's more efficient than two writes (and saves copying
operations). The Berkeley TCP implementation lacks a "push" command, so
there's an implicit push after each "write" or "writev". */
/* Return nonzero if failure; 0 if success */
static int
send_line(remote_sock, str)
int remote_sock; /* A connected TCP socket */
char str[];
{
int expected_count; /* # of bytes we expect to send. */
int bytes_sent; /* # of bytes we actually sent. */
#ifdef HAVE_WRITEV
struct iovec iov[2];
iov[0].iov_base = str;
iov[0].iov_len = strlen(str);
iov[1].iov_base = "\r\n";
iov[1].iov_len = 2;
expected_count = iov[0].iov_len + iov[1].iov_len;
/* Selector strings are short enough that we should never send a partial
packet. */
bytes_sent = writev(remote_sock, iov, 2);
#else
static char *buf = NULL;
buf = qsprintf_stcopyr(buf, "%s\r\n", str);
expected_count = strlen(buf);
/* Gopher selector strings are short enough that we should never send a
partial packet. */
bytes_sent = write(remote_sock, buf, expected_count);
#endif /* HAVE_WRITEV */
if (bytes_sent != expected_count) {
ERRSYS("vcache: Error sending selector string %s to gopher server. \
\tExpected to send %d bytes; write() or writev() reported sending only %d. %s %s",
str, expected_count, bytes_sent);
return 1;
}
return 0;
}
/* Read a gopher text stream from in_sock and save it in out_file.
Gopher text lines are terminated with crlf.
Their last line consists of ".\r\n".
This is implemented as a simple DFA.
*/
/* 6/30/93:
We do full error recovery & don't complain by default, since I've now
learned that the format is followed rather loosely. Thus the LOOSE
definition. */
#define LOOSE
static
int
receive_gopher_text(in_sock, out)
int in_sock; /* Input socket for Gopher text */
FILE *out; /* Where to save the received text. */
{
char buf[BUFSIZ]; /* buffer for reading. */
register int numread; /* Number of bytes actually read. */
char *complaint = NULL; /* Might be set to a string that contains a
complaint about the remote format. This is
usually used for recoverable errors. */
enum states { BOL, /* Beginning of line */
GOT_BEG_DOT, /* Got '.' following BOL */
MID_LINE, /* middle of line */
GOT_DOT_CR, /* Got ".\r",Expect LF */
GOT_CR, /* Got CR; expect LF */
EOT, /* got ".\r\n" by itself */
#ifndef LOOSE
BAD /* something gross happened. We have
complained about it and are now just marking
time. */
#endif
} state;
state = BOL;
while((numread = quick_read(in_sock, buf, sizeof buf, G_READ_TIMEOUT)) > 0) {
register int i;
/* Process the characters we read. */
for (i = 0; i < numread; ++i) {
register char c = buf[i]; /* current character */
switch(state) {
case BOL:
#ifdef LOOSE
case_bol: /* a label to go to from EOT. */
#endif
switch(c) {
case '.':
state = GOT_BEG_DOT;
break;
case '\r':
state = GOT_CR;
break;
case '\n':
complaint = "Got LF without CR";
putc(c, out);
state = BOL;
break;
default:
putc(c, out);
state = MID_LINE;
break;
}
break;
case GOT_BEG_DOT:
if (c == '.') {
putc('.', out);
state = MID_LINE;
} else if (c == '\r') {
state = GOT_DOT_CR;
} else if (c == '\n') {
complaint = "Got LF without CR";
state = EOT;
} else {
complaint = "Got initial dot without following dot or EOL";
putc('.', out);
putc(c, out);
state = MID_LINE;
}
break;
case MID_LINE:
if (c == '\r') {
state = GOT_CR;
} else if (c == '\n') {
complaint = "Got LF without CR";
putc('\n', out);
state = BOL;
} else {
putc(c, out);
state = MID_LINE;
}
break;
case GOT_DOT_CR:
if (c != '\n') {
complaint = "Got . CR without LF";
#ifdef LOOSE
putc('.', out);
putc('\n', out);
goto case_bol;
#else
state = BAD;
#endif
} else {
state = EOT;
}
break;
case GOT_CR:
if (c != '\n') {
complaint = "Got CR without LF";
#ifdef LOOSE
putc('\n', out);
putc(c, out);
goto case_bol;
#else
state = BAD;
#endif
} else {
putc('\n', out);
state = BOL;
}
break;
case EOT:
/* If we get text after EOT, just keep on gobbling it up. This
is not a fatal error, merely a warning. */
complaint = "Got text after EOT";
#ifdef LOOSE
putc('.', out);
putc('\n', out);
goto case_bol;
#endif
break;
#ifndef LOOSE
case BAD: /* nothing more to do */
goto abort;
break;
#endif
default:
ERR("vcache: Internal error in line %d of file %s:\
unhandled case %s", __LINE__, __FILE__);
return(-1);
break;
}
}
}
abort:
if (complaint && cache_verbose)
ERR("vcache: we encountered incorrect formatting when\
reading from remote server: %s. \
This is not a serious problem by itself, and the retrieval did not\
necessarily fail, but you should notify your system maintainer %s", complaint);
if (numread < 0) { /* If read() returned an error */
ERRSYS("vcache: read from remote gopher server failed:%s %s");
return -1;
}
#ifndef LOOSE
if (state == EOT) /* normal completion (possibly with warnings,
but all errors seem recoverable.) */
#endif
return 0; /* success */
#ifndef LOOSE
ERR(stderr, "vcache: Premature end of transmission while \
reading text from remote gopher server. %s");
return -1;
#endif
}
/* Read a gopher binary stream from in_sock and save it in out_file.
Keep on consuming it until end of transmission. */
static
int
receive_gopher_binary(in_sock, out)
int in_sock; /* Input socket for Gopher text */
FILE *out; /* Where to save the received text. */
{
char buf[BUFSIZ]; /* buffer for reading & writing. */
register int numread; /* Number of bytes actually read. */
while((numread = quick_read(in_sock, buf, sizeof buf, G_READ_TIMEOUT)) > 0) {
/* We might be writing to a pipe, so we might not be able to write an
entire buffer at once.
Write out the buffer, possibly in multiple chunks. */
int i;
int numwritten;
for (i = 0; i < numread; i += numwritten) {
numwritten = fwrite(&buf[i], sizeof buf[0], numread - i, out);
if (numwritten == 0) { /* write error! */
ERR("vcache: receive_gopher_binary(): write error %s");
return -1; /* error */
}
}
}
if (numread == 0) /* EOF! */
return 0; /* success */
else if (numread < 0) { /* If read() returned an error */
ERRSYS("vcache: read from remote gopher server failed:%s %s");
return -1;
} else {
/* should never get here! */
ERR("vcache: Internal error at line %d of file %s. %s",
__LINE__, __FILE__);
return(-1);
/*NOTREACHED*/
}
}
/* Check 1st character of gopher selector string to decide if retrieval
method is supported. If no retrieval method, punt.
This table of retrieval methods comes from Edward Vielmetti's 13 July 1992
article in alt.gopher.
*/
/*
These use the Gopher TEXT retrieval method.
0 A_FILE Text file.
4 A_MACHEX Macintosh Binhex (.hqx) text file.
c A_CALENDAR Calendar text file.
e A_EVENT Event text file.
M A_MIME MIME (RFC 1341) text file.
These use the Gopher BINARY retrieval method.
9 A_UNIXBIN Binary file.
g A_GIF GIF (Graphics Interchange Format) binary file.
s A_SOUND Sound (8 bit u-law, no headers ?) binary file.
things to do with data as it's flying back at you:
- treat as binary, read until connection drops,
send to file A_UNIXBIN
send to process A_SOUND
send to screen A_GIF
- treat as text, read til "." alone on line,
send to screen A_FILE
send to process A_MIME
A_CALENDAR
A_EVENT
send to file A_MACHEX
*/
/* In addition, the gopher protocol.txt document describes two obsolete types
(use of these types is discouraged) which Ed has not mentioned in his
letter. I'll include them in the table
below, because we want to support as many types as possible. They are:
Type 5: DOS binary archive of some kind (binary)
Type 6: UUencoded UNIX file (text).
*/
struct {
char type_char;
int (*func)();
char *name;
} retrieval_method_tab[] = {
{'0', receive_gopher_text, "GOPHER_TEXT"},
{'4', receive_gopher_text, "GOPHER_TEXT"},
{'c', receive_gopher_text, "GOPHER_TEXT"},
{'e', receive_gopher_text, "GOPHER_TEXT"},
{'M', receive_gopher_text, "GOPHER_TEXT"},
{'9', receive_gopher_binary, "GOPHER_BINARY"},
{'g', receive_gopher_binary, "GOPHER_BINARY"},
{'s', receive_gopher_binary, "GOPHER_BINARY"},
{'5', receive_gopher_binary, "GOPHER_BINARY"},
{'6', receive_gopher_text, "GOPHER_TEXT" },
{'\0', NULL, NULL}
};
static
int
(*get_retrieval_method(int gophertype))() /* actually char. */
{
int i;
for (i = 0; retrieval_method_tab[i].type_char != '\0'; ++i) {
if (gophertype == retrieval_method_tab[i].type_char) {
TRACE(5,"Using retrieval method: %s\n",
retrieval_method_tab[i].name);
return retrieval_method_tab[i].func;
}
}
ERR("vcache: Can't retrieve document -- item type %c \
unsupported. %s", gophertype);
return NULL;
}

156
prospero/user/vcache/main.c Normal file
View File

@@ -0,0 +1,156 @@
/* This is the main function for the Prospero program vcache.
Exit with status 0 if file retrieval was successful; nonzero if it was not.
This is called only by p__map_cache(), in lib/pcompat/pmap_cache.c and by
VGET in user/vget.c
*/
/*
* Copyright (c) 1991, 1992, 1993 by the University of Southern California
*
* For copying and distribution information, please see the file
* <usc-license.h>
*/
#include <usc-license.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <pfs.h>
#include <pcompat.h>
#include <perrno.h>
/* Variables declared in ftp_var.h */
extern int verbose;
extern int options;
extern int debug;
extern int trace;
/* Variables declared in vcache.c*/
extern int cache_verbose;
int pfs_debug = 0;
void
main(argc, argv)
int argc;
char *argv[];
{
int retval;
pfs_enable = PMAP_DISABLE;
if (retval = vcache1(argc,argv))
fprintf(stderr,"%s\n",p_err_string);
exit(retval);
}
/* This next routine could go in the library as well, if anything wants
to set options this way */
int
vcache1(argc, argv)
int argc;
char *argv[];
{
int manage_cache = 0; /* Must be set to manage the cache. */
int replace = 0; /* set, but never used */
int flush = 0; /* set, but never used */
char *host; /* remote host */
char *remote; /* remote filename */
char *local; /* local filename */
char *method; /* access method */
int retval;
vcache2_init();
p_initialize("VCACHE",0,NULL);
argc--;argv++;
while (argc > 0 && *argv[0] == '-') {
switch (*(argv[0]+1)) {
case 'D':
pfs_debug = 1; /* Default debug level */
verbose = 1; /* maximum verbosity */
cache_verbose = 1; /* verbosity -- see -v flag */
sscanf(argv[0],"-D%d",&pfs_debug);
options |= SO_DEBUG;
debug++;
break;
case 'f':
flush = 1;
break;
case 'm':
manage_cache = 1;
break;
case 'r':
replace = 1;
break;
case 't': /* FTP Trace */
trace++;
break;
case 'v':
verbose = 1; /* need to unify verbose and cache_verbose
variables -- they are used identically. */
cache_verbose = 1;
break;
case '\0': /* Ignore the dummy flag "-". This lets us
specify flags easily to execl(). */
break;
default: {
usage:
/* Note this doesnt use getopts, so the old usage
message was wrong, flags must be separated*/
fprintf(stderr,
"Usage: vcache [-f] [-m] [-r] [-v] local access-method-name hosttype \
host nametype name [additional args...]\n");
return(1);
} /* enclosing case of switch */
} /* switch */
argc--; argv++;
}
if((argc == 1) && flush) {
host = NULL;
remote = NULL;
local = argv[0]; argc--; argv++;
method = NULL;
}
else if((argc == 0) && flush) {
host = NULL;
remote = NULL;
local = NULL;
method = NULL;
}
else if(argc >= 6) {
local = argv[0]; argc--; argv++;
method = argv[0]; argc--; argv++;
if (!strequal(argv[0], "INTERNET-D")) goto usage;
argc--, argv++; /* hosttype always INTERNET-D for now. */
host = argv[0]; argc--; argv++;
if (!strequal(argv[0], "ASCII")) goto usage;
argc--, argv++; /* filetype always ASCII for now. */
remote = argv[0]; argc--; argv++;
}
else {
goto usage;
}
if (retval = vcache2a(host, remote, local, method, argv, manage_cache))
fprintf(stderr, "vcache: %s", p_err_string);
exit(retval);
}

View File

@@ -0,0 +1,130 @@
/*
* Copyright (c) 1980 Regents of the University of California.
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
*/
#ifndef lint
static char sccsid[] = "@(#)pclose.c 1.2 (Berkeley) 3/7/86";
#endif not lint
#include <stdio.h>
#include <posix_signal.h>
#include <sys/param.h>
#include <sys/wait.h>
#include <stdlib.h> /* For malloc and free */
#include <pmachine.h>
#include <implicit_fixes.h>
#include <pfs_threads.h> /* For P_IS_THIS_THREAD_MASTER */
#define tst(a,b) (*mode == 'r'? (b) : (a))
#define RDR 0
#define WTR 1
static int *popen_pid;
static int nfiles;
#ifdef SOLARIS
/* Should be defined in stdio.h */
extern FILE *fdopen(const int fd, const char *opt);
#endif
FILE *
mypopen(cmd,mode)
char *cmd;
char *mode;
{
int p[2];
int myside, hisside, pid;
if (nfiles <= 0)
nfiles = NFILES;
if (popen_pid == NULL) {
popen_pid = (int *)malloc((unsigned) nfiles * sizeof *popen_pid);
if (popen_pid == NULL)
return (NULL);
for (pid = 0; pid < nfiles; pid++)
popen_pid[pid] = -1;
}
if (pipe(p) < 0)
return (NULL);
myside = tst(p[WTR], p[RDR]);
hisside = tst(p[RDR], p[WTR]);
#if defined(AIX)
if ((pid = fork()) == 0) {
#else
if ((pid = vfork()) == 0) {
#endif
/* myside and hisside reverse roles in child */
(void) close(myside);
if (hisside != tst(0, 1)) {
assert(P_IS_THIS_THREAD_MASTER()); /* SOLARIS: dup2 MT-Unsafe */
(void) dup2(hisside, tst(0, 1));
(void) close(hisside);
}
execl("/bin/sh", "sh", "-c", cmd, (char *)NULL);
_exit(127);
}
if (pid == -1) {
(void) close(myside);
(void) close(hisside);
return (NULL);
}
popen_pid[myside] = pid;
(void) close(hisside);
return (fdopen(myside, mode));
}
void
pabort()
{
extern int mflag;
mflag = 0;
}
int
mypclose(ptr)
FILE *ptr;
{
int child, pid;
#ifdef POSIX_SIGNALS
sigset_t set,omask_set;
#else
int omask;
#endif /*POSIX_SIGNALS*/
void pabort();
SIGNAL_RET_TYPE (*istat)();
#ifdef BSD_UNION_WAIT
/* This is guesswork, SCO doesnt support "union wait", so I copied from vget.c*/
union wait status;
#else
int status;
#endif
child = popen_pid[fileno(ptr)];
popen_pid[fileno(ptr)] = -1;
(void) fclose(ptr);
if (child == -1)
return (-1);
istat = signal(SIGINT, pabort);
#ifdef POSIX_SIGNALS
sigemptyset(&set);
sigaddset(&set,SIGQUIT);
sigaddset(&set,SIGHUP);
sigprocmask(SIG_BLOCK, &set, &omask_set);
#else
omask = sigblock(sigmask(SIGQUIT)|sigmask(SIGHUP));
#endif
while ((pid = wait(&status)) != child && pid != -1)
;
#ifdef POSIX_SIGNALS
sigprocmask(SIG_SETMASK,&omask_set,(sigset_t *)NULL);
#else
(void) sigsetmask(omask);
#endif /*POSIX_SIGNALS*/
(void) signal(SIGINT, istat);
return (pid == -1 ? -1 : 0);
}

View File

@@ -0,0 +1,284 @@
/*
* Copyright (c) 1985 Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef lint
static char sccsid[] = "@(#)ruserpass.c 5.3 (Berkeley) 3/1/91";
#endif /* not lint */
#include <sys/types.h>
#include <stdio.h>
#include <utmp.h>
#include <ctype.h>
#include <sys/stat.h>
#include <errno.h>
#include "ftp_var.h" /* Dangerous ambiguous includes !!*/
#include <sys/socket.h> /* SCOUNIX needs MAXHOSTNAMELEN*/
#include "vcache_macros.h"
#include <pmachine.h> /* MAXHOSTNAMELEN for SOLARIS */
#include <stdlib.h> /* For malloc and free */
#include <perrno.h>
#include <string_with_strcasecmp.h>
char *renvlook(), *index(), *getenv(), *getpass(), *getlogin();
char *strcpy();
struct utmp *getutmp();
static FILE *cfile;
#define DEFAULT 1
#define LOGIN 2
#define PASSWD 3
#define ACCOUNT 4
#define MACDEF 5
#define ID 10
#define MACH 11
static char tokval[100];
static struct toktab {
char *tokstr;
int tval;
} toktab[]= {
"default", DEFAULT,
"login", LOGIN,
"password", PASSWD,
"passwd", PASSWD,
"account", ACCOUNT,
"machine", MACH,
"macdef", MACDEF,
0, 0
};
int
ruserpass(char *host, char **aname, char **apass, char **aacct)
{
char *hdir, buf[BUFSIZ], *tmp;
char myname[MAXHOSTNAMELEN], *mydomain;
int t, i, c, usedefault = 0;
struct stat stb;
static int token();
hdir = getenv("HOME");
if (hdir == NULL)
hdir = ".";
(void) sprintf(buf, "%s/.netrc", hdir);
cfile = fopen(buf, "r");
if (cfile == NULL) {
if (errno != ENOENT)
ERRSYS("%s %s %s",buf);
return(0);
}
if (gethostname(myname, sizeof(myname)) < 0)
myname[0] = '\0';
if ((mydomain = index(myname, '.')) == NULL)
mydomain = "";
next:
while ((t = token())) switch(t) {
case DEFAULT:
usedefault = 1;
/* FALL THROUGH */
case MACH:
if (!usedefault) {
if (token() != ID)
continue;
/*
* Allow match either for user's input host name
* or official hostname. Also allow match of
* incompletely-specified host in local domain.
*/
if (strcasecmp(host, tokval) == 0)
goto match;
if (strcasecmp(hostname, tokval) == 0)
goto match;
if ((tmp = index(hostname, '.')) != NULL &&
strcasecmp(tmp, mydomain) == 0 &&
strncasecmp(hostname, tokval, tmp-hostname) == 0 &&
tokval[tmp - hostname] == '\0')
goto match;
if ((tmp = index(host, '.')) != NULL &&
strcasecmp(tmp, mydomain) == 0 &&
strncasecmp(host, tokval, tmp - host) == 0 &&
tokval[tmp - host] == '\0')
goto match;
continue;
}
match:
while ((t = token()) && t != MACH && t != DEFAULT) switch(t) {
case LOGIN:
if (token())
if (*aname == 0) {
*aname = malloc((unsigned) strlen(tokval) + 1);
(void) strcpy(*aname, tokval);
} else {
if (strcmp(*aname, tokval))
goto next;
}
break;
case PASSWD:
if (strcmp(*aname, "anonymous") &&
fstat(fileno(cfile), &stb) >= 0 &&
(stb.st_mode & 077) != 0) {
ERR("Error - .netrc file not correct mode. \
Remove password or correct mode. %s");
goto bad;
}
if (token() && *apass == 0) {
*apass = malloc((unsigned) strlen(tokval) + 1);
(void) strcpy(*apass, tokval);
}
break;
case ACCOUNT:
if (fstat(fileno(cfile), &stb) >= 0
&& (stb.st_mode & 077) != 0) {
ERR("Error - .netrc file not correct mode. \
Remove password or correct mode. %s");
goto bad;
}
if (token() && *aacct == 0) {
*aacct = malloc((unsigned) strlen(tokval) + 1);
(void) strcpy(*aacct, tokval);
}
break;
case MACDEF:
if (proxy) {
(void) fclose(cfile);
return(0);
}
while ((c=getc(cfile)) != EOF && c == ' ' || c == '\t');
if (c == EOF || c == '\n') {
ERR("Missing macdef name argument. %s");
goto bad;
}
if (macnum == 16) {
ERR("Limit of 16 macros have already been defined. %s");
goto bad;
}
tmp = macros[macnum].mac_name;
*tmp++ = c;
for (i=0; i < 8 && (c=getc(cfile)) != EOF &&
!isspace(c); ++i) {
*tmp++ = c;
}
if (c == EOF) {
ERR("Macro definition missing null line terminator. %s");
goto bad;
}
*tmp = '\0';
if (c != '\n') {
while ((c=getc(cfile)) != EOF && c != '\n');
}
if (c == EOF) {
ERR("Macro definition missing null line terminator. %s");
goto bad;
}
if (macnum == 0) {
macros[macnum].mac_start = macbuf;
}
else {
macros[macnum].mac_start = macros[macnum-1].mac_end + 1;
}
tmp = macros[macnum].mac_start;
while (tmp != macbuf + 4096) {
if ((c=getc(cfile)) == EOF) {
ERR("Macro definition missing null line terminator. %s");
goto bad;
}
*tmp = c;
if (*tmp == '\n') {
if (*(tmp-1) == '\0') {
macros[macnum++].mac_end = tmp - 1;
break;
}
*tmp = '\0';
}
tmp++;
}
if (tmp == macbuf + 4096) {
ERR("4K macro buffer exceeded. %s");
goto bad;
}
break;
default:
ERR("Unknown .netrc keyword %s", tokval);
break;
}
goto done;
}
done:
(void) fclose(cfile);
return(0);
bad:
(void) fclose(cfile);
return(-1);
}
static int
token()
{
char *cp;
int c;
struct toktab *t;
if (feof(cfile))
return (0);
while ((c = getc(cfile)) != EOF &&
(c == '\n' || c == '\t' || c == ' ' || c == ','))
continue;
if (c == EOF)
return (0);
cp = tokval;
if (c == '"') {
while ((c = getc(cfile)) != EOF && c != '"') {
if (c == '\\')
c = getc(cfile);
*cp++ = c;
}
} else {
*cp++ = c;
while ((c = getc(cfile)) != EOF
&& c != '\n' && c != '\t' && c != ' ' && c != ',') {
if (c == '\\')
c = getc(cfile);
*cp++ = c;
}
}
*cp = 0;
if (tokval[0] == 0)
return (0);
for (t = toktab; t->tokstr; t++)
if (!strcmp(t->tokstr, tokval))
return (t->tval);
return (ID);
}

View File

@@ -0,0 +1,205 @@
/*
* Copyright (c) 1983 Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted provided
* that: (1) source distributions retain this entire copyright notice and
* comment, and (2) distributions including binaries display the following
* acknowledgement: ``This product includes software developed by the
* University of California, Berkeley and its contributors'' in the
* documentation or other materials provided with the distribution and in
* all advertising materials mentioning features or use of this software.
* Neither the name of the University nor the names of its contributors may
* be used to endorse or promote products derived from this software without
* specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* @(#)telnet.h 5.10 (Berkeley) 6/28/90
*/
/*
* Definitions for the TELNET protocol.
*/
#define IAC 255 /* interpret as command: */
#define DONT 254 /* you are not to use option */
#define DO 253 /* please, you use option */
#define WONT 252 /* I won't use option */
#define WILL 251 /* I will use option */
#define SB 250 /* interpret as subnegotiation */
#define GA 249 /* you may reverse the line */
#define EL 248 /* erase the current line */
#define EC 247 /* erase the current character */
#define AYT 246 /* are you there */
#define AO 245 /* abort output--but let prog finish */
#define IP 244 /* interrupt process--permanently */
#define BREAK 243 /* break */
#define DM 242 /* data mark--for connect. cleaning */
#define NOP 241 /* nop */
#define SE 240 /* end sub negotiation */
#define EOR 239 /* end of record (transparent mode) */
#define ABORT 238 /* Abort process */
#define SUSP 237 /* Suspend process */
#define xEOF 236 /* End of file: EOF is already used... */
#define SYNCH 242 /* for telfunc calls */
#ifdef TELCMDS
char *telcmds[] = {
"EOF", "SUSP", "ABORT", "EOR",
"SE", "NOP", "DMARK", "BRK", "IP", "AO", "AYT", "EC",
"EL", "GA", "SB", "WILL", "WONT", "DO", "DONT", "IAC",
};
#define TELCMD_FIRST xEOF
#define TELCMD_LAST IAC
#define TELCMD_OK(x) ((x) <= TELCMD_LAST && (x) >= TELCMD_FIRST)
#define TELCMD(x) telcmds[(x)-TELCMD_FIRST]
#endif
/* telnet options */
#define TELOPT_BINARY 0 /* 8-bit data path */
#define TELOPT_ECHO 1 /* echo */
#define TELOPT_RCP 2 /* prepare to reconnect */
#define TELOPT_SGA 3 /* suppress go ahead */
#define TELOPT_NAMS 4 /* approximate message size */
#define TELOPT_STATUS 5 /* give status */
#define TELOPT_TM 6 /* timing mark */
#define TELOPT_RCTE 7 /* remote controlled transmission and echo */
#define TELOPT_NAOL 8 /* negotiate about output line width */
#define TELOPT_NAOP 9 /* negotiate about output page size */
#define TELOPT_NAOCRD 10 /* negotiate about CR disposition */
#define TELOPT_NAOHTS 11 /* negotiate about horizontal tabstops */
#define TELOPT_NAOHTD 12 /* negotiate about horizontal tab disposition */
#define TELOPT_NAOFFD 13 /* negotiate about formfeed disposition */
#define TELOPT_NAOVTS 14 /* negotiate about vertical tab stops */
#define TELOPT_NAOVTD 15 /* negotiate about vertical tab disposition */
#define TELOPT_NAOLFD 16 /* negotiate about output LF disposition */
#define TELOPT_XASCII 17 /* extended ascic character set */
#define TELOPT_LOGOUT 18 /* force logout */
#define TELOPT_BM 19 /* byte macro */
#define TELOPT_DET 20 /* data entry terminal */
#define TELOPT_SUPDUP 21 /* supdup protocol */
#define TELOPT_SUPDUPOUTPUT 22 /* supdup output */
#define TELOPT_SNDLOC 23 /* send location */
#define TELOPT_TTYPE 24 /* terminal type */
#define TELOPT_EOR 25 /* end or record */
#define TELOPT_TUID 26 /* TACACS user identification */
#define TELOPT_OUTMRK 27 /* output marking */
#define TELOPT_TTYLOC 28 /* terminal location number */
#define TELOPT_3270REGIME 29 /* 3270 regime */
#define TELOPT_X3PAD 30 /* X.3 PAD */
#define TELOPT_NAWS 31 /* window size */
#define TELOPT_TSPEED 32 /* terminal speed */
#define TELOPT_LFLOW 33 /* remote flow control */
#define TELOPT_LINEMODE 34 /* Linemode option */
#define TELOPT_XDISPLOC 35 /* X Display Location */
#define TELOPT_ENVIRON 36 /* Environment variables */
#define TELOPT_AUTHENTICATION 45 /* XXX Auto Authenticate */
#define TELOPT_EXOPL 255 /* extended-options-list */
#define NTELOPTS (1+TELOPT_AUTHENTICATION)
#ifdef TELOPTS
char *telopts[NTELOPTS] = {
"BINARY", "ECHO", "RCP", "SUPPRESS GO AHEAD", "NAME",
"STATUS", "TIMING MARK", "RCTE", "NAOL", "NAOP",
"NAOCRD", "NAOHTS", "NAOHTD", "NAOFFD", "NAOVTS",
"NAOVTD", "NAOLFD", "EXTEND ASCII", "LOGOUT", "BYTE MACRO",
"DATA ENTRY TERMINAL", "SUPDUP", "SUPDUP OUTPUT",
"SEND LOCATION", "TERMINAL TYPE", "END OF RECORD",
"TACACS UID", "OUTPUT MARKING", "TTYLOC",
"3270 REGIME", "X.3 PAD", "NAWS", "TSPEED", "LFLOW",
"LINEMODE", "XDISPLOC", "ENVIRON",
"UNKNOWN 37", "UNKNOWN 38", "UNKNOWN 39", "UNKNOWN 40", "UNKNOWN 41",
"UNKNOWN 42", "UNKNOWN 43", "UNKNOWN 44", "AUTHENTICATION",
};
#define TELOPT_FIRST TELOPT_BINARY
#define TELOPT_LAST TELOPT_AUTHENTICATION
#define TELOPT_OK(x) ((x) <= TELOPT_LAST && (x) >= TELOPT_FIRST)
#define TELOPT(x) telopts[(x)-TELOPT_FIRST]
#endif
/* sub-option qualifiers */
#define TELQUAL_IS 0 /* option is... */
#define TELQUAL_SEND 1 /* send option */
#define TELQUAL_INFO 2 /* ENVIRON: informational version of IS */
/*
* LINEMODE suboptions
*/
#define LM_MODE 1
#define LM_FORWARDMASK 2
#define LM_SLC 3
#define MODE_EDIT 0x01
#define MODE_TRAPSIG 0x02
#define MODE_ACK 0x04
#define MODE_SOFT_TAB 0x08
#define MODE_LIT_ECHO 0x10
#define MODE_MASK 0x1f
/* Not part of protocol, but needed to simplify things... */
#define MODE_FLOW 0x0100
#define MODE_ECHO 0x0200
#define MODE_INBIN 0x0400
#define MODE_OUTBIN 0x0800
#define MODE_FORCE 0x1000
#define SLC_SYNCH 1
#define SLC_BRK 2
#define SLC_IP 3
#define SLC_AO 4
#define SLC_AYT 5
#define SLC_EOR 6
#define SLC_ABORT 7
#define SLC_EOF 8
#define SLC_SUSP 9
#define SLC_EC 10
#define SLC_EL 11
#define SLC_EW 12
#define SLC_RP 13
#define SLC_LNEXT 14
#define SLC_XON 15
#define SLC_XOFF 16
#define SLC_FORW1 17
#define SLC_FORW2 18
#define NSLC 18
#define SLC_NAMES "0", "SYNCH", "BRK", "IP", "AO", "AYT", "EOR", \
"ABORT", "EOF", "SUSP", "EC", "EL", "EW", "RP", \
"LNEXT", "XON", "XOFF", "FORW1", "FORW2"
#define SLC_NOSUPPORT 0
#define SLC_CANTCHANGE 1
#define SLC_VARIABLE 2
#define SLC_DEFAULT 3
#define SLC_LEVELBITS 0x03
#define SLC_FUNC 0
#define SLC_FLAGS 1
#define SLC_VALUE 2
#define SLC_ACK 0x80
#define SLC_FLUSHIN 0x40
#define SLC_FLUSHOUT 0x20
#define ENV_VALUE 0
#define ENV_VAR 1
#define ENV_ESC 2
/*
* AUTHENTICATION suboptions
*/
#define TELQUAL_AUTHTYPE_NONE 0
#define TELQUAL_AUTHTYPE_PRIVATE 1
#define TELQUAL_AUTHTYPE_KERBEROS 2
/* Kerberos-specific */
#define TELQUAL_AUTHTYPE_KERBEROS_V4 4
#define TELQUAL_AUTHTYPE_KERBEROS_V5 5
#define TELQUAL_AUTHTYPE_KERBEROS_USERNAME 1

View File

@@ -0,0 +1,300 @@
/* This was the main function for the Prospero program vcache.
* return with status 0 if file retrieval was successful; nonzero if it was
* not. This is called only by p__map_cache(), in lib/pcompat/pmap_cache.c and
* by VGET in user/vget.c.
*
* The memory leaks have probably all been nailed by Mitra by now.
*/
/*
* Copyright (c) 1991-1994 by the University of Southern California
*
* For copying and distribution information, please see the file
* <usc-license.h>.
*/
#include <usc-license.h>
#include <stdio.h>
#include <sys/param.h>
#include <errno.h>
#include <pmachine.h> /*SCOUNIX needs sys/types.h*/
/* SOLARIS needs prototype for tempnam() */
/* #include "ftp_var.h" /* Nasty - doesnt declare these external */
extern int debug;
extern int trace;
extern int anonlogin;
#include "vcache.h"
#include <pfs.h>
#include <psite.h> /* for P_CACHE_ENABLED, among other
definitions. */
#include <perrno.h>
/* A lot of this code memory leaks - not a problem since it exits - but
a pain if going to incorporate inside anything else. */
/* Benjamin Britt wrote routines enabling VCACHE to retrieve files
using WAIS. These are not yet very useful, since modifications
need to be made to user/vget.c and lib/pfs/pget_am.c. Therefore, they are
commented out. #define WAIS and change the definitions of WAIS_LIBS and
WAIS_TARGETS in the Makefile in order to link them in, if you wish to
experiment with them and continue developing them. You will also need the
directory user/vcache/wais, which is not part of the standard distribution,
but will be sent on request.
#define WAIS
*/
#include "vcache_macros.h"
int cache_verbose = 0;
#define verbose cache_verbose
static int
prospero_contents_get(VLINK vl, char *local);
char *old_err_string = NULL;
void
vcache2_init()
{
debug = 0;
trace = 0;
}
/*
* If called with the MANAGE argument set, will manage the cache (if compiled
* for cache management); otherwise won't. Also, won't
* This is an exported interface in Mitra's use of the Prospero library.
* Not an exported interface otherwise.
*
* Returns 0 on success, -1 on FAILURE.
*/
int
vcache2a(char *host, char *remote, char *local, char *method,
char *argv[], int manage_cache)
{
#ifndef P_CACHE_ENABLED
p__mkdirs(local, FALSE);
return vc_get_file_A(host,remote,local,method,argv);
#else
/* Add code here to manage the cache */
/* This code implements the algorithm ...
if (fetch to P_CACHE_TMP)
then mv from P_CACHE_TMP to local, overwriting
if local exists, then success, else failure
NOTE this means it wont default to return a file that exists already
but if the retrieval fails and the file exists then you'll get it
- If someone doesnt like this behaviour, then change it with options.
*/
char *tempfile = NULL;
int retval;
char *tempfile = NULL;
if (!manage_cache) {
p__mkdirs(local, FALSE);
return vc_get_file_A(host,remote,local,method,argv);
}
if (p__mkdirs(P_CACHE_TMP,TRUE)) {
/* p_err_string already set */
RETURN(-1);
}
tempfile = tempnam(P_CACHE_TMP,NULL);
if ((retval = vc_get_file_A(host,remote,tempfile,method,argv))
== 0) {
/* Succeeded in fetching file */
if (file_incache(local)) {
if (unlink(local)) {
ERRSYS("Cant unlink existing %s %s %s",local);
RETURN(-1);
}
}
if (p__mkdirs(local,FALSE)) {
/* p_err_string already set */
RETURN(-1);
}
if (renameOrCopyAndDelete(tempfile,local)) {
/* p_err_string set */
RETURN(-1);
}
RETURN(0);
} else {
/* Couldnt retrieve, maybe in the cache already */
if (file_incache(local))
RETURN(0);
RETURN(-1);
}
assert(0); /* Unreached */
cleanup:
free(tempfile);
return(retval);
#endif
}
/*
* Retrieve the file with the HSONAME REMOTE from the computer HOST.
* Retrieve it to the file LOCAL using access-method METHOD.
* Arguments to the access method in argv.
*/
int
vc_get_file_A(char *host, char *remote, char *local, char *method,
char *argv[])
{
int retval = 0;
char *slash;
int argc;
/* Set ARGC appropriately. */
for (argc = 0; argv[argc]; ++argc)
;
/* If no method provided, then we are done */
if(!method) return(0);
/* Make the directory to include the cached copy */
/* if it does not already exist */
if (p__mkdirs(local,FALSE)) {
/* p_err_string already set */
return(1);
}
anonlogin = strequal(method,"AFTP");
if(anonlogin || strcmp(method,"FTP") == 0) {
char *trans_mode;
if(argc != 1) {
ERR( "vcache: wrong number of arguments for %s%s", method);
return(1);
}
trans_mode = argv[0];
if(strcmp(trans_mode,"DIRECTORY") == 0) {
ERR("File is the directory %s on the host %s which may not be running Prospero%s",
remote,host);
return(1);
}
/* Note "aftpget" used to do a exit*/
return(aftpget(host,local,remote,trans_mode));
} else if (strequal(method, "PROSPERO-CONTENTS")) {
VLINK vl = vlalloc();
if(argc != 0) {
ERR("vcache: wrong number of arguments for %s%s", method);
vlfree(vl);
return(1);
}
vl->host = stcopyr(host, vl->host);
vl->hsoname = stcopyr(remote, vl->hsoname);
retval = prospero_contents_get(vl, local);
vlfree(vl);
if(retval) return(1);
else return(0);
} else if (strcmp(method, "GOPHER") == 0) {
extern char *strchr();
/* Remote file name is Gopher selector string. */
/* port # included in the hostname. */
/* Check validity of the argument. */
register char *cp = strchr(host, '(');
int gopherport;
int gophertype;
if (argc != 1) {
ERR("vcache: The GOPHER access method expects \
one additional argument. Got %d arguments.%s", argc);
return(1);
}
if (cp == NULL) {
ERR("vcache: The GOPHER access method requires \
that the specified hostname have a port number included. Got the hostname \
%s.%s", host);
return(1);
}
*cp++ = '\0'; /* terminate the hostname normally.
cp now points to the port start. */
gopherport = atoi(cp);
if (strlen(argv[0]) == 1) {
gophertype = *argv[0];
} else if (strequal(argv[0], "BINARY")) {
gophertype = '9'; /* generic binary type */
} else if (strequal(argv[0], "TEXT")) {
gophertype = '0'; /* generic text type */
} else {
ERR("Malformed argument to GOPHER access method.%s");
return(1);
}
if(retval = gopherget(host,local,remote,gopherport, gophertype))
return(1);
else
return(0);
} if (strcmp(method,"WAIS") == 0) {
/* Note that the remote file name is actually the docid */
retval = waisRetrieveFileByHsoname(local,remote);
return(retval ? 1 : 0 );
} else {
ERR("vcache: access method (%s) not supported.%s",method);
return(1);
}
}
static int
prospero_contents_get(VLINK vl, char *local)
{
PATTRIB at = NULL;
FILE *local_file = NULL; /* file pointer for local destination */
int retval = PSUCCESS; /* return from function */
int need_newline = 0; /* set to 1 if data didn't end with a newline
*/
/* Seek multiple instances of the attribute. */
for (at = pget_at(vl,"CONTENTS"); at; at = at->next) {
TOKEN seq = at->value.sequence;
if (strequal(at->aname, "CONTENTS") && at->avtype == ATR_SEQUENCE &&
((length(seq) >= 2
&& strequal(seq->token, "DATA"))
|| (length(seq) >= 3
&& strequal(seq->token, "TAGGED")))) {
/* Found one. Open the file */
if (!local_file) {
local_file = fopen(local, "w");
if (local_file == NULL) {
ERRSYS ( "vcache: Couldn't create the local file %s: %s",
local);
RETURN(PFAILURE);
}
}
}
/* So, we now have a file open for output and something to put in it.
*/
if (need_newline) {
putc('\n', local_file);
need_newline = 0;
}
if (strequal(elt(seq, 0), "DATA")) {
p__fputbst(elt(seq, 1), local_file);
} else if (strequal(elt(seq, 0), "TAGGED")) {
char *s;
p__fputbst(elt(seq, 1), local_file);
fputs(": ", local_file);
need_newline = p__fputbst(elt(seq, 2), local_file);
} else
internal_error("Shouldn't get here with unrecognized attribute \
0th element.");
}
if (!local_file) {
ERR("vcache: Couldn't get remote object's CONTENTS attribute.%s");
RETURN(PFAILURE);
}
if (ferror(local_file)) retval = PFAILURE;
cleanup:
if (local_file) { if (fclose(local_file)) { retval = PFAILURE; } }
if (at) atfree(at);
return(retval);
}

View File

@@ -0,0 +1,11 @@
/*
* Copyright (c) 1992, 1993 by the University of Southern California
*
* For copying and distribution information, please see the file <usc-copyr.h>.
*/
#include <usc-copyr.h>
extern int gopherget(char *host, char *local, char *selector_string, int port,
int gophertype /* actually char, but make sure default
promotions work. */ );

View File

@@ -0,0 +1,33 @@
#ifndef VCACHE_MACROS_H
#define VCACHE_MACROS_H
#include <errno.h>
extern char *old_err_string;
#include <ardp.h> /* for pfs_debug declaration. */
#include <pfs.h> /* for unixerrstr() and qsprintf_stcopyr()
prototyped declarations. */
/* An error occured, the result is likely to be in errno */
#define ERRSYS(fmt, args...) { \
old_err_string = p_err_string; \
p_err_string = qsprintf_stcopyr(NULL,fmt, \
## args, \
old_err_string, \
(errno ? unixerrstr() : "")); \
}
#define ERR(args...) { \
old_err_string = p_err_string; \
p_err_string = qsprintf_stcopyr(NULL, \
## args, \
old_err_string); \
}
#define TRACE(level, args...) { \
if (pfs_debug >= level ) fprintf(stderr,## args); \
fflush(stderr); \
}
#define RETURN(val) { retval = val ; goto cleanup ; }
#endif /*VCACHE_MACROS_H*/