]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - crypto/heimdal/appl/popper/pop_get_command.c
import of heimdal 0.3f
[FreeBSD/FreeBSD.git] / crypto / heimdal / appl / popper / pop_get_command.c
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 #include <popper.h>
8 RCSID("$Id: pop_get_command.c,v 1.15 1999/09/16 20:38:49 assar Exp $");
9
10 /* 
11  *  get_command:    Extract the command from an input line form a POP client
12  */
13
14 static state_table states[] = {
15         {auth1,  "user", 1,  1,  pop_user,   {auth1, auth2}},
16         {auth2,  "pass", 1,  99, pop_pass,   {auth1, trans}},
17 #ifdef RPOP
18         {auth2,  "rpop", 1,  1,  pop_rpop,   {auth1, trans}},
19 #endif /* RPOP */
20         {auth1,  "quit", 0,  0,  pop_quit,   {halt,  halt}},
21         {auth2,  "quit", 0,  0,  pop_quit,   {halt,  halt}},
22         {trans,  "stat", 0,  0,  pop_stat,   {trans, trans}},
23         {trans,  "list", 0,  1,  pop_list,   {trans, trans}},
24         {trans,  "retr", 1,  1,  pop_send,   {trans, trans}},
25         {trans,  "dele", 1,  1,  pop_dele,   {trans, trans}},
26         {trans,  "noop", 0,  0,  NULL,       {trans, trans}},
27         {trans,  "rset", 0,  0,  pop_rset,   {trans, trans}},
28         {trans,  "top",  2,  2,  pop_send,   {trans, trans}},
29         {trans,  "last", 0,  0,  pop_last,   {trans, trans}},
30         {trans,  "quit", 0,  0,  pop_updt,   {halt,  halt}},
31         {trans,  "help", 0,  0,  pop_help,   {trans, trans}},
32 #ifdef UIDL
33         {trans,  "uidl", 0,  1,  pop_uidl,   {trans, trans}},
34 #endif
35 #ifdef XOVER
36         {trans, "xover", 0,  0,  pop_xover,  {trans, trans}},
37 #endif
38 #ifdef XDELE
39         {trans,  "xdele", 1,  2,  pop_xdele,   {trans, trans}},
40 #endif
41         {(state) 0,  NULL,   0,  0,  NULL,       {halt,  halt}},
42 };
43
44 state_table *
45 pop_get_command(POP *p, char *mp)
46 {
47     state_table     *   s;
48     char                buf[MAXMSGLINELEN];
49
50     /*  Save a copy of the original client line */
51 #ifdef DEBUG
52     if(p->debug) strlcpy (buf, mp, sizeof(buf));
53 #endif /* DEBUG */
54
55     /*  Parse the message into the parameter array */
56     if ((p->parm_count = pop_parse(p,mp)) < 0) return(NULL);
57
58     /*  Do not log cleartext passwords */
59 #ifdef DEBUG
60     if(p->debug){
61         if(strcmp(p->pop_command,"pass") == 0)
62             pop_log(p,POP_DEBUG,"Received: \"%s xxxxxxxxx\"",p->pop_command);
63         else {
64             /*  Remove trailing <LF> */
65             buf[strlen(buf)-2] = '\0';
66             pop_log(p,POP_DEBUG,"Received: \"%s\"",buf);
67         }
68     }
69 #endif /* DEBUG */
70
71     /*  Search for the POP command in the command/state table */
72     for (s = states; s->command; s++) {
73
74         /*  Is this a valid command for the current operating state? */
75         if (strcmp(s->command,p->pop_command) == 0
76              && s->ValidCurrentState == p->CurrentState) {
77
78             /*  Were too few parameters passed to the command? */
79             if (p->parm_count < s->min_parms) {
80                 pop_msg(p,POP_FAILURE,
81                         "Too few arguments for the %s command.",
82                         p->pop_command);
83                 return NULL;
84             }
85
86             /*  Were too many parameters passed to the command? */
87             if (p->parm_count > s->max_parms) {
88                 pop_msg(p,POP_FAILURE,
89                         "Too many arguments for the %s command.",
90                         p->pop_command);
91                 return NULL;
92            }
93
94             /*  Return a pointer to the entry for this command in 
95                 the command/state table */
96             return (s);
97         }
98     }
99     /*  The client command was not located in the command/state table */
100     pop_msg(p,POP_FAILURE,
101             "Unknown command: \"%s\".",p->pop_command);
102     return NULL;
103 }
104
105 int
106 pop_help (POP *p)
107 {
108     state_table         *s;
109
110     pop_msg(p, POP_SUCCESS, "help");
111
112     for (s = states; s->command; s++) {
113         fprintf (p->output, "%s\r\n", s->command);
114     }
115     fprintf (p->output, ".\r\n");
116     fflush (p->output);
117     return POP_SUCCESS;
118 }