home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / gnu / utils / bug / 2021 < prev    next >
Encoding:
Text File  |  1992-11-08  |  6.4 KB  |  251 lines

  1. Newsgroups: gnu.utils.bug
  2. Path: sparky!uunet!think.com!sdd.hp.com!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!ctr.columbia.edu!seth
  3. From: seth@ctr.columbia.edu (Seth Robertson)
  4. Subject: Finger enhancements (to 1.37)
  5. Message-ID: <9211090350.AA05356@wookumz.gnu.ai.mit.edu>
  6. Sender: gnulists@ai.mit.edu
  7. Organization: GNUs Not Usenet
  8. Distribution: gnu
  9. Date: Sun, 8 Nov 1992 17:50:43 GMT
  10. Approved: bug-gnu-utils@prep.ai.mit.edu
  11. Lines: 238
  12.  
  13. Here are some hacks I have found useful:
  14.  
  15. MOTD -- Prepend a file on non-specific requests
  16. SHORT -- Unless specifically asked, only output one line per user
  17.  
  18. Also, I included three utility programs which I hacked off a few years
  19. ago for finger 1.10 They can be used to clean up the userdata file
  20. (get rid of deleted users, etc) or to print a list of users sorted
  21. in the order of last login.
  22.  
  23. If you have any questions, let me know.
  24.  
  25.  
  26.                                         -Seth Robertson
  27.                                          seth@ctr.columbia.edu
  28.  
  29. --- ./.orig/src/in.fingerd.c    Mon Oct 26 22:14:19 1992
  30. +++ ./src/in.fingerd.c    Sun Nov  8 22:08:09 1992
  31. @@ -18,7 +18,20 @@
  32.     along with this program; if not, write to the Free Software
  33.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  34.  
  35. +/*
  36.  
  37. +The following changes have been made:
  38. +
  39. +MOTD -- if defined, this should contain the name of the file which
  40. +        contains information which should be prepended to non-specific
  41. +    finger requests
  42. +
  43. +SHORT -- If defined, by default, you only get one line per user
  44. +     (with that line being the line with the least idle time)
  45. +
  46. +*/
  47. +
  48. +
  49.  #include <stdio.h>
  50.  #include <config.h>
  51.  
  52. @@ -325,6 +338,9 @@
  53.  {
  54.    register int i, f, len;
  55.    int match_free, match_all;
  56. +#ifdef SHORT
  57. +  int match_full_all, SaveUser = 0;
  58. +#endif /*SHORT*/
  59.    int packets_output, face;
  60.    FINGER_PACKET **hpackets, **upackets;
  61.    CLIENT **get_clients ();
  62. @@ -394,7 +410,13 @@
  63.      }
  64.  
  65.    match_free = (xstricmp (user, ".free") == 0);
  66. +
  67. +#ifdef SHORT
  68. +  match_full_all = (xstricmp (user, ".all") == 0);
  69. +  match_all = (match_full_all || !*user);
  70. +#else /*SHORT*/
  71.    match_all = ((xstricmp (user, ".all") == 0) || !*user);
  72. +#endif /*SHORT*/
  73.  
  74.    /* ".users" returns a listing of everyone in the userdata file. */
  75.    if (xstricmp (user, ".users") == 0)
  76. @@ -608,6 +630,21 @@
  77.      }
  78.      return;
  79.        }
  80. +
  81. +
  82. +#ifdef MOTD
  83. +  {
  84. +    FILE *fin = fopen(MOTD,"r");
  85. +    char buf[128];
  86. +
  87. +    if (fin)            /* Error if we cannot find it? */
  88. +      {
  89. +    while (fgets(buf,128,fin))
  90. +      fputs(buf,stdout);
  91. +    close(fin);
  92. +      }
  93. +  }
  94. +#endif /*MOTD*/
  95.    
  96.    warn_if_not_recent (HOSTDATA, stream);
  97.  
  98. @@ -633,6 +670,29 @@
  99.  
  100.    for (i = 0; hpackets[i]; i++)
  101.      {
  102. +#ifdef SHORT
  103. +      if (match_all && !match_full_all && !all_users)
  104. +        {
  105. +      /* We are searching for the record with the least amount of idle time */
  106. +
  107. +      /* If the name was the same as it was last time... */
  108. +      if (xstricmp(hpackets[SaveUser]->name,hpackets[i]->name) == 0)
  109. +        {
  110. +          /* and the idle time we had down previously was longer */
  111. +          if (hpackets[SaveUser]->idle_time > hpackets[i]->idle_time)
  112. +        {               /* Then keep the new idle time */
  113. +          SaveUser = i;
  114. +        }
  115. +        }
  116. +      else                  /* Otherwise we want to print the record we found */
  117. +        {
  118. +          ascii_packet (hpackets[SaveUser], stream, packets_output == 0);
  119. +          packets_output++;
  120. +          SaveUser = i;
  121. +        }
  122. +    }
  123. +      else
  124. +#endif /*SHORT*/
  125.        if (match_all || (xstricmp (user, hpackets[i]->name) == 0))
  126.      {
  127.        ascii_packet (hpackets[i], stream, packets_output == 0);
  128. @@ -639,6 +699,15 @@
  129.        packets_output++;
  130.      }
  131.      }
  132. +
  133. +#ifdef SHORT
  134. +  /* Make sure the last record is printed */
  135. +  if (match_all && !all_users && hpackets[SaveUser] )
  136. +    {
  137. +      ascii_packet (hpackets[SaveUser], stream, packets_output == 0);
  138. +      packets_output++;
  139. +    }
  140. +#endif /*SHORT*/
  141.  
  142.    /* If no packets were output, and the caller wanted to match everybody,
  143.       sorry, there is no one logged in anywhere that we know of.  But if the
  144. --- /dev/null    Sun Nov  8 15:19:27 1992
  145. +++ ./src/read_userdata.c    Sun Nov  8 22:29:29 1992
  146. @@ -0,0 +1,38 @@
  147. +/* Reads the userdata file in from standard in and outputs a
  148. + * list of last login times and user names.
  149. + *
  150. + * This is so that you can get a sorted list of when everyone
  151. + * last logged in
  152. + *
  153. + * Use it like:  read_userdata < /foo/userdata | sort -rn | user-to-time > /tmp/list
  154. + */
  155. +
  156. +#include <stdio.h>
  157. +
  158. +#include <general.h>
  159. +#include <client.h>
  160. +#include <getservhost.h>
  161. +#include <packet.h>
  162. +
  163. +main()
  164. +{
  165. +  FINGER_PACKET check;
  166. +  long current = (long)time ((long *)NULL);
  167. +
  168. +  while (fread(&check,sizeof(check),1,stdin))
  169. +    {
  170. +      if (!getpwnam(check.name))
  171. +    {
  172. +      fprintf(stderr,"Deleting %s\n",check.name);
  173. +      continue;
  174. +    }
  175. +
  176. +      if (check.login_time > current)
  177. +    {
  178. +      fprintf(stderr,"%s was in the future\n",check.name);
  179. +      check.login_time = 31536000; /* Magic number that I hopefully will remember */
  180. +    }
  181. +
  182. +      printf("%d %-8.8s\n",check.login_time,check.name);
  183. +    }
  184. +}
  185. --- /dev/null    Sun Nov  8 15:19:27 1992
  186. +++ ./src/reset_userdata.c    Sun Nov  8 22:29:30 1992
  187. @@ -0,0 +1,39 @@
  188. +/*
  189. +** This routine takes the userdata file as standard in and
  190. +** if the user does not exist any more, delete's him, otherwise
  191. +** if the user's login time is from the future, it changes
  192. +** the login time to a magic date that I'll never remember.
  193. +**
  194. +** Sometime you get alot of these in your database and you
  195. +** need to clear them out.
  196. +*/
  197. +
  198. +#include <stdio.h>
  199. +
  200. +#include <general.h>
  201. +#include <client.h>
  202. +#include <getservhost.h>
  203. +#include <packet.h>
  204. +
  205. +main()
  206. +{
  207. +  FINGER_PACKET check;
  208. +  long current = (long)time ((long *)NULL);
  209. +
  210. +  while (fread(&check,sizeof(check),1,stdin))
  211. +    {
  212. +      if (!getpwnam(check.name))
  213. +    {
  214. +      fprintf(stderr,"Deleting %s\n",check.name);
  215. +      continue;
  216. +    }
  217. +
  218. +      if (check.login_time > current)
  219. +    {
  220. +      fprintf(stderr,"%s was in the future\n",check.name);
  221. +      check.login_time = 31536000; /* Magic number that I hopefully will remember */
  222. +    }
  223. +
  224. +      fwrite(&check,sizeof(check),1,stdout);
  225. +    }
  226. +}
  227. --- /dev/null    Sun Nov  8 15:19:27 1992
  228. +++ ./src/user-to-time.c    Sun Nov  8 22:29:30 1992
  229. @@ -0,0 +1,20 @@
  230. +/* This converts the dates generated by read_userdata to an ASCII format
  231. + *
  232. + * Use it like:  read_userdata < /foo/userdata | sort -rn | user-to-time > /tmp/list
  233. + */
  234. +
  235. +#include <stdio.h>
  236. +
  237. +main()
  238. +{
  239. +  char buf[80];
  240. +  unsigned long ltime;
  241. +  char name[80];
  242. +
  243. +  while (fgets(buf,80,stdin))
  244. +    {
  245. +      sscanf(buf,"%lu %8c",<ime,name);
  246. +
  247. +      printf("%8s  %s",name,ctime(<ime));
  248. +    }
  249. +}
  250.  
  251.