Mercurial > hg > mlmmj
annotate src/checkwait_smtpreply.c @ 775:d0bf2135ab34
Check the server gives a reply before reading it to avoid segfaulting
author | Ben Schmidt |
---|---|
date | Fri, 12 Nov 2010 02:27:50 +1100 |
parents | a38cde48669f |
children | 04d916168efb |
rev | line source |
---|---|
0 | 1 /* Copyright (C) 2002, 2003 Mads Martin Joergensen <mmj at mmj.dk> |
2 * | |
3 * $Id$ | |
4 * | |
225 | 5 * Permission is hereby granted, free of charge, to any person obtaining a copy |
6 * of this software and associated documentation files (the "Software"), to | |
7 * deal in the Software without restriction, including without limitation the | |
8 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | |
9 * sell copies of the Software, and to permit persons to whom the Software is | |
10 * furnished to do so, subject to the following conditions: | |
11 * | |
12 * The above copyright notice and this permission notice shall be included in | |
13 * all copies or substantial portions of the Software. | |
14 * | |
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | |
21 * IN THE SOFTWARE. | |
0 | 22 */ |
23 | |
24 #include <stdio.h> | |
25 #include <unistd.h> | |
110
6bbaadfb1c43
Make checkwait_smtpreply return the string that it gets from the mailserver
mmj
parents:
107
diff
changeset
|
26 #include <string.h> |
245 | 27 |
0 | 28 #include "checkwait_smtpreply.h" |
29 #include "config.h" | |
245 | 30 #include "memory.h" |
591 | 31 #include "mygetline.h" |
0 | 32 |
110
6bbaadfb1c43
Make checkwait_smtpreply return the string that it gets from the mailserver
mmj
parents:
107
diff
changeset
|
33 |
6bbaadfb1c43
Make checkwait_smtpreply return the string that it gets from the mailserver
mmj
parents:
107
diff
changeset
|
34 char *checkwait_smtpreply(int sockfd, int replytype) |
0 | 35 { |
591 | 36 char *smtpreply; |
110
6bbaadfb1c43
Make checkwait_smtpreply return the string that it gets from the mailserver
mmj
parents:
107
diff
changeset
|
37 |
591 | 38 smtpreply = mygetline(sockfd); |
775
d0bf2135ab34
Check the server gives a reply before reading it to avoid segfaulting
Ben Schmidt
parents:
595
diff
changeset
|
39 if(smtpreply == NULL) { |
d0bf2135ab34
Check the server gives a reply before reading it to avoid segfaulting
Ben Schmidt
parents:
595
diff
changeset
|
40 /* This will never be a valid SMTP response so will always be returned, |
d0bf2135ab34
Check the server gives a reply before reading it to avoid segfaulting
Ben Schmidt
parents:
595
diff
changeset
|
41 * but is more descriptive than an empty string. */ |
d0bf2135ab34
Check the server gives a reply before reading it to avoid segfaulting
Ben Schmidt
parents:
595
diff
changeset
|
42 smtpreply = mystrdup("none / error / closed connection"); |
d0bf2135ab34
Check the server gives a reply before reading it to avoid segfaulting
Ben Schmidt
parents:
595
diff
changeset
|
43 } |
d0bf2135ab34
Check the server gives a reply before reading it to avoid segfaulting
Ben Schmidt
parents:
595
diff
changeset
|
44 |
99
6089f38bb228
Send our hostname in HELO and change the mlmmj-send output from
mmj
parents:
0
diff
changeset
|
45 #if 0 |
0 | 46 printf("replytype = [%d], smtpreply = [%s]\n", replytype, smtpreply); |
110
6bbaadfb1c43
Make checkwait_smtpreply return the string that it gets from the mailserver
mmj
parents:
107
diff
changeset
|
47 fprintf(stderr, "%s", smtpreply); |
180
8b9850c25d94
Remove fprintf(stderr, "%s", smtpreply) from checkwait_smtpreply. No need to
mmj
parents:
110
diff
changeset
|
48 #endif |
99
6089f38bb228
Send our hostname in HELO and change the mlmmj-send output from
mmj
parents:
0
diff
changeset
|
49 |
110
6bbaadfb1c43
Make checkwait_smtpreply return the string that it gets from the mailserver
mmj
parents:
107
diff
changeset
|
50 /* This case might seem like (and is ATM) total overkill. But it's |
6bbaadfb1c43
Make checkwait_smtpreply return the string that it gets from the mailserver
mmj
parents:
107
diff
changeset
|
51 * easy for us to extend it later on if needed. |
6bbaadfb1c43
Make checkwait_smtpreply return the string that it gets from the mailserver
mmj
parents:
107
diff
changeset
|
52 */ |
0 | 53 switch(replytype) { |
504 | 54 case MLMMJ_CONNECT: |
55 if(smtpreply[0] != '2' || smtpreply[1] != '2') | |
595 | 56 return smtpreply; |
504 | 57 break; |
58 case MLMMJ_HELO: | |
59 if(smtpreply[0] != '2' || smtpreply[1] != '5') | |
595 | 60 return smtpreply; |
504 | 61 break; |
62 case MLMMJ_FROM: | |
63 if(smtpreply[0] != '2' || smtpreply[1] != '5') | |
595 | 64 return smtpreply; |
504 | 65 break; |
66 case MLMMJ_RCPTTO: | |
67 if(smtpreply[0] != '2' || smtpreply[1] != '5') | |
595 | 68 return smtpreply; |
504 | 69 break; |
70 case MLMMJ_DATA: | |
71 if(smtpreply[0] != '3' || smtpreply[1] != '5') | |
595 | 72 return smtpreply; |
504 | 73 break; |
74 case MLMMJ_DOT: | |
75 if(smtpreply[0] != '2' || smtpreply[1] != '5') | |
595 | 76 return smtpreply; |
504 | 77 break; |
78 case MLMMJ_QUIT: | |
79 if(smtpreply[0] != '2' || smtpreply[1] != '2') | |
595 | 80 return smtpreply; |
504 | 81 break; |
82 case MLMMJ_RSET: | |
83 if(smtpreply[0] != '2' || smtpreply[1] != '5') | |
595 | 84 return smtpreply; |
504 | 85 break; |
86 default: | |
87 break; | |
0 | 88 } |
89 | |
595 | 90 myfree(smtpreply); |
91 | |
110
6bbaadfb1c43
Make checkwait_smtpreply return the string that it gets from the mailserver
mmj
parents:
107
diff
changeset
|
92 return NULL; |
0 | 93 } |