No empty .Rs/.Re
[netbsd-mini2440.git] / crypto / dist / heimdal / appl / popper / popper.h
blob3e18e91499bfba0d3dcdae219be4fd3cfd5e4a29
1 /*
2 * Copyright (c) 1989 Regents of the University of California.
3 * All rights reserved. The Berkeley software License Agreement
4 * specifies the terms and conditions for redistribution.
6 * static char copyright[] = "Copyright (c) 1990 Regents of the University of California.\nAll rights reserved.\n";
7 * static char SccsId[] = "@(#)@(#)popper.h 2.2 2.2 4/2/91";
9 */
11 /* $Heimdal: popper.h 14045 2004-07-14 09:10:30Z joda $
12 $NetBSD$ */
14 /*
15 * Header file for the POP programs
18 #ifdef HAVE_CONFIG_H
19 #include <config.h>
20 #define UIDL
21 #define XOVER
22 #define XDELE
23 #define DEBUG
24 #define RETURN_PATH_HANDLING
25 #endif
27 /* Common include files */
29 #include <stdio.h>
30 #include <stdarg.h>
31 #include <stdlib.h>
32 #include <string.h>
33 #include <errno.h>
34 #include <signal.h>
35 #include <setjmp.h>
36 #include <ctype.h>
37 #ifdef HAVE_FCNTL_H
38 #include <fcntl.h>
39 #endif
40 #ifdef HAVE_PWD_H
41 #include <pwd.h>
42 #endif
43 #ifdef HAVE_SYS_TYPES_H
44 #include <sys/types.h>
45 #endif
46 #ifdef HAVE_IO_H
47 #include <io.h>
48 #endif
49 #ifdef HAVE_UNISTD_H
50 #include <unistd.h>
51 #endif
52 #ifdef HAVE_SYS_STAT_H
53 #include <sys/stat.h>
54 #endif
55 #ifdef HAVE_SYS_FILE_H
56 #include <sys/file.h>
57 #endif
58 #ifdef TIME_WITH_SYS_TIME
59 #include <sys/time.h>
60 #include <time.h>
61 #elif defined(HAVE_SYS_TIME_H)
62 #include <sys/time.h>
63 #else
64 #include <time.h>
65 #endif
66 #ifdef HAVE_SYS_RESOURCE_H
67 #include <sys/resource.h>
68 #endif
69 #ifdef HAVE_SYS_WAIT_H
70 #include <sys/wait.h>
71 #endif
72 #ifdef HAVE_SYS_SOCKET_H
73 #include <sys/socket.h>
74 #endif
75 #ifdef HAVE_NETINET_IN_H
76 #include <netinet/in.h>
77 #endif
78 #ifdef HAVE_NETINET_IN6_H
79 #include <netinet/in6.h>
80 #endif
81 #ifdef HAVE_NETINET6_IN6_H
82 #include <netinet6/in6.h>
83 #endif
85 #ifdef HAVE_NETDB_H
86 #include <netdb.h>
87 #endif
88 #ifdef HAVE_ARPA_INET_H
89 #ifdef _AIX
90 struct sockaddr_dl; /* AIX fun */
91 struct ether_addr;
92 #endif
93 #include <arpa/inet.h>
94 #endif
95 #ifdef HAVE_SYSLOG_H
96 #include <syslog.h>
97 #endif
98 #ifdef HAVE_SYS_SELECT_H
99 #include <sys/select.h>
100 #endif
101 #ifdef HAVE_SYS_PARAM_H
102 #include <sys/param.h>
103 #endif
104 #include "version.h"
106 #ifdef SOCKS
107 #include <socks.h>
108 #endif
110 #include <err.h>
111 #include <roken.h>
112 #include <getarg.h>
114 #ifdef KRB4
115 #include <krb.h>
116 #include <prot.h>
117 #endif
118 #ifdef KRB5
119 #include <krb5.h>
120 #endif
122 #define MAXUSERNAMELEN 65
123 #define MAXLINELEN 1024
124 #define MAXMSGLINELEN 1024
125 #define MAXCMDLEN 4
126 #define MAXPARMCOUNT 10
127 #define MAXPARMLEN 10
128 #define ALLOC_MSGS 20
129 #define MAIL_COMMAND "/usr/lib/sendmail"
131 #define POP_FACILITY LOG_LOCAL0
132 #define POP_PRIORITY LOG_NOTICE
133 #define POP_DEBUG LOG_DEBUG
134 #define POP_INFO LOG_INFO
135 #define POP_LOGOPTS 0
137 #ifdef HAVE_PATHS_H
138 #include <paths.h>
139 #endif
140 #ifdef HAVE_MAILLOCK_H
141 #include <maillock.h>
142 #endif
144 #ifdef OTP
145 #include <otp.h>
146 #endif
148 #if defined(KRB4_MAILDIR)
149 #define POP_MAILDIR KRB4_MAILDIR
150 #elif defined(_PATH_MAILDIR)
151 #define POP_MAILDIR _PATH_MAILDIR
152 #elif defined(MAILDIR)
153 #define POP_MAILDIR MAILDIR
154 #else
155 #define POP_MAILDIR "/usr/spool/mail"
156 #endif
158 #define POP_DROP POP_MAILDIR "/.%s.pop"
159 /* POP_TMPSIZE needs to be big enough to hold the string
160 * defined by POP_TMPDROP. POP_DROP and POP_TMPDROP
161 * must be in the same filesystem.
163 #define POP_TMPDROP POP_MAILDIR "/tmpXXXXXX"
164 #define POP_TMPSIZE 256
165 #define POP_TMPXMIT "/tmp/xmitXXXXXX"
166 #define POP_OK "+OK"
167 #define POP_ERR "-ERR"
168 #define POP_SUCCESS 1
169 #define POP_FAILURE 0
170 #define POP_TERMINATE '.'
171 #define POP_TIMEOUT 120 /* timeout connection after this many secs */
173 extern int pop_timeout;
175 extern int hangup;
177 #define AUTH_NONE 0
178 #define AUTH_OTP 1
179 #define AUTH_SASL 2
181 #define pop_command pop_parm[0] /* POP command is first token */
182 #define pop_subcommand pop_parm[1] /* POP XTND subcommand is the
183 second token */
185 typedef enum { /* POP processing states */
186 auth1, /* Authorization: waiting for
187 USER command */
188 auth2, /* Authorization: waiting for
189 PASS command */
190 trans, /* Transaction */
191 update, /* Update: session ended,
192 process maildrop changes */
193 halt, /* (Halt): stop processing
194 and exit */
195 error /* (Error): something really
196 bad happened */
197 } state;
200 #define DEL_FLAG 1
201 #define RETR_FLAG 2
202 #define NEW_FLAG 4
204 typedef struct { /* Message information */
205 int number; /* Message number relative to
206 the beginning of list */
207 long length; /* Length of message in
208 bytes */
209 int lines; /* Number of (null-terminated) lines in the message */
210 long offset; /* Offset from beginning of
211 file */
212 unsigned flags;
214 #if defined(UIDL) || defined(XOVER)
215 char *msg_id; /* The POP UIDL uniqueifier */
216 #endif
217 #ifdef XOVER
218 char *subject;
219 char *from;
220 char *date;
221 #endif
222 char *name;
223 } MsgInfoList;
225 #define IS_MAILDIR(P) ((P)->temp_drop[0] == '\0')
227 typedef struct { /* POP parameter block */
228 int debug; /* Debugging requested */
229 char * myname; /* The name of this POP
230 daemon program */
231 char myhost[MaxHostNameLen]; /* The name of our host
232 computer */
233 char client[MaxHostNameLen]; /* Canonical name of client
234 computer */
235 char ipaddr[MaxHostNameLen]; /* Dotted-notation format of
236 client IP address */
237 unsigned short ipport; /* Client port for privileged
238 operations */
239 char user[MAXUSERNAMELEN]; /* Name of the POP user */
240 state CurrentState; /* The current POP operational state */
241 MsgInfoList * mlp; /* Message information list */
242 int msg_count; /* Number of messages in
243 the maildrop */
244 int msgs_deleted; /* Number of messages flagged
245 for deletion */
246 int last_msg; /* Last message touched by
247 the user */
248 long bytes_deleted; /* Number of maildrop bytes
249 flagged for deletion */
250 char drop_name[MAXPATHLEN]; /* The name of the user's
251 maildrop */
252 char temp_drop[MAXPATHLEN]; /* The name of the user's
253 temporary maildrop */
254 long drop_size; /* Size of the maildrop in
255 bytes */
256 FILE * drop; /* (Temporary) mail drop */
257 FILE * input; /* Input TCP/IP communication
258 stream */
259 FILE * output; /* Output TCP/IP communication stream */
260 FILE * trace; /* Debugging trace file */
261 char * pop_parm[MAXPARMCOUNT]; /* Parse POP parameter list */
262 int parm_count; /* Number of parameters in
263 parsed list */
264 int kerberosp; /* Using KPOP? */
265 #ifdef KRB4
266 AUTH_DAT kdata;
267 #endif
268 #ifdef KRB5
269 krb5_context context;
270 krb5_principal principal; /* principal auth as */
271 krb5_log_facility* logf;
272 #endif
273 int version; /* 4 or 5? */
274 int auth_level; /* Dont allow cleartext */
275 #ifdef OTP
276 OtpContext otp_ctx; /* OTP context */
277 #endif
278 unsigned int flags;
279 #define POP_FLAG_CAPA 1
280 } POP;
282 typedef struct { /* State information for
283 each POP command */
284 state ValidCurrentState; /* The operating state of
285 the command */
286 char * command; /* The POP command */
287 int min_parms; /* Minimum number of parms
288 for the command */
289 int max_parms; /* Maximum number of parms
290 for the command */
291 int (*function) (); /* The function that process
292 the command */
293 state result[2]; /* The resulting state after
294 command processing */
295 #define success_state result[0] /* State when a command
296 succeeds */
297 } state_table;
299 typedef struct { /* Table of extensions */
300 char * subcommand; /* The POP XTND subcommand */
301 int min_parms; /* Minimum number of parms for
302 the subcommand */
303 int max_parms; /* Maximum number of parms for
304 the subcommand */
305 int (*function) (); /* The function that processes
306 the subcommand */
307 } xtnd_table;
309 int pop_dele(POP *p);
310 int pop_dropcopy(POP *p, struct passwd *pwp);
311 int pop_dropinfo(POP *p);
312 int pop_init(POP *p,int argcount,char **argmessage);
313 int pop_last(POP *p);
314 int pop_list(POP *p);
315 int pop_parse(POP *p, char *buf);
316 int pop_pass(POP *p);
317 int pop_quit(POP *p);
318 int pop_rset(POP *p);
319 int pop_send(POP *p);
320 int pop_stat(POP *p);
321 int pop_updt(POP *p);
322 int pop_user(POP *p);
323 #ifdef UIDL
324 int pop_uidl(POP *p);
325 #endif
326 #ifdef XOVER
327 int pop_xover(POP *p);
328 #endif
329 #ifdef XDELE
330 int pop_xdele(POP *p);
331 #endif
332 int pop_help(POP *p);
333 state_table *pop_get_command(POP *p, char *mp);
334 void pop_lower(char *buf);
335 #ifdef SASL
336 int pop_auth (POP *p);
337 void pop_capa_sasl(POP *p);
338 #endif
340 int pop_log(POP *p, int stat, char *format, ...)
341 #ifdef __GNUC__
342 __attribute__ ((format (printf, 3, 4)))
343 #endif
346 int pop_msg(POP *p, int stat, char *format, ...)
347 #ifdef __GNUC__
348 __attribute__ ((format (printf, 3, 4)))
349 #endif
352 int pop_maildir_info (POP*);
353 int pop_maildir_open (POP*, MsgInfoList*);
354 int pop_maildir_update (POP*);
356 int changeuser(POP*, struct passwd*);
357 void parse_header(MsgInfoList*, char*);
358 int add_missing_headers(POP*, MsgInfoList*);
359 int login_user(POP *p);