1 /* 2 * Copyright (c) 1983 Eric P. Allman 3 * Copyright (c) 1988 Regents of the University of California. 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms are permitted 7 * provided that the above copyright notice and this paragraph are 8 * duplicated in all such forms and that any documentation, 9 * advertising materials, and other materials related to such 10 * distribution and use acknowledge that the software was developed 11 * by the University of California, Berkeley. The name of the 12 * University may not be used to endorse or promote products derived 13 * from this software without specific prior written permission. 14 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 15 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 16 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 17 */ 18 19 #ifndef lint 20 char copyright[] = 21 "@(#) Copyright (c) 1988 Regents of the University of California.\n\ 22 All rights reserved.\n"; 23 #endif /* not lint */ 24 25 #ifndef lint 26 static char sccsid[] = "@(#)praliases.c 5.4 (Berkeley) 06/29/88"; 27 #endif /* not lint */ 28 29 #include <sendmail.h> 30 31 typedef struct { 32 char *dptr; 33 int dsize; 34 } datum; 35 36 37 main(argc, argv) 38 char **argv; 39 { 40 extern char *optarg; 41 extern int optind; 42 static char *filename = "/usr/lib/aliases"; 43 datum content, key, firstkey(), nextkey(), fetch(); 44 int ch; 45 46 while ((ch = getopt(argc, argv, "f:")) != EOF) 47 switch((char)ch) { 48 case 'f': 49 filename = optarg; 50 break; 51 case '?': 52 default: 53 fputs("usage: praliases [-f file]\n", stderr); 54 exit(EX_USAGE); 55 } 56 argc -= optind; 57 argv += optind; 58 59 if (dbminit(filename) < 0) 60 exit(EX_OSFILE); 61 if (!argc) 62 for (key = firstkey(); key.dptr; key = nextkey(key)) { 63 content = fetch(key); 64 printf("%s:%s\n", key.dptr, content.dptr); 65 } 66 else for (; *argv; ++argv) { 67 key.dptr = *argv; 68 key.dsize = strlen(*argv) + 1; 69 content = fetch(key); 70 if (!content.dptr) 71 printf("%s: No such key\n", key.dptr); 72 else 73 printf("%s:%s\n", key.dptr, content.dptr); 74 } 75 exit(EX_OK); 76 } 77