home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume26 / psimail / part02 < prev    next >
Encoding:
Text File  |  1991-11-20  |  27.4 KB  |  772 lines

  1. Newsgroups: comp.sources.misc
  2. From: A.Raman@massey.ac.nz ("Anand")
  3. Subject:  v26i035:  psimail - UNIX-VMS PSI Mailer, Part02/02
  4. Message-ID: <1991Nov20.235023.15547@sparky.imd.sterling.com>
  5. X-Md4-Signature: 9788826c27c485b8e5d8fcfdbdb2c292
  6. Date: Wed, 20 Nov 1991 23:50:23 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: A.Raman@massey.ac.nz ("Anand")
  10. Posting-number: Volume 26, Issue 35
  11. Archive-name: psimail/part02
  12. Environment: UNIX
  13.  
  14. #! /bin/sh
  15. # into a shell via "sh file" or similar.  To overwrite existing files,
  16. # type "sh file -c".
  17. # The tool that generated this appeared in the comp.sources.unix newsgroup;
  18. # send mail to comp-sources-unix@uunet.uu.net if you want that tool.
  19. # Contents:  psimail/README psimail/debugmsg.c psimail/str.c
  20. #   psimail/str.h
  21. # Wrapped by kent@sparky on Tue Nov 12 22:43:54 1991
  22. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  23. echo If this archive is complete, you will see the following message:
  24. echo '          "shar: End of archive 2 (of 2)."'
  25. if test -f 'psimail/README' -a "${1}" != "-c" ; then 
  26.   echo shar: Will not clobber existing file \"'psimail/README'\"
  27. else
  28.   echo shar: Extracting \"'psimail/README'\" \(13111 characters\)
  29.   sed "s/^X//" >'psimail/README' <<'END_OF_FILE'
  30. X----------------------------------------------------------------------------
  31. X Copyright (c) 1991 Computing Services, Massey University,
  32. X Palmerston North, New Zealand
  33. X All rights reserved.
  34. X
  35. X Redistribution and use in source and binary forms, with or without
  36. X modification, are permitted provided that the following conditions
  37. X are met:
  38. X 1. Redistributions of source code must retain the above copyright
  39. X    notice, this list of conditions and the following disclaimer.
  40. X 2. Redistributions in binary form must reproduce the above copyright
  41. X    notice, this list of conditions and the following disclaimer in the
  42. X    documentation and/or other materials provided with the distribution.
  43. X 3. All advertising materials mentioning features or use of this software
  44. X    must display the following acknowledgement:
  45. X       This product includes software developed by the Systems Software
  46. X       Support Group, Computing Services, Massey University,
  47. X       Palmerston North, NZ.
  48. X 4. The name of Massey University may not be used to endorse or promote
  49. X    products derived from this software without specific prior written
  50. X    permission.
  51. X
  52. X THIS SOFTWARE IS PROVIDED BY COMPUTING SERVICES, MASSEY UNIVERSITY
  53. X `AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  54. X TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  55. X PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL MASSEY UNIVERSITY BE
  56. X LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  57. X CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  58. X SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  59. X INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  60. X CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  61. X ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  62. X POSSIBILITY OF SUCH DAMAGE.
  63. X
  64. X----------------------------------------------------------------------------
  65. X                Introduction:
  66. X                ~~~~~~~~~~~~~
  67. X
  68. XThis package contains the files necessary to make the two binaries:
  69. XSendpsimail and Recvpsimail.
  70. X
  71. XThese programs enable a UNIX machine to communicate via  email with Mail
  72. Xservers running  PSI_MAILSHR.   In  most  situations these   are VAX/VMS
  73. Xmachines.  The medium of   transfer is x.25   and the  protocol  used is
  74. XMAIL-11.
  75. X
  76. XThey have specific relevance to the Pyramid implementation of x.25 (1980)
  77. Xalthough a hack to port on other platforms should not  be  too difficult.
  78. XI will be happy to assist in a port to Sunlink x.25 if necessary.
  79. X
  80. XAfter unpacking, you should find the following files:
  81. X
  82. X1. README
  83. X2. Makefile
  84. X3. sendpsimail.c
  85. X4. recvpsimail.c
  86. X5. debugmsg.c
  87. X6. str.c
  88. X7. str.h
  89. X
  90. X`Make' should compile and lint without complaining  on a Pyramid.    You
  91. Xmay initially  want to run  the modules in  debug mode for   a couple of
  92. Xdays.  To do so, just uncomment the DEBUG definition on the CFLAGS line.
  93. XIf your /tmp directory is zonked by cron each night,  you'd also have to
  94. Xchange the definition of DEBUGDIR so you don't lose debug  data gathered
  95. Xovernight.  Each debug file will have an entire transaction  between the
  96. Xlocal host and the remote PSI site.
  97. X
  98. XAlso, you might want   to alter the   destination  and the  name  of the
  99. Xmailer.  The Sendmail example   given  later in  this document  uses the
  100. Xmailer   name `psi',  so if you  change the  mailer name,  make sure you
  101. Xuse that name for the Mailer definition in your sendmail.cf.
  102. X
  103. XIf the cpp symbol USER2ALIAS is defined, the mailer will assume that the
  104. Xmail  alias  of the user  is the same as  his/her/its user code.  If you
  105. Xhave a function that does a translation from the usercode  to the user's
  106. Xmail alias link in your own function called user2alias() that includes a
  107. Xcall to it.  Also comment out  the USER2ALIAS on  the  DEFs line so that
  108. Xthe dummy user2alias() provided will not be used.
  109. X
  110. XThe syntax for the user2alias function is:
  111. X
  112. Xchar *user2alias(u)
  113. X
  114. XIt should return the mail alias for the specified user `u.'  At the very
  115. Xleast,  it should return `u' itself,  like the dummy   one in the mailer
  116. Xdoes.  It  should also return `u' if  an alias search for  the specified
  117. Xuser failed.
  118. X
  119. XCheers!
  120. X
  121. X- venkataraman anand, November 1991        (A.Raman@massey.ac.nz)
  122. X                        (6300006412::A.Raman)
  123. X
  124. X
  125. X              Acknowledgements:
  126. X              ~~~~~~~~~~~~~~~~~
  127. X
  128. XPeter   Kay of  the   Computer  Science  department,  Massey  University
  129. Xconceived this project and we chose to design and implement it as a part
  130. Xof an  Honors  project in  Computer  Science 1991.   Thanks   are due to
  131. XG.Eustace@massey.ac.nz, (Glen Eustace) for suggestions  on improving the
  132. Xuser  interface,  bgg@pta.pyramid.com.au   (Ben  Golding)  for   helping
  133. Xidentify a problem   with Sendpsimail occasionally  dumping   core on  a
  134. XSIGPROF signal, K.Spagnolo@massey.ac.nz (Ken  Spagnolo) for helpful tips
  135. Xabout Sendmail and  J.Waters@massey.ac.nz  (Joyce Waters)  for  her  VMS
  136. Xaccount that  I borrowed to  test out intermediate   and final stages of
  137. Xthis project.
  138. X
  139. X                   
  140. X         How Incoming and Outgoing mail are treated:
  141. X         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  142. X
  143. XIncoming PSI-MAIL  is received  through an x.25  sub address.   This was
  144. Xbecause the Pyramid was found to ignore the user data  field of incoming
  145. Xx.25 call request packets and  the conventional method  of selecting the
  146. XPSI-MAIL service is via a special user data field.
  147. X
  148. XOutgoing PSI mail is  sent  by connecting to  each of the specified x.25
  149. Xnodes in sequence and  delivering the message to all  users on that node
  150. Xin the same transaction.  The way to send mail to a  PSI site is  to use
  151. Xan address of the form XXXXXXXX::User@psi-gateway.domain, where XXXXXXXX
  152. Xis the x.25  address of the node.   For example,   I  can be  reached at
  153. X6300006412::A.Raman@psi-gateway.massey.ac.nz,  (It might be cheaper   to
  154. Xreach me at A.Raman@massey.ac.nz, see "Charging Users for PSIMAIL usage")
  155. X
  156. XBoth x.25 and Sendmail can be configured differently, however, to receive
  157. Xand  send mail in   any other fashion  than has  been  suggested in this
  158. Xdocument.
  159. X
  160. X                   
  161. X           Recvpsimail and the x.25 configuration:
  162. X           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  163. X                   
  164. XRecvpsimail is the program that receives PSI mail.  If you are running a
  165. Xlater verison  of the  x.25 implementation,  and  it allows selection of
  166. Xservices based on the  user-data field of  the call request  packet, you
  167. Xmay choose to  configure the x.25 differently.   Generally, x25d must be
  168. Xsetup  so  that Recvpsimail is activated  if  an incoming   call request
  169. Xpacket contains the following user data field:
  170. X
  171. X{ '\377',  '\0',  '\0',  '\0',
  172. X  'V',     '3',   '.',    '0',
  173. X  ' ',     'M',   'A',    'I',   'L',   '-',   '1',   '1' }
  174. X
  175. XIf you choose to stick to the  method of sub-addresses used  in here, it
  176. Xshould still  work, but you will have  to  dedicate an  x.25 sub-address
  177. Xfor the purpose of receiving PSI mail.
  178. X
  179. X
  180. X              Example x25 configuration:
  181. X              ~~~~~~~~~~~~~~~~~~~~~~~~~~
  182. X
  183. X
  184. XOn the Pyramid the  file /usr/spool/x25/x25d.action needs to be changed.
  185. XInclude the line:
  186. X
  187. XXX 0 0 /usr/x25/x25subXX
  188. X
  189. Xwhere XX is the subaddress at which you want to receive PSI-MAIL.
  190. X
  191. XYour /usr/x25/x25subXX should probably look like this:
  192. X
  193. X> #! /bin/sh
  194. X> ucb su $USER -c "/usr/local/etc/recvpsimail $* \
  195. X>     2>/usr/local/etc/recvpsimail.errors"
  196. X
  197. X                   
  198. X         Sendpsimail and the Sendmail configuration:
  199. X         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  200. X
  201. XSendpsimail is  the mailer  program.  Ideally, it  is called by Sendmail
  202. Xwhen Sendmail recognizes an address of the form %s@psi-gateway.  Such an
  203. Xaddress selects the PSI mailer and passes the string defined by  %s as a
  204. Xcommand line argument   to it.   Sendpsimail is  designed to connect  to
  205. Xmultiple  nodes in one invocation.   But Sendmail can  be set up so that
  206. XSendpsimail is called separately for each destination address.
  207. X
  208. XThe first thing that Sendpsimail  does upon startup is  try to determine
  209. Xthe username of the caller from the uid of the calling program.  In most
  210. Xinstances when Sendmail runs setuid to caller, the  username is resolved
  211. Xcorrectly.   However, the sendername  is always reset from the  "From: "
  212. Xline of the mail message.  In the rare  situation  when the mail message
  213. Xdoes not contain a "From: " line, Sendpsimail would  send the message as
  214. Xthough it originated from the caller of the mailing  program.  In such a
  215. Xcase, if Sendmail was not running setuid to caller, the message could be
  216. Xsent  out as `root.'  There is  a  still more  important reason  to have
  217. XSendmail running  setuid  to caller.  That  will be discussed under  the
  218. Xsection - Charging users for PSIMAIL usage.
  219. X
  220. X                   
  221. X              Sendpsimail Exit statuses
  222. X              ~~~~~~~~~~~~~~~~~~~~~~~~~
  223. X
  224. XIf all its connections failed, then Sendpsimail does not inform the user
  225. Xand exits with the   status EX_TEMPFAIL  [See include  file sysexits.h.]
  226. XEX_TEMPFAIL is  a  signal to  Sendmail to  try  to  resend the  message.
  227. XSendmail will continue to try for a predetermined number of times before
  228. Xgiving  up.  If some  but  not all connection attempts  succeeded,  then
  229. XSendpsimail must not exit  with EX_TEMPFAIL.  That  would cause it to be
  230. Xinvoked with the same argument list once again  resulting in a duplicate
  231. Xmessage to  the destination   user for whom transmission  succeeded  the
  232. Xfirst   time.   In  that  case,    Sendpsimail  exits   with the  status
  233. XEX_SOFTWARE.  This causes Sendmail to return the message to the Sender.
  234. XIn such a case, Sendpsimail also mails  the sender giving  him a list of
  235. Xthe destination nodes to which it failed to connect.  So the  sender can
  236. Xresend  the message only  to those nodes to which  Sendpsimail could not
  237. Xconnect. 
  238. X
  239. XSome postmasters are fussy  about  the verbosity of mailers.  They might
  240. Xnot like the  mailing system to  send the user  two messages   for every
  241. Xpartial success. (One  from Sendmail returning  the unsent  message, the
  242. Xother from Sendpsimail showing which nodes it  couldn't connect to) Such
  243. Xpostmasters can configure  Sendmail  to invoke Sendpsimail  uniquely for
  244. Xeach destination address.  This  will ensure that  there are  no partial
  245. Xfailures.
  246. X
  247. X                   
  248. X            Example Sendmail Configuration
  249. X            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  250. X
  251. XThe following is  an  extract from a sendmail.cf that  shows the sort of
  252. Xchanges that might be necessary.
  253. X
  254. X---
  255. X.
  256. X.
  257. X.
  258. X#
  259. X# Define the PSI Mailer
  260. X#
  261. X
  262. XMpsi, P=/usr/local/mail/mailers/sendpsimail, F=FnDlMuL, S=0, R=0,
  263. X        A=sendpsimail $u
  264. X.
  265. X.
  266. X.
  267. X
  268. X# Include the following in Ruleset 3
  269. X# Chop off domains. `D' must be defined locally by you.  For example,
  270. X# here at Massey, we have
  271. X# CD massey massey.ac massey.ac.nz cc-server1
  272. X# under domain definitions
  273. X
  274. XR$+@psi-gateway.$=D            $@$1@psi-gateway
  275. X.
  276. X.
  277. X.
  278. X
  279. X# Include the following line in Ruleset 0.
  280. X# Calls the Mailer for matching addresses
  281. X
  282. XR$+@psi-gateway                $#psi$:$1                     user@psiaddr
  283. X
  284. X---
  285. X                   
  286. X             Charging for PSI MAIL usage:
  287. X             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  288. X
  289. XPSI mail, unlike SMTP generates a real charge.  X.25 usage is charged by
  290. XTelecom under  two categories:  Duration and Volume.   Luckily, the X.25
  291. Xserver on the system provides a convenient means of transferring charges
  292. Xto  users.  An  ascii account file  is created listing  the duration and
  293. Xnumber  of packets transferred  for the user that  made  the connection.
  294. XShould  Sendmail be   run  setuid  to  root,   then each  outgoing  mail
  295. Xconnection will be  made by  Sendpsimail invoked as `root'.    This will
  296. Xresult in the X.25 charges debited to `root' and the postmaster will end
  297. Xup  paying for all the  outgoing  PSI mail.    The  solution is  to  run
  298. XSendmail  setuid  to the caller.   This will cause  the  X.25  server to
  299. Xgenerate an accounting entry for the  user  and enable the postmaster to
  300. Xpass the charges on to him.
  301. X
  302. X                    
  303. X              KNOWN BUGS AND SHORTCOMINGS
  304. X              ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  305. X
  306. XSendpsimail mysteriously   dies   upon   receiving  a   SIGPROF   signal
  307. Xoccasionally.  It  has been  observed to occur whenever  Sendpsimail and
  308. XRecvpsimail   are active at the same   time although we cannot establish
  309. Xthat it has never occurred  when Sendpsimail  has been active by itself.
  310. XBen Golding of Pyramid  Computer  Pty Ltd,  Sydney, helped  in narrowing
  311. Xdown the  problem to a possible bug  in the  x.25 implementation  on the
  312. XPyramid (1980 version). The include file  /usr/src/x25.h  shows that the
  313. Ximplementation uses signal 27 to signal an incoming call.  Now signal 27
  314. Xis the same as SIGPROF which if not intercepted could cause a core dump.
  315. XThis   problem has been   patched  up temporarily  by  trapping  SIGPROF
  316. Xin  Sendpsimail  and   tying    it  to  a  do-nothing function.   A more
  317. Xsatisfactory solution to this problem would be nice. 
  318. X
  319. XIt would be nice to have a dbm database of x25  addresses and Node names
  320. Xfor Sendmail.  Then the user will not have to remember the x25 addresses
  321. Xof each node that mail must be sent to. An address would be  of the form
  322. XNodename::user instead of Nodenumber::user.  To  reach someone at massey
  323. Xvia  PSIMAIL  for    example, a  user     would   just  have    to  type
  324. XMassey::User@psi-gateway and not  6300006412::User@psi-gateway. 
  325. X
  326. END_OF_FILE
  327.   if test 13111 -ne `wc -c <'psimail/README'`; then
  328.     echo shar: \"'psimail/README'\" unpacked with wrong size!
  329.   fi
  330.   # end of 'psimail/README'
  331. fi
  332. if test -f 'psimail/debugmsg.c' -a "${1}" != "-c" ; then 
  333.   echo shar: Will not clobber existing file \"'psimail/debugmsg.c'\"
  334. else
  335.   echo shar: Extracting \"'psimail/debugmsg.c'\" \(4347 characters\)
  336.   sed "s/^X//" >'psimail/debugmsg.c' <<'END_OF_FILE'
  337. X#ifndef lint
  338. X   static char rcsid[] ="$Id: debugmsg.c version 1.0";
  339. X#endif
  340. X/*
  341. X * $Log debugmsg.c,v $
  342. X * debug module for the psi mailer
  343. X * anand
  344. X */
  345. X/*
  346. X * Copyright (c) 1991 Computing Services, Massey University,
  347. X * Palmerston North, New Zealand
  348. X * All rights reserved.
  349. X *
  350. X * Redistribution and use in source and binary forms, with or without
  351. X * modification, are permitted provided that the following conditions
  352. X * are met:
  353. X * 1. Redistributions of source code must retain the above copyright
  354. X *    notice, this list of conditions and the following disclaimer.
  355. X * 2. Redistributions in binary form must reproduce the above copyright
  356. X *    notice, this list of conditions and the following disclaimer in the
  357. X *    documentation and/or other materials provided with the distribution.
  358. X * 3. All advertising materials mentioning features or use of this software
  359. X *    must display the following acknowledgement:
  360. X *       This product includes software developed by the Systems Software
  361. X *       Support Group, Computing Services, Massey University,
  362. X *       Palmerston North, NZ.
  363. X * 4. The name of Massey University may not be used to endorse or promote
  364. X *    products derived from this software without specific prior written
  365. X *    permission.
  366. X *
  367. X * THIS SOFTWARE IS PROVIDED BY COMPUTING SERVICES, MASSEY UNIVERSITY
  368. X * `AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  369. X * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  370. X * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL SMIS, MASSEY UNIVERSITY BE
  371. X * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  372. X * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  373. X * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  374. X * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  375. X * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  376. X * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  377. X * POSSIBILITY OF SUCH DAMAGE.
  378. X */
  379. X
  380. X#ifdef DEBUG
  381. X
  382. X#include <stdio.h>
  383. X#include <ctype.h>   
  384. X#include <fcntl.h>
  385. X#include <strings.h>   
  386. X#include <sys/types.h>
  387. X#include <sys/stat.h>   
  388. X#include <sys/syslog.h>
  389. X   
  390. X#ifndef DEBUGDIR
  391. X# define DEBUGDIR "/tmp"    /* Where to create debug files */
  392. X#endif
  393. X
  394. Xdebugmsg(fdd, s)
  395. Xint fdd;
  396. Xchar *s;
  397. X{
  398. X   (void) write(fdd,s,strlen(s));
  399. X   (void) write(fdd,"\n",1);
  400. X}
  401. X
  402. X/*
  403. X * xdebugmsg() prints c bytes of s in DOS debug style
  404. X */
  405. Xxdebugmsg(fdd, s,c)
  406. Xu_char *s;
  407. Xint c;
  408. X{
  409. X   int i = 0, nlines = 0;
  410. X   char ascbuf[32], *ap = ascbuf;
  411. X   char buf[80], temp[16];
  412. X   long count = 0L;
  413. X
  414. X   ascbuf[0] = buf[0] = '\0';
  415. X   while (c--) {
  416. X      if (*s <= 127 && isprint(*s))
  417. X     *ap++ = *s;
  418. X      else
  419. X     *ap++ = '.';
  420. X      (void) sprintf(temp, "%02x ", (unsigned) *s & 0xff);
  421. X      (void) strcat(buf, temp);
  422. X      switch(++i) {
  423. X      case 8:
  424. X     (void) strcat(buf, "- ");
  425. X     break;
  426. X      case 16:
  427. X     i = 0;
  428. X     *ap = '\0';
  429. X     (void) strcat(buf, " ");
  430. X     (void) strcat(buf, ascbuf);
  431. X     (void) strcat(buf, "\n");
  432. X     (void) sprintf(temp, "%04X: ", count);
  433. X     (void) write(fdd, temp, strlen(temp));
  434. X     (void) write(fdd, buf, strlen(buf));
  435. X     if (++nlines >= 8) {
  436. X        nlines = 0;
  437. X        (void) write(fdd, "\n", 1);
  438. X     }
  439. X     ascbuf[0] = buf[0] = '\0';
  440. X     count += 16;
  441. X     ap = ascbuf;
  442. X     break;
  443. X      default:
  444. X     break;
  445. X      }
  446. X      ++s;
  447. X   }
  448. X   if (ap == ascbuf)
  449. X      return;
  450. X   *ap = '\0';
  451. X   while (i++ < 16) {
  452. X      (void) strcat(buf, "   ");
  453. X      if (i == 8)
  454. X     (void) strcat(buf, "  ");
  455. X   }
  456. X   (void) strcat(buf, " ");
  457. X   (void) strcat(buf, ascbuf);
  458. X   (void) strcat(buf, "\n");
  459. X   (void) sprintf(temp, "%04X: ", count);
  460. X   (void) write(fdd, temp, strlen(temp));
  461. X   (void) write(fdd, buf, strlen(buf));
  462. X}
  463. X
  464. X/*
  465. X * opendebug() opens the debug file in the appropriate place.
  466. X */
  467. Xopendebug(prog)
  468. Xchar *prog;
  469. X{
  470. X   int i, fdd;
  471. X   char debugfile[128];
  472. X   struct stat sbuf;
  473. X   
  474. X   for (i = 0; i < 100; i++) {
  475. X      (void) sprintf(debugfile, "%s/%s.debug.%d", DEBUGDIR, prog, i);
  476. X      if (!stat(debugfile, &sbuf))
  477. X     continue;
  478. X      fdd = open(debugfile, O_CREAT|O_TRUNC|O_WRONLY, 0666);
  479. X      if (fdd < 0) {
  480. X     syslog(LOG_ERR,"%s: Can't open %s: %m", prog, debugfile);
  481. X     return -1;
  482. X      }
  483. X      break;
  484. X   }
  485. X   if (i == 100) {
  486. X      syslog(LOG_ERR,"%s: Too many debug files in %s", prog, DEBUGDIR);
  487. X      return -1;
  488. X   }
  489. X   debugmsg(fdd, "Started");
  490. X   return fdd;
  491. X}
  492. X#endif
  493. END_OF_FILE
  494.   if test 4347 -ne `wc -c <'psimail/debugmsg.c'`; then
  495.     echo shar: \"'psimail/debugmsg.c'\" unpacked with wrong size!
  496.   fi
  497.   # end of 'psimail/debugmsg.c'
  498. fi
  499. if test -f 'psimail/str.c' -a "${1}" != "-c" ; then 
  500.   echo shar: Will not clobber existing file \"'psimail/str.c'\"
  501. else
  502.   echo shar: Extracting \"'psimail/str.c'\" \(4633 characters\)
  503.   sed "s/^X//" >'psimail/str.c' <<'END_OF_FILE'
  504. X/*
  505. X * $Log: str.c,v $
  506. X * Some string functions.
  507. X * Venkataraman Anand, Nov 91
  508. X */
  509. X/*
  510. X * Copyright (c) 1991 Computing Services, Massey University,
  511. X * Palmerston North, New Zealand
  512. X * All rights reserved.
  513. X *
  514. X * Redistribution and use in source and binary forms, with or without
  515. X * modification, are permitted provided that the following conditions
  516. X * are met:
  517. X * 1. Redistributions of source code must retain the above copyright
  518. X *    notice, this list of conditions and the following disclaimer.
  519. X * 2. Redistributions in binary form must reproduce the above copyright
  520. X *    notice, this list of conditions and the following disclaimer in the
  521. X *    documentation and/or other materials provided with the distribution.
  522. X * 3. All advertising materials mentioning features or use of this software
  523. X *    must display the following acknowledgement:
  524. X *       This product includes software developed by the Systems Software
  525. X *       Support Group, Computing Services, Massey University,
  526. X *       Palmerston North, NZ.
  527. X * 4. The name of Massey University may not be used to endorse or promote
  528. X *    products derived from this software without specific prior written
  529. X *    permission.
  530. X *
  531. X * THIS SOFTWARE IS PROVIDED BY COMPUTING SERVICES, MASSEY UNIVERSITY
  532. X * `AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  533. X * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  534. X * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL MASSEY UNIVERSITY BE
  535. X * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  536. X * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  537. X * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  538. X * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  539. X * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  540. X * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  541. X * POSSIBILITY OF SUCH DAMAGE.
  542. X */
  543. X
  544. X#include <stdio.h>
  545. X#include <string.h>
  546. X#include "str.h"
  547. X
  548. X#define isupper(c) ('A' <= (c) && (c) <= 'Z')
  549. X#define tolower(c) ((isupper(c))? (c)-'A'+'a' : (c))
  550. X
  551. Xstricmp (s, t)
  552. Xregister char *s, *t;
  553. X{
  554. X   while (tolower (*s) == tolower (*t)) {
  555. X      if (!*s)
  556. X     return 0;
  557. X      ++s; ++t;
  558. X   }
  559. X   return (tolower (*s) - tolower (*t));
  560. X}
  561. X
  562. Xstrnicmp (s, t, n)
  563. Xregister char *s, *t;
  564. X{
  565. X   while (tolower (*s) == tolower (*t)) {
  566. X      if (!*s || !--n)
  567. X     return 0;
  568. X      ++s; ++t;
  569. X   }
  570. X   return (tolower (*s) - tolower (*t));
  571. X}
  572. X
  573. Xchar *strsave (s)        /*  save string s */
  574. Xchar *s;
  575. X{
  576. X   char *malloc();
  577. X   register char *p;
  578. X
  579. X   if ((p = malloc ((unsigned) strlen (s) + 1)) != NULL )
  580. X       (void) strcpy (p, s);
  581. X   return (p);
  582. X}
  583. X
  584. Xchar *strtok (s, delims)   /*  return successive tokens from s */
  585. Xchar *s, *delims;
  586. X{
  587. X   static char *t = NULL;
  588. X   register char *p, *temp;
  589. X
  590. X   if (s != NULL)          /* new string */
  591. X      t = s;
  592. X
  593. X   /* preliminary check */
  594. X   if (t == NULL && s == NULL)
  595. X      return NULL;
  596. X
  597. X   /* skip leading delims */
  598. X   while (*t && strchr (delims, *t) != NULL)
  599. X      ++t;
  600. X   if (!*t)               /* string ends after delims */
  601. X      return (NULL);      /* no more tokens */
  602. X   p = t;
  603. X   while (*p && strchr (delims, *p) == NULL)
  604. X      ++p;
  605. X   if (!*p) {        /* end of string */
  606. X      p = t;
  607. X      t = NULL;      /* so next call returns NULL */
  608. X      return p;
  609. X   }
  610. X      
  611. X   *p = '\0';
  612. X   temp = p;       /* swap p and t so t points after new token */
  613. X   p = t;
  614. X   t = temp;
  615. X   ++t;
  616. X   
  617. X   return p;
  618. X}
  619. X   
  620. Xchar *stristr (s, p)        /*  return p in s (ignore case) */
  621. Xchar *s, *p;
  622. X{
  623. X   register int i;
  624. X   
  625. X   i = strlen (p);
  626. X   while (*s) {
  627. X      if (!strnicmp (s, p, i))
  628. X     return s;
  629. X      ++s;
  630. X   }
  631. X   return (NULL);
  632. X}
  633. X
  634. Xchar *strrmc(s,c)
  635. Xregister char *s;
  636. X{
  637. X   register char *p;
  638. X   
  639. X   if (!c)
  640. X      return s;
  641. X   while ((p = strchr(s,c)) != NULL)
  642. X      (void) strcpy(p,p+1);
  643. X   return s;
  644. X}
  645. X
  646. Xchar *strchr (s, c)        /*  return first occurrence of c in s  */
  647. Xregister char *s;               /* NULL otherwise  */
  648. X{
  649. X   while (*s != c && *s)
  650. X      ++s;
  651. X   /*
  652. X    * This last 'if' is necessary because the loop is exited when the
  653. X    * end of s is reached.
  654. X    * If c was '\0' it does match a character in s and therefore a test
  655. X    * is done to determine that condition.
  656. X    */
  657. X   if (*s == c)
  658. X      return s;
  659. X   else
  660. X      return (NULL);
  661. X   
  662. X}
  663. X
  664. Xchar *strrchr (s, c)            /* return last occurrence of c in s */
  665. Xchar *s;                        /* NULL otherwise  */
  666. Xint c;
  667. X{
  668. X   register char *p;
  669. X
  670. X   p = s;
  671. X   while (*s)
  672. X      ++s;          /* get to the end of s */
  673. X   while (s >= p && *s != c)
  674. X      --s;
  675. X   if (s < p)
  676. X      return (NULL);
  677. X   else
  678. X      return s;
  679. X}
  680. X      
  681. X
  682. X
  683. X
  684. X
  685. END_OF_FILE
  686.   if test 4633 -ne `wc -c <'psimail/str.c'`; then
  687.     echo shar: \"'psimail/str.c'\" unpacked with wrong size!
  688.   fi
  689.   # end of 'psimail/str.c'
  690. fi
  691. if test -f 'psimail/str.h' -a "${1}" != "-c" ; then 
  692.   echo shar: Will not clobber existing file \"'psimail/str.h'\"
  693. else
  694.   echo shar: Extracting \"'psimail/str.h'\" \(2082 characters\)
  695.   sed "s/^X//" >'psimail/str.h' <<'END_OF_FILE'
  696. X/*
  697. X * $Log: str.h,v $
  698. X * Some string function declarations
  699. X * Venkataraman Anand, Nov 91
  700. X */
  701. X
  702. X/*
  703. X * Copyright (c) 1991 Computing Services, Massey University,
  704. X * Palmerston North, New Zealand
  705. X * All rights reserved.
  706. X *
  707. X * Redistribution and use in source and binary forms, with or without
  708. X * modification, are permitted provided that the following conditions
  709. X * are met:
  710. X * 1. Redistributions of source code must retain the above copyright
  711. X *    notice, this list of conditions and the following disclaimer.
  712. X * 2. Redistributions in binary form must reproduce the above copyright
  713. X *    notice, this list of conditions and the following disclaimer in the
  714. X *    documentation and/or other materials provided with the distribution.
  715. X * 3. All advertising materials mentioning features or use of this software
  716. X *    must display the following acknowledgement:
  717. X *       This product includes software developed by the Systems Software
  718. X *       Support Group, Computing Services, Massey University,
  719. X *       Palmerston North, NZ.
  720. X * 4. The name of Massey University may not be used to endorse or promote
  721. X *    products derived from this software without specific prior written
  722. X *    permission.
  723. X *
  724. X * THIS SOFTWARE IS PROVIDED BY COMPUTING SERVICES, MASSEY UNIVERSITY
  725. X * `AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  726. X * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  727. X * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL MASSEY UNIVERSITY BE
  728. X * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  729. X * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  730. X * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  731. X * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  732. X * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  733. X * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  734. X * POSSIBILITY OF SUCH DAMAGE.
  735. X */
  736. X
  737. Xchar *strchr();
  738. Xchar *strrmc();
  739. Xchar *strsave();
  740. Xchar *stristr();
  741. Xchar *strtok();
  742. Xchar *strtrunc();
  743. Xchar *strrchr();
  744. END_OF_FILE
  745.   if test 2082 -ne `wc -c <'psimail/str.h'`; then
  746.     echo shar: \"'psimail/str.h'\" unpacked with wrong size!
  747.   fi
  748.   # end of 'psimail/str.h'
  749. fi
  750. echo shar: End of archive 2 \(of 2\).
  751. cp /dev/null ark2isdone
  752. MISSING=""
  753. for I in 1 2 ; do
  754.     if test ! -f ark${I}isdone ; then
  755.     MISSING="${MISSING} ${I}"
  756.     fi
  757. done
  758. if test "${MISSING}" = "" ; then
  759.     echo You have unpacked both archives.
  760.     rm -f ark[1-9]isdone
  761. else
  762.     echo You still must unpack the following archives:
  763.     echo "        " ${MISSING}
  764. fi
  765. exit 0
  766. exit 0 # Just in case...
  767. -- 
  768. Kent Landfield                   INTERNET: kent@sparky.IMD.Sterling.COM
  769. Sterling Software, IMD           UUCP:     uunet!sparky!kent
  770. Phone:    (402) 291-8300         FAX:      (402) 291-4362
  771. Please send comp.sources.misc-related mail to kent@uunet.uu.net.
  772.