1 /* $Id: getmodaddr.c 6155 2003-01-19 19:58:25Z rra $
9 #include "inn/innconf.h"
15 static char *GMApathname = NULL;
16 static FILE *GMAfp = NULL;
20 ** Close the file opened by GMAlistopen.
29 if (GMApathname != NULL) {
37 ** Internal library routine.
40 GMA_listopen(int fd, FILE *FromServer, FILE *ToServer, const char *request)
51 /* Send a LIST command to and capture the output. */
53 fprintf(ToServer, "list moderators\r\n");
55 fprintf(ToServer, "list %s\r\n", request);
58 /* Get the server's reply to our command. */
59 if (fgets(buff, sizeof buff, FromServer) == NULL
60 || strncmp(buff, NNTP_LIST_FOLLOWS, strlen(NNTP_LIST_FOLLOWS)) != 0) {
68 /* Slurp up the rest of the response. */
69 while (fgets(buff, sizeof buff, FromServer) != NULL) {
70 if ((p = strchr(buff, '\r')) != NULL)
72 if ((p = strchr(buff, '\n')) != NULL)
74 if (buff[0] == '.' && buff[1] == '\0') {
75 if (ferror(F) || fflush(F) == EOF || fseeko(F, 0, SEEK_SET) != 0)
79 fprintf(F, "%s\n", buff);
82 /* Ran out of input before finding the terminator; quit. */
91 ** Read the moderators file, looking for a moderator.
94 GetModeratorAddress(FILE *FromServer, FILE *ToServer, char *group,
95 char *moderatormailer)
97 static char address[SMBUF];
105 strlcpy(name, group, sizeof(name));
108 if (FromServer==NULL || ToServer==NULL){
111 * This should be part of nnrpd or the like running on the server.
112 * Open the server copy of the moderators file.
114 path = concatpath(innconf->pathetc, _PATH_MODERATORS);
115 GMAfp = fopen(path, "r");
119 * Get a local copy of the moderators file from the server.
121 GMApathname = concatpath(innconf->pathtmp, _PATH_TEMPMODERATORS);
122 fd = mkstemp(GMApathname);
124 GMAfp = GMA_listopen(fd, FromServer, ToServer, "moderators");
128 /* Fallback to the local copy if the server doesn't have it */
130 path = concatpath(innconf->pathetc, _PATH_MODERATORS);
131 GMAfp = fopen(path, "r");
137 while (fgets(buff, sizeof buff, GMAfp) != NULL) {
138 /* Skip blank and comment lines. */
139 if ((p = strchr(buff, '\n')) != NULL)
141 if (buff[0] == '\0' || buff[0] == '#')
144 /* Snip off the first word. */
145 if ((p = strchr(buff, ':')) == NULL)
146 /* Malformed line... */
150 /* If it pattern-matches the newsgroup, the second field is a
151 * format for mailing, with periods changed to dashes. */
152 if (uwildmat(name, buff)) {
153 for (save = p; ISWHITE(*save); save++)
155 for (p = name; *p; p++)
158 snprintf(address, sizeof(address), save, name);
168 /* If we don't have an address, see if the config file has a default. */
169 if ((save = moderatormailer) == NULL)
172 for (p = name; *p; p++)
175 snprintf(address, sizeof(address), save, name);