10 date 94.04.19.20.12.14; author jromine; state Exp;
15 date 93.08.26.18.25.52; author jromine; state Exp;
20 date 93.08.25.17.26.40; author jromine; state Exp;
25 date 92.11.24.18.32.32; author jromine; state Exp;
30 date 92.11.02.22.53.37; author jromine; state Exp;
35 date 92.10.26.16.48.22; author jromine; state Exp;
40 date 92.10.20.22.43.35; author jromine; state Exp;
45 date 92.10.20.15.56.14; author jromine; state Exp;
50 date 92.03.03.17.09.57; author jromine; state Exp;
55 date 92.02.11.17.40.13; author jromine; state Exp;
60 date 92.02.04.22.21.02; author jromine; state Exp;
65 date 92.02.04.21.45.44; author jromine; state Exp;
70 date 92.02.04.21.33.20; author jromine; state Exp;
75 date 92.01.31.22.04.36; author jromine; state Exp;
80 date 90.04.09.09.45.16; author sources; state Exp;
85 date 90.04.05.15.35.04; author sources; state Exp;
90 date 90.04.05.14.54.46; author sources; state Exp;
95 date 90.02.06.13.12.55; author sources; state Exp;
100 date 90.02.06.13.12.32; author sources; state Exp;
111 @add MODE IDENTIFY auth command
114 @/* popsbr.c - POP client subroutines */
116 static char ident[] = "@@(#)$Id: popsbr.c,v 2.6 1993/08/26 18:25:52 jromine Exp jromine $";
119 #if defined(NNTP) && !defined(PSHSBR)
125 #include "../h/strings.h"
126 #ifdef NNTP /* building pshsbr.o from popsbr.c */
127 #include "../h/nntp.h"
133 #define POPSERVICE "pop"
141 #define TRMLEN (sizeof TRM - 1)
146 extern char *sys_errlist[];
149 static int poprint = 0;
150 static int pophack = 0;
152 char response[BUFSIZ];
158 static int traverse (int (*)(), const char*, char *, char *, char *, char *);
159 #define targ_t char *
161 static int traverse();
165 #if !defined(NNTP) && defined(MPOP)
166 #define command pop_command
167 #define multiline pop_multiline
168 int command(), multiline();
170 static int command(), multiline();
173 static int getline();
177 #ifdef BPOP /* stupid */
178 static int xtnd_last = -1,
180 static char xtnd_name[512]; /* INCREDIBLE HACK!! */
190 static char *pop_auth (user, pass)
196 register unsigned char *dp;
200 static char buffer[BUFSIZ];
202 if ((cp = index (response, '<')) == NULL
203 || (lp = index (cp, '>')) == NULL) {
204 (void) sprintf (buffer, "APOP not available: %s", response);
205 (void) strcpy (response, buffer);
210 (void) sprintf (buffer, "%s%s", cp, pass);
212 MD5Init (&mdContext);
213 MD5Update (&mdContext, (unsigned char *) buffer,
214 (unsigned int) strlen (buffer));
215 MD5Final (digest, &mdContext);
217 (void) sprintf (cp = buffer, "%s ", user);
219 for (ep = (dp = digest) + sizeof digest / sizeof digest[0];
222 (void) sprintf (cp, "%02x", *dp++ & 0xff);
232 #if defined(RPOP) || defined(APOP)
233 int pop_init (host, user, pass, snoop, rpop)
236 int pop_init (host, user, pass, snoop)
246 #ifndef RPOP /* !APOP && !RPOP */
255 if ((apop = rpop) < 0)
261 if ((fd1 = client (host, "tcp", POPSERVICE, rpop, response)) == NOTOK)
263 (void) sprintf (buffer, "%s/%s", POPSERVICE, "kpop");
264 if ((fd1 = client (host, "tcp", buffer, rpop, response)) == NOTOK)
267 if ((fd1 = client (host, "tcp", "nntp", rpop, response)) == NOTOK)
271 if ((fd2 = dup (fd1)) == NOTOK) {
272 (void) sprintf (response, "unable to dup connection descriptor: %s",
273 errno > 0 && errno < sys_nerr ? sys_errlist[errno]
279 if (pop_set (fd1, fd2, snoop) == NOTOK)
281 if (pop_set (fd1, fd2, snoop, (char *)0) == NOTOK)
285 (void) signal (SIGPIPE, SIG_IGN);
287 switch (getline (response, sizeof response, input)) {
290 fprintf (stderr, "<--- %s\n", response);
292 if (*response == '+') {
296 char *cp = pop_auth (user, pass);
298 if (cp && command ("APOP %s", cp) != NOTOK)
303 if (command ("USER %s", user) != NOTOK
304 && command ("%s %s", rpop ? "RPOP" : (pophack++, "PASS"),
308 if (command ("USER %s", user) != NOTOK
309 && command ("PASS %s", pass) != NOTOK)
314 if (*response < CHAR_ERR) {
315 (void) command ("MODE READER");
317 if (getenv("NEWSAUTH")) /* special for IDENT protocol */
318 command("MODE IDENTIFY");
323 (void) strcpy (buffer, response);
324 (void) command ("QUIT");
325 (void) strcpy (response, buffer);
331 fprintf (stderr, "%s\n", response);
332 (void) fclose (input);
333 (void) fclose (output);
341 int pop_set (in, out, snoop)
343 int pop_set (in, out, snoop, myname)
351 if (myname && *myname)
352 strcpy (xtnd_name, myname); /* interface from bbc to msh */
355 if ((input = fdopen (in, "r")) == NULL
356 || (output = fdopen (out, "w")) == NULL) {
357 (void) strcpy (response, "fdopen failed on connection descriptor");
359 (void) fclose (input);
376 (void) sprintf (in, "%d", fileno (input));
377 (void) sprintf (out, "%d", fileno (output));
383 int pop_stat (nmsgs, nbytes)
389 extern char **brkstring();
393 if (command ("STAT") == NOTOK)
396 *nmsgs = *nbytes = 0;
397 (void) sscanf (response, "+OK %d %d", nmsgs, nbytes);
400 if (xtnd_last < 0) { /* in msh, xtnd_name is set from myname */
401 if (command("GROUP %s", xtnd_name) == NOTOK)
404 ap = brkstring (response, " ", "\n"); /* "211 nart first last ggg" */
405 xtnd_first = atoi (ap[2]);
406 xtnd_last = atoi (ap[3]);
409 /* nmsgs is not the real nart, but an incredible simuation */
411 *nmsgs = xtnd_last - xtnd_first + 1; /* because of holes... */
414 *nbytes = xtnd_first; /* for subtracting offset in msh() */
421 int pop_exists (action)
424 #ifdef XMSGS /* hacked into NNTP 1.5 */
425 if (traverse (action, "XMSGS %d-%d",
426 (targ_t)xtnd_first, (targ_t)xtnd_last, 0, 0) == OK)
429 if (traverse (action, "LISTGROUP", /* provided by INN 1.4 */
432 return traverse (action, "XHDR NONAME %d-%d",
433 (targ_t)xtnd_first, (targ_t)xtnd_last, 0, 0);
438 int pop_list (msgno, nmsgs, msgs, bytes)
440 int pop_list (msgno, nmsgs, msgs, bytes, ids)
455 if (command ("LIST %d", msgno) == NOTOK)
460 (void) sscanf (response, "+OK %d %d %d", msgs, bytes, ids);
463 (void) sscanf (response, "+OK %d %d", msgs, bytes);
466 if (command ("STAT %d", msgno) == NOTOK)
476 if (command ("LIST") == NOTOK)
479 for (i = 0; i < *nmsgs; i++)
480 switch (multiline ()) {
490 (void) sscanf (response, "%d %d %d",
491 msgs++, bytes++, ids++);
494 (void) sscanf (response, "%d %d", msgs++, bytes++);
498 switch (multiline ()) {
513 int pop_retr (msgno, action)
518 return traverse (action, "RETR %d", (targ_t)msgno, 0, 0, 0);
520 return traverse (action, "ARTICLE %d", (targ_t)msgno, 0, 0, 0);
527 static int traverse (action, fmt, a, b, c, d)
539 char buffer[sizeof response];
541 if (command (fmt, a, b, c, d) == NOTOK)
543 (void) strcpy (buffer, response);
546 switch (multiline ()) {
551 (void) strcpy (response, buffer);
555 (*action) (response);
565 return command ("DELE %d", msgno);
570 return command ("NOOP");
577 return command ("LAST");
583 return command ("RSET");
588 int pop_top (msgno, lines, action)
594 return traverse (action, "TOP %d %d", (targ_t)msgno, (targ_t)lines, 0, 0);
596 return traverse (action, "HEAD %d", (targ_t)msgno, 0, 0, 0);
602 int pop_xtnd (action, fmt, a, b, c, d)
612 extern char **brkstring();
617 (void) sprintf (buffer, "XTND %s", fmt);
618 return traverse (action, buffer, a, b, c, d);
620 sprintf (buffer, fmt, a, b, c, d);
621 ap = brkstring (buffer, " ", "\n"); /* a hack, i know... */
623 if (uleq(ap[0], "x-bboards")) { /* XTND "X-BBOARDS group */
624 /* most of these parameters are meaningless under NNTP.
625 * bbc.c was modified to set AKA and LEADERS as appropriate,
626 * the rest are left blank.
630 if (uleq (ap[0], "archive") && ap[1]) {
631 sprintf (xtnd_name, "%s", ap[1]); /* save the name */
633 xtnd_first = 1; /* setup to fail in pop_stat */
636 if (uleq (ap[0], "bboards")) {
638 if (ap[1]) { /* XTND "BBOARDS group" */
639 sprintf (xtnd_name, "%s", ap[1]); /* save the name */
640 if (command("GROUP %s", xtnd_name) == NOTOK)
643 strcpy (buffer, response); /* action must ignore extra args */
644 ap = brkstring (response, " ", "\n");/* "211 nart first last g" */
645 xtnd_first = atoi (ap[2]);
646 xtnd_last = atoi (ap[3]);
651 } else { /* XTND "BBOARDS" */
652 return traverse (action, "LIST", a, b, c, d);
655 return NOTOK; /* unknown XTND command */
665 i = command ("QUIT");
673 (void) fclose (input);
674 (void) fclose (output);
683 #if defined(MPOP) && !defined(NNTP)
684 int command (fmt, a, b, c, d)
686 static int command (fmt, a, b, c, d)
697 (void) sprintf (buffer, fmt, a, b, c, d);
700 if (cp = index (buffer, ' '))
702 fprintf (stderr, "---> %s ********\n", buffer);
708 fprintf (stderr, "---> %s\n", buffer);
710 if (putline (buffer, output) == NOTOK)
713 switch (getline (response, sizeof response, input)) {
716 fprintf (stderr, "<--- %s\n", response);
718 return (*response == '+' ? OK : NOTOK);
720 return (*response < CHAR_ERR ? OK : NOTOK);
726 fprintf (stderr, "%s\n", response);
732 #if defined(MPOP) && !defined(NNTP)
735 static int multiline () {
737 char buffer[BUFSIZ + TRMLEN];
739 if (getline (buffer, sizeof buffer, input) != OK)
743 fprintf (stderr, "<--- %s\n", response);
745 if (strncmp (buffer, TRM, TRMLEN) == 0) {
746 if (buffer[TRMLEN] == 0)
749 (void) strcpy (response, buffer + TRMLEN);
752 (void) strcpy (response, buffer);
759 static int getline (s, n, iop)
768 while (--n > 0 && (c = fgetc (iop)) != EOF)
769 if ((*p++ = c) == '\n')
771 if (ferror (iop) && c != EOF) {
772 (void) strcpy (response, "error on connection");
775 if (c == EOF && p == s) {
776 (void) strcpy (response, "connection closed by foreign host");
789 static putline (s, iop)
793 (void) fprintf (iop, "%s\r\n", s);
796 (void) strcpy (response, "lost connection");
807 @update NNTP commands for INN. Use "MODE READER" and "LISTGROUP".
812 static char ident[] = "@@(#)$Id: popsbr.c,v 2.5 1993/08/25 17:26:40 jromine Exp jromine $";
822 @off_t fixes for BSD44
827 static char ident[] = "@@(#)$Id: popsbr.c,v 2.4 1992/11/24 18:32:32 jromine Exp jromine $";
830 if (*response < CHAR_ERR)
844 static char ident[] = "@@(#)$Id: popsbr.c,v 2.3 1992/11/02 22:53:37 jromine Exp jromine $";
857 static char ident[] = "@@(#)$Id: popsbr.c,v 2.2 1992/10/26 16:48:22 jromine Exp jromine $";
862 if (traverse (action, "XMSGS %d-%d", xtnd_first, xtnd_last) == OK)
865 return traverse (action, "XHDR NONAME %d-%d", xtnd_first, xtnd_last);
868 return traverse (action, "RETR %d", (char *)msgno, 0, 0, 0);
871 return traverse (action, "ARTICLE %d", (char *)msgno, 0, 0, 0);
874 return traverse (action, "TOP %d %d", (char *)msgno, (char *)lines, 0, 0);
877 return traverse (action, "HEAD %d", (char *)msgno, 0, 0, 0);
883 @MD5 API changes (from MTR)
888 static char ident[] = "@@(#)$Id: popsbr.c,v 2.1 1992/10/20 22:43:35 jromine Exp jromine $";
891 #if !defined(NNTP) && defined(APOP)
900 #if defined(APOP) && !defined(NNTP)
903 #if defined(APOP) && !defined(NNTP)
914 static char ident[] = "@@(#)$Id: popsbr.c,v 2.0 1992/10/20 15:56:14 jromine Exp jromine $";
920 MD5Final (&mdContext);
923 for (ep = (dp = mdContext.digest)
924 + sizeof mdContext.digest / sizeof mdContext.digest[0];
930 @merge NNTP/APOP/KPOP changes
935 static char ident[] = "@@(#)$Id: pshsbr.c,v 2.2 1990/04/05 14:56:13 sources Exp $";
949 int command (fmt, a, b, c, d)
969 static char ident[] = "@@(#)$Id: popsbr.c,v 1.10 1992/02/11 17:40:13 jromine Exp jromine $";
973 #define command pop_command
974 #define multiline pop_multiline
992 #ifdef notdef /* KPOP */
998 if ((kpop = rpop) != 2) /* 2 => KPOP */
1003 #ifdef KPOP /* contact a KERBEROS kpop server */
1004 /* should test kpop flag */
1008 if ((fd1 = client (host, "tcp", POPSERVICE, rpop, response)) == NOTOK)
1018 if (command ("USER %s", user) != NOTOK
1020 && command ("%s %s",
1021 rpop ? "RPOP" : (pophack++, "PASS"),
1023 && command ("PASS %s",
1068 @accomodate KPOP cleanup in client.c
1073 static char ident[] = "@@(#)$Id: popsbr.c,v 1.9 1992/02/04 22:21:02 jromine Exp $";
1088 static char ident[] = "@@(#)$Id: popsbr.c,v 1.8 1992/02/04 21:45:44 jromine Exp jromine $";
1094 if ((fd1 = kclient (host, "tcp", POPSERVICE, rpop, response)) == NOTOK)
1105 static char ident[] = "@@(#)$Id: popsbr.c,v 1.7 1992/02/04 21:33:20 jromine Exp jromine $";
1108 static int command(), multiline(), getline();
1119 static char ident[] = "@@(#)$Id: popsbr.c,v 1.6 1992/01/31 22:04:36 jromine Exp jromine $";
1126 (void) time (&clock);
1127 (void) sprintf (cp = buffer, "%s %ld ", user, clock);
1129 (void) strcpy (cp, pass);
1133 MD5Update (&mdContext, buffer, strlen (buffer));
1137 if (command ("APOP %s", pop_auth (user, pass)) != NOTOK)
1148 static char ident[] = "@@(#)$Id: popsbr.c,v 1.5 90/04/09 09:45:16 sources Exp Locker: sources $";
1155 int pop_init (host, user, pass, snoop)
1169 if (*response == '+'
1170 && command ("USER %s", user) != NOTOK
1173 && command ("%s %s", rpop ? "RPOP" : (pophack++, "PASS"),
1176 && command ("PASS %s",
1180 if (*response != '+') {
1181 (void) strcpy (buffer, response);
1182 (void) command ("QUIT");
1183 (void) strcpy (response, buffer);
1188 static int command (fmt, a, b, c, d)
1191 static int multiline () {
1202 static char ident[] = "@@(#)$Id: popsbr.c,v 1.4 90/04/05 15:35:04 sources Exp Locker: sources $";
1205 static int traverse(), command(), multiline(), getline();
1210 && command ("USER %s", user) != NOTOK
1211 && command ("%s %s", rpop ? "RPOP" : (pophack++, "PASS"),
1217 return traverse (action, "RETR %d", msgno);
1224 return traverse (action, "TOP %d %d", msgno, lines);
1230 if (buffer[TRMLEN] == NULL)
1250 static char ident[] = "@@(#)$Id:$";
1254 if ((fd1 = client (host, "tcp", "pop", rpop, response)) == NOTOK)
1265 static char ident[] = "@@(#)$Id:";