annotate lib-src/pop.c @ 22085:e8163732f7b4

(ange-ftp-tmp-name-template): Use system-tmp-directory.
author Richard M. Stallman <rms@gnu.org>
date Sat, 16 May 1998 03:38:59 +0000
parents aa5d46f74b6a
children bfaacbee089a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1 /* pop.c: client routines for talking to a POP3-protocol post-office server
19018
f1f7c254aa77 Support auto-configuration of both Kerberos V4 and
Richard M. Stallman <rms@gnu.org>
parents: 17683
diff changeset
2 Copyright (c) 1991, 1993, 1996, 1997 Free Software Foundation, Inc.
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3 Written by Jonathan Kamens, jik@security.ov.com.
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5 This file is part of GNU Emacs.
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
6
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
7 GNU Emacs is free software; you can redistribute it and/or modify
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8 it under the terms of the GNU General Public License as published by
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9 the Free Software Foundation; either version 2, or (at your option)
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10 any later version.
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12 GNU Emacs is distributed in the hope that it will be useful,
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15 GNU General Public License for more details.
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 along with GNU Emacs; see the file COPYING. If not, write to
14186
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 14036
diff changeset
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 14036
diff changeset
20 Boston, MA 02111-1307, USA. */
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21
9613
530b4511e5b3 Only include ../src/config.h if HAVE_CONFIG_H is
Richard M. Stallman <rms@gnu.org>
parents: 9600
diff changeset
22 #ifdef HAVE_CONFIG_H
530b4511e5b3 Only include ../src/config.h if HAVE_CONFIG_H is
Richard M. Stallman <rms@gnu.org>
parents: 9600
diff changeset
23 #define NO_SHORTNAMES /* Tell config not to load remap.h */
9592
132798b0352b Include ../src/config.h.
Richard M. Stallman <rms@gnu.org>
parents: 9591
diff changeset
24 #include <../src/config.h>
9613
530b4511e5b3 Only include ../src/config.h if HAVE_CONFIG_H is
Richard M. Stallman <rms@gnu.org>
parents: 9600
diff changeset
25 #else
530b4511e5b3 Only include ../src/config.h if HAVE_CONFIG_H is
Richard M. Stallman <rms@gnu.org>
parents: 9600
diff changeset
26 #define MAIL_USE_POP
530b4511e5b3 Only include ../src/config.h if HAVE_CONFIG_H is
Richard M. Stallman <rms@gnu.org>
parents: 9600
diff changeset
27 #endif
9592
132798b0352b Include ../src/config.h.
Richard M. Stallman <rms@gnu.org>
parents: 9591
diff changeset
28
9613
530b4511e5b3 Only include ../src/config.h if HAVE_CONFIG_H is
Richard M. Stallman <rms@gnu.org>
parents: 9600
diff changeset
29 #ifdef MAIL_USE_POP
530b4511e5b3 Only include ../src/config.h if HAVE_CONFIG_H is
Richard M. Stallman <rms@gnu.org>
parents: 9600
diff changeset
30
530b4511e5b3 Only include ../src/config.h if HAVE_CONFIG_H is
Richard M. Stallman <rms@gnu.org>
parents: 9600
diff changeset
31 #ifdef HAVE_CONFIG_H
530b4511e5b3 Only include ../src/config.h if HAVE_CONFIG_H is
Richard M. Stallman <rms@gnu.org>
parents: 9600
diff changeset
32 /* Cancel these substitutions made in config.h */
530b4511e5b3 Only include ../src/config.h if HAVE_CONFIG_H is
Richard M. Stallman <rms@gnu.org>
parents: 9600
diff changeset
33 #undef open
9594
7461e7aa4f3c (open, close, read, write): Add #undefs.
Richard M. Stallman <rms@gnu.org>
parents: 9592
diff changeset
34 #undef read
7461e7aa4f3c (open, close, read, write): Add #undefs.
Richard M. Stallman <rms@gnu.org>
parents: 9592
diff changeset
35 #undef write
9613
530b4511e5b3 Only include ../src/config.h if HAVE_CONFIG_H is
Richard M. Stallman <rms@gnu.org>
parents: 9600
diff changeset
36 #undef close
530b4511e5b3 Only include ../src/config.h if HAVE_CONFIG_H is
Richard M. Stallman <rms@gnu.org>
parents: 9600
diff changeset
37 #endif
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
39 #include <sys/types.h>
15102
ed550d0805ca [WINDOWSNT]: Include winsock.h and ntlib.h.
Richard M. Stallman <rms@gnu.org>
parents: 14238
diff changeset
40 #ifdef WINDOWSNT
ed550d0805ca [WINDOWSNT]: Include winsock.h and ntlib.h.
Richard M. Stallman <rms@gnu.org>
parents: 14238
diff changeset
41 #include "ntlib.h"
ed550d0805ca [WINDOWSNT]: Include winsock.h and ntlib.h.
Richard M. Stallman <rms@gnu.org>
parents: 14238
diff changeset
42 #include <winsock.h>
ed550d0805ca [WINDOWSNT]: Include winsock.h and ntlib.h.
Richard M. Stallman <rms@gnu.org>
parents: 14238
diff changeset
43 #undef SOCKET_ERROR
15108
442458addd50 (SEND, RECV): Renamed from send, recv.
Richard M. Stallman <rms@gnu.org>
parents: 15102
diff changeset
44 #define RECV(s,buf,len,flags) recv(s,buf,len,flags)
442458addd50 (SEND, RECV): Renamed from send, recv.
Richard M. Stallman <rms@gnu.org>
parents: 15102
diff changeset
45 #define SEND(s,buf,len,flags) send(s,buf,len,flags)
442458addd50 (SEND, RECV): Renamed from send, recv.
Richard M. Stallman <rms@gnu.org>
parents: 15102
diff changeset
46 #define CLOSESOCKET(s) closesocket(s)
15102
ed550d0805ca [WINDOWSNT]: Include winsock.h and ntlib.h.
Richard M. Stallman <rms@gnu.org>
parents: 14238
diff changeset
47 #else
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
48 #include <netinet/in.h>
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49 #include <sys/socket.h>
15108
442458addd50 (SEND, RECV): Renamed from send, recv.
Richard M. Stallman <rms@gnu.org>
parents: 15102
diff changeset
50 #define RECV(s,buf,len,flags) read(s,buf,len)
442458addd50 (SEND, RECV): Renamed from send, recv.
Richard M. Stallman <rms@gnu.org>
parents: 15102
diff changeset
51 #define SEND(s,buf,len,flags) write(s,buf,len)
442458addd50 (SEND, RECV): Renamed from send, recv.
Richard M. Stallman <rms@gnu.org>
parents: 15102
diff changeset
52 #define CLOSESOCKET(s) close(s)
15102
ed550d0805ca [WINDOWSNT]: Include winsock.h and ntlib.h.
Richard M. Stallman <rms@gnu.org>
parents: 14238
diff changeset
53 #endif
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54 #include <pop.h>
9600
f0d3266e07d7 Fix mismatch in conditionals.
Richard M. Stallman <rms@gnu.org>
parents: 9594
diff changeset
55
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56 #ifdef sun
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
57 #include <malloc.h>
9613
530b4511e5b3 Only include ../src/config.h if HAVE_CONFIG_H is
Richard M. Stallman <rms@gnu.org>
parents: 9600
diff changeset
58 #endif /* sun */
9600
f0d3266e07d7 Fix mismatch in conditionals.
Richard M. Stallman <rms@gnu.org>
parents: 9594
diff changeset
59
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60 #ifdef HESIOD
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61 #include <hesiod.h>
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62 /*
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63 * It really shouldn't be necessary to put this declaration here, but
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64 * the version of hesiod.h that Athena has installed in release 7.2
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
65 * doesn't declare this function; I don't know if the 7.3 version of
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
66 * hesiod.h does.
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67 */
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68 extern struct servent *hes_getservbyname (/* char *, char * */);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69 #endif
9600
f0d3266e07d7 Fix mismatch in conditionals.
Richard M. Stallman <rms@gnu.org>
parents: 9594
diff changeset
70
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71 #include <pwd.h>
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72 #include <netdb.h>
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73 #include <errno.h>
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74 #include <stdio.h>
19018
f1f7c254aa77 Support auto-configuration of both Kerberos V4 and
Richard M. Stallman <rms@gnu.org>
parents: 17683
diff changeset
75 #ifdef STDC_HEADERS
f1f7c254aa77 Support auto-configuration of both Kerberos V4 and
Richard M. Stallman <rms@gnu.org>
parents: 17683
diff changeset
76 #include <string.h>
19978
83050d7e3f64 Use system header files instead of declaring C-library
Karl Heuer <kwzh@gnu.org>
parents: 19018
diff changeset
77 #define index strchr
83050d7e3f64 Use system header files instead of declaring C-library
Karl Heuer <kwzh@gnu.org>
parents: 19018
diff changeset
78 #endif
83050d7e3f64 Use system header files instead of declaring C-library
Karl Heuer <kwzh@gnu.org>
parents: 19018
diff changeset
79 #ifdef STDC_HEADERS
83050d7e3f64 Use system header files instead of declaring C-library
Karl Heuer <kwzh@gnu.org>
parents: 19018
diff changeset
80 #include <stdlib.h>
83050d7e3f64 Use system header files instead of declaring C-library
Karl Heuer <kwzh@gnu.org>
parents: 19018
diff changeset
81 #endif
83050d7e3f64 Use system header files instead of declaring C-library
Karl Heuer <kwzh@gnu.org>
parents: 19018
diff changeset
82 #ifdef HAVE_UNISTD_H
83050d7e3f64 Use system header files instead of declaring C-library
Karl Heuer <kwzh@gnu.org>
parents: 19018
diff changeset
83 #include <unistd.h>
19018
f1f7c254aa77 Support auto-configuration of both Kerberos V4 and
Richard M. Stallman <rms@gnu.org>
parents: 17683
diff changeset
84 #endif
9600
f0d3266e07d7 Fix mismatch in conditionals.
Richard M. Stallman <rms@gnu.org>
parents: 9594
diff changeset
85
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
86 #ifdef KERBEROS
19018
f1f7c254aa77 Support auto-configuration of both Kerberos V4 and
Richard M. Stallman <rms@gnu.org>
parents: 17683
diff changeset
87 # ifdef HAVE_KRB5_H
f1f7c254aa77 Support auto-configuration of both Kerberos V4 and
Richard M. Stallman <rms@gnu.org>
parents: 17683
diff changeset
88 # include <krb5.h>
f1f7c254aa77 Support auto-configuration of both Kerberos V4 and
Richard M. Stallman <rms@gnu.org>
parents: 17683
diff changeset
89 # endif
f1f7c254aa77 Support auto-configuration of both Kerberos V4 and
Richard M. Stallman <rms@gnu.org>
parents: 17683
diff changeset
90 # ifdef HAVE_DES_H
f1f7c254aa77 Support auto-configuration of both Kerberos V4 and
Richard M. Stallman <rms@gnu.org>
parents: 17683
diff changeset
91 # include <des.h>
f1f7c254aa77 Support auto-configuration of both Kerberos V4 and
Richard M. Stallman <rms@gnu.org>
parents: 17683
diff changeset
92 # else
f1f7c254aa77 Support auto-configuration of both Kerberos V4 and
Richard M. Stallman <rms@gnu.org>
parents: 17683
diff changeset
93 # ifdef HAVE_KERBEROSIV_DES_H
f1f7c254aa77 Support auto-configuration of both Kerberos V4 and
Richard M. Stallman <rms@gnu.org>
parents: 17683
diff changeset
94 # include <kerberosIV/des.h>
f1f7c254aa77 Support auto-configuration of both Kerberos V4 and
Richard M. Stallman <rms@gnu.org>
parents: 17683
diff changeset
95 # else
f1f7c254aa77 Support auto-configuration of both Kerberos V4 and
Richard M. Stallman <rms@gnu.org>
parents: 17683
diff changeset
96 # ifdef HAVE_KERBEROS_DES_H
f1f7c254aa77 Support auto-configuration of both Kerberos V4 and
Richard M. Stallman <rms@gnu.org>
parents: 17683
diff changeset
97 # include <kerberos/des.h>
f1f7c254aa77 Support auto-configuration of both Kerberos V4 and
Richard M. Stallman <rms@gnu.org>
parents: 17683
diff changeset
98 # endif
f1f7c254aa77 Support auto-configuration of both Kerberos V4 and
Richard M. Stallman <rms@gnu.org>
parents: 17683
diff changeset
99 # endif
f1f7c254aa77 Support auto-configuration of both Kerberos V4 and
Richard M. Stallman <rms@gnu.org>
parents: 17683
diff changeset
100 # endif
f1f7c254aa77 Support auto-configuration of both Kerberos V4 and
Richard M. Stallman <rms@gnu.org>
parents: 17683
diff changeset
101 # ifdef HAVE_KRB_H
f1f7c254aa77 Support auto-configuration of both Kerberos V4 and
Richard M. Stallman <rms@gnu.org>
parents: 17683
diff changeset
102 # include <krb.h>
f1f7c254aa77 Support auto-configuration of both Kerberos V4 and
Richard M. Stallman <rms@gnu.org>
parents: 17683
diff changeset
103 # else
f1f7c254aa77 Support auto-configuration of both Kerberos V4 and
Richard M. Stallman <rms@gnu.org>
parents: 17683
diff changeset
104 # ifdef HAVE_KERBEROSIV_KRB_H
f1f7c254aa77 Support auto-configuration of both Kerberos V4 and
Richard M. Stallman <rms@gnu.org>
parents: 17683
diff changeset
105 # include <kerberosIV/krb.h>
f1f7c254aa77 Support auto-configuration of both Kerberos V4 and
Richard M. Stallman <rms@gnu.org>
parents: 17683
diff changeset
106 # else
f1f7c254aa77 Support auto-configuration of both Kerberos V4 and
Richard M. Stallman <rms@gnu.org>
parents: 17683
diff changeset
107 # ifdef HAVE_KERBEROS_KRB_H
f1f7c254aa77 Support auto-configuration of both Kerberos V4 and
Richard M. Stallman <rms@gnu.org>
parents: 17683
diff changeset
108 # include <kerberos/krb.h>
f1f7c254aa77 Support auto-configuration of both Kerberos V4 and
Richard M. Stallman <rms@gnu.org>
parents: 17683
diff changeset
109 # endif
f1f7c254aa77 Support auto-configuration of both Kerberos V4 and
Richard M. Stallman <rms@gnu.org>
parents: 17683
diff changeset
110 # endif
f1f7c254aa77 Support auto-configuration of both Kerberos V4 and
Richard M. Stallman <rms@gnu.org>
parents: 17683
diff changeset
111 # endif
f1f7c254aa77 Support auto-configuration of both Kerberos V4 and
Richard M. Stallman <rms@gnu.org>
parents: 17683
diff changeset
112 # ifdef HAVE_COM_ERR_H
f1f7c254aa77 Support auto-configuration of both Kerberos V4 and
Richard M. Stallman <rms@gnu.org>
parents: 17683
diff changeset
113 # include <com_err.h>
f1f7c254aa77 Support auto-configuration of both Kerberos V4 and
Richard M. Stallman <rms@gnu.org>
parents: 17683
diff changeset
114 # endif
9613
530b4511e5b3 Only include ../src/config.h if HAVE_CONFIG_H is
Richard M. Stallman <rms@gnu.org>
parents: 9600
diff changeset
115 #endif /* KERBEROS */
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
116
9613
530b4511e5b3 Only include ../src/config.h if HAVE_CONFIG_H is
Richard M. Stallman <rms@gnu.org>
parents: 9600
diff changeset
117 #ifdef KERBEROS
19018
f1f7c254aa77 Support auto-configuration of both Kerberos V4 and
Richard M. Stallman <rms@gnu.org>
parents: 17683
diff changeset
118 #ifndef KERBEROS5
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
119 extern int krb_sendauth (/* long, int, KTEXT, char *, char *, char *,
9613
530b4511e5b3 Only include ../src/config.h if HAVE_CONFIG_H is
Richard M. Stallman <rms@gnu.org>
parents: 9600
diff changeset
120 u_long, MSG_DAT *, CREDENTIALS *, Key_schedule,
530b4511e5b3 Only include ../src/config.h if HAVE_CONFIG_H is
Richard M. Stallman <rms@gnu.org>
parents: 9600
diff changeset
121 struct sockaddr_in *, struct sockaddr_in *,
530b4511e5b3 Only include ../src/config.h if HAVE_CONFIG_H is
Richard M. Stallman <rms@gnu.org>
parents: 9600
diff changeset
122 char * */);
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
123 extern char *krb_realmofhost (/* char * */);
19018
f1f7c254aa77 Support auto-configuration of both Kerberos V4 and
Richard M. Stallman <rms@gnu.org>
parents: 17683
diff changeset
124 #endif /* ! KERBEROS5 */
9613
530b4511e5b3 Only include ../src/config.h if HAVE_CONFIG_H is
Richard M. Stallman <rms@gnu.org>
parents: 9600
diff changeset
125 #endif /* KERBEROS */
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
126
15102
ed550d0805ca [WINDOWSNT]: Include winsock.h and ntlib.h.
Richard M. Stallman <rms@gnu.org>
parents: 14238
diff changeset
127 #ifndef WINDOWSNT
9613
530b4511e5b3 Only include ../src/config.h if HAVE_CONFIG_H is
Richard M. Stallman <rms@gnu.org>
parents: 9600
diff changeset
128 #if !defined(HAVE_H_ERRNO) || !defined(HAVE_CONFIG_H)
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
129 extern int h_errno;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
130 #endif
15102
ed550d0805ca [WINDOWSNT]: Include winsock.h and ntlib.h.
Richard M. Stallman <rms@gnu.org>
parents: 14238
diff changeset
131 #endif
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
132
20418
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
133 #ifndef _P
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
134 # ifdef __STDC__
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
135 # define _P(a) a
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
136 # else
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
137 # define _P(a) ()
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
138 # endif /* __STDC__ */
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
139 #endif /* ! __P */
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
140
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
141 static int socket_connection _P((char *, int));
21295
f399e51d6d11 (pop_getline): Renamed from getline.
Richard M. Stallman <rms@gnu.org>
parents: 20418
diff changeset
142 static int pop_getline _P((popserver, char **));
20418
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
143 static int sendline _P((popserver, char *));
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
144 static int fullwrite _P((int, char *, int));
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
145 static int getok _P((popserver));
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
146 #if 0
20418
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
147 static int gettermination _P((popserver));
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
148 #endif
20418
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
149 static void pop_trash _P((popserver));
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
150 static char *find_crlf _P((char *, int));
9591
0774e217e8aa Don't declare malloc, realloc, free.
Richard M. Stallman <rms@gnu.org>
parents: 9158
diff changeset
151
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
152 #define ERROR_MAX 80 /* a pretty arbitrary size */
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
153 #define POP_PORT 110
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
154 #define KPOP_PORT 1109
15102
ed550d0805ca [WINDOWSNT]: Include winsock.h and ntlib.h.
Richard M. Stallman <rms@gnu.org>
parents: 14238
diff changeset
155 #ifdef WINDOWSNT
ed550d0805ca [WINDOWSNT]: Include winsock.h and ntlib.h.
Richard M. Stallman <rms@gnu.org>
parents: 14238
diff changeset
156 #define POP_SERVICE "pop3" /* we don't want the POP2 port! */
ed550d0805ca [WINDOWSNT]: Include winsock.h and ntlib.h.
Richard M. Stallman <rms@gnu.org>
parents: 14238
diff changeset
157 #else
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
158 #define POP_SERVICE "pop"
15102
ed550d0805ca [WINDOWSNT]: Include winsock.h and ntlib.h.
Richard M. Stallman <rms@gnu.org>
parents: 14238
diff changeset
159 #endif
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
160 #ifdef KERBEROS
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
161 #define KPOP_SERVICE "kpop"
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
162 #endif
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
163
21397
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
164 #ifdef GSSAPI
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
165 # ifdef HAVE_GSSAPI_H
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
166 # include <gssapi.h>
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
167 # else
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
168 # include <gssapi/gssapi.h>
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
169 # endif
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
170 #define GSSAPI_SERVICE "pop"
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
171 static int pop_auth (/* popserver server, char *user,
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
172 char *host, int flags */);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
173 static void gen_gss_error (/* char *msg, OM_uint32 major, OM_uint32 minor */);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
174 struct _pop_gssapi
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
175 {
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
176 int gss_flags; /* encryption? integrity protection? */
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
177 OM_uint32 max_size; /* max size we can send the server */
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
178 gss_ctx_id_t gss_context; /* the security context */
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
179 };
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
180 #define GSSAPI_NOPROT 0x01
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
181 #define GSSAPI_INTEGRITY 0x02
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
182 #define GSSAPI_PRIVACY 0x04
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
183 #define GSSAPI_NEEDWRAP (GSSAPI_INTEGRITY|GSSAPI_PRIVACY)
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
184 #define GSSAPI_PROTECTION (GSSAPI_NOPROT|GSSAPI_INTEGRITY|GSSAPI_PRIVACY)
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
185 #define GSSAPI_RCVBUF 1024
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
186 #define GSSAPI_SVC_TYPE {10, "\052\206\110\206\367\022\001\002\001\004"}
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
187 #define Gssapi(data) ((struct _pop_gssapi *) (data))
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
188
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
189 static int b64_decode (/* char *enc, gss_buffer_t dec */);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
190 static int b64_encode (/* gss_buffer_t dec, char **enc */);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
191 #define B64_SUCCESS 0
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
192 #define B64_BADPARAM 1
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
193 #define B64_BADCHAR 2
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
194 #define B64_BADPAD 3
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
195 #define B64_BADLEN 4
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
196 #define B64_NOMEM 5
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
197 static char *b64_error[] =
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
198 {
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
199 "Success",
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
200 "Bad parameters",
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
201 "Bad characters in encoding",
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
202 "Bad padding in encoding",
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
203 "Bad length",
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
204 "Out of memory"
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
205 };
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
206
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
207 /*
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
208 * This function is only needed if you are using the GSSAPI protection
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
209 * mechanisms; it keeps trying until it has read the requested number
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
210 * bytes from the passed-in fd.
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
211 */
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
212 static int fullread (/* int fd, char *buf, int nbytes */);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
213 #endif /* GSSAPI */
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
214
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
215 char pop_error[ERROR_MAX];
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
216 int pop_debug = 0;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
217
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
218 #ifndef min
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
219 #define min(a,b) (((a) < (b)) ? (a) : (b))
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
220 #endif
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
221
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
222 /*
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
223 * Function: pop_open (char *host, char *username, char *password,
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
224 * int flags)
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
225 *
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
226 * Purpose: Establishes a connection with a post-office server, and
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
227 * completes the authorization portion of the session.
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
228 *
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
229 * Arguments:
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
230 * host The server host with which the connection should be
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
231 * established. Optional. If omitted, internal
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
232 * heuristics will be used to determine the server host,
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
233 * if possible.
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
234 * username
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
235 * The username of the mail-drop to access. Optional.
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
236 * If omitted, internal heuristics will be used to
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
237 * determine the username, if possible.
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
238 * password
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
239 * The password to use for authorization. If omitted,
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
240 * internal heuristics will be used to determine the
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
241 * password, if possible.
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
242 * flags A bit mask containing flags controlling certain
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
243 * functions of the routine. Valid flags are defined in
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
244 * the file pop.h
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
245 *
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
246 * Return value: Upon successful establishment of a connection, a
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
247 * non-null popserver will be returned. Otherwise, null will be
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
248 * returned, and the string variable pop_error will contain an
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
249 * explanation of the error.
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
250 */
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
251 popserver
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
252 pop_open (host, username, password, flags)
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
253 char *host;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
254 char *username;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
255 char *password;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
256 int flags;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
257 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
258 int sock;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
259 popserver server;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
260
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
261 /* Determine the user name */
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
262 if (! username)
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
263 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
264 username = getenv ("USER");
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
265 if (! (username && *username))
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
266 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
267 username = getlogin ();
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
268 if (! (username && *username))
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
269 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
270 struct passwd *passwd;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
271 passwd = getpwuid (getuid ());
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
272 if (passwd && passwd->pw_name && *passwd->pw_name)
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
273 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
274 username = passwd->pw_name;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
275 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
276 else
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
277 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
278 strcpy (pop_error, "Could not determine username");
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
279 return (0);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
280 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
281 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
282 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
283 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
284
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
285 /*
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
286 * Determine the mail host.
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
287 */
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
288
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
289 if (! host)
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
290 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
291 host = getenv ("MAILHOST");
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
292 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
293
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
294 #ifdef HESIOD
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
295 if ((! host) && (! (flags & POP_NO_HESIOD)))
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
296 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
297 struct hes_postoffice *office;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
298 office = hes_getmailhost (username);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
299 if (office && office->po_type && (! strcmp (office->po_type, "POP"))
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
300 && office->po_name && *office->po_name && office->po_host
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
301 && *office->po_host)
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
302 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
303 host = office->po_host;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
304 username = office->po_name;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
305 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
306 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
307 #endif
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
308
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
309 #ifdef MAILHOST
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
310 if (! host)
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
311 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
312 host = MAILHOST;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
313 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
314 #endif
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
315
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
316 if (! host)
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
317 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
318 strcpy (pop_error, "Could not determine POP server");
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
319 return (0);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
320 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
321
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
322 /* Determine the password */
21397
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
323 #if defined(KERBEROS) || defined(GSSAPI)
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
324 # ifdef KERBEROS
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
325 # define NO_KERBEROS POP_NO_KERBEROS
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
326 # else
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
327 # define NO_KERBEROS 0
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
328 # endif /* KERBEROS */
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
329
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
330 # ifdef GSSAPI
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
331 # define NO_GSSAPI POP_NO_GSSAPI
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
332 # else
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
333 # define NO_GSSAPI 0
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
334 # endif /* GSSAPI */
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
335
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
336 # define DONT_NEED_PASSWORD (! (flags & (NO_KERBEROS | NO_GSSAPI)))
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
337 #else
21397
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
338 # define DONT_NEED_PASSWORD 0
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
339 #endif
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
340
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
341 if ((! password) && (! DONT_NEED_PASSWORD))
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
342 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
343 if (! (flags & POP_NO_GETPASS))
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
344 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
345 password = getpass ("Enter POP password:");
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
346 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
347 if (! password)
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
348 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
349 strcpy (pop_error, "Could not determine POP password");
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
350 return (0);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
351 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
352 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
353 if (password)
21397
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
354 flags |= POP_NO_KERBEROS | (!(flags & POP_NO_NOPROT) ? POP_NO_GSSAPI : 0);
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
355 else
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
356 password = username;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
357
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
358 sock = socket_connection (host, flags);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
359 if (sock == -1)
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
360 return (0);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
361
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
362 server = (popserver) malloc (sizeof (struct _popserver));
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
363 if (! server)
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
364 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
365 strcpy (pop_error, "Out of memory in pop_open");
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
366 return (0);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
367 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
368 server->buffer = (char *) malloc (GETLINE_MIN);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
369 if (! server->buffer)
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
370 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
371 strcpy (pop_error, "Out of memory in pop_open");
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
372 free ((char *) server);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
373 return (0);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
374 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
375
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
376 server->file = sock;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
377 server->data = 0;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
378 server->buffer_index = 0;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
379 server->buffer_size = GETLINE_MIN;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
380 server->in_multi = 0;
15102
ed550d0805ca [WINDOWSNT]: Include winsock.h and ntlib.h.
Richard M. Stallman <rms@gnu.org>
parents: 14238
diff changeset
381 server->trash_started = 0;
21397
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
382 server->extra = 0;
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
383
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
384 if (getok (server))
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
385 return (0);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
386
21397
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
387 #ifdef GSSAPI
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
388 /*
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
389 * unless forbidden to use GSSAPI, try the GSSAPI AUTH mechanism..first.
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
390 */
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
391 pop_error[0] = '\0'; /* so we can detect errors later... */
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
392 if (! (flags & POP_NO_GSSAPI))
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
393 {
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
394 int ret;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
395
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
396 ret = pop_auth (server, username, host, flags);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
397 if (ret == 0)
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
398 {
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
399 return (server);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
400 }
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
401 else if (ret == -2)
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
402 {
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
403 pop_close (server);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
404 return (0);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
405 }
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
406 }
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
407 #endif /* GSSAPI */
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
408 /*
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
409 * POP_NO_NOPROT is used in the case that we want protection; if
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
410 * the authentication negotiation failed, then we want to fail now.
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
411 */
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
412 if ((flags & POP_NO_NOPROT))
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
413 {
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
414 pop_close (server);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
415 #ifdef GSSAPI
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
416 if (pop_error[0] == '\0')
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
417 #endif
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
418 strcpy (pop_error, "Unable to provide protection");
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
419 return (0);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
420 }
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
421
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
422 /*
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
423 * I really shouldn't use the pop_error variable like this, but....
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
424 */
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
425 if (strlen (username) > ERROR_MAX - 6)
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
426 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
427 pop_close (server);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
428 strcpy (pop_error,
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
429 "Username too long; recompile pop.c with larger ERROR_MAX");
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
430 return (0);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
431 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
432 sprintf (pop_error, "USER %s", username);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
433
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
434 if (sendline (server, pop_error) || getok (server))
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
435 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
436 return (0);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
437 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
438
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
439 if (strlen (password) > ERROR_MAX - 6)
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
440 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
441 pop_close (server);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
442 strcpy (pop_error,
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
443 "Password too long; recompile pop.c with larger ERROR_MAX");
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
444 return (0);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
445 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
446 sprintf (pop_error, "PASS %s", password);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
447
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
448 if (sendline (server, pop_error) || getok (server))
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
449 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
450 return (0);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
451 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
452
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
453 return (server);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
454 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
455
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
456 /*
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
457 * Function: pop_stat
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
458 *
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
459 * Purpose: Issue the STAT command to the server and return (in the
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
460 * value parameters) the number of messages in the maildrop and
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
461 * the total size of the maildrop.
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
462 *
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
463 * Return value: 0 on success, or non-zero with an error in pop_error
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
464 * in failure.
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
465 *
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
466 * Side effects: On failure, may make further operations on the
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
467 * connection impossible.
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
468 */
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
469 int
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
470 pop_stat (server, count, size)
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
471 popserver server;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
472 int *count;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
473 int *size;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
474 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
475 char *fromserver;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
476
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
477 if (server->in_multi)
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
478 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
479 strcpy (pop_error, "In multi-line query in pop_stat");
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
480 return (-1);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
481 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
482
21295
f399e51d6d11 (pop_getline): Renamed from getline.
Richard M. Stallman <rms@gnu.org>
parents: 20418
diff changeset
483 if (sendline (server, "STAT") || (pop_getline (server, &fromserver) < 0))
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
484 return (-1);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
485
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
486 if (strncmp (fromserver, "+OK ", 4))
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
487 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
488 if (0 == strncmp (fromserver, "-ERR", 4))
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
489 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
490 strncpy (pop_error, fromserver, ERROR_MAX);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
491 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
492 else
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
493 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
494 strcpy (pop_error,
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
495 "Unexpected response from POP server in pop_stat");
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
496 pop_trash (server);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
497 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
498 return (-1);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
499 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
500
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
501 *count = atoi (&fromserver[4]);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
502
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
503 fromserver = index (&fromserver[4], ' ');
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
504 if (! fromserver)
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
505 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
506 strcpy (pop_error,
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
507 "Badly formatted response from server in pop_stat");
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
508 pop_trash (server);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
509 return (-1);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
510 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
511
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
512 *size = atoi (fromserver + 1);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
513
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
514 return (0);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
515 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
516
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
517 /*
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
518 * Function: pop_list
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
519 *
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
520 * Purpose: Performs the POP "list" command and returns (in value
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
521 * parameters) two malloc'd zero-terminated arrays -- one of
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
522 * message IDs, and a parallel one of sizes.
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
523 *
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
524 * Arguments:
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
525 * server The pop connection to talk to.
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
526 * message The number of the one message about which to get
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
527 * information, or 0 to get information about all
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
528 * messages.
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
529 *
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
530 * Return value: 0 on success, non-zero with error in pop_error on
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
531 * failure.
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
532 *
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
533 * Side effects: On failure, may make further operations on the
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
534 * connection impossible.
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
535 */
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
536 int
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
537 pop_list (server, message, IDs, sizes)
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
538 popserver server;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
539 int message;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
540 int **IDs;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
541 int **sizes;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
542 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
543 int how_many, i;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
544 char *fromserver;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
545
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
546 if (server->in_multi)
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
547 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
548 strcpy (pop_error, "In multi-line query in pop_list");
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
549 return (-1);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
550 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
551
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
552 if (message)
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
553 how_many = 1;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
554 else
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
555 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
556 int count, size;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
557 if (pop_stat (server, &count, &size))
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
558 return (-1);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
559 how_many = count;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
560 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
561
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
562 *IDs = (int *) malloc ((how_many + 1) * sizeof (int));
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
563 *sizes = (int *) malloc ((how_many + 1) * sizeof (int));
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
564 if (! (*IDs && *sizes))
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
565 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
566 strcpy (pop_error, "Out of memory in pop_list");
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
567 return (-1);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
568 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
569
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
570 if (message)
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
571 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
572 sprintf (pop_error, "LIST %d", message);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
573 if (sendline (server, pop_error))
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
574 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
575 free ((char *) *IDs);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
576 free ((char *) *sizes);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
577 return (-1);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
578 }
21295
f399e51d6d11 (pop_getline): Renamed from getline.
Richard M. Stallman <rms@gnu.org>
parents: 20418
diff changeset
579 if (pop_getline (server, &fromserver) < 0)
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
580 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
581 free ((char *) *IDs);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
582 free ((char *) *sizes);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
583 return (-1);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
584 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
585 if (strncmp (fromserver, "+OK ", 4))
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
586 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
587 if (! strncmp (fromserver, "-ERR", 4))
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
588 strncpy (pop_error, fromserver, ERROR_MAX);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
589 else
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
590 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
591 strcpy (pop_error,
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
592 "Unexpected response from server in pop_list");
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
593 pop_trash (server);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
594 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
595 free ((char *) *IDs);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
596 free ((char *) *sizes);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
597 return (-1);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
598 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
599 (*IDs)[0] = atoi (&fromserver[4]);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
600 fromserver = index (&fromserver[4], ' ');
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
601 if (! fromserver)
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
602 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
603 strcpy (pop_error,
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
604 "Badly formatted response from server in pop_list");
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
605 pop_trash (server);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
606 free ((char *) *IDs);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
607 free ((char *) *sizes);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
608 return (-1);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
609 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
610 (*sizes)[0] = atoi (fromserver);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
611 (*IDs)[1] = (*sizes)[1] = 0;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
612 return (0);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
613 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
614 else
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
615 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
616 if (pop_multi_first (server, "LIST", &fromserver))
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
617 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
618 free ((char *) *IDs);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
619 free ((char *) *sizes);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
620 return (-1);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
621 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
622 for (i = 0; i < how_many; i++)
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
623 {
20418
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
624 if (pop_multi_next (server, &fromserver) <= 0)
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
625 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
626 free ((char *) *IDs);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
627 free ((char *) *sizes);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
628 return (-1);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
629 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
630 (*IDs)[i] = atoi (fromserver);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
631 fromserver = index (fromserver, ' ');
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
632 if (! fromserver)
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
633 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
634 strcpy (pop_error,
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
635 "Badly formatted response from server in pop_list");
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
636 free ((char *) *IDs);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
637 free ((char *) *sizes);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
638 pop_trash (server);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
639 return (-1);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
640 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
641 (*sizes)[i] = atoi (fromserver);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
642 }
20418
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
643 if (pop_multi_next (server, &fromserver) < 0)
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
644 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
645 free ((char *) *IDs);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
646 free ((char *) *sizes);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
647 return (-1);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
648 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
649 else if (fromserver)
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
650 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
651 strcpy (pop_error,
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
652 "Too many response lines from server in pop_list");
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
653 free ((char *) *IDs);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
654 free ((char *) *sizes);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
655 return (-1);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
656 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
657 (*IDs)[i] = (*sizes)[i] = 0;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
658 return (0);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
659 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
660 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
661
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
662 /*
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
663 * Function: pop_retrieve
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
664 *
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
665 * Purpose: Retrieve a specified message from the maildrop.
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
666 *
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
667 * Arguments:
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
668 * server The server to retrieve from.
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
669 * message The message number to retrieve.
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
670 * markfrom
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
671 * If true, then mark the string "From " at the beginning
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
672 * of lines with '>'.
20418
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
673 * msg_buf Output parameter to which a buffer containing the
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
674 * message is assigned.
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
675 *
20418
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
676 * Return value: The number of bytes in msg_buf, which may contain
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
677 * embedded nulls, not including its final null, or -1 on error
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
678 * with pop_error set.
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
679 *
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
680 * Side effects: May kill connection on error.
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
681 */
20418
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
682 int
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
683 pop_retrieve (server, message, markfrom, msg_buf)
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
684 popserver server;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
685 int message;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
686 int markfrom;
20418
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
687 char **msg_buf;
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
688 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
689 int *IDs, *sizes, bufsize, fromcount = 0, cp = 0;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
690 char *ptr, *fromserver;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
691 int ret;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
692
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
693 if (server->in_multi)
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
694 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
695 strcpy (pop_error, "In multi-line query in pop_retrieve");
20418
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
696 return (-1);
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
697 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
698
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
699 if (pop_list (server, message, &IDs, &sizes))
20418
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
700 return (-1);
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
701
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
702 if (pop_retrieve_first (server, message, &fromserver))
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
703 {
20418
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
704 return (-1);
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
705 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
706
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
707 /*
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
708 * The "5" below is an arbitrary constant -- I assume that if
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
709 * there are "From" lines in the text to be marked, there
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
710 * probably won't be more than 5 of them. If there are, I
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
711 * allocate more space for them below.
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
712 */
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
713 bufsize = sizes[0] + (markfrom ? 5 : 0);
14238
b55e97028105 (pop_retrieve, getline): Avoid type clashes.
Karl Heuer <kwzh@gnu.org>
parents: 14186
diff changeset
714 ptr = (char *)malloc (bufsize);
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
715 free ((char *) IDs);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
716 free ((char *) sizes);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
717
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
718 if (! ptr)
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
719 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
720 strcpy (pop_error, "Out of memory in pop_retrieve");
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
721 pop_retrieve_flush (server);
20418
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
722 return (-1);
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
723 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
724
20418
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
725 while ((ret = pop_retrieve_next (server, &fromserver)) >= 0)
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
726 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
727 if (! fromserver)
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
728 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
729 ptr[cp] = '\0';
20418
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
730 *msg_buf = ptr;
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
731 return (cp);
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
732 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
733 if (markfrom && fromserver[0] == 'F' && fromserver[1] == 'r' &&
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
734 fromserver[2] == 'o' && fromserver[3] == 'm' &&
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
735 fromserver[4] == ' ')
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
736 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
737 if (++fromcount == 5)
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
738 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
739 bufsize += 5;
14238
b55e97028105 (pop_retrieve, getline): Avoid type clashes.
Karl Heuer <kwzh@gnu.org>
parents: 14186
diff changeset
740 ptr = (char *)realloc (ptr, bufsize);
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
741 if (! ptr)
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
742 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
743 strcpy (pop_error, "Out of memory in pop_retrieve");
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
744 pop_retrieve_flush (server);
20418
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
745 return (-1);
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
746 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
747 fromcount = 0;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
748 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
749 ptr[cp++] = '>';
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
750 }
20418
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
751 bcopy (fromserver, &ptr[cp], ret);
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
752 cp += ret;
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
753 ptr[cp++] = '\n';
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
754 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
755
20418
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
756 free (ptr);
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
757 return (-1);
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
758 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
759
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
760 int
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
761 pop_retrieve_first (server, message, response)
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
762 popserver server;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
763 int message;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
764 char **response;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
765 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
766 sprintf (pop_error, "RETR %d", message);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
767 return (pop_multi_first (server, pop_error, response));
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
768 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
769
20418
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
770 /*
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
771 Returns a negative number on error, 0 to indicate that the data has
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
772 all been read (i.e., the server has returned a "." termination
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
773 line), or a positive number indicating the number of bytes in the
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
774 returned buffer (which is null-terminated and may contain embedded
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
775 nulls, but the returned bytecount doesn't include the final null).
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
776 */
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
777
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
778 int
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
779 pop_retrieve_next (server, line)
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
780 popserver server;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
781 char **line;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
782 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
783 return (pop_multi_next (server, line));
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
784 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
785
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
786 int
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
787 pop_retrieve_flush (server)
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
788 popserver server;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
789 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
790 return (pop_multi_flush (server));
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
791 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
792
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
793 int
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
794 pop_top_first (server, message, lines, response)
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
795 popserver server;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
796 int message, lines;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
797 char **response;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
798 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
799 sprintf (pop_error, "TOP %d %d", message, lines);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
800 return (pop_multi_first (server, pop_error, response));
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
801 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
802
20418
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
803 /*
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
804 Returns a negative number on error, 0 to indicate that the data has
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
805 all been read (i.e., the server has returned a "." termination
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
806 line), or a positive number indicating the number of bytes in the
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
807 returned buffer (which is null-terminated and may contain embedded
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
808 nulls, but the returned bytecount doesn't include the final null).
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
809 */
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
810
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
811 int
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
812 pop_top_next (server, line)
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
813 popserver server;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
814 char **line;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
815 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
816 return (pop_multi_next (server, line));
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
817 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
818
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
819 int
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
820 pop_top_flush (server)
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
821 popserver server;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
822 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
823 return (pop_multi_flush (server));
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
824 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
825
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
826 int
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
827 pop_multi_first (server, command, response)
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
828 popserver server;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
829 char *command;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
830 char **response;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
831 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
832 if (server->in_multi)
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
833 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
834 strcpy (pop_error,
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
835 "Already in multi-line query in pop_multi_first");
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
836 return (-1);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
837 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
838
21295
f399e51d6d11 (pop_getline): Renamed from getline.
Richard M. Stallman <rms@gnu.org>
parents: 20418
diff changeset
839 if (sendline (server, command) || (pop_getline (server, response) < 0))
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
840 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
841 return (-1);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
842 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
843
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
844 if (0 == strncmp (*response, "-ERR", 4))
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
845 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
846 strncpy (pop_error, *response, ERROR_MAX);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
847 return (-1);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
848 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
849 else if (0 == strncmp (*response, "+OK", 3))
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
850 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
851 for (*response += 3; **response == ' '; (*response)++) /* empty */;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
852 server->in_multi = 1;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
853 return (0);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
854 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
855 else
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
856 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
857 strcpy (pop_error,
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
858 "Unexpected response from server in pop_multi_first");
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
859 return (-1);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
860 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
861 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
862
20418
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
863 /*
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
864 Read the next line of data from SERVER and place a pointer to it
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
865 into LINE. Return -1 on error, 0 if there are no more lines to read
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
866 (i.e., the server has returned a line containing only "."), or a
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
867 positive number indicating the number of bytes in the LINE buffer
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
868 (not including the final null). The data in that buffer may contain
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
869 embedded nulls, but does not contain the final CRLF. When returning
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
870 0, LINE is set to null. */
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
871
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
872 int
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
873 pop_multi_next (server, line)
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
874 popserver server;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
875 char **line;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
876 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
877 char *fromserver;
20418
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
878 int ret;
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
879
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
880 if (! server->in_multi)
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
881 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
882 strcpy (pop_error, "Not in multi-line query in pop_multi_next");
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
883 return (-1);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
884 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
885
21295
f399e51d6d11 (pop_getline): Renamed from getline.
Richard M. Stallman <rms@gnu.org>
parents: 20418
diff changeset
886 if ((ret = pop_getline (server, &fromserver)) < 0)
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
887 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
888 return (-1);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
889 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
890
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
891 if (fromserver[0] == '.')
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
892 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
893 if (! fromserver[1])
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
894 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
895 *line = 0;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
896 server->in_multi = 0;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
897 return (0);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
898 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
899 else
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
900 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
901 *line = fromserver + 1;
20418
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
902 return (ret - 1);
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
903 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
904 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
905 else
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
906 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
907 *line = fromserver;
20418
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
908 return (ret);
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
909 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
910 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
911
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
912 int
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
913 pop_multi_flush (server)
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
914 popserver server;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
915 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
916 char *line;
20418
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
917 int ret;
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
918
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
919 if (! server->in_multi)
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
920 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
921 return (0);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
922 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
923
20418
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
924 while ((ret = pop_multi_next (server, &line)))
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
925 {
20418
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
926 if (ret < 0)
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
927 return (-1);
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
928 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
929
20418
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
930 return (0);
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
931 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
932
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
933 /* Function: pop_delete
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
934 *
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
935 * Purpose: Delete a specified message.
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
936 *
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
937 * Arguments:
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
938 * server Server from which to delete the message.
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
939 * message Message to delete.
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
940 *
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
941 * Return value: 0 on success, non-zero with error in pop_error
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
942 * otherwise.
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
943 */
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
944 int
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
945 pop_delete (server, message)
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
946 popserver server;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
947 int message;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
948 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
949 if (server->in_multi)
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
950 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
951 strcpy (pop_error, "In multi-line query in pop_delete");
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
952 return (-1);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
953 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
954
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
955 sprintf (pop_error, "DELE %d", message);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
956
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
957 if (sendline (server, pop_error) || getok (server))
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
958 return (-1);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
959
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
960 return (0);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
961 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
962
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
963 /*
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
964 * Function: pop_noop
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
965 *
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
966 * Purpose: Send a noop command to the server.
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
967 *
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
968 * Argument:
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
969 * server The server to send to.
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
970 *
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
971 * Return value: 0 on success, non-zero with error in pop_error
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
972 * otherwise.
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
973 *
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
974 * Side effects: Closes connection on error.
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
975 */
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
976 int
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
977 pop_noop (server)
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
978 popserver server;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
979 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
980 if (server->in_multi)
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
981 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
982 strcpy (pop_error, "In multi-line query in pop_noop");
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
983 return (-1);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
984 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
985
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
986 if (sendline (server, "NOOP") || getok (server))
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
987 return (-1);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
988
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
989 return (0);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
990 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
991
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
992 /*
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
993 * Function: pop_last
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
994 *
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
995 * Purpose: Find out the highest seen message from the server.
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
996 *
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
997 * Arguments:
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
998 * server The server.
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
999 *
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1000 * Return value: If successful, the highest seen message, which is
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1001 * greater than or equal to 0. Otherwise, a negative number with
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1002 * the error explained in pop_error.
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1003 *
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1004 * Side effects: Closes the connection on error.
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1005 */
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1006 int
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1007 pop_last (server)
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1008 popserver server;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1009 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1010 char *fromserver;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1011
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1012 if (server->in_multi)
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1013 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1014 strcpy (pop_error, "In multi-line query in pop_last");
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1015 return (-1);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1016 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1017
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1018 if (sendline (server, "LAST"))
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1019 return (-1);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1020
21295
f399e51d6d11 (pop_getline): Renamed from getline.
Richard M. Stallman <rms@gnu.org>
parents: 20418
diff changeset
1021 if (pop_getline (server, &fromserver) < 0)
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1022 return (-1);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1023
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1024 if (! strncmp (fromserver, "-ERR", 4))
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1025 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1026 strncpy (pop_error, fromserver, ERROR_MAX);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1027 return (-1);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1028 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1029 else if (strncmp (fromserver, "+OK ", 4))
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1030 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1031 strcpy (pop_error, "Unexpected response from server in pop_last");
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1032 pop_trash (server);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1033 return (-1);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1034 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1035 else
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1036 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1037 return (atoi (&fromserver[4]));
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1038 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1039 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1040
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1041 /*
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1042 * Function: pop_reset
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1043 *
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1044 * Purpose: Reset the server to its initial connect state
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1045 *
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1046 * Arguments:
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1047 * server The server.
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1048 *
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1049 * Return value: 0 for success, non-0 with error in pop_error
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1050 * otherwise.
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1051 *
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1052 * Side effects: Closes the connection on error.
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1053 */
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1054 int
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1055 pop_reset (server)
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1056 popserver server;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1057 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1058 if (pop_retrieve_flush (server))
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1059 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1060 return (-1);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1061 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1062
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1063 if (sendline (server, "RSET") || getok (server))
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1064 return (-1);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1065
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1066 return (0);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1067 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1068
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1069 /*
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1070 * Function: pop_quit
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1071 *
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1072 * Purpose: Quit the connection to the server,
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1073 *
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1074 * Arguments:
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1075 * server The server to quit.
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1076 *
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1077 * Return value: 0 for success, non-zero otherwise with error in
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1078 * pop_error.
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1079 *
14036
621a575db6f7 Comment fixes.
Karl Heuer <kwzh@gnu.org>
parents: 9674
diff changeset
1080 * Side Effects: The popserver passed in is unusable after this
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1081 * function is called, even if an error occurs.
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1082 */
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1083 int
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1084 pop_quit (server)
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1085 popserver server;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1086 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1087 int ret = 0;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1088
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1089 if (server->file >= 0)
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1090 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1091 if (pop_retrieve_flush (server))
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1092 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1093 ret = -1;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1094 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1095
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1096 if (sendline (server, "QUIT") || getok (server))
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1097 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1098 ret = -1;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1099 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1100
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1101 close (server->file);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1102 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1103
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1104 if (server->buffer)
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1105 free (server->buffer);
21397
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1106 #ifdef GSSAPI
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1107 if (server->extra)
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1108 {
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1109 OM_uint32 minor;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1110
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1111 if (Gssapi (server->extra)->gss_context != GSS_C_NO_CONTEXT)
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1112 gss_delete_sec_context (&minor, &(Gssapi (server->extra)->gss_context),
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1113 GSS_C_NO_BUFFER);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1114 free ((char *) server->extra);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1115 }
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1116 #endif /* GSSAPI */
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1117 free ((char *) server);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1118
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1119 return (ret);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1120 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1121
15102
ed550d0805ca [WINDOWSNT]: Include winsock.h and ntlib.h.
Richard M. Stallman <rms@gnu.org>
parents: 14238
diff changeset
1122 #ifdef WINDOWSNT
ed550d0805ca [WINDOWSNT]: Include winsock.h and ntlib.h.
Richard M. Stallman <rms@gnu.org>
parents: 14238
diff changeset
1123 static int have_winsock = 0;
ed550d0805ca [WINDOWSNT]: Include winsock.h and ntlib.h.
Richard M. Stallman <rms@gnu.org>
parents: 14238
diff changeset
1124 #endif
ed550d0805ca [WINDOWSNT]: Include winsock.h and ntlib.h.
Richard M. Stallman <rms@gnu.org>
parents: 14238
diff changeset
1125
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1126 /*
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1127 * Function: socket_connection
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1128 *
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1129 * Purpose: Opens the network connection with the mail host, without
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1130 * doing any sort of I/O with it or anything.
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1131 *
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1132 * Arguments:
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1133 * host The host to which to connect.
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1134 * flags Option flags.
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1135 *
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1136 * Return value: A file descriptor indicating the connection, or -1
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1137 * indicating failure, in which case an error has been copied
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1138 * into pop_error.
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1139 */
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1140 static int
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1141 socket_connection (host, flags)
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1142 char *host;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1143 int flags;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1144 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1145 struct hostent *hostent;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1146 struct servent *servent;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1147 struct sockaddr_in addr;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1148 char found_port = 0;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1149 char *service;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1150 int sock;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1151 #ifdef KERBEROS
19018
f1f7c254aa77 Support auto-configuration of both Kerberos V4 and
Richard M. Stallman <rms@gnu.org>
parents: 17683
diff changeset
1152 #ifdef KERBEROS5
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1153 krb5_error_code rem;
19018
f1f7c254aa77 Support auto-configuration of both Kerberos V4 and
Richard M. Stallman <rms@gnu.org>
parents: 17683
diff changeset
1154 krb5_context kcontext = 0;
f1f7c254aa77 Support auto-configuration of both Kerberos V4 and
Richard M. Stallman <rms@gnu.org>
parents: 17683
diff changeset
1155 krb5_auth_context auth_context = 0;
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1156 krb5_ccache ccdef;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1157 krb5_principal client, server;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1158 krb5_error *err_ret;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1159 register char *cp;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1160 #else
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1161 KTEXT ticket;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1162 MSG_DAT msg_data;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1163 CREDENTIALS cred;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1164 Key_schedule schedule;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1165 int rem;
16603
a12b8815bcf0 gethostbyname() may return a pointer to static data, which is
Charles Hannum <mycroft@gnu.org>
parents: 15934
diff changeset
1166 char *realhost;
19018
f1f7c254aa77 Support auto-configuration of both Kerberos V4 and
Richard M. Stallman <rms@gnu.org>
parents: 17683
diff changeset
1167 #endif /* KERBEROS5 */
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1168 #endif /* KERBEROS */
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1169
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1170 int try_count = 0;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1171
15102
ed550d0805ca [WINDOWSNT]: Include winsock.h and ntlib.h.
Richard M. Stallman <rms@gnu.org>
parents: 14238
diff changeset
1172 #ifdef WINDOWSNT
ed550d0805ca [WINDOWSNT]: Include winsock.h and ntlib.h.
Richard M. Stallman <rms@gnu.org>
parents: 14238
diff changeset
1173 {
ed550d0805ca [WINDOWSNT]: Include winsock.h and ntlib.h.
Richard M. Stallman <rms@gnu.org>
parents: 14238
diff changeset
1174 WSADATA winsockData;
ed550d0805ca [WINDOWSNT]: Include winsock.h and ntlib.h.
Richard M. Stallman <rms@gnu.org>
parents: 14238
diff changeset
1175 if (WSAStartup (0x101, &winsockData) == 0)
ed550d0805ca [WINDOWSNT]: Include winsock.h and ntlib.h.
Richard M. Stallman <rms@gnu.org>
parents: 14238
diff changeset
1176 have_winsock = 1;
ed550d0805ca [WINDOWSNT]: Include winsock.h and ntlib.h.
Richard M. Stallman <rms@gnu.org>
parents: 14238
diff changeset
1177 }
ed550d0805ca [WINDOWSNT]: Include winsock.h and ntlib.h.
Richard M. Stallman <rms@gnu.org>
parents: 14238
diff changeset
1178 #endif
ed550d0805ca [WINDOWSNT]: Include winsock.h and ntlib.h.
Richard M. Stallman <rms@gnu.org>
parents: 14238
diff changeset
1179
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1180 do
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1181 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1182 hostent = gethostbyname (host);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1183 try_count++;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1184 if ((! hostent) && ((h_errno != TRY_AGAIN) || (try_count == 5)))
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1185 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1186 strcpy (pop_error, "Could not determine POP server's address");
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1187 return (-1);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1188 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1189 } while (! hostent);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1190
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1191 bzero ((char *) &addr, sizeof (addr));
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1192 addr.sin_family = AF_INET;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1193
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1194 #ifdef KERBEROS
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1195 service = (flags & POP_NO_KERBEROS) ? POP_SERVICE : KPOP_SERVICE;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1196 #else
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1197 service = POP_SERVICE;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1198 #endif
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1199
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1200 #ifdef HESIOD
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1201 if (! (flags & POP_NO_HESIOD))
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1202 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1203 servent = hes_getservbyname (service, "tcp");
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1204 if (servent)
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1205 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1206 addr.sin_port = servent->s_port;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1207 found_port = 1;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1208 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1209 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1210 #endif
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1211 if (! found_port)
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1212 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1213 servent = getservbyname (service, "tcp");
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1214 if (servent)
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1215 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1216 addr.sin_port = servent->s_port;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1217 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1218 else
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1219 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1220 #ifdef KERBEROS
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1221 addr.sin_port = htons ((flags & POP_NO_KERBEROS) ?
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1222 POP_PORT : KPOP_PORT);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1223 #else
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1224 addr.sin_port = htons (POP_PORT);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1225 #endif
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1226 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1227 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1228
19018
f1f7c254aa77 Support auto-configuration of both Kerberos V4 and
Richard M. Stallman <rms@gnu.org>
parents: 17683
diff changeset
1229 #define POP_SOCKET_ERROR "Could not create socket for POP connection: "
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1230
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1231 sock = socket (PF_INET, SOCK_STREAM, 0);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1232 if (sock < 0)
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1233 {
19018
f1f7c254aa77 Support auto-configuration of both Kerberos V4 and
Richard M. Stallman <rms@gnu.org>
parents: 17683
diff changeset
1234 strcpy (pop_error, POP_SOCKET_ERROR);
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1235 strncat (pop_error, strerror (errno),
19018
f1f7c254aa77 Support auto-configuration of both Kerberos V4 and
Richard M. Stallman <rms@gnu.org>
parents: 17683
diff changeset
1236 ERROR_MAX - sizeof (POP_SOCKET_ERROR));
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1237 return (-1);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1238
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1239 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1240
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1241 while (*hostent->h_addr_list)
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1242 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1243 bcopy (*hostent->h_addr_list, (char *) &addr.sin_addr,
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1244 hostent->h_length);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1245 if (! connect (sock, (struct sockaddr *) &addr, sizeof (addr)))
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1246 break;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1247 hostent->h_addr_list++;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1248 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1249
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1250 #define CONNECT_ERROR "Could not connect to POP server: "
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1251
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1252 if (! *hostent->h_addr_list)
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1253 {
15108
442458addd50 (SEND, RECV): Renamed from send, recv.
Richard M. Stallman <rms@gnu.org>
parents: 15102
diff changeset
1254 CLOSESOCKET (sock);
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1255 strcpy (pop_error, CONNECT_ERROR);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1256 strncat (pop_error, strerror (errno),
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1257 ERROR_MAX - sizeof (CONNECT_ERROR));
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1258 return (-1);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1259
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1260 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1261
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1262 #ifdef KERBEROS
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1263 #define KRB_ERROR "Kerberos error connecting to POP server: "
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1264 if (! (flags & POP_NO_KERBEROS))
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1265 {
19018
f1f7c254aa77 Support auto-configuration of both Kerberos V4 and
Richard M. Stallman <rms@gnu.org>
parents: 17683
diff changeset
1266 #ifdef KERBEROS5
f1f7c254aa77 Support auto-configuration of both Kerberos V4 and
Richard M. Stallman <rms@gnu.org>
parents: 17683
diff changeset
1267 if ((rem = krb5_init_context (&kcontext)))
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1268 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1269 krb5error:
19018
f1f7c254aa77 Support auto-configuration of both Kerberos V4 and
Richard M. Stallman <rms@gnu.org>
parents: 17683
diff changeset
1270 if (auth_context)
f1f7c254aa77 Support auto-configuration of both Kerberos V4 and
Richard M. Stallman <rms@gnu.org>
parents: 17683
diff changeset
1271 krb5_auth_con_free (kcontext, auth_context);
f1f7c254aa77 Support auto-configuration of both Kerberos V4 and
Richard M. Stallman <rms@gnu.org>
parents: 17683
diff changeset
1272 if (kcontext)
f1f7c254aa77 Support auto-configuration of both Kerberos V4 and
Richard M. Stallman <rms@gnu.org>
parents: 17683
diff changeset
1273 krb5_free_context (kcontext);
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1274 strcpy (pop_error, KRB_ERROR);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1275 strncat (pop_error, error_message (rem),
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1276 ERROR_MAX - sizeof(KRB_ERROR));
15108
442458addd50 (SEND, RECV): Renamed from send, recv.
Richard M. Stallman <rms@gnu.org>
parents: 15102
diff changeset
1277 CLOSESOCKET (sock);
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1278 return (-1);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1279 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1280
19018
f1f7c254aa77 Support auto-configuration of both Kerberos V4 and
Richard M. Stallman <rms@gnu.org>
parents: 17683
diff changeset
1281 if ((rem = krb5_auth_con_init (kcontext, &auth_context)))
f1f7c254aa77 Support auto-configuration of both Kerberos V4 and
Richard M. Stallman <rms@gnu.org>
parents: 17683
diff changeset
1282 goto krb5error;
f1f7c254aa77 Support auto-configuration of both Kerberos V4 and
Richard M. Stallman <rms@gnu.org>
parents: 17683
diff changeset
1283
f1f7c254aa77 Support auto-configuration of both Kerberos V4 and
Richard M. Stallman <rms@gnu.org>
parents: 17683
diff changeset
1284 if (rem = krb5_cc_default (kcontext, &ccdef))
f1f7c254aa77 Support auto-configuration of both Kerberos V4 and
Richard M. Stallman <rms@gnu.org>
parents: 17683
diff changeset
1285 goto krb5error;
f1f7c254aa77 Support auto-configuration of both Kerberos V4 and
Richard M. Stallman <rms@gnu.org>
parents: 17683
diff changeset
1286
f1f7c254aa77 Support auto-configuration of both Kerberos V4 and
Richard M. Stallman <rms@gnu.org>
parents: 17683
diff changeset
1287 if (rem = krb5_cc_get_principal (kcontext, ccdef, &client))
f1f7c254aa77 Support auto-configuration of both Kerberos V4 and
Richard M. Stallman <rms@gnu.org>
parents: 17683
diff changeset
1288 goto krb5error;
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1289
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1290 for (cp = hostent->h_name; *cp; cp++)
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1291 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1292 if (isupper (*cp))
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1293 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1294 *cp = tolower (*cp);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1295 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1296 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1297
19018
f1f7c254aa77 Support auto-configuration of both Kerberos V4 and
Richard M. Stallman <rms@gnu.org>
parents: 17683
diff changeset
1298 if (rem = krb5_sname_to_principal (kcontext, hostent->h_name,
f1f7c254aa77 Support auto-configuration of both Kerberos V4 and
Richard M. Stallman <rms@gnu.org>
parents: 17683
diff changeset
1299 POP_SERVICE, FALSE, &server))
f1f7c254aa77 Support auto-configuration of both Kerberos V4 and
Richard M. Stallman <rms@gnu.org>
parents: 17683
diff changeset
1300 goto krb5error;
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1301
19018
f1f7c254aa77 Support auto-configuration of both Kerberos V4 and
Richard M. Stallman <rms@gnu.org>
parents: 17683
diff changeset
1302 rem = krb5_sendauth (kcontext, &auth_context,
f1f7c254aa77 Support auto-configuration of both Kerberos V4 and
Richard M. Stallman <rms@gnu.org>
parents: 17683
diff changeset
1303 (krb5_pointer) &sock, "KPOPV1.0", client, server,
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1304 AP_OPTS_MUTUAL_REQUIRED,
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1305 0, /* no checksum */
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1306 0, /* no creds, use ccache instead */
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1307 ccdef,
19018
f1f7c254aa77 Support auto-configuration of both Kerberos V4 and
Richard M. Stallman <rms@gnu.org>
parents: 17683
diff changeset
1308 &err_ret,
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1309 0, /* don't need subsession key */
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1310 0); /* don't need reply */
19018
f1f7c254aa77 Support auto-configuration of both Kerberos V4 and
Richard M. Stallman <rms@gnu.org>
parents: 17683
diff changeset
1311 krb5_free_principal (kcontext, server);
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1312 if (rem)
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1313 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1314 if (err_ret && err_ret->text.length)
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1315 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1316 strcpy (pop_error, KRB_ERROR);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1317 strncat (pop_error, error_message (rem),
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1318 ERROR_MAX - sizeof (KRB_ERROR));
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1319 strncat (pop_error, " [server says '",
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1320 ERROR_MAX - strlen (pop_error) - 1);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1321 strncat (pop_error, err_ret->text.data,
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1322 min (ERROR_MAX - strlen (pop_error) - 1,
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1323 err_ret->text.length));
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1324 strncat (pop_error, "']",
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1325 ERROR_MAX - strlen (pop_error) - 1);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1326 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1327 else
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1328 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1329 strcpy (pop_error, KRB_ERROR);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1330 strncat (pop_error, error_message (rem),
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1331 ERROR_MAX - sizeof (KRB_ERROR));
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1332 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1333 if (err_ret)
19018
f1f7c254aa77 Support auto-configuration of both Kerberos V4 and
Richard M. Stallman <rms@gnu.org>
parents: 17683
diff changeset
1334 krb5_free_error (kcontext, err_ret);
f1f7c254aa77 Support auto-configuration of both Kerberos V4 and
Richard M. Stallman <rms@gnu.org>
parents: 17683
diff changeset
1335 krb5_auth_con_free (kcontext, auth_context);
f1f7c254aa77 Support auto-configuration of both Kerberos V4 and
Richard M. Stallman <rms@gnu.org>
parents: 17683
diff changeset
1336 krb5_free_context (kcontext);
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1337
15108
442458addd50 (SEND, RECV): Renamed from send, recv.
Richard M. Stallman <rms@gnu.org>
parents: 15102
diff changeset
1338 CLOSESOCKET (sock);
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1339 return (-1);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1340 }
19018
f1f7c254aa77 Support auto-configuration of both Kerberos V4 and
Richard M. Stallman <rms@gnu.org>
parents: 17683
diff changeset
1341 #else /* ! KERBEROS5 */
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1342 ticket = (KTEXT) malloc (sizeof (KTEXT_ST));
16603
a12b8815bcf0 gethostbyname() may return a pointer to static data, which is
Charles Hannum <mycroft@gnu.org>
parents: 15934
diff changeset
1343 realhost = strdup (hostent->h_name);
a12b8815bcf0 gethostbyname() may return a pointer to static data, which is
Charles Hannum <mycroft@gnu.org>
parents: 15934
diff changeset
1344 rem = krb_sendauth (0L, sock, ticket, "pop", realhost,
a12b8815bcf0 gethostbyname() may return a pointer to static data, which is
Charles Hannum <mycroft@gnu.org>
parents: 15934
diff changeset
1345 (char *) krb_realmofhost (realhost),
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1346 (unsigned long) 0, &msg_data, &cred, schedule,
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1347 (struct sockaddr_in *) 0,
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1348 (struct sockaddr_in *) 0,
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1349 "KPOPV0.1");
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1350 free ((char *) ticket);
16697
83946dc6f4e7 (socket_connection): Free realhost after using it.
Richard M. Stallman <rms@gnu.org>
parents: 16603
diff changeset
1351 free (realhost);
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1352 if (rem != KSUCCESS)
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1353 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1354 strcpy (pop_error, KRB_ERROR);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1355 strncat (pop_error, krb_err_txt[rem],
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1356 ERROR_MAX - sizeof (KRB_ERROR));
15108
442458addd50 (SEND, RECV): Renamed from send, recv.
Richard M. Stallman <rms@gnu.org>
parents: 15102
diff changeset
1357 CLOSESOCKET (sock);
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1358 return (-1);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1359 }
19018
f1f7c254aa77 Support auto-configuration of both Kerberos V4 and
Richard M. Stallman <rms@gnu.org>
parents: 17683
diff changeset
1360 #endif /* KERBEROS5 */
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1361 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1362 #endif /* KERBEROS */
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1363
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1364 return (sock);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1365 } /* socket_connection */
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1366
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1367 /*
21295
f399e51d6d11 (pop_getline): Renamed from getline.
Richard M. Stallman <rms@gnu.org>
parents: 20418
diff changeset
1368 * Function: pop_getline
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1369 *
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1370 * Purpose: Get a line of text from the connection and return a
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1371 * pointer to it. The carriage return and linefeed at the end of
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1372 * the line are stripped, but periods at the beginnings of lines
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1373 * are NOT dealt with in any special way.
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1374 *
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1375 * Arguments:
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1376 * server The server from which to get the line of text.
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1377 *
20418
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
1378 * Returns: The number of characters in the line, which is returned in
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
1379 * LINE, not including the final null. A return value of 0
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
1380 * indicates a blank line. A negative return value indicates an
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
1381 * error (in which case the contents of LINE are undefined. In
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
1382 * case of error, an error message is copied into pop_error.
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1383 *
21295
f399e51d6d11 (pop_getline): Renamed from getline.
Richard M. Stallman <rms@gnu.org>
parents: 20418
diff changeset
1384 * Notes: The line returned is overwritten with each call to pop_getline.
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1385 *
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1386 * Side effects: Closes the connection on error.
20418
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
1387 *
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
1388 * THE RETURNED LINE MAY CONTAIN EMBEDDED NULLS!
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1389 */
20418
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
1390 static int
21295
f399e51d6d11 (pop_getline): Renamed from getline.
Richard M. Stallman <rms@gnu.org>
parents: 20418
diff changeset
1391 pop_getline (server, line)
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1392 popserver server;
20418
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
1393 char **line;
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1394 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1395 #define GETLINE_ERROR "Error reading from server: "
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1396
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1397 int ret;
9674
e5a897cf215d (getline): When a search of already-read input for CRLF
Richard M. Stallman <rms@gnu.org>
parents: 9613
diff changeset
1398 int search_offset = 0;
e5a897cf215d (getline): When a search of already-read input for CRLF
Richard M. Stallman <rms@gnu.org>
parents: 9613
diff changeset
1399
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1400 if (server->data)
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1401 {
20418
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
1402 char *cp = find_crlf (server->buffer + server->buffer_index,
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
1403 server->data);
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1404 if (cp)
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1405 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1406 int found;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1407 int data_used;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1408
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1409 found = server->buffer_index;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1410 data_used = (cp + 2) - server->buffer - found;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1411
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1412 *cp = '\0'; /* terminate the string to be returned */
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1413 server->data -= data_used;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1414 server->buffer_index += data_used;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1415
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1416 if (pop_debug)
20418
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
1417 /* Embedded nulls will truncate this output prematurely,
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
1418 but that's OK because it's just for debugging anyway. */
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1419 fprintf (stderr, "<<< %s\n", server->buffer + found);
20418
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
1420 *line = server->buffer + found;
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
1421 return (data_used - 2);
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1422 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1423 else
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1424 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1425 bcopy (server->buffer + server->buffer_index,
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1426 server->buffer, server->data);
9674
e5a897cf215d (getline): When a search of already-read input for CRLF
Richard M. Stallman <rms@gnu.org>
parents: 9613
diff changeset
1427 /* Record the fact that we've searched the data already in
e5a897cf215d (getline): When a search of already-read input for CRLF
Richard M. Stallman <rms@gnu.org>
parents: 9613
diff changeset
1428 the buffer for a CRLF, so that when we search below, we
e5a897cf215d (getline): When a search of already-read input for CRLF
Richard M. Stallman <rms@gnu.org>
parents: 9613
diff changeset
1429 don't have to search the same data twice. There's a "-
e5a897cf215d (getline): When a search of already-read input for CRLF
Richard M. Stallman <rms@gnu.org>
parents: 9613
diff changeset
1430 1" here to account for the fact that the last character
e5a897cf215d (getline): When a search of already-read input for CRLF
Richard M. Stallman <rms@gnu.org>
parents: 9613
diff changeset
1431 of the data we have may be the CR of a CRLF pair, of
e5a897cf215d (getline): When a search of already-read input for CRLF
Richard M. Stallman <rms@gnu.org>
parents: 9613
diff changeset
1432 which we haven't read the second half yet, so we may have
e5a897cf215d (getline): When a search of already-read input for CRLF
Richard M. Stallman <rms@gnu.org>
parents: 9613
diff changeset
1433 to search it again when we read more data. */
e5a897cf215d (getline): When a search of already-read input for CRLF
Richard M. Stallman <rms@gnu.org>
parents: 9613
diff changeset
1434 search_offset = server->data - 1;
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1435 server->buffer_index = 0;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1436 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1437 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1438 else
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1439 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1440 server->buffer_index = 0;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1441 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1442
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1443 while (1)
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1444 {
21397
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1445 #ifdef GSSAPI
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1446 /*
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1447 * We might be playing with a protected connection. If we are, then
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1448 * we need to first read a chunk of ciphertext from the server,
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1449 * unwrap it, and stuff it into the buffer.
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1450 */
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1451 if (server->extra &&
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1452 ((Gssapi (server->extra)->gss_flags) & GSSAPI_NEEDWRAP))
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1453 {
21397
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1454 char rcvbuf[GSSAPI_RCVBUF];
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1455 OM_uint32 major, minor, length;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1456 gss_buffer_desc in_tok, out_tok;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1457 struct _pop_gssapi *gss_data = Gssapi (server->extra);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1458
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1459 ret = fullread (server->file, (char *) &length, sizeof (length));
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1460
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1461 if (ret == sizeof (length))
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1462 {
21397
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1463 in_tok.length = ntohl (length);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1464
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1465 if (in_tok.length <= GSSAPI_RCVBUF)
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1466 {
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1467 ret = fullread (server->file, rcvbuf, in_tok.length);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1468
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1469 if (ret == in_tok.length)
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1470 {
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1471 in_tok.value = (void *) rcvbuf;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1472
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1473 major = gss_unwrap (&minor, gss_data->gss_context,
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1474 &in_tok, &out_tok, 0, 0);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1475
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1476 if (major != GSS_S_COMPLETE)
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1477 {
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1478 pop_trash (server);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1479 gen_gss_error ("unwrapping", major, minor);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1480 return (-1);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1481 }
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1482
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1483 while (server->data + out_tok.length >=
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1484 server->buffer_size - 1)
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1485 server->buffer_size += GETLINE_INCR;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1486
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1487 server->buffer = (char *)realloc (server->buffer,
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1488 server->buffer_size);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1489
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1490 if (! server->buffer)
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1491 {
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1492 gss_release_buffer (&minor, &out_tok);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1493 pop_trash (server);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1494 strcpy (pop_error, "Out of memory in pop_getline");
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1495 return (-1);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1496 }
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1497
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1498 bcopy (out_tok.value, server->buffer + server->data,
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1499 out_tok.length);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1500
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1501 ret = out_tok.length;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1502
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1503 gss_release_buffer (&minor, &out_tok);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1504 }
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1505 else
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1506 ret = 0; /* force detection of unexpected EOF */
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1507 }
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1508 else
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1509 {
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1510 pop_trash (server);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1511 strcpy (pop_error, "Token from server too long in pop_getline");
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1512 return (-1);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1513 }
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1514 }
21397
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1515 else
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1516 ret = 0; /* force detection of unexpected EOF */
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1517 }
21397
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1518 else
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1519 {
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1520 #endif /* GSSAPI */
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1521 /* There's a "- 1" here to leave room for the null that we put
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1522 at the end of the read data below. We put the null there so
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1523 that find_crlf knows where to stop when we call it. */
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1524 if (server->data == server->buffer_size - 1)
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1525 {
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1526 server->buffer_size += GETLINE_INCR;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1527 server->buffer = (char *)realloc (server->buffer,
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1528 server->buffer_size);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1529 if (! server->buffer)
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1530 {
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1531 strcpy (pop_error, "Out of memory in pop_getline");
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1532 pop_trash (server);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1533 return (-1);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1534 }
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1535 }
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1536 ret = RECV (server->file, server->buffer + server->data,
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1537 server->buffer_size - server->data - 1, 0);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1538 #ifdef GSSAPI
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1539 }
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1540 #endif /* GSSAPI */
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1541 if (ret < 0)
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1542 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1543 strcpy (pop_error, GETLINE_ERROR);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1544 strncat (pop_error, strerror (errno),
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1545 ERROR_MAX - sizeof (GETLINE_ERROR));
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1546 pop_trash (server);
20418
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
1547 return (-1);
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1548 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1549 else if (ret == 0)
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1550 {
21295
f399e51d6d11 (pop_getline): Renamed from getline.
Richard M. Stallman <rms@gnu.org>
parents: 20418
diff changeset
1551 strcpy (pop_error, "Unexpected EOF from server in pop_getline");
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1552 pop_trash (server);
20418
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
1553 return (-1);
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1554 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1555 else
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1556 {
9591
0774e217e8aa Don't declare malloc, realloc, free.
Richard M. Stallman <rms@gnu.org>
parents: 9158
diff changeset
1557 char *cp;
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1558 server->data += ret;
9591
0774e217e8aa Don't declare malloc, realloc, free.
Richard M. Stallman <rms@gnu.org>
parents: 9158
diff changeset
1559 server->buffer[server->data] = '\0';
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1560
20418
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
1561 cp = find_crlf (server->buffer + search_offset,
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
1562 server->data - search_offset);
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1563 if (cp)
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1564 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1565 int data_used = (cp + 2) - server->buffer;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1566 *cp = '\0';
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1567 server->data -= data_used;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1568 server->buffer_index = data_used;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1569
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1570 if (pop_debug)
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1571 fprintf (stderr, "<<< %s\n", server->buffer);
20418
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
1572 *line = server->buffer;
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
1573 return (data_used - 2);
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1574 }
17683
975d093d45fb (getline): Don't miss CRLF pairs when the CR and LF are
Richard M. Stallman <rms@gnu.org>
parents: 16697
diff changeset
1575 /* As above, the "- 1" here is to account for the fact that
975d093d45fb (getline): Don't miss CRLF pairs when the CR and LF are
Richard M. Stallman <rms@gnu.org>
parents: 16697
diff changeset
1576 we may have read a CR without its accompanying LF. */
975d093d45fb (getline): Don't miss CRLF pairs when the CR and LF are
Richard M. Stallman <rms@gnu.org>
parents: 16697
diff changeset
1577 search_offset += ret - 1;
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1578 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1579 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1580
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1581 /* NOTREACHED */
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1582 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1583
21397
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1584 #ifdef GSSAPI
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1585 /*
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1586 * Function: fullread
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1587 *
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1588 * Purpose: Just like read, but keeps trying until the specified number
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1589 * number of bytes has been read into the buffer. This function is
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1590 * only needed if you are using the GSSAPI protection mechanisms.
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1591 *
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1592 * Return value: Same as read. Pop_error is not set.
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1593 */
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1594 static int
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1595 fullread (fd, buf, nbytes)
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1596 int fd;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1597 char *buf;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1598 int nbytes;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1599 {
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1600 char *cp;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1601 int ret;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1602
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1603 cp = buf;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1604
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1605 while (nbytes > 0 && (ret = RECV (fd, cp, nbytes, 0)) > 0)
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1606 {
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1607 cp += ret;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1608 nbytes -= ret;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1609 }
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1610
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1611 return (ret);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1612 }
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1613 #endif /* GSSAPI */
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1614
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1615 /*
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1616 * Function: sendline
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1617 *
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1618 * Purpose: Sends a line of text to the POP server. The line of text
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1619 * passed into this function should NOT have the carriage return
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1620 * and linefeed on the end of it. Periods at beginnings of lines
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1621 * will NOT be treated specially by this function.
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1622 *
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1623 * Arguments:
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1624 * server The server to which to send the text.
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1625 * line The line of text to send.
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1626 *
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1627 * Return value: Upon successful completion, a value of 0 will be
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1628 * returned. Otherwise, a non-zero value will be returned, and
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1629 * an error will be copied into pop_error.
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1630 *
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1631 * Side effects: Closes the connection on error.
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1632 */
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1633 static int
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1634 sendline (server, line)
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1635 popserver server;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1636 char *line;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1637 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1638 #define SENDLINE_ERROR "Error writing to POP server: "
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1639 int ret;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1640
21397
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1641 #ifdef GSSAPI
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1642 /*
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1643 * We might be playing with a protected connection. If we are, then we
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1644 * need to build our full plaintext, parse it into chunks small enough
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1645 * for the server to swallow, wrap each one, and send it over the net as
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1646 * specified by the RFC.
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1647 */
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1648 if (server->extra && ((Gssapi (server->extra)->gss_flags) & GSSAPI_NEEDWRAP))
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1649 {
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1650 char *sendbuf, *ptr;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1651 OM_uint32 major, minor, length;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1652 gss_buffer_desc in_tok, out_tok;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1653 int len = 0, tot_len;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1654 struct _pop_gssapi *gss_data = Gssapi (server->extra);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1655
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1656 sendbuf = malloc (strlen (line) + 3);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1657
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1658 if (! sendbuf)
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1659 {
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1660 pop_trash (server);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1661 strcpy (pop_error, "Out of memory in sendline");
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1662 return (-1);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1663 }
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1664
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1665 tot_len = sprintf (sendbuf, "%s\r\n", line);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1666
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1667 for (ptr = sendbuf; tot_len > 0; tot_len -= len, ptr += len)
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1668 {
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1669 len = ((tot_len > gss_data->max_size) ?
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1670 gss_data->max_size : tot_len);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1671
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1672 in_tok.value = (void *) ptr;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1673 in_tok.length = len;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1674
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1675 major = gss_wrap (&minor, gss_data->gss_context,
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1676 (gss_data->gss_flags & GSSAPI_PRIVACY) ? 1 : 0,
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1677 GSS_C_QOP_DEFAULT, &in_tok, 0, &out_tok);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1678
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1679 if (major != GSS_S_COMPLETE)
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1680 {
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1681 free (sendbuf);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1682 pop_trash (server);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1683 gen_gss_error ("wrapping", major, minor);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1684 return (-1);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1685 }
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1686
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1687 /*
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1688 * "Once the protection mechanism is in effect, the stream of
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1689 * command and response octets is processed into buffers of
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1690 * ciphertext. Each buffer is transferred over the connection
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1691 * as a stream of octets prepended with a four octet field in
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1692 * network byte order that represents the length of the
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1693 * following data." - RFC 1734, section 2
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1694 */
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1695 length = htonl (out_tok.length);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1696 ret = fullwrite (server->file, (char *) &length, sizeof (length));
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1697 if (ret == sizeof (length))
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1698 {
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1699 ret = fullwrite (server->file, (char *) out_tok.value,
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1700 out_tok.length);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1701 }
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1702
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1703 gss_release_buffer (&minor, &out_tok);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1704
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1705 if (ret < 0)
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1706 break;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1707 }
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1708
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1709 free (sendbuf);
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1710 }
21397
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1711 else
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1712 {
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1713 #endif /* GSSAPI */
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1714 ret = fullwrite (server->file, line, strlen (line));
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1715 if (ret >= 0)
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1716 { /* 0 indicates that a blank line was written */
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1717 ret = fullwrite (server->file, "\r\n", 2);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1718 }
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1719 #ifdef GSSAPI
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1720 }
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1721 #endif /* GSSAPI */
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1722
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1723 if (ret < 0)
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1724 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1725 pop_trash (server);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1726 strcpy (pop_error, SENDLINE_ERROR);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1727 strncat (pop_error, strerror (errno),
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1728 ERROR_MAX - sizeof (SENDLINE_ERROR));
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1729 return (ret);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1730 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1731
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1732 if (pop_debug)
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1733 fprintf (stderr, ">>> %s\n", line);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1734
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1735 return (0);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1736 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1737
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1738 /*
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1739 * Procedure: fullwrite
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1740 *
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1741 * Purpose: Just like write, but keeps trying until the entire string
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1742 * has been written.
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1743 *
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1744 * Return value: Same as write. Pop_error is not set.
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1745 */
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1746 static int
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1747 fullwrite (fd, buf, nbytes)
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1748 int fd;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1749 char *buf;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1750 int nbytes;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1751 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1752 char *cp;
20204
44f91b648e03 (fullwrite): Get rid of an extra call to write. Problem
Karl Heuer <kwzh@gnu.org>
parents: 19978
diff changeset
1753 int ret = 0;
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1754
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1755 cp = buf;
20204
44f91b648e03 (fullwrite): Get rid of an extra call to write. Problem
Karl Heuer <kwzh@gnu.org>
parents: 19978
diff changeset
1756 while (nbytes && ((ret = SEND (fd, cp, nbytes, 0)) > 0))
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1757 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1758 cp += ret;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1759 nbytes -= ret;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1760 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1761
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1762 return (ret);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1763 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1764
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1765 /*
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1766 * Procedure getok
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1767 *
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1768 * Purpose: Reads a line from the server. If the return indicator is
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1769 * positive, return with a zero exit status. If not, return with
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1770 * a negative exit status.
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1771 *
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1772 * Arguments:
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1773 * server The server to read from.
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1774 *
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1775 * Returns: 0 for success, else for failure and puts error in pop_error.
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1776 *
14036
621a575db6f7 Comment fixes.
Karl Heuer <kwzh@gnu.org>
parents: 9674
diff changeset
1777 * Side effects: On failure, may make the connection unusable.
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1778 */
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1779 static int
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1780 getok (server)
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1781 popserver server;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1782 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1783 char *fromline;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1784
21295
f399e51d6d11 (pop_getline): Renamed from getline.
Richard M. Stallman <rms@gnu.org>
parents: 20418
diff changeset
1785 if (pop_getline (server, &fromline) < 0)
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1786 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1787 return (-1);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1788 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1789
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1790 if (! strncmp (fromline, "+OK", 3))
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1791 return (0);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1792 else if (! strncmp (fromline, "-ERR", 4))
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1793 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1794 strncpy (pop_error, fromline, ERROR_MAX);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1795 pop_error[ERROR_MAX-1] = '\0';
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1796 return (-1);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1797 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1798 else
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1799 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1800 strcpy (pop_error,
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1801 "Unexpected response from server; expecting +OK or -ERR");
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1802 pop_trash (server);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1803 return (-1);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1804 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1805 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1806
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1807 #if 0
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1808 /*
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1809 * Function: gettermination
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1810 *
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1811 * Purpose: Gets the next line and verifies that it is a termination
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1812 * line (nothing but a dot).
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1813 *
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1814 * Return value: 0 on success, non-zero with pop_error set on error.
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1815 *
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1816 * Side effects: Closes the connection on error.
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1817 */
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1818 static int
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1819 gettermination (server)
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1820 popserver server;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1821 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1822 char *fromserver;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1823
21295
f399e51d6d11 (pop_getline): Renamed from getline.
Richard M. Stallman <rms@gnu.org>
parents: 20418
diff changeset
1824 if (pop_getline (server, &fromserver) < 0)
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1825 return (-1);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1826
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1827 if (strcmp (fromserver, "."))
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1828 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1829 strcpy (pop_error,
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1830 "Unexpected response from server in gettermination");
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1831 pop_trash (server);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1832 return (-1);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1833 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1834
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1835 return (0);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1836 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1837 #endif
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1838
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1839 /*
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1840 * Function pop_close
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1841 *
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1842 * Purpose: Close a pop connection, sending a "RSET" command to try to
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1843 * preserve any changes that were made and a "QUIT" command to
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1844 * try to get the server to quit, but ignoring any responses that
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1845 * are received.
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1846 *
14036
621a575db6f7 Comment fixes.
Karl Heuer <kwzh@gnu.org>
parents: 9674
diff changeset
1847 * Side effects: The server is unusable after this function returns.
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1848 * Changes made to the maildrop since the session was started (or
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1849 * since the last pop_reset) may be lost.
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1850 */
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1851 void
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1852 pop_close (server)
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1853 popserver server;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1854 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1855 pop_trash (server);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1856 free ((char *) server);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1857
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1858 return;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1859 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1860
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1861 /*
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1862 * Function: pop_trash
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1863 *
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1864 * Purpose: Like pop_close or pop_quit, but doesn't deallocate the
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1865 * memory associated with the server. It is legal to call
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1866 * pop_close or pop_quit after this function has been called.
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1867 */
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1868 static void
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1869 pop_trash (server)
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1870 popserver server;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1871 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1872 if (server->file >= 0)
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1873 {
15102
ed550d0805ca [WINDOWSNT]: Include winsock.h and ntlib.h.
Richard M. Stallman <rms@gnu.org>
parents: 14238
diff changeset
1874 /* avoid recursion; sendline can call pop_trash */
ed550d0805ca [WINDOWSNT]: Include winsock.h and ntlib.h.
Richard M. Stallman <rms@gnu.org>
parents: 14238
diff changeset
1875 if (server->trash_started)
ed550d0805ca [WINDOWSNT]: Include winsock.h and ntlib.h.
Richard M. Stallman <rms@gnu.org>
parents: 14238
diff changeset
1876 return;
ed550d0805ca [WINDOWSNT]: Include winsock.h and ntlib.h.
Richard M. Stallman <rms@gnu.org>
parents: 14238
diff changeset
1877 server->trash_started = 1;
15108
442458addd50 (SEND, RECV): Renamed from send, recv.
Richard M. Stallman <rms@gnu.org>
parents: 15102
diff changeset
1878
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1879 sendline (server, "RSET");
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1880 sendline (server, "QUIT");
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1881
15108
442458addd50 (SEND, RECV): Renamed from send, recv.
Richard M. Stallman <rms@gnu.org>
parents: 15102
diff changeset
1882 CLOSESOCKET (server->file);
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1883 server->file = -1;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1884 if (server->buffer)
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1885 {
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1886 free (server->buffer);
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1887 server->buffer = 0;
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1888 }
21397
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1889 #ifdef GSSAPI
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1890 if (server->extra)
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1891 {
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1892 OM_uint32 minor;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1893
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1894 if (Gssapi (server->extra)->gss_context != GSS_C_NO_CONTEXT)
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1895 gss_delete_sec_context (&minor,
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1896 &(Gssapi (server->extra)->gss_context),
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1897 GSS_C_NO_BUFFER);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1898 free ((char *) server->extra);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1899 server->extra = 0;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1900 }
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1901 #endif /* GSSAPI */
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1902 }
15102
ed550d0805ca [WINDOWSNT]: Include winsock.h and ntlib.h.
Richard M. Stallman <rms@gnu.org>
parents: 14238
diff changeset
1903
ed550d0805ca [WINDOWSNT]: Include winsock.h and ntlib.h.
Richard M. Stallman <rms@gnu.org>
parents: 14238
diff changeset
1904 #ifdef WINDOWSNT
ed550d0805ca [WINDOWSNT]: Include winsock.h and ntlib.h.
Richard M. Stallman <rms@gnu.org>
parents: 14238
diff changeset
1905 if (have_winsock)
ed550d0805ca [WINDOWSNT]: Include winsock.h and ntlib.h.
Richard M. Stallman <rms@gnu.org>
parents: 14238
diff changeset
1906 WSACleanup ();
ed550d0805ca [WINDOWSNT]: Include winsock.h and ntlib.h.
Richard M. Stallman <rms@gnu.org>
parents: 14238
diff changeset
1907 #endif
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1908 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1909
21397
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1910 #ifdef GSSAPI
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1911 /*
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1912 * Function: pop_auth
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1913 *
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1914 * Purpose: To perform a GSSAPI authentication handshake with a POP server.
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1915 * If the negotiation is successful, it will return 0; otherwise, it
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1916 * will fill in pop_error with the error message and return either -1,
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1917 * indicating a potentially recoverable error, or -2, indicating an
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1918 * unrecoverable error.
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1919 *
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1920 * Side effects: The server may choose to close the connection if the
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1921 * handshake fails. The connection will be trashed if the error is
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1922 * unrecoverable.
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1923 */
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1924 static int
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1925 pop_auth (server, username, host, flags)
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1926 popserver server;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1927 char *username, *host;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1928 int flags;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1929 {
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1930 int gss_flags, ret;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1931 char *fromserver;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1932 OM_uint32 max_size, t_flags;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1933 gss_ctx_id_t gss_context = GSS_C_NO_CONTEXT;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1934 gss_buffer_desc in_tok, out_tok;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1935 gss_name_t svc_name;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1936 OM_uint32 major, minor, t_minor;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1937
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1938 /* calculate usable protection mechanisms */
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1939 gss_flags = (GSSAPI_PROTECTION &
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1940 ~(((flags & POP_NO_NOPROT) ? GSSAPI_NOPROT : 0) |
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1941 ((flags & POP_NO_INTEG) ? GSSAPI_INTEGRITY : 0) |
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1942 ((flags & POP_NO_ENCRYPT) ? GSSAPI_PRIVACY : 0)));
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1943
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1944 if (gss_flags == 0)
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1945 {
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1946 strcpy (pop_error, "Unable to provide selected protection level");
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1947 return (-1);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1948 }
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1949
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1950 /* import service name of pop server */
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1951 in_tok.value = (void *) malloc (strlen (host) + sizeof (GSSAPI_SERVICE) + 2);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1952
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1953 if (! in_tok.value)
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1954 {
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1955 strcpy (pop_error, "Out of memory in pop_auth");
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1956 return (-1);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1957 }
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1958
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1959 sprintf ((char *) in_tok.value, "%s@%s", GSSAPI_SERVICE, host);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1960 in_tok.length = strlen ((char *) in_tok.value);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1961
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1962 {
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1963 gss_OID_desc svc_name_oid = GSSAPI_SVC_TYPE;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1964
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1965 major = gss_import_name (&minor, &in_tok, &svc_name_oid, &svc_name);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1966 }
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1967
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1968 free ((char *) in_tok.value);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1969
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1970 if (major != GSS_S_COMPLETE)
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1971 {
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1972 gen_gss_error ("parsing name", major, minor);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1973 return (-1);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1974 }
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1975
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1976 /* begin GSSAPI authentication handshake */
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1977 if (sendline (server, "AUTH GSSAPI") || (pop_getline (server, &fromserver) < 0))
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1978 {
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1979 gss_release_name (&t_minor, &svc_name);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1980 return (-1);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1981 }
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1982
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1983 do
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1984 {
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1985 /* sanity-check server response */
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1986 if (strncmp (fromserver, "+ ", 2))
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1987 {
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1988 gss_release_name (&t_minor, &svc_name);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1989 if (gss_context != GSS_C_NO_CONTEXT)
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1990 gss_delete_sec_context (&t_minor, &gss_context, GSS_C_NO_BUFFER);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1991 if (0 == strncmp (fromserver, "-ERR", 4))
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1992 {
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1993 strncpy (pop_error, fromserver, ERROR_MAX);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1994 return (-1);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1995 }
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1996 else
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1997 {
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1998 pop_trash (server);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
1999 strcpy (pop_error,
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2000 "Unexpected response from POP server in pop_auth");
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2001 return (-2);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2002 }
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2003 }
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2004
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2005 if (strlen (fromserver) > 2)
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2006 {
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2007 /* base 64 decode the response... */
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2008 ret = b64_decode (fromserver + 2, &in_tok);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2009 if (ret != B64_SUCCESS)
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2010 {
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2011 gss_release_name (&t_minor, &svc_name);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2012 if (gss_context != GSS_C_NO_CONTEXT)
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2013 gss_delete_sec_context (&t_minor, &gss_context,
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2014 GSS_C_NO_BUFFER);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2015 sendline (server, "*");
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2016 strcpy (pop_error, b64_error[ret]);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2017 return (-1);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2018 }
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2019 }
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2020 else
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2021 {
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2022 in_tok.length = 0;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2023 in_tok.value = 0;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2024 }
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2025
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2026 /* call init_sec_context */
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2027 major = gss_init_sec_context (&minor, GSS_C_NO_CREDENTIAL, &gss_context,
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2028 svc_name, GSS_C_NULL_OID,
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2029 GSS_C_MUTUAL_FLAG, 0,
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2030 GSS_C_NO_CHANNEL_BINDINGS,
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2031 in_tok.length ? & in_tok : GSS_C_NO_BUFFER,
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2032 0, &out_tok, 0, 0);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2033
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2034 if (in_tok.length != 0)
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2035 free ((char *) in_tok.value);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2036
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2037 /* check for error */
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2038 if (GSS_ERROR (major))
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2039 {
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2040 gss_release_name (&t_minor, &svc_name);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2041 if (gss_context != GSS_C_NO_CONTEXT)
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2042 gss_delete_sec_context (&t_minor, &gss_context, GSS_C_NO_BUFFER);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2043 sendline (server, "*");
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2044 gen_gss_error ("in init_sec_context", major, minor);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2045 return (-1);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2046 }
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2047
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2048 if (out_tok.length != 0)
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2049 {
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2050 /* base 64 encode output token, if any */
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2051 ret = b64_encode (&out_tok, &fromserver);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2052
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2053 gss_release_buffer (&t_minor, &out_tok);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2054
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2055 if (ret != B64_SUCCESS)
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2056 {
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2057 gss_release_name (&t_minor, &svc_name);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2058 if (gss_context != GSS_C_NO_CONTEXT)
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2059 gss_delete_sec_context (&t_minor, &gss_context,
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2060 GSS_C_NO_BUFFER);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2061 sendline (server, "*");
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2062 strcpy (pop_error, b64_error[ret]);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2063 return (-1);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2064 }
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2065
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2066 /* send output token... */
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2067 ret = sendline (server, fromserver);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2068
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2069 free (fromserver);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2070 }
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2071 else
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2072 /* empty output token... */
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2073 ret = sendline (server, "");
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2074
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2075 /* get next token from server */
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2076 if (ret || (pop_getline (server, &fromserver) < 0))
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2077 {
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2078 gss_release_name (&t_minor, &svc_name);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2079 if (gss_context != GSS_C_NO_CONTEXT)
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2080 gss_delete_sec_context (&t_minor, &gss_context, GSS_C_NO_BUFFER);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2081 return (-1);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2082 }
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2083 } while ((major & GSS_S_CONTINUE_NEEDED));
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2084
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2085 /* release name... */
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2086 gss_release_name (&t_minor, &svc_name);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2087
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2088 /* get final response from server */
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2089 if (strncmp (fromserver, "+ ", 2))
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2090 {
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2091 gss_delete_sec_context (&t_minor, &gss_context, GSS_C_NO_BUFFER);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2092 if (0 == strncmp (fromserver, "-ERR", 4))
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2093 {
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2094 strncpy (pop_error, fromserver, ERROR_MAX);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2095 return (-1);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2096 }
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2097 else
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2098 {
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2099 pop_trash (server);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2100 strcpy (pop_error,
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2101 "Unexpected response from POP server in pop_auth");
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2102 return (-2);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2103 }
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2104 }
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2105
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2106 /* base 64 decode... */
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2107 ret = b64_decode (fromserver + 2, &in_tok);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2108 if (ret != B64_SUCCESS)
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2109 {
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2110 gss_delete_sec_context (&t_minor, &gss_context, GSS_C_NO_BUFFER);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2111 sendline (server, "*");
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2112 strcpy (pop_error, b64_error[ret]);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2113 return (-1);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2114 }
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2115
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2116 /* unwrap... */
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2117 major = gss_unwrap (&minor, gss_context, &in_tok, &out_tok, 0, 0);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2118
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2119 free ((char *) in_tok.value);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2120
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2121 if (major != GSS_S_COMPLETE || out_tok.length != sizeof (t_flags))
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2122 {
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2123 if (out_tok.length != 0)
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2124 gss_release_buffer (&t_minor, &out_tok);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2125 gss_delete_sec_context (&t_minor, &gss_context, GSS_C_NO_BUFFER);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2126 sendline (server, "*");
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2127 gen_gss_error ("in gss_unwrap", major, minor);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2128 return (-1);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2129 }
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2130
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2131 /* get and check flags/size */
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2132 bcopy ((void *) out_tok.value, (void *) &t_flags, sizeof (t_flags));
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2133
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2134 gss_release_buffer (&t_minor, &out_tok);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2135
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2136 max_size = ntohl (t_flags);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2137
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2138 t_flags = ((max_size & 0xFF000000) >> 24) & gss_flags;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2139 max_size &= 0x00FFFFFF;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2140
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2141 if ((t_flags & GSSAPI_PRIVACY))
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2142 gss_flags = GSSAPI_PRIVACY;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2143
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2144 else if ((t_flags & GSSAPI_INTEGRITY))
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2145 gss_flags = GSSAPI_INTEGRITY;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2146
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2147 else if ((t_flags & GSSAPI_NOPROT))
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2148 gss_flags = GSSAPI_NOPROT;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2149
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2150 else
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2151 {
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2152 gss_delete_sec_context (&t_minor, &gss_context, GSS_C_NO_BUFFER);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2153 sendline (server, "*");
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2154 strcpy (pop_error, "Server does not provide selected protection level");
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2155 return (-1);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2156 }
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2157
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2158 if (max_size == 0)
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2159 {
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2160 gss_delete_sec_context (&t_minor, &gss_context, GSS_C_NO_BUFFER);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2161 sendline (server, "*");
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2162 strcpy (pop_error, "Bad server max length");
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2163 return (-1);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2164 }
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2165
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2166 if ((gss_flags & GSSAPI_NEEDWRAP))
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2167 {
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2168 major = gss_wrap_size_limit (&t_minor, gss_context,
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2169 (gss_flags & GSSAPI_PRIVACY) ? 1 : 0,
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2170 GSS_C_QOP_DEFAULT,
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2171 (max_size < GSSAPI_RCVBUF) ? max_size :
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2172 GSSAPI_RCVBUF, &max_size);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2173 if (major != GSS_S_COMPLETE)
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2174 {
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2175 gss_delete_sec_context (&t_minor, &gss_context, GSS_C_NO_BUFFER);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2176 sendline (server, "*");
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2177 gen_gss_error ("getting max size", major, minor);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2178 return (-1);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2179 }
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2180 }
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2181
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2182 /* generate return flags */
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2183 {
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2184 OM_uint32 tmp;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2185
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2186 tmp = (((gss_flags << 24) & 0xFF000000) | (GSSAPI_RCVBUF & 0x00FFFFFF));
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2187 t_flags = ntohl (tmp);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2188 }
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2189
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2190 in_tok.length = sizeof (t_flags) + strlen (username);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2191 in_tok.value = (void *) malloc (in_tok.length);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2192
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2193 if (! in_tok.value)
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2194 {
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2195 gss_delete_sec_context (&t_minor, &gss_context, GSS_C_NO_BUFFER);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2196 sendline (server, "*");
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2197 strcpy (pop_error, "Out of memory in pop_auth");
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2198 return (-1);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2199 }
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2200
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2201 bcopy ((void *) &t_flags, in_tok.value, sizeof (t_flags));
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2202 bcopy ((void *) username,
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2203 (void *) (((char *) in_tok.value) + sizeof (t_flags)),
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2204 in_tok.length - sizeof (t_flags));
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2205
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2206 /* wrap result */
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2207 major = gss_wrap (&minor, gss_context, 0, GSS_C_QOP_DEFAULT,
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2208 &in_tok, 0, &out_tok);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2209
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2210 free ((char *) in_tok.value);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2211
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2212 if (major != GSS_S_COMPLETE || out_tok.length == 0)
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2213 {
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2214 if (out_tok.length != 0)
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2215 gss_release_buffer (&t_minor, &out_tok);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2216 gss_delete_sec_context (&t_minor, &gss_context, GSS_C_NO_BUFFER);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2217 sendline (server, "*");
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2218 gen_gss_error ("in gss_wrap", major, minor);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2219 return (-1);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2220 }
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2221
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2222 /* base 64 encode... */
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2223 ret = b64_encode (&out_tok, &fromserver);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2224
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2225 gss_release_buffer (&t_minor, &out_tok);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2226
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2227 if (ret != B64_SUCCESS)
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2228 {
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2229 gss_delete_sec_context (&t_minor, &gss_context, GSS_C_NO_BUFFER);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2230 sendline (server, "*");
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2231 strcpy (pop_error, b64_error[ret]);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2232 return (-1);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2233 }
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2234
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2235 /* send to server */
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2236 ret = sendline (server, fromserver);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2237
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2238 free (fromserver);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2239
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2240 /* see if the server likes me... */
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2241 if (ret || getok (server))
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2242 {
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2243 gss_delete_sec_context (&t_minor, &gss_context, GSS_C_NO_BUFFER);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2244 return (-1);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2245 }
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2246
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2247 /* stash context */
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2248 {
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2249 struct _pop_gssapi *gss_data;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2250
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2251 gss_data = (struct _pop_gssapi *) malloc (sizeof (struct _pop_gssapi));
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2252
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2253 if (! gss_data)
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2254 {
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2255 pop_trash (server);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2256 gss_delete_sec_context (&t_minor, &gss_context, GSS_C_NO_BUFFER);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2257 strcpy (pop_error, "Out of memory in pop_auth");
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2258 return (-2);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2259 }
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2260
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2261 gss_data->gss_flags = gss_flags;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2262 gss_data->max_size = max_size;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2263 gss_data->gss_context = gss_context;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2264
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2265 server->extra = gss_data;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2266 }
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2267
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2268 return (0);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2269 }
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2270
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2271 /*
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2272 * Add as much error text to pop_error as will fit, but only put complete
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2273 * messages
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2274 */
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2275 static void
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2276 gen_gss_error (msg, major, minor)
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2277 char *msg;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2278 OM_uint32 major, minor;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2279 {
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2280 char *p = pop_error, *t, *saved;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2281 int max = ERROR_MAX - 1; /* for \0 */
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2282 OM_uint32 t_minor, msg_ctx = 0;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2283 gss_buffer_desc gss_msg;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2284
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2285 while (*msg && max)
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2286 {
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2287 *p++ = *msg++;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2288 max--;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2289 }
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2290
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2291 if (max >= 2)
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2292 {
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2293 saved = p;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2294 *p++ = ':';
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2295 *p++ = ' ';
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2296 max -= 2;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2297 }
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2298 else
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2299 {
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2300 *p = '\0';
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2301 return;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2302 }
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2303
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2304 do
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2305 {
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2306 gss_display_status (&t_minor, major, GSS_C_GSS_CODE, GSS_C_NO_OID,
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2307 &msg_ctx, &gss_msg);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2308 for (t = (char *) gss_msg.value; *t && max; max--)
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2309 {
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2310 *p++ = *t++;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2311 }
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2312 gss_release_buffer (&t_minor, &gss_msg);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2313 if (max == 0)
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2314 {
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2315 *saved = '\0';
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2316 return;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2317 }
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2318 } while (msg_ctx);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2319
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2320 saved = p;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2321
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2322 do
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2323 {
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2324 gss_display_status (&t_minor, minor, GSS_C_MECH_CODE, GSS_C_NO_OID,
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2325 &msg_ctx, &gss_msg);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2326 for (t = (char *) gss_msg.value; *t && max; max--)
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2327 {
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2328 *p++ = *t++;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2329 }
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2330 gss_release_buffer (&t_minor, &gss_msg);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2331 if (max == 0)
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2332 {
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2333 *saved = '\0';
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2334 return;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2335 }
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2336 } while (msg_ctx);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2337
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2338 *p = '\0';
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2339 return;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2340 }
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2341
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2342 /*
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2343 * table-based base64 decoding function; takes 4 characters from in and
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2344 * writes from 1 to 3 bytes to out, storing the amount written in len
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2345 */
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2346 static int
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2347 b64_d (in, out, len)
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2348 char *in, *out;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2349 int *len;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2350 {
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2351 int decodearray[] =
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2352 {
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2353 0x3e, -1, -1, -1, 0x3f, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a,
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2354 0x3b, 0x3c, 0x3d, -1, -1, -1, -1, -1, -1, -1, 0x00, 0x01,
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2355 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d,
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2356 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19,
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2357 -1, -1, -1, -1, -1, -1, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2358 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b,
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2359 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2360 };
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2361
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2362 int d;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2363
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2364 if (!in || !out || !len)
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2365 return (B64_BADPARAM);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2366
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2367 if (*in < '+' || *in > 'z')
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2368 return (B64_BADCHAR);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2369
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2370 d = decodearray[*(in++) - '+'];
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2371 if (d == -1)
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2372 return (B64_BADCHAR);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2373 *out = d << 2;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2374
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2375 if (*in < '+' || *in > 'z')
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2376 return (B64_BADCHAR);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2377
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2378 d = decodearray[*(in++) - '+'];
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2379 if (d == -1)
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2380 return (B64_BADCHAR);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2381 *(out++) |= d >> 4;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2382 *out = (d & 15) << 4;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2383
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2384 if (*in < '+' || *in > 'z')
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2385 return (B64_BADCHAR);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2386 else if (*in == '=')
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2387 if (*(in + 1) != '=')
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2388 return (B64_BADPAD);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2389 else
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2390 {
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2391 *len = 1;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2392 return (B64_SUCCESS);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2393 }
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2394
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2395 d = decodearray[*(in++) - '+'];
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2396 if (d == -1)
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2397 return (B64_BADCHAR);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2398 *(out++) |= d >> 2;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2399 *out = (d & 3) << 6;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2400
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2401 if (*in < '+' || *in > 'z')
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2402 return (B64_BADCHAR);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2403 else if (*in == '=')
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2404 {
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2405 *len = 2;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2406 return (B64_SUCCESS);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2407 }
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2408
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2409 d = decodearray[*in - '+'];
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2410 if (d == -1)
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2411 return (B64_BADCHAR);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2412 *out |= d;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2413
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2414 *len = 3;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2415 return (B64_SUCCESS);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2416 }
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2417
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2418 /*
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2419 * simple base64 encoding function that takes from 0 to 3 bytes and
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2420 * outputs 4 encoded characters, with appropriate padding
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2421 */
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2422 static int
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2423 b64_e (in, out, len)
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2424 unsigned char *in, *out;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2425 int len;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2426 {
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2427 unsigned char codearray[] =
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2428 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2429
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2430 if (!in || !out || len <= 0 || len > 3)
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2431 return (B64_BADPARAM);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2432
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2433 *(out++) = codearray[((*in) >> 2)];
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2434
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2435 if (--len == 0)
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2436 {
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2437 *(out++) = codearray[(((*in) & 3) << 4)];
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2438 *(out++) = '=';
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2439 *out = '=';
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2440 return (B64_SUCCESS);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2441 }
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2442
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2443 *(out++) = codearray[(((*in) & 3) << 4) | ((*(in + 1)) >> 4)];
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2444 in++;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2445
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2446 if (--len == 0)
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2447 {
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2448 *(out++) = codearray[(((*in) & 15) << 2)];
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2449 *out = '=';
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2450 return (B64_SUCCESS);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2451 }
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2452
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2453 *(out++) = codearray[(((*in) & 15) << 2) | ((*(in + 1)) >> 6)];
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2454 *out = codearray[((*(in + 1)) & 63)];
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2455
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2456 return (B64_SUCCESS);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2457 }
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2458
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2459 /*
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2460 * given an input string, generate an output gss_buffer_t containing the
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2461 * decoded data and correct length; works by repeatedly driving b64_d ()
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2462 * over the input string
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2463 */
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2464 static int
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2465 b64_decode (enc, dec)
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2466 char *enc;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2467 gss_buffer_t dec;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2468 {
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2469 char *tmp;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2470 int inlen, outlen = 0, t_len, ret;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2471
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2472 if (!enc || !dec)
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2473 return (B64_BADPARAM);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2474
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2475 dec->value = 0;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2476 dec->length = 0;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2477
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2478 inlen = strlen (enc);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2479 if ((inlen % 4))
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2480 return (B64_BADLEN);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2481
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2482 dec->value = (void *) (tmp = (char *) malloc ((inlen / 4) * 3));
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2483
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2484 if (! tmp)
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2485 return (B64_NOMEM);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2486
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2487 for (; inlen; inlen -= 4)
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2488 {
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2489 ret = b64_d (enc, tmp, &t_len);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2490 if (ret != B64_SUCCESS)
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2491 {
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2492 free ((char *) dec->value);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2493 dec->value = 0;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2494 return (ret);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2495 }
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2496 else if (t_len != 3)
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2497 {
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2498 dec->length = outlen + t_len;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2499 return (B64_SUCCESS);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2500 }
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2501 else
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2502 {
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2503 enc += 4;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2504 tmp += t_len;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2505 outlen += t_len;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2506 }
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2507 }
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2508
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2509 dec->length = outlen;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2510 return (B64_SUCCESS);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2511 }
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2512
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2513 /*
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2514 * given a gss_buffer_t, generate an encoded string containing the data.
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2515 * works by repeatedly driving b64_e () over the contents of the buffer_t
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2516 */
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2517 static int
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2518 b64_encode (dec, enc)
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2519 gss_buffer_t dec;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2520 char **enc;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2521 {
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2522 unsigned char *tmp, *in;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2523 int ret, len;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2524
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2525 if (!dec || !enc)
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2526 return (B64_BADPARAM);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2527
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2528 in = (unsigned char *) dec->value;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2529 len = dec->length;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2530 *enc = (char *) (tmp = (unsigned char *) malloc (((len * 4) / 3) + 5));
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2531
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2532 if (! tmp)
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2533 return (B64_NOMEM);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2534
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2535 do
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2536 {
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2537 ret = b64_e (in, tmp, len >= 3 ? 3 : len);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2538 if (ret != B64_SUCCESS)
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2539 {
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2540 free (*enc);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2541 *enc = 0;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2542 return (ret);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2543 }
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2544 else
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2545 {
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2546 in += 3;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2547 tmp += 4;
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2548 }
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2549 } while ((len -= 3) > 0);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2550
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2551 *tmp = '\0';
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2552
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2553 return (B64_SUCCESS);
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2554 }
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2555
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2556 #endif /* GSSAPI */
aa5d46f74b6a Integrate support for GSS-API
Karl Heuer <kwzh@gnu.org>
parents: 21295
diff changeset
2557
20418
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
2558 /* Return a pointer to the first CRLF in IN_STRING, which can contain
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
2559 embedded nulls and has LEN characters in it not including the final
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
2560 null, or 0 if it does not contain one. */
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2561
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2562 static char *
20418
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
2563 find_crlf (in_string, len)
9613
530b4511e5b3 Only include ../src/config.h if HAVE_CONFIG_H is
Richard M. Stallman <rms@gnu.org>
parents: 9600
diff changeset
2564 char *in_string;
20418
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
2565 int len;
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2566 {
20418
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
2567 while (len--)
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2568 {
20418
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
2569 if (*in_string == '\r')
9613
530b4511e5b3 Only include ../src/config.h if HAVE_CONFIG_H is
Richard M. Stallman <rms@gnu.org>
parents: 9600
diff changeset
2570 {
530b4511e5b3 Only include ../src/config.h if HAVE_CONFIG_H is
Richard M. Stallman <rms@gnu.org>
parents: 9600
diff changeset
2571 if (*++in_string == '\n')
530b4511e5b3 Only include ../src/config.h if HAVE_CONFIG_H is
Richard M. Stallman <rms@gnu.org>
parents: 9600
diff changeset
2572 return (in_string - 1);
530b4511e5b3 Only include ../src/config.h if HAVE_CONFIG_H is
Richard M. Stallman <rms@gnu.org>
parents: 9600
diff changeset
2573 }
530b4511e5b3 Only include ../src/config.h if HAVE_CONFIG_H is
Richard M. Stallman <rms@gnu.org>
parents: 9600
diff changeset
2574 else
530b4511e5b3 Only include ../src/config.h if HAVE_CONFIG_H is
Richard M. Stallman <rms@gnu.org>
parents: 9600
diff changeset
2575 in_string++;
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2576 }
20418
7e1538a45702 Allow messages retrieved from the POP
Karl Heuer <kwzh@gnu.org>
parents: 20204
diff changeset
2577 return (0);
9158
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2578 }
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2579
939488de5d3f Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2580 #endif /* MAIL_USE_POP */