-/* remove_resv_from_file()
- *
- * inputs - client removing the resv
- * - resv to remove
- * outputs -
- * side effects - resv if found, is removed from conf
- * - does not touch resv hash or resv_conf_list
- */
-static int
-remove_resv_from_file(struct Client *source_p, const char *name)
-{
- FILE *in, *out;
- char buf[BUFSIZE];
- char buff[BUFSIZE];
- char temppath[BUFSIZE];
- const char *filename;
- mode_t oldumask;
- char *p;
- int error_on_write = 0;
- int found_resv = 0;
-
- rb_sprintf(temppath, "%s.tmp", ConfigFileEntry.resvfile);
- filename = get_conf_name(RESV_TYPE);
-
- if((in = fopen(filename, "r")) == NULL)
- {
- sendto_one_notice(source_p, ":Cannot open %s", filename);
- return 0;
- }
-
- oldumask = umask(0);
-
- if((out = fopen(temppath, "w")) == NULL)
- {
- sendto_one_notice(source_p, ":Cannot open %s", temppath);
- fclose(in);
- umask(oldumask);
- return 0;
- }
-
- umask(oldumask);
-
- while (fgets(buf, sizeof(buf), in))
- {
- const char *resv_name;
-
- if(error_on_write)
- {
- if(temppath != NULL)
- (void) unlink(temppath);
-
- break;
- }
-
- rb_strlcpy(buff, buf, sizeof(buff));
-
- if((p = strchr(buff, '\n')) != NULL)
- *p = '\0';
-
- if((*buff == '\0') || (*buff == '#'))
- {
- error_on_write = (fputs(buf, out) < 0) ? YES : NO;
- continue;
- }
-
- if((resv_name = getfield(buff)) == NULL)
- {
- error_on_write = (fputs(buf, out) < 0) ? YES : NO;
- continue;
- }
-
- if(irccmp(resv_name, name) == 0)
- {
- found_resv++;
- }
- else
- {
- error_on_write = (fputs(buf, out) < 0) ? YES : NO;
- }
- }
-
- fclose(in);
- if (fclose(out))
- error_on_write = YES;
-
- if(error_on_write)
- {
- sendto_one_notice(source_p, ":Couldn't write temp resv file, aborted");
- return 0;
- }
- else if(!found_resv)
- {
- sendto_one_notice(source_p, ":Cannot find RESV for %s in file", name);
-
- if(temppath != NULL)
- (void) unlink(temppath);
-
- return 0;
- }
-
- if (rename(temppath, filename))
- {
- sendto_one_notice(source_p, ":Couldn't rename temp file, aborted");
- return 0;
- }
-
- sendto_one_notice(source_p, ":RESV for [%s] is removed", name);
- sendto_realops_snomask(SNO_GENERAL, L_ALL,
- "%s has removed the RESV for: [%s]", get_oper_name(source_p), name);
- ilog(L_KLINE, "UR %s %s", get_oper_name(source_p), name);
-
- return 1;
-}
-