Sophie

Sophie

distrib > * > 2008.0 > x86_64 > by-pkgid > c56375966e6b0fac3dae4f3b23902319 > files > 7

rpcbind-0.1.4-8mdv2008.0.src.rpm

--- rpcbind-0.1.4/src/warmstart.c.orig	2007-09-19 14:31:34.000000000 -0300
+++ rpcbind-0.1.4/src/warmstart.c	2007-09-19 14:32:45.000000000 -0300
@@ -34,6 +34,7 @@
  */
 
 #include <sys/types.h>
+#include <pwd.h>
 #include <sys/stat.h>
 #include <stdio.h>
 #include <rpc/rpc.h>
@@ -66,6 +67,9 @@
 static bool_t write_struct __P((char *, xdrproc_t, void *));
 static bool_t read_struct __P((char *, xdrproc_t, void *));
 
+extern int runasdaemon;
+extern char *rpcbinduser;
+
 static bool_t
 write_struct(char *filename, xdrproc_t structproc, void *list)
 {
@@ -107,13 +111,25 @@
 	FILE *fp;
 	XDR xdrs;
 	struct stat sbuf;
+        uid_t uid = 0;
 
 	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) ||
+
+        if (runasdaemon || rpcbinduser) {
+                char *id = runasdaemon ? "daemon" : rpcbinduser;
+                struct passwd *p;
+                if ((p = getpwnam(id)) == NULL) {
+                        syslog(LOG_ERR, "cannot get uid of '%s': %m", id);
+                        exit(1);
+                }
+                uid = p->pw_uid;
+        }
+
+	if ((sbuf.st_uid != uid) || (sbuf.st_mode & S_IRWXG) ||
 	    (sbuf.st_mode & S_IRWXO)) {
 		fprintf(stderr,
 		"rpcbind: invalid permissions on file = %s for reading\n",