Deleted Added
full compact
ypmatch.c (87672) ypmatch.c (90297)
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

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

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#include <sys/cdefs.h>
31
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

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

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#include <sys/cdefs.h>
31
32__FBSDID("$FreeBSD: head/usr.bin/ypmatch/ypmatch.c 87672 2001-12-11 22:08:58Z markm $");
32__FBSDID("$FreeBSD: head/usr.bin/ypmatch/ypmatch.c 90297 2002-02-06 13:30:31Z des $");
33
34#include <sys/param.h>
35#include <sys/types.h>
36#include <sys/socket.h>
37
38#include <rpc/rpc.h>
39#include <rpc/xdr.h>
40#include <rpcsvc/yp_prot.h>

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

76 char *domainname = NULL;
77 char *inkey, *inmap, *outbuf;
78 int outbuflen, key, notrans;
79 int c, r;
80 u_int i;
81
82 notrans = key = 0;
83
33
34#include <sys/param.h>
35#include <sys/types.h>
36#include <sys/socket.h>
37
38#include <rpc/rpc.h>
39#include <rpc/xdr.h>
40#include <rpcsvc/yp_prot.h>

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

76 char *domainname = NULL;
77 char *inkey, *inmap, *outbuf;
78 int outbuflen, key, notrans;
79 int c, r;
80 u_int i;
81
82 notrans = key = 0;
83
84 while( (c=getopt(argc, argv, "xd:kt")) != -1)
85 switch(c) {
84 while ((c = getopt(argc, argv, "xd:kt")) != -1)
85 switch (c) {
86 case 'x':
86 case 'x':
87 for(i=0; i<sizeof ypaliases/sizeof ypaliases[0]; i++)
87 for (i = 0; i<sizeof ypaliases/sizeof ypaliases[0]; i++)
88 printf("Use \"%s\" for \"%s\"\n",
89 ypaliases[i].alias,
90 ypaliases[i].name);
91 exit(0);
92 case 'd':
93 domainname = optarg;
94 break;
95 case 't':
96 notrans++;
97 break;
98 case 'k':
99 key++;
100 break;
101 default:
102 usage();
103 }
104
88 printf("Use \"%s\" for \"%s\"\n",
89 ypaliases[i].alias,
90 ypaliases[i].name);
91 exit(0);
92 case 'd':
93 domainname = optarg;
94 break;
95 case 't':
96 notrans++;
97 break;
98 case 'k':
99 key++;
100 break;
101 default:
102 usage();
103 }
104
105 if( (argc-optind) < 2 )
105 if ((argc-optind) < 2)
106 usage();
107
108 if (!domainname)
109 yp_get_default_domain(&domainname);
110
111 inmap = argv[argc-1];
106 usage();
107
108 if (!domainname)
109 yp_get_default_domain(&domainname);
110
111 inmap = argv[argc-1];
112 for(i=0; (!notrans) && i<sizeof ypaliases/sizeof ypaliases[0]; i++)
113 if( strcmp(inmap, ypaliases[i].alias) == 0)
112 for (i = 0; (!notrans) && i<sizeof ypaliases/sizeof ypaliases[0]; i++)
113 if (strcmp(inmap, ypaliases[i].alias) == 0)
114 inmap = ypaliases[i].name;
114 inmap = ypaliases[i].name;
115 for(; optind < argc-1; optind++) {
115 for (; optind < argc-1; optind++) {
116 inkey = argv[optind];
117
118 r = yp_match(domainname, inmap, inkey,
119 strlen(inkey), &outbuf, &outbuflen);
116 inkey = argv[optind];
117
118 r = yp_match(domainname, inmap, inkey,
119 strlen(inkey), &outbuf, &outbuflen);
120 switch(r) {
120 switch (r) {
121 case 0:
121 case 0:
122 if(key)
122 if (key)
123 printf("%s ", inkey);
124 printf("%*.*s\n", outbuflen, outbuflen, outbuf);
125 break;
126 case YPERR_YPBIND:
127 errx(1, "not running ypbind");
128 default:
129 errx(1, "can't match key %s in map %s. reason: %s",
130 inkey, inmap, yperr_string(r));
131 }
132 }
133 exit(0);
134}
123 printf("%s ", inkey);
124 printf("%*.*s\n", outbuflen, outbuflen, outbuf);
125 break;
126 case YPERR_YPBIND:
127 errx(1, "not running ypbind");
128 default:
129 errx(1, "can't match key %s in map %s. reason: %s",
130 inkey, inmap, yperr_string(r));
131 }
132 }
133 exit(0);
134}