1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
|
/* $Revision: 1.13 $
**
*/
#include <stdio.h>
#include <sys/types.h>
#include "configdata.h"
#include "clibrary.h"
#include <errno.h>
#include "paths.h"
#include "libinn.h"
#include "macros.h"
#include "nntp.h"
STATIC char GMApathname[sizeof _PATH_TEMPMODERATORS];
STATIC FILE *GMAfp;
/*
** Close the file opened by GMAlistopen.
*/
void
GMAclose()
{
if (GMAfp) {
(void)fclose(GMAfp);
GMAfp = NULL;
}
if (GMApathname[0]) {
(void)unlink(GMApathname);
GMApathname[0] = '\0';
}
}
/*
** Internal library routine.
*/
FILE *
GMA_listopen(pathname, FromServer, ToServer, request)
char *pathname;
FILE *FromServer;
FILE *ToServer;
char *request;
{
char buff[BUFSIZ];
char *p;
int oerrno;
FILE *F;
(void)unlink(pathname);
if ((F = fopen(pathname, "w")) == NULL)
return NULL;
/* Send a LIST command to and capture the output. */
if (request == NULL)
(void)fprintf(ToServer, "list moderators\r\n");
else
(void)fprintf(ToServer, "list %s\r\n", request);
(void)fflush(ToServer);
/* Get the server's reply to our command. */
if (fgets(buff, sizeof buff, FromServer) == NULL
|| !EQn(buff, NNTP_LIST_FOLLOWS, STRLEN(NNTP_LIST_FOLLOWS))) {
oerrno = errno;
GMAclose();
errno = oerrno;
return NULL;
}
/* Slurp up the rest of the response. */
while (fgets(buff, sizeof buff, FromServer) != NULL) {
if ((p = strchr(buff, '\r')) != NULL)
*p = '\0';
if ((p = strchr(buff, '\n')) != NULL)
*p = '\0';
if (buff[0] == '.' && buff[1] == '\0') {
if (ferror(F) || fflush(F) == EOF || fclose(F) == EOF)
break;
return fopen(pathname, "r");
}
(void)fprintf(F, "%s\n", buff);
}
/* Ran out of input before finding the terminator; quit. */
oerrno = errno;
(void)fclose(F);
GMAclose();
errno = oerrno;
return NULL;
}
/*
** Read the moderators file, looking for a moderator.
*/
char *
GetModeratorAddress(FromServer, ToServer, group)
FILE *FromServer;
FILE *ToServer;
char *group;
{
static char address[SMBUF];
register char *p;
char *save;
char buff[BUFSIZ];
char name[SMBUF];
(void)strcpy(name, group);
address[0] = '\0';
if (FromServer==NULL || ToServer==NULL){
/*
* This should be part of nnrpd or the like running on the server.
* Open the server copy of the moderators file.
*/
GMAfp = fopen(_PATH_MODERATORS, "r");
}else{
/*
* Get a local copy of the moderators file from the server.
*/
(void)strcpy(GMApathname, _PATH_TEMPMODERATORS);
(void)mktemp(GMApathname);
GMAfp = GMA_listopen(GMApathname, FromServer, ToServer, "moderators");
if (GMAfp == NULL) GMAfp = fopen(_PATH_MODERATORS, "r");
}
if (GMAfp != NULL) {
while (fgets(buff, sizeof buff, GMAfp) != NULL) {
/* Skip blank and comment lines. */
if ((p = strchr(buff, '\n')) != NULL)
*p = '\0';
if (buff[0] == '\0' || buff[0] == COMMENT_CHAR)
continue;
/* Snip off the first word. */
if ((p = strchr(buff, ':')) == NULL)
/* Malformed line... */
continue;
*p++ = '\0';
/* If it pattern-matches the newsgroup, the second field is a
* format for mailing, with periods changed to dashes. */
if (wildmat(name, buff)) {
for (save = p; ISWHITE(*save); save++)
continue;
for (p = name; *p; p++)
if (*p == '.')
*p = '-';
(void)sprintf(address, save, name);
break;
}
}
(void) GMAclose();
if (address[0])
return address;
}
/* If we don't have an address, see if the config file has a default. */
if ((save = GetConfigValue(_CONF_MODMAILER)) == NULL)
return NULL;
for (p = name; *p; p++)
if (*p == '.')
*p = '-';
(void)sprintf(address, save, name);
return address;
}
|