Lines Matching +full:coexist +full:- +full:support

2  * Copyright (c) 1998-2008 Proofpoint, Inc. and its suppliers.
4 * Copyright (c) 1992, 1995-1997 Eric P. Allman. All rights reserved.
16 SM_RCSID("@(#)$Id: map.c,v 8.713 2013-11-22 20:51:55 ca Exp $")
28 # error "README: coexist with NDBM, or delete -DNDBM from the Makefile"
29 # error "README: and use -DNEWDB instead."
39 # define NDBM_YP_COMPAT /* create YP-compatible NDBM files */
94 ** MAP_HAS_CHGED -- check whether fd was updated or fn refers to a different file
97 ** map -- map being checked
98 ** fn -- (full) file name of map.
99 ** fd -- fd of map.
122 fn, fd, bitset(MF_CHKED_CHGD, map->map_mflags));
126 /* XXX check can be disabled via -d38.101 for testing */
127 if (bitset(MF_CHKED_CHGD, map->map_mflags) && !tTd(38, 101))
129 map->map_mflags |= MF_CHKED_CHGD;
131 if (fd < 0 || fstat(fd, &stbuf) < 0 || stbuf.st_mtime > map->map_mtime)
134 sm_dprintf("reopen map: name=%s, fd=%d\n", map->map_mname, fd);
154 ** MAP_RESET_CHGD -- reset MF_CHKED_CHGD in a map
157 ** s -- STAB entry: if map: reset MF_CHKED_CHGD
158 ** unused -- unused variable
175 if (ST_MAP != s->s_symtype
177 && ST_DYNMAP != s->s_symtype
181 map = &s->s_map;
182 if (!bitset(MF_VALID, map->map_mflags))
186 map->map_mname, bitset(MF_CHKED_CHGD, map->map_mflags));
187 map->map_mflags &= ~MF_CHKED_CHGD;
191 ** MAPS_RESET_CHGD -- reset MF_CHKED_CHGD in all maps
194 ** msg - caller (for debugging)
215 ** SMDB_ADD_EXTENSION -- Adds an extension to a file name.
221 ** full_name -- The final file name.
222 ** max_full_name_len -- The max length for full_name.
223 ** db_name -- The name of the db.
224 ** extension -- The extension to add.
227 ** SMDBE_OK -- Success.
252 db_name[db_name_len - extension_len - 1] != '.' ||
253 strcmp(&db_name[db_name_len - extension_len], extension) != 0)
264 ** MAP.C -- implementations for various map classes.
280 ** to return the results -- it takes care of null termination
299 ** It is currently implemented in a pretty ad-hoc manner; it ought
307 # define LOCK_ON_OPEN 0 /* no such luck -- bend over backwards */
311 ** MAP_PARSEARGS -- parse config line arguments for database lookup
316 ** map -- the map being initialized.
317 ** ap -- a pointer to the args on the config line.
320 ** true -- if everything parsed OK.
321 ** false -- otherwise.
339 map->map_mflags |= MF_TRY0NULL|MF_TRY1NULL;
340 map->map_spacesub = SpaceSub; /* default value */
345 if (*p != '-')
350 map->map_mflags |= MF_APPEND;
354 map->map_app = ++p;
358 map->map_mflags |= MF_DEFER;
369 map->map_timeout = convtime(p, 's');
376 map->map_mflags |= MF_NOFOLDCASE;
382 map->map_keycolnm = p;
386 map->map_mflags |= MF_MATCHONLY;
390 map->map_mflags |= MF_INCLNULL;
391 map->map_mflags &= ~MF_TRY0NULL;
395 map->map_mflags &= ~MF_TRY1NULL;
399 map->map_mflags |= MF_OPTIONAL;
403 map->map_mflags |= MF_KEEPQUOTES;
407 map->map_spacesub = *++p;
411 map->map_tapp = ++p;
415 map->map_mflags |= MF_NODEFER;
421 map->map_valcolnm = p;
426 map->map_coldelim = *p;
432 map->map_coldelim = '\n';
436 map->map_coldelim = '\t';
440 map->map_coldelim = '\\';
446 syserr("Illegal option %c map %s", *p, map->map_mname);
454 if (map->map_app != NULL)
455 map->map_app = newstr(map->map_app);
456 if (map->map_tapp != NULL)
457 map->map_tapp = newstr(map->map_tapp);
458 if (map->map_keycolnm != NULL)
459 map->map_keycolnm = newstr(map->map_keycolnm);
460 if (map->map_valcolnm != NULL)
461 map->map_valcolnm = newstr(map->map_valcolnm);
465 map->map_file = p;
470 map->map_file = newstr(map->map_file);
476 map->map_rebuild = newstr(p);
478 if (map->map_file == NULL &&
479 !bitset(MCF_OPTFILE, map->map_class->map_cflags))
482 map->map_class->map_cname, map->map_mname);
488 ** MAP_REWRITE -- rewrite a database key, interpolating %n indications.
494 ** map -- the map that causes this.
495 ** s -- the string to rewrite, NOT necessarily null terminated.
496 ** slen -- the length of s.
497 ** av -- arguments to interpolate into buf.
539 while (l-- > 0 && (c = *sp++) != '\0')
543 if (l-- <= 0)
548 for (avp = av; --c >= '0' && *avp != NULL; avp++)
555 if (map->map_app != NULL)
556 len += strlen(map->map_app);
572 len -= slen;
576 while (slen-- > 0 && (c = *s++) != '\0')
581 if (len-- <= 1)
586 if (slen-- <= 0 || (c = *s++) == '\0')
592 if (len-- <= 1)
597 for (avp = av; --c >= '0' && *avp != NULL; avp++)
603 for (ap = *avp; (c = *ap++) != '\0' && len > 0; --len)
607 if (map->map_app != NULL && len > 0)
608 (void) sm_strlcpy(bp, map->map_app, len);
612 if (!bitset(MF_KEEPXFMT, map->map_mflags))
635 ** MAPCHOWN -- if available fchown() the fds to TrustedUid
638 ** mapname - name of map (for error reporting)
639 ** fd0 - first fd (must be valid)
640 ** fd1 - second fd (<0: do not use)
641 ** filename - name of file (for error reporting)
659 if (fchown(fd0, TrustedUid, -1) < 0 ||
660 (fd1 >= 0 && fchown(fd1, TrustedUid, -1) < 0))
680 ** INITMAPS -- rebuild alias maps
698 ** MAP_INIT -- rebuild a map
701 ** s -- STAB entry: if map: try to rebuild
702 ** unused -- unused variable
720 if (s->s_symtype != ST_MAP)
723 map = &s->s_map;
724 if (!bitset(MF_VALID, map->map_mflags))
729 map->map_class->map_cname == NULL ? "NULL" :
730 map->map_class->map_cname,
731 map->map_mname == NULL ? "NULL" : map->map_mname,
732 map->map_file == NULL ? "NULL" : map->map_file);
734 if (!bitset(MF_ALIAS, map->map_mflags) ||
735 !bitset(MCF_REBUILDABLE, map->map_class->map_cflags))
743 if (bitset(MF_OPEN, map->map_mflags))
745 map->map_mflags |= MF_CLOSING;
746 map->map_class->map_close(map);
747 map->map_mflags &= ~(MF_OPEN|MF_WRITABLE|MF_CLOSING);
754 ** OPENMAP -- open a map
757 ** map -- map to open (it must not be open).
772 if (!bitset(MF_VALID, map->map_mflags))
776 if (bitset(MF_OPEN, map->map_mflags))
789 if (map->map_class->map_open(map, O_RDONLY))
793 map->map_class->map_cname == NULL ? "NULL" :
794 map->map_class->map_cname,
795 map->map_mname == NULL ? "NULL" :
796 map->map_mname,
797 map->map_file == NULL ? "NULL" :
798 map->map_file);
799 map->map_mflags |= MF_OPEN;
800 map->map_pid = CurrentPid;
806 map->map_class->map_cname == NULL ? "NULL" :
807 map->map_class->map_cname,
808 map->map_mname == NULL ? "NULL" :
809 map->map_mname,
810 map->map_file == NULL ? "NULL" :
811 map->map_file,
814 if (!bitset(MF_OPTIONAL, map->map_mflags))
818 map->map_orgclass = map->map_class;
819 map->map_class = &BogusMapClass;
820 map->map_mflags |= MF_OPEN|MF_OPENBOGUS;
821 map->map_pid = CurrentPid;
826 map->map_mflags &= ~MF_VALID;
837 return bitset(MF_OPEN, map->map_mflags);
840 ** CLOSEMAPS -- close all open maps opened by the current pid.
843 ** bogus -- only close bogus maps.
856 ** MAP_CLOSE -- close a map opened by the current pid.
859 ** s -- STAB entry: if map: try to close
860 ** bogus -- only close bogus maps or MCF_NOTPERSIST maps.
874 if (s->s_symtype != ST_MAP)
877 map = &s->s_map;
885 ** or (bogus and it's not a bogus map and it's not not-persistent)
888 if (!bitset(MF_VALID, map->map_mflags) ||
889 !bitset(MF_OPEN, map->map_mflags) ||
890 bitset(MF_CLOSING, map->map_mflags) ||
891 map->map_pid != CurrentPid ||
892 (bogus && map->map_class != &BogusMapClass &&
893 !bitset(MCF_NOTPERSIST, map->map_class->map_cflags)))
896 if (map->map_class == &BogusMapClass && map->map_orgclass != NULL &&
897 map->map_orgclass != &BogusMapClass)
898 map->map_class = map->map_orgclass;
901 map->map_mname == NULL ? "NULL" : map->map_mname,
902 map->map_file == NULL ? "NULL" : map->map_file);
904 if (!bitset(MF_OPENBOGUS, map->map_mflags))
906 map->map_mflags |= MF_CLOSING;
907 map->map_class->map_close(map);
909 map->map_mflags &= ~(MF_OPEN|MF_WRITABLE|MF_OPENBOGUS|MF_CLOSING|MF_CHKED_CHGD);
925 ** (i.e. top-level domains are not allowed, like "com", must be in sun_init_domain()
956 ** GETCANONNAME -- look up name using service switch
959 ** host -- the host name to look up.
960 ** hbsize -- the size of the host buffer.
961 ** trymx -- if set, try MX records.
962 ** pttl -- pointer to return TTL (can be NULL).
965 ** >0 -- if the host was found.
966 ** 0 -- otherwise.
1097 if (host[strlen(host) - 1] != '.')
1143 ** EXTRACT_CANONNAME -- extract canonical name from /etc/hosts entry
1146 ** name -- the name against which to match.
1147 ** dot -- where to reinsert '.' to get FQDN
1148 ** line -- the /etc/hosts line.
1149 ** cbuf -- the location to store the result.
1150 ** cbuflen -- the size of cbuf.
1153 ** true -- if the line matched the desired name.
1154 ** false -- otherwise.
1208 (void) sm_strlcpy(p, domain, cbuflen - i - 1);
1227 ** DNS_MAP_OPEN -- stub to check proper value for dns map type
1236 sm_dprintf("dns_map_open(%s, %d)\n", map->map_mname, mode);
1241 /* issue a pseudo-error message */
1249 ** DNS_MAP_PARSEARGS -- parse dns map definition args.
1252 ** map -- pointer to MAP
1253 ** args -- pointer to the args on the config line.
1256 ** true -- if everything parsed OK.
1257 ** false -- otherwise.
1278 map_p->dns_m_type = -1;
1279 map->map_mflags |= MF_TRY0NULL|MF_TRY1NULL;
1285 if (*p != '-')
1294 map->map_mname, p);
1299 map->map_mflags |= MF_APPEND;
1303 map->map_app = ++p;
1317 ** slight abuse of map->map_file; it isn't
1321 map->map_file = newstr(p);
1335 map->map_timeout = convtime(p, 's');
1342 map->map_mflags |= MF_NOFOLDCASE;
1346 map->map_mflags |= MF_MATCHONLY;
1350 map->map_mflags |= MF_INCLNULL;
1351 map->map_mflags &= ~MF_TRY0NULL;
1355 map->map_mflags &= ~MF_TRY1NULL;
1359 map->map_mflags |= MF_OPTIONAL;
1363 map->map_mflags |= MF_KEEPQUOTES;
1368 map_p->dns_m_options |= SM_RES_DNSSEC;
1375 map->map_retry = atoi(p);
1379 map->map_mflags |= MF_NODEFER;
1383 map->map_tapp = ++p;
1388 map->map_coldelim = *p;
1394 map->map_coldelim = '\n';
1398 map->map_coldelim = '\t';
1402 map->map_coldelim = '\\';
1410 map->map_sizelimit = atoi(p);
1423 map_p->dns_m_type = dns_string_to_type(p);
1426 if (map_p->dns_m_type < 0)
1428 map->map_mname, p);
1438 if (map_p->dns_m_type < 0)
1439 syserr("dns map %s: missing -R type", map->map_mname);
1440 if (map->map_app != NULL)
1441 map->map_app = newstr(map->map_app);
1442 if (map->map_tapp != NULL)
1443 map->map_tapp = newstr(map->map_tapp);
1451 map->map_db1 = (ARBPTR_T) map_p;
1456 ** DNS_MAP_LOOKUP -- perform dns map lookup.
1459 ** map -- pointer to MAP
1460 ** name -- name to look up
1461 ** av -- arguments to interpolate into buf.
1462 ** statp -- pointer to status (EX_)
1466 ** NULL -- otherwise.
1489 map->map_mname, name);
1491 map_p = (struct dns_map *)(map->map_db1);
1492 options = map_p->dns_m_options;
1493 if (map->map_file != NULL && *map->map_file != '\0')
1498 len = strlen(map->map_file) + strlen(name) + 2;
1505 (void) sm_strlcpyn(appdomain, len, 3, name, ".", map->map_file);
1506 r = dns_lookup_map(appdomain, C_IN, map_p->dns_m_type,
1507 map->map_timeout, map->map_retry, options);
1512 r = dns_lookup_map(name, C_IN, map_p->dns_m_type,
1513 map->map_timeout, map->map_retry, options);
1526 for (rr = r->dns_r_head; rr != NULL; rr = rr->rr_next)
1531 switch (rr->rr_type)
1535 value = rr->rr_u.rr_txt;
1539 value = rr->rr_u.rr_txt;
1543 value = rr->rr_u.rr_mx->mx_r_domain;
1547 value = rr->rr_u.rr_srv->srv_r_target;
1551 value = rr->rr_u.rr_txt;
1555 value = rr->rr_u.rr_txt;
1559 value = rr->rr_u.rr_mx->mx_r_domain;
1564 value = inet_ntoa(*(rr->rr_u.rr_a));
1570 value = anynet_ntop(rr->rr_u.rr_aaaa, buf6,
1577 value = rr->rr_u.rr_txt;
1583 if (map_p->dns_m_type != rr->rr_type)
1588 rr->rr_type,
1594 if (rr->rr_type == T_AAAA && value == NULL)
1606 rr->rr_type,
1609 (map->map_coldelim == '\0' ||
1610 map->map_sizelimit == 1 ||
1611 bitset(MF_MATCHONLY, map->map_mflags)))
1631 vp, map->map_coldelim, value);
1634 if (map->map_sizelimit > 0 &&
1635 ++resnum >= map->map_sizelimit)
1649 truncate_at_delim(vp, PSBUFSIZE / 2, map->map_coldelim);
1654 sm_syslog(LOG_INFO, CurEnv->e_id, "dns %.100s => %s",
1656 if (bitset(MF_MATCHONLY, map->map_mflags))
1676 ** NDBM_MAP_OPEN -- DBM-style map open
1698 map->map_mname, map->map_file, mode);
1699 map->map_lockfd = -1;
1704 map->map_file, ".dir") >= sizeof(dirfile) ||
1706 map->map_file, ".pag") >= sizeof(pagfile))
1709 if (!bitset(MF_OPTIONAL, map->map_mflags))
1711 map->map_mname, map->map_file);
1746 if (!bitset(MF_OPTIONAL, map->map_mflags))
1748 map->map_mname, prob, map->map_file);
1799 map->map_file);
1810 map->map_file);
1822 syserr("ndbm_map_open(%s.{dir,pag}): cannot fstat pre-opened file",
1823 map->map_file);
1828 map->map_lockfd = dirfd;
1838 dbm = dbm_open(map->map_file, mode, DBMMODE);
1842 if (bitset(MF_ALIAS, map->map_mflags) &&
1846 if (map->map_lockfd >= 0)
1847 (void) close(map->map_lockfd);
1850 if (!bitset(MF_OPTIONAL, map->map_mflags))
1851 syserr("Cannot open DBM database %s", map->map_file);
1861 if (map->map_lockfd >= 0)
1862 (void) close(map->map_lockfd);
1865 syserr("dbm map \"%s\": cannot support GDBM",
1866 map->map_mname);
1876 if (map->map_lockfd >= 0)
1877 (void) close(map->map_lockfd);
1881 map->map_file);
1885 map->map_db1 = (ARBPTR_T) dbm;
1894 map->map_mtime = st.st_mtime;
1900 (void) lockfile(dfd, map->map_file, ".dir", LOCK_UN);
1902 (void) lockfile(pfd, map->map_file, ".pag", LOCK_UN);
1904 if (bitset(MF_ALIAS, map->map_mflags) &&
1910 map->map_mflags |= MF_LOCKED;
1911 mapchown(map->map_file, dfd, pfd, map->map_file);
1918 ** NDBM_MAP_LOOKUP -- look up a datum in a DBM-type map
1938 map->map_mname, name);
1942 if (!bitset(MF_NOFOLDCASE, map->map_mflags))
1944 if (key.dsize > sizeof(keybuf) - 1)
1945 key.dsize = sizeof(keybuf) - 1;
1952 if (!smdb_add_extension(buf, sizeof(buf), map->map_file, "pag"))
1955 if (!bitset(MF_OPTIONAL, map->map_mflags))
1957 map->map_mname, map->map_file);
1963 dfd = dbm_dirfno((DBM *) map->map_db1);
1964 if (dfd >= 0 && !bitset(MF_LOCKED, map->map_mflags))
1965 (void) lockfile(dfd, map->map_file, ".dir", LOCK_SH);
1966 pfd = dbm_pagfno((DBM *) map->map_db1);
1971 int omode = bitset(map->map_mflags, MF_WRITABLE) ? O_RDWR
1974 if (dfd >= 0 && !bitset(MF_LOCKED, map->map_mflags))
1975 (void) lockfile(dfd, map->map_file, ".dir", LOCK_UN);
1976 map->map_mflags |= MF_CLOSING;
1977 map->map_class->map_close(map);
1978 map->map_mflags &= ~(MF_OPEN|MF_WRITABLE|MF_CLOSING);
1979 if (map->map_class->map_open(map, omode))
1981 map->map_mflags |= MF_OPEN;
1982 map->map_pid = CurrentPid;
1984 map->map_mflags |= MF_WRITABLE;
1989 if (!bitset(MF_OPTIONAL, map->map_mflags))
1994 map->map_orgclass = map->map_class;
1995 map->map_class = &BogusMapClass;
1996 map->map_mflags |= MF_OPEN;
1997 map->map_pid = CurrentPid;
1999 map->map_file);
2005 if (bitset(MF_TRY0NULL, map->map_mflags))
2007 val = dbm_fetch((DBM *) map->map_db1, key);
2009 map->map_mflags &= ~MF_TRY1NULL;
2011 if (val.dptr == NULL && bitset(MF_TRY1NULL, map->map_mflags))
2014 val = dbm_fetch((DBM *) map->map_db1, key);
2016 map->map_mflags &= ~MF_TRY0NULL;
2018 if (dfd >= 0 && !bitset(MF_LOCKED, map->map_mflags))
2019 (void) lockfile(dfd, map->map_file, ".dir", LOCK_UN);
2022 if (bitset(MF_MATCHONLY, map->map_mflags))
2030 ** NDBM_MAP_STORE -- store a datum in the database
2046 map->map_mname, lhs, rhs);
2050 if (!bitset(MF_NOFOLDCASE, map->map_mflags))
2052 if (key.dsize > sizeof(keybuf) - 1)
2053 key.dsize = sizeof(keybuf) - 1;
2063 if (bitset(MF_INCLNULL, map->map_mflags))
2069 status = dbm_store((DBM *) map->map_db1, key, data, DBM_INSERT);
2072 if (!bitset(MF_APPEND, map->map_mflags))
2101 status = dbm_store((DBM *) map->map_db1,
2110 ** NDBM_MAP_CLOSE -- close the database
2119 map->map_mname, map->map_file, map->map_mflags);
2121 if (bitset(MF_WRITABLE, map->map_mflags))
2127 inclnull = bitset(MF_INCLNULL, map->map_mflags);
2128 map->map_mflags &= ~MF_INCLNULL;
2130 if (strstr(map->map_file, "/yp/") != NULL)
2132 long save_mflags = map->map_mflags;
2134 map->map_mflags |= MF_NOFOLDCASE;
2142 map->map_mflags = save_mflags;
2146 map->map_mflags |= MF_INCLNULL;
2152 dbm_close((DBM *) map->map_db1);
2156 if (map->map_lockfd >= 0)
2157 (void) close(map->map_lockfd);
2169 ** BT_MAP_OPEN, HASH_MAP_OPEN -- database open primitives.
2174 ** there will be a race condition. If opening for read-only,
2209 map->map_mname, map->map_file, mode);
2238 map->map_mname, map->map_file, mode);
2280 if (!smdb_add_extension(buf, sizeof(buf), map->map_file, "db"))
2283 if (!bitset(MF_OPTIONAL, map->map_mflags))
2285 map->map_mname, map->map_file);
2321 if (!bitset(MF_OPTIONAL, map->map_mflags))
2323 mapclassname, map->map_mname, prob, buf);
2329 map->map_lockfd = -1;
2338 ** Pre-lock the file to avoid race conditions. In particular,
2346 if (!bitset(MF_OPTIONAL, map->map_mflags))
2347 syserr("db_map_open: cannot pre-open database %s", buf);
2357 syserr("db_map_open(%s): file changed after pre-open", buf);
2367 syserr("db_map_open(%s): cannot fstat pre-opened file",
2372 /* actually lock the pre-opened file */
2404 ret = db->set_cachesize(db, 0, DB_CACHE_SIZE, 0);
2407 (void) db->close(db, 0);
2415 ret = db->set_h_nelem(db, DB_HASH_NELEM);
2418 (void) db->close(db, 0);
2425 ret = db->open(db,
2434 (void) db->close(db, 0);
2449 map->map_lockfd = fd;
2456 if (mode == O_RDONLY && bitset(MF_ALIAS, map->map_mflags) &&
2460 if (map->map_lockfd >= 0)
2461 (void) close(map->map_lockfd);
2464 if (!bitset(MF_OPTIONAL, map->map_mflags))
2471 fd = db->fd(db);
2473 fd = -1;
2474 errno = db->fd(db, &fd);
2480 (void) db->close(db);
2482 errno = db->close(db, 0);
2485 if (map->map_lockfd >= 0)
2486 (void) close(map->map_lockfd);
2494 map->map_mflags |= MF_LOCKED;
2503 (void) db->sync(db, 0);
2504 mapchown(map->map_file, fd, -1, buf);
2507 map->map_db2 = (ARBPTR_T) db;
2516 map->map_mtime = st.st_mtime;
2523 sl = tTdlevel(68) - 100;
2530 if (mode == O_RDONLY && bitset(MF_ALIAS, map->map_mflags) &&
2538 ** DB_MAP_LOOKUP -- look up a datum in a BTREE- or HASH-type map
2549 register DB *db = (DB *) map->map_db2;
2561 map->map_mname, name);
2562 if (!smdb_add_extension(buf, sizeof(buf), map->map_file, "db"))
2565 if (!bitset(MF_OPTIONAL, map->map_mflags))
2567 map->map_mname, map->map_file);
2572 if (key.size > sizeof(keybuf) - 1)
2573 key.size = sizeof(keybuf) - 1;
2577 if (!bitset(MF_NOFOLDCASE, map->map_mflags))
2581 fd = db->fd(db);
2583 fd = -1;
2584 errno = db->fd(db, &fd);
2586 if (fd >= 0 && !bitset(MF_LOCKED, map->map_mflags))
2591 int omode = bitset(map->map_mflags, MF_WRITABLE) ? O_RDWR
2594 if (fd >= 0 && !bitset(MF_LOCKED, map->map_mflags))
2596 map->map_mflags |= MF_CLOSING;
2597 map->map_class->map_close(map);
2598 map->map_mflags &= ~(MF_OPEN|MF_WRITABLE|MF_CLOSING);
2599 if (map->map_class->map_open(map, omode))
2601 map->map_mflags |= MF_OPEN;
2602 map->map_pid = CurrentPid;
2604 map->map_mflags |= MF_WRITABLE;
2605 db = (DB *) map->map_db2;
2610 if (!bitset(MF_OPTIONAL, map->map_mflags))
2615 map->map_orgclass = map->map_class;
2616 map->map_class = &BogusMapClass;
2617 map->map_mflags |= MF_OPEN;
2618 map->map_pid = CurrentPid;
2620 map->map_file);
2627 if (bitset(MF_TRY0NULL, map->map_mflags))
2630 st = db->get(db, &key, &val, 0);
2632 errno = db->get(db, NULL, &key, &val, 0);
2645 st = -1;
2650 map->map_mflags &= ~MF_TRY1NULL;
2652 if (st != 0 && bitset(MF_TRY1NULL, map->map_mflags))
2656 st = db->get(db, &key, &val, 0);
2658 errno = db->get(db, NULL, &key, &val, 0);
2671 st = -1;
2676 map->map_mflags &= ~MF_TRY0NULL;
2679 if (fd >= 0 && !bitset(MF_LOCKED, map->map_mflags))
2688 if (bitset(MF_MATCHONLY, map->map_mflags))
2696 ** DB_MAP_STORE -- store a datum in the NEWDB database
2708 register DB *db = map->map_db2;
2716 map->map_mname, lhs, rhs);
2720 if (!bitset(MF_NOFOLDCASE, map->map_mflags))
2722 if (key.size > sizeof(keybuf) - 1)
2723 key.size = sizeof(keybuf) - 1;
2733 if (bitset(MF_INCLNULL, map->map_mflags))
2740 status = db->put(db, &key, &data, R_NOOVERWRITE);
2742 errno = db->put(db, NULL, &key, &data, DB_NOOVERWRITE);
2754 status = -1;
2760 if (!bitset(MF_APPEND, map->map_mflags))
2792 status = db->put(db, &key, &data, 0);
2794 status = errno = db->put(db, NULL, &key, &data, 0);
2803 ** DB_MAP_CLOSE -- add distinguished entries and close the database
2810 register DB *db = map->map_db2;
2814 map->map_mname, map->map_file, map->map_mflags);
2816 if (bitset(MF_WRITABLE, map->map_mflags))
2822 (void) db->sync(db, 0);
2825 if (map->map_lockfd >= 0)
2826 (void) close(map->map_lockfd);
2830 if (db->close(db) != 0)
2846 if (map->map_pid != CurrentPid)
2848 int fd = -1;
2850 errno = db->fd(db, &fd);
2856 if ((errno = db->close(db, 0)) != 0)
2859 map->map_mname, map->map_file, map->map_mflags);
2881 map->map_mname, map->map_file,
2883 map->map_db1 = (ARBPTR_T)NULL;
2884 map->map_db2 = (ARBPTR_T)NULL;
2893 ** (it would be nice to re-use libsmdb?)
2896 if (!smdb_add_extension(buf, sizeof(buf), map->map_file, CDBext))
2899 if (!bitset(MF_OPTIONAL, map->map_mflags))
2901 map->map_mname, map->map_file);
2914 map->map_mflags |= MF_LOCKED;
2935 if (!bitset(MF_OPTIONAL, map->map_mflags))
2937 map->map_mname, prob, buf, sm_errstring(status));
2956 if (!bitset(MF_OPTIONAL, map->map_mflags))
2983 map->map_lockfd = fd;
2986 map->map_mtime = st.st_mtime;
2998 if (!bitset(MF_OPTIONAL, map->map_mflags))
3003 map->map_db2 = (ARBPTR_T)cdbmp;
3004 mapchown(map->map_file, fd, -1, buf);
3013 sl = tTdlevel(68) - 100;
3024 if (!bitset(MF_OPTIONAL, map->map_mflags))
3029 map->map_db1 = (ARBPTR_T)cdbp;
3030 if (bitset(MF_ALIAS, map->map_mflags) && !aliaswait(map, CDBEXT, true))
3053 cdbmap = map->map_db1;
3055 sm_dprintf("cdb_map_lookup(%s, %s)\n", map->map_mname, name);
3057 if (!smdb_add_extension(buf, sizeof(buf), map->map_file, CDBext))
3060 if (!bitset(MF_OPTIONAL, map->map_mflags))
3062 map->map_mname, map->map_file);
3067 if (klen > sizeof(key) - 1)
3068 klen = sizeof(key) - 1;
3072 if (!bitset(MF_NOFOLDCASE, map->map_mflags))
3076 fd = map->map_lockfd;
3077 if (fd >= 0 && !bitset(MF_LOCKED, map->map_mflags))
3082 int omode = bitset(map->map_mflags, MF_WRITABLE) ? O_RDWR
3085 if (fd >= 0 && !bitset(MF_LOCKED, map->map_mflags))
3087 map->map_mflags |= MF_CLOSING;
3088 map->map_class->map_close(map);
3089 map->map_mflags &= ~(MF_OPEN|MF_WRITABLE|MF_CLOSING);
3090 if (map->map_class->map_open(map, omode))
3092 map->map_mflags |= MF_OPEN;
3094 map->map_mflags |= MF_WRITABLE;
3095 cdbmap = map->map_db1;
3100 if (!bitset(MF_OPTIONAL, map->map_mflags))
3105 map->map_orgclass = map->map_class;
3106 map->map_class = &BogusMapClass;
3107 map->map_mflags |= MF_OPEN;
3109 map->map_file);
3116 if (bitset(MF_TRY0NULL, map->map_mflags))
3120 map->map_mflags &= ~MF_TRY1NULL;
3122 if (st != 1 && bitset(MF_TRY1NULL, map->map_mflags))
3126 map->map_mflags &= ~MF_TRY0NULL;
3128 if (fd >= 0 && !bitset(MF_LOCKED, map->map_mflags))
3143 if (bitset(MF_MATCHONLY, map->map_mflags))
3150 ** CDB_MAP_STORE -- store a datum in the CDB database
3165 cdbmp = map->map_db2;
3171 if (!bitset(MF_NOFOLDCASE, map->map_mflags))
3173 if (klen > sizeof(keybuf) - 1)
3174 klen = sizeof(keybuf) - 1;
3181 if (bitset(MF_INCLNULL, map->map_mflags))
3200 fd = -1;
3201 cdbp = map->map_db1;
3210 cdbmp = map->map_db2;
3223 map->map_file);
3226 if (fsync(fd) == -1)
3227 syserr("cdb: fsync(%s) failed", map->map_file);
3228 if (close(fd) == -1)
3229 syserr("cdb: close(%s) failed", map->map_file);
3230 fd = -1;
3250 ** NIS_MAP_OPEN -- open NIS map
3265 map->map_mname, map->map_file, mode);
3270 /* issue a pseudo-error message */
3275 p = strchr(map->map_file, '@');
3280 map->map_domain = p;
3283 if (*map->map_file == '\0')
3284 map->map_file = "mail.aliases";
3286 if (map->map_domain == NULL)
3288 yperr = yp_get_default_domain(&map->map_domain);
3291 if (!bitset(MF_OPTIONAL, map->map_mflags))
3293 map->map_file);
3300 yperr = yp_match(map->map_domain, map->map_file, "@", 1,
3304 map->map_domain, map->map_file, yperr_string(yperr));
3311 ** alias file, but powerful HP-UX NIS servers apparently
3313 ** is rebuilt, so aliaswait() just hangs. I hate HP-UX.
3317 if (!bitset(MF_ALIAS, map->map_mflags) ||
3323 if (!bitset(MF_OPTIONAL, map->map_mflags))
3326 map->map_file, map->map_domain, yperr_string(yperr));
3334 ** NIS_MAP_LOOKUP -- look up a datum in a NIS map
3354 map->map_mname, name);
3357 if (buflen > sizeof(keybuf) - 1)
3358 buflen = sizeof(keybuf) - 1;
3361 if (!bitset(MF_NOFOLDCASE, map->map_mflags))
3365 if (bitset(MF_TRY0NULL, map->map_mflags))
3367 yperr = yp_match(map->map_domain, map->map_file, keybuf, buflen,
3370 map->map_mflags &= ~MF_TRY1NULL;
3372 if (yperr == YPERR_KEY && bitset(MF_TRY1NULL, map->map_mflags))
3376 yperr = yp_match(map->map_domain, map->map_file, keybuf, buflen,
3379 map->map_mflags &= ~MF_TRY0NULL;
3384 map->map_mflags &= ~(MF_VALID|MF_OPEN);
3389 if (bitset(MF_MATCHONLY, map->map_mflags))
3401 ** NIS_GETCANONNAME -- look up canonical name in NIS
3496 # undef T_UNSPEC /* symbol conflict in nis.h -> ... -> sys/tiuser.h */
3504 # define COL_NAME(res,i) ((res->objects.objects_val)->TA_data.ta_cols.ta_cols_val)[i].tc_name
3505 # define COL_MAX(res) ((res->objects.objects_val)->TA_data.ta_cols.ta_cols_len)
3506 # define PARTIAL_NAME(x) ((x)[strlen(x) - 1] != '.')
3509 ** NISPLUS_MAP_OPEN -- open nisplus table
3523 map->map_mname, map->map_file, mode);
3532 if (*map->map_file == '\0')
3533 map->map_file = "mail_aliases.org_dir";
3535 if (PARTIAL_NAME(map->map_file) && map->map_domain == NULL)
3538 map->map_domain = newstr(nisplus_default_domain());
3541 map->map_file, map->map_domain);
3543 if (!PARTIAL_NAME(map->map_file))
3545 map->map_domain = newstr("");
3546 (void) sm_strlcpy(qbuf, map->map_file, sizeof(qbuf));
3552 map->map_file, ".", map->map_domain);
3556 while (res == NULL || res->status != NIS_SUCCESS)
3559 switch (res->status)
3578 if (!bitset(MF_OPTIONAL, map->map_mflags))
3580 map->map_file, map->map_domain,
3581 nis_sperrno(res->status));
3589 (NIS_RES_OBJECT(res)->zo_data.zo_type != NIS_TABLE_OBJ))
3594 if (!bitset(MF_OPTIONAL, map->map_mflags))
3596 map->map_file, map->map_domain,
3597 nis_sperrno(res->status));
3603 if (map->map_keycolnm == NULL)
3604 map->map_keycolnm = newstr(COL_NAME(res,0));
3611 if (strcmp(map->map_keycolnm, COL_NAME(res,i)) == 0)
3618 map->map_file, map->map_keycolnm);
3624 if (map->map_valcolnm == NULL)
3626 map->map_valcolno = max_col - 1;
3632 if (strcmp(map->map_valcolnm, COL_NAME(res,i)) == 0)
3634 map->map_valcolno = i;
3641 map->map_file, map->map_keycolnm);
3648 ** NISPLUS_MAP_LOOKUP -- look up a datum in a NISPLUS table
3668 map->map_mname, name);
3670 if (!bitset(MF_OPEN, map->map_mflags))
3674 map->map_mflags |= MF_OPEN;
3675 map->map_pid = CurrentPid;
3690 skleft = sizeof(search_key) - 4;
3702 skleft -= 3;
3708 skleft--;
3713 skleft--;
3718 if (!bitset(MF_NOFOLDCASE, map->map_mflags))
3722 if (PARTIAL_NAME(map->map_file))
3724 map->map_keycolnm, search_key, map->map_file,
3725 map->map_domain);
3728 map->map_keycolnm, search_key, map->map_file);
3733 if (result->status == NIS_SUCCESS)
3741 sm_syslog(LOG_WARNING, CurEnv->e_id,
3743 map->map_file, count);
3751 p = ((NIS_RES_OBJECT(result))->EN_col(map->map_valcolno));
3759 if (bitset(MF_MATCHONLY, map->map_mflags))
3769 if (result->status == NIS_NOTFOUND)
3771 else if (result->status == NIS_TRYAGAIN)
3776 map->map_mflags &= ~(MF_VALID|MF_OPEN);
3788 ** NISPLUS_GETCANONNAME -- look up canonical name in NIS+
3820 /* multi token -- take only first token in nbuf */
3838 if (result->status == NIS_SUCCESS)
3846 sm_syslog(LOG_WARNING, CurEnv->e_id,
3858 name, (NIS_RES_OBJECT(result))->zo_domain);
3861 vp = ((NIS_RES_OBJECT(result))->EN_col(0));
3892 if (result->status == NIS_NOTFOUND)
3894 else if (result->status == NIS_TRYAGAIN)
3901 name, result->status, *statp);
3926 ** LDAPMAP_DEQUOTE - helper routine for ldapmap_parseargs
3968 ** LDAPMAP_OPEN -- open LDAP map
3970 ** Connect to the LDAP server. Re-use existing connections since a
3985 sm_dprintf("ldapmap_open(%s, %d): ", map->map_mname, mode);
3990 strcmp(map->map_mname, "aliases.ldap") == 0)
4001 /* issue a pseudo-error message */
4006 lmap = (SM_LDAP_STRUCT *) map->map_db1;
4009 if (s->s_lmap != NULL)
4012 lmap->ldap_ld = ((SM_LDAP_STRUCT *)s->s_lmap->map_db1)->ldap_ld;
4013 lmap->ldap_pid = ((SM_LDAP_STRUCT *)s->s_lmap->map_db1)->ldap_pid;
4016 lmap->ldap_next = s->s_lmap;
4017 s->s_lmap = map;
4027 if (lmap->ldap_host != NULL)
4028 id = lmap->ldap_host;
4029 else if (lmap->ldap_uri != NULL)
4030 id = lmap->ldap_uri;
4039 map->map_orgclass = map->map_class;
4040 map->map_class = &NullMapClass;
4041 map->map_mflags |= MF_OPEN;
4042 map->map_pid = CurrentPid;
4047 if (!sm_ldap_start(map->map_mname, lmap))
4052 sm_syslog(LOG_NOTICE, CurEnv->e_id,
4057 if (!bitset(MF_OPTIONAL, map->map_mflags))
4059 if (bitset(MF_NODEFER, map->map_mflags))
4067 id, map->map_mname);
4077 id, map->map_mname);
4084 s->s_lmap = map;
4089 ** LDAPMAP_CLOSE -- close ldap map
4100 sm_dprintf("ldapmap_close(%s)\n", map->map_mname);
4102 lmap = (SM_LDAP_STRUCT *) map->map_db1;
4105 if (lmap->ldap_ld == NULL)
4114 while (s->s_lmap != NULL)
4116 MAP *smap = s->s_lmap;
4120 map->map_mname, smap->map_mname);
4121 smap->map_mflags &= ~(MF_OPEN|MF_WRITABLE);
4122 lmap = (SM_LDAP_STRUCT *) smap->map_db1;
4123 lmap->ldap_ld = NULL;
4124 s->s_lmap = lmap->ldap_next;
4125 lmap->ldap_next = NULL;
4131 ** SUNET_ID_HASH -- Convert a string to its Sunet_id canonical form
4167 ** LDAPMAP_LOOKUP -- look up a datum in a LDAP map
4215 strcmp(map->map_mname, "aliases.ldap") == 0)
4240 if (bitset(MF_MATCHONLY, map->map_mflags))
4252 lmap = (SM_LDAP_STRUCT *) map->map_db1;
4253 sm_ldap_setopts(lmap->ldap_ld, lmap);
4261 if (lmap->ldap_multi_args)
4269 /* this is ugly - can we merge it with the next loop? */
4271 if (!bitset(MF_MATCHONLY, map->map_mflags))
4295 if (!bitset(MF_NOFOLDCASE, map->map_mflags))
4296 /* && !bitset(MF_MATCHONLY, map->map_mflags)) */
4323 if (!bitset(MF_NOFOLDCASE, map->map_mflags))
4329 if (lmap->ldap_multi_args)
4332 map->map_mname);
4342 map->map_mname, name);
4346 if (lmap->ldap_multi_args)
4357 errno = sm_ldap_geterrno(lmap->ldap_ld) + E_LDAPBASE;
4359 if (!bitset(MF_OPTIONAL, map->map_mflags))
4366 if (bitset(MF_NODEFER, map->map_mflags))
4368 map->map_mname);
4371 map->map_mname);
4374 switch (save_errno - E_LDAPBASE)
4391 if (bitset(MF_NODEFER, map->map_mflags))
4393 map->map_mname);
4396 map->map_mname);
4406 if (bitset(MF_SINGLEMATCH, map->map_mflags))
4408 if (bitset(MF_MATCHONLY, map->map_mflags))
4411 if (bitset(MF_SINGLEDN, map->map_mflags))
4419 *statp = sm_ldap_results(lmap, msgid, flags, map->map_coldelim,
4438 if (!bitset(MF_OPTIONAL, map->map_mflags))
4440 if (bitset(MF_NODEFER, map->map_mflags))
4442 map->map_mname, name);
4445 map->map_mname, name);
4452 if (vp == NULL && !bitset(MF_MATCHONLY, map->map_mflags))
4458 sm_syslog(LOG_INFO, CurEnv->e_id,
4459 "ldap=%s, %.100s=>%s", map->map_mname, name,
4461 if (bitset(MF_MATCHONLY, map->map_mflags))
4483 ** LDAPMAP_FINDCONN -- find an LDAP connection to the server
4492 ** lmap -- LDAP map information
4507 if (lmap->ldap_host != NULL)
4508 id = lmap->ldap_host;
4509 else if (lmap->ldap_uri != NULL)
4510 id = lmap->ldap_uri;
4518 lmap->ldap_port,
4520 lmap->ldap_version,
4522 (lmap->ldap_binddn == NULL ? ""
4523 : lmap->ldap_binddn),
4525 (lmap->ldap_secret == NULL ? ""
4526 : lmap->ldap_secret),
4536 ** LDAPMAP_PARSEARGS -- parse ldap map definition args.
4584 lmap = (SM_LDAP_STRUCT *) map->map_db1;
4600 map->map_mflags |= MF_TRY0NULL|MF_TRY1NULL;
4601 map->map_spacesub = SpaceSub; /* default value */
4604 if (bitset(MF_ALIAS, map->map_mflags))
4607 map->map_coldelim = ',';
4638 map->map_mname);
4643 lmap->ldap_filter = ldapfilt;
4644 lmap->ldap_attr[0] = "objectClass";
4645 lmap->ldap_attr_type[0] = SM_LDAP_ATTR_OBJCLASS;
4646 lmap->ldap_attr_needobjclass[0] = NULL;
4647 lmap->ldap_attr[1] = "sendmailMTAAliasValue";
4648 lmap->ldap_attr_type[1] = SM_LDAP_ATTR_NORMAL;
4649 lmap->ldap_attr_needobjclass[1] = NULL;
4650 lmap->ldap_attr[2] = "sendmailMTAAliasSearch";
4651 lmap->ldap_attr_type[2] = SM_LDAP_ATTR_FILTER;
4652 lmap->ldap_attr_needobjclass[2] = "sendmailMTAMapObject";
4653 lmap->ldap_attr[3] = "sendmailMTAAliasURL";
4654 lmap->ldap_attr_type[3] = SM_LDAP_ATTR_URL;
4655 lmap->ldap_attr_needobjclass[3] = "sendmailMTAMapObject";
4656 lmap->ldap_attr[4] = NULL;
4657 lmap->ldap_attr_type[4] = SM_LDAP_ATTR_NONE;
4658 lmap->ldap_attr_needobjclass[4] = NULL;
4662 else if (bitset(MF_FILECLASS, map->map_mflags))
4665 map->map_coldelim = ' ';
4669 if (0 == lmap->ldap_networktmo)
4670 lmap->ldap_networktmo = (LDAP_NETWORK_TIMEOUT > 1)
4678 if (*p != '-')
4683 map->map_mflags |= MF_APPEND;
4687 map->map_app = ++p;
4691 map->map_mflags |= MF_DEFER;
4695 map->map_mflags |= MF_NOFOLDCASE;
4699 map->map_mflags |= MF_MATCHONLY;
4703 map->map_mflags |= MF_INCLNULL;
4704 map->map_mflags &= ~MF_TRY0NULL;
4708 map->map_mflags &= ~MF_TRY1NULL;
4712 map->map_mflags |= MF_OPTIONAL;
4716 map->map_mflags |= MF_KEEPQUOTES;
4720 map->map_spacesub = *++p;
4724 map->map_tapp = ++p;
4728 map->map_mflags |= MF_NODEFER;
4733 map->map_coldelim = *p;
4739 map->map_coldelim = '\n';
4743 map->map_coldelim = '\t';
4747 map->map_coldelim = '\\';
4754 map->map_mflags |= MF_SINGLEMATCH;
4759 map->map_mflags |= MF_SINGLEDN;
4766 lmap->ldap_base = p;
4773 lmap->ldap_networktmo = atoi(p);
4780 lmap->ldap_binddn = p;
4785 syserr("Must compile with -DUSE_LDAP_INIT to use LDAP URIs (-H) in map %s",
4786 map->map_mname);
4789 if (lmap->ldap_host != NULL)
4792 map->map_mname);
4797 lmap->ldap_uri = p;
4804 if (lmap->ldap_uri != NULL)
4807 map->map_mname);
4810 lmap->ldap_host = p;
4814 lmap->ldap_multi_args = true;
4820 lmap->ldap_filter = p;
4826 lmap->ldap_timelimit = atoi(p);
4827 lmap->ldap_timeout.tv_sec = lmap->ldap_timelimit;
4838 lam != NULL && lam->lam_name != NULL; lam++)
4840 if (sm_strncasecmp(p, lam->lam_name,
4841 strlen(lam->lam_name)) == 0)
4844 if (lam->lam_name != NULL)
4845 lmap->ldap_method = lam->lam_code;
4850 map->map_class->map_cflags))
4857 p, map->map_mname);
4866 lmap->ldap_attrsonly = LDAPMAP_TRUE;
4877 lmap->ldap_secret = p;
4884 lmap->ldap_port = atoi(p);
4890 lmap->ldap_options &= ~LDAP_OPT_REFERRALS;
4892 syserr("compile with -DLDAP_REFERRALS for referral support");
4904 lad != NULL && lad->lad_name != NULL; lad++)
4906 if (sm_strncasecmp(p, lad->lad_name,
4907 strlen(lad->lad_name)) == 0)
4910 if (lad->lad_name != NULL)
4911 lmap->ldap_deref = lad->lad_code;
4916 map->map_class->map_cflags))
4923 p, map->map_mname);
4939 lss != NULL && lss->lss_name != NULL; lss++)
4941 if (sm_strncasecmp(p, lss->lss_name,
4942 strlen(lss->lss_name)) == 0)
4945 if (lss->lss_name != NULL)
4946 lmap->ldap_scope = lss->lss_code;
4951 map->map_class->map_cflags))
4958 p, map->map_mname);
4968 lmap->ldap_attrsep = *p;
4974 lmap->ldap_attrsep = '\n';
4978 lmap->ldap_attrsep = '\t';
4982 lmap->ldap_attrsep = '\\';
4990 lmap->ldap_attr[0] = p;
4991 lmap->ldap_attr[1] = NULL;
4995 /* -w should be for passwd, -P should be for version */
4998 lmap->ldap_version = atoi(p);
5000 if (lmap->ldap_version > LDAP_VERSION_MAX)
5003 lmap->ldap_version, LDAP_VERSION_MAX,
5004 map->map_mname);
5009 if (lmap->ldap_version < LDAP_VERSION_MIN)
5012 lmap->ldap_version, LDAP_VERSION_MIN,
5013 map->map_mname);
5023 lmap->ldap_debug = atoi(p);
5030 lmap->ldap_sizelimit = atoi(p);
5034 syserr("Illegal option %c map %s", *p, map->map_mname);
5056 if (map->map_app != NULL)
5057 map->map_app = newstr(ldapmap_dequote(map->map_app));
5058 if (map->map_tapp != NULL)
5059 map->map_tapp = newstr(ldapmap_dequote(map->map_tapp));
5063 ** and dump it into map->map_dbptr1
5066 if (lmap->ldap_host != NULL &&
5069 LDAPDefaults->ldap_host != lmap->ldap_host))
5070 lmap->ldap_host = newstr(ldapmap_dequote(lmap->ldap_host));
5071 map->map_domain = lmap->ldap_host;
5073 if (lmap->ldap_uri != NULL &&
5076 LDAPDefaults->ldap_uri != lmap->ldap_uri))
5077 lmap->ldap_uri = newstr(ldapmap_dequote(lmap->ldap_uri));
5078 map->map_domain = lmap->ldap_uri;
5080 if (lmap->ldap_binddn != NULL &&
5083 LDAPDefaults->ldap_binddn != lmap->ldap_binddn))
5084 lmap->ldap_binddn = newstr(ldapmap_dequote(lmap->ldap_binddn));
5086 if (lmap->ldap_secret != NULL &&
5089 LDAPDefaults->ldap_secret != lmap->ldap_secret))
5098 switch (lmap->ldap_method)
5115 sfd = safefopen(ldapmap_dequote(lmap->ldap_secret),
5120 ldapmap_dequote(lmap->ldap_secret));
5123 lmap->ldap_secret = sfgets(m_tmp, sizeof(m_tmp),
5130 ldapmap_dequote(lmap->ldap_secret));
5133 if (lmap->ldap_secret != NULL &&
5137 if (m_tmp[strlen(m_tmp) - 1] == '\n')
5138 m_tmp[strlen(m_tmp) - 1] = '\0';
5140 lmap->ldap_secret = m_tmp;
5154 ldapmap_dequote(lmap->ldap_secret));
5155 lmap->ldap_secret = m_tmp;
5167 if (lmap->ldap_secret != NULL &&
5170 LDAPDefaults->ldap_secret != lmap->ldap_secret))
5171 lmap->ldap_secret = newstr(ldapmap_dequote(lmap->ldap_secret));
5173 if (lmap->ldap_base != NULL &&
5176 LDAPDefaults->ldap_base != lmap->ldap_base))
5177 lmap->ldap_base = newstr(ldapmap_dequote(lmap->ldap_base));
5187 if (bitset(MF_SINGLEMATCH, map->map_mflags))
5188 lmap->ldap_sizelimit = 2;
5194 if (lmap->ldap_filter != NULL)
5195 lmap->ldap_filter = newstr(ldapmap_dequote(lmap->ldap_filter));
5198 if (!bitset(MCF_OPTFILE, map->map_class->map_cflags))
5200 syserr("No filter given in map %s", map->map_mname);
5205 if (!attrssetup && lmap->ldap_attr[0] != NULL)
5211 p = ldapmap_dequote(lmap->ldap_attr[0]);
5212 lmap->ldap_attr[0] = NULL;
5215 lmap->ldap_attr[i] = "objectClass";
5216 lmap->ldap_attr_type[i] = SM_LDAP_ATTR_OBJCLASS;
5217 lmap->ldap_attr_needobjclass[i] = NULL;
5236 map->map_mname, LDAPMAP_MAX_ATTR);
5263 lmap->ldap_attr_type[0] == SM_LDAP_ATTR_OBJCLASS)
5276 if (SM_STRCASEEQ(v, lmap->ldap_attr[j]))
5279 v, map->map_mname);
5284 lmap->ldap_attr[use] = newstr(v);
5289 lmap->ldap_attr_needobjclass[use] = newstr(needobjclass);
5293 lmap->ldap_attr_needobjclass[use] = NULL;
5303 lmap->ldap_attr_type[use] = SM_LDAP_ATTR_DN;
5308 lmap->ldap_attr_type[use] = SM_LDAP_ATTR_FILTER;
5313 lmap->ldap_attr_type[use] = SM_LDAP_ATTR_URL;
5317 lmap->ldap_attr_type[use] = SM_LDAP_ATTR_NORMAL;
5323 type, map->map_mname);
5329 lmap->ldap_attr_type[use] = SM_LDAP_ATTR_NORMAL;
5335 lmap->ldap_attr[i] = NULL;
5343 map->map_mname);
5346 if (recurse && lmap->ldap_attrsonly == LDAPMAP_TRUE)
5348 syserr("LDAP recursion requested in %s can not be used with -n",
5349 map->map_mname);
5353 map->map_db1 = (ARBPTR_T) lmap;
5361 ** LDAPMAP_SET_DEFAULTS -- Read default map spec from LDAPDefaults in .cf
5364 ** spec -- map argument string from LDAPDefaults option
5391 map.map_class = &class->s_mapclass;
5403 syserr("readcf: option LDAPDefaultSpec: Do not set non-LDAP specific flags");
5408 if (LDAPDefaults->ldap_filter != NULL)
5413 LDAPDefaults->ldap_filter = NULL;
5416 if (LDAPDefaults->ldap_attr[0] != NULL)
5420 LDAPDefaults->ldap_attr[0] = NULL;
5431 ** Support for the CCSO Nameserver (ph/qi).
5432 ** This code is intended to replace the so-called "ph mailer".
5433 ** Contributed by Mark D. Roth. Contact him for support.
5442 /* assume we're using nph-1.2.x if not specified */
5447 /* compatibility for versions older than nph-1.2.0 */
5457 ** PH_MAP_PARSEARGS -- parse ph map definition args.
5471 "sendmail-%s phmap-20010529 libphclient-%s",
5477 pmap->ph_servers = NULL;
5478 pmap->ph_field_list = NULL;
5479 pmap->ph = NULL;
5480 pmap->ph_timeout = 0;
5481 pmap->ph_fastclose = 0;
5483 map->map_mflags |= MF_TRY0NULL|MF_TRY1NULL;
5488 if (*p != '-')
5493 map->map_mflags |= MF_INCLNULL;
5494 map->map_mflags &= ~MF_TRY0NULL;
5498 map->map_mflags &= ~MF_TRY1NULL;
5502 map->map_mflags |= MF_OPTIONAL;
5506 map->map_mflags |= MF_NOFOLDCASE;
5510 map->map_mflags |= MF_MATCHONLY;
5514 map->map_mflags |= MF_APPEND;
5518 map->map_mflags |= MF_KEEPQUOTES;
5522 map->map_mflags |= MF_NODEFER;
5526 map->map_app = ++p;
5530 map->map_tapp = ++p;
5536 pmap->ph_timeout = atoi(p);
5540 map->map_spacesub = *++p;
5544 map->map_mflags |= MF_DEFER;
5550 pmap->ph_servers = p;
5556 pmap->ph_field_list = p;
5560 syserr("ph_map_parseargs: unknown option -%c", *p);
5583 if (map->map_app != NULL)
5584 map->map_app = newstr(ph_map_dequote(map->map_app));
5585 if (map->map_tapp != NULL)
5586 map->map_tapp = newstr(ph_map_dequote(map->map_tapp));
5588 if (pmap->ph_field_list != NULL)
5589 pmap->ph_field_list = newstr(ph_map_dequote(pmap->ph_field_list));
5591 if (pmap->ph_servers != NULL)
5592 pmap->ph_servers = newstr(ph_map_dequote(pmap->ph_servers));
5595 syserr("ph_map_parseargs: -h flag is required");
5599 map->map_db1 = (ARBPTR_T) pmap;
5604 ** PH_MAP_CLOSE -- close the connection to the ph server
5613 pmap = (PH_MAP_STRUCT *)map->map_db1;
5615 sm_dprintf("ph_map_close(%s): pmap->ph_fastclose=%d\n",
5616 map->map_mname, pmap->ph_fastclose);
5619 if (pmap->ph != NULL)
5621 ph_set_sendhook(pmap->ph, NULL);
5622 ph_set_recvhook(pmap->ph, NULL);
5623 ph_close(pmap->ph, pmap->ph_fastclose);
5626 map->map_mflags &= ~(MF_OPEN|MF_WRITABLE);
5656 sm_syslog(LOG_NOTICE, CurEnv->e_id,
5672 sm_syslog(LOG_NOTICE, CurEnv->e_id,
5679 ** PH_MAP_OPEN -- sub for opening PH map
5692 sm_dprintf("ph_map_open(%s)\n", map->map_mname);
5697 /* issue a pseudo-error message */
5702 if (CurEnv != NULL && CurEnv->e_sendmode == SM_DEFER &&
5703 bitset(MF_DEFER, map->map_mflags))
5707 map->map_mname);
5712 ** map->map_tapp instead of the default permanent error.
5715 map->map_mflags &= ~MF_DEFER;
5719 pmap = (PH_MAP_STRUCT *)map->map_db1;
5720 pmap->ph_fastclose = 0; /* refresh field for reopen */
5723 hostlist = newstr(pmap->ph_servers);
5729 if (pmap->ph_timeout != 0)
5735 sm_syslog(LOG_NOTICE, CurEnv->e_id,
5741 ev = sm_setevent(pmap->ph_timeout, ph_timeout, 0);
5745 if (ph_open(&(pmap->ph), host,
5752 && ph_id(pmap->ph, phmap_id) == 0)
5764 pmap->ph_fastclose = PH_CLOSE_FAST;
5769 if (bitset(MF_NODEFER, map->map_mflags))
5774 map->map_mname);
5776 else if (!bitset(MF_OPTIONAL, map->map_mflags) && LogLevel > 1)
5777 sm_syslog(LOG_NOTICE, CurEnv->e_id,
5779 map->map_mname);
5785 ** PH_MAP_LOOKUP -- look up key from ph server
5800 pmap = (PH_MAP_STRUCT *)map->map_db1;
5805 if (pmap->ph_timeout != 0)
5811 sm_syslog(LOG_NOTICE, CurEnv->e_id,
5818 ev = sm_setevent(pmap->ph_timeout, ph_timeout, 0);
5822 i = ph_email_resolve(pmap->ph, key, pmap->ph_field_list, &value);
5823 if (i == -1)
5840 pmap->ph_fastclose = PH_CLOSE_FAST;
5850 if (bitset(MF_MATCHONLY, map->map_mflags))
5867 ** SYSLOG_MAP_PARSEARGS -- check for priority level to syslog messages.
5883 if (*p != '-')
5888 map->map_mflags |= MF_DEFER;
5893 map->map_spacesub = *++p;
5917 map->map_prio = LOG_INFO;
5925 map->map_prio = LOG_EMERG;
5930 map->map_prio = LOG_ALERT;
5935 map->map_prio = LOG_CRIT;
5940 map->map_prio = LOG_ERR;
5945 map->map_prio = LOG_WARNING;
5950 map->map_prio = LOG_NOTICE;
5955 map->map_prio = LOG_INFO;
5960 map->map_prio = LOG_DEBUG;
5970 map->map_mflags |= MF_KEEPXFMT;
5976 ** SYSLOG_MAP_LOOKUP -- rewrite and syslog message. Always return empty string
5992 map->map_mname, map->map_prio, ptr);
5994 sm_syslog(map->map_prio, CurEnv->e_id, "%s", ptr);
6009 ** DPRINTF_MAP_PARSEARGS -- check for priority level to dprintf messages.
6025 if (*p != '-')
6030 map->map_mflags |= MF_DEFER;
6035 map->map_spacesub = *++p;
6059 map->map_dbg_level = 0;
6064 syserr("dprintf map \"%s\", file %s: -d should specify a number, not %s",
6065 map->map_mname, map->map_file,
6069 map->map_dbg_level = atoi(dbg_level);
6072 map->map_mflags |= MF_KEEPXFMT;
6078 ** DPRINTF_MAP_LOOKUP -- rewrite and print message. Always return empty string
6090 if (ptr != NULL && tTd(85, map->map_dbg_level))
6110 map->map_mname, map->map_file, mode);
6114 /* issue a pseudo-error message */
6123 if (!bitset(MF_OPTIONAL, map->map_mflags))
6137 if (!bitset(MF_OPTIONAL, map->map_mflags))
6154 sm_dprintf("hes_map_lookup(%s, %s)\n", map->map_file, name);
6161 char nbuf[MAXNAME]; /* EAI:ok - larger buffer used if needed */
6164 if (nl < sizeof(nbuf) - 1)
6169 (void) sm_strlcpy(&np[1], name, sizeof(nbuf) - 1);
6171 hp = hesiod_resolve(HesiodContext, np, map->map_file);
6173 hp = hes_resolve(np, map->map_file);
6183 hp = hesiod_resolve(HesiodContext, name, map->map_file);
6185 hp = hes_resolve(name, map->map_file);
6234 if (bitset(MF_MATCHONLY, map->map_mflags))
6241 ** HES_MAP_CLOSE -- free the Hesiod context
6249 sm_dprintf("hes_map_close(%s)\n", map->map_file);
6272 ** NI_MAP_OPEN -- open NetInfo Aliases
6282 map->map_mname, map->map_file, mode);
6285 if (*map->map_file == '\0')
6286 map->map_file = NETINFO_DEFAULT_DIR;
6288 if (map->map_valcolnm == NULL)
6289 map->map_valcolnm = NETINFO_DEFAULT_PROPERTY;
6291 if (map->map_coldelim == '\0')
6293 if (bitset(MF_ALIAS, map->map_mflags))
6294 map->map_coldelim = ',';
6295 else if (bitset(MF_FILECLASS, map->map_mflags))
6296 map->map_coldelim = ' ';
6303 ** NI_MAP_LOOKUP -- look up a datum in NetInfo
6317 sm_dprintf("ni_map_lookup(%s, %s)\n", map->map_mname, name);
6319 propval = ni_propval(map->map_file, map->map_keycolnm, name,
6320 map->map_valcolnm, map->map_coldelim);
6326 if (bitset(MF_MATCHONLY, map->map_mflags))
6398 ** TEXT_MAP_OPEN -- open text table
6411 map->map_mname, map->map_file, mode);
6420 if (*map->map_file == '\0')
6423 map->map_mname);
6427 if (map->map_file[0] != '/')
6430 map->map_mname);
6439 if ((i = safefile(map->map_file, RunAsUid, RunAsGid, RunAsUserName,
6448 if (!bitset(MF_OPTIONAL, map->map_mflags))
6450 map->map_mname, map->map_file);
6454 if (map->map_keycolnm == NULL)
6455 map->map_keycolno = 0;
6458 if (!(isascii(*map->map_keycolnm) && isdigit(*map->map_keycolnm)))
6460 syserr("text map \"%s\", file %s: -k should specify a number, not %s",
6461 map->map_mname, map->map_file,
6462 map->map_keycolnm);
6465 map->map_keycolno = atoi(map->map_keycolnm);
6468 if (map->map_valcolnm == NULL)
6469 map->map_valcolno = 0;
6472 if (!(isascii(*map->map_valcolnm) && isdigit(*map->map_valcolnm)))
6474 syserr("text map \"%s\", file %s: -v should specify a number, not %s",
6475 map->map_mname, map->map_file,
6476 map->map_valcolnm);
6479 map->map_valcolno = atoi(map->map_valcolnm);
6485 map->map_mname, map->map_file);
6486 if (map->map_coldelim == '\0')
6489 sm_dprintf("%c\n", map->map_coldelim);
6492 map->map_sff = sff;
6498 ** TEXT_MAP_LOOKUP -- look up a datum in a TEXT table
6515 long sff = map->map_sff;
6522 sm_dprintf("text_map_lookup(%s, %s)\n", map->map_mname, name);
6525 if (buflen > sizeof(search_key) - 1)
6526 buflen = sizeof(search_key) - 1; /* XXX just cut if off? */
6529 if (!bitset(MF_NOFOLDCASE, map->map_mflags))
6532 f = safefopen(map->map_file, O_RDONLY, FileMode, sff);
6535 map->map_mflags &= ~(MF_VALID|MF_OPEN);
6539 key_idx = map->map_keycolno;
6540 delim = map->map_coldelim;
6565 vp = get_column(linebuf, map->map_valcolno, delim, buf, sizeof(buf));
6573 if (bitset(MF_MATCHONLY, map->map_mflags))
6580 ** TEXT_GETCANONNAME -- look up canonical name in hosts file
6647 ** STAB_MAP_LOOKUP -- look up alias in symbol table
6662 map->map_mname, name);
6667 if (bitset(MF_MATCHONLY, map->map_mflags))
6670 return map_rewrite(map, s->s_alias, strlen(s->s_alias), av);
6674 ** STAB_MAP_STORE -- store in symtab (actually using during init, not rebuild)
6686 s->s_alias = newstr(rhs);
6691 ** STAB_MAP_OPEN -- initialize (reads data file)
6693 ** This is a weird case -- it is only intended as a fallback for
6710 map->map_mname, map->map_file, mode);
6724 af = safefopen(map->map_file, O_RDONLY, 0444, sff);
6730 map->map_mtime = st.st_mtime;
6743 ** IMPL_MAP_LOOKUP -- lookup in best open database
6755 map->map_mname, name);
6758 if (bitset(MF_IMPL_HASH, map->map_mflags))
6762 if (bitset(MF_IMPL_NDBM, map->map_mflags))
6766 if (bitset(MF_IMPL_CDB, map->map_mflags))
6773 ** IMPL_MAP_STORE -- store in open databases
6784 map->map_mname, lhs, rhs);
6786 if (bitset(MF_IMPL_HASH, map->map_mflags))
6790 if (bitset(MF_IMPL_NDBM, map->map_mflags))
6794 if (bitset(MF_IMPL_CDB, map->map_mflags))
6801 ** IMPL_MAP_OPEN -- implicit database open
6813 map->map_mname, map->map_file, mode);
6816 wasopt = bitset(MF_OPTIONAL, map->map_mflags);
6819 map->map_mflags |= MF_OPTIONAL;
6821 map->map_mflags |= MF_IMPL_HASH;
6825 if (mode == O_RDONLY || strstr(map->map_file, "/yp/") == NULL)
6830 map->map_mflags &= ~MF_IMPL_HASH;
6833 map->map_mflags |= MF_IMPL_NDBM;
6837 map->map_mflags &= ~MF_IMPL_NDBM;
6841 map->map_mflags |= MF_IMPL_CDB;
6845 map->map_mflags &= ~MF_IMPL_CDB;
6848 if (!bitset(MF_ALIAS, map->map_mflags))
6853 map->map_file,
6865 map->map_mflags &= ~MF_OPTIONAL;
6870 map->map_mflags &= ~MF_OPTIONAL;
6876 ** IMPL_MAP_CLOSE -- close any open database(s)
6885 map->map_mname, map->map_file, map->map_mflags);
6887 if (bitset(MF_IMPL_HASH, map->map_mflags))
6890 map->map_mflags &= ~MF_IMPL_HASH;
6895 if (bitset(MF_IMPL_NDBM, map->map_mflags))
6898 map->map_mflags &= ~MF_IMPL_NDBM;
6902 if (bitset(MF_IMPL_CDB, map->map_mflags))
6905 map->map_mflags &= ~MF_IMPL_CDB;
6917 ** USER_MAP_OPEN -- open user map
6929 map->map_mname, mode);
6934 /* issue a pseudo-error message */
6938 if (map->map_valcolnm == NULL)
6941 else if (SM_STRCASEEQ(map->map_valcolnm, "name"))
6942 map->map_valcolno = 1;
6943 else if (SM_STRCASEEQ(map->map_valcolnm, "passwd"))
6944 map->map_valcolno = 2;
6945 else if (SM_STRCASEEQ(map->map_valcolnm, "uid"))
6946 map->map_valcolno = 3;
6947 else if (SM_STRCASEEQ(map->map_valcolnm, "gid"))
6948 map->map_valcolno = 4;
6949 else if (SM_STRCASEEQ(map->map_valcolnm, "gecos"))
6950 map->map_valcolno = 5;
6951 else if (SM_STRCASEEQ(map->map_valcolnm, "dir"))
6952 map->map_valcolno = 6;
6953 else if (SM_STRCASEEQ(map->map_valcolnm, "shell"))
6954 map->map_valcolno = 7;
6958 map->map_mname, map->map_valcolnm);
6966 ** USER_MAP_LOOKUP -- look up a user in the passwd file.
6982 map->map_mname, key);
6987 if (bitset(MF_MATCHONLY, map->map_mflags))
6994 switch (map->map_valcolno)
7030 map->map_mname, map->map_valcolno);
7063 map->map_mname, name, map->map_file);
7066 argv[i++] = map->map_file;
7067 if (map->map_rebuild != NULL)
7069 (void) sm_strlcpy(buf, map->map_rebuild, sizeof(buf));
7072 if (i >= MAXPV - 1)
7090 if (!bitset(MF_OPTIONAL, map->map_mflags))
7091 syserr("prog_map_lookup(%s) failed (%s) -- closing",
7092 map->map_mname, sm_errstring(errno));
7094 sm_dprintf("prog_map_lookup(%s) failed (%s) -- closing",
7095 map->map_mname, sm_errstring(errno));
7096 map->map_mflags &= ~(MF_VALID|MF_OPEN);
7100 i = read(fd, buf, sizeof(buf) - 1);
7104 map->map_mname, sm_errstring(errno));
7111 map->map_mname);
7122 if (bitset(MF_MATCHONLY, map->map_mflags))
7139 if (status == -1)
7142 map->map_mname, sm_errstring(errno));
7154 map->map_mname, status);
7165 ** support storing.
7170 ** at a system-dependent configuration file such as
7178 ** SEQ_MAP_PARSE -- Sequenced map parsing
7189 sm_dprintf("seq_map_parse(%s, %s)\n", map->map_mname, ap);
7216 map->map_mname, ap);
7221 map->map_mname, MAXMAPSTACK);
7226 map->map_stack[maxmap++] = &s->s_map;
7234 ** SWITCH_MAP_OPEN -- open a switched map
7236 ** This looks at the system-dependent configuration and builds
7255 map->map_mname, map->map_file, mode);
7258 nmaps = switch_map_find(map->map_file, maptype, map->map_return);
7276 map->map_mname, ".", maptype[mapno]);
7281 map->map_mname, nbuf);
7285 map->map_stack[mapno] = &s->s_map;
7289 s->s_map.map_class->map_cname,
7298 ** SEQ_MAP_CLOSE -- close all underlying maps
7308 sm_dprintf("seq_map_close(%s)\n", map->map_mname);
7312 MAP *mm = map->map_stack[mapno];
7314 if (mm == NULL || !bitset(MF_OPEN, mm->map_mflags))
7316 mm->map_mflags |= MF_CLOSING;
7317 mm->map_class->map_close(mm);
7318 mm->map_mflags &= ~(MF_OPEN|MF_WRITABLE|MF_CLOSING);
7324 ** SEQ_MAP_LOOKUP -- sequenced map lookup
7339 sm_dprintf("seq_map_lookup(%s, %s)\n", map->map_mname, key);
7343 MAP *mm = map->map_stack[mapno];
7348 if (!bitset(MF_OPEN, mm->map_mflags) &&
7351 if (bitset(mapbit, map->map_return[MA_UNAVAIL]))
7359 rv = mm->map_class->map_lookup(mm, key, args, pstat);
7364 if (bitset(mapbit, map->map_return[MA_TRYAGAIN]))
7368 else if (bitset(mapbit, map->map_return[MA_NOTFOUND]))
7379 ** SEQ_MAP_STORE -- sequenced map store
7392 map->map_mname, key, val);
7396 MAP *mm = map->map_stack[mapno];
7398 if (mm == NULL || !bitset(MF_WRITABLE, mm->map_mflags))
7401 mm->map_class->map_store(mm, key, val);
7405 map->map_mname, key, val);
7451 "null-map", NULL, 0,
7473 "bogus-map", NULL, 0,
7491 sm_dprintf("macro_map_lookup(%s, %s)\n", map->map_mname,
7503 macdefine(&CurEnv->e_macro, A_PERM, mid, NULL);
7505 macdefine(&CurEnv->e_macro, A_TEMP, mid, av[1]);
7519 # define END_OF_FIELDS -1
7546 blen--; /* for terminating END_OF_FIELDS */
7571 return -1;
7578 return -1;
7600 map->map_mname, ap);
7605 map_p->regex_pattern_buf = (regex_t *)xnalloc(sizeof(regex_t));
7611 if (*p != '-')
7616 map->map_mflags |= MF_REGEX_NOT;
7620 map->map_mflags |= MF_NOFOLDCASE;
7634 map_p->regex_delim = ++p;
7638 map->map_app = ++p;
7642 map->map_mflags |= MF_MATCHONLY;
7646 map->map_mflags |= MF_KEEPQUOTES;
7650 map->map_spacesub = *++p;
7654 map->map_mflags |= MF_DEFER;
7669 if ((regerr = regcomp(map_p->regex_pattern_buf, p, pflags)) != 0)
7674 (void) regerror(regerr, map_p->regex_pattern_buf,
7676 syserr("pattern-compile-error: %s", errbuf);
7677 sm_free(map_p->regex_pattern_buf); /* XXX */
7682 if (map->map_app != NULL)
7683 map->map_app = newstr(map->map_app);
7684 if (map_p->regex_delim != NULL)
7685 map_p->regex_delim = newstr(map_p->regex_delim);
7687 map_p->regex_delim = defdstr;
7695 substrings = map_p->regex_pattern_buf->re_nsub + 1;
7704 SM_FREE(map_p->regex_pattern_buf); /* XXX */
7711 /* optional parameter -sfields */
7713 MAX_MATCH + 1, substrings) == -1)
7715 SM_FREE(map_p->regex_pattern_buf); /* XXX */
7730 map_p->regex_subfields = fields;
7741 map->map_db1 = (ARBPTR_T) map_p; /* dirty hack */
7752 if (bitset(MF_MATCHONLY, map->map_mflags))
7774 map->map_mname, name);
7779 map_p = (struct regex_map *)(map->map_db1);
7780 reg_res = regexec(map_p->regex_pattern_buf,
7783 if (bitset(MF_REGEX_NOT, map->map_mflags))
7785 /* option -n */
7794 if (map_p->regex_subfields != NULL)
7796 /* option -s */
7807 ldp = retbuf + sizeof(retbuf) - 1;
7812 (int) map_p->regex_pattern_buf->re_nsub + 1) == -1)
7820 ip = map_p->regex_subfields;
7826 for (sp = map_p->regex_delim; *sp; sp++)
7866 cmntcnt--;
7874 anglecnt--;
7893 map->map_mname, name);
7926 for (ns_map = ns_maps; ns_map != NULL; ns_map = ns_map->next)
7928 if (strcmp(ns_map->mapname, mapname) == 0)
7936 ns_map->mapname = newstr(mapname);
7937 ns_map->map = (ns_map_t *) xalloc(sizeof(*ns_map->map));
7938 memset(ns_map->map, '\0', sizeof(*ns_map->map));
7939 ns_map->next = ns_maps;
7942 return ns_map->map;
7959 sm_dprintf("nsd_map_lookup(%s, %s)\n", map->map_mname, name);
7962 if (buflen > sizeof(keybuf) - 1)
7963 buflen = sizeof(keybuf) - 1; /* XXX simply cut off? */
7966 if (!bitset(MF_NOFOLDCASE, map->map_mflags))
7969 ns_map = ns_map_t_find(map->map_file);
7977 r = ns_lookup(ns_map, NULL, map->map_file, keybuf, NULL,
8036 ** - no check is made whether they are really numbers
8037 ** - just ignores args after the second
8065 case '-':
8066 r = v[0] - v[1];
8090 r = v[1] - v[0] + 1;
8153 for (i = 15; i >= 0; i--) {
8188 if (bitset(MF_MATCHONLY, map->map_mflags))
8282 ** SOCKET_MAP_OPEN -- open socket table
8304 map->map_mname, map->map_file, mode);
8311 /* issue a pseudo-error message */
8316 if (*map->map_file == '\0')
8319 map->map_mname);
8323 s = socket_map_findconn(map->map_file);
8324 if (s->s_socketmap != NULL)
8327 map->map_db1 = s->s_socketmap->map_db1;
8330 map->socket_map_next = s->s_socketmap;
8331 s->s_socketmap = map;
8346 p = map->map_file;
8368 map->map_mname);
8395 map->map_mname, p);
8416 map->map_mname, p);
8432 map->map_mname, colon);
8442 map->map_mname, colon);
8469 map->map_mname, colon);
8479 map->map_mname, colon);
8488 map->map_mname, colon);
8491 port = sp->s_port;
8535 map->map_mname, at);
8542 map->map_mname, at);
8552 map->map_mname, at);
8555 addr.sa.sa_family = hp->h_addrtype;
8556 switch (hp->h_addrtype)
8561 hp->h_addr, INADDRSZ);
8571 hp->h_addr, IN6ADDRSZ);
8580 map->map_mname, at, hp->h_addrtype);
8592 map->map_mname);
8605 map->map_mname,
8623 map->map_mname, at, sm_errstring(save_errno));
8628 if (hp != NULL && hp->h_addr_list[addrno] != NULL)
8635 hp->h_addr_list[addrno++],
8643 hp->h_addr_list[addrno++],
8651 map->map_mname, at,
8652 hp->h_addrtype);
8664 map->map_mname, sm_errstring(save_errno));
8679 if ((map->map_db1 = (ARBPTR_T) sm_io_open(SmFtStdiofd,
8688 map->map_mname, sm_errstring(errno));
8692 tmo = map->map_timeout;
8696 tmo *= 1000; /* s -> ms */
8697 sm_io_setinfo(map->map_db1, SM_IO_WHAT_TIMEOUT, &tmo);
8700 s->s_socketmap = map;
8705 ** SOCKET_MAP_FINDCONN -- find a SOCKET connection to the server
8714 ** conn -- SOCKET map connection specifier
8737 ** SOCKET_MAP_CLOSE -- close the socket
8748 sm_dprintf("socket_map_close(%s), pid=%ld\n", map->map_file,
8752 if (map->map_db1 == NULL)
8756 map->map_file);
8759 sm_io_close((SM_FILE_T *)map->map_db1, SM_TIME_DEFAULT);
8762 s = socket_map_findconn(map->map_file);
8763 smap = s->s_socketmap;
8770 map->map_mname, smap->map_mname);
8772 smap->map_mflags &= ~(MF_OPEN|MF_WRITABLE);
8773 smap->map_db1 = NULL;
8774 next = smap->socket_map_next;
8775 smap->socket_map_next = NULL;
8778 s->s_socketmap = NULL;
8782 ** SOCKET_MAP_LOOKUP -- look up a datum in a SOCKET table
8800 f = (SM_FILE_T *)map->map_db1;
8803 map->map_mname, name, map->map_file);
8805 if (!bitset(MF_NOFOLDCASE, map->map_mflags))
8808 if (nettolen > sizeof(keybuf) - 1)
8809 nettolen = sizeof(keybuf) - 1;
8818 nettolen = strlen(map->map_mname) + 1 + strlen(key);
8819 SM_ASSERT(nettolen > strlen(map->map_mname));
8822 nettolen, map->map_mname, key) == SM_IO_EOF) ||
8827 map->map_mname);
8837 map->map_mname);
8842 sm_syslog(LOG_INFO, CurEnv->e_id,
8844 map->map_mname);
8849 map->map_mname, errno);
8857 map->map_mname, replylen);
8864 map->map_mname);
8873 map->map_mname, replylen + 1);
8882 map->map_mname, recvlen, replylen);
8889 map->map_mname);
8906 if (bitset(MF_MATCHONLY, map->map_mflags))
8916 map->map_mname, key);
8922 map->map_mname, key, status,