xref: /illumos-gate/usr/src/cmd/ypcmd/mkalias.c (revision 2a8bcb4e)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
23*a506a34cSth  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24*a506a34cSth  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
26*a506a34cSth 
27*a506a34cSth 
287c478bd9Sstevel@tonic-gate /*
297c478bd9Sstevel@tonic-gate  * mkmap - program to convert the mail.aliases map into an
307c478bd9Sstevel@tonic-gate  * inverse map of <user@host> back to <preferred-alias>
317c478bd9Sstevel@tonic-gate  */
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate #include <stdlib.h>
347c478bd9Sstevel@tonic-gate #include <unistd.h>
357c478bd9Sstevel@tonic-gate #include <string.h>
367c478bd9Sstevel@tonic-gate #include <fcntl.h>
377c478bd9Sstevel@tonic-gate #include <ndbm.h>
387c478bd9Sstevel@tonic-gate #include <stdio.h>
397c478bd9Sstevel@tonic-gate #include <ctype.h>
407c478bd9Sstevel@tonic-gate #include <netdb.h>
417c478bd9Sstevel@tonic-gate #include <sys/systeminfo.h>
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate #include "ypdefs.h"
447c478bd9Sstevel@tonic-gate USE_YP_PREFIX
457c478bd9Sstevel@tonic-gate USE_YP_MASTER_NAME
467c478bd9Sstevel@tonic-gate USE_YP_LAST_MODIFIED
477c478bd9Sstevel@tonic-gate 
487c478bd9Sstevel@tonic-gate #define	MKAL_INCLUDE ":include:"
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate void CopyName(char *dst, char *src, int len);
517c478bd9Sstevel@tonic-gate int HostCheck(char *h, char *a);
527c478bd9Sstevel@tonic-gate void DoName(char *cp);
537c478bd9Sstevel@tonic-gate void UpperCase(char *cp);
547c478bd9Sstevel@tonic-gate void AddYPEntries(void);
557c478bd9Sstevel@tonic-gate 
567c478bd9Sstevel@tonic-gate int Verbose = 0;	/* to get the gory details */
577c478bd9Sstevel@tonic-gate int UucpOK = 0;		/* pass all UUCP names right through */
587c478bd9Sstevel@tonic-gate int DomainOK = 0;	/* pass all Domain names (with dots) */
597c478bd9Sstevel@tonic-gate int ErrorCheck = 0;	/* check carefully for errors */
607c478bd9Sstevel@tonic-gate int NoOutput = 0;	/* no output, just do the check */
617c478bd9Sstevel@tonic-gate int Simple = 0;		/* Do not do the user name preference step */
627c478bd9Sstevel@tonic-gate int NameMode = 0;	/* Try to capitalize as names */
637c478bd9Sstevel@tonic-gate 
64*a506a34cSth DBM *Indbm = NULL, *Scandbm = NULL, *Outdbm = NULL;
657c478bd9Sstevel@tonic-gate 
667c478bd9Sstevel@tonic-gate int
IsMailingList(char * s)677c478bd9Sstevel@tonic-gate IsMailingList(char *s)
687c478bd9Sstevel@tonic-gate {
697c478bd9Sstevel@tonic-gate 	/*
707c478bd9Sstevel@tonic-gate 	 * returns true if the given string is a mailing list
717c478bd9Sstevel@tonic-gate 	 */
727c478bd9Sstevel@tonic-gate 	char *p;
737c478bd9Sstevel@tonic-gate 
747c478bd9Sstevel@tonic-gate 	if (strchr(s, ','))
757c478bd9Sstevel@tonic-gate 		return (1);
767c478bd9Sstevel@tonic-gate 	if (strchr(s, '|'))
777c478bd9Sstevel@tonic-gate 		return (1);
787c478bd9Sstevel@tonic-gate 	p = strchr(s, ':');
797c478bd9Sstevel@tonic-gate 	if (p && strncmp(p, MKAL_INCLUDE, sizeof (MKAL_INCLUDE)))
807c478bd9Sstevel@tonic-gate 		return (1);
817c478bd9Sstevel@tonic-gate 	return (0);
827c478bd9Sstevel@tonic-gate }
837c478bd9Sstevel@tonic-gate 
847c478bd9Sstevel@tonic-gate int
IsQualified(char * s,char * p,char * h)857c478bd9Sstevel@tonic-gate IsQualified(char *s, char *p, char *h)
867c478bd9Sstevel@tonic-gate {
877c478bd9Sstevel@tonic-gate 	/*
887c478bd9Sstevel@tonic-gate 	 * returns true if the given string is qualified with a host name
897c478bd9Sstevel@tonic-gate 	 */
907c478bd9Sstevel@tonic-gate 	register char *middle;
917c478bd9Sstevel@tonic-gate 
927c478bd9Sstevel@tonic-gate 	middle = strchr(s, '@');
937c478bd9Sstevel@tonic-gate 	if (middle) {
947c478bd9Sstevel@tonic-gate 		for (middle = s; *middle != '@'; *p++ = *middle++)
957c478bd9Sstevel@tonic-gate 			continue;
967c478bd9Sstevel@tonic-gate 		*p = '\0';
977c478bd9Sstevel@tonic-gate 		CopyName(h, middle+1, strlen(middle + 1));
987c478bd9Sstevel@tonic-gate 		return (1);
997c478bd9Sstevel@tonic-gate 	}
1007c478bd9Sstevel@tonic-gate 	middle = strrchr(s, '!');
1017c478bd9Sstevel@tonic-gate 	if (middle) {
1027c478bd9Sstevel@tonic-gate 		strcpy(p, middle+1);
1037c478bd9Sstevel@tonic-gate 		*middle = '\0';
1047c478bd9Sstevel@tonic-gate 		CopyName(h, s, strlen(s));
1057c478bd9Sstevel@tonic-gate 		*middle = '!';
1067c478bd9Sstevel@tonic-gate 		return (1);
1077c478bd9Sstevel@tonic-gate 	}
1087c478bd9Sstevel@tonic-gate 	return (0);
1097c478bd9Sstevel@tonic-gate }
1107c478bd9Sstevel@tonic-gate 
1117c478bd9Sstevel@tonic-gate int
IsMaint(char * s)1127c478bd9Sstevel@tonic-gate IsMaint(char *s)
1137c478bd9Sstevel@tonic-gate {
1147c478bd9Sstevel@tonic-gate 	/*
1157c478bd9Sstevel@tonic-gate 	 * returns true if the given string is one of the maintenence
1167c478bd9Sstevel@tonic-gate 	 * strings used in sendmail or NIS.
1177c478bd9Sstevel@tonic-gate 	 */
1187c478bd9Sstevel@tonic-gate 	if (*s == '@')
1197c478bd9Sstevel@tonic-gate 		return (1);
1207c478bd9Sstevel@tonic-gate 	if (strncmp(s, yp_prefix, yp_prefix_sz) == 0)
1217c478bd9Sstevel@tonic-gate 		return (1);
1227c478bd9Sstevel@tonic-gate 	return (0);
1237c478bd9Sstevel@tonic-gate }
1247c478bd9Sstevel@tonic-gate 
1257c478bd9Sstevel@tonic-gate void
CopyName(char * dst,char * src,int len)1267c478bd9Sstevel@tonic-gate CopyName(char *dst, char *src, int len)
1277c478bd9Sstevel@tonic-gate {
1287c478bd9Sstevel@tonic-gate 	/*
129*a506a34cSth 	 * copy a string, but ignore white space
130*a506a34cSth 	 */
1317c478bd9Sstevel@tonic-gate 	while (*src && len--) {
1327c478bd9Sstevel@tonic-gate 		if (isspace(*src))
1337c478bd9Sstevel@tonic-gate 			src++;
1347c478bd9Sstevel@tonic-gate 		else
1357c478bd9Sstevel@tonic-gate 			*dst++ = *src++;
1367c478bd9Sstevel@tonic-gate 	}
1377c478bd9Sstevel@tonic-gate 	*dst = '\0';
1387c478bd9Sstevel@tonic-gate }
1397c478bd9Sstevel@tonic-gate 
1407c478bd9Sstevel@tonic-gate int
Compare(char * s1,char * s2)1417c478bd9Sstevel@tonic-gate Compare(char *s1, char *s2)
1427c478bd9Sstevel@tonic-gate {
1437c478bd9Sstevel@tonic-gate 	/*
1447c478bd9Sstevel@tonic-gate 	 * compare strings, but ignore white space
1457c478bd9Sstevel@tonic-gate 	 */
1467c478bd9Sstevel@tonic-gate 	while (*s1 != '\0' && isspace(*s1))
1477c478bd9Sstevel@tonic-gate 		s1++;
1487c478bd9Sstevel@tonic-gate 	while (*s2 != '\0' && isspace(*s2))
1497c478bd9Sstevel@tonic-gate 		s2++;
1507c478bd9Sstevel@tonic-gate 	return (strcmp(s1, s2));
1517c478bd9Sstevel@tonic-gate }
1527c478bd9Sstevel@tonic-gate 
1537c478bd9Sstevel@tonic-gate void
ProcessMap(void)1547c478bd9Sstevel@tonic-gate ProcessMap(void)
1557c478bd9Sstevel@tonic-gate {
1567c478bd9Sstevel@tonic-gate 	datum key, value, part, partvalue;
1577c478bd9Sstevel@tonic-gate 	char address[PBLKSIZ];	/* qualified version */
1587c478bd9Sstevel@tonic-gate 	char user[PBLKSIZ];		/* unqualified version */
1597c478bd9Sstevel@tonic-gate 	char userpart[PBLKSIZ];	/* unqualified part of qualified addr. */
1607c478bd9Sstevel@tonic-gate 	char hostpart[PBLKSIZ];	/* rest of qualified addr. */
1617c478bd9Sstevel@tonic-gate 
1627c478bd9Sstevel@tonic-gate 	for (key = dbm_firstkey(Scandbm); key.dptr != NULL;
1637c478bd9Sstevel@tonic-gate 						key = dbm_nextkey(Scandbm)) {
1647c478bd9Sstevel@tonic-gate 		value = dbm_fetch(Indbm, key);
1657c478bd9Sstevel@tonic-gate 		CopyName(address, value.dptr, value.dsize);
1667c478bd9Sstevel@tonic-gate 		CopyName(user, key.dptr, key.dsize);
1677c478bd9Sstevel@tonic-gate 		if (address == NULL) continue;
1687c478bd9Sstevel@tonic-gate 		if (IsMailingList(address)) continue;
1697c478bd9Sstevel@tonic-gate 		if (!IsQualified(address, userpart, hostpart)) continue;
1707c478bd9Sstevel@tonic-gate 		if (IsMaint(user)) continue;
1717c478bd9Sstevel@tonic-gate 		if (ErrorCheck && HostCheck(hostpart, address)) {
1727c478bd9Sstevel@tonic-gate 			printf("Invalid host %s in %s:%s\n",
1737c478bd9Sstevel@tonic-gate 				hostpart, user, address);
1747c478bd9Sstevel@tonic-gate 			continue;
1757c478bd9Sstevel@tonic-gate 		}
1767c478bd9Sstevel@tonic-gate 		part.dptr = userpart;
1777c478bd9Sstevel@tonic-gate 		part.dsize = strlen(userpart) + 1;
1787c478bd9Sstevel@tonic-gate 		if (Simple)
1797c478bd9Sstevel@tonic-gate 			partvalue.dptr = NULL;
1807c478bd9Sstevel@tonic-gate 		else
1817c478bd9Sstevel@tonic-gate 			partvalue = dbm_fetch(Indbm, part);
1827c478bd9Sstevel@tonic-gate 		value.dptr = address;
1837c478bd9Sstevel@tonic-gate 		value.dsize = strlen(address) + 1;
1847c478bd9Sstevel@tonic-gate 		if (partvalue.dptr != NULL &&
1857c478bd9Sstevel@tonic-gate 			Compare(partvalue.dptr, user) == 0) {
1867c478bd9Sstevel@tonic-gate 
1877c478bd9Sstevel@tonic-gate 			if (NameMode)
1887c478bd9Sstevel@tonic-gate 				DoName(userpart);
1897c478bd9Sstevel@tonic-gate 			if (!NoOutput)
1907c478bd9Sstevel@tonic-gate 				dbm_store(Outdbm, value, part, DBM_REPLACE);
1917c478bd9Sstevel@tonic-gate 			if (Verbose) printf("%s --> %s --> %s\n",
1927c478bd9Sstevel@tonic-gate 						userpart, user, address);
1937c478bd9Sstevel@tonic-gate 		} else {
1947c478bd9Sstevel@tonic-gate 			if (NameMode)
1957c478bd9Sstevel@tonic-gate 				DoName(user);
1967c478bd9Sstevel@tonic-gate 			key.dptr = user;
1977c478bd9Sstevel@tonic-gate 			key.dsize = strlen(user) + 1;
1987c478bd9Sstevel@tonic-gate 			if (!NoOutput)
1997c478bd9Sstevel@tonic-gate 				dbm_store(Outdbm, value, key, DBM_REPLACE);
2007c478bd9Sstevel@tonic-gate 			if (Verbose)
2017c478bd9Sstevel@tonic-gate 				printf("%s --> %s\n", user, address);
2027c478bd9Sstevel@tonic-gate 		}
2037c478bd9Sstevel@tonic-gate 	}
2047c478bd9Sstevel@tonic-gate }
2057c478bd9Sstevel@tonic-gate 
2067c478bd9Sstevel@tonic-gate 
2077c478bd9Sstevel@tonic-gate /*
2087c478bd9Sstevel@tonic-gate  * Returns true if this is an invalid host
2097c478bd9Sstevel@tonic-gate  */
2107c478bd9Sstevel@tonic-gate int
HostCheck(char * h,char * a)2117c478bd9Sstevel@tonic-gate HostCheck(char *h, char *a)
2127c478bd9Sstevel@tonic-gate {
2137c478bd9Sstevel@tonic-gate 	struct hostent *hp;
2147c478bd9Sstevel@tonic-gate 
2157c478bd9Sstevel@tonic-gate 	if (DomainOK && strchr(a, '.'))
2167c478bd9Sstevel@tonic-gate 		return (0);
2177c478bd9Sstevel@tonic-gate 
2187c478bd9Sstevel@tonic-gate 	if (UucpOK && strchr(a, '!'))
2197c478bd9Sstevel@tonic-gate 		return (0);
2207c478bd9Sstevel@tonic-gate 
2217c478bd9Sstevel@tonic-gate 	hp = gethostbyname(h);
2227c478bd9Sstevel@tonic-gate 	return (hp == NULL);
2237c478bd9Sstevel@tonic-gate }
2247c478bd9Sstevel@tonic-gate 
2257c478bd9Sstevel@tonic-gate /*
2267c478bd9Sstevel@tonic-gate  * Apply some Heurisitcs to upper case-ify the name
2277c478bd9Sstevel@tonic-gate  * If it has a dot in it.
2287c478bd9Sstevel@tonic-gate  */
2297c478bd9Sstevel@tonic-gate void
DoName(char * cp)2307c478bd9Sstevel@tonic-gate DoName(char *cp)
2317c478bd9Sstevel@tonic-gate {
2327c478bd9Sstevel@tonic-gate 	if (strchr(cp, '.') == NULL)
2337c478bd9Sstevel@tonic-gate 		return;
2347c478bd9Sstevel@tonic-gate 
2357c478bd9Sstevel@tonic-gate 	while (*cp) {
2367c478bd9Sstevel@tonic-gate 		UpperCase(cp);
2377c478bd9Sstevel@tonic-gate 		while (*cp && *cp != '-' && *cp != '.')
2387c478bd9Sstevel@tonic-gate 			cp++;
2397c478bd9Sstevel@tonic-gate 		if (*cp)
2407c478bd9Sstevel@tonic-gate 			cp++;	/* skip past punctuation */
2417c478bd9Sstevel@tonic-gate 	}
2427c478bd9Sstevel@tonic-gate }
2437c478bd9Sstevel@tonic-gate 
2447c478bd9Sstevel@tonic-gate /*
2457c478bd9Sstevel@tonic-gate  * upper cases one name - stops at a .
2467c478bd9Sstevel@tonic-gate  */
2477c478bd9Sstevel@tonic-gate void
UpperCase(char * cp)2487c478bd9Sstevel@tonic-gate UpperCase(char *cp)
2497c478bd9Sstevel@tonic-gate {
250*a506a34cSth 	int ch = cp[0];
2517c478bd9Sstevel@tonic-gate 
2527c478bd9Sstevel@tonic-gate 	if (isupper(ch))
2537c478bd9Sstevel@tonic-gate 		ch = tolower(ch);
2547c478bd9Sstevel@tonic-gate 
2557c478bd9Sstevel@tonic-gate 	if (ch == 'f' && cp[1] == 'f')
2567c478bd9Sstevel@tonic-gate 		return; /* handle ff */
2577c478bd9Sstevel@tonic-gate 
2587c478bd9Sstevel@tonic-gate 	if (ch == 'm' && cp[1] == 'c' && islower(cp[2]))
2597c478bd9Sstevel@tonic-gate 		cp[2] = toupper(cp[2]);
2607c478bd9Sstevel@tonic-gate 	if (islower(ch))
2617c478bd9Sstevel@tonic-gate 		cp[0] = toupper(ch);
2627c478bd9Sstevel@tonic-gate }
2637c478bd9Sstevel@tonic-gate 
2647c478bd9Sstevel@tonic-gate void
AddYPEntries(void)2657c478bd9Sstevel@tonic-gate AddYPEntries(void)
2667c478bd9Sstevel@tonic-gate {
2677c478bd9Sstevel@tonic-gate 	datum key, value;
2687c478bd9Sstevel@tonic-gate 	char last_modified[PBLKSIZ];
2697c478bd9Sstevel@tonic-gate 	char host_name[PBLKSIZ];
2707c478bd9Sstevel@tonic-gate 	time_t now;
2717c478bd9Sstevel@tonic-gate 
2727c478bd9Sstevel@tonic-gate 	/*
2737c478bd9Sstevel@tonic-gate 	 * Add the special NIS entries.
2747c478bd9Sstevel@tonic-gate 	 */
2757c478bd9Sstevel@tonic-gate 	key.dptr = yp_last_modified;
2767c478bd9Sstevel@tonic-gate 	key.dsize = yp_last_modified_sz;
2777c478bd9Sstevel@tonic-gate 	time(&now);
2787c478bd9Sstevel@tonic-gate 	sprintf(last_modified, "%10.10d", now);
2797c478bd9Sstevel@tonic-gate 	value.dptr = last_modified;
2807c478bd9Sstevel@tonic-gate 	value.dsize = strlen(value.dptr);
2817c478bd9Sstevel@tonic-gate 	dbm_store(Outdbm, key, value, DBM_REPLACE);
2827c478bd9Sstevel@tonic-gate 
2837c478bd9Sstevel@tonic-gate 	key.dptr = yp_master_name;
2847c478bd9Sstevel@tonic-gate 	key.dsize = yp_master_name_sz;
2857c478bd9Sstevel@tonic-gate 	sysinfo(SI_HOSTNAME, host_name, sizeof (host_name));
2867c478bd9Sstevel@tonic-gate 	value.dptr = host_name;
2877c478bd9Sstevel@tonic-gate 	value.dsize = strlen(value.dptr);
2887c478bd9Sstevel@tonic-gate 	dbm_store(Outdbm, key, value, DBM_REPLACE);
2897c478bd9Sstevel@tonic-gate }
2907c478bd9Sstevel@tonic-gate 
2917c478bd9Sstevel@tonic-gate int
main(int argc,char * argv[])2927c478bd9Sstevel@tonic-gate main(int argc, char *argv[])
2937c478bd9Sstevel@tonic-gate {
2947c478bd9Sstevel@tonic-gate 	while (argc > 1 && argv[1][0] == '-') {
2957c478bd9Sstevel@tonic-gate 	switch (argv[1][1]) {
2967c478bd9Sstevel@tonic-gate 		case 'v':
2977c478bd9Sstevel@tonic-gate 			Verbose = 1;
2987c478bd9Sstevel@tonic-gate 			break;
2997c478bd9Sstevel@tonic-gate 
3007c478bd9Sstevel@tonic-gate 		case 'u':
3017c478bd9Sstevel@tonic-gate 			UucpOK = 1;
3027c478bd9Sstevel@tonic-gate 			break;
3037c478bd9Sstevel@tonic-gate 
3047c478bd9Sstevel@tonic-gate 		case 'd':
3057c478bd9Sstevel@tonic-gate 			DomainOK = 1;
3067c478bd9Sstevel@tonic-gate 			break;
3077c478bd9Sstevel@tonic-gate 
3087c478bd9Sstevel@tonic-gate 		case 'e':
3097c478bd9Sstevel@tonic-gate 			ErrorCheck = 1;
3107c478bd9Sstevel@tonic-gate 			break;
3117c478bd9Sstevel@tonic-gate 
3127c478bd9Sstevel@tonic-gate 		case 's':
3137c478bd9Sstevel@tonic-gate 			Simple = 1;
3147c478bd9Sstevel@tonic-gate 			break;
3157c478bd9Sstevel@tonic-gate 
3167c478bd9Sstevel@tonic-gate 		case 'n':
3177c478bd9Sstevel@tonic-gate 			NameMode = 1;
3187c478bd9Sstevel@tonic-gate 			break;
3197c478bd9Sstevel@tonic-gate 
3207c478bd9Sstevel@tonic-gate 		default:
3217c478bd9Sstevel@tonic-gate 			printf("Unknown option %c\n", argv[1][1]);
3227c478bd9Sstevel@tonic-gate 			break;
3237c478bd9Sstevel@tonic-gate 		}
3247c478bd9Sstevel@tonic-gate 		argc--; argv++;
3257c478bd9Sstevel@tonic-gate 	}
3267c478bd9Sstevel@tonic-gate 	if (argc < 2) {
3277c478bd9Sstevel@tonic-gate printf("Usage: mkalias [-e] [-v] [-u] [-d] [-s] [-n] <input> <output>\n");
3287c478bd9Sstevel@tonic-gate 		exit(1);
3297c478bd9Sstevel@tonic-gate 	}
3307c478bd9Sstevel@tonic-gate 	Indbm = dbm_open(argv[1], O_RDONLY, 0);
3317c478bd9Sstevel@tonic-gate 	if (Indbm == NULL) {
3327c478bd9Sstevel@tonic-gate 		printf("Unable to open input database %s\n", argv[1]);
3337c478bd9Sstevel@tonic-gate 		exit(1);
3347c478bd9Sstevel@tonic-gate 	}
3357c478bd9Sstevel@tonic-gate 	Scandbm = dbm_open(argv[1], O_RDONLY, 0);
3367c478bd9Sstevel@tonic-gate 	if (Scandbm == NULL) {
3377c478bd9Sstevel@tonic-gate 		printf("Unable to open input database %s\n", argv[1]);
3387c478bd9Sstevel@tonic-gate 		exit(1);
3397c478bd9Sstevel@tonic-gate 	}
3407c478bd9Sstevel@tonic-gate 	if (argv[2] == NULL)
3417c478bd9Sstevel@tonic-gate 		NoOutput = 1;
3427c478bd9Sstevel@tonic-gate 	else {
3437c478bd9Sstevel@tonic-gate 		Outdbm = dbm_open(argv[2], O_RDWR|O_CREAT|O_TRUNC, 0644);
3447c478bd9Sstevel@tonic-gate 		if (Outdbm == NULL) {
3457c478bd9Sstevel@tonic-gate 			printf("Unable to open output database %s\n", argv[2]);
3467c478bd9Sstevel@tonic-gate 			exit(1);
3477c478bd9Sstevel@tonic-gate 		}
3487c478bd9Sstevel@tonic-gate 	}
3497c478bd9Sstevel@tonic-gate 	ProcessMap();
3507c478bd9Sstevel@tonic-gate 	dbm_close(Indbm);
3517c478bd9Sstevel@tonic-gate 	dbm_close(Scandbm);
3527c478bd9Sstevel@tonic-gate 	if (!NoOutput) {
3537c478bd9Sstevel@tonic-gate 		AddYPEntries();
3547c478bd9Sstevel@tonic-gate 		dbm_close(Outdbm);
3557c478bd9Sstevel@tonic-gate 	}
3567c478bd9Sstevel@tonic-gate 	return (0);
3577c478bd9Sstevel@tonic-gate }
358