mci.c (159613) | mci.c (168520) |
---|---|
1/* 2 * Copyright (c) 1998-2005 Sendmail, Inc. and its suppliers. 3 * All rights reserved. 4 * Copyright (c) 1995-1997 Eric P. Allman. All rights reserved. 5 * Copyright (c) 1988, 1993 6 * The Regents of the University of California. All rights reserved. 7 * 8 * By using this file, you agree to the terms and conditions set 9 * forth in the LICENSE file which can be found at the top level of 10 * the sendmail distribution. 11 * | 1/* 2 * Copyright (c) 1998-2005 Sendmail, Inc. and its suppliers. 3 * All rights reserved. 4 * Copyright (c) 1995-1997 Eric P. Allman. All rights reserved. 5 * Copyright (c) 1988, 1993 6 * The Regents of the University of California. All rights reserved. 7 * 8 * By using this file, you agree to the terms and conditions set 9 * forth in the LICENSE file which can be found at the top level of 10 * the sendmail distribution. 11 * |
12 * $FreeBSD: head/contrib/sendmail/src/mci.c 159613 2006-06-14 16:25:31Z gshapiro $ | 12 * $FreeBSD: head/contrib/sendmail/src/mci.c 168520 2007-04-09 01:44:16Z gshapiro $ |
13 */ 14 15#include <sendmail.h> 16 | 13 */ 14 15#include <sendmail.h> 16 |
17SM_RCSID("@(#)$Id: mci.c,v 8.217 2006/04/18 01:27:36 ca Exp $") | 17SM_RCSID("@(#)$Id: mci.c,v 8.218 2006/08/15 23:24:57 ca Exp $") |
18 19#if NETINET || NETINET6 20# include <arpa/inet.h> 21#endif /* NETINET || NETINET6 */ 22 23#include <dirent.h> 24 25static int mci_generate_persistent_path __P((const char *, char *, --- 110 unchanged lines hidden (view full) --- 136 { 137 /* we don't support caching */ 138 return NULL; 139 } 140 141 if (MciCache == NULL) 142 { 143 /* first call */ | 18 19#if NETINET || NETINET6 20# include <arpa/inet.h> 21#endif /* NETINET || NETINET6 */ 22 23#include <dirent.h> 24 25static int mci_generate_persistent_path __P((const char *, char *, --- 110 unchanged lines hidden (view full) --- 136 { 137 /* we don't support caching */ 138 return NULL; 139 } 140 141 if (MciCache == NULL) 142 { 143 /* first call */ |
144 MciCache = (MCI **) sm_pmalloc_x(MaxMciCache * sizeof *MciCache); 145 memset((char *) MciCache, '\0', MaxMciCache * sizeof *MciCache); | 144 MciCache = (MCI **) sm_pmalloc_x(MaxMciCache * sizeof(*MciCache)); 145 memset((char *) MciCache, '\0', MaxMciCache * sizeof(*MciCache)); |
146 return &MciCache[0]; 147 } 148 149 now = curtime(); 150 bestmci = &MciCache[0]; 151 for (i = 0; i < MaxMciCache; i++) 152 { 153 mci = MciCache[i]; --- 151 unchanged lines hidden (view full) --- 305 char *host; 306 MAILER *m; 307{ 308 register MCI *mci; 309 register STAB *s; 310 extern SOCKADDR CurHostAddr; 311 312 /* clear CurHostAddr so we don't get a bogus address with this name */ | 146 return &MciCache[0]; 147 } 148 149 now = curtime(); 150 bestmci = &MciCache[0]; 151 for (i = 0; i < MaxMciCache; i++) 152 { 153 mci = MciCache[i]; --- 151 unchanged lines hidden (view full) --- 305 char *host; 306 MAILER *m; 307{ 308 register MCI *mci; 309 register STAB *s; 310 extern SOCKADDR CurHostAddr; 311 312 /* clear CurHostAddr so we don't get a bogus address with this name */ |
313 memset(&CurHostAddr, '\0', sizeof CurHostAddr); | 313 memset(&CurHostAddr, '\0', sizeof(CurHostAddr)); |
314 315 /* clear out any expired connections */ 316 (void) mci_scan(NULL); 317 318 if (m->m_mno < 0) 319 syserr("!negative mno %d (%s)", m->m_mno, m->m_name); 320 321 s = stab(host, ST_MCI + m->m_mno, ST_ENTER); --- 48 unchanged lines hidden (view full) --- 370 mci->mci_errno = 0; 371 mci->mci_exitstat = EX_OK; 372 mci->mci_state = MCIS_CLOSED; 373 } 374 else 375 { 376 /* get peer host address */ 377 /* (this should really be in the mci struct) */ | 314 315 /* clear out any expired connections */ 316 (void) mci_scan(NULL); 317 318 if (m->m_mno < 0) 319 syserr("!negative mno %d (%s)", m->m_mno, m->m_name); 320 321 s = stab(host, ST_MCI + m->m_mno, ST_ENTER); --- 48 unchanged lines hidden (view full) --- 370 mci->mci_errno = 0; 371 mci->mci_exitstat = EX_OK; 372 mci->mci_state = MCIS_CLOSED; 373 } 374 else 375 { 376 /* get peer host address */ 377 /* (this should really be in the mci struct) */ |
378 SOCKADDR_LEN_T socklen = sizeof CurHostAddr; | 378 SOCKADDR_LEN_T socklen = sizeof(CurHostAddr); |
379 380 (void) getpeername(sm_io_getinfo(mci->mci_in, 381 SM_IO_WHAT_FD, NULL), 382 (struct sockaddr *) &CurHostAddr, &socklen); 383 } 384 } 385 if (mci->mci_state == MCIS_CLOSED) 386 { --- 73 unchanged lines hidden (view full) --- 460 461MCI * 462mci_new(rpool) 463 SM_RPOOL_T *rpool; 464{ 465 register MCI *mci; 466 467 if (rpool == NULL) | 379 380 (void) getpeername(sm_io_getinfo(mci->mci_in, 381 SM_IO_WHAT_FD, NULL), 382 (struct sockaddr *) &CurHostAddr, &socklen); 383 } 384 } 385 if (mci->mci_state == MCIS_CLOSED) 386 { --- 73 unchanged lines hidden (view full) --- 460 461MCI * 462mci_new(rpool) 463 SM_RPOOL_T *rpool; 464{ 465 register MCI *mci; 466 467 if (rpool == NULL) |
468 mci = (MCI *) sm_malloc_x(sizeof *mci); | 468 mci = (MCI *) sm_malloc_x(sizeof(*mci)); |
469 else | 469 else |
470 mci = (MCI *) sm_rpool_malloc_x(rpool, sizeof *mci); 471 memset((char *) mci, '\0', sizeof *mci); | 470 mci = (MCI *) sm_rpool_malloc_x(rpool, sizeof(*mci)); 471 memset((char *) mci, '\0', sizeof(*mci)); |
472 mci->mci_rpool = sm_rpool_new_x(NULL); 473 mci->mci_macro.mac_rpool = mci->mci_rpool; 474 return mci; 475} 476/* 477** MCI_MATCH -- check connection cache for a particular host 478** 479** Parameters: --- 242 unchanged lines hidden (view full) --- 722 723 if (HostStatDir == NULL || mci->mci_host == NULL) 724 return EX_OK; 725 726 if (tTd(56, 2)) 727 sm_dprintf("mci_lock_host: attempting to lock %s\n", 728 mci->mci_host); 729 | 472 mci->mci_rpool = sm_rpool_new_x(NULL); 473 mci->mci_macro.mac_rpool = mci->mci_rpool; 474 return mci; 475} 476/* 477** MCI_MATCH -- check connection cache for a particular host 478** 479** Parameters: --- 242 unchanged lines hidden (view full) --- 722 723 if (HostStatDir == NULL || mci->mci_host == NULL) 724 return EX_OK; 725 726 if (tTd(56, 2)) 727 sm_dprintf("mci_lock_host: attempting to lock %s\n", 728 mci->mci_host); 729 |
730 if (mci_generate_persistent_path(mci->mci_host, fname, sizeof fname, | 730 if (mci_generate_persistent_path(mci->mci_host, fname, sizeof(fname), |
731 true) < 0) 732 { 733 /* of course this should never happen */ 734 if (tTd(56, 2)) 735 sm_dprintf("mci_lock_host: Failed to generate host path for %s\n", 736 mci->mci_host); 737 738 retVal = EX_TEMPFAIL; --- 113 unchanged lines hidden (view full) --- 852 /* Already have the persistent information in memory */ 853 if (SingleThreadDelivery && mci->mci_statfile != NULL) 854 return true; 855 856 if (tTd(56, 1)) 857 sm_dprintf("mci_load_persistent: Attempting to load persistent information for %s\n", 858 mci->mci_host); 859 | 731 true) < 0) 732 { 733 /* of course this should never happen */ 734 if (tTd(56, 2)) 735 sm_dprintf("mci_lock_host: Failed to generate host path for %s\n", 736 mci->mci_host); 737 738 retVal = EX_TEMPFAIL; --- 113 unchanged lines hidden (view full) --- 852 /* Already have the persistent information in memory */ 853 if (SingleThreadDelivery && mci->mci_statfile != NULL) 854 return true; 855 856 if (tTd(56, 1)) 857 sm_dprintf("mci_load_persistent: Attempting to load persistent information for %s\n", 858 mci->mci_host); 859 |
860 if (mci_generate_persistent_path(mci->mci_host, fname, sizeof fname, | 860 if (mci_generate_persistent_path(mci->mci_host, fname, sizeof(fname), |
861 false) < 0) 862 { 863 /* Not much we can do if the file isn't there... */ 864 if (tTd(56, 1)) 865 sm_dprintf("mci_load_persistent: Couldn't generate host path\n"); 866 goto cleanup; 867 } 868 --- 72 unchanged lines hidden (view full) --- 941 } 942 943 SM_FREE_CLR(mci->mci_status); 944 SM_FREE_CLR(mci->mci_rstatus); 945 946 sm_io_rewind(fp, SM_TIME_DEFAULT); 947 ver = -1; 948 LineNumber = 0; | 861 false) < 0) 862 { 863 /* Not much we can do if the file isn't there... */ 864 if (tTd(56, 1)) 865 sm_dprintf("mci_load_persistent: Couldn't generate host path\n"); 866 goto cleanup; 867 } 868 --- 72 unchanged lines hidden (view full) --- 941 } 942 943 SM_FREE_CLR(mci->mci_status); 944 SM_FREE_CLR(mci->mci_rstatus); 945 946 sm_io_rewind(fp, SM_TIME_DEFAULT); 947 ver = -1; 948 LineNumber = 0; |
949 while (sm_io_fgets(fp, SM_TIME_DEFAULT, buf, sizeof buf) != NULL) | 949 while (sm_io_fgets(fp, SM_TIME_DEFAULT, buf, sizeof(buf)) != NULL) |
950 { 951 LineNumber++; 952 p = strchr(buf, '\n'); 953 if (p != NULL) 954 *p = '\0'; 955 switch (buf[0]) 956 { 957 case 'V': /* version stamp */ --- 208 unchanged lines hidden (view full) --- 1166 { 1167 leftone = removedone = false; 1168 while ((e = readdir(d)) != NULL) 1169 { 1170 if (e->d_name[0] == '.') 1171 continue; 1172 1173 (void) sm_strlcpy(newptr, e->d_name, | 950 { 951 LineNumber++; 952 p = strchr(buf, '\n'); 953 if (p != NULL) 954 *p = '\0'; 955 switch (buf[0]) 956 { 957 case 'V': /* version stamp */ --- 208 unchanged lines hidden (view full) --- 1166 { 1167 leftone = removedone = false; 1168 while ((e = readdir(d)) != NULL) 1169 { 1170 if (e->d_name[0] == '.') 1171 continue; 1172 1173 (void) sm_strlcpy(newptr, e->d_name, |
1174 sizeof newpath - | 1174 sizeof(newpath) - |
1175 (newptr - newpath)); 1176 1177 if (StopRequest) 1178 stop_sendmail(); 1179 ret = mci_traverse_persistent(action, newpath); 1180 if (ret < 0) 1181 break; 1182 if (ret == 1) --- 113 unchanged lines hidden (view full) --- 1296 { 1297 if (tTd(56, 1)) 1298 sm_dprintf("mci_print_persistent: cannot open %s: %s\n", 1299 pathname, sm_errstring(errno)); 1300 return 0; 1301 } 1302 1303 FileName = pathname; | 1175 (newptr - newpath)); 1176 1177 if (StopRequest) 1178 stop_sendmail(); 1179 ret = mci_traverse_persistent(action, newpath); 1180 if (ret < 0) 1181 break; 1182 if (ret == 1) --- 113 unchanged lines hidden (view full) --- 1296 { 1297 if (tTd(56, 1)) 1298 sm_dprintf("mci_print_persistent: cannot open %s: %s\n", 1299 pathname, sm_errstring(errno)); 1300 return 0; 1301 } 1302 1303 FileName = pathname; |
1304 memset(&mcib, '\0', sizeof mcib); | 1304 memset(&mcib, '\0', sizeof(mcib)); |
1305 if (mci_read_persistent(fp, &mcib) < 0) 1306 { 1307 syserr("%s: could not read status file", pathname); 1308 (void) sm_io_close(fp, SM_TIME_DEFAULT); 1309 FileName = NULL; 1310 return 0; 1311 } 1312 --- 15 unchanged lines hidden (view full) --- 1328 else if (mcib.mci_exitstat != 0) 1329 { 1330 char *exmsg = sm_sysexmsg(mcib.mci_exitstat); 1331 1332 if (exmsg == NULL) 1333 { 1334 char buf[80]; 1335 | 1305 if (mci_read_persistent(fp, &mcib) < 0) 1306 { 1307 syserr("%s: could not read status file", pathname); 1308 (void) sm_io_close(fp, SM_TIME_DEFAULT); 1309 FileName = NULL; 1310 return 0; 1311 } 1312 --- 15 unchanged lines hidden (view full) --- 1328 else if (mcib.mci_exitstat != 0) 1329 { 1330 char *exmsg = sm_sysexmsg(mcib.mci_exitstat); 1331 1332 if (exmsg == NULL) 1333 { 1334 char buf[80]; 1335 |
1336 (void) sm_snprintf(buf, sizeof buf, | 1336 (void) sm_snprintf(buf, sizeof(buf), |
1337 "Unknown mailer error %d", 1338 mcib.mci_exitstat); 1339 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT, "%.*s\n", 1340 width, buf); 1341 } 1342 else 1343 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT, "%.*s\n", 1344 width, &exmsg[5]); --- 130 unchanged lines hidden (view full) --- 1475 1476 if (tTd(56, 80)) 1477 sm_dprintf("mci_generate_persistent_path(%s): ", host); 1478 1479 if (*host == '\0' || *host == '.') 1480 return -1; 1481 1482 /* make certain this is not a bracketed host number */ | 1337 "Unknown mailer error %d", 1338 mcib.mci_exitstat); 1339 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT, "%.*s\n", 1340 width, buf); 1341 } 1342 else 1343 (void) sm_io_fprintf(smioout, SM_TIME_DEFAULT, "%.*s\n", 1344 width, &exmsg[5]); --- 130 unchanged lines hidden (view full) --- 1475 1476 if (tTd(56, 80)) 1477 sm_dprintf("mci_generate_persistent_path(%s): ", host); 1478 1479 if (*host == '\0' || *host == '.') 1480 return -1; 1481 1482 /* make certain this is not a bracketed host number */ |
1483 if (strlen(host) > sizeof t_host - 1) | 1483 if (strlen(host) > sizeof(t_host) - 1) |
1484 return -1; 1485 if (host[0] == '[') | 1484 return -1; 1485 if (host[0] == '[') |
1486 (void) sm_strlcpy(t_host, host + 1, sizeof t_host); | 1486 (void) sm_strlcpy(t_host, host + 1, sizeof(t_host)); |
1487 else | 1487 else |
1488 (void) sm_strlcpy(t_host, host, sizeof t_host); | 1488 (void) sm_strlcpy(t_host, host, sizeof(t_host)); |
1489 1490 /* 1491 ** Delete any trailing dots from the hostname. 1492 ** Leave 'elem' pointing at the \0. 1493 */ 1494 1495 elem = t_host + strlen(t_host); 1496 while (elem > t_host && --- 66 unchanged lines hidden --- | 1489 1490 /* 1491 ** Delete any trailing dots from the hostname. 1492 ** Leave 'elem' pointing at the \0. 1493 */ 1494 1495 elem = t_host + strlen(t_host); 1496 while (elem > t_host && --- 66 unchanged lines hidden --- |