Skip to content

Commit ce1f4aa

Browse files
committed
apply alex's patch (ossec#1360) for sending mail via curl to third party smtp server
1 parent 1ecffb1 commit ce1f4aa

File tree

10 files changed

+323
-1
lines changed

10 files changed

+323
-1
lines changed

etc/templates/en/messages.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@ yoursmtp="We found your SMTP server as"
4141
usesmtp="Do you want to use it?"
4242
usingsmtp="Using SMTP server: "
4343
whatsmtp="What's your SMTP server ip/host?"
44+
useauthsmtp="Want to use authenticated SMTP?"
45+
46+
noauthsmtp="SMTP authenticated not enabled"
47+
yesauthsmtp="SMTP authenticated enabled"
48+
userauthsmtp="Please, enter your SMTP username"
49+
passauthsmtp="Please, enter your SMTP password"
50+
usesecuresmtp="This server requires a secure connection (SSL)?"
51+
nosecuresmtp="SMTP with SSL disabled"
52+
yessecuresmtp="SMTP with SSL enabled"
4453

4554
# Part 3.1/agent
4655
serveraddr="What's the IP Address or hostname of the OSSEC HIDS server?"

install.sh

Lines changed: 104 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
### Looking up for the execution directory
2020
cd `dirname $0`
2121

