+ Add smtp authentication support.

- files/patch-smtp_authentication
  - files/remotes.sample (READ THIS)

+ fix a argument passing bug.
  - files/patch-src-send.cc

Obtained from:	Nullmailer Mailing List
This commit is contained in:
Clive Lin 2004-11-28 11:06:01 +00:00
parent 1697ad658e
commit e7468515eb
Notes: svn2git 2021-03-31 03:12:20 +00:00
svn path=/head/; revision=122657
4 changed files with 143 additions and 2 deletions

View File

@ -8,7 +8,7 @@
PORTNAME= nullmailer
# PORTVERSION= 1.00RC7
PORTVERSION= 1.00r7
PORTREVISION= 1
PORTREVISION= 2
CATEGORIES= mail
MASTER_SITES= http://untroubled.org/nullmailer/ \
ftp://mirrors.dataloss.nl/mirrors/bgware/nullmailer/%SUBDIR%/

View File

@ -0,0 +1,130 @@
diff -u protocols/protocol.cc protocols/protocol.cc
--- protocols/protocol.cc 2003-01-03 13:00:29.000000000 -0800
+++ protocols/protocol.cc 2004-08-04 12:20:34.000000000 -0700
@@ -30,10 +30,12 @@
const char* cli_help_suffix = "";
const char* cli_args_usage = "remote-address < mail-file";
const int cli_args_min = 1;
-const int cli_args_max = 1;
+const int cli_args_max = 2;
cli_option cli_options[] = {
{ 'p', "port", cli_option::integer, 0, &port,
"Set the port number on the remote host to connect to", 0 },
+ { 'a', "auth", cli_option::string, 0, &auth,
+ "Set the user and password for authentication (user,pass)", 0 } ,
{0}
};
diff -u protocols/protocol.h protocols/protocol.h
--- protocols/protocol.h 2002-12-23 10:14:53.000000000 -0800
+++ protocols/protocol.h 2004-08-04 12:21:25.000000000 -0700
@@ -8,6 +8,7 @@
// This must be provided by the protocol, but will be set by the lib.
extern int port;
+extern char* auth;
extern void protocol_prep(fdibuf* in);
extern void protocol_send(fdibuf* in, int fd);
diff -u protocols/qmqp.cc protocols/qmqp.cc
--- protocols/qmqp.cc 2003-01-03 13:00:31.000000000 -0800
+++ protocols/qmqp.cc 2004-08-04 12:21:13.000000000 -0700
@@ -31,6 +31,7 @@
#include "protocol.h"
int port = 628;
+char* auth = "";
const char* cli_program = "qmqp";
const char* cli_help_prefix = "Send an emal message via QMQP\n";
diff -u protocols/smtp.cc protocols/smtp.cc
--- protocols/smtp.cc 2003-01-03 13:00:32.000000000 -0800
+++ protocols/smtp.cc 2004-08-04 20:46:15.605469184 -0700
@@ -30,6 +30,7 @@
#include "protocol.h"
int port = 25;
+char* auth = "";
const char* cli_program = "smtp";
const char* cli_help_prefix = "Send an email message via SMTP\n";
@@ -136,6 +137,11 @@
{
}
+void to64(char* infile, char* outfile);
+void to64(const mystring& infile, mystring& outfile);
+void output64chunk(int c1, int c2, int c3, int pads, char** outfile);
+void output64chunk(int c1, int c2, int c3, int pads, mystring& outfile);
+
void protocol_send(fdibuf* in, int fd)
{
mystring hh = getenv("HELOHOST");
@@ -143,5 +149,67 @@
smtp conn(fd);
conn.docmd("", 200);
conn.docmd("HELO " + hh, 200);
+
+ if ( strlen(auth) > 0 )
+ {
+ mystring authstr = auth;
+ mystring uname = authstr.left(authstr.find_first(','));
+ mystring pass = authstr.sub(authstr.find_first(',')+1,authstr.length());
+ mystring plain = uname + "\1" + uname + "\1" + pass;
+ mystring encoded = "AUTH PLAIN ";
+ to64(plain,encoded);
+ conn.docmd(encoded,200);
+ }
conn.send(in);
}
+
+static char basis_64[] =
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+
+void to64(const mystring& infile, mystring& outfile)
+{
+ int c1, c2, c3;
+ size_t inpos = 0;
+ while ((c1 = infile[inpos++])) {
+ c2 = infile[inpos++];
+ if (!c2) {
+ output64chunk(c1, 0, 0, 2, outfile);
+ } else {
+ c3 = infile[inpos++];
+ if (!c3) {
+ output64chunk(c1, c2, 0, 1, outfile);
+ } else {
+ output64chunk(c1, c2, c3, 0, outfile);
+ }
+ }
+ }
+}
+
+void output64chunk(int c1, int c2, int c3, int pads, mystring& outfile)
+{
+ if (c1==1) c1 = 0;
+ if (c2==1) c2 = 0;
+ if (c3==1) c3 = 0;
+
+ char out[5];
+ out[0] = basis_64[c1>>2];
+ out[1] = basis_64[((c1 & 0x3)<< 4) | ((c2 & 0xF0) >> 4)];
+ switch (pads)
+ {
+ case 0:
+ out[2] = basis_64[((c2 & 0xF) << 2) | ((c3 & 0xC0) >>6)];
+ out[3] = basis_64[c3 & 0x3F];
+ break;
+ case 1:
+ out[2] = basis_64[((c2 & 0xF) << 2) | ((c3 & 0xC0) >>6)];
+ out[3] = '=';
+ break;
+ case 2:
+ out[2] = '=';
+ out[3] = '=';
+ break;
+ };
+ out[4] = 0;
+ outfile += out;
+}
+// vim:cin:si:ai:et:ts=2:sw=2:

View File

@ -0,0 +1,11 @@
--- src/send.cc.orig Sat Jan 4 04:58:31 2003
+++ src/send.cc Sun Nov 28 18:49:02 2004
@@ -166,7 +166,7 @@
unsigned i = 0;
args[i++] = program.c_str();
for(slist::const_iter opt(remote.options); opt; opt++)
- args[i++] = (*opt).c_str();
+ args[i++] = strdup((*opt).c_str());
args[i++] = remote.host.c_str();
args[i++] = 0;
execv(args[0], (char**)args);

View File

@ -1 +1 @@
localhost smtp
localhost smtp --port=25 --auth=user,pass