diff options
| author | Theodore Tso <tytso@mit.edu> | 1996-11-19 01:53:48 +0000 |
|---|---|---|
| committer | Theodore Tso <tytso@mit.edu> | 1996-11-19 01:53:48 +0000 |
| commit | cd0acd07fca64e3a3e56a11830b15896f756ad8a (patch) | |
| tree | 1748ca58fadacc400512e3916af33d4ed74d6d08 /src/appl/mailquery | |
| parent | 9b271e700b7fc4e94264b9f5d710686f5981c547 (diff) | |
Removing old POP applications
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@9427 dc483132-0cff-0310-8789-dd5450dbe970
Diffstat (limited to 'src/appl/mailquery')
| -rw-r--r-- | src/appl/mailquery/.Sanitize | 40 | ||||
| -rw-r--r-- | src/appl/mailquery/ChangeLog | 114 | ||||
| -rw-r--r-- | src/appl/mailquery/Makefile.in | 23 | ||||
| -rw-r--r-- | src/appl/mailquery/configure.in | 8 | ||||
| -rw-r--r-- | src/appl/mailquery/mailquery.M | 41 | ||||
| -rw-r--r-- | src/appl/mailquery/mailquery.c | 181 | ||||
| -rw-r--r-- | src/appl/mailquery/pop.h | 35 | ||||
| -rw-r--r-- | src/appl/mailquery/poplib.c | 498 |
8 files changed, 0 insertions, 940 deletions
diff --git a/src/appl/mailquery/.Sanitize b/src/appl/mailquery/.Sanitize deleted file mode 100644 index d58a60ee5..000000000 --- a/src/appl/mailquery/.Sanitize +++ /dev/null @@ -1,40 +0,0 @@ -# Sanitize.in for Kerberos V5 - -# Each directory to survive it's way into a release will need a file -# like this one called "./.Sanitize". All keyword lines must exist, -# and must exist in the order specified by this file. Each directory -# in the tree will be processed, top down, in the following order. - -# Hash started lines like this one are comments and will be deleted -# before anything else is done. Blank lines will also be squashed -# out. - -# The lines between the "Do-first:" line and the "Things-to-keep:" -# line are executed as a /bin/sh shell script before anything else is -# done in this - -Do-first: - -# All files listed between the "Things-to-keep:" line and the -# "Files-to-sed:" line will be kept. All other files will be removed. -# Directories listed in this section will have their own Sanitize -# called. Directories not listed will be removed in their entirety -# with rm -rf. - -Things-to-keep: - -.cvsignore -ChangeLog -Makefile.in -configure -configure.in -mailquery.M -mailquery.c -pop.h -poplib.c - -Things-to-lose: - -Do-last: - -# End of file. diff --git a/src/appl/mailquery/ChangeLog b/src/appl/mailquery/ChangeLog deleted file mode 100644 index 7d6322905..000000000 --- a/src/appl/mailquery/ChangeLog +++ /dev/null @@ -1,114 +0,0 @@ -Fri Nov 8 17:01:28 1996 Theodore Ts'o <tytso@rsts-11.mit.edu> - - * poplib.c: - * mailquery.c: Cleaned up gcc -Wall warnings. - -Thu Nov 7 15:20:25 1996 Theodore Ts'o <tytso@rsts-11.mit.edu> - - * poplib.c (reserved;): Check the error return from - krb5_init_context(), and print an error message if - necessary. - -Tue Sep 10 14:08:06 1996 Tom Yu <tlyu@mit.edu> - - * mailquery.M: remove ".so man1/header.doc" - -Fri Jul 7 15:43:24 EDT 1995 Paul Park (pjpark@mit.edu) - * Makefile.in - Remove all explicit library handling. - * configure.in - Add KRB5_LIBRARIES. - -Tue Jun 20 14:29:23 1995 Tom Yu (tlyu@dragons-lair) - - * poplib.c: HAS_STDLIB_H -> HAVE_STDLIB_H - -Thu Jun 15 17:36:11 EDT 1995 Paul Park (pjpark@mit.edu) - * Makefile.in - Change explicit library names to -l<lib> form, and - change target link line to use $(LD) and associated flags. - * configure.in - Add shared library usage check. - -Sat Jun 10 22:57:11 1995 Tom Yu (tlyu@dragons-lair) - - * poplib.c: krb5_auth_context redefinitions - -Fri Jun 9 18:27:03 1995 <tytso@rsx-11.mit.edu> - - * configure.in: Remove standardized set of autoconf macros, which - are now handled by CONFIG_RULES. - -Tue May 9 10:29:44 1995 Ezra Peisach <epeisach@kangaroo.mit.edu> - - * configure.in: Check for stdlib.h - - * poplib.c: Include <string.h>. Include <stdlib.h> if present or - define malloc(). - -Mon Mar 27 07:56:26 1995 Chris Provenzano (proven@mit.edu) - - * poplib.c (pop_init()): Use new calling convention for krb5_sendauth(). - -Thu Mar 2 12:28:20 1995 Theodore Y. Ts'o <tytso@dcl> - - * Makefile.in (ISODELIB): Remove reference to $(ISODELIB). - -Wed Mar 1 11:55:43 1995 Theodore Y. Ts'o <tytso@dcl> - - * configure.in: Replace check for -lsocket and -lnsl with - WITH_NETLIB check. - -Tue Feb 28 01:52:34 1995 John Gilmore (gnu at toad.com) - - * poplib.c: Avoid <krb5/...> includes. - -Tue Feb 14 15:30:55 1995 Chris Provenzano (proven@mit.edu) - - * poplib.c (pop_init): Call krb5_sendauth() with new calling convention - -Fri Jan 13 15:23:47 1995 Chris Provenzano (proven@mit.edu) - - * Added krb5_context to all krb5_routines - -Mon Jan 2 14:41:14 1995 Richard Basch (probe@tardis) - - * mailquery.c - Issue QUIT pop command, when done retrieving messages. - -Wed Nov 2 21:08:04 1994 Theodore Y. Ts'o (tytso@dcl) - - * poplib.c (getline, multiline): NULL should not be used as a - character assignment value. Use '\0' instead. - -Mon Oct 3 19:17:31 1994 Theodore Y. Ts'o (tytso@dcl) - - * Makefile.in: Use $(srcdir) to find manual page for make install. - -Thu Sep 29 22:53:17 1994 Theodore Y. Ts'o (tytso@dcl) - - * Makefile.in: Relink executables if libraries change - -Thu Sep 15 11:34:46 1994 Theodore Y. Ts'o (tytso@dcl) - - * configure.in: Moved CONFIG_RULES before AC_HAVE_LIBRARY() rules, - so that they work. - -Thu Aug 18 16:15:36 1994 Theodore Y. Ts'o (tytso@dcl) - - * Makefile.in: Added missing $(LIBS) to link line. - -Thu Aug 18 13:43:07 1994 Theodore Y. Ts'o (tytso at tsx-11) - - * mailquery.c: Move usage() before main() to solve redeclaration - error. - - * mailquery.c: Add #include <string.h> to fix compiler kvetching. - -Tue Aug 9 16:45:53 1994 Tom Yu (tlyu@dragons-lair) - - * poplib.c: fix stupid sterror bug - - * Makefile.in: - * configure.in: make install fixes - - * poplib.c: Ultrix cpp doesn't like '#error' - - * Makefile.in: oops forgot about $(COMERRLIB) - diff --git a/src/appl/mailquery/Makefile.in b/src/appl/mailquery/Makefile.in deleted file mode 100644 index eb740403e..000000000 --- a/src/appl/mailquery/Makefile.in +++ /dev/null @@ -1,23 +0,0 @@ -CFLAGS = $(CCOPTS) -DKPOP -DKRB5 $(DEFS) $(LOCALINCLUDE) - -all:: - -HESIODLIB = -LOCAL_LIBRARIES = $(HESIODLIB) -DEPLOCAL_LIBRARIES = $(HESIODLIB) - -mailquery: mailquery.o poplib.o $(DEPLIBS) - $(LD) $(LDFLAGS) $(LDARGS) -o mailquery mailquery.o poplib.o $(LIBS) - -mailquery.o: $(srcdir)/mailquery.c -poplib.o: $(srcdir)/poplib.c - -all:: mailquery - -clean:: - $(RM) mailquery.o poplib.o mailquery - -install:: - $(INSTALL_PROGRAM) mailquery ${DESTDIR}$(CLIENT_BINDIR)/mailquery - $(INSTALL_DATA) $(srcdir)/mailquery.M ${DESTDIR}$(CLIENT_MANDIR)/mailquery.1 - diff --git a/src/appl/mailquery/configure.in b/src/appl/mailquery/configure.in deleted file mode 100644 index c93e62d34..000000000 --- a/src/appl/mailquery/configure.in +++ /dev/null @@ -1,8 +0,0 @@ -AC_INIT(mailquery.c) -CONFIG_RULES -AC_PROG_INSTALL -AC_HAVE_HEADERS(unistd.h stdlib.h) -AC_FUNC_CHECK(strerror,AC_DEFINE(HAS_STRERROR)) -KRB5_LIBRARIES -V5_USE_SHARED_LIB -V5_AC_OUTPUT_MAKEFILE diff --git a/src/appl/mailquery/mailquery.M b/src/appl/mailquery/mailquery.M deleted file mode 100644 index 113146f40..000000000 --- a/src/appl/mailquery/mailquery.M +++ /dev/null @@ -1,41 +0,0 @@ -.\" -.\" (c) Copyright 1994 HEWLETT-PACKARD COMPANY -.\" -.\" To anyone who acknowledges that this file is provided -.\" "AS IS" without any express or implied warranty: -.\" permission to use, copy, modify, and distribute this -.\" file for any purpose is hereby granted without fee, -.\" provided that the above copyright notice and this -.\" notice appears in all copies, and that the name of -.\" Hewlett-Packard Company not be used in advertising or -.\" publicity pertaining to distribution of the software -.\" without specific, written prior permission. Hewlett- -.\" Packard Company makes no representations about the -.\" suitability of this software for any purpose. -.\" -.\" $Id -.\" -.TH mailquery 1 -.SH NAME -mailquery \- queries a pop server about how much mail is available -.SH SYNTAX -.B mailquery -[-\fId\fR\|] -[-\fIv\fR\|] -[\fI user\fR[@\fIhost\fR\|]] -.SH DESCRIPTION -The -.PN mailquery -command queries a POP server for information about how much mail a user -has. The program will exit with status = 0 if there is mail, and with -status = 1 if there is no mail. The -v flag can be used to get a more -verbose report. The -d flag can be used to turn on debugging output -in the pop library code. The pop server can be specified either by -setting the environment variable MAILHOST, or on the command line. -If no user is specified, user is set to the person who ran the program. -.SH OPTIONS - -.SH BUGS/LIMITATIONS - -.SH SEE ALSO -popper(8) diff --git a/src/appl/mailquery/mailquery.c b/src/appl/mailquery/mailquery.c deleted file mode 100644 index a2946f484..000000000 --- a/src/appl/mailquery/mailquery.c +++ /dev/null @@ -1,181 +0,0 @@ -/* - * (c) Copyright 1994 HEWLETT-PACKARD COMPANY - * - * To anyone who acknowledges that this file is provided - * "AS IS" without any express or implied warranty: - * permission to use, copy, modify, and distribute this - * file for any purpose is hereby granted without fee, - * provided that the above copyright notice and this - * notice appears in all copies, and that the name of - * Hewlett-Packard Company not be used in advertising or - * publicity pertaining to distribution of the software - * without specific, written prior permission. Hewlett- - * Packard Company makes no representations about the - * suitability of this software for any purpose. - */ -/* - * Mailquery - contact the POP mail host an see if a user has - * mail. By default the result if reflected in the - * exit status. - * - * Usage: mailquery [-dv] [-e <cmd>] - * -d - debug - * -v - print result - * -e - exec this command if there is mail. - */ -#include <stdio.h> -#ifdef HAVE_UNISTD_H -#include <unistd.h> -#endif -#ifdef HAVE_STDLIB_H -#include <stdlib.h> -#endif -#include <string.h> -#include <pwd.h> -#include <fcntl.h> -#include <sys/file.h> -#ifdef HESIOD -#include <hesiod.h> -#endif -#include "pop.h" - -extern int pop_debug; -int verbose = 0; -char *exec_cmd; - -int mailquery(); - -void usage() -{ - fprintf(stderr, "usage: mailquery [-d] [-v] [-e cmd] [user[@host]]\n"); -} - -int main(argc, argv) - int argc; - char *argv[]; -{ - extern char *getenv(); - int nbytes; - char *mhost = NULL, *mhp; - char *user = 0; - struct passwd * pwd; - char c; - extern int optind; - extern char *optarg; -#ifdef HESIOD - struct hes_postoffice *p; -#endif /* HESIOD */ - - while ((c = getopt(argc, argv, "dve:")) != EOF) { - switch (c) { - case 'd': - pop_debug = 1; - break; - - case 'e': - exec_cmd = optarg; - break; - - case 'v': - verbose = 1; - break; - - case '?': - usage(); - exit(1); - } - } - - argc -= optind; - argv += optind; - - if (argc > 0) { - user = argv[0]; - if ((mhost = strchr(argv[0], '@')) != NULL) { - *mhost = '\0'; - mhost++; - } -#ifndef HESIOD - else { - mhost = DEFMAILHOST; - } -#endif - } - - if (user == (char *) 0 || *user == '\0') { - if ((pwd = getpwuid(getuid())) == NULL) { - perror("getpwuid"); - exit(1); - } - user = pwd->pw_name; - } - - if ((mhost == NULL) && - (mhp = getenv("MAILHOST"))) - mhost = mhp; - -#ifdef HESIOD - if (mhost == NULL) { - p = hes_getmailhost(user); - if (p != NULL && strcmp(p->po_type, "POP") == 0) - mhost = p->po_host; - else { - fprintf(stderr,"no POP server listed in Hesiod for %s\n", user); - exit(1); - } - } -#endif /* HESIOD */ - - if (mhost == NULL) { - mhost = DEFMAILHOST; - } - - nbytes = mailquery(mhost, user); - - if ((nbytes > 0) && (exec_cmd != 0)) { - if (pop_debug) - fprintf(stderr, "about to execute %s\n", exec_cmd); - system(exec_cmd); - } - - exit(nbytes == 0); - -} - -int mailquery(mhost, user) - char *mhost; - char *user; -{ - int nbytes, nmsgs; - - if (pop_init(mhost, 0) == NOTOK) { - error(Errmsg); - exit(1); - } - -#ifdef KPOP - if (pop_command("USER %s", user) == NOTOK || - pop_command("PASS %s", user) == NOTOK) { -#else /* !KPOP */ - if (pop_command("USER %s", user) == NOTOK || - pop_command("RPOP %s", user) == NOTOK) { -#endif /* KPOP */ - error(Errmsg); - (void) pop_command("QUIT"); - exit (1); - } - - if (pop_stat(&nmsgs, &nbytes) == NOTOK) { - error(Errmsg); - (void) pop_command("QUIT"); - exit (1); - } - - (void) pop_command("QUIT"); - - if (verbose) - printf("%d messages (%d bytes) on host %s\n", nmsgs, nbytes, mhost); - - return nbytes; -} - diff --git a/src/appl/mailquery/pop.h b/src/appl/mailquery/pop.h deleted file mode 100644 index d2f9071a3..000000000 --- a/src/appl/mailquery/pop.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * (c) Copyright 1994 HEWLETT-PACKARD COMPANY - * - * To anyone who acknowledges that this file is provided - * "AS IS" without any express or implied warranty: - * permission to use, copy, modify, and distribute this - * file for any purpose is hereby granted without fee, - * provided that the above copyright notice and this - * notice appears in all copies, and that the name of - * Hewlett-Packard Company not be used in advertising or - * publicity pertaining to distribution of the software - * without specific, written prior permission. Hewlett- - * Packard Company makes no representations about the - * suitability of this software for any purpose. - * - */ - -/* defines for pop library */ - -#define NOTOK (-1) -#define OK 0 -#define DONE 1 - -#define DEFMAILHOST "mailhost" - -int pop_init(), pop_getline(); -char *get_errmsg(); -int pop_command(); -int pop_stat(); -int pop_retr(); -int pop_query(); -char *concat(); -void fatal(), error(), pfatal_with_name(); - -extern char Errmsg[]; diff --git a/src/appl/mailquery/poplib.c b/src/appl/mailquery/poplib.c deleted file mode 100644 index fe54ba54d..000000000 --- a/src/appl/mailquery/poplib.c +++ /dev/null @@ -1,498 +0,0 @@ -/* - * (c) Copyright 1994 HEWLETT-PACKARD COMPANY - * - * To anyone who acknowledges that this file is provided - * "AS IS" without any express or implied warranty: - * permission to use, copy, modify, and distribute this - * file for any purpose is hereby granted without fee, - * provided that the above copyright notice and this - * notice appears in all copies, and that the name of - * Hewlett-Packard Company not be used in advertising or - * publicity pertaining to distribution of the software - * without specific, written prior permission. Hewlett- - * Packard Company makes no representations about the - * suitability of this software for any purpose. - */ - -/* - * Poplib - library routines for speaking POP - */ -#include <stdio.h> -#include <unistd.h> -#include <string.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <sys/file.h> -#include <errno.h> - -#include <sys/socket.h> -#include <netinet/in.h> -#include <netdb.h> -#if defined(KRB4) && defined(KRB5) -error You cannot define both KRB4 and KRB5 -#endif -#ifndef KPOP_SERVICE -#define KPOP_SERVICE "kpop" -#endif -#ifdef KPOP -#ifdef KRB4 -#include <krb.h> -#endif -#ifdef KRB5 -#include "krb5.h" -#include "com_err.h" -#include <ctype.h> -#endif -#endif - -#ifdef HAVE_STDLIB_H -#include <stdlib.h> -#else -extern char *malloc(); -#endif - -#include "pop.h" - -void *xmalloc(); -int getline(), multiline(), putline(); - -char Errmsg[80]; /* to return error messages */ -int pop_debug; - -static FILE *sfi = 0; -static FILE *sfo = 0; - -int pop_init(host, reserved) -char *host; -int reserved; -{ - register struct hostent *hp; - register struct servent *sp; -#ifndef KPOP - int lport = IPPORT_RESERVED - 1; -#endif - struct sockaddr_in sin; - int s; - char *get_errmsg(); - char response[1024]; - char *routine; -#ifdef KPOP -#ifdef KRB4 - CREDENTIALS cred; - KTEXT ticket = (KTEXT)NULL; - int rem; -#endif -#ifdef KRB5 - krb5_error_code retval; - krb5_context context; - krb5_ccache ccdef; - krb5_principal client = NULL, server = NULL; - krb5_error *err_ret = NULL; - krb5_auth_context auth_context; -#endif -#endif - - if (sfi && sfo) { - return OK; /* guessing at this -- eichin -- XXX */ - } - - hp = gethostbyname(host); - if (hp == NULL) { - sprintf(Errmsg, "MAILHOST unknown: %s", host); - return(NOTOK); - } - -#ifdef KPOP - sp = getservbyname(KPOP_SERVICE, "tcp"); - if (sp == 0) { - (void) strcpy(Errmsg, "tcp/kpop: unknown service"); - return(NOTOK); - } -#else /* !KPOP */ - sp = getservbyname("pop", "tcp"); - if (sp == 0) { - (void) strcpy(Errmsg, "tcp/pop: unknown service"); - return(NOTOK); - } -#endif /* KPOP */ - if (sp == 0) { - strcpy(Errmsg, "tcp/pop: unknown service"); - return(NOTOK); - } - - sin.sin_family = hp->h_addrtype; - memcpy((char *)&sin.sin_addr, hp->h_addr, hp->h_length); - sin.sin_port = sp->s_port; -#ifdef KPOP - s = socket(AF_INET, SOCK_STREAM, 0); -#else /* !KPOP */ - if (reserved) - s = rresvport(&lport); - else - s = socket(AF_INET, SOCK_STREAM, 0); -#endif /* KPOP */ - - if (s < 0) { - sprintf(Errmsg, "error creating socket: %s", get_errmsg()); - return(NOTOK); - } - - if (connect(s, (struct sockaddr *)&sin, sizeof sin) < 0) { - sprintf(Errmsg, "error during connect: %s", get_errmsg()); - close(s); - return(NOTOK); - } - -#ifdef KPOP -#ifdef KRB4 - /* Get tgt creds from ticket file. This is used to calculate the - * lifetime for the pop ticket so that it expires with the - * tgt */ - rem = krb_get_cred("krbtgt", krb_realmofhost(hp->h_name), krb_realmofhost(hp->h_name), &cred); - if (rem == KSUCCESS) { - long lifetime; - lifetime = ((cred.issue_date + ((unsigned char)cred.lifetime * 5 * 60)) - time(0)) / (5 * 60); - if (lifetime > 0) - krb_set_lifetime(lifetime); - } - ticket = (KTEXT)malloc( sizeof(KTEXT_ST) ); - rem = krb_sendauth(0L, s, ticket, "pop", hp->h_name, (char *)0, - 0, (MSG_DAT *) 0, (CREDENTIALS *) 0, - (bit_64 *) 0, (struct sockaddr_in *)0, - (struct sockaddr_in *)0,"ZMAIL0.0"); - if (rem != KSUCCESS) { - (void) sprintf(Errmsg, "kerberos error: %s",krb_err_txt[rem]); - (void) close(s); - return(NOTOK); - } -#endif /* KRB4 */ -#ifdef KRB5 - retval = krb5_init_context(&context); - if (retval) { - com_err("pop_init", retval, "while initializing krb5"); - close(s); - return(NOTOK); - } - routine = "krb5_cc_default"; - if ((retval = krb5_cc_default(context, &ccdef))) { - krb5error: - sprintf(Errmsg, "%s: krb5 error: %s", routine, error_message(retval)); - close(s); - return(NOTOK); - } - routine = "krb5_cc_get_principal"; - if ((retval = krb5_cc_get_principal(context, ccdef, &client))) { - goto krb5error; - } - - routine = "krb5_sname_to_principal"; - if ((retval = krb5_sname_to_principal(context, hp->h_name, "pop", - KRB5_NT_UNKNOWN, &server))) { - goto krb5error; - } - - retval = krb5_sendauth(context, &auth_context, (krb5_pointer) &s, - "KPOPV1.0", client, server, - AP_OPTS_MUTUAL_REQUIRED, - NULL, /* no data to checksum */ - 0, /* no creds, use ccache instead */ - ccdef, - &err_ret, 0, - NULL); /* don't need reply */ - krb5_free_principal(context, server); - if (retval) { - if (err_ret && err_ret->text.length) { - sprintf(Errmsg, "krb5 error: %s [server says '%*s'] ", - error_message(retval), - err_ret->text.length, - err_ret->text.data); - krb5_free_error(context, err_ret); - } else - sprintf(Errmsg, "krb5_sendauth: krb5 error: %s", error_message(retval)); - close(s); - return(NOTOK); - } -#endif /* KRB5 */ -#endif /* KPOP */ - - sfi = fdopen(s, "r"); - sfo = fdopen(s, "w"); - if (sfi == NULL || sfo == NULL) { - sprintf(Errmsg, "error in fdopen: %s", get_errmsg()); - close(s); - return(NOTOK); - } - - if (getline(response, sizeof response, sfi) != OK) { - error(response); - return(NOTOK); - } - if (pop_debug) - fprintf(stderr, "<--- %s\n", response); - - return(OK); -} - -int pop_command(fmt, a, b, c, d) -char *fmt; -char *a, *b, *c, *d; -{ - char buf[1024]; - - sprintf(buf, fmt, a, b, c, d); - - if (pop_debug) fprintf(stderr, "---> %s\n", buf); - if (putline(buf, Errmsg, sfo) == NOTOK) return(NOTOK); - - if (getline(buf, sizeof buf, sfi) != OK) { - strcpy(Errmsg, buf); - return(NOTOK); - } - - if (pop_debug) fprintf(stderr, "<--- %s\n", buf); - if (*buf != '+') { - strcpy(Errmsg, buf); - return(NOTOK); - } else { - return(OK); - } -} - -int pop_query(nbytes, user) - int *nbytes; - char *user; -{ - char buf[1024]; - - if (strlen(user) > 120) { - if (pop_debug) fprintf(stderr, "username %s too long\n", user); - return NOTOK; - } - - sprintf(buf, "QUERY %s", user); - if (pop_debug) fprintf(stderr, "---> %s\n", buf); - if (putline(buf, Errmsg, sfo) == NOTOK) return (NOTOK); - - if (getline(buf, sizeof buf, sfi) != OK) { - strcpy(Errmsg, buf); - return NOTOK; - } - - if (pop_debug) fprintf(stderr, "<--- %s\n", buf); - if (*buf != '+') { - strcpy(Errmsg, buf); - return NOTOK; - } else { - sscanf(buf, "+OK %d", nbytes); - return OK; - } -} - -int pop_stat(nmsgs, nbytes) -int *nmsgs, *nbytes; -{ - char buf[1024]; - - if (pop_debug) fprintf(stderr, "---> STAT\n"); - if (putline("STAT", Errmsg, sfo) == NOTOK) return(NOTOK); - - if (getline(buf, sizeof buf, sfi) != OK) { - strcpy(Errmsg, buf); - return(NOTOK); - } - - if (pop_debug) fprintf(stderr, "<--- %s\n", buf); - if (*buf != '+') { - strcpy(Errmsg, buf); - return(NOTOK); - } else { - sscanf(buf, "+OK %d %d", nmsgs, nbytes); - return(OK); - } -} - -int pop_retr(msgno, action, arg) -int msgno; -int (*action)(); -char *arg; /* is this always FILE*??? -- XXX */ -{ - char buf[1024]; - int nbytes = 0; - - sprintf(buf, "RETR %d", msgno); - - if (pop_debug) - fprintf(stderr, "---> %s\n", buf); - - if (putline(buf, Errmsg, sfo) == NOTOK) return(NOTOK); - - if (getline(buf, sizeof buf, sfi) != OK) { - strcpy(Errmsg, buf); - return(NOTOK); - } - if (pop_debug) - fprintf(stderr, "<--- %s\n", buf); - - sscanf(buf, "+OK %d", &nbytes); - - while (1) { - switch (multiline(buf, sizeof buf, sfi)) { - case OK: - if ((*action)(buf, arg, nbytes) < 0) { - strcat(Errmsg, get_errmsg()); - return (DONE); /* Some error occured in action */ - } - break; - case DONE: - return (OK); - case NOTOK: - strcpy(Errmsg, buf); - return (NOTOK); - } - } -} - -int pop_getline(buf, n) - char *buf; - int n; -{ - return getline(buf, n, sfi); -} - -int getline(buf, n, f) -char *buf; -register int n; -FILE *f; -{ - register char *p; - int c; - - p = buf; - while (--n > 0 && (c = fgetc(f)) != EOF) - if ((*p++ = c) == '\n') break; - - if (ferror(f)) { - strcpy(buf, "error on connection"); - return (NOTOK); - } - - if (c == EOF && p == buf) { - strcpy(buf, "connection closed by foreign host"); - return (DONE); - } - - *p = '\0'; - if (*--p == '\n') *p = '\0'; - if (*--p == '\r') *p = '\0'; - return(OK); -} - -int multiline(buf, n, f) -char *buf; -register int n; -FILE *f; -{ - if (getline(buf, n, f) != OK) return (NOTOK); - if (*buf == '.') { - if (*(buf+1) == '\0') { - return (DONE); - } else { - strcpy(buf, buf+1); - } - } - return(OK); -} - -#ifndef HAS_STRERROR -char * -strerror(e) - int e; -{ - extern int errno, sys_nerr; - extern char *sys_errlist[]; - - if (errno < sys_nerr) - return sys_errlist[errno]; - else - return "unknown error"; -} -#endif - -char * -get_errmsg() -{ - char *s = strerror(errno); - - return(s); -} - -int putline(buf, err, f) -char *buf; -char *err; -FILE *f; -{ - fprintf(f, "%s\r\n", buf); - fflush(f); - if (ferror(f)) { - strcpy(err, "lost connection"); - return(NOTOK); - } - return(OK); -} - - -/* Print error message and exit. */ - -void fatal (s1, s2) - char *s1, *s2; -{ - error (s1, s2); - exit (1); -} - -/* Print error message. `s1' is printf control string, `s2' is arg for it. */ - -void error (s1, s2, s3) - char *s1, *s2, *s3; -{ - printf ("poplib: "); - printf (s1, s2, s3); - printf ("\n"); -} - -void pfatal_with_name (name) - char *name; -{ - char *s = concat ("", strerror(errno), " for %s"); - - fatal (s, name); -} - -/* Return a newly-allocated string whose contents concatenate those of s1, s2, s3. */ - -char * -concat (s1, s2, s3) - char *s1, *s2, *s3; -{ - int len1 = strlen (s1), len2 = strlen (s2), len3 = strlen (s3); - char *result = (char *) xmalloc (len1 + len2 + len3 + 1); - - strcpy (result, s1); - strcpy (result + len1, s2); - strcpy (result + len1 + len2, s3); - *(result + len1 + len2 + len3) = 0; - - return result; -} - -/* Like malloc but get fatal error if memory is exhausted. */ - -void * -xmalloc (size) - int size; -{ - void *result = (void *)malloc (size); - if (!result) - fatal ("virtual memory exhausted", 0); - return result; -} |
