map.c (141858) | map.c (147078) |
---|---|
1/* | 1/* |
2 * Copyright (c) 1998-2003 Sendmail, Inc. and its suppliers. | 2 * Copyright (c) 1998-2005 Sendmail, Inc. and its suppliers. |
3 * All rights reserved. 4 * Copyright (c) 1992, 1995-1997 Eric P. Allman. All rights reserved. 5 * Copyright (c) 1992, 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 */ 13 14#include <sendmail.h> 15 | 3 * All rights reserved. 4 * Copyright (c) 1992, 1995-1997 Eric P. Allman. All rights reserved. 5 * Copyright (c) 1992, 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 */ 13 14#include <sendmail.h> 15 |
16SM_RCSID("@(#)$Id: map.c,v 8.666 2004/08/17 16:50:19 gshapiro Exp $") | 16SM_RCSID("@(#)$Id: map.c,v 8.669 2005/02/09 01:46:35 ca Exp $") |
17 18#if LDAPMAP 19# include <sm/ldap.h> 20#endif /* LDAPMAP */ 21 22#if NDBM 23# include <ndbm.h> 24# ifdef R_FIRST --- 5627 unchanged lines hidden (view full) --- 5652{ 5653 register STAB *s; 5654 5655 if (tTd(38, 20)) 5656 sm_dprintf("stab_lookup(%s, %s)\n", 5657 map->map_mname, name); 5658 5659 s = stab(name, ST_ALIAS, ST_FIND); | 17 18#if LDAPMAP 19# include <sm/ldap.h> 20#endif /* LDAPMAP */ 21 22#if NDBM 23# include <ndbm.h> 24# ifdef R_FIRST --- 5627 unchanged lines hidden (view full) --- 5652{ 5653 register STAB *s; 5654 5655 if (tTd(38, 20)) 5656 sm_dprintf("stab_lookup(%s, %s)\n", 5657 map->map_mname, name); 5658 5659 s = stab(name, ST_ALIAS, ST_FIND); |
5660 if (s != NULL) 5661 return s->s_alias; 5662 return NULL; | 5660 if (s == NULL) 5661 return NULL; 5662 if (bitset(MF_MATCHONLY, map->map_mflags)) 5663 return map_rewrite(map, name, strlen(name), NULL); 5664 else 5665 return map_rewrite(map, s->s_alias, strlen(s->s_alias), av); |
5663} 5664 | 5666} 5667 |
5665 | |
5666/* 5667** STAB_MAP_STORE -- store in symtab (actually using during init, not rebuild) 5668*/ 5669 5670void 5671stab_map_store(map, lhs, rhs) 5672 register MAP *map; 5673 char *lhs; --- 1875 unchanged lines hidden (view full) --- 7549char * 7550socket_map_lookup(map, name, av, statp) 7551 MAP *map; 7552 char *name; 7553 char **av; 7554 int *statp; 7555{ 7556 unsigned int nettolen, replylen, recvlen; | 5668/* 5669** STAB_MAP_STORE -- store in symtab (actually using during init, not rebuild) 5670*/ 5671 5672void 5673stab_map_store(map, lhs, rhs) 5674 register MAP *map; 5675 char *lhs; --- 1875 unchanged lines hidden (view full) --- 7551char * 7552socket_map_lookup(map, name, av, statp) 7553 MAP *map; 7554 char *name; 7555 char **av; 7556 int *statp; 7557{ 7558 unsigned int nettolen, replylen, recvlen; |
7557 char *replybuf, *rval, *value, *status; | 7559 char *replybuf, *rval, *value, *status, *key; |
7558 SM_FILE_T *f; | 7560 SM_FILE_T *f; |
7561 char keybuf[MAXNAME + 1]; |
|
7559 7560 replybuf = NULL; 7561 rval = NULL; 7562 f = (SM_FILE_T *)map->map_db1; 7563 if (tTd(38, 20)) 7564 sm_dprintf("socket_map_lookup(%s, %s) %s\n", 7565 map->map_mname, name, map->map_file); 7566 | 7562 7563 replybuf = NULL; 7564 rval = NULL; 7565 f = (SM_FILE_T *)map->map_db1; 7566 if (tTd(38, 20)) 7567 sm_dprintf("socket_map_lookup(%s, %s) %s\n", 7568 map->map_mname, name, map->map_file); 7569 |
7567 nettolen = strlen(map->map_mname) + 1 + strlen(name); | 7570 if (!bitset(MF_NOFOLDCASE, map->map_mflags)) 7571 { 7572 nettolen = strlen(name); 7573 if (nettolen > sizeof keybuf - 1) 7574 nettolen = sizeof keybuf - 1; 7575 memmove(keybuf, name, nettolen); 7576 keybuf[nettolen] = '\0'; 7577 makelower(keybuf); 7578 key = keybuf; 7579 } 7580 else 7581 key = name; 7582 7583 nettolen = strlen(map->map_mname) + 1 + strlen(key); |
7568 SM_ASSERT(nettolen > strlen(map->map_mname)); | 7584 SM_ASSERT(nettolen > strlen(map->map_mname)); |
7569 SM_ASSERT(nettolen > strlen(name)); | 7585 SM_ASSERT(nettolen > strlen(key)); |
7570 if ((sm_io_fprintf(f, SM_TIME_DEFAULT, "%u:%s %s,", | 7586 if ((sm_io_fprintf(f, SM_TIME_DEFAULT, "%u:%s %s,", |
7571 nettolen, map->map_mname, name) == SM_IO_EOF) || | 7587 nettolen, map->map_mname, key) == SM_IO_EOF) || |
7572 (sm_io_flush(f, SM_TIME_DEFAULT) != 0) || 7573 (sm_io_error(f))) 7574 { 7575 syserr("451 4.3.0 socket_map_lookup(%s): failed to send lookup request", 7576 map->map_mname); 7577 *statp = EX_TEMPFAIL; 7578 goto errcl; 7579 } --- 53 unchanged lines hidden (view full) --- 7633 value++; 7634 } 7635 if (strcmp(status, "OK") == 0) 7636 { 7637 *statp = EX_OK; 7638 7639 /* collect the return value */ 7640 if (bitset(MF_MATCHONLY, map->map_mflags)) | 7588 (sm_io_flush(f, SM_TIME_DEFAULT) != 0) || 7589 (sm_io_error(f))) 7590 { 7591 syserr("451 4.3.0 socket_map_lookup(%s): failed to send lookup request", 7592 map->map_mname); 7593 *statp = EX_TEMPFAIL; 7594 goto errcl; 7595 } --- 53 unchanged lines hidden (view full) --- 7649 value++; 7650 } 7651 if (strcmp(status, "OK") == 0) 7652 { 7653 *statp = EX_OK; 7654 7655 /* collect the return value */ 7656 if (bitset(MF_MATCHONLY, map->map_mflags)) |
7641 rval = map_rewrite(map, name, strlen(name), NULL); | 7657 rval = map_rewrite(map, key, strlen(key), NULL); |
7642 else 7643 rval = map_rewrite(map, value, strlen(value), av); 7644 } 7645 else if (strcmp(status, "NOTFOUND") == 0) 7646 { 7647 *statp = EX_NOTFOUND; 7648 if (tTd(38, 20)) 7649 sm_dprintf("socket_map_lookup(%s): %s not found\n", | 7658 else 7659 rval = map_rewrite(map, value, strlen(value), av); 7660 } 7661 else if (strcmp(status, "NOTFOUND") == 0) 7662 { 7663 *statp = EX_NOTFOUND; 7664 if (tTd(38, 20)) 7665 sm_dprintf("socket_map_lookup(%s): %s not found\n", |
7650 map->map_mname, name); | 7666 map->map_mname, key); |
7651 } 7652 else 7653 { 7654 if (tTd(38, 5)) 7655 sm_dprintf("socket_map_lookup(%s, %s): server returned error: type=%s, reason=%s\n", | 7667 } 7668 else 7669 { 7670 if (tTd(38, 5)) 7671 sm_dprintf("socket_map_lookup(%s, %s): server returned error: type=%s, reason=%s\n", |
7656 map->map_mname, name, status, | 7672 map->map_mname, key, status, |
7657 value ? value : ""); 7658 if ((strcmp(status, "TEMP") == 0) || 7659 (strcmp(status, "TIMEOUT") == 0)) 7660 *statp = EX_TEMPFAIL; 7661 else if(strcmp(status, "PERM") == 0) 7662 *statp = EX_UNAVAILABLE; 7663 else 7664 *statp = EX_PROTOCOL; --- 14 unchanged lines hidden --- | 7673 value ? value : ""); 7674 if ((strcmp(status, "TEMP") == 0) || 7675 (strcmp(status, "TIMEOUT") == 0)) 7676 *statp = EX_TEMPFAIL; 7677 else if(strcmp(status, "PERM") == 0) 7678 *statp = EX_UNAVAILABLE; 7679 else 7680 *statp = EX_PROTOCOL; --- 14 unchanged lines hidden --- |