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