1 /* smtp.c --- Implement SMTP profile of SASL login.
2 * Copyright (C) 2002, 2003, 2004, 2005 Simon Josefsson
4 * This file is part of GNU SASL.
6 * GNU SASL is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * GNU SASL is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with GNU SASL; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 #define MAX_LINE_LENGTH BUFSIZ
38 smtp_has_starttls (void)
43 if (!writeln ("EHLO [127.0.0.1]"))
51 #define TLSGREETING "250-STARTTLS"
52 if (strncmp (in
, TLSGREETING
, strlen (TLSGREETING
)) == 0)
55 while (strncmp (in
, "250 ", 4) != 0);
65 if (!writeln ("STARTTLS"))
75 smtp_select_mechanism (char **mechlist
)
79 if (args_info
.server_flag
)
81 if (!args_info
.quiet_given
)
82 fprintf (stderr
, _("Chose SASL mechanisms:\n"));
89 if (!writeln ("EHLO [127.0.0.1]"))
97 #define GREETING "250-AUTH "
98 if (strncmp (in
, GREETING
, strlen (GREETING
)) == 0)
99 *mechlist
= in
+ strlen (GREETING
);
101 while (strncmp (in
, "250 ", 4) != 0);
108 smtp_authenticate (const char *mech
)
110 if (args_info
.server_flag
)
112 if (!args_info
.quiet_given
)
113 fprintf (stderr
, _("Using mechanism:\n"));
118 char input
[MAX_LINE_LENGTH
];
120 sprintf (input
, "AUTH %s", mech
);
121 if (!writeln (input
))
129 smtp_step_send (const char *data
)
131 char input
[MAX_LINE_LENGTH
];
133 if (args_info
.server_flag
)
134 sprintf (input
, "334 %s", data
);
136 sprintf (input
, "%s", data
);
137 if (!writeln (input
))
144 smtp_step_recv (char **data
)
153 if (p
[0] != '3' || p
[1] != '3' || p
[2] != '4' || p
[3] != ' ')
155 fprintf (stderr
, _("error: Server did not return expected SASL "
156 "data (it must begin with '334 '):\n%s\n"), p
);
160 memmove (&p
[0], &p
[4], strlen (p
) - 3);
162 if (p
[strlen (p
) - 1] == '\n')
163 p
[strlen (p
) - 1] = '\0';
164 if (p
[strlen (p
) - 1] == '\r')
165 p
[strlen (p
) - 1] = '\0';
171 smtp_auth_finish (void)
186 if (!writeln ("QUIT"))
189 /* read "221 2.0.0 foo closing ..." */