2 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
3 * unrestricted use provided that this legend is included on all tape
4 * media and as a part of the software program in whole or part. Users
5 * may copy or modify Sun RPC without charge, but are not authorized
6 * to license or distribute it to anyone else except as part of a product or
7 * program developed by the user.
9 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
10 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
11 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
13 * Sun RPC is provided with no support and without any obligation on the
14 * part of Sun Microsystems, Inc. to assist in its use, correction,
15 * modification or enhancement.
17 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
18 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
19 * OR ANY PART THEREOF.
21 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
22 * or profits or other special, indirect and consequential damages, even if
23 * Sun has been advised of the possibility of such damages.
25 * Sun Microsystems, Inc.
27 * Mountain View, California 94043
31 * Allows for gathering of registrations from an earlier dumped file.
33 * Copyright (c) 1990 by Sun Microsystems, Inc.
37 * @(#)warmstart.c 1.7 93/07/05 SMI
38 * $FreeBSD: src/usr.sbin/rpcbind/warmstart.c,v 1.4 2007/11/07 10:53:39 kevlo Exp $
41 #include <sys/types.h>
45 #include <rpc/rpcb_prot.h>
48 #include <netinet/in.h>
49 #include <rpc/pmap_prot.h>
57 * XXX this code is unsafe and is not used. It should be made safe.
61 /* These files keep the pmap_list and rpcb_list in XDR format */
62 #define RPCBFILE "/tmp/rpcbind.file"
64 #define PMAPFILE "/tmp/portmap.file"
67 static bool_t write_struct(char *, xdrproc_t, void *);
68 static bool_t read_struct(char *, xdrproc_t, void *);
71 write_struct(char *filename, xdrproc_t structproc, void *list)
78 fp = fopen(filename, "w");
82 for (i = 0; i < 10; i++)
84 fp = fopen(filename, "w");
87 "cannot open file = %s for writing", filename);
88 syslog(LOG_ERR, "cannot save any registration");
93 xdrstdio_create(&xdrs, fp, XDR_ENCODE);
95 if (structproc(&xdrs, list) == FALSE) {
96 syslog(LOG_ERR, "rpcbind: xdr_%s: failed", filename);
106 read_struct(char *filename, xdrproc_t structproc, void *list)
112 if (stat(filename, &sbuf) != 0) {
114 "rpcbind: cannot stat file = %s for reading\n", filename);
117 if ((sbuf.st_uid != 0) || (sbuf.st_mode & S_IRWXG) ||
118 (sbuf.st_mode & S_IRWXO)) {
120 "rpcbind: invalid permissions on file = %s for reading\n",
124 fp = fopen(filename, "r");
127 "rpcbind: cannot open file = %s for reading\n", filename);
130 xdrstdio_create(&xdrs, fp, XDR_DECODE);
132 if (structproc(&xdrs, list) == FALSE) {
133 fprintf(stderr, "rpcbind: xdr_%s: failed\n", filename);
141 error: fprintf(stderr, "rpcbind: will start from scratch\n");
146 write_warmstart(void)
148 write_struct(RPCBFILE, (xdrproc_t)xdr_rpcblist_ptr, &list_rbl);
150 write_struct(PMAPFILE, (xdrproc_t)xdr_pmaplist_ptr, &list_pml);
158 rpcblist_ptr tmp_rpcbl = NULL;
160 struct pmaplist *tmp_pmapl = NULL;
164 ok1 = read_struct(RPCBFILE, (xdrproc_t)xdr_rpcblist_ptr, &tmp_rpcbl);
168 ok2 = read_struct(PMAPFILE, (xdrproc_t)xdr_pmaplist_ptr, &tmp_pmapl);
171 xdr_free((xdrproc_t) xdr_rpcblist_ptr, (char *)&tmp_rpcbl);
174 xdr_free((xdrproc_t) xdr_rpcblist_ptr, (char *)&list_rbl);
175 list_rbl = tmp_rpcbl;
177 xdr_free((xdrproc_t) xdr_pmaplist_ptr, (char *)&list_pml);
178 list_pml = tmp_pmapl;