summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Dickson <steved@redhat.com>2008-02-08 14:27:57 -0500
committerSteve Dickson <steved@redhat.com>2008-02-08 14:27:57 -0500
commit40009ddc661a43883d0f7841f6bbd71e0c9b530a (patch)
tree9c655d022f27e4d2719c19a86a44fdb82144ccb1
parenta28ded4f011bcc3f75a359f5fe842bf8cd2b00f3 (diff)
downloadrpcbind-40009ddc661a43883d0f7841f6bbd71e0c9b530a.tar.gz
Fixed a warning in pmap_svc.c
Cleaned up read_struct(). Signed-off-by: Steve Dickson <steved@redhat.com>
-rw-r--r--src/pmap_svc.c2
-rw-r--r--src/rpcbind.c3
-rw-r--r--src/warmstart.c74
3 files changed, 38 insertions, 41 deletions
diff --git a/src/pmap_svc.c b/src/pmap_svc.c
index 5b43dd0..99ce508 100644
--- a/src/pmap_svc.c
+++ b/src/pmap_svc.c
@@ -314,7 +314,7 @@ pmapproc_getport(struct svc_req *rqstp /*__unused*/, SVCXPRT *xprt)
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 = '.';
diff --git a/src/rpcbind.c b/src/rpcbind.c
index 650cd29..949ece2 100644
--- a/src/rpcbind.c
+++ b/src/rpcbind.c
@@ -85,7 +85,6 @@ char *rpcbinduser = RPCBIND_USER;
#else
char *rpcbinduser = NULL;
#endif
-uid_t rpc_uid;
/* who to suid to if -s is given */
#define RUN_AS "daemon"
@@ -209,7 +208,6 @@ main(int argc, char *argv[])
err(1, "fork failed");
}
- rpc_uid = 0;
if (runasdaemon || rpcbinduser) {
struct passwd *p;
char *id = runasdaemon ? RUN_AS : rpcbinduser;
@@ -222,7 +220,6 @@ main(int argc, char *argv[])
syslog(LOG_ERR, "setuid to '%s' failed: %m", id);
exit(1);
}
- rpc_uid = p->pw_uid;
}
#ifdef WARMSTART
diff --git a/src/warmstart.c b/src/warmstart.c
index a1322b1..91e482b 100644
--- a/src/warmstart.c
+++ b/src/warmstart.c
@@ -45,6 +45,7 @@
#endif
#include <syslog.h>
#include <unistd.h>
+#include <errno.h>
#include "config.h"
#include "rpcbind.h"
@@ -88,7 +89,7 @@ write_struct(char *filename, xdrproc_t structproc, void *list)
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);
}
@@ -103,38 +104,39 @@ read_struct(char *filename, xdrproc_t structproc, void *list)
FILE *fp;
XDR xdrs;
struct stat sbuf;
- extern uid_t rpc_uid;
- if (stat(filename, &sbuf) != 0) {
- fprintf(stderr,
- "rpcbind: cannot stat file = %s for reading\n", filename);
- goto error;
- }
- if ((sbuf.st_uid != rpc_uid) || (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);
}
@@ -142,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
}
@@ -155,22 +157,20 @@ read_warmstart()
#ifdef PORTMAP
struct pmaplist *tmp_pmapl = NULL;
#endif
- int ok1, ok2 = TRUE;
+ int rc;
- 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;
+ 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;
}
- 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;
+ 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
+
+ return;
}