home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / 3b1 / volume02 / email / part01 < prev    next >
Encoding:
Internet Message Format  |  1992-07-20  |  12.2 KB

  1. Path: comp-sources-3b1
  2. From: dave@galaxia.network23.com (David H. Brierley)
  3. Subject:  v02i023:  pcmgr/smgr e-mail interface program for the 3b1, Part01/01
  4. Newsgroups: comp.sources.3b1
  5. Approved: dave@galaxia.network23.com
  6. X-Checksum-Snefru: 25c053ba f9b71d9c 75348848 07f5fd23
  7.  
  8. Submitted-by: dave@galaxia.network23.com (David H. Brierley)
  9. Posting-number: Volume 2, Issue 23
  10. Archive-name: email/part01
  11.  
  12. This is the README file for the Dave Brierley collection of miscellaneous
  13. source programs.  The collection is posted in seven separate pieces but
  14. all of the source came from the "misc" directory on my machine.  As a result
  15. of this, there is only one README file and only one Makefile, although each
  16. of the seven postings will contain a copy of these two files.  I suggest
  17. that you obtain (or save) as many of these postings as you are interested
  18. in, unpack them all in a single directory, and then compile the sources.
  19. Note that some of the programs are actually shell scripts and therefore do
  20. not need compilation.
  21.  
  22. email.c
  23.  A version of the "email" program.  This program should be installed as
  24.  /usr/bin/email and it will be used by pcmgr (or by smgr) when you click
  25.  on the envelope icon.  It provides a safe interface to the mail program
  26.  by making sure the uid is set correctly and by doing a chdir to the
  27.  users home directory (both of which are already being done by pcmgr).
  28.  This version also provides a unique feature of reading an "rc" file
  29.  from the users home directory (~/.email.rc), which can be used to specify
  30.  what mail program to use.  See the sample provided.
  31.  
  32. email.rc
  33.  Sample .email.rc file.
  34.  
  35. #! /bin/sh
  36. # This is a shell archive.  Remove anything before this line, then unpack
  37. # it by saving it into a file and typing "sh file".  To overwrite existing
  38. # files, type "sh file -c".  You can also feed this as standard input via
  39. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  40. # will see the following message at the end:
  41. #        "End of archive 1 (of 1)."
  42. # Contents:  MANIFEST Makefile README email.c email.rc
  43. # Wrapped by dave@galaxia on Tue Jul 21 10:54:09 1992
  44. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  45. if test -f 'MANIFEST' -a "${1}" != "-c" ; then 
  46.   echo shar: Will not clobber existing file \"'MANIFEST'\"
  47. else
  48. echo shar: Extracting \"'MANIFEST'\" \(251 characters\)
  49. sed "s/^X//" >'MANIFEST' <<'END_OF_FILE'
  50. X   File Name        Archive #    Description
  51. X-----------------------------------------------------------
  52. X MANIFEST                   1    
  53. X Makefile                   1    
  54. X README                     1    
  55. X email.c                    1    
  56. X email.rc                   1    
  57. END_OF_FILE
  58. if test 251 -ne `wc -c <'MANIFEST'`; then
  59.     echo shar: \"'MANIFEST'\" unpacked with wrong size!
  60. fi
  61. # end of 'MANIFEST'
  62. fi
  63. if test -f 'Makefile' -a "${1}" != "-c" ; then 
  64.   echo shar: Will not clobber existing file \"'Makefile'\"
  65. else
  66. echo shar: Extracting \"'Makefile'\" \(374 characters\)
  67. sed "s/^X//" >'Makefile' <<'END_OF_FILE'
  68. XCFLAGS    = -O
  69. X
  70. Xall:        bsdln disktest email ndf techo wclipper
  71. X
  72. Xbsdln:        bsdln.o
  73. X        $(CC) bsdln.o
  74. X        mv a.out bsdln
  75. X
  76. Xdisktest:    disktest.o
  77. X        $(CC) disktest.o
  78. X        mv a.out disktest
  79. X
  80. Xemail:        email.o
  81. X        $(CC) email.o
  82. X        mv a.out email
  83. X
  84. Xndf:        ndf.o
  85. X        $(CC) ndf.o
  86. X        mv a.out ndf
  87. X
  88. Xtecho:        techo.o
  89. X        $(CC) techo.o
  90. X        mv a.out techo
  91. X
  92. Xwclipper:    wclipper.o
  93. X        $(CC) wclipper.o
  94. X        mv a.out wclipper
  95. X
  96. END_OF_FILE
  97. if test 374 -ne `wc -c <'Makefile'`; then
  98.     echo shar: \"'Makefile'\" unpacked with wrong size!
  99. fi
  100. # end of 'Makefile'
  101. fi
  102. if test -f 'README' -a "${1}" != "-c" ; then 
  103.   echo shar: Will not clobber existing file \"'README'\"
  104. else
  105. echo shar: Extracting \"'README'\" \(4280 characters\)
  106. sed "s/^X//" >'README' <<'END_OF_FILE'
  107. XThis is the README file for the Dave Brierley collection of miscellaneous
  108. Xsource programs.  The collection is posted in seven separate pieces but
  109. Xall of the source came from the "misc" directory on my machine.  As a result
  110. Xof this, there is only one README file and only one Makefile, although each
  111. Xof the seven postings will contain a copy of these two files.  I suggest
  112. Xthat you obtain (or save) as many of these postings as you are interested
  113. Xin, unpack them all in a single directory, and then compile the sources.
  114. XNote that some of the programs are actually shell scripts and therefore do
  115. Xnot need compilation.
  116. X
  117. XINSTALLATION INSTRUCTIONS:
  118. X1. Compile all the source programs by typing "make all".  Edit the Makefile
  119. X   if you did not unpack all seven of the pieces.  Note that the Makefile
  120. X   does not contain explicit commands for using the shared library.  I always
  121. X   depend on "ccc" to do this for me.
  122. X2. Copy the resultant executables to your favorite bin directory.  I always
  123. X   use "/usr/local/bin".
  124. X3. Copy the various shell scripts to the bin directory and make then executable
  125. X   using the chmod command.  The shell scripts are all distributed with a
  126. X   suffix of ".sh".  I suggest you remove this suffix when you install it, but
  127. X   that is entirely up to you.
  128. X
  129. X
  130. XDescription of programs included in this package.  There is a line of dashes
  131. Xseparating each of the seven pieces.
  132. X
  133. Xbsdln.c
  134. X A version of the ln command that follows the BSD behaviour.  I.e. if the
  135. X target file exists, the command will fail.  The standard 3b1 version will
  136. X remove the target.
  137. X
  138. X--------------------------------------------------------------------------
  139. X
  140. Xinstall.sh
  141. X A shell script version of the BSD install command.
  142. X
  143. Xnull.sh
  144. X Zero out one or more files.
  145. X
  146. Xtolower.sh
  147. X Convert file names to lower case.  Requires ksh.
  148. X
  149. Xtoupper.sh
  150. X Convert file names to upper case.  Requires ksh.
  151. X
  152. X--------------------------------------------------------------------------
  153. X
  154. Xndf.c
  155. X Almost emulates the BSD df command.  I say "almost" because I chose to
  156. X display the numbers in terms of blocks instead of kbytes since everything
  157. X else on the machine displays sizes in blocks.  Supports the "-i" option
  158. X to displays inode information.  Also supports specifying any random
  159. X directory as an argument and it will figure out what file system it is.
  160. X
  161. X--------------------------------------------------------------------------
  162. X
  163. Xdisktest.c
  164. X A program used by the format script to test the floppy disk to be doubly
  165. X sure that it is usable.
  166. X
  167. Xformat.sh
  168. X Format a floppy disk.  Asks questions to determine desired parameters, such
  169. X as number of cylinders and number of sectors.  Will optionally run an
  170. X intensive surface test of the floppy (see disktest.c), build a file system
  171. X structure, and make the floppy bootable.  The main processing is done in a
  172. X loop so you can format multiple floppies easily.
  173. X
  174. Xnewfs.sh
  175. X Reads the VHB from the floppy and then builds a file system structure on it.
  176. X
  177. X--------------------------------------------------------------------------
  178. X
  179. Xtecho.c
  180. X A version of echo that allows direct access to termcap capabilities.  A lot
  181. X easier to use than intermixing calls to echo with calls to tput.
  182. X
  183. Xtecho.1
  184. X Hey, I actually wrote a man page for this one!
  185. X
  186. X--------------------------------------------------------------------------
  187. X
  188. Xwclipper.c
  189. X A program to read in the wtmp file and output the tail end of it.  Useful
  190. X if you want to maintain an N-day history of who has been using your system.
  191. X The output size can be specified in terms of days or kbytes.
  192. X
  193. Xwtmp.fix.sh
  194. X A shell script to control the operation of wclipper.
  195. X
  196. X--------------------------------------------------------------------------
  197. X
  198. Xemail.c
  199. X A version of the "email" program.  This program should be installed as
  200. X /usr/bin/email and it will be used by pcmgr (or by smgr) when you click
  201. X on the envelope icon.  It provides a safe interface to the mail program
  202. X by making sure the uid is set correctly and by doing a chdir to the
  203. X users home directory (both of which are already being done by pcmgr).
  204. X This version also provides a unique feature of reading an "rc" file
  205. X from the users home directory (~/.email.rc), which can be used to specify
  206. X what mail program to use.  See the sample provided.
  207. X
  208. Xemail.rc
  209. X Sample .email.rc file.
  210. END_OF_FILE
  211. if test 4280 -ne `wc -c <'README'`; then
  212.     echo shar: \"'README'\" unpacked with wrong size!
  213. fi
  214. # end of 'README'
  215. fi
  216. if test -f 'email.c' -a "${1}" != "-c" ; then 
  217.   echo shar: Will not clobber existing file \"'email.c'\"
  218. else
  219. echo shar: Extracting \"'email.c'\" \(2781 characters\)
  220. sed "s/^X//" >'email.c' <<'END_OF_FILE'
  221. X#include <stdio.h>
  222. X#include <pwd.h>
  223. X#include <string.h>
  224. X
  225. X#ifndef    MAILER
  226. X# define MAILER    "elm"
  227. X#endif
  228. X
  229. X#define MAXARGS        32
  230. X
  231. Xvoid            check_rc ();
  232. Xvoid            exit ();
  233. Xchar           *malloc ();
  234. Xvoid            perror ();
  235. Xunsigned        sleep ();
  236. X
  237. Xmain (argc, argv)
  238. Xint             argc;
  239. Xchar           *argv[];
  240. X{
  241. X    struct passwd  *getpwnam ();
  242. X    struct passwd  *pwd;
  243. X    int             c;
  244. X    int             errflg;
  245. X    char           *username;
  246. X    char            home[BUFSIZ];
  247. X    char           *mailer[MAXARGS];
  248. X    extern int      optind;
  249. X    extern char    *optarg;
  250. X
  251. X    errflg = 0;
  252. X    username = NULL;
  253. X
  254. X    while ((c = getopt (argc, argv, "iu:")) != EOF)
  255. X    switch (c) {
  256. X    case 'i':
  257. X        break;
  258. X    case 'u':
  259. X        username = optarg;
  260. X        break;
  261. X    case '?':
  262. X        errflg++;
  263. X        break;
  264. X    }
  265. X
  266. X    if (errflg || (username == NULL)) {
  267. X    (void) fprintf (stderr, "usage: email -i -u username\n");
  268. X    (void) sleep (30);
  269. X    exit (2);
  270. X    }
  271. X
  272. X    if ((pwd = getpwnam (username)) == NULL) {
  273. X    (void) fprintf (stderr, "email: unknown username %s\n", username);
  274. X    (void) sleep (30);
  275. X    exit (3);
  276. X    }
  277. X
  278. X    (void) setgid (pwd -> pw_gid);
  279. X    (void) setuid (pwd -> pw_uid);
  280. X    (void) umask (077);        /* better to be overly secure */
  281. X
  282. X    (void) strcpy (home, "HOME=");
  283. X    (void) strcat (home, pwd -> pw_dir);
  284. X    (void) putenv (home);
  285. X
  286. X    (void) chdir (pwd -> pw_dir);
  287. X    mailer[0] = MAILER;
  288. X    mailer[1] = NULL;
  289. X
  290. X    check_rc (mailer);
  291. X
  292. X    (void) execvp (mailer[0], mailer);
  293. X
  294. X    /* NOTREACHED */
  295. X    return (0);
  296. X
  297. X}
  298. X
  299. Xvoid
  300. Xcheck_rc (mailer)
  301. Xchar           *mailer[];
  302. X{
  303. X    FILE           *rc;
  304. X    static char     buffer[BUFSIZ];
  305. X    auto char      *value;
  306. X    auto char      *blank;
  307. X    int             newmask;
  308. X    int             argc;
  309. X
  310. X    if ((rc = fopen (".email.rc", "r")) == NULL) {
  311. X    return;
  312. X    }
  313. X
  314. X    while (fgets (buffer, BUFSIZ, rc) != NULL) {
  315. X    buffer[strlen (buffer) - 1] = '\0';
  316. X    if ((blank = strchr (buffer, ' ')) != NULL) {
  317. X        *blank++ = '\0';
  318. X    }
  319. X    if (strcmp (buffer, "mailer") == 0) {
  320. X        argc = 0;
  321. X        while (blank != NULL) {
  322. X        value = blank;
  323. X        while (*value == ' ') {
  324. X            ++value;
  325. X        }
  326. X        if ((blank = strchr (value, ' ')) != NULL) {
  327. X            *blank++ = '\0';
  328. X        }
  329. X        mailer[argc] = malloc ((unsigned) (strlen (value) + 1));
  330. X        if (mailer[argc] == NULL) {
  331. X            perror ("email");
  332. X            (void) fprintf (stderr, "Unable to allocate memory\n");
  333. X            exit (1);
  334. X        }
  335. X        (void) strcpy (mailer[argc], value);
  336. X        argc++;
  337. X        }
  338. X        mailer[argc] = NULL;
  339. X        continue;
  340. X    }
  341. X    if (strcmp (buffer, "umask") == 0) {
  342. X        if (sscanf (blank, "%o", &newmask) == 1) {
  343. X        (void) umask (newmask);
  344. X        }
  345. X        continue;
  346. X    }
  347. X    if (strcmp (buffer, "stty") == 0) {
  348. X        if (blank != NULL) {
  349. X        *--blank = ' ';
  350. X        }
  351. X        (void) system (buffer);
  352. X        continue;
  353. X    }
  354. X    }
  355. X
  356. X    (void) fclose (rc);
  357. X
  358. X}
  359. END_OF_FILE
  360. if test 2781 -ne `wc -c <'email.c'`; then
  361.     echo shar: \"'email.c'\" unpacked with wrong size!
  362. fi
  363. # end of 'email.c'
  364. fi
  365. if test -f 'email.rc' -a "${1}" != "-c" ; then 
  366.   echo shar: Will not clobber existing file \"'email.rc'\"
  367. else
  368. echo shar: Extracting \"'email.rc'\" \(70 characters\)
  369. sed "s/^X//" >'email.rc' <<'END_OF_FILE'
  370. Xstty erase ^H intr ^? kill ^U
  371. Xmailer /usr/local/bin/mush -C
  372. Xumask 077
  373. END_OF_FILE
  374. if test 70 -ne `wc -c <'email.rc'`; then
  375.     echo shar: \"'email.rc'\" unpacked with wrong size!
  376. fi
  377. # end of 'email.rc'
  378. fi
  379. echo shar: End of archive 1 \(of 1\).
  380. cp /dev/null ark1isdone
  381. MISSING=""
  382. for I in 1 ; do
  383.     if test ! -f ark${I}isdone ; then
  384.     MISSING="${MISSING} ${I}"
  385.     fi
  386. done
  387. if test "${MISSING}" = "" ; then
  388.     echo You have the archive.
  389.     rm -f ark[1-9]isdone
  390. else
  391.     echo You still need to unpack the following archives:
  392.     echo "        " ${MISSING}
  393. fi
  394. ##  End of shell archive.
  395. exit 0
  396. -- 
  397. David H. Brierley
  398. Home: dave@galaxia.network23.com; Work: dhb@quahog.ssd.ray.com
  399. Send comp.sources.3b1 submissions to comp-sources-3b1@galaxia.network23.com
  400. %% Can I be excused, my brain is full. **
  401.