Lines Matching +full:up +full:-

2  * Copyright (c) 1998-2003, 2006 Proofpoint, Inc. and its suppliers.
4 * Copyright (c) 1983, 1995-1997 Eric P. Allman. All rights reserved.
18 SM_RCSID("@(#)$Id: udb.c,v 8.166 2013-11-22 20:51:57 ca Exp $ (with USERDB)")
20 SM_RCSID("@(#)$Id: udb.c,v 8.166 2013-11-22 20:51:57 ca Exp $ (without USERDB)")
38 ** UDB.C -- interface between sendmail and Berkeley User Data Base.
52 /* type UE_REMOTE -- do remote call for lookup */
62 /* type UE_FORWARD -- forward message to remote */
70 /* type UE_FETCH -- look up in local database */
84 # define UDB_REMOTE 2 /* look up in remote database */
85 # define UDB_DBFETCH 3 /* look up in local database */
87 # define UDB_HESIOD 5 /* look up via hesiod */
105 ** UDBEXPAND -- look up user in database and expand
108 ** a -- address to expand.
109 ** sendq -- pointer to head of sendq to put the expansions in.
110 ** aliaslevel -- the current alias nesting depth.
111 ** e -- the current envelope.
114 ** EX_TEMPFAIL -- if something "odd" happened -- probably due
116 ** EX_OK -- otherwise.
136 register struct udbent *up; local
146 sm_dprintf("udbexpand(%s)\n", a->q_paddr);
149 if (!QS_IS_SENDABLE(a->q_state))
151 e->e_to = a->q_paddr;
165 user = a->q_user;
185 for (up = UdbEnts; !breakout; up++)
203 userleft = sizeof(userbuf) - 1;
214 switch (up->udb_type)
224 i = (*up->udb_dbp->seq)(up->udb_dbp, &key, &info, R_CURSOR);
229 (errno = (*up->udb_dbp->cursor)(up->udb_dbp,
232 (errno = (*up->udb_dbp->cursor)(up->udb_dbp,
235 i = -1;
237 (errno = dbc->c_get(dbc, &key,
249 (void) dbc->c_close(dbc);
260 a->q_flags &= ~QSELFREF;
266 if (bitset(EF_VRFYONLY, e->e_flags))
268 a->q_state = QS_VERIFIED;
272 (void) dbc->c_close(dbc);
280 if (info.size >= userleft - 1)
300 userleft--;
304 userleft -= info.size;
308 i = (*up->udb_dbp->seq)(up->udb_dbp, &key, &info, R_NEXT);
311 if ((errno = dbc->c_get(dbc, &key,
320 (void) dbc->c_close(dbc);
331 sm_syslog(LOG_INFO, e->e_id,
333 e->e_to,
336 if (naddrs > 0 && !bitset(QSELFREF, a->q_flags))
343 a->q_state = QS_EXPANDED;
347 syserr("udbexpand: db-get %.*s stat %d",
353 ** If this address has a -request address, reflect
359 (void) sm_strlcpyn(keybuf, sizeof(keybuf), 2, a->q_user,
366 i = (*up->udb_dbp->get)(up->udb_dbp, &key, &info, 0);
368 i = errno = (*up->udb_dbp->get)(up->udb_dbp, NULL,
373 a->q_owner = sm_rpool_malloc_x(e->e_rpool,
375 memmove(a->q_owner, info.data, info.size);
376 a->q_owner[info.size] = '\0';
379 if (e->e_xfp != NULL)
381 (void) sm_io_fprintf(e->e_xfp, SM_TIME_DEFAULT,
383 a->q_paddr);
385 e->e_flags |= EF_SENDRECEIPT;
386 a->q_flags |= QDELIVERED|QEXPANDED;
397 /* look up the key via hesiod */
401 syserr("udbexpand: hesiod-get %.*s stat %d",
417 a->q_user);
418 hp = hes_getmailhost(a->q_user);
423 syserr("udbexpand: hesiod-getmail %s stat %d",
424 a->q_user, hes_error());
429 a->q_user, hes_error());
432 if (strlen(hp->po_name) + strlen(hp->po_host) >
433 sizeof(pobuf) - 2)
437 a->q_user,
438 hp->po_name,
439 hp->po_host);
444 "%s@%s", hp->po_name, hp->po_host);
454 a->q_flags &= ~QSELFREF;
456 if (bitset(EF_VRFYONLY, e->e_flags))
458 a->q_state = QS_VERIFIED;
470 sm_syslog(LOG_INFO, e->e_id,
472 e->e_to,
476 if (naddrs > 0 && !bitset(QSELFREF, a->q_flags))
483 a->q_state = QS_EXPANDED;
487 ** If this address has a -request address, reflect
491 (void) sm_strlcpyn(keybuf, sizeof(keybuf), 2, a->q_user,
499 a->q_owner = sm_rpool_malloc_x(e->e_rpool,
501 memmove(a->q_owner, info.data, info.size);
502 a->q_owner[info.size] = '\0';
511 if (bitset(EF_VRFYONLY, e->e_flags))
513 a->q_state = QS_VERIFIED;
516 i = strlen(up->udb_fwdhost) + strlen(a->q_user) + 1;
523 a->q_user, "@", up->udb_fwdhost);
525 a->q_flags &= ~QSELFREF;
527 if (naddrs > 0 && !bitset(QSELFREF, a->q_flags))
534 a->q_state = QS_EXPANDED;
554 ** UDBSENDER -- return canonical external name of sender, given local name
557 ** sender -- the name of the sender on the local machine.
558 ** rpool -- resource pool from which to allocate result
563 ** NULL -- if nothing is changed from the database.
577 ** UDBMATCH -- match user in field, return result of lookup.
580 ** user -- the name of the user.
581 ** field -- the field to look up.
582 ** rpool -- resource pool from which to allocate result
587 ** NULL -- if nothing is changed from the database.
599 register struct udbent *up; local
629 if ((strlen(user) + i) > sizeof(keybuf) - 4)
642 for (up = UdbEnts; up->udb_type != UDB_EOLIST; up++)
648 switch (up->udb_type)
657 i = (*up->udb_dbp->get)(up->udb_dbp, &key, &info, 0);
659 i = errno = (*up->udb_dbp->get)(up->udb_dbp, NULL,
716 for (up = UdbEnts; up->udb_type != UDB_EOLIST; up++)
718 switch (up->udb_type)
723 if (up->udb_default == NULL)
730 i = (*up->udb_dbp->get)(up->udb_dbp,
733 i = errno = (*up->udb_dbp->get)(up->udb_dbp,
740 up->udb_default = "";
745 up->udb_default = sm_pmalloc_x(info.size + 1);
746 memmove(up->udb_default, info.data, info.size);
747 up->udb_default[info.size] = '\0';
749 else if (up->udb_default[0] == '\0')
752 /* we have a default case -- verify user:maildrop */
758 i = (*up->udb_dbp->get)(up->udb_dbp, &key, &info, 0);
760 i = errno = (*up->udb_dbp->get)(up->udb_dbp, NULL,
765 /* nope -- no aliasing for this user */
769 /* they exist -- build the actual address */
770 i = strlen(user) + strlen(up->udb_default) + 2;
772 (void) sm_strlcpyn(p, i, 3, user, "@", up->udb_default);
781 if (up->udb_default == NULL)
790 up->udb_default = "";
795 up->udb_default = sm_pmalloc_x(info.size + 1);
796 memmove(up->udb_default, info.data, info.size);
797 up->udb_default[info.size] = '\0';
799 else if (up->udb_default[0] == '\0')
802 /* we have a default case -- verify user:maildrop */
808 /* nope -- no aliasing for this user */
812 /* they exist -- build the actual address */
813 i = strlen(user) + strlen(up->udb_default) + 2;
815 (void) sm_strlcpyn(p, i, 3, user, "@", up->udb_default);
828 ** UDB_MAP_LOOKUP -- look up arbitrary entry in user database map
831 ** map -- the map being queried.
832 ** name -- the name to look up.
833 ** av -- arguments to the map lookup.
834 ** statp -- to get any error status.
855 sm_dprintf("udb_map_lookup(%s, %s)\n", map->map_mname, name);
857 if (bitset(MF_NOFOLDCASE, map->map_mflags))
863 if (keysize > sizeof(keybuf) - 1)
864 keysize = sizeof(keybuf) - 1;
870 val = udbmatch(key, map->map_file, NULL);
874 if (bitset(MF_MATCHONLY, map->map_mflags))
886 ** _UDBX_INIT -- parse the UDB specification, opening any valid entries.
889 ** e -- the current envelope.
892 ** EX_TEMPFAIL -- if it appeared it couldn't get hold of a
895 ** EX_OK -- otherwise.
909 register struct udbent *up; local
920 up = UdbEnts;
953 ** @hostname -- forward email to the indicated host.
956 ** /dbname -- search the named database on the local
958 ** Hesiod -- search the named database with BIND
965 up->udb_type = UDB_FORWARD;
966 up->udb_pid = CurrentPid;
967 up->udb_fwdhost = spec + 1;
969 up++;
977 up->udb_type = UDB_HESIOD;
978 up->udb_pid = CurrentPid;
980 up++;
985 case '/': /* look up remote name */
987 if (l > 3 && strcmp(&spec[l - 3], ".db") == 0)
989 up->udb_dbname = spec;
993 up->udb_dbname = sm_pmalloc_x(l + 4);
994 (void) sm_strlcpyn(up->udb_dbname, l + 4, 2,
999 up->udb_dbp = dbopen(up->udb_dbname, O_RDONLY,
1009 up->udb_dbp = NULL;
1011 ret = db_create(&up->udb_dbp, NULL, 0);
1014 (void) up->udb_dbp->close(up->udb_dbp,
1016 up->udb_dbp = NULL;
1020 ret = up->udb_dbp->open(up->udb_dbp,
1022 up->udb_dbname,
1033 (void) up->udb_dbp->close(up->udb_dbp, 0);
1034 up->udb_dbp = NULL;
1039 errno = db_open(up->udb_dbname, DB_BTREE,
1041 NULL, &up->udb_dbp);
1045 if (up->udb_dbp == NULL)
1056 up->udb_dbname,
1063 sm_syslog(LOG_ERR, e->e_id,
1069 up->udb_dbname,
1071 up->udb_type = UDB_EOLIST;
1072 if (up->udb_dbname != spec)
1073 sm_free(up->udb_dbname); /* XXX */
1076 if (up->udb_dbname != spec)
1077 sm_free(up->udb_dbname); /* XXX */
1087 up->udb_dbname);
1089 up->udb_type = UDB_DBFETCH;
1090 up->udb_pid = CurrentPid;
1092 up++;
1104 up->udb_type = UDB_EOLIST;
1108 for (up = UdbEnts; up->udb_type != UDB_EOLIST; up++)
1110 switch (up->udb_type)
1114 anynet_ntoa((SOCKADDR *) &up->udb_addr),
1115 up->udb_timeout);
1120 sm_dprintf("FETCH: file %s\n", up->udb_dbname);
1128 up->udb_fwdhost);
1152 for (up = UdbEnts; up->udb_type != UDB_EOLIST; up++)
1154 if (up->udb_type == UDB_DBFETCH)
1157 (*up->udb_dbp->close)(up->udb_dbp);
1159 errno = (*up->udb_dbp->close)(up->udb_dbp, 0);
1162 sm_dprintf("_udbx_init: db->close(%s)\n",
1163 up->udb_dbname);
1200 ** _UDBX_CLOSE -- close all file based UDB entries.
1211 struct udbent *up; in _udbx_close() local
1216 for (up = UdbEnts; up->udb_type != UDB_EOLIST; up++) in _udbx_close()
1218 if (up->udb_pid != CurrentPid) in _udbx_close()
1222 if (up->udb_type == UDB_DBFETCH) in _udbx_close()
1225 (*up->udb_dbp->close)(up->udb_dbp); in _udbx_close()
1227 errno = (*up->udb_dbp->close)(up->udb_dbp, 0); in _udbx_close()
1231 sm_dprintf("_udbx_close: db->close(%s)\n", in _udbx_close()
1232 up->udb_dbname); in _udbx_close()
1248 if (sm_strlcpy(kbuf, key->data, sizeof(kbuf)) >= sizeof(kbuf))
1264 return -1;
1269 *--type = ':';
1277 return -1;
1285 return -1;
1297 ** XXX it is legal for :maildrop to be multi-valued.
1300 info->data = hp[0];
1301 info->size = (size_t) strlen(info->data);