]>
git.saurik.com Git - apple/network_cmds.git/blob - yppush.tproj/yppush.c
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
23 /* $OpenBSD: yppush.c,v 1.10 1997/11/10 05:49:17 deraadt Exp $ */
26 * Copyright (c) 1995 Mats O Jansson <moj@stacken.kth.se>
27 * All rights reserved.
29 * Redistribution and use in source and binary forms, with or without
30 * modification, are permitted provided that the following conditions
32 * 1. Redistributions of source code must retain the above copyright
33 * notice, this list of conditions and the following disclaimer.
34 * 2. Redistributions in binary form must reproduce the above copyright
35 * notice, this list of conditions and the following disclaimer in the
36 * documentation and/or other materials provided with the distribution.
37 * 3. All advertising materials mentioning features or use of this software
38 * must display the following acknowledgement:
39 * This product includes software developed by Mats O Jansson
40 * 4. The name of the author may not be used to endorse or promote products
41 * derived from this software without specific prior written permission.
43 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
44 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
45 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
46 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
47 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
48 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
49 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
50 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
51 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
52 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
57 static char rcsid
[] = "$OpenBSD: yppush.c,v 1.10 1997/11/10 05:49:17 deraadt Exp $";
60 #include <sys/types.h>
67 #include <rpcsvc/yp.h>
68 #include <rpcsvc/ypclnt.h>
69 #include <sys/param.h>
71 #include <sys/resource.h>
72 #include <sys/signal.h>
78 #include "yplib_host.h"
83 char Domain
[MAXHOSTNAMELEN
], Map
[255];
87 extern void yppush_xfrrespprog_1(struct svc_req
*request
, SVCXPRT
*xprt
);
88 extern bool_t
xdr_ypreq_xfr(XDR
*, struct ypreq_xfr
*);
93 fprintf(stderr
, "Usage:\n");
95 fprintf(stderr, "\typpush [-d domainname] [-t seconds] [-p #paralleljobs] [-h host] [-v] mapname\n");
97 fprintf(stderr
, "\typpush [-d domainname] [-h host] [-v] mapname\n");
105 struct timeval timeout
;
107 timeout
.tv_sec
=60; timeout
.tv_usec
=0;
111 switch (select(_rpc_dtablesize(), &readfds
, (void *) 0,
112 (void *) 0, &timeout
)) {
114 if (errno
== EINTR
) {
117 perror("yppush: _svc_run: select failed");
120 fprintf(stderr
, "yppush: Callback timed out.\n");
123 svc_getreqset(&readfds
);
130 req_xfr(pid
, prog
, transp
, host
, client
)
137 struct ypreq_xfr request
;
140 tv
.tv_sec
=0; tv
.tv_usec
=0;
142 request
.map_parms
.domain
=(char *)&Domain
;
143 request
.map_parms
.map
=(char *)&Map
;
144 request
.map_parms
.peer
=master
;
145 request
.map_parms
.ordernum
=OrderNum
;
146 request
.transid
=(u_int
)pid
;
148 request
.port
=transp
->xp_port
;
151 printf("%d: %s(%u@%s) -> %s@%s\n",
153 request
.map_parms
.map
,
154 request
.map_parms
.ordernum
,
156 request
.map_parms
.peer
,
157 request
.map_parms
.domain
);
158 switch (clnt_call(client
, YPPROC_XFR
, xdr_ypreq_xfr
, &request
,
159 xdr_void
, NULL
, tv
)) {
164 clnt_perror(client
, "yppush: Cannot call YPPROC_XFR");
174 char host
[MAXHOSTNAMELEN
];
177 int sock
= RPC_ANYSOCK
;
184 snprintf(host
,sizeof host
,"%*.*s" ,inlen
,inlen
, indata
);
186 client
= clnt_create(host
, YPPROG
, YPVERS
, "tcp");
187 if (client
== NULL
) {
189 fprintf(stderr
,"Target Host: %s\n",host
);
190 clnt_pcreateerror("yppush: Cannot create client");
194 transp
= svcudp_create(sock
);
195 if (transp
== NULL
) {
196 fprintf(stderr
, "yppush: Cannot create callback transport.\n");
199 if (transp
->xp_port
>= IPPORT_RESERVED
) {
201 fprintf(stderr
, "yppush: Cannot allocate reserved port.\n");
205 for (prog
=0x40000000; prog
<0x5fffffff; prog
++) {
206 if (sts
= svc_register(transp
, prog
, 1,
207 yppush_xfrrespprog_1
, IPPROTO_UDP
))
212 fprintf(stderr
, "yppush: Cannot register callback.\n");
218 fprintf(stderr
, "yppush: Cannot fork.\n");
224 close(transp
->xp_sock
);
225 transp
->xp_sock
= -1;
226 req_xfr(pid
, prog
, transp
, host
, client
);
227 wait4(pid
, &status
, 0, &res
);
228 svc_unregister(prog
, 1);
230 clnt_destroy(client
);
231 /* XXX transp leak? */
237 pushit(instatus
, inkey
, inkeylen
, inval
, invallen
, indata
)
245 if(instatus
!= YP_TRUE
)
247 push(invallen
, inval
);
256 struct ypall_callback ypcb
;
259 char *domain
,*map
,*hostname
,*parallel
,*timeout
;
261 char *ypmap
= "ypservers";
263 static char map_path
[MAXPATHLEN
];
266 char order_key
[YP_LAST_LEN
] = YP_LAST_KEY
;
269 yp_get_default_domain(&domain
);
272 while( (c=getopt(argc, argv, "d:h:p:t:v?")) != -1)
274 while( (c
=getopt(argc
, argv
, "d:h:v?")) != -1)
296 if(optind
+ 1 != argc
)
301 strncpy(Domain
,domain
,sizeof(Domain
)-1);
302 Domain
[sizeof(Domain
)-1] = '\0';
303 strncpy(Map
,map
,sizeof(Map
)-1);
304 Map
[sizeof(Map
)-1] = '\0';
307 snprintf(map_path
,sizeof map_path
,"%s/%s",YP_DB_PATH
,domain
);
308 if (!((stat(map_path
, &finfo
) == 0) &&
309 ((finfo
.st_mode
& S_IFMT
) == S_IFDIR
))) {
310 fprintf(stderr
,"yppush: Map does not exist.\n");
316 snprintf(map_path
,sizeof map_path
,"%s/%s/%s%s",
317 YP_DB_PATH
,domain
,Map
,YPDB_SUFFIX
);
318 if (!(stat(map_path
, &finfo
) == 0)) {
319 fprintf(stderr
,"yppush: Map does not exist.\n");
323 snprintf(map_path
,sizeof map_path
,"%s/%s/%s",YP_DB_PATH
,domain
,Map
);
324 yp_databas
= ypdb_open(map_path
,0,O_RDONLY
);
326 if (yp_databas
== 0) {
327 fprintf(stderr
, "yppush: %s%s: Cannot open database\n",
328 map_path
, YPDB_SUFFIX
);
330 o
.dptr
= (char *) &order_key
;
331 o
.dsize
= YP_LAST_LEN
;
332 o
=ypdb_fetch(yp_databas
,o
);
333 if (o
.dptr
== NULL
) {
335 "yppush: %s: Cannot determine order number\n",
339 for(i
=0; i
<o
.dsize
-1; i
++) {
340 if (!isdigit(o
.dptr
[i
])) {
346 "yppush: %s: Invalid order number '%s'\n",
350 OrderNum
= atoi(o
.dptr
);
358 r
= yp_master(Domain
, ypmap
, &master
);
360 fprintf(stderr
, "yppush: could not get ypservers map\n");
364 if (hostname
!= NULL
) {
365 push(strlen(hostname
), hostname
);
369 printf("Contacting master for ypservers (%s).\n", master
);
372 client
= yp_bind_host(master
, YPPROG
, YPVERS
, 0, 1);
374 ypcb
.foreach
= pushit
;
377 r
= yp_all_host(client
,Domain
, ypmap
, &ypcb
);