1
0
forked from rpms/rpcbind
rpcbind/rpcbind-0.1.4-warmstarts-cleanup.patch
Steve Dickson 604a14b4a1 - Fixed a warning in pmap_svc.c
- Cleaned up warmstarts so uid are longer needed, also changed condrestarts
    to use warmstarts. (bz 428496)
2008-02-11 16:06:13 +00:00

198 lines
5.4 KiB
Diff

commit 40009ddc661a43883d0f7841f6bbd71e0c9b530a
Author: Steve Dickson <steved@redhat.com>
Date: Fri Feb 8 14:27:57 2008 -0500
Fixed a warning in pmap_svc.c
Cleaned up read_struct().
Signed-off-by: Steve Dickson <steved@redhat.com>
diff -up rpcbind-0.1.4/src/rpcbind.c.save rpcbind-0.1.4/src/rpcbind.c
--- rpcbind-0.1.4/src/rpcbind.c.save 2008-02-11 10:10:01.000000000 -0500
+++ rpcbind-0.1.4/src/rpcbind.c 2008-02-11 10:16:14.000000000 -0500
@@ -193,11 +193,7 @@ main(int argc, char *argv[])
(void) signal(SIGHUP, SIG_IGN);
(void) signal(SIGUSR1, SIG_IGN);
(void) signal(SIGUSR2, SIG_IGN);
-#ifdef WARMSTART
- if (warmstart) {
- read_warmstart();
- }
-#endif
+
if (debugging) {
#ifdef RPCBIND_DEBUG
printf("rpcbind debugging enabled.");
@@ -226,6 +222,12 @@ main(int argc, char *argv[])
}
}
+#ifdef WARMSTART
+ if (warmstart) {
+ read_warmstart();
+ }
+#endif
+
network_init();
my_svc_run();
diff -up rpcbind-0.1.4/src/warmstart.c.save rpcbind-0.1.4/src/warmstart.c
--- rpcbind-0.1.4/src/warmstart.c.save 2008-02-11 10:10:01.000000000 -0500
+++ rpcbind-0.1.4/src/warmstart.c 2008-02-11 10:16:14.000000000 -0500
@@ -45,22 +45,19 @@
#endif
#include <syslog.h>
#include <unistd.h>
+#include <errno.h>
#include "config.h"
#include "rpcbind.h"
-/*
- * XXX this code is unsafe and is not used. It should be made safe.
- */
-
#ifndef RPCBIND_STATEDIR
#define RPCBIND_STATEDIR "/tmp"
#endif
/* These files keep the pmap_list and rpcb_list in XDR format */
-#define RPCBFILE RPCBIND_STATEDIR "/rpcbind.file"
+#define RPCBFILE RPCBIND_STATEDIR "/rpcbind.xdr"
#ifdef PORTMAP
-#define PMAPFILE RPCBIND_STATEDIR "/portmap.file"
+#define PMAPFILE RPCBIND_STATEDIR "/portmap.xdr"
#endif
static bool_t write_struct __P((char *, xdrproc_t, void *));
@@ -92,7 +89,7 @@ write_struct(char *filename, xdrproc_t s
xdrstdio_create(&xdrs, fp, XDR_ENCODE);
if (structproc(&xdrs, list) == FALSE) {
- syslog(LOG_ERR, "rpcbind: xdr_%s: failed", filename);
+ syslog(LOG_ERR, "xdr_%s: failed", filename);
fclose(fp);
return (FALSE);
}
@@ -107,37 +104,39 @@ read_struct(char *filename, xdrproc_t st
FILE *fp;
XDR xdrs;
struct stat sbuf;
-
- if (stat(filename, &sbuf) != 0) {
- fprintf(stderr,
- "rpcbind: cannot stat file = %s for reading\n", filename);
- goto error;
- }
- if ((sbuf.st_uid != 0) || (sbuf.st_mode & S_IRWXG) ||
- (sbuf.st_mode & S_IRWXO)) {
- fprintf(stderr,
- "rpcbind: invalid permissions on file = %s for reading\n",
- filename);
- goto error;
- }
- fp = fopen(filename, "r");
- if (fp == NULL) {
- fprintf(stderr,
- "rpcbind: cannot open file = %s for reading\n", filename);
+
+ if (debugging)
+ fprintf(stderr, "rpcbind: using '%s' startup file\n", filename);
+
+ if ((fp = fopen(filename, "r")) == NULL) {
+ syslog(LOG_ERR,
+ "Cannot open '%s' file for reading, errno %d (%s)",
+ filename, errno, strerror(errno));
goto error;
}
- xdrstdio_create(&xdrs, fp, XDR_DECODE);
+ xdrstdio_create(&xdrs, fp, XDR_DECODE);
if (structproc(&xdrs, list) == FALSE) {
fprintf(stderr, "rpcbind: xdr_%s: failed\n", filename);
fclose(fp);
goto error;
}
XDR_DESTROY(&xdrs);
+
fclose(fp);
+ if (unlink(filename) < 0) {
+ syslog(LOG_ERR, "Cannot unlink '%s', errno %d (%s)",
+ filename, errno, strerror(errno));
+ }
return (TRUE);
-error: fprintf(stderr, "rpcbind: will start from scratch\n");
+error:
+ if (errno != ENOENT && unlink(filename) < 0) {
+ syslog(LOG_ERR, "Cannot unlink '%s', errno %d (%s)",
+ filename, errno, strerror(errno));
+ }
+ if (debugging)
+ fprintf(stderr, "rpcbind: will start from scratch\n");
return (FALSE);
}
@@ -145,9 +144,9 @@ void
write_warmstart()
{
(void) write_struct(RPCBFILE, (xdrproc_t)xdr_rpcblist_ptr, &list_rbl);
- #ifdef PORTMAP
- (void) write_struct(PMAPFILE, (xdrproc_t)xdr_pmaplist_ptr, &list_pml);
- #endif
+#ifdef PORTMAP
+ (void) write_struct(PMAPFILE, (xdrproc_t)xdr_pmaplist_ptr, &list_pml);
+#endif
}
@@ -158,22 +157,20 @@ read_warmstart()
#ifdef PORTMAP
struct pmaplist *tmp_pmapl = NULL;
#endif
- int ok1, ok2 = TRUE;
+ int rc;
+
+ rc = read_struct(RPCBFILE, (xdrproc_t)xdr_rpcblist_ptr, &tmp_rpcbl);
+ if (rc == TRUE) {
+ xdr_free((xdrproc_t) xdr_rpcblist_ptr, (char *)&list_rbl);
+ list_rbl = tmp_rpcbl;
+ }
+#ifdef PORTMAP
+ rc = read_struct(PMAPFILE, (xdrproc_t)xdr_pmaplist_ptr, &tmp_pmapl);
+ if (rc == TRUE) {
+ xdr_free((xdrproc_t) xdr_pmaplist_ptr, (char *)&list_pml);
+ list_pml = tmp_pmapl;
+ }
+#endif
- ok1 = read_struct(RPCBFILE, (xdrproc_t)xdr_rpcblist_ptr, &tmp_rpcbl);
- if (ok1 == FALSE)
- return;
- #ifdef PORTMAP
- ok2 = read_struct(PMAPFILE, (xdrproc_t)xdr_pmaplist_ptr, &tmp_pmapl);
- #endif
- if (ok2 == FALSE) {
- xdr_free((xdrproc_t) xdr_rpcblist_ptr, (char *)&tmp_rpcbl);
- return;
- }
- xdr_free((xdrproc_t) xdr_rpcblist_ptr, (char *)&list_rbl);
- list_rbl = tmp_rpcbl;
- #ifdef PORTMAP
- xdr_free((xdrproc_t) xdr_pmaplist_ptr, (char *)&list_pml);
- list_pml = tmp_pmapl;
- #endif
+ return;
}
diff -up rpcbind-0.1.4/src/pmap_svc.c.save rpcbind-0.1.4/src/pmap_svc.c
--- rpcbind-0.1.4/src/pmap_svc.c.save 2008-02-11 10:15:34.000000000 -0500
+++ rpcbind-0.1.4/src/pmap_svc.c 2008-02-11 10:16:14.000000000 -0500
@@ -314,7 +314,7 @@ pmapproc_getport(struct svc_req *rqstp /
if ((pt2 = strrchr(ua, '.')) != NULL) {
*pt2 = 0;
snprintf(serveuaddr, sizeof serveuaddr,
- "%s.%d.%d", ua,
+ "%s.%ld.%ld", ua,
(fnd->pml_map.pm_port >> 8) & 0xff,
(fnd->pml_map.pm_port) & 0xff);
*pt2 = '.';