2 * Copyright (c) 2009, Sun Microsystems, Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * - Redistributions of source code must retain the above copyright notice,
8 * this list of conditions and the following disclaimer.
9 * - Redistributions in binary form must reproduce the above copyright notice,
10 * this list of conditions and the following disclaimer in the documentation
11 * and/or other materials provided with the distribution.
12 * - Neither the name of Sun Microsystems, Inc. nor the names of its
13 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
30 * Allows for gathering of registrations from an earlier dumped file.
32 * Copyright (c) 1990 by Sun Microsystems, Inc.
36 * @(#)warmstart.c 1.7 93/07/05 SMI
37 * $FreeBSD: src/usr.sbin/rpcbind/warmstart.c,v 1.4 2007/11/07 10:53:39 kevlo Exp $
39 #include <sys/types.h>
43 #include <rpc/rpcb_prot.h>
46 #include <netinet/in.h>
47 #include <rpc/pmap_prot.h>
55 * XXX this code is unsafe and is not used. It should be made safe.
59 /* These files keep the pmap_list and rpcb_list in XDR format */
60 #define RPCBFILE "/tmp/rpcbind.file"
62 #define PMAPFILE "/tmp/portmap.file"
65 static bool_t
write_struct(char *, xdrproc_t
, void *);
66 static bool_t
read_struct(char *, xdrproc_t
, void *);
69 write_struct(char *filename
, xdrproc_t structproc
, void *list
)
76 fp
= fopen(filename
, "w");
80 for (i
= 0; i
< 10; i
++)
82 fp
= fopen(filename
, "w");
85 "cannot open file = %s for writing", filename
);
86 syslog(LOG_ERR
, "cannot save any registration");
91 xdrstdio_create(&xdrs
, fp
, XDR_ENCODE
);
93 if (structproc(&xdrs
, list
) == FALSE
) {
94 syslog(LOG_ERR
, "rpcbind: xdr_%s: failed", filename
);
104 read_struct(char *filename
, xdrproc_t structproc
, void *list
)
110 if (stat(filename
, &sbuf
) != 0) {
112 "rpcbind: cannot stat file = %s for reading\n", filename
);
115 if ((sbuf
.st_uid
!= 0) || (sbuf
.st_mode
& S_IRWXG
) ||
116 (sbuf
.st_mode
& S_IRWXO
)) {
118 "rpcbind: invalid permissions on file = %s for reading\n",
122 fp
= fopen(filename
, "r");
125 "rpcbind: cannot open file = %s for reading\n", filename
);
128 xdrstdio_create(&xdrs
, fp
, XDR_DECODE
);
130 if (structproc(&xdrs
, list
) == FALSE
) {
131 fprintf(stderr
, "rpcbind: xdr_%s: failed\n", filename
);
139 error
: fprintf(stderr
, "rpcbind: will start from scratch\n");
144 write_warmstart(void)
146 write_struct(RPCBFILE
, (xdrproc_t
)xdr_rpcblist_ptr
, &list_rbl
);
148 write_struct(PMAPFILE
, (xdrproc_t
)xdr_pmaplist_ptr
, &list_pml
);
156 rpcblist_ptr tmp_rpcbl
= NULL
;
158 struct pmaplist
*tmp_pmapl
= NULL
;
162 ok1
= read_struct(RPCBFILE
, (xdrproc_t
)xdr_rpcblist_ptr
, &tmp_rpcbl
);
166 ok2
= read_struct(PMAPFILE
, (xdrproc_t
)xdr_pmaplist_ptr
, &tmp_pmapl
);
169 xdr_free((xdrproc_t
) xdr_rpcblist_ptr
, (char *)&tmp_rpcbl
);
172 xdr_free((xdrproc_t
) xdr_rpcblist_ptr
, (char *)&list_rbl
);
173 list_rbl
= tmp_rpcbl
;
175 xdr_free((xdrproc_t
) xdr_pmaplist_ptr
, (char *)&list_pml
);
176 list_pml
= tmp_pmapl
;