1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* Portions of this source code were derived from Berkeley
* under license from the Regents of the University of
* California.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* This is a user command which issues a "Set domain binding" command to a
* YP binder (ypbind) process
*
* ypset [-h <host>] [-d <domainname>] server_to_use
*
* where host and server_to_use may be either names or internet addresses.
*/
#include <stdio.h>
#include <ctype.h>
#include <rpc/rpc.h>
#include <rpcsvc/ypclnt.h>
#include <rpcsvc/yp_prot.h>
#include "yp_b.h"
#include <sys/utsname.h>
extern CLIENT *__clnt_create_loopback();
#ifdef NULL
#undef NULL
#endif
#define NULL 0
#define TIMEOUT 30 /* Total seconds for timeout */
static char *pusage;
static char *domain = NULL;
static char default_domain_name[YPMAXDOMAIN];
static char default_host_name[256];
static char *host = NULL;
static char *server_to_use;
static struct timeval timeout = {
TIMEOUT, /* Seconds */
0 /* Microseconds */
};
static char err_usage_set[] =
"Usage:\n\
ypset [ -h host ] [ -d domainname ] server_to_use\n\n";
static char err_bad_args[] =
"Sorry, the %s argument is bad.\n";
static char err_cant_get_kname[] =
"Sorry, can't get %s back from system call.\n";
static char err_null_kname[] =
"Sorry, the %s hasn't been set on this machine.\n";
static char err_bad_hostname[] = "hostname";
static char err_bad_domainname[] = "domainname";
static char err_bad_server[] = "server_to_use";
static char err_tp_failure[] =
"Sorry, I can't set up a connection to host %s.\n";
static char err_rpc_failure[] =
"Sorry, I couldn't send my rpc message to ypbind on host %s.\n";
static char err_access_failure[] =
"ypset: Sorry, ypbind on host %s has rejected your request.\n";
static void get_command_line_args();
static void send_message();
extern void exit();
extern int getdomainname();
extern int gethostname();
extern struct netconfig *getnetconfigent();
extern unsigned int strlen();
/*
* This is the mainline for the ypset process. It pulls whatever arguments
* have been passed from the command line, and uses defaults for the rest.
*/
int
main(argc, argv)
int argc;
char **argv;
{
get_command_line_args(argc, argv);
if (!domain) {
if (!getdomainname(default_domain_name, YPMAXDOMAIN)) {
domain = default_domain_name;
} else {
(void) fprintf(stderr,
err_cant_get_kname,
err_bad_domainname);
exit(1);
}
if ((int)strlen(domain) == 0) {
(void) fprintf(stderr,
err_null_kname,
err_bad_domainname);
exit(1);
}
}
send_message();
return (0);
}
/*
* This does the command line argument processing.
*/
static void
get_command_line_args(argc, argv)
int argc;
char **argv;
{
pusage = err_usage_set;
argv++;
while (--argc > 1) {
if ((*argv)[0] == '-') {
switch ((*argv)[1]) {
case 'h': {
if (argc > 1) {
struct utsname utsname;
argv++;
argc--;
(void) uname(&utsname);
if (strcasecmp(utsname.nodename,
*argv) != 0) {
host = *argv;
if ((int)strlen(host) > 256) {
(void) fprintf(stderr,
err_bad_args,
err_bad_hostname);
exit(1);
}
}
argv++;
} else {
(void) fprintf(stderr, pusage);
exit(1);
}
break;
}
case 'd': {
if (argc > 1) {
argv++;
argc--;
domain = *argv;
argv++;
if (strlen(domain) > YPMAXDOMAIN) {
(void) fprintf(stderr,
err_bad_args,
err_bad_domainname);
exit(1);
}
} else {
(void) fprintf(stderr, pusage);
exit(1);
}
break;
}
default: {
(void) fprintf(stderr, pusage);
exit(1);
}
}
} else {
(void) fprintf(stderr, pusage);
exit(1);
}
}
if (argc == 1) {
if ((*argv)[0] == '-') {
(void) fprintf(stderr, pusage);
exit(1);
}
server_to_use = *argv;
if ((int)strlen(server_to_use) > 256) {
(void) fprintf(stderr, err_bad_args,
err_bad_server);
exit(1);
}
} else {
(void) fprintf(stderr, pusage);
exit(1);
}
}
/*
* This takes the name of the YP host of interest, and fires off
* the "set domain binding" message to the ypbind process.
*/
static void
send_message()
{
CLIENT *server, *client;
struct ypbind_setdom req;
struct ypbind_binding ypbind_info;
enum clnt_stat clnt_stat;
struct netconfig *nconf;
struct netbuf nbuf;
int err;
/*
* Open up a path to the server
*/
if ((server = clnt_create(server_to_use, YPPROG, YPVERS,
"datagram_n")) == NULL) {
(void) fprintf(stderr, err_tp_failure, server_to_use);
exit(1);
}
/* get nconf, netbuf structures */
nconf = getnetconfigent(server->cl_netid);
clnt_control(server, CLGET_SVC_ADDR, (char *)&nbuf);
/*
* Open a path to host
*/
if (!host) {
client = __clnt_create_loopback(YPBINDPROG, YPBINDVERS, &err);
if (client == (CLIENT *)NULL) {
clnt_pcreateerror("ypset: clnt_create");
exit(1);
}
client->cl_auth = authsys_create("", geteuid(), 0, 0, NULL);
if (client->cl_auth == NULL) {
clnt_pcreateerror("ypset: clnt_create");
exit(1);
}
} else {
client = clnt_create(host, YPBINDPROG,
YPBINDVERS, "datagram_n");
if (client == (CLIENT *)NULL) {
clnt_pcreateerror("ypset: clnt_create");
exit(1);
}
}
/*
* Load up the message structure and fire it off.
*/
ypbind_info.ypbind_nconf = nconf;
ypbind_info.ypbind_svcaddr = (struct netbuf *)(&nbuf);
ypbind_info.ypbind_servername = server_to_use;
ypbind_info.ypbind_hi_vers = YPVERS;
ypbind_info.ypbind_lo_vers = YPVERS;
req.ypsetdom_bindinfo = &ypbind_info;
req.ypsetdom_domain = domain;
clnt_stat = (enum clnt_stat) clnt_call(client,
YPBINDPROC_SETDOM, xdr_ypbind_setdom, (char *)&req, xdr_void, 0,
timeout);
if (clnt_stat != RPC_SUCCESS) {
if (clnt_stat == RPC_PROGUNAVAIL)
(void) fprintf(stderr,
err_access_failure, host ? host : "localhost");
else
(void) fprintf(stderr,
err_rpc_failure, host ? host : "localhost");
exit(1);
}
if (!host)
auth_destroy((client)->cl_auth);
(void) clnt_destroy(server);
(void) clnt_destroy(client);
}
|