check_smtp.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744
  1. /******************************************************************************
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License as published by
  4. the Free Software Foundation; either version 2 of the License, or
  5. (at your option) any later version.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. GNU General Public License for more details.
  10. You should have received a copy of the GNU General Public License
  11. along with this program; if not, write to the Free Software
  12. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  13. $Id$
  14. ******************************************************************************/
  15. const char *progname = "check_smtp";
  16. const char *revision = "$Revision$";
  17. const char *copyright = "2000-2004";
  18. const char *email = "nagiosplug-devel@lists.sourceforge.net";
  19. #include "common.h"
  20. #include "netutils.h"
  21. #include "utils.h"
  22. #ifdef HAVE_SSL
  23. int check_cert = FALSE;
  24. int days_till_exp;
  25. # define my_recv(buf, len) ((use_ssl && ssl_established) ? np_net_ssl_read(buf, len) : read(sd, buf, len))
  26. # define my_send(buf, len) ((use_ssl && ssl_established) ? np_net_ssl_write(buf, len) : send(sd, buf, len, 0))
  27. #else /* ifndef HAVE_SSL */
  28. # define my_recv(buf, len) read(sd, buf, len)
  29. # define my_send(buf, len) send(sd, buf, len, 0)
  30. #endif
  31. enum {
  32. SMTP_PORT = 25
  33. };
  34. #define SMTP_EXPECT "220"
  35. #define SMTP_HELO "HELO "
  36. #define SMTP_EHLO "EHLO "
  37. #define SMTP_QUIT "QUIT\r\n"
  38. #define SMTP_STARTTLS "STARTTLS\r\n"
  39. #define SMTP_AUTH_LOGIN "AUTH LOGIN\r\n"
  40. #ifndef HOST_MAX_BYTES
  41. #define HOST_MAX_BYTES 255
  42. #endif
  43. #define EHLO_SUPPORTS_STARTTLS 1
  44. int process_arguments (int, char **);
  45. int validate_arguments (void);
  46. void print_help (void);
  47. void print_usage (void);
  48. int my_close(void);
  49. #include "regex.h"
  50. char regex_expect[MAX_INPUT_BUFFER] = "";
  51. regex_t preg;
  52. regmatch_t pmatch[10];
  53. char timestamp[20] = "";
  54. char errbuf[MAX_INPUT_BUFFER];
  55. int cflags = REG_EXTENDED | REG_NOSUB | REG_NEWLINE;
  56. int eflags = 0;
  57. int errcode, excode;
  58. int server_port = SMTP_PORT;
  59. char *server_address = NULL;
  60. char *server_expect = NULL;
  61. int smtp_use_dummycmd = 0;
  62. char *mail_command = NULL;
  63. char *from_arg = NULL;
  64. int ncommands=0;
  65. int command_size=0;
  66. int nresponses=0;
  67. int response_size=0;
  68. char **commands = NULL;
  69. char **responses = NULL;
  70. char *authtype = NULL;
  71. char *authuser = NULL;
  72. char *authpass = NULL;
  73. int warning_time = 0;
  74. int check_warning_time = FALSE;
  75. int critical_time = 0;
  76. int check_critical_time = FALSE;
  77. int verbose = 0;
  78. int use_ssl = FALSE;
  79. short use_ehlo = FALSE;
  80. short ssl_established = 0;
  81. char *localhostname = NULL;
  82. int sd;
  83. char buffer[MAX_INPUT_BUFFER];
  84. enum {
  85. TCP_PROTOCOL = 1,
  86. UDP_PROTOCOL = 2,
  87. MAXBUF = 1024
  88. };
  89. /* written by lauri alanko */
  90. static char *
  91. base64 (const char *bin, size_t len)
  92. {
  93. char *buf = (char *) malloc ((len + 2) / 3 * 4 + 1);
  94. size_t i = 0, j = 0;
  95. char BASE64_END = '=';
  96. char base64_table[64];
  97. strncpy (base64_table, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", 64);
  98. while (j < len - 2) {
  99. buf[i++] = base64_table[bin[j] >> 2];
  100. buf[i++] = base64_table[((bin[j] & 3) << 4) | (bin[j + 1] >> 4)];
  101. buf[i++] = base64_table[((bin[j + 1] & 15) << 2) | (bin[j + 2] >> 6)];
  102. buf[i++] = base64_table[bin[j + 2] & 63];
  103. j += 3;
  104. }
  105. switch (len - j) {
  106. case 1:
  107. buf[i++] = base64_table[bin[j] >> 2];
  108. buf[i++] = base64_table[(bin[j] & 3) << 4];
  109. buf[i++] = BASE64_END;
  110. buf[i++] = BASE64_END;
  111. break;
  112. case 2:
  113. buf[i++] = base64_table[bin[j] >> 2];
  114. buf[i++] = base64_table[((bin[j] & 3) << 4) | (bin[j + 1] >> 4)];
  115. buf[i++] = base64_table[(bin[j + 1] & 15) << 2];
  116. buf[i++] = BASE64_END;
  117. break;
  118. case 0:
  119. break;
  120. }
  121. buf[i] = '\0';
  122. return buf;
  123. }
  124. int
  125. main (int argc, char **argv)
  126. {
  127. short supports_tls=FALSE;
  128. int n = 0;
  129. double elapsed_time;
  130. long microsec;
  131. int result = STATE_UNKNOWN;
  132. char *cmd_str = NULL;
  133. char *helocmd = NULL;
  134. char *error_msg = NULL;
  135. struct timeval tv;
  136. struct hostent *hp;
  137. setlocale (LC_ALL, "");
  138. bindtextdomain (PACKAGE, LOCALEDIR);
  139. textdomain (PACKAGE);
  140. if (process_arguments (argc, argv) == ERROR)
  141. usage4 (_("Could not parse arguments"));
  142. /* initialize the HELO command with the localhostname */
  143. if(! localhostname){
  144. localhostname = malloc (HOST_MAX_BYTES);
  145. if(!localhostname){
  146. printf(_("malloc() failed!\n"));
  147. return STATE_CRITICAL;
  148. }
  149. if(gethostname(localhostname, HOST_MAX_BYTES)){
  150. printf(_("gethostname() failed!\n"));
  151. return STATE_CRITICAL;
  152. }
  153. hp = gethostbyname(localhostname);
  154. if(!hp) helocmd = localhostname;
  155. else helocmd = hp->h_name;
  156. } else {
  157. helocmd = localhostname;
  158. }
  159. if(use_ehlo)
  160. asprintf (&helocmd, "%s%s%s", SMTP_EHLO, helocmd, "\r\n");
  161. else
  162. asprintf (&helocmd, "%s%s%s", SMTP_HELO, helocmd, "\r\n");
  163. /* initialize the MAIL command with optional FROM command */
  164. asprintf (&cmd_str, "%sFROM: %s%s", mail_command, from_arg, "\r\n");
  165. if (verbose && smtp_use_dummycmd)
  166. printf ("FROM CMD: %s", cmd_str);
  167. /* initialize alarm signal handling */
  168. (void) signal (SIGALRM, socket_timeout_alarm_handler);
  169. /* set socket timeout */
  170. (void) alarm (socket_timeout);
  171. /* start timer */
  172. gettimeofday (&tv, NULL);
  173. /* try to connect to the host at the given port number */
  174. result = my_tcp_connect (server_address, server_port, &sd);
  175. if (result == STATE_OK) { /* we connected */
  176. /* watch for the SMTP connection string and */
  177. /* return a WARNING status if we couldn't read any data */
  178. if (recv (sd, buffer, MAX_INPUT_BUFFER - 1, 0) == -1) {
  179. printf (_("recv() failed\n"));
  180. result = STATE_WARNING;
  181. }
  182. else {
  183. if (verbose)
  184. printf ("%s", buffer);
  185. /* strip the buffer of carriage returns */
  186. strip (buffer);
  187. /* make sure we find the response we are looking for */
  188. if (!strstr (buffer, server_expect)) {
  189. if (server_port == SMTP_PORT)
  190. printf (_("Invalid SMTP response received from host\n"));
  191. else
  192. printf (_("Invalid SMTP response received from host on port %d\n"),
  193. server_port);
  194. result = STATE_WARNING;
  195. }
  196. }
  197. /* send the HELO/EHLO command */
  198. send(sd, helocmd, strlen(helocmd), 0);
  199. /* allow for response to helo command to reach us */
  200. if(read (sd, buffer, MAXBUF - 1) < 0){
  201. printf (_("recv() failed\n"));
  202. return STATE_WARNING;
  203. } else if(use_ehlo){
  204. buffer[MAXBUF-1]='\0';
  205. if(strstr(buffer, "250 STARTTLS") != NULL ||
  206. strstr(buffer, "250-STARTTLS") != NULL){
  207. supports_tls=TRUE;
  208. }
  209. }
  210. if(use_ssl && ! supports_tls){
  211. printf(_("WARNING - TLS not supported by server\n"));
  212. send (sd, SMTP_QUIT, strlen (SMTP_QUIT), 0);
  213. return STATE_WARNING;
  214. }
  215. #ifdef HAVE_SSL
  216. if(use_ssl) {
  217. /* send the STARTTLS command */
  218. send(sd, SMTP_STARTTLS, strlen(SMTP_STARTTLS), 0);
  219. recv(sd,buffer, MAX_INPUT_BUFFER-1, 0); /* wait for it */
  220. if (!strstr (buffer, server_expect)) {
  221. printf (_("Server does not support STARTTLS\n"));
  222. send (sd, SMTP_QUIT, strlen (SMTP_QUIT), 0);
  223. return STATE_UNKNOWN;
  224. }
  225. result = np_net_ssl_init(sd);
  226. if(result != STATE_OK) {
  227. printf (_("CRITICAL - Cannot create SSL context.\n"));
  228. np_net_ssl_cleanup();
  229. close(sd);
  230. return STATE_CRITICAL;
  231. } else {
  232. ssl_established = 1;
  233. }
  234. # ifdef USE_OPENSSL
  235. if ( check_cert ) {
  236. result = np_net_ssl_check_cert(days_till_exp);
  237. if(result != STATE_OK){
  238. printf (_("CRITICAL - Cannot retrieve server certificate.\n"));
  239. }
  240. my_close();
  241. return result;
  242. }
  243. # endif /* USE_OPENSSL */
  244. }
  245. #endif
  246. /* sendmail will syslog a "NOQUEUE" error if session does not attempt
  247. * to do something useful. This can be prevented by giving a command
  248. * even if syntax is illegal (MAIL requires a FROM:<...> argument)
  249. *
  250. * According to rfc821 you can include a null reversepath in the from command
  251. * - but a log message is generated on the smtp server.
  252. *
  253. * You can disable sending mail_command with '--nocommand'
  254. * Use the -f option to provide a FROM address
  255. */
  256. if (smtp_use_dummycmd) {
  257. my_send(cmd_str, strlen(cmd_str));
  258. my_recv(buffer, MAX_INPUT_BUFFER-1);
  259. if (verbose)
  260. printf("%s", buffer);
  261. }
  262. while (n < ncommands) {
  263. asprintf (&cmd_str, "%s%s", commands[n], "\r\n");
  264. my_send(cmd_str, strlen(cmd_str));
  265. my_recv(buffer, MAX_INPUT_BUFFER-1);
  266. if (verbose)
  267. printf("%s", buffer);
  268. strip (buffer);
  269. if (n < nresponses) {
  270. cflags |= REG_EXTENDED | REG_NOSUB | REG_NEWLINE;
  271. errcode = regcomp (&preg, responses[n], cflags);
  272. if (errcode != 0) {
  273. regerror (errcode, &preg, errbuf, MAX_INPUT_BUFFER);
  274. printf (_("Could Not Compile Regular Expression"));
  275. return ERROR;
  276. }
  277. excode = regexec (&preg, buffer, 10, pmatch, eflags);
  278. if (excode == 0) {
  279. result = STATE_OK;
  280. }
  281. else if (excode == REG_NOMATCH) {
  282. result = STATE_WARNING;
  283. printf (_("SMTP %s - Invalid response '%s' to command '%s'\n"), state_text (result), buffer, commands[n]);
  284. }
  285. else {
  286. regerror (excode, &preg, errbuf, MAX_INPUT_BUFFER);
  287. printf (_("Execute Error: %s\n"), errbuf);
  288. result = STATE_UNKNOWN;
  289. }
  290. }
  291. n++;
  292. }
  293. if (authtype != NULL) {
  294. if (strcmp (authtype, "LOGIN") == 0) {
  295. char *abuf;
  296. int ret;
  297. do {
  298. if (authuser == NULL) {
  299. result = STATE_CRITICAL;
  300. error_msg = _("no authuser specified, ");
  301. break;
  302. }
  303. if (authpass == NULL) {
  304. result = STATE_CRITICAL;
  305. error_msg = _("no authpass specified, ");
  306. break;
  307. }
  308. /* send AUTH LOGIN */
  309. my_send(SMTP_AUTH_LOGIN, strlen(SMTP_AUTH_LOGIN));
  310. if (verbose)
  311. printf (_("sent %s\n"), "AUTH LOGIN");
  312. if((ret = my_recv(buffer, MAXBUF - 1)) < 0){
  313. error_msg = _("recv() failed after AUTH LOGIN, \n");
  314. result = STATE_WARNING;
  315. break;
  316. }
  317. buffer[ret] = 0;
  318. if (verbose)
  319. printf (_("received %s\n"), buffer);
  320. if (strncmp (buffer, "334", 3) != 0) {
  321. result = STATE_CRITICAL;
  322. error_msg = _("invalid response received after AUTH LOGIN, ");
  323. break;
  324. }
  325. /* encode authuser with base64 */
  326. abuf = base64 (authuser, strlen(authuser));
  327. strcat (abuf, "\r\n");
  328. my_send(abuf, strlen(abuf));
  329. if (verbose)
  330. printf (_("sent %s\n"), abuf);
  331. if ((ret = my_recv(buffer, MAX_INPUT_BUFFER-1)) == -1) {
  332. result = STATE_CRITICAL;
  333. error_msg = _("recv() failed after sending authuser, ");
  334. break;
  335. }
  336. buffer[ret] = 0;
  337. if (verbose) {
  338. printf (_("received %s\n"), buffer);
  339. }
  340. if (strncmp (buffer, "334", 3) != 0) {
  341. result = STATE_CRITICAL;
  342. error_msg = _("invalid response received after authuser, ");
  343. break;
  344. }
  345. /* encode authpass with base64 */
  346. abuf = base64 (authpass, strlen(authpass));
  347. strcat (abuf, "\r\n");
  348. my_send(abuf, strlen(abuf));
  349. if (verbose) {
  350. printf (_("sent %s\n"), abuf);
  351. }
  352. if ((ret = my_recv(buffer, MAX_INPUT_BUFFER-1)) == -1) {
  353. result = STATE_CRITICAL;
  354. error_msg = _("recv() failed after sending authpass, ");
  355. break;
  356. }
  357. buffer[ret] = 0;
  358. if (verbose) {
  359. printf (_("received %s\n"), buffer);
  360. }
  361. if (strncmp (buffer, "235", 3) != 0) {
  362. result = STATE_CRITICAL;
  363. error_msg = _("invalid response received after authpass, ");
  364. break;
  365. }
  366. break;
  367. } while (0);
  368. } else {
  369. result = STATE_CRITICAL;
  370. error_msg = _("only authtype LOGIN is supported, ");
  371. }
  372. }
  373. /* tell the server we're done */
  374. my_send (SMTP_QUIT, strlen (SMTP_QUIT));
  375. /* finally close the connection */
  376. close (sd);
  377. }
  378. /* reset the alarm */
  379. alarm (0);
  380. microsec = deltime (tv);
  381. elapsed_time = (double)microsec / 1.0e6;
  382. if (result == STATE_OK) {
  383. if (check_critical_time && elapsed_time > (double) critical_time)
  384. result = STATE_CRITICAL;
  385. else if (check_warning_time && elapsed_time > (double) warning_time)
  386. result = STATE_WARNING;
  387. }
  388. printf (_("SMTP %s - %s%.3f sec. response time%s%s|%s\n"),
  389. state_text (result),
  390. (error_msg == NULL ? "" : error_msg),
  391. elapsed_time,
  392. verbose?", ":"", verbose?buffer:"",
  393. fperfdata ("time", elapsed_time, "s",
  394. (int)check_warning_time, warning_time,
  395. (int)check_critical_time, critical_time,
  396. TRUE, 0, FALSE, 0));
  397. return result;
  398. }
  399. /* process command-line arguments */
  400. int
  401. process_arguments (int argc, char **argv)
  402. {
  403. int c;
  404. int option = 0;
  405. static struct option longopts[] = {
  406. {"hostname", required_argument, 0, 'H'},
  407. {"expect", required_argument, 0, 'e'},
  408. {"critical", required_argument, 0, 'c'},
  409. {"warning", required_argument, 0, 'w'},
  410. {"timeout", required_argument, 0, 't'},
  411. {"port", required_argument, 0, 'p'},
  412. {"from", required_argument, 0, 'f'},
  413. {"fqdn", required_argument, 0, 'F'},
  414. {"authtype", required_argument, 0, 'A'},
  415. {"authuser", required_argument, 0, 'U'},
  416. {"authpass", required_argument, 0, 'P'},
  417. {"command", required_argument, 0, 'C'},
  418. {"response", required_argument, 0, 'R'},
  419. {"nocommand", required_argument, 0, 'n'},
  420. {"verbose", no_argument, 0, 'v'},
  421. {"version", no_argument, 0, 'V'},
  422. {"use-ipv4", no_argument, 0, '4'},
  423. {"use-ipv6", no_argument, 0, '6'},
  424. {"help", no_argument, 0, 'h'},
  425. {"starttls",no_argument,0,'S'},
  426. {"certificate",required_argument,0,'D'},
  427. {0, 0, 0, 0}
  428. };
  429. if (argc < 2)
  430. return ERROR;
  431. for (c = 1; c < argc; c++) {
  432. if (strcmp ("-to", argv[c]) == 0)
  433. strcpy (argv[c], "-t");
  434. else if (strcmp ("-wt", argv[c]) == 0)
  435. strcpy (argv[c], "-w");
  436. else if (strcmp ("-ct", argv[c]) == 0)
  437. strcpy (argv[c], "-c");
  438. }
  439. while (1) {
  440. c = getopt_long (argc, argv, "+hVv46t:p:f:e:c:w:H:C:R:SD:F:A:U:P:",
  441. longopts, &option);
  442. if (c == -1 || c == EOF)
  443. break;
  444. switch (c) {
  445. case 'H': /* hostname */
  446. if (is_host (optarg)) {
  447. server_address = optarg;
  448. }
  449. else {
  450. usage2 (_("Invalid hostname/address"), optarg);
  451. }
  452. break;
  453. case 'p': /* port */
  454. if (is_intpos (optarg))
  455. server_port = atoi (optarg);
  456. else
  457. usage4 (_("Port must be a positive integer"));
  458. break;
  459. case 'F':
  460. /* localhostname */
  461. localhostname = strdup(optarg);
  462. break;
  463. case 'f': /* from argument */
  464. from_arg = optarg;
  465. smtp_use_dummycmd = 1;
  466. break;
  467. case 'A':
  468. authtype = optarg;
  469. break;
  470. case 'U':
  471. authuser = optarg;
  472. break;
  473. case 'P':
  474. authpass = optarg;
  475. break;
  476. case 'e': /* server expect string on 220 */
  477. server_expect = optarg;
  478. break;
  479. case 'C': /* commands */
  480. if (ncommands >= command_size) {
  481. commands = realloc (commands, command_size+8);
  482. if (commands == NULL)
  483. die (STATE_UNKNOWN,
  484. _("Could not realloc() units [%d]\n"), ncommands);
  485. }
  486. commands[ncommands] = optarg;
  487. ncommands++;
  488. break;
  489. case 'R': /* server responses */
  490. if (nresponses >= response_size) {
  491. responses = realloc (responses, response_size+8);
  492. if (responses == NULL)
  493. die (STATE_UNKNOWN,
  494. _("Could not realloc() units [%d]\n"), nresponses);
  495. }
  496. responses[nresponses] = optarg;
  497. nresponses++;
  498. break;
  499. case 'c': /* critical time threshold */
  500. if (is_intnonneg (optarg)) {
  501. critical_time = atoi (optarg);
  502. check_critical_time = TRUE;
  503. }
  504. else {
  505. usage4 (_("Critical time must be a positive integer"));
  506. }
  507. break;
  508. case 'w': /* warning time threshold */
  509. if (is_intnonneg (optarg)) {
  510. warning_time = atoi (optarg);
  511. check_warning_time = TRUE;
  512. }
  513. else {
  514. usage4 (_("Warning time must be a positive integer"));
  515. }
  516. break;
  517. case 'v': /* verbose */
  518. verbose++;
  519. break;
  520. case 't': /* timeout */
  521. if (is_intnonneg (optarg)) {
  522. socket_timeout = atoi (optarg);
  523. }
  524. else {
  525. usage4 (_("Timeout interval must be a positive integer"));
  526. }
  527. break;
  528. case 'S':
  529. /* starttls */
  530. use_ssl = TRUE;
  531. use_ehlo = TRUE;
  532. break;
  533. case 'D':
  534. /* Check SSL cert validity */
  535. #ifdef USE_OPENSSL
  536. if (!is_intnonneg (optarg))
  537. usage2 ("Invalid certificate expiration period",optarg);
  538. days_till_exp = atoi (optarg);
  539. check_cert = TRUE;
  540. #else
  541. usage (_("SSL support not available - install OpenSSL and recompile"));
  542. #endif
  543. break;
  544. case '4':
  545. address_family = AF_INET;
  546. break;
  547. case '6':
  548. #ifdef USE_IPV6
  549. address_family = AF_INET6;
  550. #else
  551. usage4 (_("IPv6 support not available"));
  552. #endif
  553. break;
  554. case 'V': /* version */
  555. print_revision (progname, revision);
  556. exit (STATE_OK);
  557. case 'h': /* help */
  558. print_help ();
  559. exit (STATE_OK);
  560. case '?': /* help */
  561. usage2 (_("Unknown argument"), optarg);
  562. }
  563. }
  564. c = optind;
  565. if (server_address == NULL) {
  566. if (argv[c]) {
  567. if (is_host (argv[c]))
  568. server_address = argv[c];
  569. else
  570. usage2 (_("Invalid hostname/address"), argv[c]);
  571. }
  572. else {
  573. asprintf (&server_address, "127.0.0.1");
  574. }
  575. }
  576. if (server_expect == NULL)
  577. server_expect = strdup (SMTP_EXPECT);
  578. if (mail_command == NULL)
  579. mail_command = strdup("MAIL ");
  580. if (from_arg==NULL)
  581. from_arg = strdup(" ");
  582. return validate_arguments ();
  583. }
  584. int
  585. validate_arguments (void)
  586. {
  587. return OK;
  588. }
  589. void
  590. print_help (void)
  591. {
  592. char *myport;
  593. asprintf (&myport, "%d", SMTP_PORT);
  594. print_revision (progname, revision);
  595. printf ("Copyright (c) 1999-2001 Ethan Galstad <nagios@nagios.org>\n");
  596. printf (COPYRIGHT, copyright, email);
  597. printf(_("This plugin will attempt to open an SMTP connection with the host.\n\n"));
  598. print_usage ();
  599. printf (_(UT_HELP_VRSN));
  600. printf (_(UT_HOST_PORT), 'p', myport);
  601. printf (_(UT_IPv46));
  602. printf (_("\
  603. -e, --expect=STRING\n\
  604. String to expect in first line of server response (default: '%s')\n\
  605. -n, nocommand\n\
  606. Suppress SMTP command\n\
  607. -C, --command=STRING\n\
  608. SMTP command (may be used repeatedly)\n\
  609. -R, --command=STRING\n\
  610. Expected response to command (may be used repeatedly)\n\
  611. -f, --from=STRING\n\
  612. FROM-address to include in MAIL command, required by Exchange 2000\n"),
  613. SMTP_EXPECT);
  614. #ifdef HAVE_SSL
  615. printf (_("\
  616. -D, --certificate=INTEGER\n\
  617. Minimum number of days a certificate has to be valid.\n\
  618. -S, --starttls\n\
  619. Use STARTTLS for the connection.\n"));
  620. #endif
  621. printf("\
  622. -A, --authtype=STRING\n\
  623. SMTP AUTH type to check (default none, only LOGIN supported)\n\
  624. -U, --authuser=STRING\n\
  625. SMTP AUTH username\n\
  626. -P, --authpass=STRING\n\
  627. SMTP AUTH password\n\
  628. ");
  629. printf (_(UT_WARN_CRIT));
  630. printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT);
  631. printf (_(UT_VERBOSE));
  632. printf(_("\n\
  633. Successul connects return STATE_OK, refusals and timeouts return\n\
  634. STATE_CRITICAL, other errors return STATE_UNKNOWN. Successful\n\
  635. connects, but incorrect reponse messages from the host result in\n\
  636. STATE_WARNING return values.\n"));
  637. printf (_(UT_SUPPORT));
  638. }
  639. void
  640. print_usage (void)
  641. {
  642. printf ("\
  643. Usage: %s -H host [-p port] [-e expect] [-C command] [-f from addr]\n\
  644. [-A authtype -U authuser -P authpass]\n\
  645. [-w warn] [-c crit] [-t timeout] [-S] [-D days] [-n] [-v] [-4|-6]\n", progname);
  646. }
  647. int
  648. my_close (void)
  649. {
  650. #ifdef HAVE_SSL
  651. np_net_ssl_cleanup();
  652. #endif
  653. return close(sd);
  654. }