1*34046Sbostic /* 2*34046Sbostic * Copyright (c) 1988 Regents of the University of California. 3*34046Sbostic * All rights reserved. 4*34046Sbostic * 5*34046Sbostic * Redistribution and use in source and binary forms are permitted 6*34046Sbostic * provided that this notice is preserved and that due credit is given 7*34046Sbostic * to the University of California at Berkeley. The name of the University 8*34046Sbostic * may not be used to endorse or promote products derived from this 9*34046Sbostic * software without specific prior written permission. This software 10*34046Sbostic * is provided ``as is'' without express or implied warranty. 11*34046Sbostic */ 1230811Sbostic 13*34046Sbostic #ifndef lint 14*34046Sbostic char copyright[] = 15*34046Sbostic "@(#) Copyright (c) 1988 Regents of the University of California.\n\ 16*34046Sbostic All rights reserved.\n"; 17*34046Sbostic #endif /* not lint */ 1830811Sbostic 19*34046Sbostic #ifndef lint 20*34046Sbostic static char sccsid[] = "@(#)praliases.c 5.3 (Berkeley) 04/21/88"; 21*34046Sbostic #endif /* not lint */ 2230811Sbostic 23*34046Sbostic #include <sendmail.h> 24*34046Sbostic 25*34046Sbostic typedef struct { 26*34046Sbostic char *dptr; 27*34046Sbostic int dsize; 28*34046Sbostic } datum; 29*34046Sbostic 30*34046Sbostic 3130811Sbostic main(argc, argv) 3230811Sbostic char **argv; 3330811Sbostic { 34*34046Sbostic extern char *optarg; 35*34046Sbostic extern int optind; 36*34046Sbostic static char *filename = "/usr/lib/aliases"; 37*34046Sbostic datum content, key, firstkey(), nextkey(), fetch(); 38*34046Sbostic int ch; 3930811Sbostic 40*34046Sbostic while ((ch = getopt(argc, argv, "f:")) != EOF) 41*34046Sbostic switch((char)ch) { 42*34046Sbostic case 'f': 43*34046Sbostic filename = optarg; 44*34046Sbostic break; 45*34046Sbostic case '?': 46*34046Sbostic default: 47*34046Sbostic fputs("usage: praliases [-f file]\n", stderr); 48*34046Sbostic exit(EX_USAGE); 49*34046Sbostic } 50*34046Sbostic argc -= optind; 51*34046Sbostic argv += optind; 5230811Sbostic 5330811Sbostic if (dbminit(filename) < 0) 5430811Sbostic exit(EX_OSFILE); 55*34046Sbostic if (!argc) 5630811Sbostic for (key = firstkey(); key.dptr; key = nextkey(key)) { 5730811Sbostic content = fetch(key); 58*34046Sbostic printf("%s:%s\n", key.dptr, content.dptr); 5930811Sbostic } 60*34046Sbostic else for (; *argv; ++argv) { 6130811Sbostic key.dptr = *argv; 62*34046Sbostic key.dsize = strlen(*argv) + 1; 6330811Sbostic content = fetch(key); 64*34046Sbostic if (!content.dptr) 6530812Sbostic printf("%s: No such key\n", key.dptr); 6630811Sbostic else 67*34046Sbostic printf("%s:%s\n", key.dptr, content.dptr); 6830811Sbostic } 6930811Sbostic exit(EX_OK); 7030811Sbostic } 71