Subject: `safety'(?) patch for finger/fingerd.
To: None <tech-userlevel@NetBSD.ORG>
From: matthew green <mrg@eterna.com.au>
List: tech-userlevel
Date: 09/09/1997 03:44:32
someone asked me if there was a way to remotely hide his non-realname
gecos info from finger today, and i said "no, there isn't."


however, below is a patch that adds a `-g' flag to both finger and
fingerd that makes this happen.  fingerd just passes the -g onto
finger when it calls it, and finger will not show non-realname
gecos information if called with the `-g' switch.

my reasoning for this is as follows:
	- local users may want other local users to know about
	  themselves.
	- local users may want _non_ local users _not_ to know
	  about themselves.
	- the administrator may want to provide finger service
	  for various reasons.

fingerd already provides a `-p' switch, which disables showing
.plan and .project files.

i'd like for these changes to go in, but i'm not too worried
about it if someone thinks that they aren't necessary.


comments?


.mrg.

Index: usr.bin/finger/extern.h
===================================================================
RCS file: /cvsroot/src/usr.bin/finger/extern.h,v
retrieving revision 1.2
diff -c -r1.2 extern.h
*** extern.h	1996/11/21 06:01:47	1.2
--- extern.h	1997/09/08 17:35:31
***************
*** 38,43 ****
--- 38,44 ----
  extern int entries;			/* Number of people. */
  extern int lflag;
  extern int oflag;
+ extern int gflag;
  extern int pplan;
  
  int	 demi_print __P((char *, int));
Index: usr.bin/finger/finger.1
===================================================================
RCS file: /cvsroot/src/usr.bin/finger/finger.1,v
retrieving revision 1.7
diff -c -r1.7 finger.1
*** finger.1	1997/01/09 20:19:18	1.7
--- finger.1	1997/09/08 17:35:31
***************
*** 42,48 ****
  .Nd user information lookup program
  .Sh SYNOPSIS
  .Nm finger
! .Op Fl lmpsho
  .Op Ar user ...
  .Op Ar user@host ...
  .Sh DESCRIPTION
--- 42,48 ----
  .Nd user information lookup program
  .Sh SYNOPSIS
  .Nm finger
! .Op Fl lmpshog
  .Op Ar user ...
  .Op Ar user@host ...
  .Sh DESCRIPTION
***************
*** 87,92 ****
--- 87,95 ----
  .Fl s
  option, the office location and office phone information is displayed
  instead of the name of the remote host.
+ .Pp
+ .It Fl g
+ This option restricts the gecos output to only the users' real names.
  .Pp
  .It Fl l
  Produces a multi-line format displaying all of the information
Index: usr.bin/finger/finger.c
===================================================================
RCS file: /cvsroot/src/usr.bin/finger/finger.c,v
retrieving revision 1.7
diff -c -r1.7 finger.c
*** finger.c	1997/05/17 19:42:24	1.7
--- finger.c	1997/09/08 17:35:32
***************
*** 81,87 ****
  #include "extern.h"
  
  time_t now;
! int entries, lflag, sflag, mflag, oflag, pplan;
  char tbuf[1024];
  
  int
--- 81,87 ----
  #include "extern.h"
  
  time_t now;
! int entries, lflag, sflag, mflag, oflag, gflag, pplan;
  char tbuf[1024];
  
  int
***************
*** 94,100 ****
  
  	oflag = 1;		/* default to old "office" behavior */
  
