popper.h
上传用户:dayuan858
上传日期:2007-01-04
资源大小:194k
文件大小:12k
源码类别:

网络编程

开发平台:

Unix_Linux

  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.  */
  7. /*
  8.  * Copyright (c) 1997 by Qualcomm Incorporated.
  9.  */
  10. /*  LINTLIBRARY */
  11. /* 
  12.  *  Header file for the POP programs
  13.  */
  14. #define BINMAIL_IS_SETGID 1
  15. #ifdef POPSCO
  16. # include <sys/syslog.h>
  17. #else
  18. # include <syslog.h>
  19. #endif
  20. #include <sys/socket.h>
  21. #include "version.h"
  22. #ifdef ISC
  23. # include <sys/types.h>
  24. # include <sys/fcntl.h>
  25. # include <net/errno.h>
  26. #endif
  27. #ifdef HAVE_SYS_PARAM_H
  28. #include <sys/param.h>
  29. # if (defined(BSD) && (BSD >= 199103))
  30. #  define HAVE_UNISTD_H
  31. #  define HAVE_VPRINTF
  32. #  define BIND43
  33. # endif
  34. #endif
  35. #ifdef BSDI
  36. #define BSD44_DBM
  37. #endif
  38. #ifdef BULLDB
  39. # undef DBM /* used by mts.c and ndbm.h */
  40. # ifdef GDBM
  41. #  include <gdbm.h>
  42. # else
  43. #  include <ndbm.h>
  44. # endif
  45. #endif
  46. #define NULLCP          ((char *) 0)
  47. #define SPACE           32
  48. #define TAB             9
  49. #define TRUE            1
  50. #define FALSE           0
  51. #define NEWLINE         'n'
  52. #define MAXUSERNAMELEN  65
  53. #define MAXDROPLEN      64
  54. #define MAXLINELEN      1024
  55. #define MAXMSGLINELEN   MAXLINELEN
  56. #define MAXCMDLEN       4
  57. #define MAXPARMCOUNT    5
  58. #define MAXPARMLEN      10
  59. #define ALLOC_MSGS  20
  60. #ifndef OSF1
  61. # define POP_FACILITY    LOG_LOCAL0
  62. #else
  63. # define POP_FACILITY    LOG_MAIL
  64. #endif
  65. #define POP_PRIORITY    LOG_NOTICE
  66. #define POP_DEBUG       LOG_DEBUG
  67. #define POP_LOGOPTS     LOG_PID
  68. #ifdef POPSCO
  69. # define L_SET  0
  70. # define L_XTND 2
  71. #endif
  72. /* ^A */
  73. #define MMDF_SEP_CHAR '01'
  74. /* For performance reasons large sites should change the pop tempdrop
  75.  * location to another directory other than the mail spool location.
  76.  * The more files referenced in a directory, the slower the access is
  77.  */
  78. /*
  79.  * The default string for HOMEDIRMAIL is "%s/.mail".  You need to change
  80.  * the value in pop_dropcopy.h in routine genpath() if you wish to modify
  81.  * the mail drop location.
  82.  */
  83. /* Define his path to default the bulletin dir.
  84.  * -DBULLDIR= "/usr/mail/bulletins"
  85.  * in the make file works well or you can define BULLDIR before the #ifdef.
  86.  */
  87. #ifndef BULLDIR
  88. #define BULLDIR NULL
  89. #endif
  90. /* Defines the minimum number of bulletins a new user
  91.    receives */
  92. #define NEWBULLCNT 1
  93. #ifndef CONTENT_LENGTH
  94. #define CONTENT_LENGTH 0
  95. #endif
  96. /* POP_TMPSIZE needs to be big enough to hold the string
  97.  * defined by POP_TMPDROP.  POP_DROP and POP_TMPDROP
  98.  * must be in the same filesystem.
  99.  */
  100. #define POP_TMPSIZE 256
  101. #define POP_OK          "+OK"
  102. #define POP_ERR         "-ERR"
  103. #define POP_SUCCESS     1
  104. #define POP_FAILURE     0
  105. #define POP_TERMINATE   '.'
  106. #define POP_TIMEOUT 120 /* timeout connection after this many secs */
  107.     /* UID's <= this value are not allowed to access email */
  108. #define BLOCK_UID 10
  109. #define DIG_SIZE 16
  110. /* Set these to the types your OS returns if they are not
  111.    already typedefed for you */
  112. #define OFF_T off_t
  113. #define PID_T pid_t
  114. #define UID_T uid_t
  115. #define GID_T gid_t
  116. #define TIME_T time_t
  117. #define SIZE_T size_t
  118. #ifdef NeXT
  119. #undef PID_T
  120. #define PID_T int
  121. #endif
  122. #ifdef CHECK_SHELL
  123. #define WILDCARD_SHELL "/POPPER/ANY/SHELL/"
  124. #endif
  125. extern int              errno;
  126. #if !(defined(BSD) && (BSD >= 199306)) && !defined(__USE_BSD)
  127. extern int              sys_nerr;
  128. extern char         *   sys_errlist[];
  129. #ifndef __linux__
  130. extern char         *   sys_siglist[];
  131. #endif
  132. #endif
  133. extern int pop_timeout;
  134. extern int hangup;
  135. #define pop_command         pop_parm[0]     /*  POP command is first token */
  136. #define pop_subcommand      pop_parm[1]     /*  POP XTND subcommand is the 
  137.                                                 second token */
  138. typedef enum {                              /*  POP processing states */
  139.     auth1,                                  /*  Authorization: waiting for 
  140.                                                 USER command */
  141.     auth2,                                  /*  Authorization: waiting for 
  142.                                                 PASS command */
  143.     trans,                                  /*  Transaction */
  144.     update,                                 /*  Update:  session ended, 
  145.                                                 process maildrop changes */
  146.     halt,                                   /*  (Halt):  stop processing 
  147.                                                 and exit */
  148.     error                                   /*  (Error): something really 
  149.                                                 bad happened */
  150. } state;
  151. typedef struct {                                /*  State information for 
  152.                                                     each POP command */
  153.     state       ValidCurrentState;              /*  The operating state of 
  154.                                                     the command */
  155.     char   *    command;                        /*  The POP command */
  156.     int         min_parms;                      /*  Minimum number of parms 
  157.                                                     for the command */
  158.     int         max_parms;                      /*  Maximum number of parms 
  159.                                                     for the command */
  160.     int         (*function) ();                 /*  The function that process 
  161.                                                     the command */
  162.     state       result[2];                      /*  The resulting state after 
  163.                                                     command processing */
  164. #define success_state   result[0]               /*  State when a command 
  165.                                                     succeeds */
  166. } state_table;
  167. typedef struct {                                /*  Table of extensions */
  168.     char   *    subcommand;                     /*  The POP XTND subcommand */
  169.     int         min_parms;                      /*  Minimum number of parms for
  170.                                                     the subcommand */
  171.     int         max_parms;                      /*  Maximum number of parms for
  172.                                                     the subcommand */
  173.     int         (*function) ();                 /*  The function that processes 
  174.                                                     the subcommand */
  175. } xtnd_table;
  176. typedef struct {                                /*  Message information */
  177.     int         number;                         /*  Message number relative to 
  178.                                                     the beginning of list */
  179.     long        length;                         /*  Length of message in 
  180.                                                     bytes */
  181.     int         lines;                          /*  Number of (null-terminated)
  182.     lines in the message */
  183.     int         body_lines; /*  Number of (null-terminated)
  184.         lines in the body */
  185.     long        offset;                         /*  Offset from beginning of 
  186.                                                     file */
  187.     int         del_flag;                       /*  Flag indicating if message 
  188.                                                     is marked for deletion */
  189.     int         retr_flag;                      /*  Flag indicating if message 
  190.                                                     was retrieved */
  191.     int orig_retr_state; /*  What was the state at the
  192.     start of this session.
  193.     Used for RSET cmd. */
  194.     char *uidl_str; /*  Cache of the UIDL str for
  195.     faster access */
  196. } MsgInfoList;
  197. typedef struct  {                               /*  POP parameter block */
  198.     int                 debug;                  /*  Debugging requested */
  199.     int                 xmitting;               /*  =1 xtnd xmit started */
  200.     int                 stats;                  /*  Stats requested */
  201.     int dirty; /*  Any mailbox changes? */
  202.     int kerberos; /*  Flag to enable kerberos
  203.     authentication */
  204.     int server_mode; /*  Default at compile time */
  205.     char            *   myname;                 /*  The name of this POP 
  206.                                                     daemon program */
  207.     char            *   myhost;                 /*  The name of our host 
  208.                                                     computer */
  209.     char            *   client;                 /*  Canonical name of client 
  210.                                                     computer */
  211.     char            *   ipaddr;                 /*  Dotted-notation format of 
  212.                                                     client IP address */
  213.     unsigned short      ipport;                 /*  Client port for privileged 
  214.                                                     operations */
  215.     char                user[MAXUSERNAMELEN];   /*  Name of the POP user */
  216.     state               CurrentState;           /*  The current POP operational                                                     state */
  217.     MsgInfoList     *   mlp;                    /*  Message information list */
  218.     int                 msg_count;              /*  Number of messages in 
  219.                                                     the maildrop */
  220.     int                 msgs_deleted;           /*  Number of messages flagged 
  221.                                                     for deletion */
  222.     int                 last_msg;               /*  Last message touched by 
  223.                                                     the user */
  224.     long                bytes_deleted;          /*  Number of maildrop bytes 
  225.                                                     flagged for deletion */
  226.     char                drop_name[MAXDROPLEN];  /*  The name of the user's 
  227.                                                     maildrop */
  228.     char                temp_drop[MAXDROPLEN];  /*  The name of the user's 
  229.                                                     temporary maildrop */
  230.     long                drop_size;              /*  Size of the maildrop in
  231.                                                     bytes */
  232.     long spool_end; /*  Offset of the end of the
  233.     mailspool */
  234.     FILE            *   drop;                   /*  (Temporary) mail drop */
  235.     FILE            *   input;                  /*  Input TCP/IP communication 
  236.                                                     stream */
  237.     FILE            *   output;                 /*  Output TCP/IP communication                                                     stream */
  238.     FILE            *   trace;                  /*  Debugging trace file */
  239.     FILE            *   hold;                   /*  In SERVER_MODE, this value
  240.     holds the drop FILE */
  241.     char            *   pop_parm[MAXPARMCOUNT]; /*  Parse POP parameter list */
  242.     int                 parm_count;             /*  Number of parameters in 
  243.                                                     parsed list */
  244.     char            *   bulldir;                /*  Bulletin directory */
  245. #ifdef BULLDB
  246. #ifdef GDBM
  247. GDBM_FILE  bull_db;
  248. #else
  249.     DBM     * bull_db; /*  Central Bulletin Database */
  250. #endif
  251. #endif
  252.     char     * mmdf_separator; /*  string between messages */
  253.     char md5str[BUFSIZ]; /*  String used with the shared
  254.     secret to create the md5
  255.     digest */
  256. } POP;
  257. #ifdef KERBEROS
  258. #ifndef KERBEROS_SERVICE
  259. # define KERBEROS_SERVICE "rcmd"
  260. #endif
  261. #ifdef SOLARIS2
  262. # include <kerberos/krb.h>
  263. #else
  264. # ifdef BSDI
  265. #  include <kerberosIV/des.h>
  266. #  include <kerberosIV/krb.h>
  267. # else
  268. #  include <krb.h>
  269. # endif
  270. #endif
  271. extern AUTH_DAT kdata;
  272. #endif /* KERBEROS */
  273. #if defined(AUTHFILE)
  274. extern int  checkauthfile();
  275. #endif
  276. #if defined(NONAUTHFILE)
  277. extern int  checknonauthfile();
  278. #endif
  279. extern int  pop_dele();
  280. extern int  pop_last();
  281. extern int  pop_list();
  282. extern int  pop_pass();
  283. extern int  pop_rpop();
  284. extern int  pop_apop();
  285. extern int  pop_auth();
  286. extern int  pop_quit();
  287. extern int  pop_rset();
  288. extern int  pop_send();
  289. extern int  pop_stat();
  290. extern int  pop_updt();
  291. extern int  pop_user();
  292. extern int  pop_xtnd();
  293. extern int  pop_xmit();
  294. extern int  pop_xmit_recv();
  295. extern int  pop_xmit_exec();
  296. extern int  pop_xlst();
  297. extern int  pop_uidl();
  298. extern int  pop_euidl();
  299. extern int  isfromline();
  300. extern int  genpath();
  301. extern char *pwerrmsg;
  302. #define pop_auth_fail pop_msg
  303. #ifndef MAXHOSTNAMELEN
  304. # define MAXHOSTNAMELEN 256
  305. #endif
  306. /*
  307. extern int  pop_auth_fail();
  308. */