134046Sbostic /*
234914Sbostic  * Copyright (c) 1983 Eric P. Allman
334046Sbostic  * Copyright (c) 1988 Regents of the University of California.
434046Sbostic  * All rights reserved.
534046Sbostic  *
6*42823Sbostic  * %sccs.include.redist.c%
734046Sbostic  */
830811Sbostic 
934046Sbostic #ifndef lint
1034046Sbostic char copyright[] =
1134046Sbostic "@(#) Copyright (c) 1988 Regents of the University of California.\n\
1234046Sbostic  All rights reserved.\n";
1334046Sbostic #endif /* not lint */
1430811Sbostic 
1534046Sbostic #ifndef lint
16*42823Sbostic static char sccsid[] = "@(#)praliases.c	5.5 (Berkeley) 06/01/90";
1734046Sbostic #endif /* not lint */
1830811Sbostic 
1934046Sbostic #include <sendmail.h>
2034046Sbostic 
2134046Sbostic typedef struct {
2234046Sbostic 	char *dptr;
2334046Sbostic 	int dsize;
2434046Sbostic } datum;
2534046Sbostic 
2634046Sbostic 
2730811Sbostic main(argc, argv)
2830811Sbostic 	char **argv;
2930811Sbostic {
3034046Sbostic 	extern char *optarg;
3134046Sbostic 	extern int optind;
3234046Sbostic 	static char *filename = "/usr/lib/aliases";
3334046Sbostic 	datum content, key, firstkey(), nextkey(), fetch();
3434046Sbostic 	int ch;
3530811Sbostic 
3634046Sbostic 	while ((ch = getopt(argc, argv, "f:")) != EOF)
3734046Sbostic 		switch((char)ch) {
3834046Sbostic 		case 'f':
3934046Sbostic 			filename = optarg;
4034046Sbostic 			break;
4134046Sbostic 		case '?':
4234046Sbostic 		default:
4334046Sbostic 			fputs("usage: praliases [-f file]\n", stderr);
4434046Sbostic 			exit(EX_USAGE);
4534046Sbostic 		}
4634046Sbostic 	argc -= optind;
4734046Sbostic 	argv += optind;
4830811Sbostic 
4930811Sbostic 	if (dbminit(filename) < 0)
5030811Sbostic 		exit(EX_OSFILE);
5134046Sbostic 	if (!argc)
5230811Sbostic 		for (key = firstkey(); key.dptr; key = nextkey(key)) {
5330811Sbostic 			content = fetch(key);
5434046Sbostic 			printf("%s:%s\n", key.dptr, content.dptr);
5530811Sbostic 		}
5634046Sbostic 	else for (; *argv; ++argv) {
5730811Sbostic 		key.dptr = *argv;
5834046Sbostic 		key.dsize = strlen(*argv) + 1;
5930811Sbostic 		content = fetch(key);
6034046Sbostic 		if (!content.dptr)
6130812Sbostic 			printf("%s: No such key\n", key.dptr);
6230811Sbostic 		else
6334046Sbostic 			printf("%s:%s\n", key.dptr, content.dptr);
6430811Sbostic 	}
6530811Sbostic 	exit(EX_OK);
6630811Sbostic }
67