! 	while ((ch = getopt(argc, argv, "lmpsho")) != EOF)
  		switch(ch) {
  		case 'l':
  			lflag = 1;		/* long format */
--- 94,100 ----
  
  	oflag = 1;		/* default to old "office" behavior */
  
! 	while ((ch = getopt(argc, argv, "lmpshog")) != EOF)
  		switch(ch) {
  		case 'l':
  			lflag = 1;		/* long format */
***************
*** 113,118 ****
--- 113,121 ----
  			break;
  		case 'o':
  			oflag = 1;		/* office info */
+ 			break;
+ 		case 'g':
+ 			gflag = 1;		/* no gecos info, besides name */
  			break;
  		case '?':
  		default:
Index: usr.bin/finger/lprint.c
===================================================================
RCS file: /cvsroot/src/usr.bin/finger/lprint.c,v
retrieving revision 1.7
diff -c -r1.7 lprint.c
*** lprint.c	1997/01/09 20:19:22	1.7
--- lprint.c	1997/09/08 17:35:33
***************
*** 103,108 ****
--- 103,110 ----
  	    pn->name, pn->realname, pn->dir);
  	(void)printf("\tShell: %-s\n", *pn->shell ? pn->shell : _PATH_BSHELL);
  
+ 	if (gflag)
+ 		goto no_gecos;
  	/*
  	 * try and print office, office phone, and home phone on one line;
  	 * if that fails, do line filling so it looks nice.
***************
*** 138,143 ****
--- 140,146 ----
  	if (oddfield)
  		putchar('\n');
  
+ no_gecos:
  	/*
  	 * long format con't:
  	 * if logged in
Index: usr.bin/finger/sprint.c
===================================================================
RCS file: /cvsroot/src/usr.bin/finger/sprint.c,v
retrieving revision 1.6
diff -c -r1.6 sprint.c
*** sprint.c	1997/03/28 02:15:21	1.6
--- sprint.c	1997/09/08 17:35:33
***************
*** 79,85 ****
  #define	MAXREALNAME	20
  #define	MAXHOSTNAME	20
  	(void)printf("%-*s %-*s %s %s\n", UT_NAMESIZE, "Login", MAXREALNAME,
! 	    "Name", "Tty  Idle  Login Time  ",
  	    (oflag) ? "Office     Office Phone" : "Where");
  	for (cnt = 0; cnt < entries; ++cnt) {
  		pn = list[cnt];
--- 79,85 ----
  #define	MAXREALNAME	20
  #define	MAXHOSTNAME	20
  	(void)printf("%-*s %-*s %s %s\n", UT_NAMESIZE, "Login", MAXREALNAME,
! 	    "Name", "Tty  Idle  Login Time  ", (gflag) ? "" :
  	    (oflag) ? "Office     Office Phone" : "Where");
  	for (cnt = 0; cnt < entries; ++cnt) {
  		pn = list[cnt];
***************
*** 114,119 ****
--- 114,121 ----
  			else
  				(void)printf(" %.5s", p + 11);
  office:
+ 			if (gflag)
+ 				goto no_gecos;
  			putchar(' ');
  			if (oflag) {
  				if (pn->office)
***************
*** 125,130 ****
--- 127,133 ----
  						    prphone(pn->officephone));
  			} else
  				(void)printf("%.*s", MAXHOSTNAME, w->host);
+ no_gecos:
  			putchar('\n');
  		}
  	}
Index: libexec/fingerd/fingerd.8
===================================================================
RCS file: /cvsroot/src/libexec/fingerd/fingerd.8,v
retrieving revision 1.5
diff -c -r1.5 fingerd.8
*** fingerd.8	1997/01/20 21:01:29	1.5
--- fingerd.8	1997/09/08 17:36:47
***************
*** 47,52 ****
--- 47,53 ----
  .Op Fl m
  .Op Fl p
  .Op Fl S
+ .Op Fl g
  .Op Fl P Ar filename
  .Sh DESCRIPTION
  .Nm Fingerd
***************
*** 136,141 ****
--- 137,144 ----
  This overrides the
  .Dq Pa Whois switch
  that may be passed in from the remote client.
+ .It Fl g
+ Do not show any gecos information besides the users' real names.
  .It Fl P
  Use an alternate program as the local information provider.
  The default local program
Index: libexec/fingerd/fingerd.c
===================================================================
RCS file: /cvsroot/src/libexec/fingerd/fingerd.c,v
retrieving revision 1.4
diff -c -r1.4 fingerd.c
*** fingerd.c	1997/01/20 21:01:30	1.4
--- fingerd.c	1997/09/08 17:36:47
***************
*** 81,87 ****
  	logging = secure = user_required = short_list = 0;
  	openlog("fingerd", LOG_PID | LOG_CONS, LOG_DAEMON);
  	opterr = 0;
! 	while ((ch = getopt(argc, argv, "sluSmpP:")) != EOF)
  		switch (ch) {
  		case 'l':
  			logging = 1;
--- 81,87 ----
  	logging = secure = user_required = short_list = 0;
  	openlog("fingerd", LOG_PID | LOG_CONS, LOG_DAEMON);
  	opterr = 0;
! 	while ((ch = getopt(argc, argv, "gsluSmpP:")) != EOF)
  		switch (ch) {
  		case 'l':
  			logging = 1;
***************
*** 104,109 ****
--- 104,112 ----
  			break;
  		case 'p':
  			av[ac++] = "-p";
+ 			break;
+ 		case 'g':
+ 			av[ac++] = "-g";
  			break;
  		case '?':
  		default: