bsd-finger: Add debian patches for IPv6

This commit is contained in:
Ersei Saggi 2024-03-14 17:03:39 -04:00
parent 043e316272
commit b441c35784
No known key found for this signature in database
GPG Key ID: 023FF4C1A9D6BAFD
2 changed files with 150 additions and 282 deletions

View File

@ -1,7 +1,9 @@
{ lib
, stdenv
, fetchurl
, buildClient ? true
{
lib,
stdenv,
fetchurl,
fetchDebianPatch,
buildClient ? true,
}:
stdenv.mkDerivation rec {
@ -10,36 +12,163 @@ stdenv.mkDerivation rec {
version = "0.17";
src = fetchurl {
url = "mirror://ibiblioPubLinux/system/network/finger/${srcName}-${version}.tar.gz";
hash = "sha256-hIhdZo0RfvUOAccDSkXYND10fOxiEuQOjQgVG8GOE/o=";
url = "http://ftp.de.debian.org/debian/pool/main/b/bsd-finger/bsd-finger_${version}.orig.tar.bz2";
hash = "sha256-KLNNYF0j6mh9eeD8SMA1q+gPiNnBVH56pGeW0QgcA2M=";
};
debianRevision = "17";
# outputs = [ "out" "man" ];
env.NIX_CFLAGS_COMPILE = "-D_GNU_SOURCE";
patches = [
./ubuntu-0.17-9.patch
# Patches original finger sources to make the programs more robust and compatible
(fetchDebianPatch {
pname = srcName;
inherit version debianRevision;
patch = "01-legacy.patch";
hash = "sha256-84znJLXez4w6WB2nOW+PHK/0srE0iG9nGAjO1/AGczw=";
})
# http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=518559
#
# Doesn't work with a non-iterable nsswitch source
#
# Currently, "finger tabbott" works by iterating through the list of users
# on the system using getpwent and checking if any of them match "tabbott".
#
# Some nsswitch backends (including Hesiod and LDAP[1]) do not support
# iterating through the complete list of users. These nsswitch backends
# instead only fully support looking up a user's information by username or
# uid.
#
# So, if tabbott is a user whose nsswitch information comes from LDAP, then
# "finger tabbott" will incorrectly report "finger: tabbott: no such user."
# "finger -m tabbott" does work correctly, however, because it looks up the
# matching username using getpwnam.
#
# A fix for this is to always look up an argument to finger for a username
# match, and having -m only control whether finger searches the entire user
# database for real name matches. Patch attached.
#
# This patch has the advantageous side effect that if there are some real
# name matches and a username match, finger will always display the username
# match first (rather than in some random place in the list).
#
# -Tim Abbott
#
# [1] with LDAP, it is typically the case that one can iterate through only
# the first 100 results from a query.
(fetchDebianPatch {
pname = srcName;
inherit version debianRevision;
patch = "02-518559-nsswitch-sources.patch";
hash = "sha256-oBXJ/kr/czevWk0TcsutGINNwCoHnEStRT8Jfgp/lbM=";
})
# http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=468454
# Implement IPv6 capacity for the server Fingerd.
(fetchDebianPatch {
pname = srcName;
inherit version debianRevision;
patch = "03-468454-fingerd-ipv6.patch";
hash = "sha256-a5+qoy2UKa2nCJrwrfJ5VPZoACFXFQ1j/rweoMYW1Z0=";
})
# http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=468454
# Implement IPv6 capability for the client Finger.
(fetchDebianPatch {
pname = srcName;
inherit version debianRevision;
patch = "04-468454-finger-ipv6.patch";
hash = "sha256-cg93NL02lJm/5Freegb3EbjDAQVkurLEEJifcyQRRfk=";
})
# http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=547014
# From: "Matthew A. Dunford" <mdunford@lbl.gov>
#
# finger segfaults when it comes across a netgroup entry in /etc/passwd.
# A netgroup entry doesn't include many of the fields in a normal passwd
# entry, so pw->pw_gecos is set to NULL, which causes finger to core
# dump.
#
# Here is part of a /etc/passwd file with a netgroup entry:
#
# nobody:x:65534:65534:nobody:/nonexistent:/bin/sh
# +@operator
#
# This patch sidesteps what finger considers a malformed passwd entry:
(fetchDebianPatch {
pname = srcName;
inherit version debianRevision;
patch = "05-547014-netgroup.patch";
hash = "sha256-d+ufp7nPZwW+t+EWASzHrXT/O6zSzt6OOV12cKVo3P0=";
})
# Decrease timeout length during connect().
# In cases where a name server is answering with A as well as AAAA records,
# but the system to be queried has lost a corresponding address, the TCP
# handshake timeout will cause a long delay before allowing the query of
# the next address family, or the next address in general.
# .
# The use of a trivial signal handler for SIGALRM allows the reduction
# of this timeout, thus producing better responsiveness for the interactive
# user of the Finger service.
# Author: Mats Erik Andersson <debian@gisladisker.se>
(fetchDebianPatch {
pname = srcName;
inherit version debianRevision;
patch = "06-572211-decrease-timeout.patch";
hash = "sha256-KtNGU5mmX1nnxQc7XnYoUuVW4We2cF81+x6EQrHF7g0=";
})
# Use cmake as build system
(fetchDebianPatch {
pname = srcName;
inherit version debianRevision;
patch = "use-cmake-as-buildsystem.patch";
hash = "sha256-YOmkF6Oxowy15mCE1pCvHKnLEXglijWFG6eydnZJFhM=";
})
# Debian-specific changes to the cmake build system (that NixOS will also benefit from)
# Adds -D_GNU_SOURCE, which will enable many C extensions that finger benefits from
(fetchDebianPatch {
pname = srcName;
inherit version debianRevision;
patch = "use-cmake-as-buildsystem-debian-extras.patch";
hash = "sha256-T3DWpyyz15JCiVJ41RrJEhsmicei8G3OaKpxvzOCcBU=";
})
# Fix typo at fingerd man page (Josue Ortega <josue@debian.org>)
(fetchDebianPatch {
pname = srcName;
inherit version debianRevision;
patch = "fix-fingerd-man-typo.patch";
hash = "sha256-f59osGi0a8Tkm2Vxg2+H2brH8WproCDvbPf4jXwi6ag=";
})
];
preBuild = let
srcdir = if buildClient then "finger" else "fingerd";
in ''
cd ${srcdir}
'';
preBuild =
let
srcdir = if buildClient then "finger" else "fingerd";
in
''
cd ${srcdir}
'';
preInstall = let
bindir = if buildClient then "bin" else "sbin";
mandir = if buildClient then "man/man1" else "man/man8";
in ''
mkdir -p $out/${bindir} $out/${mandir}
'';
preInstall =
let
bindir = if buildClient then "bin" else "sbin";
mandir = if buildClient then "man/man1" else "man/man8";
in
''
mkdir -p $out/${bindir} $out/${mandir}
'';
meta = with lib; {
description =
if buildClient
then "User information lookup program"
else "Remote user information server";
if buildClient then "User information lookup program" else "Remote user information server";
platforms = platforms.linux;
license = licenses.bsdOriginal;
mainProgram = "finger";

View File

@ -1,261 +0,0 @@
--- bsd-finger-0.17.orig/finger/finger.1
+++ bsd-finger-0.17/finger/finger.1
@@ -169,16 +169,14 @@
must be able to see the
.Pa .nofinger
file. This generally means that the home directory containing the file
-must have the other-users-execute bit set (o+w). See
+must have the other-users-execute bit set (o+x). See
.Xr chmod 1 .
If you use this feature for privacy, please test it with ``finger
@localhost'' before relying on it, just in case.
.It ~/.plan
.It ~/.project
-.It ~/.pgp
+.It ~/.pgpkey
These files are printed as part of a long-format request. The
-.Pa .project
-file is limited to one line; the
.Pa .plan
file may be arbitrarily long.
.El
--- bsd-finger-0.17.orig/finger/finger.c
+++ bsd-finger-0.17/finger/finger.c
@@ -77,7 +77,7 @@
#include "../version.h"
static void loginlist(void);
-static void userlist(int argc, char *argv[]);
+static int userlist(int argc, char *argv[]);
int lflag, pplan;
static int sflag, mflag;
@@ -92,6 +92,7 @@
int main(int argc, char *argv[]) {
int ch;
+ int err = 0;
struct sockaddr_in sin;
socklen_t slen = sizeof(sin);
@@ -159,7 +160,7 @@
}
}
else {
- userlist(argc, argv);
+ err = userlist(argc, argv);
/*
* Assign explicit "large" format if names given and -s not
* explicitly stated. Force the -l AFTER we get names so any
@@ -172,7 +173,7 @@
if (lflag) lflag_print();
else sflag_print();
}
- return 0;
+ return err;
}
/* Returns 1 if .nofinger is found and enable_nofinger is set. */
@@ -181,10 +182,16 @@
check_nofinger(struct passwd *pw)
{
if (enable_nofinger) {
- char path[PATH_MAX];
struct stat tripe;
- snprintf(path, sizeof(path), "%s/.nofinger", pw->pw_dir);
- if (stat(path, &tripe)==0) {
+ int ret;
+ char *path;
+ if (asprintf(&path, "%s/.nofinger", pw->pw_dir) < 0) {
+ eprintf("finger: Out of space.\n");
+ exit(1);
+ }
+ ret = stat(path, &tripe);
+ free(path);
+ if (!ret) {
return 1;
}
}
@@ -264,10 +271,11 @@
}
-static void
+static int
userlist(int argc, char *argv[])
{
int i;
+ int err = 0;
PERSON *pn;
PERSON *nethead, **nettail;
struct utmp *uptr;
@@ -297,13 +305,13 @@
/* handle network requests */
for (pn = nethead; pn; pn = pn->next) {
- netfinger(pn->name);
+ err |= netfinger(pn->name);
if (pn->next || entries)
xputc('\n');
}
if (entries == 0)
- return;
+ return err;
/*
* Scan thru the list of users currently logged in, saving
@@ -331,4 +339,6 @@
enter_lastlog(pn);
}
endutent();
+
+ return err;
}
--- bsd-finger-0.17.orig/finger/finger.h
+++ bsd-finger-0.17/finger/finger.h
@@ -92,7 +92,7 @@
void enter_where(struct utmp *ut, PERSON *pn);
void enter_lastlog(PERSON *pn);
int match(struct passwd *pw, const char *user);
-void netfinger(const char *name);
+int netfinger(const char *name);
const char *prphone(const char *num);
#ifndef DAYSPERNYEAR
--- bsd-finger-0.17.orig/finger/lprint.c
+++ bsd-finger-0.17/finger/lprint.c
@@ -48,7 +48,7 @@
#include <sys/types.h>
#include <sys/file.h>
#include <sys/stat.h>
-#include <sys/time.h>
+#include <time.h>
#include "finger.h"
static void lprint(PERSON *pn);
@@ -100,7 +100,7 @@
* office, office phone, home phone if available
*/
xprintf("Login: %-15s\t\t\tName: %s\nDirectory: %-25s",
- pn->name, pn->realname, pn->dir);
+ pn->name, pn->realname ? pn->realname : "", pn->dir);
xprintf("\tShell: %-s\n", *pn->shell ? pn->shell : _PATH_BSHELL);
/*
--- bsd-finger-0.17.orig/finger/net.c
+++ bsd-finger-0.17/finger/net.c
@@ -51,7 +51,7 @@
#include <ctype.h>
#include "finger.h"
-void netfinger(const char *name) {
+int netfinger(const char *name) {
register FILE *fp;
struct in_addr defaddr;
register int c, sawret, ateol;
@@ -62,7 +62,7 @@
char *alist[1], *host;
host = strrchr(name, '@');
- if (!host) return;
+ if (!host) return 1;
*host++ = '\0';
memset(&sn, 0, sizeof(sn));
@@ -70,7 +70,7 @@
sp = getservbyname("finger", "tcp");
if (!sp) {
eprintf("finger: tcp/finger: unknown service\n");
- return;
+ return 1;
}
sn.sin_port = sp->s_port;
@@ -78,7 +78,7 @@
if (!hp) {
if (!inet_aton(host, &defaddr)) {
eprintf("finger: unknown host: %s\n", host);
- return;
+ return 1;
}
def.h_name = host;
def.h_addr_list = alist;
@@ -96,7 +96,7 @@
if ((s = socket(hp->h_addrtype, SOCK_STREAM, 0)) < 0) {
eprintf("finger: socket: %s\n", strerror(errno));
- return;
+ return 1;
}
/* print hostname before connecting, in case it takes a while */
@@ -104,7 +104,7 @@
if (connect(s, (struct sockaddr *)&sn, sizeof(sn)) < 0) {
eprintf("finger: connect: %s\n", strerror(errno));
close(s);
- return;
+ return 1;
}
/* -l flag for remote fingerd */
@@ -128,7 +128,7 @@
if (!fp) {
eprintf("finger: fdopen: %s\n", strerror(errno));
close(s);
- return;
+ return 1;
}
sawret = 0;
@@ -152,4 +152,6 @@
}
if (!ateol) xputc('\n');
fclose(fp);
+
+ return 0;
}
--- bsd-finger-0.17.orig/finger/sprint.c
+++ bsd-finger-0.17/finger/sprint.c
@@ -40,7 +40,7 @@
#endif /* not lint */
#include <sys/types.h>
-#include <sys/time.h>
+#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
--- bsd-finger-0.17.orig/finger/util.c
+++ bsd-finger-0.17/finger/util.c
@@ -64,7 +64,7 @@
struct stat sb;
/* No device for X console. Utmp entry by XDM login (":0"). */
- if (w->tty[0] == ':') {
+ if (strchr(w->tty, ':')) {
w->idletime = 0; /* would be nice to have it emit ??? */
w->writable = 0;
return;
@@ -109,9 +109,8 @@
* fields[3] -> homephone
*/
nfields = 0;
- for (p = strtok(bp, ","); p; p = strtok(NULL, ",")) {
- if (*p==0) p = NULL; // skip empties
- if (nfields < 4) fields[nfields++] = p;
+ while ((p = strsep(&bp, ","))) {
+ if (nfields < 4) fields[nfields++] = *p ? p : NULL;
}
while (nfields<4) fields[nfields++] = NULL;
@@ -150,6 +149,9 @@
pn->realname = rname;
}
+ else {
+ pn->realname = NULL;
+ }
pn->office = fields[1] ? strdup(fields[1]) : NULL;
pn->officephone = fields[2] ? strdup(fields[2]) : NULL;