134046Sbostic /* 234914Sbostic * Copyright (c) 1983 Eric P. Allman 334046Sbostic * Copyright (c) 1988 Regents of the University of California. 434046Sbostic * All rights reserved. 534046Sbostic * 642823Sbostic * %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*60161Sbostic static char sccsid[] = "@(#)praliases.c 6.2 (Berkeley) 05/20/93"; 1734046Sbostic #endif /* not lint */ 1830811Sbostic 19*60161Sbostic #include <ndbm.h> 2034046Sbostic #include <sendmail.h> 2134046Sbostic 22*60161Sbostic int 2330811Sbostic main(argc, argv) 24*60161Sbostic int argc; 2530811Sbostic char **argv; 2630811Sbostic { 2734046Sbostic extern char *optarg; 2834046Sbostic extern int optind; 29*60161Sbostic DBM *dbp; 30*60161Sbostic datum content, key; 31*60161Sbostic char *filename; 3234046Sbostic int ch; 3330811Sbostic 34*60161Sbostic filename = "/etc/aliases"; 3534046Sbostic while ((ch = getopt(argc, argv, "f:")) != EOF) 3634046Sbostic switch((char)ch) { 3734046Sbostic case 'f': 3834046Sbostic filename = optarg; 3934046Sbostic break; 4034046Sbostic case '?': 4134046Sbostic default: 42*60161Sbostic (void)fprintf(stderr, "usage: praliases [-f file]\n"); 4334046Sbostic exit(EX_USAGE); 4434046Sbostic } 4534046Sbostic argc -= optind; 4634046Sbostic argv += optind; 4730811Sbostic 48*60161Sbostic if ((dbp = dbm_open(filename, O_RDONLY, 0)) == NULL) { 49*60161Sbostic (void)fprintf(stderr, 50*60161Sbostic "praliases: %s: %s\n", filename, strerror(errno)); 5130811Sbostic exit(EX_OSFILE); 52*60161Sbostic } 5334046Sbostic if (!argc) 54*60161Sbostic for (key = dbm_nextkey(dbp); 55*60161Sbostic key.dptr != NULL; key = dbm_nextkey(dbp)) { 56*60161Sbostic content = dbm_fetch(dbp, key); 57*60161Sbostic (void)printf("%s:%s\n", key.dptr, content.dptr); 5830811Sbostic } 5934046Sbostic else for (; *argv; ++argv) { 6030811Sbostic key.dptr = *argv; 6134046Sbostic key.dsize = strlen(*argv) + 1; 62*60161Sbostic content = dbm_fetch(dbp, key); 6334046Sbostic if (!content.dptr) 64*60161Sbostic (void)printf("%s: No such key\n", key.dptr); 6530811Sbostic else 66*60161Sbostic (void)printf("%s:%s\n", key.dptr, content.dptr); 6730811Sbostic } 6830811Sbostic exit(EX_OK); 6930811Sbostic } 70