Deleted Added
full compact
ypset.c (74347) ypset.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#ifndef lint
31static const char rcsid[] =
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#ifndef lint
31static const char rcsid[] =
32 "$FreeBSD: head/usr.sbin/ypset/ypset.c 74347 2001-03-16 13:10:26Z alfred $";
32 "$FreeBSD: head/usr.sbin/ypset/ypset.c 90297 2002-02-06 13:30:31Z des $";
33#endif /* not lint */
34
35#include <err.h>
36#include <netdb.h>
37#include <stdio.h>
38#include <string.h>
39#include <unistd.h>
40#include <sys/param.h>

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

64 struct ypbind_setdom ypsd;
65 struct timeval tv;
66 struct hostent *hp;
67 CLIENT *client;
68 int sock, port;
69 int r;
70 unsigned long server_addr;
71
33#endif /* not lint */
34
35#include <err.h>
36#include <netdb.h>
37#include <stdio.h>
38#include <string.h>
39#include <unistd.h>
40#include <sys/param.h>

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

64 struct ypbind_setdom ypsd;
65 struct timeval tv;
66 struct hostent *hp;
67 CLIENT *client;
68 int sock, port;
69 int r;
70 unsigned long server_addr;
71
72 if( (port=htons(getrpcport(server, YPPROG, YPPROC_NULL, IPPROTO_UDP))) == 0)
72 if ((port = htons(getrpcport(server, YPPROG, YPPROC_NULL, IPPROTO_UDP))) == 0)
73 errx(1, "%s not running ypserv", server);
74
75 bzero(&ypsd, sizeof ypsd);
76
73 errx(1, "%s not running ypserv", server);
74
75 bzero(&ypsd, sizeof ypsd);
76
77 if( (hp = gethostbyname (server)) != NULL ) {
77 if ((hp = gethostbyname (server)) != NULL) {
78 /* is this the most compatible way?? */
79 bcopy (hp->h_addr_list[0],
80 (u_long *)&ypsd.ypsetdom_binding.ypbind_binding_addr,
81 sizeof (unsigned long));
78 /* is this the most compatible way?? */
79 bcopy (hp->h_addr_list[0],
80 (u_long *)&ypsd.ypsetdom_binding.ypbind_binding_addr,
81 sizeof (unsigned long));
82 } else if( (long)(server_addr = inet_addr (server)) == -1) {
82 } else if ((long)(server_addr = inet_addr (server)) == -1) {
83 errx(1, "can't find address for %s", server);
84 } else
85 bcopy (&server_addr,
86 (u_long *)&ypsd.ypsetdom_binding.ypbind_binding_addr,
87 sizeof (server_addr));
88
89/* strncpy(ypsd.ypsetdom_domain, dom, sizeof ypsd.ypsetdom_domain); */
90 ypsd.ypsetdom_domain = dom;
91 *(u_long *)&ypsd.ypsetdom_binding.ypbind_binding_port = port;
92 ypsd.ypsetdom_vers = YPVERS;
93
94 tv.tv_sec = 15;
95 tv.tv_usec = 0;
96 sock = RPC_ANYSOCK;
97 client = clntudp_create(sin, YPBINDPROG, YPBINDVERS, tv, &sock);
83 errx(1, "can't find address for %s", server);
84 } else
85 bcopy (&server_addr,
86 (u_long *)&ypsd.ypsetdom_binding.ypbind_binding_addr,
87 sizeof (server_addr));
88
89/* strncpy(ypsd.ypsetdom_domain, dom, sizeof ypsd.ypsetdom_domain); */
90 ypsd.ypsetdom_domain = dom;
91 *(u_long *)&ypsd.ypsetdom_binding.ypbind_binding_port = port;
92 ypsd.ypsetdom_vers = YPVERS;
93
94 tv.tv_sec = 15;
95 tv.tv_usec = 0;
96 sock = RPC_ANYSOCK;
97 client = clntudp_create(sin, YPBINDPROG, YPBINDVERS, tv, &sock);
98 if (client==NULL) {
98 if (client == NULL) {
99 warnx("can't yp_bind, reason: %s", yperr_string(YPERR_YPBIND));
99 warnx("can't yp_bind, reason: %s", yperr_string(YPERR_YPBIND));
100 return YPERR_YPBIND;
100 return (YPERR_YPBIND);
101 }
102 client->cl_auth = authunix_create_default();
103
104 r = clnt_call(client, YPBINDPROC_SETDOM,
105 xdr_ypbind_setdom, &ypsd, xdr_void, NULL, tv);
101 }
102 client->cl_auth = authunix_create_default();
103
104 r = clnt_call(client, YPBINDPROC_SETDOM,
105 xdr_ypbind_setdom, &ypsd, xdr_void, NULL, tv);
106 if(r) {
106 if (r) {
107 warnx("sorry, cannot ypset for domain %s on host", dom);
108 clnt_destroy(client);
107 warnx("sorry, cannot ypset for domain %s on host", dom);
108 clnt_destroy(client);
109 return YPERR_YPBIND;
109 return (YPERR_YPBIND);
110 }
111 clnt_destroy(client);
110 }
111 clnt_destroy(client);
112 return 0;
112 return (0);
113}
114
115int
116main(argc, argv)
117char **argv;
118{
119 struct sockaddr_in sin;
120 struct hostent *hent;
121 char *domainname;
122 int c;
123
124 yp_get_default_domain(&domainname);
125
126 bzero(&sin, sizeof sin);
127 sin.sin_family = AF_INET;
128 sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
129
113}
114
115int
116main(argc, argv)
117char **argv;
118{
119 struct sockaddr_in sin;
120 struct hostent *hent;
121 char *domainname;
122 int c;
123
124 yp_get_default_domain(&domainname);
125
126 bzero(&sin, sizeof sin);
127 sin.sin_family = AF_INET;
128 sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
129
130 while( (c=getopt(argc, argv, "h:d:")) != -1)
131 switch(c) {
130 while ((c = getopt(argc, argv, "h:d:")) != -1)
131 switch (c) {
132 case 'd':
133 domainname = optarg;
134 break;
135 case 'h':
132 case 'd':
133 domainname = optarg;
134 break;
135 case 'h':
136 if( (sin.sin_addr.s_addr=inet_addr(optarg)) == -1) {
136 if ((sin.sin_addr.s_addr = inet_addr(optarg)) == -1) {
137 hent = gethostbyname(optarg);
137 hent = gethostbyname(optarg);
138 if(hent==NULL)
138 if (hent == NULL)
139 errx(1, "host %s unknown", optarg);
140 bcopy(&hent->h_addr_list[0], &sin.sin_addr,
141 sizeof sin.sin_addr);
142 }
143 break;
144 default:
145 usage();
146 }
147
139 errx(1, "host %s unknown", optarg);
140 bcopy(&hent->h_addr_list[0], &sin.sin_addr,
141 sizeof sin.sin_addr);
142 }
143 break;
144 default:
145 usage();
146 }
147
148 if(optind + 1 != argc )
148 if (optind + 1 != argc)
149 usage();
150
151 if (bind_tohost(&sin, domainname, argv[optind]))
152 exit(1);
153 exit(0);
154}
149 usage();
150
151 if (bind_tohost(&sin, domainname, argv[optind]))
152 exit(1);
153 exit(0);
154}