home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 3 / 3558 / plan.prog
Encoding:
Internet Message Format  |  1991-06-29  |  9.6 KB

  1. Return-path: <armstron@cs.arizona.edu>
  2. Received: from optima.cs.arizona.edu by vaxb.acs.unt.edu with PMDF#10363; Thu,
  3.  11 Apr 1991 16:10 CST
  4. Received: from caslon.cs.arizona.edu by optima.cs.arizona.edu (4.1/15) id
  5.  AA23217; Thu, 11 Apr 91 14:09:13 MST
  6. Received: by caslon.cs.arizona.edu; Thu, 11 Apr 91 14:09:11 -0700
  7. Date: Thu, 11 Apr 91 14:09:10 MST
  8. From: Jim Armstrong <armstron@cs.arizona.edu>
  9. Subject: RE: fingeree ...
  10. In-reply-to: <9482C88780002EE8@vaxb.acs.unt.edu>; from "christopher williams"
  11.  at Apr 11, 91 2:46 pm
  12. To: CGW@vaxb.acs.unt.edu (christopher williams)
  13. Message-id: <9104112109.AA29387@caslon.cs.arizona.edu>
  14. X-Envelope-to: CGW
  15. X-Mailer: ELM [version 2.3 PL8]
  16.  
  17. > >About a month ago there was a sample program posted to this newsgroup that
  18. > >set up a FIFO named pipe as your .plan file.  I modified the code to set up
  19. > >a simple (perhaps naive) finger monitor for users on my machine.  The process
  20. > do you still have the source for it? would you send it to me?
  21.  
  22. Here is the article which appeared in comp.unix.questions a while back.  It
  23. contains generic code that will run any program you want whenever a certain
  24. file is accessed (i.e. the .plan file in this case).  All you have to do is
  25. compile it (it creates an executable called 'plan') and then to get it
  26. running say 'plan a.out &' where a.out is some program you have written.
  27. I don't have my program any more, but basically what I did was a ps au
  28. within that program.  It used egrep to search for someone currently fingering
  29. me and appended the output to a file.  To get really fancy you could then
  30. read from that file to find out exactly who it is (all in the same program)
  31. and print out a nice personal message to whoever is fingering you as part
  32. of what looks to be your .plan file.  A couple of things to watch out for:
  33. If the finger is remote, the ps au won't find anything.  Also, if two people
  34. finger you at the same time you may run into trouble, but I didn't try
  35. experimenting with this too much.  I also found it helpful to timestamp a
  36. date to the file, too (I used localtime() for efficiency).  This makes it
  37. easier to look back later at the file and see who's been fingering you and
  38. when while you were not logged on.  It also helpful in debugging your program.
  39.  
  40. So set up this code and experiment with different programs.  Just be creative
  41. and see what else you can do with it.  One idea I used for a while is making
  42. it print a different quote each time.  The possibilites are endless.  Enjoy.
  43.  
  44. Jim
  45.  
  46.  
  47. Article 31270 of comp.unix.questions:
  48. Path: arizona!arizona.edu!cerritos.edu!usc!sdd.hp.com!wuarchive!uunet!unisoft!rembo
  49. From: rembo@unisoft.UUCP (Tony Rems)
  50. Newsgroups: comp.unix.questions
  51. Subject: Re: Finger
  52. Message-ID: <3391@unisoft.UUCP>
  53. Date: 22 Feb 91 02:44:17 GMT
  54. References: <37675@netnews.upenn.edu>
  55. Reply-To: rembo@unisoft.UUCP (Tony Rems)
  56. Organization: UniSoft Corporation -- UNIX R Us.
  57. Lines: 254
  58.  
  59. In article <37675@netnews.upenn.edu> minzhi@eniac.seas.upenn.edu (Min-Zhi Shao) writes:
  60. >
  61. >    When I fingered our system administrator, I got the following result:
  62. >
  63. >_________________________________________________________________________
  64. >Login name: gardella              In real life: Ed Gardella [CETS]
  65. >Directory: /home/cets/gardella          Shell: /usr/local/bin/bash
  66. >On since Feb 15 19:49:04 on ttyp1 from TSTEST.SEAS.UPEN
  67. >14 minutes Idle Time
  68. >No unread mail
  69. >Project: System Administrator eniac.seas.upenn.edu
  70. >Plan:
  71. >         Meander about until something interesting comes along.
  72. >
  73. >Office: 154 Moore Building           Work Phone: 898-2491
  74. >                                     Home Phone: 387-4104
  75. >
  76. >I have been fingered 3 times today
  77. >_________________________________________________________________________
  78. >
  79. >the .plan file in his home directory looks like:
  80. >
  81. >prw-r--r--  1 gardella        0 Feb 15 23:48 /home/cets/gardella/.plan
  82. >^
  83.  
  84. As you have found out by now, I'm sure, the p means that this is 
  85. a named pipe aka a FIFO.  If you'd like to do this yourself, here
  86. is a little program I wrote to do it (see the comments at the
  87. the beginning of the plan.c file for usage info):  
  88.  
  89. Here's the shar of my plan program, just cut up until it says
  90. "cut here", and then type 'sh filename' using whatever filename
  91. you save it as.  If you use 'plan' it will get overwritten.
  92.  
  93. The code here should compile w/o any problems on any BSD machine,
  94. I have tried it on a Sun, Vax 750, and Pyramid 90x.  It should
  95. also work properly on any SVR4.0 machine.  
  96.  
  97. The code is pretty heavily commented so it should be self
  98. explanatory.  
  99.  
  100. Note that you should put a -DFILENAME="your_home_dir/.plan"
  101. to get it to put your path in, or you can just edit the 
  102. source and change the value of FILENAME permanently.  
  103.  
  104. If you have any problems getting it compiled, just send me mail.
  105.  
  106. Enjoy.  
  107.  
  108. -Tony
  109.  
  110. -------------------------cut-here------------------------------------
  111. #! /bin/sh
  112. # This is a shell archive.  Remove anything before this line, then unpack
  113. # it by saving it into a file and typing "sh file".  To overwrite existing
  114. # files, type "sh file -c".  You can also feed this as standard input via
  115. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  116. # will see the following message at the end:
  117. #        "End of shell archive."
  118. # Contents:  Makefile plan.c
  119. # Wrapped by rembo@unisoft on Mon Oct  8 10:22:34 1990
  120. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  121. if test -f 'Makefile' -a "${1}" != "-c" ; then 
  122.   echo shar: Will not clobber existing file \"'Makefile'\"
  123. else
  124. echo shar: Extracting \"'Makefile'\" \(1408 characters\)
  125. sed "s/^X//" >'Makefile' <<'END_OF_FILE'
  126. DEST          = /users/eng/rembo/.unisoftbin
  127. X
  128. XEXTHDRS          = /usr/include/fcntl.h \
  129. X        /usr/include/signal.h \
  130. X        /usr/include/stdio.h \
  131. X        /usr/include/sys/fcntl.h \
  132. X        /usr/include/sys/file.h \
  133. X        /usr/include/sys/stat.h \
  134. X        /usr/include/sys/sysmacros.h \
  135. X        /usr/include/sys/sysmacros.h \
  136. X        /usr/include/sys/types.h \
  137. X        /usr/include/sys/types.h
  138. X
  139. HDRS          =
  140. X
  141. LDFLAGS          =
  142. X
  143. LIBS          =
  144. X
  145. LINKER          = cc
  146. X
  147. MAKEFILE      = Makefile
  148. X
  149. OBJS          = plan.o
  150. X
  151. PRINT          = pr
  152. X
  153. PROGRAM          = plan
  154. X
  155. SRCS          = plan.c
  156. X
  157. all:        $(PROGRAM)
  158. X
  159. X$(PROGRAM):     $(OBJS) $(LIBS)
  160. X        @echo -n "Loading $(PROGRAM) ... "
  161. X        @$(LINKER) $(LDFLAGS) $(OBJS) $(LIBS) -o $(PROGRAM)
  162. X        @echo "done"
  163. X
  164. clean:;        @rm -f $(OBJS)
  165. X
  166. depend:;    @mkmf -f $(MAKEFILE) PROGRAM=$(PROGRAM) DEST=$(DEST)
  167. X
  168. index:;        @ctags -wx $(HDRS) $(SRCS)
  169. X
  170. install:    $(PROGRAM)
  171. X        @echo Installing $(PROGRAM) in $(DEST)
  172. X        @install -s $(PROGRAM) $(DEST)
  173. X
  174. print:;        @$(PRINT) $(HDRS) $(SRCS)
  175. X
  176. program:        $(PROGRAM)
  177. X
  178. tags:           $(HDRS) $(SRCS); @ctags $(HDRS) $(SRCS)
  179. X
  180. update:        $(DEST)/$(PROGRAM)
  181. X
  182. X$(DEST)/$(PROGRAM): $(SRCS) $(LIBS) $(HDRS) $(EXTHDRS)
  183. X        @make -f $(MAKEFILE) DEST=$(DEST) install
  184. X###
  185. plan.o: /usr/include/sys/types.h /usr/include/sys/sysmacros.h \
  186. X    /usr/include/sys/sysmacros.h /usr/include/sys/file.h \
  187. X    /usr/include/sys/fcntl.h /usr/include/sys/types.h \
  188. X    /usr/include/fcntl.h /usr/include/stdio.h /usr/include/sys/stat.h \
  189. X    /usr/include/signal.h
  190. END_OF_FILE
  191. if test 1408 -ne `wc -c <'Makefile'`; then
  192.     echo shar: \"'Makefile'\" unpacked with wrong size!
  193. fi
  194. # end of 'Makefile'
  195. fi
  196. if test -f 'plan.c' -a "${1}" != "-c" ; then 
  197.   echo shar: Will not clobber existing file \"'plan.c'\"
  198. else
  199. echo shar: Extracting \"'plan.c'\" \(2197 characters\)
  200. sed "s/^X//" >'plan.c' <<'END_OF_FILE'
  201. X
  202. X/*    THIS IS THE UNPUBLISHED SOURCE CODE OF REMBO        */
  203. X/*    The copyright notice above does not evidence any       */
  204. X/*    actual or intended publication of such source code.    */
  205. X/*    So, use it if you like, but give me credit.        */
  206. X
  207. X
  208. X/*     Usage: plan program_name             */
  209. X
  210. X
  211. X/*    Description:                    */
  212. X
  213. X/*     This program takes the full pathname of an    */
  214. X/*     executable and runs it on a fifo in the     */
  215. X/*    user's home directory named .plan.  This    */
  216. X/*     way, when finger is executed, the output    */
  217. X/*     of the program goes to the fifo.        */
  218. X    
  219. X/*    Written by:  Tony Rems                 */
  220. X
  221. X/*     Send bugs and flames to /dev/null or         */
  222. X/*     rembo@unisoft.com                 */
  223. X
  224. X#include <sys/types.h>
  225. X#include <sys/file.h>
  226. X#include <stdio.h>
  227. X#include <fcntl.h>
  228. X#include <sys/stat.h>
  229. X#include <signal.h>
  230. X
  231. X/* Defines */
  232. X#define FILENAME "/users/eng/rembo/.plan"
  233. X#define PERMS 0666
  234. X#define USAGE "%s program_name\n"
  235. X
  236. X/* Function prototypes */
  237. void sig_handler();
  238. X
  239. main (argc, argv)
  240. int argc;
  241. char *argv[];
  242. X{
  243. X    int fd;
  244. X    int pid;
  245. X    int status;
  246. X
  247. X    if ( argc !=2 ) {
  248. X        fprintf (stderr, USAGE, argv[0]);
  249. X        exit(1);
  250. X    }  /* if */
  251. X
  252. X/* Catch interrupts for cleanup */
  253. X    signal(SIGTERM, sig_handler);
  254. X    signal(SIGINT, sig_handler);
  255. X    signal(SIGHUP, sig_handler);
  256. X
  257. X    unlink (FILENAME);
  258. X
  259. X/* Make the fifo */
  260. X    if ((mknod(FILENAME, S_IFIFO | PERMS, 0)) < 0 ) {
  261. X        perror("mknod");
  262. X        exit(2);
  263. X    }  /* if */
  264. X
  265. X    while (1) {
  266. X        if ((fd = open(FILENAME, O_WRONLY)) < 0 ) {
  267. X            perror("open");
  268. X            exit(3);
  269. X        } /* if */
  270. X
  271. X/* Once our open completes we know that someone else has
  272. X * opened the FIFO for reading, so we can know run our 
  273. X * program on it.  So, we fork, exec our program and
  274. X * wait for the child to complete.
  275. X */
  276. X        switch (pid = fork()) {
  277. X            case -1:
  278. X                perror("fork");
  279. X                exit(4);
  280. X                break;
  281. X            case 0:
  282. X/* If we're in the child, we copy our fifo to stdout */
  283. X/* and exec the program given */
  284. X                dup2(fd, 1);
  285. X                execlp(argv[1],argv[1],(void *)NULL);
  286. X                perror("child returned");
  287. X                exit(5);
  288. X                break;
  289. X            default:
  290. X/* If we're in the parent, we close the pipe and wait */
  291. X                close(fd);
  292. X                while (wait(&status) != pid)
  293. X                    ;
  294. X                break;
  295. X        } /* switch */
  296. X        sleep(2);
  297. X        close(fd);
  298. X    } /* while */
  299. X} /* main */
  300. X
  301. void sig_handler()  /* cleanup */
  302. X{
  303. X    unlink(FILENAME);
  304. X    exit(0);
  305. X}
  306. END_OF_FILE
  307. if test 2197 -ne `wc -c <'plan.c'`; then
  308.     echo shar: \"'plan.c'\" unpacked with wrong size!
  309. fi
  310. # end of 'plan.c'
  311. fi
  312. echo shar: End of shell archive.
  313. exit 0
  314.  
  315.  
  316.  
  317.