annotate lib-src/movemail.c @ 84:ac0620f6398e r20-0b92

Import from CVS: tag r20-0b92
author cvs
date Mon, 13 Aug 2007 09:08:29 +0200
parents 131b0175ea99
children 7d55a9ba150c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 /* movemail foo bar -- move file foo to file bar,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 locking file foo the way /bin/mail respects.
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
3 Copyright (C) 1986, 1992, 1993, 1994 Free Software Foundation, Inc.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 This file is part of GNU Emacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 GNU Emacs is free software; you can redistribute it and/or modify
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 it under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 GNU Emacs is distributed in the hope that it will be useful,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 GNU General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 along with GNU Emacs; see the file COPYING. If not, write to
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
19 the Free the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 Boston, MA 02111-1307, USA. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
22 /* Synched up with: FSF 19.28. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
23
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 /* Important notice: defining MAIL_USE_FLOCK or MAIL_USE_LOCKF *will
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 cause loss of mail* if you do it on a system that does not normally
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 use flock as its way of interlocking access to inbox files. The
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 setting of MAIL_USE_FLOCK and MAIL_USE_LOCKF *must agree* with the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 system's own conventions. It is not a choice that is up to you.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 So, if your system uses lock files rather than flock, then the only way
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 you can get proper operation is to enable movemail to write lockfiles there.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 This means you must either give that directory access modes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 that permit everyone to write lockfiles in it, or you must make movemail
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 a setuid or setgid program. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 * Modified January, 1986 by Michael R. Gretzinger (Project Athena)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 *
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
39 * Added POP (Post Office Protocol) service. When compiled -DPOP
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 * movemail will accept input filename arguments of the form
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 * "po:username". This will cause movemail to open a connection to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 * a pop server running on $MAILHOST (environment variable). Movemail
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 * must be setuid to root in order to work with POP.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 * New module: popmail.c
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 * Modified routines:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 * main - added code within #ifdef MAIL_USE_POP; added setuid (getuid ())
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 * after POP code.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 * New routines in movemail.c:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 * get_errmsg - return pointer to system error message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 #define NO_SHORTNAMES /* Tell config not to load remap.h */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 #include <../src/config.h>
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
56 #include <stdlib.h>
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
57 #include <unistd.h>
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
58 #include <time.h> /* for time() */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
59 #include <stdio.h> /* for printf() */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
60 #include <string.h> /* strcpy() */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
61
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 #include <sys/types.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 #include <sys/stat.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 #include <sys/file.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 #include <errno.h>
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
66 #include <../src/syswait.h>
54
05472e90ae02 Import from CVS: tag r19-16-pre2
cvs
parents: 48
diff changeset
67
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 #ifdef MSDOS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 #undef access
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 #endif /* MSDOS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
72 #ifdef USG
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
73 #include <fcntl.h>
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 #include <unistd.h>
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
75 #if defined (sun)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
76 #include <stdlib.h>
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
77 #endif /* sun */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 #ifndef F_OK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 #define F_OK 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 #define X_OK 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 #define W_OK 2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 #define R_OK 4
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
83 #endif
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
84 #endif /* USG */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
86 #ifdef HAVE_UNISTD_H
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
87 #include <unistd.h>
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
88 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
90 #ifdef XENIX
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 #include <sys/locking.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 #ifdef MAIL_USE_LOCKF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 #define MAIL_USE_SYSTEM_LOCK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 #ifdef MAIL_USE_FLOCK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 #define MAIL_USE_SYSTEM_LOCK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 #ifdef MAIL_USE_MMDF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 extern int lk_open (), lk_close ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 /* Cancel substitutions made by config.h for Emacs. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 #undef open
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 #undef read
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 #undef write
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 #undef close
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
112 static char *concat (CONST char *s1, CONST char *s2, CONST char *s3);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
113 static void *xmalloc (unsigned int size);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
114 #ifndef errno
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
115 extern int errno;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 #endif
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
117
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
118 static void error (CONST char *s1, CONST char *s2, CONST char *s3);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
119 static void fatal (CONST char *s1, CONST char *s2);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
120 static void pfatal_with_name (CONST char *name);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
121 static void pfatal_and_delete (CONST char *name);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
122
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
123 #ifndef HAVE_STRERROR
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
124 char *strerror (int);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
125 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 /* Nonzero means this is name of a lock file to delete on fatal error. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 char *delete_lockname;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
130 void
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
131 main (argc, argv)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
132 int argc;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
133 char **argv;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 char *inname, *outname;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 int indesc, outdesc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 int nread;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
138 WAITTYPE status;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 #ifndef MAIL_USE_SYSTEM_LOCK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 struct stat st;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 long now;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 int tem;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 char *lockname, *p;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 char *tempname;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 int desc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 #endif /* not MAIL_USE_SYSTEM_LOCK */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 delete_lockname = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 if (argc < 3)
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
152 fatal ("two arguments required", "");
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 inname = argv[1];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 outname = argv[2];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 #ifdef MAIL_USE_MMDF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 mmdf_init (argv[0]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 /* Check access to output file. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 if (access (outname, F_OK) == 0 && access (outname, W_OK) != 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 pfatal_with_name (outname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
165 /* Also check that outname's directory is writeable to the real uid. */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 char *buf = (char *) xmalloc (strlen (outname) + 1);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
168 char *p;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 strcpy (buf, outname);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
170 p = buf + strlen (buf);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
171 while (p > buf && p[-1] != '/')
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
172 *--p = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
173 if (p == buf)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
174 *p++ = '.';
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 if (access (buf, W_OK) != 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 pfatal_with_name (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 free (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 #ifdef MAIL_USE_POP
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
181 if (!memcmp (inname, "po:", 3))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 {
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
183 int status; char *user;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
185 for (user = &inname[strlen (inname) - 1]; user >= inname; user--)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
186 if (*user == ':')
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
187 break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
188
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
189 status = popmail (user, outname);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 exit (status);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 setuid (getuid ());
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 #endif /* MAIL_USE_POP */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 /* Check access to input file. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 if (access (inname, R_OK | W_OK) != 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 pfatal_with_name (inname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 #ifndef MAIL_USE_MMDF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 #ifndef MAIL_USE_SYSTEM_LOCK
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
202 /* Use a lock file named /usr/spool/mail/$USER.lock:
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 If it exists, the mail file is locked. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 /* Note: this locking mechanism is *required* by the mailer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 (on systems which use it) to prevent loss of mail.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 On systems that use a lock file, extracting the mail without locking
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 WILL occasionally cause loss of mail due to timing errors!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 So, if creation of the lock file fails
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
211 due to access permission on /usr/spool/mail,
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 you simply MUST change the permission
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 and/or make movemail a setgid program
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 so it can create lock files properly.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 You might also wish to verify that your system is one
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 which uses lock files for this purpose. Some systems use other methods.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 If your system uses the `flock' system call for mail locking,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 define MAIL_USE_SYSTEM_LOCK in config.h or the s-*.h file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 and recompile movemail. If the s- file for your system
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 should define MAIL_USE_SYSTEM_LOCK but does not, send a bug report
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 to bug-gnu-emacs@prep.ai.mit.edu so we can fix it. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 lockname = concat (inname, ".lock", "");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 tempname = (char *) xmalloc (strlen (inname) + strlen ("EXXXXXX") + 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 strcpy (tempname, inname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 p = tempname + strlen (tempname);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
229 while (p != tempname && p[-1] != '/')
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 p--;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 *p = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 strcpy (p, "EXXXXXX");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 mktemp (tempname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 unlink (tempname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 while (1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 /* Create the lock file, but not under the lock file name. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 /* Give up if cannot do that. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 desc = open (tempname, O_WRONLY | O_CREAT | O_EXCL, 0666);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 if (desc < 0)
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
242 pfatal_with_name ("lock file--see source file lib-src/movemail.c");
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 close (desc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 tem = link (tempname, lockname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 unlink (tempname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 if (tem >= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 sleep (1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
251 /* If lock file is a minute old, unlock it. */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 if (stat (lockname, &st) >= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 now = time (0);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
255 if (st.st_ctime < now - 60)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
256 unlink (lockname);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 delete_lockname = lockname;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 #endif /* not MAIL_USE_SYSTEM_LOCK */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 #endif /* not MAIL_USE_MMDF */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 if (fork () == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 setuid (getuid ());
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 #ifndef MAIL_USE_MMDF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 #ifdef MAIL_USE_SYSTEM_LOCK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 indesc = open (inname, O_RDWR);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 #else /* if not MAIL_USE_SYSTEM_LOCK */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 indesc = open (inname, O_RDONLY);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 #endif /* not MAIL_USE_SYSTEM_LOCK */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 #else /* MAIL_USE_MMDF */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 indesc = lk_open (inname, O_RDONLY, 0, 0, 10);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 #endif /* MAIL_USE_MMDF */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 if (indesc < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 pfatal_with_name (inname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 #if defined (BSD) || defined (XENIX)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 /* In case movemail is setuid to root, make sure the user can
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 read the output file. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 /* This is desirable for all systems
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 but I don't want to assume all have the umask system call */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 umask (umask (0) & 0333);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 #endif /* BSD or Xenix */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 outdesc = open (outname, O_WRONLY | O_CREAT | O_EXCL, 0666);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 if (outdesc < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 pfatal_with_name (outname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 #ifdef MAIL_USE_SYSTEM_LOCK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 #ifdef MAIL_USE_LOCKF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 if (lockf (indesc, F_LOCK, 0) < 0) pfatal_with_name (inname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 #else /* not MAIL_USE_LOCKF */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 #ifdef XENIX
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 if (locking (indesc, LK_RLCK, 0L) < 0) pfatal_with_name (inname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 if (flock (indesc, LOCK_EX) < 0) pfatal_with_name (inname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 #endif /* not MAIL_USE_LOCKF */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 #endif /* MAIL_USE_SYSTEM_LOCK */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 char buf[1024];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 while (1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 nread = read (indesc, buf, sizeof buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 if (nread != write (outdesc, buf, nread))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 int saved_errno = errno;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 unlink (outname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 errno = saved_errno;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 pfatal_with_name (outname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 if (nread < sizeof buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 #ifdef BSD
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 if (fsync (outdesc) < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 pfatal_and_delete (outname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 /* Check to make sure no errors before we zap the inbox. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 if (close (outdesc) != 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 pfatal_and_delete (outname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 #ifdef MAIL_USE_SYSTEM_LOCK
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
331 #if defined (STRIDE) || defined (XENIX)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 /* Stride, xenix have file locking, but no ftruncate. This mess will do. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 close (open (inname, O_CREAT | O_TRUNC | O_RDWR, 0666));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 ftruncate (indesc, 0L);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 #endif /* STRIDE or XENIX */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 #endif /* MAIL_USE_SYSTEM_LOCK */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 #ifdef MAIL_USE_MMDF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 lk_close (indesc, 0, 0, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 close (indesc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 #ifndef MAIL_USE_SYSTEM_LOCK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 /* Delete the input file; if we can't, at least get rid of its
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 contents. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 #ifdef MAIL_UNLINK_SPOOL
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 /* This is generally bad to do, because it destroys the permissions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 that were set on the file. Better to just empty the file. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 if (unlink (inname) < 0 && errno != ENOENT)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 #endif /* MAIL_UNLINK_SPOOL */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 creat (inname, 0600);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 #endif /* not MAIL_USE_SYSTEM_LOCK */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 exit (0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 wait (&status);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 if (!WIFEXITED (status))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 exit (1);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
362 else if (WRETCODE (status) != 0)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
363 exit (WRETCODE (status));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 #if !defined (MAIL_USE_MMDF) && !defined (MAIL_USE_SYSTEM_LOCK)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 unlink (lockname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 #endif /* not MAIL_USE_MMDF and not MAIL_USE_SYSTEM_LOCK */
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
368 exit (0);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 /* Print error message and exit. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372
54
05472e90ae02 Import from CVS: tag r19-16-pre2
cvs
parents: 48
diff changeset
373 static void
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
374 fatal (s1, s2)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
375 CONST char *s1, *s2;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 if (delete_lockname)
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
378 error (s1, s2, "");
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 unlink (delete_lockname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 exit (1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 /* Print error message. `s1' is printf control string, `s2' is arg for it. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384
54
05472e90ae02 Import from CVS: tag r19-16-pre2
cvs
parents: 48
diff changeset
385 static void
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
386 error (s1, s2, s3)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
387 CONST char *s1, *s2, *s3;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 {
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
389 printf ("movemail: ");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
390 printf (s1, s2, s3);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
391 printf ("\n");
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393
54
05472e90ae02 Import from CVS: tag r19-16-pre2
cvs
parents: 48
diff changeset
394 static void
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
395 pfatal_with_name (name)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
396 CONST char *name;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 {
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
398 char *s;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
399
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
400 s = concat ("", strerror (errno), " for %s");
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 fatal (s, name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403
54
05472e90ae02 Import from CVS: tag r19-16-pre2
cvs
parents: 48
diff changeset
404 static void
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
405 pfatal_and_delete (name)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
406 CONST char *name;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 {
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
408 char *s;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
409
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
410 s = concat ("", strerror (errno), " for %s");
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 unlink (name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 fatal (s, name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 /* Return a newly-allocated string whose contents concatenate those of s1, s2, s3. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416
54
05472e90ae02 Import from CVS: tag r19-16-pre2
cvs
parents: 48
diff changeset
417 static char *
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
418 concat (s1, s2, s3)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
419 CONST char *s1, *s2, *s3;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 int len1 = strlen (s1), len2 = strlen (s2), len3 = strlen (s3);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 char *result = (char *) xmalloc (len1 + len2 + len3 + 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 strcpy (result, s1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 strcpy (result + len1, s2);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 strcpy (result + len1 + len2, s3);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 *(result + len1 + len2 + len3) = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 return result;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 /* Like malloc but get fatal error if memory is exhausted. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
434 static void *
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
435 xmalloc (size)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
436 unsigned int size;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 {
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
438 void *result = (void *) malloc (size);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 if (!result)
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
440 fatal ("virtual memory exhausted", (char *) 0);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 return result;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 /* This is the guts of the interface to the Post Office Protocol. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 #ifdef MAIL_USE_POP
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 #include <sys/socket.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 #include <netinet/in.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 #include <netdb.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 #include <stdio.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 #include <pwd.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
454 #ifdef USG
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
455 #include <fcntl.h>
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
456 /* Cancel substitutions made by config.h for Emacs. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
457 #undef open
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
458 #undef read
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
459 #undef write
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
460 #undef close
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
461 #endif /* USG */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
462
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 #define NOTOK (-1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 #define OK 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 #define DONE 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 char *progname;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 FILE *sfi;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 FILE *sfo;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 char Errmsg[80];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
472 static int debug = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
473
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
474 char *get_errmsg ();
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
475 char *getenv ();
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
476 int mbx_write ();
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
477
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
478 int
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
479 popmail (user, outfile)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
480 char *user;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
481 char *outfile;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 {
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
483 char *host;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 int nmsgs, nbytes;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
485 char response[128];
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 register int i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 int mbfi;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 FILE *mbf;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
489 struct passwd *pw = (struct passwd *) getpwuid (getuid ());
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
490 if (pw == NULL)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
491 fatal ("cannot determine user name");
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
493 host = getenv ("MAILHOST");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
494 if (host == NULL)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 {
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
496 fatal ("no MAILHOST defined");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
497 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
498
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
499 if (pop_init (host) == NOTOK)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
500 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
501 fatal (Errmsg);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
504 if (getline (response, sizeof response, sfi) != OK)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
505 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
506 fatal (response);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
507 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
508
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
509 if (pop_command ("USER %s", user) == NOTOK
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
510 || pop_command ("RPOP %s", pw->pw_name) == NOTOK)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 {
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
512 pop_command ("QUIT");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
513 fatal (Errmsg);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
514 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
515
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
516 if (pop_stat (&nmsgs, &nbytes) == NOTOK)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
517 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
518 pop_command ("QUIT");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
519 fatal (Errmsg);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 if (!nmsgs)
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
523 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
524 pop_command ("QUIT");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
525 return 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
526 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 mbfi = open (outfile, O_WRONLY | O_CREAT | O_EXCL, 0666);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 if (mbfi < 0)
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
530 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
531 pop_command ("QUIT");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
532 pfatal_and_delete (outfile);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
533 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 fchown (mbfi, getuid (), -1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
536 if ((mbf = fdopen (mbfi, "w")) == NULL)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 {
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
538 pop_command ("QUIT");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
539 pfatal_and_delete (outfile);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
542 for (i = 1; i <= nmsgs; i++)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 mbx_delimit_begin (mbf);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
545 if (pop_retr (i, mbx_write, mbf) != OK)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
546 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
547 pop_command ("QUIT");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
548 close (mbfi);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
549 unlink (outfile);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
550 fatal (Errmsg);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
551 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 mbx_delimit_end (mbf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 fflush (mbf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 if (fsync (mbfi) < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 {
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
558 pop_command ("QUIT");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
559 pfatal_and_delete (outfile);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562 if (close (mbfi) == -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563 {
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
564 pop_command ("QUIT");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
565 pfatal_and_delete (outfile);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
568 for (i = 1; i <= nmsgs; i++)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 {
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
570 if (pop_command ("DELE %d", i) == NOTOK)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
571 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
572 /* Better to ignore this failure. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
573 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
576 pop_command ("QUIT");
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577 return (0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
580 int
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
581 pop_init (host)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
582 char *host;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 {
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
584 register struct hostent *hp;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
585 register struct servent *sp;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
586 int lport = IPPORT_RESERVED - 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
587 struct sockaddr_in sin;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
588 register int s;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
589
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
590 hp = gethostbyname (host);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
591 if (hp == NULL)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
592 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
593 sprintf (Errmsg, "MAILHOST unknown: %s", host);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
594 return NOTOK;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
595 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
596
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
597 sp = getservbyname ("pop", "tcp");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
598 if (sp == 0)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
599 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
600 strcpy (Errmsg, "tcp/pop: unknown service");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
601 return NOTOK;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
602 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
604 sin.sin_family = hp->h_addrtype;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
605 memcpy ((char *)&sin.sin_addr, hp->h_addr, hp->h_length);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
606 sin.sin_port = sp->s_port;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
607 s = rresvport (&lport);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
608 if (s < 0)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
609 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
610 sprintf (Errmsg, "error creating socket: %s", get_errmsg ());
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
611 return NOTOK;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
612 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
613
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
614 if (connect (s, (char *)&sin, sizeof sin) < 0)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 {
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
616 sprintf (Errmsg, "error during connect: %s", get_errmsg ());
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
617 close (s);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
618 return NOTOK;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
619 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
620
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
621 sfi = fdopen (s, "r");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
622 sfo = fdopen (s, "w");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
623 if (sfi == NULL || sfo == NULL)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
624 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
625 sprintf (Errmsg, "error in fdopen: %s", get_errmsg ());
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
626 close (s);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
627 return NOTOK;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
630 return OK;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
631 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
632
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
633 int
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
634 pop_command (fmt, a, b, c, d)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
635 char *fmt;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
636 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
637 char buf[128];
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
638 char errmsg[64];
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
640 sprintf (buf, fmt, a, b, c, d);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
641
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
642 if (debug) fprintf (stderr, "---> %s\n", buf);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
643 if (putline (buf, Errmsg, sfo) == NOTOK) return NOTOK;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
644
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
645 if (getline (buf, sizeof buf, sfi) != OK)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
646 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
647 strcpy (Errmsg, buf);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
648 return NOTOK;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
651 if (debug) fprintf (stderr, "<--- %s\n", buf);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
652 if (*buf != '+')
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
653 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
654 strcpy (Errmsg, buf);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
655 return NOTOK;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
656 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
657 else
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658 {
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
659 return OK;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
660 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
661 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
662
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
663
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
664 pop_stat (nmsgs, nbytes)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
665 int *nmsgs, *nbytes;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
666 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
667 char buf[128];
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
668
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
669 if (debug) fprintf (stderr, "---> STAT\n");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
670 if (putline ("STAT", Errmsg, sfo) == NOTOK)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
671 return NOTOK;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
672
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
673 if (getline (buf, sizeof buf, sfi) != OK)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
674 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
675 strcpy (Errmsg, buf);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
676 return NOTOK;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
677 }
48
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
678
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
679 if (debug) fprintf (stderr, "<--- %s\n", buf);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
680 if (*buf != '+')
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
681 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
682 strcpy (Errmsg, buf);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
683 return NOTOK;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
684 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
685 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
686 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
687 sscanf (buf, "+OK %d %d", nmsgs, nbytes);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
688 return OK;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
689 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
690 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
691
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
692 pop_retr (msgno, action, arg)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
693 int (*action)();
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
694 {
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
695 char buf[128];
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
696
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
697 sprintf (buf, "RETR %d", msgno);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
698 if (debug) fprintf (stderr, "%s\n", buf);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
699 if (putline (buf, Errmsg, sfo) == NOTOK) return NOTOK;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
700
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
701 if (getline (buf, sizeof buf, sfi) != OK)
48
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
702 {
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
703 strcpy (Errmsg, buf);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
704 return NOTOK;
48
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 0
diff changeset
705 }
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
706
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
707 while (1)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
708 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
709 switch (multiline (buf, sizeof buf, sfi))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
710 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
711 case OK:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
712 (*action)(buf, arg);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
713 break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
714 case DONE:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
715 return OK;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
716 case NOTOK:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
717 strcpy (Errmsg, buf);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
718 return NOTOK;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
719 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
720 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
721 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
722
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
723 getline (buf, n, f)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
724 char *buf;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
725 register int n;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
726 FILE *f;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
727 {
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
728 register char *p;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
729 int c;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
730
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
731 p = buf;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
732 while (--n > 0 && (c = fgetc (f)) != EOF)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
733 if ((*p++ = c) == '\n') break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
734
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
735 if (ferror (f))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
736 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
737 strcpy (buf, "error on connection");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
738 return NOTOK;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
739 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
740
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
741 if (c == EOF && p == buf)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
742 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
743 strcpy (buf, "connection closed by foreign host");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
744 return DONE;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
745 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
746
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
747 *p = NULL;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
748 if (*--p == '\n') *p = NULL;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
749 if (*--p == '\r') *p = NULL;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
750 return OK;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
751 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
752
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
753 multiline (buf, n, f)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
754 char *buf;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
755 register int n;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
756 FILE *f;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
757 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
758 if (getline (buf, n, f) != OK) return NOTOK;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
759 if (*buf == '.')
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
760 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
761 if (*(buf+1) == NULL)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
762 return DONE;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
763 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
764 strcpy (buf, buf+1);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
765 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
766 return OK;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
767 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
768
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
769 char *
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
770 get_errmsg ()
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
771 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
772 return strerror (errno);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
773 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
774
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
775 putline (buf, err, f)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
776 char *buf;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
777 char *err;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
778 FILE *f;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
779 {
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
780 fprintf (f, "%s\r\n", buf);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
781 fflush (f);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
782 if (ferror (f))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
783 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
784 strcpy (err, "lost connection");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
785 return NOTOK;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
786 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
787 return OK;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
788 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
789
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
790 mbx_write (line, mbf)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
791 char *line;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
792 FILE *mbf;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
793 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
794 fputs (line, mbf);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
795 fputc (0x0a, mbf);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
796 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
797
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
798 mbx_delimit_begin (mbf)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
799 FILE *mbf;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
800 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
801 fputs ("\f\n0, unseen,,\n", mbf);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
802 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
803
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
804 mbx_delimit_end (mbf)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
805 FILE *mbf;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
806 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
807 putc ('\037', mbf);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
808 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
809
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
810 #endif /* MAIL_USE_POP */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
811
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
812 #ifndef HAVE_STRERROR
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
813 char *
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
814 strerror (errnum)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
815 int errnum;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
816 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
817 extern char *sys_errlist[];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
818 extern int sys_nerr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
819
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
820 if (errnum >= 0 && errnum < sys_nerr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
821 return sys_errlist[errnum];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
822 return (char *) "Unknown error";
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
823 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
824
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
825 #endif /* ! HAVE_STRERROR */