22-
2322
### Looking for echo -n
2423
ECHO="echo -n"
2524
hs=`echo -n "a"`
@@ -130,6 +129,8 @@ Install()
130129
chmod 600 ${OSSEC_INIT}
131130
cp -pr ${OSSEC_INIT} ${INSTALLDIR}${OSSEC_INIT}
132131
chmod 640 ${INSTALLDIR}${OSSEC_INIT}
132+
mkdir ${INSTALLDIR}/lib
133+
cp -R /lib/* ${INSTALLDIR}/lib
133134

134135

135136
# If update_rules is set, we need to tweak
@@ -241,7 +242,104 @@ UseRootcheck()
241242
fi
242243
}
243244

245+
###############
246+
# UseSecureSMTP()
247+
###############
248+
UseSecureSMTP()
249+
{
250+
251+
# SMTP Authenticaction configuration (SSL)
252+
echo ""
253+
$ECHO " ${usesecuresmtp} ($yes/$no) [$yes]: "
254+
255+
if [ "X${USER_ENABLE_SECURESMTP}" = "X" ]; then
256+
read ESS
257+
else
258+
ESS=${USER_ENABLE_SECURESMTP}
259+
fi
260+
261+
echo ""
262+
case $ESS in
263+
$nomatch)
264+
echo " - ${nosecuresmtp}."
265+
;;
266+
*)
267+
SECURESMTP="yes"
268+
echo " - ${yessecuresmtp}."
269+
;;
270+
esac
271+
272+
# Adding to the config file
273+
if [ "X${SECURESMTP}" = "Xyes" ]; then
274+
echo "" >> $NEWCONFIG
275+
echo " <secure_smtp>yes</secure_smtp>" >> $NEWCONFIG
276+
echo "" >> $NEWCONFIG
277+
else
278+
echo "" >> $NEWCONFIG
279+
echo " <secure_smtp>no</secure_smtp>" >> $NEWCONFIG
280+
echo "" >> $NEWCONFIG
281+
fi
282+
}
283+
284+
285+
###############
286+
# UseAuthSMTP()
287+
###############
288+
UseAuthSMTP()
289+
{
290+
291+
# SMTP Authenticaction configuration
292+
echo ""
293+
$ECHO " ${useauthsmtp} ($yes/$no) [$yes]: "
294+
295+
if [ "X${USER_ENABLE_AUTHSMTP}" = "X" ]; then
296+
read EAS
297+
else
298+
EAS=${USER_ENABLE_AUTHSMTP}
299+
fi
300+
301+
echo ""
302+
case $EAS in
303+
$nomatch)
304+
echo " - ${noauthsmtp}."
305+
;;
306+
*)
307+
AUTHSMTP="yes"
308+
echo " - ${yesauthsmtp}."
309+
;;
310+
esac
311+
312+
if [ "X${AUTHSMTP}" = "Xyes" ]; then
313+
if [ "X${AUTHSMTP_USER}" = "X" ]; then
314+
echo ""
315+
$ECHO " ${userauthsmtp}: "
316+
read AUTHSMTP_USER
317+
fi
318+
319+
if [ "X${AUTHSMTP_PASS}" = "X" ]; then
320+
echo ""
321+
$ECHO " ${passauthsmtp}: "
322+
stty -echo # turn off terminal echo to prevent peeping!
323+
read AUTHSMTP_PASS
324+
stty echo # turn on
325+
echo ""
326+
fi
327+
fi
244328

329+
# Adding to the config file
330+
if [ "X${AUTHSMTP}" = "Xyes" ]; then
331+
echo "" >> $NEWCONFIG
332+
echo " <auth_smtp>yes</auth_smtp>" >> $NEWCONFIG
333+
echo " <smtp_user>$AUTHSMTP_USER</smtp_user>" >> $NEWCONFIG
334+
echo " <smtp_password>$AUTHSMTP_PASS</smtp_password>" >> $NEWCONFIG
335+
echo "" >> $NEWCONFIG
336+
UseSecureSMTP
337+
else
338+
echo "" >> $NEWCONFIG
339+
echo " <auth_smtp>no</auth_smtp>" >> $NEWCONFIG
340+
echo "" >> $NEWCONFIG
341+
fi
342+
}
245343

246344

247345
##########
@@ -552,6 +650,8 @@ ConfigureServer()
552650
echo " <email_notification>no</email_notification>" >> $NEWCONFIG
553651
fi
554652

653+
UseAuthSMTP
654+
555655
echo " </global>" >> $NEWCONFIG
556656
echo "" >> $NEWCONFIG
557657

@@ -817,6 +917,9 @@ checkDependencies()
817917

818918
PATH=$OLDOPATH
819919
export PATH
920+
921+
# Re-export sendmail_curl if curl support should be compiled in
922+
export SENDMAIL_CURL
820923
}
821924

822925
##########

src/Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ endif
6363

6464
OSSEC_LDFLAGS=${LDFLAGS} -lm
6565

66+
ifeq (${SENDMAIL_CURL},yes)
67+
DEFINES +=-DSENDMAIL_CURL=\"1\"
68+
OSSEC_LDFLAGS+=-lcurl
69+
endif
70+
6671
ifneq (${TARGET},winagent)
6772
ifeq (${uname_S},Linux)
6873
DEFINES+=-DINOTIFY_ENABLED

src/config/global-config.c

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,11 @@ int Read_Global(XML_NODE node, void *configp, void *mailp)
123123
const char *xml_heloserver = "helo_server";
124124
const char *xml_mailmaxperhour = "email_maxperhour";
125125

126+
const char *xml_auth_smtp = "auth_smtp";
127+
const char *xml_smtp_user = "smtp_user";
128+
const char *xml_smtp_pass = "smtp_password";
129+
const char *xml_secure_smtp = "secure_smtp";
130+
126131
#ifdef LIBGEOIP_ENABLED
127132
const char *xml_geoip_db_path = "geoip_db_path";
128133
const char *xml_geoip6_db_path = "geoip6_db_path";
@@ -206,6 +211,42 @@ int Read_Global(XML_NODE node, void *configp, void *mailp)
206211
return (OS_INVALID);
207212
}
208213
}
214+
/* SMTP Authentication */
215+
else if(strcmp(node[i]->element, xml_auth_smtp) == 0)
216+
{
217+
if (strcmp(node[i]->content, "yes") == 0)
218+
{
219+
if (Config) Config->authsmtp = 1;
220+
if (Mail) Mail->authsmtp = 1;
221+
}
222+
else if(strcmp(node[i]->content, "no") == 0)
223+
{
224+
if (Config) Config->authsmtp = 0;
225+
if (Mail) Mail->authsmtp = 0;
226+
}
227+
else
228+
{
229+
return(OS_INVALID);
230+
}
231+
}
232+
/* Secure SMTP (SSL) */
233+
else if(strcmp(node[i]->element, xml_secure_smtp) == 0)
234+
{
235+
if (strcmp(node[i]->content, "yes") == 0)
236+
{
237+
if (Config) Config->securesmtp = 1;
238+
if (Mail) Mail->securesmtp = 1;
239+
}
240+
else if(strcmp(node[i]->content, "no") == 0)
241+
{
242+
if (Config) Config->securesmtp = 0;
243+
if (Mail) Mail->securesmtp = 0;
244+
}
245+
else
246+
{
247+
return(OS_INVALID);
248+
}
249+
}
209250
/* Prelude support */
210251
else if (strcmp(node[i]->element, xml_prelude) == 0) {
211252
if (strcmp(node[i]->content, "yes") == 0) {
@@ -453,17 +494,39 @@ int Read_Global(XML_NODE node, void *configp, void *mailp)
453494
}
454495
os_strdup(node[i]->content, Mail->idsname);
455496
}
497+
} else if(strcmp(node[i]->element, xml_smtp_user) == 0) {
498+
if(Mail && (Mail->authsmtp))
499+
{
500+
if(Mail->smtp_user)
501+
{
502+
free(Mail->smtp_user);
503+
}
504+
os_strdup(node[i]->content, Mail->smtp_user);
505+
}
506+
} else if(strcmp(node[i]->element, xml_smtp_pass) == 0) {
507+
if(Mail && (Mail->authsmtp))
508+
{
509+
if(Mail->smtp_pass)
510+
{
511+
free(Mail->smtp_pass);
512+
}
513+
os_strdup(node[i]->content, Mail->smtp_pass);
514+
}
456515
} else if (strcmp(node[i]->element, xml_smtpserver) == 0) {
457516
#ifndef WIN32
458517
if (Mail && (Mail->mn)) {
459518
if (node[i]->content[0] == '/') {
460519
os_strdup(node[i]->content, Mail->smtpserver);
461520
} else {
521+
#ifdef SENDMAIL_CURL
522+
os_strdup(node[i]->content, Mail->smtpserver);
523+
#else
462524
Mail->smtpserver = OS_GetHost(node[i]->content, 5);
463525
if (!Mail->smtpserver) {
464526
merror(INVALID_SMTP, __local_name, node[i]->content);
465527
return (OS_INVALID);
466528
}
529+
#endif
467530
}
468531
free(Mail->smtpserver);
469532
os_strdup(node[i]->content, Mail->smtpserver);

src/config/global-config.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ typedef struct __Config {
5353
/* Mail alerting */
5454
short int mailnotify;
5555

56+
/* Mail smtp auth */
57+
short int authsmtp;
58+
short int securesmtp;
59+
5660
/* Custom Alert output*/
5761
short int custom_alert_output;
5862
char *custom_alert_output_format;

src/config/mail-config.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ typedef struct _MailConfig {
3535
char *smtpserver;
3636
char *heloserver;
3737

38+
/* auth smtp options */
39+
int authsmtp;
40+
char *smtp_user;
41+
char *smtp_pass;
42+
int securesmtp;
43+
3844
/* Granular e-mail options */
3945
unsigned int *gran_level;
4046
unsigned int **gran_id;

src/monitord/main.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ int main(int argc, char **argv)
145145
mond.emailidsname = OS_GetOneContentforElement(&xml, xml_idsname);
146146

147147
if (tmpsmtp && mond.emailfrom) {
148+
#ifndef SENDMAIL_CURL
148149
mond.smtpserver = OS_GetHost(tmpsmtp, 5);
149150
if (!mond.smtpserver) {
150151
merror(INVALID_SMTP, ARGV0, tmpsmtp);
@@ -154,6 +155,7 @@ int main(int argc, char **argv)
154155
mond.emailfrom = NULL;
155156
merror("%s: Invalid SMTP server. Disabling email reports.", ARGV0);
156157
}
158+
#endif
157159
} else {
158160
if (tmpsmtp) {
159161
free(tmpsmtp);

src/os_maild/config.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ int MailConf(int test_config, const char *cfgfile, MailConfig *Mail)
3737
Mail->gran_format = NULL;
3838
Mail->groupping = 1;
3939
Mail->strict_checking = 0;
40+
Mail->authsmtp = -1;
41+
Mail->smtp_user = NULL;
42+
Mail->smtp_pass = NULL;
43+
Mail->securesmtp = 0;
44+
4045
#ifdef LIBGEOIP_ENABLED
4146
Mail->geoip = 0;
4247
#endif

0 commit comments

Comments
 (0)