2 * SPDX-License-Identifier: BSD-3-Clause
4 * Copyright (c) 2009, Sun Microsystems, Inc.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 * - Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
14 * - Neither the name of Sun Microsystems, Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived
16 * from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
32 * Allows for gathering of registrations from an earlier dumped file.
34 * Copyright (c) 1990 by Sun Microsystems, Inc.
38 * #ident "@(#)warmstart.c 1.7 93/07/05 SMI"
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 (void) write_struct(RPCBFILE, (xdrproc_t)xdr_rpcblist_ptr, &list_rbl);
150 (void) 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;