-/* remove_xline_from_file()
- *
- * inputs - gecos to remove
- * outputs -
- * side effects - removes xline from conf, if exists
- * - does not touch xline_conf_list
- */
-static int
-remove_xline_from_file(struct Client *source_p, const char *huntgecos)
-{
- FILE *in, *out;
- char buf[BUFSIZE];
- char buff[BUFSIZE];
- char temppath[BUFSIZE];
- const char *filename;
- const char *gecos;
- mode_t oldumask;
- char *p;
- char *encoded;
- int error_on_write = 0;
- int found_xline = 0;
-
- filename = ConfigFileEntry.xlinefile;
- rb_snprintf(temppath, sizeof(temppath),
- "%s.tmp", ConfigFileEntry.xlinefile);
-
- 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))
- {
- 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((gecos = getfield(buff)) == NULL)
- {
- error_on_write = (fputs(buf, out) < 0) ? YES : NO;
- continue;
- }
-
- /* matching.. */
- encoded = xline_encode_spaces(gecos);
- if(irccmp(encoded, huntgecos) == 0)
- found_xline++;
- else
- error_on_write = (fputs(buf, out) < 0) ? YES : NO;
- rb_free(encoded);
- }
-
- fclose(in);
- if (fclose(out))
- error_on_write = YES;
-
- if(error_on_write)
- {
- sendto_one_notice(source_p,
- ":Couldn't write temp xline file, aborted");
- return 0;
- }
- else if(found_xline == 0)
- {
- sendto_one_notice(source_p, ":Cannot find X-Line for %s in file", huntgecos);
-
- 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, ":X-Line for [%s] is removed", huntgecos);
- sendto_realops_snomask(SNO_GENERAL, L_ALL,
- "%s has removed the X-Line for: [%s]",
- get_oper_name(source_p), huntgecos);
- ilog(L_KLINE, "UX %s %s", get_oper_name(source_p), huntgecos);
-
- return 1;