]>
git.saurik.com Git - apple/network_cmds.git/blob - yppush.tproj/yppush.c
3249369e6ab201333146af730591c64630cbff4e
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
25 /* $OpenBSD: yppush.c,v 1.10 1997/11/10 05:49:17 deraadt Exp $ */
28 * Copyright (c) 1995 Mats O Jansson <moj@stacken.kth.se>
29 * All rights reserved.
31 * Redistribution and use in source and binary forms, with or without
32 * modification, are permitted provided that the following conditions
34 * 1. Redistributions of source code must retain the above copyright
35 * notice, this list of conditions and the following disclaimer.
36 * 2. Redistributions in binary form must reproduce the above copyright
37 * notice, this list of conditions and the following disclaimer in the
38 * documentation and/or other materials provided with the distribution.
39 * 3. All advertising materials mentioning features or use of this software
40 * must display the following acknowledgement:
41 * This product includes software developed by Mats O Jansson
42 * 4. The name of the author may not be used to endorse or promote products
43 * derived from this software without specific prior written permission.
45 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
46 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
47 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
48 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
49 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
50 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
51 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
52 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
53 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
54 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
59 static char rcsid
[] = "$OpenBSD: yppush.c,v 1.10 1997/11/10 05:49:17 deraadt Exp $";
62 #include <sys/types.h>
69 #include <rpcsvc/yp.h>
70 #include <rpcsvc/ypclnt.h>
72 #include <sys/resource.h>
73 #include <sys/signal.h>
79 #include "yplib_host.h"
84 char Domain
[MAXHOSTNAMELEN
], Map
[255];
88 extern void yppush_xfrrespprog_1(struct svc_req
*request
, SVCXPRT
*xprt
);
89 extern bool_t
xdr_ypreq_xfr(XDR
*, struct ypreq_xfr
*);
94 fprintf(stderr
, "Usage:\n");
96 fprintf(stderr, "\typpush [-d domainname] [-t seconds] [-p #paralleljobs] [-h host] [-v] mapname\n");
98 fprintf(stderr
, "\typpush [-d domainname] [-h host] [-v] mapname\n");
106 struct timeval timeout
;
108 timeout
.tv_sec
=60; timeout
.tv_usec
=0;
112 switch (select(_rpc_dtablesize(), &readfds
, (void *) 0,
113 (void *) 0, &timeout
)) {
115 if (errno
== EINTR
) {
118 perror("yppush: _svc_run: select failed");
121 fprintf(stderr
, "yppush: Callback timed out.\n");
124 svc_getreqset(&readfds
);
131 req_xfr(pid
, prog
, transp
, host
, client
)
138 struct ypreq_xfr request
;
141 tv
.tv_sec
=0; tv
.tv_usec
=0;
143 request
.map_parms
.domain
=(char *)&Domain
;
144 request
.map_parms
.map
=(char *)&Map
;
145 request
.map_parms
.peer
=master
;
146 request
.map_parms
.ordernum
=OrderNum
;
147 request
.transid
=(u_int
)pid
;
149 request
.port
=transp
->xp_port
;
152 printf("%d: %s(%u@%s) -> %s@%s\n",
154 request
.map_parms
.map
,
155 request
.map_parms
.ordernum
,
157 request
.map_parms
.peer
,
158 request
.map_parms
.domain
);
159 switch (clnt_call(client
, YPPROC_XFR
, xdr_ypreq_xfr
, &request
,
160 xdr_void
, NULL
, tv
)) {
165 clnt_perror(client
, "yppush: Cannot call YPPROC_XFR");
175 char host
[MAXHOSTNAMELEN
];
178 int sock
= RPC_ANYSOCK
;
185 snprintf(host
,sizeof host
,"%*.*s" ,inlen
,inlen
, indata
);
187 client
= clnt_create(host
, YPPROG
, YPVERS
, "tcp");
188 if (client
== NULL
) {
190 fprintf(stderr
,"Target Host: %s\n",host
);
191 clnt_pcreateerror("yppush: Cannot create client");
195 transp
= svcudp_create(sock
);
196 if (transp
== NULL
) {
197 fprintf(stderr
, "yppush: Cannot create callback transport.\n");
200 if (transp
->xp_port
>= IPPORT_RESERVED
) {
202 fprintf(stderr
, "yppush: Cannot allocate reserved port.\n");
206 for (prog
=0x40000000; prog
<0x5fffffff; prog
++) {
207 if (sts
= svc_register(transp
, prog
, 1,
208 yppush_xfrrespprog_1
, IPPROTO_UDP
))
213 fprintf(stderr
, "yppush: Cannot register callback.\n");
219 fprintf(stderr
, "yppush: Cannot fork.\n");
225 close(transp
->xp_sock
);
226 transp
->xp_sock
= -1;
227 req_xfr(pid
, prog
, transp
, host
, client
);
228 wait4(pid
, &status
, 0, &res
);
229 svc_unregister(prog
, 1);
231 clnt_destroy(client
);
232 /* XXX transp leak? */
238 pushit(instatus
, inkey
, inkeylen
, inval
, invallen
, indata
)
246 if(instatus
!= YP_TRUE
)
248 push(invallen
, inval
);
257 struct ypall_callback ypcb
;
260 char *domain
,*map
,*hostname
,*parallel
,*timeout
;
262 char *ypmap
= "ypservers";
264 static char map_path
[MAXPATHLEN
];
267 char order_key
[YP_LAST_LEN
] = YP_LAST_KEY
;
270 yp_get_default_domain(&domain
);
273 while( (c=getopt(argc, argv, "d:h:p:t:v?")) != -1)
275 while( (c
=getopt(argc
, argv
, "d:h:v?")) != -1)
297 if(optind
+ 1 != argc
)
302 strncpy(Domain
,domain
,sizeof(Domain
)-1);
303 Domain
[sizeof(Domain
)-1] = '\0';
304 strncpy(Map
,map
,sizeof(Map
)-1);
305 Map
[sizeof(Map
)-1] = '\0';
308 snprintf(map_path
,sizeof map_path
,"%s/%s",YP_DB_PATH
,domain
);
309 if (!((stat(map_path
, &finfo
) == 0) &&
310 ((finfo
.st_mode
& S_IFMT
) == S_IFDIR
))) {
311 fprintf(stderr
,"yppush: Map does not exist.\n");
317 snprintf(map_path
,sizeof map_path
,"%s/%s/%s%s",
318 YP_DB_PATH
,domain
,Map
,YPDB_SUFFIX
);
319 if (!(stat(map_path
, &finfo
) == 0)) {
320 fprintf(stderr
,"yppush: Map does not exist.\n");
324 snprintf(map_path
,sizeof map_path
,"%s/%s/%s",YP_DB_PATH
,domain
,Map
);
325 yp_databas
= ypdb_open(map_path
,0,O_RDONLY
);
327 if (yp_databas
== 0) {
328 fprintf(stderr
, "yppush: %s%s: Cannot open database\n",
329 map_path
, YPDB_SUFFIX
);
331 o
.dptr
= (char *) &order_key
;
332 o
.dsize
= YP_LAST_LEN
;
333 o
=ypdb_fetch(yp_databas
,o
);
334 if (o
.dptr
== NULL
) {
336 "yppush: %s: Cannot determine order number\n",
340 for(i
=0; i
<o
.dsize
-1; i
++) {
341 if (!isdigit(o
.dptr
[i
])) {
347 "yppush: %s: Invalid order number '%s'\n",
351 OrderNum
= atoi(o
.dptr
);
359 r
= yp_master(Domain
, ypmap
, &master
);
361 fprintf(stderr
, "yppush: could not get ypservers map\n");
365 if (hostname
!= NULL
) {
366 push(strlen(hostname
), hostname
);
370 printf("Contacting master for ypservers (%s).\n", master
);
373 client
= yp_bind_host(master
, YPPROG
, YPVERS
, 0, 1);
375 ypcb
.foreach
= pushit
;
378 r
= yp_all_host(client
,Domain
, ypmap
, &ypcb
);