home *** CD-ROM | disk | FTP | other *** search
/ back2roots/padua / padua.7z / padua / uucp / ListSERV1_4.lha / ListSERV / source / RCS / listsearch.c,v < prev    next >
Encoding:
Text File  |  1993-12-29  |  14.0 KB  |  537 lines

  1. head    1.3;
  2. branch    1.3.1;
  3. access;
  4. symbols;
  5. locks
  6.     simons:1.3.1.9
  7.     andy:1.3; strict;
  8. comment    @ * @;
  9.  
  10.  
  11. 1.3
  12. date    92.02.24.12.54.25;    author andy;    state Exp;
  13. branches
  14.     1.3.1.1;
  15. next    ;
  16.  
  17. 1.3.1.1
  18. date    93.12.26.00.41.57;    author simons;    state Exp;
  19. branches;
  20. next    1.3.1.2;
  21.  
  22. 1.3.1.2
  23. date    93.12.26.18.42.11;    author simons;    state Exp;
  24. branches;
  25. next    1.3.1.3;
  26.  
  27. 1.3.1.3
  28. date    93.12.26.19.35.55;    author simons;    state Exp;
  29. branches;
  30. next    1.3.1.4;
  31.  
  32. 1.3.1.4
  33. date    93.12.26.21.22.27;    author simons;    state Exp;
  34. branches;
  35. next    1.3.1.5;
  36.  
  37. 1.3.1.5
  38. date    93.12.27.17.37.04;    author simons;    state Exp;
  39. branches;
  40. next    1.3.1.6;
  41.  
  42. 1.3.1.6
  43. date    93.12.28.17.35.16;    author simons;    state Exp;
  44. branches;
  45. next    1.3.1.7;
  46.  
  47. 1.3.1.7
  48. date    93.12.28.22.16.34;    author simons;    state Exp;
  49. branches;
  50. next    1.3.1.8;
  51.  
  52. 1.3.1.8
  53. date    93.12.29.06.24.47;    author simons;    state Exp;
  54. branches;
  55. next    1.3.1.9;
  56.  
  57. 1.3.1.9
  58. date    93.12.29.06.56.57;    author simons;    state Exp;
  59. branches;
  60. next    ;
  61.  
  62.  
  63. desc
  64. @Original Unix-Listserv distribution.
  65. @
  66.  
  67.  
  68. 1.3
  69. log
  70. @checked in with -k by simons at 1993/12/26 00:08:53
  71. @
  72. text
  73. @#include "listserv.h"
  74.  
  75. static char rcsid[] = "$Header: /usr/local/src/mail/listserv/RCS/listsearch.c,v 1.3 92/02/24 12:54:25 andy Exp Locker: andy $";
  76.  
  77. extern FILE *msg;
  78. extern FILE *mailer;
  79.  
  80. listsearch(from,command)
  81. char *from,*command;
  82.         {
  83.         FILE *list;
  84.         FILE *listtmp;
  85.         FILE *subslist;
  86.         DIR *listdir;
  87.         struct dirent *entry;
  88.         struct stat statbuf;
  89.         char *s, *p;
  90.         char *template = "/tmp/listservXXXXXX";
  91.         char adr[256];
  92.         char tmp[512];
  93.         char request[256];
  94.         char buf[BUFSIZ];
  95.         int i;
  96.  
  97.         printf("listsearch %s %s \n", from, command);
  98.         i = sscanf(command,"%s%s", request, adr);
  99.         if ((i < 1) || (i > 2))
  100.                 sendhelp(from, command);
  101.         if (i == 1)
  102.                 strcpy(adr, from);
  103.         cleanup(adr,&i);
  104.         listdir = opendir(SERVDIR);
  105.         if (listdir == NULL)
  106.                 {
  107.                 perror(SERVDIR);
  108.                 exit(1);
  109.                 }
  110.         i = mkstemp(template);
  111.         if ( i == -1)
  112.                 {
  113.                 callmailer(LISTSERVMANAGER, from, "");
  114.                 fprintf(mailer,"Error[5] processing request. Please try later.\n");
  115.                 fprintf(mailer,">%s\n", command);
  116.                 fflush(mailer);
  117.                 pclose(mailer);
  118.                 return(-1);
  119.                 }
  120.         else
  121.                 {
  122.                 subslist = fdopen(i, "w+");
  123.                 if (subslist == NULL)
  124.                         {
  125.                         callmailer(LISTSERVMANAGER, from, "");
  126.                         fprintf(mailer,"Error[5] processing request. Please try later.\n");
  127.                         fprintf(mailer,">%s\n", command);
  128.                         fflush(mailer);
  129.                         pclose(mailer);
  130.                         return(-1);
  131.                         }
  132.                 }
  133.  
  134.         while (entry = readdir(listdir))
  135.                 {
  136.                 if ((index(entry->d_name, '.'))
  137.                 || (isupper(entry->d_name[0])))
  138.                         continue;
  139.                 sprintf(tmp, "%s/%s", SERVDIR, entry->d_name);
  140.                 if (stat(tmp,&statbuf))
  141.                         {
  142.                         perror(tmp);
  143.                         exit(1);
  144.                         }
  145.                 /*If it's a directory, go to next entry*/
  146.                 else if ((statbuf.st_mode & S_IFMT) == S_IFDIR)
  147.                         continue;
  148.                 /*Skip the restricted access ones*/
  149.                 if (access(tmp,R_OK) != 0)
  150.                         {
  151.                         callmailer(LISTSERVMANAGER, from, "");
  152.                         p = rindex(tmp, '/');
  153.                         fprintf(mailer,"Unable to access %s\n", p+1);
  154.                         fprintf(mailer,">%s\n", command);
  155.                         fflush(mailer);
  156.                         pclose(mailer);
  157.                         continue;
  158.                         }
  159.  
  160.                 list = fopen(tmp, "r");
  161.                 if (list == NULL)
  162.                         {
  163.                         callmailer(LISTSERVMANAGER, from, "");
  164.                         fprintf(mailer,"Error[6] processing request. Please try later.\n");
  165.                         fprintf(mailer,">%s\n", command);
  166.                         fflush(mailer);
  167.                         pclose(mailer);
  168.                         return(-1);
  169.                         }
  170.                 flock(fileno(list), LOCK_EX);
  171.                 while(fgets(buf, sizeof(buf), list))
  172.                         {
  173.                         buf[strlen(buf)-1] = '\0';
  174.                         if (!strcasecmp(buf, adr))
  175.                                 {
  176.                                 fputs(entry->d_name, subslist);
  177.                                 fputs("\n", subslist);
  178.                                 }
  179.                         }
  180.                 fflush(list);
  181.                 flock(fileno(list), LOCK_UN);
  182.                 fclose(list);
  183.                 }
  184.         closedir(listdir);
  185.         if (!strcasecmp(request, "delete-all")
  186.         || !strcasecmp(request, "unsubscribe-all")
  187.         || !strcasecmp(request, "unsub-all")
  188.         || !strcasecmp(request, "del-all"))
  189.                 {
  190.                 rewind(subslist);
  191.                 while(fgets(tmp, sizeof(tmp), subslist))
  192.                         {
  193.                         strcpy(buf, SERVDIR);
  194.                         strcat(buf, "/");
  195.                         strcat(buf, tmp);
  196.                         buf[strlen(buf) -1] = '\0';
  197.                         list = fopen(buf, "r");
  198.                         if (list == NULL)
  199.                                 {
  200.                                 callmailer(LISTSERVMANAGER, from, "");
  201.                                 fprintf(mailer, "Error[7] processing request. Please try later.\n");
  202.                                 fprintf(mailer, ">%s\n", command);
  203.                                 fflush(mailer);
  204.                                 pclose(mailer);
  205.                                 return(-1);
  206.                                 }
  207.                         flock(fileno(list), LOCK_EX);
  208.  
  209.                         strcat(buf, ".tmp");
  210.                         listtmp = fopen(buf, "w");
  211.                         if (listtmp == NULL)
  212.                                 {
  213.                                 callmailer(LISTSERVMANAGER, from, "");
  214.                                 fprintf(mailer,"Error[8] processing request. Please try later.\n");
  215.                                 fprintf(mailer,">%s\n", command);
  216.                                 fflush(mailer);
  217.                                 pclose(mailer);
  218.                                 return(-1);
  219.                                 }
  220.                         /* copy the list, omitting the one address */
  221.                         while (fgets(tmp, sizeof(tmp), list))
  222.                                 {
  223.                                 tmp[strlen(tmp)-1] = '\0';
  224.                                 if (strcasecmp(tmp, adr))
  225.                                         {
  226.                                         fputs(tmp, listtmp);
  227.                                         fputs("\n", listtmp);
  228.                                         }
  229.                                 }
  230.                         fflush(listtmp);
  231.                         fclose(listtmp);
  232.  
  233.                         /* replace the old list with the shortened one */
  234.                         strcpy(tmp, buf);
  235.                         s = rindex(buf, '.');
  236.                         *s = '\0';
  237.                         unlink(buf);
  238.                         rename(tmp, buf);       /* put updated one in place */
  239.                         flock(fileno(list), LOCK_UN);   /* release lock */
  240.                         }
  241.                 }
  242. #ifndef DEBUG
  243.         if (strcmp(from, adr))
  244.                 {
  245.                 callmailer(adr, from, command);
  246.                 fprintf(mailer,"Per request by %s\n", from);
  247.                 }
  248.         else
  249.                 {
  250.                 callmailer("", from, command);
  251.                 fprintf(mailer,"Per your request\n");
  252.                 }
  253. #else
  254.         callmailer("", from, command);
  255.         fprintf(mailer,"Per your request\n");
  256.  
  257. #endif
  258.         fprintf(mailer,"\t\"%s\"\n", command);
  259.         rewind(subslist);
  260.         if ((i = getc(subslist)) == EOF)
  261.                 fprintf(mailer, "'%s' is not subscribed to any mailing lists.\n", adr);
  262.         else
  263.                 {
  264.                 if (strcasecmp(request, "delete-all")
  265.                 && strcasecmp(request, "unsubscribe-all")
  266.                 && strcasecmp(request, "unsub-all")
  267.                 && strcasecmp(request, "del-all"))
  268.                         fprintf(mailer,"'%s' is subscribed to the following mailing lists:\n", adr);
  269.                 else
  270.                         fprintf(mailer,"'%s' was DELETED from the following mailing lists:\n", adr);
  271.                 mailcat(template, "\t");
  272.                 }
  273.         fflush(mailer);
  274.         pclose(mailer);
  275.         unlink(template);
  276.         fflush(subslist);
  277.         fclose(subslist);
  278.         }
  279.  
  280.  
  281. @
  282.  
  283.  
  284. 1.3.1.1
  285. log
  286. @Changed source code to compiler under SAS/C 6.50.
  287. @
  288. text
  289. @d1 1
  290. a1 1
  291. #include <functions.h>
  292. d3 1
  293. a3 2
  294. #include "listserv.h"
  295. #include "protos.h"
  296. d5 2
  297. a6 1
  298. static char rcsid[] = "$Id$";
  299. d8 1
  300. a8 1
  301. int listsearch(from,command)
  302. @
  303.  
  304.  
  305. 1.3.1.2
  306. log
  307. @Changed listsearch() to use a more amiga-specific diretory structure.
  308. Mailing lists are administrated in a subdirectory of LISTDIR
  309. (default: "ListSERV:groups/"), with the directoryname reflecting the
  310. name of the mailing list. The actual addresses are written down in a
  311. file names 'list'.
  312. Additionally, optiomized the code a lot. Removed UNIX stuff, etc...
  313. @
  314. text
  315. @d6 1
  316. a6 1
  317. static char rcsid[] = "$Id: listsearch.c,v 1.3.1.1 1993/12/26 00:41:57 simons Exp simons $";
  318. d16 3
  319. a18 2
  320.         char *s;
  321.         char *template = tmpnam(NULL);
  322. d23 1
  323. a23 1
  324.         int i, found = 0;
  325. d32 1
  326. a32 1
  327.         listdir = opendir(LISTDIR);
  328. d35 1
  329. a35 1
  330.                 perror(LISTDIR);
  331. d38 2
  332. a39 1
  333.         if (!(subslist = fopen(template, "w")))
  334. d48 14
  335. d64 24
  336. a87 2
  337.                 sprintf(tmp, "%s%s/list", LISTDIR, entry->d_name);
  338.                 /* LockFile(tmp);       --FIXME */
  339. d98 1
  340. a105 1
  341.                                 found++;
  342. d109 1
  343. a109 1
  344.                 /* UnLockFile(tmp);       --FIXME */
  345. d122 1
  346. a169 1
  347.  
  348. a185 1
  349.  
  350. d187 2
  351. a188 4
  352.         fclose(subslist);       /* We have to close the file, so mailcat()
  353.                                  * can access it.
  354.                                  */
  355.         if (!found)
  356. d203 1
  357. a203 1
  358.         remove(template);
  359. @
  360.  
  361.  
  362. 1.3.1.3
  363. log
  364. @Removed the complete local/non-local user determination, including
  365. all >outsider< parameters and the cleanup() routine.
  366. Changed UNIX-paths to conform with AmigaDOS.
  367. @
  368. text
  369. @d6 1
  370. a6 1
  371. static char rcsid[] = "$Id: listsearch.c,v 1.3.1.2 1993/12/26 18:42:11 simons Exp simons $";
  372. d30 1
  373. a30 1
  374.  
  375. @
  376.  
  377.  
  378. 1.3.1.4
  379. log
  380. @Added 'DELETE-ALL'-command.
  381. Added filelocking mechanism.
  382. @
  383. text
  384. @d6 1
  385. a6 1
  386. static char rcsid[] = "$Id: listsearch.c,v 1.3.1.3 1993/12/26 19:35:55 simons Exp simons $";
  387. d16 1
  388. a16 1
  389.         char adr[256], tmp[512], tmp2[512], request[256], buf[BUFSIZ];
  390. d18 4
  391. d37 1
  392. a37 1
  393.         if (!(subslist = fopen(template, "w+")))
  394. d49 1
  395. a49 1
  396.                 LockFile(tmp);
  397. a52 1
  398.                         UnLockFile(tmp);
  399. d71 1
  400. a71 1
  401.                 UnLockFile(tmp);
  402. d81 1
  403. a81 1
  404.                 while(fgets(buf, sizeof(tmp), subslist))
  405. d83 2
  406. d86 1
  407. a86 3
  408.                         sprintf(tmp, "%s%s/LIST", LISTDIR, buf);
  409.                         LockFile(tmp);
  410.                         list = fopen(tmp, "r");
  411. a88 1
  412.                                 UnLockFile(tmp);
  413. d96 4
  414. a99 3
  415.                         sprintf(tmp2, "%s.tmp", tmp);
  416.                         LockFile(tmp2);
  417.                         listtmp = fopen(tmp2, "w");
  418. a101 1
  419.                                 UnLockFile(tmp2);
  420. d110 1
  421. a110 1
  422.                         while (fgets(buf, sizeof(buf), list))
  423. d112 2
  424. a113 2
  425.                                 buf[strlen(buf)-1] = '\0';
  426.                                 if (strcasecmp(buf, adr))
  427. d115 1
  428. a115 1
  429.                                         fputs(buf, listtmp);
  430. d119 1
  431. d123 6
  432. a128 5
  433.                         fclose(list);
  434.                         remove(tmp);
  435.                         rename(tmp2, tmp);       /* put updated one in place */
  436.                         UnLockFile(tmp);
  437.                         UnLockFile(tmp2);
  438. @
  439.  
  440.  
  441. 1.3.1.5
  442. log
  443. @Changes filenames for the address-list.
  444. @
  445. text
  446. @d6 1
  447. a6 1
  448. static char rcsid[] = "$Id: listsearch.c,v 1.3.1.4 1993/12/26 21:22:27 simons Exp simons $";
  449. d44 1
  450. a44 1
  451.                 sprintf(tmp, "%s%s/List", LISTDIR, entry->d_name);
  452. d81 1
  453. a81 1
  454.                         sprintf(tmp, "%s%s/List", LISTDIR, buf);
  455. @
  456.  
  457.  
  458. 1.3.1.6
  459. log
  460. @Now, LISTSERVMANAGER receives a carbon copy of any successful ADD-ALL or
  461. DELETE-ALL command.
  462. @
  463. text
  464. @d6 1
  465. a6 1
  466. static char rcsid[] = "$Id: listsearch.c,v 1.3.1.5 1993/12/27 17:37:04 simons Exp simons $";
  467. d128 1
  468. d131 1
  469. a131 1
  470.                 callmailer(LISTSERVMANAGER, adr, command);
  471. d136 1
  472. a136 1
  473.                 callmailer(LISTSERVMANAGER, from, command);
  474. d139 3
  475. d143 2
  476. d168 1
  477. @
  478.  
  479.  
  480. 1.3.1.7
  481. log
  482. @Changed function declarations to ANSI-compliant style.
  483. @
  484. text
  485. @d6 1
  486. a6 1
  487. static char rcsid[] = "$Id: listsearch.c,v 1.3.1.6 1993/12/28 17:35:16 simons Exp simons $";
  488. d8 3
  489. a10 3
  490. int listsearch(char *from,
  491.                char *command)
  492. {
  493. @
  494.  
  495.  
  496. 1.3.1.8
  497. log
  498. @Removed the strange internal string compare routines.
  499. @
  500. text
  501. @d6 1
  502. a6 1
  503. static char rcsid[] = "$Id: listsearch.c,v 1.3.1.7 1993/12/28 22:16:34 simons Exp simons $";
  504. d60 1
  505. a60 1
  506.                         if (!stricmp(buf, adr))
  507. d72 4
  508. a75 4
  509.         if (!stricmp(request, "delete-all")
  510.         || !stricmp(request, "unsubscribe-all")
  511.         || !stricmp(request, "unsub-all")
  512.         || !stricmp(request, "del-all"))
  513. d111 1
  514. a111 1
  515.                                 if (stricmp(buf, adr))
  516. d147 4
  517. a150 4
  518.                 if (stricmp(request, "delete-all")
  519.                 && stricmp(request, "unsubscribe-all")
  520.                 && stricmp(request, "unsub-all")
  521.                 && stricmp(request, "del-all"))
  522. @
  523.  
  524.  
  525. 1.3.1.9
  526. log
  527. @Changed a string comparison to be case-independent.
  528. @
  529. text
  530. @d6 1
  531. a6 1
  532. static char rcsid[] = "$Id: listsearch.c,v 1.3.1.8 1993/12/29 06:24:47 simons Exp simons $";
  533. d128 1
  534. a128 1
  535.         if (stricmp(from, adr))
  536. @
  537.