shithub: fingerd

Download patch

ref: 93c347adf541f8588aa610f66040dd96d39ccc3e
parent: e36ece0f555d55a9ee79ef64a582cd093c41ab2b
author: sirjofri <[email protected]>
date: Mon May 6 10:22:43 EDT 2024

fixes .. issues

--- a/fingerd.c
+++ b/fingerd.c
@@ -4,15 +4,13 @@
 #include <bio.h>
 
 #define BUFSIZ 8192
-#define LOG "fingerd"
 
+char *LOG = "fingerd";
 char *nsfile = "/lib/namespace.finger";
 char *usernotfound = "/lib/finger/usernotfound";
 char *filenotfound = "/lib/finger/filenotfound";
 char *motd = "/lib/finger/motd";
 
-char *req;
-
 int puserlist = 1;
 
 int
@@ -111,14 +109,54 @@
 {
 	if (!cat(filenotfound, 0))
 		print("File '%s' not found.\r\n", file);
+	syslog(1, LOG, "file %s not found", file);
 }
 
 void
+printglobalfile(char *file)
+{
+	if (bind("/lib/finger/tree/", "/", MREPL) < 0) {
+		print("unable to bind.\r\n");
+		syslog(1, LOG, "unable to bind /lib/finger/tree: %r");
+		return;
+	}
+	chdir("/");
+	if (!vaccess(file)){
+		printnofile(file);
+		return;
+	}
+	if (!cat(file, OREAD))
+		printnofile(file);
+}
+
+void
+printuserfile(char *user, char *file)
+{
+	char *path;
+	
+	path = smprint("/usr/%s/finger/", user);
+	if (bind(path, "/", MREPL) < 0) {
+		print("unable to bind!\r\n");
+		syslog(1, LOG, "unable to bind /usr/%s/finger: %r", user);
+		free(path);
+		return;
+	}
+	free(path);
+	chdir("/");
+	if (!vaccess("finger")){
+		printnouser(user);
+		return;
+	}
+	if (!cat(file, OREAD))
+		printnofile(file);
+}
+
+void
 main(int argc, char **argv)
 {
 	int n;
 	Biobuf *bin;
-	char *user, *file, *path;
+	char *user, *file, *req;
 
 	ARGBEGIN{
 	case 'l':
@@ -139,6 +177,8 @@
 		req[n-1] = 0;
 		n--;
 	}
+	
+	rfork(RFNAMEG|RFNOMNT);
 
 	if (vaccess(nsfile)){
 		if (addns("none", nsfile) < 0){
@@ -159,26 +199,10 @@
 		file = splitpath(req);
 		user = req;
 		if (strlen(user) <= 0) {
-			path = smprint("/lib/finger/tree/%s", file);
-			if (!vaccess(path)){
-				printnofile(file);
-				break;
-			}
-			if (!cat(path, OREAD))
-				printnofile(file);
-			free(path);
+			printglobalfile(file);
 			break;
 		}
-		path = smprint("/usr/%s/finger/finger", user);
-		if (!vaccess(path)){
-			printnouser(user);
-			break;
-		}
-		free(path);
-		path = smprint("/usr/%s/finger/%s", user, file);
-		if (!cat(path, OREAD))
-			printnofile(file);
-		free(path);
+		printuserfile(user, file);
 	}
 	exits(nil);
 }