134046Sbostic /* 2*34914Sbostic * Copyright (c) 1983 Eric P. Allman 334046Sbostic * Copyright (c) 1988 Regents of the University of California. 434046Sbostic * All rights reserved. 534046Sbostic * 634046Sbostic * Redistribution and use in source and binary forms are permitted 7*34914Sbostic * provided that the above copyright notice and this paragraph are 8*34914Sbostic * duplicated in all such forms and that any documentation, 9*34914Sbostic * advertising materials, and other materials related to such 10*34914Sbostic * distribution and use acknowledge that the software was developed 11*34914Sbostic * by the University of California, Berkeley. The name of the 12*34914Sbostic * University may not be used to endorse or promote products derived 13*34914Sbostic * from this software without specific prior written permission. 14*34914Sbostic * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 15*34914Sbostic * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 16*34914Sbostic * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 1734046Sbostic */ 1830811Sbostic 1934046Sbostic #ifndef lint 2034046Sbostic char copyright[] = 2134046Sbostic "@(#) Copyright (c) 1988 Regents of the University of California.\n\ 2234046Sbostic All rights reserved.\n"; 2334046Sbostic #endif /* not lint */ 2430811Sbostic 2534046Sbostic #ifndef lint 26*34914Sbostic static char sccsid[] = "@(#)praliases.c 5.4 (Berkeley) 06/29/88"; 2734046Sbostic #endif /* not lint */ 2830811Sbostic 2934046Sbostic #include <sendmail.h> 3034046Sbostic 3134046Sbostic typedef struct { 3234046Sbostic char *dptr; 3334046Sbostic int dsize; 3434046Sbostic } datum; 3534046Sbostic 3634046Sbostic 3730811Sbostic main(argc, argv) 3830811Sbostic char **argv; 3930811Sbostic { 4034046Sbostic extern char *optarg; 4134046Sbostic extern int optind; 4234046Sbostic static char *filename = "/usr/lib/aliases"; 4334046Sbostic datum content, key, firstkey(), nextkey(), fetch(); 4434046Sbostic int ch; 4530811Sbostic 4634046Sbostic while ((ch = getopt(argc, argv, "f:")) != EOF) 4734046Sbostic switch((char)ch) { 4834046Sbostic case 'f': 4934046Sbostic filename = optarg; 5034046Sbostic break; 5134046Sbostic case '?': 5234046Sbostic default: 5334046Sbostic fputs("usage: praliases [-f file]\n", stderr); 5434046Sbostic exit(EX_USAGE); 5534046Sbostic } 5634046Sbostic argc -= optind; 5734046Sbostic argv += optind; 5830811Sbostic 5930811Sbostic if (dbminit(filename) < 0) 6030811Sbostic exit(EX_OSFILE); 6134046Sbostic if (!argc) 6230811Sbostic for (key = firstkey(); key.dptr; key = nextkey(key)) { 6330811Sbostic content = fetch(key); 6434046Sbostic printf("%s:%s\n", key.dptr, content.dptr); 6530811Sbostic } 6634046Sbostic else for (; *argv; ++argv) { 6730811Sbostic key.dptr = *argv; 6834046Sbostic key.dsize = strlen(*argv) + 1; 6930811Sbostic content = fetch(key); 7034046Sbostic if (!content.dptr) 7130812Sbostic printf("%s: No such key\n", key.dptr); 7230811Sbostic else 7334046Sbostic printf("%s:%s\n", key.dptr, content.dptr); 7430811Sbostic } 7530811Sbostic exit(EX_OK); 7630811Sbostic } 77