Deleted Added
full compact
ypmatch.c (27345) ypmatch.c (28894)
1/*
2 * Copyright (c) 1992/3 Theo de Raadt <deraadt@fsa.ca>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 13 unchanged lines hidden (view full) ---

22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29
1/*
2 * Copyright (c) 1992/3 Theo de Raadt <deraadt@fsa.ca>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 13 unchanged lines hidden (view full) ---

22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29
30#ifndef LINT
31static char rcsid[] = "ypmatch.c,v 1.2 1993/05/16 02:49:03 deraadt Exp";
32#endif
30#ifndef lint
31static const char rcsid[] =
32 "$Id$";
33#endif /* not lint */
33
34#include <sys/param.h>
35#include <sys/types.h>
36#include <sys/socket.h>
34
35#include <sys/param.h>
36#include <sys/types.h>
37#include <sys/socket.h>
37#include <stdio.h>
38#include <ctype.h>
38#include <ctype.h>
39#include <err.h>
40#include <stdio.h>
41#include <unistd.h>
39
40#include <rpc/rpc.h>
41#include <rpc/xdr.h>
42#include <rpcsvc/yp_prot.h>
43#include <rpcsvc/ypclnt.h>
44
45struct ypalias {
46 char *alias, *name;

--- 4 unchanged lines hidden (view full) ---

51 { "networks", "networks.byaddr" },
52 { "hosts", "hosts.byname" },
53 { "protocols", "protocols.bynumber" },
54 { "services", "services.byname" },
55 { "aliases", "mail.aliases" },
56 { "ethers", "ethers.byname" },
57};
58
42
43#include <rpc/rpc.h>
44#include <rpc/xdr.h>
45#include <rpcsvc/yp_prot.h>
46#include <rpcsvc/ypclnt.h>
47
48struct ypalias {
49 char *alias, *name;

--- 4 unchanged lines hidden (view full) ---

54 { "networks", "networks.byaddr" },
55 { "hosts", "hosts.byname" },
56 { "protocols", "protocols.bynumber" },
57 { "services", "services.byname" },
58 { "aliases", "mail.aliases" },
59 { "ethers", "ethers.byname" },
60};
61
62static void
59usage()
60{
63usage()
64{
61 fprintf(stderr, "Usage:\n");
62 fprintf(stderr, "\typmatch [-d domain] [-t] [-k] key [key ...] mname\n");
63 fprintf(stderr, "\typmatch -x\n");
64 fprintf(stderr, "where\n");
65 fprintf(stderr, "\tmname may be either a mapname or a nickname for a map\n");
66 fprintf(stderr, "\t-t inhibits map nickname translation\n");
67 fprintf(stderr, "\t-k prints keys as well as values.\n");
68 fprintf(stderr, "\t-x dumps the map nickname translation table.\n");
65 fprintf(stderr, "%s\n%s\n",
66 "usage: ypmatch [-d domain] [-t] [-k] key [key ...] mname",
67 " ypmatch -x");
69 exit(1);
70}
71
72int
73main(argc, argv)
74char **argv;
75{
68 exit(1);
69}
70
71int
72main(argc, argv)
73char **argv;
74{
76 char *domainname;
75 char *domainname = NULL;
77 char *inkey, *inmap, *outbuf;
76 char *inkey, *inmap, *outbuf;
78 extern char *optarg;
79 extern int optind;
80 int outbuflen, key, notrans;
81 int c, r, i;
82
83 notrans = key = 0;
77 int outbuflen, key, notrans;
78 int c, r, i;
79
80 notrans = key = 0;
84 yp_get_default_domain(&domainname);
85
86 while( (c=getopt(argc, argv, "xd:kt")) != -1)
87 switch(c) {
88 case 'x':
89 for(i=0; i<sizeof ypaliases/sizeof ypaliases[0]; i++)
90 printf("Use \"%s\" for \"%s\"\n",
91 ypaliases[i].alias,
92 ypaliases[i].name);

--- 9 unchanged lines hidden (view full) ---

102 break;
103 default:
104 usage();
105 }
106
107 if( (argc-optind) < 2 )
108 usage();
109
81
82 while( (c=getopt(argc, argv, "xd:kt")) != -1)
83 switch(c) {
84 case 'x':
85 for(i=0; i<sizeof ypaliases/sizeof ypaliases[0]; i++)
86 printf("Use \"%s\" for \"%s\"\n",
87 ypaliases[i].alias,
88 ypaliases[i].name);

--- 9 unchanged lines hidden (view full) ---

98 break;
99 default:
100 usage();
101 }
102
103 if( (argc-optind) < 2 )
104 usage();
105
106 if (!domainname)
107 yp_get_default_domain(&domainname);
108
110 inmap = argv[argc-1];
111 for(i=0; (!notrans) && i<sizeof ypaliases/sizeof ypaliases[0]; i++)
112 if( strcmp(inmap, ypaliases[i].alias) == 0)
113 inmap = ypaliases[i].name;
114 for(; optind < argc-1; optind++) {
115 inkey = argv[optind];
116
117 r = yp_match(domainname, inmap, inkey,
118 strlen(inkey), &outbuf, &outbuflen);
119 switch(r) {
120 case 0:
121 if(key)
122 printf("%s ", inkey);
123 printf("%*.*s\n", outbuflen, outbuflen, outbuf);
124 break;
125 case YPERR_YPBIND:
109 inmap = argv[argc-1];
110 for(i=0; (!notrans) && i<sizeof ypaliases/sizeof ypaliases[0]; i++)
111 if( strcmp(inmap, ypaliases[i].alias) == 0)
112 inmap = ypaliases[i].name;
113 for(; optind < argc-1; optind++) {
114 inkey = argv[optind];
115
116 r = yp_match(domainname, inmap, inkey,
117 strlen(inkey), &outbuf, &outbuflen);
118 switch(r) {
119 case 0:
120 if(key)
121 printf("%s ", inkey);
122 printf("%*.*s\n", outbuflen, outbuflen, outbuf);
123 break;
124 case YPERR_YPBIND:
126 fprintf(stderr, "yp_match: not running ypbind\n");
127 exit(1);
125 errx(1, "not running ypbind");
128 default:
126 default:
129 fprintf(stderr, "Can't match key %s in map %s. Reason: %s\n",
127 errx(1, "can't match key %s in map %s. reason: %s",
130 inkey, inmap, yperr_string(r));
128 inkey, inmap, yperr_string(r));
131 exit(1);
132 break;
133 }
134 }
135 exit(0);
136}
129 }
130 }
131 exit(0);
132}