xref: /titanic_54/usr/src/cmd/ypcmd/mkalias.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright (c) 1996, by Sun Microsystems, Inc.
24*7c478bd9Sstevel@tonic-gate  * All rights reserved.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate /*
28*7c478bd9Sstevel@tonic-gate  * mkmap - program to convert the mail.aliases map into an
29*7c478bd9Sstevel@tonic-gate  * inverse map of <user@host> back to <preferred-alias>
30*7c478bd9Sstevel@tonic-gate  */
31*7c478bd9Sstevel@tonic-gate 
32*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
33*7c478bd9Sstevel@tonic-gate 
34*7c478bd9Sstevel@tonic-gate #include <stdlib.h>
35*7c478bd9Sstevel@tonic-gate #include <unistd.h>
36*7c478bd9Sstevel@tonic-gate #include <string.h>
37*7c478bd9Sstevel@tonic-gate #include <fcntl.h>
38*7c478bd9Sstevel@tonic-gate #include <ndbm.h>
39*7c478bd9Sstevel@tonic-gate #include <stdio.h>
40*7c478bd9Sstevel@tonic-gate #include <ctype.h>
41*7c478bd9Sstevel@tonic-gate #include <netdb.h>
42*7c478bd9Sstevel@tonic-gate #include <sys/systeminfo.h>
43*7c478bd9Sstevel@tonic-gate 
44*7c478bd9Sstevel@tonic-gate #include "ypdefs.h"
45*7c478bd9Sstevel@tonic-gate USE_YP_PREFIX
46*7c478bd9Sstevel@tonic-gate USE_YP_MASTER_NAME
47*7c478bd9Sstevel@tonic-gate USE_YP_LAST_MODIFIED
48*7c478bd9Sstevel@tonic-gate 
49*7c478bd9Sstevel@tonic-gate #define	MKAL_INCLUDE ":include:"
50*7c478bd9Sstevel@tonic-gate 
51*7c478bd9Sstevel@tonic-gate void CopyName(char *dst, char *src, int len);
52*7c478bd9Sstevel@tonic-gate int HostCheck(char *h, char *a);
53*7c478bd9Sstevel@tonic-gate void DoName(char *cp);
54*7c478bd9Sstevel@tonic-gate void UpperCase(char *cp);
55*7c478bd9Sstevel@tonic-gate void AddYPEntries(void);
56*7c478bd9Sstevel@tonic-gate 
57*7c478bd9Sstevel@tonic-gate int Verbose = 0;	/* to get the gory details */
58*7c478bd9Sstevel@tonic-gate int UucpOK = 0;		/* pass all UUCP names right through */
59*7c478bd9Sstevel@tonic-gate int DomainOK = 0;	/* pass all Domain names (with dots) */
60*7c478bd9Sstevel@tonic-gate int ErrorCheck = 0;	/* check carefully for errors */
61*7c478bd9Sstevel@tonic-gate int NoOutput = 0;	/* no output, just do the check */
62*7c478bd9Sstevel@tonic-gate int Simple = 0;		/* Do not do the user name preference step */
63*7c478bd9Sstevel@tonic-gate int NameMode = 0;	/* Try to capitalize as names */
64*7c478bd9Sstevel@tonic-gate 
65*7c478bd9Sstevel@tonic-gate DBM *Indbm=NULL, *Scandbm=NULL, *Outdbm=NULL;
66*7c478bd9Sstevel@tonic-gate 
67*7c478bd9Sstevel@tonic-gate int
68*7c478bd9Sstevel@tonic-gate IsMailingList(char *s)
69*7c478bd9Sstevel@tonic-gate {
70*7c478bd9Sstevel@tonic-gate 	/*
71*7c478bd9Sstevel@tonic-gate 	 * returns true if the given string is a mailing list
72*7c478bd9Sstevel@tonic-gate 	 */
73*7c478bd9Sstevel@tonic-gate 	char *p;
74*7c478bd9Sstevel@tonic-gate 
75*7c478bd9Sstevel@tonic-gate 	if (strchr(s, ','))
76*7c478bd9Sstevel@tonic-gate 		return (1);
77*7c478bd9Sstevel@tonic-gate 	if (strchr(s, '|'))
78*7c478bd9Sstevel@tonic-gate 		return (1);
79*7c478bd9Sstevel@tonic-gate 	p = strchr(s, ':');
80*7c478bd9Sstevel@tonic-gate 	if (p && strncmp(p, MKAL_INCLUDE, sizeof (MKAL_INCLUDE)))
81*7c478bd9Sstevel@tonic-gate 		return (1);
82*7c478bd9Sstevel@tonic-gate 	return (0);
83*7c478bd9Sstevel@tonic-gate }
84*7c478bd9Sstevel@tonic-gate 
85*7c478bd9Sstevel@tonic-gate int
86*7c478bd9Sstevel@tonic-gate IsQualified(char *s, char *p, char *h)
87*7c478bd9Sstevel@tonic-gate {
88*7c478bd9Sstevel@tonic-gate 	/*
89*7c478bd9Sstevel@tonic-gate 	 * returns true if the given string is qualified with a host name
90*7c478bd9Sstevel@tonic-gate 	 */
91*7c478bd9Sstevel@tonic-gate 	register char *middle;
92*7c478bd9Sstevel@tonic-gate 
93*7c478bd9Sstevel@tonic-gate 	middle = strchr(s, '@');
94*7c478bd9Sstevel@tonic-gate 	if (middle) {
95*7c478bd9Sstevel@tonic-gate 		for (middle = s; *middle != '@'; *p++ = *middle++)
96*7c478bd9Sstevel@tonic-gate 			continue;
97*7c478bd9Sstevel@tonic-gate 		*p = '\0';
98*7c478bd9Sstevel@tonic-gate 		CopyName(h, middle+1, strlen(middle + 1));
99*7c478bd9Sstevel@tonic-gate 		return (1);
100*7c478bd9Sstevel@tonic-gate 	}
101*7c478bd9Sstevel@tonic-gate 	middle = strrchr(s, '!');
102*7c478bd9Sstevel@tonic-gate 	if (middle) {
103*7c478bd9Sstevel@tonic-gate 		strcpy(p, middle+1);
104*7c478bd9Sstevel@tonic-gate 		*middle = '\0';
105*7c478bd9Sstevel@tonic-gate 		CopyName(h, s, strlen(s));
106*7c478bd9Sstevel@tonic-gate 		*middle = '!';
107*7c478bd9Sstevel@tonic-gate 		return (1);
108*7c478bd9Sstevel@tonic-gate 	}
109*7c478bd9Sstevel@tonic-gate 	return (0);
110*7c478bd9Sstevel@tonic-gate }
111*7c478bd9Sstevel@tonic-gate 
112*7c478bd9Sstevel@tonic-gate int
113*7c478bd9Sstevel@tonic-gate IsMaint(char *s)
114*7c478bd9Sstevel@tonic-gate {
115*7c478bd9Sstevel@tonic-gate 	/*
116*7c478bd9Sstevel@tonic-gate 	 * returns true if the given string is one of the maintenence
117*7c478bd9Sstevel@tonic-gate 	 * strings used in sendmail or NIS.
118*7c478bd9Sstevel@tonic-gate 	 */
119*7c478bd9Sstevel@tonic-gate 	if (*s == '@')
120*7c478bd9Sstevel@tonic-gate 		return (1);
121*7c478bd9Sstevel@tonic-gate 	if (strncmp(s, yp_prefix, yp_prefix_sz) == 0)
122*7c478bd9Sstevel@tonic-gate 		return (1);
123*7c478bd9Sstevel@tonic-gate 	return (0);
124*7c478bd9Sstevel@tonic-gate }
125*7c478bd9Sstevel@tonic-gate 
126*7c478bd9Sstevel@tonic-gate void
127*7c478bd9Sstevel@tonic-gate CopyName(char *dst, char *src, int len)
128*7c478bd9Sstevel@tonic-gate {
129*7c478bd9Sstevel@tonic-gate 	/*
130*7c478bd9Sstevel@tonic-gate 	* copy a string, but ignore white space
131*7c478bd9Sstevel@tonic-gate 	*/
132*7c478bd9Sstevel@tonic-gate 	while (*src && len--) {
133*7c478bd9Sstevel@tonic-gate 		if (isspace(*src))
134*7c478bd9Sstevel@tonic-gate 			src++;
135*7c478bd9Sstevel@tonic-gate 		else
136*7c478bd9Sstevel@tonic-gate 			*dst++ = *src++;
137*7c478bd9Sstevel@tonic-gate 	}
138*7c478bd9Sstevel@tonic-gate 	*dst = '\0';
139*7c478bd9Sstevel@tonic-gate }
140*7c478bd9Sstevel@tonic-gate 
141*7c478bd9Sstevel@tonic-gate int
142*7c478bd9Sstevel@tonic-gate Compare(char *s1, char *s2)
143*7c478bd9Sstevel@tonic-gate {
144*7c478bd9Sstevel@tonic-gate 	/*
145*7c478bd9Sstevel@tonic-gate 	 * compare strings, but ignore white space
146*7c478bd9Sstevel@tonic-gate 	 */
147*7c478bd9Sstevel@tonic-gate 	while (*s1 != '\0' && isspace(*s1))
148*7c478bd9Sstevel@tonic-gate 		s1++;
149*7c478bd9Sstevel@tonic-gate 	while (*s2 != '\0' && isspace(*s2))
150*7c478bd9Sstevel@tonic-gate 		s2++;
151*7c478bd9Sstevel@tonic-gate 	return (strcmp(s1, s2));
152*7c478bd9Sstevel@tonic-gate }
153*7c478bd9Sstevel@tonic-gate 
154*7c478bd9Sstevel@tonic-gate void
155*7c478bd9Sstevel@tonic-gate ProcessMap(void)
156*7c478bd9Sstevel@tonic-gate {
157*7c478bd9Sstevel@tonic-gate 	datum key, value, part, partvalue;
158*7c478bd9Sstevel@tonic-gate 	char address[PBLKSIZ];	/* qualified version */
159*7c478bd9Sstevel@tonic-gate 	char user[PBLKSIZ];		/* unqualified version */
160*7c478bd9Sstevel@tonic-gate 	char userpart[PBLKSIZ];	/* unqualified part of qualified addr. */
161*7c478bd9Sstevel@tonic-gate 	char hostpart[PBLKSIZ];	/* rest of qualified addr. */
162*7c478bd9Sstevel@tonic-gate 
163*7c478bd9Sstevel@tonic-gate 	for (key = dbm_firstkey(Scandbm); key.dptr != NULL;
164*7c478bd9Sstevel@tonic-gate 						key = dbm_nextkey(Scandbm)) {
165*7c478bd9Sstevel@tonic-gate 		value = dbm_fetch(Indbm, key);
166*7c478bd9Sstevel@tonic-gate 		CopyName(address, value.dptr, value.dsize);
167*7c478bd9Sstevel@tonic-gate 		CopyName(user, key.dptr, key.dsize);
168*7c478bd9Sstevel@tonic-gate 		if (address == NULL) continue;
169*7c478bd9Sstevel@tonic-gate 		if (IsMailingList(address)) continue;
170*7c478bd9Sstevel@tonic-gate 		if (!IsQualified(address, userpart, hostpart)) continue;
171*7c478bd9Sstevel@tonic-gate 		if (IsMaint(user)) continue;
172*7c478bd9Sstevel@tonic-gate 		if (ErrorCheck && HostCheck(hostpart, address)) {
173*7c478bd9Sstevel@tonic-gate 			printf("Invalid host %s in %s:%s\n",
174*7c478bd9Sstevel@tonic-gate 				hostpart, user, address);
175*7c478bd9Sstevel@tonic-gate 			continue;
176*7c478bd9Sstevel@tonic-gate 		}
177*7c478bd9Sstevel@tonic-gate 		part.dptr = userpart;
178*7c478bd9Sstevel@tonic-gate 		part.dsize = strlen(userpart) + 1;
179*7c478bd9Sstevel@tonic-gate 		if (Simple)
180*7c478bd9Sstevel@tonic-gate 			partvalue.dptr = NULL;
181*7c478bd9Sstevel@tonic-gate 		else
182*7c478bd9Sstevel@tonic-gate 			partvalue = dbm_fetch(Indbm, part);
183*7c478bd9Sstevel@tonic-gate 		value.dptr = address;
184*7c478bd9Sstevel@tonic-gate 		value.dsize = strlen(address) + 1;
185*7c478bd9Sstevel@tonic-gate 		if (partvalue.dptr != NULL &&
186*7c478bd9Sstevel@tonic-gate 			Compare(partvalue.dptr, user) == 0) {
187*7c478bd9Sstevel@tonic-gate 
188*7c478bd9Sstevel@tonic-gate 			if (NameMode)
189*7c478bd9Sstevel@tonic-gate 				DoName(userpart);
190*7c478bd9Sstevel@tonic-gate 			if (!NoOutput)
191*7c478bd9Sstevel@tonic-gate 				dbm_store(Outdbm, value, part, DBM_REPLACE);
192*7c478bd9Sstevel@tonic-gate 			if (Verbose) printf("%s --> %s --> %s\n",
193*7c478bd9Sstevel@tonic-gate 						userpart, user, address);
194*7c478bd9Sstevel@tonic-gate 		} else {
195*7c478bd9Sstevel@tonic-gate 			if (NameMode)
196*7c478bd9Sstevel@tonic-gate 				DoName(user);
197*7c478bd9Sstevel@tonic-gate 			key.dptr = user;
198*7c478bd9Sstevel@tonic-gate 			key.dsize = strlen(user) + 1;
199*7c478bd9Sstevel@tonic-gate 			if (!NoOutput)
200*7c478bd9Sstevel@tonic-gate 				dbm_store(Outdbm, value, key, DBM_REPLACE);
201*7c478bd9Sstevel@tonic-gate 			if (Verbose)
202*7c478bd9Sstevel@tonic-gate 				printf("%s --> %s\n", user, address);
203*7c478bd9Sstevel@tonic-gate 		}
204*7c478bd9Sstevel@tonic-gate 	}
205*7c478bd9Sstevel@tonic-gate }
206*7c478bd9Sstevel@tonic-gate 
207*7c478bd9Sstevel@tonic-gate 
208*7c478bd9Sstevel@tonic-gate /*
209*7c478bd9Sstevel@tonic-gate  * Returns true if this is an invalid host
210*7c478bd9Sstevel@tonic-gate  */
211*7c478bd9Sstevel@tonic-gate int
212*7c478bd9Sstevel@tonic-gate HostCheck(char *h, char *a)
213*7c478bd9Sstevel@tonic-gate {
214*7c478bd9Sstevel@tonic-gate 	struct hostent *hp;
215*7c478bd9Sstevel@tonic-gate 
216*7c478bd9Sstevel@tonic-gate 	if (DomainOK && strchr(a, '.'))
217*7c478bd9Sstevel@tonic-gate 		return (0);
218*7c478bd9Sstevel@tonic-gate 
219*7c478bd9Sstevel@tonic-gate 	if (UucpOK && strchr(a, '!'))
220*7c478bd9Sstevel@tonic-gate 		return (0);
221*7c478bd9Sstevel@tonic-gate 
222*7c478bd9Sstevel@tonic-gate 	hp = gethostbyname(h);
223*7c478bd9Sstevel@tonic-gate 	return (hp == NULL);
224*7c478bd9Sstevel@tonic-gate }
225*7c478bd9Sstevel@tonic-gate 
226*7c478bd9Sstevel@tonic-gate /*
227*7c478bd9Sstevel@tonic-gate  * Apply some Heurisitcs to upper case-ify the name
228*7c478bd9Sstevel@tonic-gate  * If it has a dot in it.
229*7c478bd9Sstevel@tonic-gate  */
230*7c478bd9Sstevel@tonic-gate void
231*7c478bd9Sstevel@tonic-gate DoName(char *cp)
232*7c478bd9Sstevel@tonic-gate {
233*7c478bd9Sstevel@tonic-gate 	if (strchr(cp, '.') == NULL)
234*7c478bd9Sstevel@tonic-gate 		return;
235*7c478bd9Sstevel@tonic-gate 
236*7c478bd9Sstevel@tonic-gate 	while (*cp) {
237*7c478bd9Sstevel@tonic-gate 		UpperCase(cp);
238*7c478bd9Sstevel@tonic-gate 		while (*cp && *cp != '-' && *cp != '.')
239*7c478bd9Sstevel@tonic-gate 			cp++;
240*7c478bd9Sstevel@tonic-gate 		if (*cp)
241*7c478bd9Sstevel@tonic-gate 			cp++;	/* skip past punctuation */
242*7c478bd9Sstevel@tonic-gate 	}
243*7c478bd9Sstevel@tonic-gate }
244*7c478bd9Sstevel@tonic-gate 
245*7c478bd9Sstevel@tonic-gate /*
246*7c478bd9Sstevel@tonic-gate  * upper cases one name - stops at a .
247*7c478bd9Sstevel@tonic-gate  */
248*7c478bd9Sstevel@tonic-gate void
249*7c478bd9Sstevel@tonic-gate UpperCase(char *cp)
250*7c478bd9Sstevel@tonic-gate {
251*7c478bd9Sstevel@tonic-gate 	register ch = cp[0];
252*7c478bd9Sstevel@tonic-gate 
253*7c478bd9Sstevel@tonic-gate 	if (isupper(ch))
254*7c478bd9Sstevel@tonic-gate 		ch = tolower(ch);
255*7c478bd9Sstevel@tonic-gate 
256*7c478bd9Sstevel@tonic-gate 	if (ch == 'f' && cp[1] == 'f')
257*7c478bd9Sstevel@tonic-gate 		return; /* handle ff */
258*7c478bd9Sstevel@tonic-gate 
259*7c478bd9Sstevel@tonic-gate 	if (ch == 'm' && cp[1] == 'c' && islower(cp[2]))
260*7c478bd9Sstevel@tonic-gate 		cp[2] = toupper(cp[2]);
261*7c478bd9Sstevel@tonic-gate 	if (islower(ch))
262*7c478bd9Sstevel@tonic-gate 		cp[0] = toupper(ch);
263*7c478bd9Sstevel@tonic-gate }
264*7c478bd9Sstevel@tonic-gate 
265*7c478bd9Sstevel@tonic-gate void
266*7c478bd9Sstevel@tonic-gate AddYPEntries(void)
267*7c478bd9Sstevel@tonic-gate {
268*7c478bd9Sstevel@tonic-gate 	datum key, value;
269*7c478bd9Sstevel@tonic-gate 	char last_modified[PBLKSIZ];
270*7c478bd9Sstevel@tonic-gate 	char host_name[PBLKSIZ];
271*7c478bd9Sstevel@tonic-gate 	time_t now;
272*7c478bd9Sstevel@tonic-gate 
273*7c478bd9Sstevel@tonic-gate 	/*
274*7c478bd9Sstevel@tonic-gate 	 * Add the special NIS entries.
275*7c478bd9Sstevel@tonic-gate 	 */
276*7c478bd9Sstevel@tonic-gate 	key.dptr = yp_last_modified;
277*7c478bd9Sstevel@tonic-gate 	key.dsize = yp_last_modified_sz;
278*7c478bd9Sstevel@tonic-gate 	time(&now);
279*7c478bd9Sstevel@tonic-gate 	sprintf(last_modified, "%10.10d", now);
280*7c478bd9Sstevel@tonic-gate 	value.dptr = last_modified;
281*7c478bd9Sstevel@tonic-gate 	value.dsize = strlen(value.dptr);
282*7c478bd9Sstevel@tonic-gate 	dbm_store(Outdbm, key, value, DBM_REPLACE);
283*7c478bd9Sstevel@tonic-gate 
284*7c478bd9Sstevel@tonic-gate 	key.dptr = yp_master_name;
285*7c478bd9Sstevel@tonic-gate 	key.dsize = yp_master_name_sz;
286*7c478bd9Sstevel@tonic-gate 	sysinfo(SI_HOSTNAME, host_name, sizeof (host_name));
287*7c478bd9Sstevel@tonic-gate 	value.dptr = host_name;
288*7c478bd9Sstevel@tonic-gate 	value.dsize = strlen(value.dptr);
289*7c478bd9Sstevel@tonic-gate 	dbm_store(Outdbm, key, value, DBM_REPLACE);
290*7c478bd9Sstevel@tonic-gate }
291*7c478bd9Sstevel@tonic-gate 
292*7c478bd9Sstevel@tonic-gate int
293*7c478bd9Sstevel@tonic-gate main(int argc, char *argv[])
294*7c478bd9Sstevel@tonic-gate {
295*7c478bd9Sstevel@tonic-gate 	while (argc > 1 && argv[1][0] == '-') {
296*7c478bd9Sstevel@tonic-gate 	switch (argv[1][1]) {
297*7c478bd9Sstevel@tonic-gate 		case 'v':
298*7c478bd9Sstevel@tonic-gate 			Verbose = 1;
299*7c478bd9Sstevel@tonic-gate 			break;
300*7c478bd9Sstevel@tonic-gate 
301*7c478bd9Sstevel@tonic-gate 		case 'u':
302*7c478bd9Sstevel@tonic-gate 			UucpOK = 1;
303*7c478bd9Sstevel@tonic-gate 			break;
304*7c478bd9Sstevel@tonic-gate 
305*7c478bd9Sstevel@tonic-gate 		case 'd':
306*7c478bd9Sstevel@tonic-gate 			DomainOK = 1;
307*7c478bd9Sstevel@tonic-gate 			break;
308*7c478bd9Sstevel@tonic-gate 
309*7c478bd9Sstevel@tonic-gate 		case 'e':
310*7c478bd9Sstevel@tonic-gate 			ErrorCheck = 1;
311*7c478bd9Sstevel@tonic-gate 			break;
312*7c478bd9Sstevel@tonic-gate 
313*7c478bd9Sstevel@tonic-gate 		case 's':
314*7c478bd9Sstevel@tonic-gate 			Simple = 1;
315*7c478bd9Sstevel@tonic-gate 			break;
316*7c478bd9Sstevel@tonic-gate 
317*7c478bd9Sstevel@tonic-gate 		case 'n':
318*7c478bd9Sstevel@tonic-gate 			NameMode = 1;
319*7c478bd9Sstevel@tonic-gate 			break;
320*7c478bd9Sstevel@tonic-gate 
321*7c478bd9Sstevel@tonic-gate 		default:
322*7c478bd9Sstevel@tonic-gate 			printf("Unknown option %c\n", argv[1][1]);
323*7c478bd9Sstevel@tonic-gate 			break;
324*7c478bd9Sstevel@tonic-gate 		}
325*7c478bd9Sstevel@tonic-gate 		argc--; argv++;
326*7c478bd9Sstevel@tonic-gate 	}
327*7c478bd9Sstevel@tonic-gate 	if (argc < 2) {
328*7c478bd9Sstevel@tonic-gate printf("Usage: mkalias [-e] [-v] [-u] [-d] [-s] [-n] <input> <output>\n");
329*7c478bd9Sstevel@tonic-gate 		exit(1);
330*7c478bd9Sstevel@tonic-gate 	}
331*7c478bd9Sstevel@tonic-gate 	Indbm = dbm_open(argv[1], O_RDONLY, 0);
332*7c478bd9Sstevel@tonic-gate 	if (Indbm == NULL) {
333*7c478bd9Sstevel@tonic-gate 		printf("Unable to open input database %s\n", argv[1]);
334*7c478bd9Sstevel@tonic-gate 		exit(1);
335*7c478bd9Sstevel@tonic-gate 	}
336*7c478bd9Sstevel@tonic-gate 	Scandbm = dbm_open(argv[1], O_RDONLY, 0);
337*7c478bd9Sstevel@tonic-gate 	if (Scandbm == NULL) {
338*7c478bd9Sstevel@tonic-gate 		printf("Unable to open input database %s\n", argv[1]);
339*7c478bd9Sstevel@tonic-gate 		exit(1);
340*7c478bd9Sstevel@tonic-gate 	}
341*7c478bd9Sstevel@tonic-gate 	if (argv[2] == NULL)
342*7c478bd9Sstevel@tonic-gate 		NoOutput = 1;
343*7c478bd9Sstevel@tonic-gate 	else {
344*7c478bd9Sstevel@tonic-gate 		Outdbm = dbm_open(argv[2], O_RDWR|O_CREAT|O_TRUNC, 0644);
345*7c478bd9Sstevel@tonic-gate 		if (Outdbm == NULL) {
346*7c478bd9Sstevel@tonic-gate 			printf("Unable to open output database %s\n", argv[2]);
347*7c478bd9Sstevel@tonic-gate 			exit(1);
348*7c478bd9Sstevel@tonic-gate 		}
349*7c478bd9Sstevel@tonic-gate 	}
350*7c478bd9Sstevel@tonic-gate 	ProcessMap();
351*7c478bd9Sstevel@tonic-gate 	dbm_close(Indbm);
352*7c478bd9Sstevel@tonic-gate 	dbm_close(Scandbm);
353*7c478bd9Sstevel@tonic-gate 	if (!NoOutput) {
354*7c478bd9Sstevel@tonic-gate 		AddYPEntries();
355*7c478bd9Sstevel@tonic-gate 		dbm_close(Outdbm);
356*7c478bd9Sstevel@tonic-gate 	}
357*7c478bd9Sstevel@tonic-gate 	return (0);
358*7c478bd9Sstevel@tonic-gate }